LCOV - code coverage report
Current view: top level - gcc/c - c-typeck.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 93.8 % 9216 8641
Test Date: 2026-06-20 15:32:29 Functions: 99.5 % 207 206
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Build expressions with type checking for C compiler.
       2              :    Copyright (C) 1987-2026 Free Software Foundation, Inc.
       3              : 
       4              : This file is part of GCC.
       5              : 
       6              : GCC is free software; you can redistribute it and/or modify it under
       7              : the terms of the GNU General Public License as published by the Free
       8              : Software Foundation; either version 3, or (at your option) any later
       9              : version.
      10              : 
      11              : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      12              : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      13              : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      14              : for more details.
      15              : 
      16              : You should have received a copy of the GNU General Public License
      17              : along with GCC; see the file COPYING3.  If not see
      18              : <http://www.gnu.org/licenses/>.  */
      19              : 
      20              : 
      21              : /* This file is part of the C front end.
      22              :    It contains routines to build C expressions given their operands,
      23              :    including computing the types of the result, C-specific error checks,
      24              :    and some optimization.  */
      25              : 
      26              : #include "config.h"
      27              : #include "system.h"
      28              : #include "coretypes.h"
      29              : #include "memmodel.h"
      30              : #include "target.h"
      31              : #include "function.h"
      32              : #include "bitmap.h"
      33              : #include "c-tree.h"
      34              : #include "gimple-expr.h"
      35              : #include "predict.h"
      36              : #include "stor-layout.h"
      37              : #include "trans-mem.h"
      38              : #include "varasm.h"
      39              : #include "stmt.h"
      40              : #include "langhooks.h"
      41              : #include "c-lang.h"
      42              : #include "intl.h"
      43              : #include "tree-iterator.h"
      44              : #include "gimplify.h"
      45              : #include "tree-inline.h"
      46              : #include "omp-general.h"
      47              : #include "c-family/c-objc.h"
      48              : #include "c-family/c-ubsan.h"
      49              : #include "gomp-constants.h"
      50              : #include "spellcheck-tree.h"
      51              : #include "c-family/c-type-mismatch.h"
      52              : #include "stringpool.h"
      53              : #include "attribs.h"
      54              : #include "asan.h"
      55              : #include "realmpfr.h"
      56              : #include "tree-pretty-print-markup.h"
      57              : #include "gcc-urlifier.h"
      58              : 
      59              : /* Possible cases of implicit conversions.  Used to select diagnostic messages
      60              :    and control folding initializers in convert_for_assignment.  */
      61              : enum impl_conv {
      62              :   ic_argpass,
      63              :   ic_assign,
      64              :   ic_init,
      65              :   ic_init_const,
      66              :   ic_return
      67              : };
      68              : 
      69              : /* The level of nesting inside "__alignof__".  */
      70              : int in_alignof;
      71              : 
      72              : /* The level of nesting inside "sizeof".  */
      73              : int in_sizeof;
      74              : 
      75              : /* The level of nesting inside "countof".  */
      76              : int in_countof;
      77              : 
      78              : /* The level of nesting inside "typeof".  */
      79              : int in_typeof;
      80              : 
      81              : /* The level of nesting inside "_Generic".  */
      82              : int in_generic;
      83              : 
      84              : /* True when parsing OpenMP loop expressions.  */
      85              : bool c_in_omp_for;
      86              : 
      87              : /* True when parsing OpenMP map clause.  */
      88              : bool c_omp_array_section_p;
      89              : 
      90              : /* The argument of last parsed sizeof expression, only to be tested
      91              :    if expr.original_code == SIZEOF_EXPR.  */
      92              : tree c_last_sizeof_arg;
      93              : location_t c_last_sizeof_loc;
      94              : 
      95              : /* Nonzero if we might need to print a "missing braces around
      96              :    initializer" message within this initializer.  */
      97              : static int found_missing_braces;
      98              : 
      99              : static bool require_constant_value;
     100              : static bool require_constant_elements;
     101              : static bool require_constexpr_value;
     102              : 
     103              : static tree qualify_type (tree, tree);
     104              : struct comptypes_data;
     105              : static bool tagged_types_tu_compatible_p (const_tree, const_tree,
     106              :                                           struct comptypes_data *);
     107              : static bool comp_target_types (location_t, tree, tree);
     108              : static bool function_types_compatible_p (const_tree, const_tree,
     109              :                                          struct comptypes_data *);
     110              : static bool type_lists_compatible_p (const_tree, const_tree,
     111              :                                      struct comptypes_data *);
     112              : static int convert_arguments (location_t, vec<location_t>, tree,
     113              :                               vec<tree, va_gc> *, vec<tree, va_gc> *, tree,
     114              :                               tree);
     115              : static tree pointer_diff (location_t, tree, tree, tree *);
     116              : static tree convert_for_assignment (location_t, location_t, tree, tree, tree,
     117              :                                     enum impl_conv, bool, tree, tree, int,
     118              :                                     int = 0);
     119              : static tree valid_compound_expr_initializer (tree, tree);
     120              : static void push_string (const char *);
     121              : static void push_member_name (tree);
     122              : static int spelling_length (void);
     123              : static char *print_spelling (char *);
     124              : static void warning_init (location_t, int, const char *);
     125              : static tree digest_init (location_t, tree, tree, tree, tree, bool, bool, bool,
     126              :                          bool, bool, bool);
     127              : static void output_init_element (location_t, tree, tree, bool, tree, tree, bool,
     128              :                                  bool, struct obstack *);
     129              : static void output_pending_init_elements (int, struct obstack *);
     130              : static bool set_designator (location_t, bool, struct obstack *);
     131              : static void push_range_stack (tree, struct obstack *);
     132              : static void add_pending_init (location_t, tree, tree, tree, bool,
     133              :                               struct obstack *);
     134              : static void set_nonincremental_init (struct obstack *);
     135              : static void set_nonincremental_init_from_string (tree, struct obstack *);
     136              : static tree find_init_member (tree, struct obstack *);
     137              : static void readonly_warning (tree, enum lvalue_use);
     138              : static int lvalue_or_else (location_t, const_tree, enum lvalue_use);
     139              : static void record_maybe_used_decl (tree, bool address);
     140              : static bool comptypes_internal (const_tree, const_tree,
     141              :                                 struct comptypes_data *data);
     142              : static bool comptypes_check_for_composite (tree t1, tree t2);
     143              : static bool handle_counted_by_p (tree);
     144              : static bool top_array_vla_p (const_tree type);
     145              : 
     146              : 
     147              : /* Return true if EXP is a null pointer constant, false otherwise.  */
     148              : 
     149              : bool
     150    188689036 : null_pointer_constant_p (const_tree expr)
     151              : {
     152              :   /* This should really operate on c_expr structures, but they aren't
     153              :      yet available everywhere required.  */
     154    188689036 :   tree type = TREE_TYPE (expr);
     155              : 
     156              :   /* An integer constant expression with the value 0, such an expression
     157              :      cast to type void*, or the predefined constant nullptr, are a null
     158              :      pointer constant.  */
     159    188689036 :   if (expr == nullptr_node)
     160              :     return true;
     161              : 
     162    188688352 :   return (TREE_CODE (expr) == INTEGER_CST
     163     19120845 :           && !TREE_OVERFLOW (expr)
     164     19120748 :           && integer_zerop (expr)
     165    192632319 :           && (INTEGRAL_TYPE_P (type)
     166       337576 :               || (TREE_CODE (type) == POINTER_TYPE
     167       337574 :                   && VOID_TYPE_P (TREE_TYPE (type))
     168       262287 :                   && TYPE_QUALS (TREE_TYPE (type)) == TYPE_UNQUALIFIED)));
     169              : }
     170              : 
     171              : /* EXPR may appear in an unevaluated part of an integer constant
     172              :    expression, but not in an evaluated part.  Wrap it in a
     173              :    C_MAYBE_CONST_EXPR, or mark it with TREE_OVERFLOW if it is just an
     174              :    INTEGER_CST and we cannot create a C_MAYBE_CONST_EXPR.  */
     175              : 
     176              : static tree
     177        62368 : note_integer_operands (tree expr)
     178              : {
     179        62368 :   tree ret;
     180        62368 :   if (TREE_CODE (expr) == INTEGER_CST && in_late_binary_op)
     181              :     {
     182           22 :       ret = copy_node (expr);
     183           22 :       TREE_OVERFLOW (ret) = 1;
     184              :     }
     185              :   else
     186              :     {
     187        62346 :       ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (expr), NULL_TREE, expr);
     188        62346 :       C_MAYBE_CONST_EXPR_INT_OPERANDS (ret) = 1;
     189              :     }
     190        62368 :   return ret;
     191              : }
     192              : 
     193              : /* Having checked whether EXPR may appear in an unevaluated part of an
     194              :    integer constant expression and found that it may, remove any
     195              :    C_MAYBE_CONST_EXPR noting this fact and return the resulting
     196              :    expression.  */
     197              : 
     198              : static inline tree
     199     33840641 : remove_c_maybe_const_expr (tree expr)
     200              : {
     201     33840641 :   if (TREE_CODE (expr) == C_MAYBE_CONST_EXPR)
     202        61517 :     return C_MAYBE_CONST_EXPR_EXPR (expr);
     203              :   else
     204              :     return expr;
     205              : }
     206              : 
     207              : /* This is a cache to hold if two types are seen.  */
     208              : 
     209              : struct tagged_tu_seen_cache {
     210              :   const struct tagged_tu_seen_cache * next;
     211              :   const_tree t1;
     212              :   const_tree t2;
     213              : };
     214              : 
     215              : /* Do `exp = require_complete_type (loc, exp);' to make sure exp
     216              :    does not have an incomplete type.  (That includes void types.)
     217              :    LOC is the location of the use.  */
     218              : 
     219              : tree
     220    775756991 : require_complete_type (location_t loc, tree value)
     221              : {
     222    775756991 :   tree type = TREE_TYPE (value);
     223              : 
     224    775756991 :   if (error_operand_p (value))
     225         9215 :     return error_mark_node;
     226              : 
     227              :   /* First, detect a valid value with a complete type.  */
     228    775747776 :   if (COMPLETE_TYPE_P (type))
     229              :     return value;
     230              : 
     231          164 :   c_incomplete_type_error (loc, value, type);
     232          164 :   return error_mark_node;
     233              : }
     234              : 
     235              : /* Print an error message for invalid use of an incomplete type.
     236              :    VALUE is the expression that was used (or 0 if that isn't known)
     237              :    and TYPE is the type that was invalid.  LOC is the location for
     238              :    the error.  */
     239              : 
     240              : void
     241          232 : c_incomplete_type_error (location_t loc, const_tree value, const_tree type)
     242              : {
     243              :   /* Avoid duplicate error message.  */
     244          232 :   if (TREE_CODE (type) == ERROR_MARK)
     245              :     return;
     246              : 
     247          232 :   if (value != NULL_TREE && (VAR_P (value) || TREE_CODE (value) == PARM_DECL))
     248           98 :     error_at (loc, "%qD has an incomplete type %qT", value, type);
     249              :   else
     250              :     {
     251          134 :     retry:
     252              :       /* We must print an error message.  Be clever about what it says.  */
     253              : 
     254          134 :       switch (TREE_CODE (type))
     255              :         {
     256           90 :         case RECORD_TYPE:
     257           90 :         case UNION_TYPE:
     258           90 :         case ENUMERAL_TYPE:
     259           90 :           break;
     260              : 
     261           38 :         case VOID_TYPE:
     262           38 :           error_at (loc, "invalid use of void expression");
     263           38 :           return;
     264              : 
     265            6 :         case ARRAY_TYPE:
     266            6 :           if (TYPE_DOMAIN (type))
     267              :             {
     268            3 :               if (TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL)
     269              :                 {
     270            3 :                   error_at (loc, "invalid use of flexible array member");
     271            3 :                   return;
     272              :                 }
     273            0 :               type = TREE_TYPE (type);
     274            0 :               goto retry;
     275              :             }
     276            3 :           error_at (loc, "invalid use of array with unspecified bounds");
     277            3 :           return;
     278              : 
     279            0 :         default:
     280            0 :           gcc_unreachable ();
     281              :         }
     282              : 
     283           90 :       if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
     284           88 :         error_at (loc, "invalid use of undefined type %qT", type);
     285              :       else
     286              :         /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL.  */
     287            2 :         error_at (loc, "invalid use of incomplete typedef %qT", type);
     288              :     }
     289              : }
     290              : 
     291              : /* Given a type, apply default promotions wrt unnamed function
     292              :    arguments and return the new type.  */
     293              : 
     294              : tree
     295    125180819 : c_type_promotes_to (tree type)
     296              : {
     297    125180819 :   tree ret = NULL_TREE;
     298              : 
     299    125180819 :   if (TYPE_MAIN_VARIANT (type) == float_type_node)
     300      1617447 :     ret = double_type_node;
     301    123563372 :   else if (c_promoting_integer_type_p (type))
     302              :     {
     303              :       /* Preserve unsignedness if not really getting any wider.  */
     304     18660806 :       if (TYPE_UNSIGNED (type)
     305     18660806 :           && (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)))
     306            0 :         ret = unsigned_type_node;
     307              :       else
     308     18660806 :         ret = integer_type_node;
     309              :     }
     310              : 
     311     20278253 :   if (ret != NULL_TREE)
     312     20278253 :     return (TYPE_ATOMIC (type)
     313     20278253 :             ? c_build_qualified_type (ret, TYPE_QUAL_ATOMIC)
     314              :             : ret);
     315              : 
     316              :   return type;
     317              : }
     318              : 
     319              : /* Return true if between two named address spaces, whether there is a superset
     320              :    named address space that encompasses both address spaces.  If there is a
     321              :    superset, return which address space is the superset.  */
     322              : 
     323              : static bool
     324      7615214 : addr_space_superset (addr_space_t as1, addr_space_t as2, addr_space_t *common)
     325              : {
     326      7615214 :   if (as1 == as2)
     327              :     {
     328      7615214 :       *common = as1;
     329      7615214 :       return true;
     330              :     }
     331            0 :   else if (targetm.addr_space.subset_p (as1, as2))
     332              :     {
     333            0 :       *common = as2;
     334            0 :       return true;
     335              :     }
     336            0 :   else if (targetm.addr_space.subset_p (as2, as1))
     337              :     {
     338            0 :       *common = as1;
     339            0 :       return true;
     340              :     }
     341              :   else
     342              :     return false;
     343              : }
     344              : 
     345              : /* Return a variant of TYPE which has all the type qualifiers of LIKE
     346              :    as well as those of TYPE.  */
     347              : 
     348              : static tree
     349      2849948 : qualify_type (tree type, tree like)
     350              : {
     351      2849948 :   addr_space_t as_type = TYPE_ADDR_SPACE (type);
     352      2849948 :   addr_space_t as_like = TYPE_ADDR_SPACE (like);
     353      2849948 :   addr_space_t as_common;
     354              : 
     355              :   /* If the two named address spaces are different, determine the common
     356              :      superset address space.  If there isn't one, raise an error.  */
     357      2849948 :   if (!addr_space_superset (as_type, as_like, &as_common))
     358              :     {
     359            0 :       as_common = as_type;
     360            0 :       error ("%qT and %qT are in disjoint named address spaces",
     361              :              type, like);
     362              :     }
     363              : 
     364      5699896 :   return c_build_qualified_type (type,
     365      2849948 :                                  TYPE_QUALS_NO_ADDR_SPACE (type)
     366      2849948 :                                  | TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (like)
     367      2849948 :                                  | ENCODE_QUAL_ADDR_SPACE (as_common));
     368              : }
     369              : 
     370              : 
     371              : /* Check consistency of type TYPE.  For derived types, we test that
     372              :    C_TYPE_VARIABLE_SIZE and C_TYPE_VARIABLY_MODIFIED are consistent with
     373              :    the requirements of the base type.  We also check that arrays with a
     374              :    non-constant length are marked with C_TYPE_VARIABLE_SIZE. If any
     375              :    inconsistency is detected false is returned and true otherwise.  */
     376              : 
     377              : static bool
     378    141394195 : c_verify_type (tree type)
     379              : {
     380    141394195 :   switch (TREE_CODE (type))
     381              :     {
     382     67330365 :     case POINTER_TYPE:
     383     67330365 :     case FUNCTION_TYPE:
     384     67330365 :     case ARRAY_TYPE:
     385              :       /* Pointer, array, functions are variably modified if and only if the
     386              :          target, element, return type is variably modified.  */
     387     67330365 :       if (!TYPE_STRUCTURAL_EQUALITY_P (type)
     388     67330365 :           && (C_TYPE_VARIABLY_MODIFIED (type)
     389     66944175 :               != C_TYPE_VARIABLY_MODIFIED (TREE_TYPE (type))))
     390              :         return false;
     391              :       /* If the target type is structural equality, the type should also. */
     392     67330365 :       if (!TYPE_STRUCTURAL_EQUALITY_P (type)
     393     67330365 :           && TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (type)))
     394              :         return false;
     395              : 
     396    141394195 :      default:
     397    141394195 :        break;
     398              :     }
     399              : 
     400    141394195 :   switch (TREE_CODE (type))
     401              :     {
     402     66412554 :     case POINTER_TYPE:
     403     66412554 :     case FUNCTION_TYPE:
     404              :       /* Pointer and functions can not have variable size.  */
     405     66412554 :       if (C_TYPE_VARIABLE_SIZE (type))
     406            0 :         return false;
     407              :       break;
     408       917811 :     case ARRAY_TYPE:
     409              :       /* An array has variable size if and only if it has a non-constant
     410              :          dimensions or its element type has variable size.  */
     411       917811 :       if ((C_TYPE_VARIABLE_SIZE (TREE_TYPE (type))
     412       917811 :            || top_array_vla_p (type))
     413       917811 :           != C_TYPE_VARIABLE_SIZE (type))
     414              :         return false;
     415              :       /* If the element type or the array has variable size, then the
     416              :          array has variable size and is variably modified.  */
     417       917811 :       if (C_TYPE_VARIABLE_SIZE (TREE_TYPE (type))
     418       917811 :           || C_TYPE_VARIABLE_SIZE (type))
     419              :         {
     420        27693 :           if (!C_TYPE_VARIABLE_SIZE (type))
     421              :             return false;
     422        27693 :           if (!C_TYPE_VARIABLY_MODIFIED (type))
     423            0 :             return false;
     424              :         }
     425              :     default:
     426              :       break;
     427              :     }
     428              :   return true;
     429              : }
     430              : 
     431              : /* Propagate C_TYPE_VARIABLY_MODIFIED and C_TYPE_VARIABLE_SIZE
     432              :    from a base type to a newly built derived or qualified type.  */
     433              : 
     434              : static tree
     435    134359727 : c_set_type_bits (tree new_type, tree old_type)
     436              : {
     437    134359727 :   gcc_checking_assert (c_verify_type (old_type));
     438              : 
     439    134359727 :   if (c_type_variably_modified_p (old_type))
     440        28342 :     C_TYPE_VARIABLY_MODIFIED (new_type) = true;
     441              : 
     442    134359727 :   if (TREE_CODE (new_type) == ARRAY_TYPE && C_TYPE_VARIABLE_SIZE (old_type))
     443              :     {
     444        16808 :       C_TYPE_VARIABLY_MODIFIED (new_type) = true;
     445        16808 :       C_TYPE_VARIABLE_SIZE (new_type) = true;
     446              :     }
     447    134359727 :   return new_type;
     448              : }
     449              : 
     450              : /* Build a pointer type using the default pointer mode.  */
     451              : 
     452              : tree
     453     71706276 : c_build_pointer_type (tree to_type)
     454              : {
     455     71706276 :   addr_space_t as = to_type == error_mark_node ? ADDR_SPACE_GENERIC
     456     71706276 :                                                : TYPE_ADDR_SPACE (to_type);
     457     71706276 :   machine_mode pointer_mode;
     458              : 
     459     71706276 :   if (as != ADDR_SPACE_GENERIC || c_default_pointer_mode == VOIDmode)
     460     71706276 :     pointer_mode = targetm.addr_space.pointer_mode (as);
     461              :   else
     462              :     pointer_mode = c_default_pointer_mode;
     463              : 
     464     71706276 :   return c_build_pointer_type_for_mode (to_type, pointer_mode, false);
     465              : }
     466              : 
     467              : /* Build a pointer type using the given mode.  */
     468              : 
     469              : tree
     470     71954846 : c_build_pointer_type_for_mode (tree type, machine_mode mode, bool m)
     471              : {
     472     71954846 :   tree ret = build_pointer_type_for_mode (type, mode, m);
     473     71954846 :   return c_set_type_bits (ret, type);
     474              : }
     475              : 
     476              : /* Build a function type.  */
     477              : 
     478              : tree
     479     53811989 : c_build_function_type (tree type, tree args, bool no)
     480              : {
     481     53811989 :   tree ret = build_function_type (type, args, no);
     482     53811989 :   return c_set_type_bits (ret, type);
     483              : }
     484              : 
     485              : /* Build an array type.  This sets typeless storage as required
     486              :    by C2Y and C_TYPE_VARIABLY_MODIFIED and C_TYPE_VARIABLE_SIZE
     487              :    based on the element type and domain.  */
     488              : 
     489              : tree
     490      1161544 : c_build_array_type (tree type, tree domain)
     491              : {
     492      1161544 :   int type_quals = TYPE_QUALS (type);
     493              : 
     494              :   /* Identify typeless storage as introduced in C2Y
     495              :      and supported also in earlier language modes.  */
     496      1725534 :   bool typeless = (char_type_p (type) && !(type_quals & TYPE_QUAL_ATOMIC))
     497      1161544 :                   || (AGGREGATE_TYPE_P (type) && TYPE_TYPELESS_STORAGE (type));
     498              : 
     499      1161544 :   tree ret = build_array_type (type, domain, typeless);
     500              : 
     501      1161544 :   if (top_array_vla_p (ret))
     502              :     {
     503        24268 :       C_TYPE_VARIABLE_SIZE (ret) = 1;
     504        24268 :       C_TYPE_VARIABLY_MODIFIED (ret) = 1;
     505              :     }
     506              : 
     507      1161544 :   return c_set_type_bits (ret, type);
     508              : }
     509              : 
     510              : 
     511              : /* Build an array type of unspecified size.  */
     512              : tree
     513          151 : c_build_array_type_unspecified (tree type)
     514              : {
     515          151 :   tree upper = build2 (COMPOUND_EXPR, TREE_TYPE (size_zero_node),
     516              :                        integer_zero_node, size_zero_node);
     517          151 :   return c_build_array_type (type, build_index_type (upper));
     518              : }
     519              : 
     520              : 
     521              : tree
     522      7431348 : c_build_type_attribute_qual_variant (tree type, tree attrs, int quals)
     523              : {
     524      7431348 :   tree ret = build_type_attribute_qual_variant (type, attrs, quals);
     525      7431348 :   return c_set_type_bits (ret, type);
     526              : }
     527              : 
     528              : tree
     529      7241760 : c_build_type_attribute_variant (tree type, tree attrs)
     530              : {
     531      7241760 :   return c_build_type_attribute_qual_variant (type, attrs, TYPE_QUALS (type));
     532              : }
     533              : 
     534              : /* Reconstruct a complex derived type.  This is used to re-construct types
     535              :    with the vector attribute.  It is called via a langhook.  */
     536              : 
     537              : tree
     538       841897 : c_reconstruct_complex_type (tree type, tree bottom)
     539              : {
     540       841897 :   tree inner, outer;
     541              : 
     542       841897 :   if (TREE_CODE (type) == POINTER_TYPE)
     543              :     {
     544       175172 :       inner = c_reconstruct_complex_type (TREE_TYPE (type), bottom);
     545       175172 :       outer = c_build_pointer_type_for_mode (inner, TYPE_MODE (type),
     546       175172 :                                              TYPE_REF_CAN_ALIAS_ALL (type));
     547              :     }
     548              :   else if (TREE_CODE (type) == ARRAY_TYPE)
     549              :     {
     550         7446 :       bool rso = TYPE_REVERSE_STORAGE_ORDER (type);
     551         7446 :       inner = c_reconstruct_complex_type (TREE_TYPE (type), bottom);
     552         7446 :       outer = c_build_array_type (inner, TYPE_DOMAIN (type));
     553         7446 :       if (rso)
     554              :         {
     555            1 :           outer = build_distinct_type_copy (outer);
     556            1 :           TYPE_REVERSE_STORAGE_ORDER (outer) = 1;
     557              :         }
     558              : 
     559         7446 :       gcc_checking_assert (C_TYPE_VARIABLE_SIZE (type)
     560              :                            == C_TYPE_VARIABLE_SIZE (outer));
     561              :     }
     562              :   else if (TREE_CODE (type) == FUNCTION_TYPE)
     563              :     {
     564          594 :       inner = c_reconstruct_complex_type (TREE_TYPE (type), bottom);
     565          594 :       outer = c_build_function_type (inner, TYPE_ARG_TYPES (type),
     566          594 :                                      TYPE_NO_NAMED_ARGS_STDARG_P (type));
     567              :     }
     568              :   else if (TREE_CODE (type) == REFERENCE_TYPE
     569              :            || TREE_CODE (type) == OFFSET_TYPE)
     570            0 :     gcc_unreachable ();
     571              :   else
     572              :     return bottom;
     573              : 
     574       183212 :   return c_build_type_attribute_qual_variant (outer, TYPE_ATTRIBUTES (type),
     575       366424 :                                               TYPE_QUALS (type));
     576              : }
     577              : 
     578              : 
     579              : /* Helper function for c_canonical_type.  Check whether FIELD
     580              :    contains a pointer to a structure or union with tag,
     581              :    possibly nested in other type derivations, and return the
     582              :    type of this nested structure or union.  */
     583              : static tree
     584      3443358 : ptr_to_tagged_member (tree field)
     585              : {
     586      3443358 :   gcc_assert (FIELD_DECL == TREE_CODE (field));
     587      3443358 :   tree type = TREE_TYPE (field);
     588      3443358 :   bool ptr_seen = false;
     589      3443358 :   while (TREE_CODE (type) == ARRAY_TYPE
     590              :          || TREE_CODE (type) == FUNCTION_TYPE
     591      4720479 :          || TREE_CODE (type) == POINTER_TYPE)
     592              :     {
     593      1277121 :       if (TREE_CODE (type) == POINTER_TYPE)
     594       700563 :         ptr_seen = true;
     595      1277121 :       type = TREE_TYPE (type);
     596              :     }
     597              : 
     598      3443358 :   if (ptr_seen
     599       680338 :       && RECORD_OR_UNION_TYPE_P (type)
     600      3692122 :       && NULL_TREE != c_type_tag (type))
     601              :     return type;
     602              : 
     603              :   return NULL_TREE;
     604              : }
     605              : 
     606              : /* For a record or union type, make necessary adaptations so that the
     607              :    type can be used as TYPE_CANONICAL.
     608              : 
     609              :    If the TYPE contains a pointer (possibly nested in other type
     610              :    derivations) to a structure or union as a member, create a copy and
     611              :    change the nested type to an incomplete type.  Otherwise, the middle-end
     612              :    gets confused when recording component aliases in the case where we
     613              :    have formed equivalency classes that include types for which these
     614              :    member pointers end up pointing to other structure or unions types
     615              :    which have the same tag but are not compatible.  */
     616              : tree
     617       888170 : c_type_canonical (tree type)
     618              : {
     619       888170 :   gcc_assert (RECORD_OR_UNION_TYPE_P (type));
     620              : 
     621       888170 :   bool needs_mod = false;
     622      3635860 :   for (tree x = TYPE_FIELDS (type); x; x = DECL_CHAIN (x))
     623              :     {
     624      2829490 :       if (!ptr_to_tagged_member (x))
     625      2747690 :         continue;
     626              :       needs_mod = true;
     627              :       break;
     628              :     }
     629       888170 :   if (!needs_mod)
     630              :     return type;
     631              : 
     632              :   /* Construct new version with such members replaced.  */
     633        81800 :   tree n = build_distinct_type_copy (type);
     634        81800 :   tree *fields = &TYPE_FIELDS (n);
     635       695668 :   for (tree x = TYPE_FIELDS (type); x; x = DECL_CHAIN (x))
     636              :     {
     637       613868 :       tree f = copy_node (x);
     638       613868 :       if (tree m = ptr_to_tagged_member (x))
     639              :         {
     640       162809 :           tree new_node = make_node (TREE_CODE (m));
     641       162809 :           TYPE_NAME (new_node) = TYPE_NAME (m);
     642       162809 :           SET_TYPE_STRUCTURAL_EQUALITY (new_node);
     643       162809 :           new_node = qualify_type (new_node, m);
     644       162809 :           TREE_TYPE (f) = c_reconstruct_complex_type (TREE_TYPE (x),
     645              :                                                       new_node);
     646              :         }
     647       613868 :       *fields = f;
     648       613868 :       fields = &DECL_CHAIN (f);
     649              :     }
     650        81800 :   TYPE_CANONICAL (n) = n;
     651        81800 :   return n;
     652              : }
     653              : 
     654              : 
     655              : /* If NTYPE is a type of a non-variadic function with a prototype
     656              :    and OTYPE is a type of a function without a prototype and ATTRS
     657              :    contains attribute format, diagnosess and removes it from ATTRS.
     658              :    Returns the result of build_type_attribute_variant of NTYPE and
     659              :    the (possibly) modified ATTRS.  */
     660              : 
     661              : static tree
     662        10757 : c_build_functype_attribute_variant (tree ntype, tree otype, tree attrs)
     663              : {
     664        10757 :   if (!prototype_p (otype)
     665        10745 :       && prototype_p (ntype)
     666        21472 :       && lookup_attribute ("format", attrs))
     667              :     {
     668           14 :       warning_at (input_location, OPT_Wattributes,
     669              :                   "%qs attribute can only be applied to variadic functions",
     670              :                   "format");
     671           14 :       attrs = remove_attribute ("format", attrs);
     672              :     }
     673        10757 :   return c_build_type_attribute_variant (ntype, attrs);
     674              : 
     675              : }
     676              : 
     677              : /* Given a type which could be a typedef name, make sure to return the
     678              :    original type.  See set_underlying_type. */
     679              : static const_tree
     680     62605426 : c_type_original (const_tree t)
     681              : {
     682              :   /* It may even be a typedef of a typedef...
     683              :      In the case of compiler-created builtin structs the TYPE_DECL
     684              :      may be a dummy, with no DECL_ORIGINAL_TYPE.  Don't fault.  */
     685     62605426 :   while (TYPE_NAME (t)
     686     32255958 :          && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL
     687     62649546 :          && DECL_ORIGINAL_TYPE (TYPE_NAME (t)))
     688        22058 :     t = DECL_ORIGINAL_TYPE (TYPE_NAME (t));
     689     62605426 :   return t;
     690              : }
     691              : 
     692              : /* Return the tag for a tagged type.  */
     693              : tree
     694     62605426 : c_type_tag (const_tree t)
     695              : {
     696     62605426 :   gcc_assert (RECORD_OR_UNION_TYPE_P (t) || TREE_CODE (t) == ENUMERAL_TYPE);
     697     62605426 :   const_tree orig = c_type_original (t);
     698     62605426 :   tree name = TYPE_NAME (orig);
     699     62605426 :   if (!name)
     700              :     return NULL_TREE;
     701     32233900 :   if (TREE_CODE (name) == TYPE_DECL)
     702              :     {
     703            4 :       if (!DECL_NAME (name))
     704              :         return NULL_TREE;
     705            2 :       name = DECL_NAME (name);
     706              :     }
     707     32233898 :   gcc_checking_assert (TREE_CODE (name) == IDENTIFIER_NODE);
     708              :   return name;
     709              : }
     710              : 
     711              : /* Remove qualifiers but not atomic.  For arrays remove qualifiers
     712              :    on the element type but also do not remove atomic.  */
     713              : static tree
     714     63943623 : remove_qualifiers (tree t)
     715              : {
     716     63943623 :   if (!t || t == error_mark_node)
     717              :     return t;
     718     63943598 :   return TYPE_ATOMIC (strip_array_types (t))
     719     63943598 :          ? c_build_qualified_type (TYPE_MAIN_VARIANT (t), TYPE_QUAL_ATOMIC)
     720     63928023 :          : TYPE_MAIN_VARIANT (t);
     721              : }
     722              : 
     723              : 
     724              : /* Helper function for composite_type_internal.  Find a compatible type
     725              :    in a (transparent) union U compatible to T.  If found, return the
     726              :    type of the corresponding member.  Otherwise, return the union type U.  */
     727              : static tree
     728      8452262 : transparent_union_replacement (tree u, tree t)
     729              : {
     730      8452257 :   if (u == error_mark_node || t == error_mark_node
     731      8452252 :       || TREE_CODE (u) != UNION_TYPE
     732           64 :       || !(TYPE_TRANSPARENT_AGGR (u) || TYPE_NAME (u) == NULL_TREE)
     733      8452326 :       || comptypes (u, t))
     734      8452198 :     return u;
     735              : 
     736           80 :   for (tree memb = TYPE_FIELDS (u); memb; memb = DECL_CHAIN (memb))
     737              :     {
     738           80 :       tree m = remove_qualifiers (TREE_TYPE (memb));
     739           80 :       if (comptypes (m, t))
     740              :         {
     741           64 :           pedwarn (input_location, OPT_Wpedantic,
     742              :                     "function types not truly compatible in ISO C");
     743           64 :           return m;
     744              :         }
     745              :     }
     746              : 
     747              :   return u;
     748              : }
     749              : 
     750              : 
     751              : 
     752              : /* Return the composite type of two compatible types.
     753              : 
     754              :    We assume that comptypes has already been done and returned
     755              :    nonzero; if that isn't so, this may crash.  In particular, we
     756              :    assume that qualifiers match.  */
     757              : 
     758              : struct composite_cache {
     759              :   tree t1;
     760              :   tree t2;
     761              :   tree composite;
     762              :   struct composite_cache* next;
     763              : };
     764              : 
     765              : tree
     766     13374487 : composite_type_internal (tree t1, tree t2, tree cond,
     767              :                          struct composite_cache* cache)
     768              : {
     769     13374487 :   enum tree_code code1;
     770     13374487 :   enum tree_code code2;
     771     13374487 :   tree attributes;
     772              : 
     773              :   /* Save time if the two types are the same.  */
     774              : 
     775     13374487 :   if (t1 == t2) return t1;
     776              : 
     777              :   /* If one type is nonsense, use the other.  */
     778      2722196 :   if (t1 == error_mark_node)
     779              :     return t2;
     780      2722192 :   if (t2 == error_mark_node)
     781              :     return t1;
     782              : 
     783      2722190 :   code1 = TREE_CODE (t1);
     784      2722190 :   code2 = TREE_CODE (t2);
     785              : 
     786              :   /* Merge the attributes.  */
     787      2722190 :   attributes = targetm.merge_type_attributes (t1, t2);
     788              : 
     789              :   /* If one is an enumerated type and the other is the compatible
     790              :      integer type, the composite type might be either of the two
     791              :      (DR#013 question 3).  For consistency, use the enumerated type as
     792              :      the composite type.  */
     793              : 
     794      2722190 :   if (code1 == ENUMERAL_TYPE
     795          194 :       && (code2 == INTEGER_TYPE
     796          194 :           || code2 == BOOLEAN_TYPE))
     797              :     return t1;
     798      2721996 :   if (code2 == ENUMERAL_TYPE
     799           69 :       && (code1 == INTEGER_TYPE
     800           69 :           || code1 == BOOLEAN_TYPE))
     801              :     return t2;
     802              : 
     803      2721927 :   gcc_assert (code1 == code2);
     804              : 
     805      2721927 :   switch (code1)
     806              :     {
     807         6376 :     case POINTER_TYPE:
     808              :       /* For two pointers, do this recursively on the target type.  */
     809         6376 :       {
     810         6376 :         gcc_checking_assert (TYPE_QUALS (t1) == TYPE_QUALS (t2));
     811         6376 :         tree target = composite_type_internal (TREE_TYPE (t1), TREE_TYPE (t2),
     812              :                                                cond, cache);
     813         6376 :         tree n = c_build_pointer_type_for_mode (target, TYPE_MODE (t1), false);
     814        12752 :         return c_build_type_attribute_qual_variant (n, attributes,
     815         6376 :                                                     TYPE_QUALS (t2));
     816              :       }
     817              : 
     818        10996 :     case ARRAY_TYPE:
     819        10996 :       {
     820        10996 :         tree d1 = TYPE_DOMAIN (t1);
     821        10996 :         tree d2 = TYPE_DOMAIN (t2);
     822              : 
     823              :         /* We should not have any type quals on arrays at all.  */
     824        10996 :         gcc_assert (!TYPE_QUALS_NO_ADDR_SPACE (t1)
     825              :                     && !TYPE_QUALS_NO_ADDR_SPACE (t2));
     826              : 
     827        10996 :         bool t1_complete = COMPLETE_TYPE_P (t1);
     828        10996 :         bool t2_complete = COMPLETE_TYPE_P (t2);
     829              : 
     830        10996 :         bool d1_zero = d1 == NULL_TREE || !TYPE_MAX_VALUE (d1);
     831        10996 :         bool d2_zero = d2 == NULL_TREE || !TYPE_MAX_VALUE (d2);
     832              : 
     833        10996 :         bool d1_variable = top_array_vla_p (t1);
     834        10996 :         bool d2_variable = top_array_vla_p (t2);
     835              : 
     836        10996 :         bool use1 = d1 && (d2_variable || d2_zero || !d1_variable);
     837        10996 :         bool use2 = d2 && (d1_variable || d1_zero || !d2_variable);
     838              : 
     839              :         /* If the first is an unspecified size pick the other one.  */
     840         9014 :         if (d2_variable && c_type_unspecified_p (t1))
     841              :           {
     842           29 :             gcc_assert (use1 && use2);
     843              :             use1 = false;
     844              :           }
     845              : 
     846              :         /* If both are VLAs but not unspecified and we are in the
     847              :            conditional operator, we create a conditional to select
     848              :            the size of the active branch.  */
     849          232 :         bool use0 = cond && d1_variable && !c_type_unspecified_p (t1)
     850        11225 :                          && d2_variable && !c_type_unspecified_p (t2);
     851              : 
     852        10996 :         tree td;
     853        10996 :         tree elt = composite_type_internal (TREE_TYPE (t1), TREE_TYPE (t2),
     854              :                                             cond, cache);
     855              : 
     856        10996 :         if (!use0)
     857              :           {
     858              :             /* Save space: see if the result is identical to one of the args.  */
     859        10879 :             if (elt == TREE_TYPE (t1) && use1)
     860        10088 :               return c_build_type_attribute_variant (t1, attributes);
     861          791 :             if (elt == TREE_TYPE (t2) && use2)
     862          673 :               return c_build_type_attribute_variant (t2, attributes);
     863              : 
     864          161 :             if (elt == TREE_TYPE (t1) && !TYPE_DOMAIN (t2) && !TYPE_DOMAIN (t1))
     865           10 :               return c_build_type_attribute_variant (t1, attributes);
     866          116 :             if (elt == TREE_TYPE (t2) && !TYPE_DOMAIN (t2) && !TYPE_DOMAIN (t1))
     867            2 :               return c_build_type_attribute_variant (t2, attributes);
     868              : 
     869          212 :             td = TYPE_DOMAIN (use1 ? t1 : t2);
     870              :           }
     871              :         else
     872              :           {
     873              :             /* Not used in C.  */
     874          117 :             gcc_assert (size_zero_node == TYPE_MIN_VALUE (d1));
     875          117 :             gcc_assert (size_zero_node == TYPE_MIN_VALUE (d2));
     876              : 
     877          117 :             tree d = fold_build3_loc (UNKNOWN_LOCATION, COND_EXPR, sizetype,
     878          117 :                                       cond, TYPE_MAX_VALUE (d1),
     879          117 :                                       TYPE_MAX_VALUE (d2));
     880              : 
     881          117 :             td = build_index_type (d);
     882              :           }
     883              : 
     884              :         /* Merge the element types, and have a size if either arg has
     885              :            one.  We may have qualifiers on the element types.  To set
     886              :            up TYPE_MAIN_VARIANT correctly, we need to form the
     887              :            composite of the unqualified types and add the qualifiers
     888              :            back at the end.  */
     889          223 :         int quals = TYPE_QUALS (strip_array_types (elt));
     890          223 :         tree unqual_elt = c_build_qualified_type (elt, TYPE_UNQUALIFIED);
     891              : 
     892          223 :         t1 = c_build_array_type (unqual_elt, td);
     893              : 
     894              :         /* Check that a type which has a varying outermost dimension
     895              :            got marked has having a variable size.  */
     896          223 :         bool varsize = (d1_variable && d2_variable)
     897           97 :                        || (d1_variable && !t2_complete)
     898          309 :                        || (d2_variable && !t1_complete);
     899          157 :         gcc_checking_assert (!varsize || C_TYPE_VARIABLE_SIZE (t1));
     900              : 
     901              :         /* Ensure a composite type involving a zero-length array type
     902              :            is a zero-length type not an incomplete type.  */
     903          223 :         if (d1_zero && d2_zero
     904           16 :             && (t1_complete || t2_complete)
     905          224 :             && !COMPLETE_TYPE_P (t1))
     906              :           {
     907            1 :             TYPE_SIZE (t1) = bitsize_zero_node;
     908            1 :             TYPE_SIZE_UNIT (t1) = size_zero_node;
     909              :           }
     910          223 :         t1 = c_build_qualified_type (t1, quals);
     911          223 :         return c_build_type_attribute_variant (t1, attributes);
     912              :       }
     913              : 
     914          253 :     case RECORD_TYPE:
     915          253 :     case UNION_TYPE:
     916          253 :       if (flag_isoc23 && !comptypes_same_p (t1, t2))
     917              :         {
     918              :           /* Go to the original type to get the right tag.  */
     919          150 :           tree tag = c_type_tag (t1);
     920              : 
     921          150 :           gcc_checking_assert (COMPLETE_TYPE_P (t1) && COMPLETE_TYPE_P (t2));
     922          150 :           gcc_checking_assert (!tag || comptypes (t1, t2));
     923              : 
     924              :           /* If a composite type for these two types is already under
     925              :              construction, return it.  */
     926              : 
     927          376 :           for (struct composite_cache *c = cache; c != NULL; c = c->next)
     928          246 :             if ((c->t1 == t1 && c->t2 == t2) || (c->t1 == t2 && c->t2 == t1))
     929           20 :                return c->composite;
     930              : 
     931              :           /* Otherwise, create a new type node and link it into the cache.  */
     932              : 
     933          130 :           tree n = make_node (code1);
     934          130 :           SET_TYPE_STRUCTURAL_EQUALITY (n);
     935          130 :           TYPE_NAME (n) = tag;
     936              : 
     937          130 :           struct composite_cache cache2 = { t1, t2, n, cache };
     938          130 :           cache = &cache2;
     939              : 
     940          130 :           tree f1 = TYPE_FIELDS (t1);
     941          130 :           tree f2 = TYPE_FIELDS (t2);
     942          130 :           tree fields = NULL_TREE;
     943              : 
     944          321 :           for (tree a = f1, b = f2; a && b;
     945          191 :                a = DECL_CHAIN (a), b = DECL_CHAIN (b))
     946              :             {
     947          191 :               tree ta = TREE_TYPE (a);
     948          191 :               tree tb = TREE_TYPE (b);
     949              : 
     950          191 :               if (DECL_C_BIT_FIELD (a))
     951              :                 {
     952           19 :                   ta = DECL_BIT_FIELD_TYPE (a);
     953           19 :                   tb = DECL_BIT_FIELD_TYPE (b);
     954              :                 }
     955              : 
     956          191 :               gcc_assert (DECL_NAME (a) == DECL_NAME (b));
     957          191 :               gcc_checking_assert (!DECL_NAME (a) || comptypes (ta, tb));
     958              : 
     959          191 :               tree t = composite_type_internal (ta, tb, cond, cache);
     960          191 :               tree f = build_decl (input_location, FIELD_DECL, DECL_NAME (a), t);
     961              : 
     962          191 :               DECL_PACKED (f) = DECL_PACKED (a);
     963          191 :               SET_DECL_ALIGN (f, DECL_ALIGN (a));
     964          191 :               DECL_ATTRIBUTES (f) = DECL_ATTRIBUTES (a);
     965          191 :               C_DECL_VARIABLE_SIZE (f) = C_TYPE_VARIABLE_SIZE (t);
     966              : 
     967          191 :               decl_attributes (&f, DECL_ATTRIBUTES (f), 0);
     968              : 
     969          191 :               finish_decl (f, input_location, NULL, NULL, NULL);
     970              : 
     971          191 :               if (DECL_C_BIT_FIELD (a))
     972              :                 {
     973              :                   /* This will be processed by finish_struct.  */
     974           19 :                   SET_DECL_C_BIT_FIELD (f);
     975           19 :                   DECL_INITIAL (f) = build_int_cst (integer_type_node,
     976           19 :                                                     tree_to_uhwi (DECL_SIZE (a)));
     977           19 :                   DECL_NONADDRESSABLE_P (f) = true;
     978           19 :                   DECL_PADDING_P (f) = !DECL_NAME (a);
     979              :                 }
     980              : 
     981          191 :               DECL_CHAIN (f) = fields;
     982          191 :               fields = f;
     983              :             }
     984              : 
     985          130 :           fields = nreverse (fields);
     986              : 
     987              :           /* Setup the struct/union type.  Because we inherit all variably
     988              :              modified components, we can ignore the size expression.  */
     989          130 :           tree expr = NULL_TREE;
     990              : 
     991              :           /* Set TYPE_STUB_DECL for debugging symbols.  */
     992          130 :           TYPE_STUB_DECL (n) = pushdecl (build_decl (input_location, TYPE_DECL,
     993              :                                                      NULL_TREE, n));
     994              : 
     995          130 :           n = finish_struct (input_location, n, fields, attributes, NULL,
     996              :                              &expr);
     997              : 
     998          130 :           return qualify_type (n, t1);
     999              :         }
    1000              :       /* FALLTHRU */
    1001          103 :     case ENUMERAL_TYPE:
    1002          103 :       if (attributes != NULL)
    1003              :         {
    1004              :           /* Try harder not to create a new aggregate type.  */
    1005            4 :           if (attribute_list_equal (TYPE_ATTRIBUTES (t1), attributes))
    1006              :             return t1;
    1007            0 :           if (attribute_list_equal (TYPE_ATTRIBUTES (t2), attributes))
    1008              :             return t2;
    1009              :         }
    1010           99 :       return c_build_type_attribute_variant (t1, attributes);
    1011              : 
    1012      2662530 :     case FUNCTION_TYPE:
    1013              :       /* Function types: prefer the one that specified arg types.
    1014              :          If both do, merge the arg types.  Also merge the return types.  */
    1015      2662530 :       {
    1016      2662530 :         tree valtype = composite_type_internal (TREE_TYPE (t1), TREE_TYPE (t2),
    1017              :                                                 cond, cache);
    1018      2662530 :         tree p1 = TYPE_ARG_TYPES (t1);
    1019      2662530 :         tree p2 = TYPE_ARG_TYPES (t2);
    1020              : 
    1021              :         /* Save space: see if the result is identical to one of the args.  */
    1022      2662530 :         if (valtype == TREE_TYPE (t1) && !TYPE_ARG_TYPES (t2))
    1023        10767 :           return c_build_functype_attribute_variant (t1, t2, attributes);
    1024      2652290 :         if (valtype == TREE_TYPE (t2) && !TYPE_ARG_TYPES (t1))
    1025          517 :           return c_build_functype_attribute_variant (t2, t1, attributes);
    1026              : 
    1027              :         /* Simple way if one arg fails to specify argument types.  */
    1028      2651773 :         if (TYPE_ARG_TYPES (t1) == NULL_TREE)
    1029              :           {
    1030            9 :             t1 = c_build_function_type (valtype, TYPE_ARG_TYPES (t2),
    1031            9 :                                         TYPE_NO_NAMED_ARGS_STDARG_P (t2));
    1032            9 :             t1 = c_build_type_attribute_variant (t1, attributes);
    1033            9 :             return qualify_type (t1, t2);
    1034              :          }
    1035      2651764 :         if (TYPE_ARG_TYPES (t2) == NULL_TREE)
    1036              :           {
    1037            1 :             t1 = c_build_function_type (valtype, TYPE_ARG_TYPES (t1),
    1038            1 :                                         TYPE_NO_NAMED_ARGS_STDARG_P (t1));
    1039            1 :             t1 = c_build_type_attribute_variant (t1, attributes);
    1040            1 :             return qualify_type (t1, t2);
    1041              :           }
    1042              : 
    1043              :         /* If both args specify argument types, we must merge the two
    1044              :            lists, argument by argument.  */
    1045      2651763 :         tree newargs = NULL_TREE;
    1046      2651763 :         tree *endp = &newargs;
    1047              : 
    1048      6877894 :         for (; p1; p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2))
    1049              :           {
    1050      6708829 :             if (p1 == void_list_node)
    1051              :               {
    1052      2482698 :                 *endp = void_list_node;
    1053      2482698 :                 break;
    1054              :               }
    1055      4226131 :             tree mv1 = remove_qualifiers (TREE_VALUE (p1));
    1056      4226131 :             tree mv2 = remove_qualifiers (TREE_VALUE (p2));
    1057              : 
    1058      4226131 :             gcc_assert (mv1);
    1059      4226131 :             gcc_assert (mv2);
    1060              : 
    1061      4226131 :             mv1 = transparent_union_replacement (mv1, mv2);
    1062      4226131 :             mv2 = transparent_union_replacement (mv2, mv1);
    1063              : 
    1064      4226131 :             *endp = tree_cons (NULL_TREE,
    1065              :                                composite_type_internal (mv1, mv2, cond, cache),
    1066              :                                NULL_TREE);
    1067              : 
    1068      4226131 :             endp = &TREE_CHAIN (*endp);
    1069              :           }
    1070              : 
    1071      2651763 :         t1 = c_build_function_type (valtype, newargs);
    1072      2651763 :         t1 = qualify_type (t1, t2);
    1073              :       }
    1074              :       /* FALLTHRU */
    1075              : 
    1076      2693535 :     default:
    1077      2693535 :       return c_build_type_attribute_variant (t1, attributes);
    1078              :     }
    1079              : }
    1080              : 
    1081              : tree
    1082      6468263 : composite_type_cond (tree t1, tree t2, tree cond)
    1083              : {
    1084      6468263 :   gcc_checking_assert (comptypes_check_for_composite (t1, t2));
    1085              : 
    1086      6468263 :   struct composite_cache cache = { };
    1087      6468263 :   tree n = composite_type_internal (t1, t2, cond, &cache);
    1088              : 
    1089      6468263 :   gcc_checking_assert (comptypes_check_for_composite (n, t1));
    1090      6468263 :   gcc_checking_assert (comptypes_check_for_composite (n, t2));
    1091      6468263 :   return n;
    1092              : }
    1093              : 
    1094              : 
    1095              : tree
    1096      6463792 : composite_type (tree t1, tree t2)
    1097              : {
    1098      6463792 :   return composite_type_cond (t1, t2, NULL_TREE);
    1099              : }
    1100              : 
    1101              : /* Return the type of a conditional expression between pointers to
    1102              :    possibly differently qualified versions of compatible types.
    1103              : 
    1104              :    We assume that comp_target_types has already been done and returned
    1105              :    true; if that isn't so, this may crash.  */
    1106              : 
    1107              : static tree
    1108       115116 : common_pointer_type (tree t1, tree t2, tree cond)
    1109              : {
    1110       115116 :   tree attributes;
    1111       115116 :   unsigned target_quals;
    1112       115116 :   addr_space_t as1, as2, as_common;
    1113       115116 :   int quals1, quals2;
    1114              : 
    1115              :   /* Save time if the two types are the same.  */
    1116              : 
    1117       115116 :   if (t1 == t2) return t1;
    1118              : 
    1119              :   /* If one type is nonsense, use the other.  */
    1120         4471 :   if (t1 == error_mark_node)
    1121              :     return t2;
    1122         4471 :   if (t2 == error_mark_node)
    1123              :     return t1;
    1124              : 
    1125         4471 :   gcc_assert (TREE_CODE (t1) == POINTER_TYPE
    1126              :               && TREE_CODE (t2) == POINTER_TYPE);
    1127              : 
    1128              :   /* Merge the attributes.  */
    1129         4471 :   attributes = targetm.merge_type_attributes (t1, t2);
    1130              : 
    1131              :   /* Find the composite type of the target types, and combine the
    1132              :      qualifiers of the two types' targets.  */
    1133         4471 :   tree pointed_to_1 = TREE_TYPE (t1);
    1134         4471 :   tree pointed_to_2 = TREE_TYPE (t2);
    1135         4471 :   tree target = composite_type_cond (TYPE_MAIN_VARIANT (pointed_to_1),
    1136         4471 :                                      TYPE_MAIN_VARIANT (pointed_to_2), cond);
    1137              : 
    1138              :   /* Strip array types to get correct qualifier for pointers to arrays */
    1139         4471 :   quals1 = TYPE_QUALS_NO_ADDR_SPACE (strip_array_types (pointed_to_1));
    1140         4471 :   quals2 = TYPE_QUALS_NO_ADDR_SPACE (strip_array_types (pointed_to_2));
    1141              : 
    1142              :   /* For function types do not merge const qualifiers, but drop them
    1143              :      if used inconsistently.  The middle-end uses these to mark const
    1144              :      and noreturn functions.  */
    1145         4471 :   if (TREE_CODE (pointed_to_1) == FUNCTION_TYPE)
    1146         2129 :     target_quals = (quals1 & quals2);
    1147              :   else
    1148         2342 :     target_quals = (quals1 | quals2);
    1149              : 
    1150              :   /* If the two named address spaces are different, determine the common
    1151              :      superset address space.  This is guaranteed to exist due to the
    1152              :      assumption that comp_target_type returned true.  */
    1153         4471 :   as1 = TYPE_ADDR_SPACE (pointed_to_1);
    1154         4471 :   as2 = TYPE_ADDR_SPACE (pointed_to_2);
    1155         4471 :   if (!addr_space_superset (as1, as2, &as_common))
    1156            0 :     gcc_unreachable ();
    1157              : 
    1158         4471 :   target_quals |= ENCODE_QUAL_ADDR_SPACE (as_common);
    1159              : 
    1160         4471 :   t1 = c_build_pointer_type (c_build_qualified_type (target, target_quals));
    1161         4471 :   return c_build_type_attribute_variant (t1, attributes);
    1162              : }
    1163              : 
    1164              : /* Return the common type for two arithmetic types under the usual
    1165              :    arithmetic conversions.  The default conversions have already been
    1166              :    applied, and enumerated types converted to their compatible integer
    1167              :    types.  The resulting type is unqualified and has no attributes.
    1168              : 
    1169              :    This is the type for the result of most arithmetic operations
    1170              :    if the operands have the given two types.  */
    1171              : 
    1172              : static tree
    1173     14000198 : c_common_type (tree t1, tree t2)
    1174              : {
    1175     14000198 :   enum tree_code code1;
    1176     14000198 :   enum tree_code code2;
    1177              : 
    1178              :   /* If one type is nonsense, use the other.  */
    1179     14000198 :   if (t1 == error_mark_node)
    1180              :     return t2;
    1181     14000198 :   if (t2 == error_mark_node)
    1182              :     return t1;
    1183              : 
    1184     14000198 :   if (TYPE_QUALS (t1) != TYPE_UNQUALIFIED)
    1185        38159 :     t1 = TYPE_MAIN_VARIANT (t1);
    1186              : 
    1187     14000198 :   if (TYPE_QUALS (t2) != TYPE_UNQUALIFIED)
    1188        49382 :     t2 = TYPE_MAIN_VARIANT (t2);
    1189              : 
    1190     14000198 :   if (TYPE_ATTRIBUTES (t1) != NULL_TREE)
    1191              :     {
    1192       188346 :       tree attrs = affects_type_identity_attributes (TYPE_ATTRIBUTES (t1));
    1193       188346 :       t1 = c_build_type_attribute_variant (t1, attrs);
    1194              :     }
    1195              : 
    1196     14000198 :   if (TYPE_ATTRIBUTES (t2) != NULL_TREE)
    1197              :     {
    1198       187824 :       tree attrs = affects_type_identity_attributes (TYPE_ATTRIBUTES (t2));
    1199       187824 :       t2 = c_build_type_attribute_variant (t2, attrs);
    1200              :     }
    1201              : 
    1202              :   /* Save time if the two types are the same.  */
    1203              : 
    1204     14000198 :   if (t1 == t2) return t1;
    1205              : 
    1206      2331677 :   code1 = TREE_CODE (t1);
    1207      2331677 :   code2 = TREE_CODE (t2);
    1208              : 
    1209      2331677 :   gcc_assert (code1 == VECTOR_TYPE || code1 == COMPLEX_TYPE
    1210              :               || code1 == FIXED_POINT_TYPE || code1 == REAL_TYPE
    1211              :               || code1 == INTEGER_TYPE || code1 == BITINT_TYPE);
    1212      2331677 :   gcc_assert (code2 == VECTOR_TYPE || code2 == COMPLEX_TYPE
    1213              :               || code2 == FIXED_POINT_TYPE || code2 == REAL_TYPE
    1214              :               || code2 == INTEGER_TYPE || code2 == BITINT_TYPE);
    1215              : 
    1216              :   /* When one operand is a decimal float type, the other operand cannot be
    1217              :      a generic float type or a complex type.  We also disallow vector types
    1218              :      here.  */
    1219      2331677 :   if ((DECIMAL_FLOAT_TYPE_P (t1) || DECIMAL_FLOAT_TYPE_P (t2))
    1220      2334100 :       && !(DECIMAL_FLOAT_TYPE_P (t1) && DECIMAL_FLOAT_TYPE_P (t2)))
    1221              :     {
    1222         1080 :       if (code1 == VECTOR_TYPE || code2 == VECTOR_TYPE)
    1223              :         {
    1224            3 :           error ("cannot mix operands of decimal floating and vector types");
    1225            3 :           return error_mark_node;
    1226              :         }
    1227         1077 :       if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE)
    1228              :         {
    1229            5 :           error ("cannot mix operands of decimal floating and complex types");
    1230            5 :           return error_mark_node;
    1231              :         }
    1232         1072 :       if (code1 == REAL_TYPE && code2 == REAL_TYPE)
    1233              :         {
    1234           16 :           error ("cannot mix operands of decimal floating "
    1235              :                  "and other floating types");
    1236           16 :           return error_mark_node;
    1237              :         }
    1238              :     }
    1239              : 
    1240              :   /* If one type is a vector type, return that type.  (How the usual
    1241              :      arithmetic conversions apply to the vector types extension is not
    1242              :      precisely specified.)  */
    1243      2331653 :   if (code1 == VECTOR_TYPE)
    1244              :     return t1;
    1245              : 
    1246      2331363 :   if (code2 == VECTOR_TYPE)
    1247              :     return t2;
    1248              : 
    1249              :   /* If one type is complex, form the common type of the non-complex
    1250              :      components, then make that complex.  Use T1 or T2 if it is the
    1251              :      required type.  */
    1252      2331360 :   if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE)
    1253              :     {
    1254        89325 :       tree subtype1 = code1 == COMPLEX_TYPE ? TREE_TYPE (t1) : t1;
    1255        89325 :       tree subtype2 = code2 == COMPLEX_TYPE ? TREE_TYPE (t2) : t2;
    1256        89325 :       tree subtype = c_common_type (subtype1, subtype2);
    1257              : 
    1258        89325 :       if (code1 == COMPLEX_TYPE && TREE_TYPE (t1) == subtype)
    1259              :         return t1;
    1260        59210 :       else if (code2 == COMPLEX_TYPE && TREE_TYPE (t2) == subtype)
    1261              :         return t2;
    1262         3242 :       else if (TREE_CODE (subtype) == BITINT_TYPE)
    1263              :         {
    1264            8 :           sorry ("%<_Complex _BitInt(%d)%> unsupported",
    1265            4 :                  TYPE_PRECISION (subtype));
    1266            6 :           return code1 == COMPLEX_TYPE ? t1 : t2;
    1267              :         }
    1268              :       else
    1269         3238 :         return build_complex_type (subtype);
    1270              :     }
    1271              : 
    1272              :   /* If only one is real, use it as the result.  */
    1273              : 
    1274      2242035 :   if (code1 == REAL_TYPE && code2 != REAL_TYPE)
    1275              :     return t1;
    1276              : 
    1277      2113065 :   if (code2 == REAL_TYPE && code1 != REAL_TYPE)
    1278              :     return t2;
    1279              : 
    1280              :   /* If both are real and either are decimal floating point types, use
    1281              :      the decimal floating point type with the greater precision. */
    1282              : 
    1283      2081732 :   if (code1 == REAL_TYPE && code2 == REAL_TYPE)
    1284              :     {
    1285       107467 :       if (TYPE_MAIN_VARIANT (t1) == dfloat128_type_node
    1286       107467 :           || TYPE_MAIN_VARIANT (t2) == dfloat128_type_node)
    1287              :         return dfloat128_type_node;
    1288              :       /* And prefer _Decimal128 over _Decimal64x which has in GCC's
    1289              :          implementation the same mode.  */
    1290       106918 :       else if (TYPE_MAIN_VARIANT (t1) == dfloat64x_type_node
    1291       106918 :                || TYPE_MAIN_VARIANT (t2) == dfloat64x_type_node)
    1292              :         return dfloat64x_type_node;
    1293       106914 :       else if (TYPE_MAIN_VARIANT (t1) == dfloat64_type_node
    1294       106914 :                || TYPE_MAIN_VARIANT (t2) == dfloat64_type_node)
    1295              :         return dfloat64_type_node;
    1296       106469 :       else if (TYPE_MAIN_VARIANT (t1) == dfloat32_type_node
    1297       106469 :                || TYPE_MAIN_VARIANT (t2) == dfloat32_type_node)
    1298              :         return dfloat32_type_node;
    1299              :     }
    1300              : 
    1301              :   /* Deal with fixed-point types.  */
    1302      2080389 :   if (code1 == FIXED_POINT_TYPE || code2 == FIXED_POINT_TYPE)
    1303              :     {
    1304            0 :       unsigned int unsignedp = 0, satp = 0;
    1305            0 :       scalar_mode m1, m2;
    1306            0 :       unsigned int fbit1, ibit1, fbit2, ibit2, max_fbit, max_ibit;
    1307              : 
    1308            0 :       m1 = SCALAR_TYPE_MODE (t1);
    1309            0 :       m2 = SCALAR_TYPE_MODE (t2);
    1310              : 
    1311              :       /* If one input type is saturating, the result type is saturating.  */
    1312            0 :       if (TYPE_SATURATING (t1) || TYPE_SATURATING (t2))
    1313              :         satp = 1;
    1314              : 
    1315              :       /* If both fixed-point types are unsigned, the result type is unsigned.
    1316              :          When mixing fixed-point and integer types, follow the sign of the
    1317              :          fixed-point type.
    1318              :          Otherwise, the result type is signed.  */
    1319            0 :       if ((TYPE_UNSIGNED (t1) && TYPE_UNSIGNED (t2)
    1320            0 :            && code1 == FIXED_POINT_TYPE && code2 == FIXED_POINT_TYPE)
    1321            0 :           || (code1 == FIXED_POINT_TYPE && code2 != FIXED_POINT_TYPE
    1322            0 :               && TYPE_UNSIGNED (t1))
    1323            0 :           || (code1 != FIXED_POINT_TYPE && code2 == FIXED_POINT_TYPE
    1324            0 :               && TYPE_UNSIGNED (t2)))
    1325              :         unsignedp = 1;
    1326              : 
    1327              :       /* The result type is signed.  */
    1328            0 :       if (unsignedp == 0)
    1329              :         {
    1330              :           /* If the input type is unsigned, we need to convert to the
    1331              :              signed type.  */
    1332            0 :           if (code1 == FIXED_POINT_TYPE && TYPE_UNSIGNED (t1))
    1333              :             {
    1334            0 :               enum mode_class mclass = (enum mode_class) 0;
    1335            0 :               if (GET_MODE_CLASS (m1) == MODE_UFRACT)
    1336              :                 mclass = MODE_FRACT;
    1337            0 :               else if (GET_MODE_CLASS (m1) == MODE_UACCUM)
    1338              :                 mclass = MODE_ACCUM;
    1339              :               else
    1340            0 :                 gcc_unreachable ();
    1341            0 :               m1 = as_a <scalar_mode>
    1342            0 :                 (mode_for_size (GET_MODE_PRECISION (m1), mclass, 0));
    1343              :             }
    1344            0 :           if (code2 == FIXED_POINT_TYPE && TYPE_UNSIGNED (t2))
    1345              :             {
    1346            0 :               enum mode_class mclass = (enum mode_class) 0;
    1347            0 :               if (GET_MODE_CLASS (m2) == MODE_UFRACT)
    1348              :                 mclass = MODE_FRACT;
    1349            0 :               else if (GET_MODE_CLASS (m2) == MODE_UACCUM)
    1350              :                 mclass = MODE_ACCUM;
    1351              :               else
    1352            0 :                 gcc_unreachable ();
    1353            0 :               m2 = as_a <scalar_mode>
    1354            0 :                 (mode_for_size (GET_MODE_PRECISION (m2), mclass, 0));
    1355              :             }
    1356              :         }
    1357              : 
    1358            0 :       if (code1 == FIXED_POINT_TYPE)
    1359              :         {
    1360            0 :           fbit1 = GET_MODE_FBIT (m1);
    1361            0 :           ibit1 = GET_MODE_IBIT (m1);
    1362              :         }
    1363              :       else
    1364              :         {
    1365            0 :           fbit1 = 0;
    1366              :           /* Signed integers need to subtract one sign bit.  */
    1367            0 :           ibit1 = TYPE_PRECISION (t1) - (!TYPE_UNSIGNED (t1));
    1368              :         }
    1369              : 
    1370            0 :       if (code2 == FIXED_POINT_TYPE)
    1371              :         {
    1372            0 :           fbit2 = GET_MODE_FBIT (m2);
    1373            0 :           ibit2 = GET_MODE_IBIT (m2);
    1374              :         }
    1375              :       else
    1376              :         {
    1377            0 :           fbit2 = 0;
    1378              :           /* Signed integers need to subtract one sign bit.  */
    1379            0 :           ibit2 = TYPE_PRECISION (t2) - (!TYPE_UNSIGNED (t2));
    1380              :         }
    1381              : 
    1382            0 :       max_ibit = ibit1 >= ibit2 ?  ibit1 : ibit2;
    1383            0 :       max_fbit = fbit1 >= fbit2 ?  fbit1 : fbit2;
    1384            0 :       return c_common_fixed_point_type_for_size (max_ibit, max_fbit, unsignedp,
    1385              :                                                  satp);
    1386              :     }
    1387              : 
    1388              :   /* Both real or both integers; use the one with greater precision.  */
    1389              : 
    1390      2080389 :   if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2))
    1391              :     return t1;
    1392      1105359 :   else if (TYPE_PRECISION (t2) > TYPE_PRECISION (t1))
    1393              :     return t2;
    1394              : 
    1395              :   /* Same precision.  Prefer long longs to longs to ints when the
    1396              :      same precision, following the C99 rules on integer type rank
    1397              :      (which are equivalent to the C90 rules for C90 types).  */
    1398              : 
    1399       740045 :   if (TYPE_MAIN_VARIANT (t1) == long_long_unsigned_type_node
    1400       740045 :       || TYPE_MAIN_VARIANT (t2) == long_long_unsigned_type_node)
    1401              :     return long_long_unsigned_type_node;
    1402              : 
    1403       650797 :   if (TYPE_MAIN_VARIANT (t1) == long_long_integer_type_node
    1404       650797 :       || TYPE_MAIN_VARIANT (t2) == long_long_integer_type_node)
    1405              :     {
    1406        15318 :       if (TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
    1407          361 :         return long_long_unsigned_type_node;
    1408              :       else
    1409              :         return long_long_integer_type_node;
    1410              :     }
    1411              : 
    1412       635479 :   if (TYPE_MAIN_VARIANT (t1) == long_unsigned_type_node
    1413       635479 :       || TYPE_MAIN_VARIANT (t2) == long_unsigned_type_node)
    1414              :     return long_unsigned_type_node;
    1415              : 
    1416       536245 :   if (TYPE_MAIN_VARIANT (t1) == long_integer_type_node
    1417       536245 :       || TYPE_MAIN_VARIANT (t2) == long_integer_type_node)
    1418              :     {
    1419              :       /* But preserve unsignedness from the other type,
    1420              :          since long cannot hold all the values of an unsigned int.  */
    1421        26421 :       if (TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
    1422          129 :         return long_unsigned_type_node;
    1423              :       else
    1424              :         return long_integer_type_node;
    1425              :     }
    1426              : 
    1427              :   /* For floating types of the same TYPE_PRECISION (which we here
    1428              :      assume means either the same set of values, or sets of values
    1429              :      neither a subset of the other, with behavior being undefined in
    1430              :      the latter case), follow the rules from TS 18661-3: prefer
    1431              :      interchange types _FloatN, then standard types long double,
    1432              :      double, float, then extended types _FloatNx.  For extended types,
    1433              :      check them starting with _Float128x as that seems most consistent
    1434              :      in spirit with preferring long double to double; for interchange
    1435              :      types, also check in that order for consistency although it's not
    1436              :      possible for more than one of them to have the same
    1437              :      precision.  */
    1438       509824 :   tree mv1 = TYPE_MAIN_VARIANT (t1);
    1439       509824 :   tree mv2 = TYPE_MAIN_VARIANT (t2);
    1440              : 
    1441      2548474 :   for (int i = NUM_FLOATN_TYPES - 1; i >= 0; i--)
    1442      2038833 :     if (mv1 == FLOATN_TYPE_NODE (i) || mv2 == FLOATN_TYPE_NODE (i))
    1443              :       return FLOATN_TYPE_NODE (i);
    1444              : 
    1445              :   /* Likewise, prefer long double to double even if same size.  */
    1446       509641 :   if (mv1 == long_double_type_node || mv2 == long_double_type_node)
    1447              :     return long_double_type_node;
    1448              : 
    1449              :   /* Likewise, prefer double to float even if same size.
    1450              :      We got a couple of embedded targets with 32 bit doubles, and the
    1451              :      pdp11 might have 64 bit floats.  */
    1452       509383 :   if (mv1 == double_type_node || mv2 == double_type_node)
    1453              :     return double_type_node;
    1454              : 
    1455       508811 :   if (mv1 == float_type_node || mv2 == float_type_node)
    1456              :     return float_type_node;
    1457              : 
    1458      2026504 :   for (int i = NUM_FLOATNX_TYPES - 1; i >= 0; i--)
    1459      1519878 :     if (mv1 == FLOATNX_TYPE_NODE (i) || mv2 == FLOATNX_TYPE_NODE (i))
    1460              :       return FLOATNX_TYPE_NODE (i);
    1461              : 
    1462       506626 :   if ((code1 == BITINT_TYPE || code2 == BITINT_TYPE) && code1 != code2)
    1463              :     {
    1464              :       /* Prefer any other integral types over bit-precise integer types.  */
    1465           10 :       if (TYPE_UNSIGNED (t1) == TYPE_UNSIGNED (t2))
    1466            6 :         return code1 == BITINT_TYPE ? t2 : t1;
    1467              :       /* If BITINT_TYPE is unsigned and the other type is signed
    1468              :          non-BITINT_TYPE with the same precision, the latter has higher rank.
    1469              :          In that case:
    1470              :          Otherwise, both operands are converted to the unsigned integer type
    1471              :          corresponding to the type of the operand with signed integer type.  */
    1472            8 :       if (TYPE_UNSIGNED (code1 == BITINT_TYPE ? t1 : t2))
    1473            5 :         return c_common_unsigned_type (code1 == BITINT_TYPE ? t2 : t1);
    1474              :     }
    1475              : 
    1476              :   /* Otherwise prefer the unsigned one.  */
    1477              : 
    1478       506618 :   if (TYPE_UNSIGNED (t1))
    1479              :     return t1;
    1480              :   else
    1481              :     return t2;
    1482              : }
    1483              : 
    1484              : /* Wrapper around c_common_type that is used by c-common.cc and other
    1485              :    front end optimizations that remove promotions.  ENUMERAL_TYPEs
    1486              :    are allowed here and are converted to their compatible integer types.
    1487              :    BOOLEAN_TYPEs are allowed here and return either boolean_type_node or
    1488              :    preferably a non-Boolean type as the common type.  */
    1489              : tree
    1490       103015 : common_type (tree t1, tree t2)
    1491              : {
    1492       103015 :   if (TREE_CODE (t1) == ENUMERAL_TYPE)
    1493            0 :     t1 = ENUM_UNDERLYING_TYPE (t1);
    1494       103015 :   if (TREE_CODE (t2) == ENUMERAL_TYPE)
    1495            1 :     t2 = ENUM_UNDERLYING_TYPE (t2);
    1496              : 
    1497              :   /* If both types are BOOLEAN_TYPE, then return boolean_type_node.  */
    1498       103015 :   if (TREE_CODE (t1) == BOOLEAN_TYPE
    1499          584 :       && TREE_CODE (t2) == BOOLEAN_TYPE)
    1500          584 :     return boolean_type_node;
    1501              : 
    1502              :   /* If either type is BOOLEAN_TYPE, then return the other.  */
    1503       102431 :   if (TREE_CODE (t1) == BOOLEAN_TYPE)
    1504              :     return t2;
    1505       102431 :   if (TREE_CODE (t2) == BOOLEAN_TYPE)
    1506              :     return t1;
    1507              : 
    1508       102431 :   return c_common_type (t1, t2);
    1509              : }
    1510              : 
    1511              : 
    1512              : 
    1513              : /* Helper function for comptypes.  For two compatible types, return 1
    1514              :    if they pass consistency checks.  In particular we test that
    1515              :    TYPE_CANONICAL is set correctly, i.e. the two types can alias.  */
    1516              : 
    1517              : static bool
    1518     43045905 : comptypes_verify (tree type1, tree type2)
    1519              : {
    1520     43045905 :   if (type1 == type2 || !type1 || !type2
    1521      3517235 :       || TREE_CODE (type1) == ERROR_MARK || TREE_CODE (type2) == ERROR_MARK)
    1522              :     return true;
    1523              : 
    1524      3517234 :   gcc_checking_assert (c_verify_type (type1));
    1525      3517234 :   gcc_checking_assert (c_verify_type (type2));
    1526              : 
    1527      3517234 :   if (TYPE_CANONICAL (type1) != TYPE_CANONICAL (type2)
    1528       388764 :       && !TYPE_STRUCTURAL_EQUALITY_P (type1)
    1529      3904523 :       && !TYPE_STRUCTURAL_EQUALITY_P (type2))
    1530              :     {
    1531              :       /* FIXME: check other types. */
    1532       386978 :       if (RECORD_OR_UNION_TYPE_P (type1)
    1533       386978 :           || TREE_CODE (type1) == ENUMERAL_TYPE
    1534       386978 :           || TREE_CODE (type2) == ENUMERAL_TYPE)
    1535            0 :         return false;
    1536              :     }
    1537              :   return true;
    1538              : }
    1539              : 
    1540              : struct comptypes_data {
    1541              : 
    1542              :   /* output */
    1543              :   bool enum_and_int_p;
    1544              :   bool different_types_p;
    1545              :   bool warning_needed;
    1546              : 
    1547              :   /* context */
    1548              :   bool anon_field;
    1549              :   bool pointedto;
    1550              : 
    1551              :   /* configuration */
    1552              :   bool equiv;
    1553              :   bool ignore_promoting_args;
    1554              : 
    1555              :   const struct tagged_tu_seen_cache* cache;
    1556              : };
    1557              : 
    1558              : 
    1559              : /* Helper function for composite_type.  This function ignores when the
    1560              :    function type of an old-style declaration is incompatible with a type
    1561              :    of a declaration with prototype because some are arguments are not
    1562              :    self-promoting.  This is ignored only for function types but not
    1563              :    ignored in a nested context.  */
    1564              : 
    1565              : static bool
    1566     19404789 : comptypes_check_for_composite (tree t1, tree t2)
    1567              : {
    1568     19404789 :   struct comptypes_data data = { };
    1569     19404789 :   data.ignore_promoting_args = FUNCTION_TYPE == TREE_CODE (t1);
    1570     19404789 :   return comptypes_internal (t1, t2, &data);
    1571              : }
    1572              : 
    1573              : 
    1574              : /* C implementation of compatible_types_for_indirection_note_p.  */
    1575              : 
    1576              : bool
    1577          762 : compatible_types_for_indirection_note_p (tree type1, tree type2)
    1578              : {
    1579          762 :   return comptypes (type1, type2);
    1580              : }
    1581              : 
    1582              : /* Return true if TYPE1 and TYPE2 are compatible types for assignment
    1583              :    or various other operations.  */
    1584              : 
    1585              : bool
    1586     56604922 : comptypes (tree type1, tree type2)
    1587              : {
    1588     56604922 :   struct comptypes_data data = { };
    1589     56604922 :   bool ret = comptypes_internal (type1, type2, &data);
    1590              : 
    1591     56604922 :   gcc_checking_assert (!ret || comptypes_verify (type1, type2));
    1592              : 
    1593     56604922 :   return ret;
    1594              : }
    1595              : 
    1596              : 
    1597              : /* Like comptypes, but it returns non-zero only for identical
    1598              :    types.  */
    1599              : 
    1600              : bool
    1601        46246 : comptypes_same_p (tree type1, tree type2)
    1602              : {
    1603        46246 :   struct comptypes_data data = { };
    1604        46246 :   bool ret = comptypes_internal (type1, type2, &data);
    1605              : 
    1606        46246 :   gcc_checking_assert (!ret || comptypes_verify (type1, type2));
    1607              : 
    1608        46246 :   if (data.different_types_p)
    1609          163 :     return false;
    1610              : 
    1611              :   return ret;
    1612              : }
    1613              : 
    1614              : 
    1615              : /* Like comptypes, but if it returns true because enum and int are
    1616              :    compatible, it sets *ENUM_AND_INT_P to true.  */
    1617              : 
    1618              : bool
    1619      5114731 : comptypes_check_enum_int (tree type1, tree type2, bool *enum_and_int_p)
    1620              : {
    1621      5114731 :   struct comptypes_data data = { };
    1622      5114731 :   bool ret = comptypes_internal (type1, type2, &data);
    1623      5114731 :   *enum_and_int_p = data.enum_and_int_p;
    1624              : 
    1625      5114731 :   gcc_checking_assert (!ret || comptypes_verify (type1, type2));
    1626              : 
    1627      5114731 :   return ret;
    1628              : }
    1629              : 
    1630              : 
    1631              : 
    1632              : /* Like comptypes, but if it returns true for struct and union types
    1633              :    considered equivalent for aliasing purposes, i.e. for setting
    1634              :    TYPE_CANONICAL after completing a struct or union.
    1635              : 
    1636              :    This function must return false only for types which are not
    1637              :    compatible according to C language semantics (cf. comptypes),
    1638              :    otherwise the middle-end would make incorrect aliasing decisions.
    1639              :    It may return true for some similar types that are not compatible
    1640              :    according to those stricter rules.
    1641              : 
    1642              :    In particular, we ignore size expression in arrays so that the
    1643              :    following structs are in the same equivalence class:
    1644              : 
    1645              :    struct foo { char (*buf)[]; };
    1646              :    struct foo { char (*buf)[3]; };
    1647              :    struct foo { char (*buf)[4]; };
    1648              : 
    1649              :    We also treat unions / structs with members which are pointers to
    1650              :    structures or unions with the same tag as equivalent (if they are not
    1651              :    incompatible for other reasons).  Although incomplete structure
    1652              :    or union types are not compatible to any other type, they may become
    1653              :    compatible to different types when completed.  To avoid having to update
    1654              :    TYPE_CANONICAL at this point, we only consider the tag when forming
    1655              :    the equivalence classes.  For example, the following types with tag
    1656              :    'foo' are all considered equivalent:
    1657              : 
    1658              :    struct bar;
    1659              :    struct foo { struct bar *x };
    1660              :    struct foo { struct bar { int a; } *x };
    1661              :    struct foo { struct bar { char b; } *x };  */
    1662              : 
    1663              : bool
    1664     14703266 : comptypes_equiv_p (tree type1, tree type2)
    1665              : {
    1666     14703266 :   struct comptypes_data data = { };
    1667     14703266 :   data.equiv = true;
    1668     14703266 :   bool ret = comptypes_internal (type1, type2, &data);
    1669              : 
    1670              :   /* check that different equivance classes are assigned only
    1671              :      to types that are not compatible.  */
    1672     14703266 :   gcc_checking_assert (ret || !comptypes (type1, type2));
    1673              : 
    1674     14703266 :   return ret;
    1675              : }
    1676              : 
    1677              : 
    1678              : /* Return true if TYPE1 and TYPE2 are compatible types for assignment
    1679              :    or various other operations.  If they are compatible but a warning may
    1680              :    be needed if you use them together, 'warning_needed' in DATA is set.
    1681              :    If one type is an enum and the other a compatible integer type, then
    1682              :    this sets 'enum_and_int_p' in DATA to true (it is never set to
    1683              :    false).  If the types are compatible but different enough not to be
    1684              :    permitted in C11 typedef redeclarations, then this sets
    1685              :    'different_types_p' in DATA to true; it is never set to
    1686              :    false, but may or may not be set if the types are incompatible.
    1687              :    If two functions types are not compatible only because one is
    1688              :    an old-style definition that does not have self-promoting arguments,
    1689              :    then this can be ignored by setting 'ignore_promoting_args_p'.
    1690              :    For 'equiv' we can compute equivalency classes (see above).  */
    1691              : 
    1692              : static bool
    1693    134503220 : comptypes_internal (const_tree type1, const_tree type2,
    1694              :                     struct comptypes_data *data)
    1695              : {
    1696    134787863 :   const_tree t1 = type1;
    1697    134787863 :   const_tree t2 = type2;
    1698              : 
    1699              :   /* Suppress errors caused by previously reported errors.  */
    1700              : 
    1701    134787863 :   if (t1 == t2 || !t1 || !t2
    1702     45490427 :       || TREE_CODE (t1) == ERROR_MARK || TREE_CODE (t2) == ERROR_MARK)
    1703              :     return true;
    1704              : 
    1705              :   /* Qualifiers must match. C99 6.7.3p9 */
    1706              : 
    1707     45490424 :   if (TYPE_QUALS (t1) != TYPE_QUALS (t2))
    1708              :     return false;
    1709              : 
    1710              :   /* Enumerated types are compatible with integer types, but this is
    1711              :      not transitive: two enumerated types in the same translation unit
    1712              :      are compatible with each other only if they are the same type.  */
    1713              : 
    1714     45450203 :   if (TREE_CODE (t1) == ENUMERAL_TYPE
    1715         1018 :       && COMPLETE_TYPE_P (t1)
    1716     45451177 :       && TREE_CODE (t2) != ENUMERAL_TYPE)
    1717              :     {
    1718          858 :       t1 = ENUM_UNDERLYING_TYPE (t1);
    1719          858 :       if (TREE_CODE (t2) != VOID_TYPE)
    1720              :         {
    1721          854 :           data->enum_and_int_p = true;
    1722          854 :           data->different_types_p = true;
    1723              :         }
    1724              :     }
    1725     45449345 :   else if (TREE_CODE (t2) == ENUMERAL_TYPE
    1726         4722 :            && COMPLETE_TYPE_P (t2)
    1727     45454061 :            && TREE_CODE (t1) != ENUMERAL_TYPE)
    1728              :     {
    1729         4600 :       t2 = ENUM_UNDERLYING_TYPE (t2);
    1730         4600 :       if (TREE_CODE (t1) != VOID_TYPE)
    1731              :         {
    1732         3701 :           data->enum_and_int_p = true;
    1733         3701 :           data->different_types_p = true;
    1734              :         }
    1735              :     }
    1736              : 
    1737     45450203 :   if (t1 == t2)
    1738              :     return true;
    1739              : 
    1740              :   /* Different classes of types can't be compatible.  */
    1741              : 
    1742     45448831 :   if (TREE_CODE (t1) != TREE_CODE (t2))
    1743              :     return false;
    1744              : 
    1745              :   /* Allow for two different type nodes which have essentially the same
    1746              :      definition.  Note that we already checked for equality of the type
    1747              :      qualifiers (just above).  */
    1748              : 
    1749     37431974 :   if (TREE_CODE (t1) != ARRAY_TYPE
    1750     37431974 :       && TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
    1751              :     return true;
    1752              : 
    1753     37093311 :   int attrval;
    1754              : 
    1755              :   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
    1756     37093311 :   if (!(attrval = comp_type_attributes (t1, t2)))
    1757              :     return false;
    1758              : 
    1759     37092934 :   if (2 == attrval)
    1760          336 :     data->warning_needed = true;
    1761              : 
    1762     37092934 :   switch (TREE_CODE (t1))
    1763              :     {
    1764      3362142 :     case INTEGER_TYPE:
    1765      3362142 :     case FIXED_POINT_TYPE:
    1766      3362142 :     case REAL_TYPE:
    1767      3362142 :     case BITINT_TYPE:
    1768              :       /* With these nodes, we can't determine type equivalence by
    1769              :          looking at what is stored in the nodes themselves, because
    1770              :          two nodes might have different TYPE_MAIN_VARIANTs but still
    1771              :          represent the same type.  For example, wchar_t and int could
    1772              :          have the same properties (TYPE_PRECISION, TYPE_MIN_VALUE,
    1773              :          TYPE_MAX_VALUE, etc.), but have different TYPE_MAIN_VARIANTs
    1774              :          and are distinct types.  On the other hand, int and the
    1775              :          following typedef
    1776              : 
    1777              :            typedef int INT __attribute((may_alias));
    1778              : 
    1779              :          have identical properties, different TYPE_MAIN_VARIANTs, but
    1780              :          represent the same type.  The canonical type system keeps
    1781              :          track of equivalence in this case, so we fall back on it.  */
    1782      3362142 :       return TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2);
    1783              : 
    1784       284643 :     case POINTER_TYPE:
    1785              :       /* Do not remove mode information.  */
    1786       284643 :       if (TYPE_MODE (t1) != TYPE_MODE (t2))
    1787              :         return false;
    1788       284643 :       data->pointedto = true;
    1789       284643 :       return comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2), data);
    1790              : 
    1791      9178288 :     case FUNCTION_TYPE:
    1792      9178288 :       return function_types_compatible_p (t1, t2, data);
    1793              : 
    1794       154885 :     case ARRAY_TYPE:
    1795       154885 :       {
    1796       154885 :         tree d1 = TYPE_DOMAIN (t1);
    1797       154885 :         tree d2 = TYPE_DOMAIN (t2);
    1798              : 
    1799              :         /* Target types must match incl. qualifiers.  */
    1800       154885 :         if (!comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2), data))
    1801              :           return false;
    1802              : 
    1803       119963 :         if ((d1 == NULL_TREE) != (d2 == NULL_TREE))
    1804         6354 :           data->different_types_p = true;
    1805              :         /* Ignore size mismatches when forming equivalence classes.  */
    1806       119963 :         if (data->equiv)
    1807              :           return true;
    1808              :         /* Sizes must match unless one is missing or variable.  */
    1809        50405 :         if (d1 == NULL_TREE || d2 == NULL_TREE || d1 == d2)
    1810              :           return true;
    1811              : 
    1812        34127 :         bool d1_zero = !TYPE_MAX_VALUE (d1);
    1813        34127 :         bool d2_zero = !TYPE_MAX_VALUE (d2);
    1814              : 
    1815        34127 :         bool d1_variable = top_array_vla_p (t1);
    1816        34127 :         bool d2_variable = top_array_vla_p (t2);
    1817              : 
    1818        34127 :         if (d1_variable != d2_variable)
    1819          943 :           data->different_types_p = true;
    1820        34127 :         if (d1_variable || d2_variable)
    1821              :           return true;
    1822         4027 :         if (d1_zero && d2_zero)
    1823              :           return true;
    1824         4027 :         if (d1_zero || d2_zero
    1825         3931 :             || !tree_int_cst_equal (TYPE_MIN_VALUE (d1), TYPE_MIN_VALUE (d2))
    1826         7958 :             || !tree_int_cst_equal (TYPE_MAX_VALUE (d1), TYPE_MAX_VALUE (d2)))
    1827         4027 :           return false;
    1828              : 
    1829              :         return true;
    1830              :       }
    1831              : 
    1832     23575225 :     case ENUMERAL_TYPE:
    1833     23575225 :     case RECORD_TYPE:
    1834     23575225 :     case UNION_TYPE:
    1835              : 
    1836     23575225 :       if (!flag_isoc23)
    1837              :         return false;
    1838              : 
    1839     23575178 :       return tagged_types_tu_compatible_p (t1, t2, data);
    1840              : 
    1841       536946 :     case VECTOR_TYPE:
    1842      1073892 :       return known_eq (TYPE_VECTOR_SUBPARTS (t1), TYPE_VECTOR_SUBPARTS (t2))
    1843       536946 :              && comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2), data);
    1844              : 
    1845              :     default:
    1846              :       return false;
    1847              :     }
    1848              :   gcc_unreachable ();
    1849              : }
    1850              : 
    1851              : /* Return true if TTL and TTR are pointers to types that are equivalent, ignoring
    1852              :    their qualifiers, except for named address spaces.  If the pointers point to
    1853              :    different named addresses, then we must determine if one address space is a
    1854              :    subset of the other.  */
    1855              : 
    1856              : static bool
    1857      1769321 : comp_target_types (location_t location, tree ttl, tree ttr)
    1858              : {
    1859      1769321 :   tree mvl = TREE_TYPE (ttl);
    1860      1769321 :   tree mvr = TREE_TYPE (ttr);
    1861      1769321 :   addr_space_t asl = TYPE_ADDR_SPACE (mvl);
    1862      1769321 :   addr_space_t asr = TYPE_ADDR_SPACE (mvr);
    1863      1769321 :   addr_space_t as_common;
    1864              : 
    1865              :   /* Fail if pointers point to incompatible address spaces.  */
    1866      1769321 :   if (!addr_space_superset (asl, asr, &as_common))
    1867              :     return 0;
    1868              : 
    1869              :   /* Qualifiers on element types of array types that are
    1870              :      pointer targets are also removed.  */
    1871      1769321 :   struct comptypes_data data = { };
    1872      1769321 :   if (!comptypes_internal (remove_qualifiers (mvl),
    1873      1769321 :                            remove_qualifiers (mvr), &data))
    1874              :     return false;
    1875              : 
    1876              :   /* For pedantic use comptypes on arrays before removing
    1877              :      qualifiers on the element type. */
    1878      1667950 :   if (TREE_CODE (mvl) == ARRAY_TYPE
    1879         1891 :       && TREE_CODE (mvr) == ARRAY_TYPE
    1880      1669841 :       && !comptypes (mvl, mvr))
    1881          190 :     pedwarn_c11 (location, OPT_Wpedantic, "invalid use of pointers to arrays "
    1882              :                                           "with different qualifiers in ISO C "
    1883              :                                           "before C23");
    1884              : 
    1885      1667950 :   if (data.warning_needed)
    1886          126 :     pedwarn (location, OPT_Wpedantic, "types are not quite compatible");
    1887              : 
    1888      1667950 :   if (data.enum_and_int_p && warn_cxx_compat)
    1889            2 :     warning_at (location, OPT_Wc___compat,
    1890              :                 "pointer target types incompatible in C++");
    1891              : 
    1892              :   return true;
    1893              : }
    1894              : 
    1895              : /* Subroutines of `comptypes'.  */
    1896              : 
    1897              : /* Return true if two 'struct', 'union', or 'enum' types T1 and T2 are
    1898              :    compatible.  The two types are not the same (which has been
    1899              :    checked earlier in comptypes_internal).  */
    1900              : 
    1901              : static bool
    1902     23575178 : tagged_types_tu_compatible_p (const_tree t1, const_tree t2,
    1903              :                               struct comptypes_data *data)
    1904              : {
    1905     23575178 :   tree s1, s2;
    1906              : 
    1907     23575178 :   if (c_type_tag (t1) != c_type_tag (t2))
    1908              :     return false;
    1909              : 
    1910              :   /* When forming equivalence classes for TYPE_CANONICAL in C23, we treat
    1911              :      structs with the same tag as equivalent, but only when they are targets
    1912              :      of pointers inside other structs.  */
    1913     19426700 :   if (data->equiv && data->pointedto && NULL_TREE != c_type_tag (t1))
    1914              :     return true;
    1915              : 
    1916              :   /* Different types without tag are incompatible except as an anonymous
    1917              :      field or when forming equivalence classes for TYPE_CANONICAL.  */
    1918     19426638 :   if (!data->anon_field && !data->equiv && NULL_TREE == c_type_tag (t1))
    1919              :     return false;
    1920              : 
    1921     14275168 :   if (!data->anon_field && TYPE_STUB_DECL (t1) != TYPE_STUB_DECL (t2))
    1922     14274115 :     data->different_types_p = true;
    1923              : 
    1924              :   /* Incomplete types are incompatible inside a TU.  */
    1925     14275168 :   if (TYPE_SIZE (t1) == NULL || TYPE_SIZE (t2) == NULL)
    1926              :     return false;
    1927              : 
    1928     14275158 :   if (ENUMERAL_TYPE != TREE_CODE (t1)
    1929     14275158 :       && (TYPE_REVERSE_STORAGE_ORDER (t1)
    1930     14275103 :           != TYPE_REVERSE_STORAGE_ORDER (t2)))
    1931              :     return false;
    1932              : 
    1933     14275148 :   if (TYPE_USER_ALIGN (t1) != TYPE_USER_ALIGN (t2))
    1934       144666 :     data->different_types_p = true;
    1935              : 
    1936              :   /* For types already being looked at in some active
    1937              :      invocation of this function, assume compatibility.
    1938              :      The cache is built as a linked list on the stack
    1939              :      with the head of the list passed downwards.  */
    1940     14275148 :   for (const struct tagged_tu_seen_cache *t = data->cache;
    1941     14284833 :        t != NULL; t = t->next)
    1942         9980 :     if (t->t1 == t1 && t->t2 == t2)
    1943              :       return true;
    1944              : 
    1945     14274853 :   const struct tagged_tu_seen_cache entry = { data->cache, t1, t2 };
    1946              : 
    1947     14274853 :   switch (TREE_CODE (t1))
    1948              :     {
    1949           55 :     case ENUMERAL_TYPE:
    1950           55 :       {
    1951           55 :         if (!comptypes (ENUM_UNDERLYING_TYPE (t1), ENUM_UNDERLYING_TYPE (t2)))
    1952              :           return false;
    1953              : 
    1954              :         /* Speed up the case where the type values are in the same order.  */
    1955           51 :         tree tv1 = TYPE_VALUES (t1);
    1956           51 :         tree tv2 = TYPE_VALUES (t2);
    1957              : 
    1958           51 :         if (tv1 == tv2)
    1959              :           return true;
    1960              : 
    1961           97 :         for (;tv1 && tv2; tv1 = TREE_CHAIN (tv1), tv2 = TREE_CHAIN (tv2))
    1962              :           {
    1963           58 :             if (TREE_PURPOSE (tv1) != TREE_PURPOSE (tv2))
    1964              :               break;
    1965              : 
    1966           51 :             if (simple_cst_equal (DECL_INITIAL (TREE_VALUE (tv1)),
    1967           51 :                                   DECL_INITIAL (TREE_VALUE (tv2))) != 1)
    1968              :               break;
    1969              :           }
    1970              : 
    1971           51 :         if (tv1 == NULL_TREE && tv2 == NULL_TREE)
    1972              :           return true;
    1973              : 
    1974           12 :         if (tv1 == NULL_TREE || tv2 == NULL_TREE)
    1975              :           return false;
    1976              : 
    1977           12 :         if (list_length (TYPE_VALUES (t1)) != list_length (TYPE_VALUES (t2)))
    1978              :           return false;
    1979              : 
    1980           20 :         for (s1 = TYPE_VALUES (t1); s1; s1 = TREE_CHAIN (s1))
    1981              :           {
    1982           16 :             s2 = purpose_member (TREE_PURPOSE (s1), TYPE_VALUES (t2));
    1983              : 
    1984           16 :             if (s2 == NULL
    1985           29 :                 || simple_cst_equal (DECL_INITIAL (TREE_VALUE (s1)),
    1986           13 :                                      DECL_INITIAL (TREE_VALUE (s2))) != 1)
    1987            8 :               return false;
    1988              :           }
    1989              : 
    1990              :         return true;
    1991              :       }
    1992              : 
    1993     14274798 :     case UNION_TYPE:
    1994     14274798 :     case RECORD_TYPE:
    1995              : 
    1996     14274798 :         if (list_length (TYPE_FIELDS (t1)) != list_length (TYPE_FIELDS (t2)))
    1997              :           return false;
    1998              : 
    1999     12329489 :         for (s1 = TYPE_FIELDS (t1), s2 = TYPE_FIELDS (t2);
    2000     13851942 :              s1 && s2;
    2001      1522453 :              s1 = DECL_CHAIN (s1), s2 = DECL_CHAIN (s2))
    2002              :           {
    2003     13786398 :             gcc_assert (TREE_CODE (s1) == FIELD_DECL);
    2004     13786398 :             gcc_assert (TREE_CODE (s2) == FIELD_DECL);
    2005              : 
    2006     13786398 :             tree ft1 = TREE_TYPE (s1);
    2007     13786398 :             tree ft2 = TREE_TYPE (s2);
    2008              : 
    2009     13786398 :             if (DECL_NAME (s1) != DECL_NAME (s2))
    2010              :               return false;
    2011              : 
    2012     12135456 :             if (DECL_ALIGN (s1) != DECL_ALIGN (s2))
    2013              :               return false;
    2014              : 
    2015      3233629 :             if (DECL_C_BIT_FIELD (s1) != DECL_C_BIT_FIELD (s2))
    2016              :                return false;
    2017              : 
    2018      3233609 :             if (DECL_C_BIT_FIELD (s1))
    2019              :               {
    2020          496 :                 if (!tree_int_cst_equal (DECL_SIZE (s1), DECL_SIZE (s2)))
    2021              :                   return false;
    2022              : 
    2023          342 :                 ft1 = DECL_BIT_FIELD_TYPE (s1);
    2024          342 :                 ft2 = DECL_BIT_FIELD_TYPE (s2);
    2025              :               }
    2026              : 
    2027      3233455 :             if (!ft1 || !ft2)
    2028              :               return false;
    2029              : 
    2030      3233455 :             if (TREE_CODE (ft1) == ERROR_MARK || TREE_CODE (ft2) == ERROR_MARK)
    2031              :               return false;
    2032              : 
    2033      3233454 :             data->anon_field = !DECL_NAME (s1);
    2034      3233454 :             data->pointedto = false;
    2035              : 
    2036      3233454 :             const struct tagged_tu_seen_cache *cache = data->cache;
    2037      3233454 :             data->cache = &entry;
    2038      3233454 :             bool ret = comptypes_internal (ft1, ft2, data);
    2039      3233454 :             data->cache = cache;
    2040      3233454 :             if (!ret)
    2041              :               return false;
    2042              : 
    2043      1591899 :             tree st1 = TYPE_SIZE (TREE_TYPE (s1));
    2044      1591899 :             tree st2 = TYPE_SIZE (TREE_TYPE (s2));
    2045              : 
    2046      1591899 :             if (data->equiv
    2047       997615 :                 && st1 && TREE_CODE (st1) == INTEGER_CST
    2048       997133 :                 && st2 && TREE_CODE (st2) == INTEGER_CST
    2049      2589026 :                 && !tree_int_cst_equal (st1, st2))
    2050              :              return false;
    2051              : 
    2052      1522487 :             tree counted_by1 = lookup_attribute ("counted_by",
    2053      1522487 :                                                  DECL_ATTRIBUTES (s1));
    2054      1522487 :             tree counted_by2 = lookup_attribute ("counted_by",
    2055      1522487 :                                                  DECL_ATTRIBUTES (s2));
    2056              :             /* If there is no counted_by attribute for both fields.  */
    2057      1522487 :             if (!counted_by1 && !counted_by2)
    2058      1522423 :               continue;
    2059              : 
    2060              :             /* If only one field has counted_by attribute.  */
    2061           64 :             if ((counted_by1 && !counted_by2)
    2062           64 :                 || (!counted_by1 && counted_by2))
    2063              :               return false;
    2064              : 
    2065              :             /* Now both s1 and s2 have counted_by attributes, check
    2066              :                whether they are the same.  */
    2067              : 
    2068           52 :             tree counted_by_field1
    2069           52 :               = lookup_field (t1, TREE_VALUE (TREE_VALUE (counted_by1)));
    2070           52 :             tree counted_by_field2
    2071           52 :               = lookup_field (t2, TREE_VALUE (TREE_VALUE (counted_by2)));
    2072              : 
    2073           52 :             gcc_assert (counted_by_field1 && counted_by_field2);
    2074              : 
    2075           94 :             while (TREE_CHAIN (counted_by_field1))
    2076           42 :               counted_by_field1 = TREE_CHAIN (counted_by_field1);
    2077           86 :             while (TREE_CHAIN (counted_by_field2))
    2078           34 :               counted_by_field2 = TREE_CHAIN (counted_by_field2);
    2079              : 
    2080           52 :             if (DECL_NAME (TREE_VALUE (counted_by_field1))
    2081           52 :                 != DECL_NAME (TREE_VALUE (counted_by_field2)))
    2082              :               return false;
    2083              :           }
    2084              :         return true;
    2085              : 
    2086            0 :     default:
    2087            0 :       gcc_unreachable ();
    2088              :     }
    2089              : }
    2090              : 
    2091              : /* Return true if two function types F1 and F2 are compatible.
    2092              :    If either type specifies no argument types,
    2093              :    the other must specify a fixed number of self-promoting arg types.
    2094              :    Otherwise, if one type specifies only the number of arguments,
    2095              :    the other must specify that number of self-promoting arg types.
    2096              :    Otherwise, the argument types must match.  */
    2097              : 
    2098              : static bool
    2099      9178288 : function_types_compatible_p (const_tree f1, const_tree f2,
    2100              :                              struct comptypes_data *data)
    2101              : {
    2102      9178288 :   tree ret1 = TREE_TYPE (f1);
    2103      9178288 :   tree ret2 = TREE_TYPE (f2);
    2104              : 
    2105              :   /* 'volatile' qualifiers on a function's return type used to mean
    2106              :      the function is noreturn.  */
    2107      9178288 :   if (TYPE_VOLATILE (ret1) != TYPE_VOLATILE (ret2))
    2108           29 :     pedwarn (input_location, 0, "function return types not compatible due to %<volatile%>");
    2109      9178288 :   if (TYPE_VOLATILE (ret1))
    2110           15 :     ret1 = build_qualified_type (TYPE_MAIN_VARIANT (ret1),
    2111           15 :                                  TYPE_QUALS (ret1) & ~TYPE_QUAL_VOLATILE);
    2112      9178288 :   if (TYPE_VOLATILE (ret2))
    2113           18 :     ret2 = build_qualified_type (TYPE_MAIN_VARIANT (ret2),
    2114           18 :                                  TYPE_QUALS (ret2) & ~TYPE_QUAL_VOLATILE);
    2115              : 
    2116      9178288 :   bool ignore_pargs = data->ignore_promoting_args;
    2117      9178288 :   data->ignore_promoting_args = false;
    2118              : 
    2119      9178288 :   if (!comptypes_internal (ret1, ret2, data))
    2120              :     return false;
    2121              : 
    2122      9175693 :   data->ignore_promoting_args = ignore_pargs;
    2123              : 
    2124      9175693 :   tree args1 = TYPE_ARG_TYPES (f1);
    2125      9175693 :   tree args2 = TYPE_ARG_TYPES (f2);
    2126              : 
    2127      9175693 :   if ((args1 == NULL_TREE) != (args2 == NULL_TREE))
    2128        45217 :     data->different_types_p = true;
    2129              : 
    2130              :   /* An unspecified parmlist matches any specified parmlist
    2131              :      whose argument types don't need default promotions.  */
    2132              : 
    2133      9175693 :   if (args1 == NULL_TREE)
    2134              :     {
    2135        23753 :       if (TYPE_NO_NAMED_ARGS_STDARG_P (f1) != TYPE_NO_NAMED_ARGS_STDARG_P (f2))
    2136              :         return false;
    2137        23750 :       if (!(data->ignore_promoting_args || self_promoting_args_p (args2)))
    2138              :         return false;
    2139        23278 :       data->ignore_promoting_args = false;
    2140              :       /* If one of these types comes from a non-prototype fn definition,
    2141              :          compare that with the other type's arglist.
    2142              :          If they don't match, ask for a warning (but no error).  */
    2143        23278 :       if (TYPE_ACTUAL_ARG_TYPES (f1)
    2144        23278 :           && !type_lists_compatible_p (args2, TYPE_ACTUAL_ARG_TYPES (f1), data))
    2145           12 :          data->warning_needed = true;
    2146        23278 :       return true;
    2147              :     }
    2148      9151940 :   if (args2 == NULL_TREE)
    2149              :     {
    2150        21546 :       if (TYPE_NO_NAMED_ARGS_STDARG_P (f1) != TYPE_NO_NAMED_ARGS_STDARG_P (f2))
    2151              :         return false;
    2152        21544 :       if (!(data->ignore_promoting_args || self_promoting_args_p (args1)))
    2153              :         return false;
    2154        21483 :       data->ignore_promoting_args = false;
    2155        21483 :       if (TYPE_ACTUAL_ARG_TYPES (f2)
    2156        21483 :           && !type_lists_compatible_p (args1, TYPE_ACTUAL_ARG_TYPES (f2), data))
    2157            1 :         data->warning_needed = true;
    2158        21483 :       return true;
    2159              :     }
    2160              : 
    2161              :   /* Both types have argument lists: compare them and propagate results.  */
    2162      9130394 :   return type_lists_compatible_p (args1, args2, data);
    2163              : }
    2164              : 
    2165              : /* Check two lists of types for compatibility, returning false for
    2166              :    incompatible, true for compatible.  */
    2167              : 
    2168              : static bool
    2169      9130470 : type_lists_compatible_p (const_tree args1, const_tree args2,
    2170              :                          struct comptypes_data *data)
    2171              : {
    2172     56742468 :   while (1)
    2173              :     {
    2174     32936469 :       if (args1 == NULL_TREE && args2 == NULL_TREE)
    2175              :         return true;
    2176              :       /* If one list is shorter than the other,
    2177              :          they fail to match.  */
    2178     23951825 :       if (args1 == NULL_TREE || args2 == NULL_TREE)
    2179              :         return false;
    2180     23951818 :       tree a1 = TREE_VALUE (args1);
    2181     23951818 :       tree a2 = TREE_VALUE (args2);
    2182     23951818 :       tree mv1 = remove_qualifiers (a1);
    2183     23951818 :       tree mv2 = remove_qualifiers (a2);
    2184              : 
    2185     23951818 :       gcc_assert (mv2);
    2186     23951818 :       gcc_assert (mv2);
    2187              : 
    2188              :       /* If one of the lists has an error marker, ignore this arg.  */
    2189     23951818 :       if (TREE_CODE (a1) == ERROR_MARK
    2190     23951814 :                || TREE_CODE (a2) == ERROR_MARK)
    2191              :         ;
    2192     23951798 :       else if (!comptypes_internal (mv1, mv2, data))
    2193              :         {
    2194       146050 :           data->different_types_p = true;
    2195              :           /* Allow  wait (union {union wait *u; int *i} *)
    2196              :              and  wait (union wait *)  to be compatible.  */
    2197       146050 :           if (TREE_CODE (a1) == UNION_TYPE
    2198          130 :               && (TYPE_NAME (a1) == NULL_TREE
    2199           98 :                   || TYPE_TRANSPARENT_AGGR (a1))
    2200          130 :               && TREE_CODE (TYPE_SIZE (a1)) == INTEGER_CST
    2201       146180 :               && tree_int_cst_equal (TYPE_SIZE (a1),
    2202          130 :                                      TYPE_SIZE (a2)))
    2203              :             {
    2204          130 :               tree memb;
    2205          130 :               for (memb = TYPE_FIELDS (a1);
    2206          166 :                    memb; memb = DECL_CHAIN (memb))
    2207              :                 {
    2208          164 :                   tree mv3 = remove_qualifiers (TREE_TYPE (memb));
    2209          164 :                   if (comptypes_internal (mv3, mv2, data))
    2210              :                     break;
    2211              :                 }
    2212              :               if (memb == NULL_TREE)
    2213              :                 return false;
    2214              :             }
    2215       145920 :           else if (TREE_CODE (a2) == UNION_TYPE
    2216          105 :                    && (TYPE_NAME (a2) == NULL_TREE
    2217           74 :                        || TYPE_TRANSPARENT_AGGR (a2))
    2218          105 :                    && TREE_CODE (TYPE_SIZE (a2)) == INTEGER_CST
    2219       146025 :                    && tree_int_cst_equal (TYPE_SIZE (a2),
    2220          105 :                                           TYPE_SIZE (a1)))
    2221              :             {
    2222          105 :               tree memb;
    2223          105 :               for (memb = TYPE_FIELDS (a2);
    2224          133 :                    memb; memb = DECL_CHAIN (memb))
    2225              :                 {
    2226          131 :                   tree mv3 = remove_qualifiers (TREE_TYPE (memb));
    2227          131 :                   if (comptypes_internal (mv3, mv1, data))
    2228              :                     break;
    2229              :                 }
    2230              :               if (memb == NULL_TREE)
    2231              :                 return false;
    2232              :             }
    2233              :           else
    2234       145815 :             return false;
    2235              :         }
    2236              : 
    2237     23805999 :       args1 = TREE_CHAIN (args1);
    2238     23805999 :       args2 = TREE_CHAIN (args2);
    2239     23805999 :     }
    2240              : }
    2241              : 
    2242              : /* Compute the size to increment a pointer by.  When a function type or void
    2243              :    type or incomplete type is passed, size_one_node is returned.
    2244              :    This function does not emit any diagnostics; the caller is responsible
    2245              :    for that.  */
    2246              : 
    2247              : static tree
    2248       234164 : c_size_in_bytes (const_tree type)
    2249              : {
    2250       234164 :   enum tree_code code = TREE_CODE (type);
    2251              : 
    2252       234164 :   if (code == FUNCTION_TYPE || code == VOID_TYPE || code == ERROR_MARK
    2253       234164 :       || !COMPLETE_TYPE_P (type))
    2254          191 :     return size_one_node;
    2255              : 
    2256              :   /* Convert in case a char is more than one unit.  */
    2257       233973 :   return size_binop_loc (input_location, CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
    2258       233973 :                          size_int (TYPE_PRECISION (char_type_node)
    2259              :                                    / BITS_PER_UNIT));
    2260              : }
    2261              : 
    2262              : /* Return either DECL or its known constant value (if it has one).  */
    2263              : 
    2264              : tree
    2265     14345736 : decl_constant_value_1 (tree decl, bool in_init)
    2266              : {
    2267     14345736 :   if (/* Note that DECL_INITIAL isn't valid for a PARM_DECL.  */
    2268     14345736 :       TREE_CODE (decl) != PARM_DECL
    2269     14345736 :       && !TREE_THIS_VOLATILE (decl)
    2270     14001399 :       && TREE_READONLY (decl)
    2271        36729 :       && DECL_INITIAL (decl) != NULL_TREE
    2272        35733 :       && !error_operand_p (DECL_INITIAL (decl))
    2273              :       /* This is invalid if initial value is not constant.
    2274              :          If it has either a function call, a memory reference,
    2275              :          or a variable, then re-evaluating it could give different results.  */
    2276        35724 :       && TREE_CONSTANT (DECL_INITIAL (decl))
    2277              :       /* Check for cases where this is sub-optimal, even though valid.  */
    2278     14368398 :       && (in_init || TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR))
    2279        17546 :     return DECL_INITIAL (decl);
    2280              :   return decl;
    2281              : }
    2282              : 
    2283              : /* Return either DECL or its known constant value (if it has one).
    2284              :    Like the above, but always return decl outside of functions.  */
    2285              : 
    2286              : tree
    2287     14345488 : decl_constant_value (tree decl)
    2288              : {
    2289              :   /* Don't change a variable array bound or initial value to a constant
    2290              :      in a place where a variable is invalid.  */
    2291     14345488 :   return current_function_decl ? decl_constant_value_1 (decl, false) : decl;
    2292              : }
    2293              : 
    2294              : /* Convert the array expression EXP to a pointer.  */
    2295              : static tree
    2296       828215 : array_to_pointer_conversion (location_t loc, tree exp)
    2297              : {
    2298       828215 :   tree orig_exp = exp;
    2299       828215 :   tree type = TREE_TYPE (exp);
    2300       828215 :   tree adr;
    2301       828215 :   tree restype = TREE_TYPE (type);
    2302       828215 :   tree ptrtype;
    2303              : 
    2304       828215 :   gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
    2305              : 
    2306       828215 :   STRIP_TYPE_NOPS (exp);
    2307              : 
    2308       828215 :   copy_warning (exp, orig_exp);
    2309              : 
    2310       828215 :   ptrtype = c_build_pointer_type (restype);
    2311              : 
    2312       828215 :   if (INDIRECT_REF_P (exp))
    2313         2906 :     return convert (ptrtype, TREE_OPERAND (exp, 0));
    2314              : 
    2315              :   /* In C++ array compound literals are temporary objects unless they are
    2316              :      const or appear in namespace scope, so they are destroyed too soon
    2317              :      to use them for much of anything  (c++/53220).  */
    2318       825309 :   if (warn_cxx_compat && TREE_CODE (exp) == COMPOUND_LITERAL_EXPR)
    2319              :     {
    2320           48 :       tree decl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
    2321           48 :       if (!TREE_READONLY (decl) && !TREE_STATIC (decl))
    2322           46 :         warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat,
    2323              :                     "converting an array compound literal to a pointer "
    2324              :                     "leads to a dangling pointer in C++");
    2325              :     }
    2326              : 
    2327       825309 :   adr = build_unary_op (loc, ADDR_EXPR, exp, true);
    2328       825309 :   return convert (ptrtype, adr);
    2329              : }
    2330              : 
    2331              : /* Convert the function expression EXP to a pointer.  */
    2332              : static tree
    2333     50612551 : function_to_pointer_conversion (location_t loc, tree exp)
    2334              : {
    2335     50612551 :   tree orig_exp = exp;
    2336              : 
    2337     50612551 :   gcc_assert (TREE_CODE (TREE_TYPE (exp)) == FUNCTION_TYPE);
    2338              : 
    2339     50612551 :   STRIP_TYPE_NOPS (exp);
    2340              : 
    2341     50612551 :   copy_warning (exp, orig_exp);
    2342              : 
    2343     50612551 :   tree exp2 = build_unary_op (loc, ADDR_EXPR, exp, false);
    2344              : 
    2345              :   /* If the function is defined and known to not require a non-local
    2346              :      context, make sure no trampoline is generated.  */
    2347     50612551 :   if (TREE_CODE (exp) == FUNCTION_DECL
    2348     50612551 :       && DECL_INITIAL (exp) && !C_FUNC_NONLOCAL_CONTEXT (exp))
    2349     16068406 :    TREE_NO_TRAMPOLINE (exp2) = 1;
    2350              : 
    2351     50612551 :   return exp2;
    2352              : }
    2353              : 
    2354              : /* Mark EXP as read, not just set, for set but not used -Wunused
    2355              :    warning purposes.  */
    2356              : 
    2357              : void
    2358    491991578 : mark_exp_read (tree exp)
    2359              : {
    2360    618387673 :   switch (TREE_CODE (exp))
    2361              :     {
    2362    203425906 :     case VAR_DECL:
    2363    203425906 :     case PARM_DECL:
    2364    203425906 :       DECL_READ_P (exp) = 1;
    2365    203425906 :       break;
    2366     19721761 :     CASE_CONVERT:
    2367     19721761 :       if (VOID_TYPE_P (TREE_TYPE (exp)))
    2368         3805 :         switch (TREE_CODE (TREE_OPERAND (exp, 0)))
    2369              :           {
    2370              :           case PREINCREMENT_EXPR:
    2371              :           case PREDECREMENT_EXPR:
    2372              :           case POSTINCREMENT_EXPR:
    2373              :           case POSTDECREMENT_EXPR:
    2374              :             return;
    2375              :           default:
    2376              :             break;
    2377              :           }
    2378              :       /* FALLTHRU */
    2379    123651118 :     case ARRAY_REF:
    2380    123651118 :     case COMPONENT_REF:
    2381    123651118 :     case MODIFY_EXPR:
    2382    123651118 :     case REALPART_EXPR:
    2383    123651118 :     case IMAGPART_EXPR:
    2384    123651118 :     case ADDR_EXPR:
    2385    123651118 :     case VIEW_CONVERT_EXPR:
    2386    123651118 :     case PREINCREMENT_EXPR:
    2387    123651118 :     case PREDECREMENT_EXPR:
    2388    123651118 :     case POSTINCREMENT_EXPR:
    2389    123651118 :     case POSTDECREMENT_EXPR:
    2390    123651118 :       mark_exp_read (TREE_OPERAND (exp, 0));
    2391    123651118 :       break;
    2392       235995 :     case COMPOUND_EXPR:
    2393              :       /* Pattern match what build_atomic_assign produces with modifycode
    2394              :          NOP_EXPR.  */
    2395       235995 :       if (VAR_P (TREE_OPERAND (exp, 1))
    2396        27227 :           && DECL_ARTIFICIAL (TREE_OPERAND (exp, 1))
    2397       263138 :           && TREE_CODE (TREE_OPERAND (exp, 0)) == COMPOUND_EXPR)
    2398              :         {
    2399         2210 :           tree t1 = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
    2400         2210 :           tree t2 = TREE_OPERAND (TREE_OPERAND (exp, 0), 1);
    2401         2210 :           if (TREE_CODE (t1) == TARGET_EXPR
    2402         2202 :               && TARGET_EXPR_SLOT (t1) == TREE_OPERAND (exp, 1)
    2403         4410 :               && TREE_CODE (t2) == CALL_EXPR)
    2404              :             {
    2405         2200 :               tree fndecl = get_callee_fndecl (t2);
    2406         2200 :               tree arg = NULL_TREE;
    2407         2200 :               if (fndecl
    2408         2200 :                   && TREE_CODE (fndecl) == FUNCTION_DECL
    2409         2200 :                   && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)
    2410         4400 :                   && call_expr_nargs (t2) >= 2)
    2411         2200 :                 switch (DECL_FUNCTION_CODE (fndecl))
    2412              :                   {
    2413          130 :                   case BUILT_IN_ATOMIC_STORE:
    2414          130 :                     arg = CALL_EXPR_ARG (t2, 1);
    2415          130 :                     break;
    2416         2070 :                   case BUILT_IN_ATOMIC_STORE_1:
    2417         2070 :                   case BUILT_IN_ATOMIC_STORE_2:
    2418         2070 :                   case BUILT_IN_ATOMIC_STORE_4:
    2419         2070 :                   case BUILT_IN_ATOMIC_STORE_8:
    2420         2070 :                   case BUILT_IN_ATOMIC_STORE_16:
    2421         2070 :                     arg = CALL_EXPR_ARG (t2, 0);
    2422         2070 :                     break;
    2423              :                   default:
    2424              :                     break;
    2425              :                   }
    2426         2200 :               if (arg)
    2427              :                 {
    2428         2200 :                   STRIP_NOPS (arg);
    2429         2200 :                   if (TREE_CODE (arg) == ADDR_EXPR
    2430         2200 :                       && DECL_P (TREE_OPERAND (arg, 0))
    2431         4400 :                       && TYPE_ATOMIC (TREE_TYPE (TREE_OPERAND (arg, 0))))
    2432         2200 :                     mark_exp_read (TREE_OPERAND (arg, 0));
    2433              :                 }
    2434              :             }
    2435              :         }
    2436              :       /* FALLTHRU */
    2437      2744434 :     case C_MAYBE_CONST_EXPR:
    2438      2744434 :       mark_exp_read (TREE_OPERAND (exp, 1));
    2439      2744434 :       break;
    2440          578 :     case OMP_ARRAY_SECTION:
    2441          578 :       mark_exp_read (TREE_OPERAND (exp, 0));
    2442          578 :       if (TREE_OPERAND (exp, 1))
    2443          384 :         mark_exp_read (TREE_OPERAND (exp, 1));
    2444          578 :       if (TREE_OPERAND (exp, 2))
    2445          543 :         mark_exp_read (TREE_OPERAND (exp, 2));
    2446              :       break;
    2447              :     default:
    2448              :       break;
    2449              :     }
    2450              : }
    2451              : 
    2452              : /* Perform the default conversion of arrays and functions to pointers.
    2453              :    Return the result of converting EXP.  For any other expression, just
    2454              :    return EXP.
    2455              : 
    2456              :    LOC is the location of the expression.  */
    2457              : 
    2458              : struct c_expr
    2459    362273283 : default_function_array_conversion (location_t loc, struct c_expr exp)
    2460              : {
    2461    362273283 :   tree orig_exp = exp.value;
    2462    362273283 :   tree type = TREE_TYPE (exp.value);
    2463    362273283 :   enum tree_code code = TREE_CODE (type);
    2464              : 
    2465    362273283 :   switch (code)
    2466              :     {
    2467              :     case ARRAY_TYPE:
    2468              :       {
    2469              :         bool not_lvalue = false;
    2470              :         bool lvalue_array_p;
    2471              : 
    2472       781306 :         while ((TREE_CODE (exp.value) == NON_LVALUE_EXPR
    2473       781306 :                 || CONVERT_EXPR_P (exp.value))
    2474       781306 :                && TREE_TYPE (TREE_OPERAND (exp.value, 0)) == type)
    2475              :           {
    2476            0 :             if (TREE_CODE (exp.value) == NON_LVALUE_EXPR)
    2477            0 :               not_lvalue = true;
    2478            0 :             exp.value = TREE_OPERAND (exp.value, 0);
    2479              :           }
    2480              : 
    2481       781306 :         copy_warning (exp.value, orig_exp);
    2482              : 
    2483       781306 :         lvalue_array_p = !not_lvalue && lvalue_p (exp.value);
    2484       781306 :         if (!flag_isoc99 && !lvalue_array_p)
    2485              :           {
    2486              :             /* Before C99, non-lvalue arrays do not decay to pointers.
    2487              :                Normally, using such an array would be invalid; but it can
    2488              :                be used correctly inside sizeof or as a statement expression.
    2489              :                Thus, do not give an error here; an error will result later.  */
    2490          109 :             return exp;
    2491              :           }
    2492              : 
    2493       781197 :         exp.value = array_to_pointer_conversion (loc, exp.value);
    2494              :       }
    2495       781197 :       break;
    2496       762314 :     case FUNCTION_TYPE:
    2497       762314 :       exp.value = function_to_pointer_conversion (loc, exp.value);
    2498       762314 :       break;
    2499              :     default:
    2500              :       break;
    2501              :     }
    2502              : 
    2503    362273174 :   return exp;
    2504              : }
    2505              : 
    2506              : struct c_expr
    2507        12659 : default_function_array_read_conversion (location_t loc, struct c_expr exp)
    2508              : {
    2509        12659 :   mark_exp_read (exp.value);
    2510              :   /* We only generate a call to .ACCESS_WITH_SIZE when it is a read.  */
    2511        12659 :   if (TREE_CODE (exp.value) == COMPONENT_REF
    2512        12659 :       && handle_counted_by_p (exp.value))
    2513            4 :     exp.value = handle_counted_by_for_component_ref (loc, exp.value);
    2514        12659 :   return default_function_array_conversion (loc, exp);
    2515              : }
    2516              : 
    2517              : /* Return whether EXPR should be treated as an atomic lvalue for the
    2518              :    purposes of load and store handling.  */
    2519              : 
    2520              : static bool
    2521    363369558 : really_atomic_lvalue (tree expr)
    2522              : {
    2523    363369558 :   if (error_operand_p (expr))
    2524              :     return false;
    2525    363361733 :   if (!TYPE_ATOMIC (TREE_TYPE (expr)))
    2526              :     return false;
    2527        57393 :   if (!COMPLETE_TYPE_P (TREE_TYPE (expr)))
    2528              :     return false;
    2529        57390 :   if (!lvalue_p (expr))
    2530              :     return false;
    2531              : 
    2532              :   /* Ignore _Atomic on register variables, since their addresses can't
    2533              :      be taken so (a) atomicity is irrelevant and (b) the normal atomic
    2534              :      sequences wouldn't work.  Ignore _Atomic on structures containing
    2535              :      bit-fields, since accessing elements of atomic structures or
    2536              :      unions is undefined behavior (C11 6.5.2.3#5), but it's unclear if
    2537              :      it's undefined at translation time or execution time, and the
    2538              :      normal atomic sequences again wouldn't work.  */
    2539        57532 :   while (handled_component_p (expr))
    2540              :     {
    2541          144 :       if (TREE_CODE (expr) == COMPONENT_REF
    2542          144 :           && DECL_C_BIT_FIELD (TREE_OPERAND (expr, 1)))
    2543              :         return false;
    2544          144 :       expr = TREE_OPERAND (expr, 0);
    2545              :     }
    2546        57388 :   if (TREE_CODE (expr) == COMPOUND_LITERAL_EXPR)
    2547            1 :     expr = COMPOUND_LITERAL_EXPR_DECL (expr);
    2548       112572 :   if (DECL_P (expr) && C_DECL_REGISTER (expr))
    2549              :     return false;
    2550              :   return true;
    2551              : }
    2552              : 
    2553              : /* If EXPR is a named constant (C23) derived from a constexpr variable
    2554              :    - that is, a reference to such a variable, or a member extracted by
    2555              :    a sequence of structure and union (but not array) member accesses
    2556              :    (where union member accesses must access the same member as
    2557              :    initialized) - then return the corresponding initializer;
    2558              :    otherwise, return NULL_TREE.  */
    2559              : 
    2560              : static tree
    2561    360177837 : maybe_get_constexpr_init (tree expr)
    2562              : {
    2563    360177837 :   tree decl = NULL_TREE;
    2564    360177837 :   if (TREE_CODE (expr) == VAR_DECL)
    2565              :     decl = expr;
    2566    348452970 :   else if (TREE_CODE (expr) == COMPOUND_LITERAL_EXPR)
    2567       822117 :     decl = COMPOUND_LITERAL_EXPR_DECL (expr);
    2568       822117 :   if (decl
    2569     12546984 :       && C_DECL_DECLARED_CONSTEXPR (decl)
    2570          378 :       && DECL_INITIAL (decl) != NULL_TREE
    2571       822495 :       && !error_operand_p (DECL_INITIAL (decl)))
    2572          378 :     return DECL_INITIAL (decl);
    2573    360177459 :   if (TREE_CODE (expr) != COMPONENT_REF)
    2574              :     return NULL_TREE;
    2575       875993 :   tree inner = maybe_get_constexpr_init (TREE_OPERAND (expr, 0));
    2576       875993 :   if (inner == NULL_TREE)
    2577              :     return NULL_TREE;
    2578          126 :   while ((CONVERT_EXPR_P (inner) || TREE_CODE (inner) == NON_LVALUE_EXPR)
    2579           47 :          && !error_operand_p (inner)
    2580          220 :          && (TYPE_MAIN_VARIANT (TREE_TYPE (inner))
    2581           47 :              == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (inner, 0)))))
    2582           47 :     inner = TREE_OPERAND (inner, 0);
    2583          126 :   if (TREE_CODE (inner) != CONSTRUCTOR)
    2584              :     return NULL_TREE;
    2585          126 :   tree field = TREE_OPERAND (expr, 1);
    2586          126 :   unsigned HOST_WIDE_INT cidx;
    2587          126 :   tree cfield, cvalue;
    2588          126 :   bool have_other_init = false;
    2589          266 :   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (inner), cidx, cfield, cvalue)
    2590              :     {
    2591          250 :       if (cfield == field)
    2592              :         return cvalue;
    2593          140 :       have_other_init = true;
    2594              :     }
    2595           16 :   if (TREE_CODE (TREE_TYPE (inner)) == UNION_TYPE
    2596           16 :       && (have_other_init || field != TYPE_FIELDS (TREE_TYPE (inner))))
    2597              :     return NULL_TREE;
    2598              :   /* Return a default initializer.  */
    2599           13 :   if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (expr)))
    2600            5 :     return build_constructor (TREE_TYPE (expr), NULL);
    2601            8 :   return build_zero_cst (TREE_TYPE (expr));
    2602              : }
    2603              : 
    2604              : /* Helper function for convert_lvalue_to_rvalue called via
    2605              :    walk_tree_without_duplicates.  Find DATA inside of the expression.  */
    2606              : 
    2607              : static tree
    2608       230295 : c_find_var_r (tree *tp, int *walk_subtrees, void *data)
    2609              : {
    2610       230295 :   if (TYPE_P (*tp))
    2611            0 :     *walk_subtrees = 0;
    2612       230295 :   else if (*tp == (tree) data)
    2613              :     return *tp;
    2614              :   return NULL_TREE;
    2615              : }
    2616              : 
    2617              : /* Convert expression EXP (location LOC) from lvalue to rvalue,
    2618              :    including converting functions and arrays to pointers if CONVERT_P.
    2619              :    If READ_P, also mark the expression as having been read.  If
    2620              :    FOR_INIT, constexpr expressions of structure and union type should
    2621              :    be replaced by the corresponding CONSTRUCTOR; otherwise, only
    2622              :    constexpr scalars (including elements of structures and unions) are
    2623              :    replaced by their initializers.  */
    2624              : 
    2625              : struct c_expr
    2626    359489615 : convert_lvalue_to_rvalue (location_t loc, struct c_expr exp,
    2627              :                           bool convert_p, bool read_p, bool for_init)
    2628              : {
    2629    359489615 :   bool force_non_npc = false;
    2630    359489615 :   if (read_p)
    2631    315428230 :     mark_exp_read (exp.value);
    2632              :   /* We only generate a call to .ACCESS_WITH_SIZE when it is a read.  */
    2633    315428230 :   if (read_p && TREE_CODE (exp.value) == COMPONENT_REF
    2634       784166 :       && handle_counted_by_p (exp.value))
    2635       784137 :     exp.value = handle_counted_by_for_component_ref (loc, exp.value);
    2636              : 
    2637    359489615 :   if (convert_p)
    2638    359476352 :     exp = default_function_array_conversion (loc, exp);
    2639    359489615 :   if (!VOID_TYPE_P (TREE_TYPE (exp.value))
    2640    359489615 :       || (flag_isoc2y
    2641         1574 :           && TYPE_QUALS (TREE_TYPE (exp.value)) != TYPE_UNQUALIFIED))
    2642    357004531 :     exp.value = require_complete_type (loc, exp.value);
    2643    359489615 :   if (for_init || !RECORD_OR_UNION_TYPE_P (TREE_TYPE (exp.value)))
    2644              :     {
    2645    359301844 :       tree init = maybe_get_constexpr_init (exp.value);
    2646    359301844 :       if (init != NULL_TREE)
    2647              :         {
    2648              :           /* A named constant of pointer type or type nullptr_t is not
    2649              :              a null pointer constant even if the initializer is
    2650              :              one.  */
    2651          375 :           if (TREE_CODE (init) == INTEGER_CST
    2652          240 :               && !INTEGRAL_TYPE_P (TREE_TYPE (init))
    2653          401 :               && integer_zerop (init))
    2654              :             force_non_npc = true;
    2655              :           exp.value = init;
    2656              :         }
    2657              :     }
    2658    359489615 :   if (really_atomic_lvalue (exp.value))
    2659              :     {
    2660        26938 :       vec<tree, va_gc> *params;
    2661        26938 :       tree nonatomic_type, tmp, tmp_addr, fndecl, func_call;
    2662        26938 :       tree expr_type = TREE_TYPE (exp.value);
    2663        26938 :       tree expr_addr = build_unary_op (loc, ADDR_EXPR, exp.value, false);
    2664        26938 :       tree seq_cst = build_int_cst (integer_type_node, MEMMODEL_SEQ_CST);
    2665              : 
    2666        26938 :       gcc_assert (TYPE_ATOMIC (expr_type));
    2667              : 
    2668              :       /* Expansion of a generic atomic load may require an addition
    2669              :          element, so allocate enough to prevent a resize.  */
    2670        26938 :       vec_alloc (params, 4);
    2671              : 
    2672              :       /* Remove the qualifiers for the rest of the expressions and
    2673              :          create the VAL temp variable to hold the RHS.  */
    2674        26938 :       nonatomic_type = build_qualified_type (expr_type, TYPE_UNQUALIFIED);
    2675        26938 :       tmp = create_tmp_var_raw (nonatomic_type);
    2676        26938 :       tmp_addr = build_unary_op (loc, ADDR_EXPR, tmp, false);
    2677        26938 :       TREE_ADDRESSABLE (tmp) = 1;
    2678              :       /* Do not disable warnings for TMP even though it's artificial.
    2679              :          -Winvalid-memory-model depends on it.  */
    2680              : 
    2681              :       /* Issue __atomic_load (&expr, &tmp, SEQ_CST);  */
    2682        26938 :       fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_LOAD);
    2683        26938 :       params->quick_push (expr_addr);
    2684        26938 :       params->quick_push (tmp_addr);
    2685        26938 :       params->quick_push (seq_cst);
    2686        26938 :       func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
    2687              : 
    2688              :       /* EXPR is always read.  */
    2689        26938 :       mark_exp_read (exp.value);
    2690              : 
    2691              :       /* Optimize the common case where c_build_function_call_vec
    2692              :          immediately folds __atomic_load (&expr, &tmp, SEQ_CST); into
    2693              :          tmp = __atomic_load_<N> (&expr, SEQ_CST);
    2694              :          In that case tmp is not addressable and can be initialized
    2695              :          fully by the rhs of the MODIFY_EXPR.  */
    2696        26938 :       tree tem = func_call;
    2697        26938 :       if (CONVERT_EXPR_P (tem) && VOID_TYPE_P (TREE_TYPE (tem)))
    2698              :         {
    2699        25683 :           tem = TREE_OPERAND (tem, 0);
    2700        25683 :           if (TREE_CODE (tem) == MODIFY_EXPR
    2701        25683 :               && TREE_OPERAND (tem, 0) == tmp
    2702        51366 :               && !walk_tree_without_duplicates (&TREE_OPERAND (tem, 1),
    2703              :                                                 c_find_var_r, tmp))
    2704              :             {
    2705        25683 :               TREE_ADDRESSABLE (tmp) = 0;
    2706        25683 :               func_call = TREE_OPERAND (tem, 1);
    2707              :             }
    2708              :         }
    2709              : 
    2710              :       /* Return tmp which contains the value loaded.  */
    2711        26938 :       exp.value = build4 (TARGET_EXPR, nonatomic_type, tmp, func_call,
    2712              :                           NULL_TREE, NULL_TREE);
    2713              :     }
    2714    359476352 :   if (convert_p && !error_operand_p (exp.value)
    2715    718958186 :       && (TREE_CODE (TREE_TYPE (exp.value)) != ARRAY_TYPE))
    2716    359468462 :     exp.value = convert (build_qualified_type (TREE_TYPE (exp.value), TYPE_UNQUALIFIED), exp.value);
    2717    359489615 :   if (force_non_npc)
    2718           24 :     exp.value = build1 (NOP_EXPR, TREE_TYPE (exp.value), exp.value);
    2719              : 
    2720    359489615 :   {
    2721    359489615 :     tree false_value, true_value;
    2722    359476352 :     if (convert_p && !error_operand_p (exp.value)
    2723    718958186 :         && c_hardbool_type_attr (TREE_TYPE (exp.value),
    2724              :                                  &false_value, &true_value))
    2725              :       {
    2726         9721 :         tree t = save_expr (exp.value);
    2727              : 
    2728         9721 :         mark_exp_read (exp.value);
    2729              : 
    2730         9721 :         tree trapfn = builtin_decl_explicit (BUILT_IN_TRAP);
    2731         9721 :         tree expr = build_call_expr_loc (loc, trapfn, 0);
    2732         9721 :         expr = build_compound_expr (loc, expr, boolean_true_node);
    2733         9721 :         expr = fold_build3_loc (loc, COND_EXPR, boolean_type_node,
    2734              :                                 fold_build2_loc (loc, NE_EXPR,
    2735              :                                                  boolean_type_node,
    2736              :                                                  t, true_value),
    2737              :                                 expr, boolean_true_node);
    2738         9721 :         expr = fold_build3_loc (loc, COND_EXPR, boolean_type_node,
    2739              :                                 fold_build2_loc (loc, NE_EXPR,
    2740              :                                                  boolean_type_node,
    2741              :                                                  t, false_value),
    2742              :                                 expr, boolean_false_node);
    2743              : 
    2744         9721 :         exp.value = expr;
    2745              :       }
    2746              :   }
    2747              : 
    2748    359489615 :   return exp;
    2749              : }
    2750              : 
    2751              : /* Wrapper for the overload above, same arguments but for tree rather than
    2752              :    c_expr.  This is important for hardbools to decay to bools.  */
    2753              : 
    2754              : static inline tree
    2755       576860 : convert_lvalue_to_rvalue (location_t loc, tree val,
    2756              :                           bool convert_p, bool read_p, bool for_init = false)
    2757              : {
    2758       576860 :   struct c_expr expr;
    2759       576860 :   memset (&expr, 0, sizeof (expr));
    2760       576860 :   expr.value = val;
    2761       576860 :   expr = convert_lvalue_to_rvalue (loc, expr, convert_p, read_p, for_init);
    2762       576860 :   return expr.value;
    2763              : }
    2764              : 
    2765              : /* EXP is an expression of integer type.  Apply the integer promotions
    2766              :    to it and return the promoted value.  */
    2767              : 
    2768              : tree
    2769     78935783 : perform_integral_promotions (tree exp)
    2770              : {
    2771     78935783 :   tree type = TREE_TYPE (exp);
    2772     78935783 :   enum tree_code code = TREE_CODE (type);
    2773              : 
    2774     78935783 :   gcc_assert (INTEGRAL_TYPE_P (type));
    2775              : 
    2776              :   /* Convert enums to the result of applying the integer promotions to
    2777              :      their underlying type.  */
    2778     78935783 :   if (code == ENUMERAL_TYPE)
    2779              :     {
    2780       650554 :       type = ENUM_UNDERLYING_TYPE (type);
    2781       650554 :       if (c_promoting_integer_type_p (type))
    2782              :         {
    2783           94 :           if (TYPE_UNSIGNED (type)
    2784           94 :               && TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
    2785            0 :             type = unsigned_type_node;
    2786              :           else
    2787           94 :             type = integer_type_node;
    2788              :         }
    2789              : 
    2790       650554 :       return convert (type, exp);
    2791              :     }
    2792              : 
    2793              :   /* ??? This should no longer be needed now bit-fields have their
    2794              :      proper types.  */
    2795     78285229 :   if (TREE_CODE (exp) == COMPONENT_REF
    2796     78285229 :       && DECL_C_BIT_FIELD (TREE_OPERAND (exp, 1)))
    2797              :     {
    2798        62213 :       if (BITINT_TYPE_P (DECL_BIT_FIELD_TYPE (TREE_OPERAND (exp, 1))))
    2799              :         {
    2800          484 :           tree btype = DECL_BIT_FIELD_TYPE (TREE_OPERAND (exp, 1));
    2801          484 :           if (TREE_CODE (btype) == BITINT_TYPE)
    2802          454 :             return convert (btype, exp);
    2803              :           else
    2804           30 :             return convert (ENUM_UNDERLYING_TYPE (btype), exp);
    2805              :         }
    2806              :       /* If it's thinner than an int, promote it like a
    2807              :          c_promoting_integer_type_p, otherwise leave it alone.  */
    2808        61729 :       if (compare_tree_int (DECL_SIZE (TREE_OPERAND (exp, 1)),
    2809        61729 :                             TYPE_PRECISION (integer_type_node)) < 0)
    2810        53467 :         return convert (integer_type_node, exp);
    2811              :     }
    2812              : 
    2813     78231278 :   if (c_promoting_integer_type_p (type))
    2814              :     {
    2815              :       /* Preserve unsignedness if not really getting any wider.  */
    2816       645590 :       if (TYPE_UNSIGNED (type)
    2817       645590 :           && TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
    2818            0 :         return convert (unsigned_type_node, exp);
    2819              : 
    2820       645590 :       return convert (integer_type_node, exp);
    2821              :     }
    2822              : 
    2823              :   return exp;
    2824              : }
    2825              : 
    2826              : 
    2827              : /* Perform default promotions for C data used in expressions.
    2828              :    Enumeral types or short or char are converted to int.
    2829              :    In addition, manifest constants symbols are replaced by their values.  */
    2830              : 
    2831              : tree
    2832     88478691 : default_conversion (tree exp)
    2833              : {
    2834     88478691 :   tree orig_exp;
    2835     88478691 :   tree type = TREE_TYPE (exp);
    2836     88478691 :   enum tree_code code = TREE_CODE (type);
    2837     88478691 :   tree promoted_type;
    2838              : 
    2839     88478691 :   mark_exp_read (exp);
    2840              :   /* We only generate a call to .ACCESS_WITH_SIZE when it is a read.  */
    2841     88478691 :   if (TREE_CODE (exp) == COMPONENT_REF
    2842     88478691 :       && handle_counted_by_p (exp))
    2843       601206 :     exp = handle_counted_by_for_component_ref (EXPR_LOCATION (exp), exp);
    2844              : 
    2845              :   /* Functions and arrays have been converted during parsing.  */
    2846     88478691 :   gcc_assert (code != FUNCTION_TYPE);
    2847     88478691 :   if (code == ARRAY_TYPE)
    2848              :     return exp;
    2849              : 
    2850              :   /* Constants can be used directly unless they're not loadable.  */
    2851     88478532 :   if (TREE_CODE (exp) == CONST_DECL)
    2852            0 :     exp = DECL_INITIAL (exp);
    2853              : 
    2854              :   /* Strip no-op conversions.  */
    2855     88478532 :   orig_exp = exp;
    2856     88850573 :   STRIP_TYPE_NOPS (exp);
    2857              : 
    2858     88478532 :   copy_warning (exp, orig_exp);
    2859              : 
    2860     88478532 :   if (code == VOID_TYPE)
    2861              :     {
    2862            2 :       error_at (EXPR_LOC_OR_LOC (exp, input_location),
    2863              :                 "void value not ignored as it ought to be");
    2864            2 :       return error_mark_node;
    2865              :     }
    2866              : 
    2867     88478530 :   exp = require_complete_type (EXPR_LOC_OR_LOC (exp, input_location), exp);
    2868     88478530 :   if (exp == error_mark_node)
    2869              :     return error_mark_node;
    2870              : 
    2871     88477626 :   promoted_type = targetm.promoted_type (type);
    2872     88477626 :   if (promoted_type)
    2873            0 :     return convert (promoted_type, exp);
    2874              : 
    2875     88477626 :   if (INTEGRAL_TYPE_P (type))
    2876     77938028 :     return perform_integral_promotions (exp);
    2877              : 
    2878              :   return exp;
    2879              : }
    2880              : 
    2881              : /* Look up COMPONENT in a structure or union TYPE.
    2882              : 
    2883              :    If the component name is not found, returns NULL_TREE.  Otherwise,
    2884              :    the return value is a TREE_LIST, with each TREE_VALUE a FIELD_DECL
    2885              :    stepping down the chain to the component, which is in the last
    2886              :    TREE_VALUE of the list.  Normally the list is of length one, but if
    2887              :    the component is embedded within (nested) anonymous structures or
    2888              :    unions, the list steps down the chain to the component.  */
    2889              : 
    2890              : tree
    2891      2322523 : lookup_field (const_tree type, tree component)
    2892              : {
    2893      2322523 :   tree field;
    2894              : 
    2895              :   /* If TYPE_LANG_SPECIFIC is set, then it is a sorted array of pointers
    2896              :      to the field elements.  Use a binary search on this array to quickly
    2897              :      find the element.  Otherwise, do a linear search.  TYPE_LANG_SPECIFIC
    2898              :      will always be set for structures which have many elements.
    2899              : 
    2900              :      Duplicate field checking replaces duplicates with NULL_TREE so
    2901              :      TYPE_LANG_SPECIFIC arrays are potentially no longer sorted.  In that
    2902              :      case just iterate using DECL_CHAIN.  */
    2903              : 
    2904      2623567 :   if (TYPE_LANG_SPECIFIC (type) && TYPE_LANG_SPECIFIC (type)->s
    2905      2623567 :       && !seen_error ())
    2906              :     {
    2907       301023 :       int bot, top, half;
    2908       301023 :       tree *field_array = &TYPE_LANG_SPECIFIC (type)->s->elts[0];
    2909              : 
    2910       301023 :       field = TYPE_FIELDS (type);
    2911       301023 :       bot = 0;
    2912       301023 :       top = TYPE_LANG_SPECIFIC (type)->s->len;
    2913      1385157 :       while (top - bot > 1)
    2914              :         {
    2915      1355737 :           half = (top - bot + 1) >> 1;
    2916      1355737 :           field = field_array[bot+half];
    2917              : 
    2918      1355737 :           if (DECL_NAME (field) == NULL_TREE)
    2919              :             {
    2920              :               /* Step through all anon unions in linear fashion.  */
    2921            0 :               while (DECL_NAME (field_array[bot]) == NULL_TREE)
    2922              :                 {
    2923            0 :                   field = field_array[bot++];
    2924            0 :                   if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)))
    2925              :                     {
    2926            0 :                       tree anon = lookup_field (TREE_TYPE (field), component);
    2927              : 
    2928            0 :                       if (anon)
    2929            0 :                         return tree_cons (NULL_TREE, field, anon);
    2930              : 
    2931              :                       /* The Plan 9 compiler permits referring
    2932              :                          directly to an anonymous struct/union field
    2933              :                          using a typedef name.  */
    2934            0 :                       if (flag_plan9_extensions
    2935            0 :                           && TYPE_NAME (TREE_TYPE (field)) != NULL_TREE
    2936            0 :                           && (TREE_CODE (TYPE_NAME (TREE_TYPE (field)))
    2937              :                               == TYPE_DECL)
    2938            0 :                           && (DECL_NAME (TYPE_NAME (TREE_TYPE (field)))
    2939              :                               == component))
    2940              :                         break;
    2941              :                     }
    2942              :                 }
    2943              : 
    2944              :               /* Entire record is only anon unions.  */
    2945            0 :               if (bot > top)
    2946              :                 return NULL_TREE;
    2947              : 
    2948              :               /* Restart the binary search, with new lower bound.  */
    2949            0 :               continue;
    2950            0 :             }
    2951              : 
    2952      1355737 :           if (DECL_NAME (field) == component)
    2953              :             break;
    2954      1084134 :           if (DECL_NAME (field) < component)
    2955              :             bot += half;
    2956              :           else
    2957       899309 :             top = bot + half;
    2958              :         }
    2959              : 
    2960       301023 :       if (DECL_NAME (field_array[bot]) == component)
    2961              :         field = field_array[bot];
    2962       271603 :       else if (DECL_NAME (field) != component)
    2963              :         return NULL_TREE;
    2964              :     }
    2965              :   else
    2966              :     {
    2967      5262197 :       for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    2968              :         {
    2969      5252828 :           if (DECL_NAME (field) == NULL_TREE
    2970      5252828 :               && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)))
    2971              :             {
    2972        12277 :               tree anon = lookup_field (TREE_TYPE (field), component);
    2973              : 
    2974        12277 :               if (anon)
    2975         3003 :                 return tree_cons (NULL_TREE, field, anon);
    2976              : 
    2977              :               /* The Plan 9 compiler permits referring directly to an
    2978              :                  anonymous struct/union field using a typedef
    2979              :                  name.  */
    2980         9274 :               if (flag_plan9_extensions
    2981          174 :                   && TYPE_NAME (TREE_TYPE (field)) != NULL_TREE
    2982          172 :                   && TREE_CODE (TYPE_NAME (TREE_TYPE (field))) == TYPE_DECL
    2983         9336 :                   && (DECL_NAME (TYPE_NAME (TREE_TYPE (field)))
    2984              :                       == component))
    2985              :                 break;
    2986              :             }
    2987              : 
    2988      5249821 :           if (DECL_NAME (field) == component)
    2989              :             break;
    2990              :         }
    2991              : 
    2992      2018497 :       if (field == NULL_TREE)
    2993              :         return NULL_TREE;
    2994              :     }
    2995              : 
    2996      2310151 :   return tree_cons (NULL_TREE, field, NULL_TREE);
    2997              : }
    2998              : 
    2999              : /* Recursively append candidate IDENTIFIER_NODEs to CANDIDATES.  */
    3000              : 
    3001              : static void
    3002          101 : lookup_field_fuzzy_find_candidates (tree type, tree component,
    3003              :                                     vec<tree> *candidates)
    3004              : {
    3005          101 :   tree field;
    3006          258 :   for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    3007              :     {
    3008          157 :       if (DECL_NAME (field) == NULL_TREE
    3009          157 :           && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)))
    3010           30 :         lookup_field_fuzzy_find_candidates (TREE_TYPE (field), component,
    3011              :                                             candidates);
    3012              : 
    3013          157 :       if (DECL_NAME (field))
    3014          111 :         candidates->safe_push (DECL_NAME (field));
    3015              :     }
    3016          101 : }
    3017              : 
    3018              : /* Like "lookup_field", but find the closest matching IDENTIFIER_NODE,
    3019              :    rather than returning a TREE_LIST for an exact match.  */
    3020              : 
    3021              : static tree
    3022           71 : lookup_field_fuzzy (tree type, tree component)
    3023              : {
    3024           71 :   gcc_assert (TREE_CODE (component) == IDENTIFIER_NODE);
    3025              : 
    3026              :   /* First, gather a list of candidates.  */
    3027           71 :   auto_vec <tree> candidates;
    3028              : 
    3029           71 :   lookup_field_fuzzy_find_candidates (type, component,
    3030              :                                       &candidates);
    3031              : 
    3032           71 :   return find_closest_identifier (component, &candidates);
    3033           71 : }
    3034              : 
    3035              : /* Support function for build_component_ref's error-handling.
    3036              : 
    3037              :    Given DATUM_TYPE, and "DATUM.COMPONENT", where DATUM is *not* a
    3038              :    struct or union, should we suggest "DATUM->COMPONENT" as a hint?  */
    3039              : 
    3040              : static bool
    3041           72 : should_suggest_deref_p (tree datum_type)
    3042              : {
    3043              :   /* We don't do it for Objective-C, since Objective-C 2.0 dot-syntax
    3044              :      allows "." for ptrs; we could be handling a failed attempt
    3045              :      to access a property.  */
    3046           72 :   if (c_dialect_objc ())
    3047              :     return false;
    3048              : 
    3049              :   /* Only suggest it for pointers...  */
    3050           72 :   if (TREE_CODE (datum_type) != POINTER_TYPE)
    3051              :     return false;
    3052              : 
    3053              :   /* ...to structs/unions.  */
    3054            8 :   tree underlying_type = TREE_TYPE (datum_type);
    3055            8 :   enum tree_code code = TREE_CODE (underlying_type);
    3056            8 :   if (code == RECORD_TYPE || code == UNION_TYPE)
    3057              :     return true;
    3058              :   else
    3059            1 :     return false;
    3060              : }
    3061              : 
    3062              : /* Give a component ref REF, decide whether we should handle its counted_by
    3063              :    attribute based on its context:
    3064              :    Do not handle counted_by when in offsetof, typeof and alignof operator.  */
    3065              : 
    3066              : static bool
    3067      2210588 : handle_counted_by_p (tree ref)
    3068              : {
    3069      2210588 :   gcc_assert (TREE_CODE (ref) == COMPONENT_REF);
    3070      2210588 :   tree datum = TREE_OPERAND (ref, 0);
    3071              :   /* If the component_ref is build for a offsetof, i.e., the datum
    3072              :      of the component_ref is a indirect_ref of null_pointer_node,
    3073              :      we should not generate call to .ACCESS_WITH_SIZE.  */
    3074      2210588 :   if (TREE_CODE (datum) == INDIRECT_REF
    3075      2210588 :       && TREE_OPERAND (datum, 0) == null_pointer_node)
    3076              :     return false;
    3077      2210254 :   if (in_typeof || in_alignof)
    3078         8786 :     return false;
    3079              :   return true;
    3080              : }
    3081              : 
    3082              : /* Given a component ref REF, if there is a counted_by attribute attached,
    3083              :    issue error when the element_type is a structure or union including a
    3084              :    flexible array member.  */
    3085              : 
    3086              : static void
    3087      2276339 : check_counted_by_attribute (location_t loc, tree ref)
    3088              : {
    3089      2276339 :   tree subdatum = TREE_OPERAND (ref, 1);
    3090      2276339 :   tree sub_type = TREE_TYPE (subdatum);
    3091              : 
    3092      2276339 :   if (!c_flexible_array_member_type_p (sub_type)
    3093      2276339 :       && TREE_CODE (sub_type) != POINTER_TYPE)
    3094              :     return;
    3095              : 
    3096       388366 :   tree element_type = TREE_TYPE (sub_type);
    3097              : 
    3098       388366 :   tree attr_counted_by = lookup_attribute ("counted_by",
    3099       388366 :                                            DECL_ATTRIBUTES (subdatum));
    3100       388366 :   if (attr_counted_by)
    3101              :     {
    3102              :       /* Issue error when the element_type is a structure or
    3103              :         union including a flexible array member.  */
    3104          881 :       if (RECORD_OR_UNION_TYPE_P (element_type)
    3105          881 :           && TYPE_INCLUDES_FLEXARRAY (element_type))
    3106              :         {
    3107            2 :           error_at (loc,
    3108              :                     "%<counted_by%> attribute is not allowed for a pointer to"
    3109              :                     " structure or union with flexible array member");
    3110            2 :           return;
    3111              :         }
    3112              :     }
    3113              : }
    3114              : 
    3115              : /* For a SUBDATUM field of a structure or union DATUM, generate a REF
    3116              :    to the object that represents its counted_by per the attribute
    3117              :    counted_by attached to this field if it's a flexible array member
    3118              :    or a pointer field, otherwise return NULL_TREE.
    3119              :    Set COUNTED_BY_TYPE to the TYPE of the counted_by field.
    3120              :    For example, if:
    3121              : 
    3122              :     struct P {
    3123              :       int k;
    3124              :       int x[] __attribute__ ((counted_by (k)));
    3125              :     } *p;
    3126              : 
    3127              :     for:
    3128              :     p->x
    3129              : 
    3130              :     the ref to the object that represents its element count will be:
    3131              : 
    3132              :     &(p->k)
    3133              : */
    3134              : 
    3135              : static tree
    3136       440624 : build_counted_by_ref (tree datum, tree subdatum,
    3137              :                       tree *counted_by_type)
    3138              : {
    3139       440624 :   tree sub_type = TREE_TYPE (subdatum);
    3140       440624 :   if (!c_flexible_array_member_type_p (sub_type)
    3141       440624 :       && TREE_CODE (sub_type) != POINTER_TYPE)
    3142              :     return NULL_TREE;
    3143              : 
    3144       440624 :   tree attr_counted_by = lookup_attribute ("counted_by",
    3145       440624 :                                            DECL_ATTRIBUTES (subdatum));
    3146       440624 :   if (!attr_counted_by)
    3147              :     return NULL_TREE;
    3148              : 
    3149          660 :   tree counted_by_ref = NULL_TREE;
    3150          660 :   *counted_by_type = NULL_TREE;
    3151              : 
    3152          660 :   tree type = TREE_TYPE (datum);
    3153              : 
    3154              :   /* If the type of the containing structure is an anonymous struct/union,
    3155              :      and this anonymous struct/union is not a root type, get the first
    3156              :      outer named structure/union type.  */
    3157          660 :   while (TREE_CODE (datum) == COMPONENT_REF
    3158           35 :          && c_type_tag (type) == NULL_TREE
    3159          730 :          && DECL_NAME (TREE_OPERAND (datum, 1)) == NULL_TREE)
    3160              :     {
    3161           35 :       datum = TREE_OPERAND (datum, 0);
    3162           35 :       type = TREE_TYPE (datum);
    3163              :     }
    3164              : 
    3165          660 :   tree field_id = TREE_VALUE (TREE_VALUE (attr_counted_by));
    3166          660 :   tree counted_by_field = lookup_field (type, field_id);
    3167          660 :   gcc_assert (counted_by_field);
    3168              : 
    3169         1072 :   tree counted_by_subdatum;
    3170         1072 :   do
    3171              :     {
    3172         1072 :       counted_by_subdatum = TREE_VALUE (counted_by_field);
    3173              :       /* Get the TYPE of the counted_by field.  */
    3174         1072 :       *counted_by_type = TREE_TYPE (counted_by_subdatum);
    3175              : 
    3176         1072 :       counted_by_ref
    3177         1072 :         = build3 (COMPONENT_REF, TREE_TYPE (counted_by_subdatum),
    3178              :                   datum, counted_by_subdatum, NULL_TREE);
    3179              : 
    3180         1072 :       datum = counted_by_ref;
    3181         1072 :       counted_by_field = TREE_CHAIN (counted_by_field);
    3182              :     }
    3183         1072 :   while (counted_by_field);
    3184              : 
    3185          660 :   counted_by_ref = build_fold_addr_expr (counted_by_ref);
    3186          660 :   return counted_by_ref;
    3187              : }
    3188              : 
    3189              : /* Given a COMPONENT_REF REF with the location LOC, the corresponding
    3190              :    COUNTED_BY_REF, and the COUNTED_BY_TYPE, generate the corresponding
    3191              :    call to the internal function .ACCESS_WITH_SIZE.
    3192              : 
    3193              :    A: For the Flexible Array Member, Generate an INDIRECT_REF to a call to
    3194              :    the internal function .ACCESS_WITH_SIZE.
    3195              : 
    3196              :    REF
    3197              : 
    3198              :    to:
    3199              : 
    3200              :    (*.ACCESS_WITH_SIZE (REF, COUNTED_BY_REF, (* TYPE_OF_SIZE)0,
    3201              :                         TYPE_SIZE_UNIT for element)
    3202              : 
    3203              :    NOTE: The return type of this function is the POINTER type pointing
    3204              :    to the original flexible array type.  Then the type of the INDIRECT_REF
    3205              :    is the original flexible array type.
    3206              :    The type of the first argument of this function is a POINTER type
    3207              :    to the original flexible array type.
    3208              : 
    3209              :    B: For pointers with counted_by, generate a call to the internal function
    3210              :    .ACCESS_WITH_SIZE.
    3211              : 
    3212              :     REF
    3213              : 
    3214              :     to:
    3215              : 
    3216              :     .ACCESS_WITH_SIZE (REF, COUNTED_BY_REF, (* TYPE_OF_SIZE)0,
    3217              :                        TYPE_SIZE_UNIT for element)
    3218              : 
    3219              :    NOTE: The return type of this function is the original pointer type.
    3220              :    The type of the first argument of this function is the original
    3221              :    pointer type.
    3222              : 
    3223              :    The 3rd argument of the call is a constant 0 with the pointer TYPE whose
    3224              :    pointee type is the TYPE of the object pointed by COUNTED_BY_REF.
    3225              : 
    3226              :    The 4th argument of the call is the TYPE_SIZE_UNIT of the element TYPE
    3227              :    of the array.
    3228              : 
    3229              :   */
    3230              : static tree
    3231          660 : build_access_with_size_for_counted_by (location_t loc, tree ref,
    3232              :                                        tree counted_by_ref,
    3233              :                                        tree counted_by_type)
    3234              : {
    3235          660 :   gcc_assert (c_flexible_array_member_type_p (TREE_TYPE (ref))
    3236              :               || TREE_CODE (TREE_TYPE (ref)) == POINTER_TYPE);
    3237              : 
    3238          660 :   bool is_fam = c_flexible_array_member_type_p (TREE_TYPE (ref));
    3239              : 
    3240              :   /* The result type of the call is a pointer to the flexible array type;
    3241              :      or is the original pointer type to the pointer field with counted_by.  */
    3242          660 :   tree result_type = is_fam ? c_build_pointer_type (TREE_TYPE (ref))
    3243          459 :                      : TREE_TYPE (ref);
    3244              : 
    3245          660 :   tree element_type = TREE_TYPE (TREE_TYPE (ref));
    3246          660 :   tree element_size = VOID_TYPE_P (element_type)
    3247          660 :                       ? size_one_node
    3248          660 :                       : TYPE_SIZE_UNIT (element_type);
    3249          660 :   if (element_size == NULL_TREE)
    3250              :     return ref;
    3251              : 
    3252          646 :   tree first_param = is_fam
    3253          646 :                      ? c_fully_fold (array_to_pointer_conversion (loc, ref),
    3254              :                                      false, NULL)
    3255          445 :                      : c_fully_fold (ref, false, NULL);
    3256          646 :   tree second_param
    3257          646 :     = c_fully_fold (counted_by_ref, false, NULL);
    3258          646 :   tree third_param = build_int_cst (c_build_pointer_type (counted_by_type), 0);
    3259              : 
    3260          646 :   tree call
    3261          646 :     = build_call_expr_internal_loc (loc, IFN_ACCESS_WITH_SIZE,
    3262              :                                     result_type, 4,
    3263              :                                     first_param,
    3264              :                                     second_param,
    3265              :                                     third_param,
    3266              :                                     element_size);
    3267              : 
    3268              :   /* Wrap the call with an INDIRECT_REF with the flexible array type.  */
    3269          646 :   if (is_fam)
    3270          201 :     call = build1 (INDIRECT_REF, TREE_TYPE (ref), call);
    3271          646 :   SET_EXPR_LOCATION (call, loc);
    3272          646 :   return call;
    3273              : }
    3274              : 
    3275              : /* For the COMPONENT_REF ref, check whether it has a counted_by attribute,
    3276              :    if so, wrap this COMPONENT_REF with the corresponding CALL to the
    3277              :    function .ACCESS_WITH_SIZE.
    3278              :    Otherwise, return the ref itself.  */
    3279              : 
    3280              : tree
    3281      2201548 : handle_counted_by_for_component_ref (location_t loc, tree ref)
    3282              : {
    3283      2201548 :   gcc_assert (TREE_CODE (ref) == COMPONENT_REF);
    3284      2201548 :   tree datum = TREE_OPERAND (ref, 0);
    3285      2201548 :   tree subdatum = TREE_OPERAND (ref, 1);
    3286      2201548 :   tree counted_by_type = NULL_TREE;
    3287              : 
    3288      2201548 :   if (!(c_flexible_array_member_type_p (TREE_TYPE (ref))
    3289      2131089 :         || TREE_CODE (TREE_TYPE (ref)) == POINTER_TYPE))
    3290              :     return ref;
    3291              : 
    3292       440624 :   tree counted_by_ref = build_counted_by_ref (datum, subdatum,
    3293              :                                               &counted_by_type);
    3294       440624 :   if (counted_by_ref)
    3295          660 :     ref = build_access_with_size_for_counted_by (loc, ref,
    3296              :                                                  counted_by_ref,
    3297              :                                                  counted_by_type);
    3298              :   return ref;
    3299              : }
    3300              : 
    3301              : /* Make an expression to refer to the COMPONENT field of structure or
    3302              :    union value DATUM.  COMPONENT is an IDENTIFIER_NODE.  LOC is the
    3303              :    location of the COMPONENT_REF.  COMPONENT_LOC is the location
    3304              :    of COMPONENT.  ARROW_LOC is the location of the first -> operand if
    3305              :    it is from -> operator.
    3306              :    If HANDLE_COUNTED_BY is true, check the counted_by attribute and generate
    3307              :    a call to .ACCESS_WITH_SIZE.  Otherwise, ignore the attribute.  */
    3308              : 
    3309              : tree
    3310      2274225 : build_component_ref (location_t loc, tree datum, tree component,
    3311              :                      location_t component_loc, location_t arrow_loc)
    3312              : {
    3313      2274225 :   tree type = TREE_TYPE (datum);
    3314      2274225 :   enum tree_code code = TREE_CODE (type);
    3315      2274225 :   tree field = NULL;
    3316      2274225 :   tree ref;
    3317      2274225 :   bool datum_lvalue = lvalue_p (datum);
    3318              : 
    3319      2274225 :   if (!objc_is_public (datum, component))
    3320            0 :     return error_mark_node;
    3321              : 
    3322              :   /* Detect Objective-C property syntax object.property.  */
    3323      2274225 :   if (c_dialect_objc ()
    3324      2274225 :       && (ref = objc_maybe_build_component_ref (datum, component)))
    3325              :     return ref;
    3326              : 
    3327              :   /* See if there is a field or component with name COMPONENT.  */
    3328              : 
    3329      2274225 :   if (code == RECORD_TYPE || code == UNION_TYPE)
    3330              :     {
    3331      2274153 :       if (!COMPLETE_TYPE_P (type))
    3332              :         {
    3333           19 :           c_incomplete_type_error (loc, NULL_TREE, type);
    3334           19 :           return error_mark_node;
    3335              :         }
    3336              : 
    3337      2274134 :       field = lookup_field (type, component);
    3338              : 
    3339      2274134 :       if (!field)
    3340              :         {
    3341           63 :           tree guessed_id = lookup_field_fuzzy (type, component);
    3342           63 :           if (guessed_id)
    3343              :             {
    3344              :               /* Attempt to provide a fixit replacement hint, if
    3345              :                  we have a valid range for the component.  */
    3346            0 :               location_t reported_loc
    3347           26 :                 = (component_loc != UNKNOWN_LOCATION) ? component_loc : loc;
    3348           26 :               gcc_rich_location rich_loc (reported_loc);
    3349           26 :               if (component_loc != UNKNOWN_LOCATION)
    3350           26 :                 rich_loc.add_fixit_misspelled_id (component_loc, guessed_id);
    3351           26 :               error_at (&rich_loc,
    3352              :                         "%qT has no member named %qE; did you mean %qE?",
    3353              :                         type, component, guessed_id);
    3354           26 :             }
    3355              :           else
    3356           37 :             error_at (loc, "%qT has no member named %qE", type, component);
    3357           63 :           return error_mark_node;
    3358              :         }
    3359              : 
    3360              :       /* Accessing elements of atomic structures or unions is undefined
    3361              :          behavior (C11 6.5.2.3#5).  */
    3362      2274071 :       if (TYPE_ATOMIC (type) && c_inhibit_evaluation_warnings == 0)
    3363              :         {
    3364           18 :           if (code == RECORD_TYPE)
    3365           12 :             warning_at (loc, 0, "accessing a member %qE of an atomic "
    3366              :                         "structure %qE", component, datum);
    3367              :           else
    3368            6 :             warning_at (loc, 0, "accessing a member %qE of an atomic "
    3369              :                         "union %qE", component, datum);
    3370              :         }
    3371              : 
    3372              :       /* Chain the COMPONENT_REFs if necessary down to the FIELD.
    3373              :          This might be better solved in future the way the C++ front
    3374              :          end does it - by giving the anonymous entities each a
    3375              :          separate name and type, and then have build_component_ref
    3376              :          recursively call itself.  We can't do that here.  */
    3377      2276339 :       do
    3378              :         {
    3379      2276339 :           tree subdatum = TREE_VALUE (field);
    3380      2276339 :           int quals;
    3381      2276339 :           tree subtype;
    3382      2276339 :           bool use_datum_quals;
    3383              : 
    3384      2276339 :           if (TREE_TYPE (subdatum) == error_mark_node)
    3385              :             return error_mark_node;
    3386              : 
    3387              :           /* If this is an rvalue, it does not have qualifiers in C
    3388              :              standard terms and we must avoid propagating such
    3389              :              qualifiers down to a non-lvalue array that is then
    3390              :              converted to a pointer.  */
    3391      4552678 :           use_datum_quals = (datum_lvalue
    3392      2276339 :                              || TREE_CODE (TREE_TYPE (subdatum)) != ARRAY_TYPE);
    3393              : 
    3394      2276339 :           quals = TYPE_QUALS (strip_array_types (TREE_TYPE (subdatum)));
    3395      2276339 :           if (use_datum_quals)
    3396      2276077 :             quals |= TYPE_QUALS (TREE_TYPE (datum));
    3397      2276339 :           subtype = c_build_qualified_type (TREE_TYPE (subdatum), quals);
    3398              : 
    3399      2276339 :           ref = build3 (COMPONENT_REF, subtype, datum, subdatum,
    3400              :                         NULL_TREE);
    3401      2276339 :           SET_EXPR_LOCATION (ref, loc);
    3402              : 
    3403      2276339 :           check_counted_by_attribute (loc, ref);
    3404              : 
    3405      2276339 :           if (TREE_READONLY (subdatum)
    3406      2276339 :               || (use_datum_quals && TREE_READONLY (datum)))
    3407        30595 :             TREE_READONLY (ref) = 1;
    3408      2276339 :           if (TREE_THIS_VOLATILE (subdatum)
    3409      2275345 :               || (use_datum_quals && TREE_THIS_VOLATILE (datum)))
    3410         2428 :             TREE_THIS_VOLATILE (ref) = 1;
    3411              : 
    3412      2276339 :           if (TREE_UNAVAILABLE (subdatum))
    3413           10 :             error_unavailable_use (subdatum, NULL_TREE);
    3414      2276329 :           else if (TREE_DEPRECATED (subdatum))
    3415           16 :             warn_deprecated_use (subdatum, NULL_TREE);
    3416              : 
    3417      2276339 :           datum = ref;
    3418              : 
    3419      2276339 :           field = TREE_CHAIN (field);
    3420              :         }
    3421      2276339 :       while (field);
    3422              : 
    3423              :       return ref;
    3424              :     }
    3425           72 :   else if (should_suggest_deref_p (type))
    3426              :     {
    3427              :       /* Special-case the error message for "ptr.field" for the case
    3428              :          where the user has confused "." vs "->".  */
    3429            7 :       rich_location richloc (line_table, loc);
    3430            7 :       if (INDIRECT_REF_P (datum) && arrow_loc != UNKNOWN_LOCATION)
    3431              :         {
    3432            2 :           richloc.add_fixit_insert_before (arrow_loc, "(*");
    3433            2 :           richloc.add_fixit_insert_after (arrow_loc, ")");
    3434            2 :           error_at (&richloc,
    3435              :                     "%qE is a pointer to pointer; did you mean to dereference "
    3436              :                     "it before applying %<->%> to it?",
    3437            2 :                     TREE_OPERAND (datum, 0));
    3438              :         }
    3439              :       else
    3440              :         {
    3441              :           /* "loc" should be the "." token.  */
    3442            5 :           richloc.add_fixit_replace ("->");
    3443            5 :           error_at (&richloc,
    3444              :                     "%qE is a pointer; did you mean to use %<->%>?",
    3445              :                     datum);
    3446              :         }
    3447            7 :       return error_mark_node;
    3448            7 :     }
    3449           65 :   else if (code != ERROR_MARK)
    3450            1 :     error_at (loc,
    3451              :               "request for member %qE in something not a structure or union",
    3452              :               component);
    3453              : 
    3454           65 :   return error_mark_node;
    3455              : }
    3456              : 
    3457              : /* Given an expression PTR for a pointer, return an expression
    3458              :    for the value pointed to.
    3459              :    ERRORSTRING is the name of the operator to appear in error messages.
    3460              : 
    3461              :    LOC is the location to use for the generated tree.  */
    3462              : 
    3463              : tree
    3464      2754555 : build_indirect_ref (location_t loc, tree ptr, ref_operator errstring)
    3465              : {
    3466      2754555 :   tree pointer = default_conversion (ptr);
    3467      2754555 :   tree type = TREE_TYPE (pointer);
    3468      2754555 :   tree ref;
    3469              : 
    3470      2754555 :   if (TREE_CODE (type) == POINTER_TYPE)
    3471              :     {
    3472      2754201 :       if (CONVERT_EXPR_P (pointer)
    3473      1973484 :           || TREE_CODE (pointer) == VIEW_CONVERT_EXPR)
    3474              :         {
    3475              :           /* If a warning is issued, mark it to avoid duplicates from
    3476              :              the backend.  This only needs to be done at
    3477              :              warn_strict_aliasing > 2.  */
    3478       780717 :           if (warn_strict_aliasing > 2)
    3479       335133 :             if (strict_aliasing_warning (EXPR_LOCATION (pointer),
    3480       335133 :                                          type, TREE_OPERAND (pointer, 0)))
    3481            7 :               suppress_warning (pointer, OPT_Wstrict_aliasing_);
    3482              :         }
    3483              : 
    3484      2754201 :       if (TREE_CODE (pointer) == ADDR_EXPR
    3485      2754201 :           && (TREE_TYPE (TREE_OPERAND (pointer, 0))
    3486        67439 :               == TREE_TYPE (type)))
    3487              :         {
    3488        67430 :           ref = TREE_OPERAND (pointer, 0);
    3489        67430 :           protected_set_expr_location (ref, loc);
    3490        67430 :           return ref;
    3491              :         }
    3492              :       else
    3493              :         {
    3494      2686771 :           tree t = TREE_TYPE (type);
    3495              : 
    3496      2686771 :           ref = build1 (INDIRECT_REF, t, pointer);
    3497              : 
    3498      2686771 :           if (VOID_TYPE_P (t) && c_inhibit_evaluation_warnings == 0)
    3499          151 :             warning_at (loc, 0, "dereferencing %<void *%> pointer");
    3500              : 
    3501              :           /* We *must* set TREE_READONLY when dereferencing a pointer to const,
    3502              :              so that we get the proper error message if the result is used
    3503              :              to assign to.  Also, &* is supposed to be a no-op.
    3504              :              And ANSI C seems to specify that the type of the result
    3505              :              should be the const type.  */
    3506              :           /* A de-reference of a pointer to const is not a const.  It is valid
    3507              :              to change it via some other pointer.  */
    3508      2686771 :           TREE_READONLY (ref) = TYPE_READONLY (t);
    3509      2686771 :           TREE_SIDE_EFFECTS (ref)
    3510      2686771 :             = TYPE_VOLATILE (t) || TREE_SIDE_EFFECTS (pointer);
    3511      2686771 :           TREE_THIS_VOLATILE (ref) = TYPE_VOLATILE (t);
    3512      2686771 :           protected_set_expr_location (ref, loc);
    3513      2686771 :           return ref;
    3514              :         }
    3515              :     }
    3516          354 :   else if (TREE_CODE (pointer) != ERROR_MARK)
    3517          278 :     invalid_indirection_error (loc, type, errstring);
    3518              : 
    3519          354 :   return error_mark_node;
    3520              : }
    3521              : 
    3522              : /* This handles expressions of the form "a[i]", which denotes
    3523              :    an array reference.
    3524              : 
    3525              :    This is logically equivalent in C to *(a+i), but we may do it differently.
    3526              :    If A is a variable or a member, we generate a primitive ARRAY_REF.
    3527              :    This avoids forcing the array out of registers, and can work on
    3528              :    arrays that are not lvalues (for example, members of structures returned
    3529              :    by functions).
    3530              : 
    3531              :    For vector types, allow vector[i] but not i[vector], and create
    3532              :    *(((type*)&vectortype) + i) for the expression.
    3533              : 
    3534              :    LOC is the location to use for the returned expression.  */
    3535              : 
    3536              : tree
    3537      3472764 : build_array_ref (location_t loc, tree array, tree index)
    3538              : {
    3539      3472764 :   tree ret;
    3540      3472764 :   bool swapped = false;
    3541      3472764 :   if (TREE_TYPE (array) == error_mark_node
    3542      3472764 :       || TREE_TYPE (index) == error_mark_node)
    3543              :     return error_mark_node;
    3544              : 
    3545      3472656 :   if (TREE_CODE (TREE_TYPE (array)) != ARRAY_TYPE
    3546      1997031 :       && TREE_CODE (TREE_TYPE (array)) != POINTER_TYPE
    3547              :       /* Allow vector[index] but not index[vector].  */
    3548      4495396 :       && !gnu_vector_type_p (TREE_TYPE (array)))
    3549              :     {
    3550          194 :       if (TREE_CODE (TREE_TYPE (index)) != ARRAY_TYPE
    3551          194 :           && TREE_CODE (TREE_TYPE (index)) != POINTER_TYPE)
    3552              :         {
    3553            2 :           error_at (loc,
    3554              :             "subscripted value is neither array nor pointer nor vector");
    3555              : 
    3556            2 :           return error_mark_node;
    3557              :         }
    3558          192 :       std::swap (array, index);
    3559          192 :       swapped = true;
    3560              :     }
    3561              : 
    3562      3472654 :   if (!INTEGRAL_TYPE_P (TREE_TYPE (index)))
    3563              :     {
    3564            2 :       error_at (loc, "array subscript is not an integer");
    3565            2 :       return error_mark_node;
    3566              :     }
    3567              : 
    3568      3472652 :   if (TREE_CODE (TREE_TYPE (TREE_TYPE (array))) == FUNCTION_TYPE)
    3569              :     {
    3570           10 :       error_at (loc, "subscripted value is pointer to function");
    3571           10 :       return error_mark_node;
    3572              :     }
    3573              : 
    3574              :   /* ??? Existing practice has been to warn only when the char
    3575              :      index is syntactically the index, not for char[array].  */
    3576      3472642 :   if (!swapped)
    3577      3472456 :      warn_array_subscript_with_type_char (loc, index);
    3578              : 
    3579              :   /* Apply default promotions *after* noticing character types.  */
    3580      3472642 :   index = default_conversion (index);
    3581      3472642 :   if (index == error_mark_node)
    3582              :     return error_mark_node;
    3583              : 
    3584      3472641 :   gcc_assert (TREE_CODE (TREE_TYPE (index)) == INTEGER_TYPE
    3585              :               || TREE_CODE (TREE_TYPE (index)) == BITINT_TYPE);
    3586              : 
    3587      3472641 :   bool was_vector = VECTOR_TYPE_P (TREE_TYPE (array));
    3588      3472641 :   bool non_lvalue = convert_vector_to_array_for_subscript (loc, &array, index);
    3589              : 
    3590              :   /* We only generate a call to .ACCESS_WITH_SIZE when it is a read.  */
    3591      3472641 :   if (TREE_CODE (array) == COMPONENT_REF
    3592      3472641 :       && handle_counted_by_p (array))
    3593       816121 :     array = handle_counted_by_for_component_ref (loc, array);
    3594              : 
    3595      3472641 :   if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE)
    3596              :     {
    3597      2498178 :       tree rval, type;
    3598              : 
    3599              :       /* An array that is indexed by a non-constant
    3600              :          cannot be stored in a register; we must be able to do
    3601              :          address arithmetic on its address.
    3602              :          Likewise an array of elements of variable size.  */
    3603      2498178 :       if (TREE_CODE (index) != INTEGER_CST
    3604      2498178 :           || (COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (array)))
    3605      2024320 :               && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array)))) != INTEGER_CST))
    3606              :         {
    3607       474598 :           if (!c_mark_addressable (array, true, true))
    3608            1 :             return error_mark_node;
    3609              :         }
    3610              :       /* An array that is indexed by a constant value which is not within
    3611              :          the array bounds cannot be stored in a register either; because we
    3612              :          would get a crash in store_bit_field/extract_bit_field when trying
    3613              :          to access a non-existent part of the register.  */
    3614      2498177 :       if (TREE_CODE (index) == INTEGER_CST
    3615      2024320 :           && TYPE_DOMAIN (TREE_TYPE (array))
    3616      4519138 :           && !int_fits_type_p (index, TYPE_DOMAIN (TREE_TYPE (array))))
    3617              :         {
    3618        60655 :           if (!c_mark_addressable (array, false, true))
    3619            0 :             return error_mark_node;
    3620              :           /* ISO C2Y disallows a negative integer constant expression index
    3621              :              when array subscripting has an operand of array type.  */
    3622        60655 :           if (flag_isoc2y
    3623           26 :               && !TREE_OVERFLOW (index)
    3624        60678 :               && tree_int_cst_sgn (index) < 0)
    3625           10 :             error_at (loc, "array subscript is negative");
    3626              :         }
    3627              : 
    3628      2498177 :       if ((pedantic || warn_c90_c99_compat || warn_c23_c2y_compat)
    3629      2474828 :           && ! was_vector)
    3630              :         {
    3631      1474911 :           tree foo = array;
    3632      2310159 :           while (TREE_CODE (foo) == COMPONENT_REF)
    3633       835248 :             foo = TREE_OPERAND (foo, 0);
    3634       975605 :           if ((VAR_P (foo) && C_DECL_REGISTER (foo))
    3635      2450450 :               || (TREE_CODE (foo) == COMPOUND_LITERAL_EXPR
    3636           72 :                   && C_DECL_REGISTER (COMPOUND_LITERAL_EXPR_DECL (foo))))
    3637           78 :             pedwarn_c23 (loc, OPT_Wpedantic,
    3638              :                          "ISO C forbids subscripting %<register%> array "
    3639              :                          "before C2Y");
    3640      1474833 :           else if (!lvalue_p (foo))
    3641          118 :             pedwarn_c90 (loc, OPT_Wpedantic,
    3642              :                          "ISO C90 forbids subscripting non-lvalue "
    3643              :                          "array");
    3644              :         }
    3645              : 
    3646      2498177 :       if (TREE_CODE (TREE_TYPE (index)) == BITINT_TYPE
    3647      2498177 :           && TYPE_PRECISION (TREE_TYPE (index)) > TYPE_PRECISION (sizetype))
    3648            3 :         index = fold_convert (sizetype, index);
    3649              : 
    3650      2498177 :       type = TREE_TYPE (TREE_TYPE (array));
    3651      2498177 :       rval = build4 (ARRAY_REF, type, array, index, NULL_TREE, NULL_TREE);
    3652              :       /* Array ref is const/volatile if the array elements are
    3653              :          or if the array is.  */
    3654      7494531 :       TREE_READONLY (rval)
    3655      2498177 :         |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array)))
    3656      2498177 :             | TREE_READONLY (array));
    3657      7494531 :       TREE_SIDE_EFFECTS (rval)
    3658      2498177 :         |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
    3659      2498177 :             | TREE_SIDE_EFFECTS (array));
    3660      4996354 :       TREE_THIS_VOLATILE (rval)
    3661      2498177 :         |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
    3662              :             /* This was added by rms on 16 Nov 91.
    3663              :                It fixes  vol struct foo *a;  a->elts[1]
    3664              :                in an inline function.
    3665              :                Hope it doesn't break something else.  */
    3666      2498177 :             | TREE_THIS_VOLATILE (array));
    3667      2498177 :       ret = require_complete_type (loc, rval);
    3668      2498177 :       protected_set_expr_location (ret, loc);
    3669      2498177 :       if (non_lvalue)
    3670       105143 :         ret = non_lvalue_loc (loc, ret);
    3671      2498177 :       return ret;
    3672              :     }
    3673              :   else
    3674              :     {
    3675       974463 :       tree ar = default_conversion (array);
    3676              : 
    3677       974463 :       if (ar == error_mark_node)
    3678              :         return ar;
    3679              : 
    3680       974463 :       gcc_assert (TREE_CODE (TREE_TYPE (ar)) == POINTER_TYPE);
    3681       974463 :       gcc_assert (TREE_CODE (TREE_TYPE (TREE_TYPE (ar))) != FUNCTION_TYPE);
    3682              : 
    3683       974463 :       ret = build_indirect_ref (loc, build_binary_op (loc, PLUS_EXPR, ar,
    3684              :                                                       index, false),
    3685              :                                 RO_ARRAY_INDEXING);
    3686       974463 :       if (non_lvalue)
    3687            0 :         ret = non_lvalue_loc (loc, ret);
    3688       974463 :       return ret;
    3689              :     }
    3690              : }
    3691              : 
    3692              : /* Build an OpenMP array section reference, creating an exact type for the
    3693              :    resulting expression based on the element type and bounds if possible.  If
    3694              :    we have variable bounds, create an incomplete array type for the result
    3695              :    instead.  */
    3696              : 
    3697              : tree
    3698         3951 : build_omp_array_section (location_t loc, tree array, tree index, tree length)
    3699              : {
    3700         3951 :   tree type = TREE_TYPE (array);
    3701         3951 :   gcc_assert (type);
    3702              : 
    3703         3951 :   tree sectype, eltype = TREE_TYPE (type);
    3704              : 
    3705              :   /* It's not an array or pointer type.  Just reuse the type of the original
    3706              :      expression as the type of the array section (an error will be raised
    3707              :      anyway, later).  */
    3708         3951 :   if (eltype == NULL_TREE || error_operand_p (eltype))
    3709           12 :     sectype = TREE_TYPE (array);
    3710              :   else
    3711              :     {
    3712         3939 :       tree idxtype = NULL_TREE;
    3713              : 
    3714         3939 :       if (index != NULL_TREE
    3715         3939 :           && length != NULL_TREE
    3716         3012 :           && INTEGRAL_TYPE_P (TREE_TYPE (index))
    3717         6946 :           && INTEGRAL_TYPE_P (TREE_TYPE (length)))
    3718              :         {
    3719         3000 :           tree low = fold_convert (sizetype, index);
    3720         3000 :           tree high = fold_convert (sizetype, length);
    3721         3000 :           high = size_binop (PLUS_EXPR, low, high);
    3722         3000 :           high = size_binop (MINUS_EXPR, high, size_one_node);
    3723         3000 :           idxtype = build_range_type (sizetype, low, high);
    3724              :         }
    3725          135 :       else if ((index == NULL_TREE || integer_zerop (index))
    3726          829 :                && length != NULL_TREE
    3727         1616 :                && INTEGRAL_TYPE_P (TREE_TYPE (length)))
    3728          660 :         idxtype = build_index_type (length);
    3729              : 
    3730         3939 :       gcc_assert (!error_operand_p (idxtype));
    3731              : 
    3732         3939 :       sectype = c_build_array_type (eltype, idxtype);
    3733              :     }
    3734              : 
    3735         3951 :   return build3_loc (loc, OMP_ARRAY_SECTION, sectype, array, index, length);
    3736              : }
    3737              : 
    3738              : 
    3739              : /* Record that REF is used.  This is relevant for undeclared static
    3740              :    function and declarations referenced from a non-local context.
    3741              :    ADDRESS indicates whether the address is taken.  */
    3742              : 
    3743              : void
    3744    475394699 : mark_decl_used (tree ref, bool address)
    3745              : {
    3746    475394699 :   if (!ref || !DECL_P (ref) || in_alignof)
    3747              :     return;
    3748              : 
    3749              :   /* Non-file-scope and non-local reference in nested function.  */
    3750    348399192 :   bool nonloc_p = current_function_decl && DECL_CONTEXT (ref)
    3751    122201529 :                   && DECL_CONTEXT (current_function_decl)
    3752    475360639 :                   && DECL_CONTEXT (ref) != current_function_decl;
    3753              : 
    3754              :   /* An undeclared static function.  */
    3755    475350555 :   bool static_p = TREE_CODE (ref) == FUNCTION_DECL
    3756    101946968 :                   && DECL_INITIAL (ref) == NULL_TREE
    3757     69746666 :                   && DECL_EXTERNAL (ref)
    3758    545094525 :                   && !TREE_PUBLIC (ref);
    3759              : 
    3760    475216635 :   if (!static_p && !nonloc_p)
    3761              :     return;
    3762              : 
    3763              :   /* If we may be in an unevaluated context, delay the decision.  */
    3764       136549 :   if (in_sizeof || in_typeof || in_countof || in_generic)
    3765          273 :     return record_maybe_used_decl (ref, address);
    3766              : 
    3767       136276 :   if (static_p)
    3768       133664 :     C_DECL_USED (ref) = 1;
    3769              : 
    3770       136276 :   if (nonloc_p && (VAR_OR_FUNCTION_DECL_P (ref)
    3771              :                    || TREE_CODE (ref) == PARM_DECL))
    3772         2049 :     DECL_NONLOCAL (ref) = 1;
    3773              : 
    3774              :   /* Nothing to do anymore.  */
    3775         2612 :   if (!nonloc_p || C_FUNC_NONLOCAL_CONTEXT (current_function_decl))
    3776       135069 :     return;
    3777              : 
    3778              :   /* Filter out the cases where referencing a non-local variable does not
    3779              :      require a non-local context passed via the static chain.  */
    3780         1207 :   if (!c_type_variably_modified_p (TREE_TYPE (ref)))
    3781         1135 :     switch (TREE_CODE (ref))
    3782              :       {
    3783          215 :       case FUNCTION_DECL:
    3784              :         /* Use of another local function that requires no context is ok.  */
    3785          215 :         if (!C_FUNC_NONLOCAL_CONTEXT (ref) && DECL_INITIAL (ref))
    3786              :           return;
    3787              :         break;
    3788          438 :       case VAR_DECL:
    3789              :         /* Static variables and constexpr are ok, but for the later only
    3790              :            when the address is not taken.  */
    3791          438 :         if (TREE_STATIC (ref) || (C_DECL_DECLARED_CONSTEXPR (ref) && !address))
    3792              :           return;
    3793              :         break;
    3794              :       case TYPE_DECL:
    3795              :         /* A typedef is ok when not for a variably-modified type. */
    3796              :         return;
    3797              :       case CONST_DECL:
    3798              :         /* An enumeration constant is ok. */
    3799              :         return;
    3800              :       case PARM_DECL:
    3801              :         break;
    3802              :       case LABEL_DECL:
    3803              :         break;
    3804            0 :       default:
    3805            0 :         gcc_unreachable ();
    3806              :     }
    3807              : 
    3808              :   /* Mark all parent functions up to the nesting level of the variable as
    3809              :      as needing the non-local context.  */
    3810         2019 :   for (tree cont = current_function_decl; cont; cont = DECL_CONTEXT (cont))
    3811              :     {
    3812         2019 :       if (cont == DECL_CONTEXT (ref))
    3813              :         break;
    3814              : 
    3815              :       /* There should not be any other type of context used for function
    3816              :          except TRANSLATION_UNIT_DECL which we should be able to reach.  */
    3817         1015 :       gcc_checking_assert (TREE_CODE (cont) == FUNCTION_DECL);
    3818              : 
    3819         1015 :       if (TREE_CODE (cont) == FUNCTION_DECL)
    3820         1015 :         C_FUNC_NONLOCAL_CONTEXT (cont) = 1;
    3821              :     }
    3822              : }
    3823              : 
    3824              : 
    3825              : /* Build an external reference to identifier ID.  FUN indicates
    3826              :    whether this will be used for a function call.  LOC is the source
    3827              :    location of the identifier.  This sets *TYPE to the type of the
    3828              :    identifier, which is not the same as the type of the returned value
    3829              :    for CONST_DECLs defined as enum constants.  If the type of the
    3830              :    identifier is not available, *TYPE is set to NULL.  */
    3831              : tree
    3832    174987973 : build_external_ref (location_t loc, tree id, bool fun, tree *type)
    3833              : {
    3834    174987973 :   tree ref;
    3835    174987973 :   tree decl = lookup_name (id);
    3836              : 
    3837              :   /* In Objective-C, an instance variable (ivar) may be preferred to
    3838              :      whatever lookup_name() found.  */
    3839    174987973 :   decl = objc_lookup_ivar (decl, id);
    3840              : 
    3841    174987973 :   *type = NULL;
    3842    174987973 :   if (decl && decl != error_mark_node)
    3843              :     {
    3844    174981552 :       ref = decl;
    3845    174981552 :       *type = TREE_TYPE (ref);
    3846    174981552 :       if (DECL_P (decl) && C_DECL_UNDERSPECIFIED (decl))
    3847            4 :         error_at (loc, "underspecified %qD referenced in its initializer",
    3848              :                   decl);
    3849              :     }
    3850         6421 :   else if (fun)
    3851              :     /* Implicit function declaration.  */
    3852         4729 :     ref = implicitly_declare (loc, id);
    3853         1692 :   else if (decl == error_mark_node)
    3854              :     /* Don't complain about something that's already been
    3855              :        complained about.  */
    3856              :     return error_mark_node;
    3857              :   else
    3858              :     {
    3859         1458 :       undeclared_variable (loc, id);
    3860         1458 :       return error_mark_node;
    3861              :     }
    3862              : 
    3863              :   /* For an OpenMP map clause, we can get better diagnostics for decls with
    3864              :      unmappable types if we return the decl with an error_mark_node type,
    3865              :      rather than returning error_mark_node for the decl itself.  */
    3866    174986281 :   if (TREE_TYPE (ref) == error_mark_node
    3867    174986281 :       && !c_omp_array_section_p)
    3868              :     return error_mark_node;
    3869              : 
    3870    174986263 :   if (TREE_UNAVAILABLE (ref))
    3871           14 :     error_unavailable_use (ref, NULL_TREE);
    3872    174986249 :   else if (TREE_DEPRECATED (ref))
    3873          100 :     warn_deprecated_use (ref, NULL_TREE);
    3874              : 
    3875              :   /* Recursive call does not count as usage.  */
    3876    174986263 :   if (ref != current_function_decl)
    3877              :     {
    3878    174983599 :       TREE_USED (ref) = 1;
    3879              :     }
    3880              : 
    3881    174986263 :   mark_decl_used (ref, false);
    3882              : 
    3883    174986263 :   if (TREE_CODE (ref) == CONST_DECL)
    3884              :     {
    3885       418940 :       used_types_insert (TREE_TYPE (ref));
    3886              : 
    3887       418940 :       if (warn_cxx_compat
    3888          429 :           && TREE_CODE (TREE_TYPE (ref)) == ENUMERAL_TYPE
    3889       419367 :           && C_TYPE_DEFINED_IN_STRUCT (TREE_TYPE (ref)))
    3890              :         {
    3891            1 :           warning_at (loc, OPT_Wc___compat,
    3892              :                       "enum constant defined in struct or union "
    3893              :                       "is not visible in C++");
    3894            1 :           inform (DECL_SOURCE_LOCATION (ref), "enum constant defined here");
    3895              :         }
    3896              : 
    3897       418940 :       ref = DECL_INITIAL (ref);
    3898       418940 :       TREE_CONSTANT (ref) = 1;
    3899              :     }
    3900              :   /* C99 6.7.4p3: An inline definition of a function with external
    3901              :      linkage ... shall not contain a reference to an identifier with
    3902              :      internal linkage.  */
    3903    174567323 :   else if (current_function_decl != NULL_TREE
    3904    173053763 :            && DECL_DECLARED_INLINE_P (current_function_decl)
    3905    159373148 :            && DECL_EXTERNAL (current_function_decl)
    3906    158591317 :            && VAR_OR_FUNCTION_DECL_P (ref)
    3907     56516193 :            && (!VAR_P (ref) || TREE_STATIC (ref))
    3908     47367581 :            && ! TREE_PUBLIC (ref)
    3909    174567357 :            && DECL_CONTEXT (ref) != current_function_decl)
    3910           25 :     record_inline_static (loc, current_function_decl, ref,
    3911              :                           csi_internal);
    3912              : 
    3913              :   return ref;
    3914              : }
    3915              : 
    3916              : static struct maybe_used_decl *maybe_used_decls;
    3917              : 
    3918              : /* Record that DECL, a reference seen inside sizeof or typeof or _Countof or
    3919              :    _Generic, might be used if the operand of sizeof is a VLA type or the
    3920              :    operand of typeof is a variably modified type or the operand of _Countof has
    3921              :    a variable number of elements or the operand of _Generic is the one selected
    3922              :    as the result.  */
    3923              : 
    3924              : static void
    3925          273 : record_maybe_used_decl (tree decl, bool address)
    3926              : {
    3927          273 :   struct maybe_used_decl *t = XOBNEW (&parser_obstack, struct maybe_used_decl);
    3928          273 :   t->decl = decl;
    3929          273 :   t->level = in_sizeof + in_typeof + in_countof + in_generic;
    3930          273 :   t->address = address;
    3931          273 :   t->next = maybe_used_decls;
    3932          273 :   maybe_used_decls = t;
    3933          273 : }
    3934              : 
    3935              : /* Pop the stack of decls possibly used inside sizeof or typeof or _Countof or
    3936              :    _Generic.  If USED is false, just discard them.  If it is true, mark them
    3937              :    used (if no longer inside sizeof or typeof or _Countof or _Generic) or move
    3938              :    them to the next level up (if still inside sizeof or typeof or _Countof or
    3939              :    _Generic).  */
    3940              : 
    3941              : void
    3942      1471740 : pop_maybe_used (bool used)
    3943              : {
    3944      1471740 :   struct maybe_used_decl *p = maybe_used_decls;
    3945      1471740 :   int cur_level = in_sizeof + in_typeof + in_countof + in_generic;
    3946      1472037 :   while (p && p->level > cur_level)
    3947              :     {
    3948          297 :       if (used)
    3949              :         {
    3950           77 :           if (cur_level == 0)
    3951           53 :             mark_decl_used (p->decl, p->address);
    3952              :           else
    3953           24 :             p->level = cur_level;
    3954              :         }
    3955          297 :       p = p->next;
    3956              :     }
    3957      1471740 :   if (!used || cur_level == 0)
    3958      1471659 :     maybe_used_decls = p;
    3959      1471740 : }
    3960              : 
    3961              : /* Pop the stack of decls possibly used inside sizeof or typeof or _Countof or
    3962              :    _Generic, without acting on them, and return the pointer to the previous top
    3963              :    of the stack.  This for use at the end of a default generic association when
    3964              :    it is not yet known whether the expression is used.  If it later turns out
    3965              :    the expression is used (or treated as used before C23), restore_maybe_used
    3966              :    should be called on the return value followed by pop_maybe_used (true);
    3967              :    otherwise, the return value can be discarded.  */
    3968              : 
    3969              : struct maybe_used_decl *
    3970         1138 : save_maybe_used ()
    3971              : {
    3972         1138 :   struct maybe_used_decl *p = maybe_used_decls, *orig = p;
    3973         1138 :   int cur_level = in_sizeof + in_typeof + in_countof + in_generic;
    3974         1170 :   while (p && p->level > cur_level)
    3975           32 :     p = p->next;
    3976         1138 :   maybe_used_decls = p;
    3977         1138 :   return orig;
    3978              : }
    3979              : 
    3980              : /* Restore the stack of decls possibly used inside sizeof or typeof or _Countof
    3981              :    or _Generic returned by save_maybe_used.  It is required that the stack is
    3982              :    at exactly the point where it was left by save_maybe_used.  */
    3983              : 
    3984              : void
    3985          280 : restore_maybe_used (struct maybe_used_decl *stack)
    3986              : {
    3987          280 :   maybe_used_decls = stack;
    3988          280 : }
    3989              : 
    3990              : /* Return the result of sizeof applied to EXPR.  */
    3991              : 
    3992              : struct c_expr
    3993       313176 : c_expr_sizeof_expr (location_t loc, struct c_expr expr)
    3994              : {
    3995       313176 :   struct c_expr ret;
    3996       313176 :   if (expr.value == error_mark_node)
    3997              :     {
    3998          111 :       ret.value = error_mark_node;
    3999          111 :       ret.original_code = ERROR_MARK;
    4000          111 :       ret.original_type = NULL;
    4001          111 :       ret.m_decimal = 0;
    4002          111 :       pop_maybe_used (false);
    4003              :     }
    4004              :   else
    4005              :     {
    4006       313065 :       bool expr_const_operands = true;
    4007              : 
    4008       313065 :       if (TREE_CODE (expr.value) == PARM_DECL
    4009       313065 :           && C_ARRAY_PARAMETER (expr.value))
    4010              :         {
    4011           55 :           auto_diagnostic_group d;
    4012           55 :           if (warning_at (loc, OPT_Wsizeof_array_argument,
    4013              :                           "%<sizeof%> on array function parameter %qE will "
    4014              :                           "return size of %qT", expr.value,
    4015           55 :                           TREE_TYPE (expr.value)))
    4016           19 :             inform (DECL_SOURCE_LOCATION (expr.value), "declared here");
    4017           55 :         }
    4018       313065 :       tree folded_expr = c_fully_fold (expr.value, require_constant_value,
    4019              :                                        &expr_const_operands);
    4020       313065 :       ret.value = c_sizeof (loc, TREE_TYPE (folded_expr));
    4021       313065 :       c_last_sizeof_arg = expr.value;
    4022       313065 :       c_last_sizeof_loc = loc;
    4023       313065 :       ret.original_code = SIZEOF_EXPR;
    4024       313065 :       ret.original_type = NULL;
    4025       313065 :       ret.m_decimal = 0;
    4026       313065 :       if (C_TYPE_VARIABLE_SIZE (TREE_TYPE (folded_expr)))
    4027              :         {
    4028              :           /* sizeof is evaluated when given a vla (C99 6.5.3.4p2).  */
    4029          288 :           ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
    4030              :                               folded_expr, ret.value);
    4031          288 :           C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !expr_const_operands;
    4032          288 :           SET_EXPR_LOCATION (ret.value, loc);
    4033              :         }
    4034       313065 :       pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (folded_expr)));
    4035              :     }
    4036       313176 :   return ret;
    4037              : }
    4038              : 
    4039              : /* Return the result of sizeof applied to T, a structure for the type
    4040              :    name passed to sizeof (rather than the type itself).  LOC is the
    4041              :    location of the original expression.  */
    4042              : 
    4043              : struct c_expr
    4044       334015 : c_expr_sizeof_type (location_t loc, struct c_type_name *t)
    4045              : {
    4046       334015 :   tree type;
    4047       334015 :   struct c_expr ret;
    4048       334015 :   tree type_expr = NULL_TREE;
    4049       334015 :   bool type_expr_const = true;
    4050       334015 :   type = groktypename (t, &type_expr, &type_expr_const);
    4051       334015 :   ret.value = c_sizeof (loc, type);
    4052       334015 :   c_last_sizeof_arg = type;
    4053       334015 :   c_last_sizeof_loc = loc;
    4054       334015 :   ret.original_code = SIZEOF_EXPR;
    4055       334015 :   ret.original_type = NULL;
    4056       334015 :   ret.m_decimal = 0;
    4057       334015 :   if (type == error_mark_node)
    4058              :     {
    4059            5 :       ret.value = error_mark_node;
    4060            5 :       ret.original_code = ERROR_MARK;
    4061              :     }
    4062              :   else
    4063       333968 :   if ((type_expr || TREE_CODE (ret.value) == INTEGER_CST)
    4064       667893 :       && C_TYPE_VARIABLE_SIZE (type))
    4065              :     {
    4066              :       /* If the type is a [*] array, it is a VLA but is represented as
    4067              :          having a size of zero.  In such a case we must ensure that
    4068              :          the result of sizeof does not get folded to a constant by
    4069              :          c_fully_fold, because if the size is evaluated the result is
    4070              :          not constant and so constraints on zero or negative size
    4071              :          arrays must not be applied when this sizeof call is inside
    4072              :          another array declarator.  */
    4073           41 :       if (!type_expr)
    4074           16 :         type_expr = integer_zero_node;
    4075           41 :       ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
    4076              :                           type_expr, ret.value);
    4077           41 :       C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !type_expr_const;
    4078              :     }
    4079       334015 :   pop_maybe_used (type != error_mark_node
    4080       334015 :                   ? C_TYPE_VARIABLE_SIZE (type) : false);
    4081       334015 :   return ret;
    4082              : }
    4083              : 
    4084              : static bool
    4085      2153456 : top_array_vla_p (const_tree type)
    4086              : {
    4087      2153456 :   if (TREE_CODE (type) != ARRAY_TYPE)
    4088              :     return false;
    4089      2153438 :   if (!COMPLETE_TYPE_P (type))
    4090              :     return false;
    4091              : 
    4092      1968487 :   tree d = TYPE_DOMAIN (type);
    4093              : 
    4094      1968487 :   if (!d)
    4095              :     return false;
    4096      1968487 :   if (!TYPE_MAX_VALUE (d))
    4097              :     return false;
    4098              : 
    4099      1967420 :   return TREE_CODE (TYPE_MAX_VALUE (d)) != INTEGER_CST
    4100      1967420 :          || TREE_CODE (TYPE_MIN_VALUE (d)) != INTEGER_CST;
    4101              : }
    4102              : 
    4103              : /* Return the result of countof applied to EXPR.  */
    4104              : 
    4105              : struct c_expr
    4106           54 : c_expr_countof_expr (location_t loc, struct c_expr expr)
    4107              : {
    4108           54 :   struct c_expr ret;
    4109           54 :   if (expr.value == error_mark_node)
    4110              :     {
    4111            1 :       ret.value = error_mark_node;
    4112            1 :       ret.original_code = ERROR_MARK;
    4113            1 :       ret.original_type = NULL;
    4114            1 :       ret.m_decimal = 0;
    4115            1 :       pop_maybe_used (false);
    4116              :     }
    4117              :   else
    4118              :     {
    4119           53 :       bool expr_const_operands = true;
    4120              : 
    4121           53 :       tree folded_expr = c_fully_fold (expr.value, require_constant_value,
    4122              :                                        &expr_const_operands);
    4123           53 :       ret.value = c_countof_type (loc, TREE_TYPE (folded_expr));
    4124           53 :       c_last_sizeof_arg = expr.value;
    4125           53 :       c_last_sizeof_loc = loc;
    4126           53 :       ret.original_code = COUNTOF_EXPR;
    4127           53 :       ret.original_type = NULL;
    4128           53 :       ret.m_decimal = 0;
    4129           53 :       if (top_array_vla_p (TREE_TYPE (folded_expr)))
    4130              :         {
    4131              :           /* countof is evaluated when given a vla.  */
    4132           11 :           ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
    4133              :                               folded_expr, ret.value);
    4134           11 :           C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !expr_const_operands;
    4135           11 :           SET_EXPR_LOCATION (ret.value, loc);
    4136              :         }
    4137           53 :       pop_maybe_used (top_array_vla_p (TREE_TYPE (folded_expr)));
    4138              :     }
    4139           54 :   return ret;
    4140              : }
    4141              : 
    4142              : /* Return the result of countof applied to T, a structure for the type
    4143              :    name passed to countof (rather than the type itself).  LOC is the
    4144              :    location of the original expression.  */
    4145              : 
    4146              : struct c_expr
    4147           18 : c_expr_countof_type (location_t loc, struct c_type_name *t)
    4148              : {
    4149           18 :   tree type;
    4150           18 :   struct c_expr ret;
    4151           18 :   tree type_expr = NULL_TREE;
    4152           18 :   bool type_expr_const = true;
    4153           18 :   type = groktypename (t, &type_expr, &type_expr_const);
    4154           18 :   ret.value = c_countof_type (loc, type);
    4155           18 :   c_last_sizeof_arg = type;
    4156           18 :   c_last_sizeof_loc = loc;
    4157           18 :   ret.original_code = COUNTOF_EXPR;
    4158           18 :   ret.original_type = NULL;
    4159           18 :   ret.m_decimal = 0;
    4160           18 :   if (type == error_mark_node)
    4161              :     {
    4162            0 :       ret.value = error_mark_node;
    4163            0 :       ret.original_code = ERROR_MARK;
    4164              :     }
    4165              :   else
    4166            8 :   if ((type_expr || TREE_CODE (ret.value) == INTEGER_CST)
    4167           22 :       && top_array_vla_p (type))
    4168              :     {
    4169              :       /* If the type is a [*] array, it is a VLA but is represented as
    4170              :          having a size of zero.  In such a case we must ensure that
    4171              :          the result of countof does not get folded to a constant by
    4172              :          c_fully_fold, because if the number of elements is evaluated
    4173              :          the result is not constant and so
    4174              :          constraints on zero or negative size arrays must not be applied
    4175              :          when this countof call is inside another array declarator.  */
    4176            6 :       if (!type_expr)
    4177            0 :         type_expr = integer_zero_node;
    4178            6 :       ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
    4179              :                           type_expr, ret.value);
    4180            6 :       C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !type_expr_const;
    4181              :     }
    4182           18 :   pop_maybe_used (type != error_mark_node ? top_array_vla_p (type) : false);
    4183           18 :   return ret;
    4184              : }
    4185              : 
    4186              : /* Return the result of maxof applied to T, a structure for the type
    4187              :    name passed to maxof (rather than the type itself).  LOC is the
    4188              :    location of the original expression.  */
    4189              : 
    4190              : struct c_expr
    4191           46 : c_expr_maxof_type (location_t loc, struct c_type_name *t)
    4192              : {
    4193           46 :   tree type;
    4194           46 :   struct c_expr ret;
    4195           46 :   tree type_expr = NULL_TREE;
    4196           46 :   bool type_expr_const = true;
    4197           46 :   type = groktypename (t, &type_expr, &type_expr_const);
    4198           46 :   ret.value = c_maxof_type (loc, type);
    4199           46 :   c_last_sizeof_arg = type;
    4200           46 :   c_last_sizeof_loc = loc;
    4201           46 :   ret.original_code = MAXOF_EXPR;
    4202           46 :   ret.original_type = NULL;
    4203           46 :   ret.m_decimal = 0;
    4204           46 :   if (type == error_mark_node)
    4205              :     {
    4206            0 :       ret.value = error_mark_node;
    4207            0 :       ret.original_code = ERROR_MARK;
    4208              :     }
    4209           46 :   pop_maybe_used (type != error_mark_node);
    4210           46 :   return ret;
    4211              : }
    4212              : 
    4213              : /* Return the result of minof applied to T, a structure for the type
    4214              :    name passed to minof (rather than the type itself).  LOC is the
    4215              :    location of the original expression.  */
    4216              : 
    4217              : struct c_expr
    4218           46 : c_expr_minof_type (location_t loc, struct c_type_name *t)
    4219              : {
    4220           46 :   tree type;
    4221           46 :   struct c_expr ret;
    4222           46 :   tree type_expr = NULL_TREE;
    4223           46 :   bool type_expr_const = true;
    4224           46 :   type = groktypename (t, &type_expr, &type_expr_const);
    4225           46 :   ret.value = c_minof_type (loc, type);
    4226           46 :   c_last_sizeof_arg = type;
    4227           46 :   c_last_sizeof_loc = loc;
    4228           46 :   ret.original_code = MINOF_EXPR;
    4229           46 :   ret.original_type = NULL;
    4230           46 :   ret.m_decimal = 0;
    4231           46 :   if (type == error_mark_node)
    4232              :     {
    4233            0 :       ret.value = error_mark_node;
    4234            0 :       ret.original_code = ERROR_MARK;
    4235              :     }
    4236           46 :   pop_maybe_used (type != error_mark_node);
    4237           46 :   return ret;
    4238              : }
    4239              : 
    4240              : /* Build a function call to function FUNCTION with parameters PARAMS.
    4241              :    The function call is at LOC.
    4242              :    PARAMS is a list--a chain of TREE_LIST nodes--in which the
    4243              :    TREE_VALUE of each node is a parameter-expression.
    4244              :    FUNCTION's data type may be a function type or a pointer-to-function.  */
    4245              : 
    4246              : tree
    4247            0 : build_function_call (location_t loc, tree function, tree params)
    4248              : {
    4249            0 :   vec<tree, va_gc> *v;
    4250            0 :   tree ret;
    4251              : 
    4252            0 :   vec_alloc (v, list_length (params));
    4253            0 :   for (; params; params = TREE_CHAIN (params))
    4254            0 :     v->quick_push (TREE_VALUE (params));
    4255            0 :   ret = c_build_function_call_vec (loc, vNULL, function, v, NULL);
    4256            0 :   vec_free (v);
    4257            0 :   return ret;
    4258              : }
    4259              : 
    4260              : /* Give a note about the location of the declaration of DECL,
    4261              :    or, failing that, a pertinent declaration for FUNCTION_EXPR.  */
    4262              : 
    4263              : static void
    4264          299 : inform_declaration (tree decl, tree function_expr)
    4265              : {
    4266          299 :   if (decl && (TREE_CODE (decl) != FUNCTION_DECL
    4267          278 :                || !DECL_IS_UNDECLARED_BUILTIN (decl)))
    4268          207 :     inform (DECL_SOURCE_LOCATION (decl), "declared here");
    4269           92 :   else if (function_expr)
    4270           92 :     switch (TREE_CODE (function_expr))
    4271              :       {
    4272              :       default:
    4273              :         break;
    4274           13 :       case COMPONENT_REF:
    4275              :         /* Show the decl of the pertinent field (e.g. for callback
    4276              :            fields in a struct.  */
    4277           13 :         {
    4278           13 :           tree field_decl = TREE_OPERAND (function_expr, 1);
    4279           13 :           if (location_t loc = DECL_SOURCE_LOCATION (field_decl))
    4280           13 :             inform (loc, "declared here");
    4281              :         }
    4282              :         break;
    4283              :       }
    4284          299 : }
    4285              : 
    4286              : 
    4287              : /* Build a function call to function FUNCTION with parameters PARAMS.
    4288              :    If FUNCTION is the result of resolving an overloaded target built-in,
    4289              :    ORIG_FUNDECL is the original function decl, otherwise it is null.
    4290              :    ORIGTYPES, if not NULL, is a vector of types; each element is
    4291              :    either NULL or the original type of the corresponding element in
    4292              :    PARAMS.  The original type may differ from TREE_TYPE of the
    4293              :    parameter for enums.  FUNCTION's data type may be a function type
    4294              :    or pointer-to-function.  This function changes the elements of
    4295              :    PARAMS.  */
    4296              : 
    4297              : tree
    4298     49913259 : build_function_call_vec (location_t loc, vec<location_t> arg_loc,
    4299              :                          tree function, vec<tree, va_gc> *params,
    4300              :                          vec<tree, va_gc> *origtypes, tree orig_fundecl)
    4301              : {
    4302     49913259 :   tree fntype, fundecl = NULL_TREE;
    4303     49913259 :   tree name = NULL_TREE, result;
    4304     49913259 :   tree tem;
    4305     49913259 :   int nargs;
    4306     49913259 :   tree *argarray;
    4307              : 
    4308              : 
    4309              :   /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
    4310     49913259 :   STRIP_TYPE_NOPS (function);
    4311              : 
    4312              :   /* Convert anything with function type to a pointer-to-function.  */
    4313     49913259 :   if (TREE_CODE (function) == FUNCTION_DECL)
    4314              :     {
    4315     49835719 :       name = DECL_NAME (function);
    4316              : 
    4317     49835719 :       if (flag_tm)
    4318          421 :         tm_malloc_replacement (function);
    4319     49835719 :       fundecl = function;
    4320     49835719 :       if (!orig_fundecl)
    4321     49835719 :         orig_fundecl = fundecl;
    4322              :       /* Atomic functions have type checking/casting already done.  They are
    4323              :          often rewritten and don't match the original parameter list.  */
    4324     99671438 :       if (name && startswith (IDENTIFIER_POINTER (name), "__atomic_"))
    4325              :         origtypes = NULL;
    4326              :     }
    4327     49913259 :   if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE)
    4328     49850237 :     function = function_to_pointer_conversion (loc, function);
    4329              : 
    4330              :   /* For Objective-C, convert any calls via a cast to OBJC_TYPE_REF
    4331              :      expressions, like those used for ObjC messenger dispatches.  */
    4332     49913259 :   if (params && !params->is_empty ())
    4333     38195391 :     function = objc_rewrite_function_call (function, (*params)[0]);
    4334              : 
    4335     49913259 :   function = c_fully_fold (function, false, NULL);
    4336              : 
    4337     49913259 :   fntype = TREE_TYPE (function);
    4338              : 
    4339     49913259 :   if (TREE_CODE (fntype) == ERROR_MARK)
    4340            5 :     return error_mark_node;
    4341              : 
    4342     49913254 :   if (!(TREE_CODE (fntype) == POINTER_TYPE
    4343     49913220 :         && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE))
    4344              :     {
    4345           37 :       if (!flag_diagnostics_show_caret && !STATEMENT_CLASS_P (function))
    4346           33 :         error_at (loc,
    4347              :                   "called object %qE is not a function or function pointer",
    4348              :                   function);
    4349            4 :       else if (DECL_P (function))
    4350              :         {
    4351            1 :           auto_diagnostic_group d;
    4352            1 :           error_at (loc,
    4353              :                     "called object %qD is not a function or function pointer",
    4354              :                     function);
    4355            1 :           inform_declaration (function, NULL_TREE);
    4356            1 :         }
    4357              :       else
    4358            3 :         error_at (loc,
    4359              :                   "called object is not a function or function pointer");
    4360           37 :       return error_mark_node;
    4361              :     }
    4362              : 
    4363     49913217 :   if (fundecl && TREE_THIS_VOLATILE (fundecl))
    4364       377254 :     current_function_returns_abnormally = 1;
    4365              : 
    4366              :   /* fntype now gets the type of function pointed to.  */
    4367     49913217 :   fntype = TREE_TYPE (fntype);
    4368     49913217 :   tree return_type = TREE_TYPE (fntype);
    4369              : 
    4370              :   /* Convert the parameters to the types declared in the
    4371              :      function prototype, or apply default promotions.  */
    4372              : 
    4373     49913217 :   nargs = convert_arguments (loc, arg_loc, fntype, params,
    4374              :                              origtypes, function, fundecl);
    4375     49913217 :   if (nargs < 0)
    4376          178 :     return error_mark_node;
    4377              : 
    4378              :   /* Check that the function is called through a compatible prototype.
    4379              :      If it is not, warn.  */
    4380     49912132 :   if (CONVERT_EXPR_P (function)
    4381          923 :       && TREE_CODE (tem = TREE_OPERAND (function, 0)) == ADDR_EXPR
    4382          215 :       && TREE_CODE (tem = TREE_OPERAND (tem, 0)) == FUNCTION_DECL
    4383     49913224 :       && !comptypes (fntype, TREE_TYPE (tem)))
    4384              :     {
    4385              :       /* This situation leads to run-time undefined behavior.  We can't,
    4386              :          therefore, simply error unless we can prove that all possible
    4387              :          executions of the program must execute the code.  */
    4388           20 :       warning_at (loc, 0, "function called through a non-compatible type");
    4389              : 
    4390           20 :       if (VOID_TYPE_P (return_type)
    4391           20 :           && TYPE_QUALS (return_type) != TYPE_UNQUALIFIED)
    4392            1 :         pedwarn (loc, 0,
    4393              :                  "function with qualified void return type called");
    4394              :      }
    4395              : 
    4396     49913039 :   argarray = vec_safe_address (params);
    4397              : 
    4398              :   /* Check that arguments to builtin functions match the expectations.  */
    4399     49913039 :   if (fundecl
    4400     49835556 :       && fndecl_built_in_p (fundecl)
    4401     83169143 :       && !check_builtin_function_arguments (loc, arg_loc, fundecl,
    4402              :                                             orig_fundecl, nargs, argarray))
    4403          338 :     return error_mark_node;
    4404              : 
    4405              :   /* Check that the arguments to the function are valid.  */
    4406     49912701 :   bool warned_p = check_function_arguments (loc, fundecl, fntype,
    4407              :                                             nargs, argarray, &arg_loc,
    4408              :                                             comptypes);
    4409              : 
    4410     49912701 :   if (TYPE_QUALS (return_type) != TYPE_UNQUALIFIED
    4411     49912701 :       && !VOID_TYPE_P (return_type))
    4412           11 :     return_type = c_build_qualified_type (return_type, TYPE_UNQUALIFIED);
    4413     49912701 :   if (name != NULL_TREE
    4414     99747919 :       && startswith (IDENTIFIER_POINTER (name), "__builtin_"))
    4415              :     {
    4416     32528930 :       if (require_constant_value)
    4417         3463 :         result
    4418         3463 :           = fold_build_call_array_initializer_loc (loc, return_type,
    4419              :                                                    function, nargs, argarray);
    4420              :       else
    4421     32525467 :         result = fold_build_call_array_loc (loc, return_type,
    4422              :                                             function, nargs, argarray);
    4423     32528930 :       if (TREE_CODE (result) == NOP_EXPR
    4424     32528930 :           && TREE_CODE (TREE_OPERAND (result, 0)) == INTEGER_CST)
    4425        26614 :         STRIP_TYPE_NOPS (result);
    4426              :     }
    4427              :   else
    4428     17383771 :     result = build_call_array_loc (loc, return_type,
    4429              :                                    function, nargs, argarray);
    4430              :   /* If -Wnonnull warning has been diagnosed, avoid diagnosing it again
    4431              :      later.  */
    4432     49912701 :   if (warned_p && TREE_CODE (result) == CALL_EXPR)
    4433          215 :     suppress_warning (result, OPT_Wnonnull);
    4434              : 
    4435              :   /* In this improbable scenario, a nested function returns a VM type.
    4436              :      Create a TARGET_EXPR so that the call always has a LHS, much as
    4437              :      what the C++ FE does for functions returning non-PODs.  */
    4438     49912701 :   if (c_type_variably_modified_p (TREE_TYPE (fntype)))
    4439              :     {
    4440           83 :       tree tmp = create_tmp_var_raw (TREE_TYPE (fntype));
    4441           83 :       result = build4 (TARGET_EXPR, TREE_TYPE (fntype), tmp, result,
    4442              :                        NULL_TREE, NULL_TREE);
    4443              :     }
    4444              : 
    4445     49912701 :   if (VOID_TYPE_P (TREE_TYPE (result)))
    4446              :     {
    4447      2394898 :       if (TYPE_QUALS (TREE_TYPE (result)) != TYPE_UNQUALIFIED)
    4448            2 :         pedwarn (loc, 0,
    4449              :                  "function with qualified void return type called");
    4450      2394898 :       return result;
    4451              :     }
    4452     47517803 :   return require_complete_type (loc, result);
    4453              : }
    4454              : 
    4455              : /* Like build_function_call_vec, but call also resolve_overloaded_builtin.  */
    4456              : 
    4457              : tree
    4458     49912816 : c_build_function_call_vec (location_t loc, const vec<location_t> &arg_loc,
    4459              :                            tree function, vec<tree, va_gc> *params,
    4460              :                            vec<tree, va_gc> *origtypes)
    4461              : {
    4462              :   /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
    4463     49912827 :   STRIP_TYPE_NOPS (function);
    4464              : 
    4465              :   /* Convert anything with function type to a pointer-to-function.  */
    4466     49912816 :   if (TREE_CODE (function) == FUNCTION_DECL)
    4467              :     {
    4468              :       /* Implement type-directed function overloading for builtins.
    4469              :          resolve_overloaded_builtin and targetm.resolve_overloaded_builtin
    4470              :          handle all the type checking.  The result is a complete expression
    4471              :          that implements this function call.  */
    4472     49835276 :       tree tem = resolve_overloaded_builtin (loc, function, params);
    4473     49835276 :       if (tem)
    4474              :         return tem;
    4475              :     }
    4476     49826793 :   return build_function_call_vec (loc, arg_loc, function, params, origtypes);
    4477              : }
    4478              : 
    4479              : /* Helper for convert_arguments called to convert the VALue of argument
    4480              :    number ARGNUM from ORIGTYPE to the corresponding parameter number
    4481              :    PARMNUM and TYPE.
    4482              :    PLOC is the location where the conversion is being performed.
    4483              :    FUNCTION and FUNDECL are the same as in convert_arguments.
    4484              :    VALTYPE is the original type of VAL before the conversion and,
    4485              :    for EXCESS_PRECISION_EXPR, the operand of the expression.
    4486              :    NPC is true if VAL represents the null pointer constant (VAL itself
    4487              :    will have been folded to an integer constant).
    4488              :    RNAME is the same as FUNCTION except in Objective C when it's
    4489              :    the function selector.
    4490              :    EXCESS_PRECISION is true when VAL was originally represented
    4491              :    as EXCESS_PRECISION_EXPR.
    4492              :    WARNOPT is the same as in convert_for_assignment.  */
    4493              : 
    4494              : static tree
    4495    125628518 : convert_argument (location_t ploc, tree function, tree fundecl,
    4496              :                   tree type, tree origtype, tree val, tree valtype,
    4497              :                   bool npc, tree rname, int parmnum, int argnum,
    4498              :                   bool excess_precision, int warnopt)
    4499              : {
    4500              :   /* Formal parm type is specified by a function prototype.  */
    4501              : 
    4502    125628518 :   if (type == error_mark_node || !COMPLETE_TYPE_P (type))
    4503              :     {
    4504            3 :       error_at (ploc, "type of formal parameter %d is incomplete",
    4505              :                 parmnum + 1);
    4506            3 :       return error_mark_node;
    4507              :     }
    4508              : 
    4509              :   /* Optionally warn about conversions that differ from the default
    4510              :      conversions.  */
    4511    125628515 :   if (warn_traditional_conversion || warn_traditional)
    4512              :     {
    4513          193 :       if (INTEGRAL_TYPE_P (type)
    4514          107 :           && SCALAR_FLOAT_TYPE_P (valtype))
    4515           19 :         warning_at (ploc, OPT_Wtraditional_conversion,
    4516              :                     "passing argument %d of %qE as integer rather "
    4517              :                     "than floating due to prototype",
    4518              :                     argnum, rname);
    4519          193 :       if (INTEGRAL_TYPE_P (type)
    4520          107 :           && TREE_CODE (valtype) == COMPLEX_TYPE)
    4521            5 :         warning_at (ploc, OPT_Wtraditional_conversion,
    4522              :                     "passing argument %d of %qE as integer rather "
    4523              :                     "than complex due to prototype",
    4524              :                     argnum, rname);
    4525          188 :       else if (TREE_CODE (type) == COMPLEX_TYPE
    4526           14 :                && SCALAR_FLOAT_TYPE_P (valtype))
    4527            7 :         warning_at (ploc, OPT_Wtraditional_conversion,
    4528              :                     "passing argument %d of %qE as complex rather "
    4529              :                     "than floating due to prototype",
    4530              :                     argnum, rname);
    4531          181 :       else if (SCALAR_FLOAT_TYPE_P (type)
    4532           71 :                && INTEGRAL_TYPE_P (valtype))
    4533           19 :         warning_at (ploc, OPT_Wtraditional_conversion,
    4534              :                     "passing argument %d of %qE as floating rather "
    4535              :                     "than integer due to prototype",
    4536              :                     argnum, rname);
    4537          162 :       else if (TREE_CODE (type) == COMPLEX_TYPE
    4538            7 :                && INTEGRAL_TYPE_P (valtype))
    4539            5 :         warning_at (ploc, OPT_Wtraditional_conversion,
    4540              :                     "passing argument %d of %qE as complex rather "
    4541              :                     "than integer due to prototype",
    4542              :                     argnum, rname);
    4543          157 :       else if (SCALAR_FLOAT_TYPE_P (type)
    4544           52 :                && TREE_CODE (valtype) == COMPLEX_TYPE)
    4545            7 :         warning_at (ploc, OPT_Wtraditional_conversion,
    4546              :                     "passing argument %d of %qE as floating rather "
    4547              :                     "than complex due to prototype",
    4548              :                     argnum, rname);
    4549              :       /* ??? At some point, messages should be written about
    4550              :          conversions between complex types, but that's too messy
    4551              :          to do now.  */
    4552          150 :       else if (SCALAR_FLOAT_TYPE_P (type)
    4553           45 :                && SCALAR_FLOAT_TYPE_P (valtype))
    4554              :         {
    4555           45 :           unsigned int formal_prec = TYPE_PRECISION (type);
    4556              : 
    4557              :           /* Warn if any argument is passed as `float',
    4558              :              since without a prototype it would be `double'.  */
    4559           45 :           if (formal_prec == TYPE_PRECISION (float_type_node)
    4560           45 :               && type != dfloat32_type_node)
    4561            7 :             warning_at (ploc, 0,
    4562              :                         "passing argument %d of %qE as %<float%> "
    4563              :                         "rather than %<double%> due to prototype",
    4564              :                         argnum, rname);
    4565              : 
    4566              :           /* Warn if mismatch between argument and prototype
    4567              :              for decimal float types.  Warn of conversions with
    4568              :              binary float types and of precision narrowing due to
    4569              :              prototype.  */
    4570           38 :           else if (type != valtype
    4571           32 :                    && (type == dfloat32_type_node
    4572           22 :                        || type == dfloat64_type_node
    4573           12 :                        || type == dfloat128_type_node
    4574            2 :                        || valtype == dfloat32_type_node
    4575            2 :                        || valtype == dfloat64_type_node
    4576            2 :                        || valtype == dfloat128_type_node)
    4577           38 :                    && (formal_prec
    4578           30 :                        <= TYPE_PRECISION (valtype)
    4579           14 :                        || (type == dfloat128_type_node
    4580           10 :                            && (valtype
    4581           10 :                                != dfloat64_type_node
    4582            8 :                                && (valtype
    4583              :                                    != dfloat32_type_node)))
    4584            8 :                        || (type == dfloat64_type_node
    4585            4 :                            && (valtype
    4586              :                                != dfloat32_type_node))))
    4587           24 :             warning_at (ploc, 0,
    4588              :                         "passing argument %d of %qE as %qT "
    4589              :                         "rather than %qT due to prototype",
    4590              :                         argnum, rname, type, valtype);
    4591              : 
    4592              :         }
    4593              :       /* Detect integer changing in width or signedness.
    4594              :          These warnings are only activated with
    4595              :          -Wtraditional-conversion, not with -Wtraditional.  */
    4596          105 :       else if (warn_traditional_conversion
    4597          105 :                && INTEGRAL_TYPE_P (type)
    4598          102 :                && INTEGRAL_TYPE_P (valtype))
    4599              :         {
    4600           83 :           unsigned int formal_prec = TYPE_PRECISION (type);
    4601           83 :           tree would_have_been = default_conversion (val);
    4602           83 :           tree type1 = TREE_TYPE (would_have_been);
    4603              : 
    4604           83 :           if (val == error_mark_node)
    4605              :             /* VAL could have been of incomplete type.  */;
    4606           83 :           else if (TREE_CODE (type) == ENUMERAL_TYPE
    4607           83 :                    && (TYPE_MAIN_VARIANT (type)
    4608            2 :                        == TYPE_MAIN_VARIANT (valtype)))
    4609              :             /* No warning if function asks for enum
    4610              :                and the actual arg is that enum type.  */
    4611              :             ;
    4612           81 :           else if (formal_prec != TYPE_PRECISION (type1))
    4613           14 :             warning_at (ploc, OPT_Wtraditional_conversion,
    4614              :                         "passing argument %d of %qE "
    4615              :                         "with different width due to prototype",
    4616              :                         argnum, rname);
    4617           67 :           else if (TYPE_UNSIGNED (type) == TYPE_UNSIGNED (type1))
    4618              :             ;
    4619              :           /* Don't complain if the formal parameter type
    4620              :              is an enum, because we can't tell now whether
    4621              :              the value was an enum--even the same enum.  */
    4622           32 :           else if (TREE_CODE (type) == ENUMERAL_TYPE)
    4623              :             ;
    4624           32 :           else if (TREE_CODE (val) == INTEGER_CST
    4625            5 :                    && int_fits_type_p (val, type))
    4626              :             /* Change in signedness doesn't matter
    4627              :                if a constant value is unaffected.  */
    4628              :             ;
    4629              :           /* If the value is extended from a narrower
    4630              :              unsigned type, it doesn't matter whether we
    4631              :              pass it as signed or unsigned; the value
    4632              :              certainly is the same either way.  */
    4633           32 :           else if (TYPE_PRECISION (valtype) < TYPE_PRECISION (type)
    4634           32 :                    && TYPE_UNSIGNED (valtype))
    4635              :             ;
    4636           32 :           else if (TYPE_UNSIGNED (type))
    4637           17 :             warning_at (ploc, OPT_Wtraditional_conversion,
    4638              :                         "passing argument %d of %qE "
    4639              :                         "as unsigned due to prototype",
    4640              :                         argnum, rname);
    4641              :           else
    4642           15 :             warning_at (ploc, OPT_Wtraditional_conversion,
    4643              :                         "passing argument %d of %qE "
    4644              :                         "as signed due to prototype",
    4645              :                         argnum, rname);
    4646              :         }
    4647              :     }
    4648              : 
    4649              :   /* Possibly restore an EXCESS_PRECISION_EXPR for the
    4650              :      sake of better warnings from convert_and_check.  */
    4651    125628515 :   if (excess_precision)
    4652          380 :     val = build1 (EXCESS_PRECISION_EXPR, valtype, val);
    4653              : 
    4654    125628515 :   tree parmval = convert_for_assignment (ploc, ploc, type,
    4655              :                                          val, origtype, ic_argpass,
    4656              :                                          npc, fundecl, function,
    4657              :                                          parmnum + 1, warnopt);
    4658    125628515 :   return parmval;
    4659              : }
    4660              : 
    4661              : /* Convert the argument expressions in the vector VALUES
    4662              :    to the types in the list TYPE_ARG_TYPES (FNTYPE).
    4663              : 
    4664              :    If the list is exhausted, or when an element has NULL as its type,
    4665              :    perform the default conversions.
    4666              : 
    4667              :    ORIGTYPES is the original types of the expressions in VALUES.  This
    4668              :    holds the type of enum values which have been converted to integral
    4669              :    types.  It may be NULL.
    4670              : 
    4671              :    FUNCTION is a tree for the called function.  It is used only for
    4672              :    error messages, where it is formatted with %qE.
    4673              : 
    4674              :    This is also where warnings about wrong number of args are generated.
    4675              : 
    4676              :    ARG_LOC are locations of function arguments (if any).
    4677              : 
    4678              :    Returns the actual number of arguments processed (which may be less
    4679              :    than the length of VALUES in some error situations), or -1 on
    4680              :    failure.  */
    4681              : 
    4682              : static int
    4683     49913217 : convert_arguments (location_t loc, vec<location_t> arg_loc, tree fntype,
    4684              :                    vec<tree, va_gc> *values, vec<tree, va_gc> *origtypes,
    4685              :                    tree function, tree fundecl)
    4686              : {
    4687     49913217 :   tree typelist = TYPE_ARG_TYPES (fntype);
    4688     49913217 :   unsigned int parmnum;
    4689     49913217 :   bool error_args = false;
    4690     49913217 :   const bool type_generic = fundecl
    4691     49913217 :     && lookup_attribute ("type generic", TYPE_ATTRIBUTES (TREE_TYPE (fundecl)));
    4692     49913217 :   bool type_generic_remove_excess_precision = false;
    4693     49913217 :   bool type_generic_overflow_p = false;
    4694     49913217 :   bool type_generic_bit_query = false;
    4695     49913217 :   tree selector;
    4696              : 
    4697              :   /* Change pointer to function to the function itself for
    4698              :      diagnostics.  */
    4699     49913217 :   if (TREE_CODE (function) == ADDR_EXPR
    4700     49913217 :       && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL)
    4701     49837817 :     function = TREE_OPERAND (function, 0);
    4702              : 
    4703              :   /* Handle an ObjC selector specially for diagnostics.  */
    4704     49913217 :   selector = objc_message_selector ();
    4705              : 
    4706              :   /* For a call to a built-in function declared without a prototype,
    4707              :      set to the built-in function's argument list.  */
    4708     49913217 :   tree builtin_typelist = NULL_TREE;
    4709              : 
    4710              :   /* For type-generic built-in functions, determine whether excess
    4711              :      precision should be removed (classification) or not
    4712              :      (comparison).  */
    4713     49913217 :   if (fundecl
    4714     49913217 :       && fndecl_built_in_p (fundecl, BUILT_IN_NORMAL))
    4715              :     {
    4716      1406269 :       built_in_function code = DECL_FUNCTION_CODE (fundecl);
    4717      1406269 :       if (C_DECL_BUILTIN_PROTOTYPE (fundecl))
    4718              :         {
    4719              :           /* For a call to a built-in function declared without a prototype
    4720              :              use the types of the parameters of the internal built-in to
    4721              :              match those of the arguments to.  */
    4722       692291 :           if (tree bdecl = builtin_decl_explicit (code))
    4723       692291 :             builtin_typelist = TYPE_ARG_TYPES (TREE_TYPE (bdecl));
    4724              :         }
    4725              : 
    4726              :       /* For type-generic built-in functions, determine whether excess
    4727              :          precision should be removed (classification) or not
    4728              :          (comparison).  */
    4729      1406269 :       if (type_generic)
    4730        60977 :         switch (code)
    4731              :           {
    4732         5399 :           case BUILT_IN_ISFINITE:
    4733         5399 :           case BUILT_IN_ISINF:
    4734         5399 :           case BUILT_IN_ISINF_SIGN:
    4735         5399 :           case BUILT_IN_ISNAN:
    4736         5399 :           case BUILT_IN_ISNORMAL:
    4737         5399 :           case BUILT_IN_ISSIGNALING:
    4738         5399 :           case BUILT_IN_FPCLASSIFY:
    4739         5399 :             type_generic_remove_excess_precision = true;
    4740         5399 :             break;
    4741              : 
    4742        21026 :           case BUILT_IN_ADD_OVERFLOW_P:
    4743        21026 :           case BUILT_IN_SUB_OVERFLOW_P:
    4744        21026 :           case BUILT_IN_MUL_OVERFLOW_P:
    4745              :             /* The last argument of these type-generic builtins
    4746              :                should not be promoted.  */
    4747        21026 :             type_generic_overflow_p = true;
    4748        21026 :             break;
    4749              : 
    4750         1348 :           case BUILT_IN_CLZG:
    4751         1348 :           case BUILT_IN_CTZG:
    4752         1348 :           case BUILT_IN_CLRSBG:
    4753         1348 :           case BUILT_IN_FFSG:
    4754         1348 :           case BUILT_IN_PARITYG:
    4755         1348 :           case BUILT_IN_POPCOUNTG:
    4756              :             /* The first argument of these type-generic builtins
    4757              :                should not be promoted.  */
    4758         1348 :             type_generic_bit_query = true;
    4759         1348 :             break;
    4760              : 
    4761              :           default:
    4762              :             break;
    4763              :           }
    4764              :     }
    4765              : 
    4766              :   /* Scan the given expressions (VALUES) and types (TYPELIST), producing
    4767              :      individual converted arguments.  */
    4768              : 
    4769     49913217 :   tree typetail, builtin_typetail, val;
    4770     49913217 :   for (typetail = typelist,
    4771     49913217 :          builtin_typetail = builtin_typelist,
    4772     49913217 :          parmnum = 0;
    4773    176480861 :        values && values->iterate (parmnum, &val);
    4774              :        ++parmnum)
    4775              :     {
    4776              :       /* The type of the function parameter (if it was declared with one).  */
    4777    252194312 :       tree type = typetail ? TREE_VALUE (typetail) : NULL_TREE;
    4778              :       /* The type of the built-in function parameter (if the function
    4779              :          is a built-in).  Used to detect type incompatibilities in
    4780              :          calls to built-ins declared without a prototype.  */
    4781    126567680 :       tree builtin_type = (builtin_typetail
    4782    127606953 :                            ? TREE_VALUE (builtin_typetail) : NULL_TREE);
    4783              :       /* The original type of the argument being passed to the function.  */
    4784    126567680 :       tree valtype = TREE_TYPE (val);
    4785              :       /* The called function (or function selector in Objective C).  */
    4786    126567680 :       tree rname = function;
    4787    126567680 :       int argnum = parmnum + 1;
    4788    126567680 :       const char *invalid_func_diag;
    4789              :       /* Set for EXCESS_PRECISION_EXPR arguments.  */
    4790    126567680 :       bool excess_precision = false;
    4791              :       /* The value of the argument after conversion to the type
    4792              :          of the function parameter it is passed to.  */
    4793    126567680 :       tree parmval;
    4794              :       /* Some __atomic_* builtins have additional hidden argument at
    4795              :          position 0.  */
    4796    126567680 :       location_t ploc
    4797    126298592 :         = !arg_loc.is_empty () && values->length () == arg_loc.length ()
    4798    126297992 :           ? expansion_point_location_if_in_system_header (arg_loc[parmnum])
    4799    126567680 :           : input_location;
    4800              : 
    4801    126567680 :       if (type == void_type_node)
    4802              :         {
    4803           33 :           auto_diagnostic_group d;
    4804           33 :           int num_expected = parmnum;
    4805           33 :           int num_actual = values->length ();
    4806           33 :           gcc_rich_location rich_loc (loc);
    4807           33 :           if (ploc != input_location)
    4808           32 :             rich_loc.add_range (ploc);
    4809           33 :           if (selector)
    4810            0 :             error_at (&rich_loc,
    4811              :                       "too many arguments to method %qE; expected %i, have %i",
    4812              :                       selector, num_expected, num_actual);
    4813              :           else
    4814           33 :             error_at (&rich_loc,
    4815              :                       "too many arguments to function %qE; expected %i, have %i",
    4816              :                       function, num_expected, num_actual);
    4817           33 :           inform_declaration (fundecl, function);
    4818           65 :           return error_args ? -1 : (int) parmnum;
    4819           33 :         }
    4820              : 
    4821    126567647 :       if (builtin_type == void_type_node)
    4822              :         {
    4823           12 :           auto_diagnostic_group d;
    4824           12 :           if (warning_at (loc, OPT_Wbuiltin_declaration_mismatch,
    4825              :                           "too many arguments to built-in function %qE "
    4826              :                           "expecting %d", function, parmnum))
    4827           12 :             inform_declaration (fundecl, function);
    4828           12 :           builtin_typetail = NULL_TREE;
    4829           12 :         }
    4830              : 
    4831        90575 :       if (!typetail && parmnum == 0 && !TYPE_NO_NAMED_ARGS_STDARG_P (fntype)
    4832    126658103 :           && !(fundecl && fndecl_built_in_p (fundecl)))
    4833              :         {
    4834         6961 :           auto_diagnostic_group d;
    4835         6961 :           bool warned;
    4836         6961 :           if (selector)
    4837            0 :             warned = warning_at (loc, OPT_Wdeprecated_non_prototype,
    4838              :                                  "ISO C23 does not allow arguments"
    4839              :                                  " for method %qE declared without parameters",
    4840              :                                  function);
    4841              :           else
    4842         6961 :             warned = warning_at (loc, OPT_Wdeprecated_non_prototype,
    4843              :                                  "ISO C23 does not allow arguments"
    4844              :                                  " for function %qE declared without parameters",
    4845              :                                  function);
    4846         6961 :           if (warned)
    4847            4 :             inform_declaration (fundecl, function);
    4848         6961 :         }
    4849              : 
    4850    126567647 :       if (selector && argnum > 2)
    4851              :         {
    4852            0 :           rname = selector;
    4853            0 :           argnum -= 2;
    4854              :         }
    4855              : 
    4856              :       /* Determine if VAL is a null pointer constant before folding it.  */
    4857    126567647 :       bool npc = null_pointer_constant_p (val);
    4858              : 
    4859              :       /* If there is excess precision and a prototype, convert once to
    4860              :          the required type rather than converting via the semantic
    4861              :          type.  Likewise without a prototype a float value represented
    4862              :          as long double should be converted once to double.  But for
    4863              :          type-generic classification functions excess precision must
    4864              :          be removed here.  */
    4865    126567647 :       if (TREE_CODE (val) == EXCESS_PRECISION_EXPR
    4866          433 :           && (type || !type_generic || !type_generic_remove_excess_precision))
    4867              :         {
    4868          413 :           val = TREE_OPERAND (val, 0);
    4869          413 :           excess_precision = true;
    4870              :         }
    4871    126567647 :       val = c_fully_fold (val, false, NULL);
    4872    253135295 :       STRIP_TYPE_NOPS (val);
    4873              : 
    4874    126567647 :       val = require_complete_type (ploc, val);
    4875              : 
    4876              :       /* Some floating-point arguments must be promoted to double when
    4877              :          no type is specified by a prototype.  This applies to
    4878              :          arguments of type float, and to architecture-specific types
    4879              :          (ARM __fp16), but not to _FloatN or _FloatNx types.  */
    4880    126567647 :       bool promote_float_arg = false;
    4881    126567647 :       if (type == NULL_TREE
    4882       941048 :           && TREE_CODE (valtype) == REAL_TYPE
    4883       269595 :           && (TYPE_PRECISION (valtype)
    4884       269595 :               <= TYPE_PRECISION (double_type_node))
    4885       262349 :           && TYPE_MAIN_VARIANT (valtype) != double_type_node
    4886       131373 :           && TYPE_MAIN_VARIANT (valtype) != long_double_type_node
    4887    126699020 :           && !DECIMAL_FLOAT_MODE_P (TYPE_MODE (valtype)))
    4888              :         {
    4889              :           /* Promote this argument, unless it has a _FloatN or
    4890              :              _FloatNx type.  */
    4891      1027486 :           promote_float_arg = true;
    4892      1027486 :           for (int i = 0; i < NUM_FLOATN_NX_TYPES; i++)
    4893       900123 :             if (TYPE_MAIN_VARIANT (valtype) == FLOATN_NX_TYPE_NODE (i))
    4894              :               {
    4895              :                 promote_float_arg = false;
    4896              :                 break;
    4897              :               }
    4898              :           /* Don't promote __bf16 either.  */
    4899       130640 :           if (TYPE_MAIN_VARIANT (valtype) == bfloat16_type_node)
    4900    126437077 :             promote_float_arg = false;
    4901              :         }
    4902              : 
    4903    126567647 :       if (type != NULL_TREE)
    4904              :         {
    4905    125626599 :           tree origtype = (!origtypes) ? NULL_TREE : (*origtypes)[parmnum];
    4906    125626599 :           parmval = convert_argument (ploc, function, fundecl, type, origtype,
    4907              :                                       val, valtype, npc, rname, parmnum, argnum,
    4908              :                                       excess_precision, 0);
    4909              :         }
    4910              :       /* A NULLPTR type is just a nullptr always.  */
    4911       941048 :       else if (TREE_CODE (TREE_TYPE (val)) == NULLPTR_TYPE)
    4912            9 :         parmval = omit_one_operand_loc (ploc, TREE_TYPE (val), nullptr_node, val);
    4913       941039 :       else if (promote_float_arg)
    4914              :         {
    4915       127293 :           if (type_generic)
    4916              :             parmval = val;
    4917              :           else
    4918              :             {
    4919              :               /* Convert `float' to `double'.  */
    4920       124522 :               if (warn_double_promotion && !c_inhibit_evaluation_warnings)
    4921            6 :                 warning_at (ploc, OPT_Wdouble_promotion,
    4922              :                             "implicit conversion from %qT to %qT when passing "
    4923              :                             "argument to function",
    4924              :                             valtype, double_type_node);
    4925       124522 :               parmval = convert (double_type_node, val);
    4926              :             }
    4927              :         }
    4928       813746 :       else if ((excess_precision && !type_generic)
    4929       813744 :                || (type_generic_overflow_p && parmnum == 2)
    4930       792722 :                || (type_generic_bit_query && parmnum == 0))
    4931              :         /* A "double" argument with excess precision being passed
    4932              :            without a prototype or in variable arguments.
    4933              :            The last argument of __builtin_*_overflow_p should not be
    4934              :            promoted, similarly the first argument of
    4935              :            __builtin_{clz,ctz,clrsb,ffs,parity,popcount}g.  */
    4936        22366 :         parmval = convert (valtype, val);
    4937      1582760 :       else if ((invalid_func_diag =
    4938       791380 :                 targetm.calls.invalid_arg_for_unprototyped_fn (typelist, fundecl, val)))
    4939              :         {
    4940            0 :           error (invalid_func_diag);
    4941            0 :           return -1;
    4942              :         }
    4943       791380 :       else if (TREE_CODE (val) == ADDR_EXPR && reject_gcc_builtin (val))
    4944              :         {
    4945              :           return -1;
    4946              :         }
    4947              :       else
    4948              :         /* Convert `short' and `char' to full-size `int'.  */
    4949       791377 :         parmval = default_conversion (val);
    4950              : 
    4951    126567644 :       (*values)[parmnum] = parmval;
    4952    126567644 :       if (parmval == error_mark_node)
    4953          105 :         error_args = true;
    4954              : 
    4955    126567644 :       if (!type && builtin_type && TREE_CODE (builtin_type) != VOID_TYPE)
    4956              :         {
    4957              :           /* For a call to a built-in function declared without a prototype,
    4958              :              perform the conversions from the argument to the expected type
    4959              :              but issue warnings rather than errors for any mismatches.
    4960              :              Ignore the converted argument and use the PARMVAL obtained
    4961              :              above by applying default conversions instead.  */
    4962         1919 :           tree origtype = (!origtypes) ? NULL_TREE : (*origtypes)[parmnum];
    4963         1919 :           convert_argument (ploc, function, fundecl, builtin_type, origtype,
    4964              :                             val, valtype, npc, rname, parmnum, argnum,
    4965              :                             excess_precision,
    4966              :                             OPT_Wbuiltin_declaration_mismatch);
    4967              :         }
    4968              : 
    4969    126567644 :       if (typetail)
    4970    125626599 :         typetail = TREE_CHAIN (typetail);
    4971              : 
    4972    126567644 :       if (builtin_typetail)
    4973      1039256 :         builtin_typetail = TREE_CHAIN (builtin_typetail);
    4974              :     }
    4975              : 
    4976     88108525 :   gcc_assert (parmnum == vec_safe_length (values));
    4977              : 
    4978     99493081 :   if (typetail != NULL_TREE && TREE_VALUE (typetail) != void_type_node)
    4979              :     {
    4980              :       /* Not enough args.
    4981              :          Determine minimum number of arguments required.  */
    4982              :       int min_expected_num = 0;
    4983          231 :       bool at_least_p = false;
    4984              :       tree iter = typelist;
    4985          386 :       while (true)
    4986              :         {
    4987          231 :           if (!iter)
    4988              :             {
    4989              :               /* Variadic arguments; stop iterating.  */
    4990              :               at_least_p = true;
    4991              :               break;
    4992              :             }
    4993          222 :           if (iter == void_list_node)
    4994              :             /* End of arguments; stop iterating.  */
    4995              :             break;
    4996          155 :           ++min_expected_num;
    4997          155 :           iter = TREE_CHAIN (iter);
    4998              :         }
    4999           76 :       auto_diagnostic_group d;
    5000           76 :       int actual_num = vec_safe_length (values);
    5001          143 :       error_at (loc,
    5002              :                 at_least_p
    5003              :                 ? G_("too few arguments to function %qE; expected at least %i, have %i")
    5004              :                 : G_("too few arguments to function %qE; expected %i, have %i"),
    5005              :                 function, min_expected_num, actual_num);
    5006           76 :       inform_declaration (fundecl, function);
    5007           76 :       return -1;
    5008           76 :     }
    5009              : 
    5010     50569165 :   if (builtin_typetail && TREE_VALUE (builtin_typetail) != void_type_node)
    5011              :     {
    5012              :       unsigned nargs = parmnum;
    5013          616 :       for (tree t = builtin_typetail; t; t = TREE_CHAIN (t))
    5014          428 :         ++nargs;
    5015              : 
    5016          188 :       auto_diagnostic_group d;
    5017          188 :       if (warning_at (loc, OPT_Wbuiltin_declaration_mismatch,
    5018              :                       "too few arguments to built-in function %qE "
    5019              :                       "expecting %u", function, nargs - 1))
    5020          173 :         inform_declaration (fundecl, function);
    5021          188 :     }
    5022              : 
    5023     49913105 :   return error_args ? -1 : (int) parmnum;
    5024              : }
    5025              : 
    5026              : /* This is the entry point used by the parser to build unary operators
    5027              :    in the input.  CODE, a tree_code, specifies the unary operator, and
    5028              :    ARG is the operand.  For unary plus, the C parser currently uses
    5029              :    CONVERT_EXPR for code.
    5030              : 
    5031              :    LOC is the location to use for the tree generated.
    5032              : */
    5033              : 
    5034              : struct c_expr
    5035      8171542 : parser_build_unary_op (location_t loc, enum tree_code code, struct c_expr arg)
    5036              : {
    5037      8171542 :   struct c_expr result;
    5038              : 
    5039      8171542 :   result.original_code = code;
    5040      8171542 :   result.original_type = NULL;
    5041      8171542 :   result.m_decimal = 0;
    5042              : 
    5043      8171542 :   if (reject_gcc_builtin (arg.value))
    5044              :     {
    5045            2 :       result.value = error_mark_node;
    5046              :     }
    5047              :   else
    5048              :     {
    5049      8171540 :       result.value = build_unary_op (loc, code, arg.value, false);
    5050              : 
    5051      8171540 :       if (TREE_OVERFLOW_P (result.value) && !TREE_OVERFLOW_P (arg.value))
    5052            5 :         overflow_warning (loc, result.value, arg.value);
    5053              :     }
    5054              : 
    5055              :   /* We are typically called when parsing a prefix token at LOC acting on
    5056              :      ARG.  Reflect this by updating the source range of the result to
    5057              :      start at LOC and end at the end of ARG.  */
    5058      8171542 :   set_c_expr_source_range (&result,
    5059              :                            loc, arg.get_finish ());
    5060              : 
    5061      8171542 :   return result;
    5062              : }
    5063              : 
    5064              : /* Returns true if TYPE is a character type, *not* including wchar_t.  */
    5065              : 
    5066              : bool
    5067      1272217 : char_type_p (tree type)
    5068              : {
    5069      1272217 :   return (type == char_type_node
    5070       980644 :           || type == unsigned_char_type_node
    5071       961581 :           || type == signed_char_type_node
    5072       960733 :           || type == char16_type_node
    5073      2012013 :           || type == char32_type_node);
    5074              : }
    5075              : 
    5076              : /* This is the entry point used by the parser to build binary operators
    5077              :    in the input.  CODE, a tree_code, specifies the binary operator, and
    5078              :    ARG1 and ARG2 are the operands.  In addition to constructing the
    5079              :    expression, we check for operands that were written with other binary
    5080              :    operators in a way that is likely to confuse the user.  ORIG_ARG1 is
    5081              :    the original first operand for TRUTH_{AND,OR}IF_EXPR before it is
    5082              :    converted to truth value, otherwise NULL_TREE.
    5083              : 
    5084              :    LOCATION is the location of the binary operator.  */
    5085              : 
    5086              : struct c_expr
    5087      9342485 : parser_build_binary_op (location_t location, enum tree_code code,
    5088              :                         struct c_expr arg1, struct c_expr arg2, tree orig_arg1)
    5089              : {
    5090      9342485 :   struct c_expr result;
    5091      9342485 :   result.m_decimal = 0;
    5092              : 
    5093      9342485 :   enum tree_code code1 = arg1.original_code;
    5094      9342485 :   enum tree_code code2 = arg2.original_code;
    5095      9342485 :   tree type1 = (arg1.original_type
    5096      9342485 :                 ? arg1.original_type
    5097      5997652 :                 : TREE_TYPE (arg1.value));
    5098      9342485 :   tree type2 = (arg2.original_type
    5099      9342485 :                 ? arg2.original_type
    5100      6895105 :                 : TREE_TYPE (arg2.value));
    5101              : 
    5102      9342485 :   result.value = build_binary_op (location, code,
    5103              :                                   arg1.value, arg2.value, true);
    5104      9342484 :   result.original_code = code;
    5105      9342484 :   result.original_type = NULL;
    5106      9342484 :   result.m_decimal = 0;
    5107              : 
    5108      9342484 :   if (TREE_CODE (result.value) == ERROR_MARK)
    5109              :     {
    5110         1297 :       set_c_expr_source_range (&result,
    5111              :                                arg1.get_start (),
    5112              :                                arg2.get_finish ());
    5113         1297 :       return result;
    5114              :     }
    5115              : 
    5116      9341187 :   if (location != UNKNOWN_LOCATION)
    5117      9341187 :     protected_set_expr_location (result.value, location);
    5118              : 
    5119      9341187 :   set_c_expr_source_range (&result,
    5120              :                            arg1.get_start (),
    5121              :                            arg2.get_finish ());
    5122              : 
    5123              :   /* Check for cases such as x+y<<z which users are likely
    5124              :      to misinterpret.  */
    5125      9341187 :   if (warn_parentheses)
    5126      2010625 :     warn_about_parentheses (location, code, code1, arg1.value, code2,
    5127              :                             arg2.value);
    5128              : 
    5129      9341187 :   if (warn_logical_op)
    5130          340 :     warn_logical_operator (location, code, TREE_TYPE (result.value),
    5131              :                            code1, arg1.value, code2, arg2.value);
    5132              : 
    5133      9341187 :   if (warn_constant_logical_operand
    5134      2009040 :       && (code == TRUTH_ANDIF_EXPR || code == TRUTH_ORIF_EXPR)
    5135        74366 :       && INTEGRAL_NB_TYPE_P (type1)
    5136        72581 :       && INTEGRAL_NB_TYPE_P (type2))
    5137              :     {
    5138        71008 :       const char *name = code == TRUTH_ANDIF_EXPR ? "&&" : "||";
    5139        71008 :       if (orig_arg1 == NULL_TREE)
    5140            0 :         orig_arg1 = arg1.value;
    5141        76405 :       auto enum_other_than_0_1 = [] (tree type) {
    5142         5397 :         if (TREE_CODE (type) != ENUMERAL_TYPE)
    5143              :           return false;
    5144           48 :         for (tree l = TYPE_VALUES (type); l; l = TREE_CHAIN (l))
    5145              :           {
    5146           40 :             tree v = DECL_INITIAL (TREE_VALUE (l));
    5147           40 :             if (!integer_zerop (v) && !integer_onep (v))
    5148              :               return true;
    5149              :           }
    5150              :         return false;
    5151              :       };
    5152       213008 :       auto diagnose_constant_logical_operand = [=] (tree val, tree type) {
    5153       142000 :         if (TREE_CODE (val) != INTEGER_CST || integer_zerop (val))
    5154       136579 :           return false;
    5155         5421 :         if (integer_onep (val) && !enum_other_than_0_1 (type))
    5156              :           return false;
    5157           32 :         gcc_rich_location richloc (location);
    5158           32 :         richloc.add_fixit_replace (name + 1);
    5159           32 :         auto_diagnostic_group d;
    5160           32 :         if (warning_at (location, OPT_Wconstant_logical_operand,
    5161              :                         "use of logical %qs with constant operand %qE",
    5162              :                         name, val))
    5163           32 :           inform (&richloc, "use %qs for bitwise operation", name + 1);
    5164           32 :         return true;
    5165           32 :       };
    5166        71008 :       if (!diagnose_constant_logical_operand (arg2.value, type2))
    5167        70992 :         diagnose_constant_logical_operand (orig_arg1, type1);
    5168              :     }
    5169              : 
    5170      9341187 :   if (warn_tautological_compare)
    5171              :     {
    5172      2009138 :       tree lhs = arg1.value;
    5173      2009138 :       tree rhs = arg2.value;
    5174      2009138 :       if (TREE_CODE (lhs) == C_MAYBE_CONST_EXPR)
    5175              :         {
    5176            2 :           if (C_MAYBE_CONST_EXPR_PRE (lhs) != NULL_TREE
    5177            2 :               && TREE_SIDE_EFFECTS (C_MAYBE_CONST_EXPR_PRE (lhs)))
    5178              :             lhs = NULL_TREE;
    5179              :           else
    5180            2 :             lhs = C_MAYBE_CONST_EXPR_EXPR (lhs);
    5181              :         }
    5182      2009138 :       if (TREE_CODE (rhs) == C_MAYBE_CONST_EXPR)
    5183              :         {
    5184           12 :           if (C_MAYBE_CONST_EXPR_PRE (rhs) != NULL_TREE
    5185           12 :               && TREE_SIDE_EFFECTS (C_MAYBE_CONST_EXPR_PRE (rhs)))
    5186              :             rhs = NULL_TREE;
    5187              :           else
    5188           12 :             rhs = C_MAYBE_CONST_EXPR_EXPR (rhs);
    5189              :         }
    5190      2009138 :       if (lhs != NULL_TREE && rhs != NULL_TREE)
    5191      2009138 :         warn_tautological_cmp (location, code, lhs, rhs);
    5192              :     }
    5193              : 
    5194      9341187 :   if (warn_logical_not_paren
    5195      2009221 :       && TREE_CODE_CLASS (code) == tcc_comparison
    5196       409683 :       && code1 == TRUTH_NOT_EXPR
    5197       409683 :       && code2 != TRUTH_NOT_EXPR
    5198              :       /* Avoid warning for !!x == y.  */
    5199      9341321 :       && (TREE_CODE (arg1.value) != NE_EXPR
    5200           27 :           || !integer_zerop (TREE_OPERAND (arg1.value, 1))))
    5201              :     {
    5202              :       /* Avoid warning for !b == y where b has _Bool type.  */
    5203          107 :       tree t = integer_zero_node;
    5204          107 :       if (TREE_CODE (arg1.value) == EQ_EXPR
    5205           98 :           && integer_zerop (TREE_OPERAND (arg1.value, 1))
    5206          205 :           && TREE_TYPE (TREE_OPERAND (arg1.value, 0)) == integer_type_node)
    5207              :         {
    5208           90 :           t = TREE_OPERAND (arg1.value, 0);
    5209          199 :           do
    5210              :             {
    5211          199 :               if (TREE_TYPE (t) != integer_type_node)
    5212              :                 break;
    5213          180 :               if (TREE_CODE (t) == C_MAYBE_CONST_EXPR)
    5214           90 :                 t = C_MAYBE_CONST_EXPR_EXPR (t);
    5215           90 :               else if (CONVERT_EXPR_P (t))
    5216           19 :                 t = TREE_OPERAND (t, 0);
    5217              :               else
    5218              :                 break;
    5219              :             }
    5220              :           while (1);
    5221              :         }
    5222          107 :       if (!C_BOOLEAN_TYPE_P (TREE_TYPE (t)))
    5223           88 :         warn_logical_not_parentheses (location, code, arg1.value, arg2.value);
    5224              :     }
    5225              : 
    5226              :   /* Warn about comparisons against string literals, with the exception
    5227              :      of testing for equality or inequality of a string literal with NULL.  */
    5228      9341187 :   if (code == EQ_EXPR || code == NE_EXPR)
    5229              :     {
    5230      1173022 :       if ((code1 == STRING_CST
    5231           16 :            && !integer_zerop (tree_strip_nop_conversions (arg2.value)))
    5232      1173033 :           || (code2 == STRING_CST
    5233           39 :               && !integer_zerop (tree_strip_nop_conversions (arg1.value))))
    5234           36 :         warning_at (location, OPT_Waddress,
    5235              :                     "comparison with string literal results in unspecified behavior");
    5236              :       /* Warn for ptr == '\0', it's likely that it should've been ptr[0].  */
    5237      1173022 :       if (POINTER_TYPE_P (type1)
    5238        90771 :           && null_pointer_constant_p (arg2.value)
    5239      1194216 :           && char_type_p (type2))
    5240              :         {
    5241           18 :           auto_diagnostic_group d;
    5242           18 :           if (warning_at (location, OPT_Wpointer_compare,
    5243              :                             "comparison between pointer and zero character "
    5244              :                             "constant"))
    5245           10 :             inform (arg1.get_start (),
    5246              :                       "did you mean to dereference the pointer?");
    5247           18 :         }
    5248      1173004 :       else if (POINTER_TYPE_P (type2)
    5249        88112 :                && null_pointer_constant_p (arg1.value)
    5250      1173274 :                && char_type_p (type1))
    5251              :         {
    5252           10 :           auto_diagnostic_group d;
    5253           10 :           if (warning_at (location, OPT_Wpointer_compare,
    5254              :                             "comparison between pointer and zero character "
    5255              :                             "constant"))
    5256           10 :             inform (arg2.get_start (),
    5257              :                       "did you mean to dereference the pointer?");
    5258           10 :         }
    5259              :     }
    5260      8168165 :   else if (TREE_CODE_CLASS (code) == tcc_comparison
    5261       998536 :            && (code1 == STRING_CST || code2 == STRING_CST))
    5262            0 :     warning_at (location, OPT_Waddress,
    5263              :                 "comparison with string literal results in unspecified "
    5264              :                 "behavior");
    5265              : 
    5266      9341187 :   if (warn_zero_as_null_pointer_constant
    5267           24 :       && c_inhibit_evaluation_warnings == 0
    5268           24 :       && TREE_CODE_CLASS (code) == tcc_comparison)
    5269              :     {
    5270           24 :       if ((TREE_CODE (type1) == POINTER_TYPE
    5271           17 :            || TREE_CODE (type1) == NULLPTR_TYPE)
    5272            9 :           && INTEGRAL_TYPE_P (type2)
    5273           33 :           && null_pointer_constant_p (arg2.value))
    5274            9 :         warning_at (arg2.get_location(), OPT_Wzero_as_null_pointer_constant,
    5275              :                     "zero as null pointer constant");
    5276              : 
    5277           24 :       if ((TREE_CODE (type2) == POINTER_TYPE
    5278           15 :            || TREE_CODE (type2) == NULLPTR_TYPE)
    5279           11 :           && INTEGRAL_TYPE_P (type1)
    5280           35 :           && null_pointer_constant_p (arg1.value))
    5281           11 :         warning_at (arg1.get_location(), OPT_Wzero_as_null_pointer_constant,
    5282              :                     "zero as null pointer constant");
    5283              :     }
    5284              : 
    5285      9341187 :   if (warn_array_compare
    5286      2008976 :       && TREE_CODE_CLASS (code) == tcc_comparison
    5287       409468 :       && TREE_CODE (type1) == ARRAY_TYPE
    5288           38 :       && TREE_CODE (type2) == ARRAY_TYPE)
    5289           15 :     do_warn_array_compare (location, code, arg1.value, arg2.value);
    5290              : 
    5291      2186348 :   if (TREE_OVERFLOW_P (result.value)
    5292          299 :       && !TREE_OVERFLOW_P (arg1.value)
    5293      9341479 :       && !TREE_OVERFLOW_P (arg2.value))
    5294          249 :     overflow_warning (location, result.value);
    5295              : 
    5296              :   /* Warn about comparisons of different enum types.  */
    5297      9341186 :   if (warn_enum_compare
    5298      2029028 :       && TREE_CODE_CLASS (code) == tcc_comparison
    5299       413939 :       && TREE_CODE (type1) == ENUMERAL_TYPE
    5300         7193 :       && TREE_CODE (type2) == ENUMERAL_TYPE
    5301      9348315 :       && TYPE_MAIN_VARIANT (type1) != TYPE_MAIN_VARIANT (type2))
    5302            2 :     warning_at (location, OPT_Wenum_compare,
    5303              :                 "comparison between %qT and %qT",
    5304              :                 type1, type2);
    5305              : 
    5306      9341186 :   if (warn_xor_used_as_pow
    5307      9341186 :       && code == BIT_XOR_EXPR
    5308        77167 :       && arg1.m_decimal
    5309          730 :       && arg2.m_decimal)
    5310          427 :     check_for_xor_used_as_pow (arg1.get_location (), arg1.value,
    5311              :                                location,
    5312              :                                arg2.get_location (), arg2.value);
    5313              : 
    5314              :   return result;
    5315              : }
    5316              : 
    5317              : /* Return a tree for the difference of pointers OP0 and OP1.
    5318              :    The resulting tree has type ptrdiff_t.  If POINTER_SUBTRACT sanitization is
    5319              :    enabled, assign to INSTRUMENT_EXPR call to libsanitizer.  */
    5320              : 
    5321              : static tree
    5322         3725 : pointer_diff (location_t loc, tree op0, tree op1, tree *instrument_expr)
    5323              : {
    5324         3725 :   tree restype = ptrdiff_type_node;
    5325         3725 :   tree result, inttype;
    5326              : 
    5327         3725 :   addr_space_t as0 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (op0)));
    5328         3725 :   addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (op1)));
    5329         3725 :   tree target_type = TREE_TYPE (TREE_TYPE (op0));
    5330         3725 :   tree orig_op0 = op0;
    5331         3725 :   tree orig_op1 = op1;
    5332              : 
    5333              :   /* If the operands point into different address spaces, we need to
    5334              :      explicitly convert them to pointers into the common address space
    5335              :      before we can subtract the numerical address values.  */
    5336         3725 :   if (as0 != as1)
    5337              :     {
    5338            0 :       addr_space_t as_common;
    5339            0 :       tree common_type;
    5340              : 
    5341              :       /* Determine the common superset address space.  This is guaranteed
    5342              :          to exist because the caller verified that comp_target_types
    5343              :          returned non-zero.  */
    5344            0 :       if (!addr_space_superset (as0, as1, &as_common))
    5345            0 :         gcc_unreachable ();
    5346              : 
    5347            0 :       common_type = common_pointer_type (TREE_TYPE (op0), TREE_TYPE (op1), NULL_TREE);
    5348            0 :       op0 = convert (common_type, op0);
    5349            0 :       op1 = convert (common_type, op1);
    5350              :     }
    5351              : 
    5352              :   /* Determine integer type result of the subtraction.  This will usually
    5353              :      be the same as the result type (ptrdiff_t), but may need to be a wider
    5354              :      type if pointers for the address space are wider than ptrdiff_t.  */
    5355         3725 :   if (TYPE_PRECISION (restype) < TYPE_PRECISION (TREE_TYPE (op0)))
    5356            0 :     inttype = c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op0)), 0);
    5357              :   else
    5358              :     inttype = restype;
    5359              : 
    5360         3725 :   if (VOID_TYPE_P (target_type))
    5361          146 :     pedwarn (loc, OPT_Wpointer_arith,
    5362              :              "pointer of type %<void *%> used in subtraction");
    5363         3725 :   if (TREE_CODE (target_type) == FUNCTION_TYPE)
    5364            4 :     pedwarn (loc, OPT_Wpointer_arith,
    5365              :              "pointer to a function used in subtraction");
    5366              : 
    5367         3725 :   if (current_function_decl != NULL_TREE
    5368         3725 :       && sanitize_flags_p (SANITIZE_POINTER_SUBTRACT))
    5369              :     {
    5370           70 :       op0 = save_expr (c_fully_fold (op0, false, NULL));
    5371           70 :       op1 = save_expr (c_fully_fold (op1, false, NULL));
    5372              : 
    5373           70 :       tree tt = builtin_decl_explicit (BUILT_IN_ASAN_POINTER_SUBTRACT);
    5374           70 :       *instrument_expr = build_call_expr_loc (loc, tt, 2, op0, op1);
    5375              :     }
    5376              : 
    5377              :   /* First do the subtraction, then build the divide operator
    5378              :      and only convert at the very end.
    5379              :      Do not do default conversions in case restype is a short type.  */
    5380              : 
    5381              :   /* POINTER_DIFF_EXPR requires a signed integer type of the same size as
    5382              :      pointers.  If some platform cannot provide that, or has a larger
    5383              :      ptrdiff_type to support differences larger than half the address
    5384              :      space, cast the pointers to some larger integer type and do the
    5385              :      computations in that type.  */
    5386         3725 :   if (TYPE_PRECISION (inttype) > TYPE_PRECISION (TREE_TYPE (op0)))
    5387            0 :     op0 = build_binary_op (loc, MINUS_EXPR, convert (inttype, op0),
    5388              :                            convert (inttype, op1), false);
    5389              :   else
    5390              :     {
    5391              :       /* Cast away qualifiers.  */
    5392         3725 :       op0 = convert (c_common_type (TREE_TYPE (op0), TREE_TYPE (op0)), op0);
    5393         3725 :       op1 = convert (c_common_type (TREE_TYPE (op1), TREE_TYPE (op1)), op1);
    5394         3725 :       op0 = build2_loc (loc, POINTER_DIFF_EXPR, inttype, op0, op1);
    5395              :     }
    5396              : 
    5397              :   /* This generates an error if op1 is pointer to incomplete type.  */
    5398         3725 :   if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (orig_op1))))
    5399            4 :     error_at (loc, "arithmetic on pointer to an incomplete type");
    5400         3721 :   else if (verify_type_context (loc, TCTX_POINTER_ARITH,
    5401         3721 :                                 TREE_TYPE (TREE_TYPE (orig_op0))))
    5402         7442 :     verify_type_context (loc, TCTX_POINTER_ARITH,
    5403         3721 :                          TREE_TYPE (TREE_TYPE (orig_op1)));
    5404              : 
    5405         3725 :   op1 = c_size_in_bytes (target_type);
    5406              : 
    5407         3725 :   if (pointer_to_zero_sized_aggr_p (TREE_TYPE (orig_op1)))
    5408            4 :     error_at (loc, "arithmetic on pointer to an empty aggregate");
    5409              : 
    5410              :   /* Divide by the size, in easiest possible way.  */
    5411         3725 :   result = fold_build2_loc (loc, EXACT_DIV_EXPR, inttype,
    5412              :                             op0, convert (inttype, op1));
    5413              : 
    5414              :   /* Convert to final result type if necessary.  */
    5415         3725 :   return convert (restype, result);
    5416              : }
    5417              : 
    5418              : /* Expand atomic compound assignments into an appropriate sequence as
    5419              :    specified by the C11 standard section 6.5.16.2.
    5420              : 
    5421              :        _Atomic T1 E1
    5422              :        T2 E2
    5423              :        E1 op= E2
    5424              : 
    5425              :   This sequence is used for all types for which these operations are
    5426              :   supported.
    5427              : 
    5428              :   In addition, built-in versions of the 'fe' prefixed routines may
    5429              :   need to be invoked for floating point (real, complex or vector) when
    5430              :   floating-point exceptions are supported.  See 6.5.16.2 footnote 113.
    5431              : 
    5432              :   T1 newval;
    5433              :   T1 old;
    5434              :   T1 *addr
    5435              :   T2 val
    5436              :   fenv_t fenv
    5437              : 
    5438              :   addr = &E1;
    5439              :   val = (E2);
    5440              :   __atomic_load (addr, &old, SEQ_CST);
    5441              :   feholdexcept (&fenv);
    5442              : loop:
    5443              :     newval = old op val;
    5444              :     if (__atomic_compare_exchange_strong (addr, &old, &newval, SEQ_CST,
    5445              :                                           SEQ_CST))
    5446              :       goto done;
    5447              :     feclearexcept (FE_ALL_EXCEPT);
    5448              :     goto loop:
    5449              : done:
    5450              :   feupdateenv (&fenv);
    5451              : 
    5452              :   The compiler will issue the __atomic_fetch_* built-in when possible,
    5453              :   otherwise it will generate the generic form of the atomic operations.
    5454              :   This requires temp(s) and has their address taken.  The atomic processing
    5455              :   is smart enough to figure out when the size of an object can utilize
    5456              :   a lock-free version, and convert the built-in call to the appropriate
    5457              :   lock-free routine.  The optimizers will then dispose of any temps that
    5458              :   are no longer required, and lock-free implementations are utilized as
    5459              :   long as there is target support for the required size.
    5460              : 
    5461              :   If the operator is NOP_EXPR, then this is a simple assignment, and
    5462              :   an __atomic_store is issued to perform the assignment rather than
    5463              :   the above loop.  */
    5464              : 
    5465              : /* Build an atomic assignment at LOC, expanding into the proper
    5466              :    sequence to store LHS MODIFYCODE= RHS.  Return a value representing
    5467              :    the result of the operation, unless RETURN_OLD_P, in which case
    5468              :    return the old value of LHS (this is only for postincrement and
    5469              :    postdecrement).  */
    5470              : 
    5471              : static tree
    5472        30433 : build_atomic_assign (location_t loc, tree lhs, enum tree_code modifycode,
    5473              :                      tree rhs, bool return_old_p)
    5474              : {
    5475        30433 :   tree fndecl, func_call;
    5476        30433 :   vec<tree, va_gc> *params;
    5477        30433 :   tree val, nonatomic_lhs_type, nonatomic_rhs_type, newval, newval_addr;
    5478        30433 :   tree old, old_addr;
    5479        30433 :   tree compound_stmt = NULL_TREE;
    5480        30433 :   tree stmt, goto_stmt;
    5481        30433 :   tree loop_label, loop_decl, done_label, done_decl;
    5482              : 
    5483        30433 :   tree lhs_type = TREE_TYPE (lhs);
    5484        30433 :   tree lhs_addr = build_unary_op (loc, ADDR_EXPR, lhs, false);
    5485        30433 :   tree seq_cst = build_int_cst (integer_type_node, MEMMODEL_SEQ_CST);
    5486        30433 :   tree rhs_semantic_type = TREE_TYPE (rhs);
    5487        30433 :   tree nonatomic_rhs_semantic_type;
    5488        30433 :   tree rhs_type;
    5489              : 
    5490        30433 :   gcc_assert (TYPE_ATOMIC (lhs_type));
    5491              : 
    5492        30433 :   if (return_old_p)
    5493         2313 :     gcc_assert (modifycode == PLUS_EXPR || modifycode == MINUS_EXPR);
    5494              : 
    5495              :   /* Allocate enough vector items for a compare_exchange.  */
    5496        30433 :   vec_alloc (params, 6);
    5497              : 
    5498              :   /* Create a compound statement to hold the sequence of statements
    5499              :      with a loop.  */
    5500        30433 :   if (modifycode != NOP_EXPR)
    5501              :     {
    5502        19954 :       compound_stmt = c_begin_compound_stmt (false);
    5503              : 
    5504              :       /* For consistency with build_modify_expr on non-_Atomic,
    5505              :          mark the lhs as read.  Also, it would be very hard to match
    5506              :          such expressions in mark_exp_read.  */
    5507        19954 :       mark_exp_read (lhs);
    5508              :     }
    5509              : 
    5510              :   /* Remove any excess precision (which is only present here in the
    5511              :      case of compound assignments).  */
    5512        30433 :   if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
    5513              :     {
    5514            0 :       gcc_assert (modifycode != NOP_EXPR);
    5515            0 :       rhs = TREE_OPERAND (rhs, 0);
    5516              :     }
    5517        30433 :   rhs_type = TREE_TYPE (rhs);
    5518              : 
    5519              :   /* Fold the RHS if it hasn't already been folded.  */
    5520        30433 :   if (modifycode != NOP_EXPR)
    5521        19954 :     rhs = c_fully_fold (rhs, false, NULL);
    5522              : 
    5523              :   /* Remove the qualifiers for the rest of the expressions and create
    5524              :      the VAL temp variable to hold the RHS.  */
    5525        30433 :   nonatomic_lhs_type = build_qualified_type (lhs_type, TYPE_UNQUALIFIED);
    5526        30433 :   nonatomic_rhs_type = build_qualified_type (rhs_type, TYPE_UNQUALIFIED);
    5527        30433 :   nonatomic_rhs_semantic_type = build_qualified_type (rhs_semantic_type,
    5528              :                                                       TYPE_UNQUALIFIED);
    5529        30433 :   val = create_tmp_var_raw (nonatomic_rhs_type);
    5530        30433 :   TREE_ADDRESSABLE (val) = 1;
    5531        30433 :   suppress_warning (val);
    5532        30433 :   rhs = build4 (TARGET_EXPR, nonatomic_rhs_type, val, rhs, NULL_TREE,
    5533              :                 NULL_TREE);
    5534        30433 :   TREE_SIDE_EFFECTS (rhs) = 1;
    5535        30433 :   SET_EXPR_LOCATION (rhs, loc);
    5536        30433 :   if (modifycode != NOP_EXPR)
    5537        19954 :     add_stmt (rhs);
    5538              : 
    5539              :   /* NOP_EXPR indicates it's a straight store of the RHS. Simply issue
    5540              :      an atomic_store.  */
    5541        30433 :   if (modifycode == NOP_EXPR)
    5542              :     {
    5543        10479 :       compound_stmt = rhs;
    5544              :       /* Build __atomic_store (&lhs, &val, SEQ_CST)  */
    5545        10479 :       rhs = build_unary_op (loc, ADDR_EXPR, val, false);
    5546        10479 :       fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_STORE);
    5547        10479 :       params->quick_push (lhs_addr);
    5548        10479 :       params->quick_push (rhs);
    5549        10479 :       params->quick_push (seq_cst);
    5550        10479 :       func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
    5551              : 
    5552        10479 :       compound_stmt = build2 (COMPOUND_EXPR, void_type_node,
    5553              :                               compound_stmt, func_call);
    5554              : 
    5555              :       /* VAL is the value which was stored, return a COMPOUND_STMT of
    5556              :          the statement and that value.  */
    5557        10479 :       return build2 (COMPOUND_EXPR, nonatomic_lhs_type, compound_stmt, val);
    5558              :     }
    5559              : 
    5560              :   /* Attempt to implement the atomic operation as an __atomic_fetch_* or
    5561              :      __atomic_*_fetch built-in rather than a CAS loop.  atomic_bool type
    5562              :      isn't applicable for such builtins.  ??? Do we want to handle enums?  */
    5563        19954 :   if ((TREE_CODE (lhs_type) == INTEGER_TYPE || POINTER_TYPE_P (lhs_type))
    5564        13941 :       && TREE_CODE (rhs_type) == INTEGER_TYPE)
    5565              :     {
    5566        11713 :       built_in_function fncode;
    5567        11713 :       switch (modifycode)
    5568              :         {
    5569         3075 :         case PLUS_EXPR:
    5570         3075 :         case POINTER_PLUS_EXPR:
    5571         2124 :           fncode = (return_old_p
    5572         3075 :                     ? BUILT_IN_ATOMIC_FETCH_ADD_N
    5573              :                     : BUILT_IN_ATOMIC_ADD_FETCH_N);
    5574              :           break;
    5575         2889 :         case MINUS_EXPR:
    5576         2094 :           fncode = (return_old_p
    5577         2889 :                     ? BUILT_IN_ATOMIC_FETCH_SUB_N
    5578              :                     : BUILT_IN_ATOMIC_SUB_FETCH_N);
    5579              :           break;
    5580          609 :         case BIT_AND_EXPR:
    5581          609 :           fncode = (return_old_p
    5582          609 :                     ? BUILT_IN_ATOMIC_FETCH_AND_N
    5583              :                     : BUILT_IN_ATOMIC_AND_FETCH_N);
    5584              :           break;
    5585          609 :         case BIT_IOR_EXPR:
    5586          609 :           fncode = (return_old_p
    5587          609 :                     ? BUILT_IN_ATOMIC_FETCH_OR_N
    5588              :                     : BUILT_IN_ATOMIC_OR_FETCH_N);
    5589              :           break;
    5590          609 :         case BIT_XOR_EXPR:
    5591          609 :           fncode = (return_old_p
    5592          609 :                     ? BUILT_IN_ATOMIC_FETCH_XOR_N
    5593              :                     : BUILT_IN_ATOMIC_XOR_FETCH_N);
    5594              :           break;
    5595         3922 :         default:
    5596         3922 :           goto cas_loop;
    5597              :         }
    5598              : 
    5599              :       /* We can only use "_1" through "_16" variants of the atomic fetch
    5600              :          built-ins.  */
    5601         7791 :       unsigned HOST_WIDE_INT size = tree_to_uhwi (TYPE_SIZE_UNIT (lhs_type));
    5602         7791 :       if (size != 1 && size != 2 && size != 4 && size != 8 && size != 16)
    5603            0 :         goto cas_loop;
    5604              : 
    5605              :       /* If this is a pointer type, we need to multiply by the size of
    5606              :          the pointer target type.  */
    5607         7791 :       if (POINTER_TYPE_P (lhs_type))
    5608              :         {
    5609         1018 :           if (!COMPLETE_TYPE_P (TREE_TYPE (lhs_type))
    5610              :               /* ??? This would introduce -Wdiscarded-qualifiers
    5611              :                  warning: __atomic_fetch_* expect volatile void *
    5612              :                  type as the first argument.  (Assignments between
    5613              :                  atomic and non-atomic objects are OK.) */
    5614         1018 :               || TYPE_RESTRICT (lhs_type))
    5615           17 :             goto cas_loop;
    5616         1001 :           tree sz = TYPE_SIZE_UNIT (TREE_TYPE (lhs_type));
    5617         1001 :           rhs = fold_build2_loc (loc, MULT_EXPR, ptrdiff_type_node,
    5618              :                                  convert (ptrdiff_type_node, rhs),
    5619              :                                  convert (ptrdiff_type_node, sz));
    5620              :         }
    5621              : 
    5622              :       /* Build __atomic_fetch_* (&lhs, &val, SEQ_CST), or
    5623              :          __atomic_*_fetch (&lhs, &val, SEQ_CST).  */
    5624         7774 :       fndecl = builtin_decl_explicit (fncode);
    5625         7774 :       params->quick_push (lhs_addr);
    5626         7774 :       params->quick_push (rhs);
    5627         7774 :       params->quick_push (seq_cst);
    5628         7774 :       func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
    5629              : 
    5630         7774 :       newval = create_tmp_var_raw (nonatomic_lhs_type);
    5631         7774 :       TREE_ADDRESSABLE (newval) = 1;
    5632         7774 :       suppress_warning (newval);
    5633         7774 :       rhs = build4 (TARGET_EXPR, nonatomic_lhs_type, newval, func_call,
    5634              :                     NULL_TREE, NULL_TREE);
    5635         7774 :       SET_EXPR_LOCATION (rhs, loc);
    5636         7774 :       add_stmt (rhs);
    5637              : 
    5638              :       /* Finish the compound statement.  */
    5639         7774 :       compound_stmt = c_end_compound_stmt (loc, compound_stmt, false);
    5640              : 
    5641              :       /* NEWVAL is the value which was stored, return a COMPOUND_STMT of
    5642              :          the statement and that value.  */
    5643         7774 :       return build2 (COMPOUND_EXPR, nonatomic_lhs_type, compound_stmt, newval);
    5644              :     }
    5645              : 
    5646         8241 : cas_loop:
    5647              :   /* Create the variables and labels required for the op= form.  */
    5648        12180 :   old = create_tmp_var_raw (nonatomic_lhs_type);
    5649        12180 :   old_addr = build_unary_op (loc, ADDR_EXPR, old, false);
    5650        12180 :   TREE_ADDRESSABLE (old) = 1;
    5651        12180 :   suppress_warning (old);
    5652              : 
    5653        12180 :   newval = create_tmp_var_raw (nonatomic_lhs_type);
    5654        12180 :   newval_addr = build_unary_op (loc, ADDR_EXPR, newval, false);
    5655        12180 :   TREE_ADDRESSABLE (newval) = 1;
    5656        12180 :   suppress_warning (newval);
    5657              : 
    5658        12180 :   loop_decl = create_artificial_label (loc);
    5659        12180 :   loop_label = build1 (LABEL_EXPR, void_type_node, loop_decl);
    5660              : 
    5661        12180 :   done_decl = create_artificial_label (loc);
    5662        12180 :   done_label = build1 (LABEL_EXPR, void_type_node, done_decl);
    5663              : 
    5664              :   /* __atomic_load (addr, &old, SEQ_CST).  */
    5665        12180 :   fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_LOAD);
    5666        12180 :   params->quick_push (lhs_addr);
    5667        12180 :   params->quick_push (old_addr);
    5668        12180 :   params->quick_push (seq_cst);
    5669        12180 :   func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
    5670        12180 :   old = build4 (TARGET_EXPR, nonatomic_lhs_type, old, func_call, NULL_TREE,
    5671              :                 NULL_TREE);
    5672        12180 :   add_stmt (old);
    5673        12180 :   params->truncate (0);
    5674              : 
    5675              :   /* Create the expressions for floating-point environment
    5676              :      manipulation, if required.  */
    5677        12180 :   bool need_fenv = (flag_trapping_math
    5678        12180 :                     && (FLOAT_TYPE_P (lhs_type) || FLOAT_TYPE_P (rhs_type)));
    5679        12180 :   tree hold_call = NULL_TREE, clear_call = NULL_TREE, update_call = NULL_TREE;
    5680        12180 :   if (need_fenv)
    5681         7054 :     targetm.atomic_assign_expand_fenv (&hold_call, &clear_call, &update_call);
    5682              : 
    5683        12180 :   if (hold_call)
    5684         7054 :     add_stmt (hold_call);
    5685              : 
    5686              :   /* loop:  */
    5687        12180 :   add_stmt (loop_label);
    5688              : 
    5689              :   /* newval = old + val;  */
    5690        12180 :   if (rhs_type != rhs_semantic_type)
    5691            0 :     val = build1 (EXCESS_PRECISION_EXPR, nonatomic_rhs_semantic_type, val);
    5692        12180 :   rhs = build_binary_op (loc, modifycode,
    5693              :                          convert_lvalue_to_rvalue (loc, old, true, true),
    5694              :                          val, true);
    5695        12180 :   if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
    5696              :     {
    5697            0 :       tree eptype = TREE_TYPE (rhs);
    5698            0 :       rhs = c_fully_fold (TREE_OPERAND (rhs, 0), false, NULL);
    5699            0 :       rhs = build1 (EXCESS_PRECISION_EXPR, eptype, rhs);
    5700              :     }
    5701              :   else
    5702        12180 :     rhs = c_fully_fold (rhs, false, NULL);
    5703        12180 :   rhs = convert_for_assignment (loc, UNKNOWN_LOCATION, nonatomic_lhs_type,
    5704              :                                 rhs, NULL_TREE, ic_assign, false, NULL_TREE,
    5705              :                                 NULL_TREE, 0);
    5706              :   /* The temporary variable for NEWVAL is only gimplified correctly (in
    5707              :      particular, given a DECL_CONTEXT) if used in a TARGET_EXPR.  To avoid
    5708              :      subsequent ICEs in nested function processing after an error, ensure such
    5709              :      a TARGET_EXPR is built even after an error.  */
    5710        12180 :   if (rhs == error_mark_node)
    5711           10 :     rhs = old;
    5712        12180 :   rhs = build4 (TARGET_EXPR, nonatomic_lhs_type, newval, rhs, NULL_TREE,
    5713              :                 NULL_TREE);
    5714        12180 :   SET_EXPR_LOCATION (rhs, loc);
    5715        12180 :   add_stmt (rhs);
    5716              : 
    5717              :   /* if (__atomic_compare_exchange (addr, &old, &new, false, SEQ_CST, SEQ_CST))
    5718              :        goto done;  */
    5719        12180 :   fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_COMPARE_EXCHANGE);
    5720        12180 :   params->quick_push (lhs_addr);
    5721        12180 :   params->quick_push (old_addr);
    5722        12180 :   params->quick_push (newval_addr);
    5723        12180 :   params->quick_push (integer_zero_node);
    5724        12180 :   params->quick_push (seq_cst);
    5725        12180 :   params->quick_push (seq_cst);
    5726        12180 :   func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
    5727              : 
    5728        12180 :   goto_stmt = build1 (GOTO_EXPR, void_type_node, done_decl);
    5729        12180 :   SET_EXPR_LOCATION (goto_stmt, loc);
    5730              : 
    5731        12180 :   stmt = build3 (COND_EXPR, void_type_node, func_call, goto_stmt, NULL_TREE);
    5732        12180 :   SET_EXPR_LOCATION (stmt, loc);
    5733        12180 :   add_stmt (stmt);
    5734              : 
    5735        12180 :   if (clear_call)
    5736         7054 :     add_stmt (clear_call);
    5737              : 
    5738              :   /* goto loop;  */
    5739        12180 :   goto_stmt  = build1 (GOTO_EXPR, void_type_node, loop_decl);
    5740        12180 :   SET_EXPR_LOCATION (goto_stmt, loc);
    5741        12180 :   add_stmt (goto_stmt);
    5742              : 
    5743              :   /* done:  */
    5744        12180 :   add_stmt (done_label);
    5745              : 
    5746        12180 :   if (update_call)
    5747         7054 :     add_stmt (update_call);
    5748              : 
    5749              :   /* Finish the compound statement.  */
    5750        12180 :   compound_stmt = c_end_compound_stmt (loc, compound_stmt, false);
    5751              : 
    5752              :   /* NEWVAL is the value that was successfully stored, return a
    5753              :      COMPOUND_EXPR of the statement and the appropriate value.  */
    5754        23787 :   return build2 (COMPOUND_EXPR, nonatomic_lhs_type, compound_stmt,
    5755        12180 :                  return_old_p ? old : newval);
    5756              : }
    5757              : 
    5758              : /* Construct and perhaps optimize a tree representation
    5759              :    for a unary operation.  CODE, a tree_code, specifies the operation
    5760              :    and XARG is the operand.
    5761              :    For any CODE other than ADDR_EXPR, NOCONVERT suppresses the default
    5762              :    promotions (such as from short to int).
    5763              :    For ADDR_EXPR, the default promotions are not applied; NOCONVERT allows
    5764              :    non-lvalues; this is only used to handle conversion of non-lvalue arrays
    5765              :    to pointers in C99.
    5766              : 
    5767              :    LOCATION is the location of the operator.  */
    5768              : 
    5769              : tree
    5770     60551563 : build_unary_op (location_t location, enum tree_code code, tree xarg,
    5771              :                 bool noconvert)
    5772              : {
    5773              :   /* No default_conversion here.  It causes trouble for ADDR_EXPR.  */
    5774     60551563 :   tree arg = xarg;
    5775     60551563 :   tree argtype = NULL_TREE;
    5776     60551563 :   enum tree_code typecode;
    5777     60551563 :   tree val;
    5778     60551563 :   tree ret = error_mark_node;
    5779     60551563 :   tree eptype = NULL_TREE;
    5780     60551563 :   const char *invalid_op_diag;
    5781              : 
    5782              :   /* If ARG is wrapped in a call to .ACCESS_WITH_SIZE — created when the
    5783              :      C parser rvalue-converts a counted_by-annotated member access (see
    5784              :      PR123569) — unwrap it here.  Unary operators that consume an rvalue
    5785              :      (!, -, +) read the value itself rather than dereferencing into the
    5786              :      pointed-to data, so the bounds-checking wrapper is unnecessary and
    5787              :      would otherwise reach build_unary_op while it is not equipped to
    5788              :      handle the wrapped form.  PR123569 fixed the ++/-- side of this by
    5789              :      suppressing wrapper creation in the parser; the rvalue-consuming
    5790              :      ops still receive the wrapper and need to strip it here.  */
    5791     60551563 :   if (is_access_with_size_p (arg))
    5792            1 :     xarg = arg = get_ref_from_access_with_size (arg);
    5793              : 
    5794     60551563 :   gcc_checking_assert (!is_access_with_size_p (arg));
    5795              : 
    5796     60551563 :   bool int_operands = EXPR_INT_CONST_OPERANDS (xarg);
    5797      6464479 :   if (int_operands)
    5798      6464479 :     arg = remove_c_maybe_const_expr (arg);
    5799              : 
    5800     60551563 :   if (code != ADDR_EXPR)
    5801      8542953 :     arg = require_complete_type (location, arg);
    5802              : 
    5803     60551563 :   typecode = TREE_CODE (TREE_TYPE (arg));
    5804     60551563 :   if (typecode == ERROR_MARK)
    5805           74 :     return error_mark_node;
    5806     60551489 :   if (typecode == ENUMERAL_TYPE || typecode == BOOLEAN_TYPE)
    5807        32272 :     typecode = INTEGER_TYPE;
    5808              : 
    5809    121102978 :   if ((invalid_op_diag
    5810     60551489 :        = targetm.invalid_unary_op (code, TREE_TYPE (xarg))))
    5811              :     {
    5812            0 :       error_at (location, invalid_op_diag);
    5813            0 :       return error_mark_node;
    5814              :     }
    5815              : 
    5816     60551489 :   if (TREE_CODE (arg) == EXCESS_PRECISION_EXPR)
    5817              :     {
    5818          245 :       eptype = TREE_TYPE (arg);
    5819          245 :       arg = TREE_OPERAND (arg, 0);
    5820              :     }
    5821              : 
    5822     60551489 :   switch (code)
    5823              :     {
    5824        28760 :     case CONVERT_EXPR:
    5825              :       /* This is used for unary plus, because a CONVERT_EXPR
    5826              :          is enough to prevent anybody from looking inside for
    5827              :          associativity, but won't generate any code.  */
    5828        28765 :       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
    5829           13 :             || typecode == FIXED_POINT_TYPE || typecode == COMPLEX_TYPE
    5830           10 :             || typecode == BITINT_TYPE
    5831            5 :             || gnu_vector_type_p (TREE_TYPE (arg))))
    5832              :         {
    5833            1 :           error_at (location, "wrong type argument to unary plus");
    5834            1 :           return error_mark_node;
    5835              :         }
    5836        28759 :       else if (!noconvert)
    5837        28759 :         arg = default_conversion (arg);
    5838        28759 :       arg = non_lvalue_loc (location, arg);
    5839        28759 :       break;
    5840              : 
    5841      6700701 :     case NEGATE_EXPR:
    5842      7148105 :       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
    5843       484076 :             || typecode == FIXED_POINT_TYPE || typecode == COMPLEX_TYPE
    5844       452809 :             || typecode == BITINT_TYPE
    5845       447404 :             || gnu_vector_type_p (TREE_TYPE (arg))))
    5846              :         {
    5847            1 :           error_at (location, "wrong type argument to unary minus");
    5848            1 :           return error_mark_node;
    5849              :         }
    5850      6700700 :       else if (!noconvert)
    5851      6700694 :         arg = default_conversion (arg);
    5852              :       break;
    5853              : 
    5854       295376 :     case BIT_NOT_EXPR:
    5855              :       /* ~ works on integer types and non float vectors. */
    5856       295376 :       if (typecode == INTEGER_TYPE
    5857       295376 :           || typecode == BITINT_TYPE
    5858       295376 :           || (gnu_vector_type_p (TREE_TYPE (arg))
    5859         2059 :               && !VECTOR_FLOAT_TYPE_P (TREE_TYPE (arg))))
    5860              :         {
    5861              :           tree e = arg;
    5862              : 
    5863              :           /* Warn if the expression has boolean value.  */
    5864       294777 :           while (TREE_CODE (e) == COMPOUND_EXPR)
    5865           11 :             e = TREE_OPERAND (e, 1);
    5866              : 
    5867       589516 :           if ((C_BOOLEAN_TYPE_P (TREE_TYPE (arg))
    5868       589516 :                || truth_value_p (TREE_CODE (e))))
    5869              :             {
    5870          148 :               auto_diagnostic_group d;
    5871          148 :               if (warning_at (location, OPT_Wbool_operation,
    5872              :                                 "%<~%> on a boolean expression"))
    5873              :                 {
    5874           12 :                   gcc_rich_location richloc (location);
    5875           12 :                   richloc.add_fixit_insert_before (location, "!");
    5876           12 :                   inform (&richloc, "did you mean to use logical not?");
    5877           12 :                 }
    5878          148 :             }
    5879       294766 :           if (!noconvert)
    5880       294763 :             arg = default_conversion (arg);
    5881              :         }
    5882          610 :       else if (typecode == COMPLEX_TYPE)
    5883              :         {
    5884          605 :           code = CONJ_EXPR;
    5885          605 :           pedwarn (location, OPT_Wpedantic,
    5886              :                    "ISO C does not support %<~%> for complex conjugation");
    5887          605 :           if (!noconvert)
    5888          605 :             arg = default_conversion (arg);
    5889              :         }
    5890              :       else
    5891              :         {
    5892            5 :           error_at (location, "wrong type argument to bit-complement");
    5893            5 :           return error_mark_node;
    5894              :         }
    5895              :       break;
    5896              : 
    5897            3 :     case ABS_EXPR:
    5898            3 :       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE))
    5899              :         {
    5900            0 :           error_at (location, "wrong type argument to abs");
    5901            0 :           return error_mark_node;
    5902              :         }
    5903            3 :       else if (!noconvert)
    5904            0 :         arg = default_conversion (arg);
    5905              :       break;
    5906              : 
    5907            7 :     case ABSU_EXPR:
    5908            7 :       if (!(typecode == INTEGER_TYPE))
    5909              :         {
    5910            0 :           error_at (location, "wrong type argument to absu");
    5911            0 :           return error_mark_node;
    5912              :         }
    5913            7 :       else if (!noconvert)
    5914            0 :         arg = default_conversion (arg);
    5915              :       break;
    5916              : 
    5917            0 :     case CONJ_EXPR:
    5918              :       /* Conjugating a real value is a no-op, but allow it anyway.  */
    5919            0 :       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
    5920              :             || typecode == COMPLEX_TYPE))
    5921              :         {
    5922            0 :           error_at (location, "wrong type argument to conjugation");
    5923            0 :           return error_mark_node;
    5924              :         }
    5925            0 :       else if (!noconvert)
    5926            0 :         arg = default_conversion (arg);
    5927              :       break;
    5928              : 
    5929       378924 :     case TRUTH_NOT_EXPR:
    5930       378924 :       if (typecode != INTEGER_TYPE && typecode != FIXED_POINT_TYPE
    5931         7282 :           && typecode != REAL_TYPE && typecode != POINTER_TYPE
    5932           21 :           && typecode != COMPLEX_TYPE && typecode != NULLPTR_TYPE
    5933           18 :           && typecode != BITINT_TYPE)
    5934              :         {
    5935           10 :           error_at (location,
    5936              :                     "wrong type argument to unary exclamation mark");
    5937           10 :           return error_mark_node;
    5938              :         }
    5939       378914 :       if (int_operands)
    5940              :         {
    5941       139865 :           arg = c_objc_common_truthvalue_conversion (location, xarg);
    5942       139865 :           arg = remove_c_maybe_const_expr (arg);
    5943              :         }
    5944              :       else
    5945       239049 :         arg = c_objc_common_truthvalue_conversion (location, arg);
    5946       378914 :       ret = invert_truthvalue_loc (location, arg);
    5947              :       /* If the TRUTH_NOT_EXPR has been folded, reset the location.  */
    5948       378914 :       if (EXPR_P (ret) && EXPR_HAS_LOCATION (ret))
    5949       238656 :         location = EXPR_LOCATION (ret);
    5950       378914 :       goto return_build_unary_op;
    5951              : 
    5952       203100 :     case REALPART_EXPR:
    5953       203100 :     case IMAGPART_EXPR:
    5954       203100 :       ret = build_real_imag_expr (location, code, arg);
    5955       203100 :       if (ret == error_mark_node)
    5956              :         return error_mark_node;
    5957       203092 :       if (eptype && TREE_CODE (eptype) == COMPLEX_TYPE)
    5958            2 :         eptype = TREE_TYPE (eptype);
    5959       203092 :       goto return_build_unary_op;
    5960              : 
    5961       936039 :     case PREINCREMENT_EXPR:
    5962       936039 :     case POSTINCREMENT_EXPR:
    5963       936039 :     case PREDECREMENT_EXPR:
    5964       936039 :     case POSTDECREMENT_EXPR:
    5965              : 
    5966       936039 :       if (TREE_CODE (arg) == C_MAYBE_CONST_EXPR)
    5967              :         {
    5968            2 :           tree inner = build_unary_op (location, code,
    5969            2 :                                        C_MAYBE_CONST_EXPR_EXPR (arg),
    5970              :                                        noconvert);
    5971            2 :           if (inner == error_mark_node)
    5972              :             return error_mark_node;
    5973            4 :           ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner),
    5974            2 :                         C_MAYBE_CONST_EXPR_PRE (arg), inner);
    5975            2 :           gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (arg));
    5976            2 :           C_MAYBE_CONST_EXPR_NON_CONST (ret) = 1;
    5977            2 :           goto return_build_unary_op;
    5978              :         }
    5979              : 
    5980              :       /* Complain about anything that is not a true lvalue.  In
    5981              :          Objective-C, skip this check for property_refs.  */
    5982       936037 :       if (!objc_is_property_ref (arg)
    5983      1872074 :           && !lvalue_or_else (location,
    5984       936037 :                               arg, ((code == PREINCREMENT_EXPR
    5985       936037 :                                      || code == POSTINCREMENT_EXPR)
    5986              :                                     ? lv_increment
    5987              :                                     : lv_decrement)))
    5988           22 :         return error_mark_node;
    5989              : 
    5990       936015 :       if (warn_cxx_compat && TREE_CODE (TREE_TYPE (arg)) == ENUMERAL_TYPE)
    5991              :         {
    5992            4 :           if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
    5993            2 :             warning_at (location, OPT_Wc___compat,
    5994              :                         "increment of enumeration value is invalid in C++");
    5995              :           else
    5996            2 :             warning_at (location, OPT_Wc___compat,
    5997              :                         "decrement of enumeration value is invalid in C++");
    5998              :         }
    5999              : 
    6000       936015 :       if (C_BOOLEAN_TYPE_P (TREE_TYPE (arg)))
    6001              :         {
    6002          664 :           if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
    6003          328 :             warning_at (location, OPT_Wbool_operation,
    6004              :                         "increment of a boolean expression");
    6005              :           else
    6006          336 :             warning_at (location, OPT_Wbool_operation,
    6007              :                         "decrement of a boolean expression");
    6008              :         }
    6009              : 
    6010              :       /* Ensure the argument is fully folded inside any SAVE_EXPR.  */
    6011       936015 :       arg = c_fully_fold (arg, false, NULL, true);
    6012              : 
    6013       936015 :       bool atomic_op;
    6014       936015 :       atomic_op = really_atomic_lvalue (arg);
    6015              : 
    6016              :       /* Increment or decrement the real part of the value,
    6017              :          and don't change the imaginary part.  */
    6018       936015 :       if (typecode == COMPLEX_TYPE)
    6019              :         {
    6020           57 :           tree real, imag;
    6021              : 
    6022           57 :           pedwarn_c23 (location, OPT_Wpedantic,
    6023              :                        "ISO C does not support %<++%> and %<--%> on complex "
    6024              :                        "types before C2Y");
    6025              : 
    6026           57 :           if (!atomic_op)
    6027              :             {
    6028           53 :               arg = stabilize_reference (arg);
    6029           53 :               real = build_unary_op (EXPR_LOCATION (arg), REALPART_EXPR, arg,
    6030              :                                      true);
    6031           53 :               imag = build_unary_op (EXPR_LOCATION (arg), IMAGPART_EXPR, arg,
    6032              :                                      true);
    6033           53 :               real = build_unary_op (EXPR_LOCATION (arg), code, real, true);
    6034           53 :               if (real == error_mark_node || imag == error_mark_node)
    6035              :                 return error_mark_node;
    6036           53 :               ret = build2 (COMPLEX_EXPR, TREE_TYPE (arg),
    6037              :                             real, imag);
    6038           53 :               goto return_build_unary_op;
    6039              :             }
    6040              :         }
    6041              : 
    6042              :       /* Report invalid types.  */
    6043              : 
    6044       935962 :       if (typecode != POINTER_TYPE && typecode != FIXED_POINT_TYPE
    6045       705523 :           && typecode != INTEGER_TYPE && typecode != REAL_TYPE
    6046          208 :           && typecode != COMPLEX_TYPE && typecode != BITINT_TYPE
    6047       936018 :           && !gnu_vector_type_p (TREE_TYPE (arg)))
    6048              :         {
    6049            5 :           if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
    6050            3 :             error_at (location, "wrong type argument to increment");
    6051              :           else
    6052            2 :             error_at (location, "wrong type argument to decrement");
    6053              : 
    6054            5 :           return error_mark_node;
    6055              :         }
    6056              : 
    6057       935957 :       {
    6058       935957 :         tree inc;
    6059              : 
    6060       935957 :         argtype = TREE_TYPE (arg);
    6061              : 
    6062              :         /* Compute the increment.  */
    6063              : 
    6064       935957 :         if (typecode == POINTER_TYPE)
    6065              :           {
    6066              :             /* If pointer target is an incomplete type,
    6067              :                we just cannot know how to do the arithmetic.  */
    6068       230439 :             if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (argtype)))
    6069              :               {
    6070           27 :                 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
    6071           17 :                   error_at (location,
    6072              :                             "increment of pointer to an incomplete type %qT",
    6073           17 :                             TREE_TYPE (argtype));
    6074              :                 else
    6075           10 :                   error_at (location,
    6076              :                             "decrement of pointer to an incomplete type %qT",
    6077           10 :                             TREE_TYPE (argtype));
    6078              :               }
    6079       230412 :             else if (TREE_CODE (TREE_TYPE (argtype)) == FUNCTION_TYPE
    6080       230412 :                      || VOID_TYPE_P (TREE_TYPE (argtype)))
    6081              :               {
    6082           10 :                 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
    6083            6 :                   pedwarn (location, OPT_Wpointer_arith,
    6084              :                            "wrong type argument to increment");
    6085              :                 else
    6086            4 :                   pedwarn (location, OPT_Wpointer_arith,
    6087              :                            "wrong type argument to decrement");
    6088              :               }
    6089              :             else
    6090       460804 :               verify_type_context (location, TCTX_POINTER_ARITH,
    6091       230402 :                                    TREE_TYPE (argtype));
    6092              : 
    6093       230439 :             inc = c_size_in_bytes (TREE_TYPE (argtype));
    6094       230439 :             inc = convert_to_ptrofftype_loc (location, inc);
    6095              :           }
    6096       705518 :         else if (FRACT_MODE_P (TYPE_MODE (argtype)))
    6097              :           {
    6098              :             /* For signed fract types, we invert ++ to -- or
    6099              :                -- to ++, and change inc from 1 to -1, because
    6100              :                it is not possible to represent 1 in signed fract constants.
    6101              :                For unsigned fract types, the result always overflows and
    6102              :                we get an undefined (original) or the maximum value.  */
    6103            0 :             if (code == PREINCREMENT_EXPR)
    6104              :               code = PREDECREMENT_EXPR;
    6105              :             else if (code == PREDECREMENT_EXPR)
    6106              :               code = PREINCREMENT_EXPR;
    6107              :             else if (code == POSTINCREMENT_EXPR)
    6108              :               code = POSTDECREMENT_EXPR;
    6109              :             else /* code == POSTDECREMENT_EXPR  */
    6110            0 :               code = POSTINCREMENT_EXPR;
    6111              : 
    6112            0 :             inc = integer_minus_one_node;
    6113            0 :             inc = convert (argtype, inc);
    6114              :           }
    6115              :         else
    6116              :           {
    6117       705467 :             inc = VECTOR_TYPE_P (argtype)
    6118       705518 :               ? build_one_cst (argtype)
    6119              :               : integer_one_node;
    6120       705518 :             inc = convert (argtype, inc);
    6121              :           }
    6122              : 
    6123              :         /* If 'arg' is an Objective-C PROPERTY_REF expression, then we
    6124              :            need to ask Objective-C to build the increment or decrement
    6125              :            expression for it.  */
    6126       935957 :         if (objc_is_property_ref (arg))
    6127            0 :           return objc_build_incr_expr_for_property_ref (location, code,
    6128           20 :                                                         arg, inc);
    6129              : 
    6130              :         /* Report a read-only lvalue.  */
    6131       935957 :         if (TYPE_READONLY (argtype))
    6132              :           {
    6133           20 :             readonly_error (location, arg,
    6134           20 :                             ((code == PREINCREMENT_EXPR
    6135           20 :                               || code == POSTINCREMENT_EXPR)
    6136              :                              ? lv_increment : lv_decrement));
    6137           20 :             return error_mark_node;
    6138              :           }
    6139       935937 :         else if (TREE_READONLY (arg))
    6140            4 :           readonly_warning (arg,
    6141            4 :                             ((code == PREINCREMENT_EXPR
    6142            4 :                               || code == POSTINCREMENT_EXPR)
    6143              :                              ? lv_increment : lv_decrement));
    6144              : 
    6145              :         /* If the argument is atomic, use the special code sequences for
    6146              :            atomic compound assignment.  */
    6147       935937 :         if (atomic_op)
    6148              :           {
    6149         4469 :             arg = stabilize_reference (arg);
    6150         8938 :             ret = build_atomic_assign (location, arg,
    6151         4469 :                                        ((code == PREINCREMENT_EXPR
    6152         4469 :                                          || code == POSTINCREMENT_EXPR)
    6153              :                                         ? PLUS_EXPR
    6154              :                                         : MINUS_EXPR),
    6155         4469 :                                        (FRACT_MODE_P (TYPE_MODE (argtype))
    6156              :                                         ? inc
    6157              :                                         : integer_one_node),
    6158              :                                        (code == POSTINCREMENT_EXPR
    6159         4469 :                                         || code == POSTDECREMENT_EXPR));
    6160       935937 :             goto return_build_unary_op;
    6161              :           }
    6162              : 
    6163       931468 :         tree true_res;
    6164       931468 :         if (c_hardbool_type_attr (TREE_TYPE (arg), NULL, &true_res))
    6165              :           {
    6166          364 :             tree larg = stabilize_reference (arg);
    6167          364 :             tree sarg = save_expr (larg);
    6168          364 :             switch (code)
    6169              :               {
    6170           91 :               case PREINCREMENT_EXPR:
    6171           91 :                 val = build2 (MODIFY_EXPR, TREE_TYPE (larg), larg, true_res);
    6172           91 :                 val = build2 (COMPOUND_EXPR, TREE_TYPE (larg), sarg, val);
    6173           91 :                 break;
    6174           91 :               case POSTINCREMENT_EXPR:
    6175           91 :                 val = build2 (MODIFY_EXPR, TREE_TYPE (larg), larg, true_res);
    6176           91 :                 val = build2 (COMPOUND_EXPR, TREE_TYPE (larg), val, sarg);
    6177           91 :                 val = build2 (COMPOUND_EXPR, TREE_TYPE (larg), sarg, val);
    6178           91 :                 break;
    6179           91 :               case PREDECREMENT_EXPR:
    6180           91 :                 {
    6181           91 :                   tree rarg = convert_lvalue_to_rvalue (location, sarg,
    6182              :                                                         true, true);
    6183           91 :                   rarg = invert_truthvalue_loc (location, rarg);
    6184           91 :                   rarg = convert (TREE_TYPE (sarg), rarg);
    6185           91 :                   val = build2 (MODIFY_EXPR, TREE_TYPE (larg), larg, rarg);
    6186              :                 }
    6187           91 :                 break;
    6188           91 :               case POSTDECREMENT_EXPR:
    6189           91 :                 {
    6190           91 :                   tree rarg = convert_lvalue_to_rvalue (location, sarg,
    6191              :                                                         true, true);
    6192           91 :                   rarg = invert_truthvalue_loc (location, rarg);
    6193           91 :                   tree iarg = convert (TREE_TYPE (larg), rarg);
    6194           91 :                   val = build2 (MODIFY_EXPR, TREE_TYPE (larg), larg, iarg);
    6195           91 :                   val = build2 (COMPOUND_EXPR, TREE_TYPE (larg), val, sarg);
    6196           91 :                   val = build2 (COMPOUND_EXPR, TREE_TYPE (larg), sarg, val);
    6197              :                 }
    6198           91 :                 break;
    6199              :               default:
    6200              :                 gcc_unreachable ();
    6201              :               }
    6202          364 :             TREE_SIDE_EFFECTS (val) = 1;
    6203              :           }
    6204       931104 :         else if (C_BOOLEAN_TYPE_P (TREE_TYPE (arg)))
    6205           64 :           val = boolean_increment (code, arg);
    6206              :         else
    6207       931040 :           val = build2 (code, TREE_TYPE (arg), arg, inc);
    6208       931468 :         TREE_SIDE_EFFECTS (val) = 1;
    6209       931468 :         if (TYPE_QUALS (TREE_TYPE (val)) != TYPE_UNQUALIFIED)
    6210         3939 :           TREE_TYPE (val) = c_build_qualified_type (TREE_TYPE (val),
    6211              :                                                     TYPE_UNQUALIFIED);
    6212       931468 :         ret = val;
    6213       931468 :         goto return_build_unary_op;
    6214              :       }
    6215              : 
    6216     52008569 :     case ADDR_EXPR:
    6217              :       /* Note that this operation never does default_conversion.  */
    6218              : 
    6219              :       /* The operand of unary '&' must be an lvalue (which excludes
    6220              :          expressions of type void), or, in C99, the result of a [] or
    6221              :          unary '*' operator.  */
    6222     52008569 :       if (VOID_TYPE_P (TREE_TYPE (arg))
    6223           25 :           && TYPE_QUALS (TREE_TYPE (arg)) == TYPE_UNQUALIFIED
    6224     52008588 :           && (!INDIRECT_REF_P (arg) || !flag_isoc99))
    6225           18 :         pedwarn (location, 0, "taking address of expression of type %<void%>");
    6226              : 
    6227              :       /* Let &* cancel out to simplify resulting code.  */
    6228     52008569 :       if (INDIRECT_REF_P (arg))
    6229              :         {
    6230              :           /* Don't let this be an lvalue.  */
    6231        22335 :           if (lvalue_p (TREE_OPERAND (arg, 0)))
    6232        16826 :             return non_lvalue_loc (location, TREE_OPERAND (arg, 0));
    6233         5509 :           ret = TREE_OPERAND (arg, 0);
    6234         5509 :           goto return_build_unary_op;
    6235              :         }
    6236              : 
    6237              :       /* Anything not already handled and not a true memory reference
    6238              :          or a non-lvalue array is an error.  */
    6239     51986234 :       if (typecode != FUNCTION_TYPE && !noconvert
    6240     51986234 :           && !lvalue_or_else (location, arg, lv_addressof))
    6241           17 :         return error_mark_node;
    6242              : 
    6243              :       /* Move address operations inside C_MAYBE_CONST_EXPR to simplify
    6244              :          folding later.  */
    6245     51986217 :       if (TREE_CODE (arg) == C_MAYBE_CONST_EXPR)
    6246              :         {
    6247           14 :           tree inner = build_unary_op (location, code,
    6248           14 :                                        C_MAYBE_CONST_EXPR_EXPR (arg),
    6249              :                                        noconvert);
    6250           28 :           ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner),
    6251           14 :                         C_MAYBE_CONST_EXPR_PRE (arg), inner);
    6252           14 :           gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (arg));
    6253           14 :           C_MAYBE_CONST_EXPR_NON_CONST (ret)
    6254           14 :             = C_MAYBE_CONST_EXPR_NON_CONST (arg);
    6255           14 :           goto return_build_unary_op;
    6256              :         }
    6257              : 
    6258              :       /* Ordinary case; arg is a COMPONENT_REF or a decl.  */
    6259              : 
    6260     51986203 :       argtype = TREE_TYPE (arg);
    6261              : 
    6262              :       /* If the lvalue is const or volatile, merge that into the type
    6263              :          to which the address will point.  This is only needed
    6264              :          for function types.  */
    6265     51986203 :       if ((DECL_P (arg) || REFERENCE_CLASS_P (arg))
    6266     51492688 :           && (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg))
    6267     82082545 :           && TREE_CODE (argtype) == FUNCTION_TYPE)
    6268              :         {
    6269     30016175 :           int orig_quals = TYPE_QUALS (strip_array_types (argtype));
    6270     30016175 :           int quals = orig_quals;
    6271              : 
    6272     30016175 :           if (TREE_READONLY (arg))
    6273     29639645 :             quals |= TYPE_QUAL_CONST;
    6274     30016175 :           if (TREE_THIS_VOLATILE (arg))
    6275       377442 :             quals |= TYPE_QUAL_VOLATILE;
    6276              : 
    6277     30016175 :           argtype = c_build_qualified_type (argtype, quals);
    6278              :         }
    6279              : 
    6280     51986203 :       switch (TREE_CODE (arg))
    6281              :         {
    6282        65702 :         case COMPONENT_REF:
    6283        65702 :           if (DECL_C_BIT_FIELD (TREE_OPERAND (arg, 1)))
    6284              :             {
    6285            8 :               error_at (location, "cannot take address of bit-field %qD",
    6286            8 :                         TREE_OPERAND (arg, 1));
    6287            8 :               return error_mark_node;
    6288              :             }
    6289              : 
    6290              :           /* fall through */
    6291              : 
    6292       139952 :         case ARRAY_REF:
    6293       139952 :           if (TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (TREE_OPERAND (arg, 0))))
    6294              :             {
    6295           78 :               if (!AGGREGATE_TYPE_P (TREE_TYPE (arg))
    6296            7 :                   && !POINTER_TYPE_P (TREE_TYPE (arg))
    6297           75 :                   && !VECTOR_TYPE_P (TREE_TYPE (arg)))
    6298              :                 {
    6299            6 :                   error_at (location, "cannot take address of scalar with "
    6300              :                             "reverse storage order");
    6301            6 :                   return error_mark_node;
    6302              :                 }
    6303              : 
    6304           63 :               if (TREE_CODE (TREE_TYPE (arg)) == ARRAY_TYPE
    6305           63 :                   && TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (arg)))
    6306           58 :                 warning_at (location, OPT_Wscalar_storage_order,
    6307              :                             "address of array with reverse scalar storage "
    6308              :                             "order requested");
    6309              :             }
    6310              : 
    6311     51986189 :         default:
    6312     51986189 :           break;
    6313              :         }
    6314              : 
    6315     51986189 :       if (!c_mark_addressable (arg))
    6316           20 :         return error_mark_node;
    6317              : 
    6318     51986169 :       gcc_assert (TREE_CODE (arg) != COMPONENT_REF
    6319              :                   || !DECL_C_BIT_FIELD (TREE_OPERAND (arg, 1)));
    6320              : 
    6321     51986169 :       argtype = c_build_pointer_type (argtype);
    6322              : 
    6323              :       /* ??? Cope with user tricks that amount to offsetof.  Delete this
    6324              :          when we have proper support for integer constant expressions.  */
    6325     51986169 :       val = get_base_address (arg);
    6326     51986169 :       if (val && INDIRECT_REF_P (val)
    6327     52010301 :           && TREE_CONSTANT (TREE_OPERAND (val, 0)))
    6328              :         {
    6329          540 :           ret = fold_offsetof (arg, argtype);
    6330          540 :           goto return_build_unary_op;
    6331              :         }
    6332              : 
    6333     51985629 :       val = build1 (ADDR_EXPR, argtype, arg);
    6334              : 
    6335     51985629 :       ret = val;
    6336     51985629 :       goto return_build_unary_op;
    6337              : 
    6338           10 :     case PAREN_EXPR:
    6339           10 :       ret = build1 (code, TREE_TYPE (arg), arg);
    6340           10 :       goto return_build_unary_op;
    6341              : 
    6342            0 :     default:
    6343            0 :       gcc_unreachable ();
    6344              :     }
    6345              : 
    6346      7024840 :   if (argtype == NULL_TREE)
    6347      7024840 :     argtype = TREE_TYPE (arg);
    6348      7024840 :   if (TREE_CODE (arg) == INTEGER_CST)
    6349      6320271 :     ret = (require_constant_value
    6350      6320271 :            ? fold_build1_initializer_loc (location, code, argtype, arg)
    6351      6301680 :            : fold_build1_loc (location, code, argtype, arg));
    6352              :   else
    6353       704569 :     ret = build1 (code, argtype, arg);
    6354     60534540 :  return_build_unary_op:
    6355     60534540 :   gcc_assert (ret != error_mark_node);
    6356      6464955 :   if (TREE_CODE (ret) == INTEGER_CST && !TREE_OVERFLOW (ret)
    6357     66999486 :       && !(TREE_CODE (xarg) == INTEGER_CST && !TREE_OVERFLOW (xarg)))
    6358          562 :     ret = build1 (NOP_EXPR, TREE_TYPE (ret), ret);
    6359     60533978 :   else if (TREE_CODE (ret) != INTEGER_CST && int_operands)
    6360           74 :     ret = note_integer_operands (ret);
    6361     60534540 :   if (eptype)
    6362          245 :     ret = build1 (EXCESS_PRECISION_EXPR, eptype, ret);
    6363     60534540 :   protected_set_expr_location (ret, location);
    6364     60534540 :   return ret;
    6365              : }
    6366              : 
    6367              : /* Return nonzero if REF is an lvalue valid for this language.
    6368              :    Lvalues can be assigned, unless their type has TYPE_READONLY.
    6369              :    Lvalues can have their address taken, unless they have C_DECL_REGISTER.  */
    6370              : 
    6371              : bool
    6372    178326001 : lvalue_p (const_tree ref)
    6373              : {
    6374    179828826 :   const enum tree_code code = TREE_CODE (ref);
    6375              : 
    6376    179828826 :   switch (code)
    6377              :     {
    6378      1478016 :     case REALPART_EXPR:
    6379      1478016 :     case IMAGPART_EXPR:
    6380      1478016 :     case COMPONENT_REF:
    6381      1478016 :       return lvalue_p (TREE_OPERAND (ref, 0));
    6382              : 
    6383        24809 :     case C_MAYBE_CONST_EXPR:
    6384        24809 :       return lvalue_p (TREE_OPERAND (ref, 1));
    6385              : 
    6386              :     case COMPOUND_LITERAL_EXPR:
    6387              :     case STRING_CST:
    6388              :       return true;
    6389              : 
    6390     25510730 :     case MEM_REF:
    6391     25510730 :     case TARGET_MEM_REF:
    6392              :       /* MEM_REFs can appear from -fgimple parsing or folding, so allow them
    6393              :          here as well.  */
    6394     25510730 :     case INDIRECT_REF:
    6395     25510730 :     case ARRAY_REF:
    6396     25510730 :     case VAR_DECL:
    6397     25510730 :     case PARM_DECL:
    6398     25510730 :     case RESULT_DECL:
    6399     25510730 :     case ERROR_MARK:
    6400     25510730 :       return (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE
    6401     25510730 :               && TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE);
    6402              : 
    6403            6 :     case BIND_EXPR:
    6404            6 :       return TREE_CODE (TREE_TYPE (ref)) == ARRAY_TYPE;
    6405              : 
    6406      7080711 :     case CALL_EXPR:
    6407      7080711 :       return is_access_with_size_p (ref);
    6408              : 
    6409              :     default:
    6410              :       return false;
    6411              :     }
    6412              : }
    6413              : 
    6414              : /* Give a warning for storing in something that is read-only in GCC
    6415              :    terms but not const in ISO C terms.  */
    6416              : 
    6417              : static void
    6418            5 : readonly_warning (tree arg, enum lvalue_use use)
    6419              : {
    6420            5 :   switch (use)
    6421              :     {
    6422            1 :     case lv_assign:
    6423            1 :       warning (0, "assignment of read-only location %qE", arg);
    6424            1 :       break;
    6425            2 :     case lv_increment:
    6426            2 :       warning (0, "increment of read-only location %qE", arg);
    6427            2 :       break;
    6428            2 :     case lv_decrement:
    6429            2 :       warning (0, "decrement of read-only location %qE", arg);
    6430            2 :       break;
    6431            0 :     default:
    6432            0 :       gcc_unreachable ();
    6433              :     }
    6434            5 :   return;
    6435              : }
    6436              : 
    6437              : 
    6438              : /* Return nonzero if REF is an lvalue valid for this language;
    6439              :    otherwise, print an error message and return zero.  USE says
    6440              :    how the lvalue is being used and so selects the error message.
    6441              :    LOCATION is the location at which any error should be reported.  */
    6442              : 
    6443              : static int
    6444      4727813 : lvalue_or_else (location_t loc, const_tree ref, enum lvalue_use use)
    6445              : {
    6446      4727813 :   int win = lvalue_p (ref);
    6447              : 
    6448      4727813 :   if (!win)
    6449           75 :     lvalue_error (loc, use);
    6450              : 
    6451      4727813 :   return win;
    6452              : }
    6453              : 
    6454              : /* Mark EXP saying that we need to be able to take the
    6455              :    address of it; it should not be allocated in a register.
    6456              :    Returns true if successful.  ARRAY_REF_P is true if this
    6457              :    is for ARRAY_REF construction - in that case we don't want
    6458              :    to look through VIEW_CONVERT_EXPR from VECTOR_TYPE to ARRAY_TYPE,
    6459              :    it is fine to use ARRAY_REFs for vector subscripts on vector
    6460              :    register variables.  If OVERRIDE_REGISTER, clear DECL_REGISTER rather
    6461              :    than producing an error for taking the address of a register.  */
    6462              : 
    6463              : bool
    6464     52531302 : c_mark_addressable (tree exp, bool array_ref_p, bool override_register)
    6465              : {
    6466     52531302 :   tree x = exp;
    6467              : 
    6468     53112148 :   while (1)
    6469     53112148 :     switch (TREE_CODE (x))
    6470              :       {
    6471        10037 :       case VIEW_CONVERT_EXPR:
    6472        10037 :         if (array_ref_p
    6473         9927 :             && TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
    6474        19964 :             && VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (x, 0))))
    6475              :           return true;
    6476          110 :         x = TREE_OPERAND (x, 0);
    6477          110 :         break;
    6478              : 
    6479       396524 :       case COMPONENT_REF:
    6480       396524 :         if (DECL_C_BIT_FIELD (TREE_OPERAND (x, 1)))
    6481              :           {
    6482            6 :             error ("cannot take address of bit-field %qD",
    6483            3 :                    TREE_OPERAND (x, 1));
    6484            3 :             return false;
    6485              :           }
    6486              :         /* FALLTHRU */
    6487       580736 :       case ADDR_EXPR:
    6488       580736 :       case ARRAY_REF:
    6489       580736 :       case REALPART_EXPR:
    6490       580736 :       case IMAGPART_EXPR:
    6491       580736 :         x = TREE_OPERAND (x, 0);
    6492       580736 :         break;
    6493              : 
    6494          587 :       case COMPOUND_LITERAL_EXPR:
    6495          587 :         if (C_DECL_REGISTER (COMPOUND_LITERAL_EXPR_DECL (x)))
    6496              :           {
    6497           16 :             if (override_register)
    6498           12 :               DECL_REGISTER (COMPOUND_LITERAL_EXPR_DECL (x)) = 0;
    6499              :             else
    6500              :               {
    6501            4 :                 error ("address of register compound literal requested");
    6502            4 :                 return false;
    6503              :               }
    6504              :           }
    6505          583 :         TREE_ADDRESSABLE (x) = 1;
    6506          583 :         TREE_ADDRESSABLE (COMPOUND_LITERAL_EXPR_DECL (x)) = 1;
    6507          583 :         return true;
    6508              : 
    6509            0 :       case CONSTRUCTOR:
    6510            0 :         TREE_ADDRESSABLE (x) = 1;
    6511            0 :         return true;
    6512              : 
    6513      1324769 :       case VAR_DECL:
    6514      1324769 :       case CONST_DECL:
    6515      1324769 :       case PARM_DECL:
    6516      1324769 :       case RESULT_DECL:
    6517      1324769 :         if (C_DECL_REGISTER (x)
    6518      1324769 :             && DECL_NONLOCAL (x))
    6519              :           {
    6520            0 :             if (TREE_PUBLIC (x) || is_global_var (x))
    6521              :               {
    6522            0 :                 error
    6523            0 :                   ("global register variable %qD used in nested function", x);
    6524            0 :                 return false;
    6525              :               }
    6526            0 :             pedwarn (input_location, 0, "register variable %qD used in nested function", x);
    6527              :           }
    6528      1324769 :         else if (C_DECL_REGISTER (x))
    6529              :           {
    6530           73 :             if (TREE_PUBLIC (x) || is_global_var (x))
    6531            4 :               error ("address of global register variable %qD requested", x);
    6532          123 :             else if (override_register && !DECL_HARD_REGISTER (x))
    6533              :               {
    6534           54 :                 DECL_REGISTER (x) = 0;
    6535           54 :                 TREE_ADDRESSABLE (x) = 1;
    6536           54 :                 mark_decl_used (x, true);
    6537           54 :                 return true;
    6538              :               }
    6539              :             else
    6540           15 :               error ("address of register variable %qD requested", x);
    6541           19 :             return false;
    6542              :           }
    6543              : 
    6544              :         /* FALLTHRU */
    6545     51951906 :       case FUNCTION_DECL:
    6546     51951906 :         TREE_ADDRESSABLE (x) = 1;
    6547     51951906 :         mark_decl_used (x, true);
    6548              :         /* FALLTHRU */
    6549              :       default:
    6550              :         return true;
    6551              :     }
    6552              : }
    6553              : 
    6554              : /* Convert EXPR to TYPE, warning about conversion problems with
    6555              :    constants.  SEMANTIC_TYPE is the type this conversion would use
    6556              :    without excess precision. If SEMANTIC_TYPE is NULL, this function
    6557              :    is equivalent to convert_and_check. This function is a wrapper that
    6558              :    handles conversions that may be different than
    6559              :    the usual ones because of excess precision.  */
    6560              : 
    6561              : static tree
    6562     23679996 : ep_convert_and_check (location_t loc, tree type, tree expr,
    6563              :                       tree semantic_type)
    6564              : {
    6565     23679996 :   if (TREE_TYPE (expr) == type)
    6566              :     return expr;
    6567              : 
    6568              :   /* For C11, integer conversions may have results with excess
    6569              :      precision.  */
    6570      2063796 :   if (flag_isoc11 || !semantic_type)
    6571      2063792 :     return convert_and_check (loc, type, expr);
    6572              : 
    6573            4 :   if (TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
    6574            4 :       && TREE_TYPE (expr) != semantic_type)
    6575              :     {
    6576              :       /* For integers, we need to check the real conversion, not
    6577              :          the conversion to the excess precision type.  */
    6578            4 :       expr = convert_and_check (loc, semantic_type, expr);
    6579              :     }
    6580              :   /* Result type is the excess precision type, which should be
    6581              :      large enough, so do not check.  */
    6582            4 :   return convert (type, expr);
    6583              : }
    6584              : 
    6585              : /* If EXPR refers to a built-in declared without a prototype returns
    6586              :    the actual type of the built-in and, if non-null, set *BLTIN to
    6587              :    a pointer to the built-in.  Otherwise return the type of EXPR
    6588              :    and clear *BLTIN if non-null.  */
    6589              : 
    6590              : static tree
    6591      2833811 : type_or_builtin_type (tree expr, tree *bltin = NULL)
    6592              : {
    6593      2833811 :   tree dummy;
    6594      2833811 :   if (!bltin)
    6595            0 :     bltin = &dummy;
    6596              : 
    6597      2833811 :   *bltin = NULL_TREE;
    6598              : 
    6599      2833811 :   tree type = TREE_TYPE (expr);
    6600      2833811 :   if (TREE_CODE (expr) != ADDR_EXPR)
    6601              :     return type;
    6602              : 
    6603       209358 :   tree oper = TREE_OPERAND (expr, 0);
    6604       209358 :   if (!DECL_P (oper)
    6605       170755 :       || TREE_CODE (oper) != FUNCTION_DECL
    6606       245784 :       || !fndecl_built_in_p (oper, BUILT_IN_NORMAL))
    6607              :     return type;
    6608              : 
    6609         2086 :   built_in_function code = DECL_FUNCTION_CODE (oper);
    6610         2086 :   if (!C_DECL_BUILTIN_PROTOTYPE (oper))
    6611              :     return type;
    6612              : 
    6613         1977 :   if ((*bltin = builtin_decl_implicit (code)))
    6614          991 :     type = c_build_pointer_type (TREE_TYPE (*bltin));
    6615              : 
    6616              :   return type;
    6617              : }
    6618              : 
    6619              : /* Build and return a conditional expression IFEXP ? OP1 : OP2.  If
    6620              :    IFEXP_BCP then the condition is a call to __builtin_constant_p, and
    6621              :    if folded to an integer constant then the unselected half may
    6622              :    contain arbitrary operations not normally permitted in constant
    6623              :    expressions.  Set the location of the expression to LOC.  */
    6624              : 
    6625              : tree
    6626       404842 : build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp,
    6627              :                         tree op1, tree op1_original_type, location_t op1_loc,
    6628              :                         tree op2, tree op2_original_type, location_t op2_loc)
    6629              : {
    6630       404842 :   tree type1;
    6631       404842 :   tree type2;
    6632       404842 :   tree result_type = NULL;
    6633       404842 :   tree semantic_result_type = NULL;
    6634       404842 :   tree orig_op1 = op1, orig_op2 = op2;
    6635       404842 :   bool int_const, op1_int_operands, op2_int_operands, int_operands;
    6636       404842 :   bool ifexp_int_operands;
    6637       404842 :   tree ret;
    6638              : 
    6639       404842 :   op1_int_operands = EXPR_INT_CONST_OPERANDS (orig_op1);
    6640       111115 :   if (op1_int_operands)
    6641       111115 :     op1 = remove_c_maybe_const_expr (op1);
    6642       404842 :   op2_int_operands = EXPR_INT_CONST_OPERANDS (orig_op2);
    6643       146254 :   if (op2_int_operands)
    6644       146254 :     op2 = remove_c_maybe_const_expr (op2);
    6645       404842 :   ifexp_int_operands = EXPR_INT_CONST_OPERANDS (ifexp);
    6646       243280 :   if (ifexp_int_operands)
    6647       243280 :     ifexp = remove_c_maybe_const_expr (ifexp);
    6648              : 
    6649              :   /* Promote both alternatives.  */
    6650              : 
    6651       404842 :   if (TREE_CODE (TREE_TYPE (op1)) != VOID_TYPE)
    6652       400920 :     op1 = default_conversion (op1);
    6653       404842 :   if (TREE_CODE (TREE_TYPE (op2)) != VOID_TYPE)
    6654       374997 :     op2 = default_conversion (op2);
    6655              : 
    6656       404842 :   if (TREE_CODE (ifexp) == ERROR_MARK
    6657       404773 :       || TREE_CODE (TREE_TYPE (op1)) == ERROR_MARK
    6658       809601 :       || TREE_CODE (TREE_TYPE (op2)) == ERROR_MARK)
    6659           83 :     return error_mark_node;
    6660              : 
    6661       404759 :   tree bltin1 = NULL_TREE;
    6662       404759 :   tree bltin2 = NULL_TREE;
    6663       404759 :   type1 = type_or_builtin_type (op1, &bltin1);
    6664       404759 :   const enum tree_code code1 = TREE_CODE (type1);
    6665       404759 :   type2 = type_or_builtin_type (op2, &bltin2);
    6666       404759 :   const enum tree_code code2 = TREE_CODE (type2);
    6667              : 
    6668       404759 :   if (code1 == POINTER_TYPE && reject_gcc_builtin (op1))
    6669            1 :     return error_mark_node;
    6670              : 
    6671       404758 :   if (code2 == POINTER_TYPE && reject_gcc_builtin (op2))
    6672            1 :     return error_mark_node;
    6673              : 
    6674              :   /* C90 does not permit non-lvalue arrays in conditional expressions.
    6675              :      In C99 they will be pointers by now.  */
    6676       404757 :   if (code1 == ARRAY_TYPE || code2 == ARRAY_TYPE)
    6677              :     {
    6678            1 :       error_at (colon_loc, "non-lvalue array in conditional expression");
    6679            1 :       return error_mark_node;
    6680              :     }
    6681              : 
    6682       404756 :   if ((TREE_CODE (op1) == EXCESS_PRECISION_EXPR
    6683       404750 :        || TREE_CODE (op2) == EXCESS_PRECISION_EXPR)
    6684            7 :       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
    6685            0 :           || code1 == COMPLEX_TYPE || code1 == BITINT_TYPE)
    6686            7 :       && (code2 == INTEGER_TYPE || code2 == REAL_TYPE
    6687            0 :           || code2 == COMPLEX_TYPE || code2 == BITINT_TYPE))
    6688              :     {
    6689            7 :       semantic_result_type = c_common_type (type1, type2);
    6690            7 :       if (TREE_CODE (op1) == EXCESS_PRECISION_EXPR)
    6691              :         {
    6692            6 :           op1 = TREE_OPERAND (op1, 0);
    6693            6 :           type1 = TREE_TYPE (op1);
    6694            6 :           gcc_assert (TREE_CODE (type1) == code1);
    6695              :         }
    6696            7 :       if (TREE_CODE (op2) == EXCESS_PRECISION_EXPR)
    6697              :         {
    6698            1 :           op2 = TREE_OPERAND (op2, 0);
    6699            1 :           type2 = TREE_TYPE (op2);
    6700            1 :           gcc_assert (TREE_CODE (type2) == code2);
    6701              :         }
    6702              :     }
    6703              : 
    6704       404756 :   if (warn_cxx_compat)
    6705              :     {
    6706          420 :       tree t1 = op1_original_type ? op1_original_type : TREE_TYPE (orig_op1);
    6707          420 :       tree t2 = op2_original_type ? op2_original_type : TREE_TYPE (orig_op2);
    6708              : 
    6709          420 :       if (TREE_CODE (t1) == ENUMERAL_TYPE
    6710            6 :           && TREE_CODE (t2) == ENUMERAL_TYPE
    6711          426 :           && TYPE_MAIN_VARIANT (t1) != TYPE_MAIN_VARIANT (t2))
    6712            2 :         warning_at (colon_loc, OPT_Wc___compat,
    6713              :                     "different enum types in conditional is "
    6714              :                     "invalid in C++: %qT vs %qT", t1, t2);
    6715              :     }
    6716              : 
    6717       404756 :   if (warn_zero_as_null_pointer_constant
    6718           20 :       && c_inhibit_evaluation_warnings == 0)
    6719              :     {
    6720           20 :       if ((code1 == POINTER_TYPE || code1 == NULLPTR_TYPE)
    6721           20 :           && INTEGRAL_TYPE_P (type2) && null_pointer_constant_p (orig_op2))
    6722            5 :         warning_at (op2_loc, OPT_Wzero_as_null_pointer_constant,
    6723              :                     "zero as null pointer constant");
    6724              : 
    6725           20 :       if ((code2 == POINTER_TYPE || code2 == NULLPTR_TYPE)
    6726           20 :           && INTEGRAL_TYPE_P (type1) && null_pointer_constant_p (orig_op1))
    6727            5 :         warning_at (op1_loc, OPT_Wzero_as_null_pointer_constant,
    6728              :                     "zero as null pointer constant");
    6729              :     }
    6730              : 
    6731              :   /* Quickly detect the usual case where op1 and op2 have the same type
    6732              :      after promotion.  */
    6733       404756 :   if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2))
    6734              :     {
    6735       269686 :       if (type1 == type2)
    6736              :         result_type = type1;
    6737              :       else
    6738         6400 :         result_type = TYPE_MAIN_VARIANT (type1);
    6739              :     }
    6740       135070 :   else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE
    6741        80414 :             || code1 == COMPLEX_TYPE || code1 == BITINT_TYPE)
    6742        54704 :            && (code2 == INTEGER_TYPE || code2 == REAL_TYPE
    6743        26152 :                || code2 == COMPLEX_TYPE || code2 == BITINT_TYPE))
    6744              :     {
    6745              :       /* In C11, a conditional expression between a floating-point
    6746              :          type and an integer type should convert the integer type to
    6747              :          the evaluation format of the floating-point type, with
    6748              :          possible excess precision.  */
    6749        28652 :       tree eptype1 = type1;
    6750        28652 :       tree eptype2 = type2;
    6751        28652 :       if (flag_isoc11)
    6752              :         {
    6753        28339 :           tree eptype;
    6754        11641 :           if (ANY_INTEGRAL_TYPE_P (type1)
    6755        28339 :               && (eptype = excess_precision_type (type2)) != NULL_TREE)
    6756              :             {
    6757            2 :               eptype2 = eptype;
    6758            2 :               if (!semantic_result_type)
    6759            2 :                 semantic_result_type = c_common_type (type1, type2);
    6760              :             }
    6761          501 :           else if (ANY_INTEGRAL_TYPE_P (type2)
    6762        28337 :                    && (eptype = excess_precision_type (type1)) != NULL_TREE)
    6763              :             {
    6764         4626 :               eptype1 = eptype;
    6765         4626 :               if (!semantic_result_type)
    6766         4626 :                 semantic_result_type = c_common_type (type1, type2);
    6767              :             }
    6768              :         }
    6769        28652 :       result_type = c_common_type (eptype1, eptype2);
    6770        28652 :       if (result_type == error_mark_node)
    6771              :         return error_mark_node;
    6772        28650 :       do_warn_double_promotion (result_type, type1, type2,
    6773              :                                 "implicit conversion from %qT to %qT to "
    6774              :                                 "match other result of conditional",
    6775              :                                 colon_loc);
    6776              : 
    6777              :       /* If -Wsign-compare, warn here if type1 and type2 have
    6778              :          different signedness.  We'll promote the signed to unsigned
    6779              :          and later code won't know it used to be different.
    6780              :          Do this check on the original types, so that explicit casts
    6781              :          will be considered, but default promotions won't.  */
    6782        28650 :       if (c_inhibit_evaluation_warnings == 0)
    6783              :         {
    6784        28459 :           int unsigned_op1 = TYPE_UNSIGNED (TREE_TYPE (orig_op1));
    6785        28459 :           int unsigned_op2 = TYPE_UNSIGNED (TREE_TYPE (orig_op2));
    6786              : 
    6787        28459 :           if (unsigned_op1 ^ unsigned_op2)
    6788              :             {
    6789              :               /* Do not warn if the result type is signed, since the
    6790              :                  signed type will only be chosen if it can represent
    6791              :                  all the values of the unsigned type.  */
    6792        13020 :               if (!TYPE_UNSIGNED (result_type))
    6793              :                 /* OK */;
    6794              :               else
    6795              :                 {
    6796        12916 :                   bool op1_maybe_const = true;
    6797        12916 :                   bool op2_maybe_const = true;
    6798              : 
    6799              :                   /* Do not warn if the signed quantity is an
    6800              :                      unsuffixed integer literal (or some static
    6801              :                      constant expression involving such literals) and
    6802              :                      it is non-negative.  This warning requires the
    6803              :                      operands to be folded for best results, so do
    6804              :                      that folding in this case even without
    6805              :                      warn_sign_compare to avoid warning options
    6806              :                      possibly affecting code generation.  */
    6807        12916 :                   c_inhibit_evaluation_warnings
    6808        12916 :                     += (ifexp == truthvalue_false_node);
    6809        12916 :                   op1 = c_fully_fold (op1, require_constant_value,
    6810              :                                       &op1_maybe_const);
    6811        12916 :                   c_inhibit_evaluation_warnings
    6812        12916 :                     -= (ifexp == truthvalue_false_node);
    6813              : 
    6814        12916 :                   c_inhibit_evaluation_warnings
    6815        12916 :                     += (ifexp == truthvalue_true_node);
    6816        12916 :                   op2 = c_fully_fold (op2, require_constant_value,
    6817              :                                       &op2_maybe_const);
    6818        12916 :                   c_inhibit_evaluation_warnings
    6819        12916 :                     -= (ifexp == truthvalue_true_node);
    6820              : 
    6821        12916 :                   if (warn_sign_compare)
    6822              :                     {
    6823         1245 :                       if ((unsigned_op2
    6824          685 :                            && tree_expr_nonnegative_p (op1))
    6825         1248 :                           || (unsigned_op1
    6826          560 :                               && tree_expr_nonnegative_p (op2)))
    6827              :                         /* OK */;
    6828           10 :                       else if (unsigned_op2)
    6829            3 :                         warning_at (op1_loc, OPT_Wsign_compare,
    6830              :                                     "operand of %<?:%> changes signedness from "
    6831              :                                     "%qT to %qT due to unsignedness of other "
    6832            3 :                                     "operand", TREE_TYPE (orig_op1),
    6833            3 :                                     TREE_TYPE (orig_op2));
    6834              :                       else
    6835            7 :                         warning_at (op2_loc, OPT_Wsign_compare,
    6836              :                                     "operand of %<?:%> changes signedness from "
    6837              :                                     "%qT to %qT due to unsignedness of other "
    6838            7 :                                     "operand", TREE_TYPE (orig_op2),
    6839            7 :                                     TREE_TYPE (orig_op1));
    6840              :                     }
    6841        12916 :                   if (!op1_maybe_const || TREE_CODE (op1) != INTEGER_CST)
    6842         7567 :                     op1 = c_wrap_maybe_const (op1, !op1_maybe_const);
    6843        12916 :                   if (!op2_maybe_const || TREE_CODE (op2) != INTEGER_CST)
    6844         4394 :                     op2 = c_wrap_maybe_const (op2, !op2_maybe_const);
    6845              :                 }
    6846              :             }
    6847              :         }
    6848              :     }
    6849       106418 :   else if (code1 == VOID_TYPE || code2 == VOID_TYPE)
    6850              :     {
    6851        25995 :       if (code1 != VOID_TYPE || code2 != VOID_TYPE)
    6852        25995 :         pedwarn (colon_loc, OPT_Wpedantic,
    6853              :                  "ISO C forbids conditional expr with only one void side");
    6854        25995 :       result_type = void_type_node;
    6855              :     }
    6856        80423 :   else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE)
    6857              :     {
    6858        80026 :       addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (type1));
    6859        80026 :       addr_space_t as2 = TYPE_ADDR_SPACE (TREE_TYPE (type2));
    6860        80026 :       addr_space_t as_common;
    6861              : 
    6862        80026 :       if (comp_target_types (colon_loc, type1, type2))
    6863              :         {
    6864         2620 :           ifexp = save_expr (ifexp);
    6865         2620 :           result_type = common_pointer_type (type1, type2, ifexp);
    6866              :         }
    6867        77406 :       else if (null_pointer_constant_p (orig_op1))
    6868              :         result_type = type2;
    6869        73244 :       else if (null_pointer_constant_p (orig_op2))
    6870              :         result_type = type1;
    6871        35284 :       else if (!addr_space_superset (as1, as2, &as_common))
    6872              :         {
    6873            0 :           error_at (colon_loc, "pointers to disjoint address spaces "
    6874              :                     "used in conditional expression");
    6875            0 :           return error_mark_node;
    6876              :         }
    6877        35284 :       else if ((VOID_TYPE_P (TREE_TYPE (type1))
    6878          326 :                 && !TYPE_ATOMIC (TREE_TYPE (type1)))
    6879        35286 :                || (VOID_TYPE_P (TREE_TYPE (type2))
    6880        34913 :                    && !TYPE_ATOMIC (TREE_TYPE (type2))))
    6881              :         {
    6882        35236 :           tree t1 = TREE_TYPE (type1);
    6883        35236 :           tree t2 = TREE_TYPE (type2);
    6884        35236 :           if (!(VOID_TYPE_P (t1)
    6885          325 :                 && !TYPE_ATOMIC (t1)))
    6886              :            {
    6887              :              /* roles are swapped */
    6888        34912 :              t1 = t2;
    6889        34912 :              t2 = TREE_TYPE (type1);
    6890              :            }
    6891        35236 :           tree t2_stripped = strip_array_types (t2);
    6892        35236 :           if ((TREE_CODE (t2) == ARRAY_TYPE)
    6893        35236 :               && (TYPE_QUALS (t2_stripped) & ~TYPE_QUALS (t1)))
    6894              :             {
    6895           18 :               if (!flag_isoc23)
    6896            6 :                 warning_at (colon_loc, OPT_Wdiscarded_array_qualifiers,
    6897              :                             "pointer to array loses qualifier "
    6898              :                             "in conditional expression");
    6899           12 :               else if (warn_c11_c23_compat > 0)
    6900            6 :                 warning_at (colon_loc, OPT_Wc11_c23_compat,
    6901              :                             "pointer to array loses qualifier "
    6902              :                             "in conditional expression in ISO C before C23");
    6903              :             }
    6904        35236 :           if (TREE_CODE (t2) == FUNCTION_TYPE)
    6905            4 :             pedwarn (colon_loc, OPT_Wpedantic,
    6906              :                      "ISO C forbids conditional expr between "
    6907              :                      "%<void *%> and function pointer");
    6908              :           /* for array, use qualifiers of element type */
    6909        35236 :           if (flag_isoc23)
    6910        11455 :             t2 = t2_stripped;
    6911        35236 :           result_type = c_build_pointer_type (qualify_type (t1, t2));
    6912              :         }
    6913              :       /* Objective-C pointer comparisons are a bit more lenient.  */
    6914           48 :       else if (objc_have_common_type (type1, type2, -3, NULL_TREE))
    6915            0 :         result_type = objc_common_type (type1, type2);
    6916              :       else
    6917              :         {
    6918           48 :           int qual = ENCODE_QUAL_ADDR_SPACE (as_common);
    6919           48 :           enum diagnostics::kind kind = diagnostics::kind::permerror;
    6920           48 :           if (!flag_isoc99)
    6921              :             /* This downgrade to a warning ensures that -std=gnu89
    6922              :                -pedantic-errors does not flag these mismatches between
    6923              :                builtins as errors (as diagnostics::kind::permerror would)
    6924              :                ISO C99 and later do not have implicit function declarations,
    6925              :                so the mismatch cannot occur naturally there.  */
    6926            5 :             kind = (bltin1 && bltin2
    6927            5 :                     ? diagnostics::kind::warning
    6928              :                     : diagnostics::kind::pedwarn);
    6929           48 :           if (emit_diagnostic (kind, colon_loc, OPT_Wincompatible_pointer_types,
    6930              :                                "pointer type mismatch "
    6931              :                                "in conditional expression"))
    6932              :             {
    6933           46 :               inform (op1_loc, "first expression has type %qT", type1);
    6934           46 :               inform (op2_loc, "second expression has type %qT", type2);
    6935              :             }
    6936           48 :           result_type = c_build_pointer_type
    6937           48 :                           (c_build_qualified_type (void_type_node, qual));
    6938              :         }
    6939              :     }
    6940          397 :   else if (code1 == POINTER_TYPE
    6941          277 :            && (code2 == INTEGER_TYPE || code2 == BITINT_TYPE))
    6942              :     {
    6943          273 :       if (!null_pointer_constant_p (orig_op2))
    6944           14 :         permerror_opt (colon_loc, OPT_Wint_conversion,
    6945              :                        "pointer/integer type mismatch "
    6946              :                        "in conditional expression");
    6947              :       else
    6948              :         {
    6949          259 :           op2 = null_pointer_node;
    6950              :         }
    6951              :       result_type = type1;
    6952              :     }
    6953          124 :   else if (code2 == POINTER_TYPE
    6954           90 :            && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
    6955              :     {
    6956           86 :       if (!null_pointer_constant_p (orig_op1))
    6957           14 :         permerror_opt (colon_loc, OPT_Wint_conversion,
    6958              :                        "pointer/integer type mismatch "
    6959              :                        "in conditional expression");
    6960              :       else
    6961              :         {
    6962           72 :           op1 = null_pointer_node;
    6963              :         }
    6964              :       result_type = type2;
    6965              :     }
    6966              :   /* 6.5.15: "if one is a null pointer constant (other than a pointer) or has
    6967              :      type nullptr_t and the other is a pointer, the result type is the pointer
    6968              :      type."  */
    6969           38 :   else if (code1 == NULLPTR_TYPE && code2 == POINTER_TYPE)
    6970              :     result_type = type2;
    6971           34 :   else if (code1 == POINTER_TYPE && code2 == NULLPTR_TYPE)
    6972              :     result_type = type1;
    6973            8 :   else if (RECORD_OR_UNION_TYPE_P (type1) && RECORD_OR_UNION_TYPE_P (type2)
    6974           38 :            && comptypes (TYPE_MAIN_VARIANT (type1),
    6975            8 :                          TYPE_MAIN_VARIANT (type2)))
    6976            8 :     result_type = composite_type (TYPE_MAIN_VARIANT (type1),
    6977            8 :                                   TYPE_MAIN_VARIANT (type2));
    6978              : 
    6979       404732 :   if (!result_type)
    6980              :     {
    6981           22 :       if (flag_cond_mismatch)
    6982            0 :         result_type = void_type_node;
    6983              :       else
    6984              :         {
    6985           22 :           error_at (colon_loc, "type mismatch in conditional expression");
    6986           22 :           return error_mark_node;
    6987              :         }
    6988              :     }
    6989              : 
    6990              :   /* Merge const and volatile flags of the incoming types.  */
    6991       404732 :   result_type
    6992       404732 :     = build_type_variant (result_type,
    6993              :                           TYPE_READONLY (type1) || TYPE_READONLY (type2),
    6994              :                           TYPE_VOLATILE (type1) || TYPE_VOLATILE (type2));
    6995              : 
    6996       404732 :   op1 = ep_convert_and_check (colon_loc, result_type, op1,
    6997              :                               semantic_result_type);
    6998       404732 :   op2 = ep_convert_and_check (colon_loc, result_type, op2,
    6999              :                               semantic_result_type);
    7000              : 
    7001       404732 :   if (ifexp_bcp && ifexp == truthvalue_true_node)
    7002              :     {
    7003           10 :       op2_int_operands = true;
    7004           10 :       op1 = c_fully_fold (op1, require_constant_value, NULL);
    7005              :     }
    7006           59 :   if (ifexp_bcp && ifexp == truthvalue_false_node)
    7007              :     {
    7008           49 :       op1_int_operands = true;
    7009           49 :       op2 = c_fully_fold (op2, require_constant_value, NULL);
    7010              :     }
    7011       907111 :   int_const = int_operands = (ifexp_int_operands
    7012       404732 :                               && op1_int_operands
    7013       404732 :                               && op2_int_operands);
    7014        97647 :   if (int_operands)
    7015              :     {
    7016        97647 :       int_const = ((ifexp == truthvalue_true_node
    7017        59044 :                     && TREE_CODE (orig_op1) == INTEGER_CST
    7018        59030 :                     && !TREE_OVERFLOW (orig_op1))
    7019        97661 :                    || (ifexp == truthvalue_false_node
    7020        38557 :                        && TREE_CODE (orig_op2) == INTEGER_CST
    7021        38541 :                        && !TREE_OVERFLOW (orig_op2)));
    7022              :     }
    7023              : 
    7024              :   /* Need to convert condition operand into a vector mask.  */
    7025       404732 :   if (VECTOR_TYPE_P (TREE_TYPE (ifexp)))
    7026              :     {
    7027            0 :       tree vectype = TREE_TYPE (ifexp);
    7028            0 :       tree elem_type = TREE_TYPE (vectype);
    7029            0 :       tree zero = build_int_cst (elem_type, 0);
    7030            0 :       tree zero_vec = build_vector_from_val (vectype, zero);
    7031            0 :       tree cmp_type = truth_type_for (vectype);
    7032            0 :       ifexp = build2 (NE_EXPR, cmp_type, ifexp, zero_vec);
    7033              :     }
    7034              : 
    7035       404732 :   if (int_const || (ifexp_bcp && TREE_CODE (ifexp) == INTEGER_CST))
    7036        97603 :     ret = fold_build3_loc (colon_loc, COND_EXPR, result_type, ifexp, op1, op2);
    7037              :   else
    7038              :     {
    7039       307129 :       if (int_operands)
    7040              :         {
    7041              :           /* Use c_fully_fold here, since C_MAYBE_CONST_EXPR might be
    7042              :              nested inside of the expression.  */
    7043           76 :           op1 = c_fully_fold (op1, false, NULL);
    7044           76 :           op2 = c_fully_fold (op2, false, NULL);
    7045              :         }
    7046       307129 :       ret = build3 (COND_EXPR, result_type, ifexp, op1, op2);
    7047       307129 :       if (int_operands)
    7048           76 :         ret = note_integer_operands (ret);
    7049              :     }
    7050       404732 :   if (semantic_result_type)
    7051         4635 :     ret = build1 (EXCESS_PRECISION_EXPR, semantic_result_type, ret);
    7052              : 
    7053       404732 :   protected_set_expr_location (ret, colon_loc);
    7054              : 
    7055              :   /* If the OP1 and OP2 are the same and don't have side-effects,
    7056              :      warn here, because the COND_EXPR will be turned into OP1.  */
    7057       404732 :   if (warn_duplicated_branches
    7058           34 :       && TREE_CODE (ret) == COND_EXPR
    7059       404766 :       && (op1 == op2 || operand_equal_p (op1, op2, OEP_ADDRESS_OF_SAME_FIELD)))
    7060           13 :     warning_at (EXPR_LOCATION (ret), OPT_Wduplicated_branches,
    7061              :                 "this condition has identical branches");
    7062              : 
    7063              :   return ret;
    7064              : }
    7065              : 
    7066              : /* EXPR is an expression, location LOC, whose result is discarded.
    7067              :    Warn if it is a call to a nodiscard function (or a COMPOUND_EXPR
    7068              :    whose right-hand operand is such a call, possibly recursively).  */
    7069              : 
    7070              : static void
    7071      6488408 : maybe_warn_nodiscard (location_t loc, tree expr)
    7072              : {
    7073      6488408 :   if (VOID_TYPE_P (TREE_TYPE (expr)))
    7074              :     return;
    7075      3968390 :   while (TREE_CODE (expr) == COMPOUND_EXPR)
    7076              :     {
    7077        49456 :       expr = TREE_OPERAND (expr, 1);
    7078        49456 :       if (EXPR_HAS_LOCATION (expr))
    7079        32355 :         loc = EXPR_LOCATION (expr);
    7080              :     }
    7081      3918934 :   if (TREE_CODE (expr) != CALL_EXPR)
    7082              :     return;
    7083       347665 :   tree fn = CALL_EXPR_FN (expr);
    7084       347665 :   if (!fn)
    7085              :     return;
    7086       347649 :   tree attr;
    7087       347649 :   if (TREE_CODE (fn) == ADDR_EXPR
    7088       346982 :       && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
    7089       694631 :       && (attr = lookup_attribute ("nodiscard",
    7090       346982 :                                    DECL_ATTRIBUTES (TREE_OPERAND (fn, 0)))))
    7091              :     {
    7092            3 :       fn = TREE_OPERAND (fn, 0);
    7093            3 :       tree args = TREE_VALUE (attr);
    7094            3 :       if (args)
    7095            1 :         args = TREE_VALUE (args);
    7096            3 :       auto_diagnostic_group d;
    7097            3 :       auto_urlify_attributes sentinel;
    7098            3 :       int warned;
    7099            3 :       if (args)
    7100            1 :         warned = warning_at (loc, OPT_Wunused_result,
    7101              :                              "ignoring return value of %qD, declared with "
    7102              :                              "attribute %<nodiscard%>: %E", fn, args);
    7103              :       else
    7104            2 :         warned = warning_at (loc, OPT_Wunused_result,
    7105              :                              "ignoring return value of %qD, declared with "
    7106              :                              "attribute %<nodiscard%>", fn);
    7107            3 :       if (warned)
    7108            3 :         inform (DECL_SOURCE_LOCATION (fn), "declared here");
    7109            3 :     }
    7110              :   else
    7111              :     {
    7112       347646 :       tree rettype = TREE_TYPE (TREE_TYPE (TREE_TYPE (fn)));
    7113       347646 :       attr = lookup_attribute ("nodiscard", TYPE_ATTRIBUTES (rettype));
    7114       347646 :       if (!attr)
    7115       347634 :         return;
    7116           12 :       tree args = TREE_VALUE (attr);
    7117           12 :       if (args)
    7118            5 :         args = TREE_VALUE (args);
    7119           12 :       auto_diagnostic_group d;
    7120           12 :       auto_urlify_attributes sentinel;
    7121           12 :       int warned;
    7122           12 :       if (args)
    7123            5 :         warned = warning_at (loc, OPT_Wunused_result,
    7124              :                              "ignoring return value of type %qT, declared "
    7125              :                              "with attribute %<nodiscard%>: %E",
    7126              :                              rettype, args);
    7127              :       else
    7128            7 :         warned = warning_at (loc, OPT_Wunused_result,
    7129              :                              "ignoring return value of type %qT, declared "
    7130              :                              "with attribute %<nodiscard%>", rettype);
    7131           12 :       if (warned)
    7132              :         {
    7133           12 :           if (TREE_CODE (fn) == ADDR_EXPR)
    7134              :             {
    7135           11 :               fn = TREE_OPERAND (fn, 0);
    7136           11 :               if (TREE_CODE (fn) == FUNCTION_DECL)
    7137           11 :                 inform (DECL_SOURCE_LOCATION (fn),
    7138              :                         "in call to %qD, declared here", fn);
    7139              :             }
    7140              :         }
    7141           12 :     }
    7142              : }
    7143              : 
    7144              : /* Return a compound expression that performs two expressions and
    7145              :    returns the value of the second of them.
    7146              : 
    7147              :    LOC is the location of the COMPOUND_EXPR.  */
    7148              : 
    7149              : tree
    7150       111824 : build_compound_expr (location_t loc, tree expr1, tree expr2)
    7151              : {
    7152       111824 :   bool expr1_int_operands, expr2_int_operands;
    7153       111824 :   tree eptype = NULL_TREE;
    7154       111824 :   tree ret;
    7155              : 
    7156       111824 :   expr1_int_operands = EXPR_INT_CONST_OPERANDS (expr1);
    7157          326 :   if (expr1_int_operands)
    7158          326 :     expr1 = remove_c_maybe_const_expr (expr1);
    7159       111824 :   expr2_int_operands = EXPR_INT_CONST_OPERANDS (expr2);
    7160        66113 :   if (expr2_int_operands)
    7161        66113 :     expr2 = remove_c_maybe_const_expr (expr2);
    7162              : 
    7163       111824 :   if (TREE_CODE (expr1) == EXCESS_PRECISION_EXPR)
    7164            0 :     expr1 = TREE_OPERAND (expr1, 0);
    7165       111824 :   if (TREE_CODE (expr2) == EXCESS_PRECISION_EXPR)
    7166              :     {
    7167            1 :       eptype = TREE_TYPE (expr2);
    7168            1 :       expr2 = TREE_OPERAND (expr2, 0);
    7169              :     }
    7170              : 
    7171       111824 :   if (!TREE_SIDE_EFFECTS (expr1))
    7172              :     {
    7173              :       /* The left-hand operand of a comma expression is like an expression
    7174              :          statement: with -Wunused, we should warn if it doesn't have
    7175              :          any side-effects, unless it was explicitly cast to (void).  */
    7176         8426 :       if (warn_unused_value)
    7177              :         {
    7178         1277 :           if (VOID_TYPE_P (TREE_TYPE (expr1))
    7179         1277 :               && CONVERT_EXPR_P (expr1))
    7180              :             ; /* (void) a, b */
    7181           14 :           else if (VOID_TYPE_P (TREE_TYPE (expr1))
    7182            4 :                    && TREE_CODE (expr1) == COMPOUND_EXPR
    7183           17 :                    && CONVERT_EXPR_P (TREE_OPERAND (expr1, 1)))
    7184              :             ; /* (void) a, (void) b, c */
    7185              :           else
    7186           11 :             warning_at (loc, OPT_Wunused_value,
    7187              :                         "left-hand operand of comma expression has no effect");
    7188              :         }
    7189              :     }
    7190       103398 :   else if (TREE_CODE (expr1) == COMPOUND_EXPR
    7191        13111 :            && warn_unused_value)
    7192              :     {
    7193              :       tree r = expr1;
    7194              :       location_t cloc = loc;
    7195         4833 :       while (TREE_CODE (r) == COMPOUND_EXPR)
    7196              :         {
    7197         2417 :           if (EXPR_HAS_LOCATION (r))
    7198         2417 :             cloc = EXPR_LOCATION (r);
    7199         2417 :           r = TREE_OPERAND (r, 1);
    7200              :         }
    7201         2416 :       if (!TREE_SIDE_EFFECTS (r)
    7202            4 :           && !VOID_TYPE_P (TREE_TYPE (r))
    7203         2420 :           && !CONVERT_EXPR_P (r))
    7204            4 :         warning_at (cloc, OPT_Wunused_value,
    7205              :                     "right-hand operand of comma expression has no effect");
    7206              :     }
    7207              : 
    7208              :   /* With -Wunused, we should also warn if the left-hand operand does have
    7209              :      side-effects, but computes a value which is not used.  For example, in
    7210              :      `foo() + bar(), baz()' the result of the `+' operator is not used,
    7211              :      so we should issue a warning.  */
    7212       100982 :   else if (warn_unused_value)
    7213        35407 :     warn_if_unused_value (expr1, loc);
    7214              : 
    7215       111824 :   maybe_warn_nodiscard (loc, expr1);
    7216              : 
    7217       111824 :   if (expr2 == error_mark_node)
    7218              :     return error_mark_node;
    7219              : 
    7220       111811 :   ret = build2 (COMPOUND_EXPR, TREE_TYPE (expr2), expr1, expr2);
    7221              : 
    7222       111811 :   if (flag_isoc99
    7223              :       && expr1_int_operands
    7224       111355 :       && expr2_int_operands)
    7225          153 :     ret = note_integer_operands (ret);
    7226              : 
    7227       111811 :   if (eptype)
    7228            1 :     ret = build1 (EXCESS_PRECISION_EXPR, eptype, ret);
    7229              : 
    7230       111811 :   protected_set_expr_location (ret, loc);
    7231       111811 :   return ret;
    7232              : }
    7233              : 
    7234              : /* Issue -Wcast-qual warnings when appropriate.  TYPE is the type to
    7235              :    which we are casting.  OTYPE is the type of the expression being
    7236              :    cast.  Both TYPE and OTYPE are pointer types.  LOC is the location
    7237              :    of the cast.  -Wcast-qual appeared on the command line.  Named
    7238              :    address space qualifiers are not handled here, because they result
    7239              :    in different warnings.  */
    7240              : 
    7241              : static void
    7242        13581 : handle_warn_cast_qual (location_t loc, tree type, tree otype)
    7243              : {
    7244        13581 :   tree in_type = type;
    7245        13581 :   tree in_otype = otype;
    7246        13581 :   int added = 0;
    7247        13581 :   int discarded = 0;
    7248        13751 :   bool is_const;
    7249              : 
    7250              :   /* Check that the qualifiers on IN_TYPE are a superset of the
    7251              :      qualifiers of IN_OTYPE.  The outermost level of POINTER_TYPE
    7252              :      nodes is uninteresting and we stop as soon as we hit a
    7253              :      non-POINTER_TYPE node on either type.  */
    7254        13751 :   do
    7255              :     {
    7256        13751 :       in_otype = TREE_TYPE (in_otype);
    7257        13751 :       in_type = TREE_TYPE (in_type);
    7258              : 
    7259              :       /* GNU C allows cv-qualified function types.  'const' means the
    7260              :          function is very pure, 'volatile' means it can't return.  We
    7261              :          need to warn when such qualifiers are added, not when they're
    7262              :          taken away.  */
    7263        13751 :       if (TREE_CODE (in_otype) == FUNCTION_TYPE
    7264           26 :           && TREE_CODE (in_type) == FUNCTION_TYPE)
    7265           18 :         added |= (TYPE_QUALS_NO_ADDR_SPACE (in_type)
    7266           18 :                   & ~TYPE_QUALS_NO_ADDR_SPACE (in_otype));
    7267              :       else
    7268        13733 :         discarded |= (TYPE_QUALS_NO_ADDR_SPACE (in_otype)
    7269        13733 :                       & ~TYPE_QUALS_NO_ADDR_SPACE (in_type));
    7270              :     }
    7271        13751 :   while (TREE_CODE (in_type) == POINTER_TYPE
    7272        13751 :          && TREE_CODE (in_otype) == POINTER_TYPE);
    7273              : 
    7274        13581 :   if (added)
    7275            2 :     warning_at (loc, OPT_Wcast_qual,
    7276              :                 "cast adds %q#v qualifier to function type", added);
    7277              : 
    7278        13581 :   if (discarded)
    7279              :     /* There are qualifiers present in IN_OTYPE that are not present
    7280              :        in IN_TYPE.  */
    7281         1117 :     warning_at (loc, OPT_Wcast_qual,
    7282              :                 "cast discards %qv qualifier from pointer target type",
    7283              :                 discarded);
    7284              : 
    7285        13581 :   if (added || discarded)
    7286              :     return;
    7287              : 
    7288              :   /* A cast from **T to const **T is unsafe, because it can cause a
    7289              :      const value to be changed with no additional warning.  We only
    7290              :      issue this warning if T is the same on both sides, and we only
    7291              :      issue the warning if there are the same number of pointers on
    7292              :      both sides, as otherwise the cast is clearly unsafe anyhow.  A
    7293              :      cast is unsafe when a qualifier is added at one level and const
    7294              :      is not present at all outer levels.
    7295              : 
    7296              :      To issue this warning, we check at each level whether the cast
    7297              :      adds new qualifiers not already seen.  We don't need to special
    7298              :      case function types, as they won't have the same
    7299              :      TYPE_MAIN_VARIANT.  */
    7300              : 
    7301        12462 :   if (TYPE_MAIN_VARIANT (in_type) != TYPE_MAIN_VARIANT (in_otype))
    7302              :     return;
    7303          227 :   if (TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE)
    7304              :     return;
    7305              : 
    7306           48 :   in_type = type;
    7307           48 :   in_otype = otype;
    7308           48 :   is_const = TYPE_READONLY (TREE_TYPE (in_type));
    7309          130 :   do
    7310              :     {
    7311          130 :       in_type = TREE_TYPE (in_type);
    7312          130 :       in_otype = TREE_TYPE (in_otype);
    7313          130 :       if ((TYPE_QUALS (in_type) &~ TYPE_QUALS (in_otype)) != 0
    7314          130 :           && !is_const)
    7315              :         {
    7316           27 :           warning_at (loc, OPT_Wcast_qual,
    7317              :                       "to be safe all intermediate pointers in cast from "
    7318              :                       "%qT to %qT must be %<const%> qualified",
    7319              :                       otype, type);
    7320           27 :           break;
    7321              :         }
    7322          103 :       if (is_const)
    7323           72 :         is_const = TYPE_READONLY (in_type);
    7324              :     }
    7325          103 :   while (TREE_CODE (in_type) == POINTER_TYPE);
    7326              : }
    7327              : 
    7328              : /* Heuristic check if two parameter types can be considered ABI-equivalent.  */
    7329              : 
    7330              : static bool
    7331         1312 : c_safe_arg_type_equiv_p (tree t1, tree t2)
    7332              : {
    7333         1312 :   if (error_operand_p (t1) || error_operand_p (t2))
    7334              :     return true;
    7335              : 
    7336         1311 :   t1 = TYPE_MAIN_VARIANT (t1);
    7337         1311 :   t2 = TYPE_MAIN_VARIANT (t2);
    7338              : 
    7339         1311 :   if (TREE_CODE (t1) == POINTER_TYPE
    7340          229 :       && TREE_CODE (t2) == POINTER_TYPE)
    7341              :     return true;
    7342              : 
    7343              :   /* Only the precision of the parameter matters.  This check should
    7344              :      make sure that the callee does not see undefined values in argument
    7345              :      registers.  */
    7346         1103 :   if (INTEGRAL_TYPE_P (t1)
    7347          913 :       && INTEGRAL_TYPE_P (t2)
    7348         1448 :       && TYPE_PRECISION (t1) == TYPE_PRECISION (t2))
    7349              :     return true;
    7350              : 
    7351          938 :   return comptypes (t1, t2);
    7352              : }
    7353              : 
    7354              : /* Check if a type cast between two function types can be considered safe.  */
    7355              : 
    7356              : static bool
    7357         7559 : c_safe_function_type_cast_p (tree t1, tree t2)
    7358              : {
    7359         7559 :   if (TREE_TYPE (t1) == void_type_node &&
    7360         5561 :       TYPE_ARG_TYPES (t1) == void_list_node)
    7361              :     return true;
    7362              : 
    7363         3722 :   if (TREE_TYPE (t2) == void_type_node &&
    7364         2889 :       TYPE_ARG_TYPES (t2) == void_list_node)
    7365              :     return true;
    7366              : 
    7367          892 :   if (!c_safe_arg_type_equiv_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    7368              :     return false;
    7369              : 
    7370          197 :   for (t1 = TYPE_ARG_TYPES (t1), t2 = TYPE_ARG_TYPES (t2);
    7371          513 :        t1 && t2;
    7372          316 :        t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
    7373          420 :     if (!c_safe_arg_type_equiv_p (TREE_VALUE (t1), TREE_VALUE (t2)))
    7374              :       return false;
    7375              : 
    7376              :   return true;
    7377              : }
    7378              : 
    7379              : /* Build an expression representing a cast to type TYPE of expression EXPR.
    7380              :    LOC is the location of the cast-- typically the open paren of the cast.  */
    7381              : 
    7382              : tree
    7383    120255146 : build_c_cast (location_t loc, tree type, tree expr)
    7384              : {
    7385    120255146 :   tree value;
    7386              : 
    7387    120255146 :   bool int_operands = EXPR_INT_CONST_OPERANDS (expr);
    7388              : 
    7389    120255146 :   if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
    7390           66 :     expr = TREE_OPERAND (expr, 0);
    7391              : 
    7392    120255146 :   value = expr;
    7393    120255146 :   if (int_operands)
    7394      6873707 :     value = remove_c_maybe_const_expr (value);
    7395              : 
    7396    120255146 :   if (type == error_mark_node || expr == error_mark_node)
    7397              :     return error_mark_node;
    7398              : 
    7399              :   /* The ObjC front-end uses TYPE_MAIN_VARIANT to tie together types differing
    7400              :      only in <protocol> qualifications.  But when constructing cast expressions,
    7401              :      the protocols do matter and must be kept around.  */
    7402    120254126 :   if (objc_is_object_ptr (type) && objc_is_object_ptr (TREE_TYPE (expr)))
    7403            0 :     return build1 (NOP_EXPR, type, expr);
    7404              : 
    7405    120254126 :   type = TYPE_MAIN_VARIANT (type);
    7406              : 
    7407    120254126 :   if (TREE_CODE (type) == ARRAY_TYPE)
    7408              :     {
    7409           13 :       error_at (loc, "cast specifies array type");
    7410           13 :       return error_mark_node;
    7411              :     }
    7412              : 
    7413    120254113 :   if (TREE_CODE (type) == FUNCTION_TYPE)
    7414              :     {
    7415            6 :       error_at (loc, "cast specifies function type");
    7416            6 :       return error_mark_node;
    7417              :     }
    7418              : 
    7419    120254107 :   if (!VOID_TYPE_P (type))
    7420              :     {
    7421    120209575 :       value = require_complete_type (loc, value);
    7422    120209575 :       if (value == error_mark_node)
    7423              :         return error_mark_node;
    7424              :     }
    7425              : 
    7426    120254106 :   if (type == TYPE_MAIN_VARIANT (TREE_TYPE (value)))
    7427              :     {
    7428     18121631 :       if (RECORD_OR_UNION_TYPE_P (type)
    7429     18121631 :           && pedwarn (loc, OPT_Wpedantic,
    7430              :                       "ISO C forbids casting nonscalar to the same type"))
    7431              :               ;
    7432     18121627 :       else if (warn_useless_cast && c_inhibit_evaluation_warnings == 0)
    7433            8 :         warning_at (loc, OPT_Wuseless_cast,
    7434              :                     "useless cast to type %qT", type);
    7435              : 
    7436              :       /* Convert to remove any qualifiers from VALUE's type.  */
    7437     18121631 :       value = convert (type, value);
    7438              :     }
    7439    102132475 :   else if (TREE_CODE (type) == UNION_TYPE)
    7440              :     {
    7441          137 :       tree field;
    7442              : 
    7443          192 :       for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    7444          185 :         if (TREE_TYPE (field) != error_mark_node
    7445          369 :             && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field)),
    7446          184 :                           TYPE_MAIN_VARIANT (TREE_TYPE (value))))
    7447              :           break;
    7448              : 
    7449          137 :       if (field)
    7450              :         {
    7451          130 :           tree t;
    7452          130 :           bool maybe_const = true;
    7453              : 
    7454          130 :           pedwarn (loc, OPT_Wpedantic, "ISO C forbids casts to union type");
    7455          130 :           t = c_fully_fold (value, false, &maybe_const);
    7456          130 :           t = build_constructor_single (type, field, t);
    7457          130 :           if (!maybe_const)
    7458           15 :             t = c_wrap_maybe_const (t, true);
    7459          130 :           t = digest_init (loc, field, type, t,
    7460              :                            NULL_TREE, false, false, false, true, false, false);
    7461          130 :           TREE_CONSTANT (t) = TREE_CONSTANT (value);
    7462          130 :           return t;
    7463              :         }
    7464            7 :       error_at (loc, "cast to union type from type not present in union");
    7465            7 :       return error_mark_node;
    7466              :     }
    7467              :   else
    7468              :     {
    7469    102132338 :       tree otype, ovalue;
    7470              : 
    7471    102132338 :       if (type == void_type_node)
    7472              :         {
    7473        18562 :           tree t = build1 (CONVERT_EXPR, type, value);
    7474        18562 :           SET_EXPR_LOCATION (t, loc);
    7475        18562 :           return t;
    7476              :         }
    7477              : 
    7478    102113776 :       otype = TREE_TYPE (value);
    7479              : 
    7480              :       /* Optionally warn about potentially worrisome casts.  */
    7481    102113776 :       if (warn_cast_qual
    7482       179871 :           && TREE_CODE (type) == POINTER_TYPE
    7483        26837 :           && TREE_CODE (otype) == POINTER_TYPE)
    7484        13581 :         handle_warn_cast_qual (loc, type, otype);
    7485              : 
    7486              :       /* Warn about conversions between pointers to disjoint
    7487              :          address spaces.  */
    7488    102113776 :       if (TREE_CODE (type) == POINTER_TYPE
    7489      3335144 :           && TREE_CODE (otype) == POINTER_TYPE
    7490    105102330 :           && !null_pointer_constant_p (value))
    7491              :         {
    7492      2934693 :           addr_space_t as_to = TYPE_ADDR_SPACE (TREE_TYPE (type));
    7493      2934693 :           addr_space_t as_from = TYPE_ADDR_SPACE (TREE_TYPE (otype));
    7494      2934693 :           addr_space_t as_common;
    7495              : 
    7496      2934693 :           if (!addr_space_superset (as_to, as_from, &as_common))
    7497              :             {
    7498            0 :               if (ADDR_SPACE_GENERIC_P (as_from))
    7499            0 :                 warning_at (loc, 0, "cast to %qs address space pointer "
    7500              :                             "from disjoint generic address space pointer",
    7501              :                             c_addr_space_name (as_to));
    7502              : 
    7503            0 :               else if (ADDR_SPACE_GENERIC_P (as_to))
    7504            0 :                 warning_at (loc, 0, "cast to generic address space pointer "
    7505              :                             "from disjoint %qs address space pointer",
    7506              :                             c_addr_space_name (as_from));
    7507              : 
    7508              :               else
    7509            0 :                 warning_at (loc, 0, "cast to %qs address space pointer "
    7510              :                             "from disjoint %qs address space pointer",
    7511              :                             c_addr_space_name (as_to),
    7512              :                             c_addr_space_name (as_from));
    7513              :             }
    7514              : 
    7515              :           /* Warn of new allocations that are not big enough for the target
    7516              :              type.  */
    7517      2934693 :           if (warn_alloc_size && TREE_CODE (value) == CALL_EXPR)
    7518         1069 :             if (tree fndecl = get_callee_fndecl (value))
    7519         1065 :               if (DECL_IS_MALLOC (fndecl))
    7520              :                 {
    7521          573 :                   tree attrs = TYPE_ATTRIBUTES (TREE_TYPE (fndecl));
    7522          573 :                   tree alloc_size = lookup_attribute ("alloc_size", attrs);
    7523          573 :                   if (alloc_size)
    7524          215 :                     warn_for_alloc_size (loc, TREE_TYPE (type), value,
    7525              :                                          alloc_size);
    7526              :                 }
    7527              :         }
    7528              : 
    7529              :       /* Warn about possible alignment problems.  */
    7530    102113776 :       if ((STRICT_ALIGNMENT || warn_cast_align == 2)
    7531            7 :           && TREE_CODE (type) == POINTER_TYPE
    7532            7 :           && TREE_CODE (otype) == POINTER_TYPE
    7533            7 :           && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE
    7534            7 :           && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
    7535              :           /* Don't warn about opaque types, where the actual alignment
    7536              :              restriction is unknown.  */
    7537           12 :           && !(RECORD_OR_UNION_TYPE_P (TREE_TYPE (otype))
    7538            5 :                && TYPE_MODE (TREE_TYPE (otype)) == VOIDmode)
    7539    102113790 :           && min_align_of_type (TREE_TYPE (type))
    7540            7 :              > min_align_of_type (TREE_TYPE (otype)))
    7541            5 :         warning_at (loc, OPT_Wcast_align,
    7542              :                     "cast increases required alignment of target type");
    7543              : 
    7544    102113776 :       if ((TREE_CODE (type) == INTEGER_TYPE
    7545    102113776 :            || TREE_CODE (type) == BITINT_TYPE)
    7546      7088766 :           && TREE_CODE (otype) == POINTER_TYPE
    7547    102139070 :           && TYPE_PRECISION (type) != TYPE_PRECISION (otype))
    7548              :       /* Unlike conversion of integers to pointers, where the
    7549              :          warning is disabled for converting constants because
    7550              :          of cases such as SIG_*, warn about converting constant
    7551              :          pointers to integers. In some cases it may cause unwanted
    7552              :          sign extension, and a warning is appropriate.  */
    7553         1450 :         warning_at (loc, OPT_Wpointer_to_int_cast,
    7554              :                     "cast from pointer to integer of different size");
    7555              : 
    7556    102113776 :       if ((TREE_CODE (value) == CALL_EXPR
    7557     34668164 :            && !is_access_with_size_p (value))
    7558    136781936 :           && TREE_CODE (type) != TREE_CODE (otype))
    7559         2306 :         warning_at (loc, OPT_Wbad_function_cast,
    7560              :                     "cast from function call of type %qT "
    7561              :                     "to non-matching type %qT", otype, type);
    7562              : 
    7563    102113776 :       if (TREE_CODE (type) == POINTER_TYPE
    7564      3335144 :           && (TREE_CODE (otype) == INTEGER_TYPE
    7565      3335144 :               || TREE_CODE (otype) == BITINT_TYPE)
    7566       346504 :           && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
    7567              :           /* Don't warn about converting any constant.  */
    7568    102422489 :           && !TREE_CONSTANT (value))
    7569          407 :         warning_at (loc,
    7570          407 :                     OPT_Wint_to_pointer_cast, "cast to pointer from integer "
    7571              :                     "of different size");
    7572              : 
    7573    102113776 :       if (warn_strict_aliasing <= 2)
    7574     93577883 :         strict_aliasing_warning (EXPR_LOCATION (value), type, expr);
    7575              : 
    7576              :       /* If pedantic, warn for conversions between function and object
    7577              :          pointer types, except for converting a null pointer constant
    7578              :          to function pointer type.  */
    7579    102113776 :       if (pedantic
    7580       238453 :           && TREE_CODE (type) == POINTER_TYPE
    7581       143951 :           && TREE_CODE (otype) == POINTER_TYPE
    7582         2620 :           && TREE_CODE (TREE_TYPE (otype)) == FUNCTION_TYPE
    7583    102113797 :           && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE)
    7584           18 :         pedwarn (loc, OPT_Wpedantic, "ISO C forbids "
    7585              :                  "conversion of function pointer to object pointer type");
    7586              : 
    7587    102113776 :       if (pedantic
    7588       238453 :           && TREE_CODE (type) == POINTER_TYPE
    7589       143951 :           && TREE_CODE (otype) == POINTER_TYPE
    7590         2620 :           && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
    7591           13 :           && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
    7592    102113786 :           && !null_pointer_constant_p (value))
    7593            4 :         pedwarn (loc, OPT_Wpedantic, "ISO C forbids "
    7594              :                  "conversion of object pointer to function pointer type");
    7595              : 
    7596    102113776 :       if (TREE_CODE (type) == POINTER_TYPE
    7597      3335144 :           && TREE_CODE (otype) == POINTER_TYPE
    7598      2988554 :           && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
    7599         8680 :           && TREE_CODE (TREE_TYPE (otype)) == FUNCTION_TYPE
    7600    102121335 :           && !c_safe_function_type_cast_p (TREE_TYPE (type),
    7601         7559 :                                            TREE_TYPE (otype)))
    7602          799 :         warning_at (loc, OPT_Wcast_function_type,
    7603              :                     "cast between incompatible function types"
    7604              :                     " from %qT to %qT", otype, type);
    7605              : 
    7606    102113776 :       ovalue = value;
    7607              :       /* If converting to boolean a value with integer operands that
    7608              :          is not itself represented as an INTEGER_CST, the call below
    7609              :          to note_integer_operands may insert a C_MAYBE_CONST_EXPR, but
    7610              :          build_binary_op as called by c_common_truthvalue_conversion
    7611              :          may also insert a C_MAYBE_CONST_EXPR to indicate that a
    7612              :          subexpression has been fully folded.  To avoid nested
    7613              :          C_MAYBE_CONST_EXPR, ensure that
    7614              :          c_objc_common_truthvalue_conversion receives an argument
    7615              :          properly marked as having integer operands in that case.  */
    7616    102113776 :       if (int_operands
    7617      6683395 :           && TREE_CODE (value) != INTEGER_CST
    7618    102113818 :           && (TREE_CODE (type) == BOOLEAN_TYPE
    7619           28 :               || (TREE_CODE (type) == ENUMERAL_TYPE
    7620           14 :                   && ENUM_UNDERLYING_TYPE (type) != NULL_TREE
    7621           14 :                   && TREE_CODE (ENUM_UNDERLYING_TYPE (type)) == BOOLEAN_TYPE)))
    7622           28 :         value = note_integer_operands (value);
    7623    102113776 :       value = convert (type, value);
    7624              : 
    7625              :       /* Ignore any integer overflow caused by the cast.  */
    7626    102113776 :       if (TREE_CODE (value) == INTEGER_CST && !FLOAT_TYPE_P (otype))
    7627              :         {
    7628      6630060 :           if (TREE_OVERFLOW_P (ovalue))
    7629              :             {
    7630            9 :               if (!TREE_OVERFLOW (value))
    7631              :                 {
    7632              :                   /* Avoid clobbering a shared constant.  */
    7633            0 :                   value = copy_node (value);
    7634            0 :                   TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue);
    7635              :                 }
    7636              :             }
    7637      6630051 :           else if (TREE_OVERFLOW (value))
    7638              :             /* Reset VALUE's overflow flags, ensuring constant sharing.  */
    7639         3093 :             value = wide_int_to_tree (TREE_TYPE (value), wi::to_wide (value));
    7640              :         }
    7641              :     }
    7642              : 
    7643              :   /* Don't let a cast be an lvalue.  */
    7644    120235407 :   if (lvalue_p (value))
    7645        90678 :     value = non_lvalue_loc (loc, value);
    7646              : 
    7647              :   /* Don't allow the results of casting to floating-point or complex
    7648              :      types be confused with actual constants, or casts involving
    7649              :      integer and pointer types other than direct integer-to-integer
    7650              :      and integer-to-pointer be confused with integer constant
    7651              :      expressions and null pointer constants.  */
    7652    120235407 :   if (TREE_CODE (value) == REAL_CST
    7653    120185464 :       || TREE_CODE (value) == COMPLEX_CST
    7654    240398248 :       || (TREE_CODE (value) == INTEGER_CST
    7655      6879090 :           && !((TREE_CODE (expr) == INTEGER_CST
    7656      6805489 :                 && INTEGRAL_TYPE_P (TREE_TYPE (expr)))
    7657        66198 :                || TREE_CODE (expr) == REAL_CST
    7658              :                || TREE_CODE (expr) == COMPLEX_CST)))
    7659       134397 :       value = build1 (NOP_EXPR, type, value);
    7660              : 
    7661              :   /* If the expression has integer operands and so can occur in an
    7662              :      unevaluated part of an integer constant expression, ensure the
    7663              :      return value reflects this.  */
    7664    120235407 :   if (int_operands
    7665      6859763 :       && INTEGRAL_TYPE_P (type)
    7666      6413584 :       && value != error_mark_node
    7667    126648990 :       && !EXPR_INT_CONST_OPERANDS (value))
    7668           11 :     value = note_integer_operands (value);
    7669              : 
    7670    120235407 :   protected_set_expr_location (value, loc);
    7671    120235407 :   return value;
    7672              : }
    7673              : 
    7674              : /* Interpret a cast of expression EXPR to type TYPE.  LOC is the
    7675              :    location of the open paren of the cast, or the position of the cast
    7676              :    expr.  */
    7677              : tree
    7678    120254650 : c_cast_expr (location_t loc, struct c_type_name *type_name, tree expr)
    7679              : {
    7680    120254650 :   tree type;
    7681    120254650 :   tree type_expr = NULL_TREE;
    7682    120254650 :   bool type_expr_const = true;
    7683    120254650 :   tree ret;
    7684    120254650 :   int saved_wsp = warn_strict_prototypes;
    7685              : 
    7686              :   /* This avoids warnings about unprototyped casts on
    7687              :      integers.  E.g. "#define SIG_DFL (void(*)())0".  */
    7688    120254650 :   if (TREE_CODE (expr) == INTEGER_CST)
    7689      6927679 :     warn_strict_prototypes = 0;
    7690    120254650 :   type = groktypename (type_name, &type_expr, &type_expr_const);
    7691    120254650 :   warn_strict_prototypes = saved_wsp;
    7692              : 
    7693       765020 :   if (TREE_CODE (expr) == ADDR_EXPR && !VOID_TYPE_P (type)
    7694    121019415 :       && reject_gcc_builtin (expr))
    7695            2 :     return error_mark_node;
    7696              : 
    7697    120254648 :   ret = build_c_cast (loc, type, expr);
    7698    120254648 :   if (ret == error_mark_node)
    7699              :     return error_mark_node;
    7700              : 
    7701    120253488 :   if (type_expr)
    7702              :     {
    7703          250 :       bool inner_expr_const = true;
    7704          250 :       ret = c_fully_fold (ret, require_constant_value, &inner_expr_const);
    7705          250 :       ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret), type_expr, ret);
    7706          500 :       C_MAYBE_CONST_EXPR_NON_CONST (ret) = !(type_expr_const
    7707          145 :                                              && inner_expr_const);
    7708          250 :       SET_EXPR_LOCATION (ret, loc);
    7709              :     }
    7710              : 
    7711    120253488 :   if (!EXPR_HAS_LOCATION (ret))
    7712      6806013 :     protected_set_expr_location (ret, loc);
    7713              : 
    7714              :   /* C++ does not permits types to be defined in a cast, but it
    7715              :      allows references to incomplete types.  */
    7716    120253488 :   if (warn_cxx_compat && type_name->specs->typespec_kind == ctsk_tagdef)
    7717            1 :     warning_at (loc, OPT_Wc___compat,
    7718              :                 "defining a type in a cast is invalid in C++");
    7719              : 
    7720              :   return ret;
    7721              : }
    7722              : 
    7723              : /* Build an assignment expression of lvalue LHS from value RHS.
    7724              :    If LHS_ORIGTYPE is not NULL, it is the original type of LHS, which
    7725              :    may differ from TREE_TYPE (LHS) for an enum bitfield.
    7726              :    MODIFYCODE is the code for a binary operator that we use
    7727              :    to combine the old value of LHS with RHS to get the new value.
    7728              :    Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
    7729              :    If RHS_ORIGTYPE is not NULL_TREE, it is the original type of RHS,
    7730              :    which may differ from TREE_TYPE (RHS) for an enum value.
    7731              : 
    7732              :    LOCATION is the location of the MODIFYCODE operator.
    7733              :    RHS_LOC is the location of the RHS.  */
    7734              : 
    7735              : tree
    7736      2906968 : build_modify_expr (location_t location, tree lhs, tree lhs_origtype,
    7737              :                    enum tree_code modifycode,
    7738              :                    location_t rhs_loc, tree rhs, tree rhs_origtype)
    7739              : {
    7740      2906968 :   tree result;
    7741      2906968 :   tree newrhs;
    7742      2906968 :   tree rhseval = NULL_TREE;
    7743      2906968 :   tree lhstype = TREE_TYPE (lhs);
    7744      2906968 :   tree olhstype = lhstype;
    7745      2906968 :   bool npc;
    7746      2906968 :   bool is_atomic_op;
    7747              : 
    7748              :   /* Types that aren't fully specified cannot be used in assignments.  */
    7749      2906968 :   lhs = require_complete_type (location, lhs);
    7750      2906968 :   rhs = require_complete_type (location, rhs);
    7751              : 
    7752              :   /* Avoid duplicate error messages from operands that had errors.  */
    7753      2906968 :   if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK)
    7754          473 :     return error_mark_node;
    7755              : 
    7756              :   /* Ensure an error for assigning a non-lvalue array to an array in
    7757              :      C90.  */
    7758      2906495 :   if (TREE_CODE (lhstype) == ARRAY_TYPE)
    7759              :     {
    7760            1 :       error_at (location, "assignment to expression with array type");
    7761            1 :       return error_mark_node;
    7762              :     }
    7763              : 
    7764              :   /* For ObjC properties, defer this check.  */
    7765      2906494 :   if (!objc_is_property_ref (lhs) && !lvalue_or_else (location, lhs, lv_assign))
    7766           32 :     return error_mark_node;
    7767              : 
    7768      2906462 :   is_atomic_op = really_atomic_lvalue (lhs);
    7769              : 
    7770      2906462 :   newrhs = rhs;
    7771              : 
    7772      2906462 :   if (TREE_CODE (lhs) == C_MAYBE_CONST_EXPR)
    7773              :     {
    7774            2 :       tree inner = build_modify_expr (location, C_MAYBE_CONST_EXPR_EXPR (lhs),
    7775              :                                       lhs_origtype, modifycode, rhs_loc, rhs,
    7776              :                                       rhs_origtype);
    7777            2 :       if (inner == error_mark_node)
    7778              :         return error_mark_node;
    7779            4 :       result = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner),
    7780            2 :                        C_MAYBE_CONST_EXPR_PRE (lhs), inner);
    7781            2 :       gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (lhs));
    7782            2 :       C_MAYBE_CONST_EXPR_NON_CONST (result) = 1;
    7783            2 :       protected_set_expr_location (result, location);
    7784            2 :       return result;
    7785              :     }
    7786              : 
    7787              :   /* If a binary op has been requested, combine the old LHS value with the RHS
    7788              :      producing the value we should actually store into the LHS.  */
    7789              : 
    7790      2906460 :   if (modifycode != NOP_EXPR)
    7791              :     {
    7792       215655 :       lhs = c_fully_fold (lhs, false, NULL, true);
    7793       215655 :       lhs = stabilize_reference (lhs);
    7794              : 
    7795              :       /* Construct the RHS for any non-atomic compound assignment. */
    7796       215655 :       if (!is_atomic_op)
    7797              :         {
    7798              :           /* If in LHS op= RHS the RHS has side-effects, ensure they
    7799              :              are preevaluated before the rest of the assignment expression's
    7800              :              side-effects, because RHS could contain e.g. function calls
    7801              :              that modify LHS.  */
    7802       200170 :           if (TREE_SIDE_EFFECTS (rhs))
    7803              :             {
    7804         8816 :               if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
    7805           28 :                 newrhs = save_expr (TREE_OPERAND (rhs, 0));
    7806              :               else
    7807         8788 :                 newrhs = save_expr (rhs);
    7808         8816 :               rhseval = newrhs;
    7809         8816 :               if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
    7810           28 :                 newrhs = build1 (EXCESS_PRECISION_EXPR, TREE_TYPE (rhs),
    7811              :                                  newrhs);
    7812              :             }
    7813       200170 :           bool clear_decl_read = false;
    7814        88537 :           if ((VAR_P (lhs) || TREE_CODE (lhs) == PARM_DECL)
    7815       153801 :               && !DECL_READ_P (lhs)
    7816       252572 :               && (VAR_P (lhs) ? warn_unused_but_set_variable
    7817              :                               : warn_unused_but_set_parameter) > 2)
    7818              :             {
    7819        21598 :               mark_exp_read (newrhs);
    7820        21598 :               if (!DECL_READ_P (lhs))
    7821       200170 :                 clear_decl_read = true;
    7822              :             }
    7823              : 
    7824       200170 :           newrhs = build_binary_op (location, modifycode,
    7825              :                                     convert_lvalue_to_rvalue (location, lhs,
    7826              :                                                               true, true),
    7827              :                                     newrhs, true);
    7828       200170 :           if (clear_decl_read)
    7829        21598 :             DECL_READ_P (lhs) = 0;
    7830              : 
    7831              :           /* The original type of the right hand side is no longer
    7832              :              meaningful.  */
    7833              :           rhs_origtype = NULL_TREE;
    7834              :         }
    7835              :     }
    7836              : 
    7837      2906460 :   if (c_dialect_objc ())
    7838              :     {
    7839              :       /* Check if we are modifying an Objective-C property reference;
    7840              :          if so, we need to generate setter calls.  */
    7841            0 :       if (TREE_CODE (newrhs) == EXCESS_PRECISION_EXPR)
    7842            0 :         result = objc_maybe_build_modify_expr (lhs, TREE_OPERAND (newrhs, 0));
    7843              :       else
    7844            0 :         result = objc_maybe_build_modify_expr (lhs, newrhs);
    7845            0 :       if (result)
    7846            0 :         goto return_result;
    7847              : 
    7848              :       /* Else, do the check that we postponed for Objective-C.  */
    7849            0 :       if (!lvalue_or_else (location, lhs, lv_assign))
    7850            0 :         return error_mark_node;
    7851              :     }
    7852              : 
    7853              :   /* Give an error for storing in something that is 'const'.  */
    7854              : 
    7855      2906460 :   if (TYPE_READONLY (lhstype)
    7856      2906460 :       || (RECORD_OR_UNION_TYPE_P (lhstype)
    7857        25783 :           && C_TYPE_FIELDS_READONLY (lhstype)))
    7858              :     {
    7859           88 :       readonly_error (location, lhs, lv_assign);
    7860           88 :       return error_mark_node;
    7861              :     }
    7862      2906372 :   else if (TREE_READONLY (lhs))
    7863            1 :     readonly_warning (lhs, lv_assign);
    7864              : 
    7865              :   /* If storing into a structure or union member,
    7866              :      it has probably been given type `int'.
    7867              :      Compute the type that would go with
    7868              :      the actual amount of storage the member occupies.  */
    7869              : 
    7870      2906372 :   if (TREE_CODE (lhs) == COMPONENT_REF
    7871       249859 :       && (TREE_CODE (lhstype) == INTEGER_TYPE
    7872       249859 :           || TREE_CODE (lhstype) == BOOLEAN_TYPE
    7873       110137 :           || SCALAR_FLOAT_TYPE_P (lhstype)
    7874        86744 :           || TREE_CODE (lhstype) == ENUMERAL_TYPE))
    7875       170111 :     lhstype = TREE_TYPE (get_unwidened (lhs, 0));
    7876              : 
    7877              :   /* If storing in a field that is in actuality a short or narrower than one,
    7878              :      we must store in the field in its actual type.  */
    7879              : 
    7880      2906372 :   if (lhstype != TREE_TYPE (lhs))
    7881              :     {
    7882            0 :       lhs = copy_node (lhs);
    7883            0 :       TREE_TYPE (lhs) = lhstype;
    7884              :     }
    7885              : 
    7886              :   /* Issue -Wc++-compat warnings about an assignment to an enum type
    7887              :      when LHS does not have its original type.  This happens for,
    7888              :      e.g., an enum bitfield in a struct.  */
    7889      2906372 :   if (warn_cxx_compat
    7890         3196 :       && lhs_origtype != NULL_TREE
    7891         3196 :       && lhs_origtype != lhstype
    7892            7 :       && TREE_CODE (lhs_origtype) == ENUMERAL_TYPE)
    7893              :     {
    7894            4 :       tree checktype = (rhs_origtype != NULL_TREE
    7895            4 :                         ? rhs_origtype
    7896            0 :                         : TREE_TYPE (rhs));
    7897            4 :       if (checktype != error_mark_node
    7898            4 :           && (TYPE_MAIN_VARIANT (checktype) != TYPE_MAIN_VARIANT (lhs_origtype)
    7899            2 :               || (is_atomic_op && modifycode != NOP_EXPR)))
    7900            2 :         warning_at (location, OPT_Wc___compat,
    7901              :                     "enum conversion in assignment is invalid in C++");
    7902              :     }
    7903              : 
    7904              :   /* Remove qualifiers.  */
    7905      2906372 :   lhstype = c_build_qualified_type (lhstype, TYPE_UNQUALIFIED);
    7906      2906372 :   olhstype = c_build_qualified_type (olhstype, TYPE_UNQUALIFIED);
    7907              : 
    7908              :   /* Convert new value to destination type.  Fold it first, then
    7909              :      restore any excess precision information, for the sake of
    7910              :      conversion warnings.  */
    7911              : 
    7912      2906372 :   if (!(is_atomic_op && modifycode != NOP_EXPR))
    7913              :     {
    7914      2890887 :       tree rhs_semantic_type = NULL_TREE;
    7915      2890887 :       if (!c_in_omp_for)
    7916              :         {
    7917      2874566 :           if (TREE_CODE (newrhs) == EXCESS_PRECISION_EXPR)
    7918              :             {
    7919         5077 :               rhs_semantic_type = TREE_TYPE (newrhs);
    7920         5077 :               newrhs = TREE_OPERAND (newrhs, 0);
    7921              :             }
    7922      2874566 :           npc = null_pointer_constant_p (newrhs);
    7923      2874566 :           newrhs = c_fully_fold (newrhs, false, NULL);
    7924      2874566 :           if (rhs_semantic_type)
    7925         5077 :             newrhs = build1 (EXCESS_PRECISION_EXPR, rhs_semantic_type, newrhs);
    7926              :         }
    7927              :       else
    7928        16321 :         npc = null_pointer_constant_p (newrhs);
    7929      2890887 :       newrhs = convert_for_assignment (location, rhs_loc, lhstype, newrhs,
    7930              :                                        rhs_origtype, ic_assign, npc,
    7931              :                                        NULL_TREE, NULL_TREE, 0);
    7932      2890887 :       if (TREE_CODE (newrhs) == ERROR_MARK)
    7933          127 :         return error_mark_node;
    7934              :     }
    7935              : 
    7936              :   /* Emit ObjC write barrier, if necessary.  */
    7937      2906245 :   if (c_dialect_objc () && flag_objc_gc)
    7938              :     {
    7939            0 :       result = objc_generate_write_barrier (lhs, modifycode, newrhs);
    7940            0 :       if (result)
    7941              :         {
    7942            0 :           protected_set_expr_location (result, location);
    7943            0 :           goto return_result;
    7944              :         }
    7945              :     }
    7946              : 
    7947              :   /* Scan operands.  */
    7948              : 
    7949      2906245 :   if (is_atomic_op)
    7950        25964 :     result = build_atomic_assign (location, lhs, modifycode, newrhs, false);
    7951              :   else
    7952              :     {
    7953      2880281 :       result = build2 (MODIFY_EXPR, lhstype, lhs, newrhs);
    7954      2880281 :       TREE_SIDE_EFFECTS (result) = 1;
    7955      2880281 :       protected_set_expr_location (result, location);
    7956              :     }
    7957              : 
    7958              :   /* If we got the LHS in a different type for storing in,
    7959              :      convert the result back to the nominal type of LHS
    7960              :      so that the value we return always has the same type
    7961              :      as the LHS argument.  */
    7962              : 
    7963      2906245 :   if (olhstype == TREE_TYPE (result))
    7964      2906245 :     goto return_result;
    7965              : 
    7966            0 :   result = convert_for_assignment (location, rhs_loc, olhstype, result,
    7967              :                                    rhs_origtype, ic_assign, false, NULL_TREE,
    7968              :                                    NULL_TREE, 0);
    7969            0 :   protected_set_expr_location (result, location);
    7970              : 
    7971      2906245 : return_result:
    7972      2906245 :   if (rhseval)
    7973         8816 :     result = build2 (COMPOUND_EXPR, TREE_TYPE (result), rhseval, result);
    7974              :   return result;
    7975              : }
    7976              : 
    7977              : /* Return whether STRUCT_TYPE has an anonymous field with type TYPE.
    7978              :    This is used to implement -fplan9-extensions.  */
    7979              : 
    7980              : static bool
    7981           26 : find_anonymous_field_with_type (tree struct_type, tree type)
    7982              : {
    7983           26 :   tree field;
    7984           26 :   bool found;
    7985              : 
    7986           26 :   gcc_assert (RECORD_OR_UNION_TYPE_P (struct_type));
    7987           26 :   found = false;
    7988           26 :   for (field = TYPE_FIELDS (struct_type);
    7989           68 :        field != NULL_TREE;
    7990           42 :        field = TREE_CHAIN (field))
    7991              :     {
    7992           42 :       tree fieldtype = remove_qualifiers (TREE_TYPE (field));
    7993           42 :       if (DECL_NAME (field) == NULL
    7994           42 :           && comptypes (type, fieldtype))
    7995              :         {
    7996            4 :           if (found)
    7997              :             return false;
    7998              :           found = true;
    7999              :         }
    8000           38 :       else if (DECL_NAME (field) == NULL
    8001            2 :                && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field))
    8002           40 :                && find_anonymous_field_with_type (TREE_TYPE (field), type))
    8003              :         {
    8004            0 :           if (found)
    8005              :             return false;
    8006              :           found = true;
    8007              :         }
    8008              :     }
    8009              :   return found;
    8010              : }
    8011              : 
    8012              : /* RHS is an expression whose type is pointer to struct.  If there is
    8013              :    an anonymous field in RHS with type TYPE, then return a pointer to
    8014              :    that field in RHS.  This is used with -fplan9-extensions.  This
    8015              :    returns NULL if no conversion could be found.  */
    8016              : 
    8017              : static tree
    8018           28 : convert_to_anonymous_field (location_t location, tree type, tree rhs)
    8019              : {
    8020           28 :   tree rhs_struct_type, lhs_main_type;
    8021           28 :   tree field, found_field;
    8022           28 :   bool found_sub_field;
    8023           28 :   tree ret;
    8024              : 
    8025           28 :   gcc_assert (POINTER_TYPE_P (TREE_TYPE (rhs)));
    8026           28 :   rhs_struct_type = TREE_TYPE (TREE_TYPE (rhs));
    8027           28 :   gcc_assert (RECORD_OR_UNION_TYPE_P (rhs_struct_type));
    8028              : 
    8029           28 :   gcc_assert (POINTER_TYPE_P (type));
    8030           28 :   lhs_main_type = remove_qualifiers (TREE_TYPE (type));
    8031              : 
    8032           28 :   found_field = NULL_TREE;
    8033           28 :   found_sub_field = false;
    8034           28 :   for (field = TYPE_FIELDS (rhs_struct_type);
    8035          172 :        field != NULL_TREE;
    8036          144 :        field = TREE_CHAIN (field))
    8037              :     {
    8038          148 :       if (DECL_NAME (field) != NULL_TREE
    8039          148 :           || !RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)))
    8040           96 :         continue;
    8041           52 :       tree fieldtype = remove_qualifiers (TREE_TYPE (field));
    8042           52 :       if (comptypes (lhs_main_type, fieldtype))
    8043              :         {
    8044           28 :           if (found_field != NULL_TREE)
    8045              :             return NULL_TREE;
    8046              :           found_field = field;
    8047              :         }
    8048           24 :       else if (find_anonymous_field_with_type (TREE_TYPE (field),
    8049              :                                                lhs_main_type))
    8050              :         {
    8051            4 :           if (found_field != NULL_TREE)
    8052              :             return NULL_TREE;
    8053              :           found_field = field;
    8054              :           found_sub_field = true;
    8055              :         }
    8056              :     }
    8057              : 
    8058           24 :   if (found_field == NULL_TREE)
    8059              :     return NULL_TREE;
    8060              : 
    8061           24 :   ret = fold_build3_loc (location, COMPONENT_REF, TREE_TYPE (found_field),
    8062              :                          build_fold_indirect_ref (rhs), found_field,
    8063              :                          NULL_TREE);
    8064           24 :   ret = build_fold_addr_expr_loc (location, ret);
    8065              : 
    8066           24 :   if (found_sub_field)
    8067              :     {
    8068            2 :       ret = convert_to_anonymous_field (location, type, ret);
    8069            2 :       gcc_assert (ret != NULL_TREE);
    8070              :     }
    8071              : 
    8072              :   return ret;
    8073              : }
    8074              : 
    8075              : /* Issue an error message for a bad initializer component.
    8076              :    GMSGID identifies the message.
    8077              :    The component name is taken from the spelling stack.  */
    8078              : 
    8079              : static void ATTRIBUTE_GCC_DIAG (2,0)
    8080          944 : error_init (location_t loc, const char *gmsgid, ...)
    8081              : {
    8082          944 :   char *ofwhat;
    8083              : 
    8084          944 :   auto_diagnostic_group d;
    8085              : 
    8086              :   /* The gmsgid may be a format string with %< and %>. */
    8087          944 :   va_list ap;
    8088          944 :   va_start (ap, gmsgid);
    8089          944 :   bool warned = emit_diagnostic_valist (diagnostics::kind::error,
    8090          944 :                                         loc, -1, gmsgid, &ap);
    8091          944 :   va_end (ap);
    8092              : 
    8093          944 :   ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
    8094          944 :   if (*ofwhat && warned)
    8095          220 :     inform (loc, "(near initialization for %qs)", ofwhat);
    8096          944 : }
    8097              : 
    8098              : /* Used to implement pedwarn_init and permerror_init.  */
    8099              : 
    8100              : static bool ATTRIBUTE_GCC_DIAG (3,0)
    8101         2538 : pedwarn_permerror_init (location_t loc, int opt, const char *gmsgid,
    8102              :                         va_list *ap, enum diagnostics::kind kind)
    8103              : {
    8104              :   /* Use the location where a macro was expanded rather than where
    8105              :      it was defined to make sure macros defined in system headers
    8106              :      but used incorrectly elsewhere are diagnosed.  */
    8107         2538 :   location_t exploc = expansion_point_location_if_in_system_header (loc);
    8108         2538 :   auto_diagnostic_group d;
    8109         2538 :   bool warned = emit_diagnostic_valist (kind, exploc, opt, gmsgid, ap);
    8110         2538 :   if (warned)
    8111              :     {
    8112         1815 :       char *ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
    8113         1815 :       if (*ofwhat)
    8114         1494 :         inform (exploc, "(near initialization for %qs)", ofwhat);
    8115              :     }
    8116         5076 :   return warned;
    8117         2538 : }
    8118              : 
    8119              : /* Issue a pedantic warning for a bad initializer component.  OPT is
    8120              :    the option OPT_* (from options.h) controlling this warning or 0 if
    8121              :    it is unconditionally given.  GMSGID identifies the message.  The
    8122              :    component name is taken from the spelling stack.  */
    8123              : 
    8124              : static bool ATTRIBUTE_GCC_DIAG (3,0)
    8125         2187 : pedwarn_init (location_t loc, int opt, const char *gmsgid, ...)
    8126              : {
    8127         2187 :   va_list ap;
    8128         2187 :   va_start (ap, gmsgid);
    8129         2187 :   bool warned = pedwarn_permerror_init (loc, opt, gmsgid, &ap,
    8130              :                                         diagnostics::kind::pedwarn);
    8131         2187 :   va_end (ap);
    8132         2187 :   return warned;
    8133              : }
    8134              : 
    8135              : /* Like pedwarn_init, but issue a permerror.  */
    8136              : 
    8137              : static bool ATTRIBUTE_GCC_DIAG (3,0)
    8138          351 : permerror_init (location_t loc, int opt, const char *gmsgid, ...)
    8139              : {
    8140          351 :   va_list ap;
    8141          351 :   va_start (ap, gmsgid);
    8142          351 :   bool warned = pedwarn_permerror_init (loc, opt, gmsgid, &ap,
    8143              :                                         diagnostics::kind::permerror);
    8144          351 :   va_end (ap);
    8145          351 :   return warned;
    8146              : }
    8147              : 
    8148              : /* Issue a warning for a bad initializer component.
    8149              : 
    8150              :    OPT is the OPT_W* value corresponding to the warning option that
    8151              :    controls this warning.  GMSGID identifies the message.  The
    8152              :    component name is taken from the spelling stack.  */
    8153              : 
    8154              : static void
    8155          146 : warning_init (location_t loc, int opt, const char *gmsgid)
    8156              : {
    8157          146 :   char *ofwhat;
    8158          146 :   bool warned;
    8159              : 
    8160          146 :   auto_diagnostic_group d;
    8161              : 
    8162              :   /* Use the location where a macro was expanded rather than where
    8163              :      it was defined to make sure macros defined in system headers
    8164              :      but used incorrectly elsewhere are diagnosed.  */
    8165          146 :   location_t exploc = expansion_point_location_if_in_system_header (loc);
    8166              : 
    8167              :   /* The gmsgid may be a format string with %< and %>. */
    8168          146 :   warned = warning_at (exploc, opt, gmsgid);
    8169          146 :   if (warned)
    8170              :     {
    8171          133 :       ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
    8172          133 :       if (*ofwhat)
    8173          133 :         inform (exploc, "(near initialization for %qs)", ofwhat);
    8174              :     }
    8175          146 : }
    8176              : 
    8177              : /* If TYPE is an array type and EXPR is a parenthesized string
    8178              :    constant, warn if pedantic that EXPR is being used to initialize an
    8179              :    object of type TYPE.  */
    8180              : 
    8181              : void
    8182      7284806 : maybe_warn_string_init (location_t loc, tree type, struct c_expr expr)
    8183              : {
    8184      7284806 :   if (pedantic
    8185        80536 :       && TREE_CODE (type) == ARRAY_TYPE
    8186         1193 :       && TREE_CODE (expr.value) == STRING_CST
    8187          472 :       && expr.original_code != STRING_CST)
    8188           13 :     pedwarn_init (loc, OPT_Wpedantic,
    8189              :                   "array initialized from parenthesized string constant");
    8190      7284806 : }
    8191              : 
    8192              : /* Attempt to locate the parameter with the given index within FNDECL,
    8193              :    returning DECL_SOURCE_LOCATION (FNDECL) if it can't be found.  */
    8194              : 
    8195              : static location_t
    8196          937 : get_fndecl_argument_location (tree fndecl, int argnum)
    8197              : {
    8198          937 :   int i;
    8199          937 :   tree param;
    8200              : 
    8201              :   /* Locate param by index within DECL_ARGUMENTS (fndecl).  */
    8202          937 :   for (i = 0, param = DECL_ARGUMENTS (fndecl);
    8203         1016 :        i < argnum && param;
    8204           79 :        i++, param = TREE_CHAIN (param))
    8205              :     ;
    8206              : 
    8207              :   /* If something went wrong (e.g. if we have a builtin and thus no arguments),
    8208              :      return DECL_SOURCE_LOCATION (FNDECL).  */
    8209          937 :   if (param == NULL)
    8210          653 :     return DECL_SOURCE_LOCATION (fndecl);
    8211              : 
    8212          284 :   return DECL_SOURCE_LOCATION (param);
    8213              : }
    8214              : 
    8215              : /* Issue a note about a mismatching argument for parameter PARMNUM
    8216              :    to FUNDECL, for types EXPECTED_TYPE and ACTUAL_TYPE.
    8217              :    Attempt to issue the note at the pertinent parameter of the decl;
    8218              :    failing that issue it at the location of FUNDECL; failing that
    8219              :    issue it at PLOC.
    8220              :    Use highlight_colors::actual for the ACTUAL_TYPE
    8221              :    and highlight_colors::expected for EXPECTED_TYPE and the
    8222              :    parameter of FUNDECL*/
    8223              : 
    8224              : static void
    8225         1061 : inform_for_arg (tree fundecl, location_t ploc, int parmnum,
    8226              :                 tree expected_type, tree actual_type)
    8227              : {
    8228         1061 :   location_t loc;
    8229         1061 :   if (fundecl && !DECL_IS_UNDECLARED_BUILTIN (fundecl))
    8230          937 :     loc = get_fndecl_argument_location (fundecl, parmnum - 1);
    8231              :   else
    8232              :     loc = ploc;
    8233              : 
    8234         1061 :   gcc_rich_location richloc (loc, nullptr, highlight_colors::expected);
    8235              : 
    8236         1061 :   pp_markup::element_expected_type elem_expected_type (expected_type);
    8237         1061 :   pp_markup::element_actual_type elem_actual_type (actual_type);
    8238         1061 :   inform (&richloc,
    8239              :           "expected %e but argument is of type %e",
    8240              :           &elem_expected_type, &elem_actual_type);
    8241         1061 : }
    8242              : 
    8243              : /* Issue a warning when an argument of ARGTYPE is passed to a built-in
    8244              :    function FUNDECL declared without prototype to parameter PARMNUM of
    8245              :    PARMTYPE when ARGTYPE does not promote to PARMTYPE.  */
    8246              : 
    8247              : static void
    8248          418 : maybe_warn_builtin_no_proto_arg (location_t loc, tree fundecl, int parmnum,
    8249              :                                  tree parmtype, tree argtype)
    8250              : {
    8251          418 :   tree_code parmcode = TREE_CODE (parmtype);
    8252          418 :   tree_code argcode = TREE_CODE (argtype);
    8253          418 :   tree promoted = c_type_promotes_to (argtype);
    8254              : 
    8255              :   /* Avoid warning for enum arguments that promote to an integer type
    8256              :      of the same size/mode.  */
    8257          418 :   if (parmcode == INTEGER_TYPE
    8258          418 :       && argcode == ENUMERAL_TYPE
    8259          418 :       && TYPE_MODE (parmtype) == TYPE_MODE (argtype))
    8260              :     return;
    8261              : 
    8262          417 :   if ((parmcode == argcode
    8263          222 :        || (parmcode == INTEGER_TYPE
    8264              :            && argcode == ENUMERAL_TYPE))
    8265          418 :       && TYPE_MAIN_VARIANT (parmtype) == TYPE_MAIN_VARIANT (promoted))
    8266              :     return;
    8267              : 
    8268              :   /* This diagnoses even signed/unsigned mismatches.  Those might be
    8269              :      safe in many cases but GCC may emit suboptimal code for them so
    8270              :      warning on those cases drives efficiency improvements.  */
    8271          398 :   if (warning_at (loc, OPT_Wbuiltin_declaration_mismatch,
    8272          398 :                   TYPE_MAIN_VARIANT (promoted) == argtype
    8273              :                   ? G_("%qD argument %d type is %qT where %qT is expected "
    8274              :                        "in a call to built-in function declared without "
    8275              :                        "prototype")
    8276              :                   : G_("%qD argument %d promotes to %qT where %qT is expected "
    8277              :                        "in a call to built-in function declared without "
    8278              :                        "prototype"),
    8279              :                   fundecl, parmnum, promoted, parmtype))
    8280          150 :     inform (DECL_SOURCE_LOCATION (fundecl),
    8281              :             "built-in %qD declared here",
    8282              :             fundecl);
    8283              : }
    8284              : 
    8285              : /* Print a declaration in quotes, with the given highlight_color.
    8286              :    Analogous to handler for %qD, but with a specific highlight color.  */
    8287              : 
    8288          199 : class pp_element_quoted_decl : public pp_element
    8289              : {
    8290              : public:
    8291          199 :   pp_element_quoted_decl (tree decl, const char *highlight_color)
    8292          199 :   : m_decl (decl),
    8293          199 :     m_highlight_color (highlight_color)
    8294              :   {
    8295              :   }
    8296              : 
    8297          199 :   void add_to_phase_2 (pp_markup::context &ctxt) override
    8298              :   {
    8299          199 :     ctxt.begin_quote ();
    8300          199 :     ctxt.begin_highlight_color (m_highlight_color);
    8301              : 
    8302          199 :     print_decl (ctxt);
    8303              : 
    8304          199 :     ctxt.end_highlight_color ();
    8305          199 :     ctxt.end_quote ();
    8306          199 :   }
    8307              : 
    8308          199 :   void print_decl (pp_markup::context &ctxt)
    8309              :   {
    8310          199 :     pretty_printer *const pp = &ctxt.m_pp;
    8311          199 :     pp->set_padding (pp_none);
    8312          199 :     if (DECL_NAME (m_decl))
    8313          199 :       pp_identifier (pp, lang_hooks.decl_printable_name (m_decl, 2));
    8314              :     else
    8315            0 :       pp_string (pp, _("({anonymous})"));
    8316          199 :   }
    8317              : 
    8318              : private:
    8319              :   tree m_decl;
    8320              :   const char *m_highlight_color;
    8321              : };
    8322              : 
    8323              : /* If TYPE is from a typedef, issue a note showing the location
    8324              :    to the user.
    8325              :    Use HIGHLIGHT_COLOR as the highlight color.  */
    8326              : 
    8327              : static void
    8328         1178 : maybe_inform_typedef_location (tree type, const char *highlight_color)
    8329              : {
    8330         1178 :   if (!typedef_variant_p (type))
    8331         1144 :     return;
    8332              : 
    8333           34 :   tree typedef_decl = TYPE_NAME (type);
    8334           34 :   gcc_assert (TREE_CODE (typedef_decl) == TYPE_DECL);
    8335           34 :   gcc_rich_location richloc (DECL_SOURCE_LOCATION (typedef_decl),
    8336           34 :                              nullptr, highlight_color);
    8337           34 :   pp_element_quoted_decl e_typedef_decl (typedef_decl, highlight_color);
    8338           34 :   inform (&richloc, "%e declared here", &e_typedef_decl);
    8339           34 : }
    8340              : 
    8341              : /* Convert value RHS to type TYPE as preparation for an assignment to
    8342              :    an lvalue of type TYPE.  If ORIGTYPE is not NULL_TREE, it is the
    8343              :    original type of RHS; this differs from TREE_TYPE (RHS) for enum
    8344              :    types.  NULL_POINTER_CONSTANT says whether RHS was a null pointer
    8345              :    constant before any folding.
    8346              :    The real work of conversion is done by `convert'.
    8347              :    The purpose of this function is to generate error messages
    8348              :    for assignments that are not allowed in C.
    8349              :    ERRTYPE says whether it is argument passing, assignment,
    8350              :    initialization or return.
    8351              : 
    8352              :    In the following example, '~' denotes where EXPR_LOC and '^' where
    8353              :    LOCATION point to:
    8354              : 
    8355              :      f (var);      [ic_argpass]
    8356              :      ^  ~~~
    8357              :      x = var;      [ic_assign]
    8358              :        ^ ~~~;
    8359              :      int x = var;  [ic_init]
    8360              :              ^^^
    8361              :      return x;     [ic_return]
    8362              :             ^
    8363              : 
    8364              :    FUNCTION is a tree for the function being called.
    8365              :    PARMNUM is the number of the argument, for printing in error messages.
    8366              :    WARNOPT may be set to a warning option to issue the corresponding warning
    8367              :    rather than an error for invalid conversions.  Used for calls to built-in
    8368              :    functions declared without a prototype.  */
    8369              : 
    8370              : static tree
    8371    167088295 : convert_for_assignment (location_t location, location_t expr_loc, tree type,
    8372              :                         tree rhs, tree origtype, enum impl_conv errtype,
    8373              :                         bool null_pointer_constant, tree fundecl,
    8374              :                         tree function, int parmnum, int warnopt /* = 0 */)
    8375              : {
    8376    167088295 :   enum tree_code codel = TREE_CODE (type);
    8377    167088295 :   tree orig_rhs = rhs;
    8378    167088295 :   tree rhstype;
    8379    167088295 :   enum tree_code coder;
    8380    167088295 :   tree rname = NULL_TREE;
    8381    167088295 :   bool objc_ok = false;
    8382              : 
    8383              :   /* Use the expansion point location to handle cases such as user's
    8384              :      function returning a wrong-type macro defined in a system header.  */
    8385    167088295 :   location = expansion_point_location_if_in_system_header (location);
    8386              : 
    8387    167088295 :   if (errtype == ic_argpass)
    8388              :     {
    8389    125628801 :       tree selector;
    8390              :       /* Change pointer to function to the function itself for
    8391              :          diagnostics.  */
    8392    125628801 :       if (TREE_CODE (function) == ADDR_EXPR
    8393    125628801 :           && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL)
    8394            0 :         function = TREE_OPERAND (function, 0);
    8395              : 
    8396              :       /* Handle an ObjC selector specially for diagnostics.  */
    8397    125628801 :       selector = objc_message_selector ();
    8398    125628801 :       rname = function;
    8399    125628801 :       if (selector && parmnum > 2)
    8400              :         {
    8401            0 :           rname = selector;
    8402            0 :           parmnum -= 2;
    8403              :         }
    8404              :     }
    8405              : 
    8406              :   /* This macro is used to emit diagnostics to ensure that all format
    8407              :      strings are complete sentences, visible to gettext and checked at
    8408              :      compile time.  */
    8409              : #define PEDWARN_FOR_ASSIGNMENT(LOCATION, PLOC, OPT, AR, AS, IN, RE)      \
    8410              :   do {                                                                   \
    8411              :     switch (errtype)                                                     \
    8412              :       {                                                                  \
    8413              :       case ic_argpass:                                                   \
    8414              :         {                                                               \
    8415              :           auto_diagnostic_group d;                                              \
    8416              :           if (pedwarn (PLOC, OPT, AR, parmnum, rname))          \
    8417              :             inform_for_arg (fundecl, (PLOC), parmnum, type, rhstype); \
    8418              :         }                                                               \
    8419              :         break;                                                           \
    8420              :       case ic_assign:                                                    \
    8421              :         pedwarn (LOCATION, OPT, AS);                                     \
    8422              :         break;                                                           \
    8423              :       case ic_init:                                                      \
    8424              :       case ic_init_const:                                                \
    8425              :         pedwarn_init (LOCATION, OPT, IN);                                \
    8426              :         break;                                                           \
    8427              :       case ic_return:                                                    \
    8428              :         pedwarn (LOCATION, OPT, RE);                                     \
    8429              :         break;                                                           \
    8430              :       default:                                                           \
    8431              :         gcc_unreachable ();                                              \
    8432              :       }                                                                  \
    8433              :   } while (0)
    8434              : 
    8435              :   /* This macro is used to emit diagnostics to ensure that all format
    8436              :      strings are complete sentences, visible to gettext and checked at
    8437              :      compile time.  It can be called with 'pedwarn' or 'warning_at'.  */
    8438              : #define WARNING_FOR_QUALIFIERS(PEDWARN, LOCATION, PLOC, OPT, AR, AS, IN, RE, QUALS) \
    8439              :   do {                                                                   \
    8440              :     switch (errtype)                                                     \
    8441              :       {                                                                  \
    8442              :       case ic_argpass:                                                   \
    8443              :         {                                                                \
    8444              :           auto_diagnostic_group d;                                       \
    8445              :           if (PEDWARN) {                                                 \
    8446              :             if (pedwarn (PLOC, OPT, AR, parmnum, rname, QUALS))          \
    8447              :               inform_for_arg (fundecl, (PLOC), parmnum, type, rhstype);  \
    8448              :           } else {                                                       \
    8449              :             if (warning_at (PLOC, OPT, AR, parmnum, rname, QUALS))       \
    8450              :               inform_for_arg (fundecl, (PLOC), parmnum, type, rhstype);  \
    8451              :           }                                                              \
    8452              :         }                                                                \
    8453              :         break;                                                           \
    8454              :       case ic_assign:                                                    \
    8455              :         if (PEDWARN)                                                     \
    8456              :           pedwarn (LOCATION, OPT, AS, QUALS);                            \
    8457              :         else                                                             \
    8458              :           warning_at (LOCATION, OPT, AS, QUALS);                         \
    8459              :         break;                                                           \
    8460              :       case ic_init:                                                      \
    8461              :       case ic_init_const:                                                \
    8462              :         if (PEDWARN)                                                     \
    8463              :           pedwarn (LOCATION, OPT, IN, QUALS);                            \
    8464              :         else                                                             \
    8465              :           warning_at (LOCATION, OPT, IN, QUALS);                         \
    8466              :         break;                                                           \
    8467              :       case ic_return:                                                    \
    8468              :         if (PEDWARN)                                                     \
    8469              :           pedwarn (LOCATION, OPT, RE, QUALS);                            \
    8470              :         else                                                             \
    8471              :           warning_at (LOCATION, OPT, RE, QUALS);                         \
    8472              :         break;                                                           \
    8473              :       default:                                                           \
    8474              :         gcc_unreachable ();                                              \
    8475              :       }                                                                  \
    8476              :   } while (0)
    8477              : 
    8478              :   /* This macro is used to emit diagnostics to ensure that all format
    8479              :      strings are complete sentences, visible to gettext and checked at
    8480              :      compile time.  It is the same as PEDWARN_FOR_ASSIGNMENT but with an
    8481              :      extra parameter to enumerate qualifiers.  */
    8482              : #define PEDWARN_FOR_QUALIFIERS(LOCATION, PLOC, OPT, AR, AS, IN, RE, QUALS) \
    8483              :    WARNING_FOR_QUALIFIERS (true, LOCATION, PLOC, OPT, AR, AS, IN, RE, QUALS)
    8484              : 
    8485              : 
    8486    167088295 :   if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
    8487         5985 :     rhs = TREE_OPERAND (rhs, 0);
    8488              : 
    8489    167088295 :   rhstype = TREE_TYPE (rhs);
    8490    167088295 :   coder = TREE_CODE (rhstype);
    8491              : 
    8492    167088295 :   if (coder == ERROR_MARK)
    8493          347 :     return error_mark_node;
    8494              : 
    8495    167087948 :   if (c_dialect_objc ())
    8496              :     {
    8497            0 :       int parmno;
    8498              : 
    8499            0 :       switch (errtype)
    8500              :         {
    8501              :         case ic_return:
    8502              :           parmno = 0;
    8503              :           break;
    8504              : 
    8505              :         case ic_assign:
    8506              :           parmno = -1;
    8507              :           break;
    8508              : 
    8509              :         case ic_init:
    8510              :         case ic_init_const:
    8511              :           parmno = -2;
    8512              :           break;
    8513              : 
    8514              :         default:
    8515            0 :           parmno = parmnum;
    8516              :           break;
    8517              :         }
    8518              : 
    8519            0 :       objc_ok = objc_compare_types (type, rhstype, parmno, rname);
    8520              :     }
    8521              : 
    8522    167087948 :   if (warn_cxx_compat)
    8523              :     {
    8524        29011 :       tree checktype = origtype != NULL_TREE ? origtype : rhstype;
    8525        29011 :       if (checktype != error_mark_node
    8526        29011 :           && TREE_CODE (type) == ENUMERAL_TYPE
    8527        29117 :           && TYPE_MAIN_VARIANT (checktype) != TYPE_MAIN_VARIANT (type))
    8528           45 :         switch (errtype)
    8529              :           {
    8530            8 :           case ic_argpass:
    8531            8 :             if (pedwarn (expr_loc, OPT_Wc___compat, "enum conversion when "
    8532              :                          "passing argument %d of %qE is invalid in C++",
    8533              :                          parmnum, rname))
    8534           16 :               inform ((fundecl && !DECL_IS_UNDECLARED_BUILTIN (fundecl))
    8535            8 :                       ? DECL_SOURCE_LOCATION (fundecl) : expr_loc,
    8536              :                       "expected %qT but argument is of type %qT",
    8537              :                       type, rhstype);
    8538              :             break;
    8539           10 :           case ic_assign:
    8540           10 :             pedwarn (location, OPT_Wc___compat, "enum conversion from %qT to "
    8541              :                      "%qT in assignment is invalid in C++", rhstype, type);
    8542           10 :             break;
    8543           18 :           case ic_init:
    8544           18 :           case ic_init_const:
    8545           18 :             pedwarn_init (location, OPT_Wc___compat, "enum conversion from "
    8546              :                           "%qT to %qT in initialization is invalid in C++",
    8547              :                           rhstype, type);
    8548           18 :             break;
    8549            9 :           case ic_return:
    8550            9 :             pedwarn (location, OPT_Wc___compat, "enum conversion from %qT to "
    8551              :                      "%qT in return is invalid in C++", rhstype, type);
    8552            9 :             break;
    8553            0 :           default:
    8554            0 :             gcc_unreachable ();
    8555              :           }
    8556              :     }
    8557              : 
    8558    167087948 :   if (warn_enum_conversion)
    8559              :     {
    8560     14600677 :       tree checktype = origtype != NULL_TREE ? origtype : rhstype;
    8561     14600677 :       if (checktype != error_mark_node
    8562     14600677 :           && TREE_CODE (checktype) == ENUMERAL_TYPE
    8563        12835 :           && TREE_CODE (type) == ENUMERAL_TYPE
    8564     14608973 :           && !comptypes (TYPE_MAIN_VARIANT (checktype), TYPE_MAIN_VARIANT (type)))
    8565              :        {
    8566            7 :           gcc_rich_location loc (location);
    8567            7 :           warning_at (&loc, OPT_Wenum_conversion,
    8568              :                       "implicit conversion from %qT to %qT",
    8569              :                       checktype, type);
    8570            7 :        }
    8571              :     }
    8572              : 
    8573    167087948 :   if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
    8574              :     {
    8575    147972220 :       warn_for_address_of_packed_member (type, orig_rhs);
    8576    147972220 :       if (type != rhstype)
    8577              :         /* Convert RHS to TYPE in order to not lose TYPE in diagnostics.  */
    8578     36866278 :         rhs = convert (type, rhs);
    8579    147972220 :       return rhs;
    8580              :     }
    8581              : 
    8582     19115728 :   if (coder == VOID_TYPE)
    8583              :     {
    8584              :       /* Except for passing an argument to an unprototyped function,
    8585              :          this is a constraint violation.  When passing an argument to
    8586              :          an unprototyped function, it is compile-time undefined;
    8587              :          making it a constraint in that case was rejected in
    8588              :          DR#252.  */
    8589            8 :       const char msg[] = "void value not ignored as it ought to be";
    8590            8 :       if (warnopt)
    8591            0 :         warning_at (location, warnopt, msg);
    8592              :       else
    8593            8 :         error_at (location, msg);
    8594            8 :       return error_mark_node;
    8595              :     }
    8596     19115720 :   rhs = require_complete_type (location, rhs);
    8597     19115720 :   if (rhs == error_mark_node)
    8598              :     return error_mark_node;
    8599              : 
    8600     19115720 :   if (coder == POINTER_TYPE && reject_gcc_builtin (rhs))
    8601            6 :     return error_mark_node;
    8602              : 
    8603              :   /* A non-reference type can convert to a reference.  This handles
    8604              :      va_start, va_copy and possibly port built-ins.  */
    8605     19115714 :   if (codel == REFERENCE_TYPE && coder != REFERENCE_TYPE)
    8606              :     {
    8607          286 :       if (!lvalue_p (rhs))
    8608              :         {
    8609            0 :           const char msg[] = "cannot pass rvalue to reference parameter";
    8610            0 :           if (warnopt)
    8611            0 :             warning_at (location, warnopt, msg);
    8612              :           else
    8613            0 :             error_at (location, msg);
    8614            0 :           return error_mark_node;
    8615              :         }
    8616          286 :       if (!c_mark_addressable (rhs))
    8617            0 :         return error_mark_node;
    8618          286 :       rhs = build1 (ADDR_EXPR, c_build_pointer_type (TREE_TYPE (rhs)), rhs);
    8619          286 :       SET_EXPR_LOCATION (rhs, location);
    8620              : 
    8621          286 :       rhs = convert_for_assignment (location, expr_loc,
    8622          286 :                                     c_build_pointer_type (TREE_TYPE (type)),
    8623              :                                     rhs, origtype, errtype,
    8624              :                                     null_pointer_constant, fundecl, function,
    8625              :                                     parmnum, warnopt);
    8626          286 :       if (rhs == error_mark_node)
    8627              :         return error_mark_node;
    8628              : 
    8629          286 :       rhs = build1 (NOP_EXPR, type, rhs);
    8630          286 :       SET_EXPR_LOCATION (rhs, location);
    8631          286 :       return rhs;
    8632              :     }
    8633              :   /* Some types can interconvert without explicit casts.  */
    8634     19115428 :   else if (codel == VECTOR_TYPE && coder == VECTOR_TYPE
    8635     19115428 :            && vector_types_convertible_p (type, TREE_TYPE (rhs), true))
    8636      9287057 :     return convert (type, rhs);
    8637              :   /* Arithmetic types all interconvert, and enum is treated like int.  */
    8638      9828371 :   else if ((codel == INTEGER_TYPE || codel == REAL_TYPE
    8639      2288699 :             || codel == FIXED_POINT_TYPE
    8640      2288699 :             || codel == ENUMERAL_TYPE || codel == COMPLEX_TYPE
    8641      2202218 :             || codel == BOOLEAN_TYPE || codel == BITINT_TYPE)
    8642      7725263 :            && (coder == INTEGER_TYPE || coder == REAL_TYPE
    8643        83536 :                || coder == FIXED_POINT_TYPE
    8644        83536 :                || coder == ENUMERAL_TYPE || coder == COMPLEX_TYPE
    8645        40466 :                || coder == BOOLEAN_TYPE || coder == BITINT_TYPE))
    8646              :     {
    8647      7723896 :       if (warnopt && errtype == ic_argpass)
    8648          418 :         maybe_warn_builtin_no_proto_arg (expr_loc, fundecl, parmnum, type,
    8649              :                                          rhstype);
    8650              : 
    8651      7723896 :       bool save = in_late_binary_op;
    8652      7687908 :       if (C_BOOLEAN_TYPE_P (type) || codel == COMPLEX_TYPE
    8653     15354655 :           || (coder == REAL_TYPE
    8654       276251 :               && (codel == INTEGER_TYPE || codel == ENUMERAL_TYPE)
    8655        24196 :               && sanitize_flags_p (SANITIZE_FLOAT_CAST)))
    8656        99881 :         in_late_binary_op = true;
    8657     11104966 :       tree ret = convert_and_check (expr_loc != UNKNOWN_LOCATION
    8658              :                                     ? expr_loc : location, type, orig_rhs,
    8659              :                                     errtype == ic_init_const);
    8660      7723896 :       in_late_binary_op = save;
    8661      7723896 :       return ret;
    8662              :     }
    8663              : 
    8664              :   /* Aggregates in different TUs might need conversion.  */
    8665      2104475 :   if ((codel == RECORD_TYPE || codel == UNION_TYPE)
    8666          105 :       && codel == coder
    8667      2104497 :       && comptypes (TYPE_MAIN_VARIANT (type), TYPE_MAIN_VARIANT (rhstype)))
    8668            9 :     return convert_and_check (expr_loc != UNKNOWN_LOCATION
    8669            9 :                               ? expr_loc : location, type, rhs);
    8670              : 
    8671              :   /* Conversion to a transparent union or record from its member types.
    8672              :      This applies only to function arguments.  */
    8673      2104466 :   if (((codel == UNION_TYPE || codel == RECORD_TYPE)
    8674           96 :       && TYPE_TRANSPARENT_AGGR (type))
    8675      2104505 :       && errtype == ic_argpass)
    8676              :     {
    8677           39 :       tree memb, marginal_memb = NULL_TREE;
    8678              : 
    8679           50 :       for (memb = TYPE_FIELDS (type); memb ; memb = DECL_CHAIN (memb))
    8680              :         {
    8681           50 :           tree memb_type = TREE_TYPE (memb);
    8682              : 
    8683           50 :           if (comptypes (TYPE_MAIN_VARIANT (memb_type),
    8684           50 :                          TYPE_MAIN_VARIANT (rhstype)))
    8685              :             break;
    8686              : 
    8687           27 :           if (TREE_CODE (memb_type) != POINTER_TYPE)
    8688            1 :             continue;
    8689              : 
    8690           26 :           if (coder == POINTER_TYPE)
    8691              :             {
    8692           26 :               tree ttl = TREE_TYPE (memb_type);
    8693           26 :               tree ttr = TREE_TYPE (rhstype);
    8694              : 
    8695              :               /* Any non-function converts to a [const][volatile] void *
    8696              :                  and vice versa; otherwise, targets must be the same.
    8697              :                  Meanwhile, the lhs target must have all the qualifiers of
    8698              :                  the rhs.  */
    8699            0 :               if ((VOID_TYPE_P (ttl) && !TYPE_ATOMIC (ttl))
    8700           26 :                   || (VOID_TYPE_P (ttr) && !TYPE_ATOMIC (ttr))
    8701           45 :                   || comp_target_types (location, memb_type, rhstype))
    8702              :                 {
    8703           16 :                   int lquals = TYPE_QUALS (ttl) & ~TYPE_QUAL_ATOMIC;
    8704           16 :                   int rquals = TYPE_QUALS (ttr) & ~TYPE_QUAL_ATOMIC;
    8705              :                   /* If this type won't generate any warnings, use it.  */
    8706           16 :                   if (lquals == rquals
    8707           16 :                       || ((TREE_CODE (ttr) == FUNCTION_TYPE
    8708            0 :                            && TREE_CODE (ttl) == FUNCTION_TYPE)
    8709            0 :                           ? ((lquals | rquals) == rquals)
    8710           16 :                           : ((lquals | rquals) == lquals)))
    8711              :                     break;
    8712              : 
    8713              :                   /* Keep looking for a better type, but remember this one.  */
    8714            0 :                   if (!marginal_memb)
    8715           10 :                     marginal_memb = memb;
    8716              :                 }
    8717              :             }
    8718              : 
    8719              :           /* Can convert integer zero to any pointer type.  */
    8720           10 :           if (null_pointer_constant)
    8721              :             {
    8722            0 :               rhs = null_pointer_node;
    8723            0 :               break;
    8724              :             }
    8725              :         }
    8726              : 
    8727           39 :       if (memb || marginal_memb)
    8728              :         {
    8729           39 :           if (!memb)
    8730              :             {
    8731              :               /* We have only a marginally acceptable member type;
    8732              :                  it needs a warning.  */
    8733            0 :               tree ttl = TREE_TYPE (TREE_TYPE (marginal_memb));
    8734            0 :               tree ttr = TREE_TYPE (rhstype);
    8735              : 
    8736              :               /* Const and volatile mean something different for function
    8737              :                  types, so the usual warnings are not appropriate.  */
    8738            0 :               if (TREE_CODE (ttr) == FUNCTION_TYPE
    8739            0 :                   && TREE_CODE (ttl) == FUNCTION_TYPE)
    8740              :                 {
    8741              :                   /* Because const and volatile on functions are
    8742              :                      restrictions that say the function will not do
    8743              :                      certain things, it is okay to use a const or volatile
    8744              :                      function where an ordinary one is wanted, but not
    8745              :                      vice-versa.  */
    8746            0 :                   if (TYPE_QUALS_NO_ADDR_SPACE (ttl)
    8747            0 :                       & ~TYPE_QUALS_NO_ADDR_SPACE (ttr))
    8748            0 :                     PEDWARN_FOR_QUALIFIERS (location, expr_loc,
    8749              :                                             OPT_Wdiscarded_qualifiers,
    8750              :                                             G_("passing argument %d of %qE "
    8751              :                                                "makes %q#v qualified function "
    8752              :                                                "pointer from unqualified"),
    8753              :                                             G_("assignment makes %q#v qualified "
    8754              :                                                "function pointer from "
    8755              :                                                "unqualified"),
    8756              :                                             G_("initialization makes %q#v qualified "
    8757              :                                                "function pointer from "
    8758              :                                                "unqualified"),
    8759              :                                             G_("return makes %q#v qualified function "
    8760              :                                                "pointer from unqualified"),
    8761              :                                             TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr));
    8762              :                 }
    8763            0 :               else if (TYPE_QUALS_NO_ADDR_SPACE (ttr)
    8764            0 :                        & ~TYPE_QUALS_NO_ADDR_SPACE (ttl))
    8765            0 :                 PEDWARN_FOR_QUALIFIERS (location, expr_loc,
    8766              :                                         OPT_Wdiscarded_qualifiers,
    8767              :                                         G_("passing argument %d of %qE discards "
    8768              :                                            "%qv qualifier from pointer target type"),
    8769              :                                         G_("assignment discards %qv qualifier "
    8770              :                                            "from pointer target type"),
    8771              :                                         G_("initialization discards %qv qualifier "
    8772              :                                            "from pointer target type"),
    8773              :                                         G_("return discards %qv qualifier from "
    8774              :                                            "pointer target type"),
    8775              :                                         TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl));
    8776              : 
    8777              :               memb = marginal_memb;
    8778              :             }
    8779              : 
    8780           39 :           if (!fundecl || !DECL_IN_SYSTEM_HEADER (fundecl))
    8781           31 :             pedwarn (location, OPT_Wpedantic,
    8782              :                      "ISO C prohibits argument conversion to union type");
    8783              : 
    8784           39 :           rhs = fold_convert_loc (location, TREE_TYPE (memb), rhs);
    8785           39 :           return build_constructor_single (type, memb, rhs);
    8786              :         }
    8787              :     }
    8788              : 
    8789              :   /* Conversions among pointers */
    8790      2104427 :   else if ((codel == POINTER_TYPE || codel == REFERENCE_TYPE)
    8791      2102904 :            && (coder == codel))
    8792              :     {
    8793              :       /* If RHS refers to a built-in declared without a prototype
    8794              :          BLTIN is the declaration of the built-in with a prototype
    8795              :          and RHSTYPE is set to the actual type of the built-in.  */
    8796      2024293 :       tree bltin;
    8797      2024293 :       rhstype = type_or_builtin_type (rhs, &bltin);
    8798              : 
    8799      2024293 :       tree ttl = TREE_TYPE (type);
    8800      2024293 :       tree ttr = TREE_TYPE (rhstype);
    8801      2024293 :       bool is_opaque_pointer;
    8802      2024293 :       bool target_cmp = false;   /* Cache comp_target_types () result.  */
    8803      2024293 :       addr_space_t asl;
    8804      2024293 :       addr_space_t asr;
    8805              : 
    8806      2024293 :       tree mvl = remove_qualifiers (ttl);
    8807      2024293 :       tree mvr = remove_qualifiers (ttr);
    8808              : 
    8809              :       /* Opaque pointers are treated like void pointers.  */
    8810      2024293 :       is_opaque_pointer = vector_targets_convertible_p (ttl, ttr);
    8811              : 
    8812              :       /* The Plan 9 compiler permits a pointer to a struct to be
    8813              :          automatically converted into a pointer to an anonymous field
    8814              :          within the struct.  */
    8815      2024293 :       if (flag_plan9_extensions
    8816           50 :           && RECORD_OR_UNION_TYPE_P (mvl)
    8817           26 :           && RECORD_OR_UNION_TYPE_P (mvr)
    8818           26 :           && mvl != mvr)
    8819              :         {
    8820           26 :           tree new_rhs = convert_to_anonymous_field (location, type, rhs);
    8821           26 :           if (new_rhs != NULL_TREE)
    8822              :             {
    8823           22 :               rhs = new_rhs;
    8824           22 :               rhstype = TREE_TYPE (rhs);
    8825           22 :               coder = TREE_CODE (rhstype);
    8826           22 :               ttr = TREE_TYPE (rhstype);
    8827           22 :               mvr = TYPE_MAIN_VARIANT (ttr);
    8828              :             }
    8829              :         }
    8830              : 
    8831              :       /* C++ does not allow the implicit conversion void* -> T*.  However,
    8832              :          for the purpose of reducing the number of false positives, we
    8833              :          tolerate the special case of
    8834              : 
    8835              :                 int *p = NULL;
    8836              : 
    8837              :          where NULL is typically defined in C to be '(void *) 0'.  */
    8838      2024293 :       if (VOID_TYPE_P (ttr) && rhs != null_pointer_node && !VOID_TYPE_P (ttl))
    8839        27030 :         warning_at (errtype == ic_argpass ? expr_loc : location,
    8840        14337 :                     OPT_Wc___compat,
    8841              :                     "request for implicit conversion "
    8842              :                     "from %qT to %qT not permitted in C++", rhstype, type);
    8843              : 
    8844              :       /* Warn of new allocations that are not big enough for the target
    8845              :          type.  */
    8846      2024293 :       if (warn_alloc_size && TREE_CODE (rhs) == CALL_EXPR)
    8847         5457 :         if (tree fndecl = get_callee_fndecl (rhs))
    8848         5457 :           if (DECL_IS_MALLOC (fndecl))
    8849              :             {
    8850         4609 :               tree attrs = TYPE_ATTRIBUTES (TREE_TYPE (fndecl));
    8851         4609 :               tree alloc_size = lookup_attribute ("alloc_size", attrs);
    8852         4609 :               if (alloc_size)
    8853          451 :                 warn_for_alloc_size (location, ttl, rhs, alloc_size);
    8854              :             }
    8855              : 
    8856              :       /* See if the pointers point to incompatible address spaces.  */
    8857      2024293 :       asl = TYPE_ADDR_SPACE (ttl);
    8858      2024293 :       asr = TYPE_ADDR_SPACE (ttr);
    8859      2024293 :       if (!null_pointer_constant_p (rhs)
    8860      2024293 :           && asr != asl && !targetm.addr_space.subset_p (asr, asl))
    8861              :         {
    8862            3 :           auto_diagnostic_group d;
    8863            3 :           bool diagnosed = true;
    8864            3 :           switch (errtype)
    8865              :             {
    8866            1 :             case ic_argpass:
    8867            1 :               {
    8868            1 :                 const char msg[] = G_("passing argument %d of %qE from "
    8869              :                                       "pointer to non-enclosed address space");
    8870            1 :                 if (warnopt)
    8871            0 :                   diagnosed
    8872            0 :                     = warning_at (expr_loc, warnopt, msg, parmnum, rname);
    8873              :                 else
    8874            1 :                   error_at (expr_loc, msg, parmnum, rname);
    8875            0 :               break;
    8876              :               }
    8877            0 :             case ic_assign:
    8878            0 :               {
    8879            0 :                 const char msg[] = G_("assignment from pointer to "
    8880              :                                       "non-enclosed address space");
    8881            0 :                 if (warnopt)
    8882            0 :                   diagnosed = warning_at (location, warnopt, msg);
    8883              :                 else
    8884            0 :                   error_at (location, msg);
    8885            0 :                 break;
    8886              :               }
    8887            0 :             case ic_init:
    8888            0 :             case ic_init_const:
    8889            0 :               {
    8890            0 :                 const char msg[] = G_("initialization from pointer to "
    8891              :                                       "non-enclosed address space");
    8892            0 :                 if (warnopt)
    8893            0 :                   diagnosed = warning_at (location, warnopt, msg);
    8894              :                 else
    8895            0 :                   error_at (location, msg);
    8896            0 :                 break;
    8897              :               }
    8898            2 :             case ic_return:
    8899            2 :               {
    8900            2 :                 const char msg[] = G_("return from pointer to "
    8901              :                                       "non-enclosed address space");
    8902            2 :                 if (warnopt)
    8903            0 :                   diagnosed = warning_at (location, warnopt, msg);
    8904              :                 else
    8905            2 :                   error_at (location, msg);
    8906            0 :                 break;
    8907              :               }
    8908            0 :             default:
    8909            0 :               gcc_unreachable ();
    8910              :             }
    8911            3 :           if (diagnosed)
    8912              :             {
    8913            3 :               if (errtype == ic_argpass)
    8914            1 :                 inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
    8915              :               else
    8916            2 :                 inform (location, "expected %qT but pointer is of type %qT",
    8917              :                         type, rhstype);
    8918              :             }
    8919            3 :           return error_mark_node;
    8920            3 :         }
    8921              : 
    8922              :       /* Check if the right-hand side has a format attribute but the
    8923              :          left-hand side doesn't.  */
    8924      2024290 :       if (warn_suggest_attribute_format
    8925      2024290 :           && check_missing_format_attribute (type, rhstype))
    8926              :         {
    8927           16 :           switch (errtype)
    8928              :           {
    8929            4 :           case ic_argpass:
    8930            4 :             warning_at (expr_loc, OPT_Wsuggest_attribute_format,
    8931              :                         "argument %d of %qE might be "
    8932              :                         "a candidate for a format attribute",
    8933              :                         parmnum, rname);
    8934            4 :             break;
    8935            4 :           case ic_assign:
    8936            4 :             warning_at (location, OPT_Wsuggest_attribute_format,
    8937              :                         "assignment left-hand side might be "
    8938              :                         "a candidate for a format attribute");
    8939            4 :             break;
    8940            4 :           case ic_init:
    8941            4 :           case ic_init_const:
    8942            4 :             warning_at (location, OPT_Wsuggest_attribute_format,
    8943              :                         "initialization left-hand side might be "
    8944              :                         "a candidate for a format attribute");
    8945            4 :             break;
    8946            4 :           case ic_return:
    8947            4 :             warning_at (location, OPT_Wsuggest_attribute_format,
    8948              :                         "return type might be "
    8949              :                         "a candidate for a format attribute");
    8950            4 :             break;
    8951            0 :           default:
    8952            0 :             gcc_unreachable ();
    8953              :           }
    8954              :         }
    8955              : 
    8956              :       /* See if the pointers point to incompatible scalar storage orders.  */
    8957      2024290 :       if (warn_scalar_storage_order
    8958      2021374 :           && !null_pointer_constant_p (rhs)
    8959      5998552 :           && (AGGREGATE_TYPE_P (ttl) && TYPE_REVERSE_STORAGE_ORDER (ttl))
    8960      1987131 :              != (AGGREGATE_TYPE_P (ttr) && TYPE_REVERSE_STORAGE_ORDER (ttr)))
    8961              :         {
    8962           18 :           tree t;
    8963              : 
    8964           18 :           switch (errtype)
    8965              :           {
    8966           11 :           case ic_argpass:
    8967              :             /* Do not warn for built-in functions, for example memcpy, since we
    8968              :                control how they behave and they can be useful in this area.  */
    8969           11 :             if (TREE_CODE (rname) != FUNCTION_DECL
    8970           11 :                 || !fndecl_built_in_p (rname))
    8971            1 :               warning_at (location, OPT_Wscalar_storage_order,
    8972              :                           "passing argument %d of %qE from incompatible "
    8973              :                           "scalar storage order", parmnum, rname);
    8974              :             break;
    8975            3 :           case ic_assign:
    8976              :             /* Do not warn if the RHS is a call to a function that returns a
    8977              :                pointer that is not an alias.  */
    8978            3 :             if (TREE_CODE (rhs) != CALL_EXPR
    8979            2 :                 || (t = get_callee_fndecl (rhs)) == NULL_TREE
    8980            5 :                 || !DECL_IS_MALLOC (t))
    8981            1 :               warning_at (location, OPT_Wscalar_storage_order,
    8982              :                           "assignment to %qT from pointer type %qT with "
    8983              :                           "incompatible scalar storage order", type, rhstype);
    8984              :             break;
    8985            3 :           case ic_init:
    8986            3 :           case ic_init_const:
    8987              :             /* Likewise.  */
    8988            3 :             if (TREE_CODE (rhs) != CALL_EXPR
    8989            2 :                 || (t = get_callee_fndecl (rhs)) == NULL_TREE
    8990            5 :                 || !DECL_IS_MALLOC (t))
    8991            1 :               warning_at (location, OPT_Wscalar_storage_order,
    8992              :                           "initialization of %qT from pointer type %qT with "
    8993              :                           "incompatible scalar storage order", type, rhstype);
    8994              :             break;
    8995            1 :           case ic_return:
    8996            1 :             warning_at (location, OPT_Wscalar_storage_order,
    8997              :                         "returning %qT from pointer type with incompatible "
    8998              :                         "scalar storage order %qT", rhstype, type);
    8999            1 :             break;
    9000            0 :           default:
    9001            0 :             gcc_unreachable ();
    9002              :           }
    9003              :         }
    9004              : 
    9005              :       /* Any non-function converts to a [const][volatile] void *
    9006              :          and vice versa; otherwise, targets must be the same.
    9007              :          Meanwhile, the lhs target must have all the qualifiers of the rhs.  */
    9008       424304 :       if ((VOID_TYPE_P (ttl) && !TYPE_ATOMIC (ttl))
    9009      1599987 :           || (VOID_TYPE_P (ttr) && !TYPE_ATOMIC (ttr))
    9010      1551546 :           || (target_cmp = comp_target_types (location, type, rhstype))
    9011         2446 :           || is_opaque_pointer
    9012      2029182 :           || ((c_common_unsigned_type (mvl)
    9013         2446 :                == c_common_unsigned_type (mvr))
    9014         3340 :               && (c_common_signed_type (mvl)
    9015         1670 :                   == c_common_signed_type (mvr))
    9016         1655 :               && TYPE_ATOMIC (mvl) == TYPE_ATOMIC (mvr)))
    9017              :         {
    9018              :           /* Warn about loss of qualifers from pointers to arrays with
    9019              :              qualifiers on the element type. */
    9020      2023491 :           if (TREE_CODE (ttr) == ARRAY_TYPE)
    9021              :             {
    9022         2131 :               ttr = strip_array_types (ttr);
    9023         2131 :               ttl = strip_array_types (ttl);
    9024              : 
    9025         2131 :               if (TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttr)
    9026         2131 :                   & ~TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttl))
    9027          115 :                 WARNING_FOR_QUALIFIERS (flag_isoc23,
    9028              :                                         location, expr_loc,
    9029              :                                         OPT_Wdiscarded_array_qualifiers,
    9030              :                                         G_("passing argument %d of %qE discards "
    9031              :                                            "%qv qualifier from pointer target type"),
    9032              :                                         G_("assignment discards %qv qualifier "
    9033              :                                            "from pointer target type"),
    9034              :                                         G_("initialization discards %qv qualifier "
    9035              :                                            "from pointer target type"),
    9036              :                                         G_("return discards %qv qualifier from "
    9037              :                                            "pointer target type"),
    9038              :                                         TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl));
    9039              :             }
    9040      2021360 :           else if (pedantic
    9041       146269 :               && ((VOID_TYPE_P (ttl) && TREE_CODE (ttr) == FUNCTION_TYPE)
    9042       146249 :                   ||
    9043              :                   (VOID_TYPE_P (ttr)
    9044         2917 :                    && !null_pointer_constant
    9045          178 :                    && TREE_CODE (ttl) == FUNCTION_TYPE)))
    9046           34 :             PEDWARN_FOR_ASSIGNMENT (location, expr_loc, OPT_Wpedantic,
    9047              :                                     G_("ISO C forbids passing argument %d of "
    9048              :                                        "%qE between function pointer "
    9049              :                                        "and %<void *%>"),
    9050              :                                     G_("ISO C forbids assignment between "
    9051              :                                        "function pointer and %<void *%>"),
    9052              :                                     G_("ISO C forbids initialization between "
    9053              :                                        "function pointer and %<void *%>"),
    9054              :                                     G_("ISO C forbids return between function "
    9055              :                                        "pointer and %<void *%>"));
    9056              :           /* Const and volatile mean something different for function types,
    9057              :              so the usual warnings are not appropriate.  */
    9058      2021326 :           else if (TREE_CODE (ttr) != FUNCTION_TYPE
    9059      1988901 :                    && TREE_CODE (ttl) != FUNCTION_TYPE)
    9060              :             {
    9061              :                /* Assignments between atomic and non-atomic objects are OK.  */
    9062      1988184 :                bool warn_quals_ped = TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttr)
    9063      1988184 :                                      & ~TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttl);
    9064      1988184 :                bool warn_quals = TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttr)
    9065      1988184 :                                  & ~TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (strip_array_types (ttl));
    9066              : 
    9067              :               /* Don't warn about loss of qualifier for conversions from
    9068              :                  qualified void* to pointers to arrays with corresponding
    9069              :                  qualifier on the element type (except for pedantic before C23). */
    9070      1988184 :               if (warn_quals || (warn_quals_ped && pedantic && !flag_isoc23))
    9071          697 :                 PEDWARN_FOR_QUALIFIERS (location, expr_loc,
    9072              :                                         OPT_Wdiscarded_qualifiers,
    9073              :                                         G_("passing argument %d of %qE discards "
    9074              :                                            "%qv qualifier from pointer target type"),
    9075              :                                         G_("assignment discards %qv qualifier "
    9076              :                                            "from pointer target type"),
    9077              :                                         G_("initialization discards %qv qualifier "
    9078              :                                            "from pointer target type"),
    9079              :                                         G_("return discards %qv qualifier from "
    9080              :                                            "pointer target type"),
    9081              :                                         TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl));
    9082           11 :               else if (warn_quals_ped)
    9083           11 :                 pedwarn_c11 (location, OPT_Wc11_c23_compat,
    9084              :                              "array with qualifier on the element is not qualified before C23");
    9085              : 
    9086              :               /* If this is not a case of ignoring a mismatch in signedness,
    9087              :                  no warning.  */
    9088      1987476 :               else if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr)
    9089      1546621 :                        || target_cmp)
    9090              :                 ;
    9091              :               /* If there is a mismatch, do warn.  */
    9092         1647 :               else if (warn_pointer_sign)
    9093           82 :                 switch (errtype)
    9094              :                   {
    9095           33 :                   case ic_argpass:
    9096           33 :                     {
    9097           33 :                       auto_diagnostic_group d;
    9098           33 :                       range_label_for_type_mismatch rhs_label (rhstype, type);
    9099           33 :                       gcc_rich_location richloc (expr_loc, &rhs_label,
    9100           33 :                                                  highlight_colors::actual);
    9101           33 :                       if (pedwarn (&richloc, OPT_Wpointer_sign,
    9102              :                                    "pointer targets in passing argument %d of "
    9103              :                                    "%qE differ in signedness", parmnum, rname))
    9104           33 :                         inform_for_arg (fundecl, expr_loc, parmnum, type,
    9105              :                                         rhstype);
    9106           33 :                     }
    9107           33 :                     break;
    9108           21 :                   case ic_assign:
    9109           21 :                     pedwarn (location, OPT_Wpointer_sign,
    9110              :                              "pointer targets in assignment from %qT to %qT "
    9111              :                              "differ in signedness", rhstype, type);
    9112           21 :                     break;
    9113           14 :                   case ic_init:
    9114           14 :                   case ic_init_const:
    9115           14 :                     pedwarn_init (location, OPT_Wpointer_sign,
    9116              :                                   "pointer targets in initialization of %qT "
    9117              :                                   "from %qT differ in signedness", type,
    9118              :                                   rhstype);
    9119           14 :                     break;
    9120           14 :                   case ic_return:
    9121           14 :                     pedwarn (location, OPT_Wpointer_sign, "pointer targets in "
    9122              :                              "returning %qT from a function with return type "
    9123              :                              "%qT differ in signedness", rhstype, type);
    9124           14 :                     break;
    9125            0 :                   default:
    9126            0 :                     gcc_unreachable ();
    9127              :                   }
    9128              :             }
    9129        33142 :           else if (TREE_CODE (ttl) == FUNCTION_TYPE
    9130         4172 :                    && TREE_CODE (ttr) == FUNCTION_TYPE)
    9131              :             {
    9132              :               /* Because const and volatile on functions are restrictions
    9133              :                  that say the function will not do certain things,
    9134              :                  it is okay to use a const or volatile function
    9135              :                  where an ordinary one is wanted, but not vice-versa.  */
    9136         3455 :               if (TYPE_QUALS_NO_ADDR_SPACE (ttl)
    9137         3455 :                   & ~TYPE_QUALS_NO_ADDR_SPACE (ttr))
    9138           18 :                 PEDWARN_FOR_QUALIFIERS (location, expr_loc,
    9139              :                                         OPT_Wdiscarded_qualifiers,
    9140              :                                         G_("passing argument %d of %qE makes "
    9141              :                                            "%q#v qualified function pointer "
    9142              :                                            "from unqualified"),
    9143              :                                         G_("assignment makes %q#v qualified function "
    9144              :                                            "pointer from unqualified"),
    9145              :                                         G_("initialization makes %q#v qualified "
    9146              :                                            "function pointer from unqualified"),
    9147              :                                         G_("return makes %q#v qualified function "
    9148              :                                            "pointer from unqualified"),
    9149              :                                         TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr));
    9150              :             }
    9151              :         }
    9152              :       /* Avoid warning about the volatile ObjC EH puts on decls.  */
    9153          799 :       else if (!objc_ok)
    9154              :         {
    9155          799 :           auto_diagnostic_group d;
    9156          799 :           bool warned = false;
    9157          799 :           pp_markup::element_expected_type e_type (type);
    9158          799 :           pp_markup::element_actual_type e_rhstype (rhstype);
    9159          799 :           switch (errtype)
    9160              :             {
    9161          306 :             case ic_argpass:
    9162          306 :               {
    9163          306 :                 range_label_for_type_mismatch rhs_label (rhstype, type);
    9164          306 :                 gcc_rich_location richloc (expr_loc, &rhs_label,
    9165          306 :                                            highlight_colors::actual);
    9166          306 :                 warned
    9167          306 :                   = permerror_opt (&richloc, OPT_Wincompatible_pointer_types,
    9168              :                                    "passing argument %d of %qE from "
    9169              :                                    "incompatible pointer type",
    9170              :                                    parmnum, rname);
    9171          306 :                 if (warned)
    9172          174 :                   inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
    9173          306 :               }
    9174          306 :               break;
    9175          267 :             case ic_assign:
    9176          267 :               if (bltin)
    9177           11 :                 warned
    9178           11 :                   = permerror_opt (location, OPT_Wincompatible_pointer_types,
    9179              :                                    "assignment to %e from pointer to "
    9180              :                                    "%qD with incompatible type %e",
    9181              :                                    &e_type, bltin, &e_rhstype);
    9182              :               else
    9183          256 :                 warned
    9184          256 :                   = permerror_opt (location, OPT_Wincompatible_pointer_types,
    9185              :                                    "assignment to %e from incompatible "
    9186              :                                    "pointer type %e",
    9187              :                                    &e_type, &e_rhstype);
    9188              :               break;
    9189          167 :             case ic_init:
    9190          167 :             case ic_init_const:
    9191          167 :               if (bltin)
    9192           13 :                 warned
    9193           13 :                   = permerror_init (location, OPT_Wincompatible_pointer_types,
    9194              :                                     "initialization of %e from pointer to "
    9195              :                                     "%qD with incompatible type %e",
    9196              :                                     &e_type, bltin, &e_rhstype);
    9197              :               else
    9198          154 :                 warned
    9199          154 :                   = permerror_init (location, OPT_Wincompatible_pointer_types,
    9200              :                                     "initialization of %e from incompatible "
    9201              :                                     "pointer type %e",
    9202              :                                     &e_type, &e_rhstype);
    9203              :               break;
    9204           59 :             case ic_return:
    9205           59 :               if (bltin)
    9206           11 :                 warned
    9207           11 :                   = permerror_opt (location, OPT_Wincompatible_pointer_types,
    9208              :                                    "returning pointer to %qD of type %e from "
    9209              :                                    "a function with incompatible type %e",
    9210              :                                    bltin, &e_rhstype, &e_type);
    9211              :               else
    9212           48 :                 warned
    9213           48 :                   = permerror_opt (location, OPT_Wincompatible_pointer_types,
    9214              :                                    "returning %e from a function with "
    9215              :                                    "incompatible return type %e",
    9216              :                                    &e_rhstype, &e_type);
    9217              :               break;
    9218            0 :             default:
    9219            0 :               gcc_unreachable ();
    9220              :             }
    9221          799 :           if (warned)
    9222              :             {
    9223              :               /* If the mismatching function type is a pointer to a function,
    9224              :                  try to show the decl of the function.  */
    9225          589 :               if (TREE_CODE (rhs) == ADDR_EXPR
    9226          589 :                   && TREE_CODE (TREE_OPERAND (rhs, 0)) == FUNCTION_DECL)
    9227              :                 {
    9228          191 :                   tree rhs_fndecl = TREE_OPERAND (rhs, 0);
    9229          191 :                   if (!DECL_IS_UNDECLARED_BUILTIN (rhs_fndecl))
    9230              :                     {
    9231          165 :                       gcc_rich_location richloc
    9232          165 :                         (DECL_SOURCE_LOCATION (rhs_fndecl), nullptr,
    9233          165 :                          highlight_colors::actual);
    9234          165 :                       pp_element_quoted_decl e_rhs_fndecl
    9235          165 :                         (rhs_fndecl, highlight_colors::actual);
    9236          165 :                       inform (&richloc,
    9237              :                               "%e declared here", &e_rhs_fndecl);
    9238          165 :                     }
    9239              :                 }
    9240              :               /* If either/both of the types are typedefs, show the decl.  */
    9241          589 :               maybe_inform_typedef_location (type,
    9242              :                                              highlight_colors::expected);
    9243          589 :               maybe_inform_typedef_location (rhstype,
    9244              :                                              highlight_colors::actual);
    9245              :             }
    9246          799 :         }
    9247              : 
    9248              :       /* If RHS isn't an address, check pointer or array of packed
    9249              :          struct or union.  */
    9250      2024290 :       warn_for_address_of_packed_member (type, orig_rhs);
    9251              : 
    9252      2024290 :       return convert (type, rhs);
    9253              :     }
    9254        80134 :   else if (codel == POINTER_TYPE && coder == ARRAY_TYPE)
    9255              :     {
    9256              :       /* ??? This should not be an error when inlining calls to
    9257              :          unprototyped functions.  */
    9258            4 :       const char msg[] = "invalid use of non-lvalue array";
    9259            4 :       if (warnopt)
    9260            0 :         warning_at (location, warnopt, msg);
    9261              :       else
    9262            4 :         error_at (location, msg);
    9263            4 :       return error_mark_node;
    9264              :     }
    9265        80130 :   else if (codel == POINTER_TYPE
    9266        78607 :            && (coder == INTEGER_TYPE
    9267        78607 :                || coder == ENUMERAL_TYPE
    9268          616 :                || coder == BOOLEAN_TYPE
    9269          616 :                || coder == NULLPTR_TYPE
    9270           27 :                || coder == BITINT_TYPE))
    9271              :     {
    9272        78594 :       if (null_pointer_constant && c_inhibit_evaluation_warnings == 0
    9273        77596 :           && coder != NULLPTR_TYPE)
    9274        77036 :         warning_at (location, OPT_Wzero_as_null_pointer_constant,
    9275              :                     "zero as null pointer constant");
    9276              :       /* A NULLPTR type is just a nullptr always.  */
    9277        78034 :       if (coder == NULLPTR_TYPE)
    9278          575 :         return omit_one_operand_loc (expr_loc, type, nullptr_node, rhs);
    9279              :       /* An explicit constant 0 or type nullptr_t can convert to a pointer,
    9280              :          or one that results from arithmetic, even including a cast to
    9281              :          integer type.  */
    9282        78019 :       else if (!null_pointer_constant)
    9283          972 :         switch (errtype)
    9284              :           {
    9285          800 :           case ic_argpass:
    9286          800 :             {
    9287          800 :               auto_diagnostic_group d;
    9288          800 :               range_label_for_type_mismatch rhs_label (rhstype, type);
    9289          800 :               gcc_rich_location richloc (expr_loc, &rhs_label,
    9290          800 :                                          highlight_colors::actual);
    9291          800 :               if (permerror_opt (&richloc, OPT_Wint_conversion,
    9292              :                                  "passing argument %d of %qE makes pointer "
    9293              :                                  "from integer without a cast", parmnum, rname))
    9294              :                 {
    9295          439 :                   maybe_emit_indirection_note (expr_loc, rhs, type);
    9296          439 :                   inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
    9297              :                 }
    9298          800 :             }
    9299          800 :             break;
    9300           93 :           case ic_assign:
    9301           93 :             permerror_opt (location, OPT_Wint_conversion,
    9302              :                            "assignment to %qT from %qT makes pointer from "
    9303              :                            "integer without a cast", type, rhstype);
    9304           93 :             break;
    9305           56 :           case ic_init:
    9306           56 :           case ic_init_const:
    9307           56 :             permerror_init (location, OPT_Wint_conversion,
    9308              :                             "initialization of %qT from %qT makes pointer "
    9309              :                             "from integer without a cast", type, rhstype);
    9310           56 :             break;
    9311           23 :           case ic_return:
    9312           23 :             permerror_init (location, OPT_Wint_conversion,
    9313              :                             "returning %qT from a function with return type "
    9314              :                             "%qT makes pointer from integer without a cast",
    9315              :                             rhstype, type);
    9316           23 :             break;
    9317            0 :           default:
    9318            0 :             gcc_unreachable ();
    9319              :           }
    9320              : 
    9321        78019 :       return convert (type, rhs);
    9322              :     }
    9323         1536 :   else if ((codel == INTEGER_TYPE || codel == BITINT_TYPE)
    9324          540 :            && coder == POINTER_TYPE)
    9325              :     {
    9326          514 :       switch (errtype)
    9327              :         {
    9328          344 :         case ic_argpass:
    9329          344 :           {
    9330          344 :             auto_diagnostic_group d;
    9331          344 :             range_label_for_type_mismatch rhs_label (rhstype, type);
    9332          344 :             gcc_rich_location richloc (expr_loc, &rhs_label,
    9333          344 :                                        highlight_colors::actual);
    9334          344 :             if (permerror_opt (&richloc, OPT_Wint_conversion,
    9335              :                                "passing argument %d of %qE makes integer from "
    9336              :                                "pointer without a cast", parmnum, rname))
    9337              :               {
    9338          323 :                 maybe_emit_indirection_note (expr_loc, rhs, type);
    9339          323 :                 inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
    9340              :               }
    9341          344 :           }
    9342          344 :           break;
    9343           52 :         case ic_assign:
    9344           52 :           permerror_opt (location, OPT_Wint_conversion,
    9345              :                          "assignment to %qT from %qT makes integer from "
    9346              :                          "pointer without a cast", type, rhstype);
    9347           52 :           break;
    9348           83 :         case ic_init:
    9349           83 :         case ic_init_const:
    9350           83 :           permerror_init (location, OPT_Wint_conversion,
    9351              :                           "initialization of %qT from %qT makes integer "
    9352              :                           "from pointer without a cast", type, rhstype);
    9353           83 :           break;
    9354           35 :         case ic_return:
    9355           35 :           permerror_opt (location, OPT_Wint_conversion, "returning %qT from a "
    9356              :                          "function with return type %qT makes integer from "
    9357              :                          "pointer without a cast", rhstype, type);
    9358           35 :           break;
    9359            0 :         default:
    9360            0 :           gcc_unreachable ();
    9361              :         }
    9362              : 
    9363          514 :       return convert (type, rhs);
    9364              :     }
    9365          626 :   else if (C_BOOLEAN_TYPE_P (type)
    9366              :            /* The type nullptr_t may be converted to bool.  The
    9367              :               result is false.  */
    9368         1024 :            && (coder == POINTER_TYPE || coder == NULLPTR_TYPE))
    9369              :     {
    9370          398 :       tree ret;
    9371          398 :       bool save = in_late_binary_op;
    9372          398 :       in_late_binary_op = true;
    9373          398 :       ret = convert (type, rhs);
    9374          398 :       in_late_binary_op = save;
    9375          398 :       return ret;
    9376              :     }
    9377          624 :   else if (codel == NULLPTR_TYPE && null_pointer_constant)
    9378            6 :     return convert (type, rhs);
    9379              : 
    9380          618 :   switch (errtype)
    9381              :     {
    9382           35 :     case ic_argpass:
    9383           35 :       {
    9384           35 :         auto_diagnostic_group d;
    9385           35 :         range_label_for_type_mismatch rhs_label (rhstype, type);
    9386           35 :         gcc_rich_location richloc (expr_loc, &rhs_label,
    9387           35 :                                    highlight_colors::actual);
    9388           35 :         const char msg[] = G_("incompatible type for argument %d of %qE");
    9389           35 :         if (warnopt)
    9390            8 :           warning_at (expr_loc, warnopt, msg, parmnum, rname);
    9391              :         else
    9392           27 :           error_at (&richloc, msg, parmnum, rname);
    9393           35 :         inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
    9394           35 :       }
    9395           35 :       break;
    9396          108 :     case ic_assign:
    9397          108 :       {
    9398          108 :         const char msg[]
    9399              :           = G_("incompatible types when assigning to type %qT from type %qT");
    9400          108 :         if (warnopt)
    9401            0 :           warning_at (expr_loc, 0, msg, type, rhstype);
    9402              :         else
    9403          108 :           error_at (expr_loc, msg, type, rhstype);
    9404          108 :         break;
    9405              :       }
    9406          460 :     case ic_init:
    9407          460 :     case ic_init_const:
    9408          460 :       {
    9409          460 :         const char msg[]
    9410              :           = G_("incompatible types when initializing type %qT using type %qT");
    9411          460 :         if (warnopt)
    9412            0 :           warning_at (location, 0, msg, type, rhstype);
    9413              :         else
    9414          460 :           error_at (location, msg, type, rhstype);
    9415          460 :         break;
    9416              :       }
    9417           15 :     case ic_return:
    9418           15 :       {
    9419           15 :         const char msg[]
    9420              :           = G_("incompatible types when returning type %qT but %qT was expected");
    9421           15 :         if (warnopt)
    9422            0 :           warning_at (location, 0, msg, rhstype, type);
    9423              :         else
    9424           15 :           error_at (location, msg, rhstype, type);
    9425           15 :         break;
    9426              :       }
    9427            0 :     default:
    9428            0 :       gcc_unreachable ();
    9429              :     }
    9430              : 
    9431          618 :   return error_mark_node;
    9432              : }
    9433              : 
    9434              : /* If VALUE is a compound expr all of whose expressions are constant, then
    9435              :    return its value.  Otherwise, return error_mark_node.
    9436              : 
    9437              :    This is for handling COMPOUND_EXPRs as initializer elements
    9438              :    which is allowed with a warning when -pedantic is specified.  */
    9439              : 
    9440              : static tree
    9441            2 : valid_compound_expr_initializer (tree value, tree endtype)
    9442              : {
    9443            2 :   if (TREE_CODE (value) == COMPOUND_EXPR)
    9444              :     {
    9445            1 :       if (valid_compound_expr_initializer (TREE_OPERAND (value, 0), endtype)
    9446            1 :           == error_mark_node)
    9447              :         return error_mark_node;
    9448            0 :       return valid_compound_expr_initializer (TREE_OPERAND (value, 1),
    9449            0 :                                               endtype);
    9450              :     }
    9451            1 :   else if (!initializer_constant_valid_p (value, endtype))
    9452            1 :     return error_mark_node;
    9453              :   else
    9454              :     return value;
    9455              : }
    9456              : 
    9457              : /* Perform appropriate conversions on the initial value of a variable,
    9458              :    store it in the declaration DECL,
    9459              :    and print any error messages that are appropriate.
    9460              :    If ORIGTYPE is not NULL_TREE, it is the original type of INIT.
    9461              :    If the init is invalid, store an ERROR_MARK.
    9462              : 
    9463              :    INIT_LOC is the location of the initial value.  */
    9464              : 
    9465              : void
    9466      7275904 : store_init_value (location_t init_loc, tree decl, tree init, tree origtype)
    9467              : {
    9468      7275904 :   tree value, type;
    9469      7275904 :   bool npc = false;
    9470      7275904 :   bool int_const_expr = false;
    9471      7275904 :   bool arith_const_expr = false;
    9472              : 
    9473              :   /* If variable's type was invalidly declared, just ignore it.  */
    9474              : 
    9475      7275904 :   type = TREE_TYPE (decl);
    9476      7275904 :   if (TREE_CODE (type) == ERROR_MARK)
    9477              :     return;
    9478              : 
    9479              :   /* Digest the specified initializer into an expression.  */
    9480              : 
    9481      7275896 :   if (init)
    9482              :     {
    9483      7275893 :       npc = null_pointer_constant_p (init);
    9484      7275893 :       int_const_expr = (TREE_CODE (init) == INTEGER_CST
    9485       420980 :                         && !TREE_OVERFLOW (init)
    9486      7696837 :                         && INTEGRAL_TYPE_P (TREE_TYPE (init)));
    9487              :       /* Not fully determined before folding.  */
    9488              :       arith_const_expr = true;
    9489              :     }
    9490      7275896 :   bool constexpr_p = (VAR_P (decl)
    9491      7275896 :                       && C_DECL_DECLARED_CONSTEXPR (decl));
    9492      7275896 :   value = digest_init (init_loc, decl, type, init, origtype, npc,
    9493              :                        int_const_expr, arith_const_expr, true,
    9494      7275896 :                        TREE_STATIC (decl) || constexpr_p, constexpr_p);
    9495              : 
    9496              :   /* Store the expression if valid; else report error.  */
    9497              : 
    9498      7275896 :   if (!in_system_header_at (input_location)
    9499      7275896 :       && AGGREGATE_TYPE_P (TREE_TYPE (decl)) && !TREE_STATIC (decl))
    9500        29003 :     warning (OPT_Wtraditional, "traditional C rejects automatic "
    9501              :              "aggregate initialization");
    9502              : 
    9503      7275896 :   if (value != error_mark_node || TREE_CODE (decl) != FUNCTION_DECL)
    9504      7275895 :     DECL_INITIAL (decl) = value;
    9505              : 
    9506              :   /* ANSI wants warnings about out-of-range constant initializers.  */
    9507      7275907 :   STRIP_TYPE_NOPS (value);
    9508      7275896 :   if (TREE_STATIC (decl))
    9509       181220 :     constant_expression_warning (value);
    9510              : 
    9511              :   /* Check if we need to set array size from compound literal size.  */
    9512      7275896 :   if (TREE_CODE (type) == ARRAY_TYPE
    9513        26825 :       && TYPE_DOMAIN (type) == NULL_TREE
    9514      7288485 :       && value != error_mark_node)
    9515              :     {
    9516              :       tree inside_init = init;
    9517              : 
    9518        11717 :       STRIP_TYPE_NOPS (inside_init);
    9519        11717 :       inside_init = fold (inside_init);
    9520              : 
    9521        11717 :       if (TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
    9522              :         {
    9523           13 :           tree cldecl = COMPOUND_LITERAL_EXPR_DECL (inside_init);
    9524              : 
    9525           13 :           if (TYPE_DOMAIN (TREE_TYPE (cldecl)))
    9526              :             {
    9527              :               /* For int foo[] = (int [3]){1}; we need to set array size
    9528              :                  now since later on array initializer will be just the
    9529              :                  brace enclosed list of the compound literal.  */
    9530           13 :               tree etype = strip_array_types (TREE_TYPE (decl));
    9531           13 :               type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
    9532           13 :               TYPE_DOMAIN (type) = TYPE_DOMAIN (TREE_TYPE (cldecl));
    9533           13 :               layout_type (type);
    9534           13 :               layout_decl (cldecl, 0);
    9535           13 :               TREE_TYPE (decl)
    9536           26 :                 = c_build_qualified_type (type, TYPE_QUALS (etype));
    9537              :             }
    9538              :         }
    9539              :     }
    9540              : }
    9541              : 
    9542              : /* Methods for storing and printing names for error messages.  */
    9543              : 
    9544              : /* Implement a spelling stack that allows components of a name to be pushed
    9545              :    and popped.  Each element on the stack is this structure.  */
    9546              : 
    9547              : struct spelling
    9548              : {
    9549              :   int kind;
    9550              :   union
    9551              :     {
    9552              :       unsigned HOST_WIDE_INT i;
    9553              :       const char *s;
    9554              :     } u;
    9555              : };
    9556              : 
    9557              : #define SPELLING_STRING 1
    9558              : #define SPELLING_MEMBER 2
    9559              : #define SPELLING_BOUNDS 3
    9560              : 
    9561              : static struct spelling *spelling;       /* Next stack element (unused).  */
    9562              : static struct spelling *spelling_base;  /* Spelling stack base.  */
    9563              : static int spelling_size;               /* Size of the spelling stack.  */
    9564              : 
    9565              : /* Macros to save and restore the spelling stack around push_... functions.
    9566              :    Alternative to SAVE_SPELLING_STACK.  */
    9567              : 
    9568              : #define SPELLING_DEPTH() (spelling - spelling_base)
    9569              : #define RESTORE_SPELLING_DEPTH(DEPTH) (spelling = spelling_base + (DEPTH))
    9570              : 
    9571              : /* Push an element on the spelling stack with type KIND and assign VALUE
    9572              :    to MEMBER.  */
    9573              : 
    9574              : #define PUSH_SPELLING(KIND, VALUE, MEMBER)                              \
    9575              : {                                                                       \
    9576              :   int depth = SPELLING_DEPTH ();                                        \
    9577              :                                                                         \
    9578              :   if (depth >= spelling_size)                                                \
    9579              :     {                                                                   \
    9580              :       spelling_size += 10;                                              \
    9581              :       spelling_base = XRESIZEVEC (struct spelling, spelling_base,       \
    9582              :                                   spelling_size);                       \
    9583              :       RESTORE_SPELLING_DEPTH (depth);                                   \
    9584              :     }                                                                   \
    9585              :                                                                         \
    9586              :   spelling->kind = (KIND);                                           \
    9587              :   spelling->MEMBER = (VALUE);                                                \
    9588              :   spelling++;                                                           \
    9589              : }
    9590              : 
    9591              : /* Push STRING on the stack.  Printed literally.  */
    9592              : 
    9593              : static void
    9594      7273119 : push_string (const char *string)
    9595              : {
    9596      7273119 :   PUSH_SPELLING (SPELLING_STRING, string, u.s);
    9597      7273119 : }
    9598              : 
    9599              : /* Push a member name on the stack.  Printed as '.' STRING.  */
    9600              : 
    9601              : static void
    9602      1230935 : push_member_name (tree decl)
    9603              : {
    9604      1230935 :   const char *const string
    9605      1230935 :     = (DECL_NAME (decl)
    9606      1230935 :        ? identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl)))
    9607          210 :        : _("<anonymous>"));
    9608      1230935 :   PUSH_SPELLING (SPELLING_MEMBER, string, u.s);
    9609      1230935 : }
    9610              : 
    9611              : /* Push an array bounds on the stack.  Printed as [BOUNDS].  */
    9612              : 
    9613              : static void
    9614      2604526 : push_array_bounds (unsigned HOST_WIDE_INT bounds)
    9615              : {
    9616      2604526 :   PUSH_SPELLING (SPELLING_BOUNDS, bounds, u.i);
    9617      2604526 : }
    9618              : 
    9619              : /* Compute the maximum size in bytes of the printed spelling.  */
    9620              : 
    9621              : static int
    9622         2892 : spelling_length (void)
    9623              : {
    9624         2892 :   int size = 0;
    9625         2892 :   struct spelling *p;
    9626              : 
    9627         6416 :   for (p = spelling_base; p < spelling; p++)
    9628              :     {
    9629         3524 :       if (p->kind == SPELLING_BOUNDS)
    9630         1479 :         size += 25;
    9631              :       else
    9632         2045 :         size += strlen (p->u.s) + 1;
    9633              :     }
    9634              : 
    9635         2892 :   return size;
    9636              : }
    9637              : 
    9638              : /* Print the spelling to BUFFER and return it.  */
    9639              : 
    9640              : static char *
    9641         2892 : print_spelling (char *buffer)
    9642              : {
    9643         2892 :   char *d = buffer;
    9644         2892 :   struct spelling *p;
    9645              : 
    9646         6416 :   for (p = spelling_base; p < spelling; p++)
    9647         3524 :     if (p->kind == SPELLING_BOUNDS)
    9648              :       {
    9649         1479 :         sprintf (d, "[" HOST_WIDE_INT_PRINT_UNSIGNED "]", p->u.i);
    9650         1479 :         d += strlen (d);
    9651              :       }
    9652              :     else
    9653              :       {
    9654         2045 :         const char *s;
    9655         2045 :         if (p->kind == SPELLING_MEMBER)
    9656          198 :           *d++ = '.';
    9657        16715 :         for (s = p->u.s; (*d = *s++); d++)
    9658              :           ;
    9659              :       }
    9660         2892 :   *d++ = '\0';
    9661         2892 :   return buffer;
    9662              : }
    9663              : 
    9664              : /* Check whether INIT, a floating or integer constant, is
    9665              :    representable in TYPE, a real floating type with the same radix or
    9666              :    a decimal floating type initialized with a binary floating
    9667              :    constant.  Return true if OK, false if not.  */
    9668              : static bool
    9669          362 : constexpr_init_fits_real_type (tree type, tree init)
    9670              : {
    9671          362 :   gcc_assert (SCALAR_FLOAT_TYPE_P (type));
    9672          362 :   gcc_assert (TREE_CODE (init) == INTEGER_CST || TREE_CODE (init) == REAL_CST);
    9673          362 :   if (TREE_CODE (init) == REAL_CST
    9674          362 :       && TYPE_MODE (TREE_TYPE (init)) == TYPE_MODE (type))
    9675              :     {
    9676              :       /* Same mode, no conversion required except for the case of
    9677              :          signaling NaNs if the types are incompatible (e.g. double and
    9678              :          long double with the same mode).  */
    9679          177 :       if (REAL_VALUE_ISSIGNALING_NAN (TREE_REAL_CST (init))
    9680          195 :           && !comptypes (TYPE_MAIN_VARIANT (type),
    9681           18 :                          TYPE_MAIN_VARIANT (TREE_TYPE (init))))
    9682              :         return false;
    9683          177 :       return true;
    9684              :     }
    9685          185 :   if (TREE_CODE (init) == INTEGER_CST)
    9686              :     {
    9687           54 :       tree converted = build_real_from_int_cst (type, init);
    9688           54 :       bool fail = false;
    9689          108 :       wide_int w = real_to_integer (&TREE_REAL_CST (converted), &fail,
    9690           54 :                                     TYPE_PRECISION (TREE_TYPE (init)));
    9691           68 :       return !fail && wi::eq_p (w, wi::to_wide (init));
    9692           54 :     }
    9693          131 :   if (REAL_VALUE_ISSIGNALING_NAN (TREE_REAL_CST (init)))
    9694              :     return false;
    9695          114 :   if ((REAL_VALUE_ISINF (TREE_REAL_CST (init))
    9696           34 :        && MODE_HAS_INFINITIES (TYPE_MODE (type)))
    9697          218 :       || (REAL_VALUE_ISNAN (TREE_REAL_CST (init))
    9698           34 :           && MODE_HAS_NANS (TYPE_MODE (type))))
    9699           20 :     return true;
    9700           94 :   if (DECIMAL_FLOAT_TYPE_P (type)
    9701          134 :       && !DECIMAL_FLOAT_TYPE_P (TREE_TYPE (init)))
    9702              :     {
    9703              :       /* This is valid if the real number represented by the
    9704              :          initializer can be exactly represented in the decimal
    9705              :          type.  Compare the values using MPFR.  */
    9706            8 :       REAL_VALUE_TYPE t;
    9707            8 :       real_convert (&t, TYPE_MODE (type), &TREE_REAL_CST (init));
    9708            8 :       mpfr_t bin_val, dec_val;
    9709            8 :       mpfr_init2 (bin_val, REAL_MODE_FORMAT (TYPE_MODE (TREE_TYPE (init)))->p);
    9710            8 :       mpfr_init2 (dec_val, REAL_MODE_FORMAT (TYPE_MODE (TREE_TYPE (init)))->p);
    9711            8 :       mpfr_from_real (bin_val, &TREE_REAL_CST (init), MPFR_RNDN);
    9712            8 :       char string[256];
    9713            8 :       real_to_decimal (string, &t, sizeof string, 0, 1);
    9714            8 :       bool res = (mpfr_strtofr (dec_val, string, NULL, 10, MPFR_RNDN) == 0
    9715            8 :                   && mpfr_equal_p (bin_val, dec_val));
    9716            8 :       mpfr_clear (bin_val);
    9717            8 :       mpfr_clear (dec_val);
    9718            8 :       return res;
    9719              :     }
    9720              :   /* exact_real_truncate is not quite right here, since it doesn't
    9721              :      allow even an exact conversion to subnormal values.  */
    9722           86 :   REAL_VALUE_TYPE t;
    9723           86 :   real_convert (&t, TYPE_MODE (type), &TREE_REAL_CST (init));
    9724           86 :   return real_identical (&t, &TREE_REAL_CST (init));
    9725              : }
    9726              : 
    9727              : /* Check whether INIT (location LOC) is valid as a 'constexpr'
    9728              :    initializer for type TYPE, and give an error if not.  INIT has
    9729              :    already been folded and verified to be constant.  INT_CONST_EXPR
    9730              :    and ARITH_CONST_EXPR say whether it is an integer constant
    9731              :    expression or arithmetic constant expression, respectively.  If
    9732              :    TYPE is not a scalar type, this function does nothing.  */
    9733              : 
    9734              : static void
    9735          916 : check_constexpr_init (location_t loc, tree type, tree init,
    9736              :                       bool int_const_expr, bool arith_const_expr)
    9737              : {
    9738          916 :   if (POINTER_TYPE_P (type))
    9739              :     {
    9740              :       /* The initializer must be null.  */
    9741           86 :       if (TREE_CODE (init) != INTEGER_CST || !integer_zerop (init))
    9742            8 :         error_at (loc, "%<constexpr%> pointer initializer is not null");
    9743           86 :       return;
    9744              :     }
    9745          830 :   if (INTEGRAL_TYPE_P (type))
    9746              :     {
    9747              :       /* The initializer must be an integer constant expression,
    9748              :          representable in the target type.  */
    9749          320 :       if (!int_const_expr)
    9750              :         {
    9751           13 :           if (TREE_CODE (init) == RAW_DATA_CST
    9752           13 :               && TYPE_PRECISION (type) == CHAR_BIT)
    9753              :             {
    9754            4 :               if (!TYPE_UNSIGNED (type))
    9755          137 :                 for (unsigned int i = 0;
    9756          140 :                      i < (unsigned) RAW_DATA_LENGTH (init); ++i)
    9757          138 :                   if (RAW_DATA_SCHAR_ELT (init, i) < 0)
    9758              :                     {
    9759            1 :                       error_at (loc, "%<constexpr%> initializer not "
    9760              :                                 "representable in type of object");
    9761            1 :                       break;
    9762              :                     }
    9763              :             }
    9764              :           else
    9765            9 :             error_at (loc, "%<constexpr%> integer initializer is not an "
    9766              :                       "integer constant expression");
    9767              :         }
    9768          307 :       else if (!int_fits_type_p (init, type))
    9769            6 :         error_at (loc, "%<constexpr%> initializer not representable in "
    9770              :                   "type of object");
    9771          320 :       return;
    9772              :     }
    9773              :   /* We don't apply any extra checks to extension types such as vector
    9774              :      or fixed-point types.  */
    9775          510 :   if (TREE_CODE (type) != REAL_TYPE && TREE_CODE (type) != COMPLEX_TYPE)
    9776              :     return;
    9777          353 :   if (!arith_const_expr)
    9778              :     {
    9779            5 :       error_at (loc, "%<constexpr%> initializer is not an arithmetic "
    9780              :                 "constant expression");
    9781            5 :       return;
    9782              :     }
    9783              :   /* We don't apply any extra checks to complex integers.  */
    9784          348 :   if (TREE_CODE (type) == COMPLEX_TYPE
    9785          348 :       && TREE_CODE (TREE_TYPE (type)) != REAL_TYPE)
    9786              :     return;
    9787              :   /* Following N3082, a real type cannot be initialized from a complex
    9788              :      type and a binary type cannot be initialized from a decimal type
    9789              :      (but initializing a decimal type from a binary type is OK).
    9790              :      Signaling NaN initializers are OK only if the types are
    9791              :      compatible (not just the same mode); all quiet NaN and infinity
    9792              :      initializations are considered to preserve the value.  */
    9793          348 :   if (TREE_CODE (TREE_TYPE (init)) == COMPLEX_TYPE
    9794          348 :       && SCALAR_FLOAT_TYPE_P (type))
    9795              :     {
    9796            6 :       error_at (loc, "%<constexpr%> initializer for a real type is of "
    9797              :                 "complex type");
    9798            6 :       return;
    9799              :     }
    9800          342 :   if (SCALAR_FLOAT_TYPE_P (type)
    9801          300 :       && SCALAR_FLOAT_TYPE_P (TREE_TYPE (init))
    9802          250 :       && DECIMAL_FLOAT_TYPE_P (TREE_TYPE (init))
    9803          481 :       && !DECIMAL_FLOAT_TYPE_P (type))
    9804              :     {
    9805            6 :       error_at (loc, "%<constexpr%> initializer for a binary "
    9806              :                 "floating-point type is of decimal type");
    9807            6 :       return;
    9808              :     }
    9809          336 :   bool fits;
    9810          336 :   if (TREE_CODE (type) == COMPLEX_TYPE)
    9811              :     {
    9812           42 :       switch (TREE_CODE (init))
    9813              :         {
    9814           10 :         case INTEGER_CST:
    9815           10 :         case REAL_CST:
    9816           10 :           fits = constexpr_init_fits_real_type (TREE_TYPE (type), init);
    9817           10 :           break;
    9818           32 :         case COMPLEX_CST:
    9819           32 :           fits = (constexpr_init_fits_real_type (TREE_TYPE (type),
    9820           32 :                                                  TREE_REALPART (init))
    9821           58 :                   && constexpr_init_fits_real_type (TREE_TYPE (type),
    9822           26 :                                                     TREE_IMAGPART (init)));
    9823              :           break;
    9824            0 :         default:
    9825            0 :           gcc_unreachable ();
    9826              :         }
    9827              :     }
    9828              :   else
    9829          294 :     fits = constexpr_init_fits_real_type (type, init);
    9830          304 :   if (!fits)
    9831           65 :     error_at (loc, "%<constexpr%> initializer not representable in "
    9832              :               "type of object");
    9833              : }
    9834              : 
    9835              : /* Digest the parser output INIT as an initializer for type TYPE
    9836              :    initializing DECL.
    9837              :    Return a C expression of type TYPE to represent the initial value.
    9838              : 
    9839              :    If ORIGTYPE is not NULL_TREE, it is the original type of INIT.
    9840              : 
    9841              :    NULL_POINTER_CONSTANT is true if INIT is a null pointer constant,
    9842              :    INT_CONST_EXPR is true if INIT is an integer constant expression,
    9843              :    and ARITH_CONST_EXPR is true if INIT is, or might be, an arithmetic
    9844              :    constant expression, false if it has already been determined in the
    9845              :    caller that it is not (but folding may have made the value passed here
    9846              :    indistinguishable from an arithmetic constant expression).
    9847              : 
    9848              :    If INIT is a string constant, STRICT_STRING is true if it is
    9849              :    unparenthesized or we should not warn here for it being parenthesized.
    9850              :    For other types of INIT, STRICT_STRING is not used.
    9851              : 
    9852              :    INIT_LOC is the location of the INIT.
    9853              : 
    9854              :    REQUIRE_CONSTANT requests an error if non-constant initializers or
    9855              :    elements are seen.  REQUIRE_CONSTEXPR means the stricter requirements
    9856              :    on initializers for 'constexpr' objects apply.  */
    9857              : 
    9858              : static tree
    9859     16907450 : digest_init (location_t init_loc, tree decl, tree type, tree init,
    9860              :              tree origtype, bool null_pointer_constant, bool int_const_expr,
    9861              :              bool arith_const_expr, bool strict_string,
    9862              :              bool require_constant, bool require_constexpr)
    9863              : {
    9864     16907450 :   enum tree_code code = TREE_CODE (type);
    9865     16907450 :   tree inside_init = init;
    9866     16907450 :   tree semantic_type = NULL_TREE;
    9867     16907450 :   bool maybe_const = true;
    9868              : 
    9869     16907450 :   if (type == error_mark_node
    9870     16907450 :       || !init
    9871     33814897 :       || error_operand_p (init))
    9872              :     return error_mark_node;
    9873              : 
    9874     16914652 :   STRIP_TYPE_NOPS (inside_init);
    9875              : 
    9876              :   /* If require_constant is TRUE,  when the initializer is a call to
    9877              :      .ACCESS_WITH_SIZE, use the first argument as the initializer.
    9878              :      For example:
    9879              :      y = (char *) .ACCESS_WITH_SIZE ((char *) &static_annotated.c,...)
    9880              :      will be converted to
    9881              :      y = &static_annotated.c.  */
    9882              : 
    9883     16906087 :   if (require_constant
    9884      2893941 :       && TREE_CODE (inside_init) == NOP_EXPR
    9885       736245 :       && TREE_CODE (TREE_OPERAND (inside_init, 0)) == CALL_EXPR
    9886     16906089 :       && is_access_with_size_p (TREE_OPERAND (inside_init, 0)))
    9887            2 :     inside_init
    9888            2 :       = get_ref_from_access_with_size (TREE_OPERAND (inside_init, 0));
    9889              : 
    9890     16906087 :   if (!c_in_omp_for)
    9891              :     {
    9892     16901335 :       if (TREE_CODE (inside_init) == EXCESS_PRECISION_EXPR)
    9893              :         {
    9894          441 :           semantic_type = TREE_TYPE (inside_init);
    9895          441 :           inside_init = TREE_OPERAND (inside_init, 0);
    9896              :         }
    9897     16901335 :       inside_init = c_fully_fold (inside_init, require_constant, &maybe_const);
    9898              :     }
    9899              :   /* TODO: this may not detect all cases of expressions folding to
    9900              :      constants that are not arithmetic constant expressions.  */
    9901     16906087 :   if (!maybe_const)
    9902              :     arith_const_expr = false;
    9903     25230967 :   else if (!INTEGRAL_TYPE_P (TREE_TYPE (inside_init))
    9904      5660035 :            && TREE_CODE (TREE_TYPE (inside_init)) != REAL_TYPE
    9905     16841218 :            && TREE_CODE (TREE_TYPE (inside_init)) != COMPLEX_TYPE)
    9906              :     arith_const_expr = false;
    9907      8418314 :   else if (TREE_CODE (inside_init) != INTEGER_CST
    9908              :            && TREE_CODE (inside_init) != REAL_CST
    9909              :            && TREE_CODE (inside_init) != COMPLEX_CST
    9910              :            && TREE_CODE (inside_init) != RAW_DATA_CST)
    9911              :     arith_const_expr = false;
    9912      5078469 :   else if (TREE_OVERFLOW (inside_init))
    9913     11827662 :     arith_const_expr = false;
    9914              : 
    9915              :   /* Initialization of an array of chars from a string constant
    9916              :      optionally enclosed in braces.  */
    9917              : 
    9918     16906087 :   if (code == ARRAY_TYPE && inside_init
    9919       189513 :       && TREE_CODE (inside_init) == STRING_CST)
    9920              :     {
    9921        11789 :       tree typ1
    9922        11789 :         = (TYPE_ATOMIC (TREE_TYPE (type))
    9923        11789 :            ? c_build_qualified_type (TYPE_MAIN_VARIANT (TREE_TYPE (type)),
    9924              :                                      TYPE_QUAL_ATOMIC)
    9925        11775 :            : TYPE_MAIN_VARIANT (TREE_TYPE (type)));
    9926              :       /* Note that an array could be both an array of character type
    9927              :          and an array of wchar_t if wchar_t is signed char or unsigned
    9928              :          char.  */
    9929        23578 :       bool char_array = (typ1 == char_type_node
    9930          516 :                          || typ1 == signed_char_type_node
    9931        12270 :                          || typ1 == unsigned_char_type_node);
    9932        11789 :       bool wchar_array = comptypes (typ1, wchar_type_node);
    9933        11789 :       bool char16_array = comptypes (typ1, char16_type_node);
    9934        11789 :       bool char32_array = comptypes (typ1, char32_type_node);
    9935              : 
    9936        11789 :       if (char_array || wchar_array || char16_array || char32_array)
    9937              :         {
    9938        11760 :           struct c_expr expr;
    9939        11760 :           tree typ2 = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init)));
    9940        11760 :           bool incompat_string_cst = false;
    9941        11760 :           expr.value = inside_init;
    9942        11760 :           expr.original_code = (strict_string ? STRING_CST : ERROR_MARK);
    9943        11760 :           expr.original_type = NULL;
    9944        11760 :           expr.m_decimal = 0;
    9945        11760 :           maybe_warn_string_init (init_loc, type, expr);
    9946              : 
    9947        11760 :           if (TYPE_DOMAIN (type) && !TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
    9948           91 :             pedwarn_init (init_loc, OPT_Wpedantic,
    9949              :                           "initialization of a flexible array member");
    9950              : 
    9951        11760 :           if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
    9952        11760 :                          TYPE_MAIN_VARIANT (type)))
    9953              :             return inside_init;
    9954              : 
    9955         4186 :           if (char_array)
    9956              :             {
    9957         4075 :               if (typ2 != char_type_node && typ2 != char8_type_node)
    9958              :                 incompat_string_cst = true;
    9959              :             }
    9960          111 :           else if (!comptypes (typ1, typ2))
    9961              :             incompat_string_cst = true;
    9962              : 
    9963              :           if (incompat_string_cst)
    9964              :             {
    9965           72 :               error_init (init_loc, "cannot initialize array of %qT from "
    9966              :                           "a string literal with type array of %qT",
    9967              :                           typ1, typ2);
    9968           72 :               return error_mark_node;
    9969              :             }
    9970              : 
    9971         4114 :           if (require_constexpr
    9972         4114 :               && TYPE_UNSIGNED (typ1) != TYPE_UNSIGNED (typ2))
    9973              :             {
    9974              :               /* Check if all characters of the string can be
    9975              :                  represented in the type of the constexpr object being
    9976              :                  initialized.  */
    9977           24 :               unsigned HOST_WIDE_INT len = TREE_STRING_LENGTH (inside_init);
    9978           24 :               const unsigned char *p =
    9979           24 :                 (const unsigned char *) TREE_STRING_POINTER (inside_init);
    9980           24 :               gcc_assert (CHAR_TYPE_SIZE == 8 && CHAR_BIT == 8);
    9981           70 :               for (unsigned i = 0; i < len; i++)
    9982           58 :                 if (p[i] > 127)
    9983              :                   {
    9984           12 :                     error_init (init_loc, "%<constexpr%> initializer not "
    9985              :                                 "representable in type of object");
    9986           12 :                     break;
    9987              :                   }
    9988              :             }
    9989              : 
    9990         4114 :           if (TYPE_DOMAIN (type) != NULL_TREE
    9991         4020 :               && TYPE_SIZE (type) != NULL_TREE
    9992         8075 :               && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
    9993              :             {
    9994         3961 :               unsigned HOST_WIDE_INT len = TREE_STRING_LENGTH (inside_init);
    9995              : 
    9996         3961 :               if (compare_tree_int (TYPE_SIZE_UNIT (type), len) < 0)
    9997              :                 {
    9998          397 :                   unsigned HOST_WIDE_INT avail
    9999          397 :                     = tree_to_uhwi (TYPE_SIZE_UNIT (type));
   10000          397 :                   unsigned unit = TYPE_PRECISION (typ1) / BITS_PER_UNIT;
   10001          397 :                   const char *p = TREE_STRING_POINTER (inside_init);
   10002              : 
   10003              :                   /* Construct truncated string.  */
   10004          397 :                   inside_init = build_string (avail, p);
   10005              : 
   10006              :                   /* Subtract the size of a single (possibly wide) character
   10007              :                      because it may be ok to ignore the terminating NUL char
   10008              :                      that is counted in the length of the constant.  */
   10009          397 :                   if (len - unit > avail)
   10010           63 :                     pedwarn_init (init_loc, 0,
   10011              :                                   "initializer-string for array of %qT "
   10012              :                                   "is too long (%wu chars into %wu "
   10013              :                                   "available)", typ1, len, avail);
   10014          334 :                   else if (warn_cxx_compat)
   10015            9 :                     warning_at (init_loc, OPT_Wc___compat,
   10016              :                                 "initializer-string for array of %qT "
   10017              :                                 "is too long for C++ (%wu chars into %wu "
   10018              :                                 "available)", typ1, len, avail);
   10019          325 :                   else if (warn_unterminated_string_initialization
   10020          325 :                            && get_attr_nonstring_decl (decl) == NULL_TREE)
   10021           22 :                     warning_at (init_loc,
   10022           22 :                                 OPT_Wunterminated_string_initialization,
   10023              :                                 "initializer-string for array of %qT "
   10024              :                                 "truncates NUL terminator but destination "
   10025              :                                 "lacks %qs attribute (%wu chars into %wu "
   10026              :                                 "available)", typ1, "nonstring", len, avail);
   10027              :                 }
   10028              :             }
   10029              : 
   10030         4114 :           TREE_TYPE (inside_init) = type;
   10031         4114 :           return inside_init;
   10032              :         }
   10033           29 :       else if (INTEGRAL_TYPE_P (typ1))
   10034              :         {
   10035           29 :           error_init (init_loc, "array of inappropriate type initialized "
   10036              :                       "from string constant");
   10037           29 :           return error_mark_node;
   10038              :         }
   10039              :     }
   10040              : 
   10041              :   /* Build a VECTOR_CST from a *constant* vector constructor.  If the
   10042              :      vector constructor is not constant (e.g. {1,2,3,foo()}) then punt
   10043              :      below and handle as a constructor.  */
   10044     16894298 :   if (code == VECTOR_TYPE
   10045      6311095 :       && VECTOR_TYPE_P (TREE_TYPE (inside_init))
   10046      6311093 :       && vector_types_convertible_p (TREE_TYPE (inside_init), type, true)
   10047     23205353 :       && TREE_CONSTANT (inside_init))
   10048              :     {
   10049       633268 :       if (TREE_CODE (inside_init) == VECTOR_CST
   10050       633365 :           && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
   10051           97 :                         TYPE_MAIN_VARIANT (type)))
   10052              :         return inside_init;
   10053              : 
   10054       633171 :       if (TREE_CODE (inside_init) == CONSTRUCTOR)
   10055              :         {
   10056              :           unsigned HOST_WIDE_INT ix;
   10057              :           tree value;
   10058      4173687 :           bool constant_p = true;
   10059              : 
   10060              :           /* Iterate through elements and check if all constructor
   10061              :              elements are *_CSTs.  */
   10062      4173687 :           FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (inside_init), ix, value)
   10063      3540572 :             if (!CONSTANT_CLASS_P (value))
   10064              :               {
   10065              :                 constant_p = false;
   10066              :                 break;
   10067              :               }
   10068              : 
   10069       633171 :           if (constant_p)
   10070       633115 :             return build_vector_from_ctor (type,
   10071       633115 :                                            CONSTRUCTOR_ELTS (inside_init));
   10072              :         }
   10073              :     }
   10074              : 
   10075     16261086 :   if (warn_sequence_point)
   10076      2449307 :     verify_sequence_points (inside_init);
   10077              : 
   10078              :   /* Any type can be initialized
   10079              :      from an expression of the same type, optionally with braces.  */
   10080              : 
   10081     16261086 :   if (inside_init && TREE_TYPE (inside_init) != NULL_TREE
   10082     32522172 :       && (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
   10083     16261086 :                      TYPE_MAIN_VARIANT (type))
   10084      3134898 :           || (code == ARRAY_TYPE
   10085          477 :               && comptypes (TREE_TYPE (inside_init), type))
   10086      3134898 :           || (gnu_vector_type_p (type)
   10087          189 :               && comptypes (TREE_TYPE (inside_init), type))
   10088      3134898 :           || (code == POINTER_TYPE
   10089       112686 :               && TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE
   10090         9296 :               && comptypes (TREE_TYPE (TREE_TYPE (inside_init)),
   10091         9296 :                             TREE_TYPE (type)))))
   10092              :     {
   10093     13128166 :       if (code == POINTER_TYPE)
   10094              :         {
   10095       785225 :           if (TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE)
   10096              :             {
   10097         1978 :               if (TREE_CODE (inside_init) == STRING_CST
   10098           68 :                   || TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
   10099         1975 :                 inside_init = array_to_pointer_conversion
   10100         1975 :                   (init_loc, inside_init);
   10101              :               else
   10102              :                 {
   10103            3 :                   error_init (init_loc, "invalid use of non-lvalue array");
   10104            3 :                   return error_mark_node;
   10105              :                 }
   10106              :             }
   10107              :         }
   10108              : 
   10109     13128163 :       if (code == VECTOR_TYPE || c_hardbool_type_attr (type))
   10110              :         /* Although the types are compatible, we may require a
   10111              :            conversion.  */
   10112      5677827 :         inside_init = convert (type, inside_init);
   10113              : 
   10114     13128163 :       if ((code == RECORD_TYPE || code == UNION_TYPE)
   10115     13128163 :           && !comptypes (TYPE_MAIN_VARIANT (type), TYPE_MAIN_VARIANT (TREE_TYPE (inside_init))))
   10116              :         {
   10117            0 :           error_init (init_loc, "invalid initializer");
   10118            0 :           return error_mark_node;
   10119              :         }
   10120              : 
   10121     13128163 :       if (require_constant
   10122      2298229 :           && TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
   10123              :         {
   10124              :           /* As an extension, allow initializing objects with static storage
   10125              :              duration with compound literals (which are then treated just as
   10126              :              the brace enclosed list they contain).  Also allow this for
   10127              :              vectors, as we can only assign them with compound literals.  */
   10128           31 :           if (flag_isoc99 && code != VECTOR_TYPE)
   10129            8 :             pedwarn_init (init_loc, OPT_Wpedantic, "initializer element "
   10130              :                           "is not constant");
   10131           31 :           tree decl = COMPOUND_LITERAL_EXPR_DECL (inside_init);
   10132           31 :           inside_init = DECL_INITIAL (decl);
   10133              :         }
   10134              : 
   10135     13128163 :       if (code == ARRAY_TYPE && TREE_CODE (inside_init) != STRING_CST
   10136       177247 :           && TREE_CODE (inside_init) != CONSTRUCTOR)
   10137              :         {
   10138            2 :           error_init (init_loc, "array initialized from non-constant array "
   10139              :                       "expression");
   10140            2 :           return error_mark_node;
   10141              :         }
   10142              : 
   10143              :       /* Compound expressions can only occur here if -Wpedantic or
   10144              :          -pedantic-errors is specified.  In the later case, we always want
   10145              :          an error.  In the former case, we simply want a warning.  */
   10146     13128161 :       if (require_constant && pedantic
   10147        20308 :           && TREE_CODE (inside_init) == COMPOUND_EXPR)
   10148              :         {
   10149            1 :           inside_init
   10150            1 :             = valid_compound_expr_initializer (inside_init,
   10151            1 :                                                TREE_TYPE (inside_init));
   10152            1 :           if (inside_init == error_mark_node)
   10153            1 :             error_init (init_loc, "initializer element is not constant");
   10154              :           else
   10155            0 :             pedwarn_init (init_loc, OPT_Wpedantic,
   10156              :                           "initializer element is not constant");
   10157            1 :           if (flag_pedantic_errors)
   10158            0 :             inside_init = error_mark_node;
   10159              :         }
   10160      2298228 :       else if (require_constant
   10161      2298228 :                && !initializer_constant_valid_p (inside_init,
   10162      2298228 :                                                  TREE_TYPE (inside_init)))
   10163              :         {
   10164           94 :           error_init (init_loc, "initializer element is not constant");
   10165           94 :           inside_init = error_mark_node;
   10166              :         }
   10167     13128066 :       else if (require_constant && !maybe_const)
   10168          219 :         pedwarn_init (init_loc, OPT_Wpedantic,
   10169              :                       "initializer element is not a constant expression");
   10170     13127847 :       else if (require_constexpr)
   10171          584 :         check_constexpr_init (init_loc, type, inside_init,
   10172              :                               int_const_expr, arith_const_expr);
   10173              : 
   10174              :       /* Added to enable additional -Wsuggest-attribute=format warnings.  */
   10175     13128161 :       if (TREE_CODE (TREE_TYPE (inside_init)) == POINTER_TYPE)
   10176       854722 :         inside_init = convert_for_assignment (init_loc, UNKNOWN_LOCATION,
   10177              :                                               type, inside_init, origtype,
   10178              :                                               (require_constant
   10179              :                                                ? ic_init_const
   10180              :                                                : ic_init), null_pointer_constant,
   10181              :                                               NULL_TREE, NULL_TREE, 0);
   10182     13128161 :       if (TREE_CODE (inside_init) == RAW_DATA_CST
   10183          256 :           && c_inhibit_evaluation_warnings == 0
   10184          256 :           && warn_conversion
   10185            1 :           && !TYPE_UNSIGNED (type)
   10186     13128162 :           && TYPE_PRECISION (type) == CHAR_BIT)
   10187          303 :         for (unsigned int i = 0;
   10188          304 :              i < (unsigned) RAW_DATA_LENGTH (inside_init); ++i)
   10189          303 :           if (RAW_DATA_SCHAR_ELT (inside_init, i) < 0)
   10190           10 :             warning_at (init_loc, OPT_Wconversion,
   10191              :                         "conversion from %qT to %qT changes value from "
   10192              :                         "%qd to %qd",
   10193              :                         integer_type_node, type,
   10194           10 :                         RAW_DATA_UCHAR_ELT (inside_init, i),
   10195           10 :                         RAW_DATA_SCHAR_ELT (inside_init, i));
   10196     13128161 :       return inside_init;
   10197              :     }
   10198              : 
   10199              :   /* Handle scalar types, including conversions.  */
   10200              : 
   10201      3132920 :   if (code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE
   10202       129530 :       || code == POINTER_TYPE || code == ENUMERAL_TYPE || code == BOOLEAN_TYPE
   10203        11796 :       || code == COMPLEX_TYPE || code == VECTOR_TYPE || code == NULLPTR_TYPE
   10204         9733 :       || code == BITINT_TYPE)
   10205              :     {
   10206      3132432 :       tree unconverted_init = inside_init;
   10207      3132432 :       if (TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE
   10208      3132432 :           && (TREE_CODE (init) == STRING_CST
   10209            2 :               || TREE_CODE (init) == COMPOUND_LITERAL_EXPR))
   10210         7319 :         inside_init = init = array_to_pointer_conversion (init_loc, init);
   10211      3132432 :       if (semantic_type)
   10212          436 :         inside_init = build1 (EXCESS_PRECISION_EXPR, semantic_type,
   10213              :                               inside_init);
   10214      3132432 :       inside_init
   10215      5683946 :         = convert_for_assignment (init_loc, UNKNOWN_LOCATION, type,
   10216              :                                   inside_init, origtype,
   10217              :                                   require_constant ? ic_init_const : ic_init,
   10218              :                                   null_pointer_constant, NULL_TREE, NULL_TREE,
   10219              :                                   0);
   10220              : 
   10221              :       /* Check to see if we have already given an error message.  */
   10222      3132432 :       if (inside_init == error_mark_node)
   10223              :         ;
   10224      3131972 :       else if (require_constant && !TREE_CONSTANT (inside_init))
   10225              :         {
   10226           36 :           error_init (init_loc, "initializer element is not constant");
   10227           36 :           inside_init = error_mark_node;
   10228              :         }
   10229      3131936 :       else if (require_constant
   10230      3712426 :                && !initializer_constant_valid_p (inside_init,
   10231       580490 :                                                  TREE_TYPE (inside_init)))
   10232              :         {
   10233           10 :           error_init (init_loc, "initializer element is not computable at "
   10234              :                       "load time");
   10235           10 :           inside_init = error_mark_node;
   10236              :         }
   10237      3131926 :       else if (require_constant && !maybe_const)
   10238            5 :         pedwarn_init (init_loc, OPT_Wpedantic,
   10239              :                       "initializer element is not a constant expression");
   10240      3131921 :       else if (require_constexpr)
   10241          332 :         check_constexpr_init (init_loc, type, unconverted_init,
   10242              :                               int_const_expr, arith_const_expr);
   10243              : 
   10244      3132432 :       return inside_init;
   10245              :     }
   10246              : 
   10247              :   /* Come here only for records and arrays.  */
   10248              : 
   10249          488 :   if (COMPLETE_TYPE_P (type) && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
   10250              :     {
   10251            0 :       error_init (init_loc,
   10252              :                   "variable-sized object may not be initialized except "
   10253              :                   "with an empty initializer");
   10254            0 :       return error_mark_node;
   10255              :     }
   10256              : 
   10257          488 :   error_init (init_loc, "invalid initializer");
   10258          488 :   return error_mark_node;
   10259              : }
   10260              : 
   10261              : /* Handle initializers that use braces.  */
   10262              : 
   10263              : /* Type of object we are accumulating a constructor for.
   10264              :    This type is always a RECORD_TYPE, UNION_TYPE or ARRAY_TYPE.  */
   10265              : static tree constructor_type;
   10266              : 
   10267              : /* For a RECORD_TYPE or UNION_TYPE, this is the chain of fields
   10268              :    left to fill.  */
   10269              : static tree constructor_fields;
   10270              : 
   10271              : /* For an ARRAY_TYPE, this is the specified index
   10272              :    at which to store the next element we get.  */
   10273              : static tree constructor_index;
   10274              : 
   10275              : /* For an ARRAY_TYPE, this is the maximum index.  */
   10276              : static tree constructor_max_index;
   10277              : 
   10278              : /* For a RECORD_TYPE, this is the first field not yet written out.  */
   10279              : static tree constructor_unfilled_fields;
   10280              : 
   10281              : /* For an ARRAY_TYPE, this is the index of the first element
   10282              :    not yet written out.  */
   10283              : static tree constructor_unfilled_index;
   10284              : 
   10285              : /* In a RECORD_TYPE, the byte index of the next consecutive field.
   10286              :    This is so we can generate gaps between fields, when appropriate.  */
   10287              : static tree constructor_bit_index;
   10288              : 
   10289              : /* If we are saving up the elements rather than allocating them,
   10290              :    this is the list of elements so far (in reverse order,
   10291              :    most recent first).  */
   10292              : static vec<constructor_elt, va_gc> *constructor_elements;
   10293              : 
   10294              : /* 1 if constructor should be incrementally stored into a constructor chain,
   10295              :    0 if all the elements should be kept in AVL tree.  */
   10296              : static int constructor_incremental;
   10297              : 
   10298              : /* 1 if so far this constructor's elements are all compile-time constants.  */
   10299              : static int constructor_constant;
   10300              : 
   10301              : /* 1 if so far this constructor's elements are all valid address constants.  */
   10302              : static int constructor_simple;
   10303              : 
   10304              : /* 1 if this constructor has an element that cannot be part of a
   10305              :    constant expression.  */
   10306              : static int constructor_nonconst;
   10307              : 
   10308              : /* 1 if this constructor is erroneous so far.  */
   10309              : static int constructor_erroneous;
   10310              : 
   10311              : /* 1 if this constructor is the universal zero initializer { 0 }.  */
   10312              : static int constructor_zeroinit;
   10313              : 
   10314              : /* 1 if this constructor should have padding bits zeroed (C23 {}.  */
   10315              : static bool constructor_zero_padding_bits;
   10316              : 
   10317              : /* 1 if this constructor is a braced scalar initializer (further nested levels
   10318              :    of braces are an error).  */
   10319              : static bool constructor_braced_scalar;
   10320              : 
   10321              : /* Structure for managing pending initializer elements, organized as an
   10322              :    AVL tree.  */
   10323              : 
   10324              : struct init_node
   10325              : {
   10326              :   struct init_node *left, *right;
   10327              :   struct init_node *parent;
   10328              :   int balance;
   10329              :   tree purpose;
   10330              :   tree value;
   10331              :   tree origtype;
   10332              : };
   10333              : 
   10334              : /* Tree of pending elements at this constructor level.
   10335              :    These are elements encountered out of order
   10336              :    which belong at places we haven't reached yet in actually
   10337              :    writing the output.
   10338              :    Will never hold tree nodes across GC runs.  */
   10339              : static struct init_node *constructor_pending_elts;
   10340              : 
   10341              : /* The SPELLING_DEPTH of this constructor.  */
   10342              : static int constructor_depth;
   10343              : 
   10344              : /* DECL node for which an initializer is being read.
   10345              :    0 means we are reading a constructor expression
   10346              :    such as (struct foo) {...}.  */
   10347              : static tree constructor_decl;
   10348              : 
   10349              : /* Nonzero if there were any member designators in this initializer.  */
   10350              : static int constructor_designated;
   10351              : 
   10352              : /* Nesting depth of designator list.  */
   10353              : static int designator_depth;
   10354              : 
   10355              : /* Nonzero if there were diagnosed errors in this designator list.  */
   10356              : static int designator_erroneous;
   10357              : 
   10358              : 
   10359              : /* This stack has a level for each implicit or explicit level of
   10360              :    structuring in the initializer, including the outermost one.  It
   10361              :    saves the values of most of the variables above.  */
   10362              : 
   10363              : struct constructor_range_stack;
   10364              : 
   10365              : struct constructor_stack
   10366              : {
   10367              :   struct constructor_stack *next;
   10368              :   tree type;
   10369              :   tree fields;
   10370              :   tree index;
   10371              :   tree max_index;
   10372              :   tree unfilled_index;
   10373              :   tree unfilled_fields;
   10374              :   tree bit_index;
   10375              :   vec<constructor_elt, va_gc> *elements;
   10376              :   struct init_node *pending_elts;
   10377              :   int offset;
   10378              :   int depth;
   10379              :   /* If value nonzero, this value should replace the entire
   10380              :      constructor at this level.  */
   10381              :   struct c_expr replacement_value;
   10382              :   struct constructor_range_stack *range_stack;
   10383              :   char constant;
   10384              :   char simple;
   10385              :   char nonconst;
   10386              :   char implicit;
   10387              :   char erroneous;
   10388              :   char outer;
   10389              :   char incremental;
   10390              :   char designated;
   10391              :   bool zero_padding_bits;
   10392              :   bool braced_scalar;
   10393              :   int designator_depth;
   10394              : };
   10395              : 
   10396              : static struct constructor_stack *constructor_stack;
   10397              : 
   10398              : /* This stack represents designators from some range designator up to
   10399              :    the last designator in the list.  */
   10400              : 
   10401              : struct constructor_range_stack
   10402              : {
   10403              :   struct constructor_range_stack *next, *prev;
   10404              :   struct constructor_stack *stack;
   10405              :   tree range_start;
   10406              :   tree index;
   10407              :   tree range_end;
   10408              :   tree fields;
   10409              : };
   10410              : 
   10411              : static struct constructor_range_stack *constructor_range_stack;
   10412              : 
   10413              : /* This stack records separate initializers that are nested.
   10414              :    Nested initializers can't happen in ANSI C, but GNU C allows them
   10415              :    in cases like { ... (struct foo) { ... } ... }.  */
   10416              : 
   10417              : struct initializer_stack
   10418              : {
   10419              :   struct initializer_stack *next;
   10420              :   tree decl;
   10421              :   struct constructor_stack *constructor_stack;
   10422              :   struct constructor_range_stack *constructor_range_stack;
   10423              :   vec<constructor_elt, va_gc> *elements;
   10424              :   struct spelling *spelling;
   10425              :   struct spelling *spelling_base;
   10426              :   int spelling_size;
   10427              :   char require_constant_value;
   10428              :   char require_constant_elements;
   10429              :   char require_constexpr_value;
   10430              :   char designated;
   10431              :   rich_location *missing_brace_richloc;
   10432              : };
   10433              : 
   10434              : static struct initializer_stack *initializer_stack;
   10435              : 
   10436              : /* Prepare to parse and output the initializer for variable DECL.  */
   10437              : 
   10438              : void
   10439      7273119 : start_init (tree decl, tree asmspec_tree ATTRIBUTE_UNUSED,
   10440              :             bool init_require_constant, bool init_require_constexpr,
   10441              :             rich_location *richloc)
   10442              : {
   10443      7273119 :   const char *locus;
   10444      7273119 :   struct initializer_stack *p = XNEW (struct initializer_stack);
   10445              : 
   10446      7273119 :   p->decl = constructor_decl;
   10447      7273119 :   p->require_constant_value = require_constant_value;
   10448      7273119 :   p->require_constant_elements = require_constant_elements;
   10449      7273119 :   p->require_constexpr_value = require_constexpr_value;
   10450      7273119 :   p->constructor_stack = constructor_stack;
   10451      7273119 :   p->constructor_range_stack = constructor_range_stack;
   10452      7273119 :   p->elements = constructor_elements;
   10453      7273119 :   p->spelling = spelling;
   10454      7273119 :   p->spelling_base = spelling_base;
   10455      7273119 :   p->spelling_size = spelling_size;
   10456      7273119 :   p->next = initializer_stack;
   10457      7273119 :   p->missing_brace_richloc = richloc;
   10458      7273119 :   p->designated = constructor_designated;
   10459      7273119 :   initializer_stack = p;
   10460              : 
   10461      7273119 :   constructor_decl = decl;
   10462      7273119 :   constructor_designated = 0;
   10463              : 
   10464      7273119 :   require_constant_value = init_require_constant;
   10465      7273119 :   require_constexpr_value = init_require_constexpr;
   10466      7273119 :   if (decl != NULL_TREE && decl != error_mark_node)
   10467              :     {
   10468      6351405 :       require_constant_elements
   10469      6173390 :         = ((init_require_constant || (pedantic && !flag_isoc99))
   10470              :            /* For a scalar, you can always use any value to initialize,
   10471              :               even within braces.  */
   10472      6363366 :            && AGGREGATE_TYPE_P (TREE_TYPE (decl)));
   10473      6351405 :       locus = identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl)));
   10474              :     }
   10475              :   else
   10476              :     {
   10477       921714 :       require_constant_elements = false;
   10478       921714 :       locus = _("(anonymous)");
   10479              :     }
   10480              : 
   10481      7273119 :   constructor_stack = 0;
   10482      7273119 :   constructor_range_stack = 0;
   10483              : 
   10484      7273119 :   found_missing_braces = 0;
   10485              : 
   10486      7273119 :   spelling_base = 0;
   10487      7273119 :   spelling_size = 0;
   10488      7273119 :   RESTORE_SPELLING_DEPTH (0);
   10489              : 
   10490      7273119 :   if (locus)
   10491      7273119 :     push_string (locus);
   10492      7273119 : }
   10493              : 
   10494              : void
   10495      7273117 : finish_init (void)
   10496              : {
   10497      7273117 :   struct initializer_stack *p = initializer_stack;
   10498              : 
   10499              :   /* Free the whole constructor stack of this initializer.  */
   10500      7273117 :   while (constructor_stack)
   10501              :     {
   10502            0 :       struct constructor_stack *q = constructor_stack;
   10503            0 :       constructor_stack = q->next;
   10504            0 :       XDELETE (q);
   10505              :     }
   10506              : 
   10507      7273117 :   gcc_assert (!constructor_range_stack);
   10508              : 
   10509              :   /* Pop back to the data of the outer initializer (if any).  */
   10510      7273117 :   XDELETE (spelling_base);
   10511              : 
   10512      7273117 :   constructor_decl = p->decl;
   10513      7273117 :   require_constant_value = p->require_constant_value;
   10514      7273117 :   require_constant_elements = p->require_constant_elements;
   10515      7273117 :   require_constexpr_value = p->require_constexpr_value;
   10516      7273117 :   constructor_stack = p->constructor_stack;
   10517      7273117 :   constructor_designated = p->designated;
   10518      7273117 :   constructor_range_stack = p->constructor_range_stack;
   10519      7273117 :   constructor_elements = p->elements;
   10520      7273117 :   spelling = p->spelling;
   10521      7273117 :   spelling_base = p->spelling_base;
   10522      7273117 :   spelling_size = p->spelling_size;
   10523      7273117 :   initializer_stack = p->next;
   10524      7273117 :   XDELETE (p);
   10525      7273117 : }
   10526              : 
   10527              : /* Call here when we see the initializer is surrounded by braces.
   10528              :    This is instead of a call to push_init_level;
   10529              :    it is matched by a call to pop_init_level.
   10530              : 
   10531              :    TYPE is the type to initialize, for a constructor expression.
   10532              :    For an initializer for a decl, TYPE is zero.  */
   10533              : 
   10534              : void
   10535      1026341 : really_start_incremental_init (tree type)
   10536              : {
   10537      1026341 :   struct constructor_stack *p = XNEW (struct constructor_stack);
   10538              : 
   10539      1026341 :   if (type == NULL_TREE)
   10540       106593 :     type = TREE_TYPE (constructor_decl);
   10541              : 
   10542      1026341 :   if (VECTOR_TYPE_P (type)
   10543      1026341 :       && TYPE_VECTOR_OPAQUE (type))
   10544            0 :     error ("opaque vector types cannot be initialized");
   10545              : 
   10546      1026341 :   p->type = constructor_type;
   10547      1026341 :   p->fields = constructor_fields;
   10548      1026341 :   p->index = constructor_index;
   10549      1026341 :   p->max_index = constructor_max_index;
   10550      1026341 :   p->unfilled_index = constructor_unfilled_index;
   10551      1026341 :   p->unfilled_fields = constructor_unfilled_fields;
   10552      1026341 :   p->bit_index = constructor_bit_index;
   10553      1026341 :   p->elements = constructor_elements;
   10554      1026341 :   p->constant = constructor_constant;
   10555      1026341 :   p->simple = constructor_simple;
   10556      1026341 :   p->nonconst = constructor_nonconst;
   10557      1026341 :   p->erroneous = constructor_erroneous;
   10558      1026341 :   p->pending_elts = constructor_pending_elts;
   10559      1026341 :   p->depth = constructor_depth;
   10560      1026341 :   p->replacement_value.value = 0;
   10561      1026341 :   p->replacement_value.original_code = ERROR_MARK;
   10562      1026341 :   p->replacement_value.original_type = NULL;
   10563      1026341 :   p->implicit = 0;
   10564      1026341 :   p->range_stack = 0;
   10565      1026341 :   p->outer = 0;
   10566      1026341 :   p->incremental = constructor_incremental;
   10567      1026341 :   p->designated = constructor_designated;
   10568      1026341 :   p->zero_padding_bits = constructor_zero_padding_bits;
   10569      1026341 :   p->braced_scalar = constructor_braced_scalar;
   10570      1026341 :   p->designator_depth = designator_depth;
   10571      1026341 :   p->next = 0;
   10572      1026341 :   constructor_stack = p;
   10573              : 
   10574      1026341 :   constructor_constant = 1;
   10575      1026341 :   constructor_simple = 1;
   10576      1026341 :   constructor_nonconst = 0;
   10577      1026341 :   constructor_depth = SPELLING_DEPTH ();
   10578      1026341 :   constructor_elements = NULL;
   10579      1026341 :   constructor_pending_elts = 0;
   10580      1026341 :   constructor_type = type;
   10581      1026341 :   constructor_incremental = 1;
   10582      1026341 :   constructor_designated = 0;
   10583      1026341 :   constructor_zero_padding_bits = false;
   10584      1026341 :   constructor_zeroinit = 1;
   10585      1026341 :   constructor_braced_scalar = false;
   10586      1026341 :   designator_depth = 0;
   10587      1026341 :   designator_erroneous = 0;
   10588              : 
   10589      1026341 :   if (RECORD_OR_UNION_TYPE_P (constructor_type))
   10590              :     {
   10591        82155 :       constructor_fields = TYPE_FIELDS (constructor_type);
   10592              :       /* Skip any nameless bit fields at the beginning.  */
   10593        82155 :       while (constructor_fields != NULL_TREE
   10594        82183 :              && DECL_UNNAMED_BIT_FIELD (constructor_fields))
   10595           28 :         constructor_fields = DECL_CHAIN (constructor_fields);
   10596              : 
   10597        82155 :       constructor_unfilled_fields = constructor_fields;
   10598        82155 :       constructor_bit_index = bitsize_zero_node;
   10599              :     }
   10600       944186 :   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   10601              :     {
   10602        18281 :       if (TYPE_DOMAIN (constructor_type))
   10603              :         {
   10604         9783 :           constructor_max_index
   10605         9783 :             = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
   10606              : 
   10607              :           /* Detect non-empty initializations of zero-length arrays.  */
   10608         9783 :           if (constructor_max_index == NULL_TREE
   10609         9783 :               && TYPE_SIZE (constructor_type))
   10610          207 :             constructor_max_index = integer_minus_one_node;
   10611              : 
   10612              :           /* constructor_max_index needs to be an INTEGER_CST.  Attempts
   10613              :              to initialize VLAs with a nonempty initializer will cause a
   10614              :              proper error; avoid tree checking errors as well by setting a
   10615              :              safe value.  */
   10616         9783 :           if (constructor_max_index
   10617         9783 :               && TREE_CODE (constructor_max_index) != INTEGER_CST)
   10618           73 :             constructor_max_index = integer_minus_one_node;
   10619              : 
   10620         9783 :           constructor_index
   10621         9783 :             = convert (bitsizetype,
   10622         9783 :                        TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
   10623              :         }
   10624              :       else
   10625              :         {
   10626         8498 :           constructor_index = bitsize_zero_node;
   10627         8498 :           constructor_max_index = NULL_TREE;
   10628              :         }
   10629              : 
   10630        18281 :       constructor_unfilled_index = constructor_index;
   10631              :     }
   10632       925905 :   else if (gnu_vector_type_p (constructor_type))
   10633              :     {
   10634              :       /* Vectors are like simple fixed-size arrays.  */
   10635      1850698 :       constructor_max_index =
   10636       925349 :         bitsize_int (TYPE_VECTOR_SUBPARTS (constructor_type) - 1);
   10637       925349 :       constructor_index = bitsize_zero_node;
   10638       925349 :       constructor_unfilled_index = constructor_index;
   10639              :     }
   10640              :   else
   10641              :     {
   10642              :       /* Handle the case of int x = {5}; */
   10643          556 :       constructor_fields = constructor_type;
   10644          556 :       constructor_unfilled_fields = constructor_type;
   10645          556 :       constructor_braced_scalar = true;
   10646              :     }
   10647      1026341 : }
   10648              : 
   10649              : extern location_t last_init_list_comma;
   10650              : 
   10651              : /* Called when we see an open brace for a nested initializer.  Finish
   10652              :    off any pending levels with implicit braces.  */
   10653              : void
   10654       342412 : finish_implicit_inits (location_t loc, struct obstack *braced_init_obstack)
   10655              : {
   10656       342414 :   while (constructor_stack->implicit)
   10657              :     {
   10658         1154 :       if (RECORD_OR_UNION_TYPE_P (constructor_type)
   10659          208 :           && constructor_fields == NULL_TREE)
   10660            0 :         process_init_element (input_location,
   10661              :                               pop_init_level (loc, 1, braced_init_obstack,
   10662              :                                               last_init_list_comma),
   10663              :                               true, braced_init_obstack);
   10664         1154 :       else if (TREE_CODE (constructor_type) == ARRAY_TYPE
   10665          946 :                && constructor_max_index
   10666         2100 :                && tree_int_cst_lt (constructor_max_index,
   10667              :                                    constructor_index))
   10668            2 :         process_init_element (input_location,
   10669              :                               pop_init_level (loc, 1, braced_init_obstack,
   10670              :                                               last_init_list_comma),
   10671              :                               true, braced_init_obstack);
   10672              :       else
   10673              :         break;
   10674              :     }
   10675       342412 : }
   10676              : 
   10677              : /* Push down into a subobject, for initialization.
   10678              :    If this is for an explicit set of braces, IMPLICIT is 0.
   10679              :    If it is because the next element belongs at a lower level,
   10680              :    IMPLICIT is 1 (or 2 if the push is because of designator list).  */
   10681              : 
   10682              : void
   10683      1045092 : push_init_level (location_t loc, int implicit,
   10684              :                  struct obstack *braced_init_obstack)
   10685              : {
   10686      1045092 :   struct constructor_stack *p;
   10687      1045092 :   tree value = NULL_TREE;
   10688              : 
   10689              :   /* Unless this is an explicit brace, we need to preserve previous
   10690              :      content if any.  */
   10691      1045092 :   if (implicit)
   10692              :     {
   10693       705323 :       if (RECORD_OR_UNION_TYPE_P (constructor_type) && constructor_fields)
   10694         1819 :         value = find_init_member (constructor_fields, braced_init_obstack);
   10695       703504 :       else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   10696       703504 :         value = find_init_member (constructor_index, braced_init_obstack);
   10697              :     }
   10698              : 
   10699      1045092 :   p = XNEW (struct constructor_stack);
   10700      1045092 :   p->type = constructor_type;
   10701      1045092 :   p->fields = constructor_fields;
   10702      1045092 :   p->index = constructor_index;
   10703      1045092 :   p->max_index = constructor_max_index;
   10704      1045092 :   p->unfilled_index = constructor_unfilled_index;
   10705      1045092 :   p->unfilled_fields = constructor_unfilled_fields;
   10706      1045092 :   p->bit_index = constructor_bit_index;
   10707      1045092 :   p->elements = constructor_elements;
   10708      1045092 :   p->constant = constructor_constant;
   10709      1045092 :   p->simple = constructor_simple;
   10710      1045092 :   p->nonconst = constructor_nonconst;
   10711      1045092 :   p->erroneous = constructor_erroneous;
   10712      1045092 :   p->pending_elts = constructor_pending_elts;
   10713      1045092 :   p->depth = constructor_depth;
   10714      1045092 :   p->replacement_value.value = NULL_TREE;
   10715      1045092 :   p->replacement_value.original_code = ERROR_MARK;
   10716      1045092 :   p->replacement_value.original_type = NULL;
   10717      1045092 :   p->implicit = implicit;
   10718      1045092 :   p->outer = 0;
   10719      1045092 :   p->incremental = constructor_incremental;
   10720      1045092 :   p->designated = constructor_designated;
   10721      1045092 :   p->zero_padding_bits = constructor_zero_padding_bits;
   10722      1045092 :   p->braced_scalar = constructor_braced_scalar;
   10723      1045092 :   p->designator_depth = designator_depth;
   10724      1045092 :   p->next = constructor_stack;
   10725      1045092 :   p->range_stack = 0;
   10726      1045092 :   constructor_stack = p;
   10727              : 
   10728      1045092 :   constructor_constant = 1;
   10729      1045092 :   constructor_simple = 1;
   10730      1045092 :   constructor_nonconst = 0;
   10731      1045092 :   constructor_depth = SPELLING_DEPTH ();
   10732      1045092 :   constructor_elements = NULL;
   10733      1045092 :   constructor_incremental = 1;
   10734              :   /* If the upper initializer is designated, then mark this as
   10735              :      designated too to prevent bogus warnings.  */
   10736      1045092 :   constructor_designated = p->designated;
   10737              :   /* If the upper initializer has padding bits zeroed, that includes
   10738              :      all nested initializers as well.  */
   10739      1045092 :   constructor_zero_padding_bits = p->zero_padding_bits;
   10740      1045092 :   constructor_braced_scalar = false;
   10741      1045092 :   constructor_pending_elts = 0;
   10742      1045092 :   if (!implicit)
   10743              :     {
   10744       339769 :       p->range_stack = constructor_range_stack;
   10745       339769 :       constructor_range_stack = 0;
   10746       339769 :       designator_depth = 0;
   10747       339769 :       designator_erroneous = 0;
   10748              :     }
   10749              : 
   10750              :   /* Don't die if an entire brace-pair level is superfluous
   10751              :      in the containing level.  */
   10752      1045092 :   if (constructor_type == NULL_TREE)
   10753              :     ;
   10754      1045092 :   else if (RECORD_OR_UNION_TYPE_P (constructor_type))
   10755              :     {
   10756              :       /* Don't die if there are extra init elts at the end.  */
   10757       160057 :       if (constructor_fields == NULL_TREE)
   10758           51 :         constructor_type = NULL_TREE;
   10759              :       else
   10760              :         {
   10761       160006 :           constructor_type = TREE_TYPE (constructor_fields);
   10762       160006 :           push_member_name (constructor_fields);
   10763       160006 :           constructor_depth++;
   10764              :         }
   10765              :     }
   10766       885035 :   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   10767              :     {
   10768       884984 :       constructor_type = TREE_TYPE (constructor_type);
   10769       884984 :       push_array_bounds (tree_to_uhwi (constructor_index));
   10770       884984 :       constructor_depth++;
   10771              :     }
   10772              : 
   10773      1045092 :   if (constructor_type == NULL_TREE)
   10774              :     {
   10775           51 :       error_init (loc, "extra brace group at end of initializer");
   10776           51 :       constructor_fields = NULL_TREE;
   10777           51 :       constructor_unfilled_fields = NULL_TREE;
   10778           51 :       return;
   10779              :     }
   10780              : 
   10781      1045041 :   if (value && TREE_CODE (value) == CONSTRUCTOR)
   10782              :     {
   10783         1686 :       constructor_constant = TREE_CONSTANT (value);
   10784         1686 :       constructor_simple = TREE_STATIC (value);
   10785         1686 :       constructor_nonconst = CONSTRUCTOR_NON_CONST (value);
   10786         1686 :       constructor_elements = CONSTRUCTOR_ELTS (value);
   10787         1686 :       constructor_zero_padding_bits |= CONSTRUCTOR_ZERO_PADDING_BITS (value);
   10788         1686 :       if (!vec_safe_is_empty (constructor_elements)
   10789         1462 :           && (TREE_CODE (constructor_type) == RECORD_TYPE
   10790         1462 :               || TREE_CODE (constructor_type) == ARRAY_TYPE))
   10791         1416 :         set_nonincremental_init (braced_init_obstack);
   10792              :     }
   10793              : 
   10794      1045041 :   if (implicit == 1)
   10795              :     {
   10796       702680 :       found_missing_braces = 1;
   10797       702680 :       if (initializer_stack->missing_brace_richloc)
   10798       702680 :         initializer_stack->missing_brace_richloc->add_fixit_insert_before
   10799       702680 :           (loc, "{");
   10800              :     }
   10801              : 
   10802      1045041 :   if (RECORD_OR_UNION_TYPE_P (constructor_type))
   10803              :     {
   10804       880833 :       constructor_fields = TYPE_FIELDS (constructor_type);
   10805              :       /* Skip any nameless bit fields at the beginning.  */
   10806       880833 :       while (constructor_fields != NULL_TREE
   10807       880897 :              && DECL_UNNAMED_BIT_FIELD (constructor_fields))
   10808           64 :         constructor_fields = DECL_CHAIN (constructor_fields);
   10809              : 
   10810       880833 :       constructor_unfilled_fields = constructor_fields;
   10811       880833 :       constructor_bit_index = bitsize_zero_node;
   10812              :     }
   10813       164208 :   else if (gnu_vector_type_p (constructor_type))
   10814              :     {
   10815              :       /* Vectors are like simple fixed-size arrays.  */
   10816         9602 :       constructor_max_index =
   10817         4801 :         bitsize_int (TYPE_VECTOR_SUBPARTS (constructor_type) - 1);
   10818         4801 :       constructor_index = bitsize_int (0);
   10819         4801 :       constructor_unfilled_index = constructor_index;
   10820              :     }
   10821       159407 :   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   10822              :     {
   10823       159327 :       if (TYPE_DOMAIN (constructor_type))
   10824              :         {
   10825       159327 :           constructor_max_index
   10826       159327 :             = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
   10827              : 
   10828              :           /* Detect non-empty initializations of zero-length arrays.  */
   10829       159327 :           if (constructor_max_index == NULL_TREE
   10830       159327 :               && TYPE_SIZE (constructor_type))
   10831          135 :             constructor_max_index = integer_minus_one_node;
   10832              : 
   10833              :           /* constructor_max_index needs to be an INTEGER_CST.  Attempts
   10834              :              to initialize VLAs will cause a proper error; avoid tree
   10835              :              checking errors as well by setting a safe value.  */
   10836       159327 :           if (constructor_max_index
   10837       159057 :               && TREE_CODE (constructor_max_index) != INTEGER_CST)
   10838            2 :             constructor_max_index = integer_minus_one_node;
   10839              : 
   10840       159327 :           constructor_index
   10841       159327 :             = convert (bitsizetype,
   10842       159327 :                        TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
   10843              :         }
   10844              :       else
   10845            0 :         constructor_index = bitsize_zero_node;
   10846              : 
   10847       159327 :       constructor_unfilled_index = constructor_index;
   10848       159327 :       if (value && TREE_CODE (value) == STRING_CST)
   10849              :         {
   10850              :           /* We need to split the char/wchar array into individual
   10851              :              characters, so that we don't have to special case it
   10852              :              everywhere.  */
   10853            7 :           set_nonincremental_init_from_string (value, braced_init_obstack);
   10854              :         }
   10855              :     }
   10856              :   else
   10857              :     {
   10858           80 :       if (constructor_type != error_mark_node)
   10859              :         {
   10860           51 :           if (p->braced_scalar)
   10861           22 :             permerror_init (input_location, 0,
   10862              :                             "braces around scalar initializer");
   10863              :           else
   10864           29 :             warning_init (input_location, 0,
   10865              :                           "braces around scalar initializer");
   10866           51 :           constructor_braced_scalar = true;
   10867              :         }
   10868           80 :       constructor_fields = constructor_type;
   10869           80 :       constructor_unfilled_fields = constructor_type;
   10870              :     }
   10871              : }
   10872              : 
   10873              : /* At the end of an implicit or explicit brace level,
   10874              :    finish up that level of constructor.  If a single expression
   10875              :    with redundant braces initialized that level, return the
   10876              :    c_expr structure for that expression.  Otherwise, the original_code
   10877              :    element is set to ERROR_MARK.
   10878              :    If we were outputting the elements as they are read, return 0 as the value
   10879              :    from inner levels (process_init_element ignores that),
   10880              :    but return error_mark_node as the value from the outermost level
   10881              :    (that's what we want to put in DECL_INITIAL).
   10882              :    Otherwise, return a CONSTRUCTOR expression as the value.  */
   10883              : 
   10884              : struct c_expr
   10885      2071433 : pop_init_level (location_t loc, int implicit,
   10886              :                 struct obstack *braced_init_obstack,
   10887              :                 location_t insert_before)
   10888              : {
   10889      2071433 :   struct constructor_stack *p;
   10890      2071433 :   struct c_expr ret;
   10891      2071433 :   ret.value = NULL_TREE;
   10892      2071433 :   ret.original_code = ERROR_MARK;
   10893      2071433 :   ret.original_type = NULL;
   10894      2071433 :   ret.m_decimal = 0;
   10895              : 
   10896      2071433 :   if (implicit == 0)
   10897              :     {
   10898              :       /* When we come to an explicit close brace,
   10899              :          pop any inner levels that didn't have explicit braces.  */
   10900      1367452 :       while (constructor_stack->implicit)
   10901         1342 :         process_init_element (input_location,
   10902              :                               pop_init_level (loc, 1, braced_init_obstack,
   10903              :                                               insert_before),
   10904              :                               true, braced_init_obstack);
   10905      1366110 :       gcc_assert (!constructor_range_stack);
   10906              :     }
   10907              :   else
   10908       705323 :     if (initializer_stack->missing_brace_richloc)
   10909       705323 :       initializer_stack->missing_brace_richloc->add_fixit_insert_before
   10910       705323 :         (insert_before, "}");
   10911              : 
   10912              :   /* Now output all pending elements.  */
   10913      2071433 :   constructor_incremental = 1;
   10914      2071433 :   output_pending_init_elements (1, braced_init_obstack);
   10915              : 
   10916      2071433 :   p = constructor_stack;
   10917              : 
   10918              :   /* Error for initializing a flexible array member, or a zero-length
   10919              :      array member in an inappropriate context.  */
   10920      2071382 :   if (constructor_type && constructor_fields
   10921       161021 :       && TREE_CODE (constructor_type) == ARRAY_TYPE
   10922       153373 :       && TYPE_DOMAIN (constructor_type)
   10923      2224798 :       && !TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type)))
   10924              :     {
   10925              :       /* Silently discard empty initializations.  The parser will
   10926              :          already have pedwarned for empty brackets for C17 and earlier.  */
   10927          300 :       if (integer_zerop (constructor_unfilled_index))
   10928           84 :         constructor_type = NULL_TREE;
   10929          300 :       if (constructor_type || flag_isoc23)
   10930              :         {
   10931          296 :           gcc_assert (!constructor_type || !TYPE_SIZE (constructor_type));
   10932              : 
   10933          296 :           if (constructor_depth <= 2)
   10934          249 :             pedwarn_init (loc, OPT_Wpedantic,
   10935              :                           "initialization of a flexible array member");
   10936           47 :           else if (constructor_type)
   10937           33 :             error_init (loc, "initialization of flexible array member "
   10938              :                              "in a nested context");
   10939              :           else
   10940           14 :             pedwarn_init (loc, OPT_Wpedantic,
   10941              :                           "initialization of flexible array member "
   10942              :                           "in a nested context");
   10943              : 
   10944              :           /* We have already issued an error message for the existence
   10945              :              of a flexible array member not at the end of the structure.
   10946              :              Discard the initializer so that we do not die later.  */
   10947          296 :           if (constructor_type
   10948          216 :               && DECL_CHAIN (constructor_fields) != NULL_TREE
   10949          302 :               && (!p->type || TREE_CODE (p->type) != UNION_TYPE))
   10950            0 :             constructor_type = NULL_TREE;
   10951              :         }
   10952              :     }
   10953              : 
   10954      2071433 :   switch (vec_safe_length (constructor_elements))
   10955              :     {
   10956         5323 :     case 0:
   10957              :       /* Initialization with { } counts as zeroinit.  */
   10958         5323 :       constructor_zeroinit = 1;
   10959         5323 :       break;
   10960       916289 :     case 1:
   10961              :       /* This might be zeroinit as well.  */
   10962       916289 :       if (integer_zerop ((*constructor_elements)[0].value))
   10963         2093 :         constructor_zeroinit = 1;
   10964              :       break;
   10965      1149821 :     default:
   10966              :       /* If the constructor has more than one element, it can't be { 0 }.  */
   10967      1149821 :       constructor_zeroinit = 0;
   10968      1149821 :       break;
   10969              :     }
   10970              : 
   10971              :   /* Warn when some structs are initialized with direct aggregation.  */
   10972      2071433 :   if (!implicit && found_missing_braces && warn_missing_braces
   10973           37 :       && !constructor_zeroinit)
   10974              :     {
   10975           18 :       gcc_assert (initializer_stack->missing_brace_richloc);
   10976           18 :       warning_at (initializer_stack->missing_brace_richloc,
   10977           18 :                   OPT_Wmissing_braces,
   10978              :                   "missing braces around initializer");
   10979              :     }
   10980              : 
   10981              :   /* Warn when some struct elements are implicitly initialized to zero.  */
   10982      2071433 :   if (warn_missing_field_initializers
   10983       425471 :       && constructor_type
   10984       425443 :       && TREE_CODE (constructor_type) == RECORD_TYPE
   10985       193403 :       && constructor_unfilled_fields)
   10986              :     {
   10987              :         /* Do not warn for flexible array members or zero-length arrays.  */
   10988           43 :         while (constructor_unfilled_fields
   10989           43 :                && (!DECL_SIZE (constructor_unfilled_fields)
   10990           43 :                    || integer_zerop (DECL_SIZE (constructor_unfilled_fields))))
   10991            0 :           constructor_unfilled_fields = DECL_CHAIN (constructor_unfilled_fields);
   10992              : 
   10993           43 :         if (constructor_unfilled_fields
   10994              :             /* Do not warn if this level of the initializer uses member
   10995              :                designators; it is likely to be deliberate.  */
   10996           43 :             && !constructor_designated
   10997              :             /* Do not warn about initializing with { 0 } or with { }.  */
   10998           24 :             && !constructor_zeroinit)
   10999              :           {
   11000           10 :             if (warning_at (input_location, OPT_Wmissing_field_initializers,
   11001              :                             "missing initializer for field %qD of %qT",
   11002              :                             constructor_unfilled_fields,
   11003              :                             constructor_type))
   11004           10 :               inform (DECL_SOURCE_LOCATION (constructor_unfilled_fields),
   11005              :                       "%qD declared here", constructor_unfilled_fields);
   11006              :           }
   11007              :     }
   11008              : 
   11009              :   /* Pad out the end of the structure.  */
   11010      2071433 :   if (p->replacement_value.value)
   11011              :     /* If this closes a superfluous brace pair,
   11012              :        just pass out the element between them.  */
   11013          138 :     ret = p->replacement_value;
   11014      2071295 :   else if (constructor_type == NULL_TREE)
   11015              :     ;
   11016      2071168 :   else if (!RECORD_OR_UNION_TYPE_P (constructor_type)
   11017      2071168 :            && TREE_CODE (constructor_type) != ARRAY_TYPE
   11018      2071168 :            && !gnu_vector_type_p (constructor_type))
   11019              :     {
   11020              :       /* A nonincremental scalar initializer--just return
   11021              :          the element, after verifying there is just one.
   11022              :          Empty scalar initializers are supported in C23.  */
   11023          636 :       if (vec_safe_is_empty (constructor_elements))
   11024              :         {
   11025          201 :           if (constructor_erroneous || constructor_type == error_mark_node)
   11026           85 :             ret.value = error_mark_node;
   11027          116 :           else if (TREE_CODE (constructor_type) == FUNCTION_TYPE)
   11028              :             {
   11029            2 :               error_init (loc, "invalid initializer");
   11030            2 :               ret.value = error_mark_node;
   11031              :             }
   11032          114 :           else if (TREE_CODE (constructor_type) == POINTER_TYPE)
   11033              :             /* Ensure this is a null pointer constant in the case of a
   11034              :                'constexpr' object initialized with {}.  */
   11035           33 :             ret.value = build_zero_cst (ptr_type_node);
   11036              :           else
   11037           81 :             ret.value = build_zero_cst (constructor_type);
   11038              :         }
   11039          435 :       else if (vec_safe_length (constructor_elements) != 1)
   11040              :         {
   11041            0 :           error_init (loc, "extra elements in scalar initializer");
   11042            0 :           ret.value = (*constructor_elements)[0].value;
   11043              :         }
   11044              :       else
   11045          435 :         ret.value = (*constructor_elements)[0].value;
   11046              :     }
   11047              :   else
   11048              :     {
   11049      2070532 :       if (constructor_erroneous)
   11050          542 :         ret.value = error_mark_node;
   11051              :       else
   11052              :         {
   11053      2069990 :           ret.value = build_constructor (constructor_type,
   11054              :                                          constructor_elements);
   11055      2069990 :           if (constructor_constant)
   11056      1739964 :             TREE_CONSTANT (ret.value) = 1;
   11057      2069990 :           if (constructor_constant && constructor_simple)
   11058      1739925 :             TREE_STATIC (ret.value) = 1;
   11059      2069990 :           if (constructor_nonconst)
   11060          672 :             CONSTRUCTOR_NON_CONST (ret.value) = 1;
   11061      2069990 :           if (constructor_zero_padding_bits)
   11062          687 :             CONSTRUCTOR_ZERO_PADDING_BITS (ret.value) = 1;
   11063              :         }
   11064              :     }
   11065              : 
   11066      2071433 :   if (ret.value && TREE_CODE (ret.value) != CONSTRUCTOR)
   11067              :     {
   11068         1316 :       if (constructor_nonconst)
   11069           15 :         ret.original_code = C_MAYBE_CONST_EXPR;
   11070         1301 :       else if (ret.original_code == C_MAYBE_CONST_EXPR)
   11071            0 :         ret.original_code = ERROR_MARK;
   11072              :     }
   11073              : 
   11074      2071433 :   constructor_type = p->type;
   11075      2071433 :   constructor_fields = p->fields;
   11076      2071433 :   constructor_index = p->index;
   11077      2071433 :   constructor_max_index = p->max_index;
   11078      2071433 :   constructor_unfilled_index = p->unfilled_index;
   11079      2071433 :   constructor_unfilled_fields = p->unfilled_fields;
   11080      2071433 :   constructor_bit_index = p->bit_index;
   11081      2071433 :   constructor_elements = p->elements;
   11082      2071433 :   constructor_constant = p->constant;
   11083      2071433 :   constructor_simple = p->simple;
   11084      2071433 :   constructor_nonconst = p->nonconst;
   11085      2071433 :   constructor_erroneous = p->erroneous;
   11086      2071433 :   constructor_incremental = p->incremental;
   11087      2071433 :   constructor_designated = p->designated;
   11088      2071433 :   constructor_zero_padding_bits = p->zero_padding_bits;
   11089      2071433 :   constructor_braced_scalar = p->braced_scalar;
   11090      2071433 :   designator_depth = p->designator_depth;
   11091      2071433 :   constructor_pending_elts = p->pending_elts;
   11092      2071433 :   constructor_depth = p->depth;
   11093      2071433 :   if (!p->implicit)
   11094      1366110 :     constructor_range_stack = p->range_stack;
   11095      2071433 :   RESTORE_SPELLING_DEPTH (constructor_depth);
   11096              : 
   11097      2071433 :   constructor_stack = p->next;
   11098      2071433 :   XDELETE (p);
   11099              : 
   11100      2071433 :   if (ret.value == NULL_TREE && constructor_stack == 0)
   11101            0 :     ret.value = error_mark_node;
   11102      2071433 :   return ret;
   11103              : }
   11104              : 
   11105              : /* Common handling for both array range and field name designators.
   11106              :    ARRAY argument is nonzero for array ranges.  Returns false for success.  */
   11107              : 
   11108              : static bool
   11109        36945 : set_designator (location_t loc, bool array,
   11110              :                 struct obstack *braced_init_obstack)
   11111              : {
   11112        36945 :   tree subtype;
   11113        36945 :   enum tree_code subcode;
   11114              : 
   11115              :   /* Don't die if an entire brace-pair level is superfluous
   11116              :      in the containing level, or for an erroneous type.  */
   11117        36945 :   if (constructor_type == NULL_TREE || constructor_type == error_mark_node)
   11118              :     return true;
   11119              : 
   11120              :   /* If there were errors in this designator list already, bail out
   11121              :      silently.  */
   11122        36936 :   if (designator_erroneous)
   11123              :     return true;
   11124              : 
   11125              :   /* Likewise for an initializer for a variable-size type.  Those are
   11126              :      diagnosed in the parser, except for empty initializer braces.  */
   11127        36936 :   if (COMPLETE_TYPE_P (constructor_type)
   11128        36936 :       && TREE_CODE (TYPE_SIZE (constructor_type)) != INTEGER_CST)
   11129              :     return true;
   11130              : 
   11131        36926 :   if (!designator_depth)
   11132              :     {
   11133        34607 :       gcc_assert (!constructor_range_stack);
   11134              : 
   11135              :       /* Designator list starts at the level of closest explicit
   11136              :          braces.  */
   11137        36282 :       while (constructor_stack->implicit)
   11138         1675 :         process_init_element (input_location,
   11139              :                               pop_init_level (loc, 1, braced_init_obstack,
   11140              :                                               last_init_list_comma),
   11141              :                               true, braced_init_obstack);
   11142        34607 :       constructor_designated = 1;
   11143        34607 :       return false;
   11144              :     }
   11145              : 
   11146         2319 :   switch (TREE_CODE (constructor_type))
   11147              :     {
   11148         1442 :     case  RECORD_TYPE:
   11149         1442 :     case  UNION_TYPE:
   11150         1442 :       subtype = TREE_TYPE (constructor_fields);
   11151         1442 :       if (subtype != error_mark_node)
   11152         1442 :         subtype = TYPE_MAIN_VARIANT (subtype);
   11153              :       break;
   11154          877 :     case ARRAY_TYPE:
   11155          877 :       subtype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
   11156          877 :       break;
   11157            0 :     default:
   11158            0 :       gcc_unreachable ();
   11159              :     }
   11160              : 
   11161         2319 :   subcode = TREE_CODE (subtype);
   11162         2319 :   if (array && subcode != ARRAY_TYPE)
   11163              :     {
   11164            1 :       error_init (loc, "array index in non-array initializer");
   11165            1 :       return true;
   11166              :     }
   11167         2318 :   else if (!array && subcode != RECORD_TYPE && subcode != UNION_TYPE)
   11168              :     {
   11169            0 :       error_init (loc, "field name not in record or union initializer");
   11170            0 :       return true;
   11171              :     }
   11172              : 
   11173         2318 :   constructor_designated = 1;
   11174         2318 :   finish_implicit_inits (loc, braced_init_obstack);
   11175         2318 :   push_init_level (loc, 2, braced_init_obstack);
   11176         2318 :   return false;
   11177              : }
   11178              : 
   11179              : /* If there are range designators in designator list, push a new designator
   11180              :    to constructor_range_stack.  RANGE_END is end of such stack range or
   11181              :    NULL_TREE if there is no range designator at this level.  */
   11182              : 
   11183              : static void
   11184          390 : push_range_stack (tree range_end, struct obstack * braced_init_obstack)
   11185              : {
   11186          390 :   struct constructor_range_stack *p;
   11187              : 
   11188          780 :   p = (struct constructor_range_stack *)
   11189          390 :     obstack_alloc (braced_init_obstack,
   11190              :                    sizeof (struct constructor_range_stack));
   11191          390 :   p->prev = constructor_range_stack;
   11192          390 :   p->next = 0;
   11193          390 :   p->fields = constructor_fields;
   11194          390 :   p->range_start = constructor_index;
   11195          390 :   p->index = constructor_index;
   11196          390 :   p->stack = constructor_stack;
   11197          390 :   p->range_end = range_end;
   11198          390 :   if (constructor_range_stack)
   11199           19 :     constructor_range_stack->next = p;
   11200          390 :   constructor_range_stack = p;
   11201          390 : }
   11202              : 
   11203              : /* Within an array initializer, specify the next index to be initialized.
   11204              :    FIRST is that index.  If LAST is nonzero, then initialize a range
   11205              :    of indices, running from FIRST through LAST.  */
   11206              : 
   11207              : void
   11208         1931 : set_init_index (location_t loc, tree first, tree last,
   11209              :                 struct obstack *braced_init_obstack)
   11210              : {
   11211         1931 :   if (set_designator (loc, true, braced_init_obstack))
   11212              :     return;
   11213              : 
   11214         1928 :   designator_erroneous = 1;
   11215              : 
   11216         3856 :   if (!INTEGRAL_TYPE_P (TREE_TYPE (first))
   11217         3845 :       || (last && !INTEGRAL_TYPE_P (TREE_TYPE (last))))
   11218              :     {
   11219           12 :       error_init (loc, "array index in initializer not of integer type");
   11220           12 :       return;
   11221              :     }
   11222              : 
   11223         1916 :   if (TREE_CODE (first) != INTEGER_CST)
   11224              :     {
   11225            6 :       first = c_fully_fold (first, false, NULL);
   11226            6 :       if (TREE_CODE (first) == INTEGER_CST)
   11227            5 :         pedwarn_init (loc, OPT_Wpedantic,
   11228              :                       "array index in initializer is not "
   11229              :                       "an integer constant expression");
   11230              :     }
   11231              : 
   11232         1916 :   if (last && TREE_CODE (last) != INTEGER_CST)
   11233              :     {
   11234            2 :       last = c_fully_fold (last, false, NULL);
   11235            2 :       if (TREE_CODE (last) == INTEGER_CST)
   11236            1 :         pedwarn_init (loc, OPT_Wpedantic,
   11237              :                       "array index in initializer is not "
   11238              :                       "an integer constant expression");
   11239              :     }
   11240              : 
   11241         1916 :   if (TREE_CODE (first) != INTEGER_CST)
   11242            1 :     error_init (loc, "nonconstant array index in initializer");
   11243         1915 :   else if (last != NULL_TREE && TREE_CODE (last) != INTEGER_CST)
   11244            1 :     error_init (loc, "nonconstant array index in initializer");
   11245         1914 :   else if (TREE_CODE (constructor_type) != ARRAY_TYPE)
   11246            9 :     error_init (loc, "array index in non-array initializer");
   11247         1905 :   else if (tree_int_cst_sgn (first) == -1)
   11248           15 :     error_init (loc, "array index in initializer exceeds array bounds");
   11249         1890 :   else if (constructor_max_index
   11250         1890 :            && tree_int_cst_lt (constructor_max_index, first))
   11251            7 :     error_init (loc, "array index in initializer exceeds array bounds");
   11252              :   else
   11253              :     {
   11254         1883 :       constant_expression_warning (first);
   11255         1883 :       if (last)
   11256          385 :         constant_expression_warning (last);
   11257         1883 :       constructor_index = convert (bitsizetype, first);
   11258         1883 :       if (tree_int_cst_lt (constructor_index, first))
   11259              :         {
   11260            0 :           constructor_index = copy_node (constructor_index);
   11261            0 :           TREE_OVERFLOW (constructor_index) = 1;
   11262              :         }
   11263              : 
   11264         1883 :       if (last)
   11265              :         {
   11266          385 :           if (tree_int_cst_equal (first, last))
   11267              :             last = NULL_TREE;
   11268          384 :           else if (tree_int_cst_lt (last, first))
   11269              :             {
   11270            2 :               error_init (loc, "empty index range in initializer");
   11271            2 :               last = NULL_TREE;
   11272              :             }
   11273              :           else
   11274              :             {
   11275          382 :               last = convert (bitsizetype, last);
   11276          382 :               if (constructor_max_index != NULL_TREE
   11277          382 :                   && tree_int_cst_lt (constructor_max_index, last))
   11278              :                 {
   11279            3 :                   error_init (loc, "array index range in initializer exceeds "
   11280              :                               "array bounds");
   11281            3 :                   last = NULL_TREE;
   11282              :                 }
   11283              :             }
   11284              :         }
   11285              : 
   11286         1883 :       designator_depth++;
   11287         1883 :       designator_erroneous = 0;
   11288         1883 :       if (constructor_range_stack || last)
   11289          379 :         push_range_stack (last, braced_init_obstack);
   11290              :     }
   11291              : }
   11292              : 
   11293              : /* Within a struct initializer, specify the next field to be initialized.  */
   11294              : 
   11295              : void
   11296        34968 : set_init_label (location_t loc, tree fieldname, location_t fieldname_loc,
   11297              :                 struct obstack *braced_init_obstack)
   11298              : {
   11299        34968 :   tree field;
   11300              : 
   11301        34968 :   if (set_designator (loc, false, braced_init_obstack))
   11302              :     return;
   11303              : 
   11304        34951 :   designator_erroneous = 1;
   11305              : 
   11306        34951 :   if (!RECORD_OR_UNION_TYPE_P (constructor_type))
   11307              :     {
   11308            3 :       error_init (loc, "field name not in record or union initializer");
   11309            3 :       return;
   11310              :     }
   11311              : 
   11312        34948 :   field = lookup_field (constructor_type, fieldname);
   11313              : 
   11314        34948 :   if (field == NULL_TREE)
   11315              :     {
   11316            8 :       tree guessed_id = lookup_field_fuzzy (constructor_type, fieldname);
   11317            8 :       if (guessed_id)
   11318              :         {
   11319            4 :           gcc_rich_location rich_loc (fieldname_loc);
   11320            4 :           rich_loc.add_fixit_misspelled_id (fieldname_loc, guessed_id);
   11321            4 :           error_at (&rich_loc,
   11322              :                     "%qT has no member named %qE; did you mean %qE?",
   11323              :                     constructor_type, fieldname, guessed_id);
   11324            4 :         }
   11325              :       else
   11326            4 :         error_at (fieldname_loc, "%qT has no member named %qE",
   11327              :                   constructor_type, fieldname);
   11328              :     }
   11329              :   else
   11330        34986 :     do
   11331              :       {
   11332        34986 :         constructor_fields = TREE_VALUE (field);
   11333        34986 :         designator_depth++;
   11334        34986 :         designator_erroneous = 0;
   11335        34986 :         if (constructor_range_stack)
   11336           11 :           push_range_stack (NULL_TREE, braced_init_obstack);
   11337        34986 :         field = TREE_CHAIN (field);
   11338        34986 :         if (field)
   11339              :           {
   11340           46 :             if (set_designator (loc, false, braced_init_obstack))
   11341              :               return;
   11342              :           }
   11343              :       }
   11344        34986 :     while (field != NULL_TREE);
   11345              : }
   11346              : 
   11347              : /* Helper function for add_pending_init.  Find inorder successor of P
   11348              :    in AVL tree.  */
   11349              : static struct init_node *
   11350          129 : init_node_successor (struct init_node *p)
   11351              : {
   11352          129 :   struct init_node *r;
   11353          129 :   if (p->right)
   11354              :     {
   11355              :       r = p->right;
   11356           58 :       while (r->left)
   11357              :         r = r->left;
   11358              :       return r;
   11359              :     }
   11360           75 :   r = p->parent;
   11361          114 :   while (r && p == r->right)
   11362              :     {
   11363           39 :       p = r;
   11364           39 :       r = r->parent;
   11365              :     }
   11366              :   return r;
   11367              : }
   11368              : 
   11369              : /* Add a new initializer to the tree of pending initializers.  PURPOSE
   11370              :    identifies the initializer, either array index or field in a structure.
   11371              :    VALUE is the value of that index or field.  If ORIGTYPE is not
   11372              :    NULL_TREE, it is the original type of VALUE.
   11373              : 
   11374              :    IMPLICIT is true if value comes from pop_init_level (1),
   11375              :    the new initializer has been merged with the existing one
   11376              :    and thus no warnings should be emitted about overriding an
   11377              :    existing initializer.  */
   11378              : 
   11379              : static void
   11380         7946 : add_pending_init (location_t loc, tree purpose, tree value, tree origtype,
   11381              :                   bool implicit, struct obstack *braced_init_obstack)
   11382              : {
   11383         7946 :   struct init_node *p, **q, *r;
   11384              : 
   11385         7946 :   q = &constructor_pending_elts;
   11386         7946 :   p = 0;
   11387              : 
   11388         7946 :   if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   11389              :     {
   11390         7214 :       while (*q != 0)
   11391              :         {
   11392         4384 :           p = *q;
   11393         4384 :           if (tree_int_cst_lt (purpose, p->purpose))
   11394          419 :             q = &p->left;
   11395         3965 :           else if (tree_int_cst_lt (p->purpose, purpose))
   11396              :             {
   11397         3354 :               if (TREE_CODE (p->value) != RAW_DATA_CST
   11398         3354 :                   || (p->right
   11399          112 :                       && tree_int_cst_le (p->right->purpose, purpose)))
   11400         3224 :                 q = &p->right;
   11401              :               else
   11402              :                 {
   11403          130 :                   widest_int pp = wi::to_widest (p->purpose);
   11404          130 :                   widest_int pw = wi::to_widest (purpose);
   11405          130 :                   if (pp + RAW_DATA_LENGTH (p->value) <= pw)
   11406           98 :                     q = &p->right;
   11407              :                   else
   11408              :                     {
   11409              :                       /* Override which should split the old RAW_DATA_CST
   11410              :                          into 2 or 3 pieces.  */
   11411           32 :                       if (!implicit && warn_override_init)
   11412            9 :                         warning_init (loc, OPT_Woverride_init,
   11413              :                                       "initialized field overwritten");
   11414           32 :                       unsigned HOST_WIDE_INT start = (pw - pp).to_uhwi ();
   11415           32 :                       unsigned HOST_WIDE_INT len = 1;
   11416           32 :                       if (TREE_CODE (value) == RAW_DATA_CST)
   11417            0 :                         len = RAW_DATA_LENGTH (value);
   11418           32 :                       unsigned HOST_WIDE_INT end = 0;
   11419           32 :                       unsigned plen = RAW_DATA_LENGTH (p->value);
   11420           32 :                       gcc_checking_assert (start < plen && start);
   11421           32 :                       if (plen - start > len)
   11422           30 :                         end = plen - start - len;
   11423           32 :                       tree v = p->value;
   11424           32 :                       tree origtype = p->origtype;
   11425           32 :                       if (start == 1)
   11426            2 :                         p->value = build_int_cst (TREE_TYPE (v),
   11427            2 :                                                   RAW_DATA_UCHAR_ELT (v, 0));
   11428              :                       else
   11429              :                         {
   11430           30 :                           p->value = v;
   11431           30 :                           if (end > 1)
   11432           26 :                             v = copy_node (v);
   11433           30 :                           RAW_DATA_LENGTH (p->value) = start;
   11434              :                         }
   11435           32 :                       if (end)
   11436              :                         {
   11437           30 :                           tree epurpose
   11438           30 :                             = size_binop (PLUS_EXPR, purpose,
   11439              :                                           bitsize_int (len));
   11440           30 :                           if (end > 1)
   11441              :                             {
   11442           28 :                               RAW_DATA_LENGTH (v) -= plen - end;
   11443           28 :                               RAW_DATA_POINTER (v) += plen - end;
   11444              :                             }
   11445              :                           else
   11446            2 :                             v = build_int_cst (TREE_TYPE (v),
   11447            2 :                                                RAW_DATA_UCHAR_ELT (v, plen
   11448              :                                                                       - end));
   11449           30 :                           add_pending_init (loc, epurpose, v, origtype,
   11450              :                                             implicit, braced_init_obstack);
   11451              :                         }
   11452           32 :                       q = &constructor_pending_elts;
   11453           32 :                       continue;
   11454           32 :                     }
   11455          130 :                 }
   11456              :             }
   11457              :           else
   11458              :             {
   11459          611 :               if (TREE_CODE (p->value) == RAW_DATA_CST
   11460          621 :                   && (RAW_DATA_LENGTH (p->value)
   11461           10 :                       > (TREE_CODE (value) == RAW_DATA_CST
   11462           10 :                          ? RAW_DATA_LENGTH (value) : 1)))
   11463              :                 {
   11464              :                   /* Override which should split the old RAW_DATA_CST
   11465              :                      into 2 pieces.  */
   11466            6 :                   if (!implicit && warn_override_init)
   11467            3 :                     warning_init (loc, OPT_Woverride_init,
   11468              :                                   "initialized field overwritten");
   11469            6 :                   unsigned HOST_WIDE_INT len = 1;
   11470            6 :                   if (TREE_CODE (value) == RAW_DATA_CST)
   11471            2 :                     len = RAW_DATA_LENGTH (value);
   11472            6 :                   if ((unsigned) RAW_DATA_LENGTH (p->value) > len + 1)
   11473              :                     {
   11474            6 :                       RAW_DATA_LENGTH (p->value) -= len;
   11475            6 :                       RAW_DATA_POINTER (p->value) += len;
   11476              :                     }
   11477              :                   else
   11478              :                     {
   11479            0 :                       unsigned int l = RAW_DATA_LENGTH (p->value) - 1;
   11480            0 :                       p->value
   11481            0 :                         = build_int_cst (TREE_TYPE (p->value),
   11482            0 :                                          RAW_DATA_UCHAR_ELT (p->value, l));
   11483              :                     }
   11484            6 :                   p->purpose = size_binop (PLUS_EXPR, p->purpose,
   11485              :                                            bitsize_int (len));
   11486            6 :                   continue;
   11487            6 :                 }
   11488          605 :               if (TREE_CODE (value) == RAW_DATA_CST)
   11489              :                 {
   11490            8 :                 handle_raw_data:
   11491              :                   /* RAW_DATA_CST value might overlap various further
   11492              :                      prior initval entries.  Find out how many.  */
   11493           13 :                   unsigned cnt = 0;
   11494           13 :                   widest_int w
   11495           26 :                     = wi::to_widest (purpose) + RAW_DATA_LENGTH (value);
   11496           13 :                   struct init_node *r = p, *last = NULL;
   11497           13 :                   bool override_init = warn_override_init;
   11498           13 :                   while ((r = init_node_successor (r))
   11499           53 :                          && wi::to_widest (r->purpose) < w)
   11500              :                     {
   11501           40 :                       ++cnt;
   11502           40 :                       if (TREE_SIDE_EFFECTS (r->value))
   11503            2 :                         warning_init (loc, OPT_Woverride_init_side_effects,
   11504              :                                       "initialized field with side-effects "
   11505              :                                       "overwritten");
   11506           38 :                       else if (override_init)
   11507              :                         {
   11508            6 :                           warning_init (loc, OPT_Woverride_init,
   11509              :                                         "initialized field overwritten");
   11510            6 :                           override_init = false;
   11511              :                         }
   11512              :                       last = r;
   11513              :                     }
   11514           13 :                   if (cnt)
   11515              :                     {
   11516           26 :                       if (TREE_CODE (last->value) == RAW_DATA_CST
   11517           13 :                           && (wi::to_widest (last->purpose)
   11518           13 :                               + RAW_DATA_LENGTH (last->value) > w))
   11519              :                         {
   11520              :                           /* The last overlapping prior initval overlaps
   11521              :                              only partially.  Shrink it and decrease cnt.  */
   11522            0 :                           unsigned int l = (wi::to_widest (last->purpose)
   11523            0 :                                             + RAW_DATA_LENGTH (last->value)
   11524            0 :                                             - w).to_uhwi ();
   11525            0 :                           --cnt;
   11526            0 :                           RAW_DATA_LENGTH (last->value) -= l;
   11527            0 :                           RAW_DATA_POINTER (last->value) += l;
   11528            0 :                           if (RAW_DATA_LENGTH (last->value) == 1)
   11529            0 :                             last->value
   11530            0 :                               = build_int_cst (TREE_TYPE (last->value),
   11531            0 :                                                RAW_DATA_UCHAR_ELT (last->value,
   11532              :                                                                    0));
   11533            0 :                           last->purpose
   11534            0 :                             = size_binop (PLUS_EXPR, last->purpose,
   11535              :                                           bitsize_int (l));
   11536              :                         }
   11537              :                       /* Instead of deleting cnt nodes from the AVL tree
   11538              :                          and rebalancing, peel of last cnt bytes from the
   11539              :                          RAW_DATA_CST.  Overriding thousands of previously
   11540              :                          initialized array elements with #embed needs to work,
   11541              :                          but doesn't need to be super efficient.  */
   11542           13 :                       gcc_checking_assert ((unsigned) RAW_DATA_LENGTH (value)
   11543              :                                            > cnt);
   11544           13 :                       RAW_DATA_LENGTH (value) -= cnt;
   11545           13 :                       const unsigned char *s
   11546           13 :                         = &RAW_DATA_UCHAR_ELT (value, RAW_DATA_LENGTH (value));
   11547           13 :                       unsigned int o = RAW_DATA_LENGTH (value);
   11548           53 :                       for (r = p; cnt--; ++o, ++s)
   11549              :                         {
   11550           40 :                           r = init_node_successor (r);
   11551           40 :                           r->purpose = size_binop (PLUS_EXPR, purpose,
   11552              :                                                    bitsize_int (o));
   11553           40 :                           r->value = build_int_cst (TREE_TYPE (value), *s);
   11554           40 :                           r->origtype = origtype;
   11555              :                         }
   11556           13 :                       if (RAW_DATA_LENGTH (value) == 1)
   11557            0 :                         value = build_int_cst (TREE_TYPE (value),
   11558            0 :                                                RAW_DATA_UCHAR_ELT (value, 0));
   11559              :                     }
   11560              :                 }
   11561          610 :               if (!implicit)
   11562              :                 {
   11563           54 :                   if (TREE_SIDE_EFFECTS (p->value))
   11564            6 :                     warning_init (loc, OPT_Woverride_init_side_effects,
   11565              :                                   "initialized field with side-effects "
   11566              :                                   "overwritten");
   11567           48 :                   else if (warn_override_init)
   11568           13 :                     warning_init (loc, OPT_Woverride_init,
   11569              :                                   "initialized field overwritten");
   11570              :                 }
   11571          610 :               p->value = value;
   11572          610 :               p->origtype = origtype;
   11573          610 :               return;
   11574              :             }
   11575              :         }
   11576         2830 :       if (TREE_CODE (value) == RAW_DATA_CST && p)
   11577              :         {
   11578           61 :           struct init_node *r;
   11579           61 :           if (q == &p->left)
   11580              :             r = p;
   11581              :           else
   11582           36 :             r = init_node_successor (p);
   11583          131 :           if (r && wi::to_widest (r->purpose) < (wi::to_widest (purpose)
   11584          131 :                                                  + RAW_DATA_LENGTH (value)))
   11585              :             {
   11586              :               /* Overlap with at least one prior initval in the range but
   11587              :                  not at the start.  */
   11588            5 :               p = r;
   11589            5 :               p->purpose = purpose;
   11590            5 :               goto handle_raw_data;
   11591              :             }
   11592              :         }
   11593              :     }
   11594              :   else
   11595              :     {
   11596         4511 :       tree bitpos;
   11597              : 
   11598         4511 :       bitpos = bit_position (purpose);
   11599        12596 :       while (*q != NULL)
   11600              :         {
   11601         4817 :           p = *q;
   11602         4817 :           if (tree_int_cst_lt (bitpos, bit_position (p->purpose)))
   11603           81 :             q = &p->left;
   11604         4736 :           else if (p->purpose != purpose)
   11605         3493 :             q = &p->right;
   11606              :           else
   11607              :             {
   11608         1243 :               if (!implicit)
   11609              :                 {
   11610          101 :                   if (TREE_SIDE_EFFECTS (p->value))
   11611            4 :                     warning_init (loc, OPT_Woverride_init_side_effects,
   11612              :                                   "initialized field with side-effects "
   11613              :                                   "overwritten");
   11614           97 :                   else if (warn_override_init)
   11615            6 :                     warning_init (loc, OPT_Woverride_init,
   11616              :                                   "initialized field overwritten");
   11617              :                 }
   11618         1243 :               p->value = value;
   11619         1243 :               p->origtype = origtype;
   11620         1243 :               return;
   11621              :             }
   11622              :         }
   11623              :     }
   11624              : 
   11625         6093 :   r = (struct init_node *) obstack_alloc (braced_init_obstack,
   11626              :                                           sizeof (struct init_node));
   11627         6093 :   r->purpose = purpose;
   11628         6093 :   r->value = value;
   11629         6093 :   r->origtype = origtype;
   11630              : 
   11631         6093 :   *q = r;
   11632         6093 :   r->parent = p;
   11633         6093 :   r->left = 0;
   11634         6093 :   r->right = 0;
   11635         6093 :   r->balance = 0;
   11636              : 
   11637         9877 :   while (p)
   11638              :     {
   11639         5160 :       struct init_node *s;
   11640              : 
   11641         5160 :       if (r == p->left)
   11642              :         {
   11643          343 :           if (p->balance == 0)
   11644          246 :             p->balance = -1;
   11645           97 :           else if (p->balance < 0)
   11646              :             {
   11647           45 :               if (r->balance < 0)
   11648              :                 {
   11649              :                   /* L rotation.  */
   11650           40 :                   p->left = r->right;
   11651           40 :                   if (p->left)
   11652            2 :                     p->left->parent = p;
   11653           40 :                   r->right = p;
   11654              : 
   11655           40 :                   p->balance = 0;
   11656           40 :                   r->balance = 0;
   11657              : 
   11658           40 :                   s = p->parent;
   11659           40 :                   p->parent = r;
   11660           40 :                   r->parent = s;
   11661           40 :                   if (s)
   11662              :                     {
   11663           31 :                       if (s->left == p)
   11664           10 :                         s->left = r;
   11665              :                       else
   11666           21 :                         s->right = r;
   11667              :                     }
   11668              :                   else
   11669            9 :                     constructor_pending_elts = r;
   11670              :                 }
   11671              :               else
   11672              :                 {
   11673              :                   /* LR rotation.  */
   11674            5 :                   struct init_node *t = r->right;
   11675              : 
   11676            5 :                   r->right = t->left;
   11677            5 :                   if (r->right)
   11678            0 :                     r->right->parent = r;
   11679            5 :                   t->left = r;
   11680              : 
   11681            5 :                   p->left = t->right;
   11682            5 :                   if (p->left)
   11683            0 :                     p->left->parent = p;
   11684            5 :                   t->right = p;
   11685              : 
   11686            5 :                   p->balance = t->balance < 0;
   11687            5 :                   r->balance = -(t->balance > 0);
   11688            5 :                   t->balance = 0;
   11689              : 
   11690            5 :                   s = p->parent;
   11691            5 :                   p->parent = t;
   11692            5 :                   r->parent = t;
   11693            5 :                   t->parent = s;
   11694            5 :                   if (s)
   11695              :                     {
   11696            0 :                       if (s->left == p)
   11697            0 :                         s->left = t;
   11698              :                       else
   11699            0 :                         s->right = t;
   11700              :                     }
   11701              :                   else
   11702            5 :                     constructor_pending_elts = t;
   11703              :                 }
   11704              :               break;
   11705              :             }
   11706              :           else
   11707              :             {
   11708              :               /* p->balance == +1; growth of left side balances the node.  */
   11709           52 :               p->balance = 0;
   11710           52 :               break;
   11711              :             }
   11712              :         }
   11713              :       else /* r == p->right */
   11714              :         {
   11715         4817 :           if (p->balance == 0)
   11716              :             /* Growth propagation from right side.  */
   11717         3538 :             p->balance++;
   11718         1279 :           else if (p->balance > 0)
   11719              :             {
   11720         1212 :               if (r->balance > 0)
   11721              :                 {
   11722              :                   /* R rotation.  */
   11723         1210 :                   p->right = r->left;
   11724         1210 :                   if (p->right)
   11725          193 :                     p->right->parent = p;
   11726         1210 :                   r->left = p;
   11727              : 
   11728         1210 :                   p->balance = 0;
   11729         1210 :                   r->balance = 0;
   11730              : 
   11731         1210 :                   s = p->parent;
   11732         1210 :                   p->parent = r;
   11733         1210 :                   r->parent = s;
   11734         1210 :                   if (s)
   11735              :                     {
   11736          410 :                       if (s->left == p)
   11737            2 :                         s->left = r;
   11738              :                       else
   11739          408 :                         s->right = r;
   11740              :                     }
   11741              :                   else
   11742          800 :                     constructor_pending_elts = r;
   11743              :                 }
   11744              :               else /* r->balance == -1 */
   11745              :                 {
   11746              :                   /* RL rotation */
   11747            2 :                   struct init_node *t = r->left;
   11748              : 
   11749            2 :                   r->left = t->right;
   11750            2 :                   if (r->left)
   11751            2 :                     r->left->parent = r;
   11752            2 :                   t->right = r;
   11753              : 
   11754            2 :                   p->right = t->left;
   11755            2 :                   if (p->right)
   11756            2 :                     p->right->parent = p;
   11757            2 :                   t->left = p;
   11758              : 
   11759            2 :                   r->balance = (t->balance < 0);
   11760            2 :                   p->balance = -(t->balance > 0);
   11761            2 :                   t->balance = 0;
   11762              : 
   11763            2 :                   s = p->parent;
   11764            2 :                   p->parent = t;
   11765            2 :                   r->parent = t;
   11766            2 :                   t->parent = s;
   11767            2 :                   if (s)
   11768              :                     {
   11769            0 :                       if (s->left == p)
   11770            0 :                         s->left = t;
   11771              :                       else
   11772            0 :                         s->right = t;
   11773              :                     }
   11774              :                   else
   11775            2 :                     constructor_pending_elts = t;
   11776              :                 }
   11777              :               break;
   11778              :             }
   11779              :           else
   11780              :             {
   11781              :               /* p->balance == -1; growth of right side balances the node.  */
   11782           67 :               p->balance = 0;
   11783           67 :               break;
   11784              :             }
   11785              :         }
   11786              : 
   11787         3784 :       r = p;
   11788         3784 :       p = p->parent;
   11789              :     }
   11790              : }
   11791              : 
   11792              : /* Build AVL tree from a sorted chain.  */
   11793              : 
   11794              : static void
   11795         1812 : set_nonincremental_init (struct obstack * braced_init_obstack)
   11796              : {
   11797         1812 :   unsigned HOST_WIDE_INT ix;
   11798         1812 :   tree index, value;
   11799              : 
   11800         1812 :   if (TREE_CODE (constructor_type) != RECORD_TYPE
   11801         1812 :       && TREE_CODE (constructor_type) != ARRAY_TYPE)
   11802              :     return;
   11803              : 
   11804         5511 :   FOR_EACH_CONSTRUCTOR_ELT (constructor_elements, ix, index, value)
   11805         3699 :     add_pending_init (input_location, index, value, NULL_TREE, true,
   11806              :                       braced_init_obstack);
   11807         1812 :   constructor_elements = NULL;
   11808         1812 :   if (TREE_CODE (constructor_type) == RECORD_TYPE)
   11809              :     {
   11810          948 :       constructor_unfilled_fields = TYPE_FIELDS (constructor_type);
   11811              :       /* Skip any nameless bit fields at the beginning.  */
   11812          948 :       while (constructor_unfilled_fields != NULL_TREE
   11813          948 :              && DECL_UNNAMED_BIT_FIELD (constructor_unfilled_fields))
   11814            0 :         constructor_unfilled_fields = TREE_CHAIN (constructor_unfilled_fields);
   11815              : 
   11816              :     }
   11817          864 :   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   11818              :     {
   11819          864 :       if (TYPE_DOMAIN (constructor_type))
   11820          806 :         constructor_unfilled_index
   11821          806 :           = convert (bitsizetype,
   11822          806 :                      TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
   11823              :       else
   11824           58 :         constructor_unfilled_index = bitsize_zero_node;
   11825              :     }
   11826         1812 :   constructor_incremental = 0;
   11827              : }
   11828              : 
   11829              : /* Build AVL tree from a string constant.  */
   11830              : 
   11831              : static void
   11832            7 : set_nonincremental_init_from_string (tree str,
   11833              :                                      struct obstack * braced_init_obstack)
   11834              : {
   11835            7 :   tree value, purpose, type;
   11836            7 :   HOST_WIDE_INT val[2];
   11837            7 :   const char *p, *end;
   11838            7 :   int byte, wchar_bytes, charwidth, bitpos;
   11839              : 
   11840            7 :   gcc_assert (TREE_CODE (constructor_type) == ARRAY_TYPE);
   11841              : 
   11842            7 :   wchar_bytes = TYPE_PRECISION (TREE_TYPE (TREE_TYPE (str))) / BITS_PER_UNIT;
   11843            7 :   charwidth = TYPE_PRECISION (char_type_node);
   11844            7 :   gcc_assert ((size_t) wchar_bytes * charwidth
   11845              :               <= ARRAY_SIZE (val) * HOST_BITS_PER_WIDE_INT);
   11846            7 :   type = TREE_TYPE (constructor_type);
   11847            7 :   p = TREE_STRING_POINTER (str);
   11848            7 :   end = p + TREE_STRING_LENGTH (str);
   11849              : 
   11850            7 :   for (purpose = bitsize_zero_node;
   11851              :        p < end
   11852           52 :        && !(constructor_max_index
   11853           20 :             && tree_int_cst_lt (constructor_max_index, purpose));
   11854           25 :        purpose = size_binop (PLUS_EXPR, purpose, bitsize_one_node))
   11855              :     {
   11856           25 :       if (wchar_bytes == 1)
   11857              :         {
   11858            9 :           val[0] = (unsigned char) *p++;
   11859            9 :           val[1] = 0;
   11860              :         }
   11861              :       else
   11862              :         {
   11863           16 :           val[1] = 0;
   11864           16 :           val[0] = 0;
   11865           64 :           for (byte = 0; byte < wchar_bytes; byte++)
   11866              :             {
   11867           48 :               if (BYTES_BIG_ENDIAN)
   11868              :                 bitpos = (wchar_bytes - byte - 1) * charwidth;
   11869              :               else
   11870           48 :                 bitpos = byte * charwidth;
   11871           48 :               val[bitpos / HOST_BITS_PER_WIDE_INT]
   11872           48 :                 |= ((unsigned HOST_WIDE_INT) ((unsigned char) *p++))
   11873           48 :                    << (bitpos % HOST_BITS_PER_WIDE_INT);
   11874              :             }
   11875              :         }
   11876              : 
   11877           25 :       if (!TYPE_UNSIGNED (type))
   11878              :         {
   11879           13 :           bitpos = ((wchar_bytes - 1) * charwidth) + HOST_BITS_PER_CHAR;
   11880           13 :           if (bitpos < HOST_BITS_PER_WIDE_INT)
   11881              :             {
   11882           13 :               if (val[0] & (HOST_WIDE_INT_1 << (bitpos - 1)))
   11883              :                 {
   11884            0 :                   val[0] |= HOST_WIDE_INT_M1U << bitpos;
   11885            0 :                   val[1] = -1;
   11886              :                 }
   11887              :             }
   11888            0 :           else if (bitpos == HOST_BITS_PER_WIDE_INT)
   11889              :             {
   11890            0 :               if (val[0] < 0)
   11891            0 :                 val[1] = -1;
   11892              :             }
   11893            0 :           else if (val[1] & (HOST_WIDE_INT_1
   11894            0 :                              << (bitpos - 1 - HOST_BITS_PER_WIDE_INT)))
   11895            0 :             val[1] |= HOST_WIDE_INT_M1U << (bitpos - HOST_BITS_PER_WIDE_INT);
   11896              :         }
   11897              : 
   11898           25 :       value = wide_int_to_tree (type,
   11899           25 :                                 wide_int::from_array (val, 2,
   11900              :                                                       HOST_BITS_PER_WIDE_INT * 2));
   11901           25 :       add_pending_init (input_location, purpose, value, NULL_TREE, true,
   11902              :                         braced_init_obstack);
   11903              :     }
   11904              : 
   11905            7 :   constructor_incremental = 0;
   11906            7 : }
   11907              : 
   11908              : /* Return value of FIELD in pending initializer or NULL_TREE if the field was
   11909              :    not initialized yet.  */
   11910              : 
   11911              : static tree
   11912       705323 : find_init_member (tree field, struct obstack * braced_init_obstack)
   11913              : {
   11914       705323 :   struct init_node *p;
   11915              : 
   11916       705323 :   if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   11917              :     {
   11918       703504 :       if (constructor_incremental
   11919       703504 :           && tree_int_cst_lt (field, constructor_unfilled_index))
   11920           16 :         set_nonincremental_init (braced_init_obstack);
   11921              : 
   11922       703504 :       p = constructor_pending_elts;
   11923       704103 :       while (p)
   11924              :         {
   11925         1151 :           if (tree_int_cst_lt (field, p->purpose))
   11926           93 :             p = p->left;
   11927         1058 :           else if (tree_int_cst_lt (p->purpose, field))
   11928          506 :             p = p->right;
   11929              :           else
   11930          552 :             return p->value;
   11931              :         }
   11932              :     }
   11933         1819 :   else if (TREE_CODE (constructor_type) == RECORD_TYPE)
   11934              :     {
   11935         1696 :       tree bitpos = bit_position (field);
   11936              : 
   11937         1696 :       if (constructor_incremental
   11938         1696 :           && (!constructor_unfilled_fields
   11939          609 :               || tree_int_cst_lt (bitpos,
   11940          609 :                                   bit_position (constructor_unfilled_fields))))
   11941          289 :         set_nonincremental_init (braced_init_obstack);
   11942              : 
   11943         1696 :       p = constructor_pending_elts;
   11944         2652 :       while (p)
   11945              :         {
   11946         2047 :           if (field == p->purpose)
   11947         1091 :             return p->value;
   11948          956 :           else if (tree_int_cst_lt (bitpos, bit_position (p->purpose)))
   11949            7 :             p = p->left;
   11950              :           else
   11951          949 :             p = p->right;
   11952              :         }
   11953              :     }
   11954          123 :   else if (TREE_CODE (constructor_type) == UNION_TYPE)
   11955              :     {
   11956          123 :       if (!vec_safe_is_empty (constructor_elements)
   11957           50 :           && (constructor_elements->last ().index == field))
   11958           50 :         return constructor_elements->last ().value;
   11959              :     }
   11960              :   return NULL_TREE;
   11961              : }
   11962              : 
   11963              : /* "Output" the next constructor element.
   11964              :    At top level, really output it to assembler code now.
   11965              :    Otherwise, collect it in a list from which we will make a CONSTRUCTOR.
   11966              :    If ORIGTYPE is not NULL_TREE, it is the original type of VALUE.
   11967              :    TYPE is the data type that the containing data type wants here.
   11968              :    FIELD is the field (a FIELD_DECL) or the index that this element fills.
   11969              :    If VALUE is a string constant, STRICT_STRING is true if it is
   11970              :    unparenthesized or we should not warn here for it being parenthesized.
   11971              :    For other types of VALUE, STRICT_STRING is not used.
   11972              : 
   11973              :    PENDING if true means output pending elements that belong
   11974              :    right after this element.  (PENDING is normally true;
   11975              :    it is false while outputting pending elements, to avoid recursion.)
   11976              : 
   11977              :    IMPLICIT is true if value comes from pop_init_level (1),
   11978              :    the new initializer has been merged with the existing one
   11979              :    and thus no warnings should be emitted about overriding an
   11980              :    existing initializer.  */
   11981              : 
   11982              : static void
   11983      9631949 : output_init_element (location_t loc, tree value, tree origtype,
   11984              :                      bool strict_string, tree type, tree field, bool pending,
   11985              :                      bool implicit, struct obstack * braced_init_obstack)
   11986              : {
   11987      9631949 :   tree semantic_type = NULL_TREE;
   11988      9631949 :   bool maybe_const = true;
   11989      9631949 :   bool npc, int_const_expr, arith_const_expr;
   11990              : 
   11991      9631949 :   if (type == error_mark_node || value == error_mark_node)
   11992              :     {
   11993          514 :       constructor_erroneous = 1;
   11994         4800 :       return;
   11995              :     }
   11996      9631435 :   if (TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
   11997       200970 :       && (TREE_CODE (value) == STRING_CST
   11998       159557 :           || TREE_CODE (value) == COMPOUND_LITERAL_EXPR)
   11999        41421 :       && !(TREE_CODE (value) == STRING_CST
   12000        41413 :            && TREE_CODE (type) == ARRAY_TYPE
   12001         3898 :            && INTEGRAL_TYPE_P (TREE_TYPE (type)))
   12002      9668958 :       && !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (value)),
   12003        37523 :                      TYPE_MAIN_VARIANT (type)))
   12004        37523 :     value = array_to_pointer_conversion (input_location, value);
   12005              : 
   12006      9631435 :   if (TREE_CODE (value) == COMPOUND_LITERAL_EXPR
   12007          182 :       && require_constant_value && pending)
   12008              :     {
   12009              :       /* As an extension, allow initializing objects with static storage
   12010              :          duration with compound literals (which are then treated just as
   12011              :          the brace enclosed list they contain).  */
   12012          114 :       if (flag_isoc99)
   12013           24 :         pedwarn_init (loc, OPT_Wpedantic, "initializer element is not "
   12014              :                       "constant");
   12015          114 :       tree decl = COMPOUND_LITERAL_EXPR_DECL (value);
   12016          114 :       value = DECL_INITIAL (decl);
   12017              :     }
   12018              : 
   12019      9631435 :   npc = null_pointer_constant_p (value);
   12020     19262870 :   int_const_expr = (TREE_CODE (value) == INTEGER_CST
   12021      4222564 :                     && !TREE_OVERFLOW (value)
   12022     13853998 :                     && INTEGRAL_TYPE_P (TREE_TYPE (value)));
   12023              :   /* Not fully determined before folding.  */
   12024      9631435 :   arith_const_expr = true;
   12025      9631435 :   if (TREE_CODE (value) == EXCESS_PRECISION_EXPR)
   12026              :     {
   12027           16 :       semantic_type = TREE_TYPE (value);
   12028           16 :       value = TREE_OPERAND (value, 0);
   12029              :     }
   12030      9631435 :   value = c_fully_fold (value, require_constant_value, &maybe_const);
   12031              :   /* TODO: this may not detect all cases of expressions folding to
   12032              :      constants that are not arithmetic constant expressions.  */
   12033      9631435 :   if (!maybe_const)
   12034              :     arith_const_expr = false;
   12035     19260313 :   else if (!INTEGRAL_TYPE_P (TREE_TYPE (value))
   12036      3189205 :            && TREE_CODE (TREE_TYPE (value)) != REAL_TYPE
   12037     11476190 :            && TREE_CODE (TREE_TYPE (value)) != COMPLEX_TYPE)
   12038              :     arith_const_expr = false;
   12039      7799447 :   else if (TREE_CODE (value) != INTEGER_CST
   12040              :            && TREE_CODE (value) != REAL_CST
   12041              :            && TREE_CODE (value) != COMPLEX_CST
   12042              :            && TREE_CODE (value) != RAW_DATA_CST)
   12043              :     arith_const_expr = false;
   12044      4611499 :   else if (TREE_OVERFLOW (value))
   12045      5019937 :     arith_const_expr = false;
   12046              : 
   12047      9631435 :   if (value == error_mark_node)
   12048            0 :     constructor_erroneous = 1;
   12049      9631435 :   else if (!TREE_CONSTANT (value))
   12050      3208395 :     constructor_constant = 0;
   12051      6423040 :   else if (!initializer_constant_valid_p (value,
   12052      6423040 :                                           TREE_TYPE (value),
   12053      6423040 :                                           AGGREGATE_TYPE_P (constructor_type)
   12054      6423040 :                                           && TYPE_REVERSE_STORAGE_ORDER
   12055              :                                              (constructor_type))
   12056      6423040 :            || (RECORD_OR_UNION_TYPE_P (constructor_type)
   12057      1041180 :                && DECL_C_BIT_FIELD (field)
   12058         7995 :                && TREE_CODE (value) != INTEGER_CST))
   12059           77 :     constructor_simple = 0;
   12060      9631435 :   if (!maybe_const)
   12061         1172 :     constructor_nonconst = 1;
   12062              : 
   12063              :   /* Digest the initializer and issue any errors about incompatible
   12064              :      types before issuing errors about non-constant initializers.  */
   12065      9631435 :   tree new_value = value;
   12066      9631435 :   if (semantic_type)
   12067           16 :     new_value = build1 (EXCESS_PRECISION_EXPR, semantic_type, value);
   12068              :   /* In the case of braces around a scalar initializer, the result of
   12069              :      this initializer processing goes through digest_init again at the
   12070              :      outer level.  In the case of a constexpr initializer for a
   12071              :      pointer, avoid converting a null pointer constant to something
   12072              :      that is not a null pointer constant to avoid a spurious error
   12073              :      from that second processing.  */
   12074      9631435 :   if (!require_constexpr_value
   12075          398 :       || !npc
   12076           69 :       || TREE_CODE (constructor_type) != POINTER_TYPE)
   12077      9631424 :     new_value = digest_init (loc,
   12078      9631424 :                              RECORD_OR_UNION_TYPE_P (constructor_type)
   12079      8557188 :                              ? field : constructor_fields
   12080      8557188 :                              ? constructor_fields : constructor_decl,
   12081              :                              type, new_value, origtype, npc,
   12082              :                              int_const_expr, arith_const_expr, strict_string,
   12083              :                              require_constant_value, require_constexpr_value);
   12084      9631435 :   if (new_value == error_mark_node)
   12085              :     {
   12086           76 :       constructor_erroneous = 1;
   12087           76 :       return;
   12088              :     }
   12089      9631359 :   if (require_constant_value || require_constant_elements)
   12090      2713770 :     constant_expression_warning (new_value);
   12091              : 
   12092              :   /* Proceed to check the constness of the original initializer.  */
   12093      9631359 :   if (!initializer_constant_valid_p (value, TREE_TYPE (value)))
   12094              :     {
   12095      3208421 :       if (require_constant_value)
   12096              :         {
   12097            0 :           error_init (loc, "initializer element is not constant");
   12098            0 :           value = error_mark_node;
   12099              :         }
   12100      3208421 :       else if (require_constant_elements)
   12101           15 :         pedwarn (loc, OPT_Wpedantic,
   12102              :                  "initializer element is not computable at load time");
   12103              :     }
   12104      6422938 :   else if (!maybe_const
   12105           54 :            && (require_constant_value || require_constant_elements))
   12106           28 :     pedwarn_init (loc, OPT_Wpedantic,
   12107              :                   "initializer element is not a constant expression");
   12108              :   /* digest_init has already carried out the additional checks
   12109              :      required for 'constexpr' initializers (using the information
   12110              :      passed to it about whether the original initializer was certain
   12111              :      kinds of constant expression), so that check does not need to be
   12112              :      repeated here.  */
   12113              : 
   12114              :   /* Issue -Wc++-compat warnings about initializing a bitfield with
   12115              :      enum type.  */
   12116      9631359 :   if (warn_cxx_compat
   12117         6897 :       && field != NULL_TREE
   12118         6897 :       && TREE_CODE (field) == FIELD_DECL
   12119          461 :       && DECL_BIT_FIELD_TYPE (field) != NULL_TREE
   12120           21 :       && (TYPE_MAIN_VARIANT (DECL_BIT_FIELD_TYPE (field))
   12121           21 :           != TYPE_MAIN_VARIANT (type))
   12122      9631380 :       && TREE_CODE (DECL_BIT_FIELD_TYPE (field)) == ENUMERAL_TYPE)
   12123              :     {
   12124           21 :       tree checktype = origtype != NULL_TREE ? origtype : TREE_TYPE (value);
   12125           21 :       if (checktype != error_mark_node
   12126           21 :           && (TYPE_MAIN_VARIANT (checktype)
   12127           21 :               != TYPE_MAIN_VARIANT (DECL_BIT_FIELD_TYPE (field))))
   12128            9 :         warning_init (loc, OPT_Wc___compat,
   12129              :                       "enum conversion in initialization is invalid in C++");
   12130              :     }
   12131              : 
   12132              :   /* If this field is empty and does not have side effects (and is not at
   12133              :      the end of structure), don't do anything other than checking the
   12134              :      initializer.  */
   12135      9631359 :   if (field
   12136      9631359 :       && (TREE_TYPE (field) == error_mark_node
   12137      9630924 :           || (COMPLETE_TYPE_P (TREE_TYPE (field))
   12138      9630615 :               && integer_zerop (TYPE_SIZE (TREE_TYPE (field)))
   12139           62 :               && !TREE_SIDE_EFFECTS (new_value)
   12140           33 :               && (TREE_CODE (constructor_type) == ARRAY_TYPE
   12141           33 :                   || DECL_CHAIN (field)))))
   12142           18 :     return;
   12143              : 
   12144              :   /* Finally, set VALUE to the initializer value digested above.  */
   12145      9631341 :   value = new_value;
   12146              : 
   12147              :   /* If this element doesn't come next in sequence,
   12148              :      put it on constructor_pending_elts.  */
   12149      9631341 :   if (TREE_CODE (constructor_type) == ARRAY_TYPE
   12150      9631341 :       && (!constructor_incremental
   12151      1720956 :           || !tree_int_cst_equal (field, constructor_unfilled_index)
   12152      1720522 :           || (TREE_CODE (value) == RAW_DATA_CST
   12153          237 :               && constructor_pending_elts
   12154           66 :               && pending)))
   12155              :     {
   12156         1341 :       if (constructor_incremental
   12157         1341 :           && (tree_int_cst_lt (field, constructor_unfilled_index)
   12158          405 :               || (TREE_CODE (value) == RAW_DATA_CST
   12159           14 :                   && constructor_pending_elts
   12160           14 :                   && pending)))
   12161           48 :         set_nonincremental_init (braced_init_obstack);
   12162              : 
   12163         1341 :       add_pending_init (loc, field, value, origtype, implicit,
   12164              :                         braced_init_obstack);
   12165         1341 :       return;
   12166              :     }
   12167      9630000 :   else if (TREE_CODE (constructor_type) == RECORD_TYPE
   12168      1042890 :            && (!constructor_incremental
   12169      1041224 :                || field != constructor_unfilled_fields))
   12170              :     {
   12171              :       /* We do this for records but not for unions.  In a union,
   12172              :          no matter which field is specified, it can be initialized
   12173              :          right away since it starts at the beginning of the union.  */
   12174         2851 :       if (constructor_incremental)
   12175              :         {
   12176         1185 :           if (!constructor_unfilled_fields)
   12177           39 :             set_nonincremental_init (braced_init_obstack);
   12178              :           else
   12179              :             {
   12180         1146 :               tree bitpos, unfillpos;
   12181              : 
   12182         1146 :               bitpos = bit_position (field);
   12183         1146 :               unfillpos = bit_position (constructor_unfilled_fields);
   12184              : 
   12185         1146 :               if (tree_int_cst_lt (bitpos, unfillpos))
   12186            4 :                 set_nonincremental_init (braced_init_obstack);
   12187              :             }
   12188              :         }
   12189              : 
   12190         2851 :       add_pending_init (loc, field, value, origtype, implicit,
   12191              :                         braced_init_obstack);
   12192         2851 :       return;
   12193              :     }
   12194      9627149 :   else if (TREE_CODE (constructor_type) == UNION_TYPE
   12195      9627149 :            && !vec_safe_is_empty (constructor_elements))
   12196              :     {
   12197           62 :       if (!implicit)
   12198              :         {
   12199           12 :           if (TREE_SIDE_EFFECTS (constructor_elements->last ().value))
   12200            3 :             warning_init (loc, OPT_Woverride_init_side_effects,
   12201              :                           "initialized field with side-effects overwritten");
   12202            9 :           else if (warn_override_init)
   12203            6 :             warning_init (loc, OPT_Woverride_init,
   12204              :                           "initialized field overwritten");
   12205              :         }
   12206              : 
   12207              :       /* We can have just one union field set.  */
   12208           62 :       constructor_elements = NULL;
   12209              :     }
   12210              : 
   12211              :   /* Otherwise, output this element either to
   12212              :      constructor_elements or to the assembler file.  */
   12213              : 
   12214      9627149 :   constructor_elt celt = {field, value};
   12215      9627149 :   vec_safe_push (constructor_elements, celt);
   12216              : 
   12217              :   /* Advance the variable that indicates sequential elements output.  */
   12218      9627149 :   if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   12219              :     {
   12220      1720517 :       tree inc = bitsize_one_node;
   12221      1720517 :       if (value && TREE_CODE (value) == RAW_DATA_CST)
   12222          232 :         inc = bitsize_int (RAW_DATA_LENGTH (value));
   12223      1720517 :       constructor_unfilled_index
   12224      1720517 :         = size_binop_loc (input_location, PLUS_EXPR,
   12225              :                           constructor_unfilled_index, inc);
   12226              :     }
   12227      7906632 :   else if (TREE_CODE (constructor_type) == RECORD_TYPE)
   12228              :     {
   12229      1040039 :       constructor_unfilled_fields
   12230      1040039 :         = DECL_CHAIN (constructor_unfilled_fields);
   12231              : 
   12232              :       /* Skip any nameless bit fields.  */
   12233      1040039 :       while (constructor_unfilled_fields != NULL_TREE
   12234      1040140 :              && DECL_UNNAMED_BIT_FIELD (constructor_unfilled_fields))
   12235          101 :         constructor_unfilled_fields
   12236          101 :           = DECL_CHAIN (constructor_unfilled_fields);
   12237              :     }
   12238      6866593 :   else if (TREE_CODE (constructor_type) == UNION_TYPE)
   12239        31314 :     constructor_unfilled_fields = NULL_TREE;
   12240              : 
   12241              :   /* Now output any pending elements which have become next.  */
   12242      9627149 :   if (pending)
   12243      9621001 :     output_pending_init_elements (0, braced_init_obstack);
   12244              : }
   12245              : 
   12246              : /* For two FIELD_DECLs in the same chain, return -1 if field1
   12247              :    comes before field2, 1 if field1 comes after field2 and
   12248              :    0 if field1 == field2.  */
   12249              : 
   12250              : static int
   12251         7008 : init_field_decl_cmp (tree field1, tree field2)
   12252              : {
   12253         7008 :   if (field1 == field2)
   12254              :     return 0;
   12255              : 
   12256         3288 :   tree bitpos1 = bit_position (field1);
   12257         3288 :   tree bitpos2 = bit_position (field2);
   12258         3288 :   if (tree_int_cst_equal (bitpos1, bitpos2))
   12259              :     {
   12260              :       /* If one of the fields has non-zero bitsize, then that
   12261              :          field must be the last one in a sequence of zero
   12262              :          sized fields, fields after it will have bigger
   12263              :          bit_position.  */
   12264           22 :       if (TREE_TYPE (field1) != error_mark_node
   12265           22 :           && COMPLETE_TYPE_P (TREE_TYPE (field1))
   12266           44 :           && integer_nonzerop (TREE_TYPE (field1)))
   12267              :         return 1;
   12268           22 :       if (TREE_TYPE (field2) != error_mark_node
   12269           22 :           && COMPLETE_TYPE_P (TREE_TYPE (field2))
   12270           37 :           && integer_nonzerop (TREE_TYPE (field2)))
   12271              :         return -1;
   12272              :       /* Otherwise, fallback to DECL_CHAIN walk to find out
   12273              :          which field comes earlier.  Walk chains of both
   12274              :          fields, so that if field1 and field2 are close to each
   12275              :          other in either order, it is found soon even for large
   12276              :          sequences of zero sized fields.  */
   12277              :       tree f1 = field1, f2 = field2;
   12278           22 :       while (1)
   12279              :         {
   12280           22 :           f1 = DECL_CHAIN (f1);
   12281           22 :           f2 = DECL_CHAIN (f2);
   12282           22 :           if (f1 == NULL_TREE)
   12283              :             {
   12284            7 :               gcc_assert (f2);
   12285              :               return 1;
   12286              :             }
   12287           15 :           if (f2 == NULL_TREE)
   12288              :             return -1;
   12289            1 :           if (f1 == field2)
   12290              :             return -1;
   12291            0 :           if (f2 == field1)
   12292              :             return 1;
   12293            0 :           if (!tree_int_cst_equal (bit_position (f1), bitpos1))
   12294              :             return 1;
   12295            0 :           if (!tree_int_cst_equal (bit_position (f2), bitpos1))
   12296              :             return -1;
   12297              :         }
   12298              :     }
   12299         3266 :   else if (tree_int_cst_lt (bitpos1, bitpos2))
   12300              :     return -1;
   12301              :   else
   12302              :     return 1;
   12303              : }
   12304              : 
   12305              : /* Output any pending elements which have become next.
   12306              :    As we output elements, constructor_unfilled_{fields,index}
   12307              :    advances, which may cause other elements to become next;
   12308              :    if so, they too are output.
   12309              : 
   12310              :    If ALL is 0, we return when there are
   12311              :    no more pending elements to output now.
   12312              : 
   12313              :    If ALL is 1, we output space as necessary so that
   12314              :    we can output all the pending elements.  */
   12315              : static void
   12316     11692434 : output_pending_init_elements (int all, struct obstack * braced_init_obstack)
   12317              : {
   12318     11692434 :   struct init_node *elt = constructor_pending_elts;
   12319     11693582 :   tree next;
   12320              : 
   12321     11693582 :  retry:
   12322              : 
   12323              :   /* Look through the whole pending tree.
   12324              :      If we find an element that should be output now,
   12325              :      output it.  Otherwise, set NEXT to the element
   12326              :      that comes first among those still pending.  */
   12327              : 
   12328     11693582 :   next = NULL_TREE;
   12329     11705681 :   while (elt)
   12330              :     {
   12331        14949 :       if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   12332              :         {
   12333         6812 :           if (tree_int_cst_equal (elt->purpose,
   12334              :                                   constructor_unfilled_index))
   12335         2829 :             output_init_element (input_location, elt->value, elt->origtype,
   12336         2829 :                                  true, TREE_TYPE (constructor_type),
   12337              :                                  constructor_unfilled_index, false, false,
   12338              :                                  braced_init_obstack);
   12339         3983 :           else if (tree_int_cst_lt (constructor_unfilled_index,
   12340         3983 :                                     elt->purpose))
   12341              :             {
   12342              :               /* Advance to the next smaller node.  */
   12343         1133 :               if (elt->left)
   12344              :                 elt = elt->left;
   12345              :               else
   12346              :                 {
   12347              :                   /* We have reached the smallest node bigger than the
   12348              :                      current unfilled index.  Fill the space first.  */
   12349          345 :                   next = elt->purpose;
   12350          345 :                   break;
   12351              :                 }
   12352              :             }
   12353              :           else
   12354              :             {
   12355              :               /* Advance to the next bigger node.  */
   12356         2850 :               if (elt->right)
   12357              :                 elt = elt->right;
   12358              :               else
   12359              :                 {
   12360              :                   /* We have reached the biggest node in a subtree.  Find
   12361              :                      the parent of it, which is the next bigger node.  */
   12362         2850 :                   while (elt->parent && elt->parent->right == elt)
   12363              :                     elt = elt->parent;
   12364         1896 :                   elt = elt->parent;
   12365         2679 :                   if (elt && tree_int_cst_lt (constructor_unfilled_index,
   12366          783 :                                               elt->purpose))
   12367              :                     {
   12368           22 :                       next = elt->purpose;
   12369           22 :                       break;
   12370              :                     }
   12371              :                 }
   12372              :             }
   12373              :         }
   12374         8137 :       else if (RECORD_OR_UNION_TYPE_P (constructor_type))
   12375              :         {
   12376              :           /* If the current record is complete we are done.  */
   12377         8137 :           if (constructor_unfilled_fields == NULL_TREE)
   12378              :             break;
   12379              : 
   12380         6544 :           int cmp = init_field_decl_cmp (constructor_unfilled_fields,
   12381              :                                          elt->purpose);
   12382         6544 :           if (cmp == 0)
   12383         3319 :             output_init_element (input_location, elt->value, elt->origtype,
   12384         3319 :                                  true, TREE_TYPE (elt->purpose),
   12385              :                                  elt->purpose, false, false,
   12386              :                                  braced_init_obstack);
   12387         3225 :           else if (cmp < 0)
   12388              :             {
   12389              :               /* Advance to the next smaller node.  */
   12390         1298 :               if (elt->left)
   12391              :                 elt = elt->left;
   12392              :               else
   12393              :                 {
   12394              :                   /* We have reached the smallest node bigger than the
   12395              :                      current unfilled field.  Fill the space first.  */
   12396          827 :                   next = elt->purpose;
   12397          827 :                   break;
   12398              :                 }
   12399              :             }
   12400              :           else
   12401              :             {
   12402              :               /* Advance to the next bigger node.  */
   12403         1927 :               if (elt->right)
   12404              :                 elt = elt->right;
   12405              :               else
   12406              :                 {
   12407              :                   /* We have reached the biggest node in a subtree.  Find
   12408              :                      the parent of it, which is the next bigger node.  */
   12409         1013 :                   while (elt->parent && elt->parent->right == elt)
   12410              :                     elt = elt->parent;
   12411          777 :                   elt = elt->parent;
   12412          777 :                   if (elt
   12413          777 :                       && init_field_decl_cmp (constructor_unfilled_fields,
   12414              :                                               elt->purpose) < 0)
   12415              :                     {
   12416           63 :                       next = elt->purpose;
   12417           63 :                       break;
   12418              :                     }
   12419              :                 }
   12420              :             }
   12421              :         }
   12422              :     }
   12423              : 
   12424              :   /* Ordinarily return, but not if we want to output all
   12425              :      and there are elements left.  */
   12426     11693582 :   if (!(all && next != NULL_TREE))
   12427     11692434 :     return;
   12428              : 
   12429              :   /* If it's not incremental, just skip over the gap, so that after
   12430              :      jumping to retry we will output the next successive element.  */
   12431         1148 :   if (RECORD_OR_UNION_TYPE_P (constructor_type))
   12432          820 :     constructor_unfilled_fields = next;
   12433          328 :   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   12434          328 :     constructor_unfilled_index = next;
   12435              : 
   12436              :   /* ELT now points to the node in the pending tree with the next
   12437              :      initializer to output.  */
   12438         1148 :   goto retry;
   12439              : }
   12440              : 
   12441              : /* Expression VALUE coincides with the start of type TYPE in a braced
   12442              :    initializer.  Return true if we should treat VALUE as initializing
   12443              :    the first element of TYPE, false if we should treat it as initializing
   12444              :    TYPE as a whole.
   12445              : 
   12446              :    If the initializer is clearly invalid, the question becomes:
   12447              :    which choice gives the best error message?  */
   12448              : 
   12449              : static bool
   12450      3489444 : initialize_elementwise_p (tree type, tree value)
   12451              : {
   12452      3489444 :   if (type == error_mark_node || value == error_mark_node)
   12453              :     return false;
   12454              : 
   12455      3488951 :   gcc_checking_assert (TYPE_MAIN_VARIANT (type) == type);
   12456              : 
   12457      3488951 :   tree value_type = TREE_TYPE (value);
   12458      3488951 :   if (value_type == error_mark_node)
   12459              :     return false;
   12460              : 
   12461              :   /* GNU vectors can be initialized elementwise.  However, treat any
   12462              :      kind of vector value as initializing the vector type as a whole,
   12463              :      regardless of whether the value is a GNU vector.  Such initializers
   12464              :      are valid if and only if they would have been valid in a non-braced
   12465              :      initializer like:
   12466              : 
   12467              :         TYPE foo = VALUE;
   12468              : 
   12469              :      so recursing into the vector type would be at best confusing or at
   12470              :      worst wrong.  For example, when -flax-vector-conversions is in effect,
   12471              :      it's possible to initialize a V8HI from a V4SI, even though the vectors
   12472              :      have different element types and different numbers of elements.  */
   12473      3488951 :   if (gnu_vector_type_p (type))
   12474        19532 :     return !VECTOR_TYPE_P (value_type);
   12475              : 
   12476      3469419 :   if (AGGREGATE_TYPE_P (type))
   12477      1743204 :     return !comptypes (type, TYPE_MAIN_VARIANT (value_type));
   12478              : 
   12479              :   return false;
   12480              : }
   12481              : 
   12482              : /* Helper function for process_init_element.  Split first element of
   12483              :    RAW_DATA_CST and save the rest to *RAW_DATA.  */
   12484              : 
   12485              : static inline tree
   12486      9625679 : maybe_split_raw_data (tree value, tree *raw_data)
   12487              : {
   12488      9625679 :   if (value == NULL_TREE || TREE_CODE (value) != RAW_DATA_CST)
   12489              :     return value;
   12490          211 :   *raw_data = value;
   12491          211 :   value = build_int_cst (integer_type_node,
   12492          211 :                          RAW_DATA_UCHAR_ELT (*raw_data, 0));
   12493          211 :   ++RAW_DATA_POINTER (*raw_data);
   12494          211 :   --RAW_DATA_LENGTH (*raw_data);
   12495          211 :   return value;
   12496              : }
   12497              : 
   12498              : /* Return non-zero if c_parser_initval should attempt to optimize
   12499              :    large initializers into RAW_DATA_CST.  In that case return how
   12500              :    many elements to optimize at most.  */
   12501              : 
   12502              : unsigned
   12503      2993171 : c_maybe_optimize_large_byte_initializer (void)
   12504              : {
   12505      2993171 :   if (!constructor_type
   12506      2993101 :       || TREE_CODE (constructor_type) != ARRAY_TYPE
   12507       210206 :       || constructor_stack->implicit)
   12508              :     return 0;
   12509       207441 :   tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
   12510       207441 :   if (TREE_CODE (elttype) != INTEGER_TYPE
   12511       207441 :       && TREE_CODE (elttype) != BITINT_TYPE)
   12512              :     return 0;
   12513       184796 :   if (TYPE_PRECISION (elttype) != CHAR_BIT
   12514        27913 :       || constructor_stack->replacement_value.value
   12515        27913 :       || (COMPLETE_TYPE_P (constructor_type)
   12516        26268 :           && !poly_int_tree_p (TYPE_SIZE (constructor_type)))
   12517       212709 :       || constructor_range_stack)
   12518              :     return 0;
   12519        27913 :   if (constructor_max_index == NULL_TREE)
   12520              :     return INT_MAX;
   12521        26268 :   if (tree_int_cst_le (constructor_max_index, constructor_index)
   12522        26268 :       || integer_all_onesp (constructor_max_index))
   12523         4768 :     return 0;
   12524        21500 :   widest_int w = wi::to_widest (constructor_max_index);
   12525        21500 :   w -= wi::to_widest (constructor_index);
   12526        21500 :   w += 1;
   12527        21500 :   if (w < 64)
   12528              :     return 0;
   12529         6892 :   if (w > INT_MAX)
   12530              :     return INT_MAX;
   12531         6892 :   return w.to_uhwi ();
   12532        21500 : }
   12533              : 
   12534              : /* Add one non-braced element to the current constructor level.
   12535              :    This adjusts the current position within the constructor's type.
   12536              :    This may also start or terminate implicit levels
   12537              :    to handle a partly-braced initializer.
   12538              : 
   12539              :    Once this has found the correct level for the new element,
   12540              :    it calls output_init_element.
   12541              : 
   12542              :    IMPLICIT is true if value comes from pop_init_level (1),
   12543              :    the new initializer has been merged with the existing one
   12544              :    and thus no warnings should be emitted about overriding an
   12545              :    existing initializer.  */
   12546              : 
   12547              : void
   12548      9615975 : process_init_element (location_t loc, struct c_expr value, bool implicit,
   12549              :                       struct obstack * braced_init_obstack)
   12550              : {
   12551      9615975 :   tree orig_value = value.value;
   12552     19231950 :   int string_flag
   12553      9615975 :     = (orig_value != NULL_TREE && TREE_CODE (orig_value) == STRING_CST);
   12554      9615975 :   bool strict_string = value.original_code == STRING_CST;
   12555      9615975 :   bool was_designated = designator_depth != 0;
   12556      9615975 :   tree raw_data = NULL_TREE;
   12557              : 
   12558      9616187 : retry:
   12559      9616187 :   designator_depth = 0;
   12560      9616187 :   designator_erroneous = 0;
   12561              : 
   12562      9616187 :   if (!implicit && value.value && !integer_zerop (value.value))
   12563      7591496 :     constructor_zeroinit = 0;
   12564              : 
   12565              :   /* Handle superfluous braces around string cst as in
   12566              :      char x[] = {"foo"}; */
   12567      9616187 :   if (constructor_type
   12568      9616059 :       && !was_designated
   12569      9579189 :       && TREE_CODE (constructor_type) == ARRAY_TYPE
   12570      1706704 :       && INTEGRAL_TYPE_P (TREE_TYPE (constructor_type))
   12571     10353720 :       && integer_zerop (constructor_unfilled_index))
   12572              :     {
   12573       163367 :       if (constructor_stack->replacement_value.value)
   12574              :         {
   12575            8 :           error_init (loc, "excess elements in %qT initializer", constructor_type);
   12576          409 :           return;
   12577              :         }
   12578       163359 :       else if (string_flag)
   12579              :         {
   12580          138 :           constructor_stack->replacement_value = value;
   12581          138 :           return;
   12582              :         }
   12583              :     }
   12584              : 
   12585      9616041 :   if (constructor_stack->replacement_value.value != NULL_TREE)
   12586              :     {
   12587            0 :       error_init (loc, "excess elements in struct initializer");
   12588            0 :       return;
   12589              :     }
   12590              : 
   12591              :   /* Ignore elements of a brace group if it is entirely superfluous
   12592              :      and has already been diagnosed, or if the type is erroneous.  */
   12593      9616041 :   if (constructor_type == NULL_TREE || constructor_type == error_mark_node)
   12594              :     return;
   12595              : 
   12596              :   /* Ignore elements of an initializer for a variable-size type.
   12597              :      Those are diagnosed in the parser (empty initializer braces are OK).  */
   12598      9615844 :   if (COMPLETE_TYPE_P (constructor_type)
   12599      9615844 :       && !poly_int_tree_p (TYPE_SIZE (constructor_type)))
   12600              :     return;
   12601              : 
   12602      8910463 :   if (!implicit && warn_designated_init && !was_designated
   12603      8875911 :       && TREE_CODE (constructor_type) == RECORD_TYPE
   12604     10650983 :       && lookup_attribute ("designated_init",
   12605      1035197 :                            TYPE_ATTRIBUTES (constructor_type)))
   12606           50 :     warning_init (loc,
   12607              :                   OPT_Wdesignated_init,
   12608              :                   "positional initialization of field "
   12609              :                   "in %<struct%> declared with %<designated_init%> attribute");
   12610              : 
   12611              :   /* If we've exhausted any levels that didn't have braces,
   12612              :      pop them now.  */
   12613     10317765 :   while (constructor_stack->implicit)
   12614              :     {
   12615       708550 :       if (RECORD_OR_UNION_TYPE_P (constructor_type)
   12616       703711 :           && constructor_fields == NULL_TREE)
   12617       701738 :         process_init_element (loc,
   12618              :                               pop_init_level (loc, 1, braced_init_obstack,
   12619              :                                               last_init_list_comma),
   12620              :                               true, braced_init_obstack);
   12621         6812 :       else if ((TREE_CODE (constructor_type) == ARRAY_TYPE
   12622         2617 :                 || gnu_vector_type_p (constructor_type))
   12623         4839 :                && constructor_max_index
   12624        11624 :                && tree_int_cst_lt (constructor_max_index,
   12625              :                                    constructor_index))
   12626          241 :         process_init_element (loc,
   12627              :                               pop_init_level (loc, 1, braced_init_obstack,
   12628              :                                               last_init_list_comma),
   12629              :                               true, braced_init_obstack);
   12630              :       else
   12631              :         break;
   12632              :     }
   12633              : 
   12634              :   /* In the case of [LO ... HI] = VALUE, only evaluate VALUE once.  */
   12635      9615786 :   if (constructor_range_stack)
   12636              :     {
   12637              :       /* If value is a compound literal and we'll be just using its
   12638              :          content, don't put it into a SAVE_EXPR.  */
   12639          371 :       if (TREE_CODE (value.value) != COMPOUND_LITERAL_EXPR
   12640            3 :           || !require_constant_value)
   12641              :         {
   12642          368 :           tree semantic_type = NULL_TREE;
   12643          368 :           if (TREE_CODE (value.value) == EXCESS_PRECISION_EXPR)
   12644              :             {
   12645            0 :               semantic_type = TREE_TYPE (value.value);
   12646            0 :               value.value = TREE_OPERAND (value.value, 0);
   12647              :             }
   12648          368 :           value.value = save_expr (value.value);
   12649          368 :           if (semantic_type)
   12650            0 :             value.value = build1 (EXCESS_PRECISION_EXPR, semantic_type,
   12651              :                                   value.value);
   12652              :         }
   12653              :     }
   12654              : 
   12655     10330030 :   while (1)
   12656              :     {
   12657     10330030 :       if (TREE_CODE (constructor_type) == RECORD_TYPE)
   12658              :         {
   12659      1041311 :           tree fieldtype;
   12660      1041311 :           enum tree_code fieldcode;
   12661              : 
   12662      1041311 :           if (constructor_fields == NULL_TREE)
   12663              :             {
   12664         1280 :               pedwarn_init (loc, 0, "excess elements in struct initializer");
   12665         1280 :               break;
   12666              :             }
   12667              : 
   12668      1040031 :           fieldtype = TREE_TYPE (constructor_fields);
   12669      1040031 :           if (fieldtype != error_mark_node)
   12670      1040030 :             fieldtype = TYPE_MAIN_VARIANT (fieldtype);
   12671      1040031 :           fieldcode = TREE_CODE (fieldtype);
   12672              : 
   12673              :           /* Error for non-static initialization of a flexible array member.  */
   12674      1040031 :           if (fieldcode == ARRAY_TYPE
   12675       156026 :               && !require_constant_value
   12676         1892 :               && TYPE_SIZE (fieldtype) == NULL_TREE
   12677      1040041 :               && DECL_CHAIN (constructor_fields) == NULL_TREE)
   12678              :             {
   12679           10 :               error_init (loc, "non-static initialization of a flexible "
   12680              :                           "array member");
   12681           10 :               break;
   12682              :             }
   12683              : 
   12684              :           /* Error for initialization of a flexible array member with
   12685              :              a string constant if the structure is in an array.  E.g.:
   12686              :              struct S { int x; char y[]; };
   12687              :              struct S s[] = { { 1, "foo" } };
   12688              :              is invalid.  */
   12689      1040021 :           if (string_flag
   12690      1040021 :               && fieldcode == ARRAY_TYPE
   12691         3353 :               && constructor_depth > 1
   12692          489 :               && TYPE_SIZE (fieldtype) == NULL_TREE
   12693      1040068 :               && DECL_CHAIN (constructor_fields) == NULL_TREE)
   12694              :             {
   12695           47 :               bool in_array_p = false;
   12696           47 :               for (struct constructor_stack *p = constructor_stack;
   12697           73 :                    p && p->type; p = p->next)
   12698           59 :                 if (TREE_CODE (p->type) == ARRAY_TYPE)
   12699              :                   {
   12700              :                     in_array_p = true;
   12701              :                     break;
   12702              :                   }
   12703           47 :               if (in_array_p)
   12704              :                 {
   12705           33 :                   error_init (loc, "initialization of flexible array "
   12706              :                               "member in a nested context");
   12707           33 :                   break;
   12708              :                 }
   12709              :             }
   12710              : 
   12711              :           /* Accept a string constant to initialize a subarray.  */
   12712      1039988 :           if (value.value != NULL_TREE
   12713      1039915 :               && fieldcode == ARRAY_TYPE
   12714       155910 :               && INTEGRAL_TYPE_P (TREE_TYPE (fieldtype))
   12715      1194595 :               && string_flag)
   12716              :             value.value = orig_value;
   12717              :           /* Otherwise, if we have come to a subaggregate,
   12718              :              and we don't have an element of its type, push into it.  */
   12719      1036972 :           else if (value.value != NULL_TREE
   12720      1036668 :                    && initialize_elementwise_p (fieldtype, value.value))
   12721              :             {
   12722          304 :               push_init_level (loc, 1, braced_init_obstack);
   12723          304 :               continue;
   12724              :             }
   12725              : 
   12726      1039684 :           value.value = maybe_split_raw_data (value.value, &raw_data);
   12727      1039684 :           if (value.value)
   12728              :             {
   12729      1039611 :               push_member_name (constructor_fields);
   12730      1039611 :               output_init_element (loc, value.value, value.original_type,
   12731              :                                    strict_string, fieldtype,
   12732              :                                    constructor_fields, true, implicit,
   12733              :                                    braced_init_obstack);
   12734      1039611 :               RESTORE_SPELLING_DEPTH (constructor_depth);
   12735              :             }
   12736              :           else
   12737              :             /* Do the bookkeeping for an element that was
   12738              :                directly output as a constructor.  */
   12739              :             {
   12740              :               /* For a record, keep track of end position of last field.  */
   12741           73 :               if (DECL_SIZE (constructor_fields))
   12742           30 :                 constructor_bit_index
   12743           30 :                   = size_binop_loc (input_location, PLUS_EXPR,
   12744              :                                     bit_position (constructor_fields),
   12745           30 :                                     DECL_SIZE (constructor_fields));
   12746              : 
   12747              :               /* If the current field was the first one not yet written out,
   12748              :                  it isn't now, so update.  */
   12749           73 :               if (constructor_unfilled_fields == constructor_fields)
   12750              :                 {
   12751           64 :                   constructor_unfilled_fields = DECL_CHAIN (constructor_fields);
   12752              :                   /* Skip any nameless bit fields.  */
   12753           64 :                   while (constructor_unfilled_fields != 0
   12754           64 :                          && (DECL_UNNAMED_BIT_FIELD
   12755              :                              (constructor_unfilled_fields)))
   12756            0 :                     constructor_unfilled_fields =
   12757            0 :                       DECL_CHAIN (constructor_unfilled_fields);
   12758              :                 }
   12759              :             }
   12760              : 
   12761      1039684 :           constructor_fields = DECL_CHAIN (constructor_fields);
   12762              :           /* Skip any nameless bit fields at the beginning.  */
   12763      1039684 :           while (constructor_fields != NULL_TREE
   12764      1039785 :                  && DECL_UNNAMED_BIT_FIELD (constructor_fields))
   12765          101 :             constructor_fields = DECL_CHAIN (constructor_fields);
   12766              :         }
   12767      9288719 :       else if (TREE_CODE (constructor_type) == UNION_TYPE)
   12768              :         {
   12769        31377 :           tree fieldtype;
   12770        31377 :           enum tree_code fieldcode;
   12771              : 
   12772        31377 :           if (constructor_fields == NULL_TREE)
   12773              :             {
   12774            3 :               pedwarn_init (loc, 0,
   12775              :                             "excess elements in union initializer");
   12776            3 :               break;
   12777              :             }
   12778              : 
   12779        31374 :           fieldtype = TREE_TYPE (constructor_fields);
   12780        31374 :           if (fieldtype != error_mark_node)
   12781        31374 :             fieldtype = TYPE_MAIN_VARIANT (fieldtype);
   12782        31374 :           fieldcode = TREE_CODE (fieldtype);
   12783              : 
   12784              :           /* Warn that traditional C rejects initialization of unions.
   12785              :              We skip the warning if the value is zero.  This is done
   12786              :              under the assumption that the zero initializer in user
   12787              :              code appears conditioned on e.g. __STDC__ to avoid
   12788              :              "missing initializer" warnings and relies on default
   12789              :              initialization to zero in the traditional C case.
   12790              :              We also skip the warning if the initializer is designated,
   12791              :              again on the assumption that this must be conditional on
   12792              :              __STDC__ anyway (and we've already complained about the
   12793              :              member-designator already).  */
   12794        33824 :           if (!in_system_header_at (input_location) && !constructor_designated
   12795        32925 :               && !(value.value && (integer_zerop (value.value)
   12796         1444 :                                    || real_zerop (value.value))))
   12797         1437 :             warning (OPT_Wtraditional, "traditional C rejects initialization "
   12798              :                      "of unions");
   12799              : 
   12800              :           /* Error for non-static initialization of a flexible array member.  */
   12801        31374 :           if (fieldcode == ARRAY_TYPE
   12802          766 :               && !require_constant_value
   12803        31431 :               && TYPE_SIZE (fieldtype) == NULL_TREE)
   12804              :             {
   12805            3 :               error_init (loc, "non-static initialization of a flexible "
   12806              :                           "array member");
   12807            3 :               break;
   12808              :             }
   12809              : 
   12810              :           /* Error for initialization of a flexible array member with
   12811              :              a string constant if the structure is in an array.  E.g.:
   12812              :              union U { int x; char y[]; };
   12813              :              union U s[] = { { 1, "foo" } };
   12814              :              is invalid.  */
   12815        31371 :           if (string_flag
   12816        31371 :               && fieldcode == ARRAY_TYPE
   12817            7 :               && constructor_depth > 1
   12818        31375 :               && TYPE_SIZE (fieldtype) == NULL_TREE)
   12819              :             {
   12820            3 :               bool in_array_p = false;
   12821            3 :               for (struct constructor_stack *p = constructor_stack;
   12822            3 :                    p && p->type; p = p->next)
   12823            3 :                 if (TREE_CODE (p->type) == ARRAY_TYPE)
   12824              :                   {
   12825              :                     in_array_p = true;
   12826              :                     break;
   12827              :                   }
   12828            3 :               if (in_array_p)
   12829              :                 {
   12830            3 :                   error_init (loc, "initialization of flexible array "
   12831              :                               "member in a nested context");
   12832            3 :                   break;
   12833              :                 }
   12834              :             }
   12835              : 
   12836              :           /* Accept a string constant to initialize a subarray.  */
   12837        31368 :           if (value.value != NULL_TREE
   12838        31368 :               && fieldcode == ARRAY_TYPE
   12839          760 :               && INTEGRAL_TYPE_P (TREE_TYPE (fieldtype))
   12840        32123 :               && string_flag)
   12841              :             value.value = orig_value;
   12842              :           /* Otherwise, if we have come to a subaggregate,
   12843              :              and we don't have an element of its type, push into it.  */
   12844        31414 :           else if (value.value != NULL_TREE
   12845        31364 :                    && initialize_elementwise_p (fieldtype, value.value))
   12846              :             {
   12847           50 :               push_init_level (loc, 1, braced_init_obstack);
   12848           50 :               continue;
   12849              :             }
   12850              : 
   12851        31318 :           value.value = maybe_split_raw_data (value.value, &raw_data);
   12852        31318 :           if (value.value)
   12853              :             {
   12854        31318 :               push_member_name (constructor_fields);
   12855        31318 :               output_init_element (loc, value.value, value.original_type,
   12856              :                                    strict_string, fieldtype,
   12857              :                                    constructor_fields, true, implicit,
   12858              :                                    braced_init_obstack);
   12859        31318 :               RESTORE_SPELLING_DEPTH (constructor_depth);
   12860              :             }
   12861              :           else
   12862              :             /* Do the bookkeeping for an element that was
   12863              :                directly output as a constructor.  */
   12864              :             {
   12865            0 :               constructor_bit_index = DECL_SIZE (constructor_fields);
   12866            0 :               constructor_unfilled_fields = DECL_CHAIN (constructor_fields);
   12867              :             }
   12868              : 
   12869        31318 :           constructor_fields = NULL_TREE;
   12870              :         }
   12871      9257342 :       else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   12872              :         {
   12873      2421981 :           tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
   12874      2421981 :           enum tree_code eltcode = TREE_CODE (elttype);
   12875              : 
   12876              :           /* Accept a string constant to initialize a subarray.  */
   12877      2421981 :           if (value.value != NULL_TREE
   12878      2421981 :               && eltcode == ARRAY_TYPE
   12879         7031 :               && INTEGRAL_TYPE_P (TREE_TYPE (elttype))
   12880      2427529 :               && string_flag)
   12881              :             value.value = orig_value;
   12882              :           /* Otherwise, if we have come to a subaggregate,
   12883              :              and we don't have an element of its type, push into it.  */
   12884      3123811 :           else if (value.value != NULL_TREE
   12885      2421485 :                    && initialize_elementwise_p (elttype, value.value))
   12886              :             {
   12887       702326 :               push_init_level (loc, 1, braced_init_obstack);
   12888       702326 :               continue;
   12889              :             }
   12890              : 
   12891      1719655 :           if (constructor_max_index != NULL_TREE
   12892       676764 :               && (tree_int_cst_lt (constructor_max_index, constructor_index)
   12893       676649 :                   || integer_all_onesp (constructor_max_index))
   12894              :               /* For VLA we got an error already.  */
   12895      1719770 :               && !C_TYPE_VARIABLE_SIZE (constructor_type))
   12896              :             {
   12897          113 :               pedwarn_init (loc, 0,
   12898              :                             "excess elements in array initializer");
   12899          113 :               break;
   12900              :             }
   12901              : 
   12902      1719542 :           if (value.value
   12903      1719542 :               && TREE_CODE (value.value) == RAW_DATA_CST
   12904          195 :               && RAW_DATA_LENGTH (value.value) > 1
   12905          195 :               && (TREE_CODE (elttype) == INTEGER_TYPE
   12906          195 :                   || TREE_CODE (elttype) == BITINT_TYPE)
   12907          195 :               && TYPE_PRECISION (elttype) == CHAR_BIT
   12908      1719737 :               && (constructor_max_index == NULL_TREE
   12909           57 :                   || tree_int_cst_lt (constructor_index,
   12910              :                                       constructor_max_index)))
   12911              :             {
   12912          195 :               unsigned int len = RAW_DATA_LENGTH (value.value);
   12913          195 :               if (constructor_max_index)
   12914              :                 {
   12915           57 :                   widest_int w = wi::to_widest (constructor_max_index);
   12916           57 :                   w -= wi::to_widest (constructor_index);
   12917           57 :                   w += 1;
   12918           57 :                   if (w < len)
   12919            3 :                     len = w.to_uhwi ();
   12920           57 :                 }
   12921          195 :               if (len < (unsigned) RAW_DATA_LENGTH (value.value))
   12922              :                 {
   12923            3 :                   raw_data = copy_node (value.value);
   12924            3 :                   RAW_DATA_LENGTH (raw_data) -= len;
   12925            3 :                   RAW_DATA_POINTER (raw_data) += len;
   12926            3 :                   RAW_DATA_LENGTH (value.value) = len;
   12927              :                 }
   12928          195 :               TREE_TYPE (value.value) = elttype;
   12929          195 :               push_array_bounds (tree_to_uhwi (constructor_index));
   12930          195 :               output_init_element (loc, value.value, value.original_type,
   12931              :                                    false, elttype, constructor_index, true,
   12932              :                                    implicit, braced_init_obstack);
   12933          195 :               RESTORE_SPELLING_DEPTH (constructor_depth);
   12934          195 :               constructor_index
   12935          195 :                 = size_binop_loc (input_location, PLUS_EXPR,
   12936          195 :                                   constructor_index, bitsize_int (len));
   12937              :             }
   12938              :           else
   12939              :             {
   12940      1719347 :               value.value = maybe_split_raw_data (value.value, &raw_data);
   12941              :               /* Now output the actual element.  */
   12942      1719347 :               if (value.value)
   12943              :                 {
   12944      1719347 :                   push_array_bounds (tree_to_uhwi (constructor_index));
   12945      1719347 :                   output_init_element (loc, value.value, value.original_type,
   12946              :                                        strict_string, elttype,
   12947              :                                        constructor_index, true, implicit,
   12948              :                                        braced_init_obstack);
   12949      1719347 :                   RESTORE_SPELLING_DEPTH (constructor_depth);
   12950              :                 }
   12951              : 
   12952      1719347 :               constructor_index
   12953      1719347 :                 = size_binop_loc (input_location, PLUS_EXPR,
   12954              :                                   constructor_index, bitsize_one_node);
   12955              : 
   12956      1719347 :               if (!value.value)
   12957              :                 /* If we are doing the bookkeeping for an element that was
   12958              :                    directly output as a constructor, we must update
   12959              :                    constructor_unfilled_index.  */
   12960            0 :                 constructor_unfilled_index = constructor_index;
   12961              :             }
   12962              :         }
   12963      6835361 :       else if (gnu_vector_type_p (constructor_type))
   12964              :         {
   12965      6834869 :           tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
   12966              : 
   12967              :           /* Do a basic check of initializer size.  Note that vectors
   12968              :              may not always have a fixed size derived from their type.  */
   12969      6834869 :           if (maybe_lt (tree_to_poly_uint64 (constructor_max_index),
   12970      6834869 :                         tree_to_poly_uint64 (constructor_index)))
   12971              :             {
   12972              :               /* Diagose VLA out-of-bounds as errors.  */
   12973            2 :               if (tree_to_poly_uint64 (constructor_max_index).is_constant())
   12974            2 :                 pedwarn_init (loc, 0,
   12975              :                               "excess elements in vector initializer");
   12976              :               else
   12977              :                 error_init (loc, "excess elements in vector initializer");
   12978              : 
   12979              :               break;
   12980              :             }
   12981              : 
   12982      6834867 :           value.value = maybe_split_raw_data (value.value, &raw_data);
   12983              :           /* Now output the actual element.  */
   12984      6834867 :           if (value.value)
   12985              :             {
   12986      6834867 :               if (TREE_CODE (value.value) == VECTOR_CST)
   12987            0 :                 elttype = TYPE_MAIN_VARIANT (constructor_type);
   12988      6834867 :               output_init_element (loc, value.value, value.original_type,
   12989              :                                    strict_string, elttype,
   12990              :                                    constructor_index, true, implicit,
   12991              :                                    braced_init_obstack);
   12992              :             }
   12993              : 
   12994      6834867 :           constructor_index
   12995      6834867 :             = size_binop_loc (input_location,
   12996              :                               PLUS_EXPR, constructor_index, bitsize_one_node);
   12997              : 
   12998      6834867 :           if (!value.value)
   12999              :             /* If we are doing the bookkeeping for an element that was
   13000              :                directly output as a constructor, we must update
   13001              :                constructor_unfilled_index.  */
   13002            0 :             constructor_unfilled_index = constructor_index;
   13003              :         }
   13004              : 
   13005              :       /* Handle the sole element allowed in a braced initializer
   13006              :          for a scalar variable.  */
   13007          492 :       else if (constructor_type != error_mark_node
   13008          492 :                && constructor_fields == NULL_TREE)
   13009              :         {
   13010           29 :           pedwarn_init (loc, 0,
   13011              :                         "excess elements in scalar initializer");
   13012           29 :           break;
   13013              :         }
   13014              :       else
   13015              :         {
   13016          463 :           value.value = maybe_split_raw_data (value.value, &raw_data);
   13017          463 :           if (value.value)
   13018          463 :             output_init_element (loc, value.value, value.original_type,
   13019              :                                  strict_string, constructor_type,
   13020              :                                  NULL_TREE, true, implicit,
   13021              :                                  braced_init_obstack);
   13022          463 :           constructor_fields = NULL_TREE;
   13023              :         }
   13024              : 
   13025              :       /* Handle range initializers either at this level or anywhere higher
   13026              :          in the designator stack.  */
   13027      9625874 :       if (constructor_range_stack)
   13028              :         {
   13029        11564 :           struct constructor_range_stack *p, *range_stack;
   13030        11564 :           int finish = 0;
   13031              : 
   13032        11564 :           range_stack = constructor_range_stack;
   13033        11564 :           constructor_range_stack = 0;
   13034        11564 :           while (constructor_stack != range_stack->stack)
   13035              :             {
   13036            0 :               gcc_assert (constructor_stack->implicit);
   13037            0 :               process_init_element (loc,
   13038              :                                     pop_init_level (loc, 1,
   13039              :                                                     braced_init_obstack,
   13040              :                                                     last_init_list_comma),
   13041              :                                     true, braced_init_obstack);
   13042              :             }
   13043          325 :           for (p = range_stack;
   13044        11889 :                !p->range_end || tree_int_cst_equal (p->index, p->range_end);
   13045          325 :                p = p->prev)
   13046              :             {
   13047          325 :               gcc_assert (constructor_stack->implicit);
   13048          325 :               process_init_element (loc,
   13049              :                                     pop_init_level (loc, 1,
   13050              :                                                     braced_init_obstack,
   13051              :                                                     last_init_list_comma),
   13052              :                                     true, braced_init_obstack);
   13053              :             }
   13054              : 
   13055        11564 :           p->index = size_binop_loc (input_location,
   13056              :                                      PLUS_EXPR, p->index, bitsize_one_node);
   13057        11564 :           if (tree_int_cst_equal (p->index, p->range_end) && !p->prev)
   13058          379 :             finish = 1;
   13059              : 
   13060        11889 :           while (1)
   13061              :             {
   13062        11889 :               constructor_index = p->index;
   13063        11889 :               constructor_fields = p->fields;
   13064        11889 :               if (finish && p->range_end && p->index == p->range_start)
   13065              :                 {
   13066            8 :                   finish = 0;
   13067            8 :                   p->prev = 0;
   13068              :                 }
   13069        11889 :               p = p->next;
   13070        11889 :               if (!p)
   13071              :                 break;
   13072          325 :               finish_implicit_inits (loc, braced_init_obstack);
   13073          325 :               push_init_level (loc, 2, braced_init_obstack);
   13074          325 :               p->stack = constructor_stack;
   13075          325 :               if (p->range_end && tree_int_cst_equal (p->index, p->range_end))
   13076           33 :                 p->index = p->range_start;
   13077              :             }
   13078              : 
   13079        11564 :           if (!finish)
   13080        11193 :             constructor_range_stack = range_stack;
   13081        11564 :           continue;
   13082        11564 :         }
   13083              : 
   13084              :       break;
   13085              :     }
   13086              : 
   13087      9615786 :   constructor_range_stack = 0;
   13088              : 
   13089      9615786 :   if (raw_data && RAW_DATA_LENGTH (raw_data))
   13090              :     {
   13091          212 :       gcc_assert (!string_flag && !was_designated);
   13092          212 :       value.value = raw_data;
   13093          212 :       raw_data = NULL_TREE;
   13094          212 :       goto retry;
   13095              :     }
   13096              : }
   13097              : 
   13098              : /* Build a complete asm-statement, whose components are a CV_QUALIFIER
   13099              :    (guaranteed to be 'volatile' or null) and ARGS (represented using
   13100              :    an ASM_EXPR node).  */
   13101              : tree
   13102       205829 : build_asm_stmt (bool is_volatile, tree args)
   13103              : {
   13104       205829 :   if (is_volatile)
   13105       165971 :     ASM_VOLATILE_P (args) = 1;
   13106       205829 :   return add_stmt (args);
   13107              : }
   13108              : 
   13109              : /* Build an asm-expr, whose components are a STRING, some OUTPUTS,
   13110              :    some INPUTS, and some CLOBBERS.  The latter three may be NULL.
   13111              :    SIMPLE indicates whether there was anything at all after the
   13112              :    string in the asm expression -- asm("blah") and asm("blah" : )
   13113              :    are subtly different.  We use a ASM_EXPR node to represent this.
   13114              :    LOC is the location of the asm, and IS_INLINE says whether this
   13115              :    is asm inline.  */
   13116              : tree
   13117       205881 : build_asm_expr (location_t loc, tree string, tree outputs, tree inputs,
   13118              :                 tree clobbers, tree labels, bool simple, bool is_inline)
   13119              : {
   13120       205881 :   tree tail;
   13121       205881 :   tree args;
   13122       205881 :   int i;
   13123       205881 :   const char *constraint;
   13124       205881 :   const char **oconstraints;
   13125       205881 :   bool allows_mem, allows_reg, is_inout;
   13126       205881 :   int ninputs, noutputs;
   13127              : 
   13128       205881 :   ninputs = list_length (inputs);
   13129       205881 :   noutputs = list_length (outputs);
   13130       205881 :   oconstraints = (const char **) alloca (noutputs * sizeof (const char *));
   13131              : 
   13132       205881 :   string = resolve_asm_operand_names (string, outputs, inputs, labels);
   13133              : 
   13134              :   /* Remove output conversions that change the type but not the mode.  */
   13135       557493 :   for (i = 0, tail = outputs; tail; ++i, tail = TREE_CHAIN (tail))
   13136              :     {
   13137       351612 :       tree output = TREE_VALUE (tail);
   13138              : 
   13139       351612 :       output = c_fully_fold (output, false, NULL, true);
   13140              : 
   13141              :       /* ??? Really, this should not be here.  Users should be using a
   13142              :          proper lvalue, dammit.  But there's a long history of using casts
   13143              :          in the output operands.  In cases like longlong.h, this becomes a
   13144              :          primitive form of typechecking -- if the cast can be removed, then
   13145              :          the output operand had a type of the proper width; otherwise we'll
   13146              :          get an error.  Gross, but ...  */
   13147       351612 :       STRIP_NOPS (output);
   13148              : 
   13149       351612 :       if (!lvalue_or_else (loc, output, lv_asm))
   13150            4 :         output = error_mark_node;
   13151              : 
   13152       351612 :       if (output != error_mark_node
   13153       351612 :           && (TREE_READONLY (output)
   13154       351605 :               || TYPE_READONLY (TREE_TYPE (output))
   13155       351605 :               || (RECORD_OR_UNION_TYPE_P (TREE_TYPE (output))
   13156          112 :                   && C_TYPE_FIELDS_READONLY (TREE_TYPE (output)))))
   13157            2 :         readonly_error (loc, output, lv_asm);
   13158              : 
   13159       351612 :       constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail)));
   13160       351612 :       oconstraints[i] = constraint;
   13161              : 
   13162       351612 :       if (parse_output_constraint (&constraint, i, ninputs, noutputs,
   13163              :                                    &allows_mem, &allows_reg, &is_inout,
   13164              :                                    nullptr))
   13165              :         {
   13166              :           /* If the operand is going to end up in memory,
   13167              :              mark it addressable.  */
   13168       351604 :           if (!allows_reg && !c_mark_addressable (output))
   13169            3 :             output = error_mark_node;
   13170         1422 :           if (!(!allows_reg && allows_mem)
   13171       350182 :               && output != error_mark_node
   13172       701784 :               && VOID_TYPE_P (TREE_TYPE (output)))
   13173              :             {
   13174            4 :               error_at (loc, "invalid use of void expression");
   13175            4 :               output = error_mark_node;
   13176              :             }
   13177       351604 :           if (allows_reg && current_function_decl == NULL_TREE)
   13178              :             {
   13179            1 :               error_at (loc, "constraint allows registers outside of "
   13180              :                              "a function");
   13181            1 :               output = error_mark_node;
   13182              :             }
   13183              :         }
   13184              :       else
   13185            8 :         output = error_mark_node;
   13186              : 
   13187       351612 :       if (current_function_decl == NULL_TREE && output != error_mark_node)
   13188              :         {
   13189            7 :           if (TREE_SIDE_EFFECTS (output))
   13190              :             {
   13191            0 :               error_at (loc, "side-effects in output operand outside "
   13192              :                              "of a function");
   13193            0 :               output = error_mark_node;
   13194              :             }
   13195              :           else
   13196              :             {
   13197            7 :               tree addr = build_unary_op (loc, ADDR_EXPR, output, false);
   13198            7 :               if (addr == error_mark_node)
   13199              :                 output = error_mark_node;
   13200            7 :               else if (!initializer_constant_valid_p (addr, TREE_TYPE (addr)))
   13201              :                 {
   13202            1 :                   error_at (loc, "output operand outside of a function is not "
   13203              :                                  "constant");
   13204            1 :                   output = error_mark_node;
   13205              :                 }
   13206              :             }
   13207              :         }
   13208       351605 :       else if (output != error_mark_node && strstr (constraint, "-"))
   13209              :         {
   13210            1 :           error_at (loc, "%<-%> modifier used inside of a function");
   13211            1 :           output = error_mark_node;
   13212              :         }
   13213              : 
   13214       351612 :       TREE_VALUE (tail) = output;
   13215              :     }
   13216              : 
   13217       571616 :   for (i = 0, tail = inputs; tail; ++i, tail = TREE_CHAIN (tail))
   13218              :     {
   13219       365735 :       tree input;
   13220              : 
   13221       365735 :       constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail)));
   13222       365735 :       input = TREE_VALUE (tail);
   13223              : 
   13224       365735 :       if (parse_input_constraint (&constraint, i, ninputs, noutputs, 0,
   13225              :                                   oconstraints, &allows_mem, &allows_reg,
   13226              :                                   nullptr))
   13227              :         {
   13228              :           /* If the operand is going to end up in memory,
   13229              :              mark it addressable.  */
   13230       365727 :           if (!allows_reg && allows_mem)
   13231              :             {
   13232         1401 :               input = c_fully_fold (input, false, NULL, true);
   13233              : 
   13234              :               /* Strip the nops as we allow this case.  FIXME, this really
   13235              :                  should be rejected or made deprecated.  */
   13236         1401 :               STRIP_NOPS (input);
   13237         1401 :               if (!c_mark_addressable (input))
   13238            2 :                 input = error_mark_node;
   13239              :             }
   13240              :           else
   13241              :             {
   13242       364326 :               input = c_fully_fold (convert_lvalue_to_rvalue (loc, input,
   13243              :                                                               true, false),
   13244              :                                     false, NULL);
   13245              : 
   13246       364326 :               if (input != error_mark_node && VOID_TYPE_P (TREE_TYPE (input)))
   13247              :                 {
   13248            4 :                   error_at (loc, "invalid use of void expression");
   13249            4 :                   input = error_mark_node;
   13250              :                 }
   13251              :             }
   13252       365727 :           if (allows_reg && current_function_decl == NULL_TREE)
   13253              :             {
   13254            1 :               error_at (loc, "constraint allows registers outside of "
   13255              :                              "a function");
   13256            1 :               input = error_mark_node;
   13257              :             }
   13258       365727 :           if (constraint[0] == ':' && input != error_mark_node)
   13259              :             {
   13260           35 :               tree t = input;
   13261           35 :               STRIP_NOPS (t);
   13262           35 :               if (TREE_CODE (t) != ADDR_EXPR
   13263           35 :                   || !(TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
   13264           23 :                        || (VAR_P (TREE_OPERAND (t, 0))
   13265           21 :                            && is_global_var (TREE_OPERAND (t, 0)))))
   13266              :                 {
   13267            5 :                   error_at (loc, "%<:%> constraint operand is not address "
   13268              :                                  "of a function or non-automatic variable");
   13269            5 :                   input = error_mark_node;
   13270              :                 }
   13271           30 :               else if (TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL)
   13272           10 :                 suppress_warning (TREE_OPERAND (t, 0), OPT_Wunused);
   13273              :             }
   13274              :         }
   13275              :       else
   13276            8 :         input = error_mark_node;
   13277              : 
   13278       365735 :       if (current_function_decl == NULL_TREE && input != error_mark_node)
   13279              :         {
   13280           58 :           if (TREE_SIDE_EFFECTS (input))
   13281              :             {
   13282            2 :               error_at (loc, "side-effects in input operand outside "
   13283              :                              "of a function");
   13284            2 :               input = error_mark_node;
   13285              :             }
   13286              :           else
   13287              :             {
   13288           56 :               tree tem = input;
   13289           56 :               if (allows_mem && lvalue_p (input))
   13290            7 :                 tem = build_unary_op (loc, ADDR_EXPR, input, false);
   13291           56 :               if (!initializer_constant_valid_p (tem, TREE_TYPE (tem)))
   13292              :                 {
   13293            2 :                   error_at (loc, "input operand outside of a function is not "
   13294              :                                  "constant");
   13295            2 :                   input = error_mark_node;
   13296              :                 }
   13297              :             }
   13298              :         }
   13299       365677 :       else if (input != error_mark_node && strstr (constraint, "-"))
   13300              :         {
   13301            3 :           error_at (loc, "%<-%> modifier used inside of a function");
   13302            3 :           input = error_mark_node;
   13303              :         }
   13304              : 
   13305       365735 :       TREE_VALUE (tail) = input;
   13306              :     }
   13307              : 
   13308       205881 :   args = build_stmt (loc, ASM_EXPR, string, outputs, inputs, clobbers, labels);
   13309              : 
   13310              :   /* asm statements without outputs, including simple ones, are treated
   13311              :      as volatile.  */
   13312       205881 :   ASM_BASIC_P (args) = simple;
   13313       205881 :   ASM_VOLATILE_P (args) = (noutputs == 0);
   13314       205881 :   ASM_INLINE_P (args) = is_inline;
   13315              : 
   13316       205881 :   return args;
   13317              : }
   13318              : 
   13319              : /* Generate a goto statement to LABEL.  LOC is the location of the
   13320              :    GOTO.  */
   13321              : 
   13322              : tree
   13323        83042 : c_finish_goto_label (location_t loc, tree label)
   13324              : {
   13325        83042 :   tree decl = lookup_label_for_goto (loc, label);
   13326        83042 :   if (!decl)
   13327              :     return NULL_TREE;
   13328        83042 :   TREE_USED (decl) = 1;
   13329        83042 :   mark_decl_used (decl, false);
   13330        83042 :   {
   13331        83042 :     add_stmt (build_predict_expr (PRED_GOTO, NOT_TAKEN));
   13332        83042 :     tree t = build1 (GOTO_EXPR, void_type_node, decl);
   13333        83042 :     SET_EXPR_LOCATION (t, loc);
   13334        83042 :     return add_stmt (t);
   13335              :   }
   13336              : }
   13337              : 
   13338              : /* Generate a computed goto statement to EXPR.  LOC is the location of
   13339              :    the GOTO.  */
   13340              : 
   13341              : tree
   13342          949 : c_finish_goto_ptr (location_t loc, c_expr val)
   13343              : {
   13344          949 :   tree expr = val.value;
   13345          949 :   tree t;
   13346          949 :   pedwarn (loc, OPT_Wpedantic, "ISO C forbids %<goto *expr;%>");
   13347          949 :   if (expr != error_mark_node
   13348          948 :       && !POINTER_TYPE_P (TREE_TYPE (expr))
   13349          954 :       && !null_pointer_constant_p (expr))
   13350              :     {
   13351            2 :       error_at (val.get_location (),
   13352              :                 "computed goto must be pointer type");
   13353            2 :       expr = build_zero_cst (ptr_type_node);
   13354              :     }
   13355          949 :   expr = c_fully_fold (expr, false, NULL);
   13356          949 :   expr = convert (ptr_type_node, expr);
   13357          949 :   t = build1 (GOTO_EXPR, void_type_node, expr);
   13358          949 :   SET_EXPR_LOCATION (t, loc);
   13359          949 :   return add_stmt (t);
   13360              : }
   13361              : 
   13362              : /* Generate a C `return' statement.  RETVAL is the expression for what
   13363              :    to return, or a null pointer for `return;' with no value.  LOC is
   13364              :    the location of the return statement, or the location of the expression,
   13365              :    if the statement has any.  If ORIGTYPE is not NULL_TREE, it
   13366              :    is the original type of RETVAL.  MUSTTAIL_P indicates a musttail
   13367              :    attribute.  */
   13368              : 
   13369              : tree
   13370     34660630 : c_finish_return (location_t loc, tree retval, tree origtype, bool musttail_p)
   13371              : {
   13372     34660630 :   tree valtype = TREE_TYPE (TREE_TYPE (current_function_decl)), ret_stmt;
   13373     34660630 :   bool no_warning = false;
   13374     34660630 :   bool npc = false;
   13375              : 
   13376              :   /* Use the expansion point to handle cases such as returning NULL
   13377              :      in a function returning void.  */
   13378     34660630 :   location_t xloc = expansion_point_location_if_in_system_header (loc);
   13379              : 
   13380     34660630 :   if (TREE_THIS_VOLATILE (current_function_decl))
   13381           23 :     warning_at (xloc, 0,
   13382              :                 "function declared %<noreturn%> has a %<return%> statement");
   13383              : 
   13384     34660630 :   set_musttail_on_return (retval, xloc, musttail_p);
   13385              : 
   13386     34660630 :   if (retval)
   13387              :     {
   13388     34639101 :       tree semantic_type = NULL_TREE;
   13389     34639101 :       npc = null_pointer_constant_p (retval);
   13390     34639101 :       if (TREE_CODE (retval) == EXCESS_PRECISION_EXPR)
   13391              :         {
   13392           92 :           semantic_type = TREE_TYPE (retval);
   13393           92 :           retval = TREE_OPERAND (retval, 0);
   13394              :         }
   13395     34639101 :       retval = c_fully_fold (retval, false, NULL);
   13396     34639101 :       if (semantic_type
   13397     34639101 :           && valtype != NULL_TREE
   13398           92 :           && TREE_CODE (valtype) != VOID_TYPE)
   13399           92 :         retval = build1 (EXCESS_PRECISION_EXPR, semantic_type, retval);
   13400              :     }
   13401              : 
   13402     34639101 :   if (!retval)
   13403              :     {
   13404        21529 :       current_function_returns_null = 1;
   13405        21529 :       if ((warn_return_type >= 0 || flag_isoc99)
   13406        21404 :           && valtype != NULL_TREE && TREE_CODE (valtype) != VOID_TYPE)
   13407              :         {
   13408           46 :           no_warning = true;
   13409           47 :           if (emit_diagnostic (flag_isoc99
   13410              :                                ? diagnostics::kind::permerror
   13411              :                                : diagnostics::kind::warning,
   13412           46 :                                loc, OPT_Wreturn_mismatch,
   13413              :                                "%<return%> with no value,"
   13414              :                                " in function returning non-void"))
   13415           27 :             inform (DECL_SOURCE_LOCATION (current_function_decl),
   13416              :                     "declared here");
   13417              :         }
   13418              :     }
   13419     34639101 :   else if (valtype == NULL_TREE || VOID_TYPE_P (valtype))
   13420              :     {
   13421          326 :       current_function_returns_null = 1;
   13422          326 :       bool warned_here;
   13423          326 :       if (TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
   13424           64 :         warned_here = permerror_opt
   13425           64 :           (xloc, OPT_Wreturn_mismatch,
   13426              :            "%<return%> with a value, in function returning void");
   13427              :       else
   13428          262 :         warned_here = pedwarn
   13429          262 :           (xloc, OPT_Wpedantic, "ISO C forbids "
   13430              :            "%<return%> with expression, in function returning void");
   13431          326 :       if (warned_here)
   13432           43 :         inform (DECL_SOURCE_LOCATION (current_function_decl),
   13433              :                 "declared here");
   13434              :     }
   13435              :   else
   13436              :     {
   13437     34638775 :       tree t = convert_for_assignment (loc, UNKNOWN_LOCATION, valtype,
   13438              :                                        retval, origtype, ic_return,
   13439              :                                        npc, NULL_TREE, NULL_TREE, 0);
   13440     34638775 :       tree res = DECL_RESULT (current_function_decl);
   13441     34638775 :       tree inner;
   13442     34638775 :       bool save;
   13443              : 
   13444     34638775 :       current_function_returns_value = 1;
   13445     34638775 :       if (t == error_mark_node)
   13446              :         {
   13447              :           /* Suppress -Wreturn-type for this function.  */
   13448          299 :           if (warn_return_type)
   13449          298 :             suppress_warning (current_function_decl, OPT_Wreturn_type);
   13450          299 :           return NULL_TREE;
   13451              :         }
   13452              : 
   13453     34638476 :       save = in_late_binary_op;
   13454     69268725 :       if (C_BOOLEAN_TYPE_P (TREE_TYPE (res))
   13455     34629444 :           || TREE_CODE (TREE_TYPE (res)) == COMPLEX_TYPE
   13456     69266640 :           || (SCALAR_FLOAT_TYPE_P (TREE_TYPE (t))
   13457       333437 :               && (TREE_CODE (TREE_TYPE (res)) == INTEGER_TYPE
   13458       333437 :                   || TREE_CODE (TREE_TYPE (res)) == ENUMERAL_TYPE)
   13459            0 :               && sanitize_flags_p (SANITIZE_FLOAT_CAST)))
   13460        10312 :         in_late_binary_op = true;
   13461     34638476 :       inner = t = convert (TREE_TYPE (res), t);
   13462     34638476 :       in_late_binary_op = save;
   13463              : 
   13464              :       /* Strip any conversions, additions, and subtractions, and see if
   13465              :          we are returning the address of a local variable.  Warn if so.  */
   13466     37916973 :       while (1)
   13467              :         {
   13468     37916973 :           switch (TREE_CODE (inner))
   13469              :             {
   13470      3277069 :             CASE_CONVERT:
   13471      3277069 :             case NON_LVALUE_EXPR:
   13472      3277069 :             case PLUS_EXPR:
   13473      3277069 :             case POINTER_PLUS_EXPR:
   13474      3277069 :               inner = TREE_OPERAND (inner, 0);
   13475      3277069 :               continue;
   13476              : 
   13477         1433 :             case MINUS_EXPR:
   13478              :               /* If the second operand of the MINUS_EXPR has a pointer
   13479              :                  type (or is converted from it), this may be valid, so
   13480              :                  don't give a warning.  */
   13481         1433 :               {
   13482         1433 :                 tree op1 = TREE_OPERAND (inner, 1);
   13483              : 
   13484         3115 :                 while (!POINTER_TYPE_P (TREE_TYPE (op1))
   13485         3369 :                        && (CONVERT_EXPR_P (op1)
   13486         1428 :                            || TREE_CODE (op1) == NON_LVALUE_EXPR))
   13487          254 :                   op1 = TREE_OPERAND (op1, 0);
   13488              : 
   13489         1433 :                 if (POINTER_TYPE_P (TREE_TYPE (op1)))
   13490              :                   break;
   13491              : 
   13492         1428 :                 inner = TREE_OPERAND (inner, 0);
   13493         1428 :                 continue;
   13494         1428 :               }
   13495              : 
   13496         2950 :             case ADDR_EXPR:
   13497         2950 :               inner = TREE_OPERAND (inner, 0);
   13498              : 
   13499         2950 :               while (REFERENCE_CLASS_P (inner)
   13500         3840 :                      && !INDIRECT_REF_P (inner))
   13501          890 :                 inner = TREE_OPERAND (inner, 0);
   13502              : 
   13503         2950 :               if (DECL_P (inner)
   13504         1623 :                   && !DECL_EXTERNAL (inner)
   13505          978 :                   && DECL_CONTEXT (inner) == current_function_decl
   13506         3172 :                   && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (current_function_decl))))
   13507              :                 {
   13508          182 :                   if (TREE_CODE (inner) == LABEL_DECL)
   13509            4 :                     warning_at (loc, OPT_Wreturn_local_addr,
   13510              :                                 "function returns address of label");
   13511          178 :                   else if (TREE_CODE (inner) == FUNCTION_DECL
   13512          178 :                            && (C_FUNC_NONLOCAL_CONTEXT (inner)
   13513            9 :                                || !DECL_INITIAL (inner)))
   13514           14 :                     warning_at (loc, OPT_Wreturn_local_addr,
   13515              :                                 "function returns address of nested function "
   13516              :                                 "referencing local context");
   13517          164 :                   else if (TREE_CODE (inner) != FUNCTION_DECL
   13518          156 :                            && !TREE_STATIC (inner))
   13519              :                     {
   13520            9 :                       warning_at (loc, OPT_Wreturn_local_addr,
   13521              :                                   "function returns address of local variable");
   13522            9 :                       tree zero = build_zero_cst (TREE_TYPE (res));
   13523            9 :                       t = build2 (COMPOUND_EXPR, TREE_TYPE (res), t, zero);
   13524              :                     }
   13525              :                 }
   13526              :               break;
   13527              : 
   13528              :             default:
   13529              :               break;
   13530      3277069 :             }
   13531              : 
   13532     34638476 :           break;
   13533              :         }
   13534              : 
   13535     34638476 :       retval = build2 (MODIFY_EXPR, TREE_TYPE (res), res, t);
   13536     34638476 :       SET_EXPR_LOCATION (retval, loc);
   13537              : 
   13538     34638476 :       if (warn_sequence_point)
   13539      2966221 :         verify_sequence_points (retval);
   13540              :     }
   13541              : 
   13542     34660331 :   ret_stmt = build_stmt (loc, RETURN_EXPR, retval);
   13543     34660331 :   if (no_warning)
   13544           46 :     suppress_warning (ret_stmt, OPT_Wreturn_type);
   13545     34660331 :   return add_stmt (ret_stmt);
   13546              : }
   13547              : 
   13548              : struct c_switch {
   13549              :   /* The SWITCH_STMT being built.  */
   13550              :   tree switch_stmt;
   13551              : 
   13552              :   /* The original type of the testing expression, i.e. before the
   13553              :      default conversion is applied.  */
   13554              :   tree orig_type;
   13555              : 
   13556              :   /* A splay-tree mapping the low element of a case range to the high
   13557              :      element, or NULL_TREE if there is no high element.  Used to
   13558              :      determine whether or not a new case label duplicates an old case
   13559              :      label.  We need a tree, rather than simply a hash table, because
   13560              :      of the GNU case range extension.  */
   13561              :   splay_tree cases;
   13562              : 
   13563              :   /* The bindings at the point of the switch.  This is used for
   13564              :      warnings crossing decls when branching to a case label.  */
   13565              :   struct c_spot_bindings *bindings;
   13566              : 
   13567              :   /* Whether the switch includes any break statements.  */
   13568              :   bool break_stmt_seen_p;
   13569              : 
   13570              :   /* The next node on the stack.  */
   13571              :   struct c_switch *next;
   13572              : 
   13573              :   /* Remember whether the controlling expression had boolean type
   13574              :      before integer promotions for the sake of -Wswitch-bool.  */
   13575              :   bool bool_cond_p;
   13576              : };
   13577              : 
   13578              : /* A stack of the currently active switch statements.  The innermost
   13579              :    switch statement is on the top of the stack.  There is no need to
   13580              :    mark the stack for garbage collection because it is only active
   13581              :    during the processing of the body of a function, and we never
   13582              :    collect at that point.  */
   13583              : 
   13584              : struct c_switch *c_switch_stack;
   13585              : 
   13586              : /* Start a C switch statement, testing expression EXP.  Return the new
   13587              :    SWITCH_STMT.  SWITCH_LOC is the location of the `switch'.
   13588              :    SWITCH_COND_LOC is the location of the switch's condition.
   13589              :    EXPLICIT_CAST_P is true if the expression EXP has an explicit cast.  */
   13590              : 
   13591              : tree
   13592        37460 : c_start_switch (location_t switch_loc,
   13593              :                 location_t switch_cond_loc,
   13594              :                 tree exp, bool explicit_cast_p, tree switch_name)
   13595              : {
   13596        37460 :   tree orig_type = error_mark_node;
   13597        37460 :   bool bool_cond_p = false;
   13598        37460 :   struct c_switch *cs;
   13599              : 
   13600        37460 :   if (exp != error_mark_node)
   13601              :     {
   13602        37417 :       orig_type = TREE_TYPE (exp);
   13603              : 
   13604        37417 :       if (!INTEGRAL_TYPE_P (orig_type))
   13605              :         {
   13606           12 :           if (orig_type != error_mark_node)
   13607              :             {
   13608           12 :               error_at (switch_cond_loc, "switch quantity not an integer");
   13609           12 :               orig_type = error_mark_node;
   13610              :             }
   13611           12 :           exp = integer_zero_node;
   13612              :         }
   13613              :       else
   13614              :         {
   13615        37405 :           tree type = TYPE_MAIN_VARIANT (orig_type);
   13616        37405 :           tree e = exp;
   13617              : 
   13618              :           /* Warn if the condition has boolean value.  */
   13619        37408 :           while (TREE_CODE (e) == COMPOUND_EXPR)
   13620            3 :             e = TREE_OPERAND (e, 1);
   13621              : 
   13622        37380 :           if ((C_BOOLEAN_TYPE_P (type)
   13623        37380 :                || truth_value_p (TREE_CODE (e)))
   13624              :               /* Explicit cast to int suppresses this warning.  */
   13625        37427 :               && !(TREE_CODE (type) == INTEGER_TYPE
   13626              :                    && explicit_cast_p))
   13627              :             bool_cond_p = true;
   13628              : 
   13629        37405 :           if (!in_system_header_at (input_location)
   13630        37405 :               && (type == long_integer_type_node
   13631        12085 :                   || type == long_unsigned_type_node))
   13632          290 :             warning_at (switch_cond_loc,
   13633          290 :                         OPT_Wtraditional, "%<long%> switch expression not "
   13634              :                         "converted to %<int%> in ISO C");
   13635              : 
   13636        37405 :           exp = c_fully_fold (exp, false, NULL);
   13637        37405 :           exp = default_conversion (exp);
   13638              : 
   13639        37405 :           if (warn_sequence_point)
   13640         6038 :             verify_sequence_points (exp);
   13641              :         }
   13642              :     }
   13643              : 
   13644              :   /* Add this new SWITCH_STMT to the stack.  */
   13645        37460 :   cs = XNEW (struct c_switch);
   13646        37460 :   cs->switch_stmt = build_stmt (switch_loc, SWITCH_STMT, exp,
   13647              :                                 NULL_TREE, orig_type, NULL_TREE, switch_name);
   13648        37460 :   cs->orig_type = orig_type;
   13649        37460 :   cs->cases = splay_tree_new (case_compare, NULL, NULL);
   13650        37460 :   cs->bindings = c_get_switch_bindings ();
   13651        37460 :   cs->break_stmt_seen_p = false;
   13652        37460 :   cs->bool_cond_p = bool_cond_p;
   13653        37460 :   cs->next = c_switch_stack;
   13654        37460 :   c_switch_stack = cs;
   13655              : 
   13656        37460 :   return add_stmt (cs->switch_stmt);
   13657              : }
   13658              : 
   13659              : /* Process a case label at location LOC, with attributes ATTRS.  */
   13660              : 
   13661              : tree
   13662      1031058 : do_case (location_t loc, tree low_value, tree high_value, tree attrs)
   13663              : {
   13664      1031058 :   tree label = NULL_TREE;
   13665              : 
   13666      1031058 :   if (low_value && TREE_CODE (low_value) != INTEGER_CST)
   13667              :     {
   13668           87 :       low_value = c_fully_fold (low_value, false, NULL);
   13669           87 :       if (TREE_CODE (low_value) == INTEGER_CST)
   13670            9 :         pedwarn (loc, OPT_Wpedantic,
   13671              :                  "case label is not an integer constant expression");
   13672              :     }
   13673              : 
   13674      1031058 :   if (high_value && TREE_CODE (high_value) != INTEGER_CST)
   13675              :     {
   13676            0 :       high_value = c_fully_fold (high_value, false, NULL);
   13677            0 :       if (TREE_CODE (high_value) == INTEGER_CST)
   13678            0 :         pedwarn (input_location, OPT_Wpedantic,
   13679              :                  "case label is not an integer constant expression");
   13680              :     }
   13681              : 
   13682      1031058 :   if (c_switch_stack == NULL)
   13683              :     {
   13684            3 :       if (low_value)
   13685            2 :         error_at (loc, "case label not within a switch statement");
   13686              :       else
   13687            1 :         error_at (loc, "%<default%> label not within a switch statement");
   13688            3 :       return NULL_TREE;
   13689              :     }
   13690              : 
   13691      1031055 :   if (c_check_switch_jump_warnings (c_switch_stack->bindings,
   13692      1031055 :                                     EXPR_LOCATION (c_switch_stack->switch_stmt),
   13693              :                                     loc))
   13694              :     return NULL_TREE;
   13695              : 
   13696      1031043 :   label = c_add_case_label (loc, c_switch_stack->cases,
   13697      1031043 :                             SWITCH_STMT_COND (c_switch_stack->switch_stmt),
   13698              :                             low_value, high_value, attrs);
   13699      1031043 :   if (label == error_mark_node)
   13700          144 :     label = NULL_TREE;
   13701              :   return label;
   13702              : }
   13703              : 
   13704              : /* Finish the switch statement.  TYPE is the original type of the
   13705              :    controlling expression of the switch, or NULL_TREE.  */
   13706              : 
   13707              : void
   13708        37460 : c_finish_switch (tree body, tree type)
   13709              : {
   13710        37460 :   struct c_switch *cs = c_switch_stack;
   13711        37460 :   location_t switch_location;
   13712              : 
   13713        37460 :   SWITCH_STMT_BODY (cs->switch_stmt) = body;
   13714              : 
   13715              :   /* Emit warnings as needed.  */
   13716        37460 :   switch_location = EXPR_LOCATION (cs->switch_stmt);
   13717        43668 :   c_do_switch_warnings (cs->cases, switch_location,
   13718         6208 :                         type ? type : SWITCH_STMT_TYPE (cs->switch_stmt),
   13719        37460 :                         SWITCH_STMT_COND (cs->switch_stmt), cs->bool_cond_p);
   13720        37460 :   if (c_switch_covers_all_cases_p (cs->cases,
   13721        37460 :                                    SWITCH_STMT_TYPE (cs->switch_stmt)))
   13722        33529 :     SWITCH_STMT_ALL_CASES_P (cs->switch_stmt) = 1;
   13723        37460 :   SWITCH_STMT_NO_BREAK_P (cs->switch_stmt) = !cs->break_stmt_seen_p;
   13724              : 
   13725              :   /* Pop the stack.  */
   13726        37460 :   c_switch_stack = cs->next;
   13727        37460 :   splay_tree_delete (cs->cases);
   13728        37460 :   c_release_switch_bindings (cs->bindings);
   13729        37460 :   XDELETE (cs);
   13730        37460 : }
   13731              : 
   13732              : /* Emit an if statement.  IF_LOCUS is the location of the 'if'.  COND,
   13733              :    THEN_BLOCK and ELSE_BLOCK are expressions to be used; ELSE_BLOCK
   13734              :    may be null.  */
   13735              : 
   13736              : void
   13737      1274609 : c_finish_if_stmt (location_t if_locus, tree cond, tree then_block,
   13738              :                   tree else_block)
   13739              : {
   13740      1274609 :   tree stmt;
   13741              : 
   13742      1274609 :   stmt = build3 (COND_EXPR, void_type_node, cond, then_block, else_block);
   13743      1274609 :   SET_EXPR_LOCATION (stmt, if_locus);
   13744      1274609 :   add_stmt (stmt);
   13745      1274609 : }
   13746              : 
   13747              : tree
   13748       187863 : c_finish_bc_stmt (location_t loc, tree label, bool is_break, tree name)
   13749              : {
   13750              :   /* In switch statements break is sometimes stylistically used after
   13751              :      a return statement.  This can lead to spurious warnings about
   13752              :      control reaching the end of a non-void function when it is
   13753              :      inlined.  Note that we are calling block_may_fallthru with
   13754              :      language specific tree nodes; this works because
   13755              :      block_may_fallthru returns true when given something it does not
   13756              :      understand.  */
   13757       187863 :   bool skip = !block_may_fallthru (cur_stmt_list);
   13758              : 
   13759       187863 :   if (is_break)
   13760       174680 :     switch (in_statement & ~IN_NAMED_STMT)
   13761              :       {
   13762            9 :       case 0:
   13763            9 :         error_at (loc, "break statement not within loop or switch");
   13764            9 :         return NULL_TREE;
   13765            4 :       case IN_OMP_BLOCK:
   13766            4 :         error_at (loc, "invalid exit from OpenMP structured block");
   13767            4 :         return NULL_TREE;
   13768           12 :       case IN_OMP_FOR:
   13769           12 :         error_at (loc, "break statement used with OpenMP for loop");
   13770           12 :         return NULL_TREE;
   13771              :       case IN_ITERATION_STMT:
   13772              :       case IN_OBJC_FOREACH:
   13773              :         break;
   13774       158755 :       default:
   13775       158755 :         gcc_assert (in_statement & IN_SWITCH_STMT);
   13776       158755 :         c_switch_stack->break_stmt_seen_p = true;
   13777       158755 :         break;
   13778              :       }
   13779              :   else
   13780        13183 :     switch (in_statement & ~(IN_SWITCH_STMT | IN_NAMED_STMT))
   13781              :       {
   13782            7 :       case 0:
   13783            7 :         error_at (loc, "continue statement not within a loop");
   13784            7 :         return NULL_TREE;
   13785            4 :       case IN_OMP_BLOCK:
   13786            4 :         error_at (loc, "invalid exit from OpenMP structured block");
   13787            4 :         return NULL_TREE;
   13788              :       case IN_ITERATION_STMT:
   13789              :       case IN_OMP_FOR:
   13790              :       case IN_OBJC_FOREACH:
   13791              :         break;
   13792            0 :       default:
   13793            0 :         gcc_unreachable ();
   13794              :       }
   13795              : 
   13796       187827 :   if (skip)
   13797              :     return NULL_TREE;
   13798       187327 :   else if ((in_statement & IN_OBJC_FOREACH)
   13799            0 :            && !(is_break && (in_statement & IN_SWITCH_STMT))
   13800            0 :            && name == NULL_TREE)
   13801              :     {
   13802              :       /* The foreach expander produces low-level code using gotos instead
   13803              :          of a structured loop construct.  */
   13804            0 :       gcc_assert (label);
   13805            0 :       return add_stmt (build_stmt (loc, GOTO_EXPR, label));
   13806              :     }
   13807       187424 :   else if (name && C_DECL_LOOP_NAME (name) && C_DECL_SWITCH_NAME (name))
   13808              :     {
   13809            0 :       label = DECL_CHAIN (name);
   13810            0 :       if (!is_break)
   13811            0 :         label = DECL_CHAIN (label);
   13812              :       /* Foreach expander from some outer level.  */
   13813            0 :       return add_stmt (build_stmt (loc, GOTO_EXPR, label));
   13814              :     }
   13815       200499 :   return add_stmt (build_stmt (loc, is_break ? BREAK_STMT : CONTINUE_STMT,
   13816       187327 :                                name));
   13817              : }
   13818              : 
   13819              : /* A helper routine for c_process_expr_stmt and c_finish_stmt_expr.  */
   13820              : 
   13821              : static void
   13822      6376584 : emit_side_effect_warnings (location_t loc, tree expr)
   13823              : {
   13824      6376584 :   maybe_warn_nodiscard (loc, expr);
   13825      6376584 :   if (!warn_unused_value)
   13826              :     return;
   13827      1303758 :   if (expr == error_mark_node)
   13828              :     ;
   13829      1303683 :   else if (!TREE_SIDE_EFFECTS (expr))
   13830              :     {
   13831         6544 :       if (!VOID_TYPE_P (TREE_TYPE (expr))
   13832         6544 :           && !warning_suppressed_p (expr, OPT_Wunused_value))
   13833           28 :         warning_at (loc, OPT_Wunused_value, "statement with no effect");
   13834              :     }
   13835      1297139 :   else if (TREE_CODE (expr) == COMPOUND_EXPR)
   13836              :     {
   13837              :       tree r = expr;
   13838              :       location_t cloc = loc;
   13839        11987 :       while (TREE_CODE (r) == COMPOUND_EXPR)
   13840              :         {
   13841         6009 :           if (EXPR_HAS_LOCATION (r))
   13842         5479 :             cloc = EXPR_LOCATION (r);
   13843         6009 :           r = TREE_OPERAND (r, 1);
   13844              :         }
   13845         5978 :       if (!TREE_SIDE_EFFECTS (r)
   13846           33 :           && !VOID_TYPE_P (TREE_TYPE (r))
   13847           24 :           && !CONVERT_EXPR_P (r)
   13848           24 :           && !warning_suppressed_p (r, OPT_Wunused_value)
   13849         5990 :           && !warning_suppressed_p (expr, OPT_Wunused_value))
   13850            8 :         warning_at (cloc, OPT_Wunused_value,
   13851              :                     "right-hand operand of comma expression has no effect");
   13852              :     }
   13853              :   else
   13854      1291161 :     warn_if_unused_value (expr, loc);
   13855              : }
   13856              : 
   13857              : /* Process an expression as if it were a complete statement.  Emit
   13858              :    diagnostics, but do not call ADD_STMT.  LOC is the location of the
   13859              :    statement.  */
   13860              : 
   13861              : tree
   13862      6253144 : c_process_expr_stmt (location_t loc, tree expr)
   13863              : {
   13864      6253144 :   tree exprv;
   13865              : 
   13866      6253144 :   if (!expr)
   13867              :     return NULL_TREE;
   13868              : 
   13869      6248764 :   expr = c_fully_fold (expr, false, NULL);
   13870              : 
   13871      6248764 :   if (warn_sequence_point)
   13872      1299466 :     verify_sequence_points (expr);
   13873              : 
   13874      6248764 :   if (TREE_TYPE (expr) != error_mark_node
   13875      6246110 :       && !COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (expr))
   13876      6248764 :       && TREE_CODE (TREE_TYPE (expr)) != ARRAY_TYPE)
   13877            0 :     error_at (loc, "expression statement has incomplete type");
   13878              : 
   13879              :   /* If we're not processing a statement expression, warn about unused values.
   13880              :      Warnings for statement expressions will be emitted later, once we figure
   13881              :      out which is the result.  */
   13882      6248764 :   if (!STATEMENT_LIST_STMT_EXPR (cur_stmt_list)
   13883      6248764 :       && (warn_unused_value || warn_unused_result))
   13884      6162850 :     emit_side_effect_warnings (EXPR_LOC_OR_LOC (expr, loc), expr);
   13885              : 
   13886              :   exprv = expr;
   13887      6287635 :   while (TREE_CODE (exprv) == COMPOUND_EXPR)
   13888        38872 :     exprv = TREE_OPERAND (exprv, 1);
   13889      6260234 :   while (CONVERT_EXPR_P (exprv))
   13890        11471 :     exprv = TREE_OPERAND (exprv, 0);
   13891      6248763 :   if (DECL_P (exprv)
   13892      6249349 :       || handled_component_p (exprv)
   13893     12477680 :       || TREE_CODE (exprv) == ADDR_EXPR)
   13894        20432 :     mark_exp_read (exprv);
   13895              : 
   13896              :   /* If the expression is not of a type to which we cannot assign a line
   13897              :      number, wrap the thing in a no-op NOP_EXPR.  */
   13898      6248763 :   if (DECL_P (expr) || CONSTANT_CLASS_P (expr))
   13899              :     {
   13900        14889 :       expr = build1 (NOP_EXPR, TREE_TYPE (expr), expr);
   13901        14889 :       SET_EXPR_LOCATION (expr, loc);
   13902              :     }
   13903              : 
   13904              :   return expr;
   13905              : }
   13906              : 
   13907              : /* Emit an expression as a statement.  LOC is the location of the
   13908              :    expression.  */
   13909              : 
   13910              : tree
   13911      5952445 : c_finish_expr_stmt (location_t loc, tree expr)
   13912              : {
   13913      5952445 :   if (expr)
   13914      5939823 :     return add_stmt (c_process_expr_stmt (loc, expr));
   13915              :   else
   13916              :     return NULL;
   13917              : }
   13918              : 
   13919              : /* Do the opposite and emit a statement as an expression.  To begin,
   13920              :    create a new binding level and return it.  */
   13921              : 
   13922              : tree
   13923        34915 : c_begin_stmt_expr (void)
   13924              : {
   13925        34915 :   tree ret;
   13926              : 
   13927              :   /* We must force a BLOCK for this level so that, if it is not expanded
   13928              :      later, there is a way to turn off the entire subtree of blocks that
   13929              :      are contained in it.  */
   13930        34915 :   keep_next_level ();
   13931        34915 :   ret = c_begin_compound_stmt (true);
   13932              : 
   13933        34915 :   c_bindings_start_stmt_expr (c_switch_stack == NULL
   13934              :                               ? NULL
   13935              :                               : c_switch_stack->bindings);
   13936              : 
   13937              :   /* Mark the current statement list as belonging to a statement list.  */
   13938        34915 :   STATEMENT_LIST_STMT_EXPR (ret) = 1;
   13939              : 
   13940        34915 :   return ret;
   13941              : }
   13942              : 
   13943              : /* LOC is the location of the compound statement to which this body
   13944              :    belongs.  */
   13945              : 
   13946              : tree
   13947        34915 : c_finish_stmt_expr (location_t loc, tree body)
   13948              : {
   13949        34915 :   tree last, type, tmp, val;
   13950        34915 :   tree *last_p;
   13951              : 
   13952        34915 :   body = c_end_compound_stmt (loc, body, true);
   13953              : 
   13954        34915 :   c_bindings_end_stmt_expr (c_switch_stack == NULL
   13955              :                             ? NULL
   13956              :                             : c_switch_stack->bindings);
   13957              : 
   13958              :   /* Locate the last statement in BODY.  See c_end_compound_stmt
   13959              :      about always returning a BIND_EXPR.  */
   13960        34915 :   last_p = &BIND_EXPR_BODY (body);
   13961        34915 :   last = BIND_EXPR_BODY (body);
   13962              : 
   13963        34915 :  continue_searching:
   13964        34915 :   if (TREE_CODE (last) == STATEMENT_LIST)
   13965              :     {
   13966        26101 :       tree_stmt_iterator l = tsi_last (last);
   13967              : 
   13968        26107 :       while (!tsi_end_p (l) && TREE_CODE (tsi_stmt (l)) == DEBUG_BEGIN_STMT)
   13969            6 :         tsi_prev (&l);
   13970              : 
   13971              :       /* This can happen with degenerate cases like ({ }).  No value.  */
   13972        26101 :       if (tsi_end_p (l))
   13973          389 :         return body;
   13974              : 
   13975              :       /* If we're supposed to generate side effects warnings, process
   13976              :          all of the statements except the last.  */
   13977        25712 :       if (warn_unused_value || warn_unused_result)
   13978              :         {
   13979        25712 :           for (tree_stmt_iterator i = tsi_start (last);
   13980       275871 :                tsi_stmt (i) != tsi_stmt (l); tsi_next (&i))
   13981              :             {
   13982       250159 :               location_t tloc;
   13983       250159 :               tree t = tsi_stmt (i);
   13984              : 
   13985       250159 :               tloc = EXPR_HAS_LOCATION (t) ? EXPR_LOCATION (t) : loc;
   13986       250159 :               emit_side_effect_warnings (tloc, t);
   13987              :             }
   13988              :         }
   13989        25712 :       last_p = tsi_stmt_ptr (l);
   13990        25712 :       last = *last_p;
   13991              :     }
   13992              : 
   13993              :   /* If the end of the list is exception related, then the list was split
   13994              :      by a call to push_cleanup.  Continue searching.  */
   13995        34526 :   if (TREE_CODE (last) == TRY_FINALLY_EXPR
   13996        34526 :       || TREE_CODE (last) == TRY_CATCH_EXPR)
   13997              :     {
   13998            0 :       last_p = &TREE_OPERAND (last, 0);
   13999            0 :       last = *last_p;
   14000            0 :       goto continue_searching;
   14001              :     }
   14002              : 
   14003        34526 :   if (last == error_mark_node)
   14004              :     return last;
   14005              : 
   14006              :   /* In the case that the BIND_EXPR is not necessary, return the
   14007              :      expression out from inside it.  */
   14008        34517 :   if ((last == BIND_EXPR_BODY (body)
   14009              :        /* Skip nested debug stmts.  */
   14010        25711 :        || last == expr_first (BIND_EXPR_BODY (body)))
   14011        45544 :       && BIND_EXPR_VARS (body) == NULL)
   14012              :     {
   14013              :       /* Even if this looks constant, do not allow it in a constant
   14014              :          expression.  */
   14015        11015 :       last = c_wrap_maybe_const (last, true);
   14016              :       /* Do not warn if the return value of a statement expression is
   14017              :          unused.  */
   14018        11015 :       suppress_warning (last, OPT_Wunused);
   14019        11015 :       return last;
   14020              :     }
   14021              : 
   14022              :   /* Extract the type of said expression.  */
   14023        23502 :   type = TREE_TYPE (last);
   14024              : 
   14025              :   /* If we're not returning a value at all, then the BIND_EXPR that
   14026              :      we already have is a fine expression to return.  */
   14027        23502 :   if (!type || VOID_TYPE_P (type))
   14028              :     return body;
   14029              : 
   14030              :   /* Now that we've located the expression containing the value, it seems
   14031              :      silly to make voidify_wrapper_expr repeat the process.  Create a
   14032              :      temporary of the appropriate type and stick it in a TARGET_EXPR.  */
   14033        18178 :   tmp = create_tmp_var_raw (type);
   14034              : 
   14035              :   /* Unwrap a no-op NOP_EXPR as added by c_finish_expr_stmt.  This avoids
   14036              :      tree_expr_nonnegative_p giving up immediately.  */
   14037        18178 :   val = last;
   14038        18178 :   if (TREE_CODE (val) == NOP_EXPR
   14039        18178 :       && TREE_TYPE (val) == TREE_TYPE (TREE_OPERAND (val, 0)))
   14040         3793 :     val = TREE_OPERAND (val, 0);
   14041              : 
   14042        18178 :   *last_p = build2 (MODIFY_EXPR, void_type_node, tmp, val);
   14043        18178 :   SET_EXPR_LOCATION (*last_p, EXPR_LOCATION (last));
   14044              : 
   14045        18178 :   {
   14046        18178 :     tree t = build4 (TARGET_EXPR, type, tmp, body, NULL_TREE, NULL_TREE);
   14047        18178 :     SET_EXPR_LOCATION (t, loc);
   14048        18178 :     return t;
   14049              :   }
   14050              : }
   14051              : 
   14052              : /* Begin and end compound statements.  This is as simple as pushing
   14053              :    and popping new statement lists from the tree.  */
   14054              : 
   14055              : tree
   14056     41199964 : c_begin_compound_stmt (bool do_scope)
   14057              : {
   14058     41199964 :   tree stmt = push_stmt_list ();
   14059     41199964 :   if (do_scope)
   14060     41103910 :     push_scope ();
   14061     41199964 :   return stmt;
   14062              : }
   14063              : 
   14064              : /* End a compound statement.  STMT is the statement.  LOC is the
   14065              :    location of the compound statement-- this is usually the location
   14066              :    of the opening brace.  */
   14067              : 
   14068              : tree
   14069     41199963 : c_end_compound_stmt (location_t loc, tree stmt, bool do_scope)
   14070              : {
   14071     41199963 :   tree block = NULL;
   14072              : 
   14073     41199963 :   if (do_scope)
   14074              :     {
   14075     41103909 :       if (c_dialect_objc ())
   14076            0 :         objc_clear_super_receiver ();
   14077     41103909 :       block = pop_scope ();
   14078              :     }
   14079              : 
   14080     41199963 :   stmt = pop_stmt_list (stmt);
   14081     41199963 :   stmt = c_build_bind_expr (loc, block, stmt);
   14082              : 
   14083              :   /* If this compound statement is nested immediately inside a statement
   14084              :      expression, then force a BIND_EXPR to be created.  Otherwise we'll
   14085              :      do the wrong thing for ({ { 1; } }) or ({ 1; { } }).  In particular,
   14086              :      STATEMENT_LISTs merge, and thus we can lose track of what statement
   14087              :      was really last.  */
   14088     82399926 :   if (building_stmt_list_p ()
   14089     41199878 :       && STATEMENT_LIST_STMT_EXPR (cur_stmt_list)
   14090     41322648 :       && TREE_CODE (stmt) != BIND_EXPR)
   14091              :     {
   14092       120942 :       stmt = build3 (BIND_EXPR, void_type_node, NULL, stmt, NULL);
   14093       120942 :       TREE_SIDE_EFFECTS (stmt) = 1;
   14094       120942 :       SET_EXPR_LOCATION (stmt, loc);
   14095              :     }
   14096              : 
   14097     41199963 :   return stmt;
   14098              : }
   14099              : 
   14100              : /* Queue a cleanup.  CLEANUP is an expression/statement to be executed
   14101              :    when the current scope is exited.  EH_ONLY is true when this is not
   14102              :    meant to apply to normal control flow transfer.  */
   14103              : 
   14104              : void
   14105          131 : push_cleanup (tree decl, tree cleanup, bool eh_only)
   14106              : {
   14107          131 :   enum tree_code code;
   14108          131 :   tree stmt, list;
   14109          131 :   bool stmt_expr;
   14110              : 
   14111          131 :   code = eh_only ? TRY_CATCH_EXPR : TRY_FINALLY_EXPR;
   14112          131 :   stmt = build_stmt (DECL_SOURCE_LOCATION (decl), code, NULL, cleanup);
   14113          131 :   add_stmt (stmt);
   14114          131 :   stmt_expr = STATEMENT_LIST_STMT_EXPR (cur_stmt_list);
   14115          131 :   list = push_stmt_list ();
   14116          131 :   TREE_OPERAND (stmt, 0) = list;
   14117          131 :   STATEMENT_LIST_STMT_EXPR (list) = stmt_expr;
   14118          131 : }
   14119              : 
   14120              : /* Build a vector comparison of ARG0 and ARG1 using CODE opcode
   14121              :    into a value of TYPE type.  Comparison is done via VEC_COND_EXPR.  */
   14122              : 
   14123              : static tree
   14124       101043 : build_vec_cmp (tree_code code, tree type,
   14125              :                tree arg0, tree arg1)
   14126              : {
   14127       101043 :   tree zero_vec = build_zero_cst (type);
   14128       101043 :   tree minus_one_vec = build_minus_one_cst (type);
   14129       101043 :   tree cmp_type = truth_type_for (TREE_TYPE (arg0));
   14130       101043 :   tree cmp = build2 (code, cmp_type, arg0, arg1);
   14131       101043 :   return build3 (VEC_COND_EXPR, type, cmp, minus_one_vec, zero_vec);
   14132              : }
   14133              : 
   14134              : /* Possibly warn about an address of OP never being NULL in a comparison
   14135              :    operation CODE involving null.  */
   14136              : 
   14137              : static void
   14138        52225 : maybe_warn_for_null_address (location_t loc, tree op, tree_code code)
   14139              : {
   14140              :   /* Prevent warnings issued for macro expansion.  */
   14141        52225 :   if (!warn_address
   14142        30445 :       || warning_suppressed_p (op, OPT_Waddress)
   14143        82306 :       || from_macro_expansion_at (loc))
   14144        24877 :     return;
   14145              : 
   14146        27348 :   if (TREE_CODE (op) == NOP_EXPR)
   14147              :     {
   14148              :       /* Allow casts to intptr_t to suppress the warning.  */
   14149         1133 :       tree type = TREE_TYPE (op);
   14150         1133 :       if (TREE_CODE (type) == INTEGER_TYPE)
   14151              :         return;
   14152         1133 :       op = TREE_OPERAND (op, 0);
   14153              :     }
   14154              : 
   14155        27348 :   if (TREE_CODE (op) == POINTER_PLUS_EXPR)
   14156              :     {
   14157              :       /* Allow a cast to void* to suppress the warning.  */
   14158           24 :       tree type = TREE_TYPE (TREE_TYPE (op));
   14159           24 :       if (VOID_TYPE_P (type))
   14160              :         return;
   14161              : 
   14162              :       /* Adding any value to a null pointer, including zero, is undefined
   14163              :          in C.  This includes the expression &p[0] where p is the null
   14164              :          pointer, although &p[0] will have been folded to p by this point
   14165              :          and so not diagnosed.  */
   14166           24 :       if (code == EQ_EXPR)
   14167           22 :         warning_at (loc, OPT_Waddress,
   14168              :                     "the comparison will always evaluate as %<false%> "
   14169              :                     "for the pointer operand in %qE must not be NULL",
   14170              :                     op);
   14171              :       else
   14172            2 :         warning_at (loc, OPT_Waddress,
   14173              :                     "the comparison will always evaluate as %<true%> "
   14174              :                     "for the pointer operand in %qE must not be NULL",
   14175              :                     op);
   14176              : 
   14177           24 :       return;
   14178              :     }
   14179              : 
   14180        27324 :   if (TREE_CODE (op) != ADDR_EXPR)
   14181              :     return;
   14182              : 
   14183          254 :   op = TREE_OPERAND (op, 0);
   14184              : 
   14185          254 :   if (TREE_CODE (op) == IMAGPART_EXPR
   14186          254 :       || TREE_CODE (op) == REALPART_EXPR)
   14187              :     {
   14188              :       /* The address of either complex part may not be null.  */
   14189           14 :       if (code == EQ_EXPR)
   14190            9 :         warning_at (loc, OPT_Waddress,
   14191              :                     "the comparison will always evaluate as %<false%> "
   14192              :                     "for the address of %qE will never be NULL",
   14193              :                     op);
   14194              :       else
   14195            5 :         warning_at (loc, OPT_Waddress,
   14196              :                     "the comparison will always evaluate as %<true%> "
   14197              :                     "for the address of %qE will never be NULL",
   14198              :                     op);
   14199           14 :       return;
   14200              :     }
   14201              : 
   14202              :   /* Set to true in the loop below if OP dereferences is operand.
   14203              :      In such a case the ultimate target need not be a decl for
   14204              :      the null [in]equality test to be constant.  */
   14205              :   bool deref = false;
   14206              : 
   14207              :   /* Get the outermost array or object, or member.  */
   14208          294 :   while (handled_component_p (op))
   14209              :     {
   14210           72 :       if (TREE_CODE (op) == COMPONENT_REF)
   14211              :         {
   14212              :           /* Get the member (its address is never null).  */
   14213           18 :           op = TREE_OPERAND (op, 1);
   14214           18 :           break;
   14215              :         }
   14216              : 
   14217              :       /* Get the outer array/object to refer to in the warning.  */
   14218           54 :       op = TREE_OPERAND (op, 0);
   14219           54 :       deref = true;
   14220              :     }
   14221              : 
   14222          192 :   if ((!deref && !decl_with_nonnull_addr_p (op))
   14223          371 :       || from_macro_expansion_at (loc))
   14224          109 :     return;
   14225              : 
   14226          131 :   bool w;
   14227          131 :   if (code == EQ_EXPR)
   14228           93 :     w = warning_at (loc, OPT_Waddress,
   14229              :                     "the comparison will always evaluate as %<false%> "
   14230              :                     "for the address of %qE will never be NULL",
   14231              :                     op);
   14232              :   else
   14233           38 :     w = warning_at (loc, OPT_Waddress,
   14234              :                     "the comparison will always evaluate as %<true%> "
   14235              :                     "for the address of %qE will never be NULL",
   14236              :                     op);
   14237              : 
   14238          131 :   if (w && DECL_P (op))
   14239          120 :     inform (DECL_SOURCE_LOCATION (op), "%qD declared here", op);
   14240              : }
   14241              : 
   14242              : /* Build a binary-operation expression without default conversions.
   14243              :    CODE is the kind of expression to build.
   14244              :    LOCATION is the operator's location.
   14245              :    This function differs from `build' in several ways:
   14246              :    the data type of the result is computed and recorded in it,
   14247              :    warnings are generated if arg data types are invalid,
   14248              :    special handling for addition and subtraction of pointers is known,
   14249              :    and some optimization is done (operations on narrow ints
   14250              :    are done in the narrower type when that gives the same result).
   14251              :    Constant folding is also done before the result is returned.
   14252              : 
   14253              :    Note that the operands will never have enumeral types, or function
   14254              :    or array types, because either they will have the default conversions
   14255              :    performed or they have both just been converted to some other type in which
   14256              :    the arithmetic is to be done.  */
   14257              : 
   14258              : tree
   14259     16877969 : build_binary_op (location_t location, enum tree_code code,
   14260              :                  tree orig_op0, tree orig_op1, bool convert_p)
   14261              : {
   14262     16877969 :   tree type0, type1, orig_type0, orig_type1;
   14263     16877969 :   tree eptype;
   14264     16877969 :   enum tree_code code0, code1;
   14265     16877969 :   tree op0, op1;
   14266     16877969 :   tree ret = error_mark_node;
   14267     16877969 :   const char *invalid_op_diag;
   14268     16877969 :   bool op0_int_operands, op1_int_operands;
   14269     16877969 :   bool int_const, int_const_or_overflow, int_operands;
   14270              : 
   14271              :   /* Expression code to give to the expression when it is built.
   14272              :      Normally this is CODE, which is what the caller asked for,
   14273              :      but in some special cases we change it.  */
   14274     16877969 :   enum tree_code resultcode = code;
   14275              : 
   14276              :   /* Data type in which the computation is to be performed.
   14277              :      In the simplest cases this is the common type of the arguments.  */
   14278     16877969 :   tree result_type = NULL;
   14279              : 
   14280              :   /* When the computation is in excess precision, the type of the
   14281              :      final EXCESS_PRECISION_EXPR.  */
   14282     16877969 :   tree semantic_result_type = NULL;
   14283              : 
   14284              :   /* Nonzero means operands have already been type-converted
   14285              :      in whatever way is necessary.
   14286              :      Zero means they need to be converted to RESULT_TYPE.  */
   14287     16877969 :   int converted = 0;
   14288              : 
   14289              :   /* Nonzero means create the expression with this type, rather than
   14290              :      RESULT_TYPE.  */
   14291     16877969 :   tree build_type = NULL_TREE;
   14292              : 
   14293              :   /* Nonzero means after finally constructing the expression
   14294              :      convert it to this type.  */
   14295     16877969 :   tree final_type = NULL_TREE;
   14296              : 
   14297              :   /* Nonzero if this is an operation like MIN or MAX which can
   14298              :      safely be computed in short if both args are promoted shorts.
   14299              :      Also implies COMMON.
   14300              :      -1 indicates a bitwise operation; this makes a difference
   14301              :      in the exact conditions for when it is safe to do the operation
   14302              :      in a narrower mode.  */
   14303     16877969 :   int shorten = 0;
   14304              : 
   14305              :   /* Nonzero if this is a comparison operation;
   14306              :      if both args are promoted shorts, compare the original shorts.
   14307              :      Also implies COMMON.  */
   14308     16877969 :   int short_compare = 0;
   14309              : 
   14310              :   /* Nonzero if this is a right-shift operation, which can be computed on the
   14311              :      original short and then promoted if the operand is a promoted short.  */
   14312     16877969 :   int short_shift = 0;
   14313              : 
   14314              :   /* Nonzero means set RESULT_TYPE to the common type of the args.  */
   14315     16877969 :   int common = 0;
   14316              : 
   14317              :   /* True means types are compatible as far as ObjC is concerned.  */
   14318     16877969 :   bool objc_ok;
   14319              : 
   14320              :   /* True means this is an arithmetic operation that may need excess
   14321              :      precision.  */
   14322     16877969 :   bool may_need_excess_precision;
   14323              : 
   14324              :   /* True means this is a boolean operation that converts both its
   14325              :      operands to truth-values.  */
   14326     16877969 :   bool boolean_op = false;
   14327              : 
   14328              :   /* Remember whether we're doing / or %.  */
   14329     16877969 :   bool doing_div_or_mod = false;
   14330              : 
   14331              :   /* Remember whether we're doing << or >>.  */
   14332     16877969 :   bool doing_shift = false;
   14333              : 
   14334              :   /* Tree holding instrumentation expression.  */
   14335     16877969 :   tree instrument_expr = NULL;
   14336              : 
   14337     16877969 :   if (location == UNKNOWN_LOCATION)
   14338           79 :     location = input_location;
   14339              : 
   14340     16877969 :   op0 = orig_op0;
   14341     16877969 :   op1 = orig_op1;
   14342              : 
   14343     16877969 :   op0_int_operands = EXPR_INT_CONST_OPERANDS (orig_op0);
   14344      8168895 :   if (op0_int_operands)
   14345      8168895 :     op0 = remove_c_maybe_const_expr (op0);
   14346     16877969 :   op1_int_operands = EXPR_INT_CONST_OPERANDS (orig_op1);
   14347     11442206 :   if (op1_int_operands)
   14348     11442206 :     op1 = remove_c_maybe_const_expr (op1);
   14349     28320175 :   int_operands = (op0_int_operands && op1_int_operands);
   14350     11442206 :   if (int_operands)
   14351              :     {
   14352     15981221 :       int_const_or_overflow = (TREE_CODE (orig_op0) == INTEGER_CST
   14353      8005781 :                                && TREE_CODE (orig_op1) == INTEGER_CST);
   14354      7975440 :       int_const = (int_const_or_overflow
   14355      7975440 :                    && !TREE_OVERFLOW (orig_op0)
   14356      7975371 :                    && !TREE_OVERFLOW (orig_op1));
   14357              :     }
   14358              :   else
   14359              :     int_const = int_const_or_overflow = false;
   14360              : 
   14361              :   /* Do not apply default conversion in mixed vector/scalar expression.  */
   14362     16877969 :   if (convert_p
   14363     16877969 :       && VECTOR_TYPE_P (TREE_TYPE (op0)) == VECTOR_TYPE_P (TREE_TYPE (op1)))
   14364              :     {
   14365     10142765 :       op0 = default_conversion (op0);
   14366     10142765 :       op1 = default_conversion (op1);
   14367              :     }
   14368              : 
   14369     16877969 :   orig_type0 = type0 = TREE_TYPE (op0);
   14370              : 
   14371     16877969 :   orig_type1 = type1 = TREE_TYPE (op1);
   14372              : 
   14373              :   /* The expression codes of the data types of the arguments tell us
   14374              :      whether the arguments are integers, floating, pointers, etc.  */
   14375     16877969 :   code0 = TREE_CODE (type0);
   14376     16877969 :   code1 = TREE_CODE (type1);
   14377              : 
   14378              :   /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
   14379     16877971 :   STRIP_TYPE_NOPS (op0);
   14380     16877972 :   STRIP_TYPE_NOPS (op1);
   14381              : 
   14382              :   /* If an error was already reported for one of the arguments,
   14383              :      avoid reporting another error.  */
   14384              : 
   14385     16877969 :   if (code0 == ERROR_MARK || code1 == ERROR_MARK)
   14386          710 :     return error_mark_node;
   14387              : 
   14388     16877259 :   if (code0 == POINTER_TYPE
   14389     16877259 :       && reject_gcc_builtin (op0, EXPR_LOCATION (orig_op0)))
   14390           11 :     return error_mark_node;
   14391              : 
   14392     16877248 :   if (code1 == POINTER_TYPE
   14393     16877248 :       && reject_gcc_builtin (op1, EXPR_LOCATION (orig_op1)))
   14394           11 :     return error_mark_node;
   14395              : 
   14396     33754474 :   if ((invalid_op_diag
   14397     16877237 :        = targetm.invalid_binary_op (code, type0, type1)))
   14398              :     {
   14399            0 :       error_at (location, invalid_op_diag);
   14400            0 :       return error_mark_node;
   14401              :     }
   14402              : 
   14403     16877237 :   switch (code)
   14404              :     {
   14405              :     case PLUS_EXPR:
   14406              :     case MINUS_EXPR:
   14407              :     case MULT_EXPR:
   14408              :     case TRUNC_DIV_EXPR:
   14409              :     case CEIL_DIV_EXPR:
   14410              :     case FLOOR_DIV_EXPR:
   14411              :     case ROUND_DIV_EXPR:
   14412              :     case EXACT_DIV_EXPR:
   14413              :       may_need_excess_precision = true;
   14414              :       break;
   14415              : 
   14416      2742125 :     case EQ_EXPR:
   14417      2742125 :     case NE_EXPR:
   14418      2742125 :     case LE_EXPR:
   14419      2742125 :     case GE_EXPR:
   14420      2742125 :     case LT_EXPR:
   14421      2742125 :     case GT_EXPR:
   14422              :       /* Excess precision for implicit conversions of integers to
   14423              :          floating point in C11 and later.  */
   14424      2742125 :       may_need_excess_precision = (flag_isoc11
   14425      2742125 :                                    && (ANY_INTEGRAL_TYPE_P (type0)
   14426       488489 :                                        || ANY_INTEGRAL_TYPE_P (type1)));
   14427              :       break;
   14428              : 
   14429              :     default:
   14430     16877237 :       may_need_excess_precision = false;
   14431              :       break;
   14432              :     }
   14433     16877237 :   if (TREE_CODE (op0) == EXCESS_PRECISION_EXPR)
   14434              :     {
   14435          184 :       op0 = TREE_OPERAND (op0, 0);
   14436          184 :       type0 = TREE_TYPE (op0);
   14437              :     }
   14438     16877053 :   else if (may_need_excess_precision
   14439     16877053 :            && (eptype = excess_precision_type (type0)) != NULL_TREE)
   14440              :     {
   14441          771 :       type0 = eptype;
   14442          771 :       op0 = convert (eptype, op0);
   14443              :     }
   14444     16877237 :   if (TREE_CODE (op1) == EXCESS_PRECISION_EXPR)
   14445              :     {
   14446          889 :       op1 = TREE_OPERAND (op1, 0);
   14447          889 :       type1 = TREE_TYPE (op1);
   14448              :     }
   14449     16876348 :   else if (may_need_excess_precision
   14450     16876348 :            && (eptype = excess_precision_type (type1)) != NULL_TREE)
   14451              :     {
   14452          592 :       type1 = eptype;
   14453          592 :       op1 = convert (eptype, op1);
   14454              :     }
   14455              : 
   14456     16877237 :   objc_ok = objc_compare_types (type0, type1, -3, NULL_TREE);
   14457              : 
   14458              :   /* In case when one of the operands of the binary operation is
   14459              :      a vector and another is a scalar -- convert scalar to vector.  */
   14460     18457195 :   if ((gnu_vector_type_p (type0) && code1 != VECTOR_TYPE)
   14461     18455274 :       || (gnu_vector_type_p (type1) && code0 != VECTOR_TYPE))
   14462              :     {
   14463         2536 :       enum stv_conv convert_flag = scalar_to_vector (location, code, orig_op0,
   14464              :                                                      orig_op1, true);
   14465              : 
   14466         2536 :       switch (convert_flag)
   14467              :         {
   14468           12 :           case stv_error:
   14469           12 :             return error_mark_node;
   14470          602 :           case stv_firstarg:
   14471          602 :             {
   14472          602 :               bool maybe_const = true;
   14473          602 :               tree sc;
   14474          602 :               sc = c_fully_fold (op0, false, &maybe_const);
   14475          602 :               sc = save_expr (sc);
   14476          602 :               sc = convert (TREE_TYPE (type1), sc);
   14477          602 :               op0 = build_vector_from_val (type1, sc);
   14478          602 :               if (!maybe_const)
   14479           93 :                 op0 = c_wrap_maybe_const (op0, true);
   14480          602 :               orig_type0 = type0 = TREE_TYPE (op0);
   14481          602 :               code0 = TREE_CODE (type0);
   14482          602 :               converted = 1;
   14483          602 :               break;
   14484              :             }
   14485         1080 :           case stv_secondarg:
   14486         1080 :             {
   14487         1080 :               bool maybe_const = true;
   14488         1080 :               tree sc;
   14489         1080 :               sc = c_fully_fold (op1, false, &maybe_const);
   14490         1080 :               sc = save_expr (sc);
   14491         1080 :               sc = convert (TREE_TYPE (type0), sc);
   14492         1080 :               op1 = build_vector_from_val (type0, sc);
   14493         1080 :               if (!maybe_const)
   14494           37 :                 op1 = c_wrap_maybe_const (op1, true);
   14495         1080 :               orig_type1 = type1 = TREE_TYPE (op1);
   14496         1080 :               code1 = TREE_CODE (type1);
   14497         1080 :               converted = 1;
   14498         1080 :               break;
   14499              :             }
   14500              :           default:
   14501              :             break;
   14502              :         }
   14503              :     }
   14504              : 
   14505     16877225 :   switch (code)
   14506              :     {
   14507      8660038 :     case PLUS_EXPR:
   14508              :       /* Handle the pointer + int case.  */
   14509      8660038 :       if (code0 == POINTER_TYPE
   14510      1252142 :           && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
   14511              :         {
   14512      1252136 :           ret = pointer_int_sum (location, PLUS_EXPR, op0, op1);
   14513      1252136 :           goto return_build_binary_op;
   14514              :         }
   14515      7407902 :       else if (code1 == POINTER_TYPE
   14516         1538 :                && (code0 == INTEGER_TYPE || code0 == BITINT_TYPE))
   14517              :         {
   14518         1532 :           ret = pointer_int_sum (location, PLUS_EXPR, op1, op0);
   14519         1532 :           goto return_build_binary_op;
   14520              :         }
   14521              :       else
   14522              :         common = 1;
   14523              :       break;
   14524              : 
   14525       791722 :     case MINUS_EXPR:
   14526              :       /* Subtraction of two similar pointers.
   14527              :          We must subtract them as integers, then divide by object size.  */
   14528       791722 :       if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
   14529       791722 :           && comp_target_types (location, type0, type1))
   14530              :         {
   14531         3725 :           ret = pointer_diff (location, op0, op1, &instrument_expr);
   14532         3725 :           goto return_build_binary_op;
   14533              :         }
   14534              :       /* Handle pointer minus int.  Just like pointer plus int.  */
   14535       787997 :       else if (code0 == POINTER_TYPE
   14536        16860 :                && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
   14537              :         {
   14538        16848 :           ret = pointer_int_sum (location, MINUS_EXPR, op0, op1);
   14539        16848 :           goto return_build_binary_op;
   14540              :         }
   14541              :       else
   14542              :         common = 1;
   14543              :       break;
   14544              : 
   14545              :     case MULT_EXPR:
   14546              :       common = 1;
   14547              :       break;
   14548              : 
   14549       274930 :     case TRUNC_DIV_EXPR:
   14550       274930 :     case CEIL_DIV_EXPR:
   14551       274930 :     case FLOOR_DIV_EXPR:
   14552       274930 :     case ROUND_DIV_EXPR:
   14553       274930 :     case EXACT_DIV_EXPR:
   14554       274930 :       doing_div_or_mod = true;
   14555       274930 :       warn_for_div_by_zero (location, op1);
   14556              : 
   14557       274929 :       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
   14558        49647 :            || code0 == FIXED_POINT_TYPE || code0 == BITINT_TYPE
   14559        47633 :            || code0 == COMPLEX_TYPE
   14560        45585 :            || gnu_vector_type_p (type0))
   14561       324575 :           && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
   14562        47214 :               || code1 == FIXED_POINT_TYPE || code1 == BITINT_TYPE
   14563        47047 :               || code1 == COMPLEX_TYPE
   14564        45587 :               || gnu_vector_type_p (type1)))
   14565              :         {
   14566       274925 :           enum tree_code tcode0 = code0, tcode1 = code1;
   14567              : 
   14568       274925 :           if (code0 == COMPLEX_TYPE || code0 == VECTOR_TYPE)
   14569        47632 :             tcode0 = TREE_CODE (TREE_TYPE (TREE_TYPE (op0)));
   14570       274925 :           if (code1 == COMPLEX_TYPE || code1 == VECTOR_TYPE)
   14571        47044 :             tcode1 = TREE_CODE (TREE_TYPE (TREE_TYPE (op1)));
   14572              : 
   14573       274925 :           if (!(((tcode0 == INTEGER_TYPE || tcode0 == BITINT_TYPE
   14574        69636 :                   || (tcode0 == ENUMERAL_TYPE && code0 == VECTOR_TYPE))
   14575       205290 :                  && (tcode1 == INTEGER_TYPE || tcode1 == BITINT_TYPE
   14576        12988 :                      || (tcode1 == ENUMERAL_TYPE && code1 == VECTOR_TYPE)))
   14577        82622 :                 || (tcode0 == FIXED_POINT_TYPE && tcode1 == FIXED_POINT_TYPE)))
   14578              :             resultcode = RDIV_EXPR;
   14579              :           else
   14580              :             /* Although it would be tempting to shorten always here, that
   14581              :                loses on some targets, since the modulo instruction is
   14582              :                undefined if the quotient can't be represented in the
   14583              :                computation mode.  We shorten only if unsigned or if
   14584              :                dividing by something we know != -1.  */
   14585       192303 :             shorten = may_shorten_divmod (op0, op1);
   14586              :           common = 1;
   14587              :         }
   14588              :       break;
   14589              : 
   14590      1587225 :     case BIT_AND_EXPR:
   14591      1587225 :     case BIT_IOR_EXPR:
   14592      1587225 :     case BIT_XOR_EXPR:
   14593      1587225 :       if ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE)
   14594      1051782 :           && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
   14595              :         shorten = -1;
   14596              :       /* Allow vector types which are not floating point types.   */
   14597       535479 :       else if (gnu_vector_type_p (type0)
   14598       535402 :                && gnu_vector_type_p (type1)
   14599       535402 :                && !VECTOR_FLOAT_TYPE_P (type0)
   14600      1070878 :                && !VECTOR_FLOAT_TYPE_P (type1))
   14601              :         common = 1;
   14602              :       break;
   14603              : 
   14604        58554 :     case TRUNC_MOD_EXPR:
   14605        58554 :     case FLOOR_MOD_EXPR:
   14606        58554 :       doing_div_or_mod = true;
   14607        58554 :       warn_for_div_by_zero (location, op1);
   14608              : 
   14609        58554 :       if (gnu_vector_type_p (type0)
   14610          297 :           && gnu_vector_type_p (type1)
   14611          297 :           && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
   14612        58851 :           && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE)
   14613              :         common = 1;
   14614        58257 :       else if ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE)
   14615        58256 :                && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
   14616              :         {
   14617              :           /* Although it would be tempting to shorten always here, that loses
   14618              :              on some targets, since the modulo instruction is undefined if the
   14619              :              quotient can't be represented in the computation mode.  We shorten
   14620              :              only if unsigned or if dividing by something we know != -1.  */
   14621        58256 :           shorten = may_shorten_divmod (op0, op1);
   14622        58256 :           common = 1;
   14623              :         }
   14624              :       break;
   14625              : 
   14626       513071 :     case TRUTH_ANDIF_EXPR:
   14627       513071 :     case TRUTH_ORIF_EXPR:
   14628       513071 :     case TRUTH_AND_EXPR:
   14629       513071 :     case TRUTH_OR_EXPR:
   14630       513071 :     case TRUTH_XOR_EXPR:
   14631       513071 :       if ((code0 == INTEGER_TYPE || code0 == POINTER_TYPE
   14632            0 :            || code0 == REAL_TYPE || code0 == COMPLEX_TYPE
   14633            0 :            || code0 == FIXED_POINT_TYPE || code0 == NULLPTR_TYPE
   14634            0 :            || code0 == BITINT_TYPE)
   14635       513071 :           && (code1 == INTEGER_TYPE || code1 == POINTER_TYPE
   14636          163 :               || code1 == REAL_TYPE || code1 == COMPLEX_TYPE
   14637           24 :               || code1 == FIXED_POINT_TYPE || code1 == NULLPTR_TYPE
   14638           22 :               || code1 == BITINT_TYPE))
   14639              :         {
   14640              :           /* Result of these operations is always an int,
   14641              :              but that does not mean the operands should be
   14642              :              converted to ints!  */
   14643       513071 :           result_type = integer_type_node;
   14644       513071 :           if (op0_int_operands)
   14645              :             {
   14646       111541 :               op0 = c_objc_common_truthvalue_conversion (location, orig_op0);
   14647       111541 :               op0 = remove_c_maybe_const_expr (op0);
   14648              :             }
   14649              :           else
   14650       401530 :             op0 = c_objc_common_truthvalue_conversion (location, op0);
   14651       513071 :           if (op1_int_operands)
   14652              :             {
   14653        72541 :               op1 = c_objc_common_truthvalue_conversion (location, orig_op1);
   14654        72541 :               op1 = remove_c_maybe_const_expr (op1);
   14655              :             }
   14656              :           else
   14657       440530 :             op1 = c_objc_common_truthvalue_conversion (location, op1);
   14658              :           converted = 1;
   14659              :           boolean_op = true;
   14660              :         }
   14661       513071 :       if (code == TRUTH_ANDIF_EXPR)
   14662              :         {
   14663       252477 :           int_const_or_overflow = (int_operands
   14664        64356 :                                    && TREE_CODE (orig_op0) == INTEGER_CST
   14665       252493 :                                    && (op0 == truthvalue_false_node
   14666        14007 :                                        || TREE_CODE (orig_op1) == INTEGER_CST));
   14667              :           int_const = (int_const_or_overflow
   14668        64329 :                        && !TREE_OVERFLOW (orig_op0)
   14669        64329 :                        && (op0 == truthvalue_false_node
   14670        13991 :                            || !TREE_OVERFLOW (orig_op1)));
   14671              :         }
   14672       324923 :       else if (code == TRUTH_ORIF_EXPR)
   14673              :         {
   14674       331603 :           int_const_or_overflow = (int_operands
   14675         6831 :                                    && TREE_CODE (orig_op0) == INTEGER_CST
   14676       331626 :                                    && (op0 == truthvalue_true_node
   14677         2146 :                                        || TREE_CODE (orig_op1) == INTEGER_CST));
   14678              :           int_const = (int_const_or_overflow
   14679         6801 :                        && !TREE_OVERFLOW (orig_op0)
   14680         6801 :                        && (op0 == truthvalue_true_node
   14681         2123 :                            || !TREE_OVERFLOW (orig_op1)));
   14682              :         }
   14683              :       break;
   14684              : 
   14685              :       /* Shift operations: result has same type as first operand;
   14686              :          always convert second operand to int.
   14687              :          Also set SHORT_SHIFT if shifting rightward.  */
   14688              : 
   14689       231404 :     case RSHIFT_EXPR:
   14690       231404 :       if (gnu_vector_type_p (type0)
   14691          814 :           && gnu_vector_type_p (type1)
   14692          258 :           && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
   14693          256 :           && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE
   14694       231660 :           && known_eq (TYPE_VECTOR_SUBPARTS (type0),
   14695              :                        TYPE_VECTOR_SUBPARTS (type1)))
   14696              :         {
   14697              :           result_type = type0;
   14698              :           converted = 1;
   14699              :         }
   14700       231150 :       else if ((code0 == INTEGER_TYPE || code0 == FIXED_POINT_TYPE
   14701         1119 :                 || code0 == BITINT_TYPE
   14702          564 :                 || (gnu_vector_type_p (type0)
   14703          560 :                     && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE))
   14704       232262 :                && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
   14705              :         {
   14706       231141 :           doing_shift = true;
   14707       231141 :           if (TREE_CODE (op1) == INTEGER_CST)
   14708              :             {
   14709       201691 :               if (tree_int_cst_sgn (op1) < 0)
   14710              :                 {
   14711          269 :                   int_const = false;
   14712          269 :                   if (c_inhibit_evaluation_warnings == 0)
   14713          129 :                     warning_at (location, OPT_Wshift_count_negative,
   14714              :                                 "right shift count is negative");
   14715              :                 }
   14716       201422 :               else if (code0 == VECTOR_TYPE)
   14717              :                 {
   14718          458 :                   if (compare_tree_int (op1,
   14719          458 :                                         TYPE_PRECISION (TREE_TYPE (type0)))
   14720              :                       >= 0)
   14721              :                     {
   14722           16 :                       int_const = false;
   14723           16 :                       if (c_inhibit_evaluation_warnings == 0)
   14724           16 :                         warning_at (location, OPT_Wshift_count_overflow,
   14725              :                                     "right shift count >= width of vector element");
   14726              :                     }
   14727              :                 }
   14728              :               else
   14729              :                 {
   14730       200964 :                   if (!integer_zerop (op1))
   14731       200606 :                     short_shift = 1;
   14732              : 
   14733       200964 :                   if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0)
   14734              :                     {
   14735          586 :                       int_const = false;
   14736          586 :                       if (c_inhibit_evaluation_warnings == 0)
   14737           52 :                         warning_at (location, OPT_Wshift_count_overflow,
   14738              :                                     "right shift count >= width of type");
   14739              :                     }
   14740              :                 }
   14741              :             }
   14742              : 
   14743              :           /* Use the type of the value to be shifted.  */
   14744              :           result_type = type0;
   14745              :           /* Avoid converting op1 to result_type later.  */
   14746              :           converted = 1;
   14747              :         }
   14748              :       break;
   14749              : 
   14750       803757 :     case LSHIFT_EXPR:
   14751       803757 :       if (gnu_vector_type_p (type0)
   14752          596 :           && gnu_vector_type_p (type1)
   14753          316 :           && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
   14754          314 :           && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE
   14755       804070 :           && known_eq (TYPE_VECTOR_SUBPARTS (type0),
   14756              :                        TYPE_VECTOR_SUBPARTS (type1)))
   14757              :         {
   14758              :           result_type = type0;
   14759              :           converted = 1;
   14760              :         }
   14761       803446 :       else if ((code0 == INTEGER_TYPE || code0 == FIXED_POINT_TYPE
   14762          781 :                 || code0 == BITINT_TYPE
   14763          291 :                 || (gnu_vector_type_p (type0)
   14764          285 :                     && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE))
   14765       804218 :                && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
   14766              :         {
   14767       803432 :           doing_shift = true;
   14768       803432 :           if (TREE_CODE (op0) == INTEGER_CST
   14769       439200 :               && tree_int_cst_sgn (op0) < 0
   14770       804181 :               && !TYPE_OVERFLOW_WRAPS (type0))
   14771              :             {
   14772              :               /* Don't reject a left shift of a negative value in a context
   14773              :                  where a constant expression is needed in C90.  */
   14774          712 :               if (flag_isoc99)
   14775          666 :                 int_const = false;
   14776          712 :               if (c_inhibit_evaluation_warnings == 0)
   14777          712 :                 warning_at (location, OPT_Wshift_negative_value,
   14778              :                             "left shift of negative value");
   14779              :             }
   14780       803432 :           if (TREE_CODE (op1) == INTEGER_CST)
   14781              :             {
   14782       730971 :               if (tree_int_cst_sgn (op1) < 0)
   14783              :                 {
   14784          313 :                   int_const = false;
   14785          313 :                   if (c_inhibit_evaluation_warnings == 0)
   14786          135 :                     warning_at (location, OPT_Wshift_count_negative,
   14787              :                                 "left shift count is negative");
   14788              :                 }
   14789       730658 :               else if (code0 == VECTOR_TYPE)
   14790              :                 {
   14791          216 :                   if (compare_tree_int (op1,
   14792          216 :                                         TYPE_PRECISION (TREE_TYPE (type0)))
   14793              :                       >= 0)
   14794              :                     {
   14795            6 :                       int_const = false;
   14796            6 :                       if (c_inhibit_evaluation_warnings == 0)
   14797            6 :                         warning_at (location, OPT_Wshift_count_overflow,
   14798              :                                     "left shift count >= width of vector element");
   14799              :                     }
   14800              :                 }
   14801       730442 :               else if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0)
   14802              :                 {
   14803        29733 :                   int_const = false;
   14804        29733 :                   if (c_inhibit_evaluation_warnings == 0)
   14805          113 :                     warning_at (location, OPT_Wshift_count_overflow,
   14806              :                                 "left shift count >= width of type");
   14807              :                 }
   14808       700709 :               else if (TREE_CODE (op0) == INTEGER_CST
   14809       365412 :                        && maybe_warn_shift_overflow (location, op0, op1)
   14810       701337 :                        && flag_isoc99)
   14811              :                 int_const = false;
   14812              :             }
   14813              : 
   14814              :           /* Use the type of the value to be shifted.  */
   14815              :           result_type = type0;
   14816              :           /* Avoid converting op1 to result_type later.  */
   14817              :           converted = 1;
   14818              :         }
   14819              :       break;
   14820              : 
   14821      1743533 :     case EQ_EXPR:
   14822      1743533 :     case NE_EXPR:
   14823      1743533 :       if (gnu_vector_type_p (type0) && gnu_vector_type_p (type1))
   14824              :         {
   14825        41899 :           tree intt;
   14826        41899 :           if (!vector_types_compatible_elements_p (type0, type1))
   14827              :             {
   14828            4 :               error_at (location, "comparing vectors with different "
   14829              :                                   "element types");
   14830            4 :               return error_mark_node;
   14831              :             }
   14832              : 
   14833        41895 :           if (maybe_ne (TYPE_VECTOR_SUBPARTS (type0),
   14834        83790 :                         TYPE_VECTOR_SUBPARTS (type1)))
   14835              :             {
   14836            1 :               error_at (location, "comparing vectors with different "
   14837              :                                   "number of elements");
   14838            1 :               return error_mark_node;
   14839              :             }
   14840              : 
   14841              :           /* It's not precisely specified how the usual arithmetic
   14842              :              conversions apply to the vector types.  Here, we use
   14843              :              the unsigned type if one of the operands is signed and
   14844              :              the other one is unsigned.  */
   14845        41894 :           if (TYPE_UNSIGNED (type0) != TYPE_UNSIGNED (type1))
   14846              :             {
   14847            4 :               if (!TYPE_UNSIGNED (type0))
   14848            4 :                 op0 = build1 (VIEW_CONVERT_EXPR, type1, op0);
   14849              :               else
   14850            0 :                 op1 = build1 (VIEW_CONVERT_EXPR, type0, op1);
   14851            4 :               warning_at (location, OPT_Wsign_compare, "comparison between "
   14852              :                           "types %qT and %qT", type0, type1);
   14853              :             }
   14854              : 
   14855              :           /* Always construct signed integer vector type.  */
   14856        41894 :           if (VECTOR_BOOLEAN_TYPE_P (type0) && VECTOR_BOOLEAN_TYPE_P (type1))
   14857              :             result_type = type0;
   14858              :           else
   14859              :             {
   14860        41894 :               auto nelts = TYPE_VECTOR_SUBPARTS (type0);
   14861              : 
   14862       125682 :               intt = c_common_type_for_size (GET_MODE_BITSIZE
   14863        83788 :                                              (SCALAR_TYPE_MODE
   14864              :                                                 (TREE_TYPE (type0))), 0);
   14865        41894 :               if (!intt)
   14866              :                 {
   14867            0 :                   error_at (location, "could not find an integer type "
   14868              :                                       "of the same size as %qT",
   14869            0 :                             TREE_TYPE (type0));
   14870            0 :                   return error_mark_node;
   14871              :                 }
   14872        41894 :               result_type = build_opaque_vector_type (intt, nelts);
   14873              :             }
   14874        41894 :           converted = 1;
   14875        41894 :           ret = build_vec_cmp (resultcode, result_type, op0, op1);
   14876        41894 :           goto return_build_binary_op;
   14877              :         }
   14878      1701634 :       if (FLOAT_TYPE_P (type0) || FLOAT_TYPE_P (type1))
   14879       254612 :         warning_at (location,
   14880       254612 :                     OPT_Wfloat_equal,
   14881              :                     "comparing floating-point with %<==%> or %<!=%> is unsafe");
   14882              :       /* Result of comparison is always int,
   14883              :          but don't convert the args to int!  */
   14884      1701634 :       build_type = integer_type_node;
   14885      1701634 :       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == BITINT_TYPE
   14886       157207 :            || code0 == FIXED_POINT_TYPE || code0 == COMPLEX_TYPE)
   14887      1579988 :           && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
   14888              :               || code1 == BITINT_TYPE
   14889              :               || code1 == FIXED_POINT_TYPE || code1 == COMPLEX_TYPE))
   14890              :         short_compare = 1;
   14891       121912 :       else if (code0 == POINTER_TYPE
   14892       121912 :                && (code1 == NULLPTR_TYPE
   14893       121535 :                    || null_pointer_constant_p (orig_op1)))
   14894              :         {
   14895        51933 :           maybe_warn_for_null_address (location, op0, code);
   14896        51933 :           result_type = type0;
   14897              :         }
   14898        69979 :       else if (code1 == POINTER_TYPE
   14899        69979 :                && (code0 == NULLPTR_TYPE
   14900        69877 :                    || null_pointer_constant_p (orig_op0)))
   14901              :         {
   14902          292 :           maybe_warn_for_null_address (location, op1, code);
   14903          292 :           result_type = type1;
   14904              :         }
   14905        69687 :       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
   14906              :         {
   14907        69597 :           tree tt0 = TREE_TYPE (type0);
   14908        69597 :           tree tt1 = TREE_TYPE (type1);
   14909        69597 :           addr_space_t as0 = TYPE_ADDR_SPACE (tt0);
   14910        69597 :           addr_space_t as1 = TYPE_ADDR_SPACE (tt1);
   14911        69597 :           addr_space_t as_common = ADDR_SPACE_GENERIC;
   14912              : 
   14913              :           /* Anything compares with void *.  void * compares with anything.
   14914              :              Otherwise, the targets must be compatible
   14915              :              and both must be object or both incomplete.  */
   14916        69597 :           if (comp_target_types (location, type0, type1))
   14917        48265 :             result_type = common_pointer_type (type0, type1, NULL_TREE);
   14918        21332 :           else if (!addr_space_superset (as0, as1, &as_common))
   14919              :             {
   14920            0 :               error_at (location, "comparison of pointers to "
   14921              :                         "disjoint address spaces");
   14922            0 :               return error_mark_node;
   14923              :             }
   14924        21332 :           else if (VOID_TYPE_P (tt0) && !TYPE_ATOMIC (tt0))
   14925              :             {
   14926        21105 :               if (pedantic && TREE_CODE (tt1) == FUNCTION_TYPE)
   14927            4 :                 pedwarn (location, OPT_Wpedantic, "ISO C forbids "
   14928              :                          "comparison of %<void *%> with function pointer");
   14929              :             }
   14930          227 :           else if (VOID_TYPE_P (tt1) && !TYPE_ATOMIC (tt1))
   14931              :             {
   14932          179 :               if (pedantic && TREE_CODE (tt0) == FUNCTION_TYPE)
   14933            4 :                 pedwarn (location, OPT_Wpedantic, "ISO C forbids "
   14934              :                          "comparison of %<void *%> with function pointer");
   14935              :             }
   14936              :           else
   14937              :             /* Avoid warning about the volatile ObjC EH puts on decls.  */
   14938           48 :             if (!objc_ok)
   14939           48 :               pedwarn (location, OPT_Wcompare_distinct_pointer_types,
   14940              :                        "comparison of distinct pointer types lacks a cast");
   14941              : 
   14942        48321 :           if (result_type == NULL_TREE)
   14943              :             {
   14944        21332 :               int qual = ENCODE_QUAL_ADDR_SPACE (as_common);
   14945        21332 :               result_type = c_build_pointer_type
   14946        21332 :                               (c_build_qualified_type (void_type_node, qual));
   14947              :             }
   14948              :         }
   14949           90 :       else if (code0 == POINTER_TYPE
   14950           26 :                && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
   14951              :         {
   14952           26 :           result_type = type0;
   14953           26 :           pedwarn (location, 0, "comparison between pointer and integer");
   14954              :         }
   14955           64 :       else if ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE)
   14956           21 :                && code1 == POINTER_TYPE)
   14957              :         {
   14958            8 :           result_type = type1;
   14959            8 :           pedwarn (location, 0, "comparison between pointer and integer");
   14960              :         }
   14961              :       /* 6.5.9: One of the following shall hold:
   14962              :          -- both operands have type nullptr_t;  */
   14963           56 :       else if (code0 == NULLPTR_TYPE && code1 == NULLPTR_TYPE)
   14964              :         {
   14965           22 :           result_type = nullptr_type_node;
   14966              :           /* No need to convert the operands to result_type later.  */
   14967           22 :           converted = 1;
   14968              :         }
   14969              :     /* -- one operand has type nullptr_t and the other is a null pointer
   14970              :        constant.  We will have to convert the former to the type of the
   14971              :        latter, because during gimplification we can't have mismatching
   14972              :        comparison operand type.  We convert from nullptr_t to the other
   14973              :        type, since only nullptr_t can be converted to nullptr_t.  Also,
   14974              :        even a constant 0 is a null pointer constant, so we may have to
   14975              :        create a pointer type from its type.  */
   14976           34 :       else if (code0 == NULLPTR_TYPE && null_pointer_constant_p (orig_op1))
   14977           19 :         result_type = (INTEGRAL_TYPE_P (type1)
   14978           19 :                        ? c_build_pointer_type (type1) : type1);
   14979           15 :       else if (code1 == NULLPTR_TYPE && null_pointer_constant_p (orig_op0))
   14980           11 :         result_type = (INTEGRAL_TYPE_P (type0)
   14981           11 :                        ? c_build_pointer_type (type0) : type0);
   14982      5030165 :       if ((C_BOOLEAN_TYPE_P (TREE_TYPE (orig_op0))
   14983      3328506 :            || truth_value_p (TREE_CODE (orig_op0)))
   14984      3395984 :           ^ (C_BOOLEAN_TYPE_P (TREE_TYPE (orig_op1))
   14985      3395980 :              || truth_value_p (TREE_CODE (orig_op1))))
   14986        71701 :         maybe_warn_bool_compare (location, code, orig_op0, orig_op1);
   14987              :       break;
   14988              : 
   14989       998588 :     case LE_EXPR:
   14990       998588 :     case GE_EXPR:
   14991       998588 :     case LT_EXPR:
   14992       998588 :     case GT_EXPR:
   14993       998588 :       if (gnu_vector_type_p (type0) && gnu_vector_type_p (type1))
   14994              :         {
   14995        59154 :           tree intt;
   14996        59154 :           if (!vector_types_compatible_elements_p (type0, type1))
   14997              :             {
   14998            5 :               error_at (location, "comparing vectors with different "
   14999              :                                   "element types");
   15000            5 :               return error_mark_node;
   15001              :             }
   15002              : 
   15003        59149 :           if (maybe_ne (TYPE_VECTOR_SUBPARTS (type0),
   15004       118298 :                         TYPE_VECTOR_SUBPARTS (type1)))
   15005              :             {
   15006            0 :               error_at (location, "comparing vectors with different "
   15007              :                                   "number of elements");
   15008            0 :               return error_mark_node;
   15009              :             }
   15010              : 
   15011              :           /* It's not precisely specified how the usual arithmetic
   15012              :              conversions apply to the vector types.  Here, we use
   15013              :              the unsigned type if one of the operands is signed and
   15014              :              the other one is unsigned.  */
   15015        59149 :           if (TYPE_UNSIGNED (type0) != TYPE_UNSIGNED (type1))
   15016              :             {
   15017           15 :               if (!TYPE_UNSIGNED (type0))
   15018            8 :                 op0 = build1 (VIEW_CONVERT_EXPR, type1, op0);
   15019              :               else
   15020            7 :                 op1 = build1 (VIEW_CONVERT_EXPR, type0, op1);
   15021           15 :               warning_at (location, OPT_Wsign_compare, "comparison between "
   15022              :                           "types %qT and %qT", type0, type1);
   15023              :             }
   15024              : 
   15025              :           /* Always construct signed integer vector type.  */
   15026       177447 :           intt = c_common_type_for_size (GET_MODE_BITSIZE
   15027       118298 :                                          (SCALAR_TYPE_MODE
   15028              :                                           (TREE_TYPE (type0))), 0);
   15029        59149 :           if (!intt)
   15030              :             {
   15031            0 :               error_at (location, "could not find an integer type "
   15032              :                                   "of the same size as %qT",
   15033            0 :                         TREE_TYPE (type0));
   15034            0 :               return error_mark_node;
   15035              :             }
   15036        59149 :           result_type = build_opaque_vector_type (intt,
   15037        59149 :                                                   TYPE_VECTOR_SUBPARTS (type0));
   15038        59149 :           converted = 1;
   15039        59149 :           ret = build_vec_cmp (resultcode, result_type, op0, op1);
   15040        59149 :           goto return_build_binary_op;
   15041              :         }
   15042       939434 :       build_type = integer_type_node;
   15043       939434 :       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
   15044        64978 :            || code0 == BITINT_TYPE || code0 == FIXED_POINT_TYPE)
   15045       875003 :           && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
   15046              :               || code1 == BITINT_TYPE || code1 == FIXED_POINT_TYPE))
   15047              :         short_compare = 1;
   15048        64463 :       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
   15049              :         {
   15050        64396 :           addr_space_t as0 = TYPE_ADDR_SPACE (TREE_TYPE (type0));
   15051        64396 :           addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (type1));
   15052        64396 :           addr_space_t as_common;
   15053              : 
   15054        64396 :           if (comp_target_types (location, type0, type1))
   15055              :             {
   15056        64231 :               result_type = common_pointer_type (type0, type1, NULL_TREE);
   15057        64231 :               if (!COMPLETE_TYPE_P (TREE_TYPE (type0))
   15058        64231 :                   != !COMPLETE_TYPE_P (TREE_TYPE (type1)))
   15059           32 :                 pedwarn_c99 (location, OPT_Wpedantic,
   15060              :                              "comparison of complete and incomplete pointers");
   15061        64199 :               else if (TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE)
   15062            0 :                 pedwarn (location, OPT_Wpedantic, "ISO C forbids "
   15063              :                          "ordered comparisons of pointers to functions");
   15064        64199 :               else if (null_pointer_constant_p (orig_op0)
   15065        64199 :                        || null_pointer_constant_p (orig_op1))
   15066            8 :                 warning_at (location, OPT_Wextra,
   15067              :                             "ordered comparison of pointer with null pointer");
   15068              : 
   15069              :             }
   15070          165 :           else if (!addr_space_superset (as0, as1, &as_common))
   15071              :             {
   15072            0 :               error_at (location, "comparison of pointers to "
   15073              :                         "disjoint address spaces");
   15074            0 :               return error_mark_node;
   15075              :             }
   15076              :           else
   15077              :             {
   15078          165 :               int qual = ENCODE_QUAL_ADDR_SPACE (as_common);
   15079          165 :               result_type = c_build_pointer_type
   15080          165 :                               (c_build_qualified_type (void_type_node, qual));
   15081          165 :               pedwarn (location, OPT_Wcompare_distinct_pointer_types,
   15082              :                        "comparison of distinct pointer types lacks a cast");
   15083              :             }
   15084              :         }
   15085           67 :       else if (code0 == POINTER_TYPE && null_pointer_constant_p (orig_op1))
   15086              :         {
   15087           17 :           result_type = type0;
   15088           17 :           if (pedantic)
   15089           11 :             pedwarn (location, OPT_Wpedantic,
   15090              :                      "ordered comparison of pointer with integer zero");
   15091            6 :           else if (extra_warnings)
   15092            1 :             warning_at (location, OPT_Wextra,
   15093              :                         "ordered comparison of pointer with integer zero");
   15094              :         }
   15095           50 :       else if (code1 == POINTER_TYPE && null_pointer_constant_p (orig_op0))
   15096              :         {
   15097           12 :           result_type = type1;
   15098           12 :           if (pedantic)
   15099            2 :             pedwarn (location, OPT_Wpedantic,
   15100              :                      "ordered comparison of pointer with integer zero");
   15101           10 :           else if (extra_warnings)
   15102            1 :             warning_at (location, OPT_Wextra,
   15103              :                         "ordered comparison of pointer with integer zero");
   15104              :         }
   15105           38 :       else if (code0 == POINTER_TYPE
   15106           18 :                && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
   15107              :         {
   15108           18 :           result_type = type0;
   15109           18 :           pedwarn (location, 0, "comparison between pointer and integer");
   15110              :         }
   15111           20 :       else if ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE)
   15112           20 :                && code1 == POINTER_TYPE)
   15113              :         {
   15114           18 :           result_type = type1;
   15115           18 :           pedwarn (location, 0, "comparison between pointer and integer");
   15116              :         }
   15117              : 
   15118       939434 :       if ((code0 == POINTER_TYPE || code1 == POINTER_TYPE)
   15119        64461 :           && current_function_decl != NULL_TREE
   15120      1003884 :           && sanitize_flags_p (SANITIZE_POINTER_COMPARE))
   15121              :         {
   15122           35 :           op0 = save_expr (c_fully_fold (op0, false, NULL));
   15123           35 :           op1 = save_expr (c_fully_fold (op1, false, NULL));
   15124              : 
   15125           35 :           tree tt = builtin_decl_explicit (BUILT_IN_ASAN_POINTER_COMPARE);
   15126           35 :           instrument_expr = build_call_expr_loc (location, tt, 2, op0, op1);
   15127              :         }
   15128              : 
   15129      2818210 :       if ((C_BOOLEAN_TYPE_P (TREE_TYPE (orig_op0))
   15130      1878776 :            || truth_value_p (TREE_CODE (orig_op0)))
   15131      1878793 :           ^ (C_BOOLEAN_TYPE_P (TREE_TYPE (orig_op1))
   15132      1878793 :              || truth_value_p (TREE_CODE (orig_op1))))
   15133          517 :         maybe_warn_bool_compare (location, code, orig_op0, orig_op1);
   15134              :       break;
   15135              : 
   15136           43 :     case MIN_EXPR:
   15137           43 :     case MAX_EXPR:
   15138              :       /* Used for OpenMP atomics.  */
   15139           43 :       gcc_assert (flag_openmp);
   15140              :       common = 1;
   15141              :       break;
   15142              : 
   15143            0 :     default:
   15144            0 :       gcc_unreachable ();
   15145              :     }
   15146              : 
   15147     15501930 :   if (code0 == ERROR_MARK || code1 == ERROR_MARK)
   15148            0 :     return error_mark_node;
   15149              : 
   15150     15501930 :   if (gnu_vector_type_p (type0)
   15151      1479503 :       && gnu_vector_type_p (type1)
   15152     16980596 :       && (!tree_int_cst_equal (TYPE_SIZE (type0), TYPE_SIZE (type1))
   15153      1478646 :           || !vector_types_compatible_elements_p (type0, type1)))
   15154              :     {
   15155           26 :       gcc_rich_location richloc (location);
   15156           26 :       maybe_range_label_for_tree_type_mismatch
   15157           26 :         label_for_op0 (orig_op0, orig_op1),
   15158           26 :         label_for_op1 (orig_op1, orig_op0);
   15159           26 :       richloc.maybe_add_expr (orig_op0, &label_for_op0, highlight_colors::lhs);
   15160           26 :       richloc.maybe_add_expr (orig_op1, &label_for_op1, highlight_colors::rhs);
   15161           26 :       binary_op_error (&richloc, code, type0, type1);
   15162           26 :       return error_mark_node;
   15163           26 :     }
   15164              : 
   15165     15501904 :   if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE
   15166      1734515 :        || code0 == FIXED_POINT_TYPE || code0 == BITINT_TYPE
   15167      1665969 :        || gnu_vector_type_p (type0))
   15168     17049927 :       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE || code1 == COMPLEX_TYPE
   15169      1572706 :           || code1 == FIXED_POINT_TYPE || code1 == BITINT_TYPE
   15170      1480762 :           || gnu_vector_type_p (type1)))
   15171              :     {
   15172     15313295 :       bool first_complex = (code0 == COMPLEX_TYPE);
   15173     15313295 :       bool second_complex = (code1 == COMPLEX_TYPE);
   15174     15313295 :       int none_complex = (!first_complex && !second_complex);
   15175              : 
   15176     15313295 :       if (shorten || common || short_compare)
   15177              :         {
   15178     13766814 :           result_type = c_common_type (type0, type1);
   15179     13766814 :           do_warn_double_promotion (result_type, type0, type1,
   15180              :                                     "implicit conversion from %qT to %qT "
   15181              :                                     "to match other operand of binary "
   15182              :                                     "expression",
   15183              :                                     location);
   15184     13766814 :           if (result_type == error_mark_node)
   15185              :             return error_mark_node;
   15186              :         }
   15187              : 
   15188     15313273 :       if (first_complex != second_complex
   15189        82045 :           && (code == PLUS_EXPR
   15190              :               || code == MINUS_EXPR
   15191        82045 :               || code == MULT_EXPR
   15192        17526 :               || (code == TRUNC_DIV_EXPR && first_complex))
   15193        65933 :           && TREE_CODE (TREE_TYPE (result_type)) == REAL_TYPE
   15194     15375527 :           && flag_signed_zeros)
   15195              :         {
   15196              :           /* An operation on mixed real/complex operands must be
   15197              :              handled specially, but the language-independent code can
   15198              :              more easily optimize the plain complex arithmetic if
   15199              :              -fno-signed-zeros.  */
   15200        61942 :           tree real_type = TREE_TYPE (result_type);
   15201        61942 :           tree real, imag;
   15202        61942 :           if (type0 != orig_type0 || type1 != orig_type1)
   15203              :             {
   15204           94 :               gcc_assert (may_need_excess_precision && common);
   15205           94 :               semantic_result_type = c_common_type (orig_type0, orig_type1);
   15206              :             }
   15207        61942 :           if (first_complex)
   15208              :             {
   15209         8253 :               if (TREE_TYPE (op0) != result_type)
   15210         1787 :                 op0 = convert_and_check (location, result_type, op0);
   15211         8253 :               if (TREE_TYPE (op1) != real_type)
   15212         4601 :                 op1 = convert_and_check (location, real_type, op1);
   15213              :             }
   15214              :           else
   15215              :             {
   15216        53689 :               if (TREE_TYPE (op0) != real_type)
   15217         2698 :                 op0 = convert_and_check (location, real_type, op0);
   15218        53689 :               if (TREE_TYPE (op1) != result_type)
   15219         1866 :                 op1 = convert_and_check (location, result_type, op1);
   15220              :             }
   15221        61942 :           if (TREE_CODE (op0) == ERROR_MARK || TREE_CODE (op1) == ERROR_MARK)
   15222            0 :             return error_mark_node;
   15223        61942 :           if (first_complex)
   15224              :             {
   15225         8253 :               op0 = save_expr (op0);
   15226         8253 :               real = build_unary_op (EXPR_LOCATION (orig_op0), REALPART_EXPR,
   15227              :                                      op0, true);
   15228         8253 :               imag = build_unary_op (EXPR_LOCATION (orig_op0), IMAGPART_EXPR,
   15229              :                                      op0, true);
   15230         8253 :               switch (code)
   15231              :                 {
   15232         3488 :                 case MULT_EXPR:
   15233         3488 :                 case TRUNC_DIV_EXPR:
   15234         3488 :                   op1 = save_expr (op1);
   15235         3488 :                   imag = build2 (resultcode, real_type, imag, op1);
   15236              :                   /* Fall through.  */
   15237         8253 :                 case PLUS_EXPR:
   15238         8253 :                 case MINUS_EXPR:
   15239         8253 :                   real = build2 (resultcode, real_type, real, op1);
   15240         8253 :                   break;
   15241            0 :                 default:
   15242            0 :                   gcc_unreachable();
   15243              :                 }
   15244              :             }
   15245              :           else
   15246              :             {
   15247        53689 :               op1 = save_expr (op1);
   15248        53689 :               real = build_unary_op (EXPR_LOCATION (orig_op1), REALPART_EXPR,
   15249              :                                      op1, true);
   15250        53689 :               imag = build_unary_op (EXPR_LOCATION (orig_op1), IMAGPART_EXPR,
   15251              :                                      op1, true);
   15252        53689 :               switch (code)
   15253              :                 {
   15254         2008 :                 case MULT_EXPR:
   15255         2008 :                   op0 = save_expr (op0);
   15256         2008 :                   imag = build2 (resultcode, real_type, op0, imag);
   15257              :                   /* Fall through.  */
   15258        31957 :                 case PLUS_EXPR:
   15259        31957 :                   real = build2 (resultcode, real_type, op0, real);
   15260        31957 :                   break;
   15261        21732 :                 case MINUS_EXPR:
   15262        21732 :                   real = build2 (resultcode, real_type, op0, real);
   15263        21732 :                   imag = build1 (NEGATE_EXPR, real_type, imag);
   15264        21732 :                   break;
   15265            0 :                 default:
   15266            0 :                   gcc_unreachable();
   15267              :                 }
   15268              :             }
   15269        61942 :           ret = build2 (COMPLEX_EXPR, result_type, real, imag);
   15270        61942 :           goto return_build_binary_op;
   15271              :         }
   15272              : 
   15273              :       /* For certain operations (which identify themselves by shorten != 0)
   15274              :          if both args were extended from the same smaller type,
   15275              :          do the arithmetic in that type and then extend.
   15276              : 
   15277              :          shorten !=0 and !=1 indicates a bitwise operation.
   15278              :          For them, this optimization is safe only if
   15279              :          both args are zero-extended or both are sign-extended.
   15280              :          Otherwise, we might change the result.
   15281              :          Eg, (short)-1 | (unsigned short)-1 is (int)-1
   15282              :          but calculated in (unsigned short) it would be (unsigned short)-1.  */
   15283              : 
   15284     15251331 :       if (shorten && none_complex)
   15285              :         {
   15286      1295598 :           final_type = result_type;
   15287      1295598 :           result_type = shorten_binary_op (result_type, op0, op1,
   15288              :                                            shorten == -1);
   15289              :         }
   15290              : 
   15291              :       /* Shifts can be shortened if shifting right.  */
   15292              : 
   15293     15251331 :       if (short_shift)
   15294              :         {
   15295       200606 :           int unsigned_arg;
   15296       200606 :           tree arg0 = get_narrower (op0, &unsigned_arg);
   15297              : 
   15298       200606 :           final_type = result_type;
   15299              : 
   15300       200606 :           if (arg0 == op0 && final_type == TREE_TYPE (op0))
   15301       141123 :             unsigned_arg = TYPE_UNSIGNED (TREE_TYPE (op0));
   15302              : 
   15303       200606 :           if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type)
   15304         2990 :               && tree_int_cst_sgn (op1) > 0
   15305              :               /* We can shorten only if the shift count is less than the
   15306              :                  number of bits in the smaller type size.  */
   15307         2990 :               && compare_tree_int (op1, TYPE_PRECISION (TREE_TYPE (arg0))) < 0
   15308              :               /* We cannot drop an unsigned shift after sign-extension.  */
   15309       203456 :               && (!TYPE_UNSIGNED (final_type) || unsigned_arg))
   15310              :             {
   15311              :               /* Do an unsigned shift if the operand was zero-extended.  */
   15312         2835 :               result_type
   15313         2835 :                 = c_common_signed_or_unsigned_type (unsigned_arg,
   15314         2835 :                                                     TREE_TYPE (arg0));
   15315              :               /* Convert value-to-be-shifted to that type.  */
   15316         2835 :               if (TREE_TYPE (op0) != result_type)
   15317         2835 :                 op0 = convert (result_type, op0);
   15318              :               converted = 1;
   15319              :             }
   15320              :         }
   15321              : 
   15322              :       /* Comparison operations are shortened too but differently.
   15323              :          They identify themselves by setting short_compare = 1.  */
   15324              : 
   15325     15251331 :       if (short_compare)
   15326              :         {
   15327              :           /* Don't write &op0, etc., because that would prevent op0
   15328              :              from being kept in a register.
   15329              :              Instead, make copies of the our local variables and
   15330              :              pass the copies by reference, then copy them back afterward.  */
   15331      2454691 :           tree xop0 = op0, xop1 = op1, xresult_type = result_type;
   15332      2454691 :           enum tree_code xresultcode = resultcode;
   15333      2454691 :           tree val
   15334      2454691 :             = shorten_compare (location, &xop0, &xop1, &xresult_type,
   15335              :                                &xresultcode);
   15336              : 
   15337      2454691 :           if (val != NULL_TREE)
   15338              :             {
   15339        15793 :               ret = val;
   15340        15793 :               goto return_build_binary_op;
   15341              :             }
   15342              : 
   15343      2438898 :           op0 = xop0, op1 = xop1;
   15344      2438898 :           converted = 1;
   15345      2438898 :           resultcode = xresultcode;
   15346              : 
   15347      2438898 :           if (c_inhibit_evaluation_warnings == 0 && !c_in_omp_for)
   15348              :             {
   15349      2291093 :               bool op0_maybe_const = true;
   15350      2291093 :               bool op1_maybe_const = true;
   15351      2291093 :               tree orig_op0_folded, orig_op1_folded;
   15352              : 
   15353      2291093 :               if (in_late_binary_op)
   15354              :                 {
   15355              :                   orig_op0_folded = orig_op0;
   15356              :                   orig_op1_folded = orig_op1;
   15357              :                 }
   15358              :               else
   15359              :                 {
   15360              :                   /* Fold for the sake of possible warnings, as in
   15361              :                      build_conditional_expr.  This requires the
   15362              :                      "original" values to be folded, not just op0 and
   15363              :                      op1.  */
   15364      2282534 :                   c_inhibit_evaluation_warnings++;
   15365      2282534 :                   op0 = c_fully_fold (op0, require_constant_value,
   15366              :                                       &op0_maybe_const);
   15367      2282534 :                   op1 = c_fully_fold (op1, require_constant_value,
   15368              :                                       &op1_maybe_const);
   15369      2282534 :                   c_inhibit_evaluation_warnings--;
   15370      2282534 :                   orig_op0_folded = c_fully_fold (orig_op0,
   15371              :                                                   require_constant_value,
   15372              :                                                   NULL);
   15373      2282534 :                   orig_op1_folded = c_fully_fold (orig_op1,
   15374              :                                                   require_constant_value,
   15375              :                                                   NULL);
   15376              :                 }
   15377              : 
   15378      2291093 :               if (warn_sign_compare)
   15379       377089 :                 warn_for_sign_compare (location, orig_op0_folded,
   15380              :                                        orig_op1_folded, op0, op1,
   15381              :                                        result_type, resultcode);
   15382      2291093 :               if (!in_late_binary_op && !int_operands)
   15383              :                 {
   15384      2104516 :                   if (!op0_maybe_const || TREE_CODE (op0) != INTEGER_CST)
   15385      2101006 :                     op0 = c_wrap_maybe_const (op0, !op0_maybe_const);
   15386      2104516 :                   if (!op1_maybe_const || TREE_CODE (op1) != INTEGER_CST)
   15387       827815 :                     op1 = c_wrap_maybe_const (op1, !op1_maybe_const);
   15388              :                 }
   15389              :             }
   15390              :         }
   15391              :     }
   15392              : 
   15393              :   /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
   15394              :      If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
   15395              :      Then the expression will be built.
   15396              :      It will be given type FINAL_TYPE if that is nonzero;
   15397              :      otherwise, it will be given type RESULT_TYPE.  */
   15398              : 
   15399     15424147 :   if (!result_type)
   15400              :     {
   15401              :       /* Favor showing any expression locations that are available. */
   15402          514 :       op_location_t oploc (location, UNKNOWN_LOCATION);
   15403          514 :       binary_op_rich_location richloc (oploc, orig_op0, orig_op1, true);
   15404          514 :       binary_op_error (&richloc, code, TREE_TYPE (op0), TREE_TYPE (op1));
   15405          514 :       return error_mark_node;
   15406          514 :     }
   15407              : 
   15408     15423633 :   if (build_type == NULL_TREE)
   15409              :     {
   15410     12798366 :       build_type = result_type;
   15411     12798366 :       if ((type0 != orig_type0 || type1 != orig_type1)
   15412          797 :           && !boolean_op)
   15413              :         {
   15414          797 :           gcc_assert (may_need_excess_precision && common);
   15415          797 :           semantic_result_type = c_common_type (orig_type0, orig_type1);
   15416              :         }
   15417              :     }
   15418              : 
   15419     15423633 :   if (!converted)
   15420              :     {
   15421     11435266 :       op0 = ep_convert_and_check (location, result_type, op0,
   15422              :                                   semantic_result_type);
   15423     11435266 :       op1 = ep_convert_and_check (location, result_type, op1,
   15424              :                                   semantic_result_type);
   15425              : 
   15426              :       /* This can happen if one operand has a vector type, and the other
   15427              :          has a different type.  */
   15428     11435266 :       if (TREE_CODE (op0) == ERROR_MARK || TREE_CODE (op1) == ERROR_MARK)
   15429            3 :         return error_mark_node;
   15430              :     }
   15431              : 
   15432     15423630 :   if (sanitize_flags_p ((SANITIZE_SHIFT
   15433              :                          | SANITIZE_DIVIDE
   15434              :                          | SANITIZE_FLOAT_DIVIDE
   15435              :                          | SANITIZE_SI_OVERFLOW))
   15436        23386 :       && current_function_decl != NULL_TREE
   15437        19923 :       && (doing_div_or_mod || doing_shift)
   15438     15426555 :       && !require_constant_value)
   15439              :     {
   15440              :       /* OP0 and/or OP1 might have side-effects.  */
   15441         2869 :       op0 = save_expr (op0);
   15442         2869 :       op1 = save_expr (op1);
   15443         2869 :       op0 = c_fully_fold (op0, false, NULL);
   15444         2869 :       op1 = c_fully_fold (op1, false, NULL);
   15445         2869 :       if (doing_div_or_mod && (sanitize_flags_p ((SANITIZE_DIVIDE
   15446              :                                                   | SANITIZE_FLOAT_DIVIDE
   15447              :                                                   | SANITIZE_SI_OVERFLOW))))
   15448          912 :         instrument_expr = ubsan_instrument_division (location, op0, op1);
   15449         1957 :       else if (doing_shift && sanitize_flags_p (SANITIZE_SHIFT))
   15450         1777 :         instrument_expr = ubsan_instrument_shift (location, code, op0, op1);
   15451              :     }
   15452              : 
   15453              :   /* Treat expressions in initializers specially as they can't trap.  */
   15454     15423630 :   if (int_const_or_overflow)
   15455      7960011 :     ret = (require_constant_value
   15456      7960011 :            ? fold_build2_initializer_loc (location, resultcode, build_type,
   15457              :                                           op0, op1)
   15458      7913890 :            : fold_build2_loc (location, resultcode, build_type, op0, op1));
   15459              :   else
   15460      7463619 :     ret = build2 (resultcode, build_type, op0, op1);
   15461     15423630 :   if (final_type != NULL_TREE)
   15462      1496204 :     ret = convert (final_type, ret);
   15463              : 
   15464     13927426 :  return_build_binary_op:
   15465     16876649 :   gcc_assert (ret != error_mark_node);
   15466     16876649 :   if (TREE_CODE (ret) == INTEGER_CST && !TREE_OVERFLOW (ret) && !int_const)
   15467         1758 :     ret = (int_operands
   15468         1758 :            ? note_integer_operands (ret)
   15469          436 :            : build1 (NOP_EXPR, TREE_TYPE (ret), ret));
   15470     16874891 :   else if (TREE_CODE (ret) != INTEGER_CST && int_operands
   15471        60309 :            && !in_late_binary_op)
   15472        60309 :     ret = note_integer_operands (ret);
   15473     16876649 :   protected_set_expr_location (ret, location);
   15474              : 
   15475     16876649 :   if (instrument_expr != NULL)
   15476         1420 :     ret = fold_build2 (COMPOUND_EXPR, TREE_TYPE (ret),
   15477              :                        instrument_expr, ret);
   15478              : 
   15479     16876649 :   if (semantic_result_type)
   15480          891 :     ret = build1_loc (location, EXCESS_PRECISION_EXPR,
   15481              :                       semantic_result_type, ret);
   15482              : 
   15483              :   return ret;
   15484              : }
   15485              : 
   15486              : 
   15487              : /* Convert EXPR to be a truth-value (type TYPE), validating its type for this
   15488              :    purpose.  LOCATION is the source location for the expression.  */
   15489              : 
   15490              : tree
   15491      4141140 : c_objc_common_truthvalue_conversion (location_t location, tree expr, tree type)
   15492              : {
   15493      4141140 :   bool int_const, int_operands;
   15494              : 
   15495      4141140 :   switch (TREE_CODE (TREE_TYPE (expr)))
   15496              :     {
   15497           72 :     case ARRAY_TYPE:
   15498           72 :       error_at (location, "used array that cannot be converted to pointer where scalar is required");
   15499           72 :       return error_mark_node;
   15500              : 
   15501           86 :     case RECORD_TYPE:
   15502           86 :       error_at (location, "used struct type value where scalar is required");
   15503           86 :       return error_mark_node;
   15504              : 
   15505           83 :     case UNION_TYPE:
   15506           83 :       error_at (location, "used union type value where scalar is required");
   15507           83 :       return error_mark_node;
   15508              : 
   15509           22 :     case VOID_TYPE:
   15510           22 :       error_at (location, "void value not ignored as it ought to be");
   15511           22 :       return error_mark_node;
   15512              : 
   15513        31030 :     case POINTER_TYPE:
   15514        31030 :       if (reject_gcc_builtin (expr))
   15515            3 :         return error_mark_node;
   15516              :       break;
   15517              : 
   15518            0 :     case FUNCTION_TYPE:
   15519            0 :       gcc_unreachable ();
   15520              : 
   15521            8 :     case VECTOR_TYPE:
   15522            8 :       error_at (location, "used vector type where scalar is required");
   15523            8 :       return error_mark_node;
   15524              : 
   15525              :     default:
   15526              :       break;
   15527              :     }
   15528              : 
   15529              :   /* Conversion of a floating constant to boolean goes through here
   15530              :      and yields an integer constant expression.  Otherwise, the result
   15531              :      is only an integer constant expression if the argument is.  */
   15532       902469 :   int_const = ((TREE_CODE (expr) == INTEGER_CST && !TREE_OVERFLOW (expr))
   15533      4140942 :                || ((TREE_CODE (expr) == REAL_CST
   15534      3238099 :                     || TREE_CODE (expr) == COMPLEX_CST)
   15535          374 :                    && (TREE_CODE (type) == BOOLEAN_TYPE
   15536           15 :                        || (TREE_CODE (type) == ENUMERAL_TYPE
   15537            5 :                            && ENUM_UNDERLYING_TYPE (type) != NULL_TREE
   15538            5 :                            && (TREE_CODE (ENUM_UNDERLYING_TYPE (type))
   15539              :                                == BOOLEAN_TYPE)))));
   15540      4140866 :   int_operands = EXPR_INT_CONST_OPERANDS (expr);
   15541       902629 :   if (int_operands && TREE_CODE (expr) != INTEGER_CST)
   15542              :     {
   15543          319 :       expr = remove_c_maybe_const_expr (expr);
   15544          319 :       expr = build2 (NE_EXPR, type, expr,
   15545          319 :                      convert (TREE_TYPE (expr), integer_zero_node));
   15546          319 :       expr = note_integer_operands (expr);
   15547              :     }
   15548              :   else
   15549              :     {
   15550              :       /* ??? Should we also give an error for vectors rather than leaving
   15551              :          those to give errors later?  */
   15552      4140547 :       expr = c_common_truthvalue_conversion (location, expr);
   15553      4140547 :       expr = fold_convert_loc (location, type, expr);
   15554              :     }
   15555              : 
   15556      4140866 :   if (TREE_CODE (expr) == INTEGER_CST && int_operands && !int_const)
   15557              :     {
   15558           76 :       if (TREE_OVERFLOW (expr))
   15559              :         return expr;
   15560              :       else
   15561           76 :         return note_integer_operands (expr);
   15562              :     }
   15563      4140790 :   if (TREE_CODE (expr) == INTEGER_CST && !int_const)
   15564          754 :     return build1 (NOP_EXPR, TREE_TYPE (expr), expr);
   15565              :   return expr;
   15566              : }
   15567              : 
   15568              : 
   15569              : /* Convert EXPR to a contained DECL, updating *TC, *TI and *SE as
   15570              :    required.  */
   15571              : 
   15572              : tree
   15573    125222467 : c_expr_to_decl (tree expr, bool *tc ATTRIBUTE_UNUSED, bool *se)
   15574              : {
   15575    125222467 :   if (TREE_CODE (expr) == COMPOUND_LITERAL_EXPR)
   15576              :     {
   15577          699 :       tree decl = COMPOUND_LITERAL_EXPR_DECL (expr);
   15578              :       /* Executing a compound literal inside a function reinitializes
   15579              :          it.  */
   15580          699 :       if (!TREE_STATIC (decl))
   15581          433 :         *se = true;
   15582          699 :       return decl;
   15583              :     }
   15584              :   else
   15585              :     return expr;
   15586              : }
   15587              : 
   15588              : /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
   15589              :    statement.  LOC is the location of the construct.  */
   15590              : 
   15591              : tree
   15592         2154 : c_finish_omp_construct (location_t loc, enum tree_code code, tree body,
   15593              :                         tree clauses)
   15594              : {
   15595         2154 :   body = c_end_compound_stmt (loc, body, true);
   15596              : 
   15597         2154 :   tree stmt = make_node (code);
   15598         2154 :   TREE_TYPE (stmt) = void_type_node;
   15599         2154 :   OMP_BODY (stmt) = body;
   15600         2154 :   OMP_CLAUSES (stmt) = clauses;
   15601         2154 :   SET_EXPR_LOCATION (stmt, loc);
   15602              : 
   15603         2154 :   return add_stmt (stmt);
   15604              : }
   15605              : 
   15606              : /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
   15607              :    statement.  LOC is the location of the OACC_DATA.  */
   15608              : 
   15609              : tree
   15610          497 : c_finish_oacc_data (location_t loc, tree clauses, tree block)
   15611              : {
   15612          497 :   tree stmt;
   15613              : 
   15614          497 :   block = c_end_compound_stmt (loc, block, true);
   15615              : 
   15616          497 :   stmt = make_node (OACC_DATA);
   15617          497 :   TREE_TYPE (stmt) = void_type_node;
   15618          497 :   OACC_DATA_CLAUSES (stmt) = clauses;
   15619          497 :   OACC_DATA_BODY (stmt) = block;
   15620          497 :   SET_EXPR_LOCATION (stmt, loc);
   15621              : 
   15622          497 :   return add_stmt (stmt);
   15623              : }
   15624              : 
   15625              : /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
   15626              :    statement.  LOC is the location of the OACC_HOST_DATA.  */
   15627              : 
   15628              : tree
   15629           21 : c_finish_oacc_host_data (location_t loc, tree clauses, tree block)
   15630              : {
   15631           21 :   tree stmt;
   15632              : 
   15633           21 :   block = c_end_compound_stmt (loc, block, true);
   15634              : 
   15635           21 :   stmt = make_node (OACC_HOST_DATA);
   15636           21 :   TREE_TYPE (stmt) = void_type_node;
   15637           21 :   OACC_HOST_DATA_CLAUSES (stmt) = clauses;
   15638           21 :   OACC_HOST_DATA_BODY (stmt) = block;
   15639           21 :   SET_EXPR_LOCATION (stmt, loc);
   15640              : 
   15641           21 :   return add_stmt (stmt);
   15642              : }
   15643              : 
   15644              : /* Like c_begin_compound_stmt, except force the retention of the BLOCK.  */
   15645              : 
   15646              : tree
   15647        12003 : c_begin_omp_parallel (void)
   15648              : {
   15649        12003 :   tree block;
   15650              : 
   15651        12003 :   keep_next_level ();
   15652        12003 :   block = c_begin_compound_stmt (true);
   15653              : 
   15654        12003 :   return block;
   15655              : }
   15656              : 
   15657              : /* Generate OMP_PARALLEL, with CLAUSES and BLOCK as its compound
   15658              :    statement.  LOC is the location of the OMP_PARALLEL.  */
   15659              : 
   15660              : tree
   15661         5677 : c_finish_omp_parallel (location_t loc, tree clauses, tree block)
   15662              : {
   15663         5677 :   tree stmt;
   15664              : 
   15665         5677 :   block = c_end_compound_stmt (loc, block, true);
   15666              : 
   15667         5677 :   stmt = make_node (OMP_PARALLEL);
   15668         5677 :   TREE_TYPE (stmt) = void_type_node;
   15669         5677 :   OMP_PARALLEL_CLAUSES (stmt) = clauses;
   15670         5677 :   OMP_PARALLEL_BODY (stmt) = block;
   15671         5677 :   SET_EXPR_LOCATION (stmt, loc);
   15672              : 
   15673         5677 :   return add_stmt (stmt);
   15674              : }
   15675              : 
   15676              : /* Like c_begin_compound_stmt, except force the retention of the BLOCK.  */
   15677              : 
   15678              : tree
   15679          898 : c_begin_omp_task (void)
   15680              : {
   15681          898 :   tree block;
   15682              : 
   15683          898 :   keep_next_level ();
   15684          898 :   block = c_begin_compound_stmt (true);
   15685              : 
   15686          898 :   return block;
   15687              : }
   15688              : 
   15689              : /* Generate OMP_TASK, with CLAUSES and BLOCK as its compound
   15690              :    statement.  LOC is the location of the #pragma.  */
   15691              : 
   15692              : tree
   15693          898 : c_finish_omp_task (location_t loc, tree clauses, tree block)
   15694              : {
   15695          898 :   tree stmt;
   15696              : 
   15697          898 :   block = c_end_compound_stmt (loc, block, true);
   15698              : 
   15699          898 :   stmt = make_node (OMP_TASK);
   15700          898 :   TREE_TYPE (stmt) = void_type_node;
   15701          898 :   OMP_TASK_CLAUSES (stmt) = clauses;
   15702          898 :   OMP_TASK_BODY (stmt) = block;
   15703          898 :   SET_EXPR_LOCATION (stmt, loc);
   15704              : 
   15705          898 :   return add_stmt (stmt);
   15706              : }
   15707              : 
   15708              : /* Generate GOMP_cancel call for #pragma omp cancel.  */
   15709              : 
   15710              : void
   15711          213 : c_finish_omp_cancel (location_t loc, tree clauses)
   15712              : {
   15713          213 :   tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL);
   15714          213 :   int mask = 0;
   15715          213 :   if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
   15716              :     mask = 1;
   15717          150 :   else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
   15718              :     mask = 2;
   15719          101 :   else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
   15720              :     mask = 4;
   15721           58 :   else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
   15722              :     mask = 8;
   15723              :   else
   15724              :     {
   15725            0 :       error_at (loc, "%<#pragma omp cancel%> must specify one of "
   15726              :                      "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> "
   15727              :                      "clauses");
   15728            0 :       return;
   15729              :     }
   15730          213 :   tree ifc = omp_find_clause (clauses, OMP_CLAUSE_IF);
   15731          213 :   if (ifc != NULL_TREE)
   15732              :     {
   15733           31 :       if (OMP_CLAUSE_IF_MODIFIER (ifc) != ERROR_MARK
   15734           31 :           && OMP_CLAUSE_IF_MODIFIER (ifc) != VOID_CST)
   15735            2 :         error_at (OMP_CLAUSE_LOCATION (ifc),
   15736              :                   "expected %<cancel%> %<if%> clause modifier");
   15737              :       else
   15738              :         {
   15739           29 :           tree ifc2 = omp_find_clause (OMP_CLAUSE_CHAIN (ifc), OMP_CLAUSE_IF);
   15740           29 :           if (ifc2 != NULL_TREE)
   15741              :             {
   15742            1 :               gcc_assert (OMP_CLAUSE_IF_MODIFIER (ifc) == VOID_CST
   15743              :                           && OMP_CLAUSE_IF_MODIFIER (ifc2) != ERROR_MARK
   15744              :                           && OMP_CLAUSE_IF_MODIFIER (ifc2) != VOID_CST);
   15745            1 :               error_at (OMP_CLAUSE_LOCATION (ifc2),
   15746              :                         "expected %<cancel%> %<if%> clause modifier");
   15747              :             }
   15748              :         }
   15749              : 
   15750           31 :       tree type = TREE_TYPE (OMP_CLAUSE_IF_EXPR (ifc));
   15751           62 :       ifc = fold_build2_loc (OMP_CLAUSE_LOCATION (ifc), NE_EXPR,
   15752           31 :                              boolean_type_node, OMP_CLAUSE_IF_EXPR (ifc),
   15753              :                              build_zero_cst (type));
   15754              :     }
   15755              :   else
   15756          182 :     ifc = boolean_true_node;
   15757          213 :   tree stmt = build_call_expr_loc (loc, fn, 2,
   15758          213 :                                    build_int_cst (integer_type_node, mask),
   15759              :                                    ifc);
   15760          213 :   add_stmt (stmt);
   15761              : }
   15762              : 
   15763              : /* Generate GOMP_cancellation_point call for
   15764              :    #pragma omp cancellation point.  */
   15765              : 
   15766              : void
   15767          167 : c_finish_omp_cancellation_point (location_t loc, tree clauses)
   15768              : {
   15769          167 :   tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT);
   15770          167 :   int mask = 0;
   15771          167 :   if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
   15772              :     mask = 1;
   15773          123 :   else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
   15774              :     mask = 2;
   15775           88 :   else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
   15776              :     mask = 4;
   15777           53 :   else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
   15778              :     mask = 8;
   15779              :   else
   15780              :     {
   15781            1 :       error_at (loc, "%<#pragma omp cancellation point%> must specify one of "
   15782              :                      "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> "
   15783              :                      "clauses");
   15784            1 :       return;
   15785              :     }
   15786          166 :   tree stmt = build_call_expr_loc (loc, fn, 1,
   15787          166 :                                    build_int_cst (integer_type_node, mask));
   15788          166 :   add_stmt (stmt);
   15789              : }
   15790              : 
   15791              : /* Helper function for handle_omp_array_sections.  Called recursively
   15792              :    to handle multiple array-section-subscripts.  C is the clause,
   15793              :    T current expression (initially OMP_CLAUSE_DECL), which is either
   15794              :    a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
   15795              :    expression if specified, TREE_VALUE length expression if specified,
   15796              :    TREE_CHAIN is what it has been specified after, or some decl.
   15797              :    TYPES vector is populated with array section types, MAYBE_ZERO_LEN
   15798              :    set to true if any of the array-section-subscript could have length
   15799              :    of zero (explicit or implicit), FIRST_NON_ONE is the index of the
   15800              :    first array-section-subscript which is known not to have length
   15801              :    of one.  Given say:
   15802              :    map(a[:b][2:1][:c][:2][:d][e:f][2:5])
   15803              :    FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
   15804              :    all are or may have length of 1, array-section-subscript [:2] is the
   15805              :    first one known not to have length 1.  For array-section-subscript
   15806              :    <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
   15807              :    0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
   15808              :    can if MAYBE_ZERO_LEN is false.  MAYBE_ZERO_LEN will be true in the above
   15809              :    case though, as some lengths could be zero.  */
   15810              : 
   15811              : static tree
   15812         6394 : handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types,
   15813              :                              bool &maybe_zero_len, unsigned int &first_non_one,
   15814              :                              enum c_omp_region_type ort)
   15815              : {
   15816         6394 :   tree ret, low_bound, length, type;
   15817         6394 :   bool openacc = (ort & C_ORT_ACC) != 0;
   15818         6394 :   if (TREE_CODE (t) != OMP_ARRAY_SECTION)
   15819              :     {
   15820         2978 :       if (error_operand_p (t))
   15821            2 :         return error_mark_node;
   15822         2976 :       c_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
   15823         2976 :       ret = t;
   15824         2976 :       if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
   15825         2877 :           && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
   15826         5539 :           && TYPE_ATOMIC (strip_array_types (TREE_TYPE (t))))
   15827              :         {
   15828            6 :           error_at (OMP_CLAUSE_LOCATION (c), "%<_Atomic%> %qE in %qs clause",
   15829            6 :                     t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   15830            6 :           return error_mark_node;
   15831              :         }
   15832         2970 :       if (!ai.check_clause (c))
   15833            0 :         return error_mark_node;
   15834         2970 :       else if (ai.component_access_p ()
   15835         3271 :                && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   15836           15 :                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO
   15837           11 :                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM))
   15838          301 :         t = ai.get_root_term (true);
   15839              :       else
   15840         2669 :         t = ai.unconverted_ref_origin ();
   15841         2970 :       if (t == error_mark_node)
   15842              :         return error_mark_node;
   15843         2970 :       if (!VAR_P (t)
   15844          741 :           && (ort == C_ORT_ACC || !EXPR_P (t))
   15845          738 :           && TREE_CODE (t) != PARM_DECL)
   15846              :         {
   15847            5 :           if (DECL_P (t))
   15848            5 :             error_at (OMP_CLAUSE_LOCATION (c),
   15849              :                       "%qD is not a variable in %qs clause", t,
   15850            5 :                       omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   15851              :           else
   15852            0 :             error_at (OMP_CLAUSE_LOCATION (c),
   15853              :                       "%qE is not a variable in %qs clause", t,
   15854            0 :                       omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   15855            5 :           return error_mark_node;
   15856              :         }
   15857         2965 :       else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
   15858         2867 :                && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
   15859         5519 :                && TYPE_ATOMIC (TREE_TYPE (t)))
   15860              :         {
   15861            0 :           error_at (OMP_CLAUSE_LOCATION (c), "%<_Atomic%> %qD in %qs clause",
   15862            0 :                     t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   15863            0 :           return error_mark_node;
   15864              :         }
   15865         2965 :       else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
   15866         2867 :                && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
   15867         2554 :                && VAR_P (t)
   15868         4971 :                && DECL_THREAD_LOCAL_P (t))
   15869              :         {
   15870            3 :           error_at (OMP_CLAUSE_LOCATION (c),
   15871              :                     "%qD is threadprivate variable in %qs clause", t,
   15872            3 :                     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   15873            3 :           return error_mark_node;
   15874              :         }
   15875         2962 :       if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
   15876         2864 :            || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND)
   15877          411 :           && TYPE_ATOMIC (TREE_TYPE (t))
   15878         2964 :           && POINTER_TYPE_P (TREE_TYPE (t)))
   15879              :         {
   15880              :           /* If the array section is pointer based and the pointer
   15881              :              itself is _Atomic qualified, we need to atomically load
   15882              :              the pointer.  */
   15883            2 :           ret = convert_lvalue_to_rvalue (OMP_CLAUSE_LOCATION (c),
   15884              :                                           ret, false, false);
   15885              :         }
   15886         2962 :       return ret;
   15887         2976 :     }
   15888              : 
   15889         3416 :   ret = handle_omp_array_sections_1 (c, TREE_OPERAND (t, 0), types,
   15890              :                                      maybe_zero_len, first_non_one, ort);
   15891         3416 :   if (ret == error_mark_node || ret == NULL_TREE)
   15892              :     return ret;
   15893              : 
   15894         3351 :   type = TREE_TYPE (ret);
   15895         3351 :   low_bound = TREE_OPERAND (t, 1);
   15896         3351 :   length = TREE_OPERAND (t, 2);
   15897              : 
   15898         3351 :   if (low_bound == error_mark_node || length == error_mark_node)
   15899              :     return error_mark_node;
   15900              : 
   15901         3351 :   if (low_bound && !INTEGRAL_TYPE_P (TREE_TYPE (low_bound)))
   15902              :     {
   15903           13 :       error_at (OMP_CLAUSE_LOCATION (c),
   15904              :                 "low bound %qE of array section does not have integral type",
   15905              :                 low_bound);
   15906           13 :       return error_mark_node;
   15907              :     }
   15908         3338 :   if (length && !INTEGRAL_TYPE_P (TREE_TYPE (length)))
   15909              :     {
   15910           12 :       error_at (OMP_CLAUSE_LOCATION (c),
   15911              :                 "length %qE of array section does not have integral type",
   15912              :                 length);
   15913           12 :       return error_mark_node;
   15914              :     }
   15915         3326 :   if (low_bound
   15916         2742 :       && TREE_CODE (low_bound) == INTEGER_CST
   15917         5779 :       && TYPE_PRECISION (TREE_TYPE (low_bound))
   15918         2453 :          > TYPE_PRECISION (sizetype))
   15919            0 :     low_bound = fold_convert (sizetype, low_bound);
   15920         3326 :   if (length
   15921         3138 :       && TREE_CODE (length) == INTEGER_CST
   15922         5519 :       && TYPE_PRECISION (TREE_TYPE (length))
   15923         2193 :          > TYPE_PRECISION (sizetype))
   15924            0 :     length = fold_convert (sizetype, length);
   15925         3326 :   if (low_bound == NULL_TREE)
   15926          584 :     low_bound = integer_zero_node;
   15927         3326 :   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   15928         3326 :       && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
   15929         1936 :           || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH))
   15930              :     {
   15931           10 :       if (length != integer_one_node)
   15932              :         {
   15933            6 :           error_at (OMP_CLAUSE_LOCATION (c),
   15934              :                     "expected single pointer in %qs clause",
   15935              :                     user_omp_clause_code_name (c, openacc));
   15936            6 :           return error_mark_node;
   15937              :         }
   15938              :     }
   15939         3320 :   if (length != NULL_TREE)
   15940              :     {
   15941         3136 :       if (!integer_nonzerop (length))
   15942              :         {
   15943          974 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
   15944              :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   15945              :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   15946              :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   15947              :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
   15948              :             {
   15949          180 :               if (integer_zerop (length))
   15950              :                 {
   15951           12 :                   error_at (OMP_CLAUSE_LOCATION (c),
   15952              :                             "zero length array section in %qs clause",
   15953           12 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   15954           12 :                   return error_mark_node;
   15955              :                 }
   15956              :             }
   15957              :           else
   15958          794 :             maybe_zero_len = true;
   15959              :         }
   15960         3124 :       if (first_non_one == types.length ()
   15961         3124 :           && (TREE_CODE (length) != INTEGER_CST || integer_onep (length)))
   15962         1597 :         first_non_one++;
   15963              :     }
   15964         3308 :   if (TREE_CODE (type) == ARRAY_TYPE)
   15965              :     {
   15966         1496 :       if (length == NULL_TREE
   15967         1496 :           && (TYPE_DOMAIN (type) == NULL_TREE
   15968          168 :               || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE))
   15969              :         {
   15970            8 :           error_at (OMP_CLAUSE_LOCATION (c),
   15971              :                     "for unknown bound array type length expression must "
   15972              :                     "be specified");
   15973            8 :           return error_mark_node;
   15974              :         }
   15975         1488 :       if (TREE_CODE (low_bound) == INTEGER_CST
   15976         1488 :           && tree_int_cst_sgn (low_bound) == -1)
   15977              :         {
   15978           35 :           error_at (OMP_CLAUSE_LOCATION (c),
   15979              :                     "negative low bound in array section in %qs clause",
   15980           35 :                     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   15981           35 :           return error_mark_node;
   15982              :         }
   15983         1453 :       if (length != NULL_TREE
   15984         1297 :           && TREE_CODE (length) == INTEGER_CST
   15985         2310 :           && tree_int_cst_sgn (length) == -1)
   15986              :         {
   15987           35 :           error_at (OMP_CLAUSE_LOCATION (c),
   15988              :                     "negative length in array section in %qs clause",
   15989           35 :                     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   15990           35 :           return error_mark_node;
   15991              :         }
   15992         1418 :       if (TYPE_DOMAIN (type)
   15993         1407 :           && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
   15994         2825 :           && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
   15995              :                         == INTEGER_CST)
   15996              :         {
   15997         1061 :           tree size
   15998         1061 :             = fold_convert (sizetype, TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
   15999         1061 :           size = size_binop (PLUS_EXPR, size, size_one_node);
   16000         1061 :           if (TREE_CODE (low_bound) == INTEGER_CST)
   16001              :             {
   16002          874 :               if (tree_int_cst_lt (size, low_bound))
   16003              :                 {
   16004           10 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16005              :                             "low bound %qE above array section size "
   16006              :                             "in %qs clause", low_bound,
   16007           10 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16008           10 :                   return error_mark_node;
   16009              :                 }
   16010          864 :               if (tree_int_cst_equal (size, low_bound))
   16011              :                 {
   16012            5 :                   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
   16013              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   16014              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   16015              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   16016              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
   16017              :                     {
   16018            5 :                       error_at (OMP_CLAUSE_LOCATION (c),
   16019              :                                 "zero length array section in %qs clause",
   16020            5 :                                 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16021            5 :                       return error_mark_node;
   16022              :                     }
   16023            0 :                   maybe_zero_len = true;
   16024              :                 }
   16025          859 :               else if (length == NULL_TREE
   16026          256 :                        && first_non_one == types.length ()
   16027          914 :                        && tree_int_cst_equal
   16028           55 :                             (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
   16029              :                              low_bound))
   16030           30 :                 first_non_one++;
   16031              :             }
   16032          187 :           else if (length == NULL_TREE)
   16033              :             {
   16034            3 :               if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
   16035              :                   && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
   16036              :                   && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
   16037              :                   && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
   16038              :                   && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
   16039            0 :                 maybe_zero_len = true;
   16040            6 :               if (first_non_one == types.length ())
   16041            1 :                 first_non_one++;
   16042              :             }
   16043         1046 :           if (length && TREE_CODE (length) == INTEGER_CST)
   16044              :             {
   16045          799 :               if (tree_int_cst_lt (size, length))
   16046              :                 {
   16047           11 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16048              :                             "length %qE above array section size "
   16049              :                             "in %qs clause", length,
   16050           11 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16051           11 :                   return error_mark_node;
   16052              :                 }
   16053          788 :               if (TREE_CODE (low_bound) == INTEGER_CST)
   16054              :                 {
   16055          688 :                   tree lbpluslen
   16056          688 :                     = size_binop (PLUS_EXPR,
   16057              :                                   fold_convert (sizetype, low_bound),
   16058              :                                   fold_convert (sizetype, length));
   16059          688 :                   if (TREE_CODE (lbpluslen) == INTEGER_CST
   16060          688 :                       && tree_int_cst_lt (size, lbpluslen))
   16061              :                     {
   16062           10 :                       error_at (OMP_CLAUSE_LOCATION (c),
   16063              :                                 "high bound %qE above array section size "
   16064              :                                 "in %qs clause", lbpluslen,
   16065           10 :                                 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16066           10 :                       return error_mark_node;
   16067              :                     }
   16068              :                 }
   16069              :             }
   16070              :         }
   16071          357 :       else if (length == NULL_TREE)
   16072              :         {
   16073           10 :           if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
   16074              :               && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
   16075              :               && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
   16076              :               && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
   16077              :               && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
   16078            0 :             maybe_zero_len = true;
   16079           20 :           if (first_non_one == types.length ())
   16080           10 :             first_non_one++;
   16081              :         }
   16082              : 
   16083              :       /* For [lb:] we will need to evaluate lb more than once.  */
   16084          929 :       if (length == NULL_TREE && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
   16085              :         {
   16086          127 :           tree lb = save_expr (low_bound);
   16087          127 :           if (lb != low_bound)
   16088              :             {
   16089            2 :               TREE_OPERAND (t, 1) = lb;
   16090            2 :               low_bound = lb;
   16091              :             }
   16092              :         }
   16093              :     }
   16094         1812 :   else if (TREE_CODE (type) == POINTER_TYPE)
   16095              :     {
   16096         1801 :       if (length == NULL_TREE)
   16097              :         {
   16098           10 :           if (TREE_CODE (ret) == PARM_DECL && C_ARRAY_PARAMETER (ret))
   16099            8 :             error_at (OMP_CLAUSE_LOCATION (c),
   16100              :                       "for array function parameter length expression "
   16101              :                       "must be specified");
   16102              :           else
   16103            2 :             error_at (OMP_CLAUSE_LOCATION (c),
   16104              :                       "for pointer type length expression must be specified");
   16105           10 :           return error_mark_node;
   16106              :         }
   16107         1791 :       if (length != NULL_TREE
   16108         1791 :           && TREE_CODE (length) == INTEGER_CST
   16109         1286 :           && tree_int_cst_sgn (length) == -1)
   16110              :         {
   16111           20 :           error_at (OMP_CLAUSE_LOCATION (c),
   16112              :                     "negative length in array section in %qs clause",
   16113           20 :                     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16114           20 :           return error_mark_node;
   16115              :         }
   16116              :       /* If there is a pointer type anywhere but in the very first
   16117              :          array-section-subscript, the array section could be non-contiguous.  */
   16118         1771 :       if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
   16119         1610 :           && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
   16120         3352 :           && TREE_CODE (TREE_OPERAND (t, 0)) == OMP_ARRAY_SECTION)
   16121              :         {
   16122              :           /* If any prior dimension has a non-one length, then deem this
   16123              :              array section as non-contiguous.  */
   16124           42 :           for (tree d = TREE_OPERAND (t, 0);
   16125           82 :                TREE_CODE (d) == OMP_ARRAY_SECTION;
   16126           40 :                d = TREE_OPERAND (d, 0))
   16127              :             {
   16128           44 :               tree d_length = TREE_OPERAND (d, 2);
   16129           44 :               if (d_length == NULL_TREE || !integer_onep (d_length))
   16130              :                 {
   16131            4 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16132              :                             "array section is not contiguous in %qs clause",
   16133            4 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16134            4 :                   return error_mark_node;
   16135              :                 }
   16136              :             }
   16137              :         }
   16138              :     }
   16139              :   else
   16140              :     {
   16141           11 :       error_at (OMP_CLAUSE_LOCATION (c),
   16142              :                 "%qE does not have pointer or array type", ret);
   16143           11 :       return error_mark_node;
   16144              :     }
   16145         3149 :   if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
   16146         2833 :     types.safe_push (TREE_TYPE (ret));
   16147              :   /* We will need to evaluate lb more than once.  */
   16148         3149 :   tree lb = save_expr (low_bound);
   16149         3149 :   if (lb != low_bound)
   16150              :     {
   16151          273 :       TREE_OPERAND (t, 1) = lb;
   16152          273 :       low_bound = lb;
   16153              :     }
   16154         3149 :   ret = build_array_ref (OMP_CLAUSE_LOCATION (c), ret, low_bound);
   16155         3149 :   return ret;
   16156              : }
   16157              : 
   16158              : /* Handle array sections for clause C.  */
   16159              : 
   16160              : static bool
   16161         2978 : handle_omp_array_sections (tree &c, enum c_omp_region_type ort)
   16162              : {
   16163         2978 :   bool maybe_zero_len = false;
   16164         2978 :   unsigned int first_non_one = 0;
   16165         2978 :   auto_vec<tree, 10> types;
   16166         2978 :   tree *tp = &OMP_CLAUSE_DECL (c);
   16167         2978 :   if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   16168         2664 :        || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
   16169         3077 :       && OMP_ITERATOR_DECL_P (*tp))
   16170           66 :     tp = &TREE_VALUE (*tp);
   16171         2978 :   tree first = handle_omp_array_sections_1 (c, *tp, types,
   16172              :                                             maybe_zero_len, first_non_one,
   16173              :                                             ort);
   16174         2978 :   if (first == error_mark_node)
   16175              :     return true;
   16176         2760 :   if (first == NULL_TREE)
   16177              :     return false;
   16178         2760 :   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   16179         2760 :       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
   16180              :     {
   16181          336 :       tree t = *tp;
   16182          336 :       tree tem = NULL_TREE;
   16183              :       /* Need to evaluate side effects in the length expressions
   16184              :          if any.  */
   16185          336 :       while (TREE_CODE (t) == TREE_LIST)
   16186              :         {
   16187            0 :           if (TREE_VALUE (t) && TREE_SIDE_EFFECTS (TREE_VALUE (t)))
   16188              :             {
   16189            0 :               if (tem == NULL_TREE)
   16190              :                 tem = TREE_VALUE (t);
   16191              :               else
   16192            0 :                 tem = build2 (COMPOUND_EXPR, TREE_TYPE (tem),
   16193            0 :                               TREE_VALUE (t), tem);
   16194              :             }
   16195            0 :           t = TREE_CHAIN (t);
   16196              :         }
   16197          336 :       if (tem)
   16198            0 :         first = build2 (COMPOUND_EXPR, TREE_TYPE (first), tem, first);
   16199          336 :       first = c_fully_fold (first, false, NULL, true);
   16200          336 :       *tp = first;
   16201              :     }
   16202              :   else
   16203              :     {
   16204         2424 :       unsigned int num = types.length (), i;
   16205         2424 :       tree t, side_effects = NULL_TREE, size = NULL_TREE;
   16206         2424 :       tree condition = NULL_TREE;
   16207              : 
   16208         2424 :       if (int_size_in_bytes (TREE_TYPE (first)) <= 0)
   16209            3 :         maybe_zero_len = true;
   16210              : 
   16211         5048 :       for (i = num, t = OMP_CLAUSE_DECL (c); i > 0;
   16212         2624 :            t = TREE_OPERAND (t, 0))
   16213              :         {
   16214         2639 :           tree low_bound = TREE_OPERAND (t, 1);
   16215         2639 :           tree length = TREE_OPERAND (t, 2);
   16216              : 
   16217         2639 :           i--;
   16218         2639 :           if (low_bound
   16219         2175 :               && TREE_CODE (low_bound) == INTEGER_CST
   16220         4628 :               && TYPE_PRECISION (TREE_TYPE (low_bound))
   16221         1989 :                  > TYPE_PRECISION (sizetype))
   16222            0 :             low_bound = fold_convert (sizetype, low_bound);
   16223         2639 :           if (length
   16224         2547 :               && TREE_CODE (length) == INTEGER_CST
   16225         4259 :               && TYPE_PRECISION (TREE_TYPE (length))
   16226         1620 :                  > TYPE_PRECISION (sizetype))
   16227            0 :             length = fold_convert (sizetype, length);
   16228         2639 :           if (low_bound == NULL_TREE)
   16229          464 :             low_bound = integer_zero_node;
   16230         2639 :           if (!maybe_zero_len && i > first_non_one)
   16231              :             {
   16232          109 :               if (integer_nonzerop (low_bound))
   16233            6 :                 goto do_warn_noncontiguous;
   16234          103 :               if (length != NULL_TREE
   16235           50 :                   && TREE_CODE (length) == INTEGER_CST
   16236           50 :                   && TYPE_DOMAIN (types[i])
   16237           50 :                   && TYPE_MAX_VALUE (TYPE_DOMAIN (types[i]))
   16238          153 :                   && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])))
   16239              :                      == INTEGER_CST)
   16240              :                 {
   16241           50 :                   tree size;
   16242           50 :                   size = size_binop (PLUS_EXPR,
   16243              :                                      TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
   16244              :                                      size_one_node);
   16245           50 :                   if (!tree_int_cst_equal (length, size))
   16246              :                     {
   16247            7 :                      do_warn_noncontiguous:
   16248           26 :                       error_at (OMP_CLAUSE_LOCATION (c),
   16249              :                                 "array section is not contiguous in %qs "
   16250              :                                 "clause",
   16251           13 :                                 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16252         2424 :                       return true;
   16253              :                     }
   16254              :                 }
   16255           96 :               if (length != NULL_TREE
   16256           96 :                   && TREE_SIDE_EFFECTS (length))
   16257              :                 {
   16258            0 :                   if (side_effects == NULL_TREE)
   16259              :                     side_effects = length;
   16260              :                   else
   16261            0 :                     side_effects = build2 (COMPOUND_EXPR,
   16262            0 :                                            TREE_TYPE (side_effects),
   16263              :                                            length, side_effects);
   16264              :                 }
   16265              :             }
   16266              :           else
   16267              :             {
   16268         2530 :               tree l;
   16269              : 
   16270         2530 :               if (i > first_non_one
   16271         2530 :                   && ((length && integer_nonzerop (length))
   16272            0 :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   16273              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   16274              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION))
   16275            0 :                 continue;
   16276         2530 :               if (length)
   16277         2497 :                 l = fold_convert (sizetype, length);
   16278              :               else
   16279              :                 {
   16280           33 :                   l = size_binop (PLUS_EXPR,
   16281              :                                   TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
   16282              :                                   size_one_node);
   16283           33 :                   l = size_binop (MINUS_EXPR, l,
   16284              :                                   fold_convert (sizetype, low_bound));
   16285              :                 }
   16286         2530 :               if (i > first_non_one)
   16287              :                 {
   16288            0 :                   l = fold_build2 (NE_EXPR, boolean_type_node, l,
   16289              :                                    size_zero_node);
   16290            0 :                   if (condition == NULL_TREE)
   16291              :                     condition = l;
   16292              :                   else
   16293            0 :                     condition = fold_build2 (BIT_AND_EXPR, boolean_type_node,
   16294              :                                              l, condition);
   16295              :                 }
   16296         2530 :               else if (size == NULL_TREE)
   16297              :                 {
   16298         2411 :                   size = size_in_bytes (TREE_TYPE (types[i]));
   16299         2411 :                   tree eltype = TREE_TYPE (types[num - 1]);
   16300         2431 :                   while (TREE_CODE (eltype) == ARRAY_TYPE)
   16301           20 :                     eltype = TREE_TYPE (eltype);
   16302         2411 :                   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   16303         2176 :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   16304         4327 :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
   16305              :                     {
   16306          539 :                       if (integer_zerop (size)
   16307         1076 :                           || integer_zerop (size_in_bytes (eltype)))
   16308              :                         {
   16309            4 :                           error_at (OMP_CLAUSE_LOCATION (c),
   16310              :                                     "zero length array section in %qs clause",
   16311            2 :                                     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16312            2 :                           return error_mark_node;
   16313              :                         }
   16314          537 :                       size = size_binop (EXACT_DIV_EXPR, size,
   16315              :                                          size_in_bytes (eltype));
   16316              :                     }
   16317         2409 :                   size = size_binop (MULT_EXPR, size, l);
   16318         2409 :                   if (condition)
   16319            0 :                     size = fold_build3 (COND_EXPR, sizetype, condition,
   16320              :                                         size, size_zero_node);
   16321              :                 }
   16322              :               else
   16323          119 :                 size = size_binop (MULT_EXPR, size, l);
   16324              :             }
   16325              :         }
   16326         2409 :       if (side_effects)
   16327            0 :         size = build2 (COMPOUND_EXPR, sizetype, side_effects, size);
   16328         2409 :       if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   16329         2176 :           || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   16330         4325 :           || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
   16331              :         {
   16332          537 :           size = size_binop (MINUS_EXPR, size, size_one_node);
   16333          537 :           size = c_fully_fold (size, false, NULL);
   16334          537 :           size = save_expr (size);
   16335          537 :           tree index_type = build_index_type (size);
   16336          537 :           tree eltype = TREE_TYPE (first);
   16337          549 :           while (TREE_CODE (eltype) == ARRAY_TYPE)
   16338           12 :             eltype = TREE_TYPE (eltype);
   16339          537 :           tree type = c_build_array_type (eltype, index_type);
   16340          537 :           tree ptype = c_build_pointer_type (eltype);
   16341          537 :           if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
   16342          296 :             t = build_fold_addr_expr (t);
   16343          537 :           tree t2 = build_fold_addr_expr (first);
   16344          537 :           t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
   16345              :                                  ptrdiff_type_node, t2);
   16346          537 :           t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
   16347              :                                 ptrdiff_type_node, t2,
   16348          537 :                                 fold_convert_loc (OMP_CLAUSE_LOCATION (c),
   16349              :                                                   ptrdiff_type_node, t));
   16350          537 :           t2 = c_fully_fold (t2, false, NULL);
   16351          537 :           if (tree_fits_shwi_p (t2))
   16352          398 :             t = build2 (MEM_REF, type, t,
   16353          398 :                         build_int_cst (ptype, tree_to_shwi (t2)));
   16354              :           else
   16355              :             {
   16356          139 :               t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c), sizetype, t2);
   16357          139 :               t = build2_loc (OMP_CLAUSE_LOCATION (c), POINTER_PLUS_EXPR,
   16358          139 :                               TREE_TYPE (t), t, t2);
   16359          139 :               t = build2 (MEM_REF, type, t, build_int_cst (ptype, 0));
   16360              :             }
   16361          537 :           OMP_CLAUSE_DECL (c) = t;
   16362          537 :           return false;
   16363              :         }
   16364         1872 :       first = c_fully_fold (first, false, NULL);
   16365         1872 :       OMP_CLAUSE_DECL (c) = first;
   16366         1872 :       if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
   16367              :         return false;
   16368              :       /* Don't set OMP_CLAUSE_SIZE for bare attach/detach clauses.  */
   16369         1861 :       if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
   16370         1861 :           || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
   16371         1721 :               && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH
   16372         1719 :               && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FORCE_DETACH))
   16373              :         {
   16374         1857 :           if (size)
   16375         1857 :             size = c_fully_fold (size, false, NULL);
   16376         1857 :           OMP_CLAUSE_SIZE (c) = size;
   16377              :         }
   16378              : 
   16379         1861 :       if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
   16380              :         return false;
   16381              : 
   16382         1723 :       auto_vec<omp_addr_token *, 10> addr_tokens;
   16383              : 
   16384         1723 :       if (!omp_parse_expr (addr_tokens, first))
   16385         1723 :         return true;
   16386              : 
   16387         1723 :       c_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
   16388              : 
   16389         1723 :       tree nc = ai.expand_map_clause (c, first, addr_tokens, ort);
   16390         1723 :       if (nc != error_mark_node)
   16391              :         {
   16392         1723 :           using namespace omp_addr_tokenizer;
   16393              : 
   16394         1723 :           if (ai.maybe_zero_length_array_section (c))
   16395         1719 :             OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
   16396              : 
   16397              :           /* !!! If we're accessing a base decl via chained access
   16398              :              methods (e.g. multiple indirections), duplicate clause
   16399              :              detection won't work properly.  Skip it in that case.  */
   16400         1723 :           if ((addr_tokens[0]->type == STRUCTURE_BASE
   16401         1436 :                || addr_tokens[0]->type == ARRAY_BASE)
   16402         1723 :               && addr_tokens[0]->u.structure_base_kind == BASE_DECL
   16403         1723 :               && addr_tokens[1]->type == ACCESS_METHOD
   16404         3446 :               && omp_access_chain_p (addr_tokens, 1))
   16405           34 :             c = nc;
   16406              : 
   16407         1723 :           return false;
   16408              :         }
   16409              :     }
   16410              :   return false;
   16411         2978 : }
   16412              : 
   16413              : /* Helper function of finish_omp_clauses.  Clone STMT as if we were making
   16414              :    an inline call.  But, remap
   16415              :    the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
   16416              :    and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL.  */
   16417              : 
   16418              : static tree
   16419          510 : c_clone_omp_udr (tree stmt, tree omp_decl1, tree omp_decl2,
   16420              :                  tree decl, tree placeholder)
   16421              : {
   16422          510 :   copy_body_data id;
   16423          510 :   hash_map<tree, tree> decl_map;
   16424              : 
   16425          510 :   decl_map.put (omp_decl1, placeholder);
   16426          510 :   decl_map.put (omp_decl2, decl);
   16427          510 :   memset (&id, 0, sizeof (id));
   16428          510 :   id.src_fn = DECL_CONTEXT (omp_decl1);
   16429          510 :   id.dst_fn = current_function_decl;
   16430          510 :   id.src_cfun = DECL_STRUCT_FUNCTION (id.src_fn);
   16431          510 :   id.decl_map = &decl_map;
   16432              : 
   16433          510 :   id.copy_decl = copy_decl_no_change;
   16434          510 :   id.transform_call_graph_edges = CB_CGE_DUPLICATE;
   16435          510 :   id.transform_new_cfg = true;
   16436          510 :   id.transform_return_to_modify = false;
   16437          510 :   id.eh_lp_nr = 0;
   16438          510 :   walk_tree (&stmt, copy_tree_body_r, &id, NULL);
   16439          510 :   return stmt;
   16440          510 : }
   16441              : 
   16442              : /* Helper function of c_finish_omp_clauses, called via walk_tree.
   16443              :    Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP.  */
   16444              : 
   16445              : static tree
   16446         1123 : c_find_omp_placeholder_r (tree *tp, int *, void *data)
   16447              : {
   16448         1123 :   if (*tp == (tree) data)
   16449           28 :     return *tp;
   16450              :   return NULL_TREE;
   16451              : }
   16452              : 
   16453              : /* Similarly, but also walk aggregate fields.  */
   16454              : 
   16455              : struct c_find_omp_var_s { tree var; hash_set<tree> *pset; };
   16456              : 
   16457              : static tree
   16458          288 : c_find_omp_var_r (tree *tp, int *, void *data)
   16459              : {
   16460          288 :   if (*tp == ((struct c_find_omp_var_s *) data)->var)
   16461              :     return *tp;
   16462          280 :   if (RECORD_OR_UNION_TYPE_P (*tp))
   16463              :     {
   16464            2 :       tree field;
   16465            2 :       hash_set<tree> *pset = ((struct c_find_omp_var_s *) data)->pset;
   16466              : 
   16467            2 :       for (field = TYPE_FIELDS (*tp); field;
   16468            0 :            field = DECL_CHAIN (field))
   16469            2 :         if (TREE_CODE (field) == FIELD_DECL)
   16470              :           {
   16471            2 :             tree ret = walk_tree (&DECL_FIELD_OFFSET (field),
   16472              :                                   c_find_omp_var_r, data, pset);
   16473            2 :             if (ret)
   16474              :               return ret;
   16475            2 :             ret = walk_tree (&DECL_SIZE (field), c_find_omp_var_r, data, pset);
   16476            2 :             if (ret)
   16477              :               return ret;
   16478            2 :             ret = walk_tree (&DECL_SIZE_UNIT (field), c_find_omp_var_r, data,
   16479              :                              pset);
   16480            2 :             if (ret)
   16481              :               return ret;
   16482            2 :             ret = walk_tree (&TREE_TYPE (field), c_find_omp_var_r, data, pset);
   16483            2 :             if (ret)
   16484              :               return ret;
   16485              :           }
   16486              :     }
   16487          278 :   else if (INTEGRAL_TYPE_P (*tp))
   16488           45 :     return walk_tree (&TYPE_MAX_VALUE (*tp), c_find_omp_var_r, data,
   16489              :                       ((struct c_find_omp_var_s *) data)->pset);
   16490              :   return NULL_TREE;
   16491              : }
   16492              : 
   16493              : /* Finish OpenMP iterators ITER.  Return true if they are erroneous
   16494              :    and clauses containing them should be removed.  */
   16495              : 
   16496              : static bool
   16497          143 : c_omp_finish_iterators (tree iter)
   16498              : {
   16499          143 :   bool ret = false;
   16500          325 :   for (tree it = iter; it; it = TREE_CHAIN (it))
   16501              :     {
   16502          182 :       tree var = TREE_VEC_ELT (it, 0);
   16503          182 :       tree begin = TREE_VEC_ELT (it, 1);
   16504          182 :       tree end = TREE_VEC_ELT (it, 2);
   16505          182 :       tree step = TREE_VEC_ELT (it, 3);
   16506          182 :       tree orig_step;
   16507          182 :       tree type = TREE_TYPE (var);
   16508          182 :       location_t loc = DECL_SOURCE_LOCATION (var);
   16509          182 :       if (type == error_mark_node)
   16510              :         {
   16511            0 :           ret = true;
   16512           34 :           continue;
   16513              :         }
   16514          182 :       if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type))
   16515              :         {
   16516            6 :           error_at (loc, "iterator %qD has neither integral nor pointer type",
   16517              :                     var);
   16518            6 :           ret = true;
   16519            6 :           continue;
   16520              :         }
   16521          176 :       else if (TYPE_ATOMIC (type))
   16522              :         {
   16523            2 :           error_at (loc, "iterator %qD has %<_Atomic%> qualified type", var);
   16524            2 :           ret = true;
   16525            2 :           continue;
   16526              :         }
   16527          174 :       else if (TYPE_READONLY (type))
   16528              :         {
   16529            4 :           error_at (loc, "iterator %qD has const qualified type", var);
   16530            4 :           ret = true;
   16531            4 :           continue;
   16532              :         }
   16533          170 :       else if (step == error_mark_node
   16534          170 :                || TREE_TYPE (step) == error_mark_node)
   16535              :         {
   16536            0 :           ret = true;
   16537            0 :           continue;
   16538              :         }
   16539          170 :       else if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
   16540              :         {
   16541            6 :           error_at (EXPR_LOC_OR_LOC (step, loc),
   16542              :                     "iterator step with non-integral type");
   16543            4 :           ret = true;
   16544            4 :           continue;
   16545              :         }
   16546          166 :       begin = c_fully_fold (build_c_cast (loc, type, begin), false, NULL);
   16547          166 :       end = c_fully_fold (build_c_cast (loc, type, end), false, NULL);
   16548          166 :       orig_step = save_expr (c_fully_fold (step, false, NULL));
   16549          166 :       tree stype = POINTER_TYPE_P (type) ? sizetype : type;
   16550          166 :       step = c_fully_fold (build_c_cast (loc, stype, orig_step), false, NULL);
   16551          166 :       if (POINTER_TYPE_P (type))
   16552              :         {
   16553           14 :           begin = save_expr (begin);
   16554           14 :           step = pointer_int_sum (loc, PLUS_EXPR, begin, step);
   16555           14 :           step = fold_build2_loc (loc, MINUS_EXPR, sizetype,
   16556              :                                   fold_convert (sizetype, step),
   16557              :                                   fold_convert (sizetype, begin));
   16558           14 :           step = fold_convert (ssizetype, step);
   16559              :         }
   16560          166 :       if (integer_zerop (step))
   16561              :         {
   16562            6 :           error_at (loc, "iterator %qD has zero step", var);
   16563            6 :           ret = true;
   16564            6 :           continue;
   16565              :         }
   16566              : 
   16567          160 :       if (begin == error_mark_node
   16568          158 :           || end == error_mark_node
   16569          156 :           || step == error_mark_node
   16570          156 :           || orig_step == error_mark_node)
   16571              :         {
   16572            4 :           ret = true;
   16573            4 :           continue;
   16574              :         }
   16575          156 :       hash_set<tree> pset;
   16576          156 :       tree it2;
   16577          197 :       for (it2 = TREE_CHAIN (it); it2; it2 = TREE_CHAIN (it2))
   16578              :         {
   16579           49 :           tree var2 = TREE_VEC_ELT (it2, 0);
   16580           49 :           tree begin2 = TREE_VEC_ELT (it2, 1);
   16581           49 :           tree end2 = TREE_VEC_ELT (it2, 2);
   16582           49 :           tree step2 = TREE_VEC_ELT (it2, 3);
   16583           49 :           tree type2 = TREE_TYPE (var2);
   16584           49 :           location_t loc2 = DECL_SOURCE_LOCATION (var2);
   16585           49 :           struct c_find_omp_var_s data = { var, &pset };
   16586           49 :           if (walk_tree (&type2, c_find_omp_var_r, &data, &pset))
   16587              :             {
   16588            2 :               error_at (loc2,
   16589              :                         "type of iterator %qD refers to outer iterator %qD",
   16590              :                         var2, var);
   16591           10 :               break;
   16592              :             }
   16593           47 :           else if (walk_tree (&begin2, c_find_omp_var_r, &data, &pset))
   16594              :             {
   16595            2 :               error_at (EXPR_LOC_OR_LOC (begin2, loc2),
   16596              :                         "begin expression refers to outer iterator %qD", var);
   16597            2 :               break;
   16598              :             }
   16599           45 :           else if (walk_tree (&end2, c_find_omp_var_r, &data, &pset))
   16600              :             {
   16601            2 :               error_at (EXPR_LOC_OR_LOC (end2, loc2),
   16602              :                         "end expression refers to outer iterator %qD", var);
   16603            2 :               break;
   16604              :             }
   16605           43 :           else if (walk_tree (&step2, c_find_omp_var_r, &data, &pset))
   16606              :             {
   16607            2 :               error_at (EXPR_LOC_OR_LOC (step2, loc2),
   16608              :                         "step expression refers to outer iterator %qD", var);
   16609            2 :               break;
   16610              :             }
   16611              :         }
   16612          156 :       if (it2)
   16613              :         {
   16614            8 :           ret = true;
   16615            8 :           continue;
   16616              :         }
   16617          148 :       TREE_VEC_ELT (it, 1) = begin;
   16618          148 :       TREE_VEC_ELT (it, 2) = end;
   16619          148 :       TREE_VEC_ELT (it, 3) = step;
   16620          148 :       TREE_VEC_ELT (it, 4) = orig_step;
   16621          156 :     }
   16622          143 :   return ret;
   16623              : }
   16624              : 
   16625              : /* Ensure that pointers are used in OpenACC attach and detach clauses.
   16626              :    Return true if an error has been detected.  */
   16627              : 
   16628              : static bool
   16629         9615 : c_oacc_check_attachments (tree c)
   16630              : {
   16631         9615 :   if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
   16632              :     return false;
   16633              : 
   16634              :   /* OpenACC attach / detach clauses must be pointers.  */
   16635         6592 :   if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
   16636         6592 :       || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
   16637              :     {
   16638           71 :       tree t = OMP_CLAUSE_DECL (c);
   16639              : 
   16640           77 :       while (TREE_CODE (t) == OMP_ARRAY_SECTION)
   16641            6 :         t = TREE_OPERAND (t, 0);
   16642              : 
   16643           71 :       if (TREE_CODE (TREE_TYPE (t)) != POINTER_TYPE)
   16644              :         {
   16645            6 :           error_at (OMP_CLAUSE_LOCATION (c), "expected pointer in %qs clause",
   16646              :                     user_omp_clause_code_name (c, true));
   16647            6 :           return true;
   16648              :         }
   16649              :     }
   16650              : 
   16651              :   return false;
   16652              : }
   16653              : 
   16654              : /* For all elements of CLAUSES, validate them against their constraints.
   16655              :    Remove any elements from the list that are invalid.  */
   16656              : 
   16657              : tree
   16658        29559 : c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
   16659              : {
   16660        29559 :   bitmap_head generic_head, firstprivate_head, lastprivate_head;
   16661        29559 :   bitmap_head aligned_head, map_head, map_field_head, map_firstprivate_head;
   16662        29559 :   bitmap_head oacc_reduction_head, is_on_device_head;
   16663        29559 :   tree c, t, type, *pc;
   16664        29559 :   tree simdlen = NULL_TREE, safelen = NULL_TREE;
   16665        29559 :   bool branch_seen = false;
   16666        29559 :   bool copyprivate_seen = false;
   16667        29559 :   bool mergeable_seen = false;
   16668        29559 :   tree *detach_seen = NULL;
   16669        29559 :   bool linear_variable_step_check = false;
   16670        29559 :   tree *nowait_clause = NULL;
   16671        29559 :   tree *grainsize_seen = NULL;
   16672        29559 :   bool num_tasks_seen = false;
   16673        29559 :   tree ordered_clause = NULL_TREE;
   16674        29559 :   tree schedule_clause = NULL_TREE;
   16675        29559 :   bool oacc_async = false;
   16676        29559 :   tree last_iterators = NULL_TREE;
   16677        29559 :   bool last_iterators_remove = false;
   16678        29559 :   tree *nogroup_seen = NULL;
   16679        29559 :   tree *order_clause = NULL;
   16680              :   /* 1 if normal/task reduction has been seen, -1 if inscan reduction
   16681              :      has been seen, -2 if mixed inscan/normal reduction diagnosed.  */
   16682        29559 :   int reduction_seen = 0;
   16683        29559 :   bool allocate_seen = false;
   16684        29559 :   bool implicit_moved = false;
   16685        29559 :   bool target_in_reduction_seen = false;
   16686        29559 :   tree *full_seen = NULL;
   16687        29559 :   bool partial_seen = false;
   16688        29559 :   bool openacc = (ort & C_ORT_ACC) != 0;
   16689        29559 :   bool init_seen = false;
   16690        29559 :   bool init_use_destroy_seen = false;
   16691        29559 :   tree init_no_targetsync_clause = NULL_TREE;
   16692        29559 :   tree depend_clause = NULL_TREE;
   16693              : 
   16694        29559 :   if (!openacc)
   16695        24322 :     clauses = omp_remove_duplicate_maps (clauses, true);
   16696              : 
   16697        29559 :   bitmap_obstack_initialize (NULL);
   16698        29559 :   bitmap_initialize (&generic_head, &bitmap_default_obstack);
   16699        29559 :   bitmap_initialize (&firstprivate_head, &bitmap_default_obstack);
   16700        29559 :   bitmap_initialize (&lastprivate_head, &bitmap_default_obstack);
   16701        29559 :   bitmap_initialize (&aligned_head, &bitmap_default_obstack);
   16702              :   /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead.  */
   16703        29559 :   bitmap_initialize (&map_head, &bitmap_default_obstack);
   16704        29559 :   bitmap_initialize (&map_field_head, &bitmap_default_obstack);
   16705        29559 :   bitmap_initialize (&map_firstprivate_head, &bitmap_default_obstack);
   16706              :   /* If ort == C_ORT_OMP used as nontemporal_head or use_device_xxx_head
   16707              :      instead and for ort == C_ORT_OMP_TARGET used as in_reduction_head.  */
   16708        29559 :   bitmap_initialize (&oacc_reduction_head, &bitmap_default_obstack);
   16709        29559 :   bitmap_initialize (&is_on_device_head, &bitmap_default_obstack);
   16710              : 
   16711        29559 :   if (openacc)
   16712        12269 :     for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
   16713         7258 :       if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ASYNC)
   16714              :         {
   16715              :           oacc_async = true;
   16716              :           break;
   16717              :         }
   16718              : 
   16719        29559 :   tree *grp_start_p = NULL, grp_sentinel = NULL_TREE;
   16720              : 
   16721        77599 :   for (pc = &clauses, c = clauses; c ; c = *pc)
   16722              :     {
   16723        48040 :       bool remove = false;
   16724        48040 :       bool need_complete = false;
   16725        48040 :       bool need_implicitly_determined = false;
   16726              : 
   16727              :       /* We've reached the end of a list of expanded nodes.  Reset the group
   16728              :          start pointer.  */
   16729        48040 :       if (c == grp_sentinel)
   16730              :         {
   16731         2507 :           if (grp_start_p
   16732         2507 :               && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
   16733           32 :             for (tree gc = *grp_start_p; gc != grp_sentinel;
   16734           22 :                  gc = OMP_CLAUSE_CHAIN (gc))
   16735           22 :               OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
   16736              :           grp_start_p = NULL;
   16737              :         }
   16738              : 
   16739        48040 :       switch (OMP_CLAUSE_CODE (c))
   16740              :         {
   16741         1139 :         case OMP_CLAUSE_SHARED:
   16742         1139 :           need_implicitly_determined = true;
   16743         1139 :           goto check_dup_generic;
   16744              : 
   16745          847 :         case OMP_CLAUSE_PRIVATE:
   16746          847 :           need_complete = true;
   16747          847 :           need_implicitly_determined = true;
   16748          847 :           goto check_dup_generic;
   16749              : 
   16750         3519 :         case OMP_CLAUSE_REDUCTION:
   16751         3519 :           if (reduction_seen == 0)
   16752         2920 :             reduction_seen = OMP_CLAUSE_REDUCTION_INSCAN (c) ? -1 : 1;
   16753          599 :           else if (reduction_seen != -2
   16754         1198 :                    && reduction_seen != (OMP_CLAUSE_REDUCTION_INSCAN (c)
   16755          599 :                                          ? -1 : 1))
   16756              :             {
   16757            2 :               error_at (OMP_CLAUSE_LOCATION (c),
   16758              :                         "%<inscan%> and non-%<inscan%> %<reduction%> clauses "
   16759              :                         "on the same construct");
   16760            2 :               reduction_seen = -2;
   16761              :             }
   16762              :           /* FALLTHRU */
   16763         4183 :         case OMP_CLAUSE_IN_REDUCTION:
   16764         4183 :         case OMP_CLAUSE_TASK_REDUCTION:
   16765         4183 :           need_implicitly_determined = true;
   16766         4183 :           t = OMP_CLAUSE_DECL (c);
   16767         4183 :           if (TREE_CODE (t) == OMP_ARRAY_SECTION)
   16768              :             {
   16769          553 :               if (handle_omp_array_sections (c, ort))
   16770              :                 {
   16771              :                   remove = true;
   16772              :                   break;
   16773              :                 }
   16774              : 
   16775          537 :               t = OMP_CLAUSE_DECL (c);
   16776          537 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   16777          537 :                   && OMP_CLAUSE_REDUCTION_INSCAN (c))
   16778              :                 {
   16779            1 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16780              :                             "%<inscan%> %<reduction%> clause with array "
   16781              :                             "section");
   16782            1 :                   remove = true;
   16783            1 :                   break;
   16784              :                 }
   16785              :             }
   16786         4166 :           t = require_complete_type (OMP_CLAUSE_LOCATION (c), t);
   16787         4166 :           if (t == error_mark_node)
   16788              :             {
   16789              :               remove = true;
   16790              :               break;
   16791              :             }
   16792         4164 :           if (oacc_async)
   16793            3 :             c_mark_addressable (t);
   16794         4164 :           type = TREE_TYPE (t);
   16795         4164 :           if (TREE_CODE (t) == MEM_REF)
   16796          536 :             type = TREE_TYPE (type);
   16797         4164 :           if (TREE_CODE (type) == ARRAY_TYPE)
   16798              :             {
   16799           74 :               tree oatype = type;
   16800           74 :               gcc_assert (TREE_CODE (t) != MEM_REF);
   16801          148 :               while (TREE_CODE (type) == ARRAY_TYPE)
   16802           74 :                 type = TREE_TYPE (type);
   16803           74 :               if (integer_zerop (TYPE_SIZE_UNIT (type)))
   16804              :                 {
   16805            1 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16806              :                             "%qD in %<reduction%> clause is a zero size array",
   16807              :                             t);
   16808            1 :                   remove = true;
   16809            1 :                   break;
   16810              :                 }
   16811           73 :               tree size = size_binop (EXACT_DIV_EXPR, TYPE_SIZE_UNIT (oatype),
   16812              :                                       TYPE_SIZE_UNIT (type));
   16813           73 :               if (integer_zerop (size))
   16814              :                 {
   16815            1 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16816              :                             "%qD in %<reduction%> clause is a zero size array",
   16817              :                             t);
   16818            1 :                   remove = true;
   16819            1 :                   break;
   16820              :                 }
   16821           72 :               size = size_binop (MINUS_EXPR, size, size_one_node);
   16822           72 :               size = save_expr (size);
   16823           72 :               tree index_type = build_index_type (size);
   16824           72 :               tree atype = c_build_array_type (TYPE_MAIN_VARIANT (type),
   16825              :                                                index_type);
   16826           72 :               atype = c_build_qualified_type (atype, TYPE_QUALS (type));
   16827           72 :               tree ptype = c_build_pointer_type (type);
   16828           72 :               if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
   16829           72 :                 t = build_fold_addr_expr (t);
   16830           72 :               t = build2 (MEM_REF, atype, t, build_int_cst (ptype, 0));
   16831           72 :               OMP_CLAUSE_DECL (c) = t;
   16832              :             }
   16833         4162 :           if (TYPE_ATOMIC (type))
   16834              :             {
   16835            3 :               error_at (OMP_CLAUSE_LOCATION (c),
   16836              :                         "%<_Atomic%> %qE in %<reduction%> clause", t);
   16837            3 :               remove = true;
   16838            3 :               break;
   16839              :             }
   16840         4159 :           if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
   16841         4159 :               || OMP_CLAUSE_REDUCTION_TASK (c))
   16842              :             {
   16843              :               /* Disallow zero sized or potentially zero sized task
   16844              :                  reductions.  */
   16845          871 :               if (integer_zerop (TYPE_SIZE_UNIT (type)))
   16846              :                 {
   16847            6 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16848              :                             "zero sized type %qT in %qs clause", type,
   16849            3 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16850            3 :                   remove = true;
   16851            3 :                   break;
   16852              :                 }
   16853          868 :               else if (TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST)
   16854              :                 {
   16855            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16856              :                             "variable sized type %qT in %qs clause", type,
   16857            0 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16858            0 :                   remove = true;
   16859            0 :                   break;
   16860              :                 }
   16861              :             }
   16862         4156 :           if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == NULL_TREE
   16863         4156 :               && (FLOAT_TYPE_P (type)
   16864         3604 :                   || TREE_CODE (type) == COMPLEX_TYPE))
   16865              :             {
   16866          340 :               enum tree_code r_code = OMP_CLAUSE_REDUCTION_CODE (c);
   16867          340 :               const char *r_name = NULL;
   16868              : 
   16869          340 :               switch (r_code)
   16870              :                 {
   16871              :                 case PLUS_EXPR:
   16872              :                 case MULT_EXPR:
   16873              :                 case MINUS_EXPR:
   16874              :                 case TRUTH_ANDIF_EXPR:
   16875              :                 case TRUTH_ORIF_EXPR:
   16876              :                   break;
   16877           13 :                 case MIN_EXPR:
   16878           13 :                   if (TREE_CODE (type) == COMPLEX_TYPE)
   16879              :                     r_name = "min";
   16880              :                   break;
   16881           38 :                 case MAX_EXPR:
   16882           38 :                   if (TREE_CODE (type) == COMPLEX_TYPE)
   16883              :                     r_name = "max";
   16884              :                   break;
   16885            3 :                 case BIT_AND_EXPR:
   16886            3 :                   r_name = "&";
   16887            3 :                   break;
   16888            2 :                 case BIT_XOR_EXPR:
   16889            2 :                   r_name = "^";
   16890            2 :                   break;
   16891              :                 case BIT_IOR_EXPR:
   16892              :                   r_name = "|";
   16893              :                   break;
   16894            0 :                 default:
   16895            0 :                   gcc_unreachable ();
   16896              :                 }
   16897            5 :               if (r_name)
   16898              :                 {
   16899           12 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16900              :                             "%qE has invalid type for %<reduction(%s)%>",
   16901              :                             t, r_name);
   16902           12 :                   remove = true;
   16903           12 :                   break;
   16904              :                 }
   16905              :             }
   16906         3816 :           else if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == error_mark_node)
   16907              :             {
   16908            2 :               error_at (OMP_CLAUSE_LOCATION (c),
   16909              :                         "user defined reduction not found for %qE", t);
   16910            2 :               remove = true;
   16911            2 :               break;
   16912              :             }
   16913         3814 :           else if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
   16914              :             {
   16915          277 :               tree list = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c);
   16916          277 :               type = TYPE_MAIN_VARIANT (type);
   16917          277 :               tree placeholder = build_decl (OMP_CLAUSE_LOCATION (c),
   16918              :                                              VAR_DECL, NULL_TREE, type);
   16919          277 :               tree decl_placeholder = NULL_TREE;
   16920          277 :               OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = placeholder;
   16921          277 :               DECL_ARTIFICIAL (placeholder) = 1;
   16922          277 :               DECL_IGNORED_P (placeholder) = 1;
   16923          277 :               if (TREE_CODE (t) == MEM_REF)
   16924              :                 {
   16925           56 :                   decl_placeholder = build_decl (OMP_CLAUSE_LOCATION (c),
   16926              :                                                  VAR_DECL, NULL_TREE, type);
   16927           56 :                   OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c) = decl_placeholder;
   16928           56 :                   DECL_ARTIFICIAL (decl_placeholder) = 1;
   16929           56 :                   DECL_IGNORED_P (decl_placeholder) = 1;
   16930              :                 }
   16931          277 :               if (TREE_ADDRESSABLE (TREE_VEC_ELT (list, 0)))
   16932           42 :                 c_mark_addressable (placeholder);
   16933          277 :               if (TREE_ADDRESSABLE (TREE_VEC_ELT (list, 1)))
   16934           76 :                 c_mark_addressable (decl_placeholder ? decl_placeholder
   16935           34 :                                     : OMP_CLAUSE_DECL (c));
   16936          277 :               OMP_CLAUSE_REDUCTION_MERGE (c)
   16937          775 :                 = c_clone_omp_udr (TREE_VEC_ELT (list, 2),
   16938          277 :                                    TREE_VEC_ELT (list, 0),
   16939          277 :                                    TREE_VEC_ELT (list, 1),
   16940              :                                    decl_placeholder ? decl_placeholder
   16941          221 :                                    : OMP_CLAUSE_DECL (c), placeholder);
   16942          277 :               OMP_CLAUSE_REDUCTION_MERGE (c)
   16943          277 :                 = build3_loc (OMP_CLAUSE_LOCATION (c), BIND_EXPR,
   16944              :                               void_type_node, NULL_TREE,
   16945          277 :                               OMP_CLAUSE_REDUCTION_MERGE (c), NULL_TREE);
   16946          277 :               TREE_SIDE_EFFECTS (OMP_CLAUSE_REDUCTION_MERGE (c)) = 1;
   16947          277 :               if (TREE_VEC_LENGTH (list) == 6)
   16948              :                 {
   16949          233 :                   if (TREE_ADDRESSABLE (TREE_VEC_ELT (list, 3)))
   16950           70 :                     c_mark_addressable (decl_placeholder ? decl_placeholder
   16951           33 :                                         : OMP_CLAUSE_DECL (c));
   16952          233 :                   if (TREE_ADDRESSABLE (TREE_VEC_ELT (list, 4)))
   16953           27 :                     c_mark_addressable (placeholder);
   16954          233 :                   tree init = TREE_VEC_ELT (list, 5);
   16955          233 :                   if (init == error_mark_node)
   16956          197 :                     init = DECL_INITIAL (TREE_VEC_ELT (list, 3));
   16957          233 :                   OMP_CLAUSE_REDUCTION_INIT (c)
   16958          651 :                     = c_clone_omp_udr (init, TREE_VEC_ELT (list, 4),
   16959          233 :                                        TREE_VEC_ELT (list, 3),
   16960              :                                        decl_placeholder ? decl_placeholder
   16961          185 :                                        : OMP_CLAUSE_DECL (c), placeholder);
   16962          233 :                   if (TREE_VEC_ELT (list, 5) == error_mark_node)
   16963              :                     {
   16964          197 :                       tree v = decl_placeholder ? decl_placeholder : t;
   16965          197 :                       OMP_CLAUSE_REDUCTION_INIT (c)
   16966          394 :                         = build2 (INIT_EXPR, TREE_TYPE (v), v,
   16967          197 :                                   OMP_CLAUSE_REDUCTION_INIT (c));
   16968              :                     }
   16969          233 :                   if (walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c),
   16970              :                                  c_find_omp_placeholder_r,
   16971              :                                  placeholder, NULL))
   16972           28 :                     OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c) = 1;
   16973              :                 }
   16974              :               else
   16975              :                 {
   16976           44 :                   tree init;
   16977           44 :                   tree v = decl_placeholder ? decl_placeholder : t;
   16978           44 :                   if (AGGREGATE_TYPE_P (TREE_TYPE (v)))
   16979           34 :                     init = build_constructor (TREE_TYPE (v), NULL);
   16980              :                   else
   16981           10 :                     init = fold_convert (TREE_TYPE (v), integer_zero_node);
   16982           44 :                   OMP_CLAUSE_REDUCTION_INIT (c)
   16983           88 :                     = build2 (INIT_EXPR, TREE_TYPE (v), v, init);
   16984              :                 }
   16985          277 :               OMP_CLAUSE_REDUCTION_INIT (c)
   16986          277 :                 = build3_loc (OMP_CLAUSE_LOCATION (c), BIND_EXPR,
   16987              :                               void_type_node, NULL_TREE,
   16988          277 :                                OMP_CLAUSE_REDUCTION_INIT (c), NULL_TREE);
   16989          277 :               TREE_SIDE_EFFECTS (OMP_CLAUSE_REDUCTION_INIT (c)) = 1;
   16990              :             }
   16991         4142 :           if (TREE_CODE (t) == MEM_REF)
   16992              :             {
   16993          607 :               if (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t))) == NULL_TREE
   16994          607 :                   || TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t))))
   16995              :                      != INTEGER_CST)
   16996              :                 {
   16997            0 :                   sorry ("variable length element type in array "
   16998              :                          "%<reduction%> clause");
   16999            0 :                   remove = true;
   17000            0 :                   break;
   17001              :                 }
   17002          607 :               t = TREE_OPERAND (t, 0);
   17003          607 :               if (TREE_CODE (t) == POINTER_PLUS_EXPR)
   17004          139 :                 t = TREE_OPERAND (t, 0);
   17005          607 :               if (TREE_CODE (t) == ADDR_EXPR)
   17006          367 :                 t = TREE_OPERAND (t, 0);
   17007              :             }
   17008         4142 :           goto check_dup_generic_t;
   17009              : 
   17010           24 :         case OMP_CLAUSE_COPYPRIVATE:
   17011           24 :           copyprivate_seen = true;
   17012           24 :           if (nowait_clause)
   17013              :             {
   17014            1 :               error_at (OMP_CLAUSE_LOCATION (*nowait_clause),
   17015              :                         "%<nowait%> clause must not be used together "
   17016              :                         "with %<copyprivate%> clause");
   17017            1 :               *nowait_clause = OMP_CLAUSE_CHAIN (*nowait_clause);
   17018            1 :               nowait_clause = NULL;
   17019              :             }
   17020           24 :           goto check_dup_generic;
   17021              : 
   17022           99 :         case OMP_CLAUSE_COPYIN:
   17023           99 :           t = OMP_CLAUSE_DECL (c);
   17024           99 :           if (!VAR_P (t) || !DECL_THREAD_LOCAL_P (t))
   17025              :             {
   17026            5 :               error_at (OMP_CLAUSE_LOCATION (c),
   17027              :                         "%qE must be %<threadprivate%> for %<copyin%>", t);
   17028            5 :               remove = true;
   17029            5 :               break;
   17030              :             }
   17031           94 :           goto check_dup_generic;
   17032              : 
   17033          480 :         case OMP_CLAUSE_LINEAR:
   17034          480 :           if (ort != C_ORT_OMP_DECLARE_SIMD)
   17035          327 :             need_implicitly_determined = true;
   17036          480 :           t = OMP_CLAUSE_DECL (c);
   17037          480 :           if (ort != C_ORT_OMP_DECLARE_SIMD
   17038          327 :               && OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_DEFAULT
   17039          485 :               && OMP_CLAUSE_LINEAR_OLD_LINEAR_MODIFIER (c))
   17040              :             {
   17041            5 :               error_at (OMP_CLAUSE_LOCATION (c),
   17042              :                         "modifier should not be specified in %<linear%> "
   17043              :                         "clause on %<simd%> or %<for%> constructs when not "
   17044              :                         "using OpenMP 5.2 modifiers");
   17045            5 :               OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
   17046              :             }
   17047          960 :           if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
   17048          503 :               && TREE_CODE (TREE_TYPE (t)) != POINTER_TYPE)
   17049              :             {
   17050            1 :               error_at (OMP_CLAUSE_LOCATION (c),
   17051              :                         "linear clause applied to non-integral non-pointer "
   17052            1 :                         "variable with type %qT", TREE_TYPE (t));
   17053            1 :               remove = true;
   17054            1 :               break;
   17055              :             }
   17056          479 :           if (TYPE_ATOMIC (TREE_TYPE (t)))
   17057              :             {
   17058            3 :               error_at (OMP_CLAUSE_LOCATION (c),
   17059              :                         "%<_Atomic%> %qD in %<linear%> clause", t);
   17060            3 :               remove = true;
   17061            3 :               break;
   17062              :             }
   17063          476 :           if (ort == C_ORT_OMP_DECLARE_SIMD)
   17064              :             {
   17065          152 :               tree s = OMP_CLAUSE_LINEAR_STEP (c);
   17066          152 :               if (TREE_CODE (s) == PARM_DECL)
   17067              :                 {
   17068            9 :                   OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c) = 1;
   17069              :                   /* map_head bitmap is used as uniform_head if
   17070              :                      declare_simd.  */
   17071            9 :                   if (!bitmap_bit_p (&map_head, DECL_UID (s)))
   17072            5 :                     linear_variable_step_check = true;
   17073            9 :                   goto check_dup_generic;
   17074              :                 }
   17075          143 :               if (TREE_CODE (s) != INTEGER_CST)
   17076              :                 {
   17077            7 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17078              :                             "%<linear%> clause step %qE is neither constant "
   17079              :                             "nor a parameter", s);
   17080            7 :                   remove = true;
   17081            7 :                   break;
   17082              :                 }
   17083              :             }
   17084          460 :           if (TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c))) == POINTER_TYPE)
   17085              :             {
   17086           20 :               tree s = OMP_CLAUSE_LINEAR_STEP (c);
   17087           20 :               s = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
   17088           20 :                                    OMP_CLAUSE_DECL (c), s);
   17089           20 :               s = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
   17090              :                                    sizetype, fold_convert (sizetype, s),
   17091           20 :                                    fold_convert
   17092              :                                      (sizetype, OMP_CLAUSE_DECL (c)));
   17093           20 :               if (s == error_mark_node)
   17094            0 :                 s = size_one_node;
   17095           20 :               OMP_CLAUSE_LINEAR_STEP (c) = s;
   17096              :             }
   17097              :           else
   17098          440 :             OMP_CLAUSE_LINEAR_STEP (c)
   17099          880 :               = fold_convert (TREE_TYPE (t), OMP_CLAUSE_LINEAR_STEP (c));
   17100          460 :           goto check_dup_generic;
   17101              : 
   17102         2887 :         check_dup_generic:
   17103         2887 :           t = OMP_CLAUSE_DECL (c);
   17104         7118 :         check_dup_generic_t:
   17105         7118 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   17106              :             {
   17107            4 :               error_at (OMP_CLAUSE_LOCATION (c),
   17108              :                         "%qE is not a variable in clause %qs", t,
   17109            2 :                         omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17110            2 :               remove = true;
   17111              :             }
   17112         1149 :           else if ((openacc && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
   17113         6077 :                    || (ort == C_ORT_OMP
   17114         5358 :                        && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
   17115         5347 :                            || (OMP_CLAUSE_CODE (c)
   17116              :                                == OMP_CLAUSE_USE_DEVICE_ADDR)))
   17117        13146 :                    || (ort == C_ORT_OMP_TARGET
   17118          347 :                        && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION))
   17119              :             {
   17120         1196 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   17121         1196 :                   && (bitmap_bit_p (&generic_head, DECL_UID (t))
   17122          109 :                       || bitmap_bit_p (&firstprivate_head, DECL_UID (t))))
   17123              :                 {
   17124            2 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17125              :                             "%qD appears more than once in data-sharing "
   17126              :                             "clauses", t);
   17127            2 :                   remove = true;
   17128            2 :                   break;
   17129              :                 }
   17130         1194 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION)
   17131          108 :                 target_in_reduction_seen = true;
   17132         1194 :               if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
   17133              :                 {
   17134            4 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17135              :                             openacc
   17136              :                             ? "%qD appears more than once in reduction clauses"
   17137              :                             : "%qD appears more than once in data clauses",
   17138              :                             t);
   17139            2 :                   remove = true;
   17140              :                 }
   17141              :               else
   17142         1192 :                 bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
   17143              :             }
   17144         5920 :           else if (bitmap_bit_p (&generic_head, DECL_UID (t))
   17145         5897 :                    || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
   17146         5896 :                    || bitmap_bit_p (&lastprivate_head, DECL_UID (t))
   17147        11816 :                    || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
   17148              :             {
   17149           24 :               error_at (OMP_CLAUSE_LOCATION (c),
   17150              :                         "%qE appears more than once in data clauses", t);
   17151           24 :               remove = true;
   17152              :             }
   17153         5896 :           else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
   17154              :                     || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR
   17155              :                     || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
   17156         1047 :                    && bitmap_bit_p (&map_head, DECL_UID (t)))
   17157              :             {
   17158            3 :               if (openacc)
   17159            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17160              :                           "%qD appears more than once in data clauses", t);
   17161              :               else
   17162            3 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17163              :                           "%qD appears both in data and map clauses", t);
   17164              :               remove = true;
   17165              :             }
   17166              :           else
   17167         5893 :             bitmap_set_bit (&generic_head, DECL_UID (t));
   17168              :           break;
   17169              : 
   17170         1333 :         case OMP_CLAUSE_FIRSTPRIVATE:
   17171         1333 :           if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c) && !implicit_moved)
   17172              :             {
   17173          153 :             move_implicit:
   17174          153 :               implicit_moved = true;
   17175              :               /* Move firstprivate and map clauses with
   17176              :                  OMP_CLAUSE_{FIRSTPRIVATE,MAP}_IMPLICIT set to the end of
   17177              :                  clauses chain.  */
   17178          153 :               tree cl1 = NULL_TREE, cl2 = NULL_TREE;
   17179          153 :               tree *pc1 = pc, *pc2 = &cl1, *pc3 = &cl2;
   17180          972 :               while (*pc1)
   17181          819 :                 if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_FIRSTPRIVATE
   17182          819 :                     && OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (*pc1))
   17183              :                   {
   17184          113 :                     *pc3 = *pc1;
   17185          113 :                     pc3 = &OMP_CLAUSE_CHAIN (*pc3);
   17186          113 :                     *pc1 = OMP_CLAUSE_CHAIN (*pc1);
   17187              :                   }
   17188          706 :                 else if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_MAP
   17189          706 :                          && OMP_CLAUSE_MAP_IMPLICIT (*pc1))
   17190              :                   {
   17191          131 :                     *pc2 = *pc1;
   17192          131 :                     pc2 = &OMP_CLAUSE_CHAIN (*pc2);
   17193          131 :                     *pc1 = OMP_CLAUSE_CHAIN (*pc1);
   17194              :                   }
   17195              :                 else
   17196          575 :                   pc1 = &OMP_CLAUSE_CHAIN (*pc1);
   17197          153 :               *pc3 = NULL;
   17198          153 :               *pc2 = cl2;
   17199          153 :               *pc1 = cl1;
   17200          153 :               continue;
   17201          153 :             }
   17202         1238 :           t = OMP_CLAUSE_DECL (c);
   17203         1238 :           need_complete = true;
   17204         1238 :           need_implicitly_determined = true;
   17205         1238 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   17206              :             {
   17207            1 :               error_at (OMP_CLAUSE_LOCATION (c),
   17208              :                         "%qE is not a variable in clause %<firstprivate%>", t);
   17209            1 :               remove = true;
   17210              :             }
   17211         1237 :           else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
   17212          113 :                    && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c)
   17213         1343 :                    && bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
   17214              :             remove = true;
   17215         1237 :           else if (bitmap_bit_p (&generic_head, DECL_UID (t))
   17216         1235 :                    || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
   17217         2471 :                    || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
   17218              :             {
   17219            4 :               error_at (OMP_CLAUSE_LOCATION (c),
   17220              :                         "%qE appears more than once in data clauses", t);
   17221            4 :               remove = true;
   17222              :             }
   17223         1233 :           else if (bitmap_bit_p (&map_head, DECL_UID (t))
   17224         1233 :                    || bitmap_bit_p (&map_field_head, DECL_UID (t)))
   17225              :             {
   17226            7 :               if (openacc)
   17227            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17228              :                           "%qD appears more than once in data clauses", t);
   17229            7 :               else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
   17230            7 :                        && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c))
   17231              :                 /* Silently drop the clause.  */;
   17232              :               else
   17233            6 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17234              :                           "%qD appears both in data and map clauses", t);
   17235              :               remove = true;
   17236              :             }
   17237              :           else
   17238         1226 :             bitmap_set_bit (&firstprivate_head, DECL_UID (t));
   17239              :           break;
   17240              : 
   17241         1523 :         case OMP_CLAUSE_LASTPRIVATE:
   17242         1523 :           t = OMP_CLAUSE_DECL (c);
   17243         1523 :           need_complete = true;
   17244         1523 :           need_implicitly_determined = true;
   17245         1523 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   17246              :             {
   17247            0 :               error_at (OMP_CLAUSE_LOCATION (c),
   17248              :                         "%qE is not a variable in clause %<lastprivate%>", t);
   17249            0 :               remove = true;
   17250              :             }
   17251         1523 :           else if (bitmap_bit_p (&generic_head, DECL_UID (t))
   17252         1523 :                    || bitmap_bit_p (&lastprivate_head, DECL_UID (t)))
   17253              :             {
   17254            3 :               error_at (OMP_CLAUSE_LOCATION (c),
   17255              :                      "%qE appears more than once in data clauses", t);
   17256            3 :               remove = true;
   17257              :             }
   17258              :           else
   17259         1520 :             bitmap_set_bit (&lastprivate_head, DECL_UID (t));
   17260              :           break;
   17261              : 
   17262          253 :         case OMP_CLAUSE_ALIGNED:
   17263          253 :           t = OMP_CLAUSE_DECL (c);
   17264          253 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   17265              :             {
   17266            0 :               error_at (OMP_CLAUSE_LOCATION (c),
   17267              :                         "%qE is not a variable in %<aligned%> clause", t);
   17268            0 :               remove = true;
   17269              :             }
   17270          289 :           else if (!POINTER_TYPE_P (TREE_TYPE (t))
   17271          289 :                    && TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE)
   17272              :             {
   17273            7 :               error_at (OMP_CLAUSE_LOCATION (c),
   17274              :                         "%qE in %<aligned%> clause is neither a pointer nor "
   17275              :                         "an array", t);
   17276            7 :               remove = true;
   17277              :             }
   17278          246 :           else if (TYPE_ATOMIC (TREE_TYPE (t)))
   17279              :             {
   17280            1 :               error_at (OMP_CLAUSE_LOCATION (c),
   17281              :                         "%<_Atomic%> %qD in %<aligned%> clause", t);
   17282            1 :               remove = true;
   17283            1 :               break;
   17284              :             }
   17285          245 :           else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
   17286              :             {
   17287            0 :               error_at (OMP_CLAUSE_LOCATION (c),
   17288              :                         "%qE appears more than once in %<aligned%> clauses",
   17289              :                         t);
   17290            0 :               remove = true;
   17291              :             }
   17292              :           else
   17293          245 :             bitmap_set_bit (&aligned_head, DECL_UID (t));
   17294              :           break;
   17295              : 
   17296          125 :         case OMP_CLAUSE_NONTEMPORAL:
   17297          125 :           t = OMP_CLAUSE_DECL (c);
   17298          125 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   17299              :             {
   17300            0 :               error_at (OMP_CLAUSE_LOCATION (c),
   17301              :                         "%qE is not a variable in %<nontemporal%> clause", t);
   17302            0 :               remove = true;
   17303              :             }
   17304          125 :           else if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
   17305              :             {
   17306            2 :               error_at (OMP_CLAUSE_LOCATION (c),
   17307              :                         "%qE appears more than once in %<nontemporal%> "
   17308              :                         "clauses", t);
   17309            2 :               remove = true;
   17310              :             }
   17311              :           else
   17312          123 :             bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
   17313              :           break;
   17314              : 
   17315          802 :         case OMP_CLAUSE_ALLOCATE:
   17316          802 :           t = OMP_CLAUSE_DECL (c);
   17317          802 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   17318              :             {
   17319            1 :               error_at (OMP_CLAUSE_LOCATION (c),
   17320              :                         "%qE is not a variable in %<allocate%> clause", t);
   17321            1 :               remove = true;
   17322              :             }
   17323          801 :           else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
   17324              :             {
   17325            2 :               warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
   17326              :                           "%qE appears more than once in %<allocate%> clauses",
   17327              :                           t);
   17328            2 :               remove = true;
   17329              :             }
   17330              :           else
   17331              :             {
   17332          799 :               bitmap_set_bit (&aligned_head, DECL_UID (t));
   17333          799 :               if (!OMP_CLAUSE_ALLOCATE_COMBINED (c))
   17334          700 :                 allocate_seen = true;
   17335              :             }
   17336              :           break;
   17337              : 
   17338          357 :         case OMP_CLAUSE_DOACROSS:
   17339          357 :           t = OMP_CLAUSE_DECL (c);
   17340          357 :           if (t == NULL_TREE)
   17341              :             break;
   17342          169 :           if (OMP_CLAUSE_DOACROSS_KIND (c) == OMP_CLAUSE_DOACROSS_SINK)
   17343              :             {
   17344          169 :               gcc_assert (TREE_CODE (t) == TREE_LIST);
   17345         1315 :               for (; t; t = TREE_CHAIN (t))
   17346              :                 {
   17347         1146 :                   tree decl = TREE_VALUE (t);
   17348         1146 :                   if (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE)
   17349              :                     {
   17350            3 :                       tree offset = TREE_PURPOSE (t);
   17351            3 :                       bool neg = wi::neg_p (wi::to_wide (offset));
   17352            3 :                       offset = fold_unary (ABS_EXPR, TREE_TYPE (offset), offset);
   17353            6 :                       tree t2 = pointer_int_sum (OMP_CLAUSE_LOCATION (c),
   17354              :                                                  neg ? MINUS_EXPR : PLUS_EXPR,
   17355              :                                                  decl, offset);
   17356            3 :                       t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
   17357              :                                             sizetype,
   17358              :                                             fold_convert (sizetype, t2),
   17359              :                                             fold_convert (sizetype, decl));
   17360            3 :                       if (t2 == error_mark_node)
   17361              :                         {
   17362              :                           remove = true;
   17363              :                           break;
   17364              :                         }
   17365            3 :                       TREE_PURPOSE (t) = t2;
   17366              :                     }
   17367              :                 }
   17368              :               break;
   17369              :             }
   17370            0 :           gcc_unreachable ();
   17371              : 
   17372           36 :         case OMP_CLAUSE_USES_ALLOCATORS:
   17373           36 :           t = OMP_CLAUSE_USES_ALLOCATORS_ALLOCATOR (c);
   17374           36 :           if (t == error_mark_node)
   17375              :             {
   17376              :               remove = true;
   17377              :               break;
   17378              :             }
   17379            6 :           if ((VAR_P (t) || TREE_CODE (t) == PARM_DECL)
   17380           33 :               && (bitmap_bit_p (&generic_head, DECL_UID (t))
   17381           27 :                   || bitmap_bit_p (&map_head, DECL_UID (t))
   17382           27 :                   || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
   17383           26 :                   || bitmap_bit_p (&lastprivate_head, DECL_UID (t))))
   17384              :             {
   17385            1 :               error_at (OMP_CLAUSE_LOCATION (c),
   17386              :                         "%qE appears more than once in data clauses", t);
   17387            1 :               remove = true;
   17388            1 :               break;
   17389              :             }
   17390              :           else
   17391           31 :             bitmap_set_bit (&generic_head, DECL_UID (t));
   17392           31 :           if (TREE_CODE (TREE_TYPE (t)) != ENUMERAL_TYPE
   17393           59 :               || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (TREE_TYPE (t))),
   17394              :                          "omp_allocator_handle_t") != 0)
   17395              :             {
   17396            3 :               error_at (OMP_CLAUSE_LOCATION (c),
   17397              :                         "allocator %qE must be of %<omp_allocator_handle_t%> "
   17398              :                         "type", t);
   17399            3 :               remove = true;
   17400            3 :               break;
   17401              :             }
   17402           28 :           tree init;
   17403           28 :           if (!DECL_P (t)
   17404           28 :               || (TREE_CODE (t) == CONST_DECL
   17405            5 :                   && ((init = DECL_INITIAL(t)) == nullptr
   17406            5 :                       || TREE_CODE (init) != INTEGER_CST
   17407            5 :                       || ((wi::to_widest (init) < 0
   17408            5 :                            || wi::to_widest (init) > GOMP_OMP_PREDEF_ALLOC_MAX)
   17409            0 :                           && (wi::to_widest (init) < GOMP_OMPX_PREDEF_ALLOC_MIN
   17410            0 :                               || (wi::to_widest (init)
   17411            0 :                                   > GOMP_OMPX_PREDEF_ALLOC_MAX))))))
   17412              :             {
   17413            0 :               remove = true;
   17414            0 :               error_at (OMP_CLAUSE_LOCATION (c),
   17415              :                         "allocator %qE must be either a variable or a "
   17416              :                         "predefined allocator", t);
   17417            0 :               break;
   17418              :             }
   17419           28 :           else if (TREE_CODE (t) == CONST_DECL)
   17420              :             {
   17421              :               /* omp_null_allocator is ignored and for predefined allocators,
   17422              :                  not special handling is required; thus, remove them removed. */
   17423            5 :               remove = true;
   17424              : 
   17425            5 :               if (OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE (c)
   17426            5 :                   || OMP_CLAUSE_USES_ALLOCATORS_TRAITS (c))
   17427              :                 {
   17428            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17429              :                             "modifiers cannot be used with predefined "
   17430              :                             "allocator %qE", t);
   17431            0 :                   break;
   17432              :                 }
   17433              :             }
   17434           28 :           t = OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE (c);
   17435           28 :           if (t == error_mark_node)
   17436              :             {
   17437              :               remove = true;
   17438              :               break;
   17439              :             }
   17440           28 :           if (t != NULL_TREE
   17441           28 :               && ((TREE_CODE (t) != CONST_DECL && TREE_CODE (t) != INTEGER_CST)
   17442            5 :                   || TREE_CODE (TREE_TYPE (t)) != ENUMERAL_TYPE
   17443            8 :                   || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (TREE_TYPE (t))),
   17444              :                              "omp_memspace_handle_t") != 0))
   17445              :             {
   17446            1 :               error_at (OMP_CLAUSE_LOCATION (c), "memspace modifier %qE must be"
   17447              :                         " constant enum of %<omp_memspace_handle_t%> type", t);
   17448            1 :               remove = true;
   17449            1 :               break;
   17450              :             }
   17451           27 :           t = OMP_CLAUSE_USES_ALLOCATORS_TRAITS (c);
   17452           27 :           if (t == error_mark_node)
   17453              :             {
   17454              :               remove = true;
   17455              :               break;
   17456              :             }
   17457           27 :           if (t != NULL_TREE
   17458              :               && t != error_mark_node
   17459           27 :               && (DECL_EXTERNAL (t)
   17460            9 :                   || TREE_CODE (t) == PARM_DECL))
   17461              :             {
   17462            3 :               error_at (OMP_CLAUSE_LOCATION (c), "traits array %qE must be "
   17463              :                         "defined in same scope as the construct on which the "
   17464              :                         "clause appears", t);
   17465            3 :               remove = true;
   17466              :             }
   17467           27 :           if (t != NULL_TREE)
   17468              :             {
   17469           11 :               bool type_err = false;
   17470              : 
   17471           11 :               if (TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE
   17472           10 :                   || DECL_SIZE (t) == NULL_TREE
   17473           20 :                   || !COMPLETE_TYPE_P (TREE_TYPE (t)))
   17474              :                 type_err = true;
   17475              :               else
   17476              :                 {
   17477            9 :                   tree elem_t = TREE_TYPE (TREE_TYPE (t));
   17478            9 :                   if (TREE_CODE (elem_t) != RECORD_TYPE
   17479           18 :                       || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (elem_t)),
   17480              :                                  "omp_alloctrait_t") != 0
   17481           18 :                       || !TYPE_READONLY (elem_t))
   17482              :                     type_err = true;
   17483              :                 }
   17484            8 :               if (type_err)
   17485              :                 {
   17486            3 :                   if (t != error_mark_node)
   17487            3 :                     error_at (OMP_CLAUSE_LOCATION (c), "traits array %qE must "
   17488              :                               "be of %<const omp_alloctrait_t []%> type", t);
   17489              :                   else
   17490            0 :                     error_at (OMP_CLAUSE_LOCATION (c), "traits array must "
   17491              :                               "be of %<const omp_alloctrait_t []%> type");
   17492              :                   remove = true;
   17493              :                 }
   17494              :               else
   17495              :                 {
   17496            8 :                   tree cst_val = decl_constant_value_1 (t, true);
   17497            8 :                   if (cst_val == t)
   17498              :                     {
   17499            1 :                       error_at (OMP_CLAUSE_LOCATION (c), "traits array must be "
   17500              :                                 "initialized with constants");
   17501              : 
   17502            1 :                       remove = true;
   17503              :                     }
   17504              :                 }
   17505              :             }
   17506           24 :           if (remove)
   17507              :             break;
   17508           18 :           pc = &OMP_CLAUSE_CHAIN (c);
   17509           18 :           continue;
   17510          713 :         case OMP_CLAUSE_DEPEND:
   17511          713 :           depend_clause = c;
   17512              :           /* FALLTHRU */
   17513          870 :         case OMP_CLAUSE_AFFINITY:
   17514          870 :           t = OMP_CLAUSE_DECL (c);
   17515          870 :           if (OMP_ITERATOR_DECL_P (t))
   17516              :             {
   17517          131 :               if (TREE_PURPOSE (t) != last_iterators)
   17518          111 :                 last_iterators_remove
   17519          111 :                   = c_omp_finish_iterators (TREE_PURPOSE (t));
   17520          131 :               last_iterators = TREE_PURPOSE (t);
   17521          131 :               t = TREE_VALUE (t);
   17522          131 :               if (last_iterators_remove)
   17523           34 :                 t = error_mark_node;
   17524              :             }
   17525              :           else
   17526              :             last_iterators = NULL_TREE;
   17527          870 :           if (TREE_CODE (t) == OMP_ARRAY_SECTION)
   17528              :             {
   17529          413 :               if (handle_omp_array_sections (c, ort))
   17530              :                 remove = true;
   17531          336 :               else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   17532          336 :                        && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ)
   17533              :                 {
   17534            1 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17535              :                             "%<depend%> clause with %<depobj%> dependence "
   17536              :                             "type on array section");
   17537            1 :                   remove = true;
   17538              :                 }
   17539              :               break;
   17540              :             }
   17541          457 :           if (t == error_mark_node)
   17542              :             remove = true;
   17543          423 :           else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   17544          423 :                    && t == ridpointers[RID_OMP_ALL_MEMORY])
   17545              :             {
   17546           15 :               if (OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_OUT
   17547           15 :                   && OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_INOUT)
   17548              :                 {
   17549            3 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17550              :                             "%<omp_all_memory%> used with %<depend%> kind "
   17551              :                             "other than %<out%> or %<inout%>");
   17552            3 :                   remove = true;
   17553              :                 }
   17554              :             }
   17555          408 :           else if (!lvalue_p (t))
   17556              :             {
   17557            6 :               error_at (OMP_CLAUSE_LOCATION (c),
   17558              :                         "%qE is not lvalue expression nor array section in "
   17559              :                         "%qs clause", t,
   17560            3 :                         omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17561            3 :               remove = true;
   17562              :             }
   17563          405 :           else if (TREE_CODE (t) == COMPONENT_REF
   17564          405 :                    && DECL_C_BIT_FIELD (TREE_OPERAND (t, 1)))
   17565              :             {
   17566            2 :               gcc_assert (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   17567              :                           || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY);
   17568            2 :               error_at (OMP_CLAUSE_LOCATION (c),
   17569              :                         "bit-field %qE in %qs clause", t,
   17570            2 :                         omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17571            2 :               remove = true;
   17572              :             }
   17573          403 :           else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   17574          403 :                    && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ)
   17575              :             {
   17576           20 :               if (!c_omp_depend_t_p (TREE_TYPE (t)))
   17577              :                 {
   17578            2 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17579              :                             "%qE does not have %<omp_depend_t%> type in "
   17580              :                             "%<depend%> clause with %<depobj%> dependence "
   17581              :                             "type", t);
   17582            2 :                   remove = true;
   17583              :                 }
   17584              :             }
   17585          383 :           else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   17586          383 :                    && c_omp_depend_t_p (TREE_TYPE (t)))
   17587              :             {
   17588            2 :               error_at (OMP_CLAUSE_LOCATION (c),
   17589              :                         "%qE should not have %<omp_depend_t%> type in "
   17590              :                         "%<depend%> clause with dependence type other than "
   17591              :                         "%<depobj%>", t);
   17592            2 :               remove = true;
   17593              :             }
   17594           12 :           if (!remove)
   17595              :             {
   17596          411 :               if (t == ridpointers[RID_OMP_ALL_MEMORY])
   17597           12 :                 t = null_pointer_node;
   17598              :               else
   17599              :                 {
   17600          399 :                   tree addr = build_unary_op (OMP_CLAUSE_LOCATION (c),
   17601              :                                               ADDR_EXPR, t, false);
   17602          399 :                   if (addr == error_mark_node)
   17603              :                     {
   17604              :                       remove = true;
   17605              :                       break;
   17606              :                     }
   17607          399 :                   t = build_indirect_ref (OMP_CLAUSE_LOCATION (c), addr,
   17608              :                                           RO_UNARY_STAR);
   17609          399 :                   if (t == error_mark_node)
   17610              :                     {
   17611              :                       remove = true;
   17612              :                       break;
   17613              :                     }
   17614              :                 }
   17615          411 :               if (OMP_ITERATOR_DECL_P (OMP_CLAUSE_DECL (c)))
   17616           31 :                 TREE_VALUE (OMP_CLAUSE_DECL (c)) = t;
   17617              :               else
   17618          380 :                 OMP_CLAUSE_DECL (c) = t;
   17619              :             }
   17620              :           break;
   17621              : 
   17622         6694 :         case OMP_CLAUSE_MAP:
   17623         6694 :           if (OMP_CLAUSE_MAP_IMPLICIT (c) && !implicit_moved)
   17624           58 :             goto move_implicit;
   17625         6636 :           if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_PUSH_MAPPER_NAME
   17626         6636 :               || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POP_MAPPER_NAME)
   17627              :             {
   17628              :               remove = true;
   17629              :               break;
   17630              :             }
   17631              :           /* FALLTHRU */
   17632         9509 :         case OMP_CLAUSE_TO:
   17633         9509 :         case OMP_CLAUSE_FROM:
   17634         9509 :           if (OMP_CLAUSE_ITERATORS (c)
   17635         9509 :               && c_omp_finish_iterators (OMP_CLAUSE_ITERATORS (c)))
   17636              :             {
   17637        22935 :               t = error_mark_node;
   17638              :               break;
   17639              :             }
   17640              :           /* FALLTHRU */
   17641         9645 :         case OMP_CLAUSE__CACHE_:
   17642         9645 :           {
   17643         9645 :             using namespace omp_addr_tokenizer;
   17644         9645 :             auto_vec<omp_addr_token *, 10> addr_tokens;
   17645              : 
   17646         9645 :             t = OMP_CLAUSE_DECL (c);
   17647         9645 :             if (TREE_CODE (t) == OMP_ARRAY_SECTION)
   17648              :               {
   17649         2001 :                 grp_start_p = pc;
   17650         2001 :                 grp_sentinel = OMP_CLAUSE_CHAIN (c);
   17651              : 
   17652         2001 :                 if (handle_omp_array_sections (c, ort))
   17653              :                   remove = true;
   17654              :                 else
   17655              :                   {
   17656         1861 :                     t = OMP_CLAUSE_DECL (c);
   17657         1861 :                     if (!omp_mappable_type (TREE_TYPE (t)))
   17658              :                       {
   17659            2 :                         error_at (OMP_CLAUSE_LOCATION (c),
   17660              :                                   "array section does not have mappable type "
   17661              :                                   "in %qs clause",
   17662            1 :                                   omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17663            1 :                         remove = true;
   17664              :                       }
   17665         1860 :                     else if (TYPE_ATOMIC (TREE_TYPE (t)))
   17666              :                       {
   17667            2 :                         error_at (OMP_CLAUSE_LOCATION (c),
   17668              :                                   "%<_Atomic%> %qE in %qs clause", t,
   17669            1 :                                   omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17670            1 :                         remove = true;
   17671              :                       }
   17672         2510 :                     while (TREE_CODE (t) == ARRAY_REF)
   17673          649 :                       t = TREE_OPERAND (t, 0);
   17674              : 
   17675         1861 :                     c_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
   17676              : 
   17677         1861 :                     if (!omp_parse_expr (addr_tokens, t))
   17678              :                       {
   17679            0 :                         sorry_at (OMP_CLAUSE_LOCATION (c),
   17680              :                                   "unsupported map expression %qE",
   17681            0 :                                   OMP_CLAUSE_DECL (c));
   17682            0 :                         remove = true;
   17683            0 :                         break;
   17684              :                       }
   17685              : 
   17686              :                     /* This check is to determine if this will be the only map
   17687              :                        node created for this clause.  Otherwise, we'll check
   17688              :                        the following FIRSTPRIVATE_POINTER or ATTACH_DETACH
   17689              :                        node on the next iteration(s) of the loop.   */
   17690         3704 :                     if (addr_tokens.length () >= 4
   17691          304 :                         && addr_tokens[0]->type == STRUCTURE_BASE
   17692          302 :                         && addr_tokens[0]->u.structure_base_kind == BASE_DECL
   17693          302 :                         && addr_tokens[1]->type == ACCESS_METHOD
   17694          302 :                         && addr_tokens[2]->type == COMPONENT_SELECTOR
   17695          302 :                         && addr_tokens[3]->type == ACCESS_METHOD
   17696         2102 :                         && (addr_tokens[3]->u.access_kind == ACCESS_DIRECT
   17697          188 :                             || (addr_tokens[3]->u.access_kind
   17698              :                                 == ACCESS_INDEXED_ARRAY)))
   17699              :                       {
   17700           55 :                         tree rt = addr_tokens[1]->expr;
   17701              : 
   17702           55 :                         gcc_assert (DECL_P (rt));
   17703              : 
   17704           55 :                         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   17705           50 :                             && OMP_CLAUSE_MAP_IMPLICIT (c)
   17706           55 :                             && (bitmap_bit_p (&map_head, DECL_UID (rt))
   17707            0 :                                 || bitmap_bit_p (&map_field_head, DECL_UID (rt))
   17708            0 :                                 || bitmap_bit_p (&map_firstprivate_head,
   17709            0 :                                                  DECL_UID (rt))))
   17710              :                           {
   17711              :                             remove = true;
   17712              :                             break;
   17713              :                           }
   17714           55 :                         if (bitmap_bit_p (&map_field_head, DECL_UID (rt)))
   17715              :                           break;
   17716           37 :                         if (bitmap_bit_p (&map_head, DECL_UID (rt)))
   17717              :                           {
   17718            0 :                             if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
   17719            0 :                               error_at (OMP_CLAUSE_LOCATION (c),
   17720              :                                         "%qD appears more than once in motion "
   17721              :                                         "clauses", rt);
   17722            0 :                             else if (openacc)
   17723            0 :                               error_at (OMP_CLAUSE_LOCATION (c),
   17724              :                                         "%qD appears more than once in data "
   17725              :                                         "clauses", rt);
   17726              :                             else
   17727            0 :                               error_at (OMP_CLAUSE_LOCATION (c),
   17728              :                                         "%qD appears more than once in map "
   17729              :                                         "clauses", rt);
   17730              :                             remove = true;
   17731              :                           }
   17732              :                         else
   17733              :                           {
   17734           37 :                             bitmap_set_bit (&map_head, DECL_UID (rt));
   17735           37 :                             bitmap_set_bit (&map_field_head, DECL_UID (rt));
   17736              :                           }
   17737              :                       }
   17738         1861 :                   }
   17739         1983 :                 if (c_oacc_check_attachments (c))
   17740            2 :                   remove = true;
   17741         1983 :                 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   17742         1807 :                     && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
   17743         1789 :                         || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
   17744         2008 :                     && !OMP_CLAUSE_SIZE (c))
   17745              :                   /* In this case, we have a single array element which is a
   17746              :                      pointer, and we already set OMP_CLAUSE_SIZE in
   17747              :                      handle_omp_array_sections above.  For attach/detach
   17748              :                      clauses, reset the OMP_CLAUSE_SIZE (representing a bias)
   17749              :                      to zero here.  */
   17750           10 :                   OMP_CLAUSE_SIZE (c) = size_zero_node;
   17751              :                 break;
   17752              :               }
   17753         7644 :             else if (!omp_parse_expr (addr_tokens, t))
   17754              :               {
   17755            0 :                 sorry_at (OMP_CLAUSE_LOCATION (c),
   17756              :                           "unsupported map expression %qE",
   17757            0 :                           OMP_CLAUSE_DECL (c));
   17758            0 :                 remove = true;
   17759            0 :                 break;
   17760              :               }
   17761         7644 :             if (t == error_mark_node)
   17762              :               {
   17763              :                 remove = true;
   17764              :                 break;
   17765              :               }
   17766              :             /* OpenACC attach / detach clauses must be pointers.  */
   17767         7632 :             if (c_oacc_check_attachments (c))
   17768              :               {
   17769              :                 remove = true;
   17770              :                 break;
   17771              :               }
   17772         7628 :             if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   17773         4781 :                 && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
   17774         4754 :                     || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
   17775         7670 :                 && !OMP_CLAUSE_SIZE (c))
   17776              :               /* For attach/detach clauses, set OMP_CLAUSE_SIZE (representing a
   17777              :                  bias) to zero here, so it is not set erroneously to the pointer
   17778              :                  size later on in gimplify.cc.  */
   17779           28 :               OMP_CLAUSE_SIZE (c) = size_zero_node;
   17780              : 
   17781         7628 :             c_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
   17782              : 
   17783         7628 :             if (!ai.check_clause (c))
   17784              :               {
   17785              :                 remove = true;
   17786              :                 break;
   17787              :               }
   17788              : 
   17789         7620 :             if (!ai.map_supported_p ())
   17790              :               {
   17791           14 :                 sorry_at (OMP_CLAUSE_LOCATION (c),
   17792              :                           "unsupported map expression %qE",
   17793            7 :                           OMP_CLAUSE_DECL (c));
   17794            7 :                 remove = true;
   17795            7 :                 break;
   17796              :               }
   17797              : 
   17798        15226 :             gcc_assert ((addr_tokens[0]->type == ARRAY_BASE
   17799              :                          || addr_tokens[0]->type == STRUCTURE_BASE)
   17800              :                         && addr_tokens[1]->type == ACCESS_METHOD);
   17801              : 
   17802         7613 :             t = addr_tokens[1]->expr;
   17803              : 
   17804         7613 :             if (addr_tokens[0]->u.structure_base_kind != BASE_DECL)
   17805            0 :               goto skip_decl_checks;
   17806              : 
   17807              :             /* For OpenMP, we can access a struct "t" and "t.d" on the same
   17808              :                mapping.  OpenACC allows multiple fields of the same structure
   17809              :                to be written.  */
   17810         7613 :             if (addr_tokens[0]->type == STRUCTURE_BASE
   17811         7613 :                 && (bitmap_bit_p (&map_field_head, DECL_UID (t))
   17812          260 :                     || (!openacc && bitmap_bit_p (&map_head, DECL_UID (t)))))
   17813          307 :               goto skip_decl_checks;
   17814              : 
   17815         7306 :             if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   17816              :               {
   17817            3 :                 if (ort != C_ORT_ACC && EXPR_P (t))
   17818              :                   break;
   17819              : 
   17820            6 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17821              :                           "%qE is not a variable in %qs clause", t,
   17822            3 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17823            3 :                 remove = true;
   17824              :               }
   17825         7303 :             else if (VAR_P (t) && DECL_THREAD_LOCAL_P (t))
   17826              :               {
   17827            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17828              :                           "%qD is threadprivate variable in %qs clause", t,
   17829            0 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17830            0 :                 remove = true;
   17831              :               }
   17832         7303 :             else if ((OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
   17833         4483 :                       || (OMP_CLAUSE_MAP_KIND (c)
   17834              :                           != GOMP_MAP_FIRSTPRIVATE_POINTER))
   17835        10743 :                      && !c_mark_addressable (t))
   17836              :               remove = true;
   17837         7303 :             else if (!(OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   17838         4483 :                        && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
   17839         4483 :                            || (OMP_CLAUSE_MAP_KIND (c)
   17840              :                                == GOMP_MAP_FIRSTPRIVATE_POINTER)
   17841         3440 :                            || (OMP_CLAUSE_MAP_KIND (c)
   17842              :                                == GOMP_MAP_FORCE_DEVICEPTR)))
   17843         6202 :                      && t == OMP_CLAUSE_DECL (c)
   17844        13247 :                      && !omp_mappable_type (TREE_TYPE (t)))
   17845              :               {
   17846           16 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17847              :                           "%qD does not have a mappable type in %qs clause", t,
   17848            8 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17849            8 :                 remove = true;
   17850              :               }
   17851         7295 :             else if (TREE_TYPE (t) == error_mark_node)
   17852              :               remove = true;
   17853         7294 :             else if (TYPE_ATOMIC (strip_array_types (TREE_TYPE (t))))
   17854              :               {
   17855            8 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17856              :                           "%<_Atomic%> %qE in %qs clause", t,
   17857            4 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17858            4 :                 remove = true;
   17859              :               }
   17860         7290 :             else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   17861         4473 :                      && OMP_CLAUSE_MAP_IMPLICIT (c)
   17862         7421 :                      && (bitmap_bit_p (&map_head, DECL_UID (t))
   17863          130 :                          || bitmap_bit_p (&map_field_head, DECL_UID (t))
   17864          130 :                          || bitmap_bit_p (&map_firstprivate_head,
   17865          130 :                                           DECL_UID (t))))
   17866              :               remove = true;
   17867         7288 :             else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   17868         7288 :                      && (OMP_CLAUSE_MAP_KIND (c)
   17869              :                          == GOMP_MAP_FIRSTPRIVATE_POINTER))
   17870              :               {
   17871         1041 :                 if (bitmap_bit_p (&generic_head, DECL_UID (t))
   17872         1041 :                     || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
   17873         2081 :                     || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
   17874              :                   {
   17875            4 :                     error_at (OMP_CLAUSE_LOCATION (c),
   17876              :                               "%qD appears more than once in data clauses", t);
   17877            4 :                     remove = true;
   17878              :                   }
   17879         1037 :                 else if (bitmap_bit_p (&map_head, DECL_UID (t))
   17880            4 :                          && !bitmap_bit_p (&map_field_head, DECL_UID (t))
   17881         1039 :                          && openacc)
   17882              :                   {
   17883            1 :                     error_at (OMP_CLAUSE_LOCATION (c),
   17884              :                               "%qD appears more than once in data clauses", t);
   17885            1 :                     remove = true;
   17886              :                   }
   17887              :                 else
   17888         1036 :                   bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
   17889              :               }
   17890         6247 :             else if (bitmap_bit_p (&map_head, DECL_UID (t))
   17891           64 :                      && !bitmap_bit_p (&map_field_head, DECL_UID (t))
   17892           18 :                      && ort != C_ORT_OMP
   17893           18 :                      && ort != C_ORT_OMP_TARGET
   17894         6257 :                      && ort != C_ORT_OMP_EXIT_DATA)
   17895              :               {
   17896            7 :                 if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
   17897            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17898              :                             "%qD appears more than once in motion clauses", t);
   17899            7 :                 else if (openacc)
   17900            7 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17901              :                             "%qD appears more than once in data clauses", t);
   17902              :                 else
   17903            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17904              :                             "%qD appears more than once in map clauses", t);
   17905              :                 remove = true;
   17906              :               }
   17907         6240 :             else if (openacc && bitmap_bit_p (&generic_head, DECL_UID (t)))
   17908              :               {
   17909            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17910              :                           "%qD appears more than once in data clauses", t);
   17911            0 :                 remove = true;
   17912              :               }
   17913         6240 :             else if (bitmap_bit_p (&firstprivate_head, DECL_UID (t))
   17914         6240 :                      || bitmap_bit_p (&is_on_device_head, DECL_UID (t)))
   17915              :               {
   17916            9 :                 if (openacc)
   17917            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17918              :                             "%qD appears more than once in data clauses", t);
   17919              :                 else
   17920            9 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17921              :                             "%qD appears both in data and map clauses", t);
   17922              :                 remove = true;
   17923              :               }
   17924         6231 :             else if (!omp_access_chain_p (addr_tokens, 1))
   17925              :               {
   17926         6231 :                 bitmap_set_bit (&map_head, DECL_UID (t));
   17927         6231 :                 if (t != OMP_CLAUSE_DECL (c)
   17928         6231 :                     && TREE_CODE (OMP_CLAUSE_DECL (c)) == COMPONENT_REF)
   17929          254 :                   bitmap_set_bit (&map_field_head, DECL_UID (t));
   17930              :               }
   17931              : 
   17932            0 :           skip_decl_checks:
   17933              :             /* If we call omp_expand_map_clause in handle_omp_array_sections,
   17934              :                the containing loop (here) iterates through the new nodes
   17935              :                created by that expansion.  Avoid expanding those again (just
   17936              :                by checking the node type).  */
   17937         7613 :             if (!remove
   17938         7613 :                 && ort != C_ORT_DECLARE_SIMD
   17939         7613 :                 && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
   17940         4731 :                     || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FIRSTPRIVATE_POINTER
   17941         3695 :                         && (OMP_CLAUSE_MAP_KIND (c)
   17942              :                             != GOMP_MAP_FIRSTPRIVATE_REFERENCE)
   17943         3695 :                         && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ALWAYS_POINTER
   17944         3695 :                         && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH
   17945         3395 :                         && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
   17946         3368 :                         && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH)))
   17947              :               {
   17948         6196 :                 grp_start_p = pc;
   17949         6196 :                 grp_sentinel = OMP_CLAUSE_CHAIN (c);
   17950         6196 :                 tree nc = ai.expand_map_clause (c, OMP_CLAUSE_DECL (c),
   17951              :                                                 addr_tokens, ort);
   17952         6196 :                 if (nc != error_mark_node)
   17953         6196 :                   c = nc;
   17954              :               }
   17955         9660 :           }
   17956         7613 :           break;
   17957              : 
   17958          232 :         case OMP_CLAUSE_ENTER:
   17959          232 :         case OMP_CLAUSE_LINK:
   17960          232 :           t = OMP_CLAUSE_DECL (c);
   17961          232 :           const char *cname;
   17962          232 :           cname = omp_clause_code_name[OMP_CLAUSE_CODE (c)];
   17963          232 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER
   17964          232 :               && OMP_CLAUSE_ENTER_TO (c))
   17965              :             cname = "to";
   17966          232 :           if (TREE_CODE (t) == FUNCTION_DECL
   17967          232 :               && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
   17968              :             ;
   17969          151 :           else if (!VAR_P (t))
   17970              :             {
   17971            1 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
   17972            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17973              :                           "%qE is neither a variable nor a function name in "
   17974              :                           "clause %qs", t, cname);
   17975              :               else
   17976            1 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17977              :                           "%qE is not a variable in clause %qs", t, cname);
   17978              :               remove = true;
   17979              :             }
   17980          150 :           else if (DECL_THREAD_LOCAL_P (t))
   17981              :             {
   17982            2 :               error_at (OMP_CLAUSE_LOCATION (c),
   17983              :                         "%qD is threadprivate variable in %qs clause", t,
   17984              :                         cname);
   17985            2 :               remove = true;
   17986              :             }
   17987          148 :           else if (!omp_mappable_type (TREE_TYPE (t)))
   17988              :             {
   17989            6 :               error_at (OMP_CLAUSE_LOCATION (c),
   17990              :                         "%qD does not have a mappable type in %qs clause", t,
   17991              :                         cname);
   17992            6 :               remove = true;
   17993              :             }
   17994            8 :           if (remove)
   17995              :             break;
   17996          223 :           if (bitmap_bit_p (&generic_head, DECL_UID (t)))
   17997              :             {
   17998            8 :               error_at (OMP_CLAUSE_LOCATION (c),
   17999              :                         "%qE appears more than once on the same "
   18000              :                         "%<declare target%> directive", t);
   18001            8 :               remove = true;
   18002              :             }
   18003              :           else
   18004          215 :             bitmap_set_bit (&generic_head, DECL_UID (t));
   18005              :           break;
   18006              : 
   18007          117 :         case OMP_CLAUSE_UNIFORM:
   18008          117 :           t = OMP_CLAUSE_DECL (c);
   18009          117 :           if (TREE_CODE (t) != PARM_DECL)
   18010              :             {
   18011            0 :               if (DECL_P (t))
   18012            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   18013              :                           "%qD is not an argument in %<uniform%> clause", t);
   18014              :               else
   18015            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   18016              :                           "%qE is not an argument in %<uniform%> clause", t);
   18017              :               remove = true;
   18018              :               break;
   18019              :             }
   18020              :           /* map_head bitmap is used as uniform_head if declare_simd.  */
   18021          117 :           bitmap_set_bit (&map_head, DECL_UID (t));
   18022          117 :           goto check_dup_generic;
   18023              : 
   18024          161 :         case OMP_CLAUSE_IS_DEVICE_PTR:
   18025          161 :         case OMP_CLAUSE_USE_DEVICE_PTR:
   18026          161 :           t = OMP_CLAUSE_DECL (c);
   18027          161 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
   18028          123 :             bitmap_set_bit (&is_on_device_head, DECL_UID (t));
   18029          161 :           if (TREE_CODE (TREE_TYPE (t)) != POINTER_TYPE)
   18030              :             {
   18031           21 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
   18032           21 :                   && !openacc)
   18033              :                 {
   18034            1 :                   error_at (OMP_CLAUSE_LOCATION (c),
   18035              :                             "%qs variable is not a pointer",
   18036            1 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   18037            1 :                   remove = true;
   18038              :                 }
   18039           20 :               else if (TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE)
   18040              :                 {
   18041            4 :                   error_at (OMP_CLAUSE_LOCATION (c),
   18042              :                             "%qs variable is neither a pointer nor an array",
   18043            4 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   18044            4 :                   remove = true;
   18045              :                 }
   18046              :             }
   18047          161 :           goto check_dup_generic;
   18048              : 
   18049           89 :         case OMP_CLAUSE_HAS_DEVICE_ADDR:
   18050           89 :           t = OMP_CLAUSE_DECL (c);
   18051           89 :           if (TREE_CODE (t) == OMP_ARRAY_SECTION)
   18052              :             {
   18053           11 :               if (handle_omp_array_sections (c, ort))
   18054              :                 remove = true;
   18055              :               else
   18056              :                 {
   18057           11 :                   t = OMP_CLAUSE_DECL (c);
   18058           24 :                   while (TREE_CODE (t) == ARRAY_REF)
   18059           13 :                     t = TREE_OPERAND (t, 0);
   18060              :                 }
   18061              :             }
   18062           89 :           bitmap_set_bit (&is_on_device_head, DECL_UID (t));
   18063           89 :           if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
   18064           89 :             c_mark_addressable (t);
   18065           89 :           goto check_dup_generic_t;
   18066              : 
   18067           36 :         case OMP_CLAUSE_USE_DEVICE_ADDR:
   18068           36 :           t = OMP_CLAUSE_DECL (c);
   18069           36 :           if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
   18070           36 :             c_mark_addressable (t);
   18071           36 :           goto check_dup_generic;
   18072              : 
   18073         4791 :         case OMP_CLAUSE_NOWAIT:
   18074         4791 :           if (copyprivate_seen)
   18075              :             {
   18076            1 :               error_at (OMP_CLAUSE_LOCATION (c),
   18077              :                         "%<nowait%> clause must not be used together "
   18078              :                         "with %<copyprivate%> clause");
   18079            1 :               remove = true;
   18080            1 :               break;
   18081              :             }
   18082         4790 :           nowait_clause = pc;
   18083         4790 :           pc = &OMP_CLAUSE_CHAIN (c);
   18084         4790 :           continue;
   18085              : 
   18086          523 :         case OMP_CLAUSE_ORDER:
   18087          523 :           if (ordered_clause)
   18088              :             {
   18089            2 :               error_at (OMP_CLAUSE_LOCATION (c),
   18090              :                         "%<order%> clause must not be used together "
   18091              :                         "with %<ordered%> clause");
   18092            2 :               remove = true;
   18093            2 :               break;
   18094              :             }
   18095          521 :           else if (order_clause)
   18096              :             {
   18097              :               /* Silently remove duplicates.  */
   18098              :               remove = true;
   18099              :               break;
   18100              :             }
   18101          513 :           order_clause = pc;
   18102          513 :           pc = &OMP_CLAUSE_CHAIN (c);
   18103          513 :           continue;
   18104              : 
   18105           32 :         case OMP_CLAUSE_DETACH:
   18106           32 :           t = OMP_CLAUSE_DECL (c);
   18107           32 :           if (detach_seen)
   18108              :             {
   18109            1 :               error_at (OMP_CLAUSE_LOCATION (c),
   18110              :                         "too many %qs clauses on a task construct",
   18111              :                         "detach");
   18112            1 :               remove = true;
   18113            1 :               break;
   18114              :             }
   18115           31 :           detach_seen = pc;
   18116           31 :           pc = &OMP_CLAUSE_CHAIN (c);
   18117           31 :           c_mark_addressable (t);
   18118           31 :           continue;
   18119              : 
   18120        14583 :         case OMP_CLAUSE_IF:
   18121        14583 :         case OMP_CLAUSE_SELF:
   18122        14583 :         case OMP_CLAUSE_NUM_THREADS:
   18123        14583 :         case OMP_CLAUSE_NUM_TEAMS:
   18124        14583 :         case OMP_CLAUSE_THREAD_LIMIT:
   18125        14583 :         case OMP_CLAUSE_DEFAULT:
   18126        14583 :         case OMP_CLAUSE_UNTIED:
   18127        14583 :         case OMP_CLAUSE_COLLAPSE:
   18128        14583 :         case OMP_CLAUSE_FINAL:
   18129        14583 :         case OMP_CLAUSE_DEVICE:
   18130        14583 :         case OMP_CLAUSE_DIST_SCHEDULE:
   18131        14583 :         case OMP_CLAUSE_DYN_GROUPPRIVATE:
   18132        14583 :         case OMP_CLAUSE_PARALLEL:
   18133        14583 :         case OMP_CLAUSE_FOR:
   18134        14583 :         case OMP_CLAUSE_SECTIONS:
   18135        14583 :         case OMP_CLAUSE_TASKGROUP:
   18136        14583 :         case OMP_CLAUSE_PROC_BIND:
   18137        14583 :         case OMP_CLAUSE_DEVICE_TYPE:
   18138        14583 :         case OMP_CLAUSE_PRIORITY:
   18139        14583 :         case OMP_CLAUSE_THREADS:
   18140        14583 :         case OMP_CLAUSE_SIMD:
   18141        14583 :         case OMP_CLAUSE_HINT:
   18142        14583 :         case OMP_CLAUSE_FILTER:
   18143        14583 :         case OMP_CLAUSE_DEFAULTMAP:
   18144        14583 :         case OMP_CLAUSE_BIND:
   18145        14583 :         case OMP_CLAUSE_NUM_GANGS:
   18146        14583 :         case OMP_CLAUSE_NUM_WORKERS:
   18147        14583 :         case OMP_CLAUSE_VECTOR_LENGTH:
   18148        14583 :         case OMP_CLAUSE_ASYNC:
   18149        14583 :         case OMP_CLAUSE_WAIT:
   18150        14583 :         case OMP_CLAUSE_AUTO:
   18151        14583 :         case OMP_CLAUSE_INDEPENDENT:
   18152        14583 :         case OMP_CLAUSE_SEQ:
   18153        14583 :         case OMP_CLAUSE_GANG:
   18154        14583 :         case OMP_CLAUSE_WORKER:
   18155        14583 :         case OMP_CLAUSE_VECTOR:
   18156        14583 :         case OMP_CLAUSE_TILE:
   18157        14583 :         case OMP_CLAUSE_IF_PRESENT:
   18158        14583 :         case OMP_CLAUSE_FINALIZE:
   18159        14583 :         case OMP_CLAUSE_NOHOST:
   18160        14583 :         case OMP_CLAUSE_INDIRECT:
   18161        14583 :         case OMP_CLAUSE_NOVARIANTS:
   18162        14583 :         case OMP_CLAUSE_NOCONTEXT:
   18163        14583 :           pc = &OMP_CLAUSE_CHAIN (c);
   18164        14583 :           continue;
   18165              : 
   18166           62 :         case OMP_CLAUSE_GRAINSIZE:
   18167           62 :           grainsize_seen = pc;
   18168           62 :           pc = &OMP_CLAUSE_CHAIN (c);
   18169           62 :           continue;
   18170              : 
   18171           50 :         case OMP_CLAUSE_NUM_TASKS:
   18172           50 :           num_tasks_seen = true;
   18173           50 :           pc = &OMP_CLAUSE_CHAIN (c);
   18174           50 :           continue;
   18175              : 
   18176           79 :         case OMP_CLAUSE_MERGEABLE:
   18177           79 :           mergeable_seen = true;
   18178           79 :           pc = &OMP_CLAUSE_CHAIN (c);
   18179           79 :           continue;
   18180              : 
   18181           18 :         case OMP_CLAUSE_NOGROUP:
   18182           18 :           nogroup_seen = pc;
   18183           18 :           pc = &OMP_CLAUSE_CHAIN (c);
   18184           18 :           continue;
   18185              : 
   18186         3465 :         case OMP_CLAUSE_SCHEDULE:
   18187         3465 :           schedule_clause = c;
   18188         3465 :           pc = &OMP_CLAUSE_CHAIN (c);
   18189         3465 :           continue;
   18190              : 
   18191          304 :         case OMP_CLAUSE_ORDERED:
   18192          304 :           ordered_clause = c;
   18193          304 :           if (order_clause)
   18194              :             {
   18195            2 :               error_at (OMP_CLAUSE_LOCATION (*order_clause),
   18196              :                         "%<order%> clause must not be used together "
   18197              :                         "with %<ordered%> clause");
   18198            2 :               *order_clause = OMP_CLAUSE_CHAIN (*order_clause);
   18199            2 :               order_clause = NULL;
   18200              :             }
   18201          304 :           pc = &OMP_CLAUSE_CHAIN (c);
   18202          304 :           continue;
   18203              : 
   18204          223 :         case OMP_CLAUSE_SAFELEN:
   18205          223 :           safelen = c;
   18206          223 :           pc = &OMP_CLAUSE_CHAIN (c);
   18207          223 :           continue;
   18208          320 :         case OMP_CLAUSE_SIMDLEN:
   18209          320 :           simdlen = c;
   18210          320 :           pc = &OMP_CLAUSE_CHAIN (c);
   18211          320 :           continue;
   18212              : 
   18213           69 :         case OMP_CLAUSE_FULL:
   18214           69 :           full_seen = pc;
   18215           69 :           pc = &OMP_CLAUSE_CHAIN (c);
   18216           69 :           continue;
   18217              : 
   18218          223 :         case OMP_CLAUSE_PARTIAL:
   18219          223 :           partial_seen = true;
   18220          223 :           pc = &OMP_CLAUSE_CHAIN (c);
   18221          223 :           continue;
   18222              : 
   18223            0 :         case OMP_CLAUSE_SIZES:
   18224            0 :           pc = &OMP_CLAUSE_CHAIN (c);
   18225            0 :           continue;
   18226              : 
   18227          205 :         case OMP_CLAUSE_INBRANCH:
   18228          205 :         case OMP_CLAUSE_NOTINBRANCH:
   18229          205 :           if (branch_seen)
   18230              :             {
   18231            1 :               error_at (OMP_CLAUSE_LOCATION (c),
   18232              :                         "%<inbranch%> clause is incompatible with "
   18233              :                         "%<notinbranch%>");
   18234            1 :               remove = true;
   18235            1 :               break;
   18236              :             }
   18237          204 :           branch_seen = true;
   18238          204 :           pc = &OMP_CLAUSE_CHAIN (c);
   18239          204 :           continue;
   18240              : 
   18241          367 :         case OMP_CLAUSE_INCLUSIVE:
   18242          367 :         case OMP_CLAUSE_EXCLUSIVE:
   18243          367 :           need_complete = true;
   18244          367 :           need_implicitly_determined = true;
   18245          367 :           t = OMP_CLAUSE_DECL (c);
   18246          367 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   18247              :             {
   18248            0 :               error_at (OMP_CLAUSE_LOCATION (c),
   18249              :                         "%qE is not a variable in clause %qs", t,
   18250            0 :                         omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   18251            0 :               remove = true;
   18252              :             }
   18253              :           break;
   18254              : 
   18255          152 :         case OMP_CLAUSE_INIT:
   18256          152 :           init_seen = true;
   18257          152 :           if (!OMP_CLAUSE_INIT_TARGETSYNC (c))
   18258           71 :             init_no_targetsync_clause = c;
   18259              :           /* FALLTHRU */
   18260          242 :         case OMP_CLAUSE_DESTROY:
   18261          242 :         case OMP_CLAUSE_USE:
   18262          242 :           init_use_destroy_seen = true;
   18263          242 :           t = OMP_CLAUSE_DECL (c);
   18264          242 :           if (bitmap_bit_p (&generic_head, DECL_UID (t)))
   18265              :             {
   18266            3 :               error_at (OMP_CLAUSE_LOCATION (c),
   18267              :                         "%qD appears more than once in action clauses", t);
   18268            3 :               remove = true;
   18269            3 :               break;
   18270              :             }
   18271          239 :           bitmap_set_bit (&generic_head, DECL_UID (t));
   18272              :           /* FALLTHRU */
   18273          298 :         case OMP_CLAUSE_INTEROP:
   18274          298 :           if (/* ort == C_ORT_OMP_INTEROP [uncomment for depobj init]  */
   18275          298 :                    !c_omp_interop_t_p (TREE_TYPE (OMP_CLAUSE_DECL (c))))
   18276              :             {
   18277           40 :               error_at (OMP_CLAUSE_LOCATION (c),
   18278              :                         "%qD must be of %<omp_interop_t%>",
   18279           20 :                         OMP_CLAUSE_DECL (c));
   18280           20 :               remove = true;
   18281              :             }
   18282          278 :           else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INIT
   18283          133 :                     || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DESTROY)
   18284          318 :                    && TREE_READONLY (OMP_CLAUSE_DECL (c)))
   18285              :             {
   18286           12 :               error_at (OMP_CLAUSE_LOCATION (c),
   18287            6 :                       "%qD shall not be const", OMP_CLAUSE_DECL (c));
   18288            6 :               remove = true;
   18289              :             }
   18290          298 :           pc = &OMP_CLAUSE_CHAIN (c);
   18291          298 :           break;
   18292            0 :         default:
   18293            0 :           gcc_unreachable ();
   18294        24952 :         }
   18295              : 
   18296        22935 :       if (!remove)
   18297              :         {
   18298        22381 :           t = OMP_CLAUSE_DECL (c);
   18299              : 
   18300        22381 :           if (need_complete)
   18301              :             {
   18302         3953 :               t = require_complete_type (OMP_CLAUSE_LOCATION (c), t);
   18303         3953 :               if (t == error_mark_node)
   18304            7 :                 remove = true;
   18305              :             }
   18306              : 
   18307        22381 :           if (need_implicitly_determined)
   18308              :             {
   18309         9552 :               const char *share_name = NULL;
   18310              : 
   18311         9552 :               if (VAR_P (t) && DECL_THREAD_LOCAL_P (t))
   18312              :                 share_name = "threadprivate";
   18313         9546 :               else switch (c_omp_predetermined_sharing (t))
   18314              :                 {
   18315              :                 case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
   18316              :                   break;
   18317           20 :                 case OMP_CLAUSE_DEFAULT_SHARED:
   18318           20 :                   if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
   18319           12 :                        || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE)
   18320           28 :                       && c_omp_predefined_variable (t))
   18321              :                     /* The __func__ variable and similar function-local
   18322              :                        predefined variables may be listed in a shared or
   18323              :                        firstprivate clause.  */
   18324              :                     break;
   18325              :                   share_name = "shared";
   18326              :                   break;
   18327              :                 case OMP_CLAUSE_DEFAULT_PRIVATE:
   18328              :                   share_name = "private";
   18329              :                   break;
   18330            0 :                 default:
   18331            0 :                   gcc_unreachable ();
   18332              :                 }
   18333              :               if (share_name)
   18334              :                 {
   18335           20 :                   error_at (OMP_CLAUSE_LOCATION (c),
   18336              :                             "%qE is predetermined %qs for %qs",
   18337              :                             t, share_name,
   18338           10 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   18339           10 :                   remove = true;
   18340              :                 }
   18341         9542 :               else if (TREE_READONLY (t)
   18342           23 :                        && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
   18343         9555 :                        && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE)
   18344              :                 {
   18345            4 :                   error_at (OMP_CLAUSE_LOCATION (c),
   18346              :                             "%<const%> qualified %qE may appear only in "
   18347              :                             "%<shared%> or %<firstprivate%> clauses", t);
   18348            4 :                   remove = true;
   18349              :                 }
   18350              :             }
   18351              :         }
   18352              : 
   18353        22381 :       if (remove)
   18354              :         {
   18355          575 :           if (grp_start_p)
   18356              :             {
   18357              :               /* If we found a clause to remove, we want to remove the whole
   18358              :                  expanded group, otherwise gimplify
   18359              :                  (omp_resolve_clause_dependencies) can get confused.  */
   18360          153 :               *grp_start_p = grp_sentinel;
   18361          153 :               pc = grp_start_p;
   18362          153 :               grp_start_p = NULL;
   18363              :             }
   18364              :           else
   18365          422 :             *pc = OMP_CLAUSE_CHAIN (c);
   18366              :         }
   18367              :       else
   18368        22360 :         pc = &OMP_CLAUSE_CHAIN (c);
   18369              :     }
   18370              : 
   18371        29559 :   if (grp_start_p
   18372        29559 :       && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
   18373           52 :     for (tree gc = *grp_start_p; gc; gc = OMP_CLAUSE_CHAIN (gc))
   18374           32 :       OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
   18375              : 
   18376        29559 :   if (simdlen
   18377        29559 :       && safelen
   18378        29676 :       && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen),
   18379          117 :                           OMP_CLAUSE_SIMDLEN_EXPR (simdlen)))
   18380              :     {
   18381            0 :       error_at (OMP_CLAUSE_LOCATION (simdlen),
   18382              :                 "%<simdlen%> clause value is bigger than "
   18383              :                 "%<safelen%> clause value");
   18384            0 :       OMP_CLAUSE_SIMDLEN_EXPR (simdlen)
   18385            0 :         = OMP_CLAUSE_SAFELEN_EXPR (safelen);
   18386              :     }
   18387              : 
   18388        29559 :   if (ordered_clause
   18389        29559 :       && schedule_clause
   18390        29559 :       && (OMP_CLAUSE_SCHEDULE_KIND (schedule_clause)
   18391              :           & OMP_CLAUSE_SCHEDULE_NONMONOTONIC))
   18392              :     {
   18393            7 :       error_at (OMP_CLAUSE_LOCATION (schedule_clause),
   18394              :                 "%<nonmonotonic%> schedule modifier specified together "
   18395              :                 "with %<ordered%> clause");
   18396           14 :       OMP_CLAUSE_SCHEDULE_KIND (schedule_clause)
   18397            7 :         = (enum omp_clause_schedule_kind)
   18398            7 :           (OMP_CLAUSE_SCHEDULE_KIND (schedule_clause)
   18399              :            & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC);
   18400              :     }
   18401              : 
   18402        29559 :   if (reduction_seen < 0 && ordered_clause)
   18403              :     {
   18404            2 :       error_at (OMP_CLAUSE_LOCATION (ordered_clause),
   18405              :                 "%qs clause specified together with %<inscan%> "
   18406              :                 "%<reduction%> clause", "ordered");
   18407            2 :       reduction_seen = -2;
   18408              :     }
   18409              : 
   18410        29559 :   if (reduction_seen < 0 && schedule_clause)
   18411              :     {
   18412            3 :       error_at (OMP_CLAUSE_LOCATION (schedule_clause),
   18413              :                 "%qs clause specified together with %<inscan%> "
   18414              :                 "%<reduction%> clause", "schedule");
   18415            3 :       reduction_seen = -2;
   18416              :     }
   18417              : 
   18418        29559 :   if (linear_variable_step_check
   18419        29559 :       || reduction_seen == -2
   18420              :       || allocate_seen
   18421        29547 :       || target_in_reduction_seen)
   18422         5190 :     for (pc = &clauses, c = clauses; c ; c = *pc)
   18423              :       {
   18424         4589 :         bool remove = false;
   18425         4589 :         if (allocate_seen)
   18426         4431 :           switch (OMP_CLAUSE_CODE (c))
   18427              :             {
   18428          430 :             case OMP_CLAUSE_REDUCTION:
   18429          430 :             case OMP_CLAUSE_IN_REDUCTION:
   18430          430 :             case OMP_CLAUSE_TASK_REDUCTION:
   18431          430 :               if (TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF)
   18432              :                 {
   18433           23 :                   t = TREE_OPERAND (OMP_CLAUSE_DECL (c), 0);
   18434           23 :                   if (TREE_CODE (t) == POINTER_PLUS_EXPR)
   18435            0 :                     t = TREE_OPERAND (t, 0);
   18436           23 :                   if (TREE_CODE (t) == ADDR_EXPR
   18437           10 :                       || INDIRECT_REF_P (t))
   18438           13 :                     t = TREE_OPERAND (t, 0);
   18439           23 :                   if (DECL_P (t))
   18440           23 :                     bitmap_clear_bit (&aligned_head, DECL_UID (t));
   18441              :                   break;
   18442              :                 }
   18443              :               /* FALLTHRU */
   18444         1318 :             case OMP_CLAUSE_PRIVATE:
   18445         1318 :             case OMP_CLAUSE_FIRSTPRIVATE:
   18446         1318 :             case OMP_CLAUSE_LASTPRIVATE:
   18447         1318 :             case OMP_CLAUSE_LINEAR:
   18448         1318 :               if (DECL_P (OMP_CLAUSE_DECL (c)))
   18449         2636 :                 bitmap_clear_bit (&aligned_head,
   18450         1318 :                                   DECL_UID (OMP_CLAUSE_DECL (c)));
   18451              :               break;
   18452              :             default:
   18453              :               break;
   18454              :             }
   18455         4589 :         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
   18456           29 :             && OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c)
   18457         4596 :             && !bitmap_bit_p (&map_head,
   18458            7 :                               DECL_UID (OMP_CLAUSE_LINEAR_STEP (c))))
   18459              :           {
   18460            2 :             error_at (OMP_CLAUSE_LOCATION (c),
   18461              :                       "%<linear%> clause step is a parameter %qD not "
   18462              :                       "specified in %<uniform%> clause",
   18463            2 :                       OMP_CLAUSE_LINEAR_STEP (c));
   18464            2 :             remove = true;
   18465              :           }
   18466         4587 :         else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   18467         4587 :                  && reduction_seen == -2)
   18468            9 :           OMP_CLAUSE_REDUCTION_INSCAN (c) = 0;
   18469         4589 :         if (target_in_reduction_seen
   18470         4589 :             && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
   18471              :           {
   18472          256 :             tree t = OMP_CLAUSE_DECL (c);
   18473          256 :             while (handled_component_p (t)
   18474              :                    || INDIRECT_REF_P (t)
   18475              :                    || TREE_CODE (t) == ADDR_EXPR
   18476              :                    || TREE_CODE (t) == MEM_REF
   18477          288 :                    || TREE_CODE (t) == NON_LVALUE_EXPR)
   18478           32 :               t = TREE_OPERAND (t, 0);
   18479          256 :             if (DECL_P (t)
   18480          256 :                 && bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
   18481          138 :               OMP_CLAUSE_MAP_IN_REDUCTION (c) = 1;
   18482              :           }
   18483              : 
   18484         4589 :         if (remove)
   18485            2 :           *pc = OMP_CLAUSE_CHAIN (c);
   18486              :         else
   18487         4587 :           pc = &OMP_CLAUSE_CHAIN (c);
   18488              :       }
   18489              : 
   18490          601 :   if (allocate_seen)
   18491         5006 :     for (pc = &clauses, c = clauses; c ; c = *pc)
   18492              :       {
   18493         4431 :         bool remove = false;
   18494         4431 :         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ALLOCATE
   18495          720 :             && !OMP_CLAUSE_ALLOCATE_COMBINED (c)
   18496         5131 :             && bitmap_bit_p (&aligned_head, DECL_UID (OMP_CLAUSE_DECL (c))))
   18497              :           {
   18498            3 :             error_at (OMP_CLAUSE_LOCATION (c),
   18499              :                       "%qD specified in %<allocate%> clause but not in "
   18500            3 :                       "an explicit privatization clause", OMP_CLAUSE_DECL (c));
   18501            3 :             remove = true;
   18502              :           }
   18503         4431 :         if (remove)
   18504            3 :           *pc = OMP_CLAUSE_CHAIN (c);
   18505              :         else
   18506         4428 :           pc = &OMP_CLAUSE_CHAIN (c);
   18507              :       }
   18508              : 
   18509        29559 :   if (nogroup_seen && reduction_seen)
   18510              :     {
   18511            1 :       error_at (OMP_CLAUSE_LOCATION (*nogroup_seen),
   18512              :                 "%<nogroup%> clause must not be used together with "
   18513              :                 "%<reduction%> clause");
   18514            1 :       *nogroup_seen = OMP_CLAUSE_CHAIN (*nogroup_seen);
   18515              :     }
   18516              : 
   18517        29559 :   if (grainsize_seen && num_tasks_seen)
   18518              :     {
   18519            2 :       error_at (OMP_CLAUSE_LOCATION (*grainsize_seen),
   18520              :                 "%<grainsize%> clause must not be used together with "
   18521              :                 "%<num_tasks%> clause");
   18522            2 :       *grainsize_seen = OMP_CLAUSE_CHAIN (*grainsize_seen);
   18523              :     }
   18524              : 
   18525        29559 :   if (full_seen && partial_seen)
   18526              :     {
   18527            4 :       error_at (OMP_CLAUSE_LOCATION (*full_seen),
   18528              :                 "%<full%> clause must not be used together with "
   18529              :                 "%<partial%> clause");
   18530            4 :       *full_seen = OMP_CLAUSE_CHAIN (*full_seen);
   18531              :     }
   18532              : 
   18533        29559 :   if (detach_seen)
   18534              :     {
   18535           31 :       if (mergeable_seen)
   18536              :         {
   18537            2 :           error_at (OMP_CLAUSE_LOCATION (*detach_seen),
   18538              :                     "%<detach%> clause must not be used together with "
   18539              :                     "%<mergeable%> clause");
   18540            2 :           *detach_seen = OMP_CLAUSE_CHAIN (*detach_seen);
   18541              :         }
   18542              :       else
   18543              :         {
   18544           29 :           tree detach_decl = OMP_CLAUSE_DECL (*detach_seen);
   18545              : 
   18546           79 :           for (pc = &clauses, c = clauses; c ; c = *pc)
   18547              :             {
   18548           50 :               bool remove = false;
   18549           50 :               if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
   18550           48 :                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
   18551           48 :                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
   18552           44 :                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE)
   18553           54 :                   && OMP_CLAUSE_DECL (c) == detach_decl)
   18554              :                 {
   18555            2 :                   error_at (OMP_CLAUSE_LOCATION (c),
   18556              :                             "the event handle of a %<detach%> clause "
   18557              :                             "should not be in a data-sharing clause");
   18558            2 :                   remove = true;
   18559              :                 }
   18560           50 :               if (remove)
   18561            2 :                 *pc = OMP_CLAUSE_CHAIN (c);
   18562              :               else
   18563           48 :                 pc = &OMP_CLAUSE_CHAIN (c);
   18564              :             }
   18565              :         }
   18566              :     }
   18567              : 
   18568        29559 :   if (ort == C_ORT_OMP_INTEROP
   18569        29559 :       && depend_clause
   18570           21 :       && (!init_use_destroy_seen
   18571           20 :           || (init_seen && init_no_targetsync_clause)))
   18572              :     {
   18573            3 :       error_at (OMP_CLAUSE_LOCATION (depend_clause),
   18574              :                 "%<depend%> clause requires action clauses with "
   18575              :                 "%<targetsync%> interop-type");
   18576            3 :       if (init_no_targetsync_clause)
   18577            2 :         inform (OMP_CLAUSE_LOCATION (init_no_targetsync_clause),
   18578              :                 "%<init%> clause lacks the %<targetsync%> modifier");
   18579              :     }
   18580              : 
   18581        29559 :   bitmap_obstack_release (NULL);
   18582        29559 :   return clauses;
   18583              : }
   18584              : 
   18585              : /* Do processing necessary to make CLAUSES well-formed, where CLAUSES result
   18586              :    from implicit instantiation of user-defined mappers (in gimplify.cc).  */
   18587              : 
   18588              : tree
   18589           15 : c_omp_finish_mapper_clauses (tree clauses)
   18590              : {
   18591           15 :   return c_finish_omp_clauses (clauses, C_ORT_OMP);
   18592              : }
   18593              : 
   18594              : /* Return code to initialize DST with a copy constructor from SRC.
   18595              :    C doesn't have copy constructors nor assignment operators, only for
   18596              :    _Atomic vars we need to perform __atomic_load from src into a temporary
   18597              :    followed by __atomic_store of the temporary to dst.  */
   18598              : 
   18599              : tree
   18600        18735 : c_omp_clause_copy_ctor (tree clause, tree dst, tree src)
   18601              : {
   18602        18735 :   if (!really_atomic_lvalue (dst) && !really_atomic_lvalue (src))
   18603        18731 :     return build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src);
   18604              : 
   18605            4 :   location_t loc = OMP_CLAUSE_LOCATION (clause);
   18606            4 :   tree type = TREE_TYPE (dst);
   18607            4 :   tree nonatomic_type = build_qualified_type (type, TYPE_UNQUALIFIED);
   18608            4 :   tree tmp = create_tmp_var (nonatomic_type);
   18609            4 :   tree tmp_addr = build_fold_addr_expr (tmp);
   18610            4 :   TREE_ADDRESSABLE (tmp) = 1;
   18611            4 :   suppress_warning (tmp);
   18612            4 :   tree src_addr = build_fold_addr_expr (src);
   18613            4 :   tree dst_addr = build_fold_addr_expr (dst);
   18614            4 :   tree seq_cst = build_int_cst (integer_type_node, MEMMODEL_SEQ_CST);
   18615            4 :   vec<tree, va_gc> *params;
   18616              :   /* Expansion of a generic atomic load may require an addition
   18617              :      element, so allocate enough to prevent a resize.  */
   18618            4 :   vec_alloc (params, 4);
   18619              : 
   18620              :   /* Build __atomic_load (&src, &tmp, SEQ_CST);  */
   18621            4 :   tree fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_LOAD);
   18622            4 :   params->quick_push (src_addr);
   18623            4 :   params->quick_push (tmp_addr);
   18624            4 :   params->quick_push (seq_cst);
   18625            4 :   tree load = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
   18626              : 
   18627            4 :   vec_alloc (params, 4);
   18628              : 
   18629              :   /* Build __atomic_store (&dst, &tmp, SEQ_CST);  */
   18630            4 :   fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_STORE);
   18631            4 :   params->quick_push (dst_addr);
   18632            4 :   params->quick_push (tmp_addr);
   18633            4 :   params->quick_push (seq_cst);
   18634            4 :   tree store = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
   18635            4 :   return build2 (COMPOUND_EXPR, void_type_node, load, store);
   18636              : }
   18637              : 
   18638              : /* Create a transaction node.  */
   18639              : 
   18640              : tree
   18641          135 : c_finish_transaction (location_t loc, tree block, int flags)
   18642              : {
   18643          135 :   tree stmt = build_stmt (loc, TRANSACTION_EXPR, block);
   18644          135 :   if (flags & TM_STMT_ATTR_OUTER)
   18645           10 :     TRANSACTION_EXPR_OUTER (stmt) = 1;
   18646          135 :   if (flags & TM_STMT_ATTR_RELAXED)
   18647           31 :     TRANSACTION_EXPR_RELAXED (stmt) = 1;
   18648          135 :   return add_stmt (stmt);
   18649              : }
   18650              : 
   18651              : /* Make a variant type in the proper way for C/C++, propagating qualifiers
   18652              :    down to the element type of an array.  If ORIG_QUAL_TYPE is not
   18653              :    NULL, then it should be used as the qualified type
   18654              :    ORIG_QUAL_INDIRECT levels down in array type derivation (to
   18655              :    preserve information about the typedef name from which an array
   18656              :    type was derived).  */
   18657              : 
   18658              : tree
   18659     74922344 : c_build_qualified_type (tree type, int type_quals, tree orig_qual_type,
   18660              :                         size_t orig_qual_indirect)
   18661              : {
   18662     74922344 :   if (type == error_mark_node)
   18663              :     return type;
   18664              : 
   18665     74922192 :   if (TREE_CODE (type) == ARRAY_TYPE)
   18666              :     {
   18667      3151108 :       tree t;
   18668      3151108 :       tree element_type = c_build_qualified_type (TREE_TYPE (type),
   18669              :                                                   type_quals, orig_qual_type,
   18670              :                                                   orig_qual_indirect - 1);
   18671              : 
   18672              :       /* See if we already have an identically qualified type.  */
   18673      3151108 :       if (orig_qual_type && orig_qual_indirect == 0)
   18674              :         t = orig_qual_type;
   18675              :       else
   18676      4594245 :         for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
   18677              :           {
   18678      4454535 :             if (TYPE_QUALS (strip_array_types (t)) == type_quals
   18679      3032392 :                 && TYPE_NAME (t) == TYPE_NAME (type)
   18680      3011357 :                 && TYPE_CONTEXT (t) == TYPE_CONTEXT (type)
   18681      7465892 :                 && attribute_list_equal (TYPE_ATTRIBUTES (t),
   18682      3011357 :                                          TYPE_ATTRIBUTES (type)))
   18683              :               break;
   18684              :           }
   18685      3151067 :       if (!t)
   18686              :         {
   18687       139710 :           tree domain = TYPE_DOMAIN (type);
   18688              : 
   18689       139710 :           t = build_variant_type_copy (type);
   18690       139710 :           TREE_TYPE (t) = element_type;
   18691       139710 :           TYPE_ADDR_SPACE (t) = TYPE_ADDR_SPACE (element_type);
   18692              : 
   18693       139710 :           if (TYPE_STRUCTURAL_EQUALITY_P (element_type)
   18694       139710 :               || (domain && TYPE_STRUCTURAL_EQUALITY_P (domain)))
   18695          196 :             SET_TYPE_STRUCTURAL_EQUALITY (t);
   18696       139514 :           else if (TYPE_CANONICAL (element_type) != element_type
   18697       139514 :                    || (domain && TYPE_CANONICAL (domain) != domain))
   18698              :             {
   18699         2762 :               tree unqualified_canon
   18700         5298 :                 = c_build_array_type (TYPE_CANONICAL (element_type),
   18701         2536 :                                       domain ? TYPE_CANONICAL (domain)
   18702              :                                              : NULL_TREE);
   18703         2762 :               if (TYPE_REVERSE_STORAGE_ORDER (type))
   18704              :                 {
   18705            0 :                   unqualified_canon
   18706            0 :                     = build_distinct_type_copy (unqualified_canon);
   18707            0 :                   TYPE_REVERSE_STORAGE_ORDER (unqualified_canon) = 1;
   18708              :                 }
   18709         2762 :               TYPE_CANONICAL (t)
   18710         5524 :                 = c_build_qualified_type (unqualified_canon, type_quals);
   18711              :             }
   18712              :           else
   18713       136752 :             TYPE_CANONICAL (t) = t;
   18714              :         }
   18715      3151108 :       return t;
   18716              :     }
   18717              : 
   18718              :   /* A restrict-qualified pointer type must be a pointer to object or
   18719              :      incomplete type.  Note that the use of POINTER_TYPE_P also allows
   18720              :      REFERENCE_TYPEs, which is appropriate for C++.  */
   18721     71771084 :   if ((type_quals & TYPE_QUAL_RESTRICT)
   18722     71771084 :       && (!POINTER_TYPE_P (type)
   18723      3414639 :           || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type))))
   18724              :     {
   18725            3 :       error ("invalid use of %<restrict%>");
   18726            3 :       type_quals &= ~TYPE_QUAL_RESTRICT;
   18727              :     }
   18728              : 
   18729     71771084 :   tree var_type = (orig_qual_type && orig_qual_indirect == 0
   18730     71771084 :                    ? orig_qual_type
   18731     71771053 :                    : build_qualified_type (type, type_quals));
   18732              : 
   18733     71771084 :   gcc_checking_assert (C_TYPE_VARIABLE_SIZE (var_type)
   18734              :                        == C_TYPE_VARIABLE_SIZE (type));
   18735     71771084 :   gcc_checking_assert (c_type_variably_modified_p (var_type)
   18736              :                        == c_type_variably_modified_p (type));
   18737              : 
   18738              :   /* A variant type does not inherit the list of incomplete vars from the
   18739              :      type main variant.  */
   18740     71771084 :   if ((RECORD_OR_UNION_TYPE_P (var_type)
   18741     69684990 :        || TREE_CODE (var_type) == ENUMERAL_TYPE)
   18742     71876433 :       && TYPE_MAIN_VARIANT (var_type) != var_type)
   18743      1414356 :     C_TYPE_INCOMPLETE_VARS (var_type) = 0;
   18744              :   return var_type;
   18745              : }
   18746              : 
   18747              : /* Build a VA_ARG_EXPR for the C parser.  */
   18748              : 
   18749              : tree
   18750        19922 : c_build_va_arg (location_t loc1, tree expr, location_t loc2, tree type,
   18751              :                 tree type_expr)
   18752              : {
   18753        19922 :   if (error_operand_p (type))
   18754            2 :     return error_mark_node;
   18755              :   /* VA_ARG_EXPR cannot be used for a scalar va_list with reverse storage
   18756              :      order because it takes the address of the expression.  */
   18757        19920 :   else if (handled_component_p (expr)
   18758           31 :            && reverse_storage_order_for_component_p (expr))
   18759              :     {
   18760            0 :       error_at (loc1, "cannot use %<va_arg%> with reverse storage order");
   18761            0 :       return error_mark_node;
   18762              :     }
   18763        19920 :   else if (!COMPLETE_TYPE_P (type))
   18764              :     {
   18765           11 :       error_at (loc2, "second argument to %<va_arg%> is of incomplete "
   18766              :                 "type %qT", type);
   18767           11 :       return error_mark_node;
   18768              :     }
   18769        19909 :   else if (TREE_CODE (type) == FUNCTION_TYPE)
   18770              :     {
   18771            1 :       error_at (loc2, "second argument to %<va_arg%> is a function type %qT",
   18772              :                 type);
   18773            1 :       return error_mark_node;
   18774              :     }
   18775            6 :   else if (TREE_CODE (type) == ARRAY_TYPE && C_TYPE_VARIABLE_SIZE (type)
   18776        19911 :            && !flag_isoc99)
   18777              :     {
   18778            1 :       error_at (loc2, "second argument to %<va_arg%> is an array type %qT",
   18779              :                 type);
   18780            1 :       return error_mark_node;
   18781              :     }
   18782        19907 :   else if (warn_cxx_compat && TREE_CODE (type) == ENUMERAL_TYPE)
   18783            1 :     warning_at (loc2, OPT_Wc___compat,
   18784              :                 "C++ requires promoted type, not enum type, in %<va_arg%>");
   18785              : 
   18786        19907 :   if (flag_isoc99 && TREE_CODE (type) == ARRAY_TYPE)
   18787              :     {
   18788            3 :       warning_at (loc2, 0, "second argument to %<va_arg%> is an array type %qT",
   18789              :                   type);
   18790              :       /* We create a trap but evaluate side effects first.  */
   18791            3 :       tree trapfn = builtin_decl_explicit (BUILT_IN_TRAP);
   18792            3 :       trapfn = build_call_expr_loc (loc2, trapfn, 0);
   18793            3 :       tree e2 = build2 (COMPOUND_EXPR, void_type_node, expr, trapfn);
   18794              :       /* Return a compound literal of the right type.  */
   18795            3 :       tree e1 = build_compound_literal (loc2, type, NULL, true, 0, NULL);
   18796            3 :       expr = build2 (COMPOUND_EXPR, type, e2, e1);
   18797            3 :     }
   18798              :   else
   18799        19904 :     expr = build_va_arg (loc2, expr, type);
   18800              : 
   18801        19907 :   if (type_expr)
   18802           26 :     expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr), type_expr, expr);
   18803              : 
   18804              :   return expr;
   18805              : }
   18806              : 
   18807              : /* Return truthvalue of whether T1 is the same tree structure as T2.
   18808              :    Return 1 if they are the same. Return false if they are different.  */
   18809              : 
   18810              : bool
   18811         1854 : c_tree_equal (tree t1, tree t2)
   18812              : {
   18813         1883 :   enum tree_code code1, code2;
   18814              : 
   18815         1883 :   if (t1 == t2)
   18816              :     return true;
   18817          661 :   if (!t1 || !t2)
   18818              :     return false;
   18819              : 
   18820          681 :   for (code1 = TREE_CODE (t1); code1 == NON_LVALUE_EXPR;
   18821           20 :        code1 = TREE_CODE (t1))
   18822           20 :     t1 = TREE_OPERAND (t1, 0);
   18823          682 :   for (code2 = TREE_CODE (t2); code2 == NON_LVALUE_EXPR;
   18824           21 :        code2 = TREE_CODE (t2))
   18825           21 :     t2 = TREE_OPERAND (t2, 0);
   18826              : 
   18827              :   /* They might have become equal now.  */
   18828          661 :   if (t1 == t2)
   18829              :     return true;
   18830              : 
   18831          640 :   if (code1 != code2)
   18832              :     return false;
   18833              : 
   18834          379 :   if (CONSTANT_CLASS_P (t1) && !comptypes (TREE_TYPE (t1), TREE_TYPE (t2)))
   18835              :     return false;
   18836              : 
   18837          379 :   switch (code1)
   18838              :     {
   18839            2 :     case INTEGER_CST:
   18840            2 :       return wi::to_wide (t1) == wi::to_wide (t2);
   18841              : 
   18842           10 :     case REAL_CST:
   18843           10 :       return real_equal (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
   18844              : 
   18845            0 :     case STRING_CST:
   18846            0 :       return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
   18847            0 :         && !memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
   18848            0 :                     TREE_STRING_LENGTH (t1));
   18849              : 
   18850            0 :     case FIXED_CST:
   18851            0 :       return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1),
   18852              :                                      TREE_FIXED_CST (t2));
   18853              : 
   18854            0 :     case COMPLEX_CST:
   18855            0 :       return c_tree_equal (TREE_REALPART (t1), TREE_REALPART (t2))
   18856            0 :              && c_tree_equal (TREE_IMAGPART (t1), TREE_IMAGPART (t2));
   18857              : 
   18858            0 :     case VECTOR_CST:
   18859            0 :       return operand_equal_p (t1, t2, OEP_ONLY_CONST);
   18860              : 
   18861            0 :     case CONSTRUCTOR:
   18862              :       /* We need to do this when determining whether or not two
   18863              :          non-type pointer to member function template arguments
   18864              :          are the same.  */
   18865            0 :       if (!comptypes (TREE_TYPE (t1), TREE_TYPE (t2))
   18866            0 :           || CONSTRUCTOR_NELTS (t1) != CONSTRUCTOR_NELTS (t2))
   18867              :         return false;
   18868              :       {
   18869              :         tree field, value;
   18870              :         unsigned int i;
   18871            0 :         FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t1), i, field, value)
   18872              :           {
   18873            0 :             constructor_elt *elt2 = CONSTRUCTOR_ELT (t2, i);
   18874            0 :             if (!c_tree_equal (field, elt2->index)
   18875            0 :                 || !c_tree_equal (value, elt2->value))
   18876            0 :               return false;
   18877              :           }
   18878              :       }
   18879              :       return true;
   18880              : 
   18881            0 :     case TREE_LIST:
   18882            0 :       if (!c_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)))
   18883              :         return false;
   18884            0 :       if (!c_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2)))
   18885              :         return false;
   18886            0 :       return c_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2));
   18887              : 
   18888            0 :     case SAVE_EXPR:
   18889            0 :       return c_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
   18890              : 
   18891           25 :     case CALL_EXPR:
   18892           25 :       {
   18893           25 :         tree arg1, arg2;
   18894           25 :         call_expr_arg_iterator iter1, iter2;
   18895           25 :         if (!c_tree_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2)))
   18896              :           return false;
   18897           50 :         for (arg1 = first_call_expr_arg (t1, &iter1),
   18898           25 :                arg2 = first_call_expr_arg (t2, &iter2);
   18899           25 :              arg1 && arg2;
   18900            0 :              arg1 = next_call_expr_arg (&iter1),
   18901            0 :                arg2 = next_call_expr_arg (&iter2))
   18902            0 :           if (!c_tree_equal (arg1, arg2))
   18903              :             return false;
   18904           25 :         if (arg1 || arg2)
   18905              :           return false;
   18906              :         return true;
   18907              :       }
   18908              : 
   18909            0 :     case TARGET_EXPR:
   18910            0 :       {
   18911            0 :         tree o1 = TREE_OPERAND (t1, 0);
   18912            0 :         tree o2 = TREE_OPERAND (t2, 0);
   18913              : 
   18914              :         /* Special case: if either target is an unallocated VAR_DECL,
   18915              :            it means that it's going to be unified with whatever the
   18916              :            TARGET_EXPR is really supposed to initialize, so treat it
   18917              :            as being equivalent to anything.  */
   18918            0 :         if (VAR_P (o1) && DECL_NAME (o1) == NULL_TREE
   18919            0 :             && !DECL_RTL_SET_P (o1))
   18920              :           /*Nop*/;
   18921            0 :         else if (VAR_P (o2) && DECL_NAME (o2) == NULL_TREE
   18922            0 :                  && !DECL_RTL_SET_P (o2))
   18923              :           /*Nop*/;
   18924            0 :         else if (!c_tree_equal (o1, o2))
   18925              :           return false;
   18926              : 
   18927            0 :         return c_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
   18928              :       }
   18929              : 
   18930           29 :     case COMPONENT_REF:
   18931           29 :       if (TREE_OPERAND (t1, 1) != TREE_OPERAND (t2, 1))
   18932              :         return false;
   18933           29 :       return c_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
   18934              : 
   18935              :     case PARM_DECL:
   18936              :     case VAR_DECL:
   18937              :     case CONST_DECL:
   18938              :     case FIELD_DECL:
   18939              :     case FUNCTION_DECL:
   18940              :     case IDENTIFIER_NODE:
   18941              :     case SSA_NAME:
   18942              :       return false;
   18943              : 
   18944            0 :     case TREE_VEC:
   18945            0 :       {
   18946            0 :         unsigned ix;
   18947            0 :         if (TREE_VEC_LENGTH (t1) != TREE_VEC_LENGTH (t2))
   18948              :           return false;
   18949            0 :         for (ix = TREE_VEC_LENGTH (t1); ix--;)
   18950            0 :           if (!c_tree_equal (TREE_VEC_ELT (t1, ix),
   18951            0 :                              TREE_VEC_ELT (t2, ix)))
   18952              :             return false;
   18953              :         return true;
   18954              :       }
   18955              : 
   18956           22 :     CASE_CONVERT:
   18957           22 :       if (!comptypes (TREE_TYPE (t1), TREE_TYPE (t2)))
   18958              :         return false;
   18959              :       break;
   18960              : 
   18961              :     default:
   18962              :       break;
   18963              :     }
   18964              : 
   18965          131 :   switch (TREE_CODE_CLASS (code1))
   18966              :     {
   18967          131 :     case tcc_unary:
   18968          131 :     case tcc_binary:
   18969          131 :     case tcc_comparison:
   18970          131 :     case tcc_expression:
   18971          131 :     case tcc_vl_exp:
   18972          131 :     case tcc_reference:
   18973          131 :     case tcc_statement:
   18974          131 :       {
   18975          131 :         int i, n = TREE_OPERAND_LENGTH (t1);
   18976              : 
   18977          131 :         switch (code1)
   18978              :           {
   18979            0 :           case PREINCREMENT_EXPR:
   18980            0 :           case PREDECREMENT_EXPR:
   18981            0 :           case POSTINCREMENT_EXPR:
   18982            0 :           case POSTDECREMENT_EXPR:
   18983            0 :             n = 1;
   18984            0 :             break;
   18985           16 :           case ARRAY_REF:
   18986           16 :             n = 2;
   18987           16 :             break;
   18988              :           default:
   18989              :             break;
   18990              :           }
   18991              : 
   18992          131 :         if (TREE_CODE_CLASS (code1) == tcc_vl_exp
   18993          131 :             && n != TREE_OPERAND_LENGTH (t2))
   18994              :           return false;
   18995              : 
   18996          305 :         for (i = 0; i < n; ++i)
   18997          186 :           if (!c_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i)))
   18998              :             return false;
   18999              : 
   19000              :         return true;
   19001              :       }
   19002              : 
   19003            0 :     case tcc_type:
   19004            0 :       return comptypes (t1, t2);
   19005            0 :     default:
   19006            0 :       gcc_unreachable ();
   19007              :     }
   19008              : }
   19009              : 
   19010              : /* Returns true when the function declaration FNDECL is implicit,
   19011              :    introduced as a result of a call to an otherwise undeclared
   19012              :    function, and false otherwise.  */
   19013              : 
   19014              : bool
   19015         2013 : c_decl_implicit (const_tree fndecl)
   19016              : {
   19017         2013 :   return C_DECL_IMPLICIT (fndecl);
   19018              : }
        

Generated by: LCOV version 2.4-beta

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