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-09-20 13:40:47 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                 :             : #include "diagnostics/diagnostics-selftests.h"
      60                 :             : 
      61                 :             : cpp_reader *parse_in;           /* Declared in c-pragma.h.  */
      62                 :             : 
      63                 :             : /* Mode used to build pointers (VOIDmode means ptr_mode).  */
      64                 :             : 
      65                 :             : machine_mode c_default_pointer_mode = VOIDmode;
      66                 :             : 
      67                 :             : /* The following symbols are subsumed in the c_global_trees array, and
      68                 :             :    listed here individually for documentation purposes.
      69                 :             : 
      70                 :             :    INTEGER_TYPE and REAL_TYPE nodes for the standard data types.
      71                 :             : 
      72                 :             :         tree short_integer_type_node;
      73                 :             :         tree long_integer_type_node;
      74                 :             :         tree long_long_integer_type_node;
      75                 :             : 
      76                 :             :         tree short_unsigned_type_node;
      77                 :             :         tree long_unsigned_type_node;
      78                 :             :         tree long_long_unsigned_type_node;
      79                 :             : 
      80                 :             :         tree truthvalue_type_node;
      81                 :             :         tree truthvalue_false_node;
      82                 :             :         tree truthvalue_true_node;
      83                 :             : 
      84                 :             :         tree ptrdiff_type_node;
      85                 :             : 
      86                 :             :         tree unsigned_char_type_node;
      87                 :             :         tree signed_char_type_node;
      88                 :             :         tree wchar_type_node;
      89                 :             : 
      90                 :             :         tree char8_type_node;
      91                 :             :         tree char16_type_node;
      92                 :             :         tree char32_type_node;
      93                 :             : 
      94                 :             :         tree float_type_node;
      95                 :             :         tree double_type_node;
      96                 :             :         tree long_double_type_node;
      97                 :             : 
      98                 :             :         tree complex_integer_type_node;
      99                 :             :         tree complex_float_type_node;
     100                 :             :         tree complex_double_type_node;
     101                 :             :         tree complex_long_double_type_node;
     102                 :             : 
     103                 :             :         tree dfloat32_type_node;
     104                 :             :         tree dfloat64_type_node;
     105                 :             :         tree dfloat128_type_node;
     106                 :             :         tree dfloat64x_type_node; 
     107                 :             : 
     108                 :             :         tree intQI_type_node;
     109                 :             :         tree intHI_type_node;
     110                 :             :         tree intSI_type_node;
     111                 :             :         tree intDI_type_node;
     112                 :             :         tree intTI_type_node;
     113                 :             : 
     114                 :             :         tree unsigned_intQI_type_node;
     115                 :             :         tree unsigned_intHI_type_node;
     116                 :             :         tree unsigned_intSI_type_node;
     117                 :             :         tree unsigned_intDI_type_node;
     118                 :             :         tree unsigned_intTI_type_node;
     119                 :             : 
     120                 :             :         tree widest_integer_literal_type_node;
     121                 :             :         tree widest_unsigned_literal_type_node;
     122                 :             : 
     123                 :             :    Nodes for types `void *' and `const void *'.
     124                 :             : 
     125                 :             :         tree ptr_type_node, const_ptr_type_node;
     126                 :             : 
     127                 :             :    Nodes for types `char *' and `const char *'.
     128                 :             : 
     129                 :             :         tree string_type_node, const_string_type_node;
     130                 :             : 
     131                 :             :    Type `char[SOMENUMBER]'.
     132                 :             :    Used when an array of char is needed and the size is irrelevant.
     133                 :             : 
     134                 :             :         tree char_array_type_node;
     135                 :             : 
     136                 :             :    Type `wchar_t[SOMENUMBER]' or something like it.
     137                 :             :    Used when a wide string literal is created.
     138                 :             : 
     139                 :             :         tree wchar_array_type_node;
     140                 :             : 
     141                 :             :    Type `char8_t[SOMENUMBER]' or something like it.
     142                 :             :    Used when a UTF-8 string literal is created.
     143                 :             : 
     144                 :             :         tree char8_array_type_node;
     145                 :             : 
     146                 :             :    Type `char16_t[SOMENUMBER]' or something like it.
     147                 :             :    Used when a UTF-16 string literal is created.
     148                 :             : 
     149                 :             :         tree char16_array_type_node;
     150                 :             : 
     151                 :             :    Type `char32_t[SOMENUMBER]' or something like it.
     152                 :             :    Used when a UTF-32 string literal is created.
     153                 :             : 
     154                 :             :         tree char32_array_type_node;
     155                 :             : 
     156                 :             :    Type `int ()' -- used for implicit declaration of functions.
     157                 :             : 
     158                 :             :         tree default_function_type;
     159                 :             : 
     160                 :             :    A VOID_TYPE node, packaged in a TREE_LIST.
     161                 :             : 
     162                 :             :         tree void_list_node;
     163                 :             : 
     164                 :             :   The lazily created VAR_DECLs for __FUNCTION__, __PRETTY_FUNCTION__,
     165                 :             :   and __func__. (C doesn't generate __FUNCTION__ and__PRETTY_FUNCTION__
     166                 :             :   VAR_DECLS, but C++ does.)
     167                 :             : 
     168                 :             :         tree function_name_decl_node;
     169                 :             :         tree pretty_function_name_decl_node;
     170                 :             :         tree c99_function_name_decl_node;
     171                 :             : 
     172                 :             :   Stack of nested function name VAR_DECLs.
     173                 :             : 
     174                 :             :         tree saved_function_name_decls;
     175                 :             : 
     176                 :             : */
     177                 :             : 
     178                 :             : tree c_global_trees[CTI_MAX];
     179                 :             : 
     180                 :             : /* Switches common to the C front ends.  */
     181                 :             : 
     182                 :             : /* Nonzero means don't output line number information.  */
     183                 :             : 
     184                 :             : char flag_no_line_commands;
     185                 :             : 
     186                 :             : /* Nonzero causes -E output not to be done, but directives such as
     187                 :             :    #define that have side effects are still obeyed.  */
     188                 :             : 
     189                 :             : char flag_no_output;
     190                 :             : 
     191                 :             : /* Nonzero means dump macros in some fashion.  */
     192                 :             : 
     193                 :             : char flag_dump_macros;
     194                 :             : 
     195                 :             : /* Nonzero means pass #include lines through to the output.  */
     196                 :             : 
     197                 :             : char flag_dump_includes;
     198                 :             : 
     199                 :             : /* Nonzero means process PCH files while preprocessing.  */
     200                 :             : 
     201                 :             : bool flag_pch_preprocess;
     202                 :             : 
     203                 :             : /* The file name to which we should write a precompiled header, or
     204                 :             :    NULL if no header will be written in this compile.  */
     205                 :             : 
     206                 :             : const char *pch_file;
     207                 :             : 
     208                 :             : /* Nonzero if an ISO standard was selected.  It rejects macros in the
     209                 :             :    user's namespace.  */
     210                 :             : int flag_iso;
     211                 :             : 
     212                 :             : /* C/ObjC language option variables.  */
     213                 :             : 
     214                 :             : 
     215                 :             : /* Nonzero means allow type mismatches in conditional expressions;
     216                 :             :    just make their values `void'.  */
     217                 :             : 
     218                 :             : int flag_cond_mismatch;
     219                 :             : 
     220                 :             : /* Nonzero means enable C89 Amendment 1 features.  */
     221                 :             : 
     222                 :             : int flag_isoc94;
     223                 :             : 
     224                 :             : /* Nonzero means use the ISO C99 (or later) dialect of C.  */
     225                 :             : 
     226                 :             : int flag_isoc99;
     227                 :             : 
     228                 :             : /* Nonzero means use the ISO C11 (or later) dialect of C.  */
     229                 :             : 
     230                 :             : int flag_isoc11;
     231                 :             : 
     232                 :             : /* Nonzero means use the ISO C23 (or later) dialect of C.  */
     233                 :             : 
     234                 :             : int flag_isoc23;
     235                 :             : 
     236                 :             : /* Nonzero means use the ISO C2Y (or later) dialect of C.  */
     237                 :             : 
     238                 :             : int flag_isoc2y;
     239                 :             : 
     240                 :             : /* Nonzero means that we have builtin functions, and main is an int.  */
     241                 :             : 
     242                 :             : int flag_hosted = 1;
     243                 :             : 
     244                 :             : 
     245                 :             : /* ObjC language option variables.  */
     246                 :             : 
     247                 :             : 
     248                 :             : /* Tells the compiler that this is a special run.  Do not perform any
     249                 :             :    compiling, instead we are to test some platform dependent features
     250                 :             :    and output a C header file with appropriate definitions.  */
     251                 :             : 
     252                 :             : int print_struct_values;
     253                 :             : 
     254                 :             : /* Tells the compiler what is the constant string class for ObjC.  */
     255                 :             : 
     256                 :             : const char *constant_string_class_name;
     257                 :             : 
     258                 :             : 
     259                 :             : /* C++ language option variables.  */
     260                 :             : 
     261                 :             : /* The reference version of the ABI for -Wabi.  */
     262                 :             : 
     263                 :             : int warn_abi_version = -1;
     264                 :             : 
     265                 :             : /* The C++ dialect being used.  Default set in c_common_post_options.  */
     266                 :             : 
     267                 :             : enum cxx_dialect cxx_dialect = cxx_unset;
     268                 :             : 
     269                 :             : /* Maximum template instantiation depth.  This limit exists to limit the
     270                 :             :    time it takes to notice excessively recursive template instantiations.
     271                 :             : 
     272                 :             :    The default is lower than the 1024 recommended by the C++0x standard
     273                 :             :    because G++ runs out of stack before 1024 with highly recursive template
     274                 :             :    argument deduction substitution (g++.dg/cpp0x/enum11.C).  */
     275                 :             : 
     276                 :             : int max_tinst_depth = 900;
     277                 :             : 
     278                 :             : /* The elements of `ridpointers' are identifier nodes for the reserved
     279                 :             :    type names and storage classes.  It is indexed by a RID_... value.  */
     280                 :             : tree *ridpointers;
     281                 :             : 
     282                 :             : tree (*make_fname_decl) (location_t, tree, int);
     283                 :             : 
     284                 :             : /* Nonzero means don't warn about problems that occur when the code is
     285                 :             :    executed.  */
     286                 :             : int c_inhibit_evaluation_warnings;
     287                 :             : 
     288                 :             : /* Whether we are building a boolean conversion inside
     289                 :             :    convert_for_assignment, or some other late binary operation.  If
     290                 :             :    build_binary_op is called for C (from code shared by C and C++) in
     291                 :             :    this case, then the operands have already been folded and the
     292                 :             :    result will not be folded again, so C_MAYBE_CONST_EXPR should not
     293                 :             :    be generated.  */
     294                 :             : bool in_late_binary_op;
     295                 :             : 
     296                 :             : /* Depending on which phase of processing we are in, we may need
     297                 :             :    to prefer input_location to libcpp's locations.  (Specifically,
     298                 :             :    after the C++ lexer is done lexing tokens, but prior to calling
     299                 :             :    cpp_finish (), we need to do so.  */
     300                 :             : bool override_libcpp_locations;
     301                 :             : 
     302                 :             : /* Information about how a function name is generated.  */
     303                 :             : struct fname_var_t
     304                 :             : {
     305                 :             :   tree *const decl;     /* pointer to the VAR_DECL.  */
     306                 :             :   const unsigned rid;   /* RID number for the identifier.  */
     307                 :             :   const int pretty;     /* How pretty is it? */
     308                 :             : };
     309                 :             : 
     310                 :             : /* The three ways of getting then name of the current function.  */
     311                 :             : 
     312                 :             : const struct fname_var_t fname_vars[] =
     313                 :             : {
     314                 :             :   /* C99 compliant __func__, must be first.  */
     315                 :             :   {&c99_function_name_decl_node, RID_C99_FUNCTION_NAME, 0},
     316                 :             :   /* GCC __FUNCTION__ compliant.  */
     317                 :             :   {&function_name_decl_node, RID_FUNCTION_NAME, 0},
     318                 :             :   /* GCC __PRETTY_FUNCTION__ compliant.  */
     319                 :             :   {&pretty_function_name_decl_node, RID_PRETTY_FUNCTION_NAME, 1},
     320                 :             :   {NULL, 0, 0},
     321                 :             : };
     322                 :             : 
     323                 :             : /* Flags to restrict availability of generic features that
     324                 :             :    are known to __has_{feature,extension}.  */
     325                 :             : 
     326                 :             : enum
     327                 :             : {
     328                 :             :   HF_FLAG_NONE = 0,
     329                 :             :   HF_FLAG_EXT = 1,      /* Available only as an extension.  */
     330                 :             :   HF_FLAG_SANITIZE = 2, /* Availability depends on sanitizer flags.  */
     331                 :             : };
     332                 :             : 
     333                 :             : /* Info for generic features which can be queried through
     334                 :             :    __has_{feature,extension}.  */
     335                 :             : 
     336                 :             : struct hf_feature_info
     337                 :             : {
     338                 :             :   const char *ident;
     339                 :             :   unsigned flags;
     340                 :             :   unsigned mask;
     341                 :             : };
     342                 :             : 
     343                 :             : /* Table of generic features which can be queried through
     344                 :             :    __has_{feature,extension}.  */
     345                 :             : 
     346                 :             : static constexpr hf_feature_info has_feature_table[] =
     347                 :             : {
     348                 :             :   { "address_sanitizer",          HF_FLAG_SANITIZE, SANITIZE_ADDRESS },
     349                 :             :   { "thread_sanitizer",                   HF_FLAG_SANITIZE, SANITIZE_THREAD },
     350                 :             :   { "leak_sanitizer",             HF_FLAG_SANITIZE, SANITIZE_LEAK },
     351                 :             :   { "hwaddress_sanitizer",        HF_FLAG_SANITIZE, SANITIZE_HWADDRESS },
     352                 :             :   { "undefined_behavior_sanitizer", HF_FLAG_SANITIZE, SANITIZE_UNDEFINED },
     353                 :             :   { "attribute_deprecated_with_message",  HF_FLAG_NONE, 0 },
     354                 :             :   { "attribute_unavailable_with_message", HF_FLAG_NONE, 0 },
     355                 :             :   { "enumerator_attributes",            HF_FLAG_NONE, 0 },
     356                 :             :   { "tls",                              HF_FLAG_NONE, 0 },
     357                 :             :   { "gnu_asm_goto_with_outputs",        HF_FLAG_EXT, 0 },
     358                 :             :   { "gnu_asm_goto_with_outputs_full",   HF_FLAG_EXT, 0 }
     359                 :             : };
     360                 :             : 
     361                 :             : /* Global visibility options.  */
     362                 :             : struct visibility_flags visibility_options;
     363                 :             : 
     364                 :             : static tree check_case_value (location_t, tree);
     365                 :             : 
     366                 :             : 
     367                 :             : static void check_nonnull_arg (void *, tree, unsigned HOST_WIDE_INT);
     368                 :             : static bool nonnull_check_p (tree, unsigned HOST_WIDE_INT);
     369                 :             : 
     370                 :             : /* Reserved words.  The third field is a mask: keywords are disabled
     371                 :             :    if they match the mask.
     372                 :             : 
     373                 :             :    Masks for languages:
     374                 :             :    C --std=c89: D_C99 | D_C23 | D_CXXONLY | D_OBJC | D_CXX_OBJC
     375                 :             :    C --std=c99: D_C23 | D_CXXONLY | D_OBJC
     376                 :             :    C --std=c17: D_C23 | D_CXXONLY | D_OBJC
     377                 :             :    C --std=c23: D_CXXONLY | D_OBJC
     378                 :             :    ObjC is like C except that D_OBJC and D_CXX_OBJC are not set
     379                 :             :    C++ --std=c++98: D_CONLY | D_CXX11 | D_CXX20 | D_OBJC
     380                 :             :    C++ --std=c++11: D_CONLY | D_CXX20 | D_OBJC
     381                 :             :    C++ --std=c++20: D_CONLY | D_OBJC
     382                 :             :    ObjC++ is like C++ except that D_OBJC is not set
     383                 :             : 
     384                 :             :    If -fno-asm is used, D_ASM is added to the mask.  If
     385                 :             :    -fno-gnu-keywords is used, D_EXT is added.  If -fno-asm and C in
     386                 :             :    C89 mode, D_EXT89 is added for both -fno-asm and -fno-gnu-keywords.
     387                 :             :    In C with -Wc++-compat, we warn if D_CXXWARN is set.
     388                 :             : 
     389                 :             :    Note the complication of the D_CXX_OBJC keywords.  These are
     390                 :             :    reserved words such as 'class'.  In C++, 'class' is a reserved
     391                 :             :    word.  In Objective-C++ it is too.  In Objective-C, it is a
     392                 :             :    reserved word too, but only if it follows an '@' sign.
     393                 :             : */
     394                 :             : const struct c_common_resword c_common_reswords[] =
     395                 :             : {
     396                 :             :   { "_Alignas",               RID_ALIGNAS,   D_CONLY },
     397                 :             :   { "_Alignof",               RID_ALIGNOF,   D_CONLY },
     398                 :             :   { "_Countof",               RID_COUNTOF,   D_CONLY },
     399                 :             :   { "_Atomic",                RID_ATOMIC,    D_CONLY },
     400                 :             :   { "_BitInt",                RID_BITINT,    D_CONLY },
     401                 :             :   { "_Bool",          RID_BOOL,      D_CONLY },
     402                 :             :   { "_Complex",               RID_COMPLEX,    0 },
     403                 :             :   { "_Imaginary",     RID_IMAGINARY, D_CONLY },
     404                 :             :   { "_Float16",         RID_FLOAT16,    0 },
     405                 :             :   { "_Float32",         RID_FLOAT32,    0 },
     406                 :             :   { "_Float64",         RID_FLOAT64,    0 },
     407                 :             :   { "_Float128",        RID_FLOAT128,   0 },
     408                 :             :   { "_Float32x",        RID_FLOAT32X,   0 },
     409                 :             :   { "_Float64x",        RID_FLOAT64X,   0 },
     410                 :             :   { "_Float128x",       RID_FLOAT128X,  0 },
     411                 :             :   { "_Decimal32",       RID_DFLOAT32,  D_CONLY },
     412                 :             :   { "_Decimal64",       RID_DFLOAT64,  D_CONLY },
     413                 :             :   { "_Decimal128",      RID_DFLOAT128, D_CONLY },
     414                 :             :   { "_Decimal64x",      RID_DFLOAT64X, D_CONLY },
     415                 :             :   { "_Fract",           RID_FRACT,     D_CONLY | D_EXT },
     416                 :             :   { "_Accum",           RID_ACCUM,     D_CONLY | D_EXT },
     417                 :             :   { "_Sat",             RID_SAT,       D_CONLY | D_EXT },
     418                 :             :   { "_Static_assert",   RID_STATIC_ASSERT, D_CONLY },
     419                 :             :   { "_Noreturn",        RID_NORETURN,  D_CONLY },
     420                 :             :   { "_Generic",         RID_GENERIC,   D_CONLY },
     421                 :             :   { "_Thread_local",    RID_THREAD,    D_CONLY },
     422                 :             :   { "__FUNCTION__",   RID_FUNCTION_NAME, 0 },
     423                 :             :   { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
     424                 :             :   { "__alignof",      RID_ALIGNOF,    0 },
     425                 :             :   { "__alignof__",    RID_ALIGNOF,    0 },
     426                 :             :   { "__asm",          RID_ASM,        0 },
     427                 :             :   { "__asm__",                RID_ASM,        0 },
     428                 :             :   { "__attribute",    RID_ATTRIBUTE,  0 },
     429                 :             :   { "__attribute__",  RID_ATTRIBUTE,  0 },
     430                 :             :   { "__auto_type",    RID_AUTO_TYPE,  D_CONLY },
     431                 :             :   { "__builtin_addressof", RID_ADDRESSOF, D_CXXONLY },
     432                 :             :   { "__builtin_assoc_barrier", RID_BUILTIN_ASSOC_BARRIER, 0 },
     433                 :             :   { "__builtin_bit_cast", RID_BUILTIN_BIT_CAST, D_CXXONLY },
     434                 :             :   { "__builtin_call_with_static_chain",
     435                 :             :     RID_BUILTIN_CALL_WITH_STATIC_CHAIN, D_CONLY },
     436                 :             :   { "__builtin_choose_expr", RID_CHOOSE_EXPR, D_CONLY },
     437                 :             :   { "__builtin_complex", RID_BUILTIN_COMPLEX, D_CONLY },
     438                 :             :   { "__builtin_convertvector", RID_BUILTIN_CONVERTVECTOR, 0 },
     439                 :             :   { "__builtin_counted_by_ref", RID_BUILTIN_COUNTED_BY_REF, D_CONLY },
     440                 :             :   { "__builtin_has_attribute", RID_BUILTIN_HAS_ATTRIBUTE, 0 },
     441                 :             :   { "__builtin_launder", RID_BUILTIN_LAUNDER, D_CXXONLY },
     442                 :             :   { "__builtin_operator_new", RID_BUILTIN_OPERATOR_NEW, D_CXXONLY },
     443                 :             :   { "__builtin_operator_delete", RID_BUILTIN_OPERATOR_DELETE, D_CXXONLY },
     444                 :             :   { "__builtin_shuffle", RID_BUILTIN_SHUFFLE, 0 },
     445                 :             :   { "__builtin_shufflevector", RID_BUILTIN_SHUFFLEVECTOR, 0 },
     446                 :             :   { "__builtin_stdc_bit_ceil", RID_BUILTIN_STDC, D_CONLY },
     447                 :             :   { "__builtin_stdc_bit_floor", RID_BUILTIN_STDC, D_CONLY },
     448                 :             :   { "__builtin_stdc_bit_width", RID_BUILTIN_STDC, D_CONLY },
     449                 :             :   { "__builtin_stdc_count_ones", RID_BUILTIN_STDC, D_CONLY },
     450                 :             :   { "__builtin_stdc_count_zeros", RID_BUILTIN_STDC, D_CONLY },
     451                 :             :   { "__builtin_stdc_first_leading_one", RID_BUILTIN_STDC, D_CONLY },
     452                 :             :   { "__builtin_stdc_first_leading_zero", RID_BUILTIN_STDC, D_CONLY },
     453                 :             :   { "__builtin_stdc_first_trailing_one", RID_BUILTIN_STDC, D_CONLY },
     454                 :             :   { "__builtin_stdc_first_trailing_zero", RID_BUILTIN_STDC, D_CONLY },
     455                 :             :   { "__builtin_stdc_has_single_bit", RID_BUILTIN_STDC, D_CONLY },
     456                 :             :   { "__builtin_stdc_leading_ones", RID_BUILTIN_STDC, D_CONLY },
     457                 :             :   { "__builtin_stdc_leading_zeros", RID_BUILTIN_STDC, D_CONLY },
     458                 :             :   { "__builtin_stdc_rotate_left", RID_BUILTIN_STDC, D_CONLY },
     459                 :             :   { "__builtin_stdc_rotate_right", RID_BUILTIN_STDC, D_CONLY },
     460                 :             :   { "__builtin_stdc_trailing_ones", RID_BUILTIN_STDC, D_CONLY },
     461                 :             :   { "__builtin_stdc_trailing_zeros", RID_BUILTIN_STDC, D_CONLY },
     462                 :             :   { "__builtin_tgmath", RID_BUILTIN_TGMATH, D_CONLY },
     463                 :             :   { "__builtin_offsetof", RID_OFFSETOF, 0 },
     464                 :             :   { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P, D_CONLY },
     465                 :             :   { "__builtin_c23_va_start", RID_C23_VA_START,       D_C23 },
     466                 :             :   { "__builtin_va_arg",       RID_VA_ARG,     0 },
     467                 :             :   { "__complex",      RID_COMPLEX,    0 },
     468                 :             :   { "__complex__",    RID_COMPLEX,    0 },
     469                 :             :   { "__const",                RID_CONST,      0 },
     470                 :             :   { "__const__",      RID_CONST,      0 },
     471                 :             :   { "__constinit",    RID_CONSTINIT,  D_CXXONLY },
     472                 :             :   { "__decltype",       RID_DECLTYPE,   D_CXXONLY },
     473                 :             :   { "__extension__",  RID_EXTENSION,  0 },
     474                 :             :   { "__func__",               RID_C99_FUNCTION_NAME, 0 },
     475                 :             :   { "__imag",         RID_IMAGPART,   0 },
     476                 :             :   { "__imag__",               RID_IMAGPART,   0 },
     477                 :             :   { "__inline",               RID_INLINE,     0 },
     478                 :             :   { "__inline__",     RID_INLINE,     0 },
     479                 :             :   { "__label__",      RID_LABEL,      0 },
     480                 :             :   { "__null",         RID_NULL,       0 },
     481                 :             :   { "__real",         RID_REALPART,   0 },
     482                 :             :   { "__real__",               RID_REALPART,   0 },
     483                 :             :   { "__restrict",     RID_RESTRICT,   0 },
     484                 :             :   { "__restrict__",   RID_RESTRICT,   0 },
     485                 :             :   { "__signed",               RID_SIGNED,     0 },
     486                 :             :   { "__signed__",     RID_SIGNED,     0 },
     487                 :             :   { "__thread",               RID_THREAD,     0 },
     488                 :             :   { "__transaction_atomic", RID_TRANSACTION_ATOMIC, 0 },
     489                 :             :   { "__transaction_relaxed", RID_TRANSACTION_RELAXED, 0 },
     490                 :             :   { "__transaction_cancel", RID_TRANSACTION_CANCEL, 0 },
     491                 :             :   { "__typeof",               RID_TYPEOF,     0 },
     492                 :             :   { "__typeof__",     RID_TYPEOF,     0 },
     493                 :             :   { "__typeof_unqual",        RID_TYPEOF_UNQUAL, D_CONLY },
     494                 :             :   { "__typeof_unqual__", RID_TYPEOF_UNQUAL, D_CONLY },
     495                 :             :   { "__volatile",     RID_VOLATILE,   0 },
     496                 :             :   { "__volatile__",   RID_VOLATILE,   0 },
     497                 :             :   { "__GIMPLE",               RID_GIMPLE,     D_CONLY },
     498                 :             :   { "__PHI",          RID_PHI,        D_CONLY },
     499                 :             :   { "__RTL",          RID_RTL,        D_CONLY },
     500                 :             :   { "alignas",                RID_ALIGNAS,    D_C23 | D_CXX11 | D_CXXWARN },
     501                 :             :   { "alignof",                RID_ALIGNOF,    D_C23 | D_CXX11 | D_CXXWARN },
     502                 :             :   { "asm",            RID_ASM,        D_ASM },
     503                 :             :   { "auto",           RID_AUTO,       0 },
     504                 :             :   { "bool",           RID_BOOL,       D_C23 | D_CXXWARN },
     505                 :             :   { "break",          RID_BREAK,      0 },
     506                 :             :   { "case",           RID_CASE,       0 },
     507                 :             :   { "catch",          RID_CATCH,      D_CXX_OBJC | D_CXXWARN },
     508                 :             :   { "char",           RID_CHAR,       0 },
     509                 :             :   { "char8_t",                RID_CHAR8,      D_CXX_CHAR8_T_FLAGS | D_CXXWARN },
     510                 :             :   { "char16_t",               RID_CHAR16,     D_CXXONLY | D_CXX11 | D_CXXWARN },
     511                 :             :   { "char32_t",               RID_CHAR32,     D_CXXONLY | D_CXX11 | D_CXXWARN },
     512                 :             :   { "class",          RID_CLASS,      D_CXX_OBJC | D_CXXWARN },
     513                 :             :   { "const",          RID_CONST,      0 },
     514                 :             :   { "consteval",      RID_CONSTEVAL,  D_CXXONLY | D_CXX20 | D_CXXWARN },
     515                 :             :   { "constexpr",      RID_CONSTEXPR,  D_C23 | D_CXX11 | D_CXXWARN },
     516                 :             :   { "constinit",      RID_CONSTINIT,  D_CXXONLY | D_CXX20 | D_CXXWARN },
     517                 :             :   { "const_cast",     RID_CONSTCAST,  D_CXXONLY | D_CXXWARN },
     518                 :             :   { "continue",               RID_CONTINUE,   0 },
     519                 :             :   { "decltype",         RID_DECLTYPE,   D_CXXONLY | D_CXX11 | D_CXXWARN },
     520                 :             :   { "default",                RID_DEFAULT,    0 },
     521                 :             :   { "delete",         RID_DELETE,     D_CXXONLY | D_CXXWARN },
     522                 :             :   { "do",             RID_DO,         0 },
     523                 :             :   { "double",         RID_DOUBLE,     0 },
     524                 :             :   { "dynamic_cast",   RID_DYNCAST,    D_CXXONLY | D_CXXWARN },
     525                 :             :   { "else",           RID_ELSE,       0 },
     526                 :             :   { "enum",           RID_ENUM,       0 },
     527                 :             :   { "explicit",               RID_EXPLICIT,   D_CXXONLY | D_CXXWARN },
     528                 :             :   { "export",         RID_EXPORT,     D_CXXONLY | D_CXXWARN },
     529                 :             :   { "extern",         RID_EXTERN,     0 },
     530                 :             :   { "false",          RID_FALSE,      D_C23 | D_CXXWARN },
     531                 :             :   { "float",          RID_FLOAT,      0 },
     532                 :             :   { "for",            RID_FOR,        0 },
     533                 :             :   { "friend",         RID_FRIEND,     D_CXXONLY | D_CXXWARN },
     534                 :             :   { "goto",           RID_GOTO,       0 },
     535                 :             :   { "if",             RID_IF,         0 },
     536                 :             :   { "inline",         RID_INLINE,     D_EXT89 },
     537                 :             :   { "int",            RID_INT,        0 },
     538                 :             :   { "long",           RID_LONG,       0 },
     539                 :             :   { "mutable",                RID_MUTABLE,    D_CXXONLY | D_CXXWARN },
     540                 :             :   { "namespace",      RID_NAMESPACE,  D_CXXONLY | D_CXXWARN },
     541                 :             :   { "new",            RID_NEW,        D_CXXONLY | D_CXXWARN },
     542                 :             :   { "noexcept",               RID_NOEXCEPT,   D_CXXONLY | D_CXX11 | D_CXXWARN },
     543                 :             :   { "nullptr",                RID_NULLPTR,    D_C23 | D_CXX11 | D_CXXWARN },
     544                 :             :   { "operator",               RID_OPERATOR,   D_CXXONLY | D_CXXWARN },
     545                 :             :   { "private",                RID_PRIVATE,    D_CXX_OBJC | D_CXXWARN },
     546                 :             :   { "protected",      RID_PROTECTED,  D_CXX_OBJC | D_CXXWARN },
     547                 :             :   { "public",         RID_PUBLIC,     D_CXX_OBJC | D_CXXWARN },
     548                 :             :   { "register",               RID_REGISTER,   0 },
     549                 :             :   { "reinterpret_cast",       RID_REINTCAST,  D_CXXONLY | D_CXXWARN },
     550                 :             :   { "restrict",               RID_RESTRICT,   D_CONLY | D_C99 },
     551                 :             :   { "return",         RID_RETURN,     0 },
     552                 :             :   { "short",          RID_SHORT,      0 },
     553                 :             :   { "signed",         RID_SIGNED,     0 },
     554                 :             :   { "sizeof",         RID_SIZEOF,     0 },
     555                 :             :   { "static",         RID_STATIC,     0 },
     556                 :             :   { "static_assert",    RID_STATIC_ASSERT, D_C23 | D_CXX11 | D_CXXWARN },
     557                 :             :   { "static_cast",    RID_STATCAST,   D_CXXONLY | D_CXXWARN },
     558                 :             :   { "struct",         RID_STRUCT,     0 },
     559                 :             :   { "switch",         RID_SWITCH,     0 },
     560                 :             :   { "template",               RID_TEMPLATE,   D_CXXONLY | D_CXXWARN },
     561                 :             :   { "this",           RID_THIS,       D_CXXONLY | D_CXXWARN },
     562                 :             :   { "thread_local",   RID_THREAD,     D_C23 | D_CXX11 | D_CXXWARN },
     563                 :             :   { "throw",          RID_THROW,      D_CXX_OBJC | D_CXXWARN },
     564                 :             :   { "true",           RID_TRUE,       D_C23 | D_CXXWARN },
     565                 :             :   { "try",            RID_TRY,        D_CXX_OBJC | D_CXXWARN },
     566                 :             :   { "typedef",                RID_TYPEDEF,    0 },
     567                 :             :   { "typename",               RID_TYPENAME,   D_CXXONLY | D_CXXWARN },
     568                 :             :   { "typeid",         RID_TYPEID,     D_CXXONLY | D_CXXWARN },
     569                 :             :   { "typeof",         RID_TYPEOF,     D_EXT11 },
     570                 :             :   { "typeof_unqual",  RID_TYPEOF_UNQUAL,      D_CONLY | D_C23 },
     571                 :             :   { "union",          RID_UNION,      0 },
     572                 :             :   { "unsigned",               RID_UNSIGNED,   0 },
     573                 :             :   { "using",          RID_USING,      D_CXXONLY | D_CXXWARN },
     574                 :             :   { "virtual",                RID_VIRTUAL,    D_CXXONLY | D_CXXWARN },
     575                 :             :   { "void",           RID_VOID,       0 },
     576                 :             :   { "volatile",               RID_VOLATILE,   0 },
     577                 :             :   { "wchar_t",                RID_WCHAR,      D_CXXONLY },
     578                 :             :   { "while",          RID_WHILE,      0 },
     579                 :             : 
     580                 :             :   /* C++ transactional memory.  */
     581                 :             :   { "synchronized",   RID_SYNCHRONIZED, D_CXX_OBJC | D_TRANSMEM },
     582                 :             :   { "atomic_noexcept",        RID_ATOMIC_NOEXCEPT, D_CXXONLY | D_TRANSMEM },
     583                 :             :   { "atomic_cancel",  RID_ATOMIC_CANCEL, D_CXXONLY | D_TRANSMEM },
     584                 :             :   { "atomic_commit",  RID_TRANSACTION_ATOMIC, D_CXXONLY | D_TRANSMEM },
     585                 :             : 
     586                 :             :   /* Concepts-related keywords */
     587                 :             :   { "concept",                RID_CONCEPT,    D_CXX_CONCEPTS_FLAGS | D_CXXWARN },
     588                 :             :   { "requires",       RID_REQUIRES,   D_CXX_CONCEPTS_FLAGS | D_CXXWARN },
     589                 :             : 
     590                 :             :   /* Modules-related keywords, these are internal unspellable tokens,
     591                 :             :      created by the preprocessor.  */
     592                 :             :   { "module ",                RID__MODULE,    D_CXX_MODULES_FLAGS | D_CXXWARN },
     593                 :             :   { "import ",                RID__IMPORT,    D_CXX_MODULES_FLAGS | D_CXXWARN },
     594                 :             :   { "export ",                RID__EXPORT,    D_CXX_MODULES_FLAGS | D_CXXWARN },
     595                 :             : 
     596                 :             :   /* Coroutines-related keywords */
     597                 :             :   { "co_await",               RID_CO_AWAIT,   D_CXX_COROUTINES_FLAGS | D_CXXWARN },
     598                 :             :   { "co_yield",               RID_CO_YIELD,   D_CXX_COROUTINES_FLAGS | D_CXXWARN },
     599                 :             :   { "co_return",      RID_CO_RETURN,  D_CXX_COROUTINES_FLAGS | D_CXXWARN },
     600                 :             : 
     601                 :             :   /* These Objective-C keywords are recognized only immediately after
     602                 :             :      an '@'.  */
     603                 :             :   { "compatibility_alias", RID_AT_ALIAS,      D_OBJC },
     604                 :             :   { "defs",           RID_AT_DEFS,            D_OBJC },
     605                 :             :   { "encode",         RID_AT_ENCODE,          D_OBJC },
     606                 :             :   { "end",            RID_AT_END,             D_OBJC },
     607                 :             :   { "implementation", RID_AT_IMPLEMENTATION,  D_OBJC },
     608                 :             :   { "interface",      RID_AT_INTERFACE,       D_OBJC },
     609                 :             :   { "protocol",               RID_AT_PROTOCOL,        D_OBJC },
     610                 :             :   { "selector",               RID_AT_SELECTOR,        D_OBJC },
     611                 :             :   { "finally",                RID_AT_FINALLY,         D_OBJC },
     612                 :             :   { "optional",               RID_AT_OPTIONAL,        D_OBJC },
     613                 :             :   { "required",               RID_AT_REQUIRED,        D_OBJC },
     614                 :             :   { "property",               RID_AT_PROPERTY,        D_OBJC },
     615                 :             :   { "package",                RID_AT_PACKAGE,         D_OBJC },
     616                 :             :   { "synthesize",     RID_AT_SYNTHESIZE,      D_OBJC },
     617                 :             :   { "dynamic",                RID_AT_DYNAMIC,         D_OBJC },
     618                 :             :   /* These are recognized only in protocol-qualifier context
     619                 :             :      (see above) */
     620                 :             :   { "bycopy",         RID_BYCOPY,             D_OBJC },
     621                 :             :   { "byref",          RID_BYREF,              D_OBJC },
     622                 :             :   { "in",             RID_IN,                 D_OBJC },
     623                 :             :   { "inout",          RID_INOUT,              D_OBJC },
     624                 :             :   { "oneway",         RID_ONEWAY,             D_OBJC },
     625                 :             :   { "out",            RID_OUT,                D_OBJC },
     626                 :             :   /* These are recognized inside a property attribute list */
     627                 :             :   { "assign",         RID_ASSIGN,             D_OBJC },
     628                 :             :   { "atomic",         RID_PROPATOMIC,         D_OBJC },
     629                 :             :   { "copy",           RID_COPY,               D_OBJC },
     630                 :             :   { "getter",         RID_GETTER,             D_OBJC },
     631                 :             :   { "nonatomic",      RID_NONATOMIC,          D_OBJC },
     632                 :             :   { "readonly",               RID_READONLY,           D_OBJC },
     633                 :             :   { "readwrite",      RID_READWRITE,          D_OBJC },
     634                 :             :   { "retain",         RID_RETAIN,             D_OBJC },
     635                 :             :   { "setter",         RID_SETTER,             D_OBJC },
     636                 :             :   /* These are Objective C implementation of nullability, accepted only in
     637                 :             :      specific contexts.  */
     638                 :             :   { "null_unspecified", RID_NULL_UNSPECIFIED, D_OBJC },
     639                 :             :   { "nullable",               RID_NULLABLE,           D_OBJC },
     640                 :             :   { "nonnull",                RID_NONNULL,            D_OBJC },
     641                 :             :   { "null_resettable",        RID_NULL_RESETTABLE,    D_OBJC },
     642                 :             : };
     643                 :             : 
     644                 :             : const unsigned int num_c_common_reswords = ARRAY_SIZE (c_common_reswords);
     645                 :             : 
     646                 :             : /* Return identifier for address space AS.  */
     647                 :             : 
     648                 :             : const char *
     649                 :           3 : c_addr_space_name (addr_space_t as)
     650                 :             : {
     651                 :           3 :   int rid = RID_FIRST_ADDR_SPACE + as;
     652                 :           3 :   gcc_assert (ridpointers [rid]);
     653                 :           3 :   return IDENTIFIER_POINTER (ridpointers [rid]);
     654                 :             : }
     655                 :             : 
     656                 :             : /* Push current bindings for the function name VAR_DECLS.  */
     657                 :             : 
     658                 :             : void
     659                 :   180372122 : start_fname_decls (void)
     660                 :             : {
     661                 :   180372122 :   unsigned ix;
     662                 :   180372122 :   tree saved = NULL_TREE;
     663                 :             : 
     664                 :   721488488 :   for (ix = 0; fname_vars[ix].decl; ix++)
     665                 :             :     {
     666                 :   541116366 :       tree decl = *fname_vars[ix].decl;
     667                 :             : 
     668                 :   541116366 :       if (decl)
     669                 :             :         {
     670                 :       50647 :           saved = tree_cons (decl, build_int_cst (integer_type_node, ix),
     671                 :             :                              saved);
     672                 :       50647 :           *fname_vars[ix].decl = NULL_TREE;
     673                 :             :         }
     674                 :             :     }
     675                 :   180372122 :   if (saved || saved_function_name_decls)
     676                 :             :     /* Normally they'll have been NULL, so only push if we've got a
     677                 :             :        stack, or they are non-NULL.  */
     678                 :       69520 :     saved_function_name_decls = tree_cons (saved, NULL_TREE,
     679                 :             :                                            saved_function_name_decls);
     680                 :   180372122 : }
     681                 :             : 
     682                 :             : /* Finish up the current bindings, adding them into the current function's
     683                 :             :    statement tree.  This must be done _before_ finish_stmt_tree is called.
     684                 :             :    If there is no current function, we must be at file scope and no statements
     685                 :             :    are involved. Pop the previous bindings.  */
     686                 :             : 
     687                 :             : void
     688                 :   180260473 : finish_fname_decls (void)
     689                 :             : {
     690                 :   180260473 :   unsigned ix;
     691                 :   180260473 :   tree stmts = NULL_TREE;
     692                 :   180260473 :   tree stack = saved_function_name_decls;
     693                 :             : 
     694                 :   180524505 :   for (; stack && TREE_VALUE (stack); stack = TREE_CHAIN (stack))
     695                 :       97256 :     append_to_statement_list (TREE_VALUE (stack), &stmts);
     696                 :             : 
     697                 :   180260473 :   if (stmts)
     698                 :             :     {
     699                 :       97151 :       tree *bodyp = &DECL_SAVED_TREE (current_function_decl);
     700                 :             : 
     701                 :       97151 :       if (TREE_CODE (*bodyp) == BIND_EXPR)
     702                 :       92712 :         bodyp = &BIND_EXPR_BODY (*bodyp);
     703                 :             : 
     704                 :       97151 :       append_to_statement_list_force (*bodyp, &stmts);
     705                 :       97151 :       *bodyp = stmts;
     706                 :             :     }
     707                 :             : 
     708                 :   721041892 :   for (ix = 0; fname_vars[ix].decl; ix++)
     709                 :   540781419 :     *fname_vars[ix].decl = NULL_TREE;
     710                 :             : 
     711                 :   180260473 :   if (stack)
     712                 :             :     {
     713                 :             :       /* We had saved values, restore them.  */
     714                 :       69520 :       tree saved;
     715                 :             : 
     716                 :      120167 :       for (saved = TREE_PURPOSE (stack); saved; saved = TREE_CHAIN (saved))
     717                 :             :         {
     718                 :       50647 :           tree decl = TREE_PURPOSE (saved);
     719                 :       50647 :           unsigned ix = TREE_INT_CST_LOW (TREE_VALUE (saved));
     720                 :             : 
     721                 :       50647 :           *fname_vars[ix].decl = decl;
     722                 :             :         }
     723                 :       69520 :       stack = TREE_CHAIN (stack);
     724                 :             :     }
     725                 :   180260473 :   saved_function_name_decls = stack;
     726                 :   180260473 : }
     727                 :             : 
     728                 :             : /* Return the text name of the current function, suitably prettified
     729                 :             :    by PRETTY_P.  Return string must be freed by caller.  */
     730                 :             : 
     731                 :             : const char *
     732                 :        3479 : fname_as_string (int pretty_p)
     733                 :             : {
     734                 :        3479 :   const char *name = "top level";
     735                 :        3479 :   char *namep;
     736                 :        3479 :   int vrb = 2, len;
     737                 :        3479 :   cpp_string cstr = { 0, 0 }, strname;
     738                 :             : 
     739                 :        3479 :   if (!pretty_p)
     740                 :             :     {
     741                 :        1880 :       name = "";
     742                 :        1880 :       vrb = 0;
     743                 :             :     }
     744                 :             : 
     745                 :        3479 :   if (current_function_decl)
     746                 :        3472 :     name = lang_hooks.decl_printable_name (current_function_decl, vrb);
     747                 :             : 
     748                 :        3479 :   len = strlen (name) + 3; /* Two for '"'s.  One for NULL.  */
     749                 :             : 
     750                 :        3479 :   namep = XNEWVEC (char, len);
     751                 :        3479 :   snprintf (namep, len, "\"%s\"", name);
     752                 :        3479 :   strname.text = (unsigned char *) namep;
     753                 :        3479 :   strname.len = len - 1;
     754                 :             : 
     755                 :        3479 :   if (cpp_interpret_string (parse_in, &strname, 1, &cstr, CPP_STRING))
     756                 :             :     {
     757                 :        3479 :       XDELETEVEC (namep);
     758                 :        3479 :       return (const char *) cstr.text;
     759                 :             :     }
     760                 :             : 
     761                 :             :   return namep;
     762                 :             : }
     763                 :             : 
     764                 :             : /* Return the VAR_DECL for a const char array naming the current
     765                 :             :    function. If the VAR_DECL has not yet been created, create it
     766                 :             :    now. RID indicates how it should be formatted and IDENTIFIER_NODE
     767                 :             :    ID is its name (unfortunately C and C++ hold the RID values of
     768                 :             :    keywords in different places, so we can't derive RID from ID in
     769                 :             :    this language independent code. LOC is the location of the
     770                 :             :    function.  */
     771                 :             : 
     772                 :             : tree
     773                 :      196108 : fname_decl (location_t loc, unsigned int rid, tree id)
     774                 :             : {
     775                 :      196108 :   unsigned ix;
     776                 :      196108 :   tree decl = NULL_TREE;
     777                 :             : 
     778                 :      567780 :   for (ix = 0; fname_vars[ix].decl; ix++)
     779                 :      567780 :     if (fname_vars[ix].rid == rid)
     780                 :             :       break;
     781                 :             : 
     782                 :      196108 :   decl = *fname_vars[ix].decl;
     783                 :      196108 :   if (!decl)
     784                 :             :     {
     785                 :             :       /* If a tree is built here, it would normally have the lineno of
     786                 :             :          the current statement.  Later this tree will be moved to the
     787                 :             :          beginning of the function and this line number will be wrong.
     788                 :             :          To avoid this problem set the lineno to 0 here; that prevents
     789                 :             :          it from appearing in the RTL.  */
     790                 :       97256 :       tree stmts;
     791                 :       97256 :       location_t saved_location = input_location;
     792                 :       97256 :       input_location = UNKNOWN_LOCATION;
     793                 :             : 
     794                 :       97256 :       stmts = push_stmt_list ();
     795                 :       97256 :       decl = (*make_fname_decl) (loc, id, fname_vars[ix].pretty);
     796                 :       97256 :       stmts = pop_stmt_list (stmts);
     797                 :       97256 :       if (!IS_EMPTY_STMT (stmts))
     798                 :       97256 :         saved_function_name_decls
     799                 :       97256 :           = tree_cons (decl, stmts, saved_function_name_decls);
     800                 :       97256 :       *fname_vars[ix].decl = decl;
     801                 :       97256 :       input_location = saved_location;
     802                 :             :     }
     803                 :      196108 :   if (!ix && !current_function_decl)
     804                 :           4 :     pedwarn (loc, 0, "%qD is not defined outside of function scope", decl);
     805                 :             : 
     806                 :      196108 :   return decl;
     807                 :             : }
     808                 :             : 
     809                 :             : /* Given a STRING_CST, give it a suitable array-of-chars data type.  */
     810                 :             : 
     811                 :             : tree
     812                 :    25873981 : fix_string_type (tree value)
     813                 :             : {
     814                 :    25873981 :   int length = TREE_STRING_LENGTH (value);
     815                 :    25873981 :   int nchars, charsz;
     816                 :    25873981 :   tree e_type, i_type, a_type;
     817                 :             : 
     818                 :             :   /* Compute the number of elements, for the array type.  */
     819                 :    25873981 :   if (TREE_TYPE (value) == char_array_type_node || !TREE_TYPE (value))
     820                 :             :     {
     821                 :    25613139 :       charsz = 1;
     822                 :    25613139 :       e_type = char_type_node;
     823                 :             :     }
     824                 :      260842 :   else if (flag_char8_t && TREE_TYPE (value) == char8_array_type_node)
     825                 :             :     {
     826                 :         370 :       charsz = TYPE_PRECISION (char8_type_node) / BITS_PER_UNIT;
     827                 :         370 :       e_type = char8_type_node;
     828                 :             :     }
     829                 :      260472 :   else if (TREE_TYPE (value) == char16_array_type_node)
     830                 :             :     {
     831                 :         942 :       charsz = TYPE_PRECISION (char16_type_node) / BITS_PER_UNIT;
     832                 :         942 :       e_type = char16_type_node;
     833                 :             :     }
     834                 :      259530 :   else if (TREE_TYPE (value) == char32_array_type_node)
     835                 :             :     {
     836                 :        3034 :       charsz = TYPE_PRECISION (char32_type_node) / BITS_PER_UNIT;
     837                 :        3034 :       e_type = char32_type_node;
     838                 :             :     }
     839                 :             :   else
     840                 :             :     {
     841                 :      256496 :       charsz = TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT;
     842                 :      256496 :       e_type = wchar_type_node;
     843                 :             :     }
     844                 :             : 
     845                 :             :   /* This matters only for targets where ssizetype has smaller precision
     846                 :             :      than 32 bits.  */
     847                 :    25873981 :   if (wi::lts_p (wi::to_wide (TYPE_MAX_VALUE (ssizetype)), length))
     848                 :             :     {
     849                 :           0 :       error ("size of string literal is too large");
     850                 :           0 :       length = tree_to_shwi (TYPE_MAX_VALUE (ssizetype)) / charsz * charsz;
     851                 :           0 :       char *str = CONST_CAST (char *, TREE_STRING_POINTER (value));
     852                 :           0 :       memset (str + length, '\0',
     853                 :           0 :               MIN (TREE_STRING_LENGTH (value) - length, charsz));
     854                 :           0 :       TREE_STRING_LENGTH (value) = length;
     855                 :             :     }
     856                 :    25873981 :   nchars = length / charsz;
     857                 :             : 
     858                 :             :   /* C89 2.2.4.1, C99 5.2.4.1 (Translation limits).  The analogous
     859                 :             :      limit in C++98 Annex B is very large (65536) and is not normative,
     860                 :             :      so we do not diagnose it (warn_overlength_strings is forced off
     861                 :             :      in c_common_post_options).  */
     862                 :    25873981 :   if (warn_overlength_strings)
     863                 :             :     {
     864                 :       14933 :       const int nchars_max = flag_isoc99 ? 4095 : 509;
     865                 :       14933 :       const int relevant_std = flag_isoc99 ? 99 : 90;
     866                 :       14933 :       if (nchars - 1 > nchars_max)
     867                 :             :         /* Translators: The %d after 'ISO C' will be 90 or 99.  Do not
     868                 :             :            separate the %d from the 'C'.  'ISO' should not be
     869                 :             :            translated, but it may be moved after 'C%d' in languages
     870                 :             :            where modifiers follow nouns.  */
     871                 :           5 :         pedwarn (input_location, OPT_Woverlength_strings,
     872                 :             :                  "string length %qd is greater than the length %qd "
     873                 :             :                  "ISO C%d compilers are required to support",
     874                 :             :                  nchars - 1, nchars_max, relevant_std);
     875                 :             :     }
     876                 :             : 
     877                 :             :   /* Create the array type for the string constant.  The ISO C++
     878                 :             :      standard says that a string literal has type `const char[N]' or
     879                 :             :      `const wchar_t[N]'.  We use the same logic when invoked as a C
     880                 :             :      front-end with -Wwrite-strings.
     881                 :             :      ??? We should change the type of an expression depending on the
     882                 :             :      state of a warning flag.  We should just be warning -- see how
     883                 :             :      this is handled in the C++ front-end for the deprecated implicit
     884                 :             :      conversion from string literals to `char*' or `wchar_t*'.
     885                 :             : 
     886                 :             :      The C++ front end relies on TYPE_MAIN_VARIANT of a cv-qualified
     887                 :             :      array type being the unqualified version of that type.
     888                 :             :      Therefore, if we are constructing an array of const char, we must
     889                 :             :      construct the matching unqualified array type first.  The C front
     890                 :             :      end does not require this, but it does no harm, so we do it
     891                 :             :      unconditionally.  */
     892                 :    25873981 :   i_type = build_index_type (size_int (nchars - 1));
     893                 :    25873981 :   a_type = build_array_type (e_type, i_type);
     894                 :    25873981 :   if (c_dialect_cxx() || warn_write_strings)
     895                 :    23522909 :     a_type = c_build_qualified_type (a_type, TYPE_QUAL_CONST);
     896                 :             : 
     897                 :    25873981 :   TREE_TYPE (value) = a_type;
     898                 :    25873981 :   TREE_CONSTANT (value) = 1;
     899                 :    25873981 :   TREE_READONLY (value) = 1;
     900                 :    25873981 :   TREE_STATIC (value) = 1;
     901                 :    25873981 :   return value;
     902                 :             : }
     903                 :             : 
     904                 :             : /* Given a string of type STRING_TYPE, determine what kind of string
     905                 :             :    token would give an equivalent execution encoding: CPP_STRING,
     906                 :             :    CPP_STRING16, or CPP_STRING32.  Return CPP_OTHER in case of error.
     907                 :             :    This may not be exactly the string token type that initially created
     908                 :             :    the string, since CPP_WSTRING is indistinguishable from the 16/32 bit
     909                 :             :    string type, and CPP_UTF8STRING is indistinguishable from CPP_STRING
     910                 :             :    at this point.
     911                 :             : 
     912                 :             :    This effectively reverses part of the logic in lex_string and
     913                 :             :    fix_string_type.  */
     914                 :             : 
     915                 :             : static enum cpp_ttype
     916                 :       11293 : get_cpp_ttype_from_string_type (tree string_type)
     917                 :             : {
     918                 :       11293 :   gcc_assert (string_type);
     919                 :       11293 :   if (TREE_CODE (string_type) == POINTER_TYPE)
     920                 :        5968 :     string_type = TREE_TYPE (string_type);
     921                 :             : 
     922                 :       11293 :   if (TREE_CODE (string_type) != ARRAY_TYPE)
     923                 :             :     return CPP_OTHER;
     924                 :             : 
     925                 :       11293 :   tree element_type = TREE_TYPE (string_type);
     926                 :       11293 :   if (TREE_CODE (element_type) != INTEGER_TYPE)
     927                 :             :     return CPP_OTHER;
     928                 :             : 
     929                 :       11293 :   int bits_per_character = TYPE_PRECISION (element_type);
     930                 :       11293 :   switch (bits_per_character)
     931                 :             :     {
     932                 :             :     case 8:
     933                 :             :       return CPP_STRING;  /* It could have also been CPP_UTF8STRING.  */
     934                 :           2 :     case 16:
     935                 :           2 :       return CPP_STRING16;
     936                 :           4 :     case 32:
     937                 :           4 :       return CPP_STRING32;
     938                 :             :     }
     939                 :             : 
     940                 :             :   return CPP_OTHER;
     941                 :             : }
     942                 :             : 
     943                 :             : /* The global record of string concatentations, for use in
     944                 :             :    extracting locations within string literals.  */
     945                 :             : 
     946                 :             : GTY(()) string_concat_db *g_string_concat_db;
     947                 :             : 
     948                 :             : /* Implementation of LANG_HOOKS_GET_SUBSTRING_LOCATION.  */
     949                 :             : 
     950                 :             : const char *
     951                 :       11293 : c_get_substring_location (const substring_loc &substr_loc,
     952                 :             :                           location_t *out_loc)
     953                 :             : {
     954                 :       11293 :   enum cpp_ttype tok_type
     955                 :       11293 :     = get_cpp_ttype_from_string_type (substr_loc.get_string_type ());
     956                 :       11293 :   if (tok_type == CPP_OTHER)
     957                 :             :     return "unrecognized string type";
     958                 :             : 
     959                 :       11293 :   return get_location_within_string (parse_in,
     960                 :             :                                      global_dc->get_file_cache (),
     961                 :             :                                      g_string_concat_db,
     962                 :             :                                      substr_loc.get_fmt_string_loc (),
     963                 :             :                                      tok_type,
     964                 :             :                                      substr_loc.get_caret_idx (),
     965                 :             :                                      substr_loc.get_start_idx (),
     966                 :             :                                      substr_loc.get_end_idx (),
     967                 :       11293 :                                      out_loc);
     968                 :             : }
     969                 :             : 
     970                 :             : 
     971                 :             : /* Return true iff T is a boolean promoted to int.  */
     972                 :             : 
     973                 :             : bool
     974                 :       78810 : bool_promoted_to_int_p (tree t)
     975                 :             : {
     976                 :       61678 :   return (CONVERT_EXPR_P (t)
     977                 :       17232 :           && TREE_TYPE (t) == integer_type_node
     978                 :       78910 :           && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == BOOLEAN_TYPE);
     979                 :             : }
     980                 :             : 
     981                 :             : /* vector_targets_convertible_p is used for vector pointer types.  The
     982                 :             :    callers perform various checks that the qualifiers are satisfactory,
     983                 :             :    while OTOH vector_targets_convertible_p ignores the number of elements
     984                 :             :    in the vectors.  That's fine with vector pointers as we can consider,
     985                 :             :    say, a vector of 8 elements as two consecutive vectors of 4 elements,
     986                 :             :    and that does not require and conversion of the pointer values.
     987                 :             :    In contrast, vector_types_convertible_p and
     988                 :             :    vector_types_compatible_elements_p are used for vector value types.  */
     989                 :             : /* True if pointers to distinct types T1 and T2 can be converted to
     990                 :             :    each other without an explicit cast.  Only returns true for opaque
     991                 :             :    vector types.  */
     992                 :             : bool
     993                 :     1998987 : vector_targets_convertible_p (const_tree t1, const_tree t2)
     994                 :             : {
     995                 :      954344 :   if (VECTOR_TYPE_P (t1) && VECTOR_TYPE_P (t2)
     996                 :      954168 :       && (TYPE_VECTOR_OPAQUE (t1) || TYPE_VECTOR_OPAQUE (t2))
     997                 :     1998987 :       && tree_int_cst_equal (TYPE_SIZE (t1), TYPE_SIZE (t2)))
     998                 :             :     return true;
     999                 :             : 
    1000                 :             :   return false;
    1001                 :             : }
    1002                 :             : 
    1003                 :             : /* vector_types_convertible_p is used for vector value types.
    1004                 :             :    It could in principle call vector_targets_convertible_p as a subroutine,
    1005                 :             :    but then the check for vector type would be duplicated with its callers,
    1006                 :             :    and also the purpose of vector_targets_convertible_p would become
    1007                 :             :    muddled.
    1008                 :             :    Where vector_types_convertible_p returns true, a conversion might still be
    1009                 :             :    needed to make the types match.
    1010                 :             :    In contrast, vector_targets_convertible_p is used for vector pointer
    1011                 :             :    values, and vector_types_compatible_elements_p is used specifically
    1012                 :             :    in the context for binary operators, as a check if use is possible without
    1013                 :             :    conversion.  */
    1014                 :             : /* True if vector types T1 and T2 can be converted to each other
    1015                 :             :    without an explicit cast.  If EMIT_LAX_NOTE is true, and T1 and T2
    1016                 :             :    can only be converted with -flax-vector-conversions yet that is not
    1017                 :             :    in effect, emit a note telling the user about that option if such
    1018                 :             :    a note has not previously been emitted.  */
    1019                 :             : bool
    1020                 :    17797430 : vector_types_convertible_p (const_tree t1, const_tree t2, bool emit_lax_note)
    1021                 :             : {
    1022                 :    17797430 :   static bool emitted_lax_note = false;
    1023                 :    17797430 :   bool convertible_lax;
    1024                 :             : 
    1025                 :    35590369 :   if ((TYPE_VECTOR_OPAQUE (t1) || TYPE_VECTOR_OPAQUE (t2))
    1026                 :    17798943 :       && tree_int_cst_equal (TYPE_SIZE (t1), TYPE_SIZE (t2)))
    1027                 :             :     return true;
    1028                 :             : 
    1029                 :    35582968 :   convertible_lax =
    1030                 :    17791484 :     (tree_int_cst_equal (TYPE_SIZE (t1), TYPE_SIZE (t2))
    1031                 :    17787992 :      && (TREE_CODE (TREE_TYPE (t1)) != REAL_TYPE
    1032                 :    10474939 :          || known_eq (TYPE_VECTOR_SUBPARTS (t1),
    1033                 :             :                       TYPE_VECTOR_SUBPARTS (t2)))
    1034                 :    53310800 :      && (INTEGRAL_TYPE_P (TREE_TYPE (t1))
    1035                 :    17759658 :          == INTEGRAL_TYPE_P (TREE_TYPE (t2))));
    1036                 :             : 
    1037                 :    17791484 :   if (!convertible_lax || flag_lax_vector_conversions)
    1038                 :       64699 :     return convertible_lax;
    1039                 :             : 
    1040                 :    17726785 :   if (known_eq (TYPE_VECTOR_SUBPARTS (t1), TYPE_VECTOR_SUBPARTS (t2))
    1041                 :    17726785 :       && lang_hooks.types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    1042                 :    16375878 :     return true;
    1043                 :             : 
    1044                 :     1350907 :   if (emit_lax_note && !emitted_lax_note)
    1045                 :             :     {
    1046                 :          10 :       emitted_lax_note = true;
    1047                 :          10 :       inform (input_location, "use %<-flax-vector-conversions%> to permit "
    1048                 :             :               "conversions between vectors with differing "
    1049                 :             :               "element types or numbers of subparts");
    1050                 :             :     }
    1051                 :             : 
    1052                 :             :   return false;
    1053                 :             : }
    1054                 :             : 
    1055                 :             : /* Build a VEC_PERM_EXPR if V0, V1 and MASK are not error_mark_nodes
    1056                 :             :    and have vector types, V0 has the same type as V1, and the number of
    1057                 :             :    elements of V0, V1, MASK is the same.
    1058                 :             : 
    1059                 :             :    In case V1 is a NULL_TREE it is assumed that __builtin_shuffle was
    1060                 :             :    called with two arguments.  In this case implementation passes the
    1061                 :             :    first argument twice in order to share the same tree code.  This fact
    1062                 :             :    could enable the mask-values being twice the vector length.  This is
    1063                 :             :    an implementation accident and this semantics is not guaranteed to
    1064                 :             :    the user.  */
    1065                 :             : tree
    1066                 :      474742 : c_build_vec_perm_expr (location_t loc, tree v0, tree v1, tree mask,
    1067                 :             :                        bool complain)
    1068                 :             : {
    1069                 :      474742 :   tree ret;
    1070                 :      474742 :   bool wrap = true;
    1071                 :      474742 :   bool maybe_const = false;
    1072                 :      474742 :   bool two_arguments = false;
    1073                 :             : 
    1074                 :      474742 :   if (v1 == NULL_TREE)
    1075                 :             :     {
    1076                 :      432671 :       two_arguments = true;
    1077                 :      432671 :       v1 = v0;
    1078                 :             :     }
    1079                 :             : 
    1080                 :      474742 :   if (v0 == error_mark_node || v1 == error_mark_node
    1081                 :      474742 :       || mask == error_mark_node)
    1082                 :             :     return error_mark_node;
    1083                 :             : 
    1084                 :      474742 :   if (!gnu_vector_type_p (TREE_TYPE (mask))
    1085                 :      474742 :       || !VECTOR_INTEGER_TYPE_P (TREE_TYPE (mask)))
    1086                 :             :     {
    1087                 :           3 :       if (complain)
    1088                 :           0 :         error_at (loc, "%<__builtin_shuffle%> last argument must "
    1089                 :             :                        "be an integer vector");
    1090                 :           3 :       return error_mark_node;
    1091                 :             :     }
    1092                 :             : 
    1093                 :      474739 :   if (!gnu_vector_type_p (TREE_TYPE (v0))
    1094                 :      474739 :       || !gnu_vector_type_p (TREE_TYPE (v1)))
    1095                 :             :     {
    1096                 :           0 :       if (complain)
    1097                 :           0 :         error_at (loc, "%<__builtin_shuffle%> arguments must be vectors");
    1098                 :           0 :       return error_mark_node;
    1099                 :             :     }
    1100                 :             : 
    1101                 :      474739 :   if (TYPE_MAIN_VARIANT (TREE_TYPE (v0)) != TYPE_MAIN_VARIANT (TREE_TYPE (v1)))
    1102                 :             :     {
    1103                 :           0 :       if (complain)
    1104                 :           0 :         error_at (loc, "%<__builtin_shuffle%> argument vectors must be of "
    1105                 :             :                        "the same type");
    1106                 :           0 :       return error_mark_node;
    1107                 :             :     }
    1108                 :             : 
    1109                 :      474739 :   if (maybe_ne (TYPE_VECTOR_SUBPARTS (TREE_TYPE (v0)),
    1110                 :      474739 :                 TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask)))
    1111                 :      474739 :       && maybe_ne (TYPE_VECTOR_SUBPARTS (TREE_TYPE (v1)),
    1112                 :           0 :                    TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask))))
    1113                 :             :     {
    1114                 :           0 :       if (complain)
    1115                 :           0 :         error_at (loc, "%<__builtin_shuffle%> number of elements of the "
    1116                 :             :                        "argument vector(s) and the mask vector should "
    1117                 :             :                        "be the same");
    1118                 :           0 :       return error_mark_node;
    1119                 :             :     }
    1120                 :             : 
    1121                 :      474739 :   if (GET_MODE_BITSIZE (SCALAR_TYPE_MODE (TREE_TYPE (TREE_TYPE (v0))))
    1122                 :      949478 :       != GET_MODE_BITSIZE (SCALAR_TYPE_MODE (TREE_TYPE (TREE_TYPE (mask)))))
    1123                 :             :     {
    1124                 :           0 :       if (complain)
    1125                 :           0 :         error_at (loc, "%<__builtin_shuffle%> argument vector(s) inner type "
    1126                 :             :                        "must have the same size as inner type of the mask");
    1127                 :           0 :       return error_mark_node;
    1128                 :             :     }
    1129                 :             : 
    1130                 :      474739 :   if (!c_dialect_cxx ())
    1131                 :             :     {
    1132                 :             :       /* Avoid C_MAYBE_CONST_EXPRs inside VEC_PERM_EXPR.  */
    1133                 :      460014 :       v0 = c_fully_fold (v0, false, &maybe_const);
    1134                 :      460014 :       wrap &= maybe_const;
    1135                 :             : 
    1136                 :      460014 :       if (two_arguments)
    1137                 :      418752 :         v1 = v0 = save_expr (v0);
    1138                 :             :       else
    1139                 :             :         {
    1140                 :       41262 :           v1 = c_fully_fold (v1, false, &maybe_const);
    1141                 :       41262 :           wrap &= maybe_const;
    1142                 :             :         }
    1143                 :             : 
    1144                 :      460014 :       mask = c_fully_fold (mask, false, &maybe_const);
    1145                 :      460014 :       wrap &= maybe_const;
    1146                 :             :     }
    1147                 :       14725 :   else if (two_arguments)
    1148                 :       13916 :     v1 = v0 = save_expr (v0);
    1149                 :             : 
    1150                 :      474739 :   ret = build3_loc (loc, VEC_PERM_EXPR, TREE_TYPE (v0), v0, v1, mask);
    1151                 :             : 
    1152                 :      474739 :   if (!c_dialect_cxx () && !wrap)
    1153                 :      460014 :     ret = c_wrap_maybe_const (ret, true);
    1154                 :             : 
    1155                 :             :   return ret;
    1156                 :             : }
    1157                 :             : 
    1158                 :             : /* Build a VEC_PERM_EXPR if V0, V1 are not error_mark_nodes
    1159                 :             :    and have vector types, V0 has the same element type as V1, and the
    1160                 :             :    number of elements the result is that of MASK.  */
    1161                 :             : tree
    1162                 :     1087335 : c_build_shufflevector (location_t loc, tree v0, tree v1,
    1163                 :             :                        const vec<tree> &mask, bool complain)
    1164                 :             : {
    1165                 :     1087335 :   tree ret;
    1166                 :     1087335 :   bool wrap = true;
    1167                 :     1087335 :   bool maybe_const = false;
    1168                 :             : 
    1169                 :     1087335 :   if (v0 == error_mark_node || v1 == error_mark_node)
    1170                 :             :     return error_mark_node;
    1171                 :             : 
    1172                 :     1087335 :   if (!gnu_vector_type_p (TREE_TYPE (v0))
    1173                 :     1087335 :       || !gnu_vector_type_p (TREE_TYPE (v1)))
    1174                 :             :     {
    1175                 :           4 :       if (complain)
    1176                 :           4 :         error_at (loc, "%<__builtin_shufflevector%> arguments must be vectors");
    1177                 :           4 :       return error_mark_node;
    1178                 :             :     }
    1179                 :             : 
    1180                 :             :   /* ???  In principle one could select a constant part of a variable size
    1181                 :             :      vector but things get a bit awkward with trying to support this here.  */
    1182                 :     1087331 :   unsigned HOST_WIDE_INT v0n, v1n;
    1183                 :     1087331 :   if (!TYPE_VECTOR_SUBPARTS (TREE_TYPE (v0)).is_constant (&v0n)
    1184                 :     1087331 :       || !TYPE_VECTOR_SUBPARTS (TREE_TYPE (v1)).is_constant (&v1n))
    1185                 :             :     {
    1186                 :             :       if (complain)
    1187                 :             :         error_at (loc, "%<__builtin_shufflevector%> arguments must be constant"
    1188                 :             :                   " size vectors");
    1189                 :             :       return error_mark_node;
    1190                 :             :     }
    1191                 :             : 
    1192                 :     1087331 :   if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (v0)))
    1193                 :     1087331 :       != TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (v1))))
    1194                 :             :     {
    1195                 :           4 :       if (complain)
    1196                 :           4 :         error_at (loc, "%<__builtin_shufflevector%> argument vectors must "
    1197                 :             :                   "have the same element type");
    1198                 :           4 :       return error_mark_node;
    1199                 :             :     }
    1200                 :             : 
    1201                 :     1087327 :   if (!pow2p_hwi (mask.length ()))
    1202                 :             :     {
    1203                 :           4 :       if (complain)
    1204                 :           4 :         error_at (loc, "%<__builtin_shufflevector%> must specify a result "
    1205                 :             :                   "with a power of two number of elements");
    1206                 :           4 :       return error_mark_node;
    1207                 :             :     }
    1208                 :             : 
    1209                 :     1087323 :   if (!c_dialect_cxx ())
    1210                 :             :     {
    1211                 :             :       /* Avoid C_MAYBE_CONST_EXPRs inside VEC_PERM_EXPR.  */
    1212                 :     1052899 :       v0 = c_fully_fold (v0, false, &maybe_const);
    1213                 :     1052899 :       wrap &= maybe_const;
    1214                 :             : 
    1215                 :     1052899 :       v1 = c_fully_fold (v1, false, &maybe_const);
    1216                 :     1052899 :       wrap &= maybe_const;
    1217                 :             :     }
    1218                 :             : 
    1219                 :     2174691 :   unsigned HOST_WIDE_INT maskl = MAX (mask.length (), MAX (v0n, v1n));
    1220                 :     1087323 :   unsigned HOST_WIDE_INT pad = (v0n < maskl ? maskl - v0n : 0);
    1221                 :     1087323 :   vec_perm_builder sel (maskl, maskl, 1);
    1222                 :     1087323 :   unsigned i;
    1223                 :    29511646 :   for (i = 0; i < mask.length (); ++i)
    1224                 :             :     {
    1225                 :    13668515 :       tree idx = mask[i];
    1226                 :    13668515 :       if (!tree_fits_shwi_p (idx))
    1227                 :             :         {
    1228                 :           4 :           if (complain)
    1229                 :           4 :             error_at (loc, "invalid element index %qE to "
    1230                 :             :                       "%<__builtin_shufflevector%>", idx);
    1231                 :     1087323 :           return error_mark_node;
    1232                 :             :         }
    1233                 :    13668511 :       HOST_WIDE_INT iidx = tree_to_shwi (idx);
    1234                 :    13668511 :       if (iidx < -1
    1235                 :    13668507 :           || (iidx != -1
    1236                 :    13668427 :               && (unsigned HOST_WIDE_INT) iidx >= v0n + v1n))
    1237                 :             :         {
    1238                 :          11 :           if (complain)
    1239                 :          11 :             error_at (loc, "invalid element index %qE to "
    1240                 :             :                       "%<__builtin_shufflevector%>", idx);
    1241                 :          11 :           return error_mark_node;
    1242                 :             :         }
    1243                 :             :       /* ???  Our VEC_PERM_EXPR does not allow for -1 yet.  */
    1244                 :    13668500 :       if (iidx == -1)
    1245                 :          80 :         iidx = i;
    1246                 :             :       /* ???  Our VEC_PERM_EXPR does not allow different sized inputs,
    1247                 :             :          so pad out a smaller v0.  */
    1248                 :    13668420 :       else if ((unsigned HOST_WIDE_INT) iidx >= v0n)
    1249                 :        1159 :         iidx += pad;
    1250                 :    13668500 :       sel.quick_push (iidx);
    1251                 :             :     }
    1252                 :             :   /* ???  VEC_PERM_EXPR does not support a result that is smaller than
    1253                 :             :      the inputs, so we have to pad id out.  */
    1254                 :     1088468 :   for (; i < maskl; ++i)
    1255                 :        1160 :     sel.quick_push (i);
    1256                 :             : 
    1257                 :     1087308 :   vec_perm_indices indices (sel, 2, maskl);
    1258                 :             : 
    1259                 :     1087308 :   tree ret_type = build_vector_type (TREE_TYPE (TREE_TYPE (v0)), maskl);
    1260                 :     2174616 :   tree mask_type = build_vector_type (build_nonstandard_integer_type
    1261                 :     1087308 :                 (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (ret_type))), 1),
    1262                 :     1087308 :                 maskl);
    1263                 :             :   /* Pad out arguments to the common vector size.  */
    1264                 :     1087308 :   if (v0n < maskl)
    1265                 :             :     {
    1266                 :         125 :       constructor_elt elt = { NULL_TREE, build_zero_cst (TREE_TYPE (v0)) };
    1267                 :         125 :       v0 = build_constructor_single (ret_type, NULL_TREE, v0);
    1268                 :         571 :       for (i = 1; i < maskl / v0n; ++i)
    1269                 :         321 :         vec_safe_push (CONSTRUCTOR_ELTS (v0), elt);
    1270                 :             :     }
    1271                 :     1087308 :   if (v1n < maskl)
    1272                 :             :     {
    1273                 :          95 :       constructor_elt elt = { NULL_TREE, build_zero_cst (TREE_TYPE (v1)) };
    1274                 :          95 :       v1 = build_constructor_single (ret_type, NULL_TREE, v1);
    1275                 :         351 :       for (i = 1; i < maskl / v1n; ++i)
    1276                 :         161 :         vec_safe_push (CONSTRUCTOR_ELTS (v1), elt);
    1277                 :             :     }
    1278                 :     1087308 :   ret = build3_loc (loc, VEC_PERM_EXPR, ret_type, v0, v1,
    1279                 :             :                     vec_perm_indices_to_tree (mask_type, indices));
    1280                 :             :   /* Get the lowpart we are interested in.  */
    1281                 :     2174616 :   if (mask.length () < maskl)
    1282                 :             :     {
    1283                 :         163 :       tree lpartt = build_vector_type (TREE_TYPE (ret_type), mask.length ());
    1284                 :         163 :       ret = build3_loc (loc, BIT_FIELD_REF,
    1285                 :         163 :                         lpartt, ret, TYPE_SIZE (lpartt), bitsize_zero_node);
    1286                 :             :       /* Wrap the lowpart operation in a TARGET_EXPR so it gets a separate
    1287                 :             :          temporary during gimplification.  See PR101530 for cases where
    1288                 :             :          we'd otherwise end up with non-toplevel BIT_FIELD_REFs.  */
    1289                 :         163 :       tree tem = create_tmp_var_raw (lpartt);
    1290                 :         163 :       DECL_CONTEXT (tem) = current_function_decl;
    1291                 :         163 :       ret = build4 (TARGET_EXPR, lpartt, tem, ret, NULL_TREE, NULL_TREE);
    1292                 :         163 :       TREE_SIDE_EFFECTS (ret) = 1;
    1293                 :             :     }
    1294                 :             : 
    1295                 :     1087308 :   if (!c_dialect_cxx () && !wrap)
    1296                 :     1052896 :     ret = c_wrap_maybe_const (ret, true);
    1297                 :             : 
    1298                 :     1087308 :   return ret;
    1299                 :     2174631 : }
    1300                 :             : 
    1301                 :             : /* Build a VEC_CONVERT ifn for __builtin_convertvector builtin.  */
    1302                 :             : 
    1303                 :             : tree
    1304                 :         490 : c_build_vec_convert (location_t loc1, tree expr, location_t loc2, tree type,
    1305                 :             :                      bool complain)
    1306                 :             : {
    1307                 :         490 :   if (error_operand_p (type))
    1308                 :           0 :     return error_mark_node;
    1309                 :         490 :   if (error_operand_p (expr))
    1310                 :           0 :     return error_mark_node;
    1311                 :             : 
    1312                 :         490 :   if (!gnu_vector_type_p (TREE_TYPE (expr))
    1313                 :         490 :       || (!VECTOR_INTEGER_TYPE_P (TREE_TYPE (expr))
    1314                 :         166 :           && !VECTOR_FLOAT_TYPE_P (TREE_TYPE (expr))))
    1315                 :             :     {
    1316                 :           4 :       if (complain)
    1317                 :           4 :         error_at (loc1, "%<__builtin_convertvector%> first argument must "
    1318                 :             :                         "be an integer or floating vector");
    1319                 :           4 :       return error_mark_node;
    1320                 :             :     }
    1321                 :             : 
    1322                 :         486 :   if (!gnu_vector_type_p (type)
    1323                 :         486 :       || (!VECTOR_INTEGER_TYPE_P (type) && !VECTOR_FLOAT_TYPE_P (type)))
    1324                 :             :     {
    1325                 :           4 :       if (complain)
    1326                 :           4 :         error_at (loc2, "%<__builtin_convertvector%> second argument must "
    1327                 :             :                         "be an integer or floating vector type");
    1328                 :           4 :       return error_mark_node;
    1329                 :             :     }
    1330                 :             : 
    1331                 :         482 :   if (maybe_ne (TYPE_VECTOR_SUBPARTS (TREE_TYPE (expr)),
    1332                 :         964 :                 TYPE_VECTOR_SUBPARTS (type)))
    1333                 :             :     {
    1334                 :           8 :       if (complain)
    1335                 :           8 :         error_at (loc1, "%<__builtin_convertvector%> number of elements "
    1336                 :             :                         "of the first argument vector and the second argument "
    1337                 :             :                         "vector type should be the same");
    1338                 :           8 :       return error_mark_node;
    1339                 :             :     }
    1340                 :             : 
    1341                 :         474 :   if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (expr)))
    1342                 :         474 :        == TYPE_MAIN_VARIANT (TREE_TYPE (type)))
    1343                 :         474 :       || (VECTOR_INTEGER_TYPE_P (TREE_TYPE (expr))
    1344                 :         303 :           && VECTOR_INTEGER_TYPE_P (type)
    1345                 :         155 :           && (TYPE_PRECISION (TREE_TYPE (TREE_TYPE (expr)))
    1346                 :         155 :               == TYPE_PRECISION (TREE_TYPE (type)))))
    1347                 :          29 :     return build1_loc (loc1, VIEW_CONVERT_EXPR, type, expr);
    1348                 :             : 
    1349                 :         445 :   bool wrap = true;
    1350                 :         445 :   bool maybe_const = false;
    1351                 :         445 :   tree ret;
    1352                 :         445 :   if (!c_dialect_cxx ())
    1353                 :             :     {
    1354                 :             :       /* Avoid C_MAYBE_CONST_EXPRs inside of VEC_CONVERT argument.  */
    1355                 :         310 :       expr = c_fully_fold (expr, false, &maybe_const);
    1356                 :         310 :       wrap &= maybe_const;
    1357                 :             :     }
    1358                 :             : 
    1359                 :         445 :   ret = build_call_expr_internal_loc (loc1, IFN_VEC_CONVERT, type, 1, expr);
    1360                 :             : 
    1361                 :         445 :   if (!wrap)
    1362                 :         310 :     ret = c_wrap_maybe_const (ret, true);
    1363                 :             : 
    1364                 :             :   return ret;
    1365                 :             : }
    1366                 :             : 
    1367                 :             : /* Like tree.cc:get_narrower, but retain conversion from C++0x scoped enum
    1368                 :             :    to integral type.  */
    1369                 :             : 
    1370                 :             : tree
    1371                 :    64695307 : c_common_get_narrower (tree op, int *unsignedp_ptr)
    1372                 :             : {
    1373                 :    64695307 :   op = get_narrower (op, unsignedp_ptr);
    1374                 :             : 
    1375                 :    64695307 :   if (TREE_CODE (TREE_TYPE (op)) == ENUMERAL_TYPE
    1376                 :    64695307 :       && ENUM_IS_SCOPED (TREE_TYPE (op)))
    1377                 :             :     {
    1378                 :             :       /* C++0x scoped enumerations don't implicitly convert to integral
    1379                 :             :          type; if we stripped an explicit conversion to a larger type we
    1380                 :             :          need to replace it so common_type will still work.  */
    1381                 :     2589038 :       tree type = c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op)),
    1382                 :     2589038 :                                           TYPE_UNSIGNED (TREE_TYPE (op)));
    1383                 :     2589038 :       op = fold_convert (type, op);
    1384                 :             :     }
    1385                 :    64695307 :   return op;
    1386                 :             : }
    1387                 :             : 
    1388                 :             : /* This is a helper function of build_binary_op.
    1389                 :             : 
    1390                 :             :    For certain operations if both args were extended from the same
    1391                 :             :    smaller type, do the arithmetic in that type and then extend.
    1392                 :             : 
    1393                 :             :    BITWISE indicates a bitwise operation.
    1394                 :             :    For them, this optimization is safe only if
    1395                 :             :    both args are zero-extended or both are sign-extended.
    1396                 :             :    Otherwise, we might change the result.
    1397                 :             :    Eg, (short)-1 | (unsigned short)-1 is (int)-1
    1398                 :             :    but calculated in (unsigned short) it would be (unsigned short)-1.
    1399                 :             : */
    1400                 :             : tree
    1401                 :     5108654 : shorten_binary_op (tree result_type, tree op0, tree op1, bool bitwise)
    1402                 :             : {
    1403                 :     5108654 :   int unsigned0, unsigned1;
    1404                 :     5108654 :   tree arg0, arg1;
    1405                 :     5108654 :   int uns;
    1406                 :     5108654 :   tree type;
    1407                 :             : 
    1408                 :             :   /* Do not shorten vector operations.  */
    1409                 :     5108654 :   if (VECTOR_TYPE_P (result_type))
    1410                 :             :     return result_type;
    1411                 :             : 
    1412                 :             :   /* Cast OP0 and OP1 to RESULT_TYPE.  Doing so prevents
    1413                 :             :      excessive narrowing when we call get_narrower below.  For
    1414                 :             :      example, suppose that OP0 is of unsigned int extended
    1415                 :             :      from signed char and that RESULT_TYPE is long long int.
    1416                 :             :      If we explicitly cast OP0 to RESULT_TYPE, OP0 would look
    1417                 :             :      like
    1418                 :             : 
    1419                 :             :      (long long int) (unsigned int) signed_char
    1420                 :             : 
    1421                 :             :      which get_narrower would narrow down to
    1422                 :             : 
    1423                 :             :      (unsigned int) signed char
    1424                 :             : 
    1425                 :             :      If we do not cast OP0 first, get_narrower would return
    1426                 :             :      signed_char, which is inconsistent with the case of the
    1427                 :             :      explicit cast.  */
    1428                 :     5091051 :   op0 = convert (result_type, op0);
    1429                 :     5091051 :   op1 = convert (result_type, op1);
    1430                 :             : 
    1431                 :     5091051 :   arg0 = c_common_get_narrower (op0, &unsigned0);
    1432                 :     5091051 :   arg1 = c_common_get_narrower (op1, &unsigned1);
    1433                 :             : 
    1434                 :             :   /* UNS is 1 if the operation to be done is an unsigned one.  */
    1435                 :     5091051 :   uns = TYPE_UNSIGNED (result_type);
    1436                 :             : 
    1437                 :             :   /* Handle the case that OP0 (or OP1) does not *contain* a conversion
    1438                 :             :      but it *requires* conversion to FINAL_TYPE.  */
    1439                 :             : 
    1440                 :     5091051 :   if ((TYPE_PRECISION (TREE_TYPE (op0))
    1441                 :     5091051 :        == TYPE_PRECISION (TREE_TYPE (arg0)))
    1442                 :     5091051 :       && TREE_TYPE (op0) != result_type)
    1443                 :        2392 :     unsigned0 = TYPE_UNSIGNED (TREE_TYPE (op0));
    1444                 :     5091051 :   if ((TYPE_PRECISION (TREE_TYPE (op1))
    1445                 :     5091051 :        == TYPE_PRECISION (TREE_TYPE (arg1)))
    1446                 :     5091051 :       && TREE_TYPE (op1) != result_type)
    1447                 :      234445 :     unsigned1 = TYPE_UNSIGNED (TREE_TYPE (op1));
    1448                 :             : 
    1449                 :             :   /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE.  */
    1450                 :             : 
    1451                 :             :   /* For bitwise operations, signedness of nominal type
    1452                 :             :      does not matter.  Consider only how operands were extended.  */
    1453                 :     5091051 :   if (bitwise)
    1454                 :     2513072 :     uns = unsigned0;
    1455                 :             : 
    1456                 :             :   /* Note that in all three cases below we refrain from optimizing
    1457                 :             :      an unsigned operation on sign-extended args.
    1458                 :             :      That would not be valid.  */
    1459                 :             : 
    1460                 :             :   /* Both args variable: if both extended in same way
    1461                 :             :      from same width, do it in that width.
    1462                 :             :      Do it unsigned if args were zero-extended.  */
    1463                 :     5091051 :   if ((TYPE_PRECISION (TREE_TYPE (arg0))
    1464                 :     5091051 :        < TYPE_PRECISION (result_type))
    1465                 :      269731 :       && (TYPE_PRECISION (TREE_TYPE (arg1))
    1466                 :      269731 :           == TYPE_PRECISION (TREE_TYPE (arg0)))
    1467                 :      187667 :       && unsigned0 == unsigned1
    1468                 :     5278524 :       && (unsigned0 || !uns))
    1469                 :             :     {
    1470                 :      187455 :       tree ctype = common_type (TREE_TYPE (arg0), TREE_TYPE (arg1));
    1471                 :      187455 :       if (ctype != error_mark_node)
    1472                 :      187455 :         return c_common_signed_or_unsigned_type (unsigned0, ctype);
    1473                 :             :     }
    1474                 :             : 
    1475                 :     4903596 :   else if (TREE_CODE (arg0) == INTEGER_CST
    1476                 :     1699300 :            && (unsigned1 || !uns)
    1477                 :     1513334 :            && (TYPE_PRECISION (TREE_TYPE (arg1))
    1478                 :     1513334 :                < TYPE_PRECISION (result_type))
    1479                 :         282 :            && (type
    1480                 :         282 :                = c_common_signed_or_unsigned_type (unsigned1,
    1481                 :         282 :                                                    TREE_TYPE (arg1)))
    1482                 :         282 :            && !POINTER_TYPE_P (type)
    1483                 :     4903878 :            && int_fits_type_p (arg0, type))
    1484                 :             :     return type;
    1485                 :             : 
    1486                 :     4903366 :   else if (TREE_CODE (arg1) == INTEGER_CST
    1487                 :     3122649 :            && (unsigned0 || !uns)
    1488                 :     2414253 :            && (TYPE_PRECISION (TREE_TYPE (arg0))
    1489                 :     2414253 :                < TYPE_PRECISION (result_type))
    1490                 :       57767 :            && (type
    1491                 :       57767 :                = c_common_signed_or_unsigned_type (unsigned0,
    1492                 :       57767 :                                                    TREE_TYPE (arg0)))
    1493                 :       57767 :            && !POINTER_TYPE_P (type)
    1494                 :     4961133 :            && int_fits_type_p (arg1, type))
    1495                 :             :     return type;
    1496                 :             : 
    1497                 :             :   return result_type;
    1498                 :             : }
    1499                 :             : 
    1500                 :             : /* Returns true iff any integer value of type FROM_TYPE can be represented as
    1501                 :             :    real of type TO_TYPE.  This is a helper function for unsafe_conversion_p.  */
    1502                 :             : 
    1503                 :             : static bool
    1504                 :         101 : int_safely_convertible_to_real_p (const_tree from_type, const_tree to_type)
    1505                 :             : {
    1506                 :         101 :   tree type_low_bound = TYPE_MIN_VALUE (from_type);
    1507                 :         101 :   tree type_high_bound = TYPE_MAX_VALUE (from_type);
    1508                 :         101 :   REAL_VALUE_TYPE real_low_bound =
    1509                 :         101 :           real_value_from_int_cst (0, type_low_bound);
    1510                 :         101 :   REAL_VALUE_TYPE real_high_bound =
    1511                 :         101 :           real_value_from_int_cst (0, type_high_bound);
    1512                 :             : 
    1513                 :         101 :   return exact_real_truncate (TYPE_MODE (to_type), &real_low_bound)
    1514                 :         101 :          && exact_real_truncate (TYPE_MODE (to_type), &real_high_bound);
    1515                 :             : }
    1516                 :             : 
    1517                 :             : /* Checks if expression EXPR of complex/real/integer type cannot be converted
    1518                 :             :    to the complex/real/integer type TYPE.  Function returns non-zero when:
    1519                 :             :         * EXPR is a constant which cannot be exactly converted to TYPE.
    1520                 :             :         * EXPR is not a constant and size of EXPR's type > than size of TYPE,
    1521                 :             :           for EXPR type and TYPE being both integers or both real, or both
    1522                 :             :           complex.
    1523                 :             :         * EXPR is not a constant of complex type and TYPE is a real or
    1524                 :             :           an integer.
    1525                 :             :         * EXPR is not a constant of real type and TYPE is an integer.
    1526                 :             :         * EXPR is not a constant of integer type which cannot be
    1527                 :             :           exactly converted to real type.
    1528                 :             : 
    1529                 :             :    Function allows conversions between types of different signedness if
    1530                 :             :    CHECK_SIGN is false and can return SAFE_CONVERSION (zero) in that
    1531                 :             :    case.  Function can return UNSAFE_SIGN if CHECK_SIGN is true.
    1532                 :             : 
    1533                 :             :    RESULT, when non-null is the result of the conversion.  When constant
    1534                 :             :    it is included in the text of diagnostics.
    1535                 :             : 
    1536                 :             :    Function allows conversions from complex constants to non-complex types,
    1537                 :             :    provided that imaginary part is zero and real part can be safely converted
    1538                 :             :    to TYPE.  */
    1539                 :             : 
    1540                 :             : enum conversion_safety
    1541                 :        9404 : unsafe_conversion_p (tree type, tree expr, tree result, bool check_sign)
    1542                 :             : {
    1543                 :        9404 :   enum conversion_safety give_warning = SAFE_CONVERSION; /* is 0 or false */
    1544                 :        9404 :   tree expr_type = TREE_TYPE (expr);
    1545                 :             : 
    1546                 :        9404 :   expr = fold_for_warn (expr);
    1547                 :             : 
    1548                 :        9404 :   if (TREE_CODE (expr) == REAL_CST || TREE_CODE (expr) == INTEGER_CST)
    1549                 :             :     {
    1550                 :             :       /* If type is complex, we are interested in compatibility with
    1551                 :             :          underlying type.  */
    1552                 :        5411 :       if (TREE_CODE (type) == COMPLEX_TYPE)
    1553                 :         114 :           type = TREE_TYPE (type);
    1554                 :             : 
    1555                 :             :       /* Warn for real constant that is not an exact integer converted
    1556                 :             :          to integer type.  */
    1557                 :        5411 :       if (SCALAR_FLOAT_TYPE_P (expr_type)
    1558                 :         658 :           && (TREE_CODE (type) == INTEGER_TYPE
    1559                 :         658 :               || TREE_CODE (type) == BITINT_TYPE))
    1560                 :             :         {
    1561                 :         283 :           if (!real_isinteger (TREE_REAL_CST_PTR (expr), TYPE_MODE (expr_type)))
    1562                 :         275 :             give_warning = UNSAFE_REAL;
    1563                 :             :         }
    1564                 :             :       /* Warn for an integer constant that does not fit into integer type.  */
    1565                 :        5128 :       else if ((TREE_CODE (expr_type) == INTEGER_TYPE
    1566                 :        5128 :                 || TREE_CODE (expr_type) == BITINT_TYPE)
    1567                 :        4743 :                && (TREE_CODE (type) == INTEGER_TYPE
    1568                 :        4743 :                    || TREE_CODE (type) == BITINT_TYPE)
    1569                 :        4019 :                && !int_fits_type_p (expr, type))
    1570                 :             :         {
    1571                 :         995 :           if (TYPE_UNSIGNED (type) && !TYPE_UNSIGNED (expr_type)
    1572                 :         961 :               && tree_int_cst_sgn (expr) < 0)
    1573                 :             :             {
    1574                 :         264 :               if (check_sign)
    1575                 :        1834 :                 give_warning = UNSAFE_SIGN;
    1576                 :             :             }
    1577                 :         432 :           else if (!TYPE_UNSIGNED (type) && TYPE_UNSIGNED (expr_type))
    1578                 :             :             {
    1579                 :         335 :               if (check_sign)
    1580                 :        1834 :                 give_warning = UNSAFE_SIGN;
    1581                 :             :             }
    1582                 :             :           else
    1583                 :             :             give_warning = UNSAFE_OTHER;
    1584                 :             :         }
    1585                 :        4432 :       else if (SCALAR_FLOAT_TYPE_P (type))
    1586                 :             :         {
    1587                 :             :           /* Warn for an integer constant that does not fit into real type.  */
    1588                 :        1009 :           if (TREE_CODE (expr_type) == INTEGER_TYPE
    1589                 :             :               || TREE_CODE (expr_type) == BITINT_TYPE)
    1590                 :             :             {
    1591                 :         634 :               REAL_VALUE_TYPE a = real_value_from_int_cst (0, expr);
    1592                 :         634 :               if (!exact_real_truncate (TYPE_MODE (type), &a))
    1593                 :          53 :                 give_warning = UNSAFE_REAL;
    1594                 :             :             }
    1595                 :             :           /* Warn for a real constant that does not fit into a smaller
    1596                 :             :              real type.  */
    1597                 :         375 :           else if (SCALAR_FLOAT_TYPE_P (expr_type)
    1598                 :         375 :                    && TYPE_PRECISION (type) < TYPE_PRECISION (expr_type))
    1599                 :             :             {
    1600                 :         227 :               REAL_VALUE_TYPE a = TREE_REAL_CST (expr);
    1601                 :         227 :               if (!exact_real_truncate (TYPE_MODE (type), &a))
    1602                 :          65 :                 give_warning = UNSAFE_REAL;
    1603                 :             :             }
    1604                 :             :         }
    1605                 :             :     }
    1606                 :             : 
    1607                 :        3993 :   else if (TREE_CODE (expr) == COMPLEX_CST)
    1608                 :             :     {
    1609                 :          69 :       tree imag_part = TREE_IMAGPART (expr);
    1610                 :             :       /* Conversion from complex constant with zero imaginary part,
    1611                 :             :          perform check for conversion of real part.  */
    1612                 :          69 :       if ((TREE_CODE (imag_part) == REAL_CST
    1613                 :          29 :            && real_zerop (imag_part))
    1614                 :          80 :           || (TREE_CODE (imag_part) == INTEGER_CST
    1615                 :          40 :               && integer_zerop (imag_part)))
    1616                 :             :         /* Note: in this branch we use recursive call to unsafe_conversion_p
    1617                 :             :            with different type of EXPR, but it is still safe, because when EXPR
    1618                 :             :            is a constant, it's type is not used in text of generated warnings
    1619                 :             :            (otherwise they could sound misleading).  */
    1620                 :          30 :         return unsafe_conversion_p (type, TREE_REALPART (expr), result,
    1621                 :          30 :                                     check_sign);
    1622                 :             :       /* Conversion from complex constant with non-zero imaginary part.  */
    1623                 :             :       else
    1624                 :             :         {
    1625                 :             :           /* Conversion to complex type.
    1626                 :             :              Perform checks for both real and imaginary parts.  */
    1627                 :          39 :           if (TREE_CODE (type) == COMPLEX_TYPE)
    1628                 :             :             {
    1629                 :          33 :               enum conversion_safety re_safety =
    1630                 :          33 :                 unsafe_conversion_p (type, TREE_REALPART (expr),
    1631                 :             :                                      result, check_sign);
    1632                 :          33 :               enum conversion_safety im_safety =
    1633                 :          33 :                 unsafe_conversion_p (type, imag_part, result, check_sign);
    1634                 :             : 
    1635                 :             :               /* Merge the results into appropriate single warning.  */
    1636                 :             : 
    1637                 :             :               /* Note: this case includes SAFE_CONVERSION, i.e. success.  */
    1638                 :          33 :               if (re_safety == im_safety)
    1639                 :             :                 give_warning = re_safety;
    1640                 :           9 :               else if (!re_safety && im_safety)
    1641                 :             :                 give_warning = im_safety;
    1642                 :           4 :               else if (re_safety && !im_safety)
    1643                 :             :                 give_warning = re_safety;
    1644                 :             :               else
    1645                 :         670 :                 give_warning = UNSAFE_OTHER;
    1646                 :             :             }
    1647                 :             :           /* Warn about conversion from complex to real or integer type.  */
    1648                 :             :           else
    1649                 :             :             give_warning = UNSAFE_IMAGINARY;
    1650                 :             :         }
    1651                 :             :     }
    1652                 :             : 
    1653                 :             :   /* Checks for remaining case: EXPR is not constant.  */
    1654                 :             :   else
    1655                 :             :     {
    1656                 :             :       /* Warn for real types converted to integer types.  */
    1657                 :        3924 :       if (SCALAR_FLOAT_TYPE_P (expr_type)
    1658                 :         213 :           && (TREE_CODE (type) == INTEGER_TYPE
    1659                 :         213 :               || TREE_CODE (type) == BITINT_TYPE))
    1660                 :             :         give_warning = UNSAFE_REAL;
    1661                 :             : 
    1662                 :        3895 :       else if ((TREE_CODE (expr_type) == INTEGER_TYPE
    1663                 :        3895 :                 || TREE_CODE (expr_type) == BITINT_TYPE)
    1664                 :        3500 :                && (TREE_CODE (type) == INTEGER_TYPE
    1665                 :        3500 :                    || TREE_CODE (type) == BITINT_TYPE))
    1666                 :             :         {
    1667                 :             :           /* Don't warn about unsigned char y = 0xff, x = (int) y;  */
    1668                 :        3279 :           expr = get_unwidened (expr, 0);
    1669                 :        3279 :           expr_type = TREE_TYPE (expr);
    1670                 :             : 
    1671                 :             :           /* Don't warn for short y; short x = ((int)y & 0xff);  */
    1672                 :        3279 :           if (TREE_CODE (expr) == BIT_AND_EXPR
    1673                 :        3265 :               || TREE_CODE (expr) == BIT_IOR_EXPR
    1674                 :        3224 :               || TREE_CODE (expr) == BIT_XOR_EXPR)
    1675                 :             :             {
    1676                 :             :               /* If both args were extended from a shortest type,
    1677                 :             :                  use that type if that is safe.  */
    1678                 :          59 :               expr_type = shorten_binary_op (expr_type,
    1679                 :          59 :                                              TREE_OPERAND (expr, 0),
    1680                 :          59 :                                              TREE_OPERAND (expr, 1),
    1681                 :             :                                              /* bitwise */1);
    1682                 :             : 
    1683                 :          59 :               if (TREE_CODE (expr) == BIT_AND_EXPR)
    1684                 :             :                 {
    1685                 :          14 :                   tree op0 = TREE_OPERAND (expr, 0);
    1686                 :          14 :                   tree op1 = TREE_OPERAND (expr, 1);
    1687                 :          14 :                   bool unsigned0 = TYPE_UNSIGNED (TREE_TYPE (op0));
    1688                 :          14 :                   bool unsigned1 = TYPE_UNSIGNED (TREE_TYPE (op1));
    1689                 :             : 
    1690                 :             :                   /* If one of the operands is a non-negative constant
    1691                 :             :                      that fits in the target type, then the type of the
    1692                 :             :                      other operand does not matter. */
    1693                 :          14 :                   if ((TREE_CODE (op0) == INTEGER_CST
    1694                 :           0 :                        && int_fits_type_p (op0, c_common_signed_type (type))
    1695                 :           0 :                        && int_fits_type_p (op0, c_common_unsigned_type (type)))
    1696                 :          14 :                       || (TREE_CODE (op1) == INTEGER_CST
    1697                 :           1 :                           && int_fits_type_p (op1, c_common_signed_type (type))
    1698                 :           1 :                           && int_fits_type_p (op1,
    1699                 :           1 :                                               c_common_unsigned_type (type))))
    1700                 :           1 :                     return SAFE_CONVERSION;
    1701                 :             :                   /* If constant is unsigned and fits in the target
    1702                 :             :                      type, then the result will also fit.  */
    1703                 :          13 :                   else if ((TREE_CODE (op0) == INTEGER_CST
    1704                 :           0 :                             && unsigned0
    1705                 :           0 :                             && int_fits_type_p (op0, type))
    1706                 :          13 :                            || (TREE_CODE (op1) == INTEGER_CST
    1707                 :           0 :                                && unsigned1
    1708                 :           0 :                                && int_fits_type_p (op1, type)))
    1709                 :             :                     return SAFE_CONVERSION;
    1710                 :             :                 }
    1711                 :             :             }
    1712                 :             :           /* Warn for integer types converted to smaller integer types.  */
    1713                 :        3278 :           if (TYPE_PRECISION (type) < TYPE_PRECISION (expr_type))
    1714                 :             :             give_warning = UNSAFE_OTHER;
    1715                 :             : 
    1716                 :             :           /* When they are the same width but different signedness,
    1717                 :             :              then the value may change.  */
    1718                 :        2742 :           else if (((TYPE_PRECISION (type) == TYPE_PRECISION (expr_type)
    1719                 :        2213 :                      && TYPE_UNSIGNED (expr_type) != TYPE_UNSIGNED (type))
    1720                 :             :                     /* Even when converted to a bigger type, if the type is
    1721                 :             :                        unsigned but expr is signed, then negative values
    1722                 :             :                        will be changed.  */
    1723                 :        1481 :                     || (TYPE_UNSIGNED (type) && !TYPE_UNSIGNED (expr_type)))
    1724                 :        4054 :                    && check_sign)
    1725                 :             :             give_warning = UNSAFE_SIGN;
    1726                 :             :         }
    1727                 :             : 
    1728                 :             :       /* Warn for integer types converted to real types if and only if
    1729                 :             :          all the range of values of the integer type cannot be
    1730                 :             :          represented by the real type.  */
    1731                 :         616 :       else if ((TREE_CODE (expr_type) == INTEGER_TYPE
    1732                 :             :                 || TREE_CODE (expr_type) == BITINT_TYPE)
    1733                 :         221 :                && SCALAR_FLOAT_TYPE_P (type))
    1734                 :             :         {
    1735                 :             :           /* Don't warn about char y = 0xff; float x = (int) y;  */
    1736                 :         101 :           expr = get_unwidened (expr, 0);
    1737                 :         101 :           expr_type = TREE_TYPE (expr);
    1738                 :             : 
    1739                 :         101 :           if (!int_safely_convertible_to_real_p (expr_type, type))
    1740                 :         670 :             give_warning = UNSAFE_OTHER;
    1741                 :             :         }
    1742                 :             : 
    1743                 :             :       /* Warn for real types converted to smaller real types.  */
    1744                 :         515 :       else if (SCALAR_FLOAT_TYPE_P (expr_type)
    1745                 :         184 :                && SCALAR_FLOAT_TYPE_P (type)
    1746                 :         699 :                && TYPE_PRECISION (type) < TYPE_PRECISION (expr_type))
    1747                 :             :         give_warning = UNSAFE_REAL;
    1748                 :             : 
    1749                 :             :       /* Check conversion between two complex types.  */
    1750                 :         463 :       else if (TREE_CODE (expr_type) == COMPLEX_TYPE
    1751                 :          32 :                && TREE_CODE (type) == COMPLEX_TYPE)
    1752                 :             :         {
    1753                 :             :           /* Extract underlying types (i.e., type of real and imaginary
    1754                 :             :              parts) of expr_type and type.  */
    1755                 :          10 :           tree from_type = TREE_TYPE (expr_type);
    1756                 :          10 :           tree to_type = TREE_TYPE (type);
    1757                 :             : 
    1758                 :             :           /* Warn for real types converted to integer types.  */
    1759                 :          10 :           if (SCALAR_FLOAT_TYPE_P (from_type)
    1760                 :           8 :               && TREE_CODE (to_type) == INTEGER_TYPE)
    1761                 :             :             give_warning = UNSAFE_REAL;
    1762                 :             : 
    1763                 :             :           /* Warn for real types converted to smaller real types.  */
    1764                 :           6 :           else if (SCALAR_FLOAT_TYPE_P (from_type)
    1765                 :           4 :                    && SCALAR_FLOAT_TYPE_P (to_type)
    1766                 :          10 :                    && TYPE_PRECISION (to_type) < TYPE_PRECISION (from_type))
    1767                 :             :             give_warning = UNSAFE_REAL;
    1768                 :             : 
    1769                 :             :           /* Check conversion for complex integer types.  Here implementation
    1770                 :             :              is simpler than for real-domain integers because it does not
    1771                 :             :              involve sophisticated cases, such as bitmasks, casts, etc.  */
    1772                 :           4 :           else if (TREE_CODE (from_type) == INTEGER_TYPE
    1773                 :           2 :                    && TREE_CODE (to_type) == INTEGER_TYPE)
    1774                 :             :             {
    1775                 :             :               /* Warn for integer types converted to smaller integer types.  */
    1776                 :           2 :               if (TYPE_PRECISION (to_type) < TYPE_PRECISION (from_type))
    1777                 :             :                 give_warning = UNSAFE_OTHER;
    1778                 :             : 
    1779                 :             :               /* Check for different signedness, see case for real-domain
    1780                 :             :                  integers (above) for a more detailed comment.  */
    1781                 :           0 :               else if (((TYPE_PRECISION (to_type) == TYPE_PRECISION (from_type)
    1782                 :           0 :                          && TYPE_UNSIGNED (to_type) != TYPE_UNSIGNED (from_type))
    1783                 :           0 :                         || (TYPE_UNSIGNED (to_type) && !TYPE_UNSIGNED (from_type)))
    1784                 :           0 :                        && check_sign)
    1785                 :             :                 give_warning = UNSAFE_SIGN;
    1786                 :             :             }
    1787                 :           2 :           else if (TREE_CODE (from_type) == INTEGER_TYPE
    1788                 :           0 :                    && SCALAR_FLOAT_TYPE_P (to_type)
    1789                 :           2 :                    && !int_safely_convertible_to_real_p (from_type, to_type))
    1790                 :             :             give_warning = UNSAFE_OTHER;
    1791                 :             :         }
    1792                 :             : 
    1793                 :             :       /* Warn for complex types converted to real or integer types.  */
    1794                 :         453 :       else if (TREE_CODE (expr_type) == COMPLEX_TYPE
    1795                 :          22 :                && TREE_CODE (type) != COMPLEX_TYPE)
    1796                 :          28 :         give_warning = UNSAFE_IMAGINARY;
    1797                 :             :     }
    1798                 :             : 
    1799                 :             :   return give_warning;
    1800                 :             : }
    1801                 :             : 
    1802                 :             : 
    1803                 :             : /* Convert EXPR to TYPE, warning about conversion problems with constants.
    1804                 :             :    Invoke this function on every expression that is converted implicitly,
    1805                 :             :    i.e. because of language rules and not because of an explicit cast.
    1806                 :             :    INIT_CONST is true if the conversion is for arithmetic types for a static
    1807                 :             :    initializer and folding must apply accordingly (discarding floating-point
    1808                 :             :    exceptions and assuming the default rounding mode is in effect).  */
    1809                 :             : 
    1810                 :             : tree
    1811                 :    12372744 : convert_and_check (location_t loc, tree type, tree expr, bool init_const)
    1812                 :             : {
    1813                 :    12372744 :   tree result;
    1814                 :    12372744 :   tree expr_for_warning;
    1815                 :             : 
    1816                 :             :   /* Convert from a value with possible excess precision rather than
    1817                 :             :      via the semantic type, but do not warn about values not fitting
    1818                 :             :      exactly in the semantic type.  */
    1819                 :    12372744 :   if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
    1820                 :             :     {
    1821                 :        5963 :       tree orig_type = TREE_TYPE (expr);
    1822                 :        5963 :       expr = TREE_OPERAND (expr, 0);
    1823                 :        5963 :       expr_for_warning = (init_const
    1824                 :        5963 :                           ? convert_init (orig_type, expr)
    1825                 :        5602 :                           : convert (orig_type, expr));
    1826                 :        5963 :       if (orig_type == type)
    1827                 :             :         return expr_for_warning;
    1828                 :             :     }
    1829                 :             :   else
    1830                 :             :     expr_for_warning = expr;
    1831                 :             : 
    1832                 :    12367274 :   if (TREE_TYPE (expr) == type)
    1833                 :             :     return expr;
    1834                 :             : 
    1835                 :    10938647 :   result = init_const ? convert_init (type, expr) : convert (type, expr);
    1836                 :             : 
    1837                 :    10938647 :   if (c_inhibit_evaluation_warnings == 0
    1838                 :    10612262 :       && !TREE_OVERFLOW_P (expr)
    1839                 :    10612236 :       && result != error_mark_node
    1840                 :    21550729 :       && !c_hardbool_type_attr (type))
    1841                 :    10604739 :     warnings_for_convert_and_check (loc, type, expr_for_warning, result);
    1842                 :             : 
    1843                 :             :   return result;
    1844                 :             : }
    1845                 :             : 
    1846                 :             : /* A node in a list that describes references to variables (EXPR), which are
    1847                 :             :    either read accesses if WRITER is zero, or write accesses, in which case
    1848                 :             :    WRITER is the parent of EXPR.  */
    1849                 :             : struct tlist
    1850                 :             : {
    1851                 :             :   struct tlist *next;
    1852                 :             :   tree expr, writer;
    1853                 :             : };
    1854                 :             : 
    1855                 :             : /* Used to implement a cache the results of a call to verify_tree.  We only
    1856                 :             :    use this for SAVE_EXPRs.  */
    1857                 :             : struct tlist_cache
    1858                 :             : {
    1859                 :             :   struct tlist_cache *next;
    1860                 :             :   struct tlist *cache_before_sp;
    1861                 :             :   struct tlist *cache_after_sp;
    1862                 :             :   tree expr;
    1863                 :             : };
    1864                 :             : 
    1865                 :             : /* Obstack to use when allocating tlist structures, and corresponding
    1866                 :             :    firstobj.  */
    1867                 :             : static struct obstack tlist_obstack;
    1868                 :             : static char *tlist_firstobj = 0;
    1869                 :             : 
    1870                 :             : /* Keep track of the identifiers we've warned about, so we can avoid duplicate
    1871                 :             :    warnings.  */
    1872                 :             : static struct tlist *warned_ids;
    1873                 :             : /* SAVE_EXPRs need special treatment.  We process them only once and then
    1874                 :             :    cache the results.  */
    1875                 :             : static struct tlist_cache *save_expr_cache;
    1876                 :             : 
    1877                 :             : static void add_tlist (struct tlist **, struct tlist *, tree, int);
    1878                 :             : static void merge_tlist (struct tlist **, struct tlist *, int);
    1879                 :             : static void verify_tree (tree, struct tlist **, struct tlist **, tree);
    1880                 :             : static bool warning_candidate_p (tree);
    1881                 :             : static bool candidate_equal_p (const_tree, const_tree);
    1882                 :             : static void warn_for_collisions (struct tlist *);
    1883                 :             : static void warn_for_collisions_1 (tree, tree, struct tlist *, int);
    1884                 :             : static struct tlist *new_tlist (struct tlist *, tree, tree);
    1885                 :             : 
    1886                 :             : /* Create a new struct tlist and fill in its fields.  */
    1887                 :             : static struct tlist *
    1888                 :    34336207 : new_tlist (struct tlist *next, tree t, tree writer)
    1889                 :             : {
    1890                 :    34336207 :   struct tlist *l;
    1891                 :    34336207 :   l = XOBNEW (&tlist_obstack, struct tlist);
    1892                 :    34336207 :   l->next = next;
    1893                 :    34336207 :   l->expr = t;
    1894                 :    34336207 :   l->writer = writer;
    1895                 :    34336207 :   return l;
    1896                 :             : }
    1897                 :             : 
    1898                 :             : /* Add duplicates of the nodes found in ADD to the list *TO.  If EXCLUDE_WRITER
    1899                 :             :    is nonnull, we ignore any node we find which has a writer equal to it.  */
    1900                 :             : 
    1901                 :             : static void
    1902                 :    60667289 : add_tlist (struct tlist **to, struct tlist *add, tree exclude_writer, int copy)
    1903                 :             : {
    1904                 :   131874486 :   while (add)
    1905                 :             :     {
    1906                 :    71207197 :       struct tlist *next = add->next;
    1907                 :    13101798 :       if (!copy)
    1908                 :     1866065 :         add->next = *to;
    1909                 :    13101798 :       if (!exclude_writer || !candidate_equal_p (add->writer, exclude_writer))
    1910                 :    69198317 :         *to = copy ? new_tlist (*to, add->expr, add->writer) : add;
    1911                 :             :       add = next;
    1912                 :             :     }
    1913                 :    11804773 : }
    1914                 :             : 
    1915                 :             : /* Merge the nodes of ADD into TO.  This merging process is done so that for
    1916                 :             :    each variable that already exists in TO, no new node is added; however if
    1917                 :             :    there is a write access recorded in ADD, and an occurrence on TO is only
    1918                 :             :    a read access, then the occurrence in TO will be modified to record the
    1919                 :             :    write.  */
    1920                 :             : 
    1921                 :             : static void
    1922                 :    42407070 : merge_tlist (struct tlist **to, struct tlist *add, int copy)
    1923                 :             : {
    1924                 :    42407070 :   struct tlist **end = to;
    1925                 :             : 
    1926                 :    79122173 :   while (*end)
    1927                 :    36715103 :     end = &(*end)->next;
    1928                 :             : 
    1929                 :    58215900 :   while (add)
    1930                 :             :     {
    1931                 :    15808830 :       int found = 0;
    1932                 :    15808830 :       struct tlist *tmp2;
    1933                 :    15808830 :       struct tlist *next = add->next;
    1934                 :             : 
    1935                 :    43135762 :       for (tmp2 = *to; tmp2; tmp2 = tmp2->next)
    1936                 :    27326932 :         if (candidate_equal_p (tmp2->expr, add->expr))
    1937                 :             :           {
    1938                 :     2706828 :             found = 1;
    1939                 :     2706828 :             if (!tmp2->writer)
    1940                 :     2700402 :               tmp2->writer = add->writer;
    1941                 :             :           }
    1942                 :    15808830 :       if (!found)
    1943                 :             :         {
    1944                 :    13115678 :           *end = copy ? new_tlist (NULL, add->expr, add->writer) : add;
    1945                 :    13115678 :           end = &(*end)->next;
    1946                 :    13115678 :           *end = 0;
    1947                 :             :         }
    1948                 :             :       add = next;
    1949                 :             :     }
    1950                 :    42407070 : }
    1951                 :             : 
    1952                 :             : /* WRITTEN is a variable, WRITER is its parent.  Warn if any of the variable
    1953                 :             :    references in list LIST conflict with it, excluding reads if ONLY writers
    1954                 :             :    is nonzero.  */
    1955                 :             : 
    1956                 :             : static void
    1957                 :     5232783 : warn_for_collisions_1 (tree written, tree writer, struct tlist *list,
    1958                 :             :                        int only_writes)
    1959                 :             : {
    1960                 :     5232783 :   struct tlist *tmp;
    1961                 :             : 
    1962                 :             :   /* Avoid duplicate warnings.  */
    1963                 :     5232946 :   for (tmp = warned_ids; tmp; tmp = tmp->next)
    1964                 :         611 :     if (candidate_equal_p (tmp->expr, written))
    1965                 :             :       return;
    1966                 :             : 
    1967                 :    18795946 :   while (list)
    1968                 :             :     {
    1969                 :    13563611 :       if (candidate_equal_p (list->expr, written)
    1970                 :     1534310 :           && !candidate_equal_p (list->writer, writer)
    1971                 :    13703084 :           && (!only_writes || list->writer))
    1972                 :             :         {
    1973                 :         562 :           warned_ids = new_tlist (warned_ids, written, NULL_TREE);
    1974                 :         562 :           warning_at (EXPR_LOC_OR_LOC (writer, input_location),
    1975                 :         562 :                       OPT_Wsequence_point, "operation on %qE may be undefined",
    1976                 :             :                       list->expr);
    1977                 :             :         }
    1978                 :    13563611 :       list = list->next;
    1979                 :             :     }
    1980                 :             : }
    1981                 :             : 
    1982                 :             : /* Given a list LIST of references to variables, find whether any of these
    1983                 :             :    can cause conflicts due to missing sequence points.  */
    1984                 :             : 
    1985                 :             : static void
    1986                 :    19966799 : warn_for_collisions (struct tlist *list)
    1987                 :             : {
    1988                 :    19966799 :   struct tlist *tmp;
    1989                 :             : 
    1990                 :    54992338 :   for (tmp = list; tmp; tmp = tmp->next)
    1991                 :             :     {
    1992                 :    35025539 :       if (tmp->writer)
    1993                 :     1330740 :         warn_for_collisions_1 (tmp->expr, tmp->writer, list, 0);
    1994                 :             :     }
    1995                 :    19966799 : }
    1996                 :             : 
    1997                 :             : /* Return nonzero if X is a tree that can be verified by the sequence point
    1998                 :             :    warnings.  */
    1999                 :             : 
    2000                 :             : static bool
    2001                 :    76530485 : warning_candidate_p (tree x)
    2002                 :             : {
    2003                 :    76530485 :   if (DECL_P (x) && DECL_ARTIFICIAL (x))
    2004                 :             :     return false;
    2005                 :             : 
    2006                 :    68847737 :   if (TREE_CODE (x) == BLOCK)
    2007                 :             :     return false;
    2008                 :             : 
    2009                 :             :   /* VOID_TYPE_P (TREE_TYPE (x)) is workaround for cp/tree.cc
    2010                 :             :      (lvalue_p) crash on TRY/CATCH. */
    2011                 :    68845606 :   if (TREE_TYPE (x) == NULL_TREE || VOID_TYPE_P (TREE_TYPE (x)))
    2012                 :             :     return false;
    2013                 :             : 
    2014                 :    67914848 :   if (!lvalue_p (x))
    2015                 :             :     return false;
    2016                 :             : 
    2017                 :             :   /* No point to track non-const calls, they will never satisfy
    2018                 :             :      operand_equal_p.  */
    2019                 :    24432086 :   if (TREE_CODE (x) == CALL_EXPR && (call_expr_flags (x) & ECF_CONST) == 0)
    2020                 :             :     return false;
    2021                 :             : 
    2022                 :    24390252 :   if (TREE_CODE (x) == STRING_CST)
    2023                 :             :     return false;
    2024                 :             : 
    2025                 :             :   return true;
    2026                 :             : }
    2027                 :             : 
    2028                 :             : /* Return nonzero if X and Y appear to be the same candidate (or NULL) */
    2029                 :             : static bool
    2030                 :    46211388 : candidate_equal_p (const_tree x, const_tree y)
    2031                 :             : {
    2032                 :    46211388 :   return (x == y) || (x && y && operand_equal_p (x, y, 0));
    2033                 :             : }
    2034                 :             : 
    2035                 :             : /* Walk the tree X, and record accesses to variables.  If X is written by the
    2036                 :             :    parent tree, WRITER is the parent.
    2037                 :             :    We store accesses in one of the two lists: PBEFORE_SP, and PNO_SP.  If this
    2038                 :             :    expression or its only operand forces a sequence point, then everything up
    2039                 :             :    to the sequence point is stored in PBEFORE_SP.  Everything else gets stored
    2040                 :             :    in PNO_SP.
    2041                 :             :    Once we return, we will have emitted warnings if any subexpression before
    2042                 :             :    such a sequence point could be undefined.  On a higher level, however, the
    2043                 :             :    sequence point may not be relevant, and we'll merge the two lists.
    2044                 :             : 
    2045                 :             :    Example: (b++, a) + b;
    2046                 :             :    The call that processes the COMPOUND_EXPR will store the increment of B
    2047                 :             :    in PBEFORE_SP, and the use of A in PNO_SP.  The higher-level call that
    2048                 :             :    processes the PLUS_EXPR will need to merge the two lists so that
    2049                 :             :    eventually, all accesses end up on the same list (and we'll warn about the
    2050                 :             :    unordered subexpressions b++ and b.
    2051                 :             : 
    2052                 :             :    A note on merging.  If we modify the former example so that our expression
    2053                 :             :    becomes
    2054                 :             :      (b++, b) + a
    2055                 :             :    care must be taken not simply to add all three expressions into the final
    2056                 :             :    PNO_SP list.  The function merge_tlist takes care of that by merging the
    2057                 :             :    before-SP list of the COMPOUND_EXPR into its after-SP list in a special
    2058                 :             :    way, so that no more than one access to B is recorded.  */
    2059                 :             : 
    2060                 :             : static void
    2061                 :    60140847 : verify_tree (tree x, struct tlist **pbefore_sp, struct tlist **pno_sp,
    2062                 :             :              tree writer)
    2063                 :             : {
    2064                 :    73824505 :   struct tlist *tmp_before, *tmp_nosp, *tmp_list2, *tmp_list3;
    2065                 :    73824505 :   enum tree_code code;
    2066                 :    73824505 :   enum tree_code_class cl;
    2067                 :             : 
    2068                 :    73824505 :  restart:
    2069                 :             :   /* X may be NULL if it is the operand of an empty statement expression
    2070                 :             :      ({ }).  */
    2071                 :    73824505 :   if (x == NULL)
    2072                 :             :     return;
    2073                 :             : 
    2074                 :    72628442 :   code = TREE_CODE (x);
    2075                 :    72628442 :   cl = TREE_CODE_CLASS (code);
    2076                 :             : 
    2077                 :    72628442 :   if (warning_candidate_p (x))
    2078                 :    23159504 :     *pno_sp = new_tlist (*pno_sp, x, writer);
    2079                 :             : 
    2080                 :    72628442 :   switch (code)
    2081                 :             :     {
    2082                 :             :     case CONSTRUCTOR:
    2083                 :             :     case SIZEOF_EXPR:
    2084                 :             :     case PAREN_SIZEOF_EXPR:
    2085                 :             :       return;
    2086                 :             : 
    2087                 :      202622 :     case COMPOUND_EXPR:
    2088                 :      202622 :     case TRUTH_ANDIF_EXPR:
    2089                 :      202622 :     case TRUTH_ORIF_EXPR:
    2090                 :      202622 :     sequenced_binary:
    2091                 :      202622 :       tmp_before = tmp_nosp = tmp_list2 = tmp_list3 = 0;
    2092                 :      202622 :       verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_nosp, NULL_TREE);
    2093                 :      202622 :       warn_for_collisions (tmp_nosp);
    2094                 :      202622 :       merge_tlist (pbefore_sp, tmp_before, 0);
    2095                 :      202622 :       merge_tlist (pbefore_sp, tmp_nosp, 0);
    2096                 :      202622 :       verify_tree (TREE_OPERAND (x, 1), &tmp_list3, &tmp_list2, NULL_TREE);
    2097                 :      202622 :       warn_for_collisions (tmp_list2);
    2098                 :      202622 :       merge_tlist (pbefore_sp, tmp_list3, 0);
    2099                 :      202622 :       merge_tlist (pno_sp, tmp_list2, 0);
    2100                 :      202622 :       return;
    2101                 :             : 
    2102                 :       67417 :     case COND_EXPR:
    2103                 :       67417 :       tmp_before = tmp_list2 = 0;
    2104                 :       67417 :       verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_list2, NULL_TREE);
    2105                 :       67417 :       warn_for_collisions (tmp_list2);
    2106                 :       67417 :       merge_tlist (pbefore_sp, tmp_before, 0);
    2107                 :       67417 :       merge_tlist (pbefore_sp, tmp_list2, 0);
    2108                 :             : 
    2109                 :       67417 :       tmp_list3 = tmp_nosp = 0;
    2110                 :       67417 :       verify_tree (TREE_OPERAND (x, 1), &tmp_list3, &tmp_nosp, NULL_TREE);
    2111                 :       67417 :       warn_for_collisions (tmp_nosp);
    2112                 :       67417 :       merge_tlist (pbefore_sp, tmp_list3, 0);
    2113                 :             : 
    2114                 :       67417 :       tmp_list3 = tmp_list2 = 0;
    2115                 :       67417 :       verify_tree (TREE_OPERAND (x, 2), &tmp_list3, &tmp_list2, NULL_TREE);
    2116                 :       67417 :       warn_for_collisions (tmp_list2);
    2117                 :       67417 :       merge_tlist (pbefore_sp, tmp_list3, 0);
    2118                 :             :       /* Rather than add both tmp_nosp and tmp_list2, we have to merge the
    2119                 :             :          two first, to avoid warning for (a ? b++ : b++).  */
    2120                 :       67417 :       merge_tlist (&tmp_nosp, tmp_list2, 0);
    2121                 :       67417 :       add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0);
    2122                 :             :       return;
    2123                 :             : 
    2124                 :      267993 :     case PREDECREMENT_EXPR:
    2125                 :      267993 :     case PREINCREMENT_EXPR:
    2126                 :      267993 :     case POSTDECREMENT_EXPR:
    2127                 :      267993 :     case POSTINCREMENT_EXPR:
    2128                 :      267993 :       verify_tree (TREE_OPERAND (x, 0), pno_sp, pno_sp, x);
    2129                 :      267993 :       return;
    2130                 :             : 
    2131                 :     3902043 :     case MODIFY_EXPR:
    2132                 :     3902043 :       tmp_before = tmp_nosp = tmp_list3 = 0;
    2133                 :     3902043 :       verify_tree (TREE_OPERAND (x, 1), &tmp_before, &tmp_nosp, NULL_TREE);
    2134                 :     3902043 :       verify_tree (TREE_OPERAND (x, 0), &tmp_list3, &tmp_list3, x);
    2135                 :             :       /* Expressions inside the LHS are not ordered wrt. the sequence points
    2136                 :             :          in the RHS.  Example:
    2137                 :             :            *a = (a++, 2)
    2138                 :             :          Despite the fact that the modification of "a" is in the before_sp
    2139                 :             :          list (tmp_before), it conflicts with the use of "a" in the LHS.
    2140                 :             :          We can handle this by adding the contents of tmp_list3
    2141                 :             :          to those of tmp_before, and redoing the collision warnings for that
    2142                 :             :          list.  */
    2143                 :     3902043 :       add_tlist (&tmp_before, tmp_list3, x, 1);
    2144                 :     3902043 :       warn_for_collisions (tmp_before);
    2145                 :             :       /* Exclude the LHS itself here; we first have to merge it into the
    2146                 :             :          tmp_nosp list.  This is done to avoid warning for "a = a"; if we
    2147                 :             :          didn't exclude the LHS, we'd get it twice, once as a read and once
    2148                 :             :          as a write.  */
    2149                 :     3902043 :       add_tlist (pno_sp, tmp_list3, x, 0);
    2150                 :     3902043 :       warn_for_collisions_1 (TREE_OPERAND (x, 0), x, tmp_nosp, 1);
    2151                 :             : 
    2152                 :     3902043 :       merge_tlist (pbefore_sp, tmp_before, 0);
    2153                 :     3902043 :       if (warning_candidate_p (TREE_OPERAND (x, 0)))
    2154                 :      938235 :         merge_tlist (&tmp_nosp, new_tlist (NULL, TREE_OPERAND (x, 0), x), 0);
    2155                 :     3902043 :       add_tlist (pno_sp, tmp_nosp, NULL_TREE, 1);
    2156                 :     3902043 :       return;
    2157                 :             : 
    2158                 :     6261547 :     case CALL_EXPR:
    2159                 :             :       /* We need to warn about conflicts among arguments and conflicts between
    2160                 :             :          args and the function address.  Side effects of the function address,
    2161                 :             :          however, are not ordered by the sequence point of the call.  */
    2162                 :     6261547 :       {
    2163                 :     6261547 :         call_expr_arg_iterator iter;
    2164                 :     6261547 :         tree arg;
    2165                 :     6261547 :         tmp_before = tmp_nosp = 0;
    2166                 :     6261547 :         verify_tree (CALL_EXPR_FN (x), &tmp_before, &tmp_nosp, NULL_TREE);
    2167                 :    27791418 :         FOR_EACH_CALL_EXPR_ARG (arg, iter, x)
    2168                 :             :           {
    2169                 :    15268324 :             tmp_list2 = tmp_list3 = 0;
    2170                 :    15268324 :             verify_tree (arg, &tmp_list2, &tmp_list3, NULL_TREE);
    2171                 :    15268324 :             merge_tlist (&tmp_list3, tmp_list2, 0);
    2172                 :    30536648 :             add_tlist (&tmp_before, tmp_list3, NULL_TREE, 0);
    2173                 :             :           }
    2174                 :     6261547 :         add_tlist (&tmp_before, tmp_nosp, NULL_TREE, 0);
    2175                 :     6261547 :         warn_for_collisions (tmp_before);
    2176                 :     6261547 :         add_tlist (pbefore_sp, tmp_before, NULL_TREE, 0);
    2177                 :     6261547 :         return;
    2178                 :             :       }
    2179                 :             : 
    2180                 :             :     case TREE_LIST:
    2181                 :             :       /* Scan all the list, e.g. indices of multi dimensional array.  */
    2182                 :           6 :       while (x)
    2183                 :             :         {
    2184                 :           3 :           tmp_before = tmp_nosp = 0;
    2185                 :           3 :           verify_tree (TREE_VALUE (x), &tmp_before, &tmp_nosp, NULL_TREE);
    2186                 :           3 :           merge_tlist (&tmp_nosp, tmp_before, 0);
    2187                 :           3 :           add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0);
    2188                 :           3 :           x = TREE_CHAIN (x);
    2189                 :             :         }
    2190                 :             :       return;
    2191                 :             : 
    2192                 :       98644 :     case SAVE_EXPR:
    2193                 :       98644 :       {
    2194                 :       98644 :         struct tlist_cache *t;
    2195                 :      102364 :         for (t = save_expr_cache; t; t = t->next)
    2196                 :       53794 :           if (candidate_equal_p (t->expr, x))
    2197                 :             :             break;
    2198                 :             : 
    2199                 :       98644 :         if (!t)
    2200                 :             :           {
    2201                 :       48570 :             t = XOBNEW (&tlist_obstack, struct tlist_cache);
    2202                 :       48570 :             t->next = save_expr_cache;
    2203                 :       48570 :             t->expr = x;
    2204                 :       48570 :             save_expr_cache = t;
    2205                 :             : 
    2206                 :       48570 :             tmp_before = tmp_nosp = 0;
    2207                 :       48570 :             verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_nosp, NULL_TREE);
    2208                 :       48570 :             warn_for_collisions (tmp_nosp);
    2209                 :             : 
    2210                 :       48570 :             tmp_list3 = 0;
    2211                 :       48570 :             merge_tlist (&tmp_list3, tmp_nosp, 0);
    2212                 :       48570 :             t->cache_before_sp = tmp_before;
    2213                 :       48570 :             t->cache_after_sp = tmp_list3;
    2214                 :             :           }
    2215                 :       98644 :         merge_tlist (pbefore_sp, t->cache_before_sp, 1);
    2216                 :       98644 :         add_tlist (pno_sp, t->cache_after_sp, NULL_TREE, 1);
    2217                 :       98644 :         return;
    2218                 :             :       }
    2219                 :             : 
    2220                 :     7115056 :     case ADDR_EXPR:
    2221                 :     7115056 :       x = TREE_OPERAND (x, 0);
    2222                 :     7115056 :       if (DECL_P (x))
    2223                 :             :         return;
    2224                 :      501533 :       writer = 0;
    2225                 :      501533 :       goto restart;
    2226                 :             : 
    2227                 :    12010342 :     case VIEW_CONVERT_EXPR:
    2228                 :    12010342 :       if (location_wrapper_p (x))
    2229                 :             :         {
    2230                 :     2983180 :           x = TREE_OPERAND (x, 0);
    2231                 :     2983180 :           goto restart;
    2232                 :             :         }
    2233                 :     9027162 :       goto do_default;
    2234                 :             : 
    2235                 :      625025 :     case LSHIFT_EXPR:
    2236                 :      625025 :     case RSHIFT_EXPR:
    2237                 :      625025 :     case ARRAY_REF:
    2238                 :      625025 :       if (cxx_dialect >= cxx17)
    2239                 :       48787 :         goto sequenced_binary;
    2240                 :      576238 :       goto do_default;
    2241                 :             : 
    2242                 :     1292120 :     case COMPONENT_REF:
    2243                 :             :       /* Treat as unary, the other operands aren't evaluated.  */
    2244                 :     1292120 :       x = TREE_OPERAND (x, 0);
    2245                 :     1292120 :       writer = 0;
    2246                 :     1292120 :       goto restart;
    2247                 :             : 
    2248                 :    49957716 :     default:
    2249                 :    49957716 :     do_default:
    2250                 :             :       /* For other expressions, simply recurse on their operands.
    2251                 :             :          Manual tail recursion for unary expressions.
    2252                 :             :          Other non-expressions need not be processed.  */
    2253                 :    49957716 :       if (cl == tcc_unary)
    2254                 :             :         {
    2255                 :     8638832 :           x = TREE_OPERAND (x, 0);
    2256                 :     8638832 :           writer = 0;
    2257                 :     8638832 :           goto restart;
    2258                 :             :         }
    2259                 :    41318884 :       else if (IS_EXPR_CODE_CLASS (cl))
    2260                 :             :         {
    2261                 :    15080934 :           int lp;
    2262                 :    15080934 :           int max = TREE_OPERAND_LENGTH (x);
    2263                 :    51165546 :           for (lp = 0; lp < max; lp++)
    2264                 :             :             {
    2265                 :    21003678 :               tmp_before = tmp_nosp = 0;
    2266                 :    21003678 :               verify_tree (TREE_OPERAND (x, lp), &tmp_before, &tmp_nosp, 0);
    2267                 :    21003678 :               merge_tlist (&tmp_nosp, tmp_before, 0);
    2268                 :    42007356 :               add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0);
    2269                 :             :             }
    2270                 :             :         }
    2271                 :             :       return;
    2272                 :             :     }
    2273                 :             : }
    2274                 :             : 
    2275                 :             : static constexpr size_t verify_sequence_points_limit = 1024;
    2276                 :             : 
    2277                 :             : /* Called from verify_sequence_points via walk_tree.  */
    2278                 :             : 
    2279                 :             : static tree
    2280                 :    89895023 : verify_tree_lim_r (tree *tp, int *walk_subtrees, void *data)
    2281                 :             : {
    2282                 :    89895023 :   if (++*((size_t *) data) > verify_sequence_points_limit)
    2283                 :          57 :     return integer_zero_node;
    2284                 :             : 
    2285                 :    89894966 :   if (TYPE_P (*tp))
    2286                 :        5866 :     *walk_subtrees = 0;
    2287                 :             : 
    2288                 :             :   return NULL_TREE;
    2289                 :             : }
    2290                 :             : 
    2291                 :             : /* Try to warn for undefined behavior in EXPR due to missing sequence
    2292                 :             :    points.  */
    2293                 :             : 
    2294                 :             : void
    2295                 :     9147201 : verify_sequence_points (tree expr)
    2296                 :             : {
    2297                 :     9147201 :   tlist *before_sp = nullptr, *after_sp = nullptr;
    2298                 :             : 
    2299                 :             :   /* verify_tree is highly recursive, and merge_tlist is O(n^2),
    2300                 :             :      so we return early if the expression is too big.  */
    2301                 :     9147201 :   size_t n = 0;
    2302                 :     9147201 :   if (walk_tree (&expr, verify_tree_lim_r, &n, nullptr))
    2303                 :          57 :     return;
    2304                 :             : 
    2305                 :     9147144 :   warned_ids = nullptr;
    2306                 :     9147144 :   save_expr_cache = nullptr;
    2307                 :     9147144 :   if (!tlist_firstobj)
    2308                 :             :     {
    2309                 :        9884 :       gcc_obstack_init (&tlist_obstack);
    2310                 :        9884 :       tlist_firstobj = (char *) obstack_alloc (&tlist_obstack, 0);
    2311                 :             :     }
    2312                 :             : 
    2313                 :     9147144 :   verify_tree (expr, &before_sp, &after_sp, NULL_TREE);
    2314                 :     9147144 :   warn_for_collisions (after_sp);
    2315                 :     9147144 :   obstack_free (&tlist_obstack, tlist_firstobj);
    2316                 :             : }
    2317                 :             : 
    2318                 :             : /* Validate the expression after `case' and apply default promotions.  */
    2319                 :             : 
    2320                 :             : static tree
    2321                 :     2719313 : check_case_value (location_t loc, tree value)
    2322                 :             : {
    2323                 :     2719313 :   if (value == NULL_TREE)
    2324                 :             :     return value;
    2325                 :             : 
    2326                 :     4535099 :   if (INTEGRAL_TYPE_P (TREE_TYPE (value))
    2327                 :     4534996 :       && TREE_CODE (value) == INTEGER_CST)
    2328                 :             :     /* Promote char or short to int.  */
    2329                 :     2719162 :     value = perform_integral_promotions (value);
    2330                 :         151 :   else if (value != error_mark_node)
    2331                 :             :     {
    2332                 :          53 :       error_at (loc, "case label does not reduce to an integer constant");
    2333                 :          53 :       value = error_mark_node;
    2334                 :             :     }
    2335                 :             : 
    2336                 :     2719313 :   constant_expression_warning (value);
    2337                 :             : 
    2338                 :     2719313 :   return value;
    2339                 :             : }
    2340                 :             : 
    2341                 :             : /* Return an integer type with BITS bits of precision,
    2342                 :             :    that is unsigned if UNSIGNEDP is nonzero, otherwise signed.  */
    2343                 :             : 
    2344                 :             : tree
    2345                 :    28468862 : c_common_type_for_size (unsigned int bits, int unsignedp)
    2346                 :             : {
    2347                 :    28468862 :   int i;
    2348                 :             : 
    2349                 :    28468862 :   if (bits == TYPE_PRECISION (integer_type_node))
    2350                 :    18856069 :     return unsignedp ? unsigned_type_node : integer_type_node;
    2351                 :             : 
    2352                 :     9612793 :   if (bits == TYPE_PRECISION (signed_char_type_node))
    2353                 :     2608866 :     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
    2354                 :             : 
    2355                 :     7003927 :   if (bits == TYPE_PRECISION (short_integer_type_node))
    2356                 :      388709 :     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
    2357                 :             : 
    2358                 :     6615218 :   if (bits == TYPE_PRECISION (long_integer_type_node))
    2359                 :     5944548 :     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
    2360                 :             : 
    2361                 :      670670 :   if (bits == TYPE_PRECISION (long_long_integer_type_node))
    2362                 :        8626 :     return (unsignedp ? long_long_unsigned_type_node
    2363                 :        7897 :             : long_long_integer_type_node);
    2364                 :             : 
    2365                 :     1038389 :   for (i = 0; i < NUM_INT_N_ENTS; i ++)
    2366                 :      662044 :     if (int_n_enabled_p[i]
    2367                 :      655479 :         && bits == int_n_data[i].bitsize)
    2368                 :      285699 :       return (unsignedp ? int_n_trees[i].unsigned_type
    2369                 :      285699 :               : int_n_trees[i].signed_type);
    2370                 :             : 
    2371                 :      376345 :   if (bits == TYPE_PRECISION (widest_integer_literal_type_node))
    2372                 :           0 :     return (unsignedp ? widest_unsigned_literal_type_node
    2373                 :           0 :             : widest_integer_literal_type_node);
    2374                 :             : 
    2375                 :     1489435 :   for (tree t = registered_builtin_types; t; t = TREE_CHAIN (t))
    2376                 :             :     {
    2377                 :     1113090 :       tree type = TREE_VALUE (t);
    2378                 :     1113090 :       if (TREE_CODE (type) == INTEGER_TYPE
    2379                 :           0 :           && bits == TYPE_PRECISION (type)
    2380                 :     1113090 :           && !!unsignedp == !!TYPE_UNSIGNED (type))
    2381                 :             :         return type;
    2382                 :             :     }
    2383                 :             : 
    2384                 :      376345 :   if (bits <= TYPE_PRECISION (intQI_type_node))
    2385                 :      315190 :     return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
    2386                 :             : 
    2387                 :       61155 :   if (bits <= TYPE_PRECISION (intHI_type_node))
    2388                 :        9631 :     return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
    2389                 :             : 
    2390                 :       51524 :   if (bits <= TYPE_PRECISION (intSI_type_node))
    2391                 :       20623 :     return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
    2392                 :             : 
    2393                 :       30901 :   if (bits <= TYPE_PRECISION (intDI_type_node))
    2394                 :       24827 :     return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
    2395                 :             : 
    2396                 :        6074 :   if (bits <= TYPE_PRECISION (widest_integer_literal_type_node))
    2397                 :          31 :     return (unsignedp ? widest_unsigned_literal_type_node
    2398                 :          14 :             : widest_integer_literal_type_node);
    2399                 :             : 
    2400                 :             :   return NULL_TREE;
    2401                 :             : }
    2402                 :             : 
    2403                 :             : /* Return a fixed-point type that has at least IBIT ibits and FBIT fbits
    2404                 :             :    that is unsigned if UNSIGNEDP is nonzero, otherwise signed;
    2405                 :             :    and saturating if SATP is nonzero, otherwise not saturating.  */
    2406                 :             : 
    2407                 :             : tree
    2408                 :           0 : c_common_fixed_point_type_for_size (unsigned int ibit, unsigned int fbit,
    2409                 :             :                                     int unsignedp, int satp)
    2410                 :             : {
    2411                 :           0 :   enum mode_class mclass;
    2412                 :           0 :   if (ibit == 0)
    2413                 :           0 :     mclass = unsignedp ? MODE_UFRACT : MODE_FRACT;
    2414                 :             :   else
    2415                 :           0 :     mclass = unsignedp ? MODE_UACCUM : MODE_ACCUM;
    2416                 :             : 
    2417                 :           0 :   opt_scalar_mode opt_mode;
    2418                 :           0 :   scalar_mode mode;
    2419                 :           0 :   FOR_EACH_MODE_IN_CLASS (opt_mode, mclass)
    2420                 :             :     {
    2421                 :           0 :       mode = opt_mode.require ();
    2422                 :           0 :       if (GET_MODE_IBIT (mode) >= ibit && GET_MODE_FBIT (mode) >= fbit)
    2423                 :             :         break;
    2424                 :             :     }
    2425                 :             : 
    2426                 :           0 :   if (!opt_mode.exists (&mode) || !targetm.scalar_mode_supported_p (mode))
    2427                 :             :     {
    2428                 :           0 :       sorry ("GCC cannot support operators with integer types and "
    2429                 :             :              "fixed-point types that have too many integral and "
    2430                 :             :              "fractional bits together");
    2431                 :           0 :       return NULL_TREE;
    2432                 :             :     }
    2433                 :             : 
    2434                 :           0 :   return c_common_type_for_mode (mode, satp);
    2435                 :             : }
    2436                 :             : 
    2437                 :             : /* Used for communication between c_common_type_for_mode and
    2438                 :             :    c_register_builtin_type.  */
    2439                 :             : tree registered_builtin_types;
    2440                 :             : 
    2441                 :             : /* Return a data type that has machine mode MODE.
    2442                 :             :    If the mode is an integer,
    2443                 :             :    then UNSIGNEDP selects between signed and unsigned types.
    2444                 :             :    If the mode is a fixed-point mode,
    2445                 :             :    then UNSIGNEDP selects between saturating and nonsaturating types.  */
    2446                 :             : 
    2447                 :             : tree
    2448                 :    12844156 : c_common_type_for_mode (machine_mode mode, int unsignedp)
    2449                 :             : {
    2450                 :    12844156 :   tree t;
    2451                 :    12844156 :   int i;
    2452                 :             : 
    2453                 :    12844156 :   if (mode == TYPE_MODE (integer_type_node))
    2454                 :     1800814 :     return unsignedp ? unsigned_type_node : integer_type_node;
    2455                 :             : 
    2456                 :    11043342 :   if (mode == TYPE_MODE (signed_char_type_node))
    2457                 :     2141860 :     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
    2458                 :             : 
    2459                 :     8901482 :   if (mode == TYPE_MODE (short_integer_type_node))
    2460                 :      121897 :     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
    2461                 :             : 
    2462                 :     8779585 :   if (mode == TYPE_MODE (long_integer_type_node))
    2463                 :     5549074 :     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
    2464                 :             : 
    2465                 :     3230511 :   if (mode == TYPE_MODE (long_long_integer_type_node))
    2466                 :       83571 :     return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node;
    2467                 :             : 
    2468                 :     4892481 :   for (i = 0; i < NUM_INT_N_ENTS; i ++)
    2469                 :     3146940 :     if (int_n_enabled_p[i]
    2470                 :     3146940 :         && mode == int_n_data[i].m)
    2471                 :     1401399 :       return (unsignedp ? int_n_trees[i].unsigned_type
    2472                 :     1401399 :               : int_n_trees[i].signed_type);
    2473                 :             : 
    2474                 :     1745541 :   if (mode == QImode)
    2475                 :           0 :     return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
    2476                 :             : 
    2477                 :     1745541 :   if (mode == HImode)
    2478                 :           0 :     return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
    2479                 :             : 
    2480                 :     1745541 :   if (mode == SImode)
    2481                 :           0 :     return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
    2482                 :             : 
    2483                 :     1745541 :   if (mode == DImode)
    2484                 :           0 :     return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
    2485                 :             : 
    2486                 :             : #if HOST_BITS_PER_WIDE_INT >= 64
    2487                 :     1745541 :   if (mode == TYPE_MODE (intTI_type_node))
    2488                 :           0 :     return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
    2489                 :             : #endif
    2490                 :             : 
    2491                 :     1745541 :   if (mode == TYPE_MODE (float_type_node))
    2492                 :       52166 :     return float_type_node;
    2493                 :             : 
    2494                 :     1693375 :   if (mode == TYPE_MODE (double_type_node))
    2495                 :       46573 :     return double_type_node;
    2496                 :             : 
    2497                 :     1646802 :   if (mode == TYPE_MODE (long_double_type_node))
    2498                 :       17605 :     return long_double_type_node;
    2499                 :             : 
    2500                 :    12402272 :   for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
    2501                 :    10925618 :     if (FLOATN_NX_TYPE_NODE (i) != NULL_TREE
    2502                 :    10925618 :         && mode == TYPE_MODE (FLOATN_NX_TYPE_NODE (i)))
    2503                 :      152543 :       return FLOATN_NX_TYPE_NODE (i);
    2504                 :             : 
    2505                 :     1476654 :   if (mode == TYPE_MODE (void_type_node))
    2506                 :           0 :     return void_type_node;
    2507                 :             : 
    2508                 :     1476654 :   if (mode == TYPE_MODE (build_pointer_type (char_type_node))
    2509                 :     1476654 :       || mode == TYPE_MODE (build_pointer_type (integer_type_node)))
    2510                 :             :     {
    2511                 :           0 :       unsigned int precision
    2512                 :           0 :         = GET_MODE_PRECISION (as_a <scalar_int_mode> (mode));
    2513                 :           0 :       return (unsignedp
    2514                 :           0 :               ? make_unsigned_type (precision)
    2515                 :           0 :               : make_signed_type (precision));
    2516                 :             :     }
    2517                 :             : 
    2518                 :     1476654 :   if (COMPLEX_MODE_P (mode))
    2519                 :             :     {
    2520                 :     1243546 :       machine_mode inner_mode;
    2521                 :     1243546 :       tree inner_type;
    2522                 :             : 
    2523                 :     1243546 :       if (mode == TYPE_MODE (complex_float_type_node))
    2524                 :      208012 :         return complex_float_type_node;
    2525                 :     1035534 :       if (mode == TYPE_MODE (complex_double_type_node))
    2526                 :      207070 :         return complex_double_type_node;
    2527                 :      828464 :       if (mode == TYPE_MODE (complex_long_double_type_node))
    2528                 :      207064 :         return complex_long_double_type_node;
    2529                 :             : 
    2530                 :     2691533 :       for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
    2531                 :     2484736 :         if (COMPLEX_FLOATN_NX_TYPE_NODE (i) != NULL_TREE
    2532                 :     2484736 :             && mode == TYPE_MODE (COMPLEX_FLOATN_NX_TYPE_NODE (i)))
    2533                 :      414603 :           return COMPLEX_FLOATN_NX_TYPE_NODE (i);
    2534                 :             : 
    2535                 :      206797 :       if (mode == TYPE_MODE (complex_integer_type_node) && !unsignedp)
    2536                 :          12 :         return complex_integer_type_node;
    2537                 :             : 
    2538                 :      206785 :       inner_mode = GET_MODE_INNER (mode);
    2539                 :      206785 :       inner_type = c_common_type_for_mode (inner_mode, unsignedp);
    2540                 :      206785 :       if (inner_type != NULL_TREE)
    2541                 :      206785 :         return build_complex_type (inner_type);
    2542                 :             :     }
    2543                 :      233108 :   else if (GET_MODE_CLASS (mode) == MODE_VECTOR_BOOL
    2544                 :      233108 :            && valid_vector_subparts_p (GET_MODE_NUNITS (mode)))
    2545                 :             :     {
    2546                 :           0 :       unsigned int elem_bits = vector_element_size (GET_MODE_PRECISION (mode),
    2547                 :             :                                                     GET_MODE_NUNITS (mode));
    2548                 :           0 :       tree bool_type = build_nonstandard_boolean_type (elem_bits);
    2549                 :           0 :       return build_vector_type_for_mode (bool_type, mode);
    2550                 :             :     }
    2551                 :      221281 :   else if (VECTOR_MODE_P (mode)
    2552                 :      246771 :            && valid_vector_subparts_p (GET_MODE_NUNITS (mode)))
    2553                 :             :     {
    2554                 :       13663 :       machine_mode inner_mode = GET_MODE_INNER (mode);
    2555                 :       13663 :       tree inner_type = c_common_type_for_mode (inner_mode, unsignedp);
    2556                 :       13663 :       if (inner_type != NULL_TREE)
    2557                 :       13663 :         return build_vector_type_for_mode (inner_type, mode);
    2558                 :             :     }
    2559                 :             : 
    2560                 :      219445 :   if (dfloat32_type_node != NULL_TREE
    2561                 :      219445 :       && mode == TYPE_MODE (dfloat32_type_node))
    2562                 :        2794 :     return dfloat32_type_node;
    2563                 :      216651 :   if (dfloat64_type_node != NULL_TREE
    2564                 :      216651 :       && mode == TYPE_MODE (dfloat64_type_node))
    2565                 :        2924 :     return dfloat64_type_node;
    2566                 :      213727 :   if (dfloat128_type_node != NULL_TREE
    2567                 :      213727 :       && mode == TYPE_MODE (dfloat128_type_node))
    2568                 :        2424 :     return dfloat128_type_node;
    2569                 :             : 
    2570                 :      211303 :   if (ALL_SCALAR_FIXED_POINT_MODE_P (mode))
    2571                 :             :     {
    2572                 :           0 :       if (mode == TYPE_MODE (short_fract_type_node))
    2573                 :           0 :         return unsignedp ? sat_short_fract_type_node : short_fract_type_node;
    2574                 :           0 :       if (mode == TYPE_MODE (fract_type_node))
    2575                 :           0 :         return unsignedp ? sat_fract_type_node : fract_type_node;
    2576                 :           0 :       if (mode == TYPE_MODE (long_fract_type_node))
    2577                 :           0 :         return unsignedp ? sat_long_fract_type_node : long_fract_type_node;
    2578                 :           0 :       if (mode == TYPE_MODE (long_long_fract_type_node))
    2579                 :           0 :         return unsignedp ? sat_long_long_fract_type_node
    2580                 :           0 :                          : long_long_fract_type_node;
    2581                 :             : 
    2582                 :           0 :       if (mode == TYPE_MODE (unsigned_short_fract_type_node))
    2583                 :           0 :         return unsignedp ? sat_unsigned_short_fract_type_node
    2584                 :           0 :                          : unsigned_short_fract_type_node;
    2585                 :           0 :       if (mode == TYPE_MODE (unsigned_fract_type_node))
    2586                 :           0 :         return unsignedp ? sat_unsigned_fract_type_node
    2587                 :           0 :                          : unsigned_fract_type_node;
    2588                 :           0 :       if (mode == TYPE_MODE (unsigned_long_fract_type_node))
    2589                 :           0 :         return unsignedp ? sat_unsigned_long_fract_type_node
    2590                 :           0 :                          : unsigned_long_fract_type_node;
    2591                 :           0 :       if (mode == TYPE_MODE (unsigned_long_long_fract_type_node))
    2592                 :           0 :         return unsignedp ? sat_unsigned_long_long_fract_type_node
    2593                 :           0 :                          : unsigned_long_long_fract_type_node;
    2594                 :             : 
    2595                 :           0 :       if (mode == TYPE_MODE (short_accum_type_node))
    2596                 :           0 :         return unsignedp ? sat_short_accum_type_node : short_accum_type_node;
    2597                 :           0 :       if (mode == TYPE_MODE (accum_type_node))
    2598                 :           0 :         return unsignedp ? sat_accum_type_node : accum_type_node;
    2599                 :           0 :       if (mode == TYPE_MODE (long_accum_type_node))
    2600                 :           0 :         return unsignedp ? sat_long_accum_type_node : long_accum_type_node;
    2601                 :           0 :       if (mode == TYPE_MODE (long_long_accum_type_node))
    2602                 :           0 :         return unsignedp ? sat_long_long_accum_type_node
    2603                 :           0 :                          : long_long_accum_type_node;
    2604                 :             : 
    2605                 :           0 :       if (mode == TYPE_MODE (unsigned_short_accum_type_node))
    2606                 :           0 :         return unsignedp ? sat_unsigned_short_accum_type_node
    2607                 :           0 :                          : unsigned_short_accum_type_node;
    2608                 :           0 :       if (mode == TYPE_MODE (unsigned_accum_type_node))
    2609                 :           0 :         return unsignedp ? sat_unsigned_accum_type_node
    2610                 :           0 :                          : unsigned_accum_type_node;
    2611                 :           0 :       if (mode == TYPE_MODE (unsigned_long_accum_type_node))
    2612                 :           0 :         return unsignedp ? sat_unsigned_long_accum_type_node
    2613                 :           0 :                          : unsigned_long_accum_type_node;
    2614                 :           0 :       if (mode == TYPE_MODE (unsigned_long_long_accum_type_node))
    2615                 :           0 :         return unsignedp ? sat_unsigned_long_long_accum_type_node
    2616                 :           0 :                          : unsigned_long_long_accum_type_node;
    2617                 :             : 
    2618                 :           0 :       if (mode == QQmode)
    2619                 :           0 :         return unsignedp ? sat_qq_type_node : qq_type_node;
    2620                 :             :       if (mode == HQmode)
    2621                 :           0 :         return unsignedp ? sat_hq_type_node : hq_type_node;
    2622                 :             :       if (mode == SQmode)
    2623                 :           0 :         return unsignedp ? sat_sq_type_node : sq_type_node;
    2624                 :             :       if (mode == DQmode)
    2625                 :           0 :         return unsignedp ? sat_dq_type_node : dq_type_node;
    2626                 :             :       if (mode == TQmode)
    2627                 :           0 :         return unsignedp ? sat_tq_type_node : tq_type_node;
    2628                 :             : 
    2629                 :             :       if (mode == UQQmode)
    2630                 :           0 :         return unsignedp ? sat_uqq_type_node : uqq_type_node;
    2631                 :             :       if (mode == UHQmode)
    2632                 :           0 :         return unsignedp ? sat_uhq_type_node : uhq_type_node;
    2633                 :             :       if (mode == USQmode)
    2634                 :           0 :         return unsignedp ? sat_usq_type_node : usq_type_node;
    2635                 :             :       if (mode == UDQmode)
    2636                 :           0 :         return unsignedp ? sat_udq_type_node : udq_type_node;
    2637                 :             :       if (mode == UTQmode)
    2638                 :           0 :         return unsignedp ? sat_utq_type_node : utq_type_node;
    2639                 :             : 
    2640                 :             :       if (mode == HAmode)
    2641                 :           0 :         return unsignedp ? sat_ha_type_node : ha_type_node;
    2642                 :             :       if (mode == SAmode)
    2643                 :           0 :         return unsignedp ? sat_sa_type_node : sa_type_node;
    2644                 :             :       if (mode == DAmode)
    2645                 :           0 :         return unsignedp ? sat_da_type_node : da_type_node;
    2646                 :             :       if (mode == TAmode)
    2647                 :           0 :         return unsignedp ? sat_ta_type_node : ta_type_node;
    2648                 :             : 
    2649                 :             :       if (mode == UHAmode)
    2650                 :           0 :         return unsignedp ? sat_uha_type_node : uha_type_node;
    2651                 :             :       if (mode == USAmode)
    2652                 :           0 :         return unsignedp ? sat_usa_type_node : usa_type_node;
    2653                 :             :       if (mode == UDAmode)
    2654                 :           0 :         return unsignedp ? sat_uda_type_node : uda_type_node;
    2655                 :             :       if (mode == UTAmode)
    2656                 :           0 :         return unsignedp ? sat_uta_type_node : uta_type_node;
    2657                 :             :     }
    2658                 :             : 
    2659                 :      213744 :   for (t = registered_builtin_types; t; t = TREE_CHAIN (t))
    2660                 :             :     {
    2661                 :      212945 :       tree type = TREE_VALUE (t);
    2662                 :      212945 :       if (TYPE_MODE (type) == mode
    2663                 :      210607 :           && VECTOR_TYPE_P (type) == VECTOR_MODE_P (mode)
    2664                 :      423552 :           && !!unsignedp == !!TYPE_UNSIGNED (type))
    2665                 :             :         return type;
    2666                 :             :     }
    2667                 :             :   return NULL_TREE;
    2668                 :             : }
    2669                 :             : 
    2670                 :             : tree
    2671                 :     1263935 : c_common_unsigned_type (tree type)
    2672                 :             : {
    2673                 :     1263935 :   return c_common_signed_or_unsigned_type (1, type);
    2674                 :             : }
    2675                 :             : 
    2676                 :             : /* Return a signed type the same as TYPE in other respects.  */
    2677                 :             : 
    2678                 :             : tree
    2679                 :    61364154 : c_common_signed_type (tree type)
    2680                 :             : {
    2681                 :    61364154 :   return c_common_signed_or_unsigned_type (0, type);
    2682                 :             : }
    2683                 :             : 
    2684                 :             : /* Return a type the same as TYPE except unsigned or
    2685                 :             :    signed according to UNSIGNEDP.  */
    2686                 :             : 
    2687                 :             : tree
    2688                 :    65541063 : c_common_signed_or_unsigned_type (int unsignedp, tree type)
    2689                 :             : {
    2690                 :    65541063 :   tree type1;
    2691                 :    65541063 :   int i;
    2692                 :             : 
    2693                 :             :   /* This block of code emulates the behavior of the old
    2694                 :             :      c_common_unsigned_type. In particular, it returns
    2695                 :             :      long_unsigned_type_node if passed a long, even when a int would
    2696                 :             :      have the same size. This is necessary for warnings to work
    2697                 :             :      correctly in archs where sizeof(int) == sizeof(long) */
    2698                 :             : 
    2699                 :    65541063 :   type1 = TYPE_MAIN_VARIANT (type);
    2700                 :    65541063 :   if (type1 == signed_char_type_node || type1 == char_type_node || type1 == unsigned_char_type_node)
    2701                 :     2675856 :     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
    2702                 :    62865207 :   if (type1 == integer_type_node || type1 == unsigned_type_node)
    2703                 :    17875648 :     return unsignedp ? unsigned_type_node : integer_type_node;
    2704                 :    44989559 :   if (type1 == short_integer_type_node || type1 == short_unsigned_type_node)
    2705                 :     6068487 :     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
    2706                 :    38921072 :   if (type1 == long_integer_type_node || type1 == long_unsigned_type_node)
    2707                 :    24637449 :     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
    2708                 :    14283623 :   if (type1 == long_long_integer_type_node || type1 == long_long_unsigned_type_node)
    2709                 :     2530680 :     return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node;
    2710                 :             : 
    2711                 :    22832290 :   for (i = 0; i < NUM_INT_N_ENTS; i ++)
    2712                 :    11752943 :     if (int_n_enabled_p[i]
    2713                 :    10293687 :         && (type1 == int_n_trees[i].unsigned_type
    2714                 :     9620807 :             || type1 == int_n_trees[i].signed_type))
    2715                 :      673596 :       return (unsignedp ? int_n_trees[i].unsigned_type
    2716                 :      673596 :               : int_n_trees[i].signed_type);
    2717                 :             : 
    2718                 :             : #if HOST_BITS_PER_WIDE_INT >= 64
    2719                 :    11079347 :   if (type1 == intTI_type_node || type1 == unsigned_intTI_type_node)
    2720                 :           0 :     return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
    2721                 :             : #endif
    2722                 :    11079347 :   if (type1 == intDI_type_node || type1 == unsigned_intDI_type_node)
    2723                 :           0 :     return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
    2724                 :    11079347 :   if (type1 == intSI_type_node || type1 == unsigned_intSI_type_node)
    2725                 :           0 :     return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
    2726                 :    11079347 :   if (type1 == intHI_type_node || type1 == unsigned_intHI_type_node)
    2727                 :           0 :     return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
    2728                 :    11079347 :   if (type1 == intQI_type_node || type1 == unsigned_intQI_type_node)
    2729                 :           0 :     return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
    2730                 :             : 
    2731                 :             : #define C_COMMON_FIXED_TYPES(NAME)          \
    2732                 :             :   if (type1 == short_ ## NAME ## _type_node \
    2733                 :             :       || type1 == unsigned_short_ ## NAME ## _type_node) \
    2734                 :             :     return unsignedp ? unsigned_short_ ## NAME ## _type_node \
    2735                 :             :                      : short_ ## NAME ## _type_node; \
    2736                 :             :   if (type1 == NAME ## _type_node \
    2737                 :             :       || type1 == unsigned_ ## NAME ## _type_node) \
    2738                 :             :     return unsignedp ? unsigned_ ## NAME ## _type_node \
    2739                 :             :                      : NAME ## _type_node; \
    2740                 :             :   if (type1 == long_ ## NAME ## _type_node \
    2741                 :             :       || type1 == unsigned_long_ ## NAME ## _type_node) \
    2742                 :             :     return unsignedp ? unsigned_long_ ## NAME ## _type_node \
    2743                 :             :                      : long_ ## NAME ## _type_node; \
    2744                 :             :   if (type1 == long_long_ ## NAME ## _type_node \
    2745                 :             :       || type1 == unsigned_long_long_ ## NAME ## _type_node) \
    2746                 :             :     return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
    2747                 :             :                      : long_long_ ## NAME ## _type_node;
    2748                 :             : 
    2749                 :             : #define C_COMMON_FIXED_MODE_TYPES(NAME) \
    2750                 :             :   if (type1 == NAME ## _type_node \
    2751                 :             :       || type1 == u ## NAME ## _type_node) \
    2752                 :             :     return unsignedp ? u ## NAME ## _type_node \
    2753                 :             :                      : NAME ## _type_node;
    2754                 :             : 
    2755                 :             : #define C_COMMON_FIXED_TYPES_SAT(NAME) \
    2756                 :             :   if (type1 == sat_ ## short_ ## NAME ## _type_node \
    2757                 :             :       || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
    2758                 :             :     return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
    2759                 :             :                      : sat_ ## short_ ## NAME ## _type_node; \
    2760                 :             :   if (type1 == sat_ ## NAME ## _type_node \
    2761                 :             :       || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
    2762                 :             :     return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
    2763                 :             :                      : sat_ ## NAME ## _type_node; \
    2764                 :             :   if (type1 == sat_ ## long_ ## NAME ## _type_node \
    2765                 :             :       || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
    2766                 :             :     return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
    2767                 :             :                      : sat_ ## long_ ## NAME ## _type_node; \
    2768                 :             :   if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
    2769                 :             :       || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
    2770                 :             :     return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
    2771                 :             :                      : sat_ ## long_long_ ## NAME ## _type_node;
    2772                 :             : 
    2773                 :             : #define C_COMMON_FIXED_MODE_TYPES_SAT(NAME)     \
    2774                 :             :   if (type1 == sat_ ## NAME ## _type_node \
    2775                 :             :       || type1 == sat_ ## u ## NAME ## _type_node) \
    2776                 :             :     return unsignedp ? sat_ ## u ## NAME ## _type_node \
    2777                 :             :                      : sat_ ## NAME ## _type_node;
    2778                 :             : 
    2779                 :    11079347 :   C_COMMON_FIXED_TYPES (fract);
    2780                 :    11079347 :   C_COMMON_FIXED_TYPES_SAT (fract);
    2781                 :    11079347 :   C_COMMON_FIXED_TYPES (accum);
    2782                 :    11079347 :   C_COMMON_FIXED_TYPES_SAT (accum);
    2783                 :             : 
    2784                 :    11079347 :   C_COMMON_FIXED_MODE_TYPES (qq);
    2785                 :    11079347 :   C_COMMON_FIXED_MODE_TYPES (hq);
    2786                 :    11079347 :   C_COMMON_FIXED_MODE_TYPES (sq);
    2787                 :    11079347 :   C_COMMON_FIXED_MODE_TYPES (dq);
    2788                 :    11079347 :   C_COMMON_FIXED_MODE_TYPES (tq);
    2789                 :    11079347 :   C_COMMON_FIXED_MODE_TYPES_SAT (qq);
    2790                 :    11079347 :   C_COMMON_FIXED_MODE_TYPES_SAT (hq);
    2791                 :    11079347 :   C_COMMON_FIXED_MODE_TYPES_SAT (sq);
    2792                 :    11079347 :   C_COMMON_FIXED_MODE_TYPES_SAT (dq);
    2793                 :    11079347 :   C_COMMON_FIXED_MODE_TYPES_SAT (tq);
    2794                 :    11079347 :   C_COMMON_FIXED_MODE_TYPES (ha);
    2795                 :    11079347 :   C_COMMON_FIXED_MODE_TYPES (sa);
    2796                 :    11079347 :   C_COMMON_FIXED_MODE_TYPES (da);
    2797                 :    11079347 :   C_COMMON_FIXED_MODE_TYPES (ta);
    2798                 :    11079347 :   C_COMMON_FIXED_MODE_TYPES_SAT (ha);
    2799                 :    11079347 :   C_COMMON_FIXED_MODE_TYPES_SAT (sa);
    2800                 :    11079347 :   C_COMMON_FIXED_MODE_TYPES_SAT (da);
    2801                 :    11079347 :   C_COMMON_FIXED_MODE_TYPES_SAT (ta);
    2802                 :             : 
    2803                 :             :   /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
    2804                 :             :      the precision; they have precision set to match their range, but
    2805                 :             :      may use a wider mode to match an ABI.  If we change modes, we may
    2806                 :             :      wind up with bad conversions.  For INTEGER_TYPEs in C, must check
    2807                 :             :      the precision as well, so as to yield correct results for
    2808                 :             :      bit-field types.  C++ does not have these separate bit-field
    2809                 :             :      types, and producing a signed or unsigned variant of an
    2810                 :             :      ENUMERAL_TYPE may cause other problems as well.  */
    2811                 :             : 
    2812                 :    11079347 :   if (!INTEGRAL_TYPE_P (type)
    2813                 :    11079347 :       || TYPE_UNSIGNED (type) == unsignedp)
    2814                 :             :     return type;
    2815                 :             : 
    2816                 :    10116522 :   if (TREE_CODE (type) == BITINT_TYPE
    2817                 :             :       /* signed _BitInt(1) is invalid, avoid creating that.  */
    2818                 :    10116522 :       && (unsignedp || TYPE_PRECISION (type) > 1))
    2819                 :     1468024 :     return build_bitint_type (TYPE_PRECISION (type), unsignedp);
    2820                 :             : 
    2821                 :             : #define TYPE_OK(node)                                                       \
    2822                 :             :   (TYPE_MODE (type) == TYPE_MODE (node)                                     \
    2823                 :             :    && TYPE_PRECISION (type) == TYPE_PRECISION (node))
    2824                 :     8648498 :   if (TYPE_OK (signed_char_type_node))
    2825                 :      457482 :     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
    2826                 :     8191016 :   if (TYPE_OK (integer_type_node))
    2827                 :     4069936 :     return unsignedp ? unsigned_type_node : integer_type_node;
    2828                 :     4121080 :   if (TYPE_OK (short_integer_type_node))
    2829                 :      883832 :     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
    2830                 :     3237248 :   if (TYPE_OK (long_integer_type_node))
    2831                 :     2777645 :     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
    2832                 :      459603 :   if (TYPE_OK (long_long_integer_type_node))
    2833                 :      116363 :     return (unsignedp ? long_long_unsigned_type_node
    2834                 :           0 :             : long_long_integer_type_node);
    2835                 :             : 
    2836                 :      668647 :   for (i = 0; i < NUM_INT_N_ENTS; i ++)
    2837                 :      343240 :     if (int_n_enabled_p[i]
    2838                 :      331160 :         && TYPE_MODE (type) == int_n_data[i].m
    2839                 :      361137 :         && TYPE_PRECISION (type) == int_n_data[i].bitsize)
    2840                 :       17833 :       return (unsignedp ? int_n_trees[i].unsigned_type
    2841                 :       17833 :               : int_n_trees[i].signed_type);
    2842                 :             : 
    2843                 :             : #if HOST_BITS_PER_WIDE_INT >= 64
    2844                 :      325407 :   if (TYPE_OK (intTI_type_node))
    2845                 :           0 :     return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
    2846                 :             : #endif
    2847                 :      325407 :   if (TYPE_OK (intDI_type_node))
    2848                 :           0 :     return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
    2849                 :      325407 :   if (TYPE_OK (intSI_type_node))
    2850                 :           0 :     return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
    2851                 :      325407 :   if (TYPE_OK (intHI_type_node))
    2852                 :           0 :     return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
    2853                 :      325407 :   if (TYPE_OK (intQI_type_node))
    2854                 :           0 :     return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
    2855                 :             : #undef TYPE_OK
    2856                 :             : 
    2857                 :      325407 :   return build_nonstandard_integer_type (TYPE_PRECISION (type), unsignedp);
    2858                 :             : }
    2859                 :             : 
    2860                 :             : /* Build a bit-field integer type for the given WIDTH and UNSIGNEDP.  */
    2861                 :             : 
    2862                 :             : tree
    2863                 :      326409 : c_build_bitfield_integer_type (unsigned HOST_WIDE_INT width, int unsignedp)
    2864                 :             : {
    2865                 :      326409 :   int i;
    2866                 :             : 
    2867                 :             :   /* Extended integer types of the same width as a standard type have
    2868                 :             :      lesser rank, so those of the same width as int promote to int or
    2869                 :             :      unsigned int and are valid for printf formats expecting int or
    2870                 :             :      unsigned int.  To avoid such special cases, avoid creating
    2871                 :             :      extended integer types for bit-fields if a standard integer type
    2872                 :             :      is available.  */
    2873                 :      326409 :   if (width == TYPE_PRECISION (integer_type_node))
    2874                 :         138 :     return unsignedp ? unsigned_type_node : integer_type_node;
    2875                 :      326271 :   if (width == TYPE_PRECISION (signed_char_type_node))
    2876                 :        6923 :     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
    2877                 :      319348 :   if (width == TYPE_PRECISION (short_integer_type_node))
    2878                 :        1426 :     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
    2879                 :      317922 :   if (width == TYPE_PRECISION (long_integer_type_node))
    2880                 :           0 :     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
    2881                 :      317922 :   if (width == TYPE_PRECISION (long_long_integer_type_node))
    2882                 :           0 :     return (unsignedp ? long_long_unsigned_type_node
    2883                 :           0 :             : long_long_integer_type_node);
    2884                 :      635844 :   for (i = 0; i < NUM_INT_N_ENTS; i ++)
    2885                 :      317922 :     if (int_n_enabled_p[i]
    2886                 :      310948 :         && width == int_n_data[i].bitsize)
    2887                 :           0 :       return (unsignedp ? int_n_trees[i].unsigned_type
    2888                 :           0 :               : int_n_trees[i].signed_type);
    2889                 :      317922 :   return build_nonstandard_integer_type (width, unsignedp);
    2890                 :             : }
    2891                 :             : 
    2892                 :             : /* The C version of the register_builtin_type langhook.  */
    2893                 :             : 
    2894                 :             : void
    2895                 :      620265 : c_register_builtin_type (tree type, const char* name)
    2896                 :             : {
    2897                 :      620265 :   tree decl;
    2898                 :             : 
    2899                 :      620265 :   decl = build_decl (UNKNOWN_LOCATION,
    2900                 :             :                      TYPE_DECL, get_identifier (name), type);
    2901                 :      620265 :   DECL_ARTIFICIAL (decl) = 1;
    2902                 :      620265 :   if (!TYPE_NAME (type))
    2903                 :      303677 :     TYPE_NAME (type) = decl;
    2904                 :      620265 :   lang_hooks.decls.pushdecl (decl);
    2905                 :             : 
    2906                 :      620265 :   registered_builtin_types = tree_cons (0, type, registered_builtin_types);
    2907                 :      620265 : }
    2908                 :             : 
    2909                 :             : /* Print an error message for invalid operands to arith operation
    2910                 :             :    CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
    2911                 :             :    RICHLOC is a rich location for the message, containing either
    2912                 :             :    three separate locations for each of the operator and operands
    2913                 :             : 
    2914                 :             :       lhs op rhs
    2915                 :             :       ~~~ ^~ ~~~
    2916                 :             : 
    2917                 :             :    (C FE), or one location ranging over all over them
    2918                 :             : 
    2919                 :             :       lhs op rhs
    2920                 :             :       ~~~~^~~~~~
    2921                 :             : 
    2922                 :             :    (C++ FE).  */
    2923                 :             : 
    2924                 :             : void
    2925                 :         558 : binary_op_error (rich_location *richloc, enum tree_code code,
    2926                 :             :                  tree type0, tree type1)
    2927                 :             : {
    2928                 :         558 :   const char *opname;
    2929                 :             : 
    2930                 :         558 :   switch (code)
    2931                 :             :     {
    2932                 :             :     case PLUS_EXPR:
    2933                 :             :       opname = "+"; break;
    2934                 :          14 :     case MINUS_EXPR:
    2935                 :          14 :       opname = "-"; break;
    2936                 :         378 :     case MULT_EXPR:
    2937                 :         378 :       opname = "*"; break;
    2938                 :           0 :     case MAX_EXPR:
    2939                 :           0 :       opname = "max"; break;
    2940                 :           0 :     case MIN_EXPR:
    2941                 :           0 :       opname = "min"; break;
    2942                 :           2 :     case EQ_EXPR:
    2943                 :           2 :       opname = "=="; break;
    2944                 :           2 :     case NE_EXPR:
    2945                 :           2 :       opname = "!="; break;
    2946                 :           0 :     case LE_EXPR:
    2947                 :           0 :       opname = "<="; break;
    2948                 :           0 :     case GE_EXPR:
    2949                 :           0 :       opname = ">="; break;
    2950                 :           1 :     case LT_EXPR:
    2951                 :           1 :       opname = "<"; break;
    2952                 :           1 :     case GT_EXPR:
    2953                 :           1 :       opname = ">"; break;
    2954                 :          21 :     case LSHIFT_EXPR:
    2955                 :          21 :       opname = "<<"; break;
    2956                 :          16 :     case RSHIFT_EXPR:
    2957                 :          16 :       opname = ">>"; break;
    2958                 :           3 :     case TRUNC_MOD_EXPR:
    2959                 :           3 :     case FLOOR_MOD_EXPR:
    2960                 :           3 :       opname = "%"; break;
    2961                 :           6 :     case TRUNC_DIV_EXPR:
    2962                 :           6 :     case FLOOR_DIV_EXPR:
    2963                 :           6 :       opname = "/"; break;
    2964                 :          40 :     case BIT_AND_EXPR:
    2965                 :          40 :       opname = "&"; break;
    2966                 :          21 :     case BIT_IOR_EXPR:
    2967                 :          21 :       opname = "|"; break;
    2968                 :           0 :     case TRUTH_ANDIF_EXPR:
    2969                 :           0 :       opname = "&&"; break;
    2970                 :           0 :     case TRUTH_ORIF_EXPR:
    2971                 :           0 :       opname = "||"; break;
    2972                 :          22 :     case BIT_XOR_EXPR:
    2973                 :          22 :       opname = "^"; break;
    2974                 :           0 :     default:
    2975                 :           0 :       gcc_unreachable ();
    2976                 :             :     }
    2977                 :         558 :   pp_markup::element_quoted_type element_0 (type0, highlight_colors::lhs);
    2978                 :        1116 :   pp_markup::element_quoted_type element_1 (type1, highlight_colors::rhs);
    2979                 :         558 :   error_at (richloc,
    2980                 :             :             "invalid operands to binary %s (have %e and %e)",
    2981                 :             :             opname, &element_0, &element_1);
    2982                 :         558 : }
    2983                 :             : 
    2984                 :             : /* Given an expression as a tree, return its original type.  Do this
    2985                 :             :    by stripping any conversion that preserves the sign and precision.  */
    2986                 :             : static tree
    2987                 :       55323 : expr_original_type (tree expr)
    2988                 :             : {
    2989                 :       55323 :   STRIP_SIGN_NOPS (expr);
    2990                 :       55323 :   return TREE_TYPE (expr);
    2991                 :             : }
    2992                 :             : 
    2993                 :             : /* Subroutine of build_binary_op, used for comparison operations.
    2994                 :             :    See if the operands have both been converted from subword integer types
    2995                 :             :    and, if so, perhaps change them both back to their original type.
    2996                 :             :    This function is also responsible for converting the two operands
    2997                 :             :    to the proper common type for comparison.
    2998                 :             : 
    2999                 :             :    The arguments of this function are all pointers to local variables
    3000                 :             :    of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
    3001                 :             :    RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
    3002                 :             : 
    3003                 :             :    LOC is the location of the comparison.
    3004                 :             : 
    3005                 :             :    If this function returns non-NULL_TREE, it means that the comparison has
    3006                 :             :    a constant value.  What this function returns is an expression for
    3007                 :             :    that value.  */
    3008                 :             : 
    3009                 :             : tree
    3010                 :    26587109 : shorten_compare (location_t loc, tree *op0_ptr, tree *op1_ptr,
    3011                 :             :                  tree *restype_ptr, enum tree_code *rescode_ptr)
    3012                 :             : {
    3013                 :    26587109 :   tree type;
    3014                 :    26587109 :   tree op0 = *op0_ptr;
    3015                 :    26587109 :   tree op1 = *op1_ptr;
    3016                 :    26587109 :   int unsignedp0, unsignedp1;
    3017                 :    26587109 :   int real1, real2;
    3018                 :    26587109 :   tree primop0, primop1;
    3019                 :    26587109 :   enum tree_code code = *rescode_ptr;
    3020                 :             : 
    3021                 :             :   /* Throw away any conversions to wider types
    3022                 :             :      already present in the operands.  */
    3023                 :             : 
    3024                 :    26587109 :   primop0 = c_common_get_narrower (op0, &unsignedp0);
    3025                 :    26587109 :   primop1 = c_common_get_narrower (op1, &unsignedp1);
    3026                 :             : 
    3027                 :             :   /* If primopN is first sign-extended from primopN's precision to opN's
    3028                 :             :      precision, then zero-extended from opN's precision to
    3029                 :             :      *restype_ptr precision, shortenings might be invalid.  */
    3030                 :    26587109 :   if (TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (TREE_TYPE (op0))
    3031                 :     1523482 :       && TYPE_PRECISION (TREE_TYPE (op0)) < TYPE_PRECISION (*restype_ptr)
    3032                 :        5823 :       && !unsignedp0
    3033                 :    26592666 :       && TYPE_UNSIGNED (TREE_TYPE (op0)))
    3034                 :             :     primop0 = op0;
    3035                 :    26587109 :   if (TYPE_PRECISION (TREE_TYPE (primop1)) < TYPE_PRECISION (TREE_TYPE (op1))
    3036                 :      927967 :       && TYPE_PRECISION (TREE_TYPE (op1)) < TYPE_PRECISION (*restype_ptr)
    3037                 :       16980 :       && !unsignedp1
    3038                 :    26598752 :       && TYPE_UNSIGNED (TREE_TYPE (op1)))
    3039                 :             :     primop1 = op1;
    3040                 :             : 
    3041                 :             :   /* Handle the case that OP0 does not *contain* a conversion
    3042                 :             :      but it *requires* conversion to FINAL_TYPE.  */
    3043                 :             : 
    3044                 :    26587109 :   if (op0 == primop0 && TREE_TYPE (op0) != *restype_ptr)
    3045                 :      435979 :     unsignedp0 = TYPE_UNSIGNED (TREE_TYPE (op0));
    3046                 :    26587109 :   if (op1 == primop1 && TREE_TYPE (op1) != *restype_ptr)
    3047                 :     6969912 :     unsignedp1 = TYPE_UNSIGNED (TREE_TYPE (op1));
    3048                 :             : 
    3049                 :             :   /* If one of the operands must be floated, we cannot optimize.  */
    3050                 :    26587109 :   real1 = SCALAR_FLOAT_TYPE_P (TREE_TYPE (primop0));
    3051                 :    26587109 :   real2 = SCALAR_FLOAT_TYPE_P (TREE_TYPE (primop1));
    3052                 :             : 
    3053                 :             :   /* If first arg is constant, swap the args (changing operation
    3054                 :             :      so value is preserved), for canonicalization.  Don't do this if
    3055                 :             :      the second arg is 0.  */
    3056                 :             : 
    3057                 :    26587109 :   if (TREE_CONSTANT (primop0)
    3058                 :     5583300 :       && !integer_zerop (primop1) && !real_zerop (primop1)
    3059                 :    30652515 :       && !fixed_zerop (primop1))
    3060                 :             :     {
    3061                 :     4065406 :       std::swap (primop0, primop1);
    3062                 :     4065406 :       std::swap (op0, op1);
    3063                 :     4065406 :       *op0_ptr = op0;
    3064                 :     4065406 :       *op1_ptr = op1;
    3065                 :     4065406 :       std::swap (unsignedp0, unsignedp1);
    3066                 :     4065406 :       std::swap (real1, real2);
    3067                 :             : 
    3068                 :     4065406 :       switch (code)
    3069                 :             :         {
    3070                 :             :         case LT_EXPR:
    3071                 :             :           code = GT_EXPR;
    3072                 :             :           break;
    3073                 :             :         case GT_EXPR:
    3074                 :             :           code = LT_EXPR;
    3075                 :             :           break;
    3076                 :             :         case LE_EXPR:
    3077                 :             :           code = GE_EXPR;
    3078                 :             :           break;
    3079                 :             :         case GE_EXPR:
    3080                 :             :           code = LE_EXPR;
    3081                 :             :           break;
    3082                 :             :         default:
    3083                 :             :           break;
    3084                 :             :         }
    3085                 :     4065406 :       *rescode_ptr = code;
    3086                 :             :     }
    3087                 :             : 
    3088                 :             :   /* If comparing an integer against a constant more bits wide,
    3089                 :             :      maybe we can deduce a value of 1 or 0 independent of the data.
    3090                 :             :      Or else truncate the constant now
    3091                 :             :      rather than extend the variable at run time.
    3092                 :             : 
    3093                 :             :      This is only interesting if the constant is the wider arg.
    3094                 :             :      Also, it is not safe if the constant is unsigned and the
    3095                 :             :      variable arg is signed, since in this case the variable
    3096                 :             :      would be sign-extended and then regarded as unsigned.
    3097                 :             :      Our technique fails in this case because the lowest/highest
    3098                 :             :      possible unsigned results don't follow naturally from the
    3099                 :             :      lowest/highest possible values of the variable operand.
    3100                 :             :      For just EQ_EXPR and NE_EXPR there is another technique that
    3101                 :             :      could be used: see if the constant can be faithfully represented
    3102                 :             :      in the other operand's type, by truncating it and reextending it
    3103                 :             :      and see if that preserves the constant's value.  */
    3104                 :             : 
    3105                 :    22003256 :   if (!real1 && !real2
    3106                 :    21978437 :       && TREE_CODE (TREE_TYPE (primop0)) != FIXED_POINT_TYPE
    3107                 :    21978437 :       && TREE_CODE (primop1) == INTEGER_CST
    3108                 :    40931832 :       && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr))
    3109                 :             :     {
    3110                 :     1598602 :       int min_gt, max_gt, min_lt, max_lt;
    3111                 :     1598602 :       tree maxval, minval;
    3112                 :             :       /* 1 if comparison is nominally unsigned.  */
    3113                 :     1598602 :       int unsignedp = TYPE_UNSIGNED (*restype_ptr);
    3114                 :     1598602 :       tree val;
    3115                 :             : 
    3116                 :     1598602 :       type = c_common_signed_or_unsigned_type (unsignedp0,
    3117                 :     1598602 :                                                TREE_TYPE (primop0));
    3118                 :             : 
    3119                 :     1598602 :       maxval = TYPE_MAX_VALUE (type);
    3120                 :     1598602 :       minval = TYPE_MIN_VALUE (type);
    3121                 :             : 
    3122                 :     1598602 :       if (unsignedp && !unsignedp0)
    3123                 :      420287 :         *restype_ptr = c_common_signed_type (*restype_ptr);
    3124                 :             : 
    3125                 :     1598602 :       if (TREE_TYPE (primop1) != *restype_ptr)
    3126                 :             :         {
    3127                 :             :           /* Convert primop1 to target type, but do not introduce
    3128                 :             :              additional overflow.  We know primop1 is an int_cst.  */
    3129                 :      420591 :           primop1 = force_fit_type (*restype_ptr,
    3130                 :             :                                     wi::to_wide
    3131                 :      841182 :                                      (primop1,
    3132                 :      420591 :                                       TYPE_PRECISION (*restype_ptr)),
    3133                 :      420591 :                                     0, TREE_OVERFLOW (primop1));
    3134                 :             :         }
    3135                 :     1598602 :       if (type != *restype_ptr)
    3136                 :             :         {
    3137                 :     1598602 :           minval = convert (*restype_ptr, minval);
    3138                 :     1598602 :           maxval = convert (*restype_ptr, maxval);
    3139                 :             :         }
    3140                 :             : 
    3141                 :     1598602 :       min_gt = tree_int_cst_lt (primop1, minval);
    3142                 :     1598602 :       max_gt = tree_int_cst_lt (primop1, maxval);
    3143                 :     1598602 :       min_lt = tree_int_cst_lt (minval, primop1);
    3144                 :     1598602 :       max_lt = tree_int_cst_lt (maxval, primop1);
    3145                 :             : 
    3146                 :     1598602 :       val = 0;
    3147                 :             :       /* This used to be a switch, but Genix compiler can't handle that.  */
    3148                 :     1598602 :       if (code == NE_EXPR)
    3149                 :             :         {
    3150                 :      362956 :           if (max_lt || min_gt)
    3151                 :          23 :             val = truthvalue_true_node;
    3152                 :             :         }
    3153                 :             :       else if (code == EQ_EXPR)
    3154                 :             :         {
    3155                 :      642922 :           if (max_lt || min_gt)
    3156                 :          35 :             val = truthvalue_false_node;
    3157                 :             :         }
    3158                 :             :       else if (code == LT_EXPR)
    3159                 :             :         {
    3160                 :      323446 :           if (max_lt)
    3161                 :          18 :             val = truthvalue_true_node;
    3162                 :      323446 :           if (!min_lt)
    3163                 :        7717 :             val = truthvalue_false_node;
    3164                 :             :         }
    3165                 :             :       else if (code == GT_EXPR)
    3166                 :             :         {
    3167                 :      121436 :           if (min_gt)
    3168                 :           8 :             val = truthvalue_true_node;
    3169                 :      121436 :           if (!max_gt)
    3170                 :           6 :             val = truthvalue_false_node;
    3171                 :             :         }
    3172                 :             :       else if (code == LE_EXPR)
    3173                 :             :         {
    3174                 :       50436 :           if (!max_gt)
    3175                 :          74 :             val = truthvalue_true_node;
    3176                 :       50436 :           if (min_gt)
    3177                 :           7 :             val = truthvalue_false_node;
    3178                 :             :         }
    3179                 :             :       else if (code == GE_EXPR)
    3180                 :             :         {
    3181                 :       97404 :           if (!min_lt)
    3182                 :         179 :             val = truthvalue_true_node;
    3183                 :       97404 :           if (max_lt)
    3184                 :       14974 :             val = truthvalue_false_node;
    3185                 :             :         }
    3186                 :             : 
    3187                 :             :       /* If primop0 was sign-extended and unsigned comparison specd,
    3188                 :             :          we did a signed comparison above using the signed type bounds.
    3189                 :             :          But the comparison we output must be unsigned.
    3190                 :             : 
    3191                 :             :          Also, for inequalities, VAL is no good; but if the signed
    3192                 :             :          comparison had *any* fixed result, it follows that the
    3193                 :             :          unsigned comparison just tests the sign in reverse
    3194                 :             :          (positive values are LE, negative ones GE).
    3195                 :             :          So we can generate an unsigned comparison
    3196                 :             :          against an extreme value of the signed type.  */
    3197                 :             : 
    3198                 :     1598602 :       if (unsignedp && !unsignedp0)
    3199                 :             :         {
    3200                 :      420287 :           if (val != 0)
    3201                 :         112 :             switch (code)
    3202                 :             :               {
    3203                 :          81 :               case LT_EXPR:
    3204                 :          81 :               case GE_EXPR:
    3205                 :          81 :                 primop1 = TYPE_MIN_VALUE (type);
    3206                 :          81 :                 val = 0;
    3207                 :          81 :                 break;
    3208                 :             : 
    3209                 :          30 :               case LE_EXPR:
    3210                 :          30 :               case GT_EXPR:
    3211                 :          30 :                 primop1 = TYPE_MAX_VALUE (type);
    3212                 :          30 :                 val = 0;
    3213                 :          30 :                 break;
    3214                 :             : 
    3215                 :             :               default:
    3216                 :             :                 break;
    3217                 :             :               }
    3218                 :      420287 :           type = c_common_unsigned_type (type);
    3219                 :             :         }
    3220                 :             : 
    3221                 :     1598602 :       if (TREE_CODE (primop0) != INTEGER_CST
    3222                 :             :           /* Don't warn if it's from a (non-system) macro.  */
    3223                 :     1598602 :           && !(from_macro_expansion_at
    3224                 :     1098543 :                (expansion_point_location_if_in_system_header
    3225                 :     1098543 :                 (EXPR_LOCATION (primop0)))))
    3226                 :             :         {
    3227                 :     1057953 :           if (val == truthvalue_false_node)
    3228                 :        7755 :             warning_at (loc, OPT_Wtype_limits,
    3229                 :             :                         "comparison is always false due to limited range of data type");
    3230                 :     1057953 :           if (val == truthvalue_true_node)
    3231                 :         187 :             warning_at (loc, OPT_Wtype_limits,
    3232                 :             :                         "comparison is always true due to limited range of data type");
    3233                 :             :         }
    3234                 :             : 
    3235                 :     1598602 :       if (val != 0)
    3236                 :             :         {
    3237                 :             :           /* Don't forget to evaluate PRIMOP0 if it has side effects.  */
    3238                 :       22930 :           if (TREE_SIDE_EFFECTS (primop0))
    3239                 :          11 :             return build2 (COMPOUND_EXPR, TREE_TYPE (val), primop0, val);
    3240                 :             :           return val;
    3241                 :             :         }
    3242                 :             : 
    3243                 :             :       /* Value is not predetermined, but do the comparison
    3244                 :             :          in the type of the operand that is not constant.
    3245                 :             :          TYPE is already properly set.  */
    3246                 :             :     }
    3247                 :             : 
    3248                 :             :   /* If either arg is decimal float and the other is float, find the
    3249                 :             :      proper common type to use for comparison.  */
    3250                 :     4583853 :   else if (real1 && real2
    3251                 :     4348048 :            && DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0)))
    3252                 :    25005055 :            && DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1))))
    3253                 :       16547 :     type = common_type (TREE_TYPE (primop0), TREE_TYPE (primop1));
    3254                 :             : 
    3255                 :             :   /* If either arg is decimal float and the other is float, fail.  */
    3256                 :     4567306 :   else if (real1 && real2
    3257                 :    29303461 :            && (DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0)))
    3258                 :     4331500 :                || DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1)))))
    3259                 :             :     {
    3260                 :           2 :       type = *restype_ptr;
    3261                 :           2 :       primop0 = op0;
    3262                 :           2 :       primop1 = op1;
    3263                 :             :     }
    3264                 :             : 
    3265                 :     4567304 :   else if (real1 && real2
    3266                 :    29303457 :            && (TYPE_PRECISION (TREE_TYPE (primop0))
    3267                 :     4331499 :                == TYPE_PRECISION (TREE_TYPE (primop1))))
    3268                 :     4236391 :     type = TREE_TYPE (primop0);
    3269                 :             : 
    3270                 :             :   /* If args' natural types are both narrower than nominal type
    3271                 :             :      and both extend in the same manner, compare them
    3272                 :             :      in the type of the wider arg.
    3273                 :             :      Otherwise must actually extend both to the nominal
    3274                 :             :      common type lest different ways of extending
    3275                 :             :      alter the result.
    3276                 :             :      (eg, (short)-1 == (unsigned short)-1  should be 0.)  */
    3277                 :             : 
    3278                 :    18152992 :   else if (unsignedp0 == unsignedp1 && real1 == real2
    3279                 :    17905566 :            && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr)
    3280                 :      506969 :            && TYPE_PRECISION (TREE_TYPE (primop1)) < TYPE_PRECISION (*restype_ptr)
    3281                 :    21089743 :            && (type = common_type (TREE_TYPE (primop0), TREE_TYPE (primop1)))
    3282                 :      354176 :               != error_mark_node)
    3283                 :             :     {
    3284                 :      354176 :       type = c_common_signed_or_unsigned_type (unsignedp0
    3285                 :      354176 :                                                || TYPE_UNSIGNED (*restype_ptr),
    3286                 :             :                                                type);
    3287                 :             :       /* Make sure shorter operand is extended the right way
    3288                 :             :          to match the longer operand.  */
    3289                 :      354176 :       primop0
    3290                 :      354176 :         = convert (c_common_signed_or_unsigned_type (unsignedp0,
    3291                 :      354176 :                                                      TREE_TYPE (primop0)),
    3292                 :             :                    primop0);
    3293                 :      354176 :       primop1
    3294                 :      354176 :         = convert (c_common_signed_or_unsigned_type (unsignedp1,
    3295                 :      354176 :                                                      TREE_TYPE (primop1)),
    3296                 :             :                    primop1);
    3297                 :             :     }
    3298                 :             :   else
    3299                 :             :     {
    3300                 :             :       /* Here we must do the comparison on the nominal type
    3301                 :             :          using the args exactly as we received them.  */
    3302                 :    20381391 :       type = *restype_ptr;
    3303                 :    20381391 :       primop0 = op0;
    3304                 :    20381391 :       primop1 = op1;
    3305                 :             : 
    3306                 :             :       /* We want to fold unsigned comparisons of >= and < against zero.
    3307                 :             :          For these, we may also issue a warning if we have a non-constant
    3308                 :             :          compared against zero, where the zero was spelled as "0" (rather
    3309                 :             :          than merely folding to it).
    3310                 :             :          If we have at least one constant, then op1 is constant
    3311                 :             :          and we may have a non-constant expression as op0.  */
    3312                 :    20050478 :       if (!real1 && !real2 && integer_zerop (primop1)
    3313                 :    28759749 :           && TYPE_UNSIGNED (*restype_ptr))
    3314                 :             :         {
    3315                 :     2797365 :           tree value = NULL_TREE;
    3316                 :             :           /* All unsigned values are >= 0, so we warn.  However,
    3317                 :             :              if OP0 is a constant that is >= 0, the signedness of
    3318                 :             :              the comparison isn't an issue, so suppress the
    3319                 :             :              warning.  */
    3320                 :     2797365 :           tree folded_op0 = fold_for_warn (op0);
    3321                 :     2797365 :           bool warn =
    3322                 :       70977 :             warn_type_limits && !in_system_header_at (loc)
    3323                 :       64761 :             && !(TREE_CODE (folded_op0) == INTEGER_CST
    3324                 :        9438 :                  && !TREE_OVERFLOW (convert (c_common_signed_type (type),
    3325                 :             :                                              folded_op0)))
    3326                 :             :             /* Do not warn for enumeration types.  */
    3327                 :     2852688 :             && (TREE_CODE (expr_original_type (folded_op0)) != ENUMERAL_TYPE);
    3328                 :             : 
    3329                 :     2797365 :           switch (code)
    3330                 :             :             {
    3331                 :       12588 :             case GE_EXPR:
    3332                 :       12588 :               if (warn)
    3333                 :          56 :                 warning_at (loc, OPT_Wtype_limits,
    3334                 :             :                             "comparison of unsigned expression in %<>= 0%> "
    3335                 :             :                             "is always true");
    3336                 :       12588 :               value = truthvalue_true_node;
    3337                 :       12588 :               break;
    3338                 :             : 
    3339                 :      312143 :             case LT_EXPR:
    3340                 :      312143 :               if (warn)
    3341                 :          55 :                 warning_at (loc, OPT_Wtype_limits,
    3342                 :             :                             "comparison of unsigned expression in %<< 0%> "
    3343                 :             :                             "is always false");
    3344                 :      312143 :               value = truthvalue_false_node;
    3345                 :      312143 :               break;
    3346                 :             : 
    3347                 :             :             default:
    3348                 :             :               break;
    3349                 :             :             }
    3350                 :             : 
    3351                 :      324731 :           if (value != NULL_TREE)
    3352                 :             :             {
    3353                 :             :               /* Don't forget to evaluate PRIMOP0 if it has side effects.  */
    3354                 :      324731 :               if (TREE_SIDE_EFFECTS (primop0))
    3355                 :          39 :                 return build2 (COMPOUND_EXPR, TREE_TYPE (value),
    3356                 :          39 :                                primop0, value);
    3357                 :             :               return value;
    3358                 :             :             }
    3359                 :             :         }
    3360                 :             :     }
    3361                 :             : 
    3362                 :    26239448 :   *op0_ptr = convert (type, primop0);
    3363                 :    26239448 :   *op1_ptr = convert (type, primop1);
    3364                 :             : 
    3365                 :    26239448 :   *restype_ptr = truthvalue_type_node;
    3366                 :             : 
    3367                 :    26239448 :   return NULL_TREE;
    3368                 :             : }
    3369                 :             : 
    3370                 :             : /* Return a tree for the sum or difference (RESULTCODE says which)
    3371                 :             :    of pointer PTROP and integer INTOP.  */
    3372                 :             : 
    3373                 :             : tree
    3374                 :     5615870 : pointer_int_sum (location_t loc, enum tree_code resultcode,
    3375                 :             :                  tree ptrop, tree intop, bool complain)
    3376                 :             : {
    3377                 :     5615870 :   tree size_exp, ret;
    3378                 :             : 
    3379                 :             :   /* The result is a pointer of the same type that is being added.  */
    3380                 :     5615870 :   tree result_type = TREE_TYPE (ptrop);
    3381                 :             : 
    3382                 :     5615870 :   if (VOID_TYPE_P (TREE_TYPE (result_type)))
    3383                 :             :     {
    3384                 :         900 :       if (complain && warn_pointer_arith)
    3385                 :          61 :         pedwarn (loc, OPT_Wpointer_arith,
    3386                 :             :                  "pointer of type %<void *%> used in arithmetic");
    3387                 :             :       else if (!complain)
    3388                 :           0 :         return error_mark_node;
    3389                 :         900 :       size_exp = integer_one_node;
    3390                 :             :     }
    3391                 :     5614970 :   else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE)
    3392                 :             :     {
    3393                 :         118 :       if (complain && warn_pointer_arith)
    3394                 :          49 :         pedwarn (loc, OPT_Wpointer_arith,
    3395                 :             :                  "pointer to a function used in arithmetic");
    3396                 :             :       else if (!complain)
    3397                 :           0 :         return error_mark_node;
    3398                 :         118 :       size_exp = integer_one_node;
    3399                 :             :     }
    3400                 :     5614852 :   else if (!verify_type_context (loc, TCTX_POINTER_ARITH,
    3401                 :     5614852 :                                  TREE_TYPE (result_type)))
    3402                 :           0 :     size_exp = integer_one_node;
    3403                 :             :   else
    3404                 :             :     {
    3405                 :     5614852 :       if (!complain && !COMPLETE_TYPE_P (TREE_TYPE (result_type)))
    3406                 :         108 :         return error_mark_node;
    3407                 :     5614744 :       size_exp = size_in_bytes_loc (loc, TREE_TYPE (result_type));
    3408                 :             :       /* Wrap the pointer expression in a SAVE_EXPR to make sure it
    3409                 :             :          is evaluated first when the size expression may depend
    3410                 :             :          on it for VM types.  */
    3411                 :     5614744 :       if (TREE_SIDE_EFFECTS (size_exp)
    3412                 :        1935 :           && TREE_SIDE_EFFECTS (ptrop)
    3413                 :     5614763 :           && variably_modified_type_p (TREE_TYPE (ptrop), NULL))
    3414                 :             :         {
    3415                 :          19 :           ptrop = save_expr (ptrop);
    3416                 :          19 :           size_exp = build2 (COMPOUND_EXPR, TREE_TYPE (intop), ptrop, size_exp);
    3417                 :             :         }
    3418                 :             :     }
    3419                 :             : 
    3420                 :             :   /* We are manipulating pointer values, so we don't need to warn
    3421                 :             :      about relying on undefined signed overflow.  We disable the
    3422                 :             :      warning here because we use integer types so fold won't know that
    3423                 :             :      they are really pointers.  */
    3424                 :     5615762 :   fold_defer_overflow_warnings ();
    3425                 :             : 
    3426                 :             :   /* If what we are about to multiply by the size of the elements
    3427                 :             :      contains a constant term, apply distributive law
    3428                 :             :      and multiply that constant term separately.
    3429                 :             :      This helps produce common subexpressions.  */
    3430                 :     5615762 :   if ((TREE_CODE (intop) == PLUS_EXPR || TREE_CODE (intop) == MINUS_EXPR)
    3431                 :      175877 :       && !TREE_CONSTANT (intop)
    3432                 :      175795 :       && TREE_CONSTANT (TREE_OPERAND (intop, 1))
    3433                 :      141145 :       && TREE_CONSTANT (size_exp)
    3434                 :             :       /* If the constant comes from pointer subtraction,
    3435                 :             :          skip this optimization--it would cause an error.  */
    3436                 :      141144 :       && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop, 0))) == INTEGER_TYPE
    3437                 :             :       /* If the constant is unsigned, and smaller than the pointer size,
    3438                 :             :          then we must skip this optimization.  This is because it could cause
    3439                 :             :          an overflow error if the constant is negative but INTOP is not.  */
    3440                 :      282288 :       && (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (intop))
    3441                 :      121132 :           || (TYPE_PRECISION (TREE_TYPE (intop))
    3442                 :      121132 :               == TYPE_PRECISION (TREE_TYPE (ptrop))))
    3443                 :     5791438 :       && TYPE_PRECISION (TREE_TYPE (intop)) <= TYPE_PRECISION (sizetype))
    3444                 :             :     {
    3445                 :       34532 :       tree intop0 = TREE_OPERAND (intop, 0);
    3446                 :       34532 :       tree intop1 = TREE_OPERAND (intop, 1);
    3447                 :       34532 :       if (TYPE_PRECISION (TREE_TYPE (intop)) != TYPE_PRECISION (sizetype)
    3448                 :       34532 :           || TYPE_UNSIGNED (TREE_TYPE (intop)) != TYPE_UNSIGNED (sizetype))
    3449                 :             :         {
    3450                 :       20012 :           tree optype = c_common_type_for_size (TYPE_PRECISION (sizetype),
    3451                 :       20012 :                                                 TYPE_UNSIGNED (sizetype));
    3452                 :       20012 :           intop0 = convert (optype, intop0);
    3453                 :       20012 :           intop1 = convert (optype, intop1);
    3454                 :             :         }
    3455                 :       34532 :       tree t = fold_build2_loc (loc, MULT_EXPR, TREE_TYPE (intop0), intop0,
    3456                 :       34532 :                                 convert (TREE_TYPE (intop0), size_exp));
    3457                 :       34532 :       intop0 = convert (sizetype, t);
    3458                 :       34532 :       if (TREE_OVERFLOW_P (intop0) && !TREE_OVERFLOW (t))
    3459                 :           0 :         intop0 = wide_int_to_tree (TREE_TYPE (intop0), wi::to_wide (intop0));
    3460                 :       34532 :       t = fold_build2_loc (loc, MULT_EXPR, TREE_TYPE (intop1), intop1,
    3461                 :       34532 :                            convert (TREE_TYPE (intop1), size_exp));
    3462                 :       34532 :       intop1 = convert (sizetype, t);
    3463                 :       34532 :       if (TREE_OVERFLOW_P (intop1) && !TREE_OVERFLOW (t))
    3464                 :           0 :         intop1 = wide_int_to_tree (TREE_TYPE (intop1), wi::to_wide (intop1));
    3465                 :       34532 :       intop = build_binary_op (EXPR_LOCATION (intop), TREE_CODE (intop),
    3466                 :             :                                intop0, intop1, true);
    3467                 :             : 
    3468                 :             :       /* Create the sum or difference.  */
    3469                 :       34532 :       if (resultcode == MINUS_EXPR)
    3470                 :          51 :         intop = fold_build1_loc (loc, NEGATE_EXPR, sizetype, intop);
    3471                 :             : 
    3472                 :       34532 :       ret = fold_build_pointer_plus_loc (loc, ptrop, intop);
    3473                 :             : 
    3474                 :       34532 :       fold_undefer_and_ignore_overflow_warnings ();
    3475                 :             : 
    3476                 :       34532 :       return ret;
    3477                 :             :     }
    3478                 :             : 
    3479                 :             :   /* Convert the integer argument to a type the same size as sizetype
    3480                 :             :      so the multiply won't overflow spuriously.  */
    3481                 :     5581230 :   if (TYPE_PRECISION (TREE_TYPE (intop)) != TYPE_PRECISION (sizetype)
    3482                 :     5581230 :       || TYPE_UNSIGNED (TREE_TYPE (intop)) != TYPE_UNSIGNED (sizetype))
    3483                 :     3887461 :     intop = convert (c_common_type_for_size (TYPE_PRECISION (sizetype),
    3484                 :     3887461 :                                              TYPE_UNSIGNED (sizetype)), intop);
    3485                 :             : 
    3486                 :             :   /* Replace the integer argument with a suitable product by the object size.
    3487                 :             :      Do this multiplication as signed, then convert to the appropriate type
    3488                 :             :      for the pointer operation and disregard an overflow that occurred only
    3489                 :             :      because of the sign-extension change in the latter conversion.  */
    3490                 :     5581230 :   {
    3491                 :     5581230 :     tree t = fold_build2_loc (loc, MULT_EXPR, TREE_TYPE (intop), intop,
    3492                 :     5581230 :                               convert (TREE_TYPE (intop), size_exp));
    3493                 :     5581230 :     intop = convert (sizetype, t);
    3494                 :     5581230 :     if (TREE_OVERFLOW_P (intop) && !TREE_OVERFLOW (t))
    3495                 :           0 :       intop = wide_int_to_tree (TREE_TYPE (intop), wi::to_wide (intop));
    3496                 :             :   }
    3497                 :             : 
    3498                 :             :   /* Create the sum or difference.  */
    3499                 :     5581230 :   if (resultcode == MINUS_EXPR)
    3500                 :      216122 :     intop = fold_build1_loc (loc, NEGATE_EXPR, sizetype, intop);
    3501                 :             : 
    3502                 :     5581230 :   ret = fold_build_pointer_plus_loc (loc, ptrop, intop);
    3503                 :             : 
    3504                 :     5581230 :   fold_undefer_and_ignore_overflow_warnings ();
    3505                 :             : 
    3506                 :     5581230 :   return ret;
    3507                 :             : }
    3508                 :             : 
    3509                 :             : /* Wrap a C_MAYBE_CONST_EXPR around an expression that is fully folded
    3510                 :             :    and if NON_CONST is known not to be permitted in an evaluated part
    3511                 :             :    of a constant expression.  */
    3512                 :             : 
    3513                 :             : tree
    3514                 :     4381790 : c_wrap_maybe_const (tree expr, bool non_const)
    3515                 :             : {
    3516                 :     4381790 :   location_t loc = EXPR_LOCATION (expr);
    3517                 :             : 
    3518                 :             :   /* This should never be called for C++.  */
    3519                 :     4381790 :   if (c_dialect_cxx ())
    3520                 :           0 :     gcc_unreachable ();
    3521                 :             : 
    3522                 :             :   /* The result of folding may have a NOP_EXPR to set TREE_NO_WARNING.  */
    3523                 :     4382536 :   STRIP_TYPE_NOPS (expr);
    3524                 :     4381790 :   expr = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (expr), NULL, expr);
    3525                 :     4381790 :   C_MAYBE_CONST_EXPR_NON_CONST (expr) = non_const;
    3526                 :     4381790 :   protected_set_expr_location (expr, loc);
    3527                 :             : 
    3528                 :     4381790 :   return expr;
    3529                 :             : }
    3530                 :             : 
    3531                 :             : /* Return whether EXPR is a declaration whose address can never be NULL.
    3532                 :             :    The address of the first struct member could be NULL only if it were
    3533                 :             :    accessed through a NULL pointer, and such an access would be invalid.
    3534                 :             :    The address of a weak symbol may be null unless it has a definition.  */
    3535                 :             : 
    3536                 :             : bool
    3537                 :        1410 : decl_with_nonnull_addr_p (const_tree expr)
    3538                 :             : {
    3539                 :        1410 :   if (!DECL_P (expr))
    3540                 :             :     return false;
    3541                 :             : 
    3542                 :        1156 :   if (TREE_CODE (expr) == FIELD_DECL
    3543                 :        1079 :       || TREE_CODE (expr) == PARM_DECL
    3544                 :        1045 :       || TREE_CODE (expr) == LABEL_DECL)
    3545                 :             :     return true;
    3546                 :             : 
    3547                 :        1020 :   if (!VAR_OR_FUNCTION_DECL_P (expr))
    3548                 :             :     return false;
    3549                 :             : 
    3550                 :        1020 :   if (!DECL_WEAK (expr))
    3551                 :             :     /* Ordinary (non-weak) symbols have nonnull addresses.  */
    3552                 :             :     return true;
    3553                 :             : 
    3554                 :         529 :   if (DECL_INITIAL (expr) && DECL_INITIAL (expr) != error_mark_node)
    3555                 :             :     /* Initialized weak symbols have nonnull addresses.  */
    3556                 :             :     return true;
    3557                 :             : 
    3558                 :         476 :   if (DECL_EXTERNAL (expr) || !TREE_STATIC (expr))
    3559                 :             :     /* Uninitialized extern weak symbols and weak symbols with no
    3560                 :             :        allocated storage might have a null address.  */
    3561                 :             :     return false;
    3562                 :             : 
    3563                 :          43 :   tree attribs = DECL_ATTRIBUTES (expr);
    3564                 :          43 :   if (lookup_attribute ("weakref", attribs))
    3565                 :             :     /* Weakref symbols might have a null address unless their referent
    3566                 :             :        is known not to.  Don't bother following weakref targets here.  */
    3567                 :             :     return false;
    3568                 :             : 
    3569                 :             :   return true;
    3570                 :             : }
    3571                 :             : 
    3572                 :             : /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
    3573                 :             :    or for an `if' or `while' statement or ?..: exp.  It should already
    3574                 :             :    have been validated to be of suitable type; otherwise, a bad
    3575                 :             :    diagnostic may result.
    3576                 :             : 
    3577                 :             :    The EXPR is located at LOCATION.
    3578                 :             : 
    3579                 :             :    This preparation consists of taking the ordinary
    3580                 :             :    representation of an expression expr and producing a valid tree
    3581                 :             :    boolean expression describing whether expr is nonzero.  We could
    3582                 :             :    simply always do build_binary_op (NE_EXPR, expr, truthvalue_false_node, 1),
    3583                 :             :    but we optimize comparisons, &&, ||, and !.
    3584                 :             : 
    3585                 :             :    The resulting type should always be `truthvalue_type_node'.  */
    3586                 :             : 
    3587                 :             : tree
    3588                 :    10613022 : c_common_truthvalue_conversion (location_t location, tree expr)
    3589                 :             : {
    3590                 :    11425744 :   STRIP_ANY_LOCATION_WRAPPER (expr);
    3591                 :    11425744 :   switch (TREE_CODE (expr))
    3592                 :             :     {
    3593                 :     2454292 :     case EQ_EXPR:   case NE_EXPR:   case UNEQ_EXPR: case LTGT_EXPR:
    3594                 :     2454292 :     case LE_EXPR:   case GE_EXPR:   case LT_EXPR:   case GT_EXPR:
    3595                 :     2454292 :     case UNLE_EXPR: case UNGE_EXPR: case UNLT_EXPR: case UNGT_EXPR:
    3596                 :     2454292 :     case ORDERED_EXPR: case UNORDERED_EXPR:
    3597                 :     2454292 :       if (TREE_TYPE (expr) == truthvalue_type_node)
    3598                 :             :         return expr;
    3599                 :      404089 :       expr = build2 (TREE_CODE (expr), truthvalue_type_node,
    3600                 :      404089 :                      TREE_OPERAND (expr, 0), TREE_OPERAND (expr, 1));
    3601                 :      404089 :       goto ret;
    3602                 :             : 
    3603                 :      589241 :     case TRUTH_ANDIF_EXPR:
    3604                 :      589241 :     case TRUTH_ORIF_EXPR:
    3605                 :      589241 :     case TRUTH_AND_EXPR:
    3606                 :      589241 :     case TRUTH_OR_EXPR:
    3607                 :      589241 :     case TRUTH_XOR_EXPR:
    3608                 :      589241 :       if (TREE_TYPE (expr) == truthvalue_type_node)
    3609                 :             :         return expr;
    3610                 :          74 :       expr = build2 (TREE_CODE (expr), truthvalue_type_node,
    3611                 :             :                      c_common_truthvalue_conversion (location,
    3612                 :          37 :                                                      TREE_OPERAND (expr, 0)),
    3613                 :             :                      c_common_truthvalue_conversion (location,
    3614                 :          37 :                                                      TREE_OPERAND (expr, 1)));
    3615                 :          37 :       goto ret;
    3616                 :             : 
    3617                 :      327769 :     case TRUTH_NOT_EXPR:
    3618                 :      327769 :       if (TREE_TYPE (expr) == truthvalue_type_node)
    3619                 :             :         return expr;
    3620                 :      324830 :       expr = build1 (TREE_CODE (expr), truthvalue_type_node,
    3621                 :             :                      c_common_truthvalue_conversion (location,
    3622                 :      324830 :                                                      TREE_OPERAND (expr, 0)));
    3623                 :      324830 :       goto ret;
    3624                 :             : 
    3625                 :             :     case ERROR_MARK:
    3626                 :             :       return expr;
    3627                 :             : 
    3628                 :     2654469 :     case INTEGER_CST:
    3629                 :     2654469 :       if (TREE_CODE (TREE_TYPE (expr)) == ENUMERAL_TYPE
    3630                 :      786499 :           && !integer_zerop (expr)
    3631                 :     3150788 :           && !integer_onep (expr))
    3632                 :        1003 :         warning_at (location, OPT_Wint_in_bool_context,
    3633                 :             :                     "enum constant in boolean context");
    3634                 :     2654469 :       return integer_zerop (expr) ? truthvalue_false_node
    3635                 :     2654469 :                                   : truthvalue_true_node;
    3636                 :             : 
    3637                 :        1288 :     case REAL_CST:
    3638                 :        1288 :       return real_compare (NE_EXPR, &TREE_REAL_CST (expr), &dconst0)
    3639                 :        1288 :              ? truthvalue_true_node
    3640                 :        1288 :              : truthvalue_false_node;
    3641                 :             : 
    3642                 :           0 :     case FIXED_CST:
    3643                 :           0 :       return fixed_compare (NE_EXPR, &TREE_FIXED_CST (expr),
    3644                 :           0 :                             &FCONST0 (TYPE_MODE (TREE_TYPE (expr))))
    3645                 :           0 :              ? truthvalue_true_node
    3646                 :           0 :              : truthvalue_false_node;
    3647                 :             : 
    3648                 :           0 :     case FUNCTION_DECL:
    3649                 :           0 :       expr = build_unary_op (location, ADDR_EXPR, expr, false);
    3650                 :             :       /* Fall through.  */
    3651                 :             : 
    3652                 :         579 :     case ADDR_EXPR:
    3653                 :         579 :       {
    3654                 :         579 :         tree inner = TREE_OPERAND (expr, 0);
    3655                 :         579 :         if (decl_with_nonnull_addr_p (inner)
    3656                 :             :             /* Check both EXPR and INNER for suppression.  */
    3657                 :         127 :             && !warning_suppressed_p (expr, OPT_Waddress)
    3658                 :         692 :             && !warning_suppressed_p (inner, OPT_Waddress))
    3659                 :             :           {
    3660                 :             :             /* Common Ada programmer's mistake.  */
    3661                 :         107 :             warning_at (location,
    3662                 :         107 :                         OPT_Waddress,
    3663                 :             :                         "the address of %qD will always evaluate as %<true%>",
    3664                 :             :                         inner);
    3665                 :         107 :             suppress_warning (inner, OPT_Waddress);
    3666                 :         107 :             return truthvalue_true_node;
    3667                 :             :           }
    3668                 :             :         break;
    3669                 :             :       }
    3670                 :             : 
    3671                 :         578 :     case COMPLEX_EXPR:
    3672                 :        1734 :       expr = build_binary_op (EXPR_LOCATION (expr),
    3673                 :         578 :                               (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1))
    3674                 :             :                                ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
    3675                 :             :                 c_common_truthvalue_conversion (location,
    3676                 :         578 :                                                 TREE_OPERAND (expr, 0)),
    3677                 :             :                 c_common_truthvalue_conversion (location,
    3678                 :         578 :                                                 TREE_OPERAND (expr, 1)),
    3679                 :             :                               false);
    3680                 :         578 :       goto ret;
    3681                 :             : 
    3682                 :          74 :     case NEGATE_EXPR:
    3683                 :          74 :     case ABS_EXPR:
    3684                 :          74 :     case ABSU_EXPR:
    3685                 :          74 :     case FLOAT_EXPR:
    3686                 :          74 :     case EXCESS_PRECISION_EXPR:
    3687                 :             :       /* These don't change whether an object is nonzero or zero.  */
    3688                 :          74 :       return c_common_truthvalue_conversion (location, TREE_OPERAND (expr, 0));
    3689                 :             : 
    3690                 :           0 :     case LROTATE_EXPR:
    3691                 :           0 :     case RROTATE_EXPR:
    3692                 :             :       /* These don't change whether an object is zero or nonzero, but
    3693                 :             :          we can't ignore them if their second arg has side-effects.  */
    3694                 :           0 :       if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1)))
    3695                 :             :         {
    3696                 :           0 :           expr = build2 (COMPOUND_EXPR, truthvalue_type_node,
    3697                 :           0 :                          TREE_OPERAND (expr, 1),
    3698                 :             :                          c_common_truthvalue_conversion
    3699                 :           0 :                          (location, TREE_OPERAND (expr, 0)));
    3700                 :           0 :           goto ret;
    3701                 :             :         }
    3702                 :             :       else
    3703                 :           0 :         return c_common_truthvalue_conversion (location,
    3704                 :           0 :                                                TREE_OPERAND (expr, 0));
    3705                 :             : 
    3706                 :         502 :     case MULT_EXPR:
    3707                 :         502 :       warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context,
    3708                 :             :                   "%<*%> in boolean context, suggest %<&&%> instead");
    3709                 :         502 :       break;
    3710                 :             : 
    3711                 :         166 :     case LSHIFT_EXPR:
    3712                 :             :       /* We will only warn on signed shifts here, because the majority of
    3713                 :             :          false positive warnings happen in code where unsigned arithmetic
    3714                 :             :          was used in anticipation of a possible overflow.
    3715                 :             :          Furthermore, if we see an unsigned type here we know that the
    3716                 :             :          result of the shift is not subject to integer promotion rules.  */
    3717                 :         166 :       if ((TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
    3718                 :           1 :            || TREE_CODE (TREE_TYPE (expr)) == BITINT_TYPE)
    3719                 :         167 :           && !TYPE_UNSIGNED (TREE_TYPE (expr)))
    3720                 :         150 :         warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context,
    3721                 :             :                     "%<<<%> in boolean context, did you mean %<<%>?");
    3722                 :             :       break;
    3723                 :             : 
    3724                 :       46792 :     case COND_EXPR:
    3725                 :       46792 :       if (warn_int_in_bool_context
    3726                 :       48300 :           && !from_macro_definition_at (EXPR_LOCATION (expr)))
    3727                 :             :         {
    3728                 :         741 :           tree val1 = fold_for_warn (TREE_OPERAND (expr, 1));
    3729                 :         741 :           tree val2 = fold_for_warn (TREE_OPERAND (expr, 2));
    3730                 :         741 :           if (TREE_CODE (val1) == INTEGER_CST
    3731                 :          78 :               && TREE_CODE (val2) == INTEGER_CST
    3732                 :          78 :               && !integer_zerop (val1)
    3733                 :          70 :               && !integer_zerop (val2)
    3734                 :         757 :               && (!integer_onep (val1)
    3735                 :          12 :                   || !integer_onep (val2)))
    3736                 :          12 :             warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context,
    3737                 :             :                         "%<?:%> using integer constants in boolean context, "
    3738                 :             :                         "the expression will always evaluate to %<true%>");
    3739                 :         729 :           else if ((TREE_CODE (val1) == INTEGER_CST
    3740                 :          66 :                     && !integer_zerop (val1)
    3741                 :          58 :                     && !integer_onep (val1))
    3742                 :         795 :                    || (TREE_CODE (val2) == INTEGER_CST
    3743                 :         332 :                        && !integer_zerop (val2)
    3744                 :         274 :                        && !integer_onep (val2)))
    3745                 :           4 :             warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context,
    3746                 :             :                         "%<?:%> using integer constants in boolean context");
    3747                 :             :         }
    3748                 :             :       /* Distribute the conversion into the arms of a COND_EXPR.  */
    3749                 :       46792 :       if (c_dialect_cxx ())
    3750                 :             :         /* Avoid premature folding.  */
    3751                 :             :         break;
    3752                 :             :       else
    3753                 :             :         {
    3754                 :       21613 :           int w = warn_int_in_bool_context;
    3755                 :       21613 :           warn_int_in_bool_context = 0;
    3756                 :             :           /* Folding will happen later for C.  */
    3757                 :       64839 :           expr = build3 (COND_EXPR, truthvalue_type_node,
    3758                 :       21613 :                          TREE_OPERAND (expr, 0),
    3759                 :             :                          c_common_truthvalue_conversion (location,
    3760                 :       21613 :                                                          TREE_OPERAND (expr, 1)),
    3761                 :             :                          c_common_truthvalue_conversion (location,
    3762                 :       21613 :                                                          TREE_OPERAND (expr, 2)));
    3763                 :       21613 :           warn_int_in_bool_context = w;
    3764                 :       21613 :           goto ret;
    3765                 :             :         }
    3766                 :             : 
    3767                 :      589199 :     CASE_CONVERT:
    3768                 :      589199 :       {
    3769                 :      589199 :         tree totype = TREE_TYPE (expr);
    3770                 :      589199 :         tree fromtype = TREE_TYPE (TREE_OPERAND (expr, 0));
    3771                 :             : 
    3772                 :      589199 :         if (POINTER_TYPE_P (totype)
    3773                 :        2016 :             && !c_inhibit_evaluation_warnings
    3774                 :        1848 :             && TREE_CODE (fromtype) == REFERENCE_TYPE)
    3775                 :             :           {
    3776                 :           0 :             tree inner = expr;
    3777                 :           0 :             STRIP_NOPS (inner);
    3778                 :             : 
    3779                 :           0 :             if (DECL_P (inner))
    3780                 :           0 :               warning_at (location,
    3781                 :           0 :                           OPT_Waddress,
    3782                 :             :                           "the compiler can assume that the address of "
    3783                 :             :                           "%qD will always evaluate to %<true%>",
    3784                 :             :                           inner);
    3785                 :             :           }
    3786                 :             : 
    3787                 :             :         /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
    3788                 :             :            since that affects how `default_conversion' will behave.  */
    3789                 :      589199 :         if (TREE_CODE (totype) == REFERENCE_TYPE
    3790                 :      589199 :             || TREE_CODE (fromtype) == REFERENCE_TYPE)
    3791                 :             :           break;
    3792                 :             :         /* Don't strip a conversion from C++0x scoped enum, since they
    3793                 :             :            don't implicitly convert to other types.  */
    3794                 :      589199 :         if (TREE_CODE (fromtype) == ENUMERAL_TYPE
    3795                 :      589199 :             && ENUM_IS_SCOPED (fromtype))
    3796                 :             :           break;
    3797                 :             :         /* If this isn't narrowing the argument, we can ignore it.  */
    3798                 :      589160 :         if (TYPE_PRECISION (totype) >= TYPE_PRECISION (fromtype))
    3799                 :             :           {
    3800                 :      571844 :             tree op0 = TREE_OPERAND (expr, 0);
    3801                 :      571844 :             if ((TREE_CODE (fromtype) == POINTER_TYPE
    3802                 :        1932 :                  && (TREE_CODE (totype) == INTEGER_TYPE
    3803                 :        1932 :                      || TREE_CODE (totype) == BITINT_TYPE))
    3804                 :      573744 :                 || warning_suppressed_p (expr, OPT_Waddress))
    3805                 :             :               /* Suppress -Waddress for casts to intptr_t, propagating
    3806                 :             :                  any suppression from the enclosing expression to its
    3807                 :             :                  operand.  */
    3808                 :          44 :               suppress_warning (op0, OPT_Waddress);
    3809                 :      571844 :             return c_common_truthvalue_conversion (location, op0);
    3810                 :             :           }
    3811                 :             :       }
    3812                 :             :       break;
    3813                 :             : 
    3814                 :        8932 :     case MODIFY_EXPR:
    3815                 :        8932 :       if (!warning_suppressed_p (expr, OPT_Wparentheses)
    3816                 :         321 :           && warn_parentheses
    3817                 :        9253 :           && warning_at (location, OPT_Wparentheses,
    3818                 :             :                          "suggest parentheses around assignment used as "
    3819                 :             :                          "truth value"))
    3820                 :          14 :         suppress_warning (expr, OPT_Wparentheses);
    3821                 :             :       break;
    3822                 :             : 
    3823                 :      240821 :     case CONST_DECL:
    3824                 :      240821 :       {
    3825                 :      240821 :         tree folded_expr = fold_for_warn (expr);
    3826                 :      240821 :         if (folded_expr != expr)
    3827                 :             :           return c_common_truthvalue_conversion (location, folded_expr);
    3828                 :             :       }
    3829                 :             :       break;
    3830                 :             : 
    3831                 :             :     default:
    3832                 :             :       break;
    3833                 :             :     }
    3834                 :             : 
    3835                 :     4563442 :   if (TREE_CODE (TREE_TYPE (expr)) == COMPLEX_TYPE)
    3836                 :             :     {
    3837                 :         405 :       tree t = save_expr (expr);
    3838                 :         405 :       expr = (build_binary_op
    3839                 :         810 :               (EXPR_LOCATION (expr),
    3840                 :         405 :                (TREE_SIDE_EFFECTS (expr)
    3841                 :             :                 ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
    3842                 :             :         c_common_truthvalue_conversion
    3843                 :             :                (location,
    3844                 :             :                 build_unary_op (location, REALPART_EXPR, t, false)),
    3845                 :             :         c_common_truthvalue_conversion
    3846                 :             :                (location,
    3847                 :             :                 build_unary_op (location, IMAGPART_EXPR, t, false)),
    3848                 :             :                false));
    3849                 :         405 :       goto ret;
    3850                 :             :     }
    3851                 :             : 
    3852                 :     4563037 :   if (FIXED_POINT_TYPE_P (TREE_TYPE (expr)))
    3853                 :             :     {
    3854                 :           0 :       tree fixed_zero_node = build_fixed (TREE_TYPE (expr),
    3855                 :           0 :                                           FCONST0 (TYPE_MODE
    3856                 :             :                                                    (TREE_TYPE (expr))));
    3857                 :           0 :       return build_binary_op (location, NE_EXPR, expr, fixed_zero_node, true);
    3858                 :             :     }
    3859                 :             :   else
    3860                 :     4563037 :     return build_binary_op (location, NE_EXPR, expr, integer_zero_node, true);
    3861                 :             : 
    3862                 :      751552 :  ret:
    3863                 :      751552 :   protected_set_expr_location (expr, location);
    3864                 :      751552 :   return expr;
    3865                 :             : }
    3866                 :             : 
    3867                 :             : static void def_builtin_1  (enum built_in_function fncode,
    3868                 :             :                             const char *name,
    3869                 :             :                             enum built_in_class fnclass,
    3870                 :             :                             tree fntype, tree libtype,
    3871                 :             :                             bool both_p, bool fallback_p, bool nonansi_p,
    3872                 :             :                             tree fnattrs, bool implicit_p);
    3873                 :             : 
    3874                 :             : 
    3875                 :             : /* Apply the TYPE_QUALS to the new DECL.  */
    3876                 :             : 
    3877                 :             : void
    3878                 :   969165727 : c_apply_type_quals_to_decl (int type_quals, tree decl)
    3879                 :             : {
    3880                 :   969165727 :   tree type = TREE_TYPE (decl);
    3881                 :             : 
    3882                 :   969165727 :   if (type == error_mark_node)
    3883                 :             :     return;
    3884                 :             : 
    3885                 :   969165502 :   if ((type_quals & TYPE_QUAL_CONST)
    3886                 :   625796532 :       || (type && TREE_CODE (type) == REFERENCE_TYPE))
    3887                 :             :     /* We used to check TYPE_NEEDS_CONSTRUCTING here, but now a constexpr
    3888                 :             :        constructor can produce constant init, so rely on cp_finish_decl to
    3889                 :             :        clear TREE_READONLY if the variable has non-constant init.  */
    3890                 :   436197725 :     TREE_READONLY (decl) = 1;
    3891                 :   969165502 :   if (type_quals & TYPE_QUAL_VOLATILE)
    3892                 :             :     {
    3893                 :      134480 :       TREE_SIDE_EFFECTS (decl) = 1;
    3894                 :      134480 :       TREE_THIS_VOLATILE (decl) = 1;
    3895                 :             :     }
    3896                 :   969165502 :   if (type_quals & TYPE_QUAL_RESTRICT)
    3897                 :             :     {
    3898                 :    11039686 :       while (type && TREE_CODE (type) == ARRAY_TYPE)
    3899                 :             :         /* Allow 'restrict' on arrays of pointers.
    3900                 :             :            FIXME currently we just ignore it.  */
    3901                 :           7 :         type = TREE_TYPE (type);
    3902                 :    11039679 :       if (!type
    3903                 :    11039679 :           || !POINTER_TYPE_P (type)
    3904                 :    22079355 :           || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type)))
    3905                 :           4 :         error ("invalid use of %<restrict%>");
    3906                 :             :     }
    3907                 :             : }
    3908                 :             : 
    3909                 :             : /* Return the typed-based alias set for T, which may be an expression
    3910                 :             :    or a type.  Return -1 if we don't do anything special.  */
    3911                 :             : 
    3912                 :             : alias_set_type
    3913                 :   660176563 : c_common_get_alias_set (tree t)
    3914                 :             : {
    3915                 :             :   /* For VLAs, use the alias set of the element type rather than the
    3916                 :             :      default of alias set 0 for types compared structurally.  */
    3917                 :   660176563 :   if (TYPE_P (t) && TYPE_STRUCTURAL_EQUALITY_P (t))
    3918                 :             :     {
    3919                 :      863288 :       if (TREE_CODE (t) == ARRAY_TYPE)
    3920                 :      432496 :         return get_alias_set (TREE_TYPE (t));
    3921                 :             :       return -1;
    3922                 :             :     }
    3923                 :             : 
    3924                 :             :   /* That's all the expressions we handle specially.  */
    3925                 :   659313275 :   if (!TYPE_P (t))
    3926                 :             :     return -1;
    3927                 :             : 
    3928                 :             :   /* Unlike char, char8_t doesn't alias in C++.  (In C, char8_t is not
    3929                 :             :      a distinct type.)  */
    3930                 :   109938932 :   if (flag_char8_t && t == char8_type_node && c_dialect_cxx ())
    3931                 :             :     return -1;
    3932                 :             : 
    3933                 :             :   /* The C standard guarantees that any object may be accessed via an
    3934                 :             :      lvalue that has narrow character type.  */
    3935                 :   109938857 :   if (t == char_type_node
    3936                 :    73015622 :       || t == signed_char_type_node
    3937                 :    68986466 :       || t == unsigned_char_type_node)
    3938                 :             :     return 0;
    3939                 :             : 
    3940                 :             :   /* The C standard specifically allows aliasing between signed and
    3941                 :             :      unsigned variants of the same type.  We treat the signed
    3942                 :             :      variant as canonical.  */
    3943                 :    57938154 :   if ((TREE_CODE (t) == INTEGER_TYPE || TREE_CODE (t) == BITINT_TYPE)
    3944                 :    57938154 :       && TYPE_UNSIGNED (t))
    3945                 :             :     {
    3946                 :    56300228 :       tree t1 = c_common_signed_type (t);
    3947                 :             : 
    3948                 :             :       /* t1 == t can happen for boolean nodes which are always unsigned.  */
    3949                 :    56300228 :       if (t1 != t)
    3950                 :    56300228 :         return get_alias_set (t1);
    3951                 :             :     }
    3952                 :             : 
    3953                 :             :   return -1;
    3954                 :             : }
    3955                 :             : 
    3956                 :             : /* Compute the value of 'sizeof (TYPE)' or '__alignof__ (TYPE)', where
    3957                 :             :    the IS_SIZEOF parameter indicates which operator is being applied.
    3958                 :             :    The COMPLAIN flag controls whether we should diagnose possibly
    3959                 :             :    ill-formed constructs or not.  LOC is the location of the SIZEOF or
    3960                 :             :    TYPEOF operator.  If MIN_ALIGNOF, the least alignment required for
    3961                 :             :    a type in any context should be returned, rather than the normal
    3962                 :             :    alignment for that type.  */
    3963                 :             : 
    3964                 :             : tree
    3965                 :    19468118 : c_sizeof_or_alignof_type (location_t loc,
    3966                 :             :                           tree type, bool is_sizeof, bool min_alignof,
    3967                 :             :                           int complain)
    3968                 :             : {
    3969                 :    19468118 :   const char *op_name;
    3970                 :    19468118 :   tree value = NULL;
    3971                 :    19468118 :   enum tree_code type_code = TREE_CODE (type);
    3972                 :             : 
    3973                 :    19468118 :   op_name = is_sizeof ? "sizeof" : "__alignof__";
    3974                 :             : 
    3975                 :    19468118 :   if (type_code == FUNCTION_TYPE)
    3976                 :             :     {
    3977                 :          64 :       if (is_sizeof)
    3978                 :             :         {
    3979                 :          58 :           if (complain && warn_pointer_arith)
    3980                 :          28 :             pedwarn (loc, OPT_Wpointer_arith,
    3981                 :             :                      "invalid application of %<sizeof%> to a function type");
    3982                 :             :           else if (!complain)
    3983                 :          20 :             return error_mark_node;
    3984                 :          38 :           value = size_one_node;
    3985                 :             :         }
    3986                 :             :       else
    3987                 :             :         {
    3988                 :           6 :           if (complain)
    3989                 :             :             {
    3990                 :           6 :               if (c_dialect_cxx ())
    3991                 :           4 :                 pedwarn (loc, OPT_Wpedantic, "ISO C++ does not permit "
    3992                 :             :                          "%<alignof%> applied to a function type");
    3993                 :             :               else
    3994                 :           2 :                 pedwarn (loc, OPT_Wpedantic, "ISO C does not permit "
    3995                 :             :                          "%<_Alignof%> applied to a function type");
    3996                 :             :             }
    3997                 :           6 :           value = size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
    3998                 :             :         }
    3999                 :             :     }
    4000                 :    19468054 :   else if (type_code == VOID_TYPE || type_code == ERROR_MARK)
    4001                 :             :     {
    4002                 :          83 :       if (type_code == VOID_TYPE
    4003                 :          83 :           && complain && warn_pointer_arith)
    4004                 :          19 :         pedwarn (loc, OPT_Wpointer_arith,
    4005                 :             :                  "invalid application of %qs to a void type", op_name);
    4006                 :          64 :       else if (!complain)
    4007                 :          30 :         return error_mark_node;
    4008                 :          53 :       value = size_one_node;
    4009                 :             :     }
    4010                 :    19467971 :   else if (!COMPLETE_TYPE_P (type)
    4011                 :    19467971 :            && ((!c_dialect_cxx () && !flag_isoc2y)
    4012                 :             :                || is_sizeof
    4013                 :         144 :                || type_code != ARRAY_TYPE))
    4014                 :             :     {
    4015                 :         271 :       if (complain)
    4016                 :         194 :         error_at (loc, "invalid application of %qs to incomplete type %qT",
    4017                 :             :                   op_name, type);
    4018                 :         271 :       return error_mark_node;
    4019                 :             :     }
    4020                 :    18789062 :   else if (c_dialect_cxx () && type_code == ARRAY_TYPE
    4021                 :    19920898 :            && !COMPLETE_TYPE_P (TREE_TYPE (type)))
    4022                 :             :     {
    4023                 :           0 :       if (complain)
    4024                 :           0 :         error_at (loc, "invalid application of %qs to array type %qT of "
    4025                 :             :                   "incomplete element type", op_name, type);
    4026                 :           0 :       return error_mark_node;
    4027                 :             :     }
    4028                 :    20419997 :   else if (!verify_type_context (loc, is_sizeof ? TCTX_SIZEOF : TCTX_ALIGNOF,
    4029                 :             :                                  type, !complain))
    4030                 :             :     {
    4031                 :           0 :       if (!complain)
    4032                 :           0 :         return error_mark_node;
    4033                 :           0 :       value = size_one_node;
    4034                 :             :     }
    4035                 :             :   else
    4036                 :             :     {
    4037                 :    19467700 :       if (is_sizeof)
    4038                 :             :         /* Convert in case a char is more than one unit.  */
    4039                 :    18515403 :         value = size_binop_loc (loc, CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
    4040                 :    18515403 :                                 size_int (TYPE_PRECISION (char_type_node)
    4041                 :             :                                           / BITS_PER_UNIT));
    4042                 :      952297 :       else if (min_alignof)
    4043                 :      742721 :         value = size_int (min_align_of_type (type));
    4044                 :             :       else
    4045                 :      209576 :         value = size_int (TYPE_ALIGN_UNIT (type));
    4046                 :             :     }
    4047                 :             : 
    4048                 :             :   /* VALUE will have the middle-end integer type sizetype.
    4049                 :             :      However, we should really return a value of type `size_t',
    4050                 :             :      which is just a typedef for an ordinary integer type.  */
    4051                 :    19467797 :   value = fold_convert_loc (loc, size_type_node, value);
    4052                 :             : 
    4053                 :    19467797 :   return value;
    4054                 :             : }
    4055                 :             : 
    4056                 :             : /* Implement the __alignof keyword: Return the minimum required
    4057                 :             :    alignment of EXPR, measured in bytes.  For VAR_DECLs,
    4058                 :             :    FUNCTION_DECLs and FIELD_DECLs return DECL_ALIGN (which can be set
    4059                 :             :    from an "aligned" __attribute__ specification).  LOC is the
    4060                 :             :    location of the ALIGNOF operator.  */
    4061                 :             : 
    4062                 :             : tree
    4063                 :       40793 : c_alignof_expr (location_t loc, tree expr)
    4064                 :             : {
    4065                 :       40793 :   tree t;
    4066                 :             : 
    4067                 :       40793 :   if (!verify_type_context (loc, TCTX_ALIGNOF, TREE_TYPE (expr)))
    4068                 :           0 :     t = size_one_node;
    4069                 :             : 
    4070                 :       40793 :   else if (VAR_OR_FUNCTION_DECL_P (expr))
    4071                 :        7245 :     t = size_int (DECL_ALIGN_UNIT (expr));
    4072                 :             : 
    4073                 :       33548 :   else if (TREE_CODE (expr) == COMPONENT_REF
    4074                 :       33548 :            && DECL_C_BIT_FIELD (TREE_OPERAND (expr, 1)))
    4075                 :             :     {
    4076                 :           1 :       error_at (loc, "%<__alignof%> applied to a bit-field");
    4077                 :           1 :       t = size_one_node;
    4078                 :             :     }
    4079                 :       33547 :   else if (TREE_CODE (expr) == COMPONENT_REF
    4080                 :       33547 :            && TREE_CODE (TREE_OPERAND (expr, 1)) == FIELD_DECL)
    4081                 :       17569 :     t = size_int (DECL_ALIGN_UNIT (TREE_OPERAND (expr, 1)));
    4082                 :             : 
    4083                 :       15978 :   else if (INDIRECT_REF_P (expr))
    4084                 :             :     {
    4085                 :          57 :       tree t = TREE_OPERAND (expr, 0);
    4086                 :          57 :       tree best = t;
    4087                 :          57 :       int bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
    4088                 :             : 
    4089                 :          57 :       while (CONVERT_EXPR_P (t)
    4090                 :          57 :              && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE)
    4091                 :             :         {
    4092                 :           0 :           int thisalign;
    4093                 :             : 
    4094                 :           0 :           t = TREE_OPERAND (t, 0);
    4095                 :           0 :           thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
    4096                 :           0 :           if (thisalign > bestalign)
    4097                 :           0 :             best = t, bestalign = thisalign;
    4098                 :             :         }
    4099                 :          57 :       return c_alignof (loc, TREE_TYPE (TREE_TYPE (best)));
    4100                 :             :     }
    4101                 :             :   else
    4102                 :       15921 :     return c_alignof (loc, TREE_TYPE (expr));
    4103                 :             : 
    4104                 :       24815 :   return fold_convert_loc (loc, size_type_node, t);
    4105                 :             : }
    4106                 :             : 
    4107                 :             : /* Implement the _Countof keyword:
    4108                 :             :    Return the number of elements of an array.  */
    4109                 :             : 
    4110                 :             : tree
    4111                 :          70 : c_countof_type (location_t loc, tree type)
    4112                 :             : {
    4113                 :          70 :   enum tree_code type_code;
    4114                 :             : 
    4115                 :          70 :   type_code = TREE_CODE (type);
    4116                 :          70 :   if (type_code != ARRAY_TYPE)
    4117                 :             :     {
    4118                 :          11 :       error_at (loc, "invalid application of %<_Countof%> to type %qT", type);
    4119                 :          11 :       return error_mark_node;
    4120                 :             :     }
    4121                 :          59 :   if (!COMPLETE_TYPE_P (type))
    4122                 :             :     {
    4123                 :           2 :       error_at (loc,
    4124                 :             :                 "invalid application of %<_Countof%> to incomplete type %qT",
    4125                 :             :                 type);
    4126                 :           2 :       return error_mark_node;
    4127                 :             :     }
    4128                 :             : 
    4129                 :          57 :   return array_type_nelts_top (type);
    4130                 :             : }
    4131                 :             : 
    4132                 :             : /* Handle C and C++ default attributes.  */
    4133                 :             : 
    4134                 :             : enum built_in_attribute
    4135                 :             : {
    4136                 :             : #define DEF_ATTR_NULL_TREE(ENUM) ENUM,
    4137                 :             : #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
    4138                 :             : #define DEF_ATTR_STRING(ENUM, VALUE) ENUM,
    4139                 :             : #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
    4140                 :             : #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
    4141                 :             : #include "builtin-attrs.def"
    4142                 :             : #undef DEF_ATTR_NULL_TREE
    4143                 :             : #undef DEF_ATTR_INT
    4144                 :             : #undef DEF_ATTR_STRING
    4145                 :             : #undef DEF_ATTR_IDENT
    4146                 :             : #undef DEF_ATTR_TREE_LIST
    4147                 :             :   ATTR_LAST
    4148                 :             : };
    4149                 :             : 
    4150                 :             : static GTY(()) tree built_in_attributes[(int) ATTR_LAST];
    4151                 :             : 
    4152                 :             : static void c_init_attributes (void);
    4153                 :             : 
    4154                 :             : enum c_builtin_type
    4155                 :             : {
    4156                 :             : #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
    4157                 :             : #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
    4158                 :             : #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
    4159                 :             : #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
    4160                 :             : #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
    4161                 :             : #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
    4162                 :             : #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
    4163                 :             : #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4164                 :             :                             ARG6) NAME,
    4165                 :             : #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4166                 :             :                             ARG6, ARG7) NAME,
    4167                 :             : #define DEF_FUNCTION_TYPE_8(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4168                 :             :                             ARG6, ARG7, ARG8) NAME,
    4169                 :             : #define DEF_FUNCTION_TYPE_9(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4170                 :             :                             ARG6, ARG7, ARG8, ARG9) NAME,
    4171                 :             : #define DEF_FUNCTION_TYPE_10(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4172                 :             :                              ARG6, ARG7, ARG8, ARG9, ARG10) NAME,
    4173                 :             : #define DEF_FUNCTION_TYPE_11(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4174                 :             :                              ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) NAME,
    4175                 :             : #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
    4176                 :             : #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
    4177                 :             : #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
    4178                 :             : #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
    4179                 :             : #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
    4180                 :             : #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
    4181                 :             :                                 NAME,
    4182                 :             : #define DEF_FUNCTION_TYPE_VAR_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4183                 :             :                                 ARG6) NAME,
    4184                 :             : #define DEF_FUNCTION_TYPE_VAR_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4185                 :             :                                 ARG6, ARG7) NAME,
    4186                 :             : #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
    4187                 :             : #include "builtin-types.def"
    4188                 :             : #undef DEF_PRIMITIVE_TYPE
    4189                 :             : #undef DEF_FUNCTION_TYPE_0
    4190                 :             : #undef DEF_FUNCTION_TYPE_1
    4191                 :             : #undef DEF_FUNCTION_TYPE_2
    4192                 :             : #undef DEF_FUNCTION_TYPE_3
    4193                 :             : #undef DEF_FUNCTION_TYPE_4
    4194                 :             : #undef DEF_FUNCTION_TYPE_5
    4195                 :             : #undef DEF_FUNCTION_TYPE_6
    4196                 :             : #undef DEF_FUNCTION_TYPE_7
    4197                 :             : #undef DEF_FUNCTION_TYPE_8
    4198                 :             : #undef DEF_FUNCTION_TYPE_9
    4199                 :             : #undef DEF_FUNCTION_TYPE_10
    4200                 :             : #undef DEF_FUNCTION_TYPE_11
    4201                 :             : #undef DEF_FUNCTION_TYPE_VAR_0
    4202                 :             : #undef DEF_FUNCTION_TYPE_VAR_1
    4203                 :             : #undef DEF_FUNCTION_TYPE_VAR_2
    4204                 :             : #undef DEF_FUNCTION_TYPE_VAR_3
    4205                 :             : #undef DEF_FUNCTION_TYPE_VAR_4
    4206                 :             : #undef DEF_FUNCTION_TYPE_VAR_5
    4207                 :             : #undef DEF_FUNCTION_TYPE_VAR_6
    4208                 :             : #undef DEF_FUNCTION_TYPE_VAR_7
    4209                 :             : #undef DEF_POINTER_TYPE
    4210                 :             :   BT_LAST
    4211                 :             : };
    4212                 :             : 
    4213                 :             : typedef enum c_builtin_type builtin_type;
    4214                 :             : 
    4215                 :             : /* A temporary array for c_common_nodes_and_builtins.  Used in
    4216                 :             :    communication with def_fn_type.  */
    4217                 :             : static tree builtin_types[(int) BT_LAST + 1];
    4218                 :             : 
    4219                 :             : /* A helper function for c_common_nodes_and_builtins.  Build function type
    4220                 :             :    for DEF with return type RET and N arguments.  If VAR is true, then the
    4221                 :             :    function should be variadic after those N arguments, or, if N is zero,
    4222                 :             :    unprototyped.
    4223                 :             : 
    4224                 :             :    Takes special care not to ICE if any of the types involved are
    4225                 :             :    error_mark_node, which indicates that said type is not in fact available
    4226                 :             :    (see builtin_type_for_size).  In which case the function type as a whole
    4227                 :             :    should be error_mark_node.  */
    4228                 :             : 
    4229                 :             : static void
    4230                 :   104204520 : def_fn_type (builtin_type def, builtin_type ret, bool var, int n, ...)
    4231                 :             : {
    4232                 :   104204520 :   tree t;
    4233                 :   104204520 :   tree *args = XALLOCAVEC (tree, n);
    4234                 :   104204520 :   va_list list;
    4235                 :   104204520 :   int i;
    4236                 :             : 
    4237                 :   104204520 :   va_start (list, n);
    4238                 :   330092065 :   for (i = 0; i < n; ++i)
    4239                 :             :     {
    4240                 :   228829950 :       builtin_type a = (builtin_type) va_arg (list, int);
    4241                 :   228829950 :       t = builtin_types[a];
    4242                 :   228829950 :       if (t == error_mark_node)
    4243                 :     2942405 :         goto egress;
    4244                 :   225887545 :       args[i] = t;
    4245                 :             :     }
    4246                 :             : 
    4247                 :   101262115 :   t = builtin_types[ret];
    4248                 :   101262115 :   if (t == error_mark_node)
    4249                 :      418825 :     goto egress;
    4250                 :   100843290 :   if (var)
    4251                 :     6197335 :     if (n == 0)
    4252                 :      827020 :       t = build_function_type (t, NULL_TREE);
    4253                 :             :     else
    4254                 :     5370315 :       t = build_varargs_function_type_array (t, n, args);
    4255                 :             :   else
    4256                 :    94645955 :     t = build_function_type_array (t, n, args);
    4257                 :             : 
    4258                 :   104204520 :  egress:
    4259                 :   104204520 :   builtin_types[def] = t;
    4260                 :   104204520 :   va_end (list);
    4261                 :   104204520 : }
    4262                 :             : 
    4263                 :             : /* Build builtin functions common to both C and C++ language
    4264                 :             :    frontends.  */
    4265                 :             : 
    4266                 :             : static void
    4267                 :      206755 : c_define_builtins (tree va_list_ref_type_node, tree va_list_arg_type_node)
    4268                 :             : {
    4269                 :             : #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
    4270                 :             :   builtin_types[ENUM] = VALUE;
    4271                 :             : #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
    4272                 :             :   def_fn_type (ENUM, RETURN, 0, 0);
    4273                 :             : #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
    4274                 :             :   def_fn_type (ENUM, RETURN, 0, 1, ARG1);
    4275                 :             : #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
    4276                 :             :   def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
    4277                 :             : #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
    4278                 :             :   def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
    4279                 :             : #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
    4280                 :             :   def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
    4281                 :             : #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
    4282                 :             :   def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
    4283                 :             : #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4284                 :             :                             ARG6)                                       \
    4285                 :             :   def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
    4286                 :             : #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4287                 :             :                             ARG6, ARG7)                                 \
    4288                 :             :   def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
    4289                 :             : #define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4290                 :             :                             ARG6, ARG7, ARG8)                           \
    4291                 :             :   def_fn_type (ENUM, RETURN, 0, 8, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6,  \
    4292                 :             :                ARG7, ARG8);
    4293                 :             : #define DEF_FUNCTION_TYPE_9(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4294                 :             :                             ARG6, ARG7, ARG8, ARG9)                     \
    4295                 :             :   def_fn_type (ENUM, RETURN, 0, 9, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6,  \
    4296                 :             :                ARG7, ARG8, ARG9);
    4297                 :             : #define DEF_FUNCTION_TYPE_10(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4298                 :             :                              ARG6, ARG7, ARG8, ARG9, ARG10)              \
    4299                 :             :   def_fn_type (ENUM, RETURN, 0, 10, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6,  \
    4300                 :             :                ARG7, ARG8, ARG9, ARG10);
    4301                 :             : #define DEF_FUNCTION_TYPE_11(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4302                 :             :                              ARG6, ARG7, ARG8, ARG9, ARG10, ARG11)       \
    4303                 :             :   def_fn_type (ENUM, RETURN, 0, 11, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6,  \
    4304                 :             :                ARG7, ARG8, ARG9, ARG10, ARG11);
    4305                 :             : #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
    4306                 :             :   def_fn_type (ENUM, RETURN, 1, 0);
    4307                 :             : #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
    4308                 :             :   def_fn_type (ENUM, RETURN, 1, 1, ARG1);
    4309                 :             : #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
    4310                 :             :   def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
    4311                 :             : #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
    4312                 :             :   def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
    4313                 :             : #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
    4314                 :             :   def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
    4315                 :             : #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
    4316                 :             :   def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
    4317                 :             : #define DEF_FUNCTION_TYPE_VAR_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4318                 :             :                                 ARG6) \
    4319                 :             :   def_fn_type (ENUM, RETURN, 1, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
    4320                 :             : #define DEF_FUNCTION_TYPE_VAR_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
    4321                 :             :                                 ARG6, ARG7)                             \
    4322                 :             :   def_fn_type (ENUM, RETURN, 1, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
    4323                 :             : #define DEF_POINTER_TYPE(ENUM, TYPE) \
    4324                 :             :   builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
    4325                 :             : 
    4326                 :             : #include "builtin-types.def"
    4327                 :             : 
    4328                 :             : #undef DEF_PRIMITIVE_TYPE
    4329                 :             : #undef DEF_FUNCTION_TYPE_0
    4330                 :             : #undef DEF_FUNCTION_TYPE_1
    4331                 :             : #undef DEF_FUNCTION_TYPE_2
    4332                 :             : #undef DEF_FUNCTION_TYPE_3
    4333                 :             : #undef DEF_FUNCTION_TYPE_4
    4334                 :             : #undef DEF_FUNCTION_TYPE_5
    4335                 :             : #undef DEF_FUNCTION_TYPE_6
    4336                 :             : #undef DEF_FUNCTION_TYPE_7
    4337                 :             : #undef DEF_FUNCTION_TYPE_8
    4338                 :             : #undef DEF_FUNCTION_TYPE_9
    4339                 :             : #undef DEF_FUNCTION_TYPE_10
    4340                 :             : #undef DEF_FUNCTION_TYPE_11
    4341                 :             : #undef DEF_FUNCTION_TYPE_VAR_0
    4342                 :             : #undef DEF_FUNCTION_TYPE_VAR_1
    4343                 :             : #undef DEF_FUNCTION_TYPE_VAR_2
    4344                 :             : #undef DEF_FUNCTION_TYPE_VAR_3
    4345                 :             : #undef DEF_FUNCTION_TYPE_VAR_4
    4346                 :             : #undef DEF_FUNCTION_TYPE_VAR_5
    4347                 :             : #undef DEF_FUNCTION_TYPE_VAR_6
    4348                 :             : #undef DEF_FUNCTION_TYPE_VAR_7
    4349                 :             : #undef DEF_POINTER_TYPE
    4350                 :      206755 :   builtin_types[(int) BT_LAST] = NULL_TREE;
    4351                 :             : 
    4352                 :      206755 :   c_init_attributes ();
    4353                 :             : 
    4354                 :             : #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P, \
    4355                 :             :                     NONANSI_P, ATTRS, IMPLICIT, COND)                   \
    4356                 :             :   if (NAME && COND)                                                     \
    4357                 :             :     def_builtin_1 (ENUM, NAME, CLASS,                                   \
    4358                 :             :                    builtin_types[(int) TYPE],                           \
    4359                 :             :                    builtin_types[(int) LIBTYPE],                        \
    4360                 :             :                    BOTH_P, FALLBACK_P, NONANSI_P,                       \
    4361                 :             :                    built_in_attributes[(int) ATTRS], IMPLICIT);
    4362                 :             : #include "builtins.def"
    4363                 :             : 
    4364                 :      206755 :   targetm.init_builtins ();
    4365                 :             : 
    4366                 :      206755 :   build_common_builtin_nodes ();
    4367                 :      206755 : }
    4368                 :             : 
    4369                 :             : /* Like get_identifier, but avoid warnings about null arguments when
    4370                 :             :    the argument may be NULL for targets where GCC lacks stdint.h type
    4371                 :             :    information.  */
    4372                 :             : 
    4373                 :             : static inline tree
    4374                 :     5582385 : c_get_ident (const char *id)
    4375                 :             : {
    4376                 :     2481060 :   return get_identifier (id);
    4377                 :             : }
    4378                 :             : 
    4379                 :             : /* Build tree nodes and builtin functions common to both C and C++ language
    4380                 :             :    frontends.  */
    4381                 :             : 
    4382                 :             : void
    4383                 :      206755 : c_common_nodes_and_builtins (void)
    4384                 :             : {
    4385                 :      206755 :   int char8_type_size;
    4386                 :      206755 :   int char16_type_size;
    4387                 :      206755 :   int char32_type_size;
    4388                 :      206755 :   int wchar_type_size;
    4389                 :      206755 :   tree array_domain_type;
    4390                 :      206755 :   tree va_list_ref_type_node;
    4391                 :      206755 :   tree va_list_arg_type_node;
    4392                 :      206755 :   int i;
    4393                 :             : 
    4394                 :      206755 :   build_common_tree_nodes (flag_signed_char);
    4395                 :             : 
    4396                 :             :   /* Define `int' and `char' first so that dbx will output them first.  */
    4397                 :      206755 :   record_builtin_type (RID_INT, NULL, integer_type_node);
    4398                 :      206755 :   record_builtin_type (RID_CHAR, "char", char_type_node);
    4399                 :             : 
    4400                 :             :   /* `signed' is the same as `int'.  FIXME: the declarations of "signed",
    4401                 :             :      "unsigned long", "long long unsigned" and "unsigned short" were in C++
    4402                 :             :      but not C.  Are the conditionals here needed?  */
    4403                 :      206755 :   if (c_dialect_cxx ())
    4404                 :       96900 :     record_builtin_type (RID_SIGNED, NULL, integer_type_node);
    4405                 :      206755 :   record_builtin_type (RID_LONG, "long int", long_integer_type_node);
    4406                 :      206755 :   record_builtin_type (RID_UNSIGNED, "unsigned int", unsigned_type_node);
    4407                 :      206755 :   record_builtin_type (RID_MAX, "long unsigned int",
    4408                 :             :                        long_unsigned_type_node);
    4409                 :             : 
    4410                 :      413510 :   for (i = 0; i < NUM_INT_N_ENTS; i ++)
    4411                 :             :     {
    4412                 :      206755 :       char name[25];
    4413                 :             : 
    4414                 :      206755 :       sprintf (name, "__int%d", int_n_data[i].bitsize);
    4415                 :      206755 :       record_builtin_type ((enum rid)(RID_FIRST_INT_N + i), name,
    4416                 :             :                            int_n_trees[i].signed_type);
    4417                 :      206755 :       sprintf (name, "__int%d__", int_n_data[i].bitsize);
    4418                 :      206755 :       record_builtin_type ((enum rid)(RID_FIRST_INT_N + i), name,
    4419                 :             :                            int_n_trees[i].signed_type);
    4420                 :      413510 :       ridpointers[RID_FIRST_INT_N + i]
    4421                 :      206755 :         = DECL_NAME (TYPE_NAME (int_n_trees[i].signed_type));
    4422                 :             : 
    4423                 :      206755 :       sprintf (name, "__int%d unsigned", int_n_data[i].bitsize);
    4424                 :      206755 :       record_builtin_type (RID_MAX, name, int_n_trees[i].unsigned_type);
    4425                 :      206755 :       sprintf (name, "__int%d__ unsigned", int_n_data[i].bitsize);
    4426                 :      206755 :       record_builtin_type (RID_MAX, name, int_n_trees[i].unsigned_type);
    4427                 :             :     }
    4428                 :             : 
    4429                 :      206755 :   if (c_dialect_cxx ())
    4430                 :       96900 :     record_builtin_type (RID_MAX, "unsigned long", long_unsigned_type_node);
    4431                 :      206755 :   record_builtin_type (RID_MAX, "long long int",
    4432                 :             :                        long_long_integer_type_node);
    4433                 :      206755 :   record_builtin_type (RID_MAX, "long long unsigned int",
    4434                 :             :                        long_long_unsigned_type_node);
    4435                 :      206755 :   if (c_dialect_cxx ())
    4436                 :       96900 :     record_builtin_type (RID_MAX, "long long unsigned",
    4437                 :             :                          long_long_unsigned_type_node);
    4438                 :      206755 :   record_builtin_type (RID_SHORT, "short int", short_integer_type_node);
    4439                 :      206755 :   record_builtin_type (RID_MAX, "short unsigned int",
    4440                 :             :                        short_unsigned_type_node);
    4441                 :      206755 :   if (c_dialect_cxx ())
    4442                 :       96900 :     record_builtin_type (RID_MAX, "unsigned short",
    4443                 :             :                          short_unsigned_type_node);
    4444                 :             : 
    4445                 :             :   /* Define both `signed char' and `unsigned char'.  */
    4446                 :      206755 :   record_builtin_type (RID_MAX, "signed char", signed_char_type_node);
    4447                 :      206755 :   record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node);
    4448                 :             : 
    4449                 :             :   /* These are types that c_common_type_for_size and
    4450                 :             :      c_common_type_for_mode use.  */
    4451                 :      206755 :   lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4452                 :             :                                          TYPE_DECL, NULL_TREE,
    4453                 :             :                                          intQI_type_node));
    4454                 :      206755 :   lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4455                 :             :                                          TYPE_DECL, NULL_TREE,
    4456                 :             :                                          intHI_type_node));
    4457                 :      206755 :   lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4458                 :             :                                          TYPE_DECL, NULL_TREE,
    4459                 :             :                                          intSI_type_node));
    4460                 :      206755 :   lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4461                 :             :                                          TYPE_DECL, NULL_TREE,
    4462                 :             :                                          intDI_type_node));
    4463                 :             : #if HOST_BITS_PER_WIDE_INT >= 64
    4464                 :             :   /* Note that this is different than the __int128 type that's part of
    4465                 :             :      the generic __intN support.  */
    4466                 :      206755 :   if (targetm.scalar_mode_supported_p (TImode))
    4467                 :      201440 :     lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4468                 :             :                                            TYPE_DECL,
    4469                 :             :                                            get_identifier ("__int128_t"),
    4470                 :             :                                            intTI_type_node));
    4471                 :             : #endif
    4472                 :      206755 :   lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4473                 :             :                                          TYPE_DECL, NULL_TREE,
    4474                 :             :                                          unsigned_intQI_type_node));
    4475                 :      206755 :   lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4476                 :             :                                          TYPE_DECL, NULL_TREE,
    4477                 :             :                                          unsigned_intHI_type_node));
    4478                 :      206755 :   lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4479                 :             :                                          TYPE_DECL, NULL_TREE,
    4480                 :             :                                          unsigned_intSI_type_node));
    4481                 :      206755 :   lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4482                 :             :                                          TYPE_DECL, NULL_TREE,
    4483                 :             :                                          unsigned_intDI_type_node));
    4484                 :             : #if HOST_BITS_PER_WIDE_INT >= 64
    4485                 :      206755 :   if (targetm.scalar_mode_supported_p (TImode))
    4486                 :      201440 :     lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4487                 :             :                                            TYPE_DECL,
    4488                 :             :                                            get_identifier ("__uint128_t"),
    4489                 :             :                                            unsigned_intTI_type_node));
    4490                 :             : #endif
    4491                 :             : 
    4492                 :             :   /* Create the widest literal types.  */
    4493                 :      206755 :   if (targetm.scalar_mode_supported_p (TImode))
    4494                 :             :     {
    4495                 :      201440 :       widest_integer_literal_type_node = intTI_type_node;
    4496                 :      201440 :       widest_unsigned_literal_type_node = unsigned_intTI_type_node;
    4497                 :             :     }
    4498                 :             :   else
    4499                 :             :     {
    4500                 :        5315 :       widest_integer_literal_type_node = intDI_type_node;
    4501                 :        5315 :       widest_unsigned_literal_type_node = unsigned_intDI_type_node;
    4502                 :             :     }
    4503                 :             : 
    4504                 :      206755 :   signed_size_type_node = c_common_signed_type (size_type_node);
    4505                 :             : 
    4506                 :      413510 :   pid_type_node =
    4507                 :      206755 :     TREE_TYPE (identifier_global_value (get_identifier (PID_TYPE)));
    4508                 :             : 
    4509                 :      206755 :   record_builtin_type (RID_FLOAT, NULL, float_type_node);
    4510                 :      206755 :   record_builtin_type (RID_DOUBLE, NULL, double_type_node);
    4511                 :      206755 :   record_builtin_type (RID_MAX, "long double", long_double_type_node);
    4512                 :             : 
    4513                 :     1860795 :   for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
    4514                 :             :     {
    4515                 :     1447285 :       if (FLOATN_NX_TYPE_NODE (i) != NULL_TREE)
    4516                 :     1240530 :         record_builtin_type ((enum rid) (RID_FLOATN_NX_FIRST + i), NULL,
    4517                 :             :                              FLOATN_NX_TYPE_NODE (i));
    4518                 :             :     }
    4519                 :             : 
    4520                 :             :   /* For C, let float128t_type_node (__float128 in some backends) be the
    4521                 :             :      same type as float128_type_node (_Float128), for C++ let those
    4522                 :             :      be distinct types that mangle and behave differently.  */
    4523                 :      206755 :   if (c_dialect_cxx ())
    4524                 :       96900 :     float128t_type_node = NULL_TREE;
    4525                 :             : 
    4526                 :             :   /* Only supported decimal floating point extension if the target
    4527                 :             :      actually supports underlying modes. */
    4528                 :      206755 :   if (targetm.scalar_mode_supported_p (SDmode)
    4529                 :      206755 :       && targetm.scalar_mode_supported_p (DDmode)
    4530                 :      413510 :       && targetm.scalar_mode_supported_p (TDmode))
    4531                 :             :     {
    4532                 :      206755 :       record_builtin_type (RID_DFLOAT32, NULL, dfloat32_type_node);
    4533                 :      206755 :       record_builtin_type (RID_DFLOAT64, NULL, dfloat64_type_node);
    4534                 :      206755 :       record_builtin_type (RID_DFLOAT128, NULL, dfloat128_type_node);
    4535                 :      206755 :       record_builtin_type (RID_DFLOAT64X, NULL, dfloat64x_type_node);
    4536                 :             :     }
    4537                 :             : 
    4538                 :      206755 :   if (targetm.fixed_point_supported_p ())
    4539                 :             :     {
    4540                 :           0 :       record_builtin_type (RID_MAX, "short _Fract", short_fract_type_node);
    4541                 :           0 :       record_builtin_type (RID_FRACT, NULL, fract_type_node);
    4542                 :           0 :       record_builtin_type (RID_MAX, "long _Fract", long_fract_type_node);
    4543                 :           0 :       record_builtin_type (RID_MAX, "long long _Fract",
    4544                 :             :                            long_long_fract_type_node);
    4545                 :           0 :       record_builtin_type (RID_MAX, "unsigned short _Fract",
    4546                 :             :                            unsigned_short_fract_type_node);
    4547                 :           0 :       record_builtin_type (RID_MAX, "unsigned _Fract",
    4548                 :             :                            unsigned_fract_type_node);
    4549                 :           0 :       record_builtin_type (RID_MAX, "unsigned long _Fract",
    4550                 :             :                            unsigned_long_fract_type_node);
    4551                 :           0 :       record_builtin_type (RID_MAX, "unsigned long long _Fract",
    4552                 :             :                            unsigned_long_long_fract_type_node);
    4553                 :           0 :       record_builtin_type (RID_MAX, "_Sat short _Fract",
    4554                 :             :                            sat_short_fract_type_node);
    4555                 :           0 :       record_builtin_type (RID_MAX, "_Sat _Fract", sat_fract_type_node);
    4556                 :           0 :       record_builtin_type (RID_MAX, "_Sat long _Fract",
    4557                 :             :                            sat_long_fract_type_node);
    4558                 :           0 :       record_builtin_type (RID_MAX, "_Sat long long _Fract",
    4559                 :             :                            sat_long_long_fract_type_node);
    4560                 :           0 :       record_builtin_type (RID_MAX, "_Sat unsigned short _Fract",
    4561                 :             :                            sat_unsigned_short_fract_type_node);
    4562                 :           0 :       record_builtin_type (RID_MAX, "_Sat unsigned _Fract",
    4563                 :             :                            sat_unsigned_fract_type_node);
    4564                 :           0 :       record_builtin_type (RID_MAX, "_Sat unsigned long _Fract",
    4565                 :             :                            sat_unsigned_long_fract_type_node);
    4566                 :           0 :       record_builtin_type (RID_MAX, "_Sat unsigned long long _Fract",
    4567                 :             :                            sat_unsigned_long_long_fract_type_node);
    4568                 :           0 :       record_builtin_type (RID_MAX, "short _Accum", short_accum_type_node);
    4569                 :           0 :       record_builtin_type (RID_ACCUM, NULL, accum_type_node);
    4570                 :           0 :       record_builtin_type (RID_MAX, "long _Accum", long_accum_type_node);
    4571                 :           0 :       record_builtin_type (RID_MAX, "long long _Accum",
    4572                 :             :                            long_long_accum_type_node);
    4573                 :           0 :       record_builtin_type (RID_MAX, "unsigned short _Accum",
    4574                 :             :                            unsigned_short_accum_type_node);
    4575                 :           0 :       record_builtin_type (RID_MAX, "unsigned _Accum",
    4576                 :             :                            unsigned_accum_type_node);
    4577                 :           0 :       record_builtin_type (RID_MAX, "unsigned long _Accum",
    4578                 :             :                            unsigned_long_accum_type_node);
    4579                 :           0 :       record_builtin_type (RID_MAX, "unsigned long long _Accum",
    4580                 :             :                            unsigned_long_long_accum_type_node);
    4581                 :           0 :       record_builtin_type (RID_MAX, "_Sat short _Accum",
    4582                 :             :                            sat_short_accum_type_node);
    4583                 :           0 :       record_builtin_type (RID_MAX, "_Sat _Accum", sat_accum_type_node);
    4584                 :           0 :       record_builtin_type (RID_MAX, "_Sat long _Accum",
    4585                 :             :                            sat_long_accum_type_node);
    4586                 :           0 :       record_builtin_type (RID_MAX, "_Sat long long _Accum",
    4587                 :             :                           sat_long_long_accum_type_node);
    4588                 :           0 :       record_builtin_type (RID_MAX, "_Sat unsigned short _Accum",
    4589                 :             :                            sat_unsigned_short_accum_type_node);
    4590                 :           0 :       record_builtin_type (RID_MAX, "_Sat unsigned _Accum",
    4591                 :             :                            sat_unsigned_accum_type_node);
    4592                 :           0 :       record_builtin_type (RID_MAX, "_Sat unsigned long _Accum",
    4593                 :             :                            sat_unsigned_long_accum_type_node);
    4594                 :           0 :       record_builtin_type (RID_MAX, "_Sat unsigned long long _Accum",
    4595                 :             :                            sat_unsigned_long_long_accum_type_node);
    4596                 :             : 
    4597                 :             :     }
    4598                 :             : 
    4599                 :      206755 :   lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4600                 :             :                                          TYPE_DECL,
    4601                 :             :                                          get_identifier ("complex int"),
    4602                 :             :                                          complex_integer_type_node));
    4603                 :      206755 :   lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4604                 :             :                                          TYPE_DECL,
    4605                 :             :                                          get_identifier ("complex float"),
    4606                 :             :                                          complex_float_type_node));
    4607                 :      206755 :   lang_hooks.decls.pushdecl (build_decl (UNKNOWN_LOCATION,
    4608                 :             :                                          TYPE_DECL,
    4609                 :             :                                          get_identifier ("complex double"),
    4610                 :             :                                          complex_double_type_node));
    4611                 :      206755 :   lang_hooks.decls.pushdecl
    4612                 :      206755 :     (build_decl (UNKNOWN_LOCATION,
    4613                 :             :                  TYPE_DECL, get_identifier ("complex long double"),
    4614                 :             :                  complex_long_double_type_node));
    4615                 :             : 
    4616                 :      206755 :   if (!c_dialect_cxx ())
    4617                 :      878840 :     for (i = 0; i < NUM_FLOATN_NX_TYPES; i++)
    4618                 :      768985 :       if (COMPLEX_FLOATN_NX_TYPE_NODE (i) != NULL_TREE)
    4619                 :             :         {
    4620                 :      659130 :           char buf[30];
    4621                 :     1318260 :           sprintf (buf, "complex _Float%d%s", floatn_nx_types[i].n,
    4622                 :      659130 :                    floatn_nx_types[i].extended ? "x" : "");
    4623                 :      659130 :           lang_hooks.decls.pushdecl
    4624                 :      659130 :             (build_decl (UNKNOWN_LOCATION,
    4625                 :             :                          TYPE_DECL,
    4626                 :             :                          get_identifier (buf),
    4627                 :             :                          COMPLEX_FLOATN_NX_TYPE_NODE (i)));
    4628                 :             :         }
    4629                 :             : 
    4630                 :             :   /* Make fileptr_type_node a distinct void * type until
    4631                 :             :      FILE type is defined.  Likewise for const struct tm*.  */
    4632                 :     1447285 :   for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
    4633                 :     1240530 :     builtin_structptr_types[i].node
    4634                 :     1240530 :       = build_variant_type_copy (builtin_structptr_types[i].base);
    4635                 :             : 
    4636                 :      206755 :   record_builtin_type (RID_VOID, NULL, void_type_node);
    4637                 :             : 
    4638                 :             :   /* Set the TYPE_NAME for any variants that were built before
    4639                 :             :      record_builtin_type gave names to the built-in types. */
    4640                 :      206755 :   {
    4641                 :      206755 :     tree void_name = TYPE_NAME (void_type_node);
    4642                 :      206755 :     TYPE_NAME (void_type_node) = NULL_TREE;
    4643                 :      206755 :     TYPE_NAME (build_qualified_type (void_type_node, TYPE_QUAL_CONST))
    4644                 :      206755 :       = void_name;
    4645                 :      206755 :     TYPE_NAME (void_type_node) = void_name;
    4646                 :             :   }
    4647                 :             : 
    4648                 :             :   /* Make a type to be the domain of a few array types
    4649                 :             :      whose domains don't really matter.
    4650                 :             :      200 is small enough that it always fits in size_t
    4651                 :             :      and large enough that it can hold most function names for the
    4652                 :             :      initializations of __FUNCTION__ and __PRETTY_FUNCTION__.  */
    4653                 :      206755 :   array_domain_type = build_index_type (size_int (200));
    4654                 :             : 
    4655                 :             :   /* Make a type for arrays of characters.
    4656                 :             :      With luck nothing will ever really depend on the length of this
    4657                 :             :      array type.  */
    4658                 :      206755 :   char_array_type_node
    4659                 :      206755 :     = build_array_type (char_type_node, array_domain_type);
    4660                 :             : 
    4661                 :      206755 :   string_type_node = build_pointer_type (char_type_node);
    4662                 :      206755 :   const_string_type_node
    4663                 :      206755 :     = build_pointer_type (build_qualified_type
    4664                 :             :                           (char_type_node, TYPE_QUAL_CONST));
    4665                 :             : 
    4666                 :             :   /* This is special for C++ so functions can be overloaded.  */
    4667                 :      212168 :   wchar_type_node = get_identifier (MODIFIED_WCHAR_TYPE);
    4668                 :      206755 :   wchar_type_node = TREE_TYPE (identifier_global_value (wchar_type_node));
    4669                 :      206755 :   wchar_type_size = TYPE_PRECISION (wchar_type_node);
    4670                 :      206755 :   underlying_wchar_type_node = wchar_type_node;
    4671                 :      206755 :   if (c_dialect_cxx ())
    4672                 :             :     {
    4673                 :       96900 :       if (TYPE_UNSIGNED (wchar_type_node))
    4674                 :           7 :         wchar_type_node = make_unsigned_type (wchar_type_size);
    4675                 :             :       else
    4676                 :       96893 :         wchar_type_node = make_signed_type (wchar_type_size);
    4677                 :       96900 :       record_builtin_type (RID_WCHAR, "wchar_t", wchar_type_node);
    4678                 :             :     }
    4679                 :             : 
    4680                 :             :   /* This is for wide string constants.  */
    4681                 :      206755 :   wchar_array_type_node
    4682                 :      206755 :     = build_array_type (wchar_type_node, array_domain_type);
    4683                 :             : 
    4684                 :             :   /* Define 'char8_t'.  */
    4685                 :      206755 :   char8_type_node = get_identifier (CHAR8_TYPE);
    4686                 :      206755 :   char8_type_node = TREE_TYPE (identifier_global_value (char8_type_node));
    4687                 :      206755 :   char8_type_size = TYPE_PRECISION (char8_type_node);
    4688                 :      206755 :   if (c_dialect_cxx ())
    4689                 :             :     {
    4690                 :       96900 :       char8_type_node = make_unsigned_type (char8_type_size);
    4691                 :       96900 :       TYPE_STRING_FLAG (char8_type_node) = true;
    4692                 :             : 
    4693                 :       96900 :       if (flag_char8_t)
    4694                 :       30514 :         record_builtin_type (RID_CHAR8, "char8_t", char8_type_node);
    4695                 :             :     }
    4696                 :             : 
    4697                 :             :   /* This is for UTF-8 string constants.  */
    4698                 :      206755 :   char8_array_type_node
    4699                 :      206755 :     = build_array_type (char8_type_node, array_domain_type);
    4700                 :             : 
    4701                 :             :   /* Define 'char16_t'.  */
    4702                 :      206755 :   char16_type_node = get_identifier (CHAR16_TYPE);
    4703                 :      206755 :   char16_type_node = TREE_TYPE (identifier_global_value (char16_type_node));
    4704                 :      206755 :   char16_type_size = TYPE_PRECISION (char16_type_node);
    4705                 :      206755 :   if (c_dialect_cxx ())
    4706                 :             :     {
    4707                 :       96900 :       char16_type_node = make_unsigned_type (char16_type_size);
    4708                 :             : 
    4709                 :       96900 :       if (cxx_dialect >= cxx11)
    4710                 :       82858 :         record_builtin_type (RID_CHAR16, "char16_t", char16_type_node);
    4711                 :             :     }
    4712                 :             : 
    4713                 :             :   /* This is for UTF-16 string constants.  */
    4714                 :      206755 :   char16_array_type_node
    4715                 :      206755 :     = build_array_type (char16_type_node, array_domain_type);
    4716                 :             : 
    4717                 :             :   /* Define 'char32_t'.  */
    4718                 :      206755 :   char32_type_node = get_identifier (CHAR32_TYPE);
    4719                 :      206755 :   char32_type_node = TREE_TYPE (identifier_global_value (char32_type_node));
    4720                 :      206755 :   char32_type_size = TYPE_PRECISION (char32_type_node);
    4721                 :      206755 :   if (c_dialect_cxx ())
    4722                 :             :     {
    4723                 :       96900 :       char32_type_node = make_unsigned_type (char32_type_size);
    4724                 :             : 
    4725                 :       96900 :       if (cxx_dialect >= cxx11)
    4726                 :       82858 :         record_builtin_type (RID_CHAR32, "char32_t", char32_type_node);
    4727                 :             :     }
    4728                 :             : 
    4729                 :             :   /* This is for UTF-32 string constants.  */
    4730                 :      206755 :   char32_array_type_node
    4731                 :      206755 :     = build_array_type (char32_type_node, array_domain_type);
    4732                 :             : 
    4733                 :      206755 :   if (strcmp (WINT_TYPE, "wchar_t") == 0)
    4734                 :             :     wint_type_node = wchar_type_node;
    4735                 :             :   else
    4736                 :      413510 :     wint_type_node =
    4737                 :      206755 :       TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE)));
    4738                 :             : 
    4739                 :      413510 :   intmax_type_node =
    4740                 :      212168 :     TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE)));
    4741                 :      413510 :   uintmax_type_node =
    4742                 :      212168 :     TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE)));
    4743                 :             : 
    4744                 :      206755 :   if (SIG_ATOMIC_TYPE)
    4745                 :      206755 :     sig_atomic_type_node =
    4746                 :      206755 :       TREE_TYPE (identifier_global_value (c_get_ident (SIG_ATOMIC_TYPE)));
    4747                 :      206755 :   if (INT8_TYPE)
    4748                 :      206755 :     int8_type_node =
    4749                 :      206755 :       TREE_TYPE (identifier_global_value (c_get_ident (INT8_TYPE)));
    4750                 :      206755 :   if (INT16_TYPE)
    4751                 :      206755 :     int16_type_node =
    4752                 :      206755 :       TREE_TYPE (identifier_global_value (c_get_ident (INT16_TYPE)));
    4753                 :      206755 :   if (INT32_TYPE)
    4754                 :      206755 :     int32_type_node =
    4755                 :      206755 :       TREE_TYPE (identifier_global_value (c_get_ident (INT32_TYPE)));
    4756                 :      206755 :   if (INT64_TYPE)
    4757                 :      413510 :     int64_type_node =
    4758                 :      413510 :       TREE_TYPE (identifier_global_value (c_get_ident (INT64_TYPE)));
    4759                 :      206755 :   if (UINT8_TYPE)
    4760                 :      206755 :     uint8_type_node =
    4761                 :      206755 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT8_TYPE)));
    4762                 :      206755 :   if (UINT16_TYPE)
    4763                 :      206755 :     c_uint16_type_node = uint16_type_node =
    4764                 :      206755 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT16_TYPE)));
    4765                 :      206755 :   if (UINT32_TYPE)
    4766                 :      206755 :     c_uint32_type_node = uint32_type_node =
    4767                 :      206755 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT32_TYPE)));
    4768                 :      206755 :   if (UINT64_TYPE)
    4769                 :      413510 :     c_uint64_type_node = uint64_type_node =
    4770                 :      413510 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT64_TYPE)));
    4771                 :      206755 :   if (INT_LEAST8_TYPE)
    4772                 :      206755 :     int_least8_type_node =
    4773                 :      206755 :       TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST8_TYPE)));
    4774                 :      206755 :   if (INT_LEAST16_TYPE)
    4775                 :      206755 :     int_least16_type_node =
    4776                 :      206755 :       TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST16_TYPE)));
    4777                 :      206755 :   if (INT_LEAST32_TYPE)
    4778                 :      206755 :     int_least32_type_node =
    4779                 :      206755 :       TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST32_TYPE)));
    4780                 :      206755 :   if (INT_LEAST64_TYPE)
    4781                 :      413510 :     int_least64_type_node =
    4782                 :      413510 :       TREE_TYPE (identifier_global_value (c_get_ident (INT_LEAST64_TYPE)));
    4783                 :      206755 :   if (UINT_LEAST8_TYPE)
    4784                 :      206755 :     uint_least8_type_node =
    4785                 :      206755 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST8_TYPE)));
    4786                 :      206755 :   if (UINT_LEAST16_TYPE)
    4787                 :      206755 :     uint_least16_type_node =
    4788                 :      206755 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST16_TYPE)));
    4789                 :      206755 :   if (UINT_LEAST32_TYPE)
    4790                 :      206755 :     uint_least32_type_node =
    4791                 :      206755 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST32_TYPE)));
    4792                 :      206755 :   if (UINT_LEAST64_TYPE)
    4793                 :      413510 :     uint_least64_type_node =
    4794                 :      413510 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT_LEAST64_TYPE)));
    4795                 :      206755 :   if (INT_FAST8_TYPE)
    4796                 :      206755 :     int_fast8_type_node =
    4797                 :      206755 :       TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST8_TYPE)));
    4798                 :      206755 :   if (INT_FAST16_TYPE)
    4799                 :      413510 :     int_fast16_type_node =
    4800                 :      413510 :       TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST16_TYPE)));
    4801                 :      206755 :   if (INT_FAST32_TYPE)
    4802                 :      413510 :     int_fast32_type_node =
    4803                 :      413510 :       TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST32_TYPE)));
    4804                 :      206755 :   if (INT_FAST64_TYPE)
    4805                 :      413510 :     int_fast64_type_node =
    4806                 :      413510 :       TREE_TYPE (identifier_global_value (c_get_ident (INT_FAST64_TYPE)));
    4807                 :      206755 :   if (UINT_FAST8_TYPE)
    4808                 :      206755 :     uint_fast8_type_node =
    4809                 :      206755 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST8_TYPE)));
    4810                 :      206755 :   if (UINT_FAST16_TYPE)
    4811                 :      413510 :     uint_fast16_type_node =
    4812                 :      413510 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST16_TYPE)));
    4813                 :      206755 :   if (UINT_FAST32_TYPE)
    4814                 :      413510 :     uint_fast32_type_node =
    4815                 :      413510 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST32_TYPE)));
    4816                 :      206755 :   if (UINT_FAST64_TYPE)
    4817                 :      413510 :     uint_fast64_type_node =
    4818                 :      413510 :       TREE_TYPE (identifier_global_value (c_get_ident (UINT_FAST64_TYPE)));
    4819                 :      206755 :   if (INTPTR_TYPE)
    4820                 :      413510 :     intptr_type_node =
    4821                 :      413510 :       TREE_TYPE (identifier_global_value (c_get_ident (INTPTR_TYPE)));
    4822                 :      206755 :   if (UINTPTR_TYPE)
    4823                 :      413510 :     uintptr_type_node =
    4824                 :      413510 :       TREE_TYPE (identifier_global_value (c_get_ident (UINTPTR_TYPE)));
    4825                 :             : 
    4826                 :      206755 :   default_function_type = build_function_type (integer_type_node, NULL_TREE);
    4827                 :      206755 :   unsigned_ptrdiff_type_node = c_common_unsigned_type (ptrdiff_type_node);
    4828                 :             : 
    4829                 :      206755 :   lang_hooks.decls.pushdecl
    4830                 :      206755 :     (build_decl (UNKNOWN_LOCATION,
    4831                 :             :                  TYPE_DECL, get_identifier ("__builtin_va_list"),
    4832                 :             :                  va_list_type_node));
    4833                 :      206755 :   if (targetm.enum_va_list_p)
    4834                 :             :     {
    4835                 :             :       int l;
    4836                 :             :       const char *pname;
    4837                 :             :       tree ptype;
    4838                 :             : 
    4839                 :      609635 :       for (l = 0; targetm.enum_va_list_p (l, &pname, &ptype); ++l)
    4840                 :             :         {
    4841                 :      402880 :           lang_hooks.decls.pushdecl
    4842                 :      402880 :             (build_decl (UNKNOWN_LOCATION,
    4843                 :             :                          TYPE_DECL, get_identifier (pname),
    4844                 :             :                          ptype));
    4845                 :             : 
    4846                 :             :         }
    4847                 :             :     }
    4848                 :             : 
    4849                 :      206755 :   if (TREE_CODE (va_list_type_node) == ARRAY_TYPE)
    4850                 :             :     {
    4851                 :      402796 :       va_list_arg_type_node = va_list_ref_type_node =
    4852                 :      201398 :         build_pointer_type (TREE_TYPE (va_list_type_node));
    4853                 :             :     }
    4854                 :             :   else
    4855                 :             :     {
    4856                 :        5357 :       va_list_arg_type_node = va_list_type_node;
    4857                 :        5357 :       va_list_ref_type_node = build_reference_type (va_list_type_node);
    4858                 :             :     }
    4859                 :             : 
    4860                 :      206755 :   c_define_builtins (va_list_ref_type_node, va_list_arg_type_node);
    4861                 :             : 
    4862                 :      206755 :   main_identifier_node = get_identifier ("main");
    4863                 :             : 
    4864                 :             :   /* Create the built-in __null node.  It is important that this is
    4865                 :             :      not shared.  */
    4866                 :      206755 :   null_node = make_int_cst (1, 1);
    4867                 :      212168 :   TREE_TYPE (null_node) = c_common_type_for_size (POINTER_SIZE, 0);
    4868                 :             : 
    4869                 :             :   /* Create the built-in nullptr node.  This part of its initialization is
    4870                 :             :      common to C and C++.  The front ends can further adjust its definition
    4871                 :             :      in {c,cxx}_init_decl_processing.  In particular, we aren't setting the
    4872                 :             :      alignment here for C++ backward ABI bug compatibility.  */
    4873                 :      206755 :   nullptr_type_node = make_node (NULLPTR_TYPE);
    4874                 :      413510 :   TYPE_SIZE (nullptr_type_node) = bitsize_int (GET_MODE_BITSIZE (ptr_mode));
    4875                 :      413510 :   TYPE_SIZE_UNIT (nullptr_type_node) = size_int (GET_MODE_SIZE (ptr_mode));
    4876                 :      206755 :   TYPE_UNSIGNED (nullptr_type_node) = 1;
    4877                 :      413510 :   TYPE_PRECISION (nullptr_type_node) = GET_MODE_BITSIZE (ptr_mode);
    4878                 :      206755 :   SET_TYPE_MODE (nullptr_type_node, ptr_mode);
    4879                 :      206755 :   nullptr_node = build_int_cst (nullptr_type_node, 0);
    4880                 :             : 
    4881                 :             :   /* Since builtin_types isn't gc'ed, don't export these nodes.  */
    4882                 :      206755 :   memset (builtin_types, 0, sizeof (builtin_types));
    4883                 :      206755 : }
    4884                 :             : 
    4885                 :             : /* The number of named compound-literals generated thus far.  */
    4886                 :             : static GTY(()) int compound_literal_number;
    4887                 :             : 
    4888                 :             : /* Set DECL_NAME for DECL, a VAR_DECL for a compound-literal.  */
    4889                 :             : 
    4890                 :             : void
    4891                 :         273 : set_compound_literal_name (tree decl)
    4892                 :             : {
    4893                 :         273 :   char *name;
    4894                 :         273 :   ASM_FORMAT_PRIVATE_NAME (name, "__compound_literal",
    4895                 :             :                            compound_literal_number);
    4896                 :         273 :   compound_literal_number++;
    4897                 :         273 :   DECL_NAME (decl) = get_identifier (name);
    4898                 :         273 : }
    4899                 :             : 
    4900                 :             : /* build_va_arg helper function.  Return a VA_ARG_EXPR with location LOC, type
    4901                 :             :    TYPE and operand OP.  */
    4902                 :             : 
    4903                 :             : static tree
    4904                 :       50813 : build_va_arg_1 (location_t loc, tree type, tree op)
    4905                 :             : {
    4906                 :       50813 :   tree expr = build1 (VA_ARG_EXPR, type, op);
    4907                 :       50813 :   SET_EXPR_LOCATION (expr, loc);
    4908                 :       50813 :   return expr;
    4909                 :             : }
    4910                 :             : 
    4911                 :             : /* Return a VA_ARG_EXPR corresponding to a source-level expression
    4912                 :             :    va_arg (EXPR, TYPE) at source location LOC.  */
    4913                 :             : 
    4914                 :             : tree
    4915                 :       50813 : build_va_arg (location_t loc, tree expr, tree type)
    4916                 :             : {
    4917                 :       50813 :   tree va_type = TREE_TYPE (expr);
    4918                 :       50813 :   tree canon_va_type = (va_type == error_mark_node
    4919                 :       50813 :                         ? error_mark_node
    4920                 :       50803 :                         : targetm.canonical_va_list_type (va_type));
    4921                 :             : 
    4922                 :       50813 :   if (va_type == error_mark_node
    4923                 :       50803 :       || canon_va_type == NULL_TREE)
    4924                 :             :     {
    4925                 :          10 :       if (canon_va_type == NULL_TREE)
    4926                 :          12 :         error_at (loc, "first argument to %<va_arg%> not of type %<va_list%>");
    4927                 :             : 
    4928                 :             :       /* Let's handle things neutrally, if expr:
    4929                 :             :          - has undeclared type, or
    4930                 :             :          - is not an va_list type.  */
    4931                 :          22 :       return build_va_arg_1 (loc, type, error_mark_node);
    4932                 :             :     }
    4933                 :             : 
    4934                 :       50791 :   if (TREE_CODE (canon_va_type) != ARRAY_TYPE)
    4935                 :             :     {
    4936                 :             :       /* Case 1: Not an array type.  */
    4937                 :             : 
    4938                 :             :       /* Take the address, to get '&ap'.  Note that &ap is not a va_list
    4939                 :             :          type.  */
    4940                 :         258 :       c_common_mark_addressable_vec (expr);
    4941                 :         258 :       expr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (expr)), expr);
    4942                 :             : 
    4943                 :         258 :       return build_va_arg_1 (loc, type, expr);
    4944                 :             :     }
    4945                 :             : 
    4946                 :             :   /* Case 2: Array type.
    4947                 :             : 
    4948                 :             :      Background:
    4949                 :             : 
    4950                 :             :      For contrast, let's start with the simple case (case 1).  If
    4951                 :             :      canon_va_type is not an array type, but say a char *, then when
    4952                 :             :      passing-by-value a va_list, the type of the va_list param decl is
    4953                 :             :      the same as for another va_list decl (all ap's are char *):
    4954                 :             : 
    4955                 :             :      f2_1 (char * ap)
    4956                 :             :        D.1815 = VA_ARG (&ap, 0B, 1);
    4957                 :             :        return D.1815;
    4958                 :             : 
    4959                 :             :      f2 (int i)
    4960                 :             :        char * ap.0;
    4961                 :             :        char * ap;
    4962                 :             :        __builtin_va_start (&ap, 0);
    4963                 :             :        ap.0 = ap;
    4964                 :             :        res = f2_1 (ap.0);
    4965                 :             :        __builtin_va_end (&ap);
    4966                 :             :        D.1812 = res;
    4967                 :             :        return D.1812;
    4968                 :             : 
    4969                 :             :      However, if canon_va_type is ARRAY_TYPE, then when passing-by-value a
    4970                 :             :      va_list the type of the va_list param decl (case 2b, struct * ap) is not
    4971                 :             :      the same as for another va_list decl (case 2a, struct ap[1]).
    4972                 :             : 
    4973                 :             :      f2_1 (struct  * ap)
    4974                 :             :        D.1844 = VA_ARG (ap, 0B, 0);
    4975                 :             :        return D.1844;
    4976                 :             : 
    4977                 :             :      f2 (int i)
    4978                 :             :        struct  ap[1];
    4979                 :             :        __builtin_va_start (&ap, 0);
    4980                 :             :        res = f2_1 (&ap);
    4981                 :             :        __builtin_va_end (&ap);
    4982                 :             :        D.1841 = res;
    4983                 :             :        return D.1841;
    4984                 :             : 
    4985                 :             :      Case 2b is different because:
    4986                 :             :      - on the callee side, the parm decl has declared type va_list, but
    4987                 :             :        grokdeclarator changes the type of the parm decl to a pointer to the
    4988                 :             :        array elem type.
    4989                 :             :      - on the caller side, the pass-by-value uses &ap.
    4990                 :             : 
    4991                 :             :      We unify these two cases (case 2a: va_list is array type,
    4992                 :             :      case 2b: va_list is pointer to array elem type), by adding '&' for the
    4993                 :             :      array type case, such that we have a pointer to array elem in both
    4994                 :             :      cases.  */
    4995                 :             : 
    4996                 :       50533 :   if (TREE_CODE (va_type) == ARRAY_TYPE)
    4997                 :             :     {
    4998                 :             :       /* Case 2a: va_list is array type.  */
    4999                 :             : 
    5000                 :             :       /* Take the address, to get '&ap'.  Make sure it's a pointer to array
    5001                 :             :          elem type.  */
    5002                 :       49786 :       c_common_mark_addressable_vec (expr);
    5003                 :       49786 :       expr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (canon_va_type)),
    5004                 :             :                      expr);
    5005                 :             : 
    5006                 :             :       /* Verify that &ap is still recognized as having va_list type.  */
    5007                 :       49786 :       tree canon_expr_type
    5008                 :       49786 :         = targetm.canonical_va_list_type (TREE_TYPE (expr));
    5009                 :       49786 :       gcc_assert (canon_expr_type != NULL_TREE);
    5010                 :             :     }
    5011                 :             :   else
    5012                 :             :     {
    5013                 :             :       /* Case 2b: va_list is pointer to array elem type.  */
    5014                 :         747 :       gcc_assert (POINTER_TYPE_P (va_type));
    5015                 :             : 
    5016                 :             :       /* Comparison as in std_canonical_va_list_type.  */
    5017                 :         747 :       gcc_assert (TYPE_MAIN_VARIANT (TREE_TYPE (va_type))
    5018                 :             :                   == TYPE_MAIN_VARIANT (TREE_TYPE (canon_va_type)));
    5019                 :             : 
    5020                 :             :       /* Don't take the address.  We've already got '&ap'.  */
    5021                 :       50533 :       ;
    5022                 :             :     }
    5023                 :             : 
    5024                 :       50533 :   return build_va_arg_1 (loc, type, expr);
    5025                 :             : }
    5026                 :             : 
    5027                 :             : 
    5028                 :             : /* Linked list of disabled built-in functions.  */
    5029                 :             : 
    5030                 :             : struct disabled_builtin
    5031                 :             : {
    5032                 :             :   const char *name;
    5033                 :             :   struct disabled_builtin *next;
    5034                 :             : };
    5035                 :             : static disabled_builtin *disabled_builtins = NULL;
    5036                 :             : 
    5037                 :             : static bool builtin_function_disabled_p (const char *);
    5038                 :             : 
    5039                 :             : /* Disable a built-in function specified by -fno-builtin-NAME.  If NAME
    5040                 :             :    begins with "__builtin_", give an error.  */
    5041                 :             : 
    5042                 :             : void
    5043                 :         308 : disable_builtin_function (const char *name)
    5044                 :             : {
    5045                 :         308 :   if (startswith (name, "__builtin_"))
    5046                 :           0 :     error ("cannot disable built-in function %qs", name);
    5047                 :             :   else
    5048                 :             :     {
    5049                 :         308 :       disabled_builtin *new_disabled_builtin = XNEW (disabled_builtin);
    5050                 :         308 :       new_disabled_builtin->name = name;
    5051                 :         308 :       new_disabled_builtin->next = disabled_builtins;
    5052                 :         308 :       disabled_builtins = new_disabled_builtin;
    5053                 :             :     }
    5054                 :         308 : }
    5055                 :             : 
    5056                 :             : 
    5057                 :             : /* Return true if the built-in function NAME has been disabled, false
    5058                 :             :    otherwise.  */
    5059                 :             : 
    5060                 :             : static bool
    5061                 :   158533154 : builtin_function_disabled_p (const char *name)
    5062                 :             : {
    5063                 :   158533154 :   disabled_builtin *p;
    5064                 :   158817614 :   for (p = disabled_builtins; p != NULL; p = p->next)
    5065                 :             :     {
    5066                 :      284768 :       if (strcmp (name, p->name) == 0)
    5067                 :             :         return true;
    5068                 :             :     }
    5069                 :             :   return false;
    5070                 :             : }
    5071                 :             : 
    5072                 :             : 
    5073                 :             : /* Worker for DEF_BUILTIN.
    5074                 :             :    Possibly define a builtin function with one or two names.
    5075                 :             :    Does not declare a non-__builtin_ function if flag_no_builtin, or if
    5076                 :             :    nonansi_p and flag_no_nonansi_builtin.  */
    5077                 :             : 
    5078                 :             : static void
    5079                 :   312150152 : def_builtin_1 (enum built_in_function fncode,
    5080                 :             :                const char *name,
    5081                 :             :                enum built_in_class fnclass,
    5082                 :             :                tree fntype, tree libtype,
    5083                 :             :                bool both_p, bool fallback_p, bool nonansi_p,
    5084                 :             :                tree fnattrs, bool implicit_p)
    5085                 :             : {
    5086                 :   312150152 :   tree decl;
    5087                 :   312150152 :   const char *libname;
    5088                 :             : 
    5089                 :   312150152 :   if (fntype == error_mark_node)
    5090                 :             :     return;
    5091                 :             : 
    5092                 :   294193827 :   gcc_assert ((!both_p && !fallback_p)
    5093                 :             :               || startswith (name, "__builtin_"));
    5094                 :             : 
    5095                 :   294193827 :   libname = name + strlen ("__builtin_");
    5096                 :   294193827 :   decl = add_builtin_function (name, fntype, fncode, fnclass,
    5097                 :             :                                (fallback_p ? libname : NULL),
    5098                 :             :                                fnattrs);
    5099                 :             : 
    5100                 :   294193827 :   set_builtin_decl (fncode, decl, implicit_p);
    5101                 :             : 
    5102                 :   294193827 :   if (both_p
    5103                 :   158955953 :       && !flag_no_builtin && !builtin_function_disabled_p (libname)
    5104                 :   452726673 :       && !(nonansi_p && flag_no_nonansi_builtin))
    5105                 :   142674311 :     add_builtin_function (libname, libtype, fncode, fnclass,
    5106                 :             :                           NULL, fnattrs);
    5107                 :             : }
    5108                 :             : 
    5109                 :             : /* Nonzero if the type T promotes to int.  This is (nearly) the
    5110                 :             :    integral promotions defined in ISO C99 6.3.1.1/2.  */
    5111                 :             : 
    5112                 :             : bool
    5113                 :   498370315 : c_promoting_integer_type_p (const_tree t)
    5114                 :             : {
    5115                 :   498370315 :   switch (TREE_CODE (t))
    5116                 :             :     {
    5117                 :   387435611 :     case INTEGER_TYPE:
    5118                 :   387435611 :       return (TYPE_MAIN_VARIANT (t) == char_type_node
    5119                 :   381848491 :               || TYPE_MAIN_VARIANT (t) == signed_char_type_node
    5120                 :   381458954 :               || TYPE_MAIN_VARIANT (t) == unsigned_char_type_node
    5121                 :   367065215 :               || TYPE_MAIN_VARIANT (t) == short_integer_type_node
    5122                 :   366033636 :               || TYPE_MAIN_VARIANT (t) == short_unsigned_type_node
    5123                 :   748016113 :               || TYPE_PRECISION (t) < TYPE_PRECISION (integer_type_node));
    5124                 :             : 
    5125                 :      657798 :     case ENUMERAL_TYPE:
    5126                 :             :       /* ??? Technically all enumerations not larger than an int
    5127                 :             :          promote to an int.  But this is used along code paths
    5128                 :             :          that only want to notice a size change.  */
    5129                 :      657798 :       return TYPE_PRECISION (t) < TYPE_PRECISION (integer_type_node);
    5130                 :             : 
    5131                 :             :     case BOOLEAN_TYPE:
    5132                 :             :       return true;
    5133                 :             : 
    5134                 :             :     default:
    5135                 :             :       return false;
    5136                 :             :     }
    5137                 :             : }
    5138                 :             : 
    5139                 :             : /* Return 1 if PARMS specifies a fixed number of parameters
    5140                 :             :    and none of their types is affected by default promotions.  */
    5141                 :             : 
    5142                 :             : bool
    5143                 :       21751 : self_promoting_args_p (const_tree parms)
    5144                 :             : {
    5145                 :       21751 :   const_tree t;
    5146                 :       64755 :   for (t = parms; t; t = TREE_CHAIN (t))
    5147                 :             :     {
    5148                 :       43535 :       tree type = TREE_VALUE (t);
    5149                 :             : 
    5150                 :       43535 :       if (type == error_mark_node)
    5151                 :           2 :         continue;
    5152                 :             : 
    5153                 :       43533 :       if (TREE_CHAIN (t) == NULL_TREE && type != void_type_node)
    5154                 :             :         return false;
    5155                 :             : 
    5156                 :       43052 :       if (type == NULL_TREE)
    5157                 :             :         return false;
    5158                 :             : 
    5159                 :       43052 :       if (TYPE_MAIN_VARIANT (type) == float_type_node)
    5160                 :             :         return false;
    5161                 :             : 
    5162                 :       43007 :       if (c_promoting_integer_type_p (type))
    5163                 :             :         return false;
    5164                 :             :     }
    5165                 :             :   return true;
    5166                 :             : }
    5167                 :             : 
    5168                 :             : /* Recursively remove any '*' or '&' operator from TYPE.  */
    5169                 :             : tree
    5170                 :    36838951 : strip_pointer_operator (tree t)
    5171                 :             : {
    5172                 :    39134333 :   while (POINTER_TYPE_P (t))
    5173                 :     2295382 :     t = TREE_TYPE (t);
    5174                 :    36838951 :   return t;
    5175                 :             : }
    5176                 :             : 
    5177                 :             : /* Recursively remove pointer or array type from TYPE. */
    5178                 :             : tree
    5179                 :    10688276 : strip_pointer_or_array_types (tree t)
    5180                 :             : {
    5181                 :    15503050 :   while (TREE_CODE (t) == ARRAY_TYPE || POINTER_TYPE_P (t))
    5182                 :     4814774 :     t = TREE_TYPE (t);
    5183                 :    10688276 :   return t;
    5184                 :             : }
    5185                 :             : 
    5186                 :             : /* Used to compare case labels.  K1 and K2 are actually tree nodes
    5187                 :             :    representing case labels, or NULL_TREE for a `default' label.
    5188                 :             :    Returns -1 if K1 is ordered before K2, -1 if K1 is ordered after
    5189                 :             :    K2, and 0 if K1 and K2 are equal.  */
    5190                 :             : 
    5191                 :             : int
    5192                 :    27636666 : case_compare (splay_tree_key k1, splay_tree_key k2)
    5193                 :             : {
    5194                 :             :   /* Consider a NULL key (such as arises with a `default' label) to be
    5195                 :             :      smaller than anything else.  */
    5196                 :    27636666 :   if (!k1)
    5197                 :     3750660 :     return k2 ? -1 : 0;
    5198                 :    24562044 :   else if (!k2)
    5199                 :             :     return k1 ? 1 : 0;
    5200                 :             : 
    5201                 :    23750412 :   return tree_int_cst_compare ((tree) k1, (tree) k2);
    5202                 :             : }
    5203                 :             : 
    5204                 :             : /* Process a case label, located at LOC, for the range LOW_VALUE
    5205                 :             :    ... HIGH_VALUE.  If LOW_VALUE and HIGH_VALUE are both NULL_TREE
    5206                 :             :    then this case label is actually a `default' label.  If only
    5207                 :             :    HIGH_VALUE is NULL_TREE, then case label was declared using the
    5208                 :             :    usual C/C++ syntax, rather than the GNU case range extension.
    5209                 :             :    CASES is a tree containing all the case ranges processed so far;
    5210                 :             :    COND is the condition for the switch-statement itself.
    5211                 :             :    Returns the CASE_LABEL_EXPR created, or ERROR_MARK_NODE if no
    5212                 :             :    CASE_LABEL_EXPR is created.  ATTRS are the attributes to be applied
    5213                 :             :    to the label.  */
    5214                 :             : 
    5215                 :             : tree
    5216                 :     3024154 : c_add_case_label (location_t loc, splay_tree cases, tree cond,
    5217                 :             :                   tree low_value, tree high_value, tree attrs)
    5218                 :             : {
    5219                 :     3024154 :   tree type;
    5220                 :     3024154 :   tree label;
    5221                 :     3024154 :   tree case_label;
    5222                 :     3024154 :   splay_tree_node node;
    5223                 :             : 
    5224                 :             :   /* Create the LABEL_DECL itself.  */
    5225                 :     3024154 :   label = create_artificial_label (loc);
    5226                 :     3024154 :   decl_attributes (&label, attrs, 0);
    5227                 :             : 
    5228                 :             :   /* If there was an error processing the switch condition, bail now
    5229                 :             :      before we get more confused.  */
    5230                 :     3024154 :   if (!cond || cond == error_mark_node)
    5231                 :           0 :     goto error_out;
    5232                 :             : 
    5233                 :     2718875 :   if ((low_value && TREE_TYPE (low_value)
    5234                 :     2718875 :        && POINTER_TYPE_P (TREE_TYPE (low_value)))
    5235                 :     5743028 :       || (high_value && TREE_TYPE (high_value)
    5236                 :         440 :           && POINTER_TYPE_P (TREE_TYPE (high_value))))
    5237                 :             :     {
    5238                 :           1 :       error_at (loc, "pointers are not permitted as case values");
    5239                 :           1 :       goto error_out;
    5240                 :             :     }
    5241                 :             : 
    5242                 :             :   /* Case ranges are a GNU extension.  */
    5243                 :     3024153 :   if (high_value)
    5244                 :             :     {
    5245                 :         440 :       if (c_dialect_cxx ())
    5246                 :         126 :         pedwarn (loc, OPT_Wpedantic,
    5247                 :             :                  "range expressions in switch statements are non-standard");
    5248                 :         314 :       else if (warn_c23_c2y_compat > 0)
    5249                 :             :         {
    5250                 :          13 :           if (pedantic && !flag_isoc2y)
    5251                 :           0 :             pedwarn (loc, OPT_Wc23_c2y_compat,
    5252                 :             :                      "ISO C does not support range expressions in switch "
    5253                 :             :                      "statements before C2Y");
    5254                 :             :           else
    5255                 :          13 :             warning_at (loc, OPT_Wc23_c2y_compat,
    5256                 :             :                         "ISO C does not support range expressions in switch "
    5257                 :             :                         "statements before C2Y");
    5258                 :             :         }
    5259                 :         301 :       else if (warn_c23_c2y_compat && pedantic && !flag_isoc2y)
    5260                 :          28 :         pedwarn (loc, OPT_Wpedantic,
    5261                 :             :                  "ISO C does not support range expressions in switch "
    5262                 :             :                  "statements before C2Y");
    5263                 :             :     }
    5264                 :             : 
    5265                 :     3024153 :   type = TREE_TYPE (cond);
    5266                 :     3024153 :   if (low_value)
    5267                 :             :     {
    5268                 :     2718874 :       low_value = check_case_value (loc, low_value);
    5269                 :     2718874 :       tree tem = NULL_TREE;
    5270                 :     2718874 :       if (high_value
    5271                 :         440 :           && !c_dialect_cxx ()
    5272                 :         314 :           && low_value != error_mark_node
    5273                 :         313 :           && !int_fits_type_p (low_value, type)
    5274                 :     2719314 :           && pedwarn (loc, OPT_Wpedantic,
    5275                 :             :                       "conversion of %qE to %qT in range expression changes "
    5276                 :             :                       "value to %qE", low_value, type,
    5277                 :          20 :                       (tem = fold_convert (type, low_value))))
    5278                 :          20 :         low_value = tem;
    5279                 :     2718874 :       low_value = convert_and_check (loc, type, low_value);
    5280                 :     2718874 :       low_value = fold (low_value);
    5281                 :     2718874 :       if (low_value == error_mark_node)
    5282                 :         147 :         goto error_out;
    5283                 :             :     }
    5284                 :     3024006 :   if (high_value)
    5285                 :             :     {
    5286                 :         439 :       high_value = check_case_value (loc, high_value);
    5287                 :         439 :       tree tem = NULL_TREE;
    5288                 :         439 :       if (!c_dialect_cxx ()
    5289                 :         313 :           && high_value != error_mark_node
    5290                 :         312 :           && !int_fits_type_p (high_value, type)
    5291                 :         752 :           && pedwarn (loc, OPT_Wpedantic,
    5292                 :             :                       "conversion of %qE to %qT in range expression changes "
    5293                 :             :                       "value to %qE", high_value, type,
    5294                 :          20 :                       (tem = fold_convert (type, high_value))))
    5295                 :          20 :         high_value = tem;
    5296                 :         439 :       high_value = convert_and_check (loc, type, high_value);
    5297                 :         439 :       high_value = fold (high_value);
    5298                 :         439 :       if (high_value == error_mark_node)
    5299                 :           4 :         goto error_out;
    5300                 :             :     }
    5301                 :             : 
    5302                 :     3024002 :   if (low_value && high_value)
    5303                 :             :     {
    5304                 :             :       /* If the LOW_VALUE and HIGH_VALUE are the same, then this isn't
    5305                 :             :          really a case range, even though it was written that way.
    5306                 :             :          Remove the HIGH_VALUE to simplify later processing.  */
    5307                 :         435 :       if (tree_int_cst_equal (low_value, high_value))
    5308                 :             :         high_value = NULL_TREE;
    5309                 :         416 :       else if (!tree_int_cst_lt (low_value, high_value))
    5310                 :             :         {
    5311                 :          28 :           warning_at (loc, 0, "empty range specified");
    5312                 :          28 :           goto error_out;
    5313                 :             :         }
    5314                 :             :     }
    5315                 :             : 
    5316                 :             :   /* Look up the LOW_VALUE in the table of case labels we already
    5317                 :             :      have.  */
    5318                 :     3023974 :   node = splay_tree_lookup (cases, (splay_tree_key) low_value);
    5319                 :             :   /* If there was not an exact match, check for overlapping ranges.
    5320                 :             :      There's no need to do this if there's no LOW_VALUE or HIGH_VALUE;
    5321                 :             :      that's a `default' label and the only overlap is an exact match.  */
    5322                 :     3023974 :   if (!node && (low_value || high_value))
    5323                 :             :     {
    5324                 :     2718677 :       splay_tree_node low_bound;
    5325                 :     2718677 :       splay_tree_node high_bound;
    5326                 :             : 
    5327                 :             :       /* Even though there wasn't an exact match, there might be an
    5328                 :             :          overlap between this case range and another case range.
    5329                 :             :          Since we've (inductively) not allowed any overlapping case
    5330                 :             :          ranges, we simply need to find the greatest low case label
    5331                 :             :          that is smaller that LOW_VALUE, and the smallest low case
    5332                 :             :          label that is greater than LOW_VALUE.  If there is an overlap
    5333                 :             :          it will occur in one of these two ranges.  */
    5334                 :     2718677 :       low_bound = splay_tree_predecessor (cases,
    5335                 :             :                                           (splay_tree_key) low_value);
    5336                 :     2718677 :       high_bound = splay_tree_successor (cases,
    5337                 :             :                                          (splay_tree_key) low_value);
    5338                 :             : 
    5339                 :             :       /* Check to see if the LOW_BOUND overlaps.  It is smaller than
    5340                 :             :          the LOW_VALUE, so there is no need to check unless the
    5341                 :             :          LOW_BOUND is in fact itself a case range.  */
    5342                 :     2718677 :       if (low_bound
    5343                 :     1830525 :           && CASE_HIGH ((tree) low_bound->value)
    5344                 :     2718844 :           && tree_int_cst_compare (CASE_HIGH ((tree) low_bound->value),
    5345                 :             :                                     low_value) >= 0)
    5346                 :             :         node = low_bound;
    5347                 :             :       /* Check to see if the HIGH_BOUND overlaps.  The low end of that
    5348                 :             :          range is bigger than the low end of the current range, so we
    5349                 :             :          are only interested if the current range is a real range, and
    5350                 :             :          not an ordinary case label.  */
    5351                 :     2718665 :       else if (high_bound
    5352                 :     2718665 :                && high_value
    5353                 :     2718665 :                && (tree_int_cst_compare ((tree) high_bound->key,
    5354                 :             :                                          high_value)
    5355                 :             :                    <= 0))
    5356                 :             :         node = high_bound;
    5357                 :             :     }
    5358                 :             :   /* If there was an overlap, issue an error.  */
    5359                 :     3023955 :   if (node)
    5360                 :             :     {
    5361                 :          37 :       tree duplicate = CASE_LABEL ((tree) node->value);
    5362                 :             : 
    5363                 :          37 :       if (high_value)
    5364                 :             :         {
    5365                 :          10 :           error_at (loc, "duplicate (or overlapping) case value");
    5366                 :          10 :           inform (DECL_SOURCE_LOCATION (duplicate),
    5367                 :             :                   "this is the first entry overlapping that value");
    5368                 :             :         }
    5369                 :          27 :       else if (low_value)
    5370                 :             :         {
    5371                 :          26 :           error_at (loc, "duplicate case value") ;
    5372                 :          26 :           inform (DECL_SOURCE_LOCATION (duplicate), "previously used here");
    5373                 :             :         }
    5374                 :             :       else
    5375                 :             :         {
    5376                 :           1 :           error_at (loc, "multiple default labels in one switch");
    5377                 :           1 :           inform (DECL_SOURCE_LOCATION (duplicate),
    5378                 :             :                   "this is the first default label");
    5379                 :             :         }
    5380                 :          37 :       goto error_out;
    5381                 :             :     }
    5382                 :             : 
    5383                 :             :   /* Add a CASE_LABEL to the statement-tree.  */
    5384                 :     3023937 :   case_label = add_stmt (build_case_label (low_value, high_value, label));
    5385                 :             :   /* Register this case label in the splay tree.  */
    5386                 :     3023937 :   splay_tree_insert (cases,
    5387                 :             :                      (splay_tree_key) low_value,
    5388                 :             :                      (splay_tree_value) case_label);
    5389                 :             : 
    5390                 :     3023937 :   return case_label;
    5391                 :             : 
    5392                 :         217 :  error_out:
    5393                 :             :   /* Add a label so that the back-end doesn't think that the beginning of
    5394                 :             :      the switch is unreachable.  Note that we do not add a case label, as
    5395                 :             :      that just leads to duplicates and thence to failure later on.  */
    5396                 :         217 :   if (!cases->root)
    5397                 :             :     {
    5398                 :         153 :       tree t = create_artificial_label (loc);
    5399                 :         153 :       add_stmt (build_stmt (loc, LABEL_EXPR, t));
    5400                 :             :     }
    5401                 :         217 :   return error_mark_node;
    5402                 :             : }
    5403                 :             : 
    5404                 :             : /* Subroutine of c_switch_covers_all_cases_p, called via
    5405                 :             :    splay_tree_foreach.  Return 1 if it doesn't cover all the cases.
    5406                 :             :    ARGS[0] is initially NULL and after the first iteration is the
    5407                 :             :    so far highest case label.  ARGS[1] is the minimum of SWITCH_COND's
    5408                 :             :    type.  */
    5409                 :             : 
    5410                 :             : static int
    5411                 :      134344 : c_switch_covers_all_cases_p_1 (splay_tree_node node, void *data)
    5412                 :             : {
    5413                 :      134344 :   tree label = (tree) node->value;
    5414                 :      134344 :   tree *args = (tree *) data;
    5415                 :             : 
    5416                 :             :   /* If there is a default case, we shouldn't have called this.  */
    5417                 :      134344 :   gcc_assert (CASE_LOW (label));
    5418                 :             : 
    5419                 :      134344 :   if (args[0] == NULL_TREE)
    5420                 :             :     {
    5421                 :       46896 :       if (wi::to_widest (args[1]) < wi::to_widest (CASE_LOW (label)))
    5422                 :             :         return 1;
    5423                 :             :     }
    5424                 :       87448 :   else if (wi::add (wi::to_widest (args[0]), 1)
    5425                 :      174896 :            != wi::to_widest (CASE_LOW (label)))
    5426                 :             :     return 1;
    5427                 :      116310 :   if (CASE_HIGH (label))
    5428                 :         109 :     args[0] = CASE_HIGH (label);
    5429                 :             :   else
    5430                 :      116201 :     args[0] = CASE_LOW (label);
    5431                 :             :   return 0;
    5432                 :             : }
    5433                 :             : 
    5434                 :             : /* Return true if switch with CASES and switch condition with type
    5435                 :             :    covers all possible values in the case labels.  */
    5436                 :             : 
    5437                 :             : bool
    5438                 :       80114 : c_switch_covers_all_cases_p (splay_tree cases, tree type)
    5439                 :             : {
    5440                 :             :   /* If there is default:, this is always the case.  */
    5441                 :       80114 :   splay_tree_node default_node
    5442                 :       80114 :     = splay_tree_lookup (cases, (splay_tree_key) NULL);
    5443                 :       80114 :   if (default_node)
    5444                 :             :     return true;
    5445                 :             : 
    5446                 :       47428 :   if (!INTEGRAL_TYPE_P (type))
    5447                 :             :     return false;
    5448                 :             : 
    5449                 :       47361 :   tree args[2] = { NULL_TREE, TYPE_MIN_VALUE (type) };
    5450                 :       47361 :   if (splay_tree_foreach (cases, c_switch_covers_all_cases_p_1, args))
    5451                 :             :     return false;
    5452                 :             : 
    5453                 :             :   /* If there are no cases at all, or if the highest case label
    5454                 :             :      is smaller than TYPE_MAX_VALUE, return false.  */
    5455                 :       29327 :   if (args[0] == NULL_TREE
    5456                 :       29327 :       || wi::to_widest (args[0]) < wi::to_widest (TYPE_MAX_VALUE (type)))
    5457                 :       29281 :     return false;
    5458                 :             : 
    5459                 :             :   return true;
    5460                 :             : }
    5461                 :             : 
    5462                 :             : /* Return true if stmt can fall through.  Used by block_may_fallthru
    5463                 :             :    default case.  */
    5464                 :             : 
    5465                 :             : bool
    5466                 :     1773441 : c_block_may_fallthru (const_tree stmt)
    5467                 :             : {
    5468                 :     1773441 :   switch (TREE_CODE (stmt))
    5469                 :             :     {
    5470                 :         283 :     case SWITCH_STMT:
    5471                 :         283 :       return (!SWITCH_STMT_ALL_CASES_P (stmt)
    5472                 :         184 :               || !SWITCH_STMT_NO_BREAK_P (stmt)
    5473                 :         311 :               || block_may_fallthru (SWITCH_STMT_BODY (stmt)));
    5474                 :             : 
    5475                 :             :     default:
    5476                 :             :       return true;
    5477                 :             :     }
    5478                 :             : }
    5479                 :             : 
    5480                 :             : /* Finish an expression taking the address of LABEL (an
    5481                 :             :    IDENTIFIER_NODE).  Returns an expression for the address.
    5482                 :             : 
    5483                 :             :    LOC is the location for the expression returned.  */
    5484                 :             : 
    5485                 :             : tree
    5486                 :        2117 : finish_label_address_expr (tree label, location_t loc)
    5487                 :             : {
    5488                 :        2117 :   tree result;
    5489                 :             : 
    5490                 :        2117 :   pedwarn (input_location, OPT_Wpedantic, "taking the address of a label is non-standard");
    5491                 :             : 
    5492                 :        2117 :   if (label == error_mark_node)
    5493                 :             :     return error_mark_node;
    5494                 :             : 
    5495                 :        2111 :   label = lookup_label (label);
    5496                 :        2111 :   if (label == NULL_TREE)
    5497                 :           5 :     result = null_pointer_node;
    5498                 :             :   else
    5499                 :             :     {
    5500                 :        2106 :       TREE_USED (label) = 1;
    5501                 :        2106 :       result = build1 (ADDR_EXPR, ptr_type_node, label);
    5502                 :             :       /* The current function is not necessarily uninlinable.
    5503                 :             :          Computed gotos are incompatible with inlining, but the value
    5504                 :             :          here could be used only in a diagnostic, for example.  */
    5505                 :        2106 :       protected_set_expr_location (result, loc);
    5506                 :             :     }
    5507                 :             : 
    5508                 :             :   return result;
    5509                 :             : }
    5510                 :             : 
    5511                 :             : 
    5512                 :             : /* Given a boolean expression ARG, return a tree representing an increment
    5513                 :             :    or decrement (as indicated by CODE) of ARG.  The front end must check for
    5514                 :             :    invalid cases (e.g., decrement in C++).  */
    5515                 :             : tree
    5516                 :          85 : boolean_increment (enum tree_code code, tree arg)
    5517                 :             : {
    5518                 :          85 :   tree val;
    5519                 :          85 :   tree true_res = build_int_cst (TREE_TYPE (arg), 1);
    5520                 :             : 
    5521                 :          85 :   arg = stabilize_reference (arg);
    5522                 :          85 :   switch (code)
    5523                 :             :     {
    5524                 :          28 :     case PREINCREMENT_EXPR:
    5525                 :          28 :       val = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg, true_res);
    5526                 :          28 :       break;
    5527                 :          29 :     case POSTINCREMENT_EXPR:
    5528                 :          29 :       val = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg, true_res);
    5529                 :          29 :       arg = save_expr (arg);
    5530                 :          29 :       val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), val, arg);
    5531                 :          29 :       val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), arg, val);
    5532                 :          29 :       break;
    5533                 :          14 :     case PREDECREMENT_EXPR:
    5534                 :          14 :       val = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg,
    5535                 :             :                     invert_truthvalue_loc (input_location, arg));
    5536                 :          14 :       break;
    5537                 :          14 :     case POSTDECREMENT_EXPR:
    5538                 :          14 :       val = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg,
    5539                 :             :                     invert_truthvalue_loc (input_location, arg));
    5540                 :          14 :       arg = save_expr (arg);
    5541                 :          14 :       val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), val, arg);
    5542                 :          14 :       val = build2 (COMPOUND_EXPR, TREE_TYPE (arg), arg, val);
    5543                 :          14 :       break;
    5544                 :           0 :     default:
    5545                 :           0 :       gcc_unreachable ();
    5546                 :             :     }
    5547                 :          85 :   TREE_SIDE_EFFECTS (val) = 1;
    5548                 :          85 :   return val;
    5549                 :             : }
    5550                 :             : 
    5551                 :             : /* Built-in macros for stddef.h and stdint.h, that require macros
    5552                 :             :    defined in this file.  */
    5553                 :             : void
    5554                 :      206229 : c_stddef_cpp_builtins(void)
    5555                 :             : {
    5556                 :      211642 :   builtin_define_with_value ("__SIZE_TYPE__", SIZE_TYPE, 0);
    5557                 :      211642 :   builtin_define_with_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE, 0);
    5558                 :      211642 :   builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE, 0);
    5559                 :             :   /* C++ has wchar_t as a builtin type, C doesn't, so if WINT_TYPE
    5560                 :             :      maps to wchar_t, define it to the underlying WCHAR_TYPE in C, and
    5561                 :             :      to wchar_t in C++, so the desired type equivalence holds.  */
    5562                 :      206229 :   if (!c_dialect_cxx ()
    5563                 :             :       && strcmp (WINT_TYPE, "wchar_t") == 0)
    5564                 :             :     builtin_define_with_value ("__WINT_TYPE__", WCHAR_TYPE, 0);
    5565                 :             :   else
    5566                 :      206229 :     builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE, 0);
    5567                 :      211642 :   builtin_define_with_value ("__INTMAX_TYPE__", INTMAX_TYPE, 0);
    5568                 :      211642 :   builtin_define_with_value ("__UINTMAX_TYPE__", UINTMAX_TYPE, 0);
    5569                 :      206229 :   if (flag_char8_t)
    5570                 :      126817 :     builtin_define_with_value ("__CHAR8_TYPE__", CHAR8_TYPE, 0);
    5571                 :      206229 :   builtin_define_with_value ("__CHAR16_TYPE__", CHAR16_TYPE, 0);
    5572                 :      206229 :   builtin_define_with_value ("__CHAR32_TYPE__", CHAR32_TYPE, 0);
    5573                 :      206229 :   if (SIG_ATOMIC_TYPE)
    5574                 :      206229 :     builtin_define_with_value ("__SIG_ATOMIC_TYPE__", SIG_ATOMIC_TYPE, 0);
    5575                 :      206229 :   if (INT8_TYPE)
    5576                 :      206229 :     builtin_define_with_value ("__INT8_TYPE__", INT8_TYPE, 0);
    5577                 :      206229 :   if (INT16_TYPE)
    5578                 :      206229 :     builtin_define_with_value ("__INT16_TYPE__", INT16_TYPE, 0);
    5579                 :      206229 :   if (INT32_TYPE)
    5580                 :      206229 :     builtin_define_with_value ("__INT32_TYPE__", INT32_TYPE, 0);
    5581                 :      206229 :   if (INT64_TYPE)
    5582                 :      211642 :     builtin_define_with_value ("__INT64_TYPE__", INT64_TYPE, 0);
    5583                 :      206229 :   if (UINT8_TYPE)
    5584                 :      206229 :     builtin_define_with_value ("__UINT8_TYPE__", UINT8_TYPE, 0);
    5585                 :      206229 :   if (UINT16_TYPE)
    5586                 :      206229 :     builtin_define_with_value ("__UINT16_TYPE__", UINT16_TYPE, 0);
    5587                 :      206229 :   if (UINT32_TYPE)
    5588                 :      206229 :     builtin_define_with_value ("__UINT32_TYPE__", UINT32_TYPE, 0);
    5589                 :      206229 :   if (UINT64_TYPE)
    5590                 :      211642 :     builtin_define_with_value ("__UINT64_TYPE__", UINT64_TYPE, 0);
    5591                 :      206229 :   if (INT_LEAST8_TYPE)
    5592                 :      206229 :     builtin_define_with_value ("__INT_LEAST8_TYPE__", INT_LEAST8_TYPE, 0);
    5593                 :      206229 :   if (INT_LEAST16_TYPE)
    5594                 :      206229 :     builtin_define_with_value ("__INT_LEAST16_TYPE__", INT_LEAST16_TYPE, 0);
    5595                 :      206229 :   if (INT_LEAST32_TYPE)
    5596                 :      206229 :     builtin_define_with_value ("__INT_LEAST32_TYPE__", INT_LEAST32_TYPE, 0);
    5597                 :      206229 :   if (INT_LEAST64_TYPE)
    5598                 :      211642 :     builtin_define_with_value ("__INT_LEAST64_TYPE__", INT_LEAST64_TYPE, 0);
    5599                 :      206229 :   if (UINT_LEAST8_TYPE)
    5600                 :      206229 :     builtin_define_with_value ("__UINT_LEAST8_TYPE__", UINT_LEAST8_TYPE, 0);
    5601                 :      206229 :   if (UINT_LEAST16_TYPE)
    5602                 :      206229 :     builtin_define_with_value ("__UINT_LEAST16_TYPE__", UINT_LEAST16_TYPE, 0);
    5603                 :      206229 :   if (UINT_LEAST32_TYPE)
    5604                 :      206229 :     builtin_define_with_value ("__UINT_LEAST32_TYPE__", UINT_LEAST32_TYPE, 0);
    5605                 :      206229 :   if (UINT_LEAST64_TYPE)
    5606                 :      211642 :     builtin_define_with_value ("__UINT_LEAST64_TYPE__", UINT_LEAST64_TYPE, 0);
    5607                 :      206229 :   if (INT_FAST8_TYPE)
    5608                 :      206229 :     builtin_define_with_value ("__INT_FAST8_TYPE__", INT_FAST8_TYPE, 0);
    5609                 :      206229 :   if (INT_FAST16_TYPE)
    5610                 :      211642 :     builtin_define_with_value ("__INT_FAST16_TYPE__", INT_FAST16_TYPE, 0);
    5611                 :      206229 :   if (INT_FAST32_TYPE)
    5612                 :      211642 :     builtin_define_with_value ("__INT_FAST32_TYPE__", INT_FAST32_TYPE, 0);
    5613                 :      206229 :   if (INT_FAST64_TYPE)
    5614                 :      211642 :     builtin_define_with_value ("__INT_FAST64_TYPE__", INT_FAST64_TYPE, 0);
    5615                 :      206229 :   if (UINT_FAST8_TYPE)
    5616                 :      206229 :     builtin_define_with_value ("__UINT_FAST8_TYPE__", UINT_FAST8_TYPE, 0);
    5617                 :      206229 :   if (UINT_FAST16_TYPE)
    5618                 :      211642 :     builtin_define_with_value ("__UINT_FAST16_TYPE__", UINT_FAST16_TYPE, 0);
    5619                 :      206229 :   if (UINT_FAST32_TYPE)
    5620                 :      211642 :     builtin_define_with_value ("__UINT_FAST32_TYPE__", UINT_FAST32_TYPE, 0);
    5621                 :      206229 :   if (UINT_FAST64_TYPE)
    5622                 :      211642 :     builtin_define_with_value ("__UINT_FAST64_TYPE__", UINT_FAST64_TYPE, 0);
    5623                 :      206229 :   if (INTPTR_TYPE)
    5624                 :      211642 :     builtin_define_with_value ("__INTPTR_TYPE__", INTPTR_TYPE, 0);
    5625                 :      206229 :   if (UINTPTR_TYPE)
    5626                 :      211642 :     builtin_define_with_value ("__UINTPTR_TYPE__", UINTPTR_TYPE, 0);
    5627                 :             :   /* GIMPLE FE testcases need access to the GCC internal 'sizetype'.
    5628                 :             :      Expose it as __SIZETYPE__.  */
    5629                 :      206229 :   if (flag_gimple)
    5630                 :         228 :     builtin_define_with_value ("__SIZETYPE__", SIZETYPE, 0);
    5631                 :      206229 : }
    5632                 :             : 
    5633                 :             : static void
    5634                 :      206755 : c_init_attributes (void)
    5635                 :             : {
    5636                 :             :   /* Fill in the built_in_attributes array.  */
    5637                 :             : #define DEF_ATTR_NULL_TREE(ENUM)                                \
    5638                 :             :   built_in_attributes[(int) ENUM] = NULL_TREE;
    5639                 :             : #define DEF_ATTR_INT(ENUM, VALUE)                               \
    5640                 :             :   built_in_attributes[(int) ENUM] = build_int_cst (integer_type_node, VALUE);
    5641                 :             : #define DEF_ATTR_STRING(ENUM, VALUE)                            \
    5642                 :             :   built_in_attributes[(int) ENUM] = build_string (strlen (VALUE), VALUE);
    5643                 :             : #define DEF_ATTR_IDENT(ENUM, STRING)                            \
    5644                 :             :   built_in_attributes[(int) ENUM] = get_identifier (STRING);
    5645                 :             : #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
    5646                 :             :   built_in_attributes[(int) ENUM]                       \
    5647                 :             :     = tree_cons (built_in_attributes[(int) PURPOSE],    \
    5648                 :             :                  built_in_attributes[(int) VALUE],      \
    5649                 :             :                  built_in_attributes[(int) CHAIN]);
    5650                 :             : #include "builtin-attrs.def"
    5651                 :             : #undef DEF_ATTR_NULL_TREE
    5652                 :             : #undef DEF_ATTR_INT
    5653                 :             : #undef DEF_ATTR_IDENT
    5654                 :             : #undef DEF_ATTR_TREE_LIST
    5655                 :      206755 : }
    5656                 :             : 
    5657                 :             : /* Check whether the byte alignment ALIGN is a valid user-specified
    5658                 :             :    alignment less than the supported maximum.  If so, return ALIGN's
    5659                 :             :    base-2 log; if not, output an error and return -1.  If OBJFILE
    5660                 :             :    then reject alignments greater than MAX_OFILE_ALIGNMENT when
    5661                 :             :    converted to bits.  Otherwise, consider valid only alignments
    5662                 :             :    that are less than HOST_BITS_PER_INT - LOG2_BITS_PER_UNIT.
    5663                 :             :    Zero is not considered a valid argument (and results in -1 on
    5664                 :             :    return) but it only triggers a warning when WARN_ZERO is set.  */
    5665                 :             : 
    5666                 :             : int
    5667                 :      571782 : check_user_alignment (const_tree align, bool objfile, bool warn_zero)
    5668                 :             : {
    5669                 :      571782 :   if (error_operand_p (align))
    5670                 :             :     return -1;
    5671                 :             : 
    5672                 :      571759 :   if (TREE_CODE (align) != INTEGER_CST
    5673                 :      571759 :       || !INTEGRAL_TYPE_P (TREE_TYPE (align)))
    5674                 :             :     {
    5675                 :          27 :       error ("requested alignment is not an integer constant");
    5676                 :          27 :       return -1;
    5677                 :             :     }
    5678                 :             : 
    5679                 :      571732 :   if (integer_zerop (align))
    5680                 :             :     {
    5681                 :          75 :       if (warn_zero)
    5682                 :          63 :         warning (OPT_Wattributes,
    5683                 :             :                  "requested alignment %qE is not a positive power of 2",
    5684                 :             :                  align);
    5685                 :          75 :       return -1;
    5686                 :             :     }
    5687                 :             : 
    5688                 :             :   /* Log2 of the byte alignment ALIGN.  */
    5689                 :      571657 :   int log2align;
    5690                 :      571657 :   if (tree_int_cst_sgn (align) == -1
    5691                 :      571657 :       || (log2align = tree_log2 (align)) == -1)
    5692                 :             :     {
    5693                 :          36 :       error ("requested alignment %qE is not a positive power of 2",
    5694                 :             :              align);
    5695                 :          36 :       return -1;
    5696                 :             :     }
    5697                 :             : 
    5698                 :      571621 :   if (objfile)
    5699                 :             :     {
    5700                 :       15683 :       unsigned maxalign = MAX_OFILE_ALIGNMENT / BITS_PER_UNIT;
    5701                 :       15683 :       if (!tree_fits_uhwi_p (align) || tree_to_uhwi (align) > maxalign)
    5702                 :             :         {
    5703                 :          10 :           error ("requested alignment %qE exceeds object file maximum %u",
    5704                 :             :                  align, maxalign);
    5705                 :          10 :           return -1;
    5706                 :             :         }
    5707                 :             :     }
    5708                 :             : 
    5709                 :      571611 :   if (log2align >= HOST_BITS_PER_INT - LOG2_BITS_PER_UNIT)
    5710                 :             :     {
    5711                 :          17 :       error ("requested alignment %qE exceeds maximum %u",
    5712                 :             :              align, 1U << (HOST_BITS_PER_INT - LOG2_BITS_PER_UNIT - 1));
    5713                 :          17 :       return -1;
    5714                 :             :     }
    5715                 :             : 
    5716                 :             :   return log2align;
    5717                 :             : }
    5718                 :             : 
    5719                 :             : /* Determine the ELF symbol visibility for DECL, which is either a
    5720                 :             :    variable or a function.  It is an error to use this function if a
    5721                 :             :    definition of DECL is not available in this translation unit.
    5722                 :             :    Returns true if the final visibility has been determined by this
    5723                 :             :    function; false if the caller is free to make additional
    5724                 :             :    modifications.  */
    5725                 :             : 
    5726                 :             : bool
    5727                 :    50963147 : c_determine_visibility (tree decl)
    5728                 :             : {
    5729                 :    50963147 :   gcc_assert (VAR_OR_FUNCTION_DECL_P (decl));
    5730                 :             : 
    5731                 :             :   /* If the user explicitly specified the visibility with an
    5732                 :             :      attribute, honor that.  DECL_VISIBILITY will have been set during
    5733                 :             :      the processing of the attribute.  We check for an explicit
    5734                 :             :      attribute, rather than just checking DECL_VISIBILITY_SPECIFIED,
    5735                 :             :      to distinguish the use of an attribute from the use of a "#pragma
    5736                 :             :      GCC visibility push(...)"; in the latter case we still want other
    5737                 :             :      considerations to be able to overrule the #pragma.  */
    5738                 :    50963147 :   if (lookup_attribute ("visibility", DECL_ATTRIBUTES (decl))
    5739                 :             :       || (TARGET_DLLIMPORT_DECL_ATTRIBUTES
    5740                 :             :           && (lookup_attribute ("dllimport", DECL_ATTRIBUTES (decl))
    5741                 :             :               || lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl)))))
    5742                 :             :     return true;
    5743                 :             : 
    5744                 :             :   /* Set default visibility to whatever the user supplied with
    5745                 :             :      visibility_specified depending on #pragma GCC visibility.  */
    5746                 :    50331632 :   if (!DECL_VISIBILITY_SPECIFIED (decl))
    5747                 :             :     {
    5748                 :    50330394 :       if (visibility_options.inpragma
    5749                 :    50330394 :           || DECL_VISIBILITY (decl) != default_visibility)
    5750                 :             :         {
    5751                 :      210826 :           DECL_VISIBILITY (decl) = default_visibility;
    5752                 :      210826 :           DECL_VISIBILITY_SPECIFIED (decl) = visibility_options.inpragma;
    5753                 :             :           /* If visibility changed and DECL already has DECL_RTL, ensure
    5754                 :             :              symbol flags are updated.  */
    5755                 :       14204 :           if (((VAR_P (decl) && TREE_STATIC (decl))
    5756                 :      210774 :                || TREE_CODE (decl) == FUNCTION_DECL)
    5757                 :      407500 :               && DECL_RTL_SET_P (decl))
    5758                 :           0 :             make_decl_rtl (decl);
    5759                 :             :         }
    5760                 :             :     }
    5761                 :             :   return false;
    5762                 :             : }
    5763                 :             : 
    5764                 :             : /* Data to communicate through check_function_arguments_recurse between
    5765                 :             :    check_function_nonnull and check_nonnull_arg.  */
    5766                 :             : 
    5767                 :             : struct nonnull_arg_ctx
    5768                 :             : {
    5769                 :             :   /* Location of the call.  */
    5770                 :             :   location_t loc;
    5771                 :             :   /* The function whose arguments are being checked and its type (used
    5772                 :             :      for calls through function pointers).  */
    5773                 :             :   const_tree fndecl, fntype;
    5774                 :             :   /* For nonnull_if_nonzero, index of the other arguments.  */
    5775                 :             :   unsigned HOST_WIDE_INT other1, other2;
    5776                 :             :   /* True if a warning has been issued.  */
    5777                 :             :   bool warned_p;
    5778                 :             : };
    5779                 :             : 
    5780                 :             : /* Check the argument list of a function call to CTX.FNDECL of CTX.FNTYPE
    5781                 :             :    for null in argument slots that are marked as requiring a non-null
    5782                 :             :    pointer argument.  The NARGS arguments are passed in the array ARGARRAY.
    5783                 :             :    Return true if we have warned.  */
    5784                 :             : 
    5785                 :             : static bool
    5786                 :     6405824 : check_function_nonnull (nonnull_arg_ctx &ctx, int nargs, tree *argarray)
    5787                 :             : {
    5788                 :     6405824 :   int firstarg = 0;
    5789                 :     6405824 :   if (TREE_CODE (ctx.fntype) == METHOD_TYPE)
    5790                 :             :     {
    5791                 :      479421 :       bool closure = false;
    5792                 :      479421 :       if (ctx.fndecl)
    5793                 :             :         {
    5794                 :             :           /* For certain lambda expressions the C++ front end emits calls
    5795                 :             :              that pass a null this pointer as an argument named __closure
    5796                 :             :              to the member operator() of empty function.  Detect those
    5797                 :             :              and avoid checking them, but proceed to check the remaining
    5798                 :             :              arguments.  */
    5799                 :      479270 :           tree arg0 = DECL_ARGUMENTS (ctx.fndecl);
    5800                 :      479270 :           if (tree arg0name = DECL_NAME (arg0))
    5801                 :      479270 :             closure = id_equal (arg0name, "__closure");
    5802                 :             :         }
    5803                 :             : 
    5804                 :             :       /* In calls to C++ non-static member functions check the this
    5805                 :             :          pointer regardless of whether the function is declared with
    5806                 :             :          attribute nonnull.  */
    5807                 :      953872 :       firstarg = 1;
    5808                 :      479270 :       if (!closure)
    5809                 :      474602 :         check_function_arguments_recurse (check_nonnull_arg, &ctx, argarray[0],
    5810                 :             :                                           firstarg, OPT_Wnonnull);
    5811                 :             :     }
    5812                 :             : 
    5813                 :     6405824 :   tree attrs = lookup_attribute ("nonnull", TYPE_ATTRIBUTES (ctx.fntype));
    5814                 :             : 
    5815                 :     6405824 :   tree a = attrs;
    5816                 :             :   /* See if any of the nonnull attributes has no arguments.  If so,
    5817                 :             :      then every pointer argument is checked (in which case the check
    5818                 :             :      for pointer type is done in check_nonnull_arg).  */
    5819                 :    13041947 :   while (a != NULL_TREE && TREE_VALUE (a) != NULL_TREE)
    5820                 :      102272 :     a = lookup_attribute ("nonnull", TREE_CHAIN (a));
    5821                 :             : 
    5822                 :     6405824 :   if (a != NULL_TREE)
    5823                 :       68483 :     for (int i = firstarg; i < nargs; i++)
    5824                 :       42728 :       check_function_arguments_recurse (check_nonnull_arg, &ctx, argarray[i],
    5825                 :       42728 :                                         i + 1, OPT_Wnonnull);
    5826                 :     6380069 :   else if (attrs)
    5827                 :             :     {
    5828                 :             :       /* Walk the argument list.  If we encounter an argument number we
    5829                 :             :          should check for non-null, do it.  */
    5830                 :      343891 :       for (int i = firstarg; i < nargs; i++)
    5831                 :             :         {
    5832                 :      146378 :           for (a = attrs; ; a = TREE_CHAIN (a))
    5833                 :             :             {
    5834                 :      398497 :               a = lookup_attribute ("nonnull", a);
    5835                 :      398497 :               if (a == NULL_TREE || nonnull_check_p (TREE_VALUE (a), i + 1))
    5836                 :             :                 break;
    5837                 :             :             }
    5838                 :             : 
    5839                 :      252119 :           if (a != NULL_TREE)
    5840                 :      122931 :             check_function_arguments_recurse (check_nonnull_arg, &ctx,
    5841                 :      122931 :                                               argarray[i], i + 1,
    5842                 :             :                                               OPT_Wnonnull);
    5843                 :      252119 :           a = NULL_TREE;
    5844                 :             :         }
    5845                 :             :     }
    5846                 :     6405824 :   if (a == NULL_TREE)
    5847                 :     6380069 :     for (attrs = TYPE_ATTRIBUTES (ctx.fntype);
    5848                 :     6437077 :          (attrs = lookup_attribute ("nonnull_if_nonzero", attrs));
    5849                 :       57008 :          attrs = TREE_CHAIN (attrs))
    5850                 :             :       {
    5851                 :       57008 :         tree args = TREE_VALUE (attrs);
    5852                 :       57008 :         unsigned int idx = TREE_INT_CST_LOW (TREE_VALUE (args)) - 1;
    5853                 :       57008 :         unsigned int idx2
    5854                 :       57008 :           = TREE_INT_CST_LOW (TREE_VALUE (TREE_CHAIN (args))) - 1;
    5855                 :       57008 :         unsigned int idx3 = idx2;
    5856                 :       57008 :         if (tree chain2 = TREE_CHAIN (TREE_CHAIN (args)))
    5857                 :         478 :           idx3 = TREE_INT_CST_LOW (TREE_VALUE (chain2)) - 1;
    5858                 :       57008 :         if (idx < (unsigned) nargs - firstarg
    5859                 :       57003 :             && idx2 < (unsigned) nargs - firstarg
    5860                 :       56998 :             && idx3 < (unsigned) nargs - firstarg
    5861                 :       56998 :             && INTEGRAL_TYPE_P (TREE_TYPE (argarray[firstarg + idx2]))
    5862                 :       56925 :             && integer_nonzerop (argarray[firstarg + idx2])
    5863                 :       31709 :             && INTEGRAL_TYPE_P (TREE_TYPE (argarray[firstarg + idx3]))
    5864                 :       88717 :             && integer_nonzerop (argarray[firstarg + idx3]))
    5865                 :             :           {
    5866                 :       31618 :             ctx.other1 = firstarg + idx2 + 1;
    5867                 :       31618 :             ctx.other2 = firstarg + idx3 + 1;
    5868                 :       31618 :             check_function_arguments_recurse (check_nonnull_arg, &ctx,
    5869                 :       31618 :                                               argarray[firstarg + idx],
    5870                 :       31618 :                                               firstarg + idx + 1,
    5871                 :             :                                               OPT_Wnonnull);
    5872                 :       31618 :             ctx.other1 = 0;
    5873                 :       31618 :             ctx.other2 = 0;
    5874                 :             :           }
    5875                 :             :       }
    5876                 :     6405824 :   return ctx.warned_p;
    5877                 :             : }
    5878                 :             : 
    5879                 :             : /* Check that the Nth argument of a function call (counting backwards
    5880                 :             :    from the end) is a (pointer)0.  The NARGS arguments are passed in the
    5881                 :             :    array ARGARRAY.  */
    5882                 :             : 
    5883                 :             : static void
    5884                 :     6391561 : check_function_sentinel (const_tree fntype, int nargs, tree *argarray)
    5885                 :             : {
    5886                 :     6391561 :   tree attr = lookup_attribute ("sentinel", TYPE_ATTRIBUTES (fntype));
    5887                 :             : 
    5888                 :     6391561 :   if (attr)
    5889                 :             :     {
    5890                 :         112 :       int len = 0;
    5891                 :         112 :       int pos = 0;
    5892                 :         112 :       tree sentinel;
    5893                 :         112 :       function_args_iterator iter;
    5894                 :         112 :       tree t;
    5895                 :             : 
    5896                 :             :       /* Skip over the named arguments.  */
    5897                 :         237 :       FOREACH_FUNCTION_ARGS (fntype, t, iter)
    5898                 :             :         {
    5899                 :         125 :           if (len == nargs)
    5900                 :             :             break;
    5901                 :         125 :           len++;
    5902                 :             :         }
    5903                 :             : 
    5904                 :         112 :       if (TREE_VALUE (attr))
    5905                 :             :         {
    5906                 :          59 :           tree p = TREE_VALUE (TREE_VALUE (attr));
    5907                 :          59 :           pos = TREE_INT_CST_LOW (p);
    5908                 :             :         }
    5909                 :             : 
    5910                 :             :       /* The sentinel must be one of the varargs, i.e.
    5911                 :             :          in position >= the number of fixed arguments.  */
    5912                 :         112 :       if ((nargs - 1 - pos) < len)
    5913                 :             :         {
    5914                 :          22 :           warning (OPT_Wformat_,
    5915                 :             :                    "not enough variable arguments to fit a sentinel");
    5916                 :          22 :           return;
    5917                 :             :         }
    5918                 :             : 
    5919                 :             :       /* Validate the sentinel.  */
    5920                 :          90 :       sentinel = fold_for_warn (argarray[nargs - 1 - pos]);
    5921                 :         138 :       if ((!POINTER_TYPE_P (TREE_TYPE (sentinel))
    5922                 :          42 :            || !integer_zerop (sentinel))
    5923                 :          56 :           && TREE_CODE (TREE_TYPE (sentinel)) != NULLPTR_TYPE
    5924                 :             :           /* Although __null (in C++) is only an integer we allow it
    5925                 :             :              nevertheless, as we are guaranteed that it's exactly
    5926                 :             :              as wide as a pointer, and we don't want to force
    5927                 :             :              users to cast the NULL they have written there.
    5928                 :             :              We warn with -Wstrict-null-sentinel, though.  */
    5929                 :         138 :           && (warn_strict_null_sentinel || null_node != sentinel))
    5930                 :          45 :         warning (OPT_Wformat_, "missing sentinel in function call");
    5931                 :             :     }
    5932                 :             : }
    5933                 :             : 
    5934                 :             : /* Check that the same argument isn't passed to two or more
    5935                 :             :    restrict-qualified formal and issue a -Wrestrict warning
    5936                 :             :    if it is.  Return true if a warning has been issued.  */
    5937                 :             : 
    5938                 :             : static bool
    5939                 :    52232847 : check_function_restrict (const_tree fndecl, const_tree fntype,
    5940                 :             :                          int nargs, tree *unfolded_argarray)
    5941                 :             : {
    5942                 :    52232847 :   int i;
    5943                 :    52232847 :   tree parms = TYPE_ARG_TYPES (fntype);
    5944                 :             : 
    5945                 :             :   /* Call fold_for_warn on all of the arguments.  */
    5946                 :    52232847 :   auto_vec<tree> argarray (nargs);
    5947                 :   235352652 :   for (i = 0; i < nargs; i++)
    5948                 :   130886958 :     argarray.quick_push (fold_for_warn (unfolded_argarray[i]));
    5949                 :             : 
    5950                 :    52232847 :   if (fndecl
    5951                 :    51695496 :       && TREE_CODE (fndecl) == FUNCTION_DECL)
    5952                 :             :     {
    5953                 :             :       /* Avoid diagnosing calls built-ins with a zero size/bound
    5954                 :             :          here.  They are checked in more detail elsewhere.  */
    5955                 :    51695496 :       if (fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)
    5956                 :     1707811 :           && nargs == 3
    5957                 :      326589 :           && TREE_CODE (argarray[2]) == INTEGER_CST
    5958                 :    51866499 :           && integer_zerop (argarray[2]))
    5959                 :             :         return false;
    5960                 :             : 
    5961                 :    51669894 :       if (DECL_ARGUMENTS (fndecl))
    5962                 :    52207245 :         parms = DECL_ARGUMENTS (fndecl);
    5963                 :             :     }
    5964                 :             : 
    5965                 :   183017397 :   for (i = 0; i < nargs; i++)
    5966                 :   130810152 :     TREE_VISITED (argarray[i]) = 0;
    5967                 :             : 
    5968                 :             :   bool warned = false;
    5969                 :             : 
    5970                 :   182139590 :   for (i = 0; i < nargs && parms && parms != void_list_node; i++)
    5971                 :             :     {
    5972                 :   129932345 :       tree type;
    5973                 :   129932345 :       if (TREE_CODE (parms) == PARM_DECL)
    5974                 :             :         {
    5975                 :    15541067 :           type = TREE_TYPE (parms);
    5976                 :    15541067 :           parms = DECL_CHAIN (parms);
    5977                 :             :         }
    5978                 :             :       else
    5979                 :             :         {
    5980                 :   114391278 :           type = TREE_VALUE (parms);
    5981                 :   114391278 :           parms = TREE_CHAIN (parms);
    5982                 :             :         }
    5983                 :   129932345 :       if (POINTER_TYPE_P (type)
    5984                 :     7978751 :           && TYPE_RESTRICT (type)
    5985                 :   130179889 :           && !TYPE_READONLY (TREE_TYPE (type)))
    5986                 :      248216 :         warned |= warn_for_restrict (i, argarray.address (), nargs);
    5987                 :             :     }
    5988                 :             : 
    5989                 :   183017397 :   for (i = 0; i < nargs; i++)
    5990                 :   130810152 :     TREE_VISITED (argarray[i]) = 0;
    5991                 :             : 
    5992                 :             :   return warned;
    5993                 :    52232847 : }
    5994                 :             : 
    5995                 :             : /* Helper for check_function_nonnull; given a list of operands which
    5996                 :             :    must be non-null in ARGS, determine if operand PARAM_NUM should be
    5997                 :             :    checked.  */
    5998                 :             : 
    5999                 :             : static bool
    6000                 :      269309 : nonnull_check_p (tree args, unsigned HOST_WIDE_INT param_num)
    6001                 :             : {
    6002                 :      269309 :   unsigned HOST_WIDE_INT arg_num = 0;
    6003                 :             : 
    6004                 :      715313 :   for (; args; args = TREE_CHAIN (args))
    6005                 :             :     {
    6006                 :      568935 :       bool found = get_attribute_operand (TREE_VALUE (args), &arg_num);
    6007                 :             : 
    6008                 :      568935 :       gcc_assert (found);
    6009                 :             : 
    6010                 :      568935 :       if (arg_num == param_num)
    6011                 :             :         return true;
    6012                 :             :     }
    6013                 :             :   return false;
    6014                 :             : }
    6015                 :             : 
    6016                 :             : /* Check that the function argument PARAM (which is operand number
    6017                 :             :    PARAM_NUM) is non-null.  This is called by check_function_nonnull
    6018                 :             :    via check_function_arguments_recurse.  */
    6019                 :             : 
    6020                 :             : static void
    6021                 :      670907 : check_nonnull_arg (void *ctx, tree param, unsigned HOST_WIDE_INT param_num)
    6022                 :             : {
    6023                 :      670907 :   struct nonnull_arg_ctx *pctx = (struct nonnull_arg_ctx *) ctx;
    6024                 :             : 
    6025                 :             :   /* Just skip checking the argument if it's not a pointer.  This can
    6026                 :             :      happen if the "nonnull" attribute was given without an operand
    6027                 :             :      list (which means to check every pointer argument).  */
    6028                 :             : 
    6029                 :      670907 :   tree paramtype = TREE_TYPE (param);
    6030                 :      670907 :   if (TREE_CODE (paramtype) != POINTER_TYPE
    6031                 :       60546 :       && TREE_CODE (paramtype) != NULLPTR_TYPE)
    6032                 :      670158 :     return;
    6033                 :             : 
    6034                 :             :   /* Diagnose the simple cases of null arguments.  */
    6035                 :      610367 :   if (!integer_zerop (fold_for_warn (param)))
    6036                 :             :     return;
    6037                 :             : 
    6038                 :         749 :   auto_diagnostic_group adg;
    6039                 :             : 
    6040                 :         749 :   const location_t loc = EXPR_LOC_OR_LOC (param, pctx->loc);
    6041                 :             : 
    6042                 :         749 :   if (TREE_CODE (pctx->fntype) == METHOD_TYPE)
    6043                 :         109 :     --param_num;
    6044                 :             : 
    6045                 :         749 :   bool warned;
    6046                 :         749 :   if (param_num == 0)
    6047                 :             :     {
    6048                 :          30 :       warned = warning_at (loc, OPT_Wnonnull,
    6049                 :             :                            "%qs pointer is null", "this");
    6050                 :          30 :       if (warned && pctx->fndecl)
    6051                 :          27 :         inform (DECL_SOURCE_LOCATION (pctx->fndecl),
    6052                 :             :                 "in a call to non-static member function %qD",
    6053                 :             :                 pctx->fndecl);
    6054                 :             :     }
    6055                 :             :   else
    6056                 :             :     {
    6057                 :         719 :       if (pctx->other1 && pctx->other2 != pctx->other1)
    6058                 :          14 :         warned = warning_at (loc, OPT_Wnonnull,
    6059                 :             :                              "argument %u null where non-null expected "
    6060                 :             :                              "because arguments %u and %u are nonzero",
    6061                 :             :                              (unsigned) param_num,
    6062                 :             :                              TREE_CODE (pctx->fntype) == METHOD_TYPE
    6063                 :           0 :                              ? (unsigned) pctx->other1 - 1
    6064                 :             :                              : (unsigned) pctx->other1,
    6065                 :             :                              TREE_CODE (pctx->fntype) == METHOD_TYPE
    6066                 :           0 :                              ? (unsigned) pctx->other2 - 1
    6067                 :             :                              : (unsigned) pctx->other2);
    6068                 :         705 :       else if (pctx->other1)
    6069                 :          50 :         warned = warning_at (loc, OPT_Wnonnull,
    6070                 :             :                              "argument %u null where non-null expected "
    6071                 :             :                              "because argument %u is nonzero",
    6072                 :             :                              (unsigned) param_num,
    6073                 :             :                              TREE_CODE (pctx->fntype) == METHOD_TYPE
    6074                 :           0 :                              ? (unsigned) pctx->other1 - 1
    6075                 :             :                              : (unsigned) pctx->other1);
    6076                 :             :       else
    6077                 :         655 :         warned = warning_at (loc, OPT_Wnonnull,
    6078                 :             :                              "argument %u null where non-null expected",
    6079                 :             :                              (unsigned) param_num);
    6080                 :         719 :       if (warned && pctx->fndecl)
    6081                 :         688 :         inform (DECL_SOURCE_LOCATION (pctx->fndecl),
    6082                 :             :                 "in a call to function %qD declared %qs",
    6083                 :             :                 pctx->fndecl,
    6084                 :         688 :                 pctx->other1 ? "nonnull_if_nonzero" : "nonnull");
    6085                 :             :     }
    6086                 :             : 
    6087                 :         746 :   if (warned)
    6088                 :         746 :     pctx->warned_p = true;
    6089                 :         749 : }
    6090                 :             : 
    6091                 :             : /* Helper for attribute handling; fetch the operand number from
    6092                 :             :    the attribute argument list.  */
    6093                 :             : 
    6094                 :             : bool
    6095                 :      568935 : get_attribute_operand (tree arg_num_expr, unsigned HOST_WIDE_INT *valp)
    6096                 :             : {
    6097                 :             :   /* Verify the arg number is a small constant.  */
    6098                 :      568935 :   if (tree_fits_uhwi_p (arg_num_expr))
    6099                 :             :     {
    6100                 :      568935 :       *valp = tree_to_uhwi (arg_num_expr);
    6101                 :      568935 :       return true;
    6102                 :             :     }
    6103                 :             :   else
    6104                 :             :     return false;
    6105                 :             : }
    6106                 :             : 
    6107                 :             : /* Arguments being collected for optimization.  */
    6108                 :             : typedef const char *const_char_p;               /* For DEF_VEC_P.  */
    6109                 :             : static GTY(()) vec<const_char_p, va_gc> *optimize_args;
    6110                 :             : 
    6111                 :             : 
    6112                 :             : /* Inner function to convert a TREE_LIST to argv string to parse the optimize
    6113                 :             :    options in ARGS.  ATTR_P is true if this is for attribute(optimize), and
    6114                 :             :    false for #pragma GCC optimize.  */
    6115                 :             : 
    6116                 :             : bool
    6117                 :      343955 : parse_optimize_options (tree args, bool attr_p)
    6118                 :             : {
    6119                 :      343955 :   bool ret = true;
    6120                 :      343955 :   unsigned opt_argc;
    6121                 :      343955 :   unsigned i;
    6122                 :      343955 :   const char **opt_argv;
    6123                 :      343955 :   struct cl_decoded_option *decoded_options;
    6124                 :      343955 :   unsigned int decoded_options_count;
    6125                 :      343955 :   tree ap;
    6126                 :             : 
    6127                 :             :   /* Build up argv vector.  Just in case the string is stored away, use garbage
    6128                 :             :      collected strings.  */
    6129                 :      343955 :   vec_safe_truncate (optimize_args, 0);
    6130                 :      343955 :   vec_safe_push (optimize_args, (const char *) NULL);
    6131                 :             : 
    6132                 :      706609 :   for (ap = args; ap != NULL_TREE; ap = TREE_CHAIN (ap))
    6133                 :             :     {
    6134                 :      362654 :       tree value = TREE_VALUE (ap);
    6135                 :             : 
    6136                 :      362654 :       if (TREE_CODE (value) == INTEGER_CST)
    6137                 :             :         {
    6138                 :         305 :           char buffer[HOST_BITS_PER_LONG / 3 + 4];
    6139                 :         305 :           sprintf (buffer, "-O%ld", (long) TREE_INT_CST_LOW (value));
    6140                 :         305 :           vec_safe_push (optimize_args, ggc_strdup (buffer));
    6141                 :             :         }
    6142                 :             : 
    6143                 :      362349 :       else if (TREE_CODE (value) == STRING_CST)
    6144                 :             :         {
    6145                 :             :           /* Split string into multiple substrings.  */
    6146                 :      362345 :           size_t len = TREE_STRING_LENGTH (value);
    6147                 :      362345 :           char *p = ASTRDUP (TREE_STRING_POINTER (value));
    6148                 :      362345 :           char *end = p + len;
    6149                 :      362345 :           char *comma;
    6150                 :      362345 :           char *next_p = p;
    6151                 :             : 
    6152                 :      724739 :           while (next_p != NULL)
    6153                 :             :             {
    6154                 :      362394 :               size_t len2;
    6155                 :      362394 :               char *q, *r;
    6156                 :             : 
    6157                 :      362394 :               p = next_p;
    6158                 :      362394 :               comma = strchr (p, ',');
    6159                 :      362394 :               if (comma)
    6160                 :             :                 {
    6161                 :          49 :                   len2 = comma - p;
    6162                 :          49 :                   *comma = '\0';
    6163                 :          49 :                   next_p = comma+1;
    6164                 :             :                 }
    6165                 :             :               else
    6166                 :             :                 {
    6167                 :      362345 :                   len2 = end - p;
    6168                 :      362345 :                   next_p = NULL;
    6169                 :             :                 }
    6170                 :             : 
    6171                 :             :               /* If the user supplied -Oxxx or -fxxx, only allow -Oxxx or -fxxx
    6172                 :             :                  options.  */
    6173                 :      362394 :               if (*p == '-' && p[1] != 'O' && p[1] != 'f')
    6174                 :             :                 {
    6175                 :           0 :                   ret = false;
    6176                 :           0 :                   if (attr_p)
    6177                 :             :                     {
    6178                 :           0 :                       auto_urlify_attributes sentinel;
    6179                 :           0 :                       warning (OPT_Wattributes,
    6180                 :             :                                "bad option %qs to attribute %<optimize%>", p);
    6181                 :           0 :                     }
    6182                 :             :                   else
    6183                 :           0 :                     warning (OPT_Wpragmas,
    6184                 :             :                              "bad option %qs to pragma %<optimize%>", p);
    6185                 :           0 :                   continue;
    6186                 :           0 :                 }
    6187                 :             : 
    6188                 :             :               /* Can't use GC memory here, see PR88007.  */
    6189                 :      362394 :               r = q = XOBNEWVEC (&opts_obstack, char, len2 + 3);
    6190                 :             : 
    6191                 :      362394 :               if (*p != '-')
    6192                 :             :                 {
    6193                 :       42757 :                   *r++ = '-';
    6194                 :             : 
    6195                 :             :                   /* Assume that Ox is -Ox, a numeric value is -Ox, a s by
    6196                 :             :                      itself is -Os, and any other switch begins with a -f.  */
    6197                 :       42757 :                   if ((*p >= '0' && *p <= '9')
    6198                 :       42600 :                       || (p[0] == 's' && p[1] == '\0'))
    6199                 :         157 :                     *r++ = 'O';
    6200                 :       42600 :                   else if (*p != 'O')
    6201                 :       23307 :                     *r++ = 'f';
    6202                 :             :                 }
    6203                 :             : 
    6204                 :      362394 :               memcpy (r, p, len2);
    6205                 :      362394 :               r[len2] = '\0';
    6206                 :      362394 :               vec_safe_push (optimize_args, (const char *) q);
    6207                 :             :             }
    6208                 :             : 
    6209                 :             :         }
    6210                 :             :     }
    6211                 :             : 
    6212                 :      343955 :   opt_argc = optimize_args->length ();
    6213                 :      343955 :   opt_argv = (const char **) alloca (sizeof (char *) * (opt_argc + 1));
    6214                 :             : 
    6215                 :      706654 :   for (i = 1; i < opt_argc; i++)
    6216                 :      362699 :     opt_argv[i] = (*optimize_args)[i];
    6217                 :             : 
    6218                 :             :   /* Now parse the options.  */
    6219                 :      343955 :   decode_cmdline_options_to_array_default_mask (opt_argc, opt_argv,
    6220                 :             :                                                 &decoded_options,
    6221                 :             :                                                 &decoded_options_count);
    6222                 :             :   /* Drop non-Optimization options.  */
    6223                 :      343955 :   unsigned j = 1;
    6224                 :      706654 :   for (i = 1; i < decoded_options_count; ++i)
    6225                 :             :     {
    6226                 :      362699 :       if (! (cl_options[decoded_options[i].opt_index].flags & CL_OPTIMIZATION))
    6227                 :             :         {
    6228                 :           3 :           ret = false;
    6229                 :           3 :           if (attr_p)
    6230                 :             :             {
    6231                 :           2 :               auto_urlify_attributes sentinel;
    6232                 :           2 :               warning (OPT_Wattributes,
    6233                 :             :                        "bad option %qs to attribute %<optimize%>",
    6234                 :           2 :                        decoded_options[i].orig_option_with_args_text);
    6235                 :           2 :             }
    6236                 :             :           else
    6237                 :           1 :             warning (OPT_Wpragmas,
    6238                 :             :                      "bad option %qs to pragma %<optimize%>",
    6239                 :             :                      decoded_options[i].orig_option_with_args_text);
    6240                 :           3 :           continue;
    6241                 :           3 :         }
    6242                 :      362696 :       if (i != j)
    6243                 :           0 :         decoded_options[j] = decoded_options[i];
    6244                 :      362696 :       j++;
    6245                 :             :     }
    6246                 :      343955 :   decoded_options_count = j;
    6247                 :             : 
    6248                 :             :   /* Merge the decoded options with save_decoded_options.  */
    6249                 :      343955 :   unsigned save_opt_count = save_opt_decoded_options->length ();
    6250                 :      343955 :   unsigned merged_decoded_options_count
    6251                 :             :     = save_opt_count + decoded_options_count;
    6252                 :      343955 :   cl_decoded_option *merged_decoded_options
    6253                 :      343955 :     = XNEWVEC (cl_decoded_option, merged_decoded_options_count);
    6254                 :             : 
    6255                 :             :   /* Note the first decoded_options is used for the program name.  */
    6256                 :     1972638 :   for (unsigned i = 0; i < save_opt_count; ++i)
    6257                 :     1628683 :     merged_decoded_options[i + 1] = (*save_opt_decoded_options)[i];
    6258                 :      706651 :   for (unsigned i = 1; i < decoded_options_count; ++i)
    6259                 :      362696 :     merged_decoded_options[save_opt_count + i] = decoded_options[i];
    6260                 :             : 
    6261                 :             :    /* And apply them.  */
    6262                 :      343955 :   decode_options (&global_options, &global_options_set,
    6263                 :             :                   merged_decoded_options, merged_decoded_options_count,
    6264                 :             :                   input_location, global_dc, NULL);
    6265                 :      343955 :   free (decoded_options);
    6266                 :             : 
    6267                 :      343955 :   targetm.override_options_after_change();
    6268                 :             : 
    6269                 :      343955 :   optimize_args->truncate (0);
    6270                 :      343955 :   return ret;
    6271                 :             : }
    6272                 :             : 
    6273                 :             : /* Check whether ATTR is a valid attribute fallthrough.  */
    6274                 :             : 
    6275                 :             : bool
    6276                 :   270287236 : attribute_fallthrough_p (tree attr)
    6277                 :             : {
    6278                 :   270287236 :   if (attr == error_mark_node)
    6279                 :             :    return false;
    6280                 :   270287218 :   tree t = lookup_attribute ("", "fallthrough", attr);
    6281                 :   270287218 :   if (t == NULL_TREE)
    6282                 :             :     return false;
    6283                 :       18077 :   auto_urlify_attributes sentinel;
    6284                 :             :   /* It is no longer true that "this attribute shall appear at most once in
    6285                 :             :      each attribute-list", but we still give a warning.  */
    6286                 :       18077 :   if (lookup_attribute ("", "fallthrough", TREE_CHAIN (t)))
    6287                 :           9 :     warning (OPT_Wattributes, "attribute %<fallthrough%> specified multiple "
    6288                 :             :              "times");
    6289                 :             :   /* No attribute-argument-clause shall be present.  */
    6290                 :       18068 :   else if (TREE_VALUE (t) != NULL_TREE)
    6291                 :           4 :     warning (OPT_Wattributes, "%<fallthrough%> attribute specified with "
    6292                 :             :              "a parameter");
    6293                 :             :   /* Warn if other attributes are found.  */
    6294                 :       36180 :   for (t = attr; t != NULL_TREE; t = TREE_CHAIN (t))
    6295                 :             :     {
    6296                 :       18103 :       tree name = get_attribute_name (t);
    6297                 :       18103 :       if (!is_attribute_p ("fallthrough", name)
    6298                 :       18103 :           || !is_attribute_namespace_p ("", t))
    6299                 :             :         {
    6300                 :          17 :           if (!c_dialect_cxx () && get_attribute_namespace (t) == NULL_TREE)
    6301                 :             :             /* The specifications of standard attributes in C mean
    6302                 :             :                this is a constraint violation.  */
    6303                 :           3 :             pedwarn (input_location, OPT_Wattributes, "%qE attribute ignored",
    6304                 :             :                      get_attribute_name (t));
    6305                 :             :           else
    6306                 :          14 :             warning (OPT_Wattributes, "%qE attribute ignored", name);
    6307                 :             :         }
    6308                 :             :     }
    6309                 :       18077 :   return true;
    6310                 :       18077 : }
    6311                 :             : 
    6312                 :             : 
    6313                 :             : /* Check for valid arguments being passed to a function with FNTYPE.
    6314                 :             :    There are NARGS arguments in the array ARGARRAY.  LOC should be used
    6315                 :             :    for diagnostics.  Return true if either -Wnonnull or -Wrestrict has
    6316                 :             :    been issued.
    6317                 :             : 
    6318                 :             :    The arguments in ARGARRAY may not have been folded yet (e.g. for C++,
    6319                 :             :    to preserve location wrappers); checks that require folded arguments
    6320                 :             :    should call fold_for_warn on them.
    6321                 :             : 
    6322                 :             :    Use the frontend-supplied COMP_TYPES when determining if
    6323                 :             :    one type is a subclass of another.  */
    6324                 :             : 
    6325                 :             : bool
    6326                 :    52829996 : check_function_arguments (location_t loc, const_tree fndecl, const_tree fntype,
    6327                 :             :                           int nargs, tree *argarray, vec<location_t> *arglocs,
    6328                 :             :                           bool (*comp_types) (tree, tree))
    6329                 :             : {
    6330                 :    52829996 :   bool warned_p = false;
    6331                 :             : 
    6332                 :    52829996 :   if (c_inhibit_evaluation_warnings)
    6333                 :             :     return warned_p;
    6334                 :             : 
    6335                 :             :   /* Check for null being passed in a pointer argument that must be
    6336                 :             :      non-null.  In C++, this includes the this pointer.  We also need
    6337                 :             :      to do this if format checking is enabled.  */
    6338                 :    52237574 :   if (warn_nonnull)
    6339                 :             :     {
    6340                 :     6405824 :       nonnull_arg_ctx ctx = { loc, fndecl, fntype, 0, 0, false };
    6341                 :     6405824 :       warned_p = check_function_nonnull (ctx, nargs, argarray);
    6342                 :             :     }
    6343                 :             : 
    6344                 :             :   /* Check for errors in format strings.  */
    6345                 :             : 
    6346                 :    52237574 :   if (warn_format || warn_suggest_attribute_format)
    6347                 :     6468560 :     check_function_format (fndecl ? fndecl : fntype, TYPE_ATTRIBUTES (fntype), nargs,
    6348                 :             :                            argarray, arglocs, comp_types);
    6349                 :             : 
    6350                 :    52237574 :   if (warn_format)
    6351                 :     6391561 :     check_function_sentinel (fntype, nargs, argarray);
    6352                 :             : 
    6353                 :    52237574 :   if (fndecl && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
    6354                 :             :     {
    6355                 :     1712538 :       switch (DECL_FUNCTION_CODE (fndecl))
    6356                 :             :         {
    6357                 :             :         case BUILT_IN_SPRINTF:
    6358                 :             :         case BUILT_IN_SPRINTF_CHK:
    6359                 :             :         case BUILT_IN_SNPRINTF:
    6360                 :             :         case BUILT_IN_SNPRINTF_CHK:
    6361                 :             :           /* Let the sprintf pass handle these.  */
    6362                 :             :           return warned_p;
    6363                 :             : 
    6364                 :             :         default:
    6365                 :             :           break;
    6366                 :             :         }
    6367                 :             :     }
    6368                 :             : 
    6369                 :             :   /* check_function_restrict sets the DECL_READ_P for arguments
    6370                 :             :      so it must be called unconditionally.  */
    6371                 :    52232847 :   warned_p |= check_function_restrict (fndecl, fntype, nargs, argarray);
    6372                 :             : 
    6373                 :    52232847 :   return warned_p;
    6374                 :             : }
    6375                 :             : 
    6376                 :             : /* Generic argument checking recursion routine.  PARAM is the argument to
    6377                 :             :    be checked.  PARAM_NUM is the number of the argument.  CALLBACK is invoked
    6378                 :             :    once the argument is resolved.  CTX is context for the callback.
    6379                 :             :    OPT is the warning for which this is done.  */
    6380                 :             : void
    6381                 :      726671 : check_function_arguments_recurse (void (*callback)
    6382                 :             :                                   (void *, tree, unsigned HOST_WIDE_INT),
    6383                 :             :                                   void *ctx, tree param,
    6384                 :             :                                   unsigned HOST_WIDE_INT param_num,
    6385                 :             :                                   opt_code opt)
    6386                 :             : {
    6387                 :     1136711 :   if (opt != OPT_Wformat_ && warning_suppressed_p (param))
    6388                 :             :     return;
    6389                 :             : 
    6390                 :      775703 :   if (CONVERT_EXPR_P (param)
    6391                 :     1256075 :       && (TYPE_PRECISION (TREE_TYPE (param))
    6392                 :      480372 :           == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (param, 0)))))
    6393                 :             :     {
    6394                 :             :       /* Strip coercion.  */
    6395                 :      818494 :       check_function_arguments_recurse (callback, ctx,
    6396                 :      409247 :                                         TREE_OPERAND (param, 0), param_num,
    6397                 :             :                                         opt);
    6398                 :      409247 :       return;
    6399                 :             :     }
    6400                 :             : 
    6401                 :      725755 :   if (TREE_CODE (param) == CALL_EXPR && CALL_EXPR_FN (param))
    6402                 :             :     {
    6403                 :        8257 :       tree type = TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (param)));
    6404                 :        8257 :       tree attrs;
    6405                 :        8257 :       bool found_format_arg = false;
    6406                 :             : 
    6407                 :             :       /* See if this is a call to a known internationalization function
    6408                 :             :          that modifies a format arg.  Such a function may have multiple
    6409                 :             :          format_arg attributes (for example, ngettext).  */
    6410                 :             : 
    6411                 :        8257 :       for (attrs = TYPE_ATTRIBUTES (type);
    6412                 :        8639 :            attrs;
    6413                 :         382 :            attrs = TREE_CHAIN (attrs))
    6414                 :         382 :         if (is_attribute_p ("format_arg", get_attribute_name (attrs)))
    6415                 :             :           {
    6416                 :         226 :             tree inner_arg;
    6417                 :         226 :             tree format_num_expr;
    6418                 :         226 :             int format_num;
    6419                 :         226 :             int i;
    6420                 :         226 :             call_expr_arg_iterator iter;
    6421                 :             : 
    6422                 :             :             /* Extract the argument number, which was previously checked
    6423                 :             :                to be valid.  */
    6424                 :         226 :             format_num_expr = TREE_VALUE (TREE_VALUE (attrs));
    6425                 :             : 
    6426                 :         226 :             format_num = tree_to_uhwi (format_num_expr);
    6427                 :             : 
    6428                 :         226 :             for (inner_arg = first_call_expr_arg (param, &iter), i = 1;
    6429                 :         320 :                  inner_arg != NULL_TREE;
    6430                 :          94 :                  inner_arg = next_call_expr_arg (&iter), i++)
    6431                 :         320 :               if (i == format_num)
    6432                 :             :                 {
    6433                 :         226 :                   check_function_arguments_recurse (callback, ctx,
    6434                 :             :                                                     inner_arg, param_num,
    6435                 :             :                                                     opt);
    6436                 :         226 :                   found_format_arg = true;
    6437                 :         226 :                   break;
    6438                 :             :                 }
    6439                 :             :           }
    6440                 :             : 
    6441                 :             :       /* If we found a format_arg attribute and did a recursive check,
    6442                 :             :          we are done with checking this argument.  Otherwise, we continue
    6443                 :             :          and this will be considered a non-literal.  */
    6444                 :        8257 :       if (found_format_arg)
    6445                 :             :         return;
    6446                 :             :     }
    6447                 :             : 
    6448                 :      725577 :   if (TREE_CODE (param) == COND_EXPR)
    6449                 :             :     {
    6450                 :             :       /* Simplify to avoid warning for an impossible case.  */
    6451                 :         811 :       param = fold_for_warn (param);
    6452                 :         811 :       if (TREE_CODE (param) == COND_EXPR)
    6453                 :             :         {
    6454                 :             :           /* Check both halves of the conditional expression.  */
    6455                 :         793 :           check_function_arguments_recurse (callback, ctx,
    6456                 :         793 :                                             TREE_OPERAND (param, 1),
    6457                 :             :                                             param_num, opt);
    6458                 :        1586 :           check_function_arguments_recurse (callback, ctx,
    6459                 :         793 :                                             TREE_OPERAND (param, 2),
    6460                 :             :                                             param_num, opt);
    6461                 :         793 :           return;
    6462                 :             :         }
    6463                 :             :     }
    6464                 :             : 
    6465                 :      724784 :   (*callback) (ctx, param, param_num);
    6466                 :             : }
    6467                 :             : 
    6468                 :             : /* Checks for a builtin function FNDECL that the number of arguments
    6469                 :             :    NARGS against the required number REQUIRED and issues an error if
    6470                 :             :    there is a mismatch.  Returns true if the number of arguments is
    6471                 :             :    correct, otherwise false.  LOC is the location of FNDECL.  */
    6472                 :             : 
    6473                 :             : static bool
    6474                 :      773773 : builtin_function_validate_nargs (location_t loc, tree fndecl, int nargs,
    6475                 :             :                                  int required, bool complain)
    6476                 :             : {
    6477                 :      773773 :   if (nargs < required)
    6478                 :             :     {
    6479                 :         182 :       if (complain)
    6480                 :         143 :         error_at (loc, "too few arguments to function %qE", fndecl);
    6481                 :         182 :       return false;
    6482                 :             :     }
    6483                 :      773591 :   else if (nargs > required)
    6484                 :             :     {
    6485                 :         138 :       if (complain)
    6486                 :          93 :         error_at (loc, "too many arguments to function %qE", fndecl);
    6487                 :         138 :       return false;
    6488                 :             :     }
    6489                 :             :   return true;
    6490                 :             : }
    6491                 :             : 
    6492                 :             : /* Helper macro for check_builtin_function_arguments.  */
    6493                 :             : #define ARG_LOCATION(N)                                 \
    6494                 :             :   (arg_loc.is_empty ()                                  \
    6495                 :             :    ? EXPR_LOC_OR_LOC (args[(N)], input_location)        \
    6496                 :             :    : expansion_point_location (arg_loc[(N)]))
    6497                 :             : 
    6498                 :             : /* Verifies the NARGS arguments ARGS to the builtin function FNDECL.
    6499                 :             :    Returns false if there was an error, otherwise true.  LOC is the
    6500                 :             :    location of the function; ARG_LOC is a vector of locations of the
    6501                 :             :    arguments.  If FNDECL is the result of resolving an overloaded
    6502                 :             :    target built-in, ORIG_FNDECL is the original function decl,
    6503                 :             :    otherwise it is null.  */
    6504                 :             : 
    6505                 :             : bool
    6506                 :    39498850 : check_builtin_function_arguments (location_t loc, vec<location_t> arg_loc,
    6507                 :             :                                   tree fndecl, tree orig_fndecl, int nargs,
    6508                 :             :                                   tree *args, bool complain)
    6509                 :             : {
    6510                 :    39498850 :   if (!fndecl_built_in_p (fndecl))
    6511                 :             :     return true;
    6512                 :             : 
    6513                 :    39498850 :   if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD)
    6514                 :    32078955 :     return (!targetm.check_builtin_call
    6515                 :    32078955 :             || targetm.check_builtin_call (loc, arg_loc, fndecl, orig_fndecl,
    6516                 :             :                                            nargs, args, complain));
    6517                 :             : 
    6518                 :     7419895 :   if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_FRONTEND)
    6519                 :             :     return true;
    6520                 :             : 
    6521                 :     7390168 :   gcc_assert (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL);
    6522                 :     7390168 :   switch (DECL_FUNCTION_CODE (fndecl))
    6523                 :             :     {
    6524                 :           2 :     case BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX:
    6525                 :           2 :       if (!tree_fits_uhwi_p (args[2]))
    6526                 :             :         {
    6527                 :           0 :           if (complain)
    6528                 :           0 :             error_at (
    6529                 :           0 :               ARG_LOCATION (2),
    6530                 :             :               "third argument to function %qE must be a constant integer",
    6531                 :             :               fndecl);
    6532                 :           0 :           return false;
    6533                 :             :         }
    6534                 :             :       /* fall through */
    6535                 :             : 
    6536                 :         264 :     case BUILT_IN_ALLOCA_WITH_ALIGN:
    6537                 :         264 :       {
    6538                 :             :         /* Get the requested alignment (in bits) if it's a constant
    6539                 :             :            integer expression.  */
    6540                 :         264 :         unsigned HOST_WIDE_INT align
    6541                 :         264 :           = tree_fits_uhwi_p (args[1]) ? tree_to_uhwi (args[1]) : 0;
    6542                 :             : 
    6543                 :             :         /* Determine if the requested alignment is a power of 2.  */
    6544                 :         264 :         if ((align & (align - 1)))
    6545                 :             :           align = 0;
    6546                 :             : 
    6547                 :             :         /* The maximum alignment in bits corresponding to the same
    6548                 :             :            maximum in bytes enforced in check_user_alignment().  */
    6549                 :         315 :         unsigned maxalign = (UINT_MAX >> 1) + 1;
    6550                 :             : 
    6551                 :             :         /* Reject invalid alignments.  */
    6552                 :         181 :         if (align < BITS_PER_UNIT || maxalign < align)
    6553                 :             :           {
    6554                 :         134 :             if (complain)
    6555                 :         169 :               error_at (ARG_LOCATION (1),
    6556                 :             :                         "second argument to function %qE must be a constant "
    6557                 :             :                         "integer power of 2 between %qi and %qu bits",
    6558                 :             :                         fndecl, BITS_PER_UNIT, maxalign);
    6559                 :         134 :             return false;
    6560                 :             :           }
    6561                 :             :         return true;
    6562                 :             :       }
    6563                 :             : 
    6564                 :       95581 :     case BUILT_IN_CONSTANT_P:
    6565                 :       95581 :       return builtin_function_validate_nargs (loc, fndecl, nargs, 1, complain);
    6566                 :             : 
    6567                 :      275393 :     case BUILT_IN_ISFINITE:
    6568                 :      275393 :     case BUILT_IN_ISINF:
    6569                 :      275393 :     case BUILT_IN_ISINF_SIGN:
    6570                 :      275393 :     case BUILT_IN_ISNAN:
    6571                 :      275393 :     case BUILT_IN_ISNORMAL:
    6572                 :      275393 :     case BUILT_IN_ISSIGNALING:
    6573                 :      275393 :     case BUILT_IN_SIGNBIT:
    6574                 :      275393 :       if (builtin_function_validate_nargs (loc, fndecl, nargs, 1, complain))
    6575                 :             :         {
    6576                 :      275358 :           if (TREE_CODE (TREE_TYPE (args[0])) != REAL_TYPE)
    6577                 :             :             {
    6578                 :          37 :               if (complain)
    6579                 :          28 :                 error_at (ARG_LOCATION (0),
    6580                 :             :                           "non-floating-point argument in "
    6581                 :             :                           "call to function %qE",
    6582                 :             :                           fndecl);
    6583                 :          37 :               return false;
    6584                 :             :             }
    6585                 :             :           return true;
    6586                 :             :         }
    6587                 :             :       return false;
    6588                 :             : 
    6589                 :      229868 :     case BUILT_IN_ISGREATER:
    6590                 :      229868 :     case BUILT_IN_ISGREATEREQUAL:
    6591                 :      229868 :     case BUILT_IN_ISLESS:
    6592                 :      229868 :     case BUILT_IN_ISLESSEQUAL:
    6593                 :      229868 :     case BUILT_IN_ISLESSGREATER:
    6594                 :      229868 :     case BUILT_IN_ISUNORDERED:
    6595                 :      229868 :     case BUILT_IN_ISEQSIG:
    6596                 :      229868 :       if (builtin_function_validate_nargs (loc, fndecl, nargs, 2, complain))
    6597                 :             :         {
    6598                 :      229833 :           enum tree_code code0, code1;
    6599                 :      229833 :           code0 = TREE_CODE (TREE_TYPE (args[0]));
    6600                 :      229833 :           code1 = TREE_CODE (TREE_TYPE (args[1]));
    6601                 :      229833 :           if (!((code0 == REAL_TYPE && code1 == REAL_TYPE)
    6602                 :         147 :                 || (code0 == REAL_TYPE
    6603                 :          56 :                     && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
    6604                 :          92 :                 || ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE)
    6605                 :          81 :                     && code1 == REAL_TYPE)))
    6606                 :             :             {
    6607                 :          39 :               if (complain)
    6608                 :          18 :                 error_at (loc,
    6609                 :             :                           "non-floating-point arguments in call to "
    6610                 :             :                           "function %qE",
    6611                 :             :                           fndecl);
    6612                 :          39 :               return false;
    6613                 :             :             }
    6614                 :             :           return true;
    6615                 :             :         }
    6616                 :             :       return false;
    6617                 :             : 
    6618                 :       39007 :     case BUILT_IN_FPCLASSIFY:
    6619                 :       39007 :       if (builtin_function_validate_nargs (loc, fndecl, nargs, 6, complain))
    6620                 :             :         {
    6621                 :      233970 :           for (unsigned int i = 0; i < 5; i++)
    6622                 :      194979 :             if (TREE_CODE (args[i]) != INTEGER_CST)
    6623                 :             :               {
    6624                 :          12 :                 if (complain)
    6625                 :          12 :                   error_at (ARG_LOCATION (i),
    6626                 :             :                             "non-const integer argument %u in "
    6627                 :             :                             "call to function %qE",
    6628                 :             :                             i + 1, fndecl);
    6629                 :          12 :                 return false;
    6630                 :             :               }
    6631                 :             : 
    6632                 :       38991 :           if (TREE_CODE (TREE_TYPE (args[5])) != REAL_TYPE)
    6633                 :             :             {
    6634                 :           2 :               if (complain)
    6635                 :           4 :                 error_at (ARG_LOCATION (5),
    6636                 :             :                           "non-floating-point argument in "
    6637                 :             :                           "call to function %qE",
    6638                 :             :                           fndecl);
    6639                 :           2 :               return false;
    6640                 :             :             }
    6641                 :             :           return true;
    6642                 :             :         }
    6643                 :             :       return false;
    6644                 :             : 
    6645                 :         415 :     case BUILT_IN_ASSUME_ALIGNED:
    6646                 :         810 :       if (builtin_function_validate_nargs (loc, fndecl, nargs, 2 + (nargs > 2),
    6647                 :             :                                            complain))
    6648                 :             :         {
    6649                 :         413 :           if (nargs >= 3
    6650                 :          18 :               && TREE_CODE (TREE_TYPE (args[2])) != INTEGER_TYPE
    6651                 :         420 :               && TREE_CODE (TREE_TYPE (args[2])) != BITINT_TYPE)
    6652                 :             :             {
    6653                 :           6 :               if (complain)
    6654                 :           6 :                 error_at (ARG_LOCATION (2),
    6655                 :             :                           "non-integer argument 3 in call to "
    6656                 :             :                           "function %qE",
    6657                 :             :                           fndecl);
    6658                 :           6 :               return false;
    6659                 :             :             }
    6660                 :             :           return true;
    6661                 :             :         }
    6662                 :             :       return false;
    6663                 :             : 
    6664                 :       74169 :     case BUILT_IN_ADD_OVERFLOW:
    6665                 :       74169 :     case BUILT_IN_SUB_OVERFLOW:
    6666                 :       74169 :     case BUILT_IN_MUL_OVERFLOW:
    6667                 :       74169 :       if (builtin_function_validate_nargs (loc, fndecl, nargs, 3, complain))
    6668                 :             :         {
    6669                 :             :           unsigned i;
    6670                 :      222051 :           for (i = 0; i < 2; i++)
    6671                 :      148060 :             if (!INTEGRAL_TYPE_P (TREE_TYPE (args[i])))
    6672                 :             :               {
    6673                 :          55 :                 if (complain)
    6674                 :          77 :                   error_at (ARG_LOCATION (i),
    6675                 :             :                             "argument %u in call to function "
    6676                 :             :                             "%qE does not have integral type",
    6677                 :             :                             i + 1, fndecl);
    6678                 :          55 :                 return false;
    6679                 :             :               }
    6680                 :       73991 :           if (TREE_CODE (TREE_TYPE (args[2])) != POINTER_TYPE
    6681                 :       73991 :               || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (args[2]))))
    6682                 :             :             {
    6683                 :          60 :               if (complain)
    6684                 :          75 :                 error_at (ARG_LOCATION (2),
    6685                 :             :                           "argument 3 in call to function %qE "
    6686                 :             :                           "does not have pointer to integral type",
    6687                 :             :                           fndecl);
    6688                 :          60 :               return false;
    6689                 :             :             }
    6690                 :       73931 :           else if (TREE_CODE (TREE_TYPE (TREE_TYPE (args[2]))) == ENUMERAL_TYPE)
    6691                 :             :             {
    6692                 :          16 :               if (complain)
    6693                 :          11 :                 error_at (ARG_LOCATION (2),
    6694                 :             :                           "argument 3 in call to function %qE "
    6695                 :             :                           "has pointer to enumerated type",
    6696                 :             :                           fndecl);
    6697                 :          16 :               return false;
    6698                 :             :             }
    6699                 :       73915 :           else if (TREE_CODE (TREE_TYPE (TREE_TYPE (args[2]))) == BOOLEAN_TYPE)
    6700                 :             :             {
    6701                 :          21 :               if (complain)
    6702                 :          16 :                 error_at (ARG_LOCATION (2),
    6703                 :             :                           "argument 3 in call to function %qE "
    6704                 :             :                           "has pointer to boolean type",
    6705                 :             :                           fndecl);
    6706                 :          21 :               return false;
    6707                 :             :             }
    6708                 :       73894 :           else if (TYPE_READONLY (TREE_TYPE (TREE_TYPE (args[2]))))
    6709                 :             :             {
    6710                 :          30 :               if (complain)
    6711                 :          30 :                 error_at (ARG_LOCATION (2),
    6712                 :             :                           "argument %u in call to function %qE "
    6713                 :             :                           "has pointer to %qs type (%qT)",
    6714                 :          21 :                           3, fndecl, "const", TREE_TYPE (args[2]));
    6715                 :          30 :               return false;
    6716                 :             :             }
    6717                 :       73864 :           else if (TYPE_ATOMIC (TREE_TYPE (TREE_TYPE (args[2]))))
    6718                 :             :             {
    6719                 :           6 :               if (complain)
    6720                 :          12 :                 error_at (ARG_LOCATION (2),
    6721                 :             :                           "argument %u in call to function %qE "
    6722                 :             :                           "has pointer to %qs type (%qT)",
    6723                 :           6 :                           3, fndecl, "_Atomic", TREE_TYPE (args[2]));
    6724                 :           6 :               return false;
    6725                 :             :             }
    6726                 :             :           return true;
    6727                 :             :         }
    6728                 :             :       return false;
    6729                 :             : 
    6730                 :       41854 :     case BUILT_IN_ADD_OVERFLOW_P:
    6731                 :       41854 :     case BUILT_IN_SUB_OVERFLOW_P:
    6732                 :       41854 :     case BUILT_IN_MUL_OVERFLOW_P:
    6733                 :       41854 :       if (builtin_function_validate_nargs (loc, fndecl, nargs, 3, complain))
    6734                 :             :         {
    6735                 :             :           unsigned i;
    6736                 :      167205 :           for (i = 0; i < 3; i++)
    6737                 :      125421 :             if (!INTEGRAL_TYPE_P (TREE_TYPE (args[i])))
    6738                 :             :               {
    6739                 :          37 :                 if (complain)
    6740                 :          35 :                   error_at (ARG_LOCATION (i),
    6741                 :             :                             "argument %u in call to function "
    6742                 :             :                             "%qE does not have integral type",
    6743                 :             :                             i + 1, fndecl);
    6744                 :          37 :                 return false;
    6745                 :             :               }
    6746                 :       41784 :           if (TREE_CODE (TREE_TYPE (args[2])) == ENUMERAL_TYPE)
    6747                 :             :             {
    6748                 :          13 :               if (complain)
    6749                 :           5 :                 error_at (ARG_LOCATION (2),
    6750                 :             :                           "argument %u in call to function "
    6751                 :             :                           "%qE has enumerated type",
    6752                 :             :                           3, fndecl);
    6753                 :          13 :               return false;
    6754                 :             :             }
    6755                 :       41771 :           else if (TREE_CODE (TREE_TYPE (args[2])) == BOOLEAN_TYPE)
    6756                 :             :             {
    6757                 :          13 :               if (complain)
    6758                 :           5 :                 error_at (ARG_LOCATION (2),
    6759                 :             :                           "argument %u in call to function "
    6760                 :             :                           "%qE has boolean type",
    6761                 :             :                           3, fndecl);
    6762                 :          13 :               return false;
    6763                 :             :             }
    6764                 :             :           return true;
    6765                 :             :         }
    6766                 :             :       return false;
    6767                 :             : 
    6768                 :       10156 :     case BUILT_IN_CLEAR_PADDING:
    6769                 :       10156 :       if (builtin_function_validate_nargs (loc, fndecl, nargs, 1, complain))
    6770                 :             :         {
    6771                 :       10141 :           if (!POINTER_TYPE_P (TREE_TYPE (args[0])))
    6772                 :             :             {
    6773                 :           7 :               if (complain)
    6774                 :           5 :                 error_at (ARG_LOCATION (0),
    6775                 :             :                           "argument %u in call to function "
    6776                 :             :                           "%qE does not have pointer type",
    6777                 :             :                           1, fndecl);
    6778                 :           7 :               return false;
    6779                 :             :             }
    6780                 :       10134 :           else if (!COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (args[0]))))
    6781                 :             :             {
    6782                 :          11 :               if (complain)
    6783                 :          10 :                 error_at (ARG_LOCATION (0),
    6784                 :             :                           "argument %u in call to function "
    6785                 :             :                           "%qE points to incomplete type",
    6786                 :             :                           1, fndecl);
    6787                 :          11 :               return false;
    6788                 :             :             }
    6789                 :       10123 :           else if (TYPE_READONLY (TREE_TYPE (TREE_TYPE (args[0]))))
    6790                 :             :             {
    6791                 :           7 :               if (complain)
    6792                 :           5 :                 error_at (ARG_LOCATION (0),
    6793                 :             :                           "argument %u in call to function %qE "
    6794                 :             :                           "has pointer to %qs type (%qT)",
    6795                 :           4 :                           1, fndecl, "const", TREE_TYPE (args[0]));
    6796                 :           7 :               return false;
    6797                 :             :             }
    6798                 :       10116 :           else if (TYPE_ATOMIC (TREE_TYPE (TREE_TYPE (args[0]))))
    6799                 :             :             {
    6800                 :           0 :               if (complain)
    6801                 :           0 :                 error_at (ARG_LOCATION (0),
    6802                 :             :                           "argument %u in call to function %qE "
    6803                 :             :                           "has pointer to %qs type (%qT)",
    6804                 :           0 :                           1, fndecl, "_Atomic", TREE_TYPE (args[0]));
    6805                 :           0 :               return false;
    6806                 :             :             }
    6807                 :             :           return true;
    6808                 :             :         }
    6809                 :             :       return false;
    6810                 :             : 
    6811                 :       58380 :     case BUILT_IN_CLZG:
    6812                 :       58380 :     case BUILT_IN_CTZG:
    6813                 :       58380 :     case BUILT_IN_CLRSBG:
    6814                 :       58380 :     case BUILT_IN_FFSG:
    6815                 :       58380 :     case BUILT_IN_PARITYG:
    6816                 :       58380 :     case BUILT_IN_POPCOUNTG:
    6817                 :       58380 :       if (nargs == 2
    6818                 :       58380 :           && (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_CLZG
    6819                 :       16426 :               || DECL_FUNCTION_CODE (fndecl) == BUILT_IN_CTZG))
    6820                 :             :         {
    6821                 :       51050 :           if (!INTEGRAL_TYPE_P (TREE_TYPE (args[1])))
    6822                 :             :             {
    6823                 :          18 :               if (complain)
    6824                 :          15 :                 error_at (ARG_LOCATION (1),
    6825                 :             :                           "argument %u in call to function "
    6826                 :             :                           "%qE does not have integral type",
    6827                 :             :                           2, fndecl);
    6828                 :          18 :               return false;
    6829                 :             :             }
    6830                 :       51032 :           if ((TYPE_PRECISION (TREE_TYPE (args[1]))
    6831                 :       51032 :                > TYPE_PRECISION (integer_type_node))
    6832                 :       51032 :               || (TYPE_PRECISION (TREE_TYPE (args[1]))
    6833                 :       51018 :                   == TYPE_PRECISION (integer_type_node)
    6834                 :       51012 :                   && TYPE_UNSIGNED (TREE_TYPE (args[1]))))
    6835                 :             :             {
    6836                 :          28 :               if (complain)
    6837                 :          26 :                 error_at (ARG_LOCATION (1),
    6838                 :             :                           "argument %u in call to function "
    6839                 :             :                           "%qE does not have %<int%> type",
    6840                 :             :                           2, fndecl);
    6841                 :          28 :               return false;
    6842                 :             :             }
    6843                 :             :         }
    6844                 :        7330 :       else if (!builtin_function_validate_nargs (loc, fndecl, nargs, 1,
    6845                 :             :                                                  complain))
    6846                 :             :         return false;
    6847                 :             : 
    6848                 :       58268 :       if (!INTEGRAL_TYPE_P (TREE_TYPE (args[0])))
    6849                 :             :         {
    6850                 :          82 :           if (complain)
    6851                 :          80 :             error_at (ARG_LOCATION (0),
    6852                 :             :                       "argument %u in call to function "
    6853                 :             :                       "%qE does not have integral type",
    6854                 :             :                       1, fndecl);
    6855                 :          82 :           return false;
    6856                 :             :         }
    6857                 :       58186 :       if (TREE_CODE (TREE_TYPE (args[0])) == ENUMERAL_TYPE)
    6858                 :             :         {
    6859                 :          42 :           if (complain)
    6860                 :          24 :             error_at (ARG_LOCATION (0),
    6861                 :             :                       "argument %u in call to function "
    6862                 :             :                       "%qE has enumerated type",
    6863                 :             :                       1, fndecl);
    6864                 :          42 :           return false;
    6865                 :             :         }
    6866                 :       58144 :       if (TREE_CODE (TREE_TYPE (args[0])) == BOOLEAN_TYPE)
    6867                 :             :         {
    6868                 :          50 :           if (complain)
    6869                 :          40 :             error_at (ARG_LOCATION (0),
    6870                 :             :                       "argument %u in call to function "
    6871                 :             :                       "%qE has boolean type",
    6872                 :             :                       1, fndecl);
    6873                 :          50 :           return false;
    6874                 :             :         }
    6875                 :       58094 :       if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_FFSG
    6876                 :       58094 :           || DECL_FUNCTION_CODE (fndecl) == BUILT_IN_CLRSBG)
    6877                 :             :         {
    6878                 :         288 :           if (TYPE_UNSIGNED (TREE_TYPE (args[0])))
    6879                 :             :             {
    6880                 :          14 :               if (complain)
    6881                 :          10 :                 error_at (ARG_LOCATION (0),
    6882                 :             :                           "argument 1 in call to function "
    6883                 :             :                           "%qE has unsigned type",
    6884                 :             :                           fndecl);
    6885                 :          14 :               return false;
    6886                 :             :             }
    6887                 :             :         }
    6888                 :       57806 :       else if (!TYPE_UNSIGNED (TREE_TYPE (args[0])))
    6889                 :             :         {
    6890                 :          42 :           if (complain)
    6891                 :          42 :             error_at (ARG_LOCATION (0),
    6892                 :             :                       "argument 1 in call to function "
    6893                 :             :                       "%qE has signed type",
    6894                 :             :                       fndecl);
    6895                 :          42 :           return false;
    6896                 :             :         }
    6897                 :             :       return true;
    6898                 :             : 
    6899                 :             :     default:
    6900                 :             :       return true;
    6901                 :             :     }
    6902                 :             : }
    6903                 :             : 
    6904                 :             : /* Subroutine of c_parse_error.
    6905                 :             :    Return the result of concatenating LHS and RHS. RHS is really
    6906                 :             :    a string literal, its first character is indicated by RHS_START and
    6907                 :             :    RHS_SIZE is its length (including the terminating NUL character).
    6908                 :             : 
    6909                 :             :    The caller is responsible for deleting the returned pointer.  */
    6910                 :             : 
    6911                 :             : static char *
    6912                 :        8742 : catenate_strings (const char *lhs, const char *rhs_start, int rhs_size)
    6913                 :             : {
    6914                 :        8742 :   const size_t lhs_size = strlen (lhs);
    6915                 :        8742 :   char *result = XNEWVEC (char, lhs_size + rhs_size);
    6916                 :        8742 :   memcpy (result, lhs, lhs_size);
    6917                 :        8742 :   memcpy (result + lhs_size, rhs_start, rhs_size);
    6918                 :        8742 :   return result;
    6919                 :             : }
    6920                 :             : 
    6921                 :             : /* Issue the error given by GMSGID at RICHLOC, indicating that it occurred
    6922                 :             :    before TOKEN, which had the associated VALUE.  */
    6923                 :             : 
    6924                 :             : void
    6925                 :        8756 : c_parse_error (const char *gmsgid, enum cpp_ttype token_type,
    6926                 :             :                tree value, unsigned char token_flags,
    6927                 :             :                rich_location *richloc)
    6928                 :             : {
    6929                 :             : #define catenate_messages(M1, M2) catenate_strings ((M1), (M2), sizeof (M2))
    6930                 :             : 
    6931                 :        8756 :   char *message = NULL;
    6932                 :             : 
    6933                 :        8756 :   if (token_type == CPP_EOF)
    6934                 :         472 :     message = catenate_messages (gmsgid, " at end of input");
    6935                 :        8284 :   else if (token_type == CPP_CHAR
    6936                 :             :            || token_type == CPP_WCHAR
    6937                 :             :            || token_type == CPP_CHAR16
    6938                 :             :            || token_type == CPP_CHAR32
    6939                 :        8284 :            || token_type == CPP_UTF8CHAR)
    6940                 :             :     {
    6941                 :          24 :       unsigned int val = TREE_INT_CST_LOW (value);
    6942                 :          24 :       const char *prefix;
    6943                 :             : 
    6944                 :          24 :       switch (token_type)
    6945                 :             :         {
    6946                 :             :         default:
    6947                 :             :           prefix = "";
    6948                 :             :           break;
    6949                 :           0 :         case CPP_WCHAR:
    6950                 :           0 :           prefix = "L";
    6951                 :           0 :           break;
    6952                 :           0 :         case CPP_CHAR16:
    6953                 :           0 :           prefix = "u";
    6954                 :           0 :           break;
    6955                 :           0 :         case CPP_CHAR32:
    6956                 :           0 :           prefix = "U";
    6957                 :           0 :           break;
    6958                 :           0 :         case CPP_UTF8CHAR:
    6959                 :           0 :           prefix = "u8";
    6960                 :           0 :           break;
    6961                 :             :         }
    6962                 :             : 
    6963                 :          24 :       if (val <= UCHAR_MAX && ISGRAPH (val))
    6964                 :          20 :         message = catenate_messages (gmsgid, " before %s'%c'");
    6965                 :             :       else
    6966                 :           4 :         message = catenate_messages (gmsgid, " before %s'\\x%x'");
    6967                 :             : 
    6968                 :          24 :       error_at (richloc, message, prefix, val);
    6969                 :          24 :       free (message);
    6970                 :          24 :       message = NULL;
    6971                 :             :     }
    6972                 :        8260 :   else if (token_type == CPP_CHAR_USERDEF
    6973                 :             :            || token_type == CPP_WCHAR_USERDEF
    6974                 :             :            || token_type == CPP_CHAR16_USERDEF
    6975                 :             :            || token_type == CPP_CHAR32_USERDEF
    6976                 :        8260 :            || token_type == CPP_UTF8CHAR_USERDEF)
    6977                 :          12 :     message = catenate_messages (gmsgid,
    6978                 :             :                                  " before user-defined character literal");
    6979                 :        8248 :   else if (token_type == CPP_STRING_USERDEF
    6980                 :             :            || token_type == CPP_WSTRING_USERDEF
    6981                 :             :            || token_type == CPP_STRING16_USERDEF
    6982                 :             :            || token_type == CPP_STRING32_USERDEF
    6983                 :        8248 :            || token_type == CPP_UTF8STRING_USERDEF)
    6984                 :          25 :     message = catenate_messages (gmsgid, " before user-defined string literal");
    6985                 :        8223 :   else if (token_type == CPP_STRING
    6986                 :             :            || token_type == CPP_WSTRING
    6987                 :             :            || token_type == CPP_STRING16
    6988                 :             :            || token_type == CPP_STRING32
    6989                 :        8223 :            || token_type == CPP_UTF8STRING)
    6990                 :          44 :     message = catenate_messages (gmsgid, " before string constant");
    6991                 :        8179 :   else if (token_type == CPP_NUMBER)
    6992                 :         528 :     message = catenate_messages (gmsgid, " before numeric constant");
    6993                 :        7651 :   else if (token_type == CPP_NAME)
    6994                 :             :     {
    6995                 :        2095 :       message = catenate_messages (gmsgid, " before %qE");
    6996                 :        2095 :       error_at (richloc, message, value);
    6997                 :        2095 :       free (message);
    6998                 :        2095 :       message = NULL;
    6999                 :             :     }
    7000                 :        5556 :   else if (token_type == CPP_PRAGMA)
    7001                 :          20 :     message = catenate_messages (gmsgid, " before %<#pragma%>");
    7002                 :        5536 :   else if (token_type == CPP_PRAGMA_EOL)
    7003                 :         476 :     message = catenate_messages (gmsgid, " before end of line");
    7004                 :        5060 :   else if (token_type == CPP_DECLTYPE)
    7005                 :          12 :     message = catenate_messages (gmsgid, " before %<decltype%>");
    7006                 :        5048 :   else if (token_type == CPP_EMBED)
    7007                 :           0 :     message = catenate_messages (gmsgid, " before %<#embed%>");
    7008                 :        5048 :   else if (token_type < N_TTYPES)
    7009                 :             :     {
    7010                 :        5034 :       message = catenate_messages (gmsgid, " before %qs token");
    7011                 :        5034 :       error_at (richloc, message, cpp_type2name (token_type, token_flags));
    7012                 :        5034 :       free (message);
    7013                 :        5034 :       message = NULL;
    7014                 :             :     }
    7015                 :             :   else
    7016                 :          14 :     error_at (richloc, gmsgid);
    7017                 :             : 
    7018                 :        8756 :   if (message)
    7019                 :             :     {
    7020                 :        1589 :       error_at (richloc, message);
    7021                 :        1589 :       free (message);
    7022                 :             :     }
    7023                 :             : #undef catenate_messages
    7024                 :        8756 : }
    7025                 :             : 
    7026                 :             : /* Return the gcc option code associated with the reason for a cpp
    7027                 :             :    message, or 0 if none.  */
    7028                 :             : 
    7029                 :             : static diagnostics::option_id
    7030                 :      148730 : c_option_controlling_cpp_diagnostic (enum cpp_warning_reason reason)
    7031                 :             : {
    7032                 :      148730 :   const struct cpp_reason_option_codes_t *entry;
    7033                 :             : 
    7034                 :     4270033 :   for (entry = cpp_reason_option_codes; entry->reason != CPP_W_NONE; entry++)
    7035                 :             :     {
    7036                 :     4263107 :       if (entry->reason == reason)
    7037                 :      141804 :         return entry->option_code;
    7038                 :             :     }
    7039                 :           0 :   return 0;
    7040                 :             : }
    7041                 :             : 
    7042                 :             : /* Return TRUE if the given option index corresponds to a diagnostic
    7043                 :             :    issued by libcpp.  Linear search seems fine for now.  */
    7044                 :             : bool
    7045                 :     2090440 : c_option_is_from_cpp_diagnostics (int option_index)
    7046                 :             : {
    7047                 :    49544805 :   for (auto entry = cpp_reason_option_codes; entry->reason != CPP_W_NONE;
    7048                 :             :        ++entry)
    7049                 :             :     {
    7050                 :    48770014 :       if (entry->option_code == option_index)
    7051                 :             :         return true;
    7052                 :             :     }
    7053                 :             :   return false;
    7054                 :             : }
    7055                 :             : 
    7056                 :             : /* Callback from cpp_diagnostic for PFILE to print diagnostics from the
    7057                 :             :    preprocessor.  The diagnostic is of type LEVEL, with REASON set
    7058                 :             :    to the reason code if LEVEL is represents a warning, at location
    7059                 :             :    RICHLOC unless this is after lexing and the compiler's location
    7060                 :             :    should be used instead; MSG is the translated message and AP
    7061                 :             :    the arguments.  Returns true if a diagnostic was emitted, false
    7062                 :             :    otherwise.  */
    7063                 :             : 
    7064                 :             : bool
    7065                 :      148740 : c_cpp_diagnostic (cpp_reader *pfile ATTRIBUTE_UNUSED,
    7066                 :             :                   enum cpp_diagnostic_level level,
    7067                 :             :                   enum cpp_warning_reason reason,
    7068                 :             :                   rich_location *richloc,
    7069                 :             :                   const char *msg, va_list *ap)
    7070                 :             : {
    7071                 :      148740 :   diagnostics::diagnostic_info diagnostic;
    7072                 :      148740 :   enum diagnostics::kind dlevel;
    7073                 :      148740 :   bool save_warn_system_headers = global_dc->m_warn_system_headers;
    7074                 :      148740 :   bool ret;
    7075                 :             : 
    7076                 :      148740 :   switch (level)
    7077                 :             :     {
    7078                 :          90 :     case CPP_DL_WARNING_SYSHDR:
    7079                 :          90 :       if (flag_no_output)
    7080                 :             :         return false;
    7081                 :          89 :       global_dc->m_warn_system_headers = 1;
    7082                 :             :       /* Fall through.  */
    7083                 :       26225 :     case CPP_DL_WARNING:
    7084                 :       26225 :       if (flag_no_output)
    7085                 :             :         return false;
    7086                 :             :       dlevel = diagnostics::kind::warning;
    7087                 :             :       break;
    7088                 :      117447 :     case CPP_DL_PEDWARN:
    7089                 :      117447 :       if (flag_no_output && !flag_pedantic_errors)
    7090                 :             :         return false;
    7091                 :             :       dlevel = diagnostics::kind::pedwarn;
    7092                 :             :       break;
    7093                 :             :     case CPP_DL_ERROR:
    7094                 :             :       dlevel = diagnostics::kind::error;
    7095                 :             :       break;
    7096                 :           0 :     case CPP_DL_ICE:
    7097                 :           0 :       dlevel = diagnostics::kind::ice;
    7098                 :           0 :       break;
    7099                 :         604 :     case CPP_DL_NOTE:
    7100                 :         604 :       dlevel = diagnostics::kind::note;
    7101                 :         604 :       break;
    7102                 :         360 :     case CPP_DL_FATAL:
    7103                 :         360 :       dlevel = diagnostics::kind::fatal;
    7104                 :         360 :       break;
    7105                 :           0 :     default:
    7106                 :           0 :       gcc_unreachable ();
    7107                 :             :     }
    7108                 :      148730 :   if (override_libcpp_locations)
    7109                 :         247 :     richloc->set_range (0, input_location, SHOW_RANGE_WITH_CARET);
    7110                 :      148730 :   diagnostic_set_info_translated (&diagnostic, msg, ap,
    7111                 :             :                                   richloc, dlevel);
    7112                 :      297460 :   diagnostic_set_option_id (&diagnostic,
    7113                 :             :                             c_option_controlling_cpp_diagnostic (reason));
    7114                 :      148730 :   ret = diagnostic_report_diagnostic (global_dc, &diagnostic);
    7115                 :      148370 :   if (level == CPP_DL_WARNING_SYSHDR)
    7116                 :          89 :     global_dc->m_warn_system_headers = save_warn_system_headers;
    7117                 :             :   return ret;
    7118                 :      148380 : }
    7119                 :             : 
    7120                 :             : /* Convert a character from the host to the target execution character
    7121                 :             :    set.  cpplib handles this, mostly.  */
    7122                 :             : 
    7123                 :             : HOST_WIDE_INT
    7124                 :     6562867 : c_common_to_target_charset (HOST_WIDE_INT c)
    7125                 :             : {
    7126                 :             :   /* Character constants in GCC proper are sign-extended under -fsigned-char,
    7127                 :             :      zero-extended under -fno-signed-char.  cpplib insists that characters
    7128                 :             :      and character constants are always unsigned.  Hence we must convert
    7129                 :             :      back and forth.  */
    7130                 :     6562867 :   cppchar_t uc = ((cppchar_t)c) & ((((cppchar_t)1) << CHAR_BIT)-1);
    7131                 :             : 
    7132                 :     6562867 :   uc = cpp_host_to_exec_charset (parse_in, uc);
    7133                 :             : 
    7134                 :     6562867 :   if (flag_signed_char)
    7135                 :     6562770 :     return ((HOST_WIDE_INT)uc) << (HOST_BITS_PER_WIDE_INT - CHAR_TYPE_SIZE)
    7136                 :     6562770 :                                >> (HOST_BITS_PER_WIDE_INT - CHAR_TYPE_SIZE);
    7137                 :             :   else
    7138                 :          97 :     return uc;
    7139                 :             : }
    7140                 :             : 
    7141                 :             : /* Fold an offsetof-like expression.  EXPR is a nested sequence of component
    7142                 :             :    references with an INDIRECT_REF of a constant at the bottom; much like the
    7143                 :             :    traditional rendering of offsetof as a macro.  TYPE is the desired type of
    7144                 :             :    the whole expression.  Return the folded result.  */
    7145                 :             : 
    7146                 :             : tree
    7147                 :       15092 : fold_offsetof (tree expr, tree type, enum tree_code ctx)
    7148                 :             : {
    7149                 :       15101 :   tree base, off, t;
    7150                 :       15101 :   tree_code code = TREE_CODE (expr);
    7151                 :       15101 :   switch (code)
    7152                 :             :     {
    7153                 :             :     case ERROR_MARK:
    7154                 :             :       return expr;
    7155                 :             : 
    7156                 :          12 :     case VAR_DECL:
    7157                 :          12 :       error ("cannot apply %<offsetof%> to static data member %qD", expr);
    7158                 :          12 :       return error_mark_node;
    7159                 :             : 
    7160                 :           9 :     case CALL_EXPR:
    7161                 :           9 :     case TARGET_EXPR:
    7162                 :           9 :       error ("cannot apply %<offsetof%> when %<operator[]%> is overloaded");
    7163                 :           9 :       return error_mark_node;
    7164                 :             : 
    7165                 :        6630 :     case NOP_EXPR:
    7166                 :        6630 :     case INDIRECT_REF:
    7167                 :        6630 :       if (!TREE_CONSTANT (TREE_OPERAND (expr, 0)))
    7168                 :             :         {
    7169                 :          17 :           error ("cannot apply %<offsetof%> to a non constant address");
    7170                 :          17 :           return error_mark_node;
    7171                 :             :         }
    7172                 :        6613 :       return convert (type, TREE_OPERAND (expr, 0));
    7173                 :             : 
    7174                 :        7218 :     case COMPONENT_REF:
    7175                 :        7218 :       base = fold_offsetof (TREE_OPERAND (expr, 0), type, code);
    7176                 :        7218 :       if (base == error_mark_node)
    7177                 :             :         return base;
    7178                 :             : 
    7179                 :        7215 :       t = TREE_OPERAND (expr, 1);
    7180                 :        7215 :       if (DECL_C_BIT_FIELD (t))
    7181                 :             :         {
    7182                 :           1 :           error ("attempt to take address of bit-field structure "
    7183                 :             :                  "member %qD", t);
    7184                 :           1 :           return error_mark_node;
    7185                 :             :         }
    7186                 :        7214 :       off = size_binop_loc (input_location, PLUS_EXPR, DECL_FIELD_OFFSET (t),
    7187                 :        7214 :                             size_int (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (t))
    7188                 :             :                                       / BITS_PER_UNIT));
    7189                 :        7214 :       break;
    7190                 :             : 
    7191                 :        1222 :     case ARRAY_REF:
    7192                 :        1222 :       base = fold_offsetof (TREE_OPERAND (expr, 0), type, code);
    7193                 :        1222 :       if (base == error_mark_node)
    7194                 :             :         return base;
    7195                 :             : 
    7196                 :        1219 :       t = TREE_OPERAND (expr, 1);
    7197                 :        1219 :       STRIP_ANY_LOCATION_WRAPPER (t);
    7198                 :             : 
    7199                 :             :       /* Check if the offset goes beyond the upper bound of the array.  */
    7200                 :        1219 :       if (TREE_CODE (t) == INTEGER_CST && tree_int_cst_sgn (t) >= 0)
    7201                 :             :         {
    7202                 :         956 :           tree upbound = array_ref_up_bound (expr);
    7203                 :         956 :           if (upbound != NULL_TREE
    7204                 :         844 :               && TREE_CODE (upbound) == INTEGER_CST
    7205                 :        1800 :               && !tree_int_cst_equal (upbound,
    7206                 :         844 :                                       TYPE_MAX_VALUE (TREE_TYPE (upbound))))
    7207                 :             :             {
    7208                 :         835 :               if (ctx != ARRAY_REF && ctx != COMPONENT_REF)
    7209                 :         433 :                 upbound = size_binop (PLUS_EXPR, upbound,
    7210                 :             :                                       build_int_cst (TREE_TYPE (upbound), 1));
    7211                 :         835 :               if (tree_int_cst_lt (upbound, t))
    7212                 :             :                 {
    7213                 :         244 :                   tree v;
    7214                 :             : 
    7215                 :         244 :                   for (v = TREE_OPERAND (expr, 0);
    7216                 :         420 :                        TREE_CODE (v) == COMPONENT_REF;
    7217                 :         176 :                        v = TREE_OPERAND (v, 0))
    7218                 :         280 :                     if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v, 0)))
    7219                 :             :                         == RECORD_TYPE)
    7220                 :             :                       {
    7221                 :         220 :                         tree fld_chain = DECL_CHAIN (TREE_OPERAND (v, 1));
    7222                 :         307 :                         for (; fld_chain; fld_chain = DECL_CHAIN (fld_chain))
    7223                 :         191 :                           if (TREE_CODE (fld_chain) == FIELD_DECL)
    7224                 :             :                             break;
    7225                 :             : 
    7226                 :             :                         if (fld_chain)
    7227                 :             :                           break;
    7228                 :             :                       }
    7229                 :             :                   /* Don't warn if the array might be considered a poor
    7230                 :             :                      man's flexible array member with a very permissive
    7231                 :             :                      definition thereof.  */
    7232                 :         244 :                   if (TREE_CODE (v) == ARRAY_REF
    7233                 :         172 :                       || TREE_CODE (v) == COMPONENT_REF)
    7234                 :         176 :                     warning (OPT_Warray_bounds_,
    7235                 :             :                              "index %E denotes an offset "
    7236                 :             :                              "greater than size of %qT",
    7237                 :         176 :                              t, TREE_TYPE (TREE_OPERAND (expr, 0)));
    7238                 :             :                 }
    7239                 :             :             }
    7240                 :             :         }
    7241                 :             : 
    7242                 :        1219 :       t = convert (sizetype, t);
    7243                 :        1219 :       off = size_binop (MULT_EXPR, TYPE_SIZE_UNIT (TREE_TYPE (expr)), t);
    7244                 :        1219 :       break;
    7245                 :             : 
    7246                 :           9 :     case COMPOUND_EXPR:
    7247                 :             :       /* Handle static members of volatile structs.  */
    7248                 :           9 :       t = TREE_OPERAND (expr, 1);
    7249                 :           9 :       gcc_checking_assert (VAR_P (get_base_address (t)));
    7250                 :             :       return fold_offsetof (t, type);
    7251                 :             : 
    7252                 :           0 :     default:
    7253                 :           0 :       gcc_unreachable ();
    7254                 :             :     }
    7255                 :             : 
    7256                 :        8433 :   if (!POINTER_TYPE_P (type))
    7257                 :        7564 :     return size_binop (PLUS_EXPR, base, convert (type, off));
    7258                 :         869 :   return fold_build_pointer_plus (base, off);
    7259                 :             : }
    7260                 :             : 
    7261                 :             : /* *PTYPE is an incomplete array.  Complete it with a domain based on
    7262                 :             :    INITIAL_VALUE.  If INITIAL_VALUE is not present, use 1 if DO_DEFAULT
    7263                 :             :    is true.  Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
    7264                 :             :    2 if INITIAL_VALUE was NULL, and 3 if INITIAL_VALUE was empty.  */
    7265                 :             : 
    7266                 :             : int
    7267                 :      548203 : complete_array_type (tree *ptype, tree initial_value, bool do_default)
    7268                 :             : {
    7269                 :      548203 :   tree maxindex, type, main_type, elt, unqual_elt;
    7270                 :      548203 :   int failure = 0, quals;
    7271                 :      548203 :   bool overflow_p = false;
    7272                 :             : 
    7273                 :      548203 :   maxindex = size_zero_node;
    7274                 :      548203 :   if (initial_value)
    7275                 :             :     {
    7276                 :      540762 :       STRIP_ANY_LOCATION_WRAPPER (initial_value);
    7277                 :             : 
    7278                 :      540762 :       if (TREE_CODE (initial_value) == STRING_CST)
    7279                 :             :         {
    7280                 :      436351 :           int eltsize
    7281                 :      436351 :             = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value)));
    7282                 :      436351 :           maxindex = size_int (TREE_STRING_LENGTH (initial_value) / eltsize
    7283                 :             :                                - 1);
    7284                 :             :         }
    7285                 :      104411 :       else if (TREE_CODE (initial_value) == CONSTRUCTOR)
    7286                 :             :         {
    7287                 :      103509 :           vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (initial_value);
    7288                 :             : 
    7289                 :      103509 :           if (vec_safe_is_empty (v))
    7290                 :             :             {
    7291                 :         404 :               if (pedantic)
    7292                 :          68 :                 failure = 3;
    7293                 :         404 :               maxindex = ssize_int (-1);
    7294                 :             :             }
    7295                 :             :           else
    7296                 :             :             {
    7297                 :      103105 :               tree curindex;
    7298                 :      103105 :               unsigned HOST_WIDE_INT cnt = 1;
    7299                 :      103105 :               constructor_elt *ce;
    7300                 :      103105 :               bool fold_p = false;
    7301                 :             : 
    7302                 :      103105 :               if ((*v)[0].index)
    7303                 :       90462 :                 maxindex = (*v)[0].index, fold_p = true;
    7304                 :      103105 :               if (TREE_CODE ((*v)[0].value) == RAW_DATA_CST)
    7305                 :           4 :                 cnt = 0;
    7306                 :             : 
    7307                 :             :               curindex = maxindex;
    7308                 :             : 
    7309                 :    16254154 :               for (; vec_safe_iterate (v, cnt, &ce); cnt++)
    7310                 :             :                 {
    7311                 :    16151049 :                   bool curfold_p = false;
    7312                 :    16151049 :                   if (ce->index)
    7313                 :    14909118 :                     curindex = ce->index, curfold_p = true;
    7314                 :    16151049 :                   if (!ce->index || TREE_CODE (ce->value) == RAW_DATA_CST)
    7315                 :             :                     {
    7316                 :     1242290 :                       if (fold_p || curfold_p)
    7317                 :             :                         {
    7318                 :             :                           /* Since we treat size types now as ordinary
    7319                 :             :                              unsigned types, we need an explicit overflow
    7320                 :             :                              check.  */
    7321                 :         359 :                           tree orig = curindex;
    7322                 :         359 :                           curindex = fold_convert (sizetype, curindex);
    7323                 :         359 :                           overflow_p |= tree_int_cst_lt (curindex, orig);
    7324                 :         359 :                           curfold_p = false;
    7325                 :             :                         }
    7326                 :     1242290 :                       if (TREE_CODE (ce->value) == RAW_DATA_CST)
    7327                 :         359 :                         curindex
    7328                 :         718 :                           = size_binop (PLUS_EXPR, curindex,
    7329                 :             :                                         size_int (RAW_DATA_LENGTH (ce->value)
    7330                 :             :                                                   - ((ce->index || !cnt)
    7331                 :             :                                                      ? 1 : 0)));
    7332                 :             :                       else
    7333                 :     1241931 :                         curindex = size_binop (PLUS_EXPR, curindex,
    7334                 :             :                                                size_one_node);
    7335                 :             :                     }
    7336                 :    16151049 :                   if (tree_int_cst_lt (maxindex, curindex))
    7337                 :    16151049 :                     maxindex = curindex, fold_p = curfold_p;
    7338                 :             :                 }
    7339                 :      103105 :               if (fold_p)
    7340                 :             :                 {
    7341                 :       90458 :                   tree orig = maxindex;
    7342                 :       90458 :                   maxindex = fold_convert (sizetype, maxindex);
    7343                 :       90458 :                   overflow_p |= tree_int_cst_lt (maxindex, orig);
    7344                 :             :                 }
    7345                 :             :             }
    7346                 :             :         }
    7347                 :             :       else
    7348                 :             :         {
    7349                 :             :           /* Make an error message unless that happened already.  */
    7350                 :         902 :           if (initial_value != error_mark_node)
    7351                 :          31 :             failure = 1;
    7352                 :             :         }
    7353                 :             :     }
    7354                 :             :   else
    7355                 :             :     {
    7356                 :        7441 :       failure = 2;
    7357                 :        7441 :       if (!do_default)
    7358                 :             :         return failure;
    7359                 :             :     }
    7360                 :             : 
    7361                 :      540849 :   type = *ptype;
    7362                 :      540849 :   elt = TREE_TYPE (type);
    7363                 :      540849 :   quals = TYPE_QUALS (strip_array_types (elt));
    7364                 :      540849 :   if (quals == 0)
    7365                 :             :     unqual_elt = elt;
    7366                 :             :   else
    7367                 :      509140 :     unqual_elt = c_build_qualified_type (elt, KEEP_QUAL_ADDR_SPACE (quals));
    7368                 :             : 
    7369                 :             :   /* Using build_distinct_type_copy and modifying things afterward instead
    7370                 :             :      of using build_array_type to create a new type preserves all of the
    7371                 :             :      TYPE_LANG_FLAG_? bits that the front end may have set.  */
    7372                 :      540849 :   main_type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
    7373                 :      540849 :   TREE_TYPE (main_type) = unqual_elt;
    7374                 :     1081698 :   TYPE_DOMAIN (main_type)
    7375                 :      540849 :     = build_range_type (TREE_TYPE (maxindex),
    7376                 :      540849 :                         build_int_cst (TREE_TYPE (maxindex), 0), maxindex);
    7377                 :      540849 :   TYPE_TYPELESS_STORAGE (main_type) = TYPE_TYPELESS_STORAGE (type);
    7378                 :      540849 :   layout_type (main_type);
    7379                 :             : 
    7380                 :             :   /* Set TYPE_STRUCTURAL_EQUALITY_P early.  */
    7381                 :      540849 :   if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (main_type))
    7382                 :     1081317 :       || TYPE_STRUCTURAL_EQUALITY_P (TYPE_DOMAIN (main_type)))
    7383                 :         381 :     SET_TYPE_STRUCTURAL_EQUALITY (main_type);
    7384                 :             :   else
    7385                 :      540468 :     TYPE_CANONICAL (main_type) = main_type;
    7386                 :             : 
    7387                 :             :   /* Make sure we have the canonical MAIN_TYPE. */
    7388                 :      540849 :   hashval_t hashcode = type_hash_canon_hash (main_type);
    7389                 :      540849 :   main_type = type_hash_canon (hashcode, main_type);
    7390                 :             : 
    7391                 :             :   /* Fix the canonical type.  */
    7392                 :      540849 :   if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (main_type))
    7393                 :     1081317 :       || TYPE_STRUCTURAL_EQUALITY_P (TYPE_DOMAIN (main_type)))
    7394                 :         381 :     gcc_assert (TYPE_STRUCTURAL_EQUALITY_P (main_type));
    7395                 :      540468 :   else if (TYPE_CANONICAL (TREE_TYPE (main_type)) != TREE_TYPE (main_type)
    7396                 :      540468 :            || (TYPE_CANONICAL (TYPE_DOMAIN (main_type))
    7397                 :      523656 :                != TYPE_DOMAIN (main_type)))
    7398                 :       16812 :     TYPE_CANONICAL (main_type)
    7399                 :       33624 :       = build_array_type (TYPE_CANONICAL (TREE_TYPE (main_type)),
    7400                 :       16812 :                           TYPE_CANONICAL (TYPE_DOMAIN (main_type)),
    7401                 :       16812 :                           TYPE_TYPELESS_STORAGE (main_type));
    7402                 :             : 
    7403                 :      540849 :   if (quals == 0)
    7404                 :             :     type = main_type;
    7405                 :             :   else
    7406                 :      509140 :     type = c_build_qualified_type (main_type, quals);
    7407                 :             : 
    7408                 :      540849 :   if (COMPLETE_TYPE_P (type)
    7409                 :      540840 :       && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST
    7410                 :     1081683 :       && (overflow_p || TREE_OVERFLOW (TYPE_SIZE_UNIT (type))))
    7411                 :             :     {
    7412                 :           4 :       error ("size of array is too large");
    7413                 :             :       /* If we proceed with the array type as it is, we'll eventually
    7414                 :             :          crash in tree_to_[su]hwi().  */
    7415                 :           4 :       type = error_mark_node;
    7416                 :             :     }
    7417                 :             : 
    7418                 :      540849 :   *ptype = type;
    7419                 :      540849 :   return failure;
    7420                 :             : }
    7421                 :             : 
    7422                 :             : /* INIT is an constructor of a structure with a flexible array member.
    7423                 :             :    Complete the flexible array member with a domain based on it's value.  */
    7424                 :             : void
    7425                 :     8748631 : complete_flexible_array_elts (tree init)
    7426                 :             : {
    7427                 :     8853750 :   tree elt, type;
    7428                 :             : 
    7429                 :     8853750 :   if (init == NULL_TREE || TREE_CODE (init) != CONSTRUCTOR)
    7430                 :             :     return;
    7431                 :             : 
    7432                 :      106629 :   if (vec_safe_is_empty (CONSTRUCTOR_ELTS (init)))
    7433                 :             :     return;
    7434                 :             : 
    7435                 :      105372 :   elt = CONSTRUCTOR_ELTS (init)->last ().value;
    7436                 :      105372 :   type = TREE_TYPE (elt);
    7437                 :      105372 :   if (TREE_CODE (type) == ARRAY_TYPE
    7438                 :      105372 :       && TYPE_SIZE (type) == NULL_TREE)
    7439                 :         253 :     complete_array_type (&TREE_TYPE (elt), elt, false);
    7440                 :             :   else
    7441                 :             :     complete_flexible_array_elts (elt);
    7442                 :             : }
    7443                 :             : 
    7444                 :             : /* Like c_mark_addressable but don't check register qualifier.  */
    7445                 :             : void
    7446                 :     1097908 : c_common_mark_addressable_vec (tree t)
    7447                 :             : {
    7448                 :     1271022 :   while (handled_component_p (t) || TREE_CODE (t) == C_MAYBE_CONST_EXPR)
    7449                 :             :     {
    7450                 :      173114 :       if (TREE_CODE (t) == C_MAYBE_CONST_EXPR)
    7451                 :          26 :         t = C_MAYBE_CONST_EXPR_EXPR (t);
    7452                 :             :       else
    7453                 :      173088 :         t = TREE_OPERAND (t, 0);
    7454                 :             :     }
    7455                 :     1097908 :   if (!VAR_P (t)
    7456                 :             :       && TREE_CODE (t) != PARM_DECL
    7457                 :             :       && TREE_CODE (t) != COMPOUND_LITERAL_EXPR
    7458                 :             :       && TREE_CODE (t) != TARGET_EXPR)
    7459                 :             :     return;
    7460                 :     1078625 :   if (!VAR_P (t) || !DECL_HARD_REGISTER (t))
    7461                 :     1078556 :     TREE_ADDRESSABLE (t) = 1;
    7462                 :     1078625 :   if (TREE_CODE (t) == COMPOUND_LITERAL_EXPR)
    7463                 :         126 :     TREE_ADDRESSABLE (COMPOUND_LITERAL_EXPR_DECL (t)) = 1;
    7464                 :     1078499 :   else if (TREE_CODE (t) == TARGET_EXPR)
    7465                 :          28 :     TREE_ADDRESSABLE (TARGET_EXPR_SLOT (t)) = 1;
    7466                 :             : }
    7467                 :             : 
    7468                 :             : 
    7469                 :             : 
    7470                 :             : /* Used to help initialize the builtin-types.def table.  When a type of
    7471                 :             :    the correct size doesn't exist, use error_mark_node instead of NULL.
    7472                 :             :    The later results in segfaults even when a decl using the type doesn't
    7473                 :             :    get invoked.  */
    7474                 :             : 
    7475                 :             : tree
    7476                 :     1111920 : builtin_type_for_size (int size, bool unsignedp)
    7477                 :             : {
    7478                 :     1111920 :   tree type = c_common_type_for_size (size, unsignedp);
    7479                 :     1111920 :   return type ? type : error_mark_node;
    7480                 :             : }
    7481                 :             : 
    7482                 :             : /* Work out the size of the first argument of a call to
    7483                 :             :    __builtin_speculation_safe_value.  Only pointers and integral types
    7484                 :             :    are permitted.  Return -1 if the argument type is not supported or
    7485                 :             :    the size is too large; 0 if the argument type is a pointer or the
    7486                 :             :    size if it is integral.  */
    7487                 :             : static enum built_in_function
    7488                 :         154 : speculation_safe_value_resolve_call (tree function, vec<tree, va_gc> *params,
    7489                 :             :                                      bool complain)
    7490                 :             : {
    7491                 :             :   /* Type of the argument.  */
    7492                 :         154 :   tree type;
    7493                 :         154 :   int size;
    7494                 :             : 
    7495                 :         154 :   if (vec_safe_is_empty (params))
    7496                 :             :     {
    7497                 :          10 :       if (complain)
    7498                 :          10 :         error ("too few arguments to function %qE", function);
    7499                 :          10 :       return BUILT_IN_NONE;
    7500                 :             :     }
    7501                 :             : 
    7502                 :         144 :   type = TREE_TYPE ((*params)[0]);
    7503                 :         144 :   if (TREE_CODE (type) == ARRAY_TYPE && c_dialect_cxx ())
    7504                 :             :     {
    7505                 :             :       /* Force array-to-pointer decay for C++.   */
    7506                 :           0 :       (*params)[0] = default_conversion ((*params)[0]);
    7507                 :           0 :       type = TREE_TYPE ((*params)[0]);
    7508                 :             :     }
    7509                 :             : 
    7510                 :         144 :   if (POINTER_TYPE_P (type))
    7511                 :             :     return BUILT_IN_SPECULATION_SAFE_VALUE_PTR;
    7512                 :             : 
    7513                 :         128 :   if (!INTEGRAL_TYPE_P (type))
    7514                 :          42 :     goto incompatible;
    7515                 :             : 
    7516                 :          86 :   if (!COMPLETE_TYPE_P (type))
    7517                 :           0 :     goto incompatible;
    7518                 :             : 
    7519                 :          86 :   size = tree_to_uhwi (TYPE_SIZE_UNIT (type));
    7520                 :          86 :   if (size == 1 || size == 2 || size == 4 || size == 8 || size == 16)
    7521                 :          86 :     return ((enum built_in_function)
    7522                 :         172 :             ((int) BUILT_IN_SPECULATION_SAFE_VALUE_1 + exact_log2 (size)));
    7523                 :             : 
    7524                 :           0 :  incompatible:
    7525                 :             :   /* Issue the diagnostic only if the argument is valid, otherwise
    7526                 :             :      it would be redundant at best and could be misleading.  */
    7527                 :          42 :   if (type != error_mark_node && complain)
    7528                 :           6 :     error ("operand type %qT is incompatible with argument %d of %qE",
    7529                 :             :            type, 1, function);
    7530                 :             : 
    7531                 :             :   return BUILT_IN_NONE;
    7532                 :             : }
    7533                 :             : 
    7534                 :             : /* Validate and coerce PARAMS, the arguments to ORIG_FUNCTION to fit
    7535                 :             :    the prototype for FUNCTION.  The first argument is mandatory, a second
    7536                 :             :    argument, if present, must be type compatible with the first.  */
    7537                 :             : static bool
    7538                 :         102 : speculation_safe_value_resolve_params (location_t loc, tree orig_function,
    7539                 :             :                                        vec<tree, va_gc> *params, bool complain)
    7540                 :             : {
    7541                 :         102 :   tree val;
    7542                 :             : 
    7543                 :         102 :   if (params->length () == 0)
    7544                 :             :     {
    7545                 :           0 :       if (complain)
    7546                 :           0 :         error_at (loc, "too few arguments to function %qE", orig_function);
    7547                 :           0 :       return false;
    7548                 :             :     }
    7549                 :             : 
    7550                 :         102 :   else if (params->length () > 2)
    7551                 :             :     {
    7552                 :          21 :       if (complain)
    7553                 :           0 :         error_at (loc, "too many arguments to function %qE", orig_function);
    7554                 :          21 :       return false;
    7555                 :             :     }
    7556                 :             : 
    7557                 :          81 :   val = (*params)[0];
    7558                 :          81 :   if (TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE)
    7559                 :           0 :     val = default_conversion (val);
    7560                 :          81 :   if (!(TREE_CODE (TREE_TYPE (val)) == POINTER_TYPE
    7561                 :          65 :         || TREE_CODE (TREE_TYPE (val)) == INTEGER_TYPE))
    7562                 :             :     {
    7563                 :           0 :       if (complain)
    7564                 :           0 :         error_at (loc, "expecting argument of type pointer or of type integer "
    7565                 :             :                        "for argument 1");
    7566                 :           0 :       return false;
    7567                 :             :     }
    7568                 :          81 :   (*params)[0] = val;
    7569                 :             : 
    7570                 :          81 :   if (params->length () == 2)
    7571                 :             :     {
    7572                 :          32 :       tree val2 = (*params)[1];
    7573                 :          32 :       if (TREE_CODE (TREE_TYPE (val2)) == ARRAY_TYPE)
    7574                 :           0 :         val2 = default_conversion (val2);
    7575                 :          32 :       if (error_operand_p (val2))
    7576                 :             :         return false;
    7577                 :          40 :       if (!(TREE_TYPE (val) == TREE_TYPE (val2)
    7578                 :           9 :             || useless_type_conversion_p (TREE_TYPE (val), TREE_TYPE (val2))))
    7579                 :             :         {
    7580                 :           9 :           if (complain)
    7581                 :           0 :             error_at (loc, "both arguments must be compatible");
    7582                 :           9 :           return false;
    7583                 :             :         }
    7584                 :          22 :       (*params)[1] = val2;
    7585                 :             :     }
    7586                 :             : 
    7587                 :             :   return true;
    7588                 :             : }
    7589                 :             : 
    7590                 :             : /* Cast the result of the builtin back to the type of the first argument,
    7591                 :             :    preserving any qualifiers that it might have.  */
    7592                 :             : static tree
    7593                 :          71 : speculation_safe_value_resolve_return (tree first_param, tree result)
    7594                 :             : {
    7595                 :          71 :   tree ptype = TREE_TYPE (first_param);
    7596                 :          71 :   tree rtype = TREE_TYPE (result);
    7597                 :          71 :   ptype = TYPE_MAIN_VARIANT (ptype);
    7598                 :             : 
    7599                 :          71 :   if (tree_int_cst_equal (TYPE_SIZE (ptype), TYPE_SIZE (rtype)))
    7600                 :          71 :     return convert (ptype, result);
    7601                 :             : 
    7602                 :             :   return result;
    7603                 :             : }
    7604                 :             : 
    7605                 :             : /* A helper function for resolve_overloaded_builtin in resolving the
    7606                 :             :    overloaded __sync_ builtins.  Returns a positive power of 2 if the
    7607                 :             :    first operand of PARAMS is a pointer to a supported data type.
    7608                 :             :    Returns 0 if an error is encountered.  Return -1 for _BitInt
    7609                 :             :    __atomic*fetch* with unsupported type which should be handled by
    7610                 :             :    a cas loop.
    7611                 :             :    FETCH is true when FUNCTION is one of the _FETCH_OP_ or _OP_FETCH_
    7612                 :             :    built-ins.  ORIG_FORMAT is for __sync_* rather than __atomic_*
    7613                 :             :    built-ins.  */
    7614                 :             : 
    7615                 :             : static int
    7616                 :      325491 : sync_resolve_size (tree function, vec<tree, va_gc> *params, bool fetch,
    7617                 :             :                    bool orig_format, bool complain)
    7618                 :             : {
    7619                 :             :   /* Type of the argument.  */
    7620                 :      325491 :   tree argtype;
    7621                 :             :   /* Type the argument points to.  */
    7622                 :      325491 :   tree type;
    7623                 :      325491 :   int size;
    7624                 :             : 
    7625                 :      325491 :   if (vec_safe_is_empty (params))
    7626                 :             :     {
    7627                 :         106 :       if (complain)
    7628                 :         106 :         error ("too few arguments to function %qE", function);
    7629                 :         106 :       return 0;
    7630                 :             :     }
    7631                 :             : 
    7632                 :      325385 :   argtype = type = TREE_TYPE ((*params)[0]);
    7633                 :      325385 :   if (TREE_CODE (type) == ARRAY_TYPE && c_dialect_cxx ())
    7634                 :             :     {
    7635                 :             :       /* Force array-to-pointer decay for C++.  */
    7636                 :           3 :       (*params)[0] = default_conversion ((*params)[0]);
    7637                 :           3 :       type = TREE_TYPE ((*params)[0]);
    7638                 :             :     }
    7639                 :      325385 :   if (TREE_CODE (type) != POINTER_TYPE)
    7640                 :        2127 :     goto incompatible;
    7641                 :             : 
    7642                 :      323258 :   type = TREE_TYPE (type);
    7643                 :      323258 :   if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type))
    7644                 :         288 :     goto incompatible;
    7645                 :             : 
    7646                 :      322970 :   if (!COMPLETE_TYPE_P (type))
    7647                 :           2 :     goto incompatible;
    7648                 :             : 
    7649                 :      322968 :   if (fetch && TREE_CODE (type) == BOOLEAN_TYPE)
    7650                 :          84 :     goto incompatible;
    7651                 :             : 
    7652                 :      322884 :   size = tree_to_uhwi (TYPE_SIZE_UNIT (type));
    7653                 :      322884 :   if (size == 16
    7654                 :        7675 :       && TREE_CODE (type) == BITINT_TYPE
    7655                 :      323410 :       && !targetm.scalar_mode_supported_p (TImode))
    7656                 :             :     {
    7657                 :           0 :       if (fetch && !orig_format)
    7658                 :             :         return -1;
    7659                 :           0 :       goto incompatible;
    7660                 :             :     }
    7661                 :             : 
    7662                 :      322884 :   if (size == 1 || size == 2 || size == 4 || size == 8 || size == 16)
    7663                 :             :     return size;
    7664                 :             : 
    7665                 :         528 :   if (fetch && !orig_format && TREE_CODE (type) == BITINT_TYPE)
    7666                 :             :     return -1;
    7667                 :             : 
    7668                 :           0 :  incompatible:
    7669                 :             :   /* Issue the diagnostic only if the argument is valid, otherwise
    7670                 :             :      it would be redundant at best and could be misleading.  */
    7671                 :        2501 :   if (argtype != error_mark_node && complain)
    7672                 :         920 :     error ("operand type %qT is incompatible with argument %d of %qE",
    7673                 :             :            argtype, 1, function);
    7674                 :             :   return 0;
    7675                 :             : }
    7676                 :             : 
    7677                 :             : /* A helper function for resolve_overloaded_builtin.  Adds casts to
    7678                 :             :    PARAMS to make arguments match up with those of FUNCTION.  Drops
    7679                 :             :    the variadic arguments at the end.  Returns false if some error
    7680                 :             :    was encountered; true on success.  */
    7681                 :             : 
    7682                 :             : static bool
    7683                 :      322356 : sync_resolve_params (location_t loc, tree orig_function, tree function,
    7684                 :             :                      vec<tree, va_gc> *params, bool orig_format, bool complain)
    7685                 :             : {
    7686                 :      322356 :   function_args_iterator iter;
    7687                 :      322356 :   tree ptype;
    7688                 :      322356 :   unsigned int parmnum;
    7689                 :             : 
    7690                 :      322356 :   function_args_iter_init (&iter, TREE_TYPE (function));
    7691                 :             :   /* We've declared the implementation functions to use "volatile void *"
    7692                 :             :      as the pointer parameter, so we shouldn't get any complaints from the
    7693                 :             :      call to check_function_arguments what ever type the user used.  */
    7694                 :      322356 :   function_args_iter_next (&iter);
    7695                 :      322356 :   ptype = TREE_TYPE (TREE_TYPE ((*params)[0]));
    7696                 :      322356 :   ptype = TYPE_MAIN_VARIANT (ptype);
    7697                 :             : 
    7698                 :             :   /* For the rest of the values, we need to cast these to FTYPE, so that we
    7699                 :             :      don't get warnings for passing pointer types, etc.  */
    7700                 :      322356 :   parmnum = 0;
    7701                 :     1808082 :   while (1)
    7702                 :             :     {
    7703                 :     1065219 :       tree val, arg_type;
    7704                 :             : 
    7705                 :     1065219 :       arg_type = function_args_iter_cond (&iter);
    7706                 :             :       /* XXX void_type_node belies the abstraction.  */
    7707                 :     1065219 :       if (arg_type == void_type_node)
    7708                 :             :         break;
    7709                 :             : 
    7710                 :      742921 :       ++parmnum;
    7711                 :      742921 :       if (params->length () <= parmnum)
    7712                 :             :         {
    7713                 :          58 :           if (complain)
    7714                 :           7 :             error_at (loc, "too few arguments to function %qE", orig_function);
    7715                 :          58 :           return false;
    7716                 :             :         }
    7717                 :             : 
    7718                 :             :       /* Only convert parameters if arg_type is unsigned integer type with
    7719                 :             :          new format sync routines, i.e. don't attempt to convert pointer
    7720                 :             :          arguments (e.g. EXPECTED argument of __atomic_compare_exchange_n),
    7721                 :             :          bool arguments (e.g. WEAK argument) or signed int arguments (memmodel
    7722                 :             :          kinds).  */
    7723                 :      742863 :       if (TREE_CODE (arg_type) == INTEGER_TYPE && TYPE_UNSIGNED (arg_type))
    7724                 :             :         {
    7725                 :             :           /* Ideally for the first conversion we'd use convert_for_assignment
    7726                 :             :              so that we get warnings for anything that doesn't match the pointer
    7727                 :             :              type.  This isn't portable across the C and C++ front ends atm.  */
    7728                 :      206407 :           val = (*params)[parmnum];
    7729                 :      206407 :           val = convert (ptype, val);
    7730                 :      206407 :           val = convert (arg_type, val);
    7731                 :      206407 :           (*params)[parmnum] = val;
    7732                 :             :         }
    7733                 :             : 
    7734                 :      742863 :       function_args_iter_next (&iter);
    7735                 :      742863 :     }
    7736                 :             : 
    7737                 :             :   /* __atomic routines are not variadic.  */
    7738                 :      322298 :   if (!orig_format && params->length () != parmnum + 1)
    7739                 :             :     {
    7740                 :         106 :       if (complain)
    7741                 :         103 :         error_at (loc, "too many arguments to function %qE", orig_function);
    7742                 :         106 :       return false;
    7743                 :             :     }
    7744                 :             : 
    7745                 :             :   /* The definition of these primitives is variadic, with the remaining
    7746                 :             :      being "an optional list of variables protected by the memory barrier".
    7747                 :             :      No clue what that's supposed to mean, precisely, but we consider all
    7748                 :             :      call-clobbered variables to be protected so we're safe.  */
    7749                 :      322192 :   params->truncate (parmnum + 1);
    7750                 :             : 
    7751                 :      322192 :   return true;
    7752                 :             : }
    7753                 :             : 
    7754                 :             : /* A helper function for resolve_overloaded_builtin.  Adds a cast to
    7755                 :             :    RESULT to make it match the type of the first pointer argument in
    7756                 :             :    PARAMS.  */
    7757                 :             : 
    7758                 :             : static tree
    7759                 :      213343 : sync_resolve_return (tree first_param, tree result, bool orig_format)
    7760                 :             : {
    7761                 :      213343 :   tree ptype = TREE_TYPE (TREE_TYPE (first_param));
    7762                 :      213343 :   tree rtype = TREE_TYPE (result);
    7763                 :      213343 :   ptype = TYPE_MAIN_VARIANT (ptype);
    7764                 :             : 
    7765                 :             :   /* New format doesn't require casting unless the types are the same size.  */
    7766                 :      213343 :   if (orig_format || tree_int_cst_equal (TYPE_SIZE (ptype), TYPE_SIZE (rtype)))
    7767                 :      213343 :     return convert (ptype, result);
    7768                 :             :   else
    7769                 :             :     return result;
    7770                 :             : }
    7771                 :             : 
    7772                 :             : /* This function verifies the PARAMS to generic atomic FUNCTION.
    7773                 :             :    It returns the size if all the parameters are the same size, otherwise
    7774                 :             :    0 is returned if the parameters are invalid.  */
    7775                 :             : 
    7776                 :             : static int
    7777                 :       83110 : get_atomic_generic_size (location_t loc, tree function,
    7778                 :             :                          vec<tree, va_gc> *params, bool complain)
    7779                 :             : {
    7780                 :       83110 :   unsigned int n_param;
    7781                 :       83110 :   unsigned int n_model;
    7782                 :       83110 :   unsigned int outputs = 0; // bitset of output parameters
    7783                 :       83110 :   unsigned int x;
    7784                 :       83110 :   int size_0;
    7785                 :       83110 :   tree type_0;
    7786                 :             : 
    7787                 :             :   /* Determine the parameter makeup.  */
    7788                 :       83110 :   switch (DECL_FUNCTION_CODE (function))
    7789                 :             :     {
    7790                 :             :     case BUILT_IN_ATOMIC_EXCHANGE:
    7791                 :             :       n_param = 4;
    7792                 :             :       n_model = 1;
    7793                 :             :       outputs = 5;
    7794                 :             :       break;
    7795                 :       50003 :     case BUILT_IN_ATOMIC_LOAD:
    7796                 :       50003 :       n_param = 3;
    7797                 :       50003 :       n_model = 1;
    7798                 :       50003 :       outputs = 2;
    7799                 :       50003 :       break;
    7800                 :       11487 :     case BUILT_IN_ATOMIC_STORE:
    7801                 :       11487 :       n_param = 3;
    7802                 :       11487 :       n_model = 1;
    7803                 :       11487 :       outputs = 1;
    7804                 :       11487 :       break;
    7805                 :       20988 :     case BUILT_IN_ATOMIC_COMPARE_EXCHANGE:
    7806                 :       20988 :       n_param = 6;
    7807                 :       20988 :       n_model = 2;
    7808                 :       20988 :       outputs = 3;
    7809                 :       20988 :       break;
    7810                 :           0 :     default:
    7811                 :           0 :       gcc_unreachable ();
    7812                 :             :     }
    7813                 :             : 
    7814                 :       83110 :   if (vec_safe_length (params) != n_param)
    7815                 :             :     {
    7816                 :         466 :       if (complain)
    7817                 :         247 :         error_at (loc, "incorrect number of arguments to function %qE",
    7818                 :             :                   function);
    7819                 :         466 :       return 0;
    7820                 :             :     }
    7821                 :             : 
    7822                 :             :   /* Get type of first parameter, and determine its size.  */
    7823                 :       82644 :   type_0 = TREE_TYPE ((*params)[0]);
    7824                 :       82644 :   if (TREE_CODE (type_0) == ARRAY_TYPE && c_dialect_cxx ())
    7825                 :             :     {
    7826                 :             :       /* Force array-to-pointer decay for C++.  */
    7827                 :          15 :       (*params)[0] = default_conversion ((*params)[0]);
    7828                 :          15 :       type_0 = TREE_TYPE ((*params)[0]);
    7829                 :             :     }
    7830                 :       82644 :   if (TREE_CODE (type_0) != POINTER_TYPE || VOID_TYPE_P (TREE_TYPE (type_0)))
    7831                 :             :     {
    7832                 :         152 :       if (complain)
    7833                 :          41 :         error_at (loc, "argument 1 of %qE must be a non-void pointer type",
    7834                 :             :                   function);
    7835                 :         152 :       return 0;
    7836                 :             :     }
    7837                 :             : 
    7838                 :       82492 :   if (!COMPLETE_TYPE_P (TREE_TYPE (type_0)))
    7839                 :             :     {
    7840                 :          23 :       if (complain)
    7841                 :           8 :         error_at (loc, "argument 1 of %qE must be a pointer to a complete type",
    7842                 :             :                   function);
    7843                 :          23 :       return 0;
    7844                 :             :     }
    7845                 :             : 
    7846                 :             :   /* Types must be compile time constant sizes. */
    7847                 :       82469 :   if (!tree_fits_uhwi_p ((TYPE_SIZE_UNIT (TREE_TYPE (type_0)))))
    7848                 :             :     {
    7849                 :           1 :       if (complain)
    7850                 :           1 :         error_at (loc,
    7851                 :             :                   "argument 1 of %qE must be a pointer to a constant size type",
    7852                 :             :                   function);
    7853                 :           1 :       return 0;
    7854                 :             :     }
    7855                 :             : 
    7856                 :       82468 :   size_0 = tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type_0)));
    7857                 :             : 
    7858                 :             :   /* Zero size objects are not allowed.  */
    7859                 :       82468 :   if (size_0 == 0)
    7860                 :             :     {
    7861                 :          22 :       if (complain)
    7862                 :           7 :         error_at (
    7863                 :             :           loc, "argument 1 of %qE must be a pointer to a nonzero size object",
    7864                 :             :           function);
    7865                 :          22 :       return 0;
    7866                 :             :     }
    7867                 :             : 
    7868                 :             :   /* Check each other parameter is a pointer and the same size.  */
    7869                 :      289259 :   for (x = 0; x < n_param - n_model; x++)
    7870                 :             :     {
    7871                 :      206952 :       int size;
    7872                 :      206952 :       tree type = TREE_TYPE ((*params)[x]);
    7873                 :             :       /* __atomic_compare_exchange has a bool in the 4th position, skip it.  */
    7874                 :      206952 :       if (n_param == 6 && x == 3)
    7875                 :       20810 :         continue;
    7876                 :      186142 :       if (TREE_CODE (type) == ARRAY_TYPE && c_dialect_cxx ())
    7877                 :             :         {
    7878                 :             :           /* Force array-to-pointer decay for C++.  */
    7879                 :          18 :           (*params)[x] = default_conversion ((*params)[x]);
    7880                 :          18 :           type = TREE_TYPE ((*params)[x]);
    7881                 :             :         }
    7882                 :      186142 :       if (!POINTER_TYPE_P (type))
    7883                 :             :         {
    7884                 :          16 :           if (complain)
    7885                 :          13 :             error_at (loc, "argument %d of %qE must be a pointer type", x + 1,
    7886                 :             :                       function);
    7887                 :          16 :           return 0;
    7888                 :             :         }
    7889                 :      186126 :       else if (TYPE_SIZE_UNIT (TREE_TYPE (type))
    7890                 :      186126 :                && TREE_CODE ((TYPE_SIZE_UNIT (TREE_TYPE (type))))
    7891                 :             :                   != INTEGER_CST)
    7892                 :             :         {
    7893                 :           1 :           if (complain)
    7894                 :           1 :             error_at (loc,
    7895                 :             :                       "argument %d of %qE must be a pointer to a constant "
    7896                 :             :                       "size type",
    7897                 :             :                       x + 1, function);
    7898                 :           1 :           return 0;
    7899                 :             :         }
    7900                 :      186125 :       else if (FUNCTION_POINTER_TYPE_P (type))
    7901                 :             :         {
    7902                 :          10 :           if (complain)
    7903                 :           7 :             error_at (loc,
    7904                 :             :                       "argument %d of %qE must not be a pointer to a "
    7905                 :             :                       "function",
    7906                 :             :                       x + 1, function);
    7907                 :          10 :           return 0;
    7908                 :             :         }
    7909                 :      186115 :       tree type_size = TYPE_SIZE_UNIT (TREE_TYPE (type));
    7910                 :      186115 :       size = type_size ? tree_to_uhwi (type_size) : 0;
    7911                 :      186115 :       if (size != size_0)
    7912                 :             :         {
    7913                 :          34 :           if (complain)
    7914                 :          25 :             error_at (loc, "size mismatch in argument %d of %qE", x + 1,
    7915                 :             :                       function);
    7916                 :          34 :           return 0;
    7917                 :             :         }
    7918                 :             : 
    7919                 :      186081 :       {
    7920                 :      186081 :         auto_diagnostic_group d;
    7921                 :      186081 :         int quals = TYPE_QUALS (TREE_TYPE (type));
    7922                 :             :         /* Must not write to an argument of a const-qualified type.  */
    7923                 :      186081 :         if (outputs & (1 << x) && quals & TYPE_QUAL_CONST)
    7924                 :             :           {
    7925                 :          57 :             if (c_dialect_cxx ())
    7926                 :             :               {
    7927                 :          45 :                 if (complain)
    7928                 :          42 :                   error_at (loc,
    7929                 :             :                             "argument %d of %qE must not be a pointer to "
    7930                 :             :                             "a %<const%> type",
    7931                 :             :                             x + 1, function);
    7932                 :          45 :                 return 0;
    7933                 :             :               }
    7934                 :             :             else
    7935                 :          12 :               pedwarn (loc, OPT_Wdiscarded_qualifiers, "argument %d "
    7936                 :             :                        "of %qE discards %<const%> qualifier", x + 1,
    7937                 :             :                        function);
    7938                 :             :           }
    7939                 :             :         /* Only the first argument is allowed to be volatile.  */
    7940                 :      186036 :         if (x > 0 && quals & TYPE_QUAL_VOLATILE)
    7941                 :             :           {
    7942                 :          44 :             if (c_dialect_cxx ())
    7943                 :             :               {
    7944                 :          33 :                 if (complain)
    7945                 :          30 :                   error_at (loc,
    7946                 :             :                             "argument %d of %qE must not be a pointer to "
    7947                 :             :                             "a %<volatile%> type",
    7948                 :             :                             x + 1, function);
    7949                 :          33 :                 return 0;
    7950                 :             :               }
    7951                 :             :             else
    7952                 :          11 :               pedwarn (loc, OPT_Wdiscarded_qualifiers, "argument %d "
    7953                 :             :                        "of %qE discards %<volatile%> qualifier", x + 1,
    7954                 :             :                        function);
    7955                 :             :           }
    7956                 :      186081 :       }
    7957                 :             :     }
    7958                 :             : 
    7959                 :             :   /* Check memory model parameters for validity.  */
    7960                 :      185408 :   for (x = n_param - n_model ; x < n_param; x++)
    7961                 :             :     {
    7962                 :      103117 :       tree p = (*params)[x];
    7963                 :      103117 :       if (!INTEGRAL_TYPE_P (TREE_TYPE (p)))
    7964                 :             :         {
    7965                 :          10 :           if (complain)
    7966                 :           7 :             error_at (loc, "non-integer memory model argument %d of %qE", x + 1,
    7967                 :             :                       function);
    7968                 :          10 :           return 0;
    7969                 :             :         }
    7970                 :      103107 :       p = fold_for_warn (p);
    7971                 :      103107 :       if (TREE_CODE (p) == INTEGER_CST)
    7972                 :             :         {
    7973                 :             :           /* memmodel_base masks the low 16 bits, thus ignore any bits above
    7974                 :             :              it by using TREE_INT_CST_LOW instead of tree_to_*hwi.  Those high
    7975                 :             :              bits will be checked later during expansion in target specific
    7976                 :             :              way.  */
    7977                 :       79318 :           if (memmodel_base (TREE_INT_CST_LOW (p)) >= MEMMODEL_LAST)
    7978                 :             :             {
    7979                 :          20 :               if (complain)
    7980                 :          14 :                 warning_at (loc, OPT_Winvalid_memory_model,
    7981                 :             :                             "invalid memory model argument %d of %qE", x + 1,
    7982                 :             :                             function);
    7983                 :             :               else
    7984                 :             :                 return 0;
    7985                 :             :             }
    7986                 :             :         }
    7987                 :             :     }
    7988                 :             : 
    7989                 :             :   return size_0;
    7990                 :             : }
    7991                 :             : 
    7992                 :             : 
    7993                 :             : /* This will take an __atomic_ generic FUNCTION call, and add a size parameter N
    7994                 :             :    at the beginning of the parameter list PARAMS representing the size of the
    7995                 :             :    objects.  This is to match the library ABI requirement.  LOC is the location
    7996                 :             :    of the function call.
    7997                 :             :    The new function is returned if it needed rebuilding, otherwise NULL_TREE is
    7998                 :             :    returned to allow the external call to be constructed.  */
    7999                 :             : 
    8000                 :             : static tree
    8001                 :        4146 : add_atomic_size_parameter (unsigned n, location_t loc, tree function,
    8002                 :             :                            vec<tree, va_gc> *params)
    8003                 :             : {
    8004                 :        4146 :   tree size_node;
    8005                 :             : 
    8006                 :             :   /* Insert a SIZE_T parameter as the first param.  If there isn't
    8007                 :             :      enough space, allocate a new vector and recursively re-build with that.  */
    8008                 :        4146 :   if (!params->space (1))
    8009                 :             :     {
    8010                 :          33 :       unsigned int z, len;
    8011                 :          33 :       vec<tree, va_gc> *v;
    8012                 :          33 :       tree f;
    8013                 :             : 
    8014                 :          33 :       len = params->length ();
    8015                 :          33 :       vec_alloc (v, len + 1);
    8016                 :          33 :       v->quick_push (build_int_cst (size_type_node, n));
    8017                 :         165 :       for (z = 0; z < len; z++)
    8018                 :         132 :         v->quick_push ((*params)[z]);
    8019                 :          33 :       f = build_function_call_vec (loc, vNULL, function, v, NULL);
    8020                 :          33 :       vec_free (v);
    8021                 :          33 :       return f;
    8022                 :             :     }
    8023                 :             : 
    8024                 :             :   /* Add the size parameter and leave as a function call for processing.  */
    8025                 :        4113 :   size_node = build_int_cst (size_type_node, n);
    8026                 :        4113 :   params->quick_insert (0, size_node);
    8027                 :        4113 :   return NULL_TREE;
    8028                 :             : }
    8029                 :             : 
    8030                 :             : 
    8031                 :             : /* Return whether atomic operations for naturally aligned N-byte
    8032                 :             :    arguments are supported, whether inline or through libatomic.  */
    8033                 :             : static bool
    8034                 :       82291 : atomic_size_supported_p (int n)
    8035                 :             : {
    8036                 :       82291 :   switch (n)
    8037                 :             :     {
    8038                 :             :     case 1:
    8039                 :             :     case 2:
    8040                 :             :     case 4:
    8041                 :             :     case 8:
    8042                 :             :       return true;
    8043                 :             : 
    8044                 :        6968 :     case 16:
    8045                 :        6968 :       return targetm.scalar_mode_supported_p (TImode);
    8046                 :             : 
    8047                 :        4146 :     default:
    8048                 :        4146 :       return false;
    8049                 :             :     }
    8050                 :             : }
    8051                 :             : 
    8052                 :             : /* This will process an __atomic_exchange function call, determine whether it
    8053                 :             :    needs to be mapped to the _N variation, or turned into a library call.
    8054                 :             :    LOC is the location of the builtin call.
    8055                 :             :    FUNCTION is the DECL that has been invoked;
    8056                 :             :    PARAMS is the argument list for the call.  The return value is non-null
    8057                 :             :    TRUE is returned if it is translated into the proper format for a call to the
    8058                 :             :    external library, and NEW_RETURN is set the tree for that function.
    8059                 :             :    FALSE is returned if processing for the _N variation is required, and
    8060                 :             :    NEW_RETURN is set to the return value the result is copied into.  */
    8061                 :             : static bool
    8062                 :         632 : resolve_overloaded_atomic_exchange (location_t loc, tree function,
    8063                 :             :                                     vec<tree, va_gc> *params, tree *new_return,
    8064                 :             :                                     bool complain)
    8065                 :             : {
    8066                 :         632 :   tree p0, p1, p2, p3;
    8067                 :         632 :   tree I_type, I_type_ptr;
    8068                 :         632 :   int n = get_atomic_generic_size (loc, function, params, complain);
    8069                 :             : 
    8070                 :             :   /* Size of 0 is an error condition.  */
    8071                 :         632 :   if (n == 0)
    8072                 :             :     {
    8073                 :         195 :       *new_return = error_mark_node;
    8074                 :         195 :       return true;
    8075                 :             :     }
    8076                 :             : 
    8077                 :             :   /* If not a lock-free size, change to the library generic format.  */
    8078                 :         437 :   if (!atomic_size_supported_p (n))
    8079                 :             :     {
    8080                 :          39 :       *new_return = add_atomic_size_parameter (n, loc, function, params);
    8081                 :          39 :       return true;
    8082                 :             :     }
    8083                 :             : 
    8084                 :             :   /* Otherwise there is a lockfree match, transform the call from:
    8085                 :             :        void fn(T* mem, T* desired, T* return, model)
    8086                 :             :      into
    8087                 :             :        *return = (T) (fn (In* mem, (In) *desired, model))  */
    8088                 :             : 
    8089                 :         398 :   p0 = (*params)[0];
    8090                 :         398 :   p1 = (*params)[1];
    8091                 :         398 :   p2 = (*params)[2];
    8092                 :         398 :   p3 = (*params)[3];
    8093                 :             : 
    8094                 :             :   /* Create pointer to appropriate size.  */
    8095                 :         398 :   I_type = builtin_type_for_size (BITS_PER_UNIT * n, 1);
    8096                 :         398 :   I_type_ptr = build_pointer_type (I_type);
    8097                 :             : 
    8098                 :             :   /* Convert object pointer to required type.  */
    8099                 :         398 :   p0 = build1 (VIEW_CONVERT_EXPR, I_type_ptr, p0);
    8100                 :         398 :   (*params)[0] = p0;
    8101                 :             :   /* Convert new value to required type, and dereference it.
    8102                 :             :      If *p1 type can have padding or may involve floating point which
    8103                 :             :      could e.g. be promoted to wider precision and demoted afterwards,
    8104                 :             :      state of padding bits might not be preserved.  */
    8105                 :         398 :   build_indirect_ref (loc, p1, RO_UNARY_STAR);
    8106                 :         398 :   p1 = build2_loc (loc, MEM_REF, I_type,
    8107                 :             :                    build1 (VIEW_CONVERT_EXPR, I_type_ptr, p1),
    8108                 :         398 :                    build_zero_cst (TREE_TYPE (p1)));
    8109                 :         398 :   (*params)[1] = p1;
    8110                 :             : 
    8111                 :             :   /* Move memory model to the 3rd position, and end param list.  */
    8112                 :         398 :   (*params)[2] = p3;
    8113                 :         398 :   params->truncate (3);
    8114                 :             : 
    8115                 :             :   /* Convert return pointer and dereference it for later assignment.  */
    8116                 :         398 :   *new_return = build_indirect_ref (loc, p2, RO_UNARY_STAR);
    8117                 :             : 
    8118                 :         398 :   return false;
    8119                 :             : }
    8120                 :             : 
    8121                 :             : /* This will process an __atomic_compare_exchange function call, determine
    8122                 :             :    whether it needs to be mapped to the _N variation, or turned into a lib call.
    8123                 :             :    LOC is the location of the builtin call.
    8124                 :             :    FUNCTION is the DECL that has been invoked;
    8125                 :             :    PARAMS is the argument list for the call.  The return value is non-null
    8126                 :             :    TRUE is returned if it is translated into the proper format for a call to the
    8127                 :             :    external library, and NEW_RETURN is set the tree for that function.
    8128                 :             :    FALSE is returned if processing for the _N variation is required.  */
    8129                 :             : 
    8130                 :             : static bool
    8131                 :       20988 : resolve_overloaded_atomic_compare_exchange (location_t loc, tree function,
    8132                 :             :                                             vec<tree, va_gc> *params,
    8133                 :             :                                             tree *new_return, bool complain)
    8134                 :             : {
    8135                 :       20988 :   tree p0, p1, p2;
    8136                 :       20988 :   tree I_type, I_type_ptr;
    8137                 :       20988 :   int n = get_atomic_generic_size (loc, function, params, complain);
    8138                 :             : 
    8139                 :             :   /* Size of 0 is an error condition.  */
    8140                 :       20988 :   if (n == 0)
    8141                 :             :     {
    8142                 :         178 :       *new_return = error_mark_node;
    8143                 :         178 :       return true;
    8144                 :             :     }
    8145                 :             : 
    8146                 :             :   /* If not a lock-free size, change to the library generic format.  */
    8147                 :       20810 :   if (!atomic_size_supported_p (n))
    8148                 :             :     {
    8149                 :             :       /* The library generic format does not have the weak parameter, so
    8150                 :             :          remove it from the param list.  Since a parameter has been removed,
    8151                 :             :          we can be sure that there is room for the SIZE_T parameter, meaning
    8152                 :             :          there will not be a recursive rebuilding of the parameter list, so
    8153                 :             :          there is no danger this will be done twice.  */
    8154                 :        1198 :       if (n > 0)
    8155                 :             :         {
    8156                 :        1198 :           (*params)[3] = (*params)[4];
    8157                 :        1198 :           (*params)[4] = (*params)[5];
    8158                 :        1198 :           params->truncate (5);
    8159                 :             :         }
    8160                 :        1198 :       *new_return = add_atomic_size_parameter (n, loc, function, params);
    8161                 :        1198 :       return true;
    8162                 :             :     }
    8163                 :             : 
    8164                 :             :   /* Otherwise, there is a match, so the call needs to be transformed from:
    8165                 :             :        bool fn(T* mem, T* desired, T* return, weak, success, failure)
    8166                 :             :      into
    8167                 :             :        bool fn ((In *)mem, (In *)expected, (In) *desired, weak, succ, fail)  */
    8168                 :             : 
    8169                 :       19612 :   p0 = (*params)[0];
    8170                 :       19612 :   p1 = (*params)[1];
    8171                 :       19612 :   p2 = (*params)[2];
    8172                 :             : 
    8173                 :             :   /* Create pointer to appropriate size.  */
    8174                 :       19612 :   I_type = builtin_type_for_size (BITS_PER_UNIT * n, 1);
    8175                 :       19612 :   I_type_ptr = build_pointer_type (I_type);
    8176                 :             : 
    8177                 :             :   /* Convert object pointer to required type.  */
    8178                 :       19612 :   p0 = build1 (VIEW_CONVERT_EXPR, I_type_ptr, p0);
    8179                 :       19612 :   (*params)[0] = p0;
    8180                 :             : 
    8181                 :             :   /* Convert expected pointer to required type.  */
    8182                 :       19612 :   p1 = build1 (VIEW_CONVERT_EXPR, I_type_ptr, p1);
    8183                 :       19612 :   (*params)[1] = p1;
    8184                 :             : 
    8185                 :             :   /* Convert desired value to required type, and dereference it.
    8186                 :             :      If *p2 type can have padding or may involve floating point which
    8187                 :             :      could e.g. be promoted to wider precision and demoted afterwards,
    8188                 :             :      state of padding bits might not be preserved.  */
    8189                 :       19612 :   build_indirect_ref (loc, p2, RO_UNARY_STAR);
    8190                 :       19612 :   p2 = build2_loc (loc, MEM_REF, I_type,
    8191                 :             :                    build1 (VIEW_CONVERT_EXPR, I_type_ptr, p2),
    8192                 :       19612 :                    build_zero_cst (TREE_TYPE (p2)));
    8193                 :       19612 :   (*params)[2] = p2;
    8194                 :             : 
    8195                 :             :   /* The rest of the parameters are fine. NULL means no special return value
    8196                 :             :      processing.*/
    8197                 :       19612 :   *new_return = NULL;
    8198                 :       19612 :   return false;
    8199                 :             : }
    8200                 :             : 
    8201                 :             : /* This will process an __atomic_load function call, determine whether it
    8202                 :             :    needs to be mapped to the _N variation, or turned into a library call.
    8203                 :             :    LOC is the location of the builtin call.
    8204                 :             :    FUNCTION is the DECL that has been invoked;
    8205                 :             :    PARAMS is the argument list for the call.  The return value is non-null
    8206                 :             :    TRUE is returned if it is translated into the proper format for a call to the
    8207                 :             :    external library, and NEW_RETURN is set the tree for that function.
    8208                 :             :    FALSE is returned if processing for the _N variation is required, and
    8209                 :             :    NEW_RETURN is set to the return value the result is copied into.  */
    8210                 :             : 
    8211                 :             : static bool
    8212                 :       50003 : resolve_overloaded_atomic_load (location_t loc, tree function,
    8213                 :             :                                 vec<tree, va_gc> *params, tree *new_return,
    8214                 :             :                                 bool complain)
    8215                 :             : {
    8216                 :       50003 :   tree p0, p1, p2;
    8217                 :       50003 :   tree I_type, I_type_ptr;
    8218                 :       50003 :   int n = get_atomic_generic_size (loc, function, params, complain);
    8219                 :             : 
    8220                 :             :   /* Size of 0 is an error condition.  */
    8221                 :       50003 :   if (n == 0)
    8222                 :             :     {
    8223                 :         278 :       *new_return = error_mark_node;
    8224                 :         278 :       return true;
    8225                 :             :     }
    8226                 :             : 
    8227                 :             :   /* If not a lock-free size, change to the library generic format.  */
    8228                 :       49725 :   if (!atomic_size_supported_p (n))
    8229                 :             :     {
    8230                 :        2499 :       *new_return = add_atomic_size_parameter (n, loc, function, params);
    8231                 :        2499 :       return true;
    8232                 :             :     }
    8233                 :             : 
    8234                 :             :   /* Otherwise, there is a match, so the call needs to be transformed from:
    8235                 :             :        void fn(T* mem, T* return, model)
    8236                 :             :      into
    8237                 :             :        *return = (T) (fn ((In *) mem, model))  */
    8238                 :             : 
    8239                 :       47226 :   p0 = (*params)[0];
    8240                 :       47226 :   p1 = (*params)[1];
    8241                 :       47226 :   p2 = (*params)[2];
    8242                 :             : 
    8243                 :             :   /* Create pointer to appropriate size.  */
    8244                 :       47226 :   I_type = builtin_type_for_size (BITS_PER_UNIT * n, 1);
    8245                 :       47226 :   I_type_ptr = build_pointer_type (I_type);
    8246                 :             : 
    8247                 :             :   /* Convert object pointer to required type.  */
    8248                 :       47226 :   p0 = build1 (VIEW_CONVERT_EXPR, I_type_ptr, p0);
    8249                 :       47226 :   (*params)[0] = p0;
    8250                 :             : 
    8251                 :             :   /* Move memory model to the 2nd position, and end param list.  */
    8252                 :       47226 :   (*params)[1] = p2;
    8253                 :       47226 :   params->truncate (2);
    8254                 :             : 
    8255                 :             :   /* Convert return pointer and dereference it for later assignment.  */
    8256                 :       47226 :   *new_return = build_indirect_ref (loc, p1, RO_UNARY_STAR);
    8257                 :             : 
    8258                 :       47226 :   return false;
    8259                 :             : }
    8260                 :             : 
    8261                 :             : /* This will process an __atomic_store function call, determine whether it
    8262                 :             :    needs to be mapped to the _N variation, or turned into a library call.
    8263                 :             :    LOC is the location of the builtin call.
    8264                 :             :    FUNCTION is the DECL that has been invoked;
    8265                 :             :    PARAMS is the argument list for the call.  The return value is non-null
    8266                 :             :    TRUE is returned if it is translated into the proper format for a call to the
    8267                 :             :    external library, and NEW_RETURN is set the tree for that function.
    8268                 :             :    FALSE is returned if processing for the _N variation is required, and
    8269                 :             :    NEW_RETURN is set to the return value the result is copied into.  */
    8270                 :             : 
    8271                 :             : static bool
    8272                 :       11487 : resolve_overloaded_atomic_store (location_t loc, tree function,
    8273                 :             :                                  vec<tree, va_gc> *params, tree *new_return,
    8274                 :             :                                  bool complain)
    8275                 :             : {
    8276                 :       11487 :   tree p0, p1;
    8277                 :       11487 :   tree I_type, I_type_ptr;
    8278                 :       11487 :   int n = get_atomic_generic_size (loc, function, params, complain);
    8279                 :             : 
    8280                 :             :   /* Size of 0 is an error condition.  */
    8281                 :       11487 :   if (n == 0)
    8282                 :             :     {
    8283                 :         168 :       *new_return = error_mark_node;
    8284                 :         168 :       return true;
    8285                 :             :     }
    8286                 :             : 
    8287                 :             :   /* If not a lock-free size, change to the library generic format.  */
    8288                 :       11319 :   if (!atomic_size_supported_p (n))
    8289                 :             :     {
    8290                 :         410 :       *new_return = add_atomic_size_parameter (n, loc, function, params);
    8291                 :         410 :       return true;
    8292                 :             :     }
    8293                 :             : 
    8294                 :             :   /* Otherwise, there is a match, so the call needs to be transformed from:
    8295                 :             :        void fn(T* mem, T* value, model)
    8296                 :             :      into
    8297                 :             :        fn ((In *) mem, (In) *value, model)  */
    8298                 :             : 
    8299                 :       10909 :   p0 = (*params)[0];
    8300                 :       10909 :   p1 = (*params)[1];
    8301                 :             : 
    8302                 :             :   /* Create pointer to appropriate size.  */
    8303                 :       10909 :   I_type = builtin_type_for_size (BITS_PER_UNIT * n, 1);
    8304                 :       10909 :   I_type_ptr = build_pointer_type (I_type);
    8305                 :             : 
    8306                 :             :   /* Convert object pointer to required type.  */
    8307                 :       10909 :   p0 = build1 (VIEW_CONVERT_EXPR, I_type_ptr, p0);
    8308                 :       10909 :   (*params)[0] = p0;
    8309                 :             : 
    8310                 :             :   /* Convert new value to required type, and dereference it.  */
    8311                 :       10909 :   p1 = build_indirect_ref (loc, p1, RO_UNARY_STAR);
    8312                 :       10909 :   p1 = build1 (VIEW_CONVERT_EXPR, I_type, p1);
    8313                 :       10909 :   (*params)[1] = p1;
    8314                 :             : 
    8315                 :             :   /* The memory model is in the right spot already. Return is void.  */
    8316                 :       10909 :   *new_return = NULL_TREE;
    8317                 :             : 
    8318                 :       10909 :   return false;
    8319                 :             : }
    8320                 :             : 
    8321                 :             : /* Emit __atomic*fetch* on _BitInt which doesn't have a size of
    8322                 :             :    1, 2, 4, 8 or 16 bytes using __atomic_compare_exchange loop.
    8323                 :             :    ORIG_CODE is the DECL_FUNCTION_CODE of ORIG_FUNCTION and
    8324                 :             :    ORIG_PARAMS arguments of the call.  */
    8325                 :             : 
    8326                 :             : static tree
    8327                 :         528 : atomic_bitint_fetch_using_cas_loop (location_t loc,
    8328                 :             :                                     enum built_in_function orig_code,
    8329                 :             :                                     tree orig_function,
    8330                 :             :                                     vec<tree, va_gc> *orig_params)
    8331                 :             : {
    8332                 :         528 :   enum tree_code code = ERROR_MARK;
    8333                 :         528 :   bool return_old_p = false;
    8334                 :         528 :   switch (orig_code)
    8335                 :             :     {
    8336                 :           0 :     case BUILT_IN_ATOMIC_ADD_FETCH_N:
    8337                 :           0 :       code = PLUS_EXPR;
    8338                 :           0 :       break;
    8339                 :           1 :     case BUILT_IN_ATOMIC_SUB_FETCH_N:
    8340                 :           1 :       code = MINUS_EXPR;
    8341                 :           1 :       break;
    8342                 :           0 :     case BUILT_IN_ATOMIC_AND_FETCH_N:
    8343                 :           0 :       code = BIT_AND_EXPR;
    8344                 :           0 :       break;
    8345                 :             :     case BUILT_IN_ATOMIC_NAND_FETCH_N:
    8346                 :             :       break;
    8347                 :           1 :     case BUILT_IN_ATOMIC_XOR_FETCH_N:
    8348                 :           1 :       code = BIT_XOR_EXPR;
    8349                 :           1 :       break;
    8350                 :           0 :     case BUILT_IN_ATOMIC_OR_FETCH_N:
    8351                 :           0 :       code = BIT_IOR_EXPR;
    8352                 :           0 :       break;
    8353                 :         106 :     case BUILT_IN_ATOMIC_FETCH_ADD_N:
    8354                 :         106 :       code = PLUS_EXPR;
    8355                 :         106 :       return_old_p = true;
    8356                 :         106 :       break;
    8357                 :         104 :     case BUILT_IN_ATOMIC_FETCH_SUB_N:
    8358                 :         104 :       code = MINUS_EXPR;
    8359                 :         104 :       return_old_p = true;
    8360                 :         104 :       break;
    8361                 :         105 :     case BUILT_IN_ATOMIC_FETCH_AND_N:
    8362                 :         105 :       code = BIT_AND_EXPR;
    8363                 :         105 :       return_old_p = true;
    8364                 :         105 :       break;
    8365                 :           0 :     case BUILT_IN_ATOMIC_FETCH_NAND_N:
    8366                 :           0 :       return_old_p = true;
    8367                 :           0 :       break;
    8368                 :         104 :     case BUILT_IN_ATOMIC_FETCH_XOR_N:
    8369                 :         104 :       code = BIT_XOR_EXPR;
    8370                 :         104 :       return_old_p = true;
    8371                 :         104 :       break;
    8372                 :         106 :     case BUILT_IN_ATOMIC_FETCH_OR_N:
    8373                 :         106 :       code = BIT_IOR_EXPR;
    8374                 :         106 :       return_old_p = true;
    8375                 :         106 :       break;
    8376                 :           0 :     default:
    8377                 :           0 :       gcc_unreachable ();
    8378                 :             :     }
    8379                 :             : 
    8380                 :         528 :   if (orig_params->length () != 3)
    8381                 :             :     {
    8382                 :           0 :       if (orig_params->length () < 3)
    8383                 :           0 :         error_at (loc, "too few arguments to function %qE", orig_function);
    8384                 :             :       else
    8385                 :           0 :         error_at (loc, "too many arguments to function %qE", orig_function);
    8386                 :           0 :       return error_mark_node;
    8387                 :             :     }
    8388                 :             : 
    8389                 :         528 :   tree stmts = push_stmt_list ();
    8390                 :             : 
    8391                 :         528 :   tree nonatomic_lhs_type = TREE_TYPE (TREE_TYPE ((*orig_params)[0]));
    8392                 :         528 :   nonatomic_lhs_type = TYPE_MAIN_VARIANT (nonatomic_lhs_type);
    8393                 :         528 :   gcc_assert (TREE_CODE (nonatomic_lhs_type) == BITINT_TYPE);
    8394                 :             : 
    8395                 :         528 :   tree lhs_addr = (*orig_params)[0];
    8396                 :         528 :   tree val = convert (nonatomic_lhs_type, (*orig_params)[1]);
    8397                 :         528 :   tree model = convert (integer_type_node, (*orig_params)[2]);
    8398                 :         528 :   if (!c_dialect_cxx ())
    8399                 :             :     {
    8400                 :         528 :       lhs_addr = c_fully_fold (lhs_addr, false, NULL);
    8401                 :         528 :       val = c_fully_fold (val, false, NULL);
    8402                 :         528 :       model = c_fully_fold (model, false, NULL);
    8403                 :             :     }
    8404                 :         528 :   if (TREE_SIDE_EFFECTS (lhs_addr))
    8405                 :             :     {
    8406                 :           1 :       tree var = create_tmp_var_raw (TREE_TYPE (lhs_addr));
    8407                 :           1 :       lhs_addr = build4 (TARGET_EXPR, TREE_TYPE (lhs_addr), var, lhs_addr,
    8408                 :             :                          NULL_TREE, NULL_TREE);
    8409                 :           1 :       add_stmt (lhs_addr);
    8410                 :             :     }
    8411                 :         528 :   if (TREE_SIDE_EFFECTS (val))
    8412                 :             :     {
    8413                 :           1 :       tree var = create_tmp_var_raw (nonatomic_lhs_type);
    8414                 :           1 :       val = build4 (TARGET_EXPR, nonatomic_lhs_type, var, val, NULL_TREE,
    8415                 :             :                     NULL_TREE);
    8416                 :           1 :       add_stmt (val);
    8417                 :             :     }
    8418                 :         528 :   if (TREE_SIDE_EFFECTS (model))
    8419                 :             :     {
    8420                 :           1 :       tree var = create_tmp_var_raw (integer_type_node);
    8421                 :           1 :       model = build4 (TARGET_EXPR, integer_type_node, var, model, NULL_TREE,
    8422                 :             :                       NULL_TREE);
    8423                 :           1 :       add_stmt (model);
    8424                 :             :     }
    8425                 :             : 
    8426                 :         528 :   tree old = create_tmp_var_raw (nonatomic_lhs_type);
    8427                 :         528 :   tree old_addr = build_unary_op (loc, ADDR_EXPR, old, false);
    8428                 :         528 :   TREE_ADDRESSABLE (old) = 1;
    8429                 :         528 :   suppress_warning (old);
    8430                 :             : 
    8431                 :         528 :   tree newval = create_tmp_var_raw (nonatomic_lhs_type);
    8432                 :         528 :   tree newval_addr = build_unary_op (loc, ADDR_EXPR, newval, false);
    8433                 :         528 :   TREE_ADDRESSABLE (newval) = 1;
    8434                 :         528 :   suppress_warning (newval);
    8435                 :             : 
    8436                 :         528 :   tree loop_decl = create_artificial_label (loc);
    8437                 :         528 :   tree loop_label = build1 (LABEL_EXPR, void_type_node, loop_decl);
    8438                 :             : 
    8439                 :         528 :   tree done_decl = create_artificial_label (loc);
    8440                 :         528 :   tree done_label = build1 (LABEL_EXPR, void_type_node, done_decl);
    8441                 :             : 
    8442                 :         528 :   vec<tree, va_gc> *params;
    8443                 :         528 :   vec_alloc (params, 6);
    8444                 :             : 
    8445                 :             :   /* __atomic_load (addr, &old, SEQ_CST).  */
    8446                 :         528 :   tree fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_LOAD);
    8447                 :         528 :   params->quick_push (lhs_addr);
    8448                 :         528 :   params->quick_push (old_addr);
    8449                 :         528 :   params->quick_push (build_int_cst (integer_type_node, MEMMODEL_RELAXED));
    8450                 :         528 :   tree func_call = resolve_overloaded_builtin (loc, fndecl, params);
    8451                 :         528 :   if (func_call == NULL_TREE)
    8452                 :         528 :     func_call = build_function_call_vec (loc, vNULL, fndecl, params, NULL);
    8453                 :         528 :   old = build4 (TARGET_EXPR, nonatomic_lhs_type, old, func_call, NULL_TREE,
    8454                 :             :                 NULL_TREE);
    8455                 :         528 :   add_stmt (old);
    8456                 :         528 :   params->truncate (0);
    8457                 :             : 
    8458                 :             :   /* loop:  */
    8459                 :         528 :   add_stmt (loop_label);
    8460                 :             : 
    8461                 :             :   /* newval = old + val;  */
    8462                 :         528 :   tree rhs;
    8463                 :         528 :   switch (code)
    8464                 :             :     {
    8465                 :         211 :     case PLUS_EXPR:
    8466                 :         211 :     case MINUS_EXPR:
    8467                 :         211 :       if (!TYPE_OVERFLOW_WRAPS (nonatomic_lhs_type))
    8468                 :             :         {
    8469                 :         211 :           tree utype
    8470                 :         211 :             = build_bitint_type (TYPE_PRECISION (nonatomic_lhs_type), 1);
    8471                 :         211 :           rhs = convert (nonatomic_lhs_type,
    8472                 :             :                          build2_loc (loc, code, utype,
    8473                 :             :                                      convert (utype, old),
    8474                 :             :                                      convert (utype, val)));
    8475                 :             :         }
    8476                 :             :       else
    8477                 :           0 :         rhs = build2_loc (loc, code, nonatomic_lhs_type, old, val);
    8478                 :             :       break;
    8479                 :         316 :     case BIT_AND_EXPR:
    8480                 :         316 :     case BIT_IOR_EXPR:
    8481                 :         316 :     case BIT_XOR_EXPR:
    8482                 :         316 :       rhs = build2_loc (loc, code, nonatomic_lhs_type, old, val);
    8483                 :         316 :       break;
    8484                 :           1 :     case ERROR_MARK:
    8485                 :           1 :       rhs = build2_loc (loc, BIT_AND_EXPR, nonatomic_lhs_type,
    8486                 :             :                         build1_loc (loc, BIT_NOT_EXPR,
    8487                 :             :                                     nonatomic_lhs_type, old), val);
    8488                 :           1 :       break;
    8489                 :           0 :     default:
    8490                 :           0 :       gcc_unreachable ();
    8491                 :             :     }
    8492                 :         528 :   rhs = build4 (TARGET_EXPR, nonatomic_lhs_type, newval, rhs, NULL_TREE,
    8493                 :             :                 NULL_TREE);
    8494                 :         528 :   SET_EXPR_LOCATION (rhs, loc);
    8495                 :         528 :   add_stmt (rhs);
    8496                 :             : 
    8497                 :             :   /* if (__atomic_compare_exchange (addr, &old, &new, false, model, model))
    8498                 :             :        goto done;  */
    8499                 :         528 :   fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_COMPARE_EXCHANGE);
    8500                 :         528 :   params->quick_push (lhs_addr);
    8501                 :         528 :   params->quick_push (old_addr);
    8502                 :         528 :   params->quick_push (newval_addr);
    8503                 :         528 :   params->quick_push (integer_zero_node);
    8504                 :         528 :   params->quick_push (model);
    8505                 :         528 :   if (tree_fits_uhwi_p (model)
    8506                 :         527 :       && (tree_to_uhwi (model) == MEMMODEL_RELEASE
    8507                 :         447 :           || tree_to_uhwi (model) == MEMMODEL_ACQ_REL))
    8508                 :         129 :     params->quick_push (build_int_cst (integer_type_node, MEMMODEL_RELAXED));
    8509                 :             :   else
    8510                 :         399 :     params->quick_push (model);
    8511                 :         528 :   func_call = resolve_overloaded_builtin (loc, fndecl, params);
    8512                 :         528 :   if (func_call == NULL_TREE)
    8513                 :         528 :     func_call = build_function_call_vec (loc, vNULL, fndecl, params, NULL);
    8514                 :             : 
    8515                 :         528 :   tree goto_stmt = build1 (GOTO_EXPR, void_type_node, done_decl);
    8516                 :         528 :   SET_EXPR_LOCATION (goto_stmt, loc);
    8517                 :             : 
    8518                 :         528 :   tree stmt
    8519                 :         528 :     = build3 (COND_EXPR, void_type_node, func_call, goto_stmt, NULL_TREE);
    8520                 :         528 :   SET_EXPR_LOCATION (stmt, loc);
    8521                 :         528 :   add_stmt (stmt);
    8522                 :             : 
    8523                 :             :   /* goto loop;  */
    8524                 :         528 :   goto_stmt = build1 (GOTO_EXPR, void_type_node, loop_decl);
    8525                 :         528 :   SET_EXPR_LOCATION (goto_stmt, loc);
    8526                 :         528 :   add_stmt (goto_stmt);
    8527                 :             : 
    8528                 :             :   /* done:  */
    8529                 :         528 :   add_stmt (done_label);
    8530                 :             : 
    8531                 :         528 :   tree ret = create_tmp_var_raw (nonatomic_lhs_type);
    8532                 :         531 :   stmt = build2_loc (loc, MODIFY_EXPR, void_type_node, ret,
    8533                 :             :                      return_old_p ? old : newval);
    8534                 :         528 :   add_stmt (stmt);
    8535                 :             : 
    8536                 :             :   /* Finish the compound statement.  */
    8537                 :         528 :   stmts = pop_stmt_list (stmts);
    8538                 :             : 
    8539                 :         528 :   return build4 (TARGET_EXPR, nonatomic_lhs_type, ret, stmts, NULL_TREE,
    8540                 :         528 :                  NULL_TREE);
    8541                 :             : }
    8542                 :             : 
    8543                 :             : 
    8544                 :             : /* Some builtin functions are placeholders for other expressions.  This
    8545                 :             :    function should be called immediately after parsing the call expression
    8546                 :             :    before surrounding code has committed to the type of the expression.
    8547                 :             : 
    8548                 :             :    LOC is the location of the builtin call.
    8549                 :             : 
    8550                 :             :    FUNCTION is the DECL that has been invoked; it is known to be a builtin.
    8551                 :             :    PARAMS is the argument list for the call.  The return value is non-null
    8552                 :             :    when expansion is complete, and null if normal processing should
    8553                 :             :    continue.  */
    8554                 :             : 
    8555                 :             : tree
    8556                 :    57185470 : resolve_overloaded_builtin (location_t loc, tree function,
    8557                 :             :                             vec<tree, va_gc> *params, bool complain)
    8558                 :             : {
    8559                 :             :   /* Is function one of the _FETCH_OP_ or _OP_FETCH_ built-ins?
    8560                 :             :      Those are not valid to call with a pointer to _Bool (or C++ bool)
    8561                 :             :      and so must be rejected.  */
    8562                 :    57185470 :   bool fetch_op = true;
    8563                 :    57185470 :   bool orig_format = true;
    8564                 :    57185470 :   tree new_return = NULL_TREE;
    8565                 :             : 
    8566                 :    57185470 :   switch (DECL_BUILT_IN_CLASS (function))
    8567                 :             :     {
    8568                 :     8955859 :     case BUILT_IN_NORMAL:
    8569                 :     8955859 :       break;
    8570                 :    32079028 :     case BUILT_IN_MD:
    8571                 :    32079028 :       if (targetm.resolve_overloaded_builtin)
    8572                 :           0 :         return targetm.resolve_overloaded_builtin (loc, function, params,
    8573                 :           0 :                                                    complain);
    8574                 :             :       else
    8575                 :             :         return NULL_TREE;
    8576                 :             :     default:
    8577                 :             :       return NULL_TREE;
    8578                 :             :     }
    8579                 :             : 
    8580                 :             :   /* Handle BUILT_IN_NORMAL here.  */
    8581                 :     8955859 :   enum built_in_function orig_code = DECL_FUNCTION_CODE (function);
    8582                 :     8955859 :   switch (orig_code)
    8583                 :             :     {
    8584                 :         154 :     case BUILT_IN_SPECULATION_SAFE_VALUE_N:
    8585                 :         154 :       {
    8586                 :         154 :         tree new_function, first_param, result;
    8587                 :         154 :         enum built_in_function fncode
    8588                 :         154 :           = speculation_safe_value_resolve_call (function, params, complain);
    8589                 :             : 
    8590                 :         154 :         if (fncode == BUILT_IN_NONE)
    8591                 :          52 :           return error_mark_node;
    8592                 :             : 
    8593                 :         102 :         first_param = (*params)[0];
    8594                 :         102 :         if (!speculation_safe_value_resolve_params (loc, function, params,
    8595                 :             :                                                     complain))
    8596                 :          31 :           return error_mark_node;
    8597                 :             : 
    8598                 :          71 :         if (targetm.have_speculation_safe_value (true))
    8599                 :             :           {
    8600                 :          71 :             new_function = builtin_decl_explicit (fncode);
    8601                 :          71 :             result = build_function_call_vec (loc, vNULL, new_function, params,
    8602                 :             :                                               NULL);
    8603                 :             : 
    8604                 :          71 :             if (result == error_mark_node)
    8605                 :             :               return result;
    8606                 :             : 
    8607                 :          71 :             return speculation_safe_value_resolve_return (first_param, result);
    8608                 :             :           }
    8609                 :             :         else
    8610                 :             :           {
    8611                 :             :             /* This target doesn't have, or doesn't need, active mitigation
    8612                 :             :                against incorrect speculative execution.  Simply return the
    8613                 :             :                first parameter to the builtin.  */
    8614                 :           0 :             if (!targetm.have_speculation_safe_value (false))
    8615                 :             :               {
    8616                 :           0 :                 if (complain)
    8617                 :             :                   /* The user has invoked __builtin_speculation_safe_value
    8618                 :             :                      even though __HAVE_SPECULATION_SAFE_VALUE is not
    8619                 :             :                      defined: emit a warning.  */
    8620                 :           0 :                   warning_at (
    8621                 :           0 :                     input_location, 0,
    8622                 :             :                     "this target does not define a speculation barrier; "
    8623                 :             :                     "your program will still execute correctly, "
    8624                 :             :                     "but incorrect speculation may not be "
    8625                 :             :                     "restricted");
    8626                 :             :                 else
    8627                 :           0 :                   return error_mark_node;
    8628                 :             :               }
    8629                 :             : 
    8630                 :             :             /* If the optional second argument is present, handle any side
    8631                 :             :                effects now.  */
    8632                 :           0 :             if (params->length () == 2
    8633                 :           0 :                 && TREE_SIDE_EFFECTS ((*params)[1]))
    8634                 :           0 :               return build2 (COMPOUND_EXPR, TREE_TYPE (first_param),
    8635                 :           0 :                              (*params)[1], first_param);
    8636                 :             : 
    8637                 :             :             return first_param;
    8638                 :             :           }
    8639                 :             :       }
    8640                 :             : 
    8641                 :       83110 :     case BUILT_IN_ATOMIC_EXCHANGE:
    8642                 :       83110 :     case BUILT_IN_ATOMIC_COMPARE_EXCHANGE:
    8643                 :       83110 :     case BUILT_IN_ATOMIC_LOAD:
    8644                 :       83110 :     case BUILT_IN_ATOMIC_STORE:
    8645                 :       83110 :       {
    8646                 :             :         /* Handle these 4 together so that they can fall through to the next
    8647                 :             :            case if the call is transformed to an _N variant.  */
    8648                 :       83110 :         switch (orig_code)
    8649                 :             :           {
    8650                 :         632 :           case BUILT_IN_ATOMIC_EXCHANGE:
    8651                 :         632 :             {
    8652                 :         632 :               if (resolve_overloaded_atomic_exchange (loc, function, params,
    8653                 :             :                                                       &new_return, complain))
    8654                 :         234 :                 return new_return;
    8655                 :             :               /* Change to the _N variant.  */
    8656                 :             :               orig_code = BUILT_IN_ATOMIC_EXCHANGE_N;
    8657                 :             :               break;
    8658                 :             :             }
    8659                 :             : 
    8660                 :       20988 :           case BUILT_IN_ATOMIC_COMPARE_EXCHANGE:
    8661                 :       20988 :             {
    8662                 :       20988 :               if (resolve_overloaded_atomic_compare_exchange (
    8663                 :             :                     loc, function, params, &new_return, complain))
    8664                 :        1376 :                 return new_return;
    8665                 :             :               /* Change to the _N variant.  */
    8666                 :             :               orig_code = BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N;
    8667                 :             :               break;
    8668                 :             :             }
    8669                 :       50003 :           case BUILT_IN_ATOMIC_LOAD:
    8670                 :       50003 :             {
    8671                 :       50003 :               if (resolve_overloaded_atomic_load (loc, function, params,
    8672                 :             :                                                   &new_return, complain))
    8673                 :        2777 :                 return new_return;
    8674                 :             :               /* Change to the _N variant.  */
    8675                 :             :               orig_code = BUILT_IN_ATOMIC_LOAD_N;
    8676                 :             :               break;
    8677                 :             :             }
    8678                 :       11487 :           case BUILT_IN_ATOMIC_STORE:
    8679                 :       11487 :             {
    8680                 :       11487 :               if (resolve_overloaded_atomic_store (loc, function, params,
    8681                 :             :                                                    &new_return, complain))
    8682                 :         578 :                 return new_return;
    8683                 :             :               /* Change to the _N variant.  */
    8684                 :             :               orig_code = BUILT_IN_ATOMIC_STORE_N;
    8685                 :             :               break;
    8686                 :             :             }
    8687                 :           0 :           default:
    8688                 :           0 :             gcc_unreachable ();
    8689                 :             :           }
    8690                 :             :       }
    8691                 :             :       /* FALLTHRU */
    8692                 :             :     case BUILT_IN_ATOMIC_EXCHANGE_N:
    8693                 :             :     case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N:
    8694                 :             :     case BUILT_IN_ATOMIC_LOAD_N:
    8695                 :             :     case BUILT_IN_ATOMIC_STORE_N:
    8696                 :             :       fetch_op = false;
    8697                 :             :       /* FALLTHRU */
    8698                 :             :     case BUILT_IN_ATOMIC_ADD_FETCH_N:
    8699                 :             :     case BUILT_IN_ATOMIC_SUB_FETCH_N:
    8700                 :             :     case BUILT_IN_ATOMIC_AND_FETCH_N:
    8701                 :             :     case BUILT_IN_ATOMIC_NAND_FETCH_N:
    8702                 :             :     case BUILT_IN_ATOMIC_XOR_FETCH_N:
    8703                 :             :     case BUILT_IN_ATOMIC_OR_FETCH_N:
    8704                 :             :     case BUILT_IN_ATOMIC_FETCH_ADD_N:
    8705                 :             :     case BUILT_IN_ATOMIC_FETCH_SUB_N:
    8706                 :             :     case BUILT_IN_ATOMIC_FETCH_AND_N:
    8707                 :             :     case BUILT_IN_ATOMIC_FETCH_NAND_N:
    8708                 :             :     case BUILT_IN_ATOMIC_FETCH_XOR_N:
    8709                 :             :     case BUILT_IN_ATOMIC_FETCH_OR_N:
    8710                 :             :       orig_format = false;
    8711                 :             :       /* FALLTHRU */
    8712                 :             :     case BUILT_IN_SYNC_FETCH_AND_ADD_N:
    8713                 :             :     case BUILT_IN_SYNC_FETCH_AND_SUB_N:
    8714                 :             :     case BUILT_IN_SYNC_FETCH_AND_OR_N:
    8715                 :             :     case BUILT_IN_SYNC_FETCH_AND_AND_N:
    8716                 :             :     case BUILT_IN_SYNC_FETCH_AND_XOR_N:
    8717                 :             :     case BUILT_IN_SYNC_FETCH_AND_NAND_N:
    8718                 :             :     case BUILT_IN_SYNC_ADD_AND_FETCH_N:
    8719                 :             :     case BUILT_IN_SYNC_SUB_AND_FETCH_N:
    8720                 :             :     case BUILT_IN_SYNC_OR_AND_FETCH_N:
    8721                 :             :     case BUILT_IN_SYNC_AND_AND_FETCH_N:
    8722                 :             :     case BUILT_IN_SYNC_XOR_AND_FETCH_N:
    8723                 :             :     case BUILT_IN_SYNC_NAND_AND_FETCH_N:
    8724                 :             :     case BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N:
    8725                 :             :     case BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_N:
    8726                 :             :     case BUILT_IN_SYNC_LOCK_TEST_AND_SET_N:
    8727                 :             :     case BUILT_IN_SYNC_LOCK_RELEASE_N:
    8728                 :             :       {
    8729                 :             :         /* The following are not _FETCH_OPs and must be accepted with
    8730                 :             :            pointers to _Bool (or C++ bool).  */
    8731                 :             :         if (fetch_op)
    8732                 :       68864 :           fetch_op = (orig_code != BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
    8733                 :       68864 :                       && orig_code != BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_N
    8734                 :       68378 :                       && orig_code != BUILT_IN_SYNC_LOCK_TEST_AND_SET_N
    8735                 :       68864 :                       && orig_code != BUILT_IN_SYNC_LOCK_RELEASE_N);
    8736                 :             : 
    8737                 :      325491 :         int n = sync_resolve_size (function, params, fetch_op, orig_format,
    8738                 :             :                                    complain);
    8739                 :      325491 :         tree new_function, first_param, result;
    8740                 :      325491 :         enum built_in_function fncode;
    8741                 :             : 
    8742                 :      325491 :         if (n == 0)
    8743                 :        2607 :           return error_mark_node;
    8744                 :             : 
    8745                 :      322884 :         if (n == -1)
    8746                 :             :           {
    8747                 :             :             /* complain is related to SFINAE context.
    8748                 :             :                _BitInt is not defined in C++, hence can't enter this clause
    8749                 :             :                with complain unset.  Even if at the abstraction level
    8750                 :             :                this complain is unset that still makes sense (whether
    8751                 :             :                this function should report an error or not if anything is
    8752                 :             :                wrong).
    8753                 :             :                Since can't test avoiding an error when this value is false not
    8754                 :             :                writing the code and instead asserting value is not set.  */
    8755                 :         528 :             gcc_assert (complain);
    8756                 :         528 :             return atomic_bitint_fetch_using_cas_loop (loc, orig_code, function,
    8757                 :         528 :                                                        params);
    8758                 :             :           }
    8759                 :             : 
    8760                 :      322356 :         fncode = (enum built_in_function)((int)orig_code + exact_log2 (n) + 1);
    8761                 :      322356 :         new_function = builtin_decl_explicit (fncode);
    8762                 :      322356 :         if (!sync_resolve_params (loc, function, new_function, params,
    8763                 :             :                                   orig_format, complain))
    8764                 :         164 :           return error_mark_node;
    8765                 :             : 
    8766                 :      322192 :         first_param = (*params)[0];
    8767                 :      322192 :         result = build_function_call_vec (loc, vNULL, new_function, params,
    8768                 :             :                                           NULL);
    8769                 :      322192 :         if (result == error_mark_node)
    8770                 :             :           return result;
    8771                 :      322180 :         if (orig_code != BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_N
    8772                 :      322180 :             && orig_code != BUILT_IN_SYNC_LOCK_RELEASE_N
    8773                 :      321873 :             && orig_code != BUILT_IN_ATOMIC_STORE_N
    8774                 :      321873 :             && orig_code != BUILT_IN_ATOMIC_COMPARE_EXCHANGE_N)
    8775                 :      213343 :           result = sync_resolve_return (first_param, result, orig_format);
    8776                 :             : 
    8777                 :      322180 :         if (fetch_op)
    8778                 :             :           /* Prevent -Wunused-value warning.  */
    8779                 :       65359 :           TREE_USED (result) = true;
    8780                 :             : 
    8781                 :             :         /* If new_return is set, assign function to that expr and cast the
    8782                 :             :            result to void since the generic interface returned void.  */
    8783                 :      322180 :         if (new_return)
    8784                 :             :           {
    8785                 :             :             /* Cast function result from I{1,2,4,8,16} to the required type.  */
    8786                 :       47624 :             if (TREE_CODE (TREE_TYPE (new_return)) == BITINT_TYPE)
    8787                 :             :               {
    8788                 :         599 :                 struct bitint_info info;
    8789                 :         599 :                 unsigned prec = TYPE_PRECISION (TREE_TYPE (new_return));
    8790                 :         599 :                 targetm.c.bitint_type_info (prec, &info);
    8791                 :         599 :                 if (!info.extended)
    8792                 :             :                   /* For _BitInt which has the padding bits undefined
    8793                 :             :                      convert to the _BitInt type rather than VCE to force
    8794                 :             :                      zero or sign extension.  */
    8795                 :         599 :                   result = build1 (NOP_EXPR, TREE_TYPE (new_return), result);
    8796                 :             :               }
    8797                 :       47624 :             result
    8798                 :       47624 :               = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (new_return), result);
    8799                 :       47624 :             result = build2 (MODIFY_EXPR, TREE_TYPE (new_return), new_return,
    8800                 :             :                              result);
    8801                 :       47624 :             TREE_SIDE_EFFECTS (result) = 1;
    8802                 :       47624 :             protected_set_expr_location (result, loc);
    8803                 :       47624 :             result = convert (void_type_node, result);
    8804                 :             :           }
    8805                 :             :         return result;
    8806                 :             :       }
    8807                 :             : 
    8808                 :             :     default:
    8809                 :             :       return NULL_TREE;
    8810                 :             :     }
    8811                 :             : }
    8812                 :             : 
    8813                 :             : /* vector_types_compatible_elements_p is used in type checks of vectors
    8814                 :             :    values used as operands of binary operators.  Where it returns true, and
    8815                 :             :    the other checks of the caller succeed (being vector types in he first
    8816                 :             :    place, and matching number of elements), we can just treat the types
    8817                 :             :    as essentially the same.
    8818                 :             :    Contrast with vector_targets_convertible_p, which is used for vector
    8819                 :             :    pointer types,  and vector_types_convertible_p, which will allow
    8820                 :             :    language-specific matches under the control of flag_lax_vector_conversions,
    8821                 :             :    and might still require a conversion.  */
    8822                 :             : /* True if vector types T1 and T2 can be inputs to the same binary
    8823                 :             :    operator without conversion.
    8824                 :             :    We don't check the overall vector size here because some of our callers
    8825                 :             :    want to give different error messages when the vectors are compatible
    8826                 :             :    except for the element count.  */
    8827                 :             : 
    8828                 :             : bool
    8829                 :     1592043 : vector_types_compatible_elements_p (tree t1, tree t2)
    8830                 :             : {
    8831                 :     3183810 :   bool opaque = TYPE_VECTOR_OPAQUE (t1) || TYPE_VECTOR_OPAQUE (t2);
    8832                 :     1592043 :   t1 = TREE_TYPE (t1);
    8833                 :     1592043 :   t2 = TREE_TYPE (t2);
    8834                 :             : 
    8835                 :     1592043 :   enum tree_code c1 = TREE_CODE (t1), c2 = TREE_CODE (t2);
    8836                 :             : 
    8837                 :     1592043 :   gcc_assert ((INTEGRAL_TYPE_P (t1)
    8838                 :             :                || c1 == REAL_TYPE
    8839                 :             :                || c1 == FIXED_POINT_TYPE)
    8840                 :             :               && (INTEGRAL_TYPE_P (t2)
    8841                 :             :                   || c2 == REAL_TYPE
    8842                 :             :                   || c2 == FIXED_POINT_TYPE));
    8843                 :             : 
    8844                 :     1592043 :   t1 = c_common_signed_type (t1);
    8845                 :     1592043 :   t2 = c_common_signed_type (t2);
    8846                 :             :   /* Equality works here because c_common_signed_type uses
    8847                 :             :      TYPE_MAIN_VARIANT.  */
    8848                 :     1592043 :   if (t1 == t2)
    8849                 :             :     return true;
    8850                 :          31 :   if (opaque && c1 == c2
    8851                 :           4 :       && (INTEGRAL_TYPE_P (t1) || c1 == REAL_TYPE)
    8852                 :          35 :       && TYPE_PRECISION (t1) == TYPE_PRECISION (t2))
    8853                 :           4 :     return true;
    8854                 :             :   return false;
    8855                 :             : }
    8856                 :             : 
    8857                 :             : /* Check for missing format attributes on function pointers.  LTYPE is
    8858                 :             :    the new type or left-hand side type.  RTYPE is the old type or
    8859                 :             :    right-hand side type.  Returns TRUE if LTYPE is missing the desired
    8860                 :             :    attribute.  */
    8861                 :             : 
    8862                 :             : bool
    8863                 :        9930 : check_missing_format_attribute (tree ltype, tree rtype)
    8864                 :             : {
    8865                 :        9930 :   tree const ttr = TREE_TYPE (rtype), ttl = TREE_TYPE (ltype);
    8866                 :        9930 :   tree ra;
    8867                 :             : 
    8868                 :        9939 :   for (ra = TYPE_ATTRIBUTES (ttr); ra; ra = TREE_CHAIN (ra))
    8869                 :          73 :     if (is_attribute_p ("format", get_attribute_name (ra)))
    8870                 :             :       break;
    8871                 :        9930 :   if (ra)
    8872                 :             :     {
    8873                 :          64 :       tree la;
    8874                 :          64 :       for (la = TYPE_ATTRIBUTES (ttl); la; la = TREE_CHAIN (la))
    8875                 :          24 :         if (is_attribute_p ("format", get_attribute_name (la)))
    8876                 :             :           break;
    8877                 :          64 :       return !la;
    8878                 :             :     }
    8879                 :             :   else
    8880                 :             :     return false;
    8881                 :             : }
    8882                 :             : 
    8883                 :             : /* Setup a TYPE_DECL node as a typedef representation.
    8884                 :             : 
    8885                 :             :    X is a TYPE_DECL for a typedef statement.  Create a brand new
    8886                 :             :    ..._TYPE node (which will be just a variant of the existing
    8887                 :             :    ..._TYPE node with identical properties) and then install X
    8888                 :             :    as the TYPE_NAME of this brand new (duplicate) ..._TYPE node.
    8889                 :             : 
    8890                 :             :    The whole point here is to end up with a situation where each
    8891                 :             :    and every ..._TYPE node the compiler creates will be uniquely
    8892                 :             :    associated with AT MOST one node representing a typedef name.
    8893                 :             :    This way, even though the compiler substitutes corresponding
    8894                 :             :    ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
    8895                 :             :    early on, later parts of the compiler can always do the reverse
    8896                 :             :    translation and get back the corresponding typedef name.  For
    8897                 :             :    example, given:
    8898                 :             : 
    8899                 :             :         typedef struct S MY_TYPE;
    8900                 :             :         MY_TYPE object;
    8901                 :             : 
    8902                 :             :    Later parts of the compiler might only know that `object' was of
    8903                 :             :    type `struct S' if it were not for code just below.  With this
    8904                 :             :    code however, later parts of the compiler see something like:
    8905                 :             : 
    8906                 :             :         struct S' == struct S
    8907                 :             :         typedef struct S' MY_TYPE;
    8908                 :             :         struct S' object;
    8909                 :             : 
    8910                 :             :     And they can then deduce (from the node for type struct S') that
    8911                 :             :     the original object declaration was:
    8912                 :             : 
    8913                 :             :                 MY_TYPE object;
    8914                 :             : 
    8915                 :             :     Being able to do this is important for proper support of protoize,
    8916                 :             :     and also for generating precise symbolic debugging information
    8917                 :             :     which takes full account of the programmer's (typedef) vocabulary.
    8918                 :             : 
    8919                 :             :     Obviously, we don't want to generate a duplicate ..._TYPE node if
    8920                 :             :     the TYPE_DECL node that we are now processing really represents a
    8921                 :             :     standard built-in type.  */
    8922                 :             : 
    8923                 :             : void
    8924                 :   174365383 : set_underlying_type (tree x)
    8925                 :             : {
    8926                 :   174365383 :   if (x == error_mark_node || TREE_TYPE (x) == error_mark_node)
    8927                 :             :     return;
    8928                 :   174365355 :   if (DECL_IS_UNDECLARED_BUILTIN (x) && TREE_CODE (TREE_TYPE (x)) != ARRAY_TYPE)
    8929                 :             :     {
    8930                 :     6218494 :       if (TYPE_NAME (TREE_TYPE (x)) == 0)
    8931                 :     4962687 :         TYPE_NAME (TREE_TYPE (x)) = x;
    8932                 :             :     }
    8933                 :   168146861 :   else if (DECL_ORIGINAL_TYPE (x))
    8934                 :      162993 :     gcc_checking_assert (TYPE_NAME (TREE_TYPE (x)) == x);
    8935                 :             :   else
    8936                 :             :     {
    8937                 :   167983868 :       tree tt = TREE_TYPE (x);
    8938                 :   167983868 :       DECL_ORIGINAL_TYPE (x) = tt;
    8939                 :   167983868 :       tt = build_variant_type_copy (tt);
    8940                 :   167983868 :       TYPE_STUB_DECL (tt) = TYPE_STUB_DECL (DECL_ORIGINAL_TYPE (x));
    8941                 :   167983868 :       TYPE_NAME (tt) = x;
    8942                 :             : 
    8943                 :             :       /* Mark the type as used only when its type decl is decorated
    8944                 :             :          with attribute unused.  */
    8945                 :   167983868 :       if (lookup_attribute ("unused", DECL_ATTRIBUTES (x)))
    8946                 :         254 :         TREE_USED (tt) = 1;
    8947                 :             : 
    8948                 :   167983868 :       TREE_TYPE (x) = tt;
    8949                 :             :     }
    8950                 :             : }
    8951                 :             : 
    8952                 :             : /* Return true if it is worth exposing the DECL_ORIGINAL_TYPE of TYPE to
    8953                 :             :    the user in diagnostics, false if it would be better to use TYPE itself.
    8954                 :             :    TYPE is known to satisfy typedef_variant_p.  */
    8955                 :             : 
    8956                 :             : bool
    8957                 :       31157 : user_facing_original_type_p (const_tree type)
    8958                 :             : {
    8959                 :       31157 :   gcc_assert (typedef_variant_p (type));
    8960                 :       31157 :   tree decl = TYPE_NAME (type);
    8961                 :             : 
    8962                 :             :   /* Look through any typedef in "user" code.  */
    8963                 :       31157 :   if (!DECL_IN_SYSTEM_HEADER (decl) && !DECL_IS_UNDECLARED_BUILTIN (decl))
    8964                 :             :     return true;
    8965                 :             : 
    8966                 :             :   /* If the original type is also named and is in the user namespace,
    8967                 :             :      assume it too is a user-facing type.  */
    8968                 :        1576 :   tree orig_type = DECL_ORIGINAL_TYPE (decl);
    8969                 :        1576 :   if (tree orig_id = TYPE_IDENTIFIER (orig_type))
    8970                 :        1448 :     if (!name_reserved_for_implementation_p (IDENTIFIER_POINTER (orig_id)))
    8971                 :             :       return true;
    8972                 :             : 
    8973                 :         698 :   switch (TREE_CODE (orig_type))
    8974                 :             :     {
    8975                 :             :     /* Don't look through to an anonymous vector type, since the syntax
    8976                 :             :        we use for them in diagnostics isn't real C or C++ syntax.
    8977                 :             :        And if ORIG_TYPE is named but in the implementation namespace,
    8978                 :             :        TYPE is likely to be more meaningful to the user.  */
    8979                 :             :     case VECTOR_TYPE:
    8980                 :             :       return false;
    8981                 :             : 
    8982                 :             :     /* Don't expose anonymous tag types that are presumably meant to be
    8983                 :             :        known by their typedef name.  Also don't expose tags that are in
    8984                 :             :        the implementation namespace, such as:
    8985                 :             : 
    8986                 :             :          typedef struct __foo foo;  */
    8987                 :             :     case RECORD_TYPE:
    8988                 :             :     case UNION_TYPE:
    8989                 :             :     case ENUMERAL_TYPE:
    8990                 :             :       return false;
    8991                 :             : 
    8992                 :             :     /* Look through to anything else.  */
    8993                 :             :     default:
    8994                 :             :       return true;
    8995                 :             :     }
    8996                 :             : }
    8997                 :             : 
    8998                 :             : /* Record the types used by the current global variable declaration
    8999                 :             :    being parsed, so that we can decide later to emit their debug info.
    9000                 :             :    Those types are in types_used_by_cur_var_decl, and we are going to
    9001                 :             :    store them in the types_used_by_vars_hash hash table.
    9002                 :             :    DECL is the declaration of the global variable that has been parsed.  */
    9003                 :             : 
    9004                 :             : void
    9005                 :    23257552 : record_types_used_by_current_var_decl (tree decl)
    9006                 :             : {
    9007                 :    23257552 :   gcc_assert (decl && DECL_P (decl) && TREE_STATIC (decl));
    9008                 :             : 
    9009                 :    44975749 :   while (types_used_by_cur_var_decl && !types_used_by_cur_var_decl->is_empty ())
    9010                 :             :     {
    9011                 :    21718197 :       tree type = types_used_by_cur_var_decl->pop ();
    9012                 :    21718197 :       types_used_by_var_decl_insert (type, decl);
    9013                 :             :     }
    9014                 :    23257552 : }
    9015                 :             : 
    9016                 :             : /* The C and C++ parsers both use vectors to hold function arguments.
    9017                 :             :    For efficiency, we keep a cache of unused vectors.  This is the
    9018                 :             :    cache.  */
    9019                 :             : 
    9020                 :             : typedef vec<tree, va_gc> *tree_gc_vec;
    9021                 :             : static GTY((deletable)) vec<tree_gc_vec, va_gc> *tree_vector_cache;
    9022                 :             : 
    9023                 :             : /* Return a new vector from the cache.  If the cache is empty,
    9024                 :             :    allocate a new vector.  These vectors are GC'ed, so it is OK if the
    9025                 :             :    pointer is not released..  */
    9026                 :             : 
    9027                 :             : vec<tree, va_gc> *
    9028                 :  1042601059 : make_tree_vector (void)
    9029                 :             : {
    9030                 :  1042601059 :   if (tree_vector_cache && !tree_vector_cache->is_empty ())
    9031                 :  1014289333 :     return tree_vector_cache->pop ();
    9032                 :             :   else
    9033                 :             :     {
    9034                 :             :       /* Passing 0 to vec::alloc returns NULL, and our callers require
    9035                 :             :          that we always return a non-NULL value.  The vector code uses
    9036                 :             :          4 when growing a NULL vector, so we do too.  */
    9037                 :    28311726 :       vec<tree, va_gc> *v;
    9038                 :    28311726 :       vec_alloc (v, 4);
    9039                 :    28311726 :       return v;
    9040                 :             :     }
    9041                 :             : }
    9042                 :             : 
    9043                 :             : /* Release a vector of trees back to the cache.  */
    9044                 :             : 
    9045                 :             : void
    9046                 :  1406216259 : release_tree_vector (vec<tree, va_gc> *vec)
    9047                 :             : {
    9048                 :  1406216259 :   if (vec != NULL)
    9049                 :             :     {
    9050                 :  1016005943 :       if (vec->allocated () >= 16)
    9051                 :             :         /* Don't cache vecs that have expanded more than once.  On a p64
    9052                 :             :            target, vecs double in alloc size with each power of 2 elements, e.g
    9053                 :             :            at 16 elements the alloc increases from 128 to 256 bytes.  */
    9054                 :      899714 :         vec_free (vec);
    9055                 :             :       else
    9056                 :             :         {
    9057                 :  1015106229 :           vec->truncate (0);
    9058                 :  1015106229 :           vec_safe_push (tree_vector_cache, vec);
    9059                 :             :         }
    9060                 :             :     }
    9061                 :  1406216259 : }
    9062                 :             : 
    9063                 :             : /* Get a new tree vector holding a single tree.  */
    9064                 :             : 
    9065                 :             : vec<tree, va_gc> *
    9066                 :    49394553 : make_tree_vector_single (tree t)
    9067                 :             : {
    9068                 :    49394553 :   vec<tree, va_gc> *ret = make_tree_vector ();
    9069                 :    49394553 :   ret->quick_push (t);
    9070                 :    49394553 :   return ret;
    9071                 :             : }
    9072                 :             : 
    9073                 :             : /* Get a new tree vector of the TREE_VALUEs of a TREE_LIST chain.  */
    9074                 :             : 
    9075                 :             : vec<tree, va_gc> *
    9076                 :        5888 : make_tree_vector_from_list (tree list)
    9077                 :             : {
    9078                 :        5888 :   vec<tree, va_gc> *ret = make_tree_vector ();
    9079                 :       16032 :   for (; list; list = TREE_CHAIN (list))
    9080                 :       10144 :     vec_safe_push (ret, TREE_VALUE (list));
    9081                 :        5888 :   return ret;
    9082                 :             : }
    9083                 :             : 
    9084                 :             : /* Append to a tree vector V the values of a CONSTRUCTOR CTOR
    9085                 :             :    and return the new possibly reallocated vector.  */
    9086                 :             : 
    9087                 :             : vec<tree, va_gc> *
    9088                 :     1381722 : append_ctor_to_tree_vector (vec<tree, va_gc> *v, tree ctor)
    9089                 :             : {
    9090                 :     2603511 :   unsigned nelts = vec_safe_length (v) + CONSTRUCTOR_NELTS (ctor);
    9091                 :     1381722 :   vec_safe_reserve (v, CONSTRUCTOR_NELTS (ctor));
    9092                 :     3427192 :   for (unsigned i = 0; i < CONSTRUCTOR_NELTS (ctor); ++i)
    9093                 :     2045470 :     if (TREE_CODE (CONSTRUCTOR_ELT (ctor, i)->value) == RAW_DATA_CST)
    9094                 :             :       {
    9095                 :          24 :         tree raw_data = CONSTRUCTOR_ELT (ctor, i)->value;
    9096                 :          24 :         nelts += RAW_DATA_LENGTH (raw_data) - 1;
    9097                 :          24 :         vec_safe_reserve (v, nelts - v->length ());
    9098                 :          48 :         if (TYPE_PRECISION (TREE_TYPE (raw_data)) > CHAR_BIT
    9099                 :          24 :             || TYPE_UNSIGNED (TREE_TYPE (raw_data)))
    9100                 :        6264 :           for (unsigned j = 0; j < (unsigned) RAW_DATA_LENGTH (raw_data); ++j)
    9101                 :        6240 :             v->quick_push (build_int_cst (TREE_TYPE (raw_data),
    9102                 :        6240 :                                           RAW_DATA_UCHAR_ELT (raw_data, j)));
    9103                 :             :         else
    9104                 :           0 :           for (unsigned j = 0; j < (unsigned) RAW_DATA_LENGTH (raw_data); ++j)
    9105                 :           0 :             v->quick_push (build_int_cst (TREE_TYPE (raw_data),
    9106                 :           0 :                                           RAW_DATA_SCHAR_ELT (raw_data, j)));
    9107                 :             :       }
    9108                 :             :     else
    9109                 :     2045446 :       v->quick_push (CONSTRUCTOR_ELT (ctor, i)->value);
    9110                 :     1381722 :   return v;
    9111                 :             : }
    9112                 :             : 
    9113                 :             : /* Get a new tree vector of the values of a CONSTRUCTOR.  */
    9114                 :             : 
    9115                 :             : vec<tree, va_gc> *
    9116                 :        4973 : make_tree_vector_from_ctor (tree ctor)
    9117                 :             : {
    9118                 :        4973 :   vec<tree,va_gc> *ret
    9119                 :        4973 :     = CONSTRUCTOR_NELTS (ctor) <= 16 ? make_tree_vector () : NULL;
    9120                 :        4973 :   return append_ctor_to_tree_vector (ret, ctor);
    9121                 :             : }
    9122                 :             : 
    9123                 :             : /* Get a new tree vector which is a copy of an existing one.  */
    9124                 :             : 
    9125                 :             : vec<tree, va_gc> *
    9126                 :    28900557 : make_tree_vector_copy (const vec<tree, va_gc> *orig)
    9127                 :             : {
    9128                 :    28900557 :   vec<tree, va_gc> *ret;
    9129                 :    28900557 :   unsigned int ix;
    9130                 :    28900557 :   tree t;
    9131                 :             : 
    9132                 :    28900557 :   ret = make_tree_vector ();
    9133                 :    28900557 :   vec_safe_reserve (ret, vec_safe_length (orig));
    9134                 :    70126973 :   FOR_EACH_VEC_SAFE_ELT (orig, ix, t)
    9135                 :    12325859 :     ret->quick_push (t);
    9136                 :    28900557 :   return ret;
    9137                 :             : }
    9138                 :             : 
    9139                 :             : /* Return true if KEYWORD starts a type specifier.  */
    9140                 :             : 
    9141                 :             : bool
    9142                 :          16 : keyword_begins_type_specifier (enum rid keyword)
    9143                 :             : {
    9144                 :          16 :   switch (keyword)
    9145                 :             :     {
    9146                 :             :     case RID_AUTO_TYPE:
    9147                 :             :     case RID_INT:
    9148                 :             :     case RID_CHAR:
    9149                 :             :     case RID_FLOAT:
    9150                 :             :     case RID_DOUBLE:
    9151                 :             :     case RID_VOID:
    9152                 :             :     case RID_UNSIGNED:
    9153                 :             :     case RID_LONG:
    9154                 :             :     case RID_SHORT:
    9155                 :             :     case RID_SIGNED:
    9156                 :             :     CASE_RID_FLOATN_NX:
    9157                 :             :     case RID_DFLOAT32:
    9158                 :             :     case RID_DFLOAT64:
    9159                 :             :     case RID_DFLOAT128:
    9160                 :             :     case RID_FRACT:
    9161                 :             :     case RID_ACCUM:
    9162                 :             :     case RID_BOOL:
    9163                 :             :     case RID_BITINT:
    9164                 :             :     case RID_WCHAR:
    9165                 :             :     case RID_CHAR8:
    9166                 :             :     case RID_CHAR16:
    9167                 :             :     case RID_CHAR32:
    9168                 :             :     case RID_SAT:
    9169                 :             :     case RID_COMPLEX:
    9170                 :             :     case RID_TYPEOF:
    9171                 :             :     case RID_STRUCT:
    9172                 :             :     case RID_CLASS:
    9173                 :             :     case RID_UNION:
    9174                 :             :     case RID_ENUM:
    9175                 :             :       return true;
    9176                 :           1 :     default:
    9177                 :           1 :       if (keyword >= RID_FIRST_INT_N
    9178                 :             :           && keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS
    9179                 :           0 :           && int_n_enabled_p[keyword-RID_FIRST_INT_N])
    9180                 :             :         return true;
    9181                 :             :       return false;
    9182                 :             :     }
    9183                 :             : }
    9184                 :             : 
    9185                 :             : /* Return true if KEYWORD names a type qualifier.  */
    9186                 :             : 
    9187                 :             : bool
    9188                 :       12128 : keyword_is_type_qualifier (enum rid keyword)
    9189                 :             : {
    9190                 :       12128 :   switch (keyword)
    9191                 :             :     {
    9192                 :             :     case RID_CONST:
    9193                 :             :     case RID_VOLATILE:
    9194                 :             :     case RID_RESTRICT:
    9195                 :             :     case RID_ATOMIC:
    9196                 :             :       return true;
    9197                 :          58 :     default:
    9198                 :          58 :       return false;
    9199                 :             :     }
    9200                 :             : }
    9201                 :             : 
    9202                 :             : /* Return true if KEYWORD names a storage class specifier.
    9203                 :             : 
    9204                 :             :    RID_TYPEDEF is not included in this list despite `typedef' being
    9205                 :             :    listed in C99 6.7.1.1.  6.7.1.3 indicates that `typedef' is listed as
    9206                 :             :    such for syntactic convenience only.  */
    9207                 :             : 
    9208                 :             : bool
    9209                 :       12154 : keyword_is_storage_class_specifier (enum rid keyword)
    9210                 :             : {
    9211                 :       12154 :   switch (keyword)
    9212                 :             :     {
    9213                 :             :     case RID_STATIC:
    9214                 :             :     case RID_EXTERN:
    9215                 :             :     case RID_REGISTER:
    9216                 :             :     case RID_AUTO:
    9217                 :             :     case RID_MUTABLE:
    9218                 :             :     case RID_THREAD:
    9219                 :             :       return true;
    9220                 :       12128 :     default:
    9221                 :       12128 :       return false;
    9222                 :             :     }
    9223                 :             : }
    9224                 :             : 
    9225                 :             : /* Return true if KEYWORD names a function-specifier [dcl.fct.spec].  */
    9226                 :             : 
    9227                 :             : static bool
    9228                 :          58 : keyword_is_function_specifier (enum rid keyword)
    9229                 :             : {
    9230                 :          58 :   switch (keyword)
    9231                 :             :     {
    9232                 :             :     case RID_INLINE:
    9233                 :             :     case RID_NORETURN:
    9234                 :             :     case RID_VIRTUAL:
    9235                 :             :     case RID_EXPLICIT:
    9236                 :             :       return true;
    9237                 :          56 :     default:
    9238                 :           0 :       return false;
    9239                 :             :     }
    9240                 :             : }
    9241                 :             : 
    9242                 :             : /* Return true if KEYWORD names a decl-specifier [dcl.spec] or a
    9243                 :             :    declaration-specifier (C99 6.7).  */
    9244                 :             : 
    9245                 :             : bool
    9246                 :       12154 : keyword_is_decl_specifier (enum rid keyword)
    9247                 :             : {
    9248                 :       12154 :   if (keyword_is_storage_class_specifier (keyword)
    9249                 :       12128 :       || keyword_is_type_qualifier (keyword)
    9250                 :       12154 :       || keyword_is_function_specifier (keyword))
    9251                 :       12098 :     return true;
    9252                 :             : 
    9253                 :          56 :   switch (keyword)
    9254                 :             :     {
    9255                 :             :     case RID_TYPEDEF:
    9256                 :             :     case RID_FRIEND:
    9257                 :             :     case RID_CONSTEXPR:
    9258                 :             :     case RID_CONSTINIT:
    9259                 :             :       return true;
    9260                 :             :     default:
    9261                 :             :       return false;
    9262                 :             :     }
    9263                 :             : }
    9264                 :             : 
    9265                 :             : /* Initialize language-specific-bits of tree_contains_struct.  */
    9266                 :             : 
    9267                 :             : void
    9268                 :      207045 : c_common_init_ts (void)
    9269                 :             : {
    9270                 :      207045 :   MARK_TS_EXP (SIZEOF_EXPR);
    9271                 :      207045 :   MARK_TS_EXP (PAREN_SIZEOF_EXPR);
    9272                 :      207045 :   MARK_TS_EXP (C_MAYBE_CONST_EXPR);
    9273                 :      207045 :   MARK_TS_EXP (EXCESS_PRECISION_EXPR);
    9274                 :      207045 :   MARK_TS_EXP (BREAK_STMT);
    9275                 :      207045 :   MARK_TS_EXP (CONTINUE_STMT);
    9276                 :      207045 :   MARK_TS_EXP (DO_STMT);
    9277                 :      207045 :   MARK_TS_EXP (FOR_STMT);
    9278                 :      207045 :   MARK_TS_EXP (SWITCH_STMT);
    9279                 :      207045 :   MARK_TS_EXP (WHILE_STMT);
    9280                 :             : 
    9281                 :      207045 :   MARK_TS_DECL_COMMON (CONCEPT_DECL);
    9282                 :      207045 : }
    9283                 :             : 
    9284                 :             : /* Build a user-defined numeric literal out of an integer constant type VALUE
    9285                 :             :    with identifier SUFFIX.  */
    9286                 :             : 
    9287                 :             : tree
    9288                 :      947099 : build_userdef_literal (tree suffix_id, tree value,
    9289                 :             :                        enum overflow_type overflow, tree num_string)
    9290                 :             : {
    9291                 :      947099 :   tree literal = make_node (USERDEF_LITERAL);
    9292                 :      947099 :   USERDEF_LITERAL_SUFFIX_ID (literal) = suffix_id;
    9293                 :      947099 :   USERDEF_LITERAL_VALUE (literal) = value;
    9294                 :      947099 :   USERDEF_LITERAL_OVERFLOW (literal) = overflow;
    9295                 :      947099 :   USERDEF_LITERAL_NUM_STRING (literal) = num_string;
    9296                 :      947099 :   return literal;
    9297                 :             : }
    9298                 :             : 
    9299                 :             : /* For vector[index], convert the vector to an array of the underlying type.
    9300                 :             :    Return true if the resulting ARRAY_REF should not be an lvalue.  */
    9301                 :             : 
    9302                 :             : bool
    9303                 :     8774399 : convert_vector_to_array_for_subscript (location_t loc,
    9304                 :             :                                        tree *vecp, tree index)
    9305                 :             : {
    9306                 :     8774399 :   bool ret = false;
    9307                 :     8774399 :   if (gnu_vector_type_p (TREE_TYPE (*vecp)))
    9308                 :             :     {
    9309                 :     1037614 :       tree type = TREE_TYPE (*vecp);
    9310                 :     1037614 :       tree newitype;
    9311                 :             : 
    9312                 :     1037614 :       ret = !lvalue_p (*vecp);
    9313                 :             : 
    9314                 :     1037614 :       index = fold_for_warn (index);
    9315                 :             :       /* Warn out-of-bounds index for vectors only if known.  */
    9316                 :     1037614 :       if (poly_int_tree_p (index))
    9317                 :     1024817 :         if (!tree_fits_poly_uint64_p (index)
    9318                 :     1024817 :             || known_ge (tree_to_poly_uint64 (index),
    9319                 :             :                           TYPE_VECTOR_SUBPARTS (type)))
    9320                 :          82 :             warning_at (loc, OPT_Warray_bounds_, "index value is out of bound");
    9321                 :             : 
    9322                 :             :       /* We are building an ARRAY_REF so mark the vector as addressable
    9323                 :             :          to not run into the gimplifiers premature setting of DECL_GIMPLE_REG_P
    9324                 :             :          for function parameters.  */
    9325                 :     1037614 :       c_common_mark_addressable_vec (*vecp);
    9326                 :             : 
    9327                 :             :       /* Make sure qualifiers are copied from the vector type to the new element
    9328                 :             :          of the array type.  */
    9329                 :     1037614 :       newitype = build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type));
    9330                 :             : 
    9331                 :     1037614 :       *vecp = build1 (VIEW_CONVERT_EXPR,
    9332                 :             :                       build_array_type_nelts (newitype,
    9333                 :             :                                               TYPE_VECTOR_SUBPARTS (type)),
    9334                 :             :                       *vecp);
    9335                 :             :     }
    9336                 :     8774399 :   return ret;
    9337                 :             : }
    9338                 :             : 
    9339                 :             : /* Determine which of the operands, if any, is a scalar that needs to be
    9340                 :             :    converted to a vector, for the range of operations.  */
    9341                 :             : enum stv_conv
    9342                 :        3452 : scalar_to_vector (location_t loc, enum tree_code code, tree op0, tree op1,
    9343                 :             :                   bool complain)
    9344                 :             : {
    9345                 :        3452 :   tree type0 = TREE_TYPE (op0);
    9346                 :        3452 :   tree type1 = TREE_TYPE (op1);
    9347                 :        3452 :   bool integer_only_op = false;
    9348                 :        3452 :   enum stv_conv ret = stv_firstarg;
    9349                 :             : 
    9350                 :        3452 :   gcc_assert (gnu_vector_type_p (type0) || gnu_vector_type_p (type1));
    9351                 :        3452 :   switch (code)
    9352                 :             :     {
    9353                 :             :       /* Most GENERIC binary expressions require homogeneous arguments.
    9354                 :             :          LSHIFT_EXPR and RSHIFT_EXPR are exceptions and accept a first
    9355                 :             :          argument that is a vector and a second one that is a scalar, so
    9356                 :             :          we never return stv_secondarg for them.  */
    9357                 :         951 :       case RSHIFT_EXPR:
    9358                 :         951 :       case LSHIFT_EXPR:
    9359                 :         951 :         if (TREE_CODE (type0) == INTEGER_TYPE
    9360                 :         951 :             && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE)
    9361                 :             :           {
    9362                 :          50 :             if (unsafe_conversion_p (TREE_TYPE (type1), op0,
    9363                 :             :                                      NULL_TREE, false))
    9364                 :             :               {
    9365                 :           0 :                 if (complain)
    9366                 :           0 :                   error_at (loc, "conversion of scalar %qT to vector %qT "
    9367                 :             :                             "involves truncation", type0, type1);
    9368                 :           0 :                 return stv_error;
    9369                 :             :               }
    9370                 :             :             else
    9371                 :             :               return stv_firstarg;
    9372                 :             :           }
    9373                 :             :         break;
    9374                 :             : 
    9375                 :         311 :       case BIT_IOR_EXPR:
    9376                 :         311 :       case BIT_XOR_EXPR:
    9377                 :         311 :       case BIT_AND_EXPR:
    9378                 :         311 :         integer_only_op = true;
    9379                 :             :         /* fall through */
    9380                 :             : 
    9381                 :        2489 :       case VEC_COND_EXPR:
    9382                 :             : 
    9383                 :        2489 :       case PLUS_EXPR:
    9384                 :        2489 :       case MINUS_EXPR:
    9385                 :        2489 :       case MULT_EXPR:
    9386                 :        2489 :       case TRUNC_DIV_EXPR:
    9387                 :        2489 :       case CEIL_DIV_EXPR:
    9388                 :        2489 :       case FLOOR_DIV_EXPR:
    9389                 :        2489 :       case ROUND_DIV_EXPR:
    9390                 :        2489 :       case EXACT_DIV_EXPR:
    9391                 :        2489 :       case TRUNC_MOD_EXPR:
    9392                 :        2489 :       case FLOOR_MOD_EXPR:
    9393                 :        2489 :       case RDIV_EXPR:
    9394                 :        2489 :       case EQ_EXPR:
    9395                 :        2489 :       case NE_EXPR:
    9396                 :        2489 :       case LE_EXPR:
    9397                 :        2489 :       case GE_EXPR:
    9398                 :        2489 :       case LT_EXPR:
    9399                 :        2489 :       case GT_EXPR:
    9400                 :             :       /* What about UNLT_EXPR?  */
    9401                 :        2489 :         if (gnu_vector_type_p (type0))
    9402                 :             :           {
    9403                 :        1836 :             ret = stv_secondarg;
    9404                 :        1836 :             std::swap (type0, type1);
    9405                 :        1836 :             std::swap (op0, op1);
    9406                 :             :           }
    9407                 :             : 
    9408                 :        2489 :         if (TREE_CODE (type0) == INTEGER_TYPE
    9409                 :        2489 :             && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE)
    9410                 :             :           {
    9411                 :        1779 :             if (unsafe_conversion_p (TREE_TYPE (type1), op0,
    9412                 :             :                                      NULL_TREE, false))
    9413                 :             :               {
    9414                 :          11 :                 if (complain)
    9415                 :           8 :                   error_at (loc, "conversion of scalar %qT to vector %qT "
    9416                 :             :                             "involves truncation", type0, type1);
    9417                 :          11 :                 return stv_error;
    9418                 :             :               }
    9419                 :             :             return ret;
    9420                 :             :           }
    9421                 :         710 :         else if (!integer_only_op
    9422                 :             :                     /* Allow integer --> real conversion if safe.  */
    9423                 :         710 :                  && (SCALAR_FLOAT_TYPE_P (type0)
    9424                 :         468 :                      || TREE_CODE (type0) == INTEGER_TYPE)
    9425                 :        1420 :                  && SCALAR_FLOAT_TYPE_P (TREE_TYPE (type1)))
    9426                 :             :           {
    9427                 :         686 :             if (unsafe_conversion_p (TREE_TYPE (type1), op0,
    9428                 :             :                                      NULL_TREE, false))
    9429                 :             :               {
    9430                 :          22 :                 if (complain)
    9431                 :          22 :                   error_at (loc, "conversion of scalar %qT to vector %qT "
    9432                 :             :                             "involves truncation", type0, type1);
    9433                 :          22 :                 return stv_error;
    9434                 :             :               }
    9435                 :             :             return ret;
    9436                 :             :           }
    9437                 :             :       default:
    9438                 :             :         break;
    9439                 :             :     }
    9440                 :             : 
    9441                 :             :   return stv_nothing;
    9442                 :             : }
    9443                 :             : 
    9444                 :             : /* Return the alignment of std::max_align_t.
    9445                 :             : 
    9446                 :             :    [support.types.layout] The type max_align_t is a POD type whose alignment
    9447                 :             :    requirement is at least as great as that of every scalar type, and whose
    9448                 :             :    alignment requirement is supported in every context.  */
    9449                 :             : 
    9450                 :             : unsigned
    9451                 :      253960 : max_align_t_align ()
    9452                 :             : {
    9453                 :      253960 :   unsigned int max_align = MAX (TYPE_ALIGN (long_long_integer_type_node),
    9454                 :             :                                 TYPE_ALIGN (long_double_type_node));
    9455                 :      253960 :   if (float128_type_node != NULL_TREE)
    9456                 :      253960 :     max_align = MAX (max_align, TYPE_ALIGN (float128_type_node));
    9457                 :      253960 :   return max_align;
    9458                 :             : }
    9459                 :             : 
    9460                 :             : /* Return true iff ALIGN is an integral constant that is a fundamental
    9461                 :             :    alignment, as defined by [basic.align] in the c++-11
    9462                 :             :    specifications.
    9463                 :             : 
    9464                 :             :    That is:
    9465                 :             : 
    9466                 :             :        [A fundamental alignment is represented by an alignment less than or
    9467                 :             :         equal to the greatest alignment supported by the implementation
    9468                 :             :         in all contexts, which is equal to alignof(max_align_t)].  */
    9469                 :             : 
    9470                 :             : bool
    9471                 :           0 : cxx_fundamental_alignment_p (unsigned align)
    9472                 :             : {
    9473                 :           0 :   return (align <= max_align_t_align ());
    9474                 :             : }
    9475                 :             : 
    9476                 :             : /* Return true if T is a pointer to a zero-sized aggregate.  */
    9477                 :             : 
    9478                 :             : bool
    9479                 :     1314043 : pointer_to_zero_sized_aggr_p (tree t)
    9480                 :             : {
    9481                 :     1314043 :   if (!POINTER_TYPE_P (t))
    9482                 :             :     return false;
    9483                 :     1314043 :   t = TREE_TYPE (t);
    9484                 :     1314043 :   return (TYPE_SIZE (t) && integer_zerop (TYPE_SIZE (t)));
    9485                 :             : }
    9486                 :             : 
    9487                 :             : /* For an EXPR of a FUNCTION_TYPE that references a GCC built-in function
    9488                 :             :    with no library fallback or for an ADDR_EXPR whose operand is such type
    9489                 :             :    issues an error pointing to the location LOC.
    9490                 :             :    Returns true when the expression has been diagnosed and false
    9491                 :             :    otherwise.  */
    9492                 :             : 
    9493                 :             : bool
    9494                 :  4320228506 : reject_gcc_builtin (const_tree expr, location_t loc /* = UNKNOWN_LOCATION */)
    9495                 :             : {
    9496                 :  4320228506 :   if (TREE_CODE (expr) == ADDR_EXPR)
    9497                 :   104586736 :     expr = TREE_OPERAND (expr, 0);
    9498                 :             : 
    9499                 :  4320228506 :   STRIP_ANY_LOCATION_WRAPPER (expr);
    9500                 :             : 
    9501                 :  4320228506 :   if (TREE_TYPE (expr)
    9502                 :  4320228364 :       && TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE
    9503                 :     2025596 :       && TREE_CODE (expr) == FUNCTION_DECL
    9504                 :             :       /* The intersection of DECL_BUILT_IN and DECL_IS_UNDECLARED_BUILTIN avoids
    9505                 :             :          false positives for user-declared built-ins such as abs or
    9506                 :             :          strlen, and for C++ operators new and delete.
    9507                 :             :          The c_decl_implicit() test avoids false positives for implicitly
    9508                 :             :          declared built-ins with library fallbacks (such as abs).  */
    9509                 :     1999186 :       && fndecl_built_in_p (expr)
    9510                 :       69068 :       && DECL_IS_UNDECLARED_BUILTIN (expr)
    9511                 :        2372 :       && !c_decl_implicit (expr)
    9512                 :  4320230873 :       && !DECL_ASSEMBLER_NAME_SET_P (expr))
    9513                 :             :     {
    9514                 :         220 :       if (loc == UNKNOWN_LOCATION)
    9515                 :          82 :         loc = EXPR_LOC_OR_LOC (expr, input_location);
    9516                 :             : 
    9517                 :             :       /* Reject arguments that are built-in functions with
    9518                 :             :          no library fallback.  */
    9519                 :         220 :       error_at (loc, "built-in function %qE must be directly called", expr);
    9520                 :             : 
    9521                 :         220 :       return true;
    9522                 :             :     }
    9523                 :             : 
    9524                 :             :   return false;
    9525                 :             : }
    9526                 :             : 
    9527                 :             : /* Issue an ERROR for an invalid SIZE of array NAME which is null
    9528                 :             :    for unnamed arrays.  */
    9529                 :             : 
    9530                 :             : void
    9531                 :        1412 : invalid_array_size_error (location_t loc, cst_size_error error,
    9532                 :             :                           const_tree size, const_tree name)
    9533                 :             : {
    9534                 :        1412 :   tree maxsize = max_object_size ();
    9535                 :        1412 :   switch (error)
    9536                 :             :     {
    9537                 :           0 :     case cst_size_not_constant:
    9538                 :           0 :       if (name)
    9539                 :           0 :         error_at (loc, "size of array %qE is not a constant expression",
    9540                 :             :                   name);
    9541                 :             :       else
    9542                 :           0 :         error_at (loc, "size of array is not a constant expression");
    9543                 :             :       break;
    9544                 :         422 :     case cst_size_negative:
    9545                 :         422 :       if (name)
    9546                 :         131 :         error_at (loc, "size %qE of array %qE is negative",
    9547                 :             :                   size, name);
    9548                 :             :       else
    9549                 :         291 :         error_at (loc, "size %qE of array is negative",
    9550                 :             :                   size);
    9551                 :             :       break;
    9552                 :         930 :     case cst_size_too_big:
    9553                 :         930 :       if (name)
    9554                 :         103 :         error_at (loc, "size %qE of array %qE exceeds maximum "
    9555                 :             :                   "object size %qE", size, name, maxsize);
    9556                 :             :       else
    9557                 :         827 :         error_at (loc, "size %qE of array exceeds maximum "
    9558                 :             :                   "object size %qE", size, maxsize);
    9559                 :             :       break;
    9560                 :          60 :     case cst_size_overflow:
    9561                 :          60 :       if (name)
    9562                 :          39 :         error_at (loc, "size of array %qE exceeds maximum "
    9563                 :             :                   "object size %qE", name, maxsize);
    9564                 :             :       else
    9565                 :          21 :         error_at (loc, "size of array exceeds maximum "
    9566                 :             :                   "object size %qE", maxsize);
    9567                 :             :       break;
    9568                 :           0 :     default:
    9569                 :           0 :       gcc_unreachable ();
    9570                 :             :     }
    9571                 :        1412 : }
    9572                 :             : 
    9573                 :             : /* Check if array size calculations overflow or if the array covers more
    9574                 :             :    than half of the address space.  Return true if the size of the array
    9575                 :             :    is valid, false otherwise.  T is either the type of the array or its
    9576                 :             :    size, and NAME is the name of the array, or null for unnamed arrays.  */
    9577                 :             : 
    9578                 :             : bool
    9579                 :     7467010 : valid_array_size_p (location_t loc, const_tree t, tree name, bool complain)
    9580                 :             : {
    9581                 :     7467010 :   if (t == error_mark_node)
    9582                 :             :     return true;
    9583                 :             : 
    9584                 :     7466869 :   const_tree size;
    9585                 :     7466869 :   if (TYPE_P (t))
    9586                 :             :     {
    9587                 :     5350406 :       if (!COMPLETE_TYPE_P (t))
    9588                 :             :         return true;
    9589                 :     2804209 :       size = TYPE_SIZE_UNIT (t);
    9590                 :             :     }
    9591                 :             :   else
    9592                 :             :     size = t;
    9593                 :             : 
    9594                 :     4920672 :   if (TREE_CODE (size) != INTEGER_CST)
    9595                 :             :     return true;
    9596                 :             : 
    9597                 :     4896266 :   cst_size_error error;
    9598                 :     4896266 :   if (valid_constant_size_p (size, &error))
    9599                 :             :     return true;
    9600                 :             : 
    9601                 :        1103 :   if (!complain)
    9602                 :             :     return false;
    9603                 :             : 
    9604                 :        1088 :   if (TREE_CODE (TREE_TYPE (size)) == ENUMERAL_TYPE)
    9605                 :             :     /* Show the value of the enumerator rather than its name.  */
    9606                 :          16 :     size = convert (ssizetype, const_cast<tree> (size));
    9607                 :             : 
    9608                 :        1088 :   invalid_array_size_error (loc, error, size, name);
    9609                 :        1088 :   return false;
    9610                 :             : }
    9611                 :             : 
    9612                 :             : /* Read SOURCE_DATE_EPOCH from environment to have a deterministic
    9613                 :             :    timestamp to replace embedded current dates to get reproducible
    9614                 :             :    results.  Returns -1 if SOURCE_DATE_EPOCH is not defined.  */
    9615                 :             : 
    9616                 :             : time_t
    9617                 :        2495 : cb_get_source_date_epoch (cpp_reader *pfile ATTRIBUTE_UNUSED)
    9618                 :             : {
    9619                 :        2495 :   char *source_date_epoch;
    9620                 :        2495 :   int64_t epoch;
    9621                 :        2495 :   char *endptr;
    9622                 :             : 
    9623                 :        2495 :   source_date_epoch = getenv ("SOURCE_DATE_EPOCH");
    9624                 :        2495 :   if (!source_date_epoch)
    9625                 :             :     return (time_t) -1;
    9626                 :             : 
    9627                 :           3 :   errno = 0;
    9628                 :             : #if defined(INT64_T_IS_LONG)
    9629                 :           3 :   epoch = strtol (source_date_epoch, &endptr, 10);
    9630                 :             : #else
    9631                 :             :   epoch = strtoll (source_date_epoch, &endptr, 10);
    9632                 :             : #endif
    9633                 :           3 :   if (errno != 0 || endptr == source_date_epoch || *endptr != '\0'
    9634                 :           2 :       || epoch < 0 || epoch > MAX_SOURCE_DATE_EPOCH)
    9635                 :             :     {
    9636                 :           1 :       error_at (input_location, "environment variable %qs must "
    9637                 :             :                 "expand to a non-negative integer less than or equal to %wd",
    9638                 :             :                 "SOURCE_DATE_EPOCH", MAX_SOURCE_DATE_EPOCH);
    9639                 :           1 :       return (time_t) -1;
    9640                 :             :     }
    9641                 :             : 
    9642                 :             :   return (time_t) epoch;
    9643                 :             : }
    9644                 :             : 
    9645                 :             : /* Callback for libcpp for offering spelling suggestions for misspelled
    9646                 :             :    directives.  GOAL is an unrecognized string; CANDIDATES is a
    9647                 :             :    NULL-terminated array of candidate strings.  Return the closest
    9648                 :             :    match to GOAL within CANDIDATES, or NULL if none are good
    9649                 :             :    suggestions.  */
    9650                 :             : 
    9651                 :             : const char *
    9652                 :          19 : cb_get_suggestion (cpp_reader *, const char *goal,
    9653                 :             :                    const char *const *candidates)
    9654                 :             : {
    9655                 :          19 :   best_match<const char *, const char *> bm (goal);
    9656                 :         204 :   while (*candidates)
    9657                 :         166 :     bm.consider (*candidates++);
    9658                 :          19 :   return bm.get_best_meaningful_candidate ();
    9659                 :             : }
    9660                 :             : 
    9661                 :             : /* Return the latice point which is the wider of the two FLT_EVAL_METHOD
    9662                 :             :    modes X, Y.  This isn't just  >, as the FLT_EVAL_METHOD values added
    9663                 :             :    by C TS 18661-3 for interchange  types that are computed in their
    9664                 :             :    native precision are larger than the C11 values for evaluating in the
    9665                 :             :    precision of float/double/long double.  If either mode is
    9666                 :             :    FLT_EVAL_METHOD_UNPREDICTABLE, return that.  */
    9667                 :             : 
    9668                 :             : enum flt_eval_method
    9669                 :      527488 : excess_precision_mode_join (enum flt_eval_method x,
    9670                 :             :                             enum flt_eval_method y)
    9671                 :             : {
    9672                 :      527488 :   if (x == FLT_EVAL_METHOD_UNPREDICTABLE
    9673                 :      527488 :       || y == FLT_EVAL_METHOD_UNPREDICTABLE)
    9674                 :             :     return FLT_EVAL_METHOD_UNPREDICTABLE;
    9675                 :             : 
    9676                 :             :   /* GCC only supports one interchange type right now, _Float16.  If
    9677                 :             :      we're evaluating _Float16 in 16-bit precision, then flt_eval_method
    9678                 :             :      will be FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16.  */
    9679                 :      527164 :   if (x == FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16)
    9680                 :             :     return y;
    9681                 :      525175 :   if (y == FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16)
    9682                 :             :     return x;
    9683                 :             : 
    9684                 :             :   /* Other values for flt_eval_method are directly comparable, and we want
    9685                 :             :      the maximum.  */
    9686                 :      525163 :   return MAX (x, y);
    9687                 :             : }
    9688                 :             : 
    9689                 :             : /* Return the value that should be set for FLT_EVAL_METHOD in the
    9690                 :             :    context of ISO/IEC TS 18861-3.
    9691                 :             : 
    9692                 :             :    This relates to the effective excess precision seen by the user,
    9693                 :             :    which is the join point of the precision the target requests for
    9694                 :             :    -fexcess-precision={standard,fast,16} and the implicit excess precision
    9695                 :             :    the target uses.  */
    9696                 :             : 
    9697                 :             : static enum flt_eval_method
    9698                 :      412458 : c_ts18661_flt_eval_method (void)
    9699                 :             : {
    9700                 :      412458 :   enum flt_eval_method implicit
    9701                 :      412458 :     = targetm.c.excess_precision (EXCESS_PRECISION_TYPE_IMPLICIT);
    9702                 :             : 
    9703                 :      299274 :   enum excess_precision_type flag_type
    9704                 :      412458 :     = (flag_excess_precision == EXCESS_PRECISION_STANDARD
    9705                 :      412458 :        ? EXCESS_PRECISION_TYPE_STANDARD
    9706                 :             :        : (flag_excess_precision == EXCESS_PRECISION_FLOAT16
    9707                 :      299286 :           ? EXCESS_PRECISION_TYPE_FLOAT16
    9708                 :             :           : EXCESS_PRECISION_TYPE_FAST));
    9709                 :             : 
    9710                 :      412458 :   enum flt_eval_method requested
    9711                 :      412458 :     = targetm.c.excess_precision (flag_type);
    9712                 :             : 
    9713                 :      412458 :   return excess_precision_mode_join (implicit, requested);
    9714                 :             : }
    9715                 :             : 
    9716                 :             : /* As c_cpp_ts18661_flt_eval_method, but clamps the expected values to
    9717                 :             :    those that were permitted by C11.  That is to say, eliminates
    9718                 :             :    FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16.  */
    9719                 :             : 
    9720                 :             : static enum flt_eval_method
    9721                 :      102828 : c_c11_flt_eval_method (void)
    9722                 :             : {
    9723                 :      102828 :   return excess_precision_mode_join (c_ts18661_flt_eval_method (),
    9724                 :      102828 :                                      FLT_EVAL_METHOD_PROMOTE_TO_FLOAT);
    9725                 :             : }
    9726                 :             : 
    9727                 :             : /* Return the value that should be set for FLT_EVAL_METHOD.
    9728                 :             :    MAYBE_C11_ONLY_P is TRUE if we should check
    9729                 :             :    FLAG_PERMITTED_EVAL_METHODS as to whether we should limit the possible
    9730                 :             :    values we can return to those from C99/C11, and FALSE otherwise.
    9731                 :             :    See the comments on c_ts18661_flt_eval_method for what value we choose
    9732                 :             :    to set here.  */
    9733                 :             : 
    9734                 :             : int
    9735                 :      412458 : c_flt_eval_method (bool maybe_c11_only_p)
    9736                 :             : {
    9737                 :      412458 :   if (maybe_c11_only_p
    9738                 :      206229 :       && flag_permitted_flt_eval_methods
    9739                 :             :           == PERMITTED_FLT_EVAL_METHODS_C11)
    9740                 :      102828 :     return c_c11_flt_eval_method ();
    9741                 :             :   else
    9742                 :      309630 :     return c_ts18661_flt_eval_method ();
    9743                 :             : }
    9744                 :             : 
    9745                 :             : /* An enum for get_missing_token_insertion_kind for describing the best
    9746                 :             :    place to insert a missing token, if there is one.  */
    9747                 :             : 
    9748                 :             : enum missing_token_insertion_kind
    9749                 :             : {
    9750                 :             :   MTIK_IMPOSSIBLE,
    9751                 :             :   MTIK_INSERT_BEFORE_NEXT,
    9752                 :             :   MTIK_INSERT_AFTER_PREV
    9753                 :             : };
    9754                 :             : 
    9755                 :             : /* Given a missing token of TYPE, determine if it is reasonable to
    9756                 :             :    emit a fix-it hint suggesting the insertion of the token, and,
    9757                 :             :    if so, where the token should be inserted relative to other tokens.
    9758                 :             : 
    9759                 :             :    It only makes sense to do this for values of TYPE that are symbols.
    9760                 :             : 
    9761                 :             :    Some symbols should go before the next token, e.g. in:
    9762                 :             :      if flag)
    9763                 :             :    we want to insert the missing '(' immediately before "flag",
    9764                 :             :    giving:
    9765                 :             :      if (flag)
    9766                 :             :    rather than:
    9767                 :             :      if( flag)
    9768                 :             :    These use MTIK_INSERT_BEFORE_NEXT.
    9769                 :             : 
    9770                 :             :    Other symbols should go after the previous token, e.g. in:
    9771                 :             :      if (flag
    9772                 :             :        do_something ();
    9773                 :             :    we want to insert the missing ')' immediately after the "flag",
    9774                 :             :    giving:
    9775                 :             :      if (flag)
    9776                 :             :        do_something ();
    9777                 :             :    rather than:
    9778                 :             :      if (flag
    9779                 :             :        )do_something ();
    9780                 :             :    These use MTIK_INSERT_AFTER_PREV.  */
    9781                 :             : 
    9782                 :             : static enum missing_token_insertion_kind
    9783                 :        3229 : get_missing_token_insertion_kind (enum cpp_ttype type)
    9784                 :             : {
    9785                 :        3229 :   switch (type)
    9786                 :             :     {
    9787                 :             :       /* Insert missing "opening" brackets immediately
    9788                 :             :          before the next token.  */
    9789                 :             :     case CPP_OPEN_SQUARE:
    9790                 :             :     case CPP_OPEN_PAREN:
    9791                 :             :       return MTIK_INSERT_BEFORE_NEXT;
    9792                 :             : 
    9793                 :             :       /* Insert other missing symbols immediately after
    9794                 :             :          the previous token.  */
    9795                 :        1958 :     case CPP_CLOSE_PAREN:
    9796                 :        1958 :     case CPP_CLOSE_SQUARE:
    9797                 :        1958 :     case CPP_SEMICOLON:
    9798                 :        1958 :     case CPP_COMMA:
    9799                 :        1958 :     case CPP_COLON:
    9800                 :        1958 :       return MTIK_INSERT_AFTER_PREV;
    9801                 :             : 
    9802                 :             :       /* Other kinds of token don't get fix-it hints.  */
    9803                 :         987 :     default:
    9804                 :         987 :       return MTIK_IMPOSSIBLE;
    9805                 :             :     }
    9806                 :             : }
    9807                 :             : 
    9808                 :             : /* Given RICHLOC, a location for a diagnostic describing a missing token
    9809                 :             :    of kind TOKEN_TYPE, potentially add a fix-it hint suggesting the
    9810                 :             :    insertion of the token.
    9811                 :             : 
    9812                 :             :    The location of the attempted fix-it hint depends on TOKEN_TYPE:
    9813                 :             :    it will either be:
    9814                 :             :      (a) immediately after PREV_TOKEN_LOC, or
    9815                 :             : 
    9816                 :             :      (b) immediately before the primary location within RICHLOC (taken to
    9817                 :             :          be that of the token following where the token was expected).
    9818                 :             : 
    9819                 :             :    If we manage to add a fix-it hint, then the location of the
    9820                 :             :    fix-it hint is likely to be more useful as the primary location
    9821                 :             :    of the diagnostic than that of the following token, so we swap
    9822                 :             :    these locations.
    9823                 :             : 
    9824                 :             :    For example, given this bogus code:
    9825                 :             :        123456789012345678901234567890
    9826                 :             :    1 | int missing_semicolon (void)
    9827                 :             :    2 | {
    9828                 :             :    3 |   return 42
    9829                 :             :    4 | }
    9830                 :             : 
    9831                 :             :    we will emit:
    9832                 :             : 
    9833                 :             :      "expected ';' before '}'"
    9834                 :             : 
    9835                 :             :    RICHLOC's primary location is at the closing brace, so before "swapping"
    9836                 :             :    we would emit the error at line 4 column 1:
    9837                 :             : 
    9838                 :             :        123456789012345678901234567890
    9839                 :             :    3 |   return 42  |< fix-it hint emitted for this line
    9840                 :             :      |            ; |
    9841                 :             :    4 | }            |< "expected ';' before '}'" emitted at this line
    9842                 :             :      | ^            |
    9843                 :             : 
    9844                 :             :    It's more useful for the location of the diagnostic to be at the
    9845                 :             :    fix-it hint, so we swap the locations, so the primary location
    9846                 :             :    is at the fix-it hint, with the old primary location inserted
    9847                 :             :    as a secondary location, giving this, with the error at line 3
    9848                 :             :    column 12:
    9849                 :             : 
    9850                 :             :        123456789012345678901234567890
    9851                 :             :    3 |   return 42   |< "expected ';' before '}'" emitted at this line,
    9852                 :             :      |            ^  |   with fix-it hint
    9853                 :             :    4 |            ;  |
    9854                 :             :      | }             |< secondary range emitted here
    9855                 :             :      | ~             |.  */
    9856                 :             : 
    9857                 :             : void
    9858                 :        3229 : maybe_suggest_missing_token_insertion (rich_location *richloc,
    9859                 :             :                                        enum cpp_ttype token_type,
    9860                 :             :                                        location_t prev_token_loc)
    9861                 :             : {
    9862                 :        3229 :   gcc_assert (richloc);
    9863                 :             : 
    9864                 :        3229 :   enum missing_token_insertion_kind mtik
    9865                 :        3229 :     = get_missing_token_insertion_kind (token_type);
    9866                 :             : 
    9867                 :        3229 :   switch (mtik)
    9868                 :             :     {
    9869                 :             :     default:
    9870                 :             :       gcc_unreachable ();
    9871                 :             :       break;
    9872                 :             : 
    9873                 :             :     case MTIK_IMPOSSIBLE:
    9874                 :             :       return;
    9875                 :             : 
    9876                 :         284 :     case MTIK_INSERT_BEFORE_NEXT:
    9877                 :             :       /* Attempt to add the fix-it hint before the primary location
    9878                 :             :          of RICHLOC.  */
    9879                 :         284 :       richloc->add_fixit_insert_before (cpp_type2name (token_type, 0));
    9880                 :         284 :       break;
    9881                 :             : 
    9882                 :        1958 :     case MTIK_INSERT_AFTER_PREV:
    9883                 :             :       /* Attempt to add the fix-it hint after PREV_TOKEN_LOC.  */
    9884                 :        1958 :       richloc->add_fixit_insert_after (prev_token_loc,
    9885                 :             :                                        cpp_type2name (token_type, 0));
    9886                 :        1958 :       break;
    9887                 :             :     }
    9888                 :             : 
    9889                 :             :   /* If we were successful, use the fix-it hint's location as the
    9890                 :             :      primary location within RICHLOC, adding the old primary location
    9891                 :             :      back as a secondary location.  */
    9892                 :        2242 :   if (!richloc->seen_impossible_fixit_p ())
    9893                 :             :     {
    9894                 :        2238 :       fixit_hint *hint = richloc->get_last_fixit_hint ();
    9895                 :        2238 :       location_t hint_loc = hint->get_start_loc ();
    9896                 :        2238 :       location_t old_loc = richloc->get_loc ();
    9897                 :             : 
    9898                 :        2238 :       richloc->set_range (0, hint_loc, SHOW_RANGE_WITH_CARET);
    9899                 :        2238 :       richloc->add_range (old_loc);
    9900                 :             :     }
    9901                 :             : }
    9902                 :             : 
    9903                 :             : /* Potentially emit a note about likely missing '&' or '*',
    9904                 :             :    depending on EXPR and EXPECTED_TYPE.  */
    9905                 :             : 
    9906                 :             : void
    9907                 :        2202 : maybe_emit_indirection_note (location_t loc,
    9908                 :             :                              tree expr, tree expected_type)
    9909                 :             : {
    9910                 :        2202 :   gcc_assert (expr);
    9911                 :        2202 :   gcc_assert (expected_type);
    9912                 :             : 
    9913                 :        2202 :   tree actual_type = TREE_TYPE (expr);
    9914                 :             : 
    9915                 :             :   /* Missing '&'.  */
    9916                 :        2202 :   if (TREE_CODE (expected_type) == POINTER_TYPE
    9917                 :        1224 :       && compatible_types_for_indirection_note_p (actual_type,
    9918                 :        1224 :                                                   TREE_TYPE (expected_type))
    9919                 :        2280 :       && lvalue_p (expr))
    9920                 :             :     {
    9921                 :          43 :       gcc_rich_location richloc (loc);
    9922                 :          43 :       richloc.add_fixit_insert_before ("&");
    9923                 :          43 :       inform (&richloc, "possible fix: take the address with %qs", "&");
    9924                 :          43 :     }
    9925                 :             : 
    9926                 :             :   /* Missing '*'.  */
    9927                 :        2202 :   if (TREE_CODE (actual_type) == POINTER_TYPE
    9928                 :        2202 :       && compatible_types_for_indirection_note_p (TREE_TYPE (actual_type),
    9929                 :             :                                                   expected_type))
    9930                 :             :     {
    9931                 :          78 :       gcc_rich_location richloc (loc);
    9932                 :          78 :       richloc.add_fixit_insert_before ("*");
    9933                 :          78 :       inform (&richloc, "possible fix: dereference with %qs", "*");
    9934                 :          78 :     }
    9935                 :        2202 : }
    9936                 :             : 
    9937                 :             : #if CHECKING_P
    9938                 :             : 
    9939                 :             : namespace selftest {
    9940                 :             : 
    9941                 :             : /* Verify that fold_for_warn on error_mark_node is safe.  */
    9942                 :             : 
    9943                 :             : static void
    9944                 :           3 : test_fold_for_warn ()
    9945                 :             : {
    9946                 :           3 :   ASSERT_EQ (error_mark_node, fold_for_warn (error_mark_node));
    9947                 :           3 : }
    9948                 :             : 
    9949                 :             : /* Run all of the selftests within this file.  */
    9950                 :             : 
    9951                 :             : static void
    9952                 :           3 : c_common_cc_tests ()
    9953                 :             : {
    9954                 :           0 :   test_fold_for_warn ();
    9955                 :           0 : }
    9956                 :             : 
    9957                 :             : /* Run all of the tests within c-family.  */
    9958                 :             : 
    9959                 :             : void
    9960                 :           3 : c_family_tests (void)
    9961                 :             : {
    9962                 :           3 :   c_common_cc_tests ();
    9963                 :           3 :   c_format_cc_tests ();
    9964                 :           3 :   c_indentation_cc_tests ();
    9965                 :           3 :   c_pretty_print_cc_tests ();
    9966                 :           3 :   c_spellcheck_cc_tests ();
    9967                 :           3 :   c_opt_problem_cc_tests ();
    9968                 :             : 
    9969                 :             :   /* According to https://gcc.gnu.org/pipermail/gcc/2021-November/237703.html
    9970                 :             :      this has some language-specific assumptions, so we run it here.  */
    9971                 :           3 :   diagnostics::selftest::context_cc_tests ();
    9972                 :           3 : }
    9973                 :             : 
    9974                 :             : } // namespace selftest
    9975                 :             : 
    9976                 :             : #endif /* #if CHECKING_P */
    9977                 :             : 
    9978                 :             : /* Attempt to locate a suitable location within FILE for a
    9979                 :             :    #include directive to be inserted before.
    9980                 :             :    LOC is the location of the relevant diagnostic.
    9981                 :             : 
    9982                 :             :    Attempt to return the location within FILE immediately
    9983                 :             :    after the last #include within that file, or the start of
    9984                 :             :    that file if it has no #include directives.
    9985                 :             : 
    9986                 :             :    Return UNKNOWN_LOCATION if no suitable location is found,
    9987                 :             :    or if an error occurs.  */
    9988                 :             : 
    9989                 :             : static location_t
    9990                 :         427 : try_to_locate_new_include_insertion_point (const char *file, location_t loc)
    9991                 :             : {
    9992                 :             :   /* Locate the last ordinary map within FILE that ended with a #include.  */
    9993                 :         427 :   const line_map_ordinary *last_include_ord_map = NULL;
    9994                 :             : 
    9995                 :             :   /* ...and the next ordinary map within FILE after that one.  */
    9996                 :         427 :   const line_map_ordinary *last_ord_map_after_include = NULL;
    9997                 :             : 
    9998                 :             :   /* ...and the first ordinary map within FILE.  */
    9999                 :         427 :   const line_map_ordinary *first_ord_map_in_file = NULL;
   10000                 :             : 
   10001                 :             :   /*  Get ordinary map containing LOC (or its expansion).  */
   10002                 :         427 :   const line_map_ordinary *ord_map_for_loc = NULL;
   10003                 :         427 :   linemap_resolve_location (line_table, loc, LRK_MACRO_EXPANSION_POINT,
   10004                 :             :                             &ord_map_for_loc);
   10005                 :         427 :   gcc_assert (ord_map_for_loc);
   10006                 :             : 
   10007                 :       11981 :   for (unsigned int i = 0; i < LINEMAPS_ORDINARY_USED (line_table); i++)
   10008                 :             :     {
   10009                 :       11981 :       const line_map_ordinary *ord_map
   10010                 :       11981 :         = LINEMAPS_ORDINARY_MAP_AT (line_table, i);
   10011                 :             : 
   10012                 :       23962 :       if (const line_map_ordinary *from
   10013                 :       11981 :           = linemap_included_from_linemap (line_table, ord_map))
   10014                 :             :         /* We cannot use pointer equality, because with preprocessed
   10015                 :             :            input all filename strings are unique.  */
   10016                 :        9607 :         if (0 == strcmp (from->to_file, file))
   10017                 :             :           {
   10018                 :       11981 :             last_include_ord_map = from;
   10019                 :       11981 :             last_ord_map_after_include = NULL;
   10020                 :             :           }
   10021                 :             : 
   10022                 :             :       /* Likewise, use strcmp, and reject any line-zero introductory
   10023                 :             :          map.  */
   10024                 :       11981 :       if (ord_map->to_line && 0 == strcmp (ord_map->to_file, file))
   10025                 :             :         {
   10026                 :         669 :           if (!first_ord_map_in_file)
   10027                 :         427 :             first_ord_map_in_file = ord_map;
   10028                 :         669 :           if (last_include_ord_map && !last_ord_map_after_include)
   10029                 :         166 :             last_ord_map_after_include = ord_map;
   10030                 :             :         }
   10031                 :             : 
   10032                 :             :       /* Stop searching when reaching the ord_map containing LOC,
   10033                 :             :          as it makes no sense to provide fix-it hints that appear
   10034                 :             :          after the diagnostic in question.  */
   10035                 :       11981 :       if (ord_map == ord_map_for_loc)
   10036                 :             :         break;
   10037                 :             :     }
   10038                 :             : 
   10039                 :             :   /* Determine where to insert the #include.  */
   10040                 :         427 :   const line_map_ordinary *ord_map_for_insertion;
   10041                 :             : 
   10042                 :             :   /* We want the next ordmap in the file after the last one that's a
   10043                 :             :      #include, but failing that, the start of the file.  */
   10044                 :         427 :   if (last_ord_map_after_include)
   10045                 :             :     ord_map_for_insertion = last_ord_map_after_include;
   10046                 :             :   else
   10047                 :         263 :     ord_map_for_insertion = first_ord_map_in_file;
   10048                 :             : 
   10049                 :         263 :   if (!ord_map_for_insertion)
   10050                 :             :     return UNKNOWN_LOCATION;
   10051                 :             : 
   10052                 :             :   /* The "start_location" is column 0, meaning "the whole line".
   10053                 :             :      rich_location and diagnostics::changes can't cope with this, so use
   10054                 :             :      column 1 instead.  */
   10055                 :         427 :   location_t col_0 = ord_map_for_insertion->start_location;
   10056                 :         427 :   return linemap_position_for_loc_and_offset (line_table, col_0, 1);
   10057                 :             : }
   10058                 :             : 
   10059                 :             : /* A map from filenames to sets of headers added to them, for
   10060                 :             :    ensuring idempotency within maybe_add_include_fixit.  */
   10061                 :             : 
   10062                 :             : /* The values within the map.  We need string comparison as there's
   10063                 :             :    no guarantee that two different diagnostics that are recommending
   10064                 :             :    adding e.g. "<stdio.h>" are using the same buffer.  */
   10065                 :             : 
   10066                 :             : typedef hash_set <const char *, false, nofree_string_hash> per_file_includes_t;
   10067                 :             : 
   10068                 :             : /* The map itself.  We don't need string comparison for the filename keys,
   10069                 :             :    as they come from libcpp.  */
   10070                 :             : 
   10071                 :             : typedef hash_map <const char *, per_file_includes_t *> added_includes_t;
   10072                 :             : static added_includes_t *added_includes;
   10073                 :             : 
   10074                 :             : /* Attempt to add a fix-it hint to RICHLOC, adding "#include HEADER\n"
   10075                 :             :    in a suitable location within the file of RICHLOC's primary
   10076                 :             :    location.
   10077                 :             : 
   10078                 :             :    This function is idempotent: a header will be added at most once to
   10079                 :             :    any given file.
   10080                 :             : 
   10081                 :             :    If OVERRIDE_LOCATION is true, then if a fix-it is added and will be
   10082                 :             :    printed, then RICHLOC's primary location will be replaced by that of
   10083                 :             :    the fix-it hint (for use by "inform" notes where the location of the
   10084                 :             :    issue has already been reported).  */
   10085                 :             : 
   10086                 :             : void
   10087                 :         879 : maybe_add_include_fixit (rich_location *richloc, const char *header,
   10088                 :             :                          bool override_location)
   10089                 :             : {
   10090                 :         879 :   location_t loc = richloc->get_loc ();
   10091                 :         879 :   const char *file = LOCATION_FILE (loc);
   10092                 :         879 :   if (!file)
   10093                 :         452 :     return;
   10094                 :             : 
   10095                 :             :   /* Idempotency: don't add the same header more than once to a given file.  */
   10096                 :         879 :   if (!added_includes)
   10097                 :         344 :     added_includes = new added_includes_t ();
   10098                 :         879 :   per_file_includes_t *&set = added_includes->get_or_insert (file);
   10099                 :         879 :   if (set)
   10100                 :         535 :     if (set->contains (header))
   10101                 :             :       /* ...then we've already added HEADER to that file.  */
   10102                 :             :       return;
   10103                 :         427 :   if (!set)
   10104                 :         344 :     set = new per_file_includes_t ();
   10105                 :         427 :   set->add (header);
   10106                 :             : 
   10107                 :             :   /* Attempt to locate a suitable place for the new directive.  */
   10108                 :         427 :   location_t include_insert_loc
   10109                 :         427 :     = try_to_locate_new_include_insertion_point (file, loc);
   10110                 :         427 :   if (include_insert_loc == UNKNOWN_LOCATION)
   10111                 :             :     return;
   10112                 :             : 
   10113                 :         427 :   char *text = xasprintf ("#include %s\n", header);
   10114                 :         427 :   richloc->add_fixit_insert_before (include_insert_loc, text);
   10115                 :         427 :   free (text);
   10116                 :             : 
   10117                 :         427 :   if (override_location && global_dc->get_source_printing_options ().enabled)
   10118                 :             :     {
   10119                 :             :       /* Replace the primary location with that of the insertion point for the
   10120                 :             :          fix-it hint.
   10121                 :             : 
   10122                 :             :          We use SHOW_LINES_WITHOUT_RANGE so that we don't meaningless print a
   10123                 :             :          caret for the insertion point (or colorize it).
   10124                 :             : 
   10125                 :             :          Hence we print e.g.:
   10126                 :             : 
   10127                 :             :          ../x86_64-pc-linux-gnu/libstdc++-v3/include/vector:74:1: note: msg 2
   10128                 :             :           73 | # include <debug/vector>
   10129                 :             :          +++ |+#include <vector>
   10130                 :             :           74 | #endif
   10131                 :             : 
   10132                 :             :          rather than:
   10133                 :             : 
   10134                 :             :          ../x86_64-pc-linux-gnu/libstdc++-v3/include/vector:74:1: note: msg 2
   10135                 :             :           73 | # include <debug/vector>
   10136                 :             :          +++ |+#include <vector>
   10137                 :             :           74 | #endif
   10138                 :             :              | ^
   10139                 :             : 
   10140                 :             :          avoiding the caret on the first column of line 74.  */
   10141                 :         177 :       richloc->set_range (0, include_insert_loc, SHOW_LINES_WITHOUT_RANGE);
   10142                 :             :     }
   10143                 :             : }
   10144                 :             : 
   10145                 :             : /* Attempt to convert a braced array initializer list CTOR for array
   10146                 :             :    TYPE into a STRING_CST for convenience and efficiency.  Return
   10147                 :             :    the converted string on success or the original ctor on failure.
   10148                 :             :    Also, for non-convertable CTORs which contain RAW_DATA_CST values
   10149                 :             :    among the elts try to extend the range of RAW_DATA_CSTs.  */
   10150                 :             : 
   10151                 :             : static tree
   10152                 :       44749 : braced_list_to_string (tree type, tree ctor, bool member)
   10153                 :             : {
   10154                 :             :   /* Ignore non-members with unknown size like arrays with unspecified
   10155                 :             :      bound.  */
   10156                 :       44749 :   tree typesize = TYPE_SIZE_UNIT (type);
   10157                 :       44749 :   if (!member && !tree_fits_uhwi_p (typesize))
   10158                 :             :     return ctor;
   10159                 :             : 
   10160                 :             :   /* If the target char size differs from the host char size, we'd risk
   10161                 :             :      loosing data and getting object sizes wrong by converting to
   10162                 :             :      host chars.  */
   10163                 :       44733 :   if (TYPE_PRECISION (char_type_node) != CHAR_BIT)
   10164                 :             :     return ctor;
   10165                 :             : 
   10166                 :             :   /* STRING_CST doesn't support wide characters.  */
   10167                 :       44733 :   gcc_checking_assert (TYPE_PRECISION (TREE_TYPE (type)) == CHAR_BIT);
   10168                 :             : 
   10169                 :             :   /* If the array has an explicit bound, use it to constrain the size
   10170                 :             :      of the string.  If it doesn't, be sure to create a string that's
   10171                 :             :      as long as implied by the index of the last zero specified via
   10172                 :             :      a designator, as in:
   10173                 :             :        const char a[] = { [7] = 0 };  */
   10174                 :       44733 :   unsigned HOST_WIDE_INT maxelts;
   10175                 :       44733 :   if (typesize)
   10176                 :             :     {
   10177                 :       44654 :       maxelts = tree_to_uhwi (typesize);
   10178                 :       44654 :       maxelts /= tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type)));
   10179                 :             :     }
   10180                 :             :   else
   10181                 :             :     maxelts = HOST_WIDE_INT_M1U;
   10182                 :             : 
   10183                 :             :   /* Avoid converting initializers for zero-length arrays (but do
   10184                 :             :      create them for flexible array members).  */
   10185                 :       44654 :   if (!maxelts)
   10186                 :             :     return ctor;
   10187                 :             : 
   10188                 :       44584 :   unsigned HOST_WIDE_INT nelts = CONSTRUCTOR_NELTS (ctor);
   10189                 :             : 
   10190                 :       44584 :   auto_vec<char> str;
   10191                 :       44584 :   str.reserve (nelts + 1);
   10192                 :             : 
   10193                 :       44584 :   unsigned HOST_WIDE_INT i, j = HOST_WIDE_INT_M1U;
   10194                 :       44584 :   tree index, value;
   10195                 :       44584 :   bool check_raw_data = false;
   10196                 :             : 
   10197                 :      636043 :   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), i, index, value)
   10198                 :             :     {
   10199                 :      591459 :       if (check_raw_data)
   10200                 :             :         {
   10201                 :             :           /* The preprocessor always surrounds CPP_EMBED tokens in between
   10202                 :             :              CPP_NUMBER and CPP_COMMA tokens.  Try to undo that here now that
   10203                 :             :              the whole initializer is parsed.  E.g. if we have
   10204                 :             :              [0] = 'T', [1] = "his is a #embed tex", [20] = 't'
   10205                 :             :              where the middle value is RAW_DATA_CST and in its owner this is
   10206                 :             :              surrounded by 'T' and 't' characters, we can create from it just
   10207                 :             :              [0] = "This is a #embed text"
   10208                 :             :              Similarly if a RAW_DATA_CST needs to be split into two parts
   10209                 :             :              because of designated init store but the stored value is actually
   10210                 :             :              the same as in the RAW_DATA_OWNER's memory we can merge multiple
   10211                 :             :              RAW_DATA_CSTs.  */
   10212                 :        1178 :           if (TREE_CODE (value) == RAW_DATA_CST
   10213                 :         540 :               && index
   10214                 :         540 :               && tree_fits_uhwi_p (index))
   10215                 :             :             {
   10216                 :         540 :               tree owner = RAW_DATA_OWNER (value);
   10217                 :         540 :               unsigned int start, end, k;
   10218                 :         540 :               if (TREE_CODE (owner) == STRING_CST)
   10219                 :             :                 {
   10220                 :         214 :                   start
   10221                 :         214 :                     = RAW_DATA_POINTER (value) - TREE_STRING_POINTER (owner);
   10222                 :         214 :                   end = TREE_STRING_LENGTH (owner) - RAW_DATA_LENGTH (value);
   10223                 :             :                 }
   10224                 :             :               else
   10225                 :             :                 {
   10226                 :         326 :                   gcc_checking_assert (TREE_CODE (owner) == RAW_DATA_CST);
   10227                 :         326 :                   start
   10228                 :         326 :                     = RAW_DATA_POINTER (value) - RAW_DATA_POINTER (owner);
   10229                 :         326 :                   end = RAW_DATA_LENGTH (owner) - RAW_DATA_LENGTH (value);
   10230                 :             :                 }
   10231                 :         540 :               end -= start;
   10232                 :         540 :               unsigned HOST_WIDE_INT l = j == HOST_WIDE_INT_M1U ? i : j;
   10233                 :         965 :               for (k = 0; k < start && k < l; ++k)
   10234                 :             :                 {
   10235                 :         451 :                   constructor_elt *elt = CONSTRUCTOR_ELT (ctor, l - k - 1);
   10236                 :         902 :                   if (elt->index == NULL_TREE
   10237                 :         451 :                       || !tree_fits_uhwi_p (elt->index)
   10238                 :         451 :                       || !tree_fits_shwi_p (elt->value)
   10239                 :        1348 :                       || wi::to_widest (index) != (wi::to_widest (elt->index)
   10240                 :        1343 :                                                    + (k + 1)))
   10241                 :             :                     break;
   10242                 :         446 :                   if (TYPE_UNSIGNED (TREE_TYPE (value)))
   10243                 :             :                     {
   10244                 :         370 :                       if (tree_to_shwi (elt->value)
   10245                 :         370 :                           != *((const unsigned char *)
   10246                 :         370 :                                RAW_DATA_POINTER (value) - k - 1))
   10247                 :             :                         break;
   10248                 :             :                     }
   10249                 :          76 :                   else if (tree_to_shwi (elt->value)
   10250                 :          76 :                            != *((const signed char *)
   10251                 :          76 :                                 RAW_DATA_POINTER (value) - k - 1))
   10252                 :             :                     break;
   10253                 :             :                 }
   10254                 :         540 :               start = k;
   10255                 :         540 :               l = 0;
   10256                 :        1395 :               for (k = 0; k < end && k + 1 < CONSTRUCTOR_NELTS (ctor) - i; ++k)
   10257                 :             :                 {
   10258                 :         434 :                   constructor_elt *elt = CONSTRUCTOR_ELT (ctor, i + k + 1);
   10259                 :         868 :                   if (elt->index == NULL_TREE
   10260                 :         434 :                       || !tree_fits_uhwi_p (elt->index)
   10261                 :        1302 :                       || (wi::to_widest (elt->index)
   10262                 :         868 :                           != (wi::to_widest (index)
   10263                 :        1302 :                               + (RAW_DATA_LENGTH (value) + l))))
   10264                 :             :                     break;
   10265                 :         434 :                   if (TREE_CODE (elt->value) == RAW_DATA_CST
   10266                 :           2 :                       && RAW_DATA_OWNER (elt->value) == RAW_DATA_OWNER (value)
   10267                 :         434 :                       && (RAW_DATA_POINTER (elt->value)
   10268                 :           2 :                           == RAW_DATA_POINTER (value) + l))
   10269                 :             :                     {
   10270                 :           0 :                       l += RAW_DATA_LENGTH (elt->value);
   10271                 :           0 :                       end -= RAW_DATA_LENGTH (elt->value) - 1;
   10272                 :           0 :                       continue;
   10273                 :             :                     }
   10274                 :         434 :                   if (!tree_fits_shwi_p (elt->value))
   10275                 :             :                     break;
   10276                 :         431 :                   if (TYPE_UNSIGNED (TREE_TYPE (value)))
   10277                 :             :                     {
   10278                 :         377 :                       if (tree_to_shwi (elt->value)
   10279                 :         377 :                           != *((const unsigned char *)
   10280                 :         377 :                                RAW_DATA_POINTER (value)
   10281                 :         377 :                                + RAW_DATA_LENGTH (value) + k))
   10282                 :             :                         break;
   10283                 :             :                     }
   10284                 :          54 :                   else if (tree_to_shwi (elt->value)
   10285                 :          54 :                            != *((const signed char *)
   10286                 :          54 :                                 RAW_DATA_POINTER (value)
   10287                 :          54 :                                 + RAW_DATA_LENGTH (value) + k))
   10288                 :             :                     break;
   10289                 :         396 :                   ++l;
   10290                 :             :                 }
   10291                 :         540 :               end = k;
   10292                 :         540 :               if (start != 0 || end != 0)
   10293                 :             :                 {
   10294                 :         447 :                   if (j == HOST_WIDE_INT_M1U)
   10295                 :         409 :                     j = i - start;
   10296                 :             :                   else
   10297                 :          38 :                     j -= start;
   10298                 :         447 :                   RAW_DATA_POINTER (value) -= start;
   10299                 :         447 :                   RAW_DATA_LENGTH (value) += start + end;
   10300                 :         447 :                   i += end;
   10301                 :         447 :                   if (start == 0)
   10302                 :          22 :                     CONSTRUCTOR_ELT (ctor, j)->index = index;
   10303                 :         447 :                   CONSTRUCTOR_ELT (ctor, j)->value = value;
   10304                 :         447 :                   ++j;
   10305                 :         447 :                   continue;
   10306                 :             :                 }
   10307                 :             :             }
   10308                 :         731 :           if (j != HOST_WIDE_INT_M1U)
   10309                 :             :             {
   10310                 :         175 :               CONSTRUCTOR_ELT (ctor, j)->index = index;
   10311                 :         175 :               CONSTRUCTOR_ELT (ctor, j)->value = value;
   10312                 :         175 :               ++j;
   10313                 :             :             }
   10314                 :         731 :           continue;
   10315                 :         731 :         }
   10316                 :             : 
   10317                 :      590281 :       unsigned HOST_WIDE_INT idx = i;
   10318                 :      590281 :       if (index)
   10319                 :             :         {
   10320                 :      590281 :           if (!tree_fits_uhwi_p (index))
   10321                 :             :             {
   10322                 :          22 :               check_raw_data = true;
   10323                 :          22 :               continue;
   10324                 :             :             }
   10325                 :      590259 :           idx = tree_to_uhwi (index);
   10326                 :             :         }
   10327                 :             : 
   10328                 :             :       /* auto_vec is limited to UINT_MAX elements.  */
   10329                 :      590259 :       if (idx > UINT_MAX)
   10330                 :             :         {
   10331                 :           0 :           check_raw_data = true;
   10332                 :           0 :           continue;
   10333                 :             :         }
   10334                 :             : 
   10335                 :             :       /* Avoid non-constant initializers.  */
   10336                 :      590259 :       if (!tree_fits_shwi_p (value))
   10337                 :             :         {
   10338                 :         644 :           check_raw_data = true;
   10339                 :         644 :           --i;
   10340                 :         644 :           continue;
   10341                 :             :         }
   10342                 :             : 
   10343                 :             :       /* Skip over embedded nuls except the last one (initializer
   10344                 :             :          elements are in ascending order of indices).  */
   10345                 :      589615 :       HOST_WIDE_INT val = tree_to_shwi (value);
   10346                 :      589615 :       if (!val && i + 1 < nelts)
   10347                 :        5950 :         continue;
   10348                 :             : 
   10349                 :      583665 :       if (idx < str.length ())
   10350                 :             :         {
   10351                 :           0 :           check_raw_data = true;
   10352                 :           0 :           continue;
   10353                 :             :         }
   10354                 :             : 
   10355                 :             :       /* Bail if the CTOR has a block of more than 256 embedded nuls
   10356                 :             :          due to implicitly initialized elements.  */
   10357                 :      583665 :       unsigned nchars = (idx - str.length ()) + 1;
   10358                 :      583665 :       if (nchars > 256)
   10359                 :             :         {
   10360                 :           3 :           check_raw_data = true;
   10361                 :           3 :           continue;
   10362                 :             :         }
   10363                 :             : 
   10364                 :      583662 :       if (nchars > 1)
   10365                 :             :         {
   10366                 :        3649 :           str.reserve (idx);
   10367                 :        3649 :           str.quick_grow_cleared (idx);
   10368                 :             :         }
   10369                 :             : 
   10370                 :      583662 :       if (idx >= maxelts)
   10371                 :             :         {
   10372                 :           0 :           check_raw_data = true;
   10373                 :           0 :           continue;
   10374                 :             :         }
   10375                 :             : 
   10376                 :      583662 :       str.safe_insert (idx, val);
   10377                 :             :     }
   10378                 :             : 
   10379                 :       44584 :   if (check_raw_data)
   10380                 :             :     {
   10381                 :         669 :       if (j != HOST_WIDE_INT_M1U)
   10382                 :         409 :         CONSTRUCTOR_ELTS (ctor)->truncate (j);
   10383                 :         669 :       return ctor;
   10384                 :             :     }
   10385                 :             : 
   10386                 :             :   /* Append a nul string termination.  */
   10387                 :       87753 :   if (maxelts != HOST_WIDE_INT_M1U && str.length () < maxelts)
   10388                 :       17129 :     str.safe_push (0);
   10389                 :             : 
   10390                 :             :   /* Build a STRING_CST with the same type as the array.  */
   10391                 :      131745 :   tree res = build_string (str.length (), str.begin ());
   10392                 :       43915 :   TREE_TYPE (res) = type;
   10393                 :       43915 :   return res;
   10394                 :       44584 : }
   10395                 :             : 
   10396                 :             : /* Implementation of the two-argument braced_lists_to_string withe
   10397                 :             :    the same arguments plus MEMBER which is set for struct members
   10398                 :             :    to allow initializers for flexible member arrays.  */
   10399                 :             : 
   10400                 :             : static tree
   10401                 :   175983048 : braced_lists_to_strings (tree type, tree ctor, bool member)
   10402                 :             : {
   10403                 :   175983048 :   if (TREE_CODE (ctor) != CONSTRUCTOR)
   10404                 :             :     return ctor;
   10405                 :             : 
   10406                 :     5081185 :   tree_code code = TREE_CODE (type);
   10407                 :             : 
   10408                 :     5081185 :   tree ttp;
   10409                 :     5081185 :   if (code == ARRAY_TYPE)
   10410                 :      204111 :     ttp = TREE_TYPE (type);
   10411                 :     4877074 :   else if (code == RECORD_TYPE)
   10412                 :             :     {
   10413                 :     4832324 :       ttp = TREE_TYPE (ctor);
   10414                 :     4832324 :       if (TREE_CODE (ttp) == ARRAY_TYPE)
   10415                 :             :         {
   10416                 :      217798 :           type = ttp;
   10417                 :      217798 :           ttp = TREE_TYPE (ttp);
   10418                 :             :         }
   10419                 :             :     }
   10420                 :             :   else
   10421                 :             :     return ctor;
   10422                 :             : 
   10423                 :     5034547 :   if ((TREE_CODE (ttp) == ARRAY_TYPE || TREE_CODE (ttp) == INTEGER_TYPE)
   10424                 :     5309440 :       && TYPE_STRING_FLAG (ttp))
   10425                 :       44749 :     return braced_list_to_string (type, ctor, member);
   10426                 :             : 
   10427                 :     4991686 :   code = TREE_CODE (ttp);
   10428                 :     4991686 :   if (code == ARRAY_TYPE || RECORD_OR_UNION_TYPE_P (ttp))
   10429                 :             :     {
   10430                 :     4667862 :       bool rec = RECORD_OR_UNION_TYPE_P (ttp);
   10431                 :             : 
   10432                 :             :       /* Handle array of arrays or struct member initializers.  */
   10433                 :     4667862 :       tree val;
   10434                 :     4667862 :       unsigned HOST_WIDE_INT idx;
   10435                 :    15233375 :       FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), idx, val)
   10436                 :             :         {
   10437                 :    10565513 :           val = braced_lists_to_strings (ttp, val, rec);
   10438                 :    10565513 :           CONSTRUCTOR_ELT (ctor, idx)->value = val;
   10439                 :             :         }
   10440                 :             :     }
   10441                 :             : 
   10442                 :             :   return ctor;
   10443                 :             : }
   10444                 :             : 
   10445                 :             : /* Attempt to convert a CTOR containing braced array initializer lists
   10446                 :             :    for array TYPE into one containing STRING_CSTs, for convenience and
   10447                 :             :    efficiency.  Recurse for arrays of arrays and member initializers.
   10448                 :             :    Return the converted CTOR or STRING_CST on success or the original
   10449                 :             :    CTOR otherwise.  */
   10450                 :             : 
   10451                 :             : tree
   10452                 :   165417535 : braced_lists_to_strings (tree type, tree ctor)
   10453                 :             : {
   10454                 :   165417535 :   return braced_lists_to_strings (type, ctor, false);
   10455                 :             : }
   10456                 :             : 
   10457                 :             : 
   10458                 :             : /* Emit debug for functions before finalizing early debug.  */
   10459                 :             : 
   10460                 :             : void
   10461                 :      176847 : c_common_finalize_early_debug (void)
   10462                 :             : {
   10463                 :             :   /* Emit early debug for reachable functions, and by consequence,
   10464                 :             :      locally scoped symbols.  Also emit debug for extern declared
   10465                 :             :      functions that are still reachable at this point.  */
   10466                 :      176847 :   struct cgraph_node *cnode;
   10467                 :     8552418 :   FOR_EACH_FUNCTION (cnode)
   10468                 :     3720565 :     if (!cnode->alias && !cnode->thunk
   10469                 :     7816864 :         && (cnode->has_gimple_body_p ()
   10470                 :     1280983 :             || !DECL_IS_UNDECLARED_BUILTIN (cnode->decl)))
   10471                 :     3502927 :       (*debug_hooks->early_global_decl) (cnode->decl);
   10472                 :      176847 : }
   10473                 :             : 
   10474                 :             : /* Determine whether TYPE is an ISO C99 flexible array member type "[]".  */
   10475                 :             : bool
   10476                 :    10320365 : c_flexible_array_member_type_p (const_tree type)
   10477                 :             : {
   10478                 :    10320365 :   if (TREE_CODE (type) == ARRAY_TYPE
   10479                 :     3523794 :       && TYPE_SIZE (type) == NULL_TREE
   10480                 :      465172 :       && TYPE_DOMAIN (type) != NULL_TREE
   10481                 :    10785537 :       && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE)
   10482                 :      465172 :     return true;
   10483                 :             : 
   10484                 :             :   return false;
   10485                 :             : }
   10486                 :             : 
   10487                 :             : /* Get the LEVEL of the strict_flex_array for the ARRAY_FIELD based on the
   10488                 :             :    values of attribute strict_flex_array and the flag_strict_flex_arrays.  */
   10489                 :             : unsigned int
   10490                 :      520568 : c_strict_flex_array_level_of (tree array_field)
   10491                 :             : {
   10492                 :      520568 :   gcc_assert (TREE_CODE (array_field) == FIELD_DECL);
   10493                 :      520568 :   unsigned int strict_flex_array_level = flag_strict_flex_arrays;
   10494                 :             : 
   10495                 :      520568 :   tree attr_strict_flex_array
   10496                 :      520568 :     = lookup_attribute ("strict_flex_array", DECL_ATTRIBUTES (array_field));
   10497                 :             :   /* If there is a strict_flex_array attribute attached to the field,
   10498                 :             :      override the flag_strict_flex_arrays.  */
   10499                 :      520568 :   if (attr_strict_flex_array)
   10500                 :             :     {
   10501                 :             :       /* Get the value of the level first from the attribute.  */
   10502                 :           6 :       unsigned HOST_WIDE_INT attr_strict_flex_array_level = 0;
   10503                 :           6 :       gcc_assert (TREE_VALUE (attr_strict_flex_array) != NULL_TREE);
   10504                 :           6 :       attr_strict_flex_array = TREE_VALUE (attr_strict_flex_array);
   10505                 :           6 :       gcc_assert (TREE_VALUE (attr_strict_flex_array) != NULL_TREE);
   10506                 :           6 :       attr_strict_flex_array = TREE_VALUE (attr_strict_flex_array);
   10507                 :           6 :       gcc_assert (tree_fits_uhwi_p (attr_strict_flex_array));
   10508                 :           6 :       attr_strict_flex_array_level = tree_to_uhwi (attr_strict_flex_array);
   10509                 :             : 
   10510                 :             :       /* The attribute has higher priority than flag_struct_flex_array.  */
   10511                 :           6 :       strict_flex_array_level = attr_strict_flex_array_level;
   10512                 :             :     }
   10513                 :      520568 :   return strict_flex_array_level;
   10514                 :             : }
   10515                 :             : 
   10516                 :             : /* Map from identifiers to booleans.  Value is true for features, and
   10517                 :             :    false for extensions.  Used to implement __has_{feature,extension}.  */
   10518                 :             : 
   10519                 :             : using feature_map_t = hash_map <tree, bool>;
   10520                 :             : static feature_map_t *feature_map;
   10521                 :             : 
   10522                 :             : /* Register a feature for __has_{feature,extension}.  FEATURE_P is true
   10523                 :             :    if the feature identified by NAME is a feature (as opposed to an
   10524                 :             :    extension).  */
   10525                 :             : 
   10526                 :             : void
   10527                 :     1442045 : c_common_register_feature (const char *name, bool feature_p)
   10528                 :             : {
   10529                 :     1442045 :   bool dup = feature_map->put (get_identifier (name), feature_p);
   10530                 :     1442045 :   gcc_checking_assert (!dup);
   10531                 :     1442045 : }
   10532                 :             : 
   10533                 :             : /* Lazily initialize hash table for __has_{feature,extension},
   10534                 :             :    dispatching to the appropriate front end to register language-specific
   10535                 :             :    features.  */
   10536                 :             : 
   10537                 :             : static void
   10538                 :       46651 : init_has_feature ()
   10539                 :             : {
   10540                 :       46651 :   gcc_checking_assert (!feature_map);
   10541                 :       46651 :   feature_map = new feature_map_t;
   10542                 :             : 
   10543                 :      559812 :   for (unsigned i = 0; i < ARRAY_SIZE (has_feature_table); i++)
   10544                 :             :     {
   10545                 :      513161 :       const hf_feature_info *info = has_feature_table + i;
   10546                 :             : 
   10547                 :      513161 :       if ((info->flags & HF_FLAG_SANITIZE) && !(flag_sanitize & info->mask))
   10548                 :      232378 :         continue;
   10549                 :             : 
   10550                 :      280783 :       const bool feature_p = !(info->flags & HF_FLAG_EXT);
   10551                 :      280783 :       c_common_register_feature (info->ident, feature_p);
   10552                 :             :     }
   10553                 :             : 
   10554                 :             :   /* Register language-specific features.  */
   10555                 :       46651 :   c_family_register_lang_features ();
   10556                 :       46651 : }
   10557                 :             : 
   10558                 :             : /* If STRICT_P is true, evaluate __has_feature (IDENT).
   10559                 :             :    Otherwise, evaluate __has_extension (IDENT).  */
   10560                 :             : 
   10561                 :             : bool
   10562                 :      127243 : has_feature_p (const char *ident, bool strict_p)
   10563                 :             : {
   10564                 :      127243 :   if (!feature_map)
   10565                 :       46651 :     init_has_feature ();
   10566                 :             : 
   10567                 :      127243 :   tree name = canonicalize_attr_name (get_identifier (ident));
   10568                 :      127243 :   bool *feat_p = feature_map->get (name);
   10569                 :      127243 :   if (!feat_p)
   10570                 :             :     return false;
   10571                 :             : 
   10572                 :       72009 :   return !strict_p || *feat_p;
   10573                 :             : }
   10574                 :             : 
   10575                 :             : /* This is the slow path of c-common.h's c_hardbool_type_attr.  */
   10576                 :             : 
   10577                 :             : tree
   10578                 :       64235 : c_hardbool_type_attr_1 (tree type, tree *false_value, tree *true_value)
   10579                 :             : {
   10580                 :       64235 :   tree attr = lookup_attribute ("hardbool", TYPE_ATTRIBUTES (type));
   10581                 :       64235 :   if (!attr)
   10582                 :             :     return attr;
   10583                 :             : 
   10584                 :       35375 :   if (false_value)
   10585                 :       18453 :     *false_value = TREE_VALUE (TYPE_VALUES (type));
   10586                 :             : 
   10587                 :       35375 :   if (true_value)
   10588                 :       18817 :     *true_value = TREE_VALUE (TREE_CHAIN (TYPE_VALUES (type)));
   10589                 :             : 
   10590                 :             :   return attr;
   10591                 :             : }
   10592                 :             : 
   10593                 :             : #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.