LCOV - code coverage report
Current view: top level - gcc/c - c-typeck.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 93.7 % 9214 8636
Test Date: 2026-10-24 16:24:59 Functions: 99.5 % 208 207
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    193604644 : 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    193604644 :   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    193604644 :   if (expr == nullptr_node)
     160              :     return true;
     161              : 
     162    193603950 :   return (TREE_CODE (expr) == INTEGER_CST
     163     19506683 :           && !TREE_OVERFLOW (expr)
     164     19506586 :           && integer_zerop (expr)
     165    197571125 :           && (INTEGRAL_TYPE_P (type)
     166       338718 :               || (TREE_CODE (type) == POINTER_TYPE
     167       338716 :                   && VOID_TYPE_P (TREE_TYPE (type))
     168       263346 :                   && 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        62370 : note_integer_operands (tree expr)
     178              : {
     179        62370 :   tree ret;
     180        62370 :   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        62348 :       ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (expr), NULL_TREE, expr);
     188        62348 :       C_MAYBE_CONST_EXPR_INT_OPERANDS (ret) = 1;
     189              :     }
     190        62370 :   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     34569268 : remove_c_maybe_const_expr (tree expr)
     200              : {
     201     34569268 :   if (TREE_CODE (expr) == C_MAYBE_CONST_EXPR)
     202        61518 :     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    795530042 : require_complete_type (location_t loc, tree value)
     221              : {
     222    795530042 :   tree type = TREE_TYPE (value);
     223              : 
     224    795530042 :   if (error_operand_p (value))
     225         8980 :     return error_mark_node;
     226              : 
     227              :   /* First, detect a valid value with a complete type.  */
     228    795521062 :   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 (flexible_array_member_type_p (type))
     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    128387527 : c_type_promotes_to (tree type)
     296              : {
     297    128387527 :   tree ret = NULL_TREE;
     298              : 
     299    128387527 :   if (TYPE_MAIN_VARIANT (type) == float_type_node)
     300      1641258 :     ret = double_type_node;
     301    126746269 :   else if (c_promoting_integer_type_p (type))
     302              :     {
     303              :       /* Preserve unsignedness if not really getting any wider.  */
     304     19207324 :       if (TYPE_UNSIGNED (type)
     305     19207324 :           && (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)))
     306            0 :         ret = unsigned_type_node;
     307              :       else
     308     19207324 :         ret = integer_type_node;
     309              :     }
     310              : 
     311     20848582 :   if (ret != NULL_TREE)
     312     20848582 :     return (TYPE_ATOMIC (type)
     313     20848582 :             ? 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      7719635 : addr_space_superset (addr_space_t as1, addr_space_t as2, addr_space_t *common)
     325              : {
     326      7719635 :   if (as1 == as2)
     327              :     {
     328      7719635 :       *common = as1;
     329      7719635 :       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      2909169 : qualify_type (tree type, tree like)
     350              : {
     351      2909169 :   addr_space_t as_type = TYPE_ADDR_SPACE (type);
     352      2909169 :   addr_space_t as_like = TYPE_ADDR_SPACE (like);
     353      2909169 :   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      2909169 :   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      5818338 :   return c_build_qualified_type (type,
     365      2909169 :                                  TYPE_QUALS_NO_ADDR_SPACE (type)
     366      2909169 :                                  | TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (like)
     367      2909169 :                                  | 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    145369166 : c_verify_type (tree type)
     379              : {
     380    145369166 :   switch (TREE_CODE (type))
     381              :     {
     382     69584038 :     case POINTER_TYPE:
     383     69584038 :     case FUNCTION_TYPE:
     384     69584038 :     case ARRAY_TYPE:
     385              :       /* Pointer, array, functions are variably modified if and only if the
     386              :          target, element, return type is variably modified.  */
     387     69584038 :       if (!TYPE_STRUCTURAL_EQUALITY_P (type)
     388     69584038 :           && (C_TYPE_VARIABLY_MODIFIED (type)
     389     69197385 :               != C_TYPE_VARIABLY_MODIFIED (TREE_TYPE (type))))
     390              :         return false;
     391              :       /* If the target type is structural equality, the type should also. */
     392     69584038 :       if (!TYPE_STRUCTURAL_EQUALITY_P (type)
     393     69584038 :           && TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (type)))
     394              :         return false;
     395    145369166 :     default:
     396    145369166 :        break;
     397              :     }
     398              : 
     399    145369166 :   switch (TREE_CODE (type))
     400              :     {
     401     68662634 :     case POINTER_TYPE:
     402     68662634 :     case FUNCTION_TYPE:
     403              :       /* Pointer and functions can not have variable size.  */
     404     68662634 :       if (C_TYPE_VARIABLE_SIZE (type))
     405            0 :         return false;
     406              :       break;
     407       921404 :     case ARRAY_TYPE:
     408              :       /* An array has variable size if and only if it has a non-constant
     409              :          dimensions or its element type has variable size.  */
     410       921404 :       if ((C_TYPE_VARIABLE_SIZE (TREE_TYPE (type))
     411       921404 :            || top_array_vla_p (type))
     412       921404 :           != C_TYPE_VARIABLE_SIZE (type))
     413              :         return false;
     414              :       /* If the element type or the array has variable size, then the
     415              :          array has variable size and is variably modified.  */
     416       921404 :       if (C_TYPE_VARIABLE_SIZE (TREE_TYPE (type))
     417       921404 :           || C_TYPE_VARIABLE_SIZE (type))
     418              :         {
     419        27704 :           if (!C_TYPE_VARIABLE_SIZE (type))
     420              :             return false;
     421        27704 :           if (!C_TYPE_VARIABLY_MODIFIED (type))
     422              :             return false;
     423              :         }
     424              : 
     425              :       /* va_list violates this, accept such types here.  */
     426       921404 :       if (!COMPLETE_TYPE_P (TREE_TYPE (type)))
     427              :         return true;
     428              : 
     429       921398 :       if (COMPLETE_TYPE_P (type))
     430              :         {
     431              :           /* If the size is unknown, it can not be complete.  */
     432       913136 :           if (NULL_TREE == TYPE_DOMAIN (type))
     433              :             return false;
     434              : 
     435              :           /* Zero-length arrays must have size zero.  */
     436       913136 :           if (zero_length_array_type_p (type)
     437       913136 :               && !integer_zerop (TYPE_SIZE (type)))
     438              :             return false;
     439              :         }
     440              :       else
     441              :         {
     442              :           /* If not complete but has a domain, it must be a FAM.  */
     443         8262 :           if (NULL_TREE != TYPE_DOMAIN (type)
     444         8262 :               && !flexible_array_member_type_p (type))
     445              :             return false;
     446              :         }
     447              :     default:
     448              :       break;
     449              :     }
     450              :   return true;
     451              : }
     452              : 
     453              : /* Propagate C_TYPE_VARIABLY_MODIFIED and C_TYPE_VARIABLE_SIZE
     454              :    from a base type to a newly built derived or qualified type.  */
     455              : 
     456              : static tree
     457    138099160 : c_set_type_bits (tree new_type, tree old_type)
     458              : {
     459    138099160 :   gcc_checking_assert (c_verify_type (old_type));
     460              : 
     461    138099160 :   if (c_type_variably_modified_p (old_type))
     462        28354 :     C_TYPE_VARIABLY_MODIFIED (new_type) = true;
     463              : 
     464    138099160 :   if (TREE_CODE (new_type) == ARRAY_TYPE && C_TYPE_VARIABLE_SIZE (old_type))
     465              :     {
     466        16809 :       C_TYPE_VARIABLY_MODIFIED (new_type) = true;
     467        16809 :       C_TYPE_VARIABLE_SIZE (new_type) = true;
     468              :     }
     469    138099160 :   return new_type;
     470              : }
     471              : 
     472              : /* Build a pointer type using the default pointer mode.  */
     473              : 
     474              : tree
     475     73835807 : c_build_pointer_type (tree to_type)
     476              : {
     477     73835807 :   addr_space_t as = to_type == error_mark_node ? ADDR_SPACE_GENERIC
     478     73835807 :                                                : TYPE_ADDR_SPACE (to_type);
     479     73835807 :   machine_mode pointer_mode;
     480              : 
     481     73835807 :   if (as != ADDR_SPACE_GENERIC || c_default_pointer_mode == VOIDmode)
     482     73835807 :     pointer_mode = targetm.addr_space.pointer_mode (as);
     483              :   else
     484              :     pointer_mode = c_default_pointer_mode;
     485              : 
     486     73835807 :   return c_build_pointer_type_for_mode (to_type, pointer_mode, false);
     487              : }
     488              : 
     489              : /* Build a pointer type using the given mode.  */
     490              : 
     491              : tree
     492     74085168 : c_build_pointer_type_for_mode (tree type, machine_mode mode, bool m)
     493              : {
     494     74085168 :   tree ret = build_pointer_type_for_mode (type, mode, m);
     495     74085168 :   return c_set_type_bits (ret, type);
     496              : }
     497              : 
     498              : /* Build a function type.  */
     499              : 
     500              : tree
     501     55281488 : c_build_function_type (tree type, tree args, bool no)
     502              : {
     503     55281488 :   tree ret = build_function_type (type, args, no);
     504     55281488 :   return c_set_type_bits (ret, type);
     505              : }
     506              : 
     507              : /* Build an array type.  This sets typeless storage as required
     508              :    by C2Y and C_TYPE_VARIABLY_MODIFIED and C_TYPE_VARIABLE_SIZE
     509              :    based on the element type and domain.  */
     510              : 
     511              : tree
     512      1165740 : c_build_array_type (tree type, tree domain)
     513              : {
     514      1165740 :   int type_quals = TYPE_QUALS (type);
     515              : 
     516              :   /* Identify typeless storage as introduced in C2Y
     517              :      and supported also in earlier language modes.  */
     518      1731805 :   bool typeless = (char_type_p (type) && !(type_quals & TYPE_QUAL_ATOMIC))
     519      1165740 :                   || (AGGREGATE_TYPE_P (type) && TYPE_TYPELESS_STORAGE (type));
     520              : 
     521      1165740 :   tree ret = build_array_type (type, domain, typeless);
     522              : 
     523      1165740 :   if (top_array_vla_p (ret))
     524              :     {
     525        24283 :       C_TYPE_VARIABLE_SIZE (ret) = 1;
     526        24283 :       C_TYPE_VARIABLY_MODIFIED (ret) = 1;
     527              :     }
     528              : 
     529      1165740 :   return c_set_type_bits (ret, type);
     530              : }
     531              : 
     532              : /* Build an array type of unspecified size.  */
     533              : tree
     534          151 : c_build_array_type_unspecified (tree type)
     535              : {
     536          151 :   tree upper = build2 (COMPOUND_EXPR, TREE_TYPE (size_zero_node),
     537              :                        integer_zero_node, size_zero_node);
     538          151 :   return c_build_array_type (type, build_index_type (upper));
     539              : }
     540              : 
     541              : /* Build an array type of zero size.  */
     542              : tree
     543         2609 : c_build_array_type_zero_size (tree type)
     544              : {
     545              :   /* The GCC extension for zero-length arrays differs from
     546              :      ISO flexible array members in that sizeof yields
     547              :      zero.  */
     548         2609 :   type = c_build_array_type (type, build_index_type (NULL_TREE));
     549         2609 :   type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
     550         2609 :   TYPE_SIZE (type) = bitsize_zero_node;
     551         2609 :   TYPE_SIZE_UNIT (type) = size_zero_node;
     552         2609 :   SET_TYPE_STRUCTURAL_EQUALITY (type);
     553         2609 :   return type;
     554              : }
     555              : 
     556              : tree
     557      7566764 : c_build_type_attribute_qual_variant (tree type, tree attrs, int quals)
     558              : {
     559      7566764 :   tree ret = build_type_attribute_qual_variant (type, attrs, quals);
     560      7566764 :   return c_set_type_bits (ret, type);
     561              : }
     562              : 
     563              : tree
     564      7376748 : c_build_type_attribute_variant (tree type, tree attrs)
     565              : {
     566      7376748 :   return c_build_type_attribute_qual_variant (type, attrs, TYPE_QUALS (type));
     567              : }
     568              : 
     569              : /* Reconstruct a complex derived type.  This is used to re-construct types
     570              :    with the vector attribute.  It is called via a langhook.  */
     571              : 
     572              : tree
     573       845608 : c_reconstruct_complex_type (tree type, tree bottom)
     574              : {
     575       845608 :   tree inner, outer;
     576              : 
     577       845608 :   if (TREE_CODE (type) == POINTER_TYPE)
     578              :     {
     579       175671 :       inner = c_reconstruct_complex_type (TREE_TYPE (type), bottom);
     580       175671 :       outer = c_build_pointer_type_for_mode (inner, TYPE_MODE (type),
     581       175671 :                                              TYPE_REF_CAN_ALIAS_ALL (type));
     582              :     }
     583              :   else if (TREE_CODE (type) == ARRAY_TYPE)
     584              :     {
     585         7367 :       bool rso = TYPE_REVERSE_STORAGE_ORDER (type);
     586         7367 :       inner = c_reconstruct_complex_type (TREE_TYPE (type), bottom);
     587         7367 :       outer = c_build_array_type (inner, TYPE_DOMAIN (type));
     588         7367 :       if (rso)
     589              :         {
     590            1 :           outer = build_distinct_type_copy (outer);
     591            1 :           TYPE_REVERSE_STORAGE_ORDER (outer) = 1;
     592              :         }
     593              : 
     594         7367 :       gcc_checking_assert (C_TYPE_VARIABLE_SIZE (type)
     595              :                            == C_TYPE_VARIABLE_SIZE (outer));
     596              :     }
     597              :   else if (TREE_CODE (type) == FUNCTION_TYPE)
     598              :     {
     599          602 :       inner = c_reconstruct_complex_type (TREE_TYPE (type), bottom);
     600          602 :       outer = c_build_function_type (inner, TYPE_ARG_TYPES (type),
     601          602 :                                      TYPE_NO_NAMED_ARGS_STDARG_P (type));
     602              :     }
     603              :   else if (TREE_CODE (type) == REFERENCE_TYPE
     604              :            || TREE_CODE (type) == OFFSET_TYPE)
     605            0 :     gcc_unreachable ();
     606              :   else
     607              :     return bottom;
     608              : 
     609       183640 :   return c_build_type_attribute_qual_variant (outer, TYPE_ATTRIBUTES (type),
     610       367280 :                                               TYPE_QUALS (type));
     611              : }
     612              : 
     613              : 
     614              : /* Helper function for c_canonical_type.  Check whether FIELD
     615              :    contains a pointer to a structure or union with tag,
     616              :    possibly nested in other type derivations, and return the
     617              :    type of this nested structure or union.  */
     618              : static tree
     619      3460521 : ptr_to_tagged_member (tree field)
     620              : {
     621      3460521 :   gcc_assert (FIELD_DECL == TREE_CODE (field));
     622      3460521 :   tree type = TREE_TYPE (field);
     623      3460521 :   bool ptr_seen = false;
     624      3460521 :   while (TREE_CODE (type) == ARRAY_TYPE
     625              :          || TREE_CODE (type) == FUNCTION_TYPE
     626      4743289 :          || TREE_CODE (type) == POINTER_TYPE)
     627              :     {
     628      1282768 :       if (TREE_CODE (type) == POINTER_TYPE)
     629       702522 :         ptr_seen = true;
     630      1282768 :       type = TREE_TYPE (type);
     631              :     }
     632              : 
     633      3460521 :   if (ptr_seen
     634       682235 :       && RECORD_OR_UNION_TYPE_P (type)
     635      3710262 :       && NULL_TREE != c_type_tag (type))
     636       245586 :     return type;
     637              : 
     638              :   return NULL_TREE;
     639              : }
     640              : 
     641              : /* For a record or union type, make necessary adaptations so that the
     642              :    type can be used as TYPE_CANONICAL.
     643              : 
     644              :    If the TYPE contains a pointer (possibly nested in other type
     645              :    derivations) to a structure or union as a member, create a copy and
     646              :    change the nested type to an incomplete type.  Otherwise, the middle-end
     647              :    gets confused when recording component aliases in the case where we
     648              :    have formed equivalency classes that include types for which these
     649              :    member pointers end up pointing to other structure or unions types
     650              :    which have the same tag but are not compatible.  */
     651              : tree
     652       892893 : c_type_canonical (tree type)
     653              : {
     654       892893 :   gcc_assert (RECORD_OR_UNION_TYPE_P (type));
     655              : 
     656       892893 :   bool needs_mod = false;
     657      3656596 :   for (tree x = TYPE_FIELDS (type); x; x = DECL_CHAIN (x))
     658              :     {
     659      2845961 :       if (!ptr_to_tagged_member (x))
     660      2763703 :         continue;
     661              :       needs_mod = true;
     662              :       break;
     663              :     }
     664       892893 :   if (!needs_mod)
     665              :     return type;
     666              : 
     667              :   /* Construct new version with such members replaced.  */
     668        82258 :   tree n = build_distinct_type_copy (type);
     669        82258 :   tree *fields = &TYPE_FIELDS (n);
     670       696818 :   for (tree x = TYPE_FIELDS (type); x; x = DECL_CHAIN (x))
     671              :     {
     672       614560 :       tree f = copy_node (x);
     673       614560 :       if (tree m = ptr_to_tagged_member (x))
     674              :         {
     675       163328 :           tree new_node = make_node (TREE_CODE (m));
     676       163328 :           TYPE_NAME (new_node) = TYPE_NAME (m);
     677       163328 :           SET_TYPE_STRUCTURAL_EQUALITY (new_node);
     678       163328 :           new_node = qualify_type (new_node, m);
     679       163328 :           TREE_TYPE (f) = c_reconstruct_complex_type (TREE_TYPE (x),
     680              :                                                       new_node);
     681              :         }
     682       614560 :       *fields = f;
     683       614560 :       fields = &DECL_CHAIN (f);
     684              :     }
     685        82258 :   TYPE_CANONICAL (n) = n;
     686        82258 :   return n;
     687              : }
     688              : 
     689              : 
     690              : /* If NTYPE is a type of a non-variadic function with a prototype
     691              :    and OTYPE is a type of a function without a prototype and ATTRS
     692              :    contains attribute format, diagnosess and removes it from ATTRS.
     693              :    Returns the result of build_type_attribute_variant of NTYPE and
     694              :    the (possibly) modified ATTRS.  */
     695              : 
     696              : static tree
     697        10785 : c_build_functype_attribute_variant (tree ntype, tree otype, tree attrs)
     698              : {
     699        10785 :   if (!prototype_p (otype)
     700        10773 :       && prototype_p (ntype)
     701        21528 :       && lookup_attribute ("format", attrs))
     702              :     {
     703           14 :       warning_at (input_location, OPT_Wattributes,
     704              :                   "%qs attribute can only be applied to variadic functions",
     705              :                   "format");
     706           14 :       attrs = remove_attribute ("format", attrs);
     707              :     }
     708        10785 :   return c_build_type_attribute_variant (ntype, attrs);
     709              : 
     710              : }
     711              : 
     712              : /* Given a type which could be a typedef name, make sure to return the
     713              :    original type.  See set_underlying_type. */
     714              : static const_tree
     715     62779217 : c_type_original (const_tree t)
     716              : {
     717              :   /* It may even be a typedef of a typedef...
     718              :      In the case of compiler-created builtin structs the TYPE_DECL
     719              :      may be a dummy, with no DECL_ORIGINAL_TYPE.  Don't fault.  */
     720     62779217 :   while (TYPE_NAME (t)
     721     32299544 :          && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL
     722     62823685 :          && DECL_ORIGINAL_TYPE (TYPE_NAME (t)))
     723        22232 :     t = DECL_ORIGINAL_TYPE (TYPE_NAME (t));
     724     62779217 :   return t;
     725              : }
     726              : 
     727              : /* Return the tag for a tagged type.  */
     728              : tree
     729     62779217 : c_type_tag (const_tree t)
     730              : {
     731     62779217 :   gcc_assert (RECORD_OR_UNION_TYPE_P (t) || TREE_CODE (t) == ENUMERAL_TYPE);
     732     62779217 :   const_tree orig = c_type_original (t);
     733     62779217 :   tree name = TYPE_NAME (orig);
     734     62779217 :   if (!name)
     735              :     return NULL_TREE;
     736     32277312 :   if (TREE_CODE (name) == TYPE_DECL)
     737              :     {
     738            4 :       if (!DECL_NAME (name))
     739              :         return NULL_TREE;
     740            2 :       name = DECL_NAME (name);
     741              :     }
     742     32277310 :   gcc_checking_assert (TREE_CODE (name) == IDENTIFIER_NODE);
     743              :   return name;
     744              : }
     745              : 
     746              : /* Remove qualifiers but not atomic.  For arrays remove qualifiers
     747              :    on the element type but also do not remove atomic.  */
     748              : static tree
     749     66189195 : remove_qualifiers (tree t)
     750              : {
     751     66189195 :   if (!t || t == error_mark_node)
     752              :     return t;
     753     66189170 :   return TYPE_ATOMIC (strip_array_types (t))
     754     66189170 :          ? c_build_qualified_type (TYPE_MAIN_VARIANT (t), TYPE_QUAL_ATOMIC)
     755     66173603 :          : TYPE_MAIN_VARIANT (t);
     756              : }
     757              : 
     758              : 
     759              : /* Helper function for composite_type_internal.  Find a compatible type
     760              :    in a (transparent) union U compatible to T.  If found, return the
     761              :    type of the corresponding member.  Otherwise, return the union type U.  */
     762              : static tree
     763      8723570 : transparent_union_replacement (tree u, tree t)
     764              : {
     765      8723565 :   if (u == error_mark_node || t == error_mark_node
     766      8723560 :       || TREE_CODE (u) != UNION_TYPE
     767           64 :       || !(TYPE_TRANSPARENT_AGGR (u) || TYPE_NAME (u) == NULL_TREE)
     768      8723634 :       || comptypes (u, t))
     769              :     return u;
     770              : 
     771           80 :   for (tree memb = TYPE_FIELDS (u); memb; memb = DECL_CHAIN (memb))
     772              :     {
     773           80 :       tree m = remove_qualifiers (TREE_TYPE (memb));
     774           80 :       if (comptypes (m, t))
     775              :         {
     776           64 :           pedwarn (input_location, OPT_Wpedantic,
     777              :                     "function types not truly compatible in ISO C");
     778           64 :           return m;
     779              :         }
     780              :     }
     781              : 
     782              :   return u;
     783              : }
     784              : 
     785              : 
     786              : 
     787              : /* Return the composite type of two compatible types.
     788              : 
     789              :    We assume that comptypes has already been done and returned
     790              :    nonzero; if that isn't so, this may crash.  In particular, we
     791              :    assume that qualifiers match.  */
     792              : 
     793              : struct composite_cache {
     794              :   tree t1;
     795              :   tree t2;
     796              :   tree composite;
     797              :   struct composite_cache* next;
     798              : };
     799              : 
     800              : tree
     801     13765353 : composite_type_internal (tree t1, tree t2, tree cond,
     802              :                          struct composite_cache* cache)
     803              : {
     804     13765353 :   enum tree_code code1;
     805     13765353 :   enum tree_code code2;
     806     13765353 :   tree attributes;
     807              : 
     808              :   /* Save time if the two types are the same.  */
     809              : 
     810     13765353 :   if (t1 == t2) return t1;
     811              : 
     812              :   /* If one type is nonsense, use the other.  */
     813      2788224 :   if (t1 == error_mark_node)
     814              :     return t2;
     815      2788220 :   if (t2 == error_mark_node)
     816              :     return t1;
     817              : 
     818      2788218 :   code1 = TREE_CODE (t1);
     819      2788218 :   code2 = TREE_CODE (t2);
     820              : 
     821              :   /* Merge the attributes.  */
     822      2788218 :   attributes = targetm.merge_type_attributes (t1, t2);
     823              : 
     824              :   /* If one is an enumerated type and the other is the compatible
     825              :      integer type, the composite type might be either of the two
     826              :      (DR#013 question 3).  For consistency, use the enumerated type as
     827              :      the composite type.  */
     828              : 
     829      2788218 :   if (code1 == ENUMERAL_TYPE
     830          197 :       && (code2 == INTEGER_TYPE
     831          197 :           || code2 == BOOLEAN_TYPE))
     832              :     return t1;
     833      2788021 :   if (code2 == ENUMERAL_TYPE
     834           69 :       && (code1 == INTEGER_TYPE
     835           69 :           || code1 == BOOLEAN_TYPE))
     836              :     return t2;
     837              : 
     838      2787952 :   gcc_assert (code1 == code2);
     839              : 
     840      2787952 :   switch (code1)
     841              :     {
     842         6376 :     case POINTER_TYPE:
     843              :       /* For two pointers, do this recursively on the target type.  */
     844         6376 :       {
     845         6376 :         gcc_checking_assert (TYPE_QUALS (t1) == TYPE_QUALS (t2));
     846         6376 :         tree target = composite_type_internal (TREE_TYPE (t1), TREE_TYPE (t2),
     847              :                                                cond, cache);
     848         6376 :         tree n = c_build_pointer_type_for_mode (target, TYPE_MODE (t1), false);
     849        12752 :         return c_build_type_attribute_qual_variant (n, attributes,
     850         6376 :                                                     TYPE_QUALS (t2));
     851              :       }
     852              : 
     853        10996 :     case ARRAY_TYPE:
     854        10996 :       {
     855        10996 :         tree d1 = TYPE_DOMAIN (t1);
     856        10996 :         tree d2 = TYPE_DOMAIN (t2);
     857              : 
     858              :         /* We should not have any type quals on arrays at all.  */
     859        10996 :         gcc_assert (!TYPE_QUALS_NO_ADDR_SPACE (t1)
     860              :                     && !TYPE_QUALS_NO_ADDR_SPACE (t2));
     861              : 
     862        10996 :         bool d1_zero = zero_length_array_type_p (t1)
     863        10996 :                        || flexible_array_member_type_p (t1);
     864        10996 :         bool d2_zero = zero_length_array_type_p (t2)
     865        10996 :                        || flexible_array_member_type_p (t2);
     866              : 
     867        10996 :         bool d1_variable = top_array_vla_p (t1);
     868        10996 :         bool d2_variable = top_array_vla_p (t2);
     869              : 
     870        10996 :         bool use1 = d1 && (d2_variable || !d2 || d2_zero || !d1_variable);
     871        10996 :         bool use2 = d2 && (d1_variable || !d1 || d1_zero || !d2_variable);
     872              : 
     873              :         /* If the first is an unspecified size pick the other one.  */
     874        10996 :         if (d2_variable && c_type_unspecified_p (t1))
     875              :           {
     876           29 :             gcc_assert (use1 && use2);
     877              :             use1 = false;
     878              :           }
     879              : 
     880              :         /* If both are VLAs but not unspecified and we are in the
     881              :            conditional operator, we create a conditional to select
     882              :            the size of the active branch.  */
     883          232 :         bool use0 = cond && d1_variable && !c_type_unspecified_p (t1)
     884        11225 :                          && d2_variable && !c_type_unspecified_p (t2);
     885              : 
     886        10996 :         tree td;
     887        10996 :         tree elt = composite_type_internal (TREE_TYPE (t1), TREE_TYPE (t2),
     888              :                                             cond, cache);
     889              : 
     890        10996 :         if (!use0)
     891              :           {
     892              :             /* Save space: see if the result is identical to one of the args.  */
     893        10879 :             if (elt == TREE_TYPE (t1) && use1)
     894        10088 :               return c_build_type_attribute_variant (t1, attributes);
     895          791 :             if (elt == TREE_TYPE (t2) && use2)
     896          673 :               return c_build_type_attribute_variant (t2, attributes);
     897              : 
     898          161 :             if (elt == TREE_TYPE (t1) && !TYPE_DOMAIN (t2) && !TYPE_DOMAIN (t1))
     899           10 :               return c_build_type_attribute_variant (t1, attributes);
     900          116 :             if (elt == TREE_TYPE (t2) && !TYPE_DOMAIN (t2) && !TYPE_DOMAIN (t1))
     901            2 :               return c_build_type_attribute_variant (t2, attributes);
     902              : 
     903          212 :             td = TYPE_DOMAIN (use1 ? t1 : t2);
     904              :           }
     905              :         else
     906              :           {
     907              :             /* Not used in C.  */
     908          117 :             gcc_assert (size_zero_node == TYPE_MIN_VALUE (d1));
     909          117 :             gcc_assert (size_zero_node == TYPE_MIN_VALUE (d2));
     910              : 
     911          117 :             tree d = fold_build3_loc (UNKNOWN_LOCATION, COND_EXPR, sizetype,
     912          117 :                                       cond, TYPE_MAX_VALUE (d1),
     913          117 :                                       TYPE_MAX_VALUE (d2));
     914              : 
     915          117 :             td = build_index_type (d);
     916              :           }
     917              : 
     918              :         /* Merge the element types, and have a size if either arg has
     919              :            one.  We may have qualifiers on the element types.  To set
     920              :            up TYPE_MAIN_VARIANT correctly, we need to form the
     921              :            composite of the unqualified types and add the qualifiers
     922              :            back at the end.  */
     923          223 :         int quals = TYPE_QUALS (strip_array_types (elt));
     924          223 :         tree unqual_elt = c_build_qualified_type (elt, TYPE_UNQUALIFIED);
     925              : 
     926          223 :         if ((!d1 || d1_zero) && (!d2 || d2_zero) && (d1 || d2))
     927            1 :           t1 = c_build_array_type_zero_size (unqual_elt);
     928              :         else
     929          222 :           t1 = c_build_array_type (unqual_elt, td);
     930              : 
     931              :         /* Check that a type which has a varying outermost dimension
     932              :            got marked as having a variable size.  */
     933          223 :         bool varsize = (d1_variable && d2_variable)
     934           97 :                        || (d1_variable && !d2)
     935          309 :                        || (d2_variable && !d1);
     936          157 :         gcc_checking_assert (!varsize || C_TYPE_VARIABLE_SIZE (t1));
     937              : 
     938          223 :         t1 = c_build_qualified_type (t1, quals);
     939          223 :         return c_build_type_attribute_variant (t1, attributes);
     940              :       }
     941              : 
     942          253 :     case RECORD_TYPE:
     943          253 :     case UNION_TYPE:
     944          253 :       if (flag_isoc23 && !comptypes_same_p (t1, t2))
     945              :         {
     946              :           /* Go to the original type to get the right tag.  */
     947          150 :           tree tag = c_type_tag (t1);
     948              : 
     949          150 :           gcc_checking_assert (COMPLETE_TYPE_P (t1) && COMPLETE_TYPE_P (t2));
     950          150 :           gcc_checking_assert (!tag || comptypes (t1, t2));
     951              : 
     952              :           /* If a composite type for these two types is already under
     953              :              construction, return it.  */
     954              : 
     955          376 :           for (struct composite_cache *c = cache; c != NULL; c = c->next)
     956          246 :             if ((c->t1 == t1 && c->t2 == t2) || (c->t1 == t2 && c->t2 == t1))
     957           20 :                return c->composite;
     958              : 
     959              :           /* Otherwise, create a new type node and link it into the cache.  */
     960              : 
     961          130 :           tree n = make_node (code1);
     962          130 :           SET_TYPE_STRUCTURAL_EQUALITY (n);
     963          130 :           TYPE_NAME (n) = tag;
     964              : 
     965          130 :           struct composite_cache cache2 = { t1, t2, n, cache };
     966          130 :           cache = &cache2;
     967              : 
     968          130 :           tree f1 = TYPE_FIELDS (t1);
     969          130 :           tree f2 = TYPE_FIELDS (t2);
     970          130 :           tree fields = NULL_TREE;
     971              : 
     972          321 :           for (tree a = f1, b = f2; a && b;
     973          191 :                a = DECL_CHAIN (a), b = DECL_CHAIN (b))
     974              :             {
     975          191 :               tree ta = TREE_TYPE (a);
     976          191 :               tree tb = TREE_TYPE (b);
     977              : 
     978          191 :               if (DECL_C_BIT_FIELD (a))
     979              :                 {
     980           19 :                   ta = DECL_BIT_FIELD_TYPE (a);
     981           19 :                   tb = DECL_BIT_FIELD_TYPE (b);
     982              :                 }
     983              : 
     984          191 :               gcc_assert (DECL_NAME (a) == DECL_NAME (b));
     985          191 :               gcc_checking_assert (!DECL_NAME (a) || comptypes (ta, tb));
     986              : 
     987          191 :               tree t = composite_type_internal (ta, tb, cond, cache);
     988          191 :               tree f = build_decl (input_location, FIELD_DECL, DECL_NAME (a), t);
     989              : 
     990          191 :               DECL_PACKED (f) = DECL_PACKED (a);
     991          191 :               SET_DECL_ALIGN (f, DECL_ALIGN (a));
     992          191 :               DECL_ATTRIBUTES (f) = DECL_ATTRIBUTES (a);
     993          191 :               C_DECL_VARIABLE_SIZE (f) = C_TYPE_VARIABLE_SIZE (t);
     994              : 
     995          191 :               decl_attributes (&f, DECL_ATTRIBUTES (f), 0);
     996              : 
     997          191 :               finish_decl (f, input_location, NULL, NULL, NULL);
     998              : 
     999          191 :               if (DECL_C_BIT_FIELD (a))
    1000              :                 {
    1001              :                   /* This will be processed by finish_struct.  */
    1002           19 :                   SET_DECL_C_BIT_FIELD (f);
    1003           19 :                   DECL_INITIAL (f) = build_int_cst (integer_type_node,
    1004           19 :                                                     tree_to_uhwi (DECL_SIZE (a)));
    1005           19 :                   DECL_NONADDRESSABLE_P (f) = true;
    1006           19 :                   DECL_PADDING_P (f) = !DECL_NAME (a);
    1007              :                 }
    1008              : 
    1009          191 :               DECL_CHAIN (f) = fields;
    1010          191 :               fields = f;
    1011              :             }
    1012              : 
    1013          130 :           fields = nreverse (fields);
    1014              : 
    1015              :           /* Setup the struct/union type.  Because we inherit all variably
    1016              :              modified components, we can ignore the size expression.  */
    1017          130 :           tree expr = NULL_TREE;
    1018              : 
    1019              :           /* Set TYPE_STUB_DECL for debugging symbols.  */
    1020          130 :           TYPE_STUB_DECL (n) = pushdecl (build_decl (input_location, TYPE_DECL,
    1021              :                                                      NULL_TREE, n));
    1022              : 
    1023          130 :           n = finish_struct (input_location, n, fields, attributes, NULL,
    1024              :                              &expr);
    1025              : 
    1026          130 :           return qualify_type (n, t1);
    1027              :         }
    1028              :       /* FALLTHRU */
    1029          103 :     case ENUMERAL_TYPE:
    1030          103 :       if (attributes != NULL)
    1031              :         {
    1032              :           /* Try harder not to create a new aggregate type.  */
    1033            4 :           if (attribute_list_equal (TYPE_ATTRIBUTES (t1), attributes))
    1034              :             return t1;
    1035            0 :           if (attribute_list_equal (TYPE_ATTRIBUTES (t2), attributes))
    1036              :             return t2;
    1037              :         }
    1038           99 :       return c_build_type_attribute_variant (t1, attributes);
    1039              : 
    1040      2721263 :     case FUNCTION_TYPE:
    1041              :       /* Function types: prefer the one that specified arg types.
    1042              :          If both do, merge the arg types.  Also merge the return types.  */
    1043      2721263 :       {
    1044      2721263 :         tree valtype = composite_type_internal (TREE_TYPE (t1), TREE_TYPE (t2),
    1045              :                                                 cond, cache);
    1046      2721263 :         tree p1 = TYPE_ARG_TYPES (t1);
    1047      2721263 :         tree p2 = TYPE_ARG_TYPES (t2);
    1048              : 
    1049              :         /* Save space: see if the result is identical to one of the args.  */
    1050      2721263 :         if (valtype == TREE_TYPE (t1) && !TYPE_ARG_TYPES (t2))
    1051        10795 :           return c_build_functype_attribute_variant (t1, t2, attributes);
    1052      2711003 :         if (valtype == TREE_TYPE (t2) && !TYPE_ARG_TYPES (t1))
    1053          525 :           return c_build_functype_attribute_variant (t2, t1, attributes);
    1054              : 
    1055              :         /* Simple way if one arg fails to specify argument types.  */
    1056      2710478 :         if (TYPE_ARG_TYPES (t1) == NULL_TREE)
    1057              :           {
    1058            9 :             t1 = c_build_function_type (valtype, TYPE_ARG_TYPES (t2),
    1059            9 :                                         TYPE_NO_NAMED_ARGS_STDARG_P (t2));
    1060            9 :             t1 = c_build_type_attribute_variant (t1, attributes);
    1061            9 :             return qualify_type (t1, t2);
    1062              :          }
    1063      2710469 :         if (TYPE_ARG_TYPES (t2) == NULL_TREE)
    1064              :           {
    1065            1 :             t1 = c_build_function_type (valtype, TYPE_ARG_TYPES (t1),
    1066            1 :                                         TYPE_NO_NAMED_ARGS_STDARG_P (t1));
    1067            1 :             t1 = c_build_type_attribute_variant (t1, attributes);
    1068            1 :             return qualify_type (t1, t2);
    1069              :           }
    1070              : 
    1071              :         /* If both args specify argument types, we must merge the two
    1072              :            lists, argument by argument.  */
    1073      2710468 :         tree newargs = NULL_TREE;
    1074      2710468 :         tree *endp = &newargs;
    1075              : 
    1076      7072253 :         for (; p1; p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2))
    1077              :           {
    1078      6903752 :             if (p1 == void_list_node)
    1079              :               {
    1080      2541967 :                 *endp = void_list_node;
    1081      2541967 :                 break;
    1082              :               }
    1083      4361785 :             tree mv1 = remove_qualifiers (TREE_VALUE (p1));
    1084      4361785 :             tree mv2 = remove_qualifiers (TREE_VALUE (p2));
    1085              : 
    1086      4361785 :             gcc_assert (mv1);
    1087      4361785 :             gcc_assert (mv2);
    1088              : 
    1089      4361785 :             mv1 = transparent_union_replacement (mv1, mv2);
    1090      4361785 :             mv2 = transparent_union_replacement (mv2, mv1);
    1091              : 
    1092      4361785 :             *endp = tree_cons (NULL_TREE,
    1093              :                                composite_type_internal (mv1, mv2, cond, cache),
    1094              :                                NULL_TREE);
    1095              : 
    1096      4361785 :             endp = &TREE_CHAIN (*endp);
    1097              :           }
    1098              : 
    1099      2710468 :         t1 = c_build_function_type (valtype, newargs);
    1100      2710468 :         t1 = qualify_type (t1, t2);
    1101              :       }
    1102              :       /* FALLTHRU */
    1103              : 
    1104      2759532 :     default:
    1105      2759532 :       return c_build_type_attribute_variant (t1, attributes);
    1106              :     }
    1107              : }
    1108              : 
    1109              : tree
    1110      6664742 : composite_type_cond (tree t1, tree t2, tree cond)
    1111              : {
    1112      6664742 :   gcc_checking_assert (comptypes_check_for_composite (t1, t2));
    1113              : 
    1114      6664742 :   struct composite_cache cache = { };
    1115      6664742 :   tree n = composite_type_internal (t1, t2, cond, &cache);
    1116              : 
    1117      6664742 :   gcc_checking_assert (comptypes_check_for_composite (n, t1));
    1118      6664742 :   gcc_checking_assert (comptypes_check_for_composite (n, t2));
    1119      6664742 :   return n;
    1120              : }
    1121              : 
    1122              : 
    1123              : tree
    1124      6660265 : composite_type (tree t1, tree t2)
    1125              : {
    1126      6660265 :   return composite_type_cond (t1, t2, NULL_TREE);
    1127              : }
    1128              : 
    1129              : /* Return the type of a conditional expression between pointers to
    1130              :    possibly differently qualified versions of compatible types.
    1131              : 
    1132              :    We assume that comp_target_types has already been done and returned
    1133              :    true; if that isn't so, this may crash.  */
    1134              : 
    1135              : static tree
    1136       116768 : common_pointer_type (tree t1, tree t2, tree cond)
    1137              : {
    1138       116768 :   tree attributes;
    1139       116768 :   unsigned target_quals;
    1140       116768 :   addr_space_t as1, as2, as_common;
    1141       116768 :   int quals1, quals2;
    1142              : 
    1143              :   /* Save time if the two types are the same.  */
    1144              : 
    1145       116768 :   if (t1 == t2) return t1;
    1146              : 
    1147              :   /* If one type is nonsense, use the other.  */
    1148         4477 :   if (t1 == error_mark_node)
    1149              :     return t2;
    1150         4477 :   if (t2 == error_mark_node)
    1151              :     return t1;
    1152              : 
    1153         4477 :   gcc_assert (TREE_CODE (t1) == POINTER_TYPE
    1154              :               && TREE_CODE (t2) == POINTER_TYPE);
    1155              : 
    1156              :   /* Merge the attributes.  */
    1157         4477 :   attributes = targetm.merge_type_attributes (t1, t2);
    1158              : 
    1159              :   /* Find the composite type of the target types, and combine the
    1160              :      qualifiers of the two types' targets.  */
    1161         4477 :   tree pointed_to_1 = TREE_TYPE (t1);
    1162         4477 :   tree pointed_to_2 = TREE_TYPE (t2);
    1163         4477 :   tree target = composite_type_cond (TYPE_MAIN_VARIANT (pointed_to_1),
    1164         4477 :                                      TYPE_MAIN_VARIANT (pointed_to_2), cond);
    1165              : 
    1166              :   /* Strip array types to get correct qualifier for pointers to arrays */
    1167         4477 :   quals1 = TYPE_QUALS_NO_ADDR_SPACE (strip_array_types (pointed_to_1));
    1168         4477 :   quals2 = TYPE_QUALS_NO_ADDR_SPACE (strip_array_types (pointed_to_2));
    1169              : 
    1170              :   /* For function types do not merge const qualifiers, but drop them
    1171              :      if used inconsistently.  The middle-end uses these to mark const
    1172              :      and noreturn functions.  */
    1173         4477 :   if (TREE_CODE (pointed_to_1) == FUNCTION_TYPE)
    1174         2129 :     target_quals = (quals1 & quals2);
    1175              :   else
    1176         2348 :     target_quals = (quals1 | quals2);
    1177              : 
    1178              :   /* If the two named address spaces are different, determine the common
    1179              :      superset address space.  This is guaranteed to exist due to the
    1180              :      assumption that comp_target_type returned true.  */
    1181         4477 :   as1 = TYPE_ADDR_SPACE (pointed_to_1);
    1182         4477 :   as2 = TYPE_ADDR_SPACE (pointed_to_2);
    1183         4477 :   if (!addr_space_superset (as1, as2, &as_common))
    1184            0 :     gcc_unreachable ();
    1185              : 
    1186         4477 :   target_quals |= ENCODE_QUAL_ADDR_SPACE (as_common);
    1187              : 
    1188         4477 :   t1 = c_build_pointer_type (c_build_qualified_type (target, target_quals));
    1189         4477 :   return c_build_type_attribute_variant (t1, attributes);
    1190              : }
    1191              : 
    1192              : /* Return the common type for two arithmetic types under the usual
    1193              :    arithmetic conversions.  The default conversions have already been
    1194              :    applied, and enumerated types converted to their compatible integer
    1195              :    types.  The resulting type is unqualified and has no attributes.
    1196              : 
    1197              :    This is the type for the result of most arithmetic operations
    1198              :    if the operands have the given two types.  */
    1199              : 
    1200              : static tree
    1201     14113700 : c_common_type (tree t1, tree t2)
    1202              : {
    1203     14113700 :   enum tree_code code1;
    1204     14113700 :   enum tree_code code2;
    1205              : 
    1206              :   /* If one type is nonsense, use the other.  */
    1207     14113700 :   if (t1 == error_mark_node)
    1208              :     return t2;
    1209     14113700 :   if (t2 == error_mark_node)
    1210              :     return t1;
    1211              : 
    1212     14113700 :   if (TYPE_QUALS (t1) != TYPE_UNQUALIFIED)
    1213        38052 :     t1 = TYPE_MAIN_VARIANT (t1);
    1214              : 
    1215     14113700 :   if (TYPE_QUALS (t2) != TYPE_UNQUALIFIED)
    1216        49480 :     t2 = TYPE_MAIN_VARIANT (t2);
    1217              : 
    1218     14113700 :   if (TYPE_ATTRIBUTES (t1) != NULL_TREE)
    1219              :     {
    1220       189486 :       tree attrs = affects_type_identity_attributes (TYPE_ATTRIBUTES (t1));
    1221       189486 :       t1 = c_build_type_attribute_variant (t1, attrs);
    1222              :     }
    1223              : 
    1224     14113700 :   if (TYPE_ATTRIBUTES (t2) != NULL_TREE)
    1225              :     {
    1226       188964 :       tree attrs = affects_type_identity_attributes (TYPE_ATTRIBUTES (t2));
    1227       188964 :       t2 = c_build_type_attribute_variant (t2, attrs);
    1228              :     }
    1229              : 
    1230              :   /* Save time if the two types are the same.  */
    1231              : 
    1232     14113700 :   if (t1 == t2) return t1;
    1233              : 
    1234      2346678 :   code1 = TREE_CODE (t1);
    1235      2346678 :   code2 = TREE_CODE (t2);
    1236              : 
    1237      2346678 :   gcc_assert (code1 == VECTOR_TYPE || code1 == COMPLEX_TYPE
    1238              :               || code1 == FIXED_POINT_TYPE || code1 == REAL_TYPE
    1239              :               || code1 == INTEGER_TYPE || code1 == BITINT_TYPE);
    1240      2346678 :   gcc_assert (code2 == VECTOR_TYPE || code2 == COMPLEX_TYPE
    1241              :               || code2 == FIXED_POINT_TYPE || code2 == REAL_TYPE
    1242              :               || code2 == INTEGER_TYPE || code2 == BITINT_TYPE);
    1243              : 
    1244              :   /* When one operand is a decimal float type, the other operand cannot be
    1245              :      a generic float type or a complex type.  We also disallow vector types
    1246              :      here.  */
    1247      2346678 :   if ((DECIMAL_FLOAT_TYPE_P (t1) || DECIMAL_FLOAT_TYPE_P (t2))
    1248      2349101 :       && !(DECIMAL_FLOAT_TYPE_P (t1) && DECIMAL_FLOAT_TYPE_P (t2)))
    1249              :     {
    1250         1080 :       if (code1 == VECTOR_TYPE || code2 == VECTOR_TYPE)
    1251              :         {
    1252            3 :           error ("cannot mix operands of decimal floating and vector types");
    1253            3 :           return error_mark_node;
    1254              :         }
    1255         1077 :       if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE)
    1256              :         {
    1257            5 :           error ("cannot mix operands of decimal floating and complex types");
    1258            5 :           return error_mark_node;
    1259              :         }
    1260         1072 :       if (code1 == REAL_TYPE && code2 == REAL_TYPE)
    1261              :         {
    1262           16 :           error ("cannot mix operands of decimal floating "
    1263              :                  "and other floating types");
    1264           16 :           return error_mark_node;
    1265              :         }
    1266              :     }
    1267              : 
    1268              :   /* If one type is a vector type, return that type.  (How the usual
    1269              :      arithmetic conversions apply to the vector types extension is not
    1270              :      precisely specified.)  */
    1271      2346654 :   if (code1 == VECTOR_TYPE)
    1272              :     return t1;
    1273              : 
    1274      2346362 :   if (code2 == VECTOR_TYPE)
    1275              :     return t2;
    1276              : 
    1277              :   /* If one type is complex, form the common type of the non-complex
    1278              :      components, then make that complex.  Use T1 or T2 if it is the
    1279              :      required type.  */
    1280      2346359 :   if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE)
    1281              :     {
    1282        89365 :       tree subtype1 = code1 == COMPLEX_TYPE ? TREE_TYPE (t1) : t1;
    1283        89365 :       tree subtype2 = code2 == COMPLEX_TYPE ? TREE_TYPE (t2) : t2;
    1284        89365 :       tree subtype = c_common_type (subtype1, subtype2);
    1285              : 
    1286        89365 :       if (code1 == COMPLEX_TYPE && TREE_TYPE (t1) == subtype)
    1287              :         return t1;
    1288        59243 :       else if (code2 == COMPLEX_TYPE && TREE_TYPE (t2) == subtype)
    1289              :         return t2;
    1290         3258 :       else if (TREE_CODE (subtype) == BITINT_TYPE)
    1291              :         {
    1292            8 :           sorry ("%<_Complex _BitInt(%d)%> unsupported",
    1293            4 :                  TYPE_PRECISION (subtype));
    1294            4 :           return code1 == COMPLEX_TYPE ? t1 : t2;
    1295              :         }
    1296              :       else
    1297         3254 :         return build_complex_type (subtype);
    1298              :     }
    1299              : 
    1300              :   /* If only one is real, use it as the result.  */
    1301              : 
    1302      2256994 :   if (code1 == REAL_TYPE && code2 != REAL_TYPE)
    1303              :     return t1;
    1304              : 
    1305      2127875 :   if (code2 == REAL_TYPE && code1 != REAL_TYPE)
    1306              :     return t2;
    1307              : 
    1308              :   /* If both are real and either are decimal floating point types, use
    1309              :      the decimal floating point type with the greater precision. */
    1310              : 
    1311      2096530 :   if (code1 == REAL_TYPE && code2 == REAL_TYPE)
    1312              :     {
    1313       107624 :       if (TYPE_MAIN_VARIANT (t1) == dfloat128_type_node
    1314       107624 :           || TYPE_MAIN_VARIANT (t2) == dfloat128_type_node)
    1315              :         return dfloat128_type_node;
    1316              :       /* And prefer _Decimal128 over _Decimal64x which has in GCC's
    1317              :          implementation the same mode.  */
    1318       107075 :       else if (TYPE_MAIN_VARIANT (t1) == dfloat64x_type_node
    1319       107075 :                || TYPE_MAIN_VARIANT (t2) == dfloat64x_type_node)
    1320              :         return dfloat64x_type_node;
    1321       107071 :       else if (TYPE_MAIN_VARIANT (t1) == dfloat64_type_node
    1322       107071 :                || TYPE_MAIN_VARIANT (t2) == dfloat64_type_node)
    1323              :         return dfloat64_type_node;
    1324       106626 :       else if (TYPE_MAIN_VARIANT (t1) == dfloat32_type_node
    1325       106626 :                || TYPE_MAIN_VARIANT (t2) == dfloat32_type_node)
    1326              :         return dfloat32_type_node;
    1327              :     }
    1328              : 
    1329              :   /* Deal with fixed-point types.  */
    1330      2095187 :   if (code1 == FIXED_POINT_TYPE || code2 == FIXED_POINT_TYPE)
    1331              :     {
    1332            0 :       unsigned int unsignedp = 0, satp = 0;
    1333            0 :       scalar_mode m1, m2;
    1334            0 :       unsigned int fbit1, ibit1, fbit2, ibit2, max_fbit, max_ibit;
    1335              : 
    1336            0 :       m1 = SCALAR_TYPE_MODE (t1);
    1337            0 :       m2 = SCALAR_TYPE_MODE (t2);
    1338              : 
    1339              :       /* If one input type is saturating, the result type is saturating.  */
    1340            0 :       if (TYPE_SATURATING (t1) || TYPE_SATURATING (t2))
    1341              :         satp = 1;
    1342              : 
    1343              :       /* If both fixed-point types are unsigned, the result type is unsigned.
    1344              :          When mixing fixed-point and integer types, follow the sign of the
    1345              :          fixed-point type.
    1346              :          Otherwise, the result type is signed.  */
    1347            0 :       if ((TYPE_UNSIGNED (t1) && TYPE_UNSIGNED (t2)
    1348            0 :            && code1 == FIXED_POINT_TYPE && code2 == FIXED_POINT_TYPE)
    1349            0 :           || (code1 == FIXED_POINT_TYPE && code2 != FIXED_POINT_TYPE
    1350            0 :               && TYPE_UNSIGNED (t1))
    1351            0 :           || (code1 != FIXED_POINT_TYPE && code2 == FIXED_POINT_TYPE
    1352            0 :               && TYPE_UNSIGNED (t2)))
    1353              :         unsignedp = 1;
    1354              : 
    1355              :       /* The result type is signed.  */
    1356            0 :       if (unsignedp == 0)
    1357              :         {
    1358              :           /* If the input type is unsigned, we need to convert to the
    1359              :              signed type.  */
    1360            0 :           if (code1 == FIXED_POINT_TYPE && TYPE_UNSIGNED (t1))
    1361              :             {
    1362            0 :               enum mode_class mclass = (enum mode_class) 0;
    1363            0 :               if (GET_MODE_CLASS (m1) == MODE_UFRACT)
    1364              :                 mclass = MODE_FRACT;
    1365            0 :               else if (GET_MODE_CLASS (m1) == MODE_UACCUM)
    1366              :                 mclass = MODE_ACCUM;
    1367              :               else
    1368            0 :                 gcc_unreachable ();
    1369            0 :               m1 = as_a <scalar_mode>
    1370            0 :                 (mode_for_size (GET_MODE_PRECISION (m1), mclass, 0));
    1371              :             }
    1372            0 :           if (code2 == FIXED_POINT_TYPE && TYPE_UNSIGNED (t2))
    1373              :             {
    1374            0 :               enum mode_class mclass = (enum mode_class) 0;
    1375            0 :               if (GET_MODE_CLASS (m2) == MODE_UFRACT)
    1376              :                 mclass = MODE_FRACT;
    1377            0 :               else if (GET_MODE_CLASS (m2) == MODE_UACCUM)
    1378              :                 mclass = MODE_ACCUM;
    1379              :               else
    1380            0 :                 gcc_unreachable ();
    1381            0 :               m2 = as_a <scalar_mode>
    1382            0 :                 (mode_for_size (GET_MODE_PRECISION (m2), mclass, 0));
    1383              :             }
    1384              :         }
    1385              : 
    1386            0 :       if (code1 == FIXED_POINT_TYPE)
    1387              :         {
    1388            0 :           fbit1 = GET_MODE_FBIT (m1);
    1389            0 :           ibit1 = GET_MODE_IBIT (m1);
    1390              :         }
    1391              :       else
    1392              :         {
    1393            0 :           fbit1 = 0;
    1394              :           /* Signed integers need to subtract one sign bit.  */
    1395            0 :           ibit1 = TYPE_PRECISION (t1) - (!TYPE_UNSIGNED (t1));
    1396              :         }
    1397              : 
    1398            0 :       if (code2 == FIXED_POINT_TYPE)
    1399              :         {
    1400            0 :           fbit2 = GET_MODE_FBIT (m2);
    1401            0 :           ibit2 = GET_MODE_IBIT (m2);
    1402              :         }
    1403              :       else
    1404              :         {
    1405            0 :           fbit2 = 0;
    1406              :           /* Signed integers need to subtract one sign bit.  */
    1407            0 :           ibit2 = TYPE_PRECISION (t2) - (!TYPE_UNSIGNED (t2));
    1408              :         }
    1409              : 
    1410            0 :       max_ibit = ibit1 >= ibit2 ?  ibit1 : ibit2;
    1411            0 :       max_fbit = fbit1 >= fbit2 ?  fbit1 : fbit2;
    1412            0 :       return c_common_fixed_point_type_for_size (max_ibit, max_fbit, unsignedp,
    1413              :                                                  satp);
    1414              :     }
    1415              : 
    1416              :   /* Both real or both integers; use the one with greater precision.  */
    1417              : 
    1418      2095187 :   if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2))
    1419              :     return t1;
    1420      1118368 :   else if (TYPE_PRECISION (t2) > TYPE_PRECISION (t1))
    1421              :     return t2;
    1422              : 
    1423              :   /* Same precision.  Prefer long longs to longs to ints when the
    1424              :      same precision, following the C99 rules on integer type rank
    1425              :      (which are equivalent to the C90 rules for C90 types).  */
    1426              : 
    1427       752205 :   if (TYPE_MAIN_VARIANT (t1) == long_long_unsigned_type_node
    1428       752205 :       || TYPE_MAIN_VARIANT (t2) == long_long_unsigned_type_node)
    1429              :     return long_long_unsigned_type_node;
    1430              : 
    1431       662893 :   if (TYPE_MAIN_VARIANT (t1) == long_long_integer_type_node
    1432       662893 :       || TYPE_MAIN_VARIANT (t2) == long_long_integer_type_node)
    1433              :     {
    1434        15348 :       if (TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
    1435          361 :         return long_long_unsigned_type_node;
    1436              :       else
    1437              :         return long_long_integer_type_node;
    1438              :     }
    1439              : 
    1440       647545 :   if (TYPE_MAIN_VARIANT (t1) == long_unsigned_type_node
    1441       647545 :       || TYPE_MAIN_VARIANT (t2) == long_unsigned_type_node)
    1442              :     return long_unsigned_type_node;
    1443              : 
    1444       548063 :   if (TYPE_MAIN_VARIANT (t1) == long_integer_type_node
    1445       548063 :       || TYPE_MAIN_VARIANT (t2) == long_integer_type_node)
    1446              :     {
    1447              :       /* But preserve unsignedness from the other type,
    1448              :          since long cannot hold all the values of an unsigned int.  */
    1449        26425 :       if (TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
    1450          127 :         return long_unsigned_type_node;
    1451              :       else
    1452              :         return long_integer_type_node;
    1453              :     }
    1454              : 
    1455              :   /* For floating types of the same TYPE_PRECISION (which we here
    1456              :      assume means either the same set of values, or sets of values
    1457              :      neither a subset of the other, with behavior being undefined in
    1458              :      the latter case), follow the rules from TS 18661-3: prefer
    1459              :      interchange types _FloatN, then standard types long double,
    1460              :      double, float, then extended types _FloatNx.  For extended types,
    1461              :      check them starting with _Float128x as that seems most consistent
    1462              :      in spirit with preferring long double to double; for interchange
    1463              :      types, also check in that order for consistency although it's not
    1464              :      possible for more than one of them to have the same
    1465              :      precision.  */
    1466       521638 :   tree mv1 = TYPE_MAIN_VARIANT (t1);
    1467       521638 :   tree mv2 = TYPE_MAIN_VARIANT (t2);
    1468              : 
    1469      2607544 :   for (int i = NUM_FLOATN_TYPES - 1; i >= 0; i--)
    1470      2086089 :     if (mv1 == FLOATN_TYPE_NODE (i) || mv2 == FLOATN_TYPE_NODE (i))
    1471              :       return FLOATN_TYPE_NODE (i);
    1472              : 
    1473              :   /* Likewise, prefer long double to double even if same size.  */
    1474       521455 :   if (mv1 == long_double_type_node || mv2 == long_double_type_node)
    1475              :     return long_double_type_node;
    1476              : 
    1477              :   /* Likewise, prefer double to float even if same size.
    1478              :      We got a couple of embedded targets with 32 bit doubles, and the
    1479              :      pdp11 might have 64 bit floats.  */
    1480       521197 :   if (mv1 == double_type_node || mv2 == double_type_node)
    1481              :     return double_type_node;
    1482              : 
    1483       520625 :   if (mv1 == float_type_node || mv2 == float_type_node)
    1484              :     return float_type_node;
    1485              : 
    1486      2073760 :   for (int i = NUM_FLOATNX_TYPES - 1; i >= 0; i--)
    1487      1555320 :     if (mv1 == FLOATNX_TYPE_NODE (i) || mv2 == FLOATNX_TYPE_NODE (i))
    1488              :       return FLOATNX_TYPE_NODE (i);
    1489              : 
    1490       518440 :   if ((code1 == BITINT_TYPE || code2 == BITINT_TYPE) && code1 != code2)
    1491              :     {
    1492              :       /* Prefer any other integral types over bit-precise integer types.  */
    1493           33 :       if (TYPE_UNSIGNED (t1) == TYPE_UNSIGNED (t2))
    1494           20 :         return code1 == BITINT_TYPE ? t2 : t1;
    1495              :       /* If BITINT_TYPE is unsigned and the other type is signed
    1496              :          non-BITINT_TYPE with the same precision, the latter has higher rank.
    1497              :          In that case:
    1498              :          Otherwise, both operands are converted to the unsigned integer type
    1499              :          corresponding to the type of the operand with signed integer type.  */
    1500           15 :       if (TYPE_UNSIGNED (code1 == BITINT_TYPE ? t1 : t2))
    1501           12 :         return c_common_unsigned_type (code1 == BITINT_TYPE ? t2 : t1);
    1502              :     }
    1503              : 
    1504              :   /* Otherwise prefer the unsigned one.  */
    1505              : 
    1506       518409 :   if (TYPE_UNSIGNED (t1))
    1507              :     return t1;
    1508              :   else
    1509       212456 :     return t2;
    1510              : }
    1511              : 
    1512              : /* Wrapper around c_common_type that is used by c-common.cc and other
    1513              :    front end optimizations that remove promotions.  ENUMERAL_TYPEs
    1514              :    are allowed here and are converted to their compatible integer types.
    1515              :    BOOLEAN_TYPEs are allowed here and return either boolean_type_node or
    1516              :    preferably a non-Boolean type as the common type.  */
    1517              : tree
    1518       104245 : common_type (tree t1, tree t2)
    1519              : {
    1520       104245 :   if (TREE_CODE (t1) == ENUMERAL_TYPE)
    1521            0 :     t1 = ENUM_UNDERLYING_TYPE (t1);
    1522       104245 :   if (TREE_CODE (t2) == ENUMERAL_TYPE)
    1523            1 :     t2 = ENUM_UNDERLYING_TYPE (t2);
    1524              : 
    1525              :   /* If both types are BOOLEAN_TYPE, then return boolean_type_node.  */
    1526       104245 :   if (TREE_CODE (t1) == BOOLEAN_TYPE
    1527          584 :       && TREE_CODE (t2) == BOOLEAN_TYPE)
    1528          584 :     return boolean_type_node;
    1529              : 
    1530              :   /* If either type is BOOLEAN_TYPE, then return the other.  */
    1531       103661 :   if (TREE_CODE (t1) == BOOLEAN_TYPE)
    1532              :     return t2;
    1533       103661 :   if (TREE_CODE (t2) == BOOLEAN_TYPE)
    1534              :     return t1;
    1535              : 
    1536       103661 :   return c_common_type (t1, t2);
    1537              : }
    1538              : 
    1539              : 
    1540              : 
    1541              : /* Helper function for comptypes.  For two compatible types, return 1
    1542              :    if they pass consistency checks.  In particular we test that
    1543              :    TYPE_CANONICAL is set correctly, i.e. the two types can alias.  */
    1544              : 
    1545              : static bool
    1546     43545390 : comptypes_verify (tree type1, tree type2)
    1547              : {
    1548     43545390 :   if (type1 == type2 || !type1 || !type2
    1549      3635004 :       || TREE_CODE (type1) == ERROR_MARK || TREE_CODE (type2) == ERROR_MARK)
    1550              :     return true;
    1551              : 
    1552      3635003 :   gcc_checking_assert (c_verify_type (type1));
    1553      3635003 :   gcc_checking_assert (c_verify_type (type2));
    1554              : 
    1555      3635003 :   if (TYPE_CANONICAL (type1) != TYPE_CANONICAL (type2)
    1556       402800 :       && !TYPE_STRUCTURAL_EQUALITY_P (type1)
    1557      4036300 :       && !TYPE_STRUCTURAL_EQUALITY_P (type2))
    1558              :     {
    1559              :       /* FIXME: check other types. */
    1560       400986 :       if (RECORD_OR_UNION_TYPE_P (type1)
    1561       400986 :           || TREE_CODE (type1) == ENUMERAL_TYPE
    1562       400986 :           || TREE_CODE (type2) == ENUMERAL_TYPE)
    1563            0 :         return false;
    1564              :     }
    1565              :   return true;
    1566              : }
    1567              : 
    1568              : struct comptypes_data {
    1569              : 
    1570              :   /* output */
    1571              :   bool enum_and_int_p;
    1572              :   bool different_types_p;
    1573              :   bool warning_needed;
    1574              : 
    1575              :   /* context */
    1576              :   bool anon_field;
    1577              :   bool pointedto;
    1578              : 
    1579              :   /* configuration */
    1580              :   bool equiv;
    1581              :   bool ignore_promoting_args;
    1582              : 
    1583              :   const struct tagged_tu_seen_cache* cache;
    1584              : };
    1585              : 
    1586              : 
    1587              : /* Helper function for composite_type.  This function ignores when the
    1588              :    function type of an old-style declaration is incompatible with a type
    1589              :    of a declaration with prototype because some are arguments are not
    1590              :    self-promoting.  This is ignored only for function types but not
    1591              :    ignored in a nested context.  */
    1592              : 
    1593              : static bool
    1594     19994226 : comptypes_check_for_composite (tree t1, tree t2)
    1595              : {
    1596     19994226 :   struct comptypes_data data = { };
    1597     19994226 :   data.ignore_promoting_args = FUNCTION_TYPE == TREE_CODE (t1);
    1598     19994226 :   return comptypes_internal (t1, t2, &data);
    1599              : }
    1600              : 
    1601              : 
    1602              : /* C implementation of compatible_types_for_indirection_note_p.  */
    1603              : 
    1604              : bool
    1605          762 : compatible_types_for_indirection_note_p (tree type1, tree type2)
    1606              : {
    1607          762 :   return comptypes (type1, type2);
    1608              : }
    1609              : 
    1610              : /* Return true if TYPE1 and TYPE2 are compatible types for assignment
    1611              :    or various other operations.  */
    1612              : 
    1613              : bool
    1614     57035337 : comptypes (tree type1, tree type2)
    1615              : {
    1616     57035337 :   struct comptypes_data data = { };
    1617     57035337 :   bool ret = comptypes_internal (type1, type2, &data);
    1618              : 
    1619     57035337 :   gcc_checking_assert (!ret || comptypes_verify (type1, type2));
    1620              : 
    1621     57035337 :   return ret;
    1622              : }
    1623              : 
    1624              : 
    1625              : /* Like comptypes, but it returns non-zero only for identical
    1626              :    types.  */
    1627              : 
    1628              : bool
    1629        46516 : comptypes_same_p (tree type1, tree type2)
    1630              : {
    1631        46516 :   struct comptypes_data data = { };
    1632        46516 :   bool ret = comptypes_internal (type1, type2, &data);
    1633              : 
    1634        46516 :   gcc_checking_assert (!ret || comptypes_verify (type1, type2));
    1635              : 
    1636        46516 :   if (data.different_types_p)
    1637          163 :     return false;
    1638              : 
    1639              :   return ret;
    1640              : }
    1641              : 
    1642              : 
    1643              : /* Like comptypes, but if it returns true because enum and int are
    1644              :    compatible, it sets *ENUM_AND_INT_P to true.  */
    1645              : 
    1646              : bool
    1647      5246529 : comptypes_check_enum_int (tree type1, tree type2, bool *enum_and_int_p)
    1648              : {
    1649      5246529 :   struct comptypes_data data = { };
    1650      5246529 :   bool ret = comptypes_internal (type1, type2, &data);
    1651      5246529 :   *enum_and_int_p = data.enum_and_int_p;
    1652              : 
    1653      5246529 :   gcc_checking_assert (!ret || comptypes_verify (type1, type2));
    1654              : 
    1655      5246529 :   return ret;
    1656              : }
    1657              : 
    1658              : 
    1659              : 
    1660              : /* Like comptypes, but if it returns true for struct and union types
    1661              :    considered equivalent for aliasing purposes, i.e. for setting
    1662              :    TYPE_CANONICAL after completing a struct or union.
    1663              : 
    1664              :    This function must return false only for types which are not
    1665              :    compatible according to C language semantics (cf. comptypes),
    1666              :    otherwise the middle-end would make incorrect aliasing decisions.
    1667              :    It may return true for some similar types that are not compatible
    1668              :    according to those stricter rules.
    1669              : 
    1670              :    In particular, we ignore size expression in arrays so that the
    1671              :    following structs are in the same equivalence class:
    1672              : 
    1673              :    struct foo { char (*buf)[]; };
    1674              :    struct foo { char (*buf)[3]; };
    1675              :    struct foo { char (*buf)[4]; };
    1676              : 
    1677              :    We also treat unions / structs with members which are pointers to
    1678              :    structures or unions with the same tag as equivalent (if they are not
    1679              :    incompatible for other reasons).  Although incomplete structure
    1680              :    or union types are not compatible to any other type, they may become
    1681              :    compatible to different types when completed.  To avoid having to update
    1682              :    TYPE_CANONICAL at this point, we only consider the tag when forming
    1683              :    the equivalence classes.  For example, the following types with tag
    1684              :    'foo' are all considered equivalent:
    1685              : 
    1686              :    struct bar;
    1687              :    struct foo { struct bar *x };
    1688              :    struct foo { struct bar { int a; } *x };
    1689              :    struct foo { struct bar { char b; } *x };  */
    1690              : 
    1691              : bool
    1692     14747335 : comptypes_equiv_p (tree type1, tree type2)
    1693              : {
    1694     14747335 :   struct comptypes_data data = { };
    1695     14747335 :   data.equiv = true;
    1696     14747335 :   bool ret = comptypes_internal (type1, type2, &data);
    1697              : 
    1698              :   /* check that different equivance classes are assigned only
    1699              :      to types that are not compatible.  */
    1700     14747335 :   gcc_checking_assert (ret || !comptypes (type1, type2));
    1701              : 
    1702     14747335 :   return ret;
    1703              : }
    1704              : 
    1705              : 
    1706              : /* Return true if TYPE1 and TYPE2 are compatible types for assignment
    1707              :    or various other operations.  If they are compatible but a warning may
    1708              :    be needed if you use them together, 'warning_needed' in DATA is set.
    1709              :    If one type is an enum and the other a compatible integer type, then
    1710              :    this sets 'enum_and_int_p' in DATA to true (it is never set to
    1711              :    false).  If the types are compatible but different enough not to be
    1712              :    permitted in C11 typedef redeclarations, then this sets
    1713              :    'different_types_p' in DATA to true; it is never set to
    1714              :    false, but may or may not be set if the types are incompatible.
    1715              :    If two functions types are not compatible only because one is
    1716              :    an old-style definition that does not have self-promoting arguments,
    1717              :    then this can be ignored by setting 'ignore_promoting_args_p'.
    1718              :    For 'equiv' we can compute equivalency classes (see above).  */
    1719              : 
    1720              : static bool
    1721    136971519 : comptypes_internal (const_tree type1, const_tree type2,
    1722              :                     struct comptypes_data *data)
    1723              : {
    1724    137255948 :   const_tree t1 = type1;
    1725    137255948 :   const_tree t2 = type2;
    1726              : 
    1727              :   /* Suppress errors caused by previously reported errors.  */
    1728              : 
    1729    137255948 :   if (t1 == t2 || !t1 || !t2
    1730     45919430 :       || TREE_CODE (t1) == ERROR_MARK || TREE_CODE (t2) == ERROR_MARK)
    1731              :     return true;
    1732              : 
    1733              :   /* Qualifiers must match. C99 6.7.3p9 */
    1734              : 
    1735     45919427 :   if (TYPE_QUALS (t1) != TYPE_QUALS (t2))
    1736              :     return false;
    1737              : 
    1738              :   /* Enumerated types are compatible with integer types, but this is
    1739              :      not transitive: two enumerated types in the same translation unit
    1740              :      are compatible with each other only if they are the same type.  */
    1741              : 
    1742     45879134 :   if (TREE_CODE (t1) == ENUMERAL_TYPE
    1743         1008 :       && COMPLETE_TYPE_P (t1)
    1744     45880098 :       && TREE_CODE (t2) != ENUMERAL_TYPE)
    1745              :     {
    1746          848 :       t1 = ENUM_UNDERLYING_TYPE (t1);
    1747          848 :       if (TREE_CODE (t2) != VOID_TYPE)
    1748              :         {
    1749          844 :           data->enum_and_int_p = true;
    1750          844 :           data->different_types_p = true;
    1751              :         }
    1752              :     }
    1753     45878286 :   else if (TREE_CODE (t2) == ENUMERAL_TYPE
    1754         4745 :            && COMPLETE_TYPE_P (t2)
    1755     45883025 :            && TREE_CODE (t1) != ENUMERAL_TYPE)
    1756              :     {
    1757         4623 :       t2 = ENUM_UNDERLYING_TYPE (t2);
    1758         4623 :       if (TREE_CODE (t1) != VOID_TYPE)
    1759              :         {
    1760         3724 :           data->enum_and_int_p = true;
    1761         3724 :           data->different_types_p = true;
    1762              :         }
    1763              :     }
    1764              : 
    1765     45879134 :   if (t1 == t2)
    1766              :     return true;
    1767              : 
    1768              :   /* Different classes of types can't be compatible.  */
    1769              : 
    1770     45877746 :   if (TREE_CODE (t1) != TREE_CODE (t2))
    1771              :     return false;
    1772              : 
    1773              :   /* Allow for two different type nodes which have essentially the same
    1774              :      definition.  Note that we already checked for equality of the type
    1775              :      qualifiers (just above).  */
    1776              : 
    1777     37833070 :   if (TREE_CODE (t1) != ARRAY_TYPE
    1778     37833070 :       && TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
    1779              :     return true;
    1780              : 
    1781     37464772 :   int attrval;
    1782              : 
    1783              :   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
    1784     37464772 :   if (!(attrval = comp_type_attributes (t1, t2)))
    1785              :     return false;
    1786              : 
    1787     37464395 :   if (2 == attrval)
    1788          336 :     data->warning_needed = true;
    1789              : 
    1790     37464395 :   switch (TREE_CODE (t1))
    1791              :     {
    1792      3380487 :     case INTEGER_TYPE:
    1793      3380487 :     case FIXED_POINT_TYPE:
    1794      3380487 :     case REAL_TYPE:
    1795      3380487 :     case BITINT_TYPE:
    1796              :       /* With these nodes, we can't determine type equivalence by
    1797              :          looking at what is stored in the nodes themselves, because
    1798              :          two nodes might have different TYPE_MAIN_VARIANTs but still
    1799              :          represent the same type.  For example, wchar_t and int could
    1800              :          have the same properties (TYPE_PRECISION, TYPE_MIN_VALUE,
    1801              :          TYPE_MAX_VALUE, etc.), but have different TYPE_MAIN_VARIANTs
    1802              :          and are distinct types.  On the other hand, int and the
    1803              :          following typedef
    1804              : 
    1805              :            typedef int INT __attribute((may_alias));
    1806              : 
    1807              :          have identical properties, different TYPE_MAIN_VARIANTs, but
    1808              :          represent the same type.  The canonical type system keeps
    1809              :          track of equivalence in this case, so we fall back on it.  */
    1810      3380487 :       return TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2);
    1811              : 
    1812       284429 :     case POINTER_TYPE:
    1813              :       /* Do not remove mode information.  */
    1814       284429 :       if (TYPE_MODE (t1) != TYPE_MODE (t2))
    1815              :         return false;
    1816       284429 :       data->pointedto = true;
    1817       284429 :       return comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2), data);
    1818              : 
    1819      9467458 :     case FUNCTION_TYPE:
    1820      9467458 :       return function_types_compatible_p (t1, t2, data);
    1821              : 
    1822       155220 :     case ARRAY_TYPE:
    1823       155220 :       {
    1824       155220 :         tree d1 = TYPE_DOMAIN (t1);
    1825       155220 :         tree d2 = TYPE_DOMAIN (t2);
    1826              : 
    1827              :         /* Target types must match incl. qualifiers.  */
    1828       155220 :         if (!comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2), data))
    1829              :           return false;
    1830              : 
    1831       120246 :         if ((d1 == NULL_TREE) != (d2 == NULL_TREE))
    1832         6356 :           data->different_types_p = true;
    1833              :         /* Ignore size mismatches when forming equivalence classes.  */
    1834       120246 :         if (data->equiv)
    1835              :           return true;
    1836              :         /* Sizes must match unless one is missing or variable.  */
    1837        50408 :         if (d1 == NULL_TREE || d2 == NULL_TREE || d1 == d2)
    1838              :           return true;
    1839              : 
    1840        34127 :         bool d1_variable = top_array_vla_p (t1);
    1841        34127 :         bool d2_variable = top_array_vla_p (t2);
    1842              : 
    1843        34127 :         if (d1_variable != d2_variable)
    1844          943 :           data->different_types_p = true;
    1845        34127 :         if (d1_variable || d2_variable)
    1846              :           return true;
    1847              : 
    1848         4027 :         bool d1_zero = zero_length_array_type_p (t1)
    1849         4027 :                        || flexible_array_member_type_p (t1);
    1850              : 
    1851         4027 :         bool d2_zero = zero_length_array_type_p (t2)
    1852         4027 :                        || flexible_array_member_type_p (t2);
    1853              : 
    1854           93 :         if (d1_zero && d2_zero)
    1855              :           return true;
    1856         4027 :         if (d1_zero || d2_zero)
    1857              :           return false;
    1858              : 
    1859         3931 :         if (!tree_int_cst_equal (TYPE_MIN_VALUE (d1), TYPE_MIN_VALUE (d2))
    1860         3931 :             || !tree_int_cst_equal (TYPE_MAX_VALUE (d1), TYPE_MAX_VALUE (d2)))
    1861         3931 :           return false;
    1862              : 
    1863              :         return true;
    1864              :       }
    1865              : 
    1866     23636683 :     case ENUMERAL_TYPE:
    1867     23636683 :     case RECORD_TYPE:
    1868     23636683 :     case UNION_TYPE:
    1869              : 
    1870     23636683 :       if (!flag_isoc23)
    1871              :         return false;
    1872              : 
    1873     23636636 :       return tagged_types_tu_compatible_p (t1, t2, data);
    1874              : 
    1875       539313 :     case VECTOR_TYPE:
    1876      1078626 :       return known_eq (TYPE_VECTOR_SUBPARTS (t1), TYPE_VECTOR_SUBPARTS (t2))
    1877       539313 :              && comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2), data);
    1878              : 
    1879              :     default:
    1880              :       return false;
    1881              :     }
    1882              :   gcc_unreachable ();
    1883              : }
    1884              : 
    1885              : /* Return true if TTL and TTR are pointers to types that are equivalent, ignoring
    1886              :    their qualifiers, except for named address spaces.  If the pointers point to
    1887              :    different named addresses, then we must determine if one address space is a
    1888              :    subset of the other.  */
    1889              : 
    1890              : static bool
    1891      1782521 : comp_target_types (location_t location, tree ttl, tree ttr)
    1892              : {
    1893      1782521 :   tree mvl = TREE_TYPE (ttl);
    1894      1782521 :   tree mvr = TREE_TYPE (ttr);
    1895      1782521 :   addr_space_t asl = TYPE_ADDR_SPACE (mvl);
    1896      1782521 :   addr_space_t asr = TYPE_ADDR_SPACE (mvr);
    1897      1782521 :   addr_space_t as_common;
    1898              : 
    1899              :   /* Fail if pointers point to incompatible address spaces.  */
    1900      1782521 :   if (!addr_space_superset (asl, asr, &as_common))
    1901              :     return 0;
    1902              : 
    1903              :   /* Qualifiers on element types of array types that are
    1904              :      pointer targets are also removed.  */
    1905      1782521 :   struct comptypes_data data = { };
    1906      1782521 :   if (!comptypes_internal (remove_qualifiers (mvl),
    1907      1782521 :                            remove_qualifiers (mvr), &data))
    1908              :     return false;
    1909              : 
    1910              :   /* For pedantic use comptypes on arrays before removing
    1911              :      qualifiers on the element type. */
    1912      1681098 :   if (TREE_CODE (mvl) == ARRAY_TYPE
    1913         1891 :       && TREE_CODE (mvr) == ARRAY_TYPE
    1914      1682989 :       && !comptypes (mvl, mvr))
    1915          190 :     pedwarn_c11 (location, OPT_Wpedantic, "invalid use of pointers to arrays "
    1916              :                                           "with different qualifiers in ISO C "
    1917              :                                           "before C23");
    1918              : 
    1919      1681098 :   if (data.warning_needed)
    1920          126 :     pedwarn (location, OPT_Wpedantic, "types are not quite compatible");
    1921              : 
    1922      1681098 :   if (data.enum_and_int_p && warn_cxx_compat)
    1923            2 :     warning_at (location, OPT_Wc___compat,
    1924              :                 "pointer target types incompatible in C++");
    1925              : 
    1926              :   return true;
    1927              : }
    1928              : 
    1929              : /* Subroutines of `comptypes'.  */
    1930              : 
    1931              : /* Return true if two 'struct', 'union', or 'enum' types T1 and T2 are
    1932              :    compatible.  The two types are not the same (which has been
    1933              :    checked earlier in comptypes_internal).  */
    1934              : 
    1935              : static bool
    1936     23636636 : tagged_types_tu_compatible_p (const_tree t1, const_tree t2,
    1937              :                               struct comptypes_data *data)
    1938              : {
    1939     23636636 :   tree s1, s2;
    1940              : 
    1941     23636636 :   if (c_type_tag (t1) != c_type_tag (t2))
    1942              :     return false;
    1943              : 
    1944              :   /* When forming equivalence classes for TYPE_CANONICAL in C23, we treat
    1945              :      structs with the same tag as equivalent, but only when they are targets
    1946              :      of pointers inside other structs.  */
    1947     19472520 :   if (data->equiv && data->pointedto && NULL_TREE != c_type_tag (t1))
    1948              :     return true;
    1949              : 
    1950              :   /* Different types without tag are incompatible except as an anonymous
    1951              :      field or when forming equivalence classes for TYPE_CANONICAL.  */
    1952     19472458 :   if (!data->anon_field && !data->equiv && NULL_TREE == c_type_tag (t1))
    1953              :     return false;
    1954              : 
    1955     14298223 :   if (!data->anon_field && TYPE_STUB_DECL (t1) != TYPE_STUB_DECL (t2))
    1956     14297162 :     data->different_types_p = true;
    1957              : 
    1958              :   /* Incomplete types are incompatible inside a TU.  */
    1959     14298223 :   if (TYPE_SIZE (t1) == NULL || TYPE_SIZE (t2) == NULL)
    1960              :     return false;
    1961              : 
    1962     14298213 :   if (ENUMERAL_TYPE != TREE_CODE (t1)
    1963     14298213 :       && (TYPE_REVERSE_STORAGE_ORDER (t1)
    1964     14298158 :           != TYPE_REVERSE_STORAGE_ORDER (t2)))
    1965              :     return false;
    1966              : 
    1967     14298203 :   if (TYPE_USER_ALIGN (t1) != TYPE_USER_ALIGN (t2))
    1968       145014 :     data->different_types_p = true;
    1969              : 
    1970              :   /* For types already being looked at in some active
    1971              :      invocation of this function, assume compatibility.
    1972              :      The cache is built as a linked list on the stack
    1973              :      with the head of the list passed downwards.  */
    1974     14298203 :   for (const struct tagged_tu_seen_cache *t = data->cache;
    1975     14307896 :        t != NULL; t = t->next)
    1976         9988 :     if (t->t1 == t1 && t->t2 == t2)
    1977              :       return true;
    1978              : 
    1979     14297908 :   const struct tagged_tu_seen_cache entry = { data->cache, t1, t2 };
    1980              : 
    1981     14297908 :   switch (TREE_CODE (t1))
    1982              :     {
    1983           55 :     case ENUMERAL_TYPE:
    1984           55 :       {
    1985           55 :         if (!comptypes (ENUM_UNDERLYING_TYPE (t1), ENUM_UNDERLYING_TYPE (t2)))
    1986              :           return false;
    1987              : 
    1988              :         /* Speed up the case where the type values are in the same order.  */
    1989           51 :         tree tv1 = TYPE_VALUES (t1);
    1990           51 :         tree tv2 = TYPE_VALUES (t2);
    1991              : 
    1992           51 :         if (tv1 == tv2)
    1993              :           return true;
    1994              : 
    1995           97 :         for (;tv1 && tv2; tv1 = TREE_CHAIN (tv1), tv2 = TREE_CHAIN (tv2))
    1996              :           {
    1997           58 :             if (TREE_PURPOSE (tv1) != TREE_PURPOSE (tv2))
    1998              :               break;
    1999              : 
    2000           51 :             if (simple_cst_equal (DECL_INITIAL (TREE_VALUE (tv1)),
    2001           51 :                                   DECL_INITIAL (TREE_VALUE (tv2))) != 1)
    2002              :               break;
    2003              :           }
    2004              : 
    2005           51 :         if (tv1 == NULL_TREE && tv2 == NULL_TREE)
    2006              :           return true;
    2007              : 
    2008           12 :         if (tv1 == NULL_TREE || tv2 == NULL_TREE)
    2009              :           return false;
    2010              : 
    2011           12 :         if (list_length (TYPE_VALUES (t1)) != list_length (TYPE_VALUES (t2)))
    2012              :           return false;
    2013              : 
    2014           20 :         for (s1 = TYPE_VALUES (t1); s1; s1 = TREE_CHAIN (s1))
    2015              :           {
    2016           16 :             s2 = purpose_member (TREE_PURPOSE (s1), TYPE_VALUES (t2));
    2017              : 
    2018           16 :             if (s2 == NULL
    2019           29 :                 || simple_cst_equal (DECL_INITIAL (TREE_VALUE (s1)),
    2020           13 :                                      DECL_INITIAL (TREE_VALUE (s2))) != 1)
    2021              :               return false;
    2022              :           }
    2023              : 
    2024              :         return true;
    2025              :       }
    2026              : 
    2027     14297853 :     case UNION_TYPE:
    2028     14297853 :     case RECORD_TYPE:
    2029              : 
    2030     14297853 :         if (list_length (TYPE_FIELDS (t1)) != list_length (TYPE_FIELDS (t2)))
    2031              :           return false;
    2032              : 
    2033     12339691 :         for (s1 = TYPE_FIELDS (t1), s2 = TYPE_FIELDS (t2);
    2034     13863192 :              s1 && s2;
    2035      1523501 :              s1 = DECL_CHAIN (s1), s2 = DECL_CHAIN (s2))
    2036              :           {
    2037     13797358 :             gcc_assert (TREE_CODE (s1) == FIELD_DECL);
    2038     13797358 :             gcc_assert (TREE_CODE (s2) == FIELD_DECL);
    2039              : 
    2040     13797358 :             tree ft1 = TREE_TYPE (s1);
    2041     13797358 :             tree ft2 = TREE_TYPE (s2);
    2042              : 
    2043     13797358 :             if (DECL_NAME (s1) != DECL_NAME (s2))
    2044              :               return false;
    2045              : 
    2046     12140411 :             if (DECL_ALIGN (s1) != DECL_ALIGN (s2))
    2047              :               return false;
    2048              : 
    2049      3235847 :             if (DECL_C_BIT_FIELD (s1) != DECL_C_BIT_FIELD (s2))
    2050              :                return false;
    2051              : 
    2052      3235827 :             if (DECL_C_BIT_FIELD (s1))
    2053              :               {
    2054          538 :                 if (!tree_int_cst_equal (DECL_SIZE (s1), DECL_SIZE (s2)))
    2055              :                   return false;
    2056              : 
    2057          342 :                 ft1 = DECL_BIT_FIELD_TYPE (s1);
    2058          342 :                 ft2 = DECL_BIT_FIELD_TYPE (s2);
    2059              :               }
    2060              : 
    2061      3235631 :             if (!ft1 || !ft2)
    2062              :               return false;
    2063              : 
    2064      3235631 :             if (TREE_CODE (ft1) == ERROR_MARK || TREE_CODE (ft2) == ERROR_MARK)
    2065              :               return false;
    2066              : 
    2067      3235630 :             data->anon_field = !DECL_NAME (s1);
    2068      3235630 :             data->pointedto = false;
    2069              : 
    2070      3235630 :             const struct tagged_tu_seen_cache *cache = data->cache;
    2071      3235630 :             data->cache = &entry;
    2072      3235630 :             bool ret = comptypes_internal (ft1, ft2, data);
    2073      3235630 :             data->cache = cache;
    2074      3235630 :             if (!ret)
    2075              :               return false;
    2076              : 
    2077      1593227 :             tree st1 = TYPE_SIZE (TREE_TYPE (s1));
    2078      1593227 :             tree st2 = TYPE_SIZE (TREE_TYPE (s2));
    2079              : 
    2080      1593227 :             if (data->equiv
    2081       998943 :                 && st1 && TREE_CODE (st1) == INTEGER_CST
    2082       998461 :                 && st2 && TREE_CODE (st2) == INTEGER_CST
    2083      2591682 :                 && !tree_int_cst_equal (st1, st2))
    2084              :              return false;
    2085              : 
    2086      1523535 :             tree counted_by1 = lookup_attribute ("counted_by",
    2087      1523535 :                                                  DECL_ATTRIBUTES (s1));
    2088      1523535 :             tree counted_by2 = lookup_attribute ("counted_by",
    2089      1523535 :                                                  DECL_ATTRIBUTES (s2));
    2090              :             /* If there is no counted_by attribute for both fields.  */
    2091      1523535 :             if (!counted_by1 && !counted_by2)
    2092      1523471 :               continue;
    2093              : 
    2094              :             /* If only one field has counted_by attribute.  */
    2095           64 :             if ((counted_by1 && !counted_by2)
    2096           64 :                 || (!counted_by1 && counted_by2))
    2097              :               return false;
    2098              : 
    2099              :             /* Now both s1 and s2 have counted_by attributes, check
    2100              :                whether they are the same.  */
    2101              : 
    2102           52 :             tree counted_by_field1
    2103           52 :               = lookup_field (t1, TREE_VALUE (TREE_VALUE (counted_by1)));
    2104           52 :             tree counted_by_field2
    2105           52 :               = lookup_field (t2, TREE_VALUE (TREE_VALUE (counted_by2)));
    2106              : 
    2107           52 :             gcc_assert (counted_by_field1 && counted_by_field2);
    2108              : 
    2109           94 :             while (TREE_CHAIN (counted_by_field1))
    2110           42 :               counted_by_field1 = TREE_CHAIN (counted_by_field1);
    2111           86 :             while (TREE_CHAIN (counted_by_field2))
    2112           34 :               counted_by_field2 = TREE_CHAIN (counted_by_field2);
    2113              : 
    2114           52 :             if (DECL_NAME (TREE_VALUE (counted_by_field1))
    2115           52 :                 != DECL_NAME (TREE_VALUE (counted_by_field2)))
    2116              :               return false;
    2117              :           }
    2118              :         return true;
    2119              : 
    2120            0 :     default:
    2121            0 :       gcc_unreachable ();
    2122              :     }
    2123              : }
    2124              : 
    2125              : /* Return true if two function types F1 and F2 are compatible.
    2126              :    If either type specifies no argument types,
    2127              :    the other must specify a fixed number of self-promoting arg types.
    2128              :    Otherwise, if one type specifies only the number of arguments,
    2129              :    the other must specify that number of self-promoting arg types.
    2130              :    Otherwise, the argument types must match.  */
    2131              : 
    2132              : static bool
    2133      9467458 : function_types_compatible_p (const_tree f1, const_tree f2,
    2134              :                              struct comptypes_data *data)
    2135              : {
    2136      9467458 :   tree ret1 = TREE_TYPE (f1);
    2137      9467458 :   tree ret2 = TREE_TYPE (f2);
    2138              : 
    2139              :   /* 'volatile' qualifiers on a function's return type used to mean
    2140              :      the function is noreturn.  */
    2141      9467458 :   if (TYPE_VOLATILE (ret1) != TYPE_VOLATILE (ret2))
    2142           29 :     pedwarn (input_location, 0, "function return types not compatible due to %<volatile%>");
    2143      9467458 :   if (TYPE_VOLATILE (ret1))
    2144           15 :     ret1 = build_qualified_type (TYPE_MAIN_VARIANT (ret1),
    2145           15 :                                  TYPE_QUALS (ret1) & ~TYPE_QUAL_VOLATILE);
    2146      9467458 :   if (TYPE_VOLATILE (ret2))
    2147           18 :     ret2 = build_qualified_type (TYPE_MAIN_VARIANT (ret2),
    2148           18 :                                  TYPE_QUALS (ret2) & ~TYPE_QUAL_VOLATILE);
    2149              : 
    2150      9467458 :   bool ignore_pargs = data->ignore_promoting_args;
    2151      9467458 :   data->ignore_promoting_args = false;
    2152              : 
    2153      9467458 :   if (!comptypes_internal (ret1, ret2, data))
    2154              :     return false;
    2155              : 
    2156      9464869 :   data->ignore_promoting_args = ignore_pargs;
    2157              : 
    2158      9464869 :   tree args1 = TYPE_ARG_TYPES (f1);
    2159      9464869 :   tree args2 = TYPE_ARG_TYPES (f2);
    2160              : 
    2161      9464869 :   if ((args1 == NULL_TREE) != (args2 == NULL_TREE))
    2162        45321 :     data->different_types_p = true;
    2163              : 
    2164              :   /* An unspecified parmlist matches any specified parmlist
    2165              :      whose argument types don't need default promotions.  */
    2166              : 
    2167      9464869 :   if (args1 == NULL_TREE)
    2168              :     {
    2169        23801 :       if (TYPE_NO_NAMED_ARGS_STDARG_P (f1) != TYPE_NO_NAMED_ARGS_STDARG_P (f2))
    2170              :         return false;
    2171        23798 :       if (!(data->ignore_promoting_args || self_promoting_args_p (args2)))
    2172              :         return false;
    2173        23326 :       data->ignore_promoting_args = false;
    2174              :       /* If one of these types comes from a non-prototype fn definition,
    2175              :          compare that with the other type's arglist.
    2176              :          If they don't match, ask for a warning (but no error).  */
    2177        23326 :       if (TYPE_ACTUAL_ARG_TYPES (f1)
    2178        23326 :           && !type_lists_compatible_p (args2, TYPE_ACTUAL_ARG_TYPES (f1), data))
    2179           12 :          data->warning_needed = true;
    2180              :       return true;
    2181              :     }
    2182      9441068 :   if (args2 == NULL_TREE)
    2183              :     {
    2184        21602 :       if (TYPE_NO_NAMED_ARGS_STDARG_P (f1) != TYPE_NO_NAMED_ARGS_STDARG_P (f2))
    2185              :         return false;
    2186        21600 :       if (!(data->ignore_promoting_args || self_promoting_args_p (args1)))
    2187              :         return false;
    2188        21539 :       data->ignore_promoting_args = false;
    2189        21539 :       if (TYPE_ACTUAL_ARG_TYPES (f2)
    2190        21539 :           && !type_lists_compatible_p (args1, TYPE_ACTUAL_ARG_TYPES (f2), data))
    2191            1 :         data->warning_needed = true;
    2192              :       return true;
    2193              :     }
    2194              : 
    2195              :   /* Both types have argument lists: compare them and propagate results.  */
    2196      9419466 :   return type_lists_compatible_p (args1, args2, data);
    2197              : }
    2198              : 
    2199              : /* Check two lists of types for compatibility, returning false for
    2200              :    incompatible, true for compatible.  */
    2201              : 
    2202              : static bool
    2203      9419542 : type_lists_compatible_p (const_tree args1, const_tree args2,
    2204              :                          struct comptypes_data *data)
    2205              : {
    2206     58963244 :   while (1)
    2207              :     {
    2208     34191393 :       if (args1 == NULL_TREE && args2 == NULL_TREE)
    2209              :         return true;
    2210              :       /* If one list is shorter than the other,
    2211              :          they fail to match.  */
    2212     24917292 :       if (args1 == NULL_TREE || args2 == NULL_TREE)
    2213              :         return false;
    2214     24917285 :       tree a1 = TREE_VALUE (args1);
    2215     24917285 :       tree a2 = TREE_VALUE (args2);
    2216     24917285 :       tree mv1 = remove_qualifiers (a1);
    2217     24917285 :       tree mv2 = remove_qualifiers (a2);
    2218              : 
    2219     24917285 :       gcc_assert (mv2);
    2220     24917285 :       gcc_assert (mv2);
    2221              : 
    2222              :       /* If one of the lists has an error marker, ignore this arg.  */
    2223     24917285 :       if (TREE_CODE (a1) == ERROR_MARK
    2224     24917281 :                || TREE_CODE (a2) == ERROR_MARK)
    2225              :         ;
    2226     24917265 :       else if (!comptypes_internal (mv1, mv2, data))
    2227              :         {
    2228       145665 :           data->different_types_p = true;
    2229              :           /* Allow  wait (union {union wait *u; int *i} *)
    2230              :              and  wait (union wait *)  to be compatible.  */
    2231       145665 :           if (TREE_CODE (a1) == UNION_TYPE
    2232          130 :               && (TYPE_NAME (a1) == NULL_TREE
    2233           98 :                   || TYPE_TRANSPARENT_AGGR (a1))
    2234          130 :               && TREE_CODE (TYPE_SIZE (a1)) == INTEGER_CST
    2235       145795 :               && tree_int_cst_equal (TYPE_SIZE (a1),
    2236          130 :                                      TYPE_SIZE (a2)))
    2237              :             {
    2238          130 :               tree memb;
    2239          130 :               for (memb = TYPE_FIELDS (a1);
    2240          166 :                    memb; memb = DECL_CHAIN (memb))
    2241              :                 {
    2242          164 :                   tree mv3 = remove_qualifiers (TREE_TYPE (memb));
    2243          164 :                   if (comptypes_internal (mv3, mv2, data))
    2244              :                     break;
    2245              :                 }
    2246              :               if (memb == NULL_TREE)
    2247              :                 return false;
    2248              :             }
    2249       145535 :           else if (TREE_CODE (a2) == UNION_TYPE
    2250          105 :                    && (TYPE_NAME (a2) == NULL_TREE
    2251           74 :                        || TYPE_TRANSPARENT_AGGR (a2))
    2252          105 :                    && TREE_CODE (TYPE_SIZE (a2)) == INTEGER_CST
    2253       145640 :                    && tree_int_cst_equal (TYPE_SIZE (a2),
    2254          105 :                                           TYPE_SIZE (a1)))
    2255              :             {
    2256          105 :               tree memb;
    2257          105 :               for (memb = TYPE_FIELDS (a2);
    2258          133 :                    memb; memb = DECL_CHAIN (memb))
    2259              :                 {
    2260          131 :                   tree mv3 = remove_qualifiers (TREE_TYPE (memb));
    2261          131 :                   if (comptypes_internal (mv3, mv1, data))
    2262              :                     break;
    2263              :                 }
    2264              :               if (memb == NULL_TREE)
    2265              :                 return false;
    2266              :             }
    2267              :           else
    2268              :             return false;
    2269              :         }
    2270              : 
    2271     24771851 :       args1 = TREE_CHAIN (args1);
    2272     24771851 :       args2 = TREE_CHAIN (args2);
    2273     24771851 :     }
    2274              : }
    2275              : 
    2276              : /* Compute the size to increment a pointer by.  When a function type or void
    2277              :    type or incomplete type is passed, size_one_node is returned.
    2278              :    This function does not emit any diagnostics; the caller is responsible
    2279              :    for that.  */
    2280              : 
    2281              : static tree
    2282       236701 : c_size_in_bytes (const_tree type)
    2283              : {
    2284       236701 :   enum tree_code code = TREE_CODE (type);
    2285              : 
    2286       236701 :   if (code == FUNCTION_TYPE || code == VOID_TYPE || code == ERROR_MARK
    2287       236701 :       || !COMPLETE_TYPE_P (type))
    2288          195 :     return size_one_node;
    2289              : 
    2290              :   /* Convert in case a char is more than one unit.  */
    2291       236506 :   return size_binop_loc (input_location, CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
    2292       236506 :                          size_int (TYPE_PRECISION (char_type_node)
    2293              :                                    / BITS_PER_UNIT));
    2294              : }
    2295              : 
    2296              : /* Return either DECL or its known constant value (if it has one).  */
    2297              : 
    2298              : tree
    2299     14451482 : decl_constant_value_1 (tree decl, bool in_init)
    2300              : {
    2301     14451482 :   if (/* Note that DECL_INITIAL isn't valid for a PARM_DECL.  */
    2302     14451482 :       TREE_CODE (decl) != PARM_DECL
    2303     14451482 :       && !TREE_THIS_VOLATILE (decl)
    2304     14105553 :       && TREE_READONLY (decl)
    2305        37642 :       && DECL_INITIAL (decl) != NULL_TREE
    2306        36628 :       && !error_operand_p (DECL_INITIAL (decl))
    2307              :       /* This is invalid if initial value is not constant.
    2308              :          If it has either a function call, a memory reference,
    2309              :          or a variable, then re-evaluating it could give different results.  */
    2310        36619 :       && TREE_CONSTANT (DECL_INITIAL (decl))
    2311              :       /* Check for cases where this is sub-optimal, even though valid.  */
    2312     14474918 :       && (in_init || TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR))
    2313        17772 :     return DECL_INITIAL (decl);
    2314              :   return decl;
    2315              : }
    2316              : 
    2317              : /* Return either DECL or its known constant value (if it has one).
    2318              :    Like the above, but always return decl outside of functions.  */
    2319              : 
    2320              : tree
    2321     14451220 : decl_constant_value (tree decl)
    2322              : {
    2323              :   /* Don't change a variable array bound or initial value to a constant
    2324              :      in a place where a variable is invalid.  */
    2325     14451220 :   return current_function_decl ? decl_constant_value_1 (decl, false) : decl;
    2326              : }
    2327              : 
    2328              : /* Convert the array expression EXP to a pointer.  */
    2329              : static tree
    2330       831845 : array_to_pointer_conversion (location_t loc, tree exp)
    2331              : {
    2332       831845 :   tree orig_exp = exp;
    2333       831845 :   tree type = TREE_TYPE (exp);
    2334       831845 :   tree adr;
    2335       831845 :   tree restype = TREE_TYPE (type);
    2336       831845 :   tree ptrtype;
    2337              : 
    2338       831845 :   gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
    2339              : 
    2340       831845 :   STRIP_TYPE_NOPS (exp);
    2341              : 
    2342       831845 :   copy_warning (exp, orig_exp);
    2343              : 
    2344       831845 :   ptrtype = c_build_pointer_type (restype);
    2345              : 
    2346       831845 :   if (INDIRECT_REF_P (exp))
    2347         2907 :     return convert (ptrtype, TREE_OPERAND (exp, 0));
    2348              : 
    2349              :   /* In C++ array compound literals are temporary objects unless they are
    2350              :      const or appear in namespace scope, so they are destroyed too soon
    2351              :      to use them for much of anything  (c++/53220).  */
    2352       828938 :   if (warn_cxx_compat && TREE_CODE (exp) == COMPOUND_LITERAL_EXPR)
    2353              :     {
    2354           48 :       tree decl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
    2355           48 :       if (!TREE_READONLY (decl) && !TREE_STATIC (decl))
    2356           46 :         warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat,
    2357              :                     "converting an array compound literal to a pointer "
    2358              :                     "leads to a dangling pointer in C++");
    2359              :     }
    2360              : 
    2361       828938 :   adr = build_unary_op (loc, ADDR_EXPR, exp, true);
    2362       828938 :   return convert (ptrtype, adr);
    2363              : }
    2364              : 
    2365              : /* Convert the function expression EXP to a pointer.  */
    2366              : static tree
    2367     52381455 : function_to_pointer_conversion (location_t loc, tree exp)
    2368              : {
    2369     52381455 :   tree orig_exp = exp;
    2370              : 
    2371     52381455 :   gcc_assert (TREE_CODE (TREE_TYPE (exp)) == FUNCTION_TYPE);
    2372              : 
    2373     52381455 :   STRIP_TYPE_NOPS (exp);
    2374              : 
    2375     52381455 :   copy_warning (exp, orig_exp);
    2376              : 
    2377     52381455 :   tree exp2 = build_unary_op (loc, ADDR_EXPR, exp, false);
    2378              : 
    2379              :   /* If the function is defined and known to not require a non-local
    2380              :      context, make sure no trampoline is generated.  */
    2381     52381455 :   if (TREE_CODE (exp) == FUNCTION_DECL
    2382     52381455 :       && DECL_INITIAL (exp) && !C_FUNC_NONLOCAL_CONTEXT (exp))
    2383     16663110 :    TREE_NO_TRAMPOLINE (exp2) = 1;
    2384              : 
    2385     52381455 :   return exp2;
    2386              : }
    2387              : 
    2388              : /* Mark EXP as read, not just set, for set but not used -Wunused
    2389              :    warning purposes.  */
    2390              : 
    2391              : void
    2392    503274489 : mark_exp_read (tree exp)
    2393              : {
    2394    633722390 :   switch (TREE_CODE (exp))
    2395              :     {
    2396    208798738 :     case VAR_DECL:
    2397    208798738 :     case PARM_DECL:
    2398    208798738 :       DECL_READ_P (exp) = 1;
    2399    208798738 :       break;
    2400     20402166 :     CASE_CONVERT:
    2401     20402166 :       if (VOID_TYPE_P (TREE_TYPE (exp)))
    2402         3807 :         switch (TREE_CODE (TREE_OPERAND (exp, 0)))
    2403              :           {
    2404              :           case PREINCREMENT_EXPR:
    2405              :           case PREDECREMENT_EXPR:
    2406              :           case POSTINCREMENT_EXPR:
    2407              :           case POSTDECREMENT_EXPR:
    2408              :             return;
    2409              :           default:
    2410              :             break;
    2411              :           }
    2412              :       /* FALLTHRU */
    2413    127687716 :     case ARRAY_REF:
    2414    127687716 :     case COMPONENT_REF:
    2415    127687716 :     case MODIFY_EXPR:
    2416    127687716 :     case REALPART_EXPR:
    2417    127687716 :     case IMAGPART_EXPR:
    2418    127687716 :     case ADDR_EXPR:
    2419    127687716 :     case VIEW_CONVERT_EXPR:
    2420    127687716 :     case PREINCREMENT_EXPR:
    2421    127687716 :     case PREDECREMENT_EXPR:
    2422    127687716 :     case POSTINCREMENT_EXPR:
    2423    127687716 :     case POSTDECREMENT_EXPR:
    2424    127687716 :       mark_exp_read (TREE_OPERAND (exp, 0));
    2425    127687716 :       break;
    2426       236230 :     case COMPOUND_EXPR:
    2427              :       /* Pattern match what build_atomic_assign produces with modifycode
    2428              :          NOP_EXPR.  */
    2429       236230 :       if (VAR_P (TREE_OPERAND (exp, 1))
    2430        27227 :           && DECL_ARTIFICIAL (TREE_OPERAND (exp, 1))
    2431       263373 :           && TREE_CODE (TREE_OPERAND (exp, 0)) == COMPOUND_EXPR)
    2432              :         {
    2433         2210 :           tree t1 = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
    2434         2210 :           tree t2 = TREE_OPERAND (TREE_OPERAND (exp, 0), 1);
    2435         2210 :           if (TREE_CODE (t1) == TARGET_EXPR
    2436         2202 :               && TARGET_EXPR_SLOT (t1) == TREE_OPERAND (exp, 1)
    2437         4410 :               && TREE_CODE (t2) == CALL_EXPR)
    2438              :             {
    2439         2200 :               tree fndecl = get_callee_fndecl (t2);
    2440         2200 :               tree arg = NULL_TREE;
    2441         2200 :               if (fndecl
    2442         2200 :                   && TREE_CODE (fndecl) == FUNCTION_DECL
    2443         2200 :                   && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)
    2444         4400 :                   && call_expr_nargs (t2) >= 2)
    2445         2200 :                 switch (DECL_FUNCTION_CODE (fndecl))
    2446              :                   {
    2447          130 :                   case BUILT_IN_ATOMIC_STORE:
    2448          130 :                     arg = CALL_EXPR_ARG (t2, 1);
    2449          130 :                     break;
    2450         2070 :                   case BUILT_IN_ATOMIC_STORE_1:
    2451         2070 :                   case BUILT_IN_ATOMIC_STORE_2:
    2452         2070 :                   case BUILT_IN_ATOMIC_STORE_4:
    2453         2070 :                   case BUILT_IN_ATOMIC_STORE_8:
    2454         2070 :                   case BUILT_IN_ATOMIC_STORE_16:
    2455         2070 :                     arg = CALL_EXPR_ARG (t2, 0);
    2456         2070 :                     break;
    2457              :                   default:
    2458              :                     break;
    2459              :                   }
    2460         2200 :               if (arg)
    2461              :                 {
    2462         2200 :                   STRIP_NOPS (arg);
    2463         2200 :                   if (TREE_CODE (arg) == ADDR_EXPR
    2464         2200 :                       && DECL_P (TREE_OPERAND (arg, 0))
    2465         4400 :                       && TYPE_ATOMIC (TREE_TYPE (TREE_OPERAND (arg, 0))))
    2466         2200 :                     mark_exp_read (TREE_OPERAND (arg, 0));
    2467              :                 }
    2468              :             }
    2469              :         }
    2470              :       /* FALLTHRU */
    2471      2759634 :     case C_MAYBE_CONST_EXPR:
    2472      2759634 :       mark_exp_read (TREE_OPERAND (exp, 1));
    2473      2759634 :       break;
    2474          586 :     case OMP_ARRAY_SECTION:
    2475          586 :       mark_exp_read (TREE_OPERAND (exp, 0));
    2476          586 :       if (TREE_OPERAND (exp, 1))
    2477          388 :         mark_exp_read (TREE_OPERAND (exp, 1));
    2478          586 :       if (TREE_OPERAND (exp, 2))
    2479          551 :         mark_exp_read (TREE_OPERAND (exp, 2));
    2480              :       break;
    2481              :     default:
    2482              :       break;
    2483              :     }
    2484              : }
    2485              : 
    2486              : /* Perform the default conversion of arrays and functions to pointers.
    2487              :    Return the result of converting EXP.  For any other expression, just
    2488              :    return EXP.
    2489              : 
    2490              :    LOC is the location of the expression.  */
    2491              : 
    2492              : struct c_expr
    2493    372257391 : default_function_array_conversion (location_t loc, struct c_expr exp)
    2494              : {
    2495    372257391 :   tree orig_exp = exp.value;
    2496    372257391 :   tree type = TREE_TYPE (exp.value);
    2497    372257391 :   enum tree_code code = TREE_CODE (type);
    2498              : 
    2499    372257391 :   switch (code)
    2500              :     {
    2501              :     case ARRAY_TYPE:
    2502              :       {
    2503              :         bool not_lvalue = false;
    2504              :         bool lvalue_array_p;
    2505              : 
    2506       784911 :         while ((TREE_CODE (exp.value) == NON_LVALUE_EXPR
    2507       784911 :                 || CONVERT_EXPR_P (exp.value))
    2508       784911 :                && TREE_TYPE (TREE_OPERAND (exp.value, 0)) == type)
    2509              :           {
    2510            0 :             if (TREE_CODE (exp.value) == NON_LVALUE_EXPR)
    2511            0 :               not_lvalue = true;
    2512            0 :             exp.value = TREE_OPERAND (exp.value, 0);
    2513              :           }
    2514              : 
    2515       784911 :         copy_warning (exp.value, orig_exp);
    2516              : 
    2517       784911 :         lvalue_array_p = !not_lvalue && lvalue_p (exp.value);
    2518       784911 :         if (!flag_isoc99 && !lvalue_array_p)
    2519              :           {
    2520              :             /* Before C99, non-lvalue arrays do not decay to pointers.
    2521              :                Normally, using such an array would be invalid; but it can
    2522              :                be used correctly inside sizeof or as a statement expression.
    2523              :                Thus, do not give an error here; an error will result later.  */
    2524          109 :             return exp;
    2525              :           }
    2526              : 
    2527       784802 :         exp.value = array_to_pointer_conversion (loc, exp.value);
    2528              :       }
    2529       784802 :       break;
    2530       762552 :     case FUNCTION_TYPE:
    2531       762552 :       exp.value = function_to_pointer_conversion (loc, exp.value);
    2532       762552 :       break;
    2533              :     default:
    2534              :       break;
    2535              :     }
    2536              : 
    2537    372257282 :   return exp;
    2538              : }
    2539              : 
    2540              : struct c_expr
    2541        12679 : default_function_array_read_conversion (location_t loc, struct c_expr exp)
    2542              : {
    2543        12679 :   mark_exp_read (exp.value);
    2544              :   /* We only generate a call to .ACCESS_WITH_SIZE when it is a read.  */
    2545        12679 :   if (TREE_CODE (exp.value) == COMPONENT_REF
    2546        12679 :       && handle_counted_by_p (exp.value))
    2547            4 :     exp.value = handle_counted_by_for_component_ref (loc, exp.value);
    2548        12679 :   return default_function_array_conversion (loc, exp);
    2549              : }
    2550              : 
    2551              : /* Return whether EXPR should be treated as an atomic lvalue for the
    2552              :    purposes of load and store handling.  */
    2553              : 
    2554              : static bool
    2555    373377209 : really_atomic_lvalue (tree expr)
    2556              : {
    2557    373377209 :   if (error_operand_p (expr))
    2558              :     return false;
    2559    373369621 :   if (!TYPE_ATOMIC (TREE_TYPE (expr)))
    2560              :     return false;
    2561        57407 :   if (!COMPLETE_TYPE_P (TREE_TYPE (expr)))
    2562              :     return false;
    2563        57404 :   if (!lvalue_p (expr))
    2564              :     return false;
    2565              : 
    2566              :   /* Ignore _Atomic on register variables, since their addresses can't
    2567              :      be taken so (a) atomicity is irrelevant and (b) the normal atomic
    2568              :      sequences wouldn't work.  Ignore _Atomic on structures containing
    2569              :      bit-fields, since accessing elements of atomic structures or
    2570              :      unions is undefined behavior (C11 6.5.2.3#5), but it's unclear if
    2571              :      it's undefined at translation time or execution time, and the
    2572              :      normal atomic sequences again wouldn't work.  */
    2573        57530 :   while (handled_component_p (expr))
    2574              :     {
    2575          128 :       if (TREE_CODE (expr) == COMPONENT_REF
    2576          128 :           && DECL_C_BIT_FIELD (TREE_OPERAND (expr, 1)))
    2577              :         return false;
    2578          128 :       expr = TREE_OPERAND (expr, 0);
    2579              :     }
    2580        57402 :   if (TREE_CODE (expr) == COMPOUND_LITERAL_EXPR)
    2581            1 :     expr = COMPOUND_LITERAL_EXPR_DECL (expr);
    2582       112616 :   if (DECL_P (expr) && C_DECL_REGISTER (expr))
    2583            7 :     return false;
    2584              :   return true;
    2585              : }
    2586              : 
    2587              : /* If EXPR is a named constant (C23) derived from a constexpr variable
    2588              :    - that is, a reference to such a variable, or a member extracted by
    2589              :    a sequence of structure and union (but not array) member accesses
    2590              :    (where union member accesses must access the same member as
    2591              :    initialized) - then return the corresponding initializer;
    2592              :    otherwise, return NULL_TREE.  */
    2593              : 
    2594              : static tree
    2595    370150240 : maybe_get_constexpr_init (tree expr)
    2596              : {
    2597    370150240 :   tree decl = NULL_TREE;
    2598    370150240 :   if (TREE_CODE (expr) == VAR_DECL)
    2599              :     decl = expr;
    2600    358344924 :   else if (TREE_CODE (expr) == COMPOUND_LITERAL_EXPR)
    2601       827419 :     decl = COMPOUND_LITERAL_EXPR_DECL (expr);
    2602       827419 :   if (decl
    2603     12632735 :       && C_DECL_DECLARED_CONSTEXPR (decl)
    2604          498 :       && DECL_INITIAL (decl) != NULL_TREE
    2605       827917 :       && !error_operand_p (DECL_INITIAL (decl)))
    2606          498 :     return DECL_INITIAL (decl);
    2607    370149742 :   if (TREE_CODE (expr) != COMPONENT_REF)
    2608              :     return NULL_TREE;
    2609       879755 :   tree inner = maybe_get_constexpr_init (TREE_OPERAND (expr, 0));
    2610       879755 :   if (inner == NULL_TREE)
    2611              :     return NULL_TREE;
    2612          126 :   while ((CONVERT_EXPR_P (inner) || TREE_CODE (inner) == NON_LVALUE_EXPR)
    2613           47 :          && !error_operand_p (inner)
    2614          220 :          && (TYPE_MAIN_VARIANT (TREE_TYPE (inner))
    2615           47 :              == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (inner, 0)))))
    2616           47 :     inner = TREE_OPERAND (inner, 0);
    2617          126 :   if (TREE_CODE (inner) != CONSTRUCTOR)
    2618              :     return NULL_TREE;
    2619          126 :   tree field = TREE_OPERAND (expr, 1);
    2620          126 :   unsigned HOST_WIDE_INT cidx;
    2621          126 :   tree cfield, cvalue;
    2622          126 :   bool have_other_init = false;
    2623          266 :   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (inner), cidx, cfield, cvalue)
    2624              :     {
    2625          250 :       if (cfield == field)
    2626              :         return cvalue;
    2627          140 :       have_other_init = true;
    2628              :     }
    2629           16 :   if (TREE_CODE (TREE_TYPE (inner)) == UNION_TYPE
    2630           16 :       && (have_other_init || field != TYPE_FIELDS (TREE_TYPE (inner))))
    2631              :     return NULL_TREE;
    2632              :   /* Return a default initializer.  */
    2633           13 :   if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (expr)))
    2634            5 :     return build_constructor (TREE_TYPE (expr), NULL);
    2635            8 :   return build_zero_cst (TREE_TYPE (expr));
    2636              : }
    2637              : 
    2638              : /* Helper function for convert_lvalue_to_rvalue called via
    2639              :    walk_tree_without_duplicates.  Find DATA inside of the expression.  */
    2640              : 
    2641              : static tree
    2642       230125 : c_find_var_r (tree *tp, int *walk_subtrees, void *data)
    2643              : {
    2644       230125 :   if (TYPE_P (*tp))
    2645            0 :     *walk_subtrees = 0;
    2646       230125 :   else if (*tp == (tree) data)
    2647            0 :     return *tp;
    2648              :   return NULL_TREE;
    2649              : }
    2650              : 
    2651              : /* Convert expression EXP (location LOC) from lvalue to rvalue,
    2652              :    including converting functions and arrays to pointers if CONVERT_P.
    2653              :    If READ_P, also mark the expression as having been read.  If
    2654              :    FOR_INIT, constexpr expressions of structure and union type should
    2655              :    be replaced by the corresponding CONSTRUCTOR; otherwise, only
    2656              :    constexpr scalars (including elements of structures and unions) are
    2657              :    replaced by their initializers.  */
    2658              : 
    2659              : struct c_expr
    2660    369458442 : convert_lvalue_to_rvalue (location_t loc, struct c_expr exp,
    2661              :                           bool convert_p, bool read_p, bool for_init)
    2662              : {
    2663    369458442 :   bool force_non_npc = false;
    2664    369458442 :   if (read_p)
    2665    324133665 :     mark_exp_read (exp.value);
    2666              :   /* We only generate a call to .ACCESS_WITH_SIZE when it is a read.  */
    2667    324133665 :   if (read_p && TREE_CODE (exp.value) == COMPONENT_REF
    2668       786294 :       && handle_counted_by_p (exp.value))
    2669       786265 :     exp.value = handle_counted_by_for_component_ref (loc, exp.value);
    2670              : 
    2671    369458442 :   if (convert_p)
    2672    369445035 :     exp = default_function_array_conversion (loc, exp);
    2673    369458442 :   if (!VOID_TYPE_P (TREE_TYPE (exp.value))
    2674    369458442 :       || (flag_isoc2y
    2675         1574 :           && TYPE_QUALS (TREE_TYPE (exp.value)) != TYPE_UNQUALIFIED))
    2676    366860603 :     exp.value = require_complete_type (loc, exp.value);
    2677    369458442 :   if (for_init || !RECORD_OR_UNION_TYPE_P (TREE_TYPE (exp.value)))
    2678              :     {
    2679    369270485 :       tree init = maybe_get_constexpr_init (exp.value);
    2680    369270485 :       if (init != NULL_TREE)
    2681              :         {
    2682              :           /* A named constant of pointer type or type nullptr_t is not
    2683              :              a null pointer constant even if the initializer is
    2684              :              one.  */
    2685          495 :           if (TREE_CODE (init) == INTEGER_CST
    2686          360 :               && !INTEGRAL_TYPE_P (TREE_TYPE (init))
    2687          521 :               && integer_zerop (init))
    2688              :             force_non_npc = true;
    2689              :           exp.value = init;
    2690              :         }
    2691              :     }
    2692    369458442 :   if (really_atomic_lvalue (exp.value))
    2693              :     {
    2694        26928 :       vec<tree, va_gc> *params;
    2695        26928 :       tree nonatomic_type, tmp, tmp_addr, fndecl, func_call;
    2696        26928 :       tree expr_type = TREE_TYPE (exp.value);
    2697        26928 :       tree expr_addr = build_unary_op (loc, ADDR_EXPR, exp.value, false);
    2698        26928 :       tree seq_cst = build_int_cst (integer_type_node, MEMMODEL_SEQ_CST);
    2699              : 
    2700        26928 :       gcc_assert (TYPE_ATOMIC (expr_type));
    2701              : 
    2702              :       /* Expansion of a generic atomic load may require an addition
    2703              :          element, so allocate enough to prevent a resize.  */
    2704        26928 :       vec_alloc (params, 4);
    2705              : 
    2706              :       /* Remove the qualifiers for the rest of the expressions and
    2707              :          create the VAL temp variable to hold the RHS.  */
    2708        26928 :       nonatomic_type = build_qualified_type (expr_type, TYPE_UNQUALIFIED);
    2709        26928 :       tmp = create_tmp_var_raw (nonatomic_type);
    2710        26928 :       tmp_addr = build_unary_op (loc, ADDR_EXPR, tmp, false);
    2711        26928 :       TREE_ADDRESSABLE (tmp) = 1;
    2712              :       /* Do not disable warnings for TMP even though it's artificial.
    2713              :          -Winvalid-memory-model depends on it.  */
    2714              : 
    2715              :       /* Issue __atomic_load (&expr, &tmp, SEQ_CST);  */
    2716        26928 :       fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_LOAD);
    2717        26928 :       params->quick_push (expr_addr);
    2718        26928 :       params->quick_push (tmp_addr);
    2719        26928 :       params->quick_push (seq_cst);
    2720        26928 :       func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
    2721              : 
    2722              :       /* EXPR is always read.  */
    2723        26928 :       mark_exp_read (exp.value);
    2724              : 
    2725              :       /* Optimize the common case where c_build_function_call_vec
    2726              :          immediately folds __atomic_load (&expr, &tmp, SEQ_CST); into
    2727              :          tmp = __atomic_load_<N> (&expr, SEQ_CST);
    2728              :          In that case tmp is not addressable and can be initialized
    2729              :          fully by the rhs of the MODIFY_EXPR.  */
    2730        26928 :       tree tem = func_call;
    2731        26928 :       if (CONVERT_EXPR_P (tem) && VOID_TYPE_P (TREE_TYPE (tem)))
    2732              :         {
    2733        25673 :           tem = TREE_OPERAND (tem, 0);
    2734        25673 :           if (TREE_CODE (tem) == MODIFY_EXPR
    2735        25673 :               && TREE_OPERAND (tem, 0) == tmp
    2736        51346 :               && !walk_tree_without_duplicates (&TREE_OPERAND (tem, 1),
    2737              :                                                 c_find_var_r, tmp))
    2738              :             {
    2739        25673 :               TREE_ADDRESSABLE (tmp) = 0;
    2740        25673 :               func_call = TREE_OPERAND (tem, 1);
    2741              :             }
    2742              :         }
    2743              : 
    2744              :       /* Return tmp which contains the value loaded.  */
    2745        26928 :       exp.value = build4 (TARGET_EXPR, nonatomic_type, tmp, func_call,
    2746              :                           NULL_TREE, NULL_TREE);
    2747              :     }
    2748    369445035 :   if (convert_p && !error_operand_p (exp.value)
    2749    738895935 :       && (TREE_CODE (TREE_TYPE (exp.value)) != ARRAY_TYPE))
    2750    369437384 :     exp.value = convert (build_qualified_type (TREE_TYPE (exp.value), TYPE_UNQUALIFIED), exp.value);
    2751    369458442 :   if (force_non_npc)
    2752           24 :     exp.value = build1 (NOP_EXPR, TREE_TYPE (exp.value), exp.value);
    2753              : 
    2754    369458442 :   {
    2755    369458442 :     tree false_value, true_value;
    2756    369445035 :     if (convert_p && !error_operand_p (exp.value)
    2757    738895935 :         && c_hardbool_type_attr (TREE_TYPE (exp.value),
    2758              :                                  &false_value, &true_value))
    2759              :       {
    2760         9721 :         tree t = save_expr (exp.value);
    2761              : 
    2762         9721 :         mark_exp_read (exp.value);
    2763              : 
    2764         9721 :         tree trapfn = builtin_decl_explicit (BUILT_IN_TRAP);
    2765         9721 :         tree expr = build_call_expr_loc (loc, trapfn, 0);
    2766         9721 :         expr = build_compound_expr (loc, expr, boolean_true_node);
    2767         9721 :         expr = fold_build3_loc (loc, COND_EXPR, boolean_type_node,
    2768              :                                 fold_build2_loc (loc, NE_EXPR,
    2769              :                                                  boolean_type_node,
    2770              :                                                  t, true_value),
    2771              :                                 expr, boolean_true_node);
    2772         9721 :         expr = fold_build3_loc (loc, COND_EXPR, boolean_type_node,
    2773              :                                 fold_build2_loc (loc, NE_EXPR,
    2774              :                                                  boolean_type_node,
    2775              :                                                  t, false_value),
    2776              :                                 expr, boolean_false_node);
    2777              : 
    2778         9721 :         exp.value = expr;
    2779              :       }
    2780              :   }
    2781              : 
    2782    369458442 :   return exp;
    2783              : }
    2784              : 
    2785              : /* Wrapper for the overload above, same arguments but for tree rather than
    2786              :    c_expr.  This is important for hardbools to decay to bools.  */
    2787              : 
    2788              : static inline tree
    2789       580845 : convert_lvalue_to_rvalue (location_t loc, tree val,
    2790              :                           bool convert_p, bool read_p, bool for_init = false)
    2791              : {
    2792       580845 :   struct c_expr expr;
    2793       580845 :   memset (&expr, 0, sizeof (expr));
    2794       580845 :   expr.value = val;
    2795       580845 :   expr = convert_lvalue_to_rvalue (loc, expr, convert_p, read_p, for_init);
    2796       580845 :   return expr.value;
    2797              : }
    2798              : 
    2799              : /* EXP is an expression of integer type.  Apply the integer promotions
    2800              :    to it and return the promoted value.  */
    2801              : 
    2802              : tree
    2803     78590169 : perform_integral_promotions (tree exp)
    2804              : {
    2805     78590169 :   tree type = TREE_TYPE (exp);
    2806     78590169 :   enum tree_code code = TREE_CODE (type);
    2807              : 
    2808     78590169 :   gcc_assert (INTEGRAL_TYPE_P (type));
    2809              : 
    2810              :   /* Convert enums to the result of applying the integer promotions to
    2811              :      their underlying type.  */
    2812     78590169 :   if (code == ENUMERAL_TYPE)
    2813              :     {
    2814       654450 :       type = ENUM_UNDERLYING_TYPE (type);
    2815       654450 :       if (c_promoting_integer_type_p (type))
    2816              :         {
    2817           94 :           if (TYPE_UNSIGNED (type)
    2818           94 :               && TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
    2819            0 :             type = unsigned_type_node;
    2820              :           else
    2821           94 :             type = integer_type_node;
    2822              :         }
    2823              : 
    2824       654450 :       return convert (type, exp);
    2825              :     }
    2826              : 
    2827              :   /* ??? This should no longer be needed now bit-fields have their
    2828              :      proper types.  */
    2829     77935719 :   if (TREE_CODE (exp) == COMPONENT_REF
    2830     77935719 :       && DECL_C_BIT_FIELD (TREE_OPERAND (exp, 1)))
    2831              :     {
    2832        62436 :       if (BITINT_TYPE_P (DECL_BIT_FIELD_TYPE (TREE_OPERAND (exp, 1))))
    2833              :         {
    2834          584 :           tree btype = DECL_BIT_FIELD_TYPE (TREE_OPERAND (exp, 1));
    2835          584 :           if (TREE_CODE (btype) == BITINT_TYPE)
    2836          546 :             return convert (btype, exp);
    2837              :           else
    2838           38 :             return convert (ENUM_UNDERLYING_TYPE (btype), exp);
    2839              :         }
    2840              :       /* If it's thinner than an int, promote it like a
    2841              :          c_promoting_integer_type_p, otherwise leave it alone.  */
    2842        61852 :       if (compare_tree_int (DECL_SIZE (TREE_OPERAND (exp, 1)),
    2843        61852 :                             TYPE_PRECISION (integer_type_node)) < 0)
    2844        53590 :         return convert (integer_type_node, exp);
    2845              :     }
    2846              : 
    2847     77881545 :   if (c_promoting_integer_type_p (type))
    2848              :     {
    2849              :       /* Preserve unsignedness if not really getting any wider.  */
    2850       654061 :       if (TYPE_UNSIGNED (type)
    2851       654061 :           && TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
    2852            0 :         return convert (unsigned_type_node, exp);
    2853              : 
    2854       654061 :       return convert (integer_type_node, exp);
    2855              :     }
    2856              : 
    2857              :   return exp;
    2858              : }
    2859              : 
    2860              : 
    2861              : /* Perform default promotions for C data used in expressions.
    2862              :    Enumeral types or short or char are converted to int.
    2863              :    In addition, manifest constants symbols are replaced by their values.  */
    2864              : 
    2865              : tree
    2866     88183362 : default_conversion (tree exp)
    2867              : {
    2868     88183362 :   tree orig_exp;
    2869     88183362 :   tree type = TREE_TYPE (exp);
    2870     88183362 :   enum tree_code code = TREE_CODE (type);
    2871     88183362 :   tree promoted_type;
    2872              : 
    2873     88183362 :   mark_exp_read (exp);
    2874              :   /* We only generate a call to .ACCESS_WITH_SIZE when it is a read.  */
    2875     88183362 :   if (TREE_CODE (exp) == COMPONENT_REF
    2876     88183362 :       && handle_counted_by_p (exp))
    2877       602923 :     exp = handle_counted_by_for_component_ref (EXPR_LOCATION (exp), exp);
    2878              : 
    2879              :   /* Functions and arrays have been converted during parsing.  */
    2880     88183362 :   gcc_assert (code != FUNCTION_TYPE);
    2881     88183362 :   if (code == ARRAY_TYPE)
    2882              :     return exp;
    2883              : 
    2884              :   /* Constants can be used directly unless they're not loadable.  */
    2885     88183202 :   if (TREE_CODE (exp) == CONST_DECL)
    2886            0 :     exp = DECL_INITIAL (exp);
    2887              : 
    2888              :   /* Strip no-op conversions.  */
    2889     88183202 :   orig_exp = exp;
    2890     88546774 :   STRIP_TYPE_NOPS (exp);
    2891              : 
    2892     88183202 :   copy_warning (exp, orig_exp);
    2893              : 
    2894     88183202 :   if (code == VOID_TYPE)
    2895              :     {
    2896            2 :       error_at (EXPR_LOC_OR_LOC (exp, input_location),
    2897              :                 "void value not ignored as it ought to be");
    2898            2 :       return error_mark_node;
    2899              :     }
    2900              : 
    2901     88183200 :   exp = require_complete_type (EXPR_LOC_OR_LOC (exp, input_location), exp);
    2902     88183200 :   if (exp == error_mark_node)
    2903              :     return error_mark_node;
    2904              : 
    2905     88182295 :   promoted_type = targetm.promoted_type (type);
    2906     88182295 :   if (promoted_type)
    2907            0 :     return convert (promoted_type, exp);
    2908              : 
    2909     88182295 :   if (INTEGRAL_TYPE_P (type))
    2910              :     {
    2911              :       /* Avoid performing integral promotion of bit-precise integer
    2912              :          type bit-field to its corresponding bit-precise integer if
    2913              :          orig_exp is a cast to it to its underlying type.  */
    2914     77590672 :       if (orig_exp != exp
    2915        12950 :           && TREE_CODE (exp) == COMPONENT_REF
    2916           42 :           && DECL_C_BIT_FIELD (TREE_OPERAND (exp, 1))
    2917     77590703 :           && BITINT_TYPE_P (DECL_BIT_FIELD_TYPE (TREE_OPERAND (exp, 1))))
    2918           31 :         return perform_integral_promotions (orig_exp);
    2919     77590641 :       return perform_integral_promotions (exp);
    2920              :     }
    2921              : 
    2922              :   return exp;
    2923              : }
    2924              : 
    2925              : /* Look up COMPONENT in a structure or union TYPE.
    2926              : 
    2927              :    If the component name is not found, returns NULL_TREE.  Otherwise,
    2928              :    the return value is a TREE_LIST, with each TREE_VALUE a FIELD_DECL
    2929              :    stepping down the chain to the component, which is in the last
    2930              :    TREE_VALUE of the list.  Normally the list is of length one, but if
    2931              :    the component is embedded within (nested) anonymous structures or
    2932              :    unions, the list steps down the chain to the component.  */
    2933              : 
    2934              : tree
    2935      2329659 : lookup_field (const_tree type, tree component)
    2936              : {
    2937      2329659 :   tree field;
    2938              : 
    2939              :   /* If TYPE_LANG_SPECIFIC is set, then it is a sorted array of pointers
    2940              :      to the field elements.  Use a binary search on this array to quickly
    2941              :      find the element.  Otherwise, do a linear search.  TYPE_LANG_SPECIFIC
    2942              :      will always be set for structures which have many elements.
    2943              : 
    2944              :      Duplicate field checking replaces duplicates with NULL_TREE so
    2945              :      TYPE_LANG_SPECIFIC arrays are potentially no longer sorted.  In that
    2946              :      case just iterate using DECL_CHAIN.  */
    2947              : 
    2948      2631807 :   if (TYPE_LANG_SPECIFIC (type) && TYPE_LANG_SPECIFIC (type)->s
    2949      2631807 :       && !seen_error ())
    2950              :     {
    2951       302127 :       int bot, top, half;
    2952       302127 :       tree *field_array = &TYPE_LANG_SPECIFIC (type)->s->elts[0];
    2953              : 
    2954       302127 :       field = TYPE_FIELDS (type);
    2955       302127 :       bot = 0;
    2956       302127 :       top = TYPE_LANG_SPECIFIC (type)->s->len;
    2957      1387650 :       while (top - bot > 1)
    2958              :         {
    2959      1358407 :           half = (top - bot + 1) >> 1;
    2960      1358407 :           field = field_array[bot+half];
    2961              : 
    2962      1358407 :           if (DECL_NAME (field) == NULL_TREE)
    2963              :             {
    2964              :               /* Step through all anon unions in linear fashion.  */
    2965            0 :               while (DECL_NAME (field_array[bot]) == NULL_TREE)
    2966              :                 {
    2967            0 :                   field = field_array[bot++];
    2968            0 :                   if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)))
    2969              :                     {
    2970            0 :                       tree anon = lookup_field (TREE_TYPE (field), component);
    2971              : 
    2972            0 :                       if (anon)
    2973            0 :                         return tree_cons (NULL_TREE, field, anon);
    2974              : 
    2975              :                       /* The Plan 9 compiler permits referring
    2976              :                          directly to an anonymous struct/union field
    2977              :                          using a typedef name.  */
    2978            0 :                       if (flag_plan9_extensions
    2979            0 :                           && TYPE_NAME (TREE_TYPE (field)) != NULL_TREE
    2980            0 :                           && (TREE_CODE (TYPE_NAME (TREE_TYPE (field)))
    2981              :                               == TYPE_DECL)
    2982            0 :                           && (DECL_NAME (TYPE_NAME (TREE_TYPE (field)))
    2983              :                               == component))
    2984              :                         break;
    2985              :                     }
    2986              :                 }
    2987              : 
    2988              :               /* Entire record is only anon unions.  */
    2989            0 :               if (bot > top)
    2990              :                 return NULL_TREE;
    2991              : 
    2992              :               /* Restart the binary search, with new lower bound.  */
    2993            0 :               continue;
    2994            0 :             }
    2995              : 
    2996      1358407 :           if (DECL_NAME (field) == component)
    2997              :             break;
    2998      1085523 :           if (DECL_NAME (field) < component)
    2999              :             bot += half;
    3000              :           else
    3001       898275 :             top = bot + half;
    3002              :         }
    3003              : 
    3004       302127 :       if (DECL_NAME (field_array[bot]) == component)
    3005              :         field = field_array[bot];
    3006       272884 :       else if (DECL_NAME (field) != component)
    3007              :         return NULL_TREE;
    3008              :     }
    3009              :   else
    3010              :     {
    3011      5276938 :       for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    3012              :         {
    3013      5267445 :           if (DECL_NAME (field) == NULL_TREE
    3014      5267445 :               && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)))
    3015              :             {
    3016        12406 :               tree anon = lookup_field (TREE_TYPE (field), component);
    3017              : 
    3018        12406 :               if (anon)
    3019         3008 :                 return tree_cons (NULL_TREE, field, anon);
    3020              : 
    3021              :               /* The Plan 9 compiler permits referring directly to an
    3022              :                  anonymous struct/union field using a typedef
    3023              :                  name.  */
    3024         9398 :               if (flag_plan9_extensions
    3025          174 :                   && TYPE_NAME (TREE_TYPE (field)) != NULL_TREE
    3026          172 :                   && TREE_CODE (TYPE_NAME (TREE_TYPE (field))) == TYPE_DECL
    3027         9460 :                   && (DECL_NAME (TYPE_NAME (TREE_TYPE (field)))
    3028              :                       == component))
    3029              :                 break;
    3030              :             }
    3031              : 
    3032      5264433 :           if (DECL_NAME (field) == component)
    3033              :             break;
    3034              :         }
    3035              : 
    3036      2024524 :       if (field == NULL_TREE)
    3037              :         return NULL_TREE;
    3038              :     }
    3039              : 
    3040      2317158 :   return tree_cons (NULL_TREE, field, NULL_TREE);
    3041              : }
    3042              : 
    3043              : /* Recursively append candidate IDENTIFIER_NODEs to CANDIDATES.  */
    3044              : 
    3045              : static void
    3046          101 : lookup_field_fuzzy_find_candidates (tree type, tree component,
    3047              :                                     vec<tree> *candidates)
    3048              : {
    3049          101 :   tree field;
    3050          258 :   for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    3051              :     {
    3052          157 :       if (DECL_NAME (field) == NULL_TREE
    3053          157 :           && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)))
    3054           30 :         lookup_field_fuzzy_find_candidates (TREE_TYPE (field), component,
    3055              :                                             candidates);
    3056              : 
    3057          157 :       if (DECL_NAME (field))
    3058          111 :         candidates->safe_push (DECL_NAME (field));
    3059              :     }
    3060          101 : }
    3061              : 
    3062              : /* Like "lookup_field", but find the closest matching IDENTIFIER_NODE,
    3063              :    rather than returning a TREE_LIST for an exact match.  */
    3064              : 
    3065              : static tree
    3066           71 : lookup_field_fuzzy (tree type, tree component)
    3067              : {
    3068           71 :   gcc_assert (TREE_CODE (component) == IDENTIFIER_NODE);
    3069              : 
    3070              :   /* First, gather a list of candidates.  */
    3071           71 :   auto_vec <tree> candidates;
    3072              : 
    3073           71 :   lookup_field_fuzzy_find_candidates (type, component,
    3074              :                                       &candidates);
    3075              : 
    3076           71 :   return find_closest_identifier (component, &candidates);
    3077           71 : }
    3078              : 
    3079              : /* Support function for build_component_ref's error-handling.
    3080              : 
    3081              :    Given DATUM_TYPE, and "DATUM.COMPONENT", where DATUM is *not* a
    3082              :    struct or union, should we suggest "DATUM->COMPONENT" as a hint?  */
    3083              : 
    3084              : static bool
    3085           72 : should_suggest_deref_p (tree datum_type)
    3086              : {
    3087              :   /* We don't do it for Objective-C, since Objective-C 2.0 dot-syntax
    3088              :      allows "." for ptrs; we could be handling a failed attempt
    3089              :      to access a property.  */
    3090           72 :   if (c_dialect_objc ())
    3091              :     return false;
    3092              : 
    3093              :   /* Only suggest it for pointers...  */
    3094           72 :   if (TREE_CODE (datum_type) != POINTER_TYPE)
    3095              :     return false;
    3096              : 
    3097              :   /* ...to structs/unions.  */
    3098            8 :   tree underlying_type = TREE_TYPE (datum_type);
    3099            8 :   enum tree_code code = TREE_CODE (underlying_type);
    3100            8 :   if (code == RECORD_TYPE || code == UNION_TYPE)
    3101              :     return true;
    3102              :   else
    3103            1 :     return false;
    3104              : }
    3105              : 
    3106              : /* Give a component ref REF, decide whether we should handle its counted_by
    3107              :    attribute based on its context:
    3108              :    Do not handle counted_by when in offsetof, typeof and alignof operator.  */
    3109              : 
    3110              : static bool
    3111      2215287 : handle_counted_by_p (tree ref)
    3112              : {
    3113      2215287 :   gcc_assert (TREE_CODE (ref) == COMPONENT_REF);
    3114      2215287 :   tree datum = TREE_OPERAND (ref, 0);
    3115              :   /* If the component_ref is build for a offsetof, i.e., the datum
    3116              :      of the component_ref is a indirect_ref of null_pointer_node,
    3117              :      we should not generate call to .ACCESS_WITH_SIZE.  */
    3118      2215287 :   if (TREE_CODE (datum) == INDIRECT_REF
    3119      2215287 :       && TREE_OPERAND (datum, 0) == null_pointer_node)
    3120              :     return false;
    3121      2214949 :   if (in_typeof || in_alignof)
    3122         8786 :     return false;
    3123              :   return true;
    3124              : }
    3125              : 
    3126              : /* Given a component ref REF, if there is a counted_by attribute attached,
    3127              :    issue error when the element_type is a structure or union including a
    3128              :    flexible array member.  */
    3129              : 
    3130              : static void
    3131      2283093 : check_counted_by_attribute (location_t loc, tree ref)
    3132              : {
    3133      2283093 :   tree subdatum = TREE_OPERAND (ref, 1);
    3134      2283093 :   tree sub_type = TREE_TYPE (subdatum);
    3135              : 
    3136      2283093 :   if (!flexible_array_member_type_p (sub_type)
    3137      2283093 :       && TREE_CODE (sub_type) != POINTER_TYPE)
    3138              :     return;
    3139              : 
    3140       389801 :   tree element_type = TREE_TYPE (sub_type);
    3141              : 
    3142       389801 :   tree attr_counted_by = lookup_attribute ("counted_by",
    3143       389801 :                                            DECL_ATTRIBUTES (subdatum));
    3144       389801 :   if (attr_counted_by)
    3145              :     {
    3146              :       /* Issue error when the element_type is a structure or
    3147              :         union including a flexible array member.  */
    3148          883 :       if (RECORD_OR_UNION_TYPE_P (element_type)
    3149          883 :           && TYPE_INCLUDES_FLEXARRAY (element_type))
    3150              :         {
    3151            2 :           error_at (loc,
    3152              :                     "%<counted_by%> attribute is not allowed for a pointer to"
    3153              :                     " structure or union with flexible array member");
    3154            2 :           return;
    3155              :         }
    3156              :     }
    3157              : }
    3158              : 
    3159              : /* For a SUBDATUM field of a structure or union DATUM, generate a REF
    3160              :    to the object that represents its counted_by per the attribute
    3161              :    counted_by attached to this field if it's a flexible array member
    3162              :    or a pointer field, otherwise return NULL_TREE.
    3163              :    Set COUNTED_BY_TYPE to the TYPE of the counted_by field.
    3164              :    For example, if:
    3165              : 
    3166              :     struct P {
    3167              :       int k;
    3168              :       int x[] __attribute__ ((counted_by (k)));
    3169              :     } *p;
    3170              : 
    3171              :     for:
    3172              :     p->x
    3173              : 
    3174              :     the ref to the object that represents its element count will be:
    3175              : 
    3176              :     &(p->k)
    3177              : */
    3178              : 
    3179              : static tree
    3180       441708 : build_counted_by_ref (tree datum, tree subdatum,
    3181              :                       tree *counted_by_type)
    3182              : {
    3183       441708 :   tree sub_type = TREE_TYPE (subdatum);
    3184       441708 :   if (!flexible_array_member_type_p (sub_type)
    3185       441708 :       && TREE_CODE (sub_type) != POINTER_TYPE)
    3186              :     return NULL_TREE;
    3187              : 
    3188       441708 :   tree attr_counted_by = lookup_attribute ("counted_by",
    3189       441708 :                                            DECL_ATTRIBUTES (subdatum));
    3190       441708 :   if (!attr_counted_by)
    3191              :     return NULL_TREE;
    3192              : 
    3193          661 :   tree counted_by_ref = NULL_TREE;
    3194          661 :   *counted_by_type = NULL_TREE;
    3195              : 
    3196          661 :   tree type = TREE_TYPE (datum);
    3197              : 
    3198              :   /* If the type of the containing structure is an anonymous struct/union,
    3199              :      and this anonymous struct/union is not a root type, get the first
    3200              :      outer named structure/union type.  */
    3201          661 :   while (TREE_CODE (datum) == COMPONENT_REF
    3202           35 :          && c_type_tag (type) == NULL_TREE
    3203          731 :          && DECL_NAME (TREE_OPERAND (datum, 1)) == NULL_TREE)
    3204              :     {
    3205           35 :       datum = TREE_OPERAND (datum, 0);
    3206           35 :       type = TREE_TYPE (datum);
    3207              :     }
    3208              : 
    3209          661 :   tree field_id = TREE_VALUE (TREE_VALUE (attr_counted_by));
    3210          661 :   tree counted_by_field = lookup_field (type, field_id);
    3211          661 :   gcc_assert (counted_by_field);
    3212              : 
    3213         1073 :   tree counted_by_subdatum;
    3214         1073 :   do
    3215              :     {
    3216         1073 :       counted_by_subdatum = TREE_VALUE (counted_by_field);
    3217              :       /* Get the TYPE of the counted_by field.  */
    3218         1073 :       *counted_by_type = TREE_TYPE (counted_by_subdatum);
    3219              : 
    3220         1073 :       counted_by_ref
    3221         1073 :         = build3 (COMPONENT_REF, TREE_TYPE (counted_by_subdatum),
    3222              :                   datum, counted_by_subdatum, NULL_TREE);
    3223              : 
    3224         1073 :       datum = counted_by_ref;
    3225         1073 :       counted_by_field = TREE_CHAIN (counted_by_field);
    3226              :     }
    3227         1073 :   while (counted_by_field);
    3228              : 
    3229          661 :   counted_by_ref = build_fold_addr_expr (counted_by_ref);
    3230          661 :   return counted_by_ref;
    3231              : }
    3232              : 
    3233              : /* Given a COMPONENT_REF REF with the location LOC, the corresponding
    3234              :    COUNTED_BY_REF, and the COUNTED_BY_TYPE, generate the corresponding
    3235              :    call to the internal function .ACCESS_WITH_SIZE.
    3236              : 
    3237              :    A: For the Flexible Array Member, Generate an INDIRECT_REF to a call to
    3238              :    the internal function .ACCESS_WITH_SIZE.
    3239              : 
    3240              :    REF
    3241              : 
    3242              :    to:
    3243              : 
    3244              :    (*.ACCESS_WITH_SIZE (REF, COUNTED_BY_REF, (* TYPE_OF_SIZE)0,
    3245              :                         TYPE_SIZE_UNIT for element)
    3246              : 
    3247              :    NOTE: The return type of this function is the POINTER type pointing
    3248              :    to the original flexible array type.  Then the type of the INDIRECT_REF
    3249              :    is the original flexible array type.
    3250              :    The type of the first argument of this function is a POINTER type
    3251              :    to the original flexible array type.
    3252              : 
    3253              :    B: For pointers with counted_by, generate a call to the internal function
    3254              :    .ACCESS_WITH_SIZE.
    3255              : 
    3256              :     REF
    3257              : 
    3258              :     to:
    3259              : 
    3260              :     .ACCESS_WITH_SIZE (REF, COUNTED_BY_REF, (* TYPE_OF_SIZE)0,
    3261              :                        TYPE_SIZE_UNIT for element)
    3262              : 
    3263              :    NOTE: The return type of this function is the original pointer type.
    3264              :    The type of the first argument of this function is the original
    3265              :    pointer type.
    3266              : 
    3267              :    The 3rd argument of the call is a constant 0 with the pointer TYPE whose
    3268              :    pointee type is the TYPE of the object pointed by COUNTED_BY_REF.
    3269              : 
    3270              :    The 4th argument of the call is the TYPE_SIZE_UNIT of the element TYPE
    3271              :    of the array.
    3272              : 
    3273              :   */
    3274              : static tree
    3275          661 : build_access_with_size_for_counted_by (location_t loc, tree ref,
    3276              :                                        tree counted_by_ref,
    3277              :                                        tree counted_by_type)
    3278              : {
    3279          661 :   gcc_assert (flexible_array_member_type_p (TREE_TYPE (ref))
    3280              :               || TREE_CODE (TREE_TYPE (ref)) == POINTER_TYPE);
    3281              : 
    3282          661 :   bool is_fam = flexible_array_member_type_p (TREE_TYPE (ref));
    3283              : 
    3284              :   /* The result type of the call is a pointer to the flexible array type;
    3285              :      or is the original pointer type to the pointer field with counted_by.  */
    3286          661 :   tree result_type = is_fam ? c_build_pointer_type (TREE_TYPE (ref))
    3287          459 :                      : TREE_TYPE (ref);
    3288              : 
    3289          661 :   tree element_type = TREE_TYPE (TREE_TYPE (ref));
    3290          661 :   tree element_size = VOID_TYPE_P (element_type)
    3291          661 :                       ? size_one_node
    3292          661 :                       : TYPE_SIZE_UNIT (element_type);
    3293          661 :   if (element_size == NULL_TREE)
    3294              :     return ref;
    3295              : 
    3296          647 :   tree first_param = is_fam
    3297          647 :                      ? c_fully_fold (array_to_pointer_conversion (loc, ref),
    3298              :                                      false, NULL)
    3299          445 :                      : c_fully_fold (ref, false, NULL);
    3300          647 :   tree second_param
    3301          647 :     = c_fully_fold (counted_by_ref, false, NULL);
    3302          647 :   tree third_param = build_int_cst (c_build_pointer_type (counted_by_type), 0);
    3303              : 
    3304          647 :   tree call
    3305          647 :     = build_call_expr_internal_loc (loc, IFN_ACCESS_WITH_SIZE,
    3306              :                                     result_type, 4,
    3307              :                                     first_param,
    3308              :                                     second_param,
    3309              :                                     third_param,
    3310              :                                     element_size);
    3311              : 
    3312              :   /* Wrap the call with an INDIRECT_REF with the flexible array type.  */
    3313          647 :   if (is_fam)
    3314          202 :     call = build1 (INDIRECT_REF, TREE_TYPE (ref), call);
    3315          647 :   SET_EXPR_LOCATION (call, loc);
    3316          647 :   return call;
    3317              : }
    3318              : 
    3319              : /* For the COMPONENT_REF ref, check whether it has a counted_by attribute,
    3320              :    if so, wrap this COMPONENT_REF with the corresponding CALL to the
    3321              :    function .ACCESS_WITH_SIZE.
    3322              :    Otherwise, return the ref itself.  */
    3323              : 
    3324              : tree
    3325      2206243 : handle_counted_by_for_component_ref (location_t loc, tree ref)
    3326              : {
    3327      2206243 :   gcc_assert (TREE_CODE (ref) == COMPONENT_REF);
    3328      2206243 :   tree datum = TREE_OPERAND (ref, 0);
    3329      2206243 :   tree subdatum = TREE_OPERAND (ref, 1);
    3330      2206243 :   tree counted_by_type = NULL_TREE;
    3331              : 
    3332      2206243 :   if (!(flexible_array_member_type_p (TREE_TYPE (ref))
    3333      2135720 :         || TREE_CODE (TREE_TYPE (ref)) == POINTER_TYPE))
    3334              :     return ref;
    3335              : 
    3336       441708 :   tree counted_by_ref = build_counted_by_ref (datum, subdatum,
    3337              :                                               &counted_by_type);
    3338       441708 :   if (counted_by_ref)
    3339          661 :     ref = build_access_with_size_for_counted_by (loc, ref,
    3340              :                                                  counted_by_ref,
    3341              :                                                  counted_by_type);
    3342              :   return ref;
    3343              : }
    3344              : 
    3345              : /* Make an expression to refer to the COMPONENT field of structure or
    3346              :    union value DATUM.  COMPONENT is an IDENTIFIER_NODE.  LOC is the
    3347              :    location of the COMPONENT_REF.  COMPONENT_LOC is the location
    3348              :    of COMPONENT.  ARROW_LOC is the location of the first -> operand if
    3349              :    it is from -> operator.
    3350              :    If HANDLE_COUNTED_BY is true, check the counted_by attribute and generate
    3351              :    a call to .ACCESS_WITH_SIZE.  Otherwise, ignore the attribute.  */
    3352              : 
    3353              : tree
    3354      2280974 : build_component_ref (location_t loc, tree datum, tree component,
    3355              :                      location_t component_loc, location_t arrow_loc)
    3356              : {
    3357      2280974 :   tree type = TREE_TYPE (datum);
    3358      2280974 :   enum tree_code code = TREE_CODE (type);
    3359      2280974 :   tree field = NULL;
    3360      2280974 :   tree ref;
    3361      2280974 :   bool datum_lvalue = lvalue_p (datum);
    3362              : 
    3363      2280974 :   if (!objc_is_public (datum, component))
    3364            0 :     return error_mark_node;
    3365              : 
    3366              :   /* Detect Objective-C property syntax object.property.  */
    3367      2280974 :   if (c_dialect_objc ()
    3368      2280974 :       && (ref = objc_maybe_build_component_ref (datum, component)))
    3369              :     return ref;
    3370              : 
    3371              :   /* See if there is a field or component with name COMPONENT.  */
    3372              : 
    3373      2280974 :   if (code == RECORD_TYPE || code == UNION_TYPE)
    3374              :     {
    3375      2280902 :       if (!COMPLETE_TYPE_P (type))
    3376              :         {
    3377           19 :           c_incomplete_type_error (loc, NULL_TREE, type);
    3378           19 :           return error_mark_node;
    3379              :         }
    3380              : 
    3381      2280883 :       field = lookup_field (type, component);
    3382              : 
    3383      2280883 :       if (!field)
    3384              :         {
    3385           63 :           tree guessed_id = lookup_field_fuzzy (type, component);
    3386           63 :           if (guessed_id)
    3387              :             {
    3388              :               /* Attempt to provide a fixit replacement hint, if
    3389              :                  we have a valid range for the component.  */
    3390            0 :               location_t reported_loc
    3391           26 :                 = (component_loc != UNKNOWN_LOCATION) ? component_loc : loc;
    3392           26 :               gcc_rich_location rich_loc (reported_loc);
    3393           26 :               if (component_loc != UNKNOWN_LOCATION)
    3394           26 :                 rich_loc.add_fixit_misspelled_id (component_loc, guessed_id);
    3395           26 :               error_at (&rich_loc,
    3396              :                         "%qT has no member named %qE; did you mean %qE?",
    3397              :                         type, component, guessed_id);
    3398           26 :             }
    3399              :           else
    3400           37 :             error_at (loc, "%qT has no member named %qE", type, component);
    3401           63 :           return error_mark_node;
    3402              :         }
    3403              : 
    3404              :       /* Accessing elements of atomic structures or unions is undefined
    3405              :          behavior (C11 6.5.2.3#5).  */
    3406      2280820 :       if (TYPE_ATOMIC (type) && c_inhibit_evaluation_warnings == 0)
    3407              :         {
    3408           18 :           if (code == RECORD_TYPE)
    3409           12 :             warning_at (loc, 0, "accessing a member %qE of an atomic "
    3410              :                         "structure %qE", component, datum);
    3411              :           else
    3412            6 :             warning_at (loc, 0, "accessing a member %qE of an atomic "
    3413              :                         "union %qE", component, datum);
    3414              :         }
    3415              : 
    3416              :       /* Chain the COMPONENT_REFs if necessary down to the FIELD.
    3417              :          This might be better solved in future the way the C++ front
    3418              :          end does it - by giving the anonymous entities each a
    3419              :          separate name and type, and then have build_component_ref
    3420              :          recursively call itself.  We can't do that here.  */
    3421      2283093 :       do
    3422              :         {
    3423      2283093 :           tree subdatum = TREE_VALUE (field);
    3424      2283093 :           int quals;
    3425      2283093 :           tree subtype;
    3426      2283093 :           bool use_datum_quals;
    3427              : 
    3428      2283093 :           if (TREE_TYPE (subdatum) == error_mark_node)
    3429              :             return error_mark_node;
    3430              : 
    3431              :           /* If this is an rvalue, it does not have qualifiers in C
    3432              :              standard terms and we must avoid propagating such
    3433              :              qualifiers down to a non-lvalue array that is then
    3434              :              converted to a pointer.  */
    3435      4566186 :           use_datum_quals = (datum_lvalue
    3436      2283093 :                              || TREE_CODE (TREE_TYPE (subdatum)) != ARRAY_TYPE);
    3437              : 
    3438      2283093 :           quals = TYPE_QUALS (strip_array_types (TREE_TYPE (subdatum)));
    3439      2283093 :           if (use_datum_quals)
    3440      2282831 :             quals |= TYPE_QUALS (TREE_TYPE (datum));
    3441      2283093 :           subtype = c_build_qualified_type (TREE_TYPE (subdatum), quals);
    3442              : 
    3443      2283093 :           ref = build3 (COMPONENT_REF, subtype, datum, subdatum,
    3444              :                         NULL_TREE);
    3445      2283093 :           SET_EXPR_LOCATION (ref, loc);
    3446              : 
    3447      2283093 :           check_counted_by_attribute (loc, ref);
    3448              : 
    3449      2283093 :           if (TREE_READONLY (subdatum)
    3450      2283093 :               || (use_datum_quals && TREE_READONLY (datum)))
    3451        30842 :             TREE_READONLY (ref) = 1;
    3452      2283093 :           if (TREE_THIS_VOLATILE (subdatum)
    3453      2282067 :               || (use_datum_quals && TREE_THIS_VOLATILE (datum)))
    3454         2476 :             TREE_THIS_VOLATILE (ref) = 1;
    3455              : 
    3456      2283093 :           if (TREE_UNAVAILABLE (subdatum))
    3457           10 :             error_unavailable_use (subdatum, NULL_TREE);
    3458      2283083 :           else if (TREE_DEPRECATED (subdatum))
    3459           16 :             warn_deprecated_use (subdatum, NULL_TREE);
    3460              : 
    3461      2283093 :           datum = ref;
    3462              : 
    3463      2283093 :           field = TREE_CHAIN (field);
    3464              :         }
    3465      2283093 :       while (field);
    3466              : 
    3467              :       return ref;
    3468              :     }
    3469           72 :   else if (should_suggest_deref_p (type))
    3470              :     {
    3471              :       /* Special-case the error message for "ptr.field" for the case
    3472              :          where the user has confused "." vs "->".  */
    3473            7 :       rich_location richloc (line_table, loc);
    3474            7 :       if (INDIRECT_REF_P (datum) && arrow_loc != UNKNOWN_LOCATION)
    3475              :         {
    3476            2 :           richloc.add_fixit_insert_before (arrow_loc, "(*");
    3477            2 :           richloc.add_fixit_insert_after (arrow_loc, ")");
    3478            2 :           error_at (&richloc,
    3479              :                     "%qE is a pointer to pointer; did you mean to dereference "
    3480              :                     "it before applying %<->%> to it?",
    3481            2 :                     TREE_OPERAND (datum, 0));
    3482              :         }
    3483              :       else
    3484              :         {
    3485              :           /* "loc" should be the "." token.  */
    3486            5 :           richloc.add_fixit_replace ("->");
    3487            5 :           error_at (&richloc,
    3488              :                     "%qE is a pointer; did you mean to use %<->%>?",
    3489              :                     datum);
    3490              :         }
    3491            7 :       return error_mark_node;
    3492            7 :     }
    3493           65 :   else if (code != ERROR_MARK)
    3494            1 :     error_at (loc,
    3495              :               "request for member %qE in something not a structure or union",
    3496              :               component);
    3497              : 
    3498           65 :   return error_mark_node;
    3499              : }
    3500              : 
    3501              : /* Given an expression PTR for a pointer, return an expression
    3502              :    for the value pointed to.
    3503              :    ERRORSTRING is the name of the operator to appear in error messages.
    3504              : 
    3505              :    LOC is the location to use for the generated tree.  */
    3506              : 
    3507              : tree
    3508      2769240 : build_indirect_ref (location_t loc, tree ptr, ref_operator errstring)
    3509              : {
    3510      2769240 :   tree pointer = default_conversion (ptr);
    3511      2769240 :   tree type = TREE_TYPE (pointer);
    3512      2769240 :   tree ref;
    3513              : 
    3514      2769240 :   if (TREE_CODE (type) == POINTER_TYPE)
    3515              :     {
    3516      2768886 :       if (CONVERT_EXPR_P (pointer)
    3517      1985266 :           || TREE_CODE (pointer) == VIEW_CONVERT_EXPR)
    3518              :         {
    3519              :           /* If a warning is issued, mark it to avoid duplicates from
    3520              :              the backend.  This only needs to be done at
    3521              :              warn_strict_aliasing > 2.  */
    3522       783620 :           if (warn_strict_aliasing > 2)
    3523       335156 :             if (strict_aliasing_warning (EXPR_LOCATION (pointer),
    3524       335156 :                                          type, TREE_OPERAND (pointer, 0)))
    3525            8 :               suppress_warning (pointer, OPT_Wstrict_aliasing_);
    3526              :         }
    3527              : 
    3528      2768886 :       if (TREE_CODE (pointer) == ADDR_EXPR
    3529      2768886 :           && (TREE_TYPE (TREE_OPERAND (pointer, 0))
    3530        67454 :               == TREE_TYPE (type)))
    3531              :         {
    3532        67445 :           ref = TREE_OPERAND (pointer, 0);
    3533        67445 :           protected_set_expr_location (ref, loc);
    3534        67445 :           return ref;
    3535              :         }
    3536              :       else
    3537              :         {
    3538      2701441 :           tree t = TREE_TYPE (type);
    3539              : 
    3540      2701441 :           ref = build1 (INDIRECT_REF, t, pointer);
    3541              : 
    3542      2701441 :           if (VOID_TYPE_P (t) && c_inhibit_evaluation_warnings == 0)
    3543          151 :             warning_at (loc, 0, "dereferencing %<void *%> pointer");
    3544              : 
    3545              :           /* We *must* set TREE_READONLY when dereferencing a pointer to const,
    3546              :              so that we get the proper error message if the result is used
    3547              :              to assign to.  Also, &* is supposed to be a no-op.
    3548              :              And ANSI C seems to specify that the type of the result
    3549              :              should be the const type.  */
    3550              :           /* A de-reference of a pointer to const is not a const.  It is valid
    3551              :              to change it via some other pointer.  */
    3552      2701441 :           TREE_READONLY (ref) = TYPE_READONLY (t);
    3553      2701441 :           TREE_SIDE_EFFECTS (ref)
    3554      2701441 :             = TYPE_VOLATILE (t) || TREE_SIDE_EFFECTS (pointer);
    3555      2701441 :           TREE_THIS_VOLATILE (ref) = TYPE_VOLATILE (t);
    3556      2701441 :           protected_set_expr_location (ref, loc);
    3557      2701441 :           return ref;
    3558              :         }
    3559              :     }
    3560          354 :   else if (TREE_CODE (pointer) != ERROR_MARK)
    3561          278 :     invalid_indirection_error (loc, type, errstring);
    3562              : 
    3563          354 :   return error_mark_node;
    3564              : }
    3565              : 
    3566              : /* This handles expressions of the form "a[i]", which denotes
    3567              :    an array reference.
    3568              : 
    3569              :    This is logically equivalent in C to *(a+i), but we may do it differently.
    3570              :    If A is a variable or a member, we generate a primitive ARRAY_REF.
    3571              :    This avoids forcing the array out of registers, and can work on
    3572              :    arrays that are not lvalues (for example, members of structures returned
    3573              :    by functions).
    3574              : 
    3575              :    For vector types, allow vector[i] but not i[vector], and create
    3576              :    *(((type*)&vectortype) + i) for the expression.
    3577              : 
    3578              :    LOC is the location to use for the returned expression.  */
    3579              : 
    3580              : tree
    3581      3495484 : build_array_ref (location_t loc, tree array, tree index)
    3582              : {
    3583      3495484 :   tree ret;
    3584      3495484 :   bool swapped = false;
    3585      3495484 :   if (TREE_TYPE (array) == error_mark_node
    3586      3495484 :       || TREE_TYPE (index) == error_mark_node)
    3587              :     return error_mark_node;
    3588              : 
    3589      3495376 :   if (TREE_CODE (TREE_TYPE (array)) != ARRAY_TYPE
    3590      2009561 :       && TREE_CODE (TREE_TYPE (array)) != POINTER_TYPE
    3591              :       /* Allow vector[index] but not index[vector].  */
    3592      4525239 :       && !gnu_vector_type_p (TREE_TYPE (array)))
    3593              :     {
    3594          194 :       if (TREE_CODE (TREE_TYPE (index)) != ARRAY_TYPE
    3595          194 :           && TREE_CODE (TREE_TYPE (index)) != POINTER_TYPE)
    3596              :         {
    3597            2 :           error_at (loc,
    3598              :             "subscripted value is neither array nor pointer nor vector");
    3599              : 
    3600            2 :           return error_mark_node;
    3601              :         }
    3602          192 :       std::swap (array, index);
    3603          192 :       swapped = true;
    3604              :     }
    3605              : 
    3606      3495374 :   if (!INTEGRAL_TYPE_P (TREE_TYPE (index)))
    3607              :     {
    3608            2 :       error_at (loc, "array subscript is not an integer");
    3609            2 :       return error_mark_node;
    3610              :     }
    3611              : 
    3612      3495372 :   if (TREE_CODE (TREE_TYPE (TREE_TYPE (array))) == FUNCTION_TYPE)
    3613              :     {
    3614           10 :       error_at (loc, "subscripted value is pointer to function");
    3615           10 :       return error_mark_node;
    3616              :     }
    3617              : 
    3618              :   /* ??? Existing practice has been to warn only when the char
    3619              :      index is syntactically the index, not for char[array].  */
    3620      3495362 :   if (!swapped)
    3621      3495176 :      warn_array_subscript_with_type_char (loc, index);
    3622              : 
    3623              :   /* Apply default promotions *after* noticing character types.  */
    3624      3495362 :   index = default_conversion (index);
    3625      3495362 :   if (index == error_mark_node)
    3626              :     return error_mark_node;
    3627              : 
    3628      3495361 :   gcc_assert (TREE_CODE (TREE_TYPE (index)) == INTEGER_TYPE
    3629              :               || TREE_CODE (TREE_TYPE (index)) == BITINT_TYPE);
    3630              : 
    3631      3495361 :   bool was_vector = VECTOR_TYPE_P (TREE_TYPE (array));
    3632      3495361 :   bool non_lvalue = convert_vector_to_array_for_subscript (loc, &array, index);
    3633              : 
    3634              :   /* We only generate a call to .ACCESS_WITH_SIZE when it is a read.  */
    3635      3495361 :   if (TREE_CODE (array) == COMPONENT_REF
    3636      3495361 :       && handle_counted_by_p (array))
    3637       816971 :     array = handle_counted_by_for_component_ref (loc, array);
    3638              : 
    3639      3495361 :   if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE)
    3640              :     {
    3641      2515491 :       tree rval, type;
    3642              : 
    3643              :       /* An array that is indexed by a non-constant
    3644              :          cannot be stored in a register; we must be able to do
    3645              :          address arithmetic on its address.
    3646              :          Likewise an array of elements of variable size.  */
    3647      2515491 :       if (TREE_CODE (index) != INTEGER_CST
    3648      2515491 :           || (COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (array)))
    3649      2033706 :               && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array)))) != INTEGER_CST))
    3650              :         {
    3651       482525 :           if (!c_mark_addressable (array, true, true))
    3652            1 :             return error_mark_node;
    3653              :         }
    3654              :       /* An array that is indexed by a constant value which is not within
    3655              :          the array bounds cannot be stored in a register either; because we
    3656              :          would get a crash in store_bit_field/extract_bit_field when trying
    3657              :          to access a non-existent part of the register.  */
    3658      2515490 :       if (TREE_CODE (index) == INTEGER_CST
    3659      2033706 :           && TYPE_DOMAIN (TREE_TYPE (array))
    3660      4545837 :           && !int_fits_type_p (index, TYPE_DOMAIN (TREE_TYPE (array))))
    3661              :         {
    3662        60657 :           if (!c_mark_addressable (array, false, true))
    3663            0 :             return error_mark_node;
    3664              :           /* ISO C2Y disallows a negative integer constant expression index
    3665              :              when array subscripting has an operand of array type.  */
    3666        60657 :           if (flag_isoc2y
    3667           26 :               && !TREE_OVERFLOW (index)
    3668        60680 :               && tree_int_cst_sgn (index) < 0)
    3669           10 :             error_at (loc, "array subscript is negative");
    3670              :         }
    3671              : 
    3672      2515490 :       if ((pedantic || warn_c90_c99_compat || warn_c23_c2y_compat)
    3673      2492009 :           && ! was_vector)
    3674              :         {
    3675      1485093 :           tree foo = array;
    3676      2321181 :           while (TREE_CODE (foo) == COMPONENT_REF)
    3677       836088 :             foo = TREE_OPERAND (foo, 0);
    3678       985116 :           if ((VAR_P (foo) && C_DECL_REGISTER (foo))
    3679      2470143 :               || (TREE_CODE (foo) == COMPOUND_LITERAL_EXPR
    3680           72 :                   && C_DECL_REGISTER (COMPOUND_LITERAL_EXPR_DECL (foo))))
    3681           78 :             pedwarn_c23 (loc, OPT_Wpedantic,
    3682              :                          "ISO C forbids subscripting %<register%> array "
    3683              :                          "before C2Y");
    3684      1485015 :           else if (!lvalue_p (foo))
    3685          118 :             pedwarn_c90 (loc, OPT_Wpedantic,
    3686              :                          "ISO C90 forbids subscripting non-lvalue "
    3687              :                          "array");
    3688              :         }
    3689              : 
    3690      2515490 :       if (TREE_CODE (TREE_TYPE (index)) == BITINT_TYPE
    3691      2515490 :           && TYPE_PRECISION (TREE_TYPE (index)) > TYPE_PRECISION (sizetype))
    3692            3 :         index = fold_convert (sizetype, index);
    3693              : 
    3694      2515490 :       type = TREE_TYPE (TREE_TYPE (array));
    3695      2515490 :       rval = build4 (ARRAY_REF, type, array, index, NULL_TREE, NULL_TREE);
    3696              :       /* Array ref is const/volatile if the array elements are
    3697              :          or if the array is.  */
    3698      7546470 :       TREE_READONLY (rval)
    3699      2515490 :         |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array)))
    3700      2515490 :             | TREE_READONLY (array));
    3701      7546470 :       TREE_SIDE_EFFECTS (rval)
    3702      2515490 :         |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
    3703      2515490 :             | TREE_SIDE_EFFECTS (array));
    3704      5030980 :       TREE_THIS_VOLATILE (rval)
    3705      2515490 :         |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
    3706              :             /* This was added by rms on 16 Nov 91.
    3707              :                It fixes  vol struct foo *a;  a->elts[1]
    3708              :                in an inline function.
    3709              :                Hope it doesn't break something else.  */
    3710      2515490 :             | TREE_THIS_VOLATILE (array));
    3711      2515490 :       ret = require_complete_type (loc, rval);
    3712      2515490 :       protected_set_expr_location (ret, loc);
    3713      2515490 :       if (non_lvalue)
    3714       105736 :         ret = non_lvalue_loc (loc, ret);
    3715              :       return ret;
    3716              :     }
    3717              :   else
    3718              :     {
    3719       979870 :       tree ar = default_conversion (array);
    3720              : 
    3721       979870 :       if (ar == error_mark_node)
    3722              :         return ar;
    3723              : 
    3724       979870 :       gcc_assert (TREE_CODE (TREE_TYPE (ar)) == POINTER_TYPE);
    3725       979870 :       gcc_assert (TREE_CODE (TREE_TYPE (TREE_TYPE (ar))) != FUNCTION_TYPE);
    3726              : 
    3727       979870 :       ret = build_indirect_ref (loc, build_binary_op (loc, PLUS_EXPR, ar,
    3728              :                                                       index, false),
    3729              :                                 RO_ARRAY_INDEXING);
    3730       979870 :       if (non_lvalue)
    3731            0 :         ret = non_lvalue_loc (loc, ret);
    3732              :       return ret;
    3733              :     }
    3734              : }
    3735              : 
    3736              : /* Build an OpenMP array section reference, creating an exact type for the
    3737              :    resulting expression based on the element type and bounds if possible.  If
    3738              :    we have variable bounds, create an incomplete array type for the result
    3739              :    instead.  */
    3740              : 
    3741              : tree
    3742         3984 : build_omp_array_section (location_t loc, tree array, tree index, tree length)
    3743              : {
    3744         3984 :   tree type = TREE_TYPE (array);
    3745         3984 :   gcc_assert (type);
    3746              : 
    3747         3984 :   tree sectype, eltype = TREE_TYPE (type);
    3748              : 
    3749              :   /* It's not an array or pointer type.  Just reuse the type of the original
    3750              :      expression as the type of the array section (an error will be raised
    3751              :      anyway, later).  */
    3752         3984 :   if (eltype == NULL_TREE || error_operand_p (eltype))
    3753           12 :     sectype = TREE_TYPE (array);
    3754              :   else
    3755              :     {
    3756         3972 :       tree idxtype = NULL_TREE;
    3757              : 
    3758         3972 :       if (index != NULL_TREE
    3759         3972 :           && length != NULL_TREE
    3760         3032 :           && INTEGRAL_TYPE_P (TREE_TYPE (index))
    3761         6999 :           && INTEGRAL_TYPE_P (TREE_TYPE (length)))
    3762              :         {
    3763         3020 :           tree low = fold_convert (sizetype, index);
    3764         3020 :           tree high = fold_convert (sizetype, length);
    3765         3020 :           high = size_binop (PLUS_EXPR, low, high);
    3766         3020 :           high = size_binop (MINUS_EXPR, high, size_one_node);
    3767         3020 :           idxtype = build_range_type (sizetype, low, high);
    3768              :         }
    3769          137 :       else if ((index == NULL_TREE || integer_zerop (index))
    3770          840 :                && length != NULL_TREE
    3771         1638 :                && INTEGRAL_TYPE_P (TREE_TYPE (length)))
    3772          669 :         idxtype = build_index_type (length);
    3773              : 
    3774         3972 :       gcc_assert (!error_operand_p (idxtype));
    3775              : 
    3776         3972 :       sectype = c_build_array_type (eltype, idxtype);
    3777              :     }
    3778              : 
    3779         3984 :   return build3_loc (loc, OMP_ARRAY_SECTION, sectype, array, index, length);
    3780              : }
    3781              : 
    3782              : 
    3783              : /* Record that REF is used.  This is relevant for undeclared static
    3784              :    function and declarations referenced from a non-local context.
    3785              :    ADDRESS indicates whether the address is taken.  */
    3786              : 
    3787              : void
    3788    489658590 : mark_decl_used (tree ref, bool address)
    3789              : {
    3790    489658590 :   if (!ref || !DECL_P (ref) || in_alignof)
    3791              :     return;
    3792              : 
    3793              :   /* Non-file-scope and non-local reference in nested function.  */
    3794    359128772 :   bool nonloc_p = current_function_decl && DECL_CONTEXT (ref)
    3795    125107248 :                   && DECL_CONTEXT (current_function_decl)
    3796    489624557 :                   && DECL_CONTEXT (ref) != current_function_decl;
    3797              : 
    3798              :   /* An undeclared static function.  */
    3799    489614453 :   bool static_p = TREE_CODE (ref) == FUNCTION_DECL
    3800    105485603 :                   && DECL_INITIAL (ref) == NULL_TREE
    3801     72095794 :                   && DECL_EXTERNAL (ref)
    3802    561707551 :                   && !TREE_PUBLIC (ref);
    3803              : 
    3804    489480731 :   if (!static_p && !nonloc_p)
    3805              :     return;
    3806              : 
    3807              :   /* If we may be in an unevaluated context, delay the decision.  */
    3808       136365 :   if (in_sizeof || in_typeof || in_countof || in_generic)
    3809          273 :     return record_maybe_used_decl (ref, address);
    3810              : 
    3811       136092 :   if (static_p)
    3812       133466 :     C_DECL_USED (ref) = 1;
    3813              : 
    3814       136092 :   if (nonloc_p && (VAR_OR_FUNCTION_DECL_P (ref)
    3815              :                    || TREE_CODE (ref) == PARM_DECL))
    3816         2061 :     DECL_NONLOCAL (ref) = 1;
    3817              : 
    3818              :   /* Nothing to do anymore.  */
    3819         2626 :   if (!nonloc_p || C_FUNC_NONLOCAL_CONTEXT (current_function_decl))
    3820              :     return;
    3821              : 
    3822              :   /* Filter out the cases where referencing a non-local variable does not
    3823              :      require a non-local context passed via the static chain.  */
    3824         1219 :   if (!c_type_variably_modified_p (TREE_TYPE (ref)))
    3825         1147 :     switch (TREE_CODE (ref))
    3826              :       {
    3827          219 :       case FUNCTION_DECL:
    3828              :         /* Use of another local function that requires no context is ok.  */
    3829          219 :         if (!C_FUNC_NONLOCAL_CONTEXT (ref) && DECL_INITIAL (ref))
    3830              :           return;
    3831              :         break;
    3832          440 :       case VAR_DECL:
    3833              :         /* Static variables and constexpr are ok, but for the later only
    3834              :            when the address is not taken.  */
    3835          440 :         if (TREE_STATIC (ref) || (C_DECL_DECLARED_CONSTEXPR (ref) && !address))
    3836              :           return;
    3837              :         break;
    3838              :       case TYPE_DECL:
    3839              :         /* A typedef is ok when not for a variably-modified type. */
    3840              :         return;
    3841              :       case CONST_DECL:
    3842              :         /* An enumeration constant is ok. */
    3843              :         return;
    3844              :       case PARM_DECL:
    3845              :         break;
    3846              :       case LABEL_DECL:
    3847              :         break;
    3848            0 :       default:
    3849            0 :         gcc_unreachable ();
    3850              :     }
    3851              : 
    3852              :   /* Mark all parent functions up to the nesting level of the variable as
    3853              :      as needing the non-local context.  */
    3854         2031 :   for (tree cont = current_function_decl; cont; cont = DECL_CONTEXT (cont))
    3855              :     {
    3856         2031 :       if (cont == DECL_CONTEXT (ref))
    3857              :         break;
    3858              : 
    3859              :       /* There should not be any other type of context used for function
    3860              :          except TRANSLATION_UNIT_DECL which we should be able to reach.  */
    3861         1021 :       gcc_checking_assert (TREE_CODE (cont) == FUNCTION_DECL);
    3862              : 
    3863         1021 :       if (TREE_CODE (cont) == FUNCTION_DECL)
    3864         1021 :         C_FUNC_NONLOCAL_CONTEXT (cont) = 1;
    3865              :     }
    3866              : }
    3867              : 
    3868              : 
    3869              : /* Build an external reference to identifier ID.  FUN indicates
    3870              :    whether this will be used for a function call.  LOC is the source
    3871              :    location of the identifier.  This sets *TYPE to the type of the
    3872              :    identifier, which is not the same as the type of the returned value
    3873              :    for CONST_DECLs defined as enum constants.  If the type of the
    3874              :    identifier is not available, *TYPE is set to NULL.  */
    3875              : tree
    3876    179675028 : build_external_ref (location_t loc, tree id, bool fun, tree *type)
    3877              : {
    3878    179675028 :   tree ref;
    3879    179675028 :   tree decl = lookup_name (id);
    3880              : 
    3881              :   /* In Objective-C, an instance variable (ivar) may be preferred to
    3882              :      whatever lookup_name() found.  */
    3883    179675028 :   decl = objc_lookup_ivar (decl, id);
    3884              : 
    3885    179675028 :   *type = NULL;
    3886    179675028 :   if (decl && decl != error_mark_node)
    3887              :     {
    3888    179668845 :       ref = decl;
    3889    179668845 :       *type = TREE_TYPE (ref);
    3890    179668845 :       if (DECL_P (decl) && C_DECL_UNDERSPECIFIED (decl))
    3891            4 :         error_at (loc, "underspecified %qD referenced in its initializer",
    3892              :                   decl);
    3893              :     }
    3894         6183 :   else if (fun)
    3895              :     /* Implicit function declaration.  */
    3896         4730 :     ref = implicitly_declare (loc, id);
    3897         1453 :   else if (decl == error_mark_node)
    3898              :     /* Don't complain about something that's already been
    3899              :        complained about.  */
    3900              :     return error_mark_node;
    3901              :   else
    3902              :     {
    3903         1218 :       undeclared_variable (loc, id);
    3904         1218 :       return error_mark_node;
    3905              :     }
    3906              : 
    3907              :   /* For an OpenMP map clause, we can get better diagnostics for decls with
    3908              :      unmappable types if we return the decl with an error_mark_node type,
    3909              :      rather than returning error_mark_node for the decl itself.  */
    3910    179673575 :   if (TREE_TYPE (ref) == error_mark_node
    3911    179673575 :       && !c_omp_array_section_p)
    3912              :     return error_mark_node;
    3913              : 
    3914    179673557 :   if (TREE_UNAVAILABLE (ref))
    3915           14 :     error_unavailable_use (ref, NULL_TREE);
    3916    179673543 :   else if (TREE_DEPRECATED (ref))
    3917          100 :     warn_deprecated_use (ref, NULL_TREE);
    3918              : 
    3919              :   /* Recursive call does not count as usage.  */
    3920    179673557 :   if (ref != current_function_decl)
    3921              :     {
    3922    179670863 :       TREE_USED (ref) = 1;
    3923              :     }
    3924              : 
    3925    179673557 :   mark_decl_used (ref, false);
    3926              : 
    3927    179673557 :   if (TREE_CODE (ref) == CONST_DECL)
    3928              :     {
    3929       419980 :       used_types_insert (TREE_TYPE (ref));
    3930              : 
    3931       419980 :       if (warn_cxx_compat
    3932          429 :           && TREE_CODE (TREE_TYPE (ref)) == ENUMERAL_TYPE
    3933       420407 :           && C_TYPE_DEFINED_IN_STRUCT (TREE_TYPE (ref)))
    3934              :         {
    3935            1 :           warning_at (loc, OPT_Wc___compat,
    3936              :                       "enum constant defined in struct or union "
    3937              :                       "is not visible in C++");
    3938            1 :           inform (DECL_SOURCE_LOCATION (ref), "enum constant defined here");
    3939              :         }
    3940              : 
    3941       419980 :       ref = DECL_INITIAL (ref);
    3942       419980 :       TREE_CONSTANT (ref) = 1;
    3943              :     }
    3944              :   /* C99 6.7.4p3: An inline definition of a function with external
    3945              :      linkage ... shall not contain a reference to an identifier with
    3946              :      internal linkage.  */
    3947    179253577 :   else if (current_function_decl != NULL_TREE
    3948    177738818 :            && DECL_DECLARED_INLINE_P (current_function_decl)
    3949    163923636 :            && DECL_EXTERNAL (current_function_decl)
    3950    163146920 :            && VAR_OR_FUNCTION_DECL_P (ref)
    3951     58322801 :            && (!VAR_P (ref) || TREE_STATIC (ref))
    3952     49118128 :            && ! TREE_PUBLIC (ref)
    3953    179253611 :            && DECL_CONTEXT (ref) != current_function_decl)
    3954           25 :     record_inline_static (loc, current_function_decl, ref,
    3955              :                           csi_internal);
    3956              : 
    3957              :   return ref;
    3958              : }
    3959              : 
    3960              : static struct maybe_used_decl *maybe_used_decls;
    3961              : 
    3962              : /* Record that DECL, a reference seen inside sizeof or typeof or _Countof or
    3963              :    _Generic, might be used if the operand of sizeof is a VLA type or the
    3964              :    operand of typeof is a variably modified type or the operand of _Countof has
    3965              :    a variable number of elements or the operand of _Generic is the one selected
    3966              :    as the result.  */
    3967              : 
    3968              : static void
    3969          273 : record_maybe_used_decl (tree decl, bool address)
    3970              : {
    3971          273 :   struct maybe_used_decl *t = XOBNEW (&parser_obstack, struct maybe_used_decl);
    3972          273 :   t->decl = decl;
    3973          273 :   t->level = in_sizeof + in_typeof + in_countof + in_generic;
    3974          273 :   t->address = address;
    3975          273 :   t->next = maybe_used_decls;
    3976          273 :   maybe_used_decls = t;
    3977          273 : }
    3978              : 
    3979              : /* Pop the stack of decls possibly used inside sizeof or typeof or _Countof or
    3980              :    _Generic.  If USED is false, just discard them.  If it is true, mark them
    3981              :    used (if no longer inside sizeof or typeof or _Countof or _Generic) or move
    3982              :    them to the next level up (if still inside sizeof or typeof or _Countof or
    3983              :    _Generic).  */
    3984              : 
    3985              : void
    3986      1472353 : pop_maybe_used (bool used)
    3987              : {
    3988      1472353 :   struct maybe_used_decl *p = maybe_used_decls;
    3989      1472353 :   int cur_level = in_sizeof + in_typeof + in_countof + in_generic;
    3990      1472650 :   while (p && p->level > cur_level)
    3991              :     {
    3992          297 :       if (used)
    3993              :         {
    3994           77 :           if (cur_level == 0)
    3995           53 :             mark_decl_used (p->decl, p->address);
    3996              :           else
    3997           24 :             p->level = cur_level;
    3998              :         }
    3999          297 :       p = p->next;
    4000              :     }
    4001      1472353 :   if (!used || cur_level == 0)
    4002      1472272 :     maybe_used_decls = p;
    4003      1472353 : }
    4004              : 
    4005              : /* Pop the stack of decls possibly used inside sizeof or typeof or _Countof or
    4006              :    _Generic, without acting on them, and return the pointer to the previous top
    4007              :    of the stack.  This for use at the end of a default generic association when
    4008              :    it is not yet known whether the expression is used.  If it later turns out
    4009              :    the expression is used (or treated as used before C23), restore_maybe_used
    4010              :    should be called on the return value followed by pop_maybe_used (true);
    4011              :    otherwise, the return value can be discarded.  */
    4012              : 
    4013              : struct maybe_used_decl *
    4014         1208 : save_maybe_used ()
    4015              : {
    4016         1208 :   struct maybe_used_decl *p = maybe_used_decls, *orig = p;
    4017         1208 :   int cur_level = in_sizeof + in_typeof + in_countof + in_generic;
    4018         1240 :   while (p && p->level > cur_level)
    4019           32 :     p = p->next;
    4020         1208 :   maybe_used_decls = p;
    4021         1208 :   return orig;
    4022              : }
    4023              : 
    4024              : /* Restore the stack of decls possibly used inside sizeof or typeof or _Countof
    4025              :    or _Generic returned by save_maybe_used.  It is required that the stack is
    4026              :    at exactly the point where it was left by save_maybe_used.  */
    4027              : 
    4028              : void
    4029          277 : restore_maybe_used (struct maybe_used_decl *stack)
    4030              : {
    4031          277 :   maybe_used_decls = stack;
    4032          277 : }
    4033              : 
    4034              : /* Return the result of sizeof applied to EXPR.  */
    4035              : 
    4036              : struct c_expr
    4037       313979 : c_expr_sizeof_expr (location_t loc, struct c_expr expr)
    4038              : {
    4039       313979 :   struct c_expr ret;
    4040       313979 :   if (expr.value == error_mark_node)
    4041              :     {
    4042          111 :       ret.value = error_mark_node;
    4043          111 :       ret.original_code = ERROR_MARK;
    4044          111 :       ret.original_type = NULL;
    4045          111 :       ret.m_decimal = 0;
    4046          111 :       pop_maybe_used (false);
    4047              :     }
    4048              :   else
    4049              :     {
    4050       313868 :       bool expr_const_operands = true;
    4051              : 
    4052       313868 :       if (TREE_CODE (expr.value) == PARM_DECL
    4053       313868 :           && C_ARRAY_PARAMETER (expr.value))
    4054              :         {
    4055           55 :           auto_diagnostic_group d;
    4056           55 :           if (warning_at (loc, OPT_Wsizeof_array_argument,
    4057              :                           "%<sizeof%> on array function parameter %qE will "
    4058              :                           "return size of %qT", expr.value,
    4059           55 :                           TREE_TYPE (expr.value)))
    4060           19 :             inform (DECL_SOURCE_LOCATION (expr.value), "declared here");
    4061           55 :         }
    4062       313868 :       tree folded_expr = c_fully_fold (expr.value, require_constant_value,
    4063              :                                        &expr_const_operands);
    4064       313868 :       ret.value = c_sizeof (loc, TREE_TYPE (folded_expr));
    4065       313868 :       c_last_sizeof_arg = expr.value;
    4066       313868 :       c_last_sizeof_loc = loc;
    4067       313868 :       ret.original_code = SIZEOF_EXPR;
    4068       313868 :       ret.original_type = NULL;
    4069       313868 :       ret.m_decimal = 0;
    4070       313868 :       if (C_TYPE_VARIABLE_SIZE (TREE_TYPE (folded_expr)))
    4071              :         {
    4072              :           /* sizeof is evaluated when given a vla (C99 6.5.3.4p2).  */
    4073          292 :           ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
    4074              :                               folded_expr, ret.value);
    4075          292 :           C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !expr_const_operands;
    4076          292 :           SET_EXPR_LOCATION (ret.value, loc);
    4077              :         }
    4078       313868 :       pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (folded_expr)));
    4079              :     }
    4080       313979 :   return ret;
    4081              : }
    4082              : 
    4083              : /* Return the result of sizeof applied to T, a structure for the type
    4084              :    name passed to sizeof (rather than the type itself).  LOC is the
    4085              :    location of the original expression.  */
    4086              : 
    4087              : struct c_expr
    4088       332678 : c_expr_sizeof_type (location_t loc, struct c_type_name *t)
    4089              : {
    4090       332678 :   tree type;
    4091       332678 :   struct c_expr ret;
    4092       332678 :   tree type_expr = NULL_TREE;
    4093       332678 :   bool type_expr_const = true;
    4094       332678 :   type = groktypename (t, &type_expr, &type_expr_const);
    4095       332678 :   ret.value = c_sizeof (loc, type);
    4096       332678 :   c_last_sizeof_arg = type;
    4097       332678 :   c_last_sizeof_loc = loc;
    4098       332678 :   ret.original_code = SIZEOF_EXPR;
    4099       332678 :   ret.original_type = NULL;
    4100       332678 :   ret.m_decimal = 0;
    4101       332678 :   if (type == error_mark_node)
    4102              :     {
    4103            5 :       ret.value = error_mark_node;
    4104            5 :       ret.original_code = ERROR_MARK;
    4105              :     }
    4106              :   else
    4107       332631 :   if ((type_expr || TREE_CODE (ret.value) == INTEGER_CST)
    4108       665219 :       && C_TYPE_VARIABLE_SIZE (type))
    4109              :     {
    4110              :       /* If the type is a [*] array, it is a VLA but is represented as
    4111              :          having a size of zero.  In such a case we must ensure that
    4112              :          the result of sizeof does not get folded to a constant by
    4113              :          c_fully_fold, because if the size is evaluated the result is
    4114              :          not constant and so constraints on zero or negative size
    4115              :          arrays must not be applied when this sizeof call is inside
    4116              :          another array declarator.  */
    4117           41 :       if (!type_expr)
    4118           16 :         type_expr = integer_zero_node;
    4119           41 :       ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
    4120              :                           type_expr, ret.value);
    4121           41 :       C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !type_expr_const;
    4122              :     }
    4123       332678 :   pop_maybe_used (type != error_mark_node
    4124       332678 :                   ? C_TYPE_VARIABLE_SIZE (type) : false);
    4125       332678 :   return ret;
    4126              : }
    4127              : 
    4128              : static bool
    4129      2161245 : top_array_vla_p (const_tree type)
    4130              : {
    4131      2161245 :   if (TREE_CODE (type) != ARRAY_TYPE)
    4132              :     return false;
    4133              : 
    4134      2161227 :   tree d = TYPE_DOMAIN (type);
    4135              : 
    4136      2161227 :   if (!d)
    4137              :     return false;
    4138      2067336 :   if (!TYPE_MAX_VALUE (d))
    4139              :     return false;
    4140              : 
    4141      1974989 :   return TREE_CODE (TYPE_MAX_VALUE (d)) != INTEGER_CST
    4142      1974989 :          || TREE_CODE (TYPE_MIN_VALUE (d)) != INTEGER_CST;
    4143              : }
    4144              : 
    4145              : /* Return the result of countof applied to EXPR.  */
    4146              : 
    4147              : struct c_expr
    4148           54 : c_expr_countof_expr (location_t loc, struct c_expr expr)
    4149              : {
    4150           54 :   struct c_expr ret;
    4151           54 :   if (expr.value == error_mark_node)
    4152              :     {
    4153            1 :       ret.value = error_mark_node;
    4154            1 :       ret.original_code = ERROR_MARK;
    4155            1 :       ret.original_type = NULL;
    4156            1 :       ret.m_decimal = 0;
    4157            1 :       pop_maybe_used (false);
    4158              :     }
    4159              :   else
    4160              :     {
    4161           53 :       bool expr_const_operands = true;
    4162              : 
    4163           53 :       tree folded_expr = c_fully_fold (expr.value, require_constant_value,
    4164              :                                        &expr_const_operands);
    4165           53 :       ret.value = c_countof_type (loc, TREE_TYPE (folded_expr));
    4166           53 :       c_last_sizeof_arg = expr.value;
    4167           53 :       c_last_sizeof_loc = loc;
    4168           53 :       ret.original_code = COUNTOF_EXPR;
    4169           53 :       ret.original_type = NULL;
    4170           53 :       ret.m_decimal = 0;
    4171           53 :       if (top_array_vla_p (TREE_TYPE (folded_expr)))
    4172              :         {
    4173              :           /* countof is evaluated when given a vla.  */
    4174           11 :           ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
    4175              :                               folded_expr, ret.value);
    4176           11 :           C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !expr_const_operands;
    4177           11 :           SET_EXPR_LOCATION (ret.value, loc);
    4178              :         }
    4179           53 :       pop_maybe_used (top_array_vla_p (TREE_TYPE (folded_expr)));
    4180              :     }
    4181           54 :   return ret;
    4182              : }
    4183              : 
    4184              : /* Return the result of countof applied to T, a structure for the type
    4185              :    name passed to countof (rather than the type itself).  LOC is the
    4186              :    location of the original expression.  */
    4187              : 
    4188              : struct c_expr
    4189           18 : c_expr_countof_type (location_t loc, struct c_type_name *t)
    4190              : {
    4191           18 :   tree type;
    4192           18 :   struct c_expr ret;
    4193           18 :   tree type_expr = NULL_TREE;
    4194           18 :   bool type_expr_const = true;
    4195           18 :   type = groktypename (t, &type_expr, &type_expr_const);
    4196           18 :   ret.value = c_countof_type (loc, type);
    4197           18 :   c_last_sizeof_arg = type;
    4198           18 :   c_last_sizeof_loc = loc;
    4199           18 :   ret.original_code = COUNTOF_EXPR;
    4200           18 :   ret.original_type = NULL;
    4201           18 :   ret.m_decimal = 0;
    4202           18 :   if (type == error_mark_node)
    4203              :     {
    4204            0 :       ret.value = error_mark_node;
    4205            0 :       ret.original_code = ERROR_MARK;
    4206              :     }
    4207              :   else
    4208            8 :   if ((type_expr || TREE_CODE (ret.value) == INTEGER_CST)
    4209           22 :       && top_array_vla_p (type))
    4210              :     {
    4211              :       /* If the type is a [*] array, it is a VLA but is represented as
    4212              :          having a size of zero.  In such a case we must ensure that
    4213              :          the result of countof does not get folded to a constant by
    4214              :          c_fully_fold, because if the number of elements is evaluated
    4215              :          the result is not constant and so
    4216              :          constraints on zero or negative size arrays must not be applied
    4217              :          when this countof call is inside another array declarator.  */
    4218            6 :       if (!type_expr)
    4219            0 :         type_expr = integer_zero_node;
    4220            6 :       ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
    4221              :                           type_expr, ret.value);
    4222            6 :       C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !type_expr_const;
    4223              :     }
    4224           18 :   pop_maybe_used (type != error_mark_node ? top_array_vla_p (type) : false);
    4225           18 :   return ret;
    4226              : }
    4227              : 
    4228              : /* Return the result of maxof applied to T, a structure for the type
    4229              :    name passed to maxof (rather than the type itself).  LOC is the
    4230              :    location of the original expression.  */
    4231              : 
    4232              : struct c_expr
    4233           46 : c_expr_maxof_type (location_t loc, struct c_type_name *t)
    4234              : {
    4235           46 :   tree type;
    4236           46 :   struct c_expr ret;
    4237           46 :   tree type_expr = NULL_TREE;
    4238           46 :   bool type_expr_const = true;
    4239           46 :   type = groktypename (t, &type_expr, &type_expr_const);
    4240           46 :   ret.value = c_maxof_type (loc, type);
    4241           46 :   c_last_sizeof_arg = type;
    4242           46 :   c_last_sizeof_loc = loc;
    4243           46 :   ret.original_code = MAXOF_EXPR;
    4244           46 :   ret.original_type = NULL;
    4245           46 :   ret.m_decimal = 0;
    4246           46 :   if (type == error_mark_node)
    4247              :     {
    4248            0 :       ret.value = error_mark_node;
    4249            0 :       ret.original_code = ERROR_MARK;
    4250              :     }
    4251           46 :   pop_maybe_used (type != error_mark_node);
    4252           46 :   return ret;
    4253              : }
    4254              : 
    4255              : /* Return the result of minof applied to T, a structure for the type
    4256              :    name passed to minof (rather than the type itself).  LOC is the
    4257              :    location of the original expression.  */
    4258              : 
    4259              : struct c_expr
    4260           46 : c_expr_minof_type (location_t loc, struct c_type_name *t)
    4261              : {
    4262           46 :   tree type;
    4263           46 :   struct c_expr ret;
    4264           46 :   tree type_expr = NULL_TREE;
    4265           46 :   bool type_expr_const = true;
    4266           46 :   type = groktypename (t, &type_expr, &type_expr_const);
    4267           46 :   ret.value = c_minof_type (loc, type);
    4268           46 :   c_last_sizeof_arg = type;
    4269           46 :   c_last_sizeof_loc = loc;
    4270           46 :   ret.original_code = MINOF_EXPR;
    4271           46 :   ret.original_type = NULL;
    4272           46 :   ret.m_decimal = 0;
    4273           46 :   if (type == error_mark_node)
    4274              :     {
    4275            0 :       ret.value = error_mark_node;
    4276            0 :       ret.original_code = ERROR_MARK;
    4277              :     }
    4278           46 :   pop_maybe_used (type != error_mark_node);
    4279           46 :   return ret;
    4280              : }
    4281              : 
    4282              : /* Build a function call to function FUNCTION with parameters PARAMS.
    4283              :    The function call is at LOC.
    4284              :    PARAMS is a list--a chain of TREE_LIST nodes--in which the
    4285              :    TREE_VALUE of each node is a parameter-expression.
    4286              :    FUNCTION's data type may be a function type or a pointer-to-function.  */
    4287              : 
    4288              : tree
    4289            0 : build_function_call (location_t loc, tree function, tree params)
    4290              : {
    4291            0 :   vec<tree, va_gc> *v;
    4292            0 :   tree ret;
    4293              : 
    4294            0 :   vec_alloc (v, list_length (params));
    4295            0 :   for (; params; params = TREE_CHAIN (params))
    4296            0 :     v->quick_push (TREE_VALUE (params));
    4297            0 :   ret = c_build_function_call_vec (loc, vNULL, function, v, NULL);
    4298            0 :   vec_free (v);
    4299            0 :   return ret;
    4300              : }
    4301              : 
    4302              : /* Give a note about the location of the declaration of DECL,
    4303              :    or, failing that, a pertinent declaration for FUNCTION_EXPR.  */
    4304              : 
    4305              : static void
    4306          299 : inform_declaration (tree decl, tree function_expr)
    4307              : {
    4308          299 :   if (decl && (TREE_CODE (decl) != FUNCTION_DECL
    4309          278 :                || !DECL_IS_UNDECLARED_BUILTIN (decl)))
    4310          207 :     inform (DECL_SOURCE_LOCATION (decl), "declared here");
    4311           92 :   else if (function_expr)
    4312           92 :     switch (TREE_CODE (function_expr))
    4313              :       {
    4314              :       default:
    4315              :         break;
    4316           13 :       case COMPONENT_REF:
    4317              :         /* Show the decl of the pertinent field (e.g. for callback
    4318              :            fields in a struct.  */
    4319           13 :         {
    4320           13 :           tree field_decl = TREE_OPERAND (function_expr, 1);
    4321           13 :           if (location_t loc = DECL_SOURCE_LOCATION (field_decl))
    4322           13 :             inform (loc, "declared here");
    4323              :         }
    4324              :         break;
    4325              :       }
    4326          299 : }
    4327              : 
    4328              : 
    4329              : /* Build a function call to function FUNCTION with parameters PARAMS.
    4330              :    If FUNCTION is the result of resolving an overloaded target built-in,
    4331              :    ORIG_FUNDECL is the original function decl, otherwise it is null.
    4332              :    ORIGTYPES, if not NULL, is a vector of types; each element is
    4333              :    either NULL or the original type of the corresponding element in
    4334              :    PARAMS.  The original type may differ from TREE_TYPE of the
    4335              :    parameter for enums.  FUNCTION's data type may be a function type
    4336              :    or pointer-to-function.  This function changes the elements of
    4337              :    PARAMS.  */
    4338              : 
    4339              : tree
    4340     51681996 : build_function_call_vec (location_t loc, vec<location_t> arg_loc,
    4341              :                          tree function, vec<tree, va_gc> *params,
    4342              :                          vec<tree, va_gc> *origtypes, tree orig_fundecl)
    4343              : {
    4344     51681996 :   tree fntype, fundecl = NULL_TREE;
    4345     51681996 :   tree name = NULL_TREE, result;
    4346     51681996 :   tree tem;
    4347     51681996 :   int nargs;
    4348     51681996 :   tree *argarray;
    4349              : 
    4350              : 
    4351              :   /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
    4352     51681996 :   STRIP_TYPE_NOPS (function);
    4353              : 
    4354              :   /* Convert anything with function type to a pointer-to-function.  */
    4355     51681996 :   if (TREE_CODE (function) == FUNCTION_DECL)
    4356              :     {
    4357     51604292 :       name = DECL_NAME (function);
    4358              : 
    4359     51604292 :       if (flag_tm)
    4360          421 :         tm_malloc_replacement (function);
    4361     51604292 :       fundecl = function;
    4362     51604292 :       if (!orig_fundecl)
    4363     51604292 :         orig_fundecl = fundecl;
    4364              :       /* Atomic functions have type checking/casting already done.  They are
    4365              :          often rewritten and don't match the original parameter list.  */
    4366    103208584 :       if (name && startswith (IDENTIFIER_POINTER (name), "__atomic_"))
    4367              :         origtypes = NULL;
    4368              :     }
    4369     51681996 :   if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE)
    4370     51618903 :     function = function_to_pointer_conversion (loc, function);
    4371              : 
    4372              :   /* For Objective-C, convert any calls via a cast to OBJC_TYPE_REF
    4373              :      expressions, like those used for ObjC messenger dispatches.  */
    4374     51681996 :   if (params && !params->is_empty ())
    4375     39379375 :     function = objc_rewrite_function_call (function, (*params)[0]);
    4376              : 
    4377     51681996 :   function = c_fully_fold (function, false, NULL);
    4378              : 
    4379     51681996 :   fntype = TREE_TYPE (function);
    4380              : 
    4381     51681996 :   if (TREE_CODE (fntype) == ERROR_MARK)
    4382            5 :     return error_mark_node;
    4383              : 
    4384     51681991 :   if (!(TREE_CODE (fntype) == POINTER_TYPE
    4385     51681957 :         && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE))
    4386              :     {
    4387           37 :       if (!flag_diagnostics_show_caret && !STATEMENT_CLASS_P (function))
    4388           33 :         error_at (loc,
    4389              :                   "called object %qE is not a function or function pointer",
    4390              :                   function);
    4391            4 :       else if (DECL_P (function))
    4392              :         {
    4393            1 :           auto_diagnostic_group d;
    4394            1 :           error_at (loc,
    4395              :                     "called object %qD is not a function or function pointer",
    4396              :                     function);
    4397            1 :           inform_declaration (function, NULL_TREE);
    4398            1 :         }
    4399              :       else
    4400            3 :         error_at (loc,
    4401              :                   "called object is not a function or function pointer");
    4402           37 :       return error_mark_node;
    4403              :     }
    4404              : 
    4405     51681954 :   if (fundecl && TREE_THIS_VOLATILE (fundecl))
    4406       384250 :     current_function_returns_abnormally = 1;
    4407              : 
    4408              :   /* fntype now gets the type of function pointed to.  */
    4409     51681954 :   fntype = TREE_TYPE (fntype);
    4410     51681954 :   tree return_type = TREE_TYPE (fntype);
    4411              : 
    4412              :   /* Convert the parameters to the types declared in the
    4413              :      function prototype, or apply default promotions.  */
    4414              : 
    4415     51681954 :   nargs = convert_arguments (loc, arg_loc, fntype, params,
    4416              :                              origtypes, function, fundecl);
    4417     51681954 :   if (nargs < 0)
    4418          179 :     return error_mark_node;
    4419              : 
    4420              :   /* Check that the function is called through a compatible prototype.
    4421              :      If it is not, warn.  */
    4422     51680860 :   if (CONVERT_EXPR_P (function)
    4423          931 :       && TREE_CODE (tem = TREE_OPERAND (function, 0)) == ADDR_EXPR
    4424          215 :       && TREE_CODE (tem = TREE_OPERAND (tem, 0)) == FUNCTION_DECL
    4425     51681960 :       && !comptypes (fntype, TREE_TYPE (tem)))
    4426              :     {
    4427              :       /* This situation leads to run-time undefined behavior.  We can't,
    4428              :          therefore, simply error unless we can prove that all possible
    4429              :          executions of the program must execute the code.  */
    4430           20 :       warning_at (loc, 0, "function called through a non-compatible type");
    4431              : 
    4432           20 :       if (VOID_TYPE_P (return_type)
    4433           20 :           && TYPE_QUALS (return_type) != TYPE_UNQUALIFIED)
    4434            1 :         pedwarn (loc, 0,
    4435              :                  "function with qualified void return type called");
    4436              :      }
    4437              : 
    4438     51681775 :   argarray = vec_safe_address (params);
    4439              : 
    4440              :   /* Check that arguments to builtin functions match the expectations.  */
    4441     51681775 :   if (fundecl
    4442     51604128 :       && fndecl_built_in_p (fundecl)
    4443     86110924 :       && !check_builtin_function_arguments (loc, arg_loc, fundecl,
    4444              :                                             orig_fundecl, nargs, argarray))
    4445          338 :     return error_mark_node;
    4446              : 
    4447              :   /* Check that the arguments to the function are valid.  */
    4448     51681437 :   bool warned_p = check_function_arguments (loc, fundecl, fntype,
    4449              :                                             nargs, argarray, &arg_loc,
    4450              :                                             comptypes);
    4451              : 
    4452     51681437 :   if (TYPE_QUALS (return_type) != TYPE_UNQUALIFIED
    4453     51681437 :       && !VOID_TYPE_P (return_type))
    4454           11 :     return_type = c_build_qualified_type (return_type, TYPE_UNQUALIFIED);
    4455     51681437 :   if (name != NULL_TREE
    4456    103285227 :       && startswith (IDENTIFIER_POINTER (name), "__builtin_"))
    4457              :     {
    4458     33696975 :       if (require_constant_value)
    4459         3464 :         result
    4460         3464 :           = fold_build_call_array_initializer_loc (loc, return_type,
    4461              :                                                    function, nargs, argarray);
    4462              :       else
    4463     33693511 :         result = fold_build_call_array_loc (loc, return_type,
    4464              :                                             function, nargs, argarray);
    4465     33696975 :       if (TREE_CODE (result) == NOP_EXPR
    4466     33696975 :           && TREE_CODE (TREE_OPERAND (result, 0)) == INTEGER_CST)
    4467        26554 :         STRIP_TYPE_NOPS (result);
    4468              :     }
    4469              :   else
    4470     17984462 :     result = build_call_array_loc (loc, return_type,
    4471              :                                    function, nargs, argarray);
    4472              :   /* If -Wnonnull warning has been diagnosed, avoid diagnosing it again
    4473              :      later.  */
    4474     51681437 :   if (warned_p && TREE_CODE (result) == CALL_EXPR)
    4475          215 :     suppress_warning (result, OPT_Wnonnull);
    4476              : 
    4477              :   /* In this improbable scenario, a nested function returns a VM type.
    4478              :      Create a TARGET_EXPR so that the call always has a LHS, much as
    4479              :      what the C++ FE does for functions returning non-PODs.  */
    4480     51681437 :   if (c_type_variably_modified_p (TREE_TYPE (fntype)))
    4481              :     {
    4482           83 :       tree tmp = create_tmp_var_raw (TREE_TYPE (fntype));
    4483           83 :       result = build4 (TARGET_EXPR, TREE_TYPE (fntype), tmp, result,
    4484              :                        NULL_TREE, NULL_TREE);
    4485              :     }
    4486              : 
    4487     51681437 :   if (VOID_TYPE_P (TREE_TYPE (result)))
    4488              :     {
    4489      2507474 :       if (TYPE_QUALS (TREE_TYPE (result)) != TYPE_UNQUALIFIED)
    4490            2 :         pedwarn (loc, 0,
    4491              :                  "function with qualified void return type called");
    4492              :       return result;
    4493              :     }
    4494     49173963 :   return require_complete_type (loc, result);
    4495              : }
    4496              : 
    4497              : /* Like build_function_call_vec, but call also resolve_overloaded_builtin.  */
    4498              : 
    4499              : tree
    4500     51681552 : c_build_function_call_vec (location_t loc, const vec<location_t> &arg_loc,
    4501              :                            tree function, vec<tree, va_gc> *params,
    4502              :                            vec<tree, va_gc> *origtypes)
    4503              : {
    4504              :   /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
    4505     51681563 :   STRIP_TYPE_NOPS (function);
    4506              : 
    4507              :   /* Convert anything with function type to a pointer-to-function.  */
    4508     51681552 :   if (TREE_CODE (function) == FUNCTION_DECL)
    4509              :     {
    4510              :       /* Implement type-directed function overloading for builtins.
    4511              :          resolve_overloaded_builtin and targetm.resolve_overloaded_builtin
    4512              :          handle all the type checking.  The result is a complete expression
    4513              :          that implements this function call.  */
    4514     51603848 :       tree tem = resolve_overloaded_builtin (loc, function, params);
    4515     51603848 :       if (tem)
    4516              :         return tem;
    4517              :     }
    4518     51595309 :   return build_function_call_vec (loc, arg_loc, function, params, origtypes);
    4519              : }
    4520              : 
    4521              : /* Helper for convert_arguments called to convert the VALue of argument
    4522              :    number ARGNUM from ORIGTYPE to the corresponding parameter number
    4523              :    PARMNUM and TYPE.
    4524              :    PLOC is the location where the conversion is being performed.
    4525              :    FUNCTION and FUNDECL are the same as in convert_arguments.
    4526              :    VALTYPE is the original type of VAL before the conversion and,
    4527              :    for EXCESS_PRECISION_EXPR, the operand of the expression.
    4528              :    NPC is true if VAL represents the null pointer constant (VAL itself
    4529              :    will have been folded to an integer constant).
    4530              :    RNAME is the same as FUNCTION except in Objective C when it's
    4531              :    the function selector.
    4532              :    EXCESS_PRECISION is true when VAL was originally represented
    4533              :    as EXCESS_PRECISION_EXPR.
    4534              :    WARNOPT is the same as in convert_for_assignment.  */
    4535              : 
    4536              : static tree
    4537    129279952 : convert_argument (location_t ploc, tree function, tree fundecl,
    4538              :                   tree type, tree origtype, tree val, tree valtype,
    4539              :                   bool npc, tree rname, int parmnum, int argnum,
    4540              :                   bool excess_precision, int warnopt)
    4541              : {
    4542              :   /* Formal parm type is specified by a function prototype.  */
    4543              : 
    4544    129279952 :   if (type == error_mark_node || !COMPLETE_TYPE_P (type))
    4545              :     {
    4546            3 :       error_at (ploc, "type of formal parameter %d is incomplete",
    4547              :                 parmnum + 1);
    4548            3 :       return error_mark_node;
    4549              :     }
    4550              : 
    4551              :   /* Optionally warn about conversions that differ from the default
    4552              :      conversions.  */
    4553    129279949 :   if (warn_traditional_conversion || warn_traditional)
    4554              :     {
    4555          193 :       if (INTEGRAL_TYPE_P (type)
    4556          107 :           && SCALAR_FLOAT_TYPE_P (valtype))
    4557           19 :         warning_at (ploc, OPT_Wtraditional_conversion,
    4558              :                     "passing argument %d of %qE as integer rather "
    4559              :                     "than floating due to prototype",
    4560              :                     argnum, rname);
    4561          193 :       if (INTEGRAL_TYPE_P (type)
    4562          107 :           && TREE_CODE (valtype) == COMPLEX_TYPE)
    4563            5 :         warning_at (ploc, OPT_Wtraditional_conversion,
    4564              :                     "passing argument %d of %qE as integer rather "
    4565              :                     "than complex due to prototype",
    4566              :                     argnum, rname);
    4567          188 :       else if (TREE_CODE (type) == COMPLEX_TYPE
    4568           14 :                && SCALAR_FLOAT_TYPE_P (valtype))
    4569            7 :         warning_at (ploc, OPT_Wtraditional_conversion,
    4570              :                     "passing argument %d of %qE as complex rather "
    4571              :                     "than floating due to prototype",
    4572              :                     argnum, rname);
    4573          181 :       else if (SCALAR_FLOAT_TYPE_P (type)
    4574           71 :                && INTEGRAL_TYPE_P (valtype))
    4575           19 :         warning_at (ploc, OPT_Wtraditional_conversion,
    4576              :                     "passing argument %d of %qE as floating rather "
    4577              :                     "than integer due to prototype",
    4578              :                     argnum, rname);
    4579          162 :       else if (TREE_CODE (type) == COMPLEX_TYPE
    4580            7 :                && INTEGRAL_TYPE_P (valtype))
    4581            5 :         warning_at (ploc, OPT_Wtraditional_conversion,
    4582              :                     "passing argument %d of %qE as complex rather "
    4583              :                     "than integer due to prototype",
    4584              :                     argnum, rname);
    4585          157 :       else if (SCALAR_FLOAT_TYPE_P (type)
    4586           52 :                && TREE_CODE (valtype) == COMPLEX_TYPE)
    4587            7 :         warning_at (ploc, OPT_Wtraditional_conversion,
    4588              :                     "passing argument %d of %qE as floating rather "
    4589              :                     "than complex due to prototype",
    4590              :                     argnum, rname);
    4591              :       /* ??? At some point, messages should be written about
    4592              :          conversions between complex types, but that's too messy
    4593              :          to do now.  */
    4594          150 :       else if (SCALAR_FLOAT_TYPE_P (type)
    4595           45 :                && SCALAR_FLOAT_TYPE_P (valtype))
    4596              :         {
    4597           45 :           unsigned int formal_prec = TYPE_PRECISION (type);
    4598              : 
    4599              :           /* Warn if any argument is passed as `float',
    4600              :              since without a prototype it would be `double'.  */
    4601           45 :           if (formal_prec == TYPE_PRECISION (float_type_node)
    4602           45 :               && type != dfloat32_type_node)
    4603            7 :             warning_at (ploc, 0,
    4604              :                         "passing argument %d of %qE as %<float%> "
    4605              :                         "rather than %<double%> due to prototype",
    4606              :                         argnum, rname);
    4607              : 
    4608              :           /* Warn if mismatch between argument and prototype
    4609              :              for decimal float types.  Warn of conversions with
    4610              :              binary float types and of precision narrowing due to
    4611              :              prototype.  */
    4612           38 :           else if (type != valtype
    4613           32 :                    && (type == dfloat32_type_node
    4614           22 :                        || type == dfloat64_type_node
    4615           12 :                        || type == dfloat128_type_node
    4616            2 :                        || valtype == dfloat32_type_node
    4617            2 :                        || valtype == dfloat64_type_node
    4618            2 :                        || valtype == dfloat128_type_node)
    4619           38 :                    && (formal_prec
    4620           30 :                        <= TYPE_PRECISION (valtype)
    4621           14 :                        || (type == dfloat128_type_node
    4622           10 :                            && (valtype
    4623           10 :                                != dfloat64_type_node
    4624            8 :                                && (valtype
    4625              :                                    != dfloat32_type_node)))
    4626            8 :                        || (type == dfloat64_type_node
    4627            4 :                            && (valtype
    4628              :                                != dfloat32_type_node))))
    4629           24 :             warning_at (ploc, 0,
    4630              :                         "passing argument %d of %qE as %qT "
    4631              :                         "rather than %qT due to prototype",
    4632              :                         argnum, rname, type, valtype);
    4633              : 
    4634              :         }
    4635              :       /* Detect integer changing in width or signedness.
    4636              :          These warnings are only activated with
    4637              :          -Wtraditional-conversion, not with -Wtraditional.  */
    4638          105 :       else if (warn_traditional_conversion
    4639          105 :                && INTEGRAL_TYPE_P (type)
    4640          102 :                && INTEGRAL_TYPE_P (valtype))
    4641              :         {
    4642           83 :           unsigned int formal_prec = TYPE_PRECISION (type);
    4643           83 :           tree would_have_been = default_conversion (val);
    4644           83 :           tree type1 = TREE_TYPE (would_have_been);
    4645              : 
    4646           83 :           if (val == error_mark_node)
    4647              :             /* VAL could have been of incomplete type.  */;
    4648           83 :           else if (TREE_CODE (type) == ENUMERAL_TYPE
    4649           83 :                    && (TYPE_MAIN_VARIANT (type)
    4650            2 :                        == TYPE_MAIN_VARIANT (valtype)))
    4651              :             /* No warning if function asks for enum
    4652              :                and the actual arg is that enum type.  */
    4653              :             ;
    4654           81 :           else if (formal_prec != TYPE_PRECISION (type1))
    4655           14 :             warning_at (ploc, OPT_Wtraditional_conversion,
    4656              :                         "passing argument %d of %qE "
    4657              :                         "with different width due to prototype",
    4658              :                         argnum, rname);
    4659           67 :           else if (TYPE_UNSIGNED (type) == TYPE_UNSIGNED (type1))
    4660              :             ;
    4661              :           /* Don't complain if the formal parameter type
    4662              :              is an enum, because we can't tell now whether
    4663              :              the value was an enum--even the same enum.  */
    4664           32 :           else if (TREE_CODE (type) == ENUMERAL_TYPE)
    4665              :             ;
    4666           32 :           else if (TREE_CODE (val) == INTEGER_CST
    4667            5 :                    && int_fits_type_p (val, type))
    4668              :             /* Change in signedness doesn't matter
    4669              :                if a constant value is unaffected.  */
    4670              :             ;
    4671              :           /* If the value is extended from a narrower
    4672              :              unsigned type, it doesn't matter whether we
    4673              :              pass it as signed or unsigned; the value
    4674              :              certainly is the same either way.  */
    4675           32 :           else if (TYPE_PRECISION (valtype) < TYPE_PRECISION (type)
    4676           32 :                    && TYPE_UNSIGNED (valtype))
    4677              :             ;
    4678           32 :           else if (TYPE_UNSIGNED (type))
    4679           17 :             warning_at (ploc, OPT_Wtraditional_conversion,
    4680              :                         "passing argument %d of %qE "
    4681              :                         "as unsigned due to prototype",
    4682              :                         argnum, rname);
    4683              :           else
    4684           15 :             warning_at (ploc, OPT_Wtraditional_conversion,
    4685              :                         "passing argument %d of %qE "
    4686              :                         "as signed due to prototype",
    4687              :                         argnum, rname);
    4688              :         }
    4689              :     }
    4690              : 
    4691              :   /* Possibly restore an EXCESS_PRECISION_EXPR for the
    4692              :      sake of better warnings from convert_and_check.  */
    4693    129279949 :   if (excess_precision)
    4694          380 :     val = build1 (EXCESS_PRECISION_EXPR, valtype, val);
    4695              : 
    4696    129279949 :   tree parmval = convert_for_assignment (ploc, ploc, type,
    4697              :                                          val, origtype, ic_argpass,
    4698              :                                          npc, fundecl, function,
    4699              :                                          parmnum + 1, warnopt);
    4700    129279949 :   return parmval;
    4701              : }
    4702              : 
    4703              : /* Convert the argument expressions in the vector VALUES
    4704              :    to the types in the list TYPE_ARG_TYPES (FNTYPE).
    4705              : 
    4706              :    If the list is exhausted, or when an element has NULL as its type,
    4707              :    perform the default conversions.
    4708              : 
    4709              :    ORIGTYPES is the original types of the expressions in VALUES.  This
    4710              :    holds the type of enum values which have been converted to integral
    4711              :    types.  It may be NULL.
    4712              : 
    4713              :    FUNCTION is a tree for the called function.  It is used only for
    4714              :    error messages, where it is formatted with %qE.
    4715              : 
    4716              :    This is also where warnings about wrong number of args are generated.
    4717              : 
    4718              :    ARG_LOC are locations of function arguments (if any).
    4719              : 
    4720              :    Returns the actual number of arguments processed (which may be less
    4721              :    than the length of VALUES in some error situations), or -1 on
    4722              :    failure.  */
    4723              : 
    4724              : static int
    4725     51681954 : convert_arguments (location_t loc, vec<location_t> arg_loc, tree fntype,
    4726              :                    vec<tree, va_gc> *values, vec<tree, va_gc> *origtypes,
    4727              :                    tree function, tree fundecl)
    4728              : {
    4729     51681954 :   tree typelist = TYPE_ARG_TYPES (fntype);
    4730     51681954 :   unsigned int parmnum;
    4731     51681954 :   bool error_args = false;
    4732     51681954 :   const bool type_generic = fundecl
    4733     51681954 :     && lookup_attribute ("type generic", TYPE_ATTRIBUTES (TREE_TYPE (fundecl)));
    4734     51681954 :   bool type_generic_remove_excess_precision = false;
    4735     51681954 :   bool type_generic_overflow_p = false;
    4736     51681954 :   bool type_generic_bit_query = false;
    4737     51681954 :   tree selector;
    4738              : 
    4739              :   /* Change pointer to function to the function itself for
    4740              :      diagnostics.  */
    4741     51681954 :   if (TREE_CODE (function) == ADDR_EXPR
    4742     51681954 :       && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL)
    4743     51606390 :     function = TREE_OPERAND (function, 0);
    4744              : 
    4745              :   /* Handle an ObjC selector specially for diagnostics.  */
    4746     51681954 :   selector = objc_message_selector ();
    4747              : 
    4748              :   /* For a call to a built-in function declared without a prototype,
    4749              :      set to the built-in function's argument list.  */
    4750     51681954 :   tree builtin_typelist = NULL_TREE;
    4751              : 
    4752              :   /* For type-generic built-in functions, determine whether excess
    4753              :      precision should be removed (classification) or not
    4754              :      (comparison).  */
    4755     51681954 :   if (fundecl
    4756     51681954 :       && fndecl_built_in_p (fundecl, BUILT_IN_NORMAL))
    4757              :     {
    4758      1415189 :       built_in_function code = DECL_FUNCTION_CODE (fundecl);
    4759      1415189 :       if (C_DECL_BUILTIN_PROTOTYPE (fundecl))
    4760              :         {
    4761              :           /* For a call to a built-in function declared without a prototype
    4762              :              use the types of the parameters of the internal built-in to
    4763              :              match those of the arguments to.  */
    4764       696134 :           if (tree bdecl = builtin_decl_explicit (code))
    4765       696134 :             builtin_typelist = TYPE_ARG_TYPES (TREE_TYPE (bdecl));
    4766              :         }
    4767              : 
    4768              :       /* For type-generic built-in functions, determine whether excess
    4769              :          precision should be removed (classification) or not
    4770              :          (comparison).  */
    4771      1415189 :       if (type_generic)
    4772        61259 :         switch (code)
    4773              :           {
    4774         5441 :           case BUILT_IN_ISFINITE:
    4775         5441 :           case BUILT_IN_ISINF:
    4776         5441 :           case BUILT_IN_ISINF_SIGN:
    4777         5441 :           case BUILT_IN_ISNAN:
    4778         5441 :           case BUILT_IN_ISNORMAL:
    4779         5441 :           case BUILT_IN_ISSIGNALING:
    4780         5441 :           case BUILT_IN_FPCLASSIFY:
    4781         5441 :             type_generic_remove_excess_precision = true;
    4782         5441 :             break;
    4783              : 
    4784        21033 :           case BUILT_IN_ADD_OVERFLOW_P:
    4785        21033 :           case BUILT_IN_SUB_OVERFLOW_P:
    4786        21033 :           case BUILT_IN_MUL_OVERFLOW_P:
    4787              :             /* The last argument of these type-generic builtins
    4788              :                should not be promoted.  */
    4789        21033 :             type_generic_overflow_p = true;
    4790        21033 :             break;
    4791              : 
    4792         1386 :           case BUILT_IN_CLZG:
    4793         1386 :           case BUILT_IN_CTZG:
    4794         1386 :           case BUILT_IN_CLRSBG:
    4795         1386 :           case BUILT_IN_FFSG:
    4796         1386 :           case BUILT_IN_PARITYG:
    4797         1386 :           case BUILT_IN_POPCOUNTG:
    4798              :             /* The first argument of these type-generic builtins
    4799              :                should not be promoted.  */
    4800         1386 :             type_generic_bit_query = true;
    4801         1386 :             break;
    4802              : 
    4803              :           default:
    4804              :             break;
    4805              :           }
    4806              :     }
    4807              : 
    4808              :   /* Scan the given expressions (VALUES) and types (TYPELIST), producing
    4809              :      individual converted arguments.  */
    4810              : 
    4811     51681954 :   tree typetail, builtin_typetail, val;
    4812    130219249 :   for (typetail = typelist,
    4813     51681954 :          builtin_typetail = builtin_typelist,
    4814     51681954 :          parmnum = 0;
    4815    181901203 :        values && values->iterate (parmnum, &val);
    4816              :        ++parmnum)
    4817              :     {
    4818              :       /* The type of the function parameter (if it was declared with one).  */
    4819    259497351 :       tree type = typetail ? TREE_VALUE (typetail) : NULL_TREE;
    4820              :       /* The type of the built-in function parameter (if the function
    4821              :          is a built-in).  Used to detect type incompatibilities in
    4822              :          calls to built-ins declared without a prototype.  */
    4823    130219285 :       tree builtin_type = (builtin_typetail
    4824    131261267 :                            ? TREE_VALUE (builtin_typetail) : NULL_TREE);
    4825              :       /* The original type of the argument being passed to the function.  */
    4826    130219285 :       tree valtype = TREE_TYPE (val);
    4827              :       /* The called function (or function selector in Objective C).  */
    4828    130219285 :       tree rname = function;
    4829    130219285 :       int argnum = parmnum + 1;
    4830    130219285 :       const char *invalid_func_diag;
    4831              :       /* Set for EXCESS_PRECISION_EXPR arguments.  */
    4832    130219285 :       bool excess_precision = false;
    4833              :       /* The value of the argument after conversion to the type
    4834              :          of the function parameter it is passed to.  */
    4835    130219285 :       tree parmval;
    4836              :       /* Some __atomic_* builtins have additional hidden argument at
    4837              :          position 0.  */
    4838    130219285 :       location_t ploc
    4839    129949498 :         = !arg_loc.is_empty () && values->length () == arg_loc.length ()
    4840    129948898 :           ? expansion_point_location_if_in_system_header (arg_loc[parmnum])
    4841    130219285 :           : input_location;
    4842              : 
    4843    130219285 :       if (type == void_type_node)
    4844              :         {
    4845           33 :           auto_diagnostic_group d;
    4846           33 :           int num_expected = parmnum;
    4847           33 :           int num_actual = values->length ();
    4848           33 :           gcc_rich_location rich_loc (loc);
    4849           33 :           if (ploc != input_location)
    4850           32 :             rich_loc.add_range (ploc);
    4851           33 :           if (selector)
    4852            0 :             error_at (&rich_loc,
    4853              :                       "too many arguments to method %qE; expected %i, have %i",
    4854              :                       selector, num_expected, num_actual);
    4855              :           else
    4856           33 :             error_at (&rich_loc,
    4857              :                       "too many arguments to function %qE; expected %i, have %i",
    4858              :                       function, num_expected, num_actual);
    4859           33 :           inform_declaration (fundecl, function);
    4860           65 :           return error_args ? -1 : (int) parmnum;
    4861           33 :         }
    4862              : 
    4863    130219252 :       if (builtin_type == void_type_node)
    4864              :         {
    4865           12 :           auto_diagnostic_group d;
    4866           12 :           if (warning_at (loc, OPT_Wbuiltin_declaration_mismatch,
    4867              :                           "too many arguments to built-in function %qE "
    4868              :                           "expecting %d", function, parmnum))
    4869           12 :             inform_declaration (fundecl, function);
    4870           12 :           builtin_typetail = NULL_TREE;
    4871           12 :         }
    4872              : 
    4873        90896 :       if (!typetail && parmnum == 0 && !TYPE_NO_NAMED_ARGS_STDARG_P (fntype)
    4874    130310029 :           && !(fundecl && fndecl_built_in_p (fundecl)))
    4875              :         {
    4876         6962 :           auto_diagnostic_group d;
    4877         6962 :           bool warned;
    4878         6962 :           if (selector)
    4879            0 :             warned = warning_at (loc, OPT_Wdeprecated_non_prototype,
    4880              :                                  "ISO C23 does not allow arguments"
    4881              :                                  " for method %qE declared without parameters",
    4882              :                                  function);
    4883              :           else
    4884         6962 :             warned = warning_at (loc, OPT_Wdeprecated_non_prototype,
    4885              :                                  "ISO C23 does not allow arguments"
    4886              :                                  " for function %qE declared without parameters",
    4887              :                                  function);
    4888         6962 :           if (warned)
    4889            4 :             inform_declaration (fundecl, function);
    4890         6962 :         }
    4891              : 
    4892    130219252 :       if (selector && argnum > 2)
    4893              :         {
    4894            0 :           rname = selector;
    4895            0 :           argnum -= 2;
    4896              :         }
    4897              : 
    4898              :       /* Determine if VAL is a null pointer constant before folding it.  */
    4899    130219252 :       bool npc = null_pointer_constant_p (val);
    4900              : 
    4901              :       /* If there is excess precision and a prototype, convert once to
    4902              :          the required type rather than converting via the semantic
    4903              :          type.  Likewise without a prototype a float value represented
    4904              :          as long double should be converted once to double.  But for
    4905              :          type-generic classification functions excess precision must
    4906              :          be removed here.  */
    4907    130219252 :       if (TREE_CODE (val) == EXCESS_PRECISION_EXPR
    4908          433 :           && (type || !type_generic || !type_generic_remove_excess_precision))
    4909              :         {
    4910          413 :           val = TREE_OPERAND (val, 0);
    4911          413 :           excess_precision = true;
    4912              :         }
    4913    130219252 :       val = c_fully_fold (val, false, NULL);
    4914    260438505 :       STRIP_TYPE_NOPS (val);
    4915              : 
    4916    130219252 :       val = require_complete_type (ploc, val);
    4917              : 
    4918              :       /* Some floating-point arguments must be promoted to double when
    4919              :          no type is specified by a prototype.  This applies to
    4920              :          arguments of type float, and to architecture-specific types
    4921              :          (ARM __fp16), but not to _FloatN or _FloatNx types.  */
    4922    130219252 :       bool promote_float_arg = false;
    4923    130219252 :       if (type == NULL_TREE
    4924       941219 :           && TREE_CODE (valtype) == REAL_TYPE
    4925       269747 :           && (TYPE_PRECISION (valtype)
    4926       269747 :               <= TYPE_PRECISION (double_type_node))
    4927       262493 :           && TYPE_MAIN_VARIANT (valtype) != double_type_node
    4928       131475 :           && TYPE_MAIN_VARIANT (valtype) != long_double_type_node
    4929    130350727 :           && !DECIMAL_FLOAT_MODE_P (TYPE_MODE (valtype)))
    4930              :         {
    4931              :           /* Promote this argument, unless it has a _FloatN or
    4932              :              _FloatNx type.  */
    4933      1028302 :           promote_float_arg = true;
    4934      1028302 :           for (int i = 0; i < NUM_FLOATN_NX_TYPES; i++)
    4935       900837 :             if (TYPE_MAIN_VARIANT (valtype) == FLOATN_NX_TYPE_NODE (i))
    4936              :               {
    4937              :                 promote_float_arg = false;
    4938              :                 break;
    4939              :               }
    4940              :           /* Don't promote __bf16 either.  */
    4941       130742 :           if (TYPE_MAIN_VARIANT (valtype) == bfloat16_type_node)
    4942    130088580 :             promote_float_arg = false;
    4943              :         }
    4944              : 
    4945    130219252 :       if (type != NULL_TREE)
    4946              :         {
    4947    129278033 :           tree origtype = (!origtypes) ? NULL_TREE : (*origtypes)[parmnum];
    4948    129278033 :           parmval = convert_argument (ploc, function, fundecl, type, origtype,
    4949              :                                       val, valtype, npc, rname, parmnum, argnum,
    4950              :                                       excess_precision, 0);
    4951              :         }
    4952              :       /* A NULLPTR type is just a nullptr always.  */
    4953       941219 :       else if (TREE_CODE (TREE_TYPE (val)) == NULLPTR_TYPE)
    4954            9 :         parmval = omit_one_operand_loc (ploc, TREE_TYPE (val), nullptr_node, val);
    4955       941210 :       else if (promote_float_arg)
    4956              :         {
    4957       127395 :           if (type_generic)
    4958              :             parmval = val;
    4959              :           else
    4960              :             {
    4961              :               /* Convert `float' to `double'.  */
    4962       124528 :               if (warn_double_promotion && !c_inhibit_evaluation_warnings)
    4963            6 :                 warning_at (ploc, OPT_Wdouble_promotion,
    4964              :                             "implicit conversion from %qT to %qT when passing "
    4965              :                             "argument to function",
    4966              :                             valtype, double_type_node);
    4967       124528 :               parmval = convert (double_type_node, val);
    4968              :             }
    4969              :         }
    4970       813815 :       else if ((excess_precision && !type_generic)
    4971       813813 :                || (type_generic_overflow_p && parmnum == 2)
    4972       792784 :                || (type_generic_bit_query && parmnum == 0))
    4973              :         /* A "double" argument with excess precision being passed
    4974              :            without a prototype or in variable arguments.
    4975              :            The last argument of __builtin_*_overflow_p should not be
    4976              :            promoted, similarly the first argument of
    4977              :            __builtin_{clz,ctz,clrsb,ffs,parity,popcount}g.  */
    4978        22411 :         parmval = convert (valtype, val);
    4979      1582808 :       else if ((invalid_func_diag =
    4980       791404 :                 targetm.calls.invalid_arg_for_unprototyped_fn (typelist, fundecl, val)))
    4981              :         {
    4982            0 :           error (invalid_func_diag);
    4983            0 :           return -1;
    4984              :         }
    4985       791404 :       else if (TREE_CODE (val) == ADDR_EXPR && reject_gcc_builtin (val))
    4986              :         {
    4987              :           return -1;
    4988              :         }
    4989              :       else
    4990              :         /* Convert `short' and `char' to full-size `int'.  */
    4991       791401 :         parmval = default_conversion (val);
    4992              : 
    4993    130219249 :       (*values)[parmnum] = parmval;
    4994    130219249 :       if (parmval == error_mark_node)
    4995          106 :         error_args = true;
    4996              : 
    4997    130219249 :       if (!type && builtin_type && TREE_CODE (builtin_type) != VOID_TYPE)
    4998              :         {
    4999              :           /* For a call to a built-in function declared without a prototype,
    5000              :              perform the conversions from the argument to the expected type
    5001              :              but issue warnings rather than errors for any mismatches.
    5002              :              Ignore the converted argument and use the PARMVAL obtained
    5003              :              above by applying default conversions instead.  */
    5004         1919 :           tree origtype = (!origtypes) ? NULL_TREE : (*origtypes)[parmnum];
    5005         1919 :           convert_argument (ploc, function, fundecl, builtin_type, origtype,
    5006              :                             val, valtype, npc, rname, parmnum, argnum,
    5007              :                             excess_precision,
    5008              :                             OPT_Wbuiltin_declaration_mismatch);
    5009              :         }
    5010              : 
    5011    130219249 :       if (typetail)
    5012    129278033 :         typetail = TREE_CHAIN (typetail);
    5013              : 
    5014    130219249 :       if (builtin_typetail)
    5015      1041965 :         builtin_typetail = TREE_CHAIN (builtin_typetail);
    5016              :     }
    5017              : 
    5018     91061246 :   gcc_assert (parmnum == vec_safe_length (values));
    5019              : 
    5020    103030299 :   if (typetail != NULL_TREE && TREE_VALUE (typetail) != void_type_node)
    5021              :     {
    5022              :       /* Not enough args.
    5023              :          Determine minimum number of arguments required.  */
    5024              :       int min_expected_num = 0;
    5025          231 :       bool at_least_p = false;
    5026              :       tree iter = typelist;
    5027          386 :       while (true)
    5028              :         {
    5029          231 :           if (!iter)
    5030              :             {
    5031              :               /* Variadic arguments; stop iterating.  */
    5032              :               at_least_p = true;
    5033              :               break;
    5034              :             }
    5035          222 :           if (iter == void_list_node)
    5036              :             /* End of arguments; stop iterating.  */
    5037              :             break;
    5038          155 :           ++min_expected_num;
    5039          155 :           iter = TREE_CHAIN (iter);
    5040              :         }
    5041           76 :       auto_diagnostic_group d;
    5042           76 :       int actual_num = vec_safe_length (values);
    5043          143 :       error_at (loc,
    5044              :                 at_least_p
    5045              :                 ? G_("too few arguments to function %qE; expected at least %i, have %i")
    5046              :                 : G_("too few arguments to function %qE; expected %i, have %i"),
    5047              :                 function, min_expected_num, actual_num);
    5048           76 :       inform_declaration (fundecl, function);
    5049           76 :       return -1;
    5050           76 :     }
    5051              : 
    5052     52341634 :   if (builtin_typetail && TREE_VALUE (builtin_typetail) != void_type_node)
    5053              :     {
    5054          616 :       unsigned nargs = parmnum;
    5055          616 :       for (tree t = builtin_typetail; t; t = TREE_CHAIN (t))
    5056          428 :         ++nargs;
    5057              : 
    5058          188 :       auto_diagnostic_group d;
    5059          188 :       if (warning_at (loc, OPT_Wbuiltin_declaration_mismatch,
    5060              :                       "too few arguments to built-in function %qE "
    5061              :                       "expecting %u", function, nargs - 1))
    5062          173 :         inform_declaration (fundecl, function);
    5063          188 :     }
    5064              : 
    5065     51681842 :   return error_args ? -1 : (int) parmnum;
    5066              : }
    5067              : 
    5068              : /* This is the entry point used by the parser to build unary operators
    5069              :    in the input.  CODE, a tree_code, specifies the unary operator, and
    5070              :    ARG is the operand.  For unary plus, the C parser currently uses
    5071              :    CONVERT_EXPR for code.
    5072              : 
    5073              :    LOC is the location to use for the tree generated.
    5074              : */
    5075              : 
    5076              : struct c_expr
    5077      8465792 : parser_build_unary_op (location_t loc, enum tree_code code, struct c_expr arg)
    5078              : {
    5079      8465792 :   struct c_expr result;
    5080              : 
    5081      8465792 :   result.original_code = code;
    5082      8465792 :   result.original_type = NULL;
    5083      8465792 :   result.m_decimal = 0;
    5084              : 
    5085      8465792 :   if (reject_gcc_builtin (arg.value))
    5086              :     {
    5087            2 :       result.value = error_mark_node;
    5088              :     }
    5089              :   else
    5090              :     {
    5091      8465790 :       result.value = build_unary_op (loc, code, arg.value, false);
    5092              : 
    5093      8465790 :       if (TREE_OVERFLOW_P (result.value) && !TREE_OVERFLOW_P (arg.value))
    5094            5 :         overflow_warning (loc, result.value, arg.value);
    5095              :     }
    5096              : 
    5097              :   /* We are typically called when parsing a prefix token at LOC acting on
    5098              :      ARG.  Reflect this by updating the source range of the result to
    5099              :      start at LOC and end at the end of ARG.  */
    5100      8465792 :   set_c_expr_source_range (&result,
    5101              :                            loc, arg.get_finish ());
    5102              : 
    5103      8465792 :   return result;
    5104              : }
    5105              : 
    5106              : /* Returns true if TYPE is a character type, *not* including wchar_t.  */
    5107              : 
    5108              : bool
    5109      1276846 : char_type_p (tree type)
    5110              : {
    5111      1276846 :   return (type == char_type_node
    5112       984530 :           || type == unsigned_char_type_node
    5113       965323 :           || type == signed_char_type_node
    5114       964441 :           || type == char16_type_node
    5115      2019376 :           || type == char32_type_node);
    5116              : }
    5117              : 
    5118              : /* This is the entry point used by the parser to build binary operators
    5119              :    in the input.  CODE, a tree_code, specifies the binary operator, and
    5120              :    ARG1 and ARG2 are the operands.  In addition to constructing the
    5121              :    expression, we check for operands that were written with other binary
    5122              :    operators in a way that is likely to confuse the user.  ORIG_ARG1 is
    5123              :    the original first operand for TRUTH_{AND,OR}IF_EXPR before it is
    5124              :    converted to truth value, otherwise NULL_TREE.
    5125              : 
    5126              :    LOCATION is the location of the binary operator.  */
    5127              : 
    5128              : struct c_expr
    5129      9415202 : parser_build_binary_op (location_t location, enum tree_code code,
    5130              :                         struct c_expr arg1, struct c_expr arg2, tree orig_arg1)
    5131              : {
    5132      9415202 :   struct c_expr result;
    5133      9415202 :   result.m_decimal = 0;
    5134              : 
    5135      9415202 :   enum tree_code code1 = arg1.original_code;
    5136      9415202 :   enum tree_code code2 = arg2.original_code;
    5137      9415202 :   tree type1 = (arg1.original_type
    5138      9415202 :                 ? arg1.original_type
    5139      6039392 :                 : TREE_TYPE (arg1.value));
    5140      9415202 :   tree type2 = (arg2.original_type
    5141      9415202 :                 ? arg2.original_type
    5142      6947902 :                 : TREE_TYPE (arg2.value));
    5143              : 
    5144      9415202 :   result.value = build_binary_op (location, code,
    5145              :                                   arg1.value, arg2.value, true);
    5146      9415201 :   result.original_code = code;
    5147      9415201 :   result.original_type = NULL;
    5148      9415201 :   result.m_decimal = 0;
    5149              : 
    5150      9415201 :   if (TREE_CODE (result.value) == ERROR_MARK)
    5151              :     {
    5152         1297 :       set_c_expr_source_range (&result,
    5153              :                                arg1.get_start (),
    5154              :                                arg2.get_finish ());
    5155         1297 :       return result;
    5156              :     }
    5157              : 
    5158      9413904 :   if (location != UNKNOWN_LOCATION)
    5159      9413904 :     protected_set_expr_location (result.value, location);
    5160              : 
    5161      9413904 :   set_c_expr_source_range (&result,
    5162              :                            arg1.get_start (),
    5163              :                            arg2.get_finish ());
    5164              : 
    5165              :   /* Check for cases such as x+y<<z which users are likely
    5166              :      to misinterpret.  */
    5167      9413904 :   if (warn_parentheses)
    5168      2013771 :     warn_about_parentheses (location, code, code1, arg1.value, code2,
    5169              :                             arg2.value);
    5170              : 
    5171      9413904 :   if (warn_logical_op)
    5172          340 :     warn_logical_operator (location, code, TREE_TYPE (result.value),
    5173              :                            code1, arg1.value, code2, arg2.value);
    5174              : 
    5175      9413904 :   if (warn_constant_logical_operand
    5176      2012186 :       && (code == TRUTH_ANDIF_EXPR || code == TRUTH_ORIF_EXPR)
    5177        74718 :       && INTEGRAL_NB_TYPE_P (type1)
    5178        72897 :       && INTEGRAL_NB_TYPE_P (type2))
    5179              :     {
    5180        71300 :       const char *name = code == TRUTH_ANDIF_EXPR ? "&&" : "||";
    5181        71300 :       if (orig_arg1 == NULL_TREE)
    5182            0 :         orig_arg1 = arg1.value;
    5183        76693 :       auto enum_other_than_0_1 = [] (tree type) {
    5184         5393 :         if (TREE_CODE (type) != ENUMERAL_TYPE)
    5185              :           return false;
    5186           48 :         for (tree l = TYPE_VALUES (type); l; l = TREE_CHAIN (l))
    5187              :           {
    5188           40 :             tree v = DECL_INITIAL (TREE_VALUE (l));
    5189           40 :             if (!integer_zerop (v) && !integer_onep (v))
    5190              :               return true;
    5191              :           }
    5192              :         return false;
    5193              :       };
    5194       213884 :       auto diagnose_constant_logical_operand = [=] (tree val, tree type) {
    5195       142584 :         if (TREE_CODE (val) != INTEGER_CST || integer_zerop (val))
    5196              :           return false;
    5197         5417 :         if (integer_onep (val) && !enum_other_than_0_1 (type))
    5198              :           return false;
    5199           32 :         gcc_rich_location richloc (location);
    5200           32 :         richloc.add_fixit_replace (name + 1);
    5201           32 :         auto_diagnostic_group d;
    5202           32 :         if (warning_at (location, OPT_Wconstant_logical_operand,
    5203              :                         "use of logical %qs with constant operand %qE",
    5204              :                         name, val))
    5205           32 :           inform (&richloc, "use %qs for bitwise operation", name + 1);
    5206           32 :         return true;
    5207           32 :       };
    5208        71300 :       if (!diagnose_constant_logical_operand (arg2.value, type2))
    5209        71284 :         diagnose_constant_logical_operand (orig_arg1, type1);
    5210              :     }
    5211              : 
    5212      9413904 :   if (warn_tautological_compare)
    5213              :     {
    5214      2012284 :       tree lhs = arg1.value;
    5215      2012284 :       tree rhs = arg2.value;
    5216      2012284 :       if (TREE_CODE (lhs) == C_MAYBE_CONST_EXPR)
    5217              :         {
    5218            2 :           if (C_MAYBE_CONST_EXPR_PRE (lhs) != NULL_TREE
    5219            2 :               && TREE_SIDE_EFFECTS (C_MAYBE_CONST_EXPR_PRE (lhs)))
    5220              :             lhs = NULL_TREE;
    5221              :           else
    5222            2 :             lhs = C_MAYBE_CONST_EXPR_EXPR (lhs);
    5223              :         }
    5224      2012284 :       if (TREE_CODE (rhs) == C_MAYBE_CONST_EXPR)
    5225              :         {
    5226           12 :           if (C_MAYBE_CONST_EXPR_PRE (rhs) != NULL_TREE
    5227           12 :               && TREE_SIDE_EFFECTS (C_MAYBE_CONST_EXPR_PRE (rhs)))
    5228              :             rhs = NULL_TREE;
    5229              :           else
    5230           12 :             rhs = C_MAYBE_CONST_EXPR_EXPR (rhs);
    5231              :         }
    5232      2012284 :       if (lhs != NULL_TREE && rhs != NULL_TREE)
    5233      2012284 :         warn_tautological_cmp (location, code, lhs, rhs);
    5234              :     }
    5235              : 
    5236      9413904 :   if (warn_logical_not_paren
    5237      2012367 :       && TREE_CODE_CLASS (code) == tcc_comparison
    5238       410647 :       && code1 == TRUTH_NOT_EXPR
    5239       410647 :       && code2 != TRUTH_NOT_EXPR
    5240              :       /* Avoid warning for !!x == y.  */
    5241      9414038 :       && (TREE_CODE (arg1.value) != NE_EXPR
    5242           27 :           || !integer_zerop (TREE_OPERAND (arg1.value, 1))))
    5243              :     {
    5244              :       /* Avoid warning for !b == y where b has _Bool type.  */
    5245          107 :       tree t = integer_zero_node;
    5246          107 :       if (TREE_CODE (arg1.value) == EQ_EXPR
    5247           98 :           && integer_zerop (TREE_OPERAND (arg1.value, 1))
    5248          205 :           && TREE_TYPE (TREE_OPERAND (arg1.value, 0)) == integer_type_node)
    5249              :         {
    5250           90 :           t = TREE_OPERAND (arg1.value, 0);
    5251          199 :           do
    5252              :             {
    5253          199 :               if (TREE_TYPE (t) != integer_type_node)
    5254              :                 break;
    5255          180 :               if (TREE_CODE (t) == C_MAYBE_CONST_EXPR)
    5256           90 :                 t = C_MAYBE_CONST_EXPR_EXPR (t);
    5257           90 :               else if (CONVERT_EXPR_P (t))
    5258           19 :                 t = TREE_OPERAND (t, 0);
    5259              :               else
    5260              :                 break;
    5261              :             }
    5262              :           while (1);
    5263              :         }
    5264          107 :       if (!C_BOOLEAN_TYPE_P (TREE_TYPE (t)))
    5265           88 :         warn_logical_not_parentheses (location, code, arg1.value, arg2.value);
    5266              :     }
    5267              : 
    5268              :   /* Warn about comparisons against string literals, with the exception
    5269              :      of testing for equality or inequality of a string literal with NULL.  */
    5270      9413904 :   if (code == EQ_EXPR || code == NE_EXPR)
    5271              :     {
    5272      1182125 :       if ((code1 == STRING_CST
    5273           16 :            && !integer_zerop (tree_strip_nop_conversions (arg2.value)))
    5274      1182136 :           || (code2 == STRING_CST
    5275           39 :               && !integer_zerop (tree_strip_nop_conversions (arg1.value))))
    5276           36 :         warning_at (location, OPT_Waddress,
    5277              :                     "comparison with string literal results in unspecified behavior");
    5278              :       /* Warn for ptr == '\0', it's likely that it should've been ptr[0].  */
    5279      1182125 :       if (POINTER_TYPE_P (type1)
    5280        92521 :           && null_pointer_constant_p (arg2.value)
    5281      1203446 :           && char_type_p (type2))
    5282              :         {
    5283           18 :           auto_diagnostic_group d;
    5284           18 :           if (warning_at (location, OPT_Wpointer_compare,
    5285              :                             "comparison between pointer and zero character "
    5286              :                             "constant"))
    5287           10 :             inform (arg1.get_start (),
    5288              :                       "did you mean to dereference the pointer?");
    5289           18 :         }
    5290      1182107 :       else if (POINTER_TYPE_P (type2)
    5291        89856 :                && null_pointer_constant_p (arg1.value)
    5292      1182379 :                && char_type_p (type1))
    5293              :         {
    5294           10 :           auto_diagnostic_group d;
    5295           10 :           if (warning_at (location, OPT_Wpointer_compare,
    5296              :                             "comparison between pointer and zero character "
    5297              :                             "constant"))
    5298           10 :             inform (arg2.get_start (),
    5299              :                       "did you mean to dereference the pointer?");
    5300           10 :         }
    5301              :     }
    5302      8231779 :   else if (TREE_CODE_CLASS (code) == tcc_comparison
    5303      1012259 :            && (code1 == STRING_CST || code2 == STRING_CST))
    5304            0 :     warning_at (location, OPT_Waddress,
    5305              :                 "comparison with string literal results in unspecified "
    5306              :                 "behavior");
    5307              : 
    5308      9413904 :   if (warn_zero_as_null_pointer_constant
    5309           24 :       && c_inhibit_evaluation_warnings == 0
    5310           24 :       && TREE_CODE_CLASS (code) == tcc_comparison)
    5311              :     {
    5312           24 :       if ((TREE_CODE (type1) == POINTER_TYPE
    5313           17 :            || TREE_CODE (type1) == NULLPTR_TYPE)
    5314            9 :           && INTEGRAL_TYPE_P (type2)
    5315           33 :           && null_pointer_constant_p (arg2.value))
    5316            9 :         warning_at (arg2.get_location(), OPT_Wzero_as_null_pointer_constant,
    5317              :                     "zero as null pointer constant");
    5318              : 
    5319           24 :       if ((TREE_CODE (type2) == POINTER_TYPE
    5320           15 :            || TREE_CODE (type2) == NULLPTR_TYPE)
    5321           11 :           && INTEGRAL_TYPE_P (type1)
    5322           35 :           && null_pointer_constant_p (arg1.value))
    5323           11 :         warning_at (arg1.get_location(), OPT_Wzero_as_null_pointer_constant,
    5324              :                     "zero as null pointer constant");
    5325              :     }
    5326              : 
    5327      9413904 :   if (warn_array_compare
    5328      2012122 :       && TREE_CODE_CLASS (code) == tcc_comparison
    5329       410432 :       && TREE_CODE (type1) == ARRAY_TYPE
    5330           38 :       && TREE_CODE (type2) == ARRAY_TYPE)
    5331           15 :     do_warn_array_compare (location, code, arg1.value, arg2.value);
    5332              : 
    5333      2202355 :   if (TREE_OVERFLOW_P (result.value)
    5334          299 :       && !TREE_OVERFLOW_P (arg1.value)
    5335      9414196 :       && !TREE_OVERFLOW_P (arg2.value))
    5336          249 :     overflow_warning (location, result.value);
    5337              : 
    5338              :   /* Warn about comparisons of different enum types.  */
    5339      9413903 :   if (warn_enum_compare
    5340      2032246 :       && TREE_CODE_CLASS (code) == tcc_comparison
    5341       414973 :       && TREE_CODE (type1) == ENUMERAL_TYPE
    5342         7305 :       && TREE_CODE (type2) == ENUMERAL_TYPE
    5343      9421144 :       && TYPE_MAIN_VARIANT (type1) != TYPE_MAIN_VARIANT (type2))
    5344            2 :     warning_at (location, OPT_Wenum_compare,
    5345              :                 "comparison between %qT and %qT",
    5346              :                 type1, type2);
    5347              : 
    5348      9413903 :   if (warn_xor_used_as_pow
    5349      9413903 :       && code == BIT_XOR_EXPR
    5350        84341 :       && arg1.m_decimal
    5351          737 :       && arg2.m_decimal)
    5352          427 :     check_for_xor_used_as_pow (arg1.get_location (), arg1.value,
    5353              :                                location,
    5354              :                                arg2.get_location (), arg2.value);
    5355              : 
    5356              :   return result;
    5357              : }
    5358              : 
    5359              : /* Return a tree for the difference of pointers OP0 and OP1.
    5360              :    The resulting tree has type ptrdiff_t.  If POINTER_SUBTRACT sanitization is
    5361              :    enabled, assign to INSTRUMENT_EXPR call to libsanitizer.  */
    5362              : 
    5363              : static tree
    5364         3730 : pointer_diff (location_t loc, tree op0, tree op1, tree *instrument_expr)
    5365              : {
    5366         3730 :   tree restype = ptrdiff_type_node;
    5367         3730 :   tree result, inttype;
    5368              : 
    5369         3730 :   addr_space_t as0 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (op0)));
    5370         3730 :   addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (op1)));
    5371         3730 :   tree target_type = TREE_TYPE (TREE_TYPE (op0));
    5372         3730 :   tree orig_op0 = op0;
    5373         3730 :   tree orig_op1 = op1;
    5374              : 
    5375              :   /* If the operands point into different address spaces, we need to
    5376              :      explicitly convert them to pointers into the common address space
    5377              :      before we can subtract the numerical address values.  */
    5378         3730 :   if (as0 != as1)
    5379              :     {
    5380            0 :       addr_space_t as_common;
    5381            0 :       tree common_type;
    5382              : 
    5383              :       /* Determine the common superset address space.  This is guaranteed
    5384              :          to exist because the caller verified that comp_target_types
    5385              :          returned non-zero.  */
    5386            0 :       if (!addr_space_superset (as0, as1, &as_common))
    5387            0 :         gcc_unreachable ();
    5388              : 
    5389            0 :       common_type = common_pointer_type (TREE_TYPE (op0), TREE_TYPE (op1), NULL_TREE);
    5390            0 :       op0 = convert (common_type, op0);
    5391            0 :       op1 = convert (common_type, op1);
    5392              :     }
    5393              : 
    5394              :   /* Determine integer type result of the subtraction.  This will usually
    5395              :      be the same as the result type (ptrdiff_t), but may need to be a wider
    5396              :      type if pointers for the address space are wider than ptrdiff_t.  */
    5397         3730 :   if (TYPE_PRECISION (restype) < TYPE_PRECISION (TREE_TYPE (op0)))
    5398            0 :     inttype = c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op0)), 0);
    5399              :   else
    5400              :     inttype = restype;
    5401              : 
    5402         3730 :   if (VOID_TYPE_P (target_type))
    5403          150 :     pedwarn (loc, OPT_Wpointer_arith,
    5404              :              "pointer of type %<void *%> used in subtraction");
    5405         3730 :   if (TREE_CODE (target_type) == FUNCTION_TYPE)
    5406            4 :     pedwarn (loc, OPT_Wpointer_arith,
    5407              :              "pointer to a function used in subtraction");
    5408              : 
    5409         3730 :   if (current_function_decl != NULL_TREE
    5410         3730 :       && sanitize_flags_p (SANITIZE_POINTER_SUBTRACT))
    5411              :     {
    5412           70 :       op0 = save_expr (c_fully_fold (op0, false, NULL));
    5413           70 :       op1 = save_expr (c_fully_fold (op1, false, NULL));
    5414              : 
    5415           70 :       tree tt = builtin_decl_explicit (BUILT_IN_ASAN_POINTER_SUBTRACT);
    5416           70 :       *instrument_expr = build_call_expr_loc (loc, tt, 2, op0, op1);
    5417              :     }
    5418              : 
    5419              :   /* First do the subtraction, then build the divide operator
    5420              :      and only convert at the very end.
    5421              :      Do not do default conversions in case restype is a short type.  */
    5422              : 
    5423              :   /* POINTER_DIFF_EXPR requires a signed integer type of the same size as
    5424              :      pointers.  If some platform cannot provide that, or has a larger
    5425              :      ptrdiff_type to support differences larger than half the address
    5426              :      space, cast the pointers to some larger integer type and do the
    5427              :      computations in that type.  */
    5428         3730 :   if (TYPE_PRECISION (inttype) > TYPE_PRECISION (TREE_TYPE (op0)))
    5429            0 :     op0 = build_binary_op (loc, MINUS_EXPR, convert (inttype, op0),
    5430              :                            convert (inttype, op1), false);
    5431              :   else
    5432              :     {
    5433              :       /* Cast away qualifiers.  */
    5434         3730 :       op0 = convert (c_common_type (TREE_TYPE (op0), TREE_TYPE (op0)), op0);
    5435         3730 :       op1 = convert (c_common_type (TREE_TYPE (op1), TREE_TYPE (op1)), op1);
    5436         3730 :       op0 = build2_loc (loc, POINTER_DIFF_EXPR, inttype, op0, op1);
    5437              :     }
    5438              : 
    5439              :   /* This generates an error if op1 is pointer to incomplete type.  */
    5440         3730 :   if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (orig_op1))))
    5441            4 :     error_at (loc, "arithmetic on pointer to an incomplete type");
    5442         3726 :   else if (verify_type_context (loc, TCTX_POINTER_ARITH,
    5443         3726 :                                 TREE_TYPE (TREE_TYPE (orig_op0))))
    5444         7452 :     verify_type_context (loc, TCTX_POINTER_ARITH,
    5445         3726 :                          TREE_TYPE (TREE_TYPE (orig_op1)));
    5446              : 
    5447         3730 :   op1 = c_size_in_bytes (target_type);
    5448              : 
    5449         3730 :   if (pointer_to_zero_sized_aggr_p (TREE_TYPE (orig_op1)))
    5450            4 :     error_at (loc, "arithmetic on pointer to an empty aggregate");
    5451              : 
    5452              :   /* Divide by the size, in easiest possible way.  */
    5453         3730 :   result = fold_build2_loc (loc, EXACT_DIV_EXPR, inttype,
    5454              :                             op0, convert (inttype, op1));
    5455              : 
    5456              :   /* Convert to final result type if necessary.  */
    5457         3730 :   return convert (restype, result);
    5458              : }
    5459              : 
    5460              : /* Expand atomic compound assignments into an appropriate sequence as
    5461              :    specified by the C11 standard section 6.5.16.2.
    5462              : 
    5463              :        _Atomic T1 E1
    5464              :        T2 E2
    5465              :        E1 op= E2
    5466              : 
    5467              :   This sequence is used for all types for which these operations are
    5468              :   supported.
    5469              : 
    5470              :   In addition, built-in versions of the 'fe' prefixed routines may
    5471              :   need to be invoked for floating point (real, complex or vector) when
    5472              :   floating-point exceptions are supported.  See 6.5.16.2 footnote 113.
    5473              : 
    5474              :   T1 newval;
    5475              :   T1 old;
    5476              :   T1 *addr
    5477              :   T2 val
    5478              :   fenv_t fenv
    5479              : 
    5480              :   addr = &E1;
    5481              :   val = (E2);
    5482              :   __atomic_load (addr, &old, SEQ_CST);
    5483              :   feholdexcept (&fenv);
    5484              : loop:
    5485              :     newval = old op val;
    5486              :     if (__atomic_compare_exchange_strong (addr, &old, &newval, SEQ_CST,
    5487              :                                           SEQ_CST))
    5488              :       goto done;
    5489              :     feclearexcept (FE_ALL_EXCEPT);
    5490              :     goto loop:
    5491              : done:
    5492              :   feupdateenv (&fenv);
    5493              : 
    5494              :   The compiler will issue the __atomic_fetch_* built-in when possible,
    5495              :   otherwise it will generate the generic form of the atomic operations.
    5496              :   This requires temp(s) and has their address taken.  The atomic processing
    5497              :   is smart enough to figure out when the size of an object can utilize
    5498              :   a lock-free version, and convert the built-in call to the appropriate
    5499              :   lock-free routine.  The optimizers will then dispose of any temps that
    5500              :   are no longer required, and lock-free implementations are utilized as
    5501              :   long as there is target support for the required size.
    5502              : 
    5503              :   If the operator is NOP_EXPR, then this is a simple assignment, and
    5504              :   an __atomic_store is issued to perform the assignment rather than
    5505              :   the above loop.  */
    5506              : 
    5507              : /* Build an atomic assignment at LOC, expanding into the proper
    5508              :    sequence to store LHS MODIFYCODE= RHS.  Return a value representing
    5509              :    the result of the operation, unless RETURN_OLD_P, in which case
    5510              :    return the old value of LHS (this is only for postincrement and
    5511              :    postdecrement).  */
    5512              : 
    5513              : static tree
    5514        30457 : build_atomic_assign (location_t loc, tree lhs, enum tree_code modifycode,
    5515              :                      tree rhs, bool return_old_p)
    5516              : {
    5517        30457 :   tree fndecl, func_call;
    5518        30457 :   vec<tree, va_gc> *params;
    5519        30457 :   tree val, nonatomic_lhs_type, nonatomic_rhs_type, newval, newval_addr;
    5520        30457 :   tree old, old_addr;
    5521        30457 :   tree compound_stmt = NULL_TREE;
    5522        30457 :   tree stmt, goto_stmt;
    5523        30457 :   tree loop_label, loop_decl, done_label, done_decl;
    5524              : 
    5525        30457 :   tree lhs_type = TREE_TYPE (lhs);
    5526        30457 :   tree lhs_addr = build_unary_op (loc, ADDR_EXPR, lhs, false);
    5527        30457 :   tree seq_cst = build_int_cst (integer_type_node, MEMMODEL_SEQ_CST);
    5528        30457 :   tree rhs_semantic_type = TREE_TYPE (rhs);
    5529        30457 :   tree nonatomic_rhs_semantic_type;
    5530        30457 :   tree rhs_type;
    5531              : 
    5532        30457 :   gcc_assert (TYPE_ATOMIC (lhs_type));
    5533              : 
    5534        30457 :   if (return_old_p)
    5535         2313 :     gcc_assert (modifycode == PLUS_EXPR || modifycode == MINUS_EXPR);
    5536              : 
    5537              :   /* Allocate enough vector items for a compare_exchange.  */
    5538        30457 :   vec_alloc (params, 6);
    5539              : 
    5540              :   /* Create a compound statement to hold the sequence of statements
    5541              :      with a loop.  */
    5542        30457 :   if (modifycode != NOP_EXPR)
    5543              :     {
    5544        19954 :       compound_stmt = c_begin_compound_stmt (false);
    5545              : 
    5546              :       /* For consistency with build_modify_expr on non-_Atomic,
    5547              :          mark the lhs as read.  Also, it would be very hard to match
    5548              :          such expressions in mark_exp_read.  */
    5549        19954 :       mark_exp_read (lhs);
    5550              :     }
    5551              : 
    5552              :   /* Remove any excess precision (which is only present here in the
    5553              :      case of compound assignments).  */
    5554        30457 :   if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
    5555              :     {
    5556            0 :       gcc_assert (modifycode != NOP_EXPR);
    5557            0 :       rhs = TREE_OPERAND (rhs, 0);
    5558              :     }
    5559        30457 :   rhs_type = TREE_TYPE (rhs);
    5560              : 
    5561              :   /* Fold the RHS if it hasn't already been folded.  */
    5562        30457 :   if (modifycode != NOP_EXPR)
    5563        19954 :     rhs = c_fully_fold (rhs, false, NULL);
    5564              : 
    5565              :   /* Remove the qualifiers for the rest of the expressions and create
    5566              :      the VAL temp variable to hold the RHS.  */
    5567        30457 :   nonatomic_lhs_type = build_qualified_type (lhs_type, TYPE_UNQUALIFIED);
    5568        30457 :   nonatomic_rhs_type = build_qualified_type (rhs_type, TYPE_UNQUALIFIED);
    5569        30457 :   nonatomic_rhs_semantic_type = build_qualified_type (rhs_semantic_type,
    5570              :                                                       TYPE_UNQUALIFIED);
    5571        30457 :   val = create_tmp_var_raw (nonatomic_rhs_type);
    5572        30457 :   TREE_ADDRESSABLE (val) = 1;
    5573        30457 :   suppress_warning (val);
    5574        30457 :   rhs = build4 (TARGET_EXPR, nonatomic_rhs_type, val, rhs, NULL_TREE,
    5575              :                 NULL_TREE);
    5576        30457 :   TREE_SIDE_EFFECTS (rhs) = 1;
    5577        30457 :   SET_EXPR_LOCATION (rhs, loc);
    5578        30457 :   if (modifycode != NOP_EXPR)
    5579        19954 :     add_stmt (rhs);
    5580              : 
    5581              :   /* NOP_EXPR indicates it's a straight store of the RHS. Simply issue
    5582              :      an atomic_store.  */
    5583        19954 :   if (modifycode == NOP_EXPR)
    5584              :     {
    5585        10503 :       compound_stmt = rhs;
    5586              :       /* Build __atomic_store (&lhs, &val, SEQ_CST)  */
    5587        10503 :       rhs = build_unary_op (loc, ADDR_EXPR, val, false);
    5588        10503 :       fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_STORE);
    5589        10503 :       params->quick_push (lhs_addr);
    5590        10503 :       params->quick_push (rhs);
    5591        10503 :       params->quick_push (seq_cst);
    5592        10503 :       func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
    5593              : 
    5594        10503 :       compound_stmt = build2 (COMPOUND_EXPR, void_type_node,
    5595              :                               compound_stmt, func_call);
    5596              : 
    5597              :       /* VAL is the value which was stored, return a COMPOUND_STMT of
    5598              :          the statement and that value.  */
    5599        10503 :       return build2 (COMPOUND_EXPR, nonatomic_lhs_type, compound_stmt, val);
    5600              :     }
    5601              : 
    5602              :   /* Attempt to implement the atomic operation as an __atomic_fetch_* or
    5603              :      __atomic_*_fetch built-in rather than a CAS loop.  atomic_bool type
    5604              :      isn't applicable for such builtins.  ??? Do we want to handle enums?  */
    5605        19954 :   if ((TREE_CODE (lhs_type) == INTEGER_TYPE || POINTER_TYPE_P (lhs_type))
    5606        13941 :       && TREE_CODE (rhs_type) == INTEGER_TYPE)
    5607              :     {
    5608        11713 :       built_in_function fncode;
    5609        11713 :       switch (modifycode)
    5610              :         {
    5611         3075 :         case PLUS_EXPR:
    5612         3075 :         case POINTER_PLUS_EXPR:
    5613         2124 :           fncode = (return_old_p
    5614         3075 :                     ? BUILT_IN_ATOMIC_FETCH_ADD_N
    5615              :                     : BUILT_IN_ATOMIC_ADD_FETCH_N);
    5616              :           break;
    5617         2889 :         case MINUS_EXPR:
    5618         2094 :           fncode = (return_old_p
    5619         2889 :                     ? BUILT_IN_ATOMIC_FETCH_SUB_N
    5620              :                     : BUILT_IN_ATOMIC_SUB_FETCH_N);
    5621              :           break;
    5622          609 :         case BIT_AND_EXPR:
    5623          609 :           fncode = (return_old_p
    5624          609 :                     ? BUILT_IN_ATOMIC_FETCH_AND_N
    5625              :                     : BUILT_IN_ATOMIC_AND_FETCH_N);
    5626              :           break;
    5627          609 :         case BIT_IOR_EXPR:
    5628          609 :           fncode = (return_old_p
    5629          609 :                     ? BUILT_IN_ATOMIC_FETCH_OR_N
    5630              :                     : BUILT_IN_ATOMIC_OR_FETCH_N);
    5631              :           break;
    5632          609 :         case BIT_XOR_EXPR:
    5633          609 :           fncode = (return_old_p
    5634          609 :                     ? BUILT_IN_ATOMIC_FETCH_XOR_N
    5635              :                     : BUILT_IN_ATOMIC_XOR_FETCH_N);
    5636              :           break;
    5637         3922 :         default:
    5638         3922 :           goto cas_loop;
    5639              :         }
    5640              : 
    5641              :       /* We can only use "_1" through "_16" variants of the atomic fetch
    5642              :          built-ins.  */
    5643         7791 :       unsigned HOST_WIDE_INT size = tree_to_uhwi (TYPE_SIZE_UNIT (lhs_type));
    5644         7791 :       if (size != 1 && size != 2 && size != 4 && size != 8 && size != 16)
    5645            0 :         goto cas_loop;
    5646              : 
    5647              :       /* If this is a pointer type, we need to multiply by the size of
    5648              :          the pointer target type.  */
    5649         7791 :       if (POINTER_TYPE_P (lhs_type))
    5650              :         {
    5651         1018 :           if (!COMPLETE_TYPE_P (TREE_TYPE (lhs_type))
    5652              :               /* ??? This would introduce -Wdiscarded-qualifiers
    5653              :                  warning: __atomic_fetch_* expect volatile void *
    5654              :                  type as the first argument.  (Assignments between
    5655              :                  atomic and non-atomic objects are OK.) */
    5656         1018 :               || TYPE_RESTRICT (lhs_type))
    5657           17 :             goto cas_loop;
    5658         1001 :           tree sz = TYPE_SIZE_UNIT (TREE_TYPE (lhs_type));
    5659         1001 :           rhs = fold_build2_loc (loc, MULT_EXPR, ptrdiff_type_node,
    5660              :                                  convert (ptrdiff_type_node, rhs),
    5661              :                                  convert (ptrdiff_type_node, sz));
    5662              :         }
    5663              : 
    5664              :       /* Build __atomic_fetch_* (&lhs, &val, SEQ_CST), or
    5665              :          __atomic_*_fetch (&lhs, &val, SEQ_CST).  */
    5666         7774 :       fndecl = builtin_decl_explicit (fncode);
    5667         7774 :       params->quick_push (lhs_addr);
    5668         7774 :       params->quick_push (rhs);
    5669         7774 :       params->quick_push (seq_cst);
    5670         7774 :       func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
    5671              : 
    5672         7774 :       newval = create_tmp_var_raw (nonatomic_lhs_type);
    5673         7774 :       TREE_ADDRESSABLE (newval) = 1;
    5674         7774 :       suppress_warning (newval);
    5675         7774 :       rhs = build4 (TARGET_EXPR, nonatomic_lhs_type, newval, func_call,
    5676              :                     NULL_TREE, NULL_TREE);
    5677         7774 :       SET_EXPR_LOCATION (rhs, loc);
    5678         7774 :       add_stmt (rhs);
    5679              : 
    5680              :       /* Finish the compound statement.  */
    5681         7774 :       compound_stmt = c_end_compound_stmt (loc, compound_stmt, false);
    5682              : 
    5683              :       /* NEWVAL is the value which was stored, return a COMPOUND_STMT of
    5684              :          the statement and that value.  */
    5685         7774 :       return build2 (COMPOUND_EXPR, nonatomic_lhs_type, compound_stmt, newval);
    5686              :     }
    5687              : 
    5688         8241 : cas_loop:
    5689              :   /* Create the variables and labels required for the op= form.  */
    5690        12180 :   old = create_tmp_var_raw (nonatomic_lhs_type);
    5691        12180 :   old_addr = build_unary_op (loc, ADDR_EXPR, old, false);
    5692        12180 :   TREE_ADDRESSABLE (old) = 1;
    5693        12180 :   suppress_warning (old);
    5694              : 
    5695        12180 :   newval = create_tmp_var_raw (nonatomic_lhs_type);
    5696        12180 :   newval_addr = build_unary_op (loc, ADDR_EXPR, newval, false);
    5697        12180 :   TREE_ADDRESSABLE (newval) = 1;
    5698        12180 :   suppress_warning (newval);
    5699              : 
    5700        12180 :   loop_decl = create_artificial_label (loc);
    5701        12180 :   loop_label = build1 (LABEL_EXPR, void_type_node, loop_decl);
    5702              : 
    5703        12180 :   done_decl = create_artificial_label (loc);
    5704        12180 :   done_label = build1 (LABEL_EXPR, void_type_node, done_decl);
    5705              : 
    5706              :   /* __atomic_load (addr, &old, SEQ_CST).  */
    5707        12180 :   fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_LOAD);
    5708        12180 :   params->quick_push (lhs_addr);
    5709        12180 :   params->quick_push (old_addr);
    5710        12180 :   params->quick_push (seq_cst);
    5711        12180 :   func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
    5712        12180 :   old = build4 (TARGET_EXPR, nonatomic_lhs_type, old, func_call, NULL_TREE,
    5713              :                 NULL_TREE);
    5714        12180 :   add_stmt (old);
    5715        12180 :   params->truncate (0);
    5716              : 
    5717              :   /* Create the expressions for floating-point environment
    5718              :      manipulation, if required.  */
    5719        12180 :   bool need_fenv = (flag_trapping_math
    5720        12180 :                     && (FLOAT_TYPE_P (lhs_type) || FLOAT_TYPE_P (rhs_type)));
    5721        12180 :   tree hold_call = NULL_TREE, clear_call = NULL_TREE, update_call = NULL_TREE;
    5722        12180 :   if (need_fenv)
    5723         7054 :     targetm.atomic_assign_expand_fenv (&hold_call, &clear_call, &update_call);
    5724              : 
    5725        12180 :   if (hold_call)
    5726         7054 :     add_stmt (hold_call);
    5727              : 
    5728              :   /* loop:  */
    5729        12180 :   add_stmt (loop_label);
    5730              : 
    5731              :   /* newval = old + val;  */
    5732        12180 :   if (rhs_type != rhs_semantic_type)
    5733            0 :     val = build1 (EXCESS_PRECISION_EXPR, nonatomic_rhs_semantic_type, val);
    5734        12180 :   rhs = build_binary_op (loc, modifycode,
    5735              :                          convert_lvalue_to_rvalue (loc, old, true, true),
    5736              :                          val, true);
    5737        12180 :   if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
    5738              :     {
    5739            0 :       tree eptype = TREE_TYPE (rhs);
    5740            0 :       rhs = c_fully_fold (TREE_OPERAND (rhs, 0), false, NULL);
    5741            0 :       rhs = build1 (EXCESS_PRECISION_EXPR, eptype, rhs);
    5742              :     }
    5743              :   else
    5744        12180 :     rhs = c_fully_fold (rhs, false, NULL);
    5745        12180 :   rhs = convert_for_assignment (loc, UNKNOWN_LOCATION, nonatomic_lhs_type,
    5746              :                                 rhs, NULL_TREE, ic_assign, false, NULL_TREE,
    5747              :                                 NULL_TREE, 0);
    5748              :   /* The temporary variable for NEWVAL is only gimplified correctly (in
    5749              :      particular, given a DECL_CONTEXT) if used in a TARGET_EXPR.  To avoid
    5750              :      subsequent ICEs in nested function processing after an error, ensure such
    5751              :      a TARGET_EXPR is built even after an error.  */
    5752        12180 :   if (rhs == error_mark_node)
    5753           10 :     rhs = old;
    5754        12180 :   rhs = build4 (TARGET_EXPR, nonatomic_lhs_type, newval, rhs, NULL_TREE,
    5755              :                 NULL_TREE);
    5756        12180 :   SET_EXPR_LOCATION (rhs, loc);
    5757        12180 :   add_stmt (rhs);
    5758              : 
    5759              :   /* if (__atomic_compare_exchange (addr, &old, &new, false, SEQ_CST, SEQ_CST))
    5760              :        goto done;  */
    5761        12180 :   fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_COMPARE_EXCHANGE);
    5762        12180 :   params->quick_push (lhs_addr);
    5763        12180 :   params->quick_push (old_addr);
    5764        12180 :   params->quick_push (newval_addr);
    5765        12180 :   params->quick_push (integer_zero_node);
    5766        12180 :   params->quick_push (seq_cst);
    5767        12180 :   params->quick_push (seq_cst);
    5768        12180 :   func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
    5769              : 
    5770        12180 :   goto_stmt = build1 (GOTO_EXPR, void_type_node, done_decl);
    5771        12180 :   SET_EXPR_LOCATION (goto_stmt, loc);
    5772              : 
    5773        12180 :   stmt = build3 (COND_EXPR, void_type_node, func_call, goto_stmt, NULL_TREE);
    5774        12180 :   SET_EXPR_LOCATION (stmt, loc);
    5775        12180 :   add_stmt (stmt);
    5776              : 
    5777        12180 :   if (clear_call)
    5778         7054 :     add_stmt (clear_call);
    5779              : 
    5780              :   /* goto loop;  */
    5781        12180 :   goto_stmt  = build1 (GOTO_EXPR, void_type_node, loop_decl);
    5782        12180 :   SET_EXPR_LOCATION (goto_stmt, loc);
    5783        12180 :   add_stmt (goto_stmt);
    5784              : 
    5785              :   /* done:  */
    5786        12180 :   add_stmt (done_label);
    5787              : 
    5788        12180 :   if (update_call)
    5789         7054 :     add_stmt (update_call);
    5790              : 
    5791              :   /* Finish the compound statement.  */
    5792        12180 :   compound_stmt = c_end_compound_stmt (loc, compound_stmt, false);
    5793              : 
    5794              :   /* NEWVAL is the value that was successfully stored, return a
    5795              :      COMPOUND_EXPR of the statement and the appropriate value.  */
    5796        23787 :   return build2 (COMPOUND_EXPR, nonatomic_lhs_type, compound_stmt,
    5797        12180 :                  return_old_p ? old : newval);
    5798              : }
    5799              : 
    5800              : /* Construct and perhaps optimize a tree representation
    5801              :    for a unary operation.  CODE, a tree_code, specifies the operation
    5802              :    and XARG is the operand.
    5803              :    For any CODE other than ADDR_EXPR, NOCONVERT suppresses the default
    5804              :    promotions (such as from short to int).
    5805              :    For ADDR_EXPR, the default promotions are not applied; NOCONVERT allows
    5806              :    non-lvalues; this is only used to handle conversion of non-lvalue arrays
    5807              :    to pointers in C99.
    5808              : 
    5809              :    LOCATION is the location of the operator.  */
    5810              : 
    5811              : tree
    5812     62629537 : build_unary_op (location_t location, enum tree_code code, tree xarg,
    5813              :                 bool noconvert)
    5814              : {
    5815              :   /* No default_conversion here.  It causes trouble for ADDR_EXPR.  */
    5816     62629537 :   tree arg = xarg;
    5817     62629537 :   tree argtype = NULL_TREE;
    5818     62629537 :   enum tree_code typecode;
    5819     62629537 :   tree val;
    5820     62629537 :   tree ret = error_mark_node;
    5821     62629537 :   tree eptype = NULL_TREE;
    5822     62629537 :   const char *invalid_op_diag;
    5823              : 
    5824              :   /* If ARG is wrapped in a call to .ACCESS_WITH_SIZE — created when the
    5825              :      C parser rvalue-converts a counted_by-annotated member access (see
    5826              :      PR123569) — unwrap it here.  Unary operators that consume an rvalue
    5827              :      (!, -, +) read the value itself rather than dereferencing into the
    5828              :      pointed-to data, so the bounds-checking wrapper is unnecessary and
    5829              :      would otherwise reach build_unary_op while it is not equipped to
    5830              :      handle the wrapped form.  PR123569 fixed the ++/-- side of this by
    5831              :      suppressing wrapper creation in the parser; the rvalue-consuming
    5832              :      ops still receive the wrapper and need to strip it here.  */
    5833     62629537 :   if (is_access_with_size_p (arg))
    5834            1 :     xarg = arg = get_ref_from_access_with_size (arg);
    5835              : 
    5836     62629537 :   gcc_checking_assert (!is_access_with_size_p (arg));
    5837              : 
    5838     62629537 :   bool int_operands = EXPR_INT_CONST_OPERANDS (xarg);
    5839              :   if (int_operands)
    5840      6751135 :     arg = remove_c_maybe_const_expr (arg);
    5841              : 
    5842     62629537 :   if (code != ADDR_EXPR)
    5843      8845338 :     arg = require_complete_type (location, arg);
    5844              : 
    5845     62629537 :   typecode = TREE_CODE (TREE_TYPE (arg));
    5846     62629537 :   if (typecode == ERROR_MARK)
    5847           74 :     return error_mark_node;
    5848     62629463 :   if (typecode == ENUMERAL_TYPE || typecode == BOOLEAN_TYPE)
    5849        32408 :     typecode = INTEGER_TYPE;
    5850              : 
    5851    125258926 :   if ((invalid_op_diag
    5852     62629463 :        = targetm.invalid_unary_op (code, TREE_TYPE (xarg))))
    5853              :     {
    5854            0 :       error_at (location, invalid_op_diag);
    5855            0 :       return error_mark_node;
    5856              :     }
    5857              : 
    5858     62629463 :   if (TREE_CODE (arg) == EXCESS_PRECISION_EXPR)
    5859              :     {
    5860          251 :       eptype = TREE_TYPE (arg);
    5861          251 :       arg = TREE_OPERAND (arg, 0);
    5862              :     }
    5863              : 
    5864     62629463 :   switch (code)
    5865              :     {
    5866        28807 :     case CONVERT_EXPR:
    5867              :       /* This is used for unary plus, because a CONVERT_EXPR
    5868              :          is enough to prevent anybody from looking inside for
    5869              :          associativity, but won't generate any code.  */
    5870        28812 :       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
    5871           53 :             || typecode == FIXED_POINT_TYPE || typecode == COMPLEX_TYPE
    5872           50 :             || typecode == BITINT_TYPE
    5873            5 :             || gnu_vector_type_p (TREE_TYPE (arg))))
    5874              :         {
    5875            1 :           error_at (location, "wrong type argument to unary plus");
    5876            1 :           return error_mark_node;
    5877              :         }
    5878        28806 :       else if (!noconvert)
    5879        28806 :         arg = default_conversion (arg);
    5880        28806 :       arg = non_lvalue_loc (location, arg);
    5881        28806 :       break;
    5882              : 
    5883      6989717 :     case NEGATE_EXPR:
    5884      7439972 :       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
    5885       486991 :             || typecode == FIXED_POINT_TYPE || typecode == COMPLEX_TYPE
    5886       455723 :             || typecode == BITINT_TYPE
    5887       450255 :             || gnu_vector_type_p (TREE_TYPE (arg))))
    5888              :         {
    5889            1 :           error_at (location, "wrong type argument to unary minus");
    5890            1 :           return error_mark_node;
    5891              :         }
    5892      6989716 :       else if (!noconvert)
    5893      6989665 :         arg = default_conversion (arg);
    5894              :       break;
    5895              : 
    5896       297164 :     case BIT_NOT_EXPR:
    5897              :       /* ~ works on integer types and non float vectors. */
    5898       297164 :       if (typecode == INTEGER_TYPE
    5899       297164 :           || typecode == BITINT_TYPE
    5900       297164 :           || (gnu_vector_type_p (TREE_TYPE (arg))
    5901         2132 :               && !VECTOR_FLOAT_TYPE_P (TREE_TYPE (arg))))
    5902              :         {
    5903              :           tree e = arg;
    5904              : 
    5905              :           /* Warn if the expression has boolean value.  */
    5906       296565 :           while (TREE_CODE (e) == COMPOUND_EXPR)
    5907           11 :             e = TREE_OPERAND (e, 1);
    5908              : 
    5909       593092 :           if ((C_BOOLEAN_TYPE_P (TREE_TYPE (arg))
    5910       593092 :                || truth_value_p (TREE_CODE (e))))
    5911              :             {
    5912          149 :               auto_diagnostic_group d;
    5913          149 :               if (warning_at (location, OPT_Wbool_operation,
    5914              :                                 "%<~%> on a boolean expression"))
    5915              :                 {
    5916           12 :                   gcc_rich_location richloc (location);
    5917           12 :                   richloc.add_fixit_insert_before (location, "!");
    5918           12 :                   inform (&richloc, "did you mean to use logical not?");
    5919           12 :                 }
    5920          149 :             }
    5921       296554 :           if (!noconvert)
    5922       296551 :             arg = default_conversion (arg);
    5923              :         }
    5924          610 :       else if (typecode == COMPLEX_TYPE)
    5925              :         {
    5926          605 :           code = CONJ_EXPR;
    5927          605 :           pedwarn (location, OPT_Wpedantic,
    5928              :                    "ISO C does not support %<~%> for complex conjugation");
    5929          605 :           if (!noconvert)
    5930          605 :             arg = default_conversion (arg);
    5931              :         }
    5932              :       else
    5933              :         {
    5934            5 :           error_at (location, "wrong type argument to bit-complement");
    5935            5 :           return error_mark_node;
    5936              :         }
    5937              :       break;
    5938              : 
    5939            3 :     case ABS_EXPR:
    5940            3 :       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE))
    5941              :         {
    5942            0 :           error_at (location, "wrong type argument to abs");
    5943            0 :           return error_mark_node;
    5944              :         }
    5945            3 :       else if (!noconvert)
    5946            0 :         arg = default_conversion (arg);
    5947              :       break;
    5948              : 
    5949            7 :     case ABSU_EXPR:
    5950            7 :       if (!(typecode == INTEGER_TYPE))
    5951              :         {
    5952            0 :           error_at (location, "wrong type argument to absu");
    5953            0 :           return error_mark_node;
    5954              :         }
    5955            7 :       else if (!noconvert)
    5956            0 :         arg = default_conversion (arg);
    5957              :       break;
    5958              : 
    5959            0 :     case CONJ_EXPR:
    5960              :       /* Conjugating a real value is a no-op, but allow it anyway.  */
    5961            0 :       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
    5962              :             || typecode == COMPLEX_TYPE))
    5963              :         {
    5964            0 :           error_at (location, "wrong type argument to conjugation");
    5965            0 :           return error_mark_node;
    5966              :         }
    5967            0 :       else if (!noconvert)
    5968            0 :         arg = default_conversion (arg);
    5969              :       break;
    5970              : 
    5971       378934 :     case TRUTH_NOT_EXPR:
    5972       378934 :       if (typecode != INTEGER_TYPE && typecode != FIXED_POINT_TYPE
    5973         7184 :           && typecode != REAL_TYPE && typecode != POINTER_TYPE
    5974           21 :           && typecode != COMPLEX_TYPE && typecode != NULLPTR_TYPE
    5975           18 :           && typecode != BITINT_TYPE)
    5976              :         {
    5977           10 :           error_at (location,
    5978              :                     "wrong type argument to unary exclamation mark");
    5979           10 :           return error_mark_node;
    5980              :         }
    5981       378924 :       if (int_operands)
    5982              :         {
    5983       139879 :           arg = c_objc_common_truthvalue_conversion (location, xarg);
    5984       139879 :           arg = remove_c_maybe_const_expr (arg);
    5985              :         }
    5986              :       else
    5987       239045 :         arg = c_objc_common_truthvalue_conversion (location, arg);
    5988       378924 :       ret = invert_truthvalue_loc (location, arg);
    5989       378924 :       eptype = NULL_TREE;
    5990              :       /* If the TRUTH_NOT_EXPR has been folded, reset the location.  */
    5991       378924 :       if (EXPR_P (ret) && EXPR_HAS_LOCATION (ret))
    5992       238638 :         location = EXPR_LOCATION (ret);
    5993       378924 :       goto return_build_unary_op;
    5994              : 
    5995       203107 :     case REALPART_EXPR:
    5996       203107 :     case IMAGPART_EXPR:
    5997       203107 :       ret = build_real_imag_expr (location, code, arg);
    5998       203107 :       if (ret == error_mark_node)
    5999              :         return error_mark_node;
    6000       203099 :       if (eptype && TREE_CODE (eptype) == COMPLEX_TYPE)
    6001            2 :         eptype = TREE_TYPE (eptype);
    6002       203099 :       goto return_build_unary_op;
    6003              : 
    6004       947554 :     case PREINCREMENT_EXPR:
    6005       947554 :     case POSTINCREMENT_EXPR:
    6006       947554 :     case PREDECREMENT_EXPR:
    6007       947554 :     case POSTDECREMENT_EXPR:
    6008              : 
    6009       947554 :       if (TREE_CODE (arg) == C_MAYBE_CONST_EXPR)
    6010              :         {
    6011            2 :           tree inner = build_unary_op (location, code,
    6012            2 :                                        C_MAYBE_CONST_EXPR_EXPR (arg),
    6013              :                                        noconvert);
    6014            2 :           if (inner == error_mark_node)
    6015              :             return error_mark_node;
    6016            4 :           ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner),
    6017            2 :                         C_MAYBE_CONST_EXPR_PRE (arg), inner);
    6018            2 :           gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (arg));
    6019            2 :           C_MAYBE_CONST_EXPR_NON_CONST (ret) = 1;
    6020            2 :           goto return_build_unary_op;
    6021              :         }
    6022              : 
    6023              :       /* Complain about anything that is not a true lvalue.  In
    6024              :          Objective-C, skip this check for property_refs.  */
    6025       947552 :       if (!objc_is_property_ref (arg)
    6026      1895104 :           && !lvalue_or_else (location,
    6027       947552 :                               arg, ((code == PREINCREMENT_EXPR
    6028       947552 :                                      || code == POSTINCREMENT_EXPR)
    6029              :                                     ? lv_increment
    6030              :                                     : lv_decrement)))
    6031           22 :         return error_mark_node;
    6032              : 
    6033       947530 :       if (warn_cxx_compat && TREE_CODE (TREE_TYPE (arg)) == ENUMERAL_TYPE)
    6034              :         {
    6035            4 :           if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
    6036            2 :             warning_at (location, OPT_Wc___compat,
    6037              :                         "increment of enumeration value is invalid in C++");
    6038              :           else
    6039            2 :             warning_at (location, OPT_Wc___compat,
    6040              :                         "decrement of enumeration value is invalid in C++");
    6041              :         }
    6042              : 
    6043       947530 :       if (C_BOOLEAN_TYPE_P (TREE_TYPE (arg)))
    6044              :         {
    6045          664 :           if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
    6046          328 :             warning_at (location, OPT_Wbool_operation,
    6047              :                         "increment of a boolean expression");
    6048              :           else
    6049          336 :             warning_at (location, OPT_Wbool_operation,
    6050              :                         "decrement of a boolean expression");
    6051              :         }
    6052              : 
    6053              :       /* Ensure the argument is fully folded inside any SAVE_EXPR.  */
    6054       947530 :       arg = c_fully_fold (arg, false, NULL, true);
    6055              : 
    6056       947530 :       bool atomic_op;
    6057       947530 :       atomic_op = really_atomic_lvalue (arg);
    6058              : 
    6059              :       /* Increment or decrement the real part of the value,
    6060              :          and don't change the imaginary part.  */
    6061       947530 :       if (typecode == COMPLEX_TYPE)
    6062              :         {
    6063           57 :           tree real, imag;
    6064              : 
    6065           57 :           pedwarn_c23 (location, OPT_Wpedantic,
    6066              :                        "ISO C does not support %<++%> and %<--%> on complex "
    6067              :                        "types before C2Y");
    6068              : 
    6069           57 :           if (!atomic_op)
    6070              :             {
    6071           53 :               arg = stabilize_reference (arg);
    6072           53 :               real = build_unary_op (EXPR_LOCATION (arg), REALPART_EXPR, arg,
    6073              :                                      true);
    6074           53 :               imag = build_unary_op (EXPR_LOCATION (arg), IMAGPART_EXPR, arg,
    6075              :                                      true);
    6076           53 :               real = build_unary_op (EXPR_LOCATION (arg), code, real, true);
    6077           53 :               if (real == error_mark_node || imag == error_mark_node)
    6078              :                 return error_mark_node;
    6079           53 :               ret = build2 (COMPLEX_EXPR, TREE_TYPE (arg),
    6080              :                             real, imag);
    6081           53 :               goto return_build_unary_op;
    6082              :             }
    6083              :         }
    6084              : 
    6085              :       /* Report invalid types.  */
    6086              : 
    6087       947477 :       if (typecode != POINTER_TYPE && typecode != FIXED_POINT_TYPE
    6088       714506 :           && typecode != INTEGER_TYPE && typecode != REAL_TYPE
    6089          208 :           && typecode != COMPLEX_TYPE && typecode != BITINT_TYPE
    6090       947533 :           && !gnu_vector_type_p (TREE_TYPE (arg)))
    6091              :         {
    6092            5 :           if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
    6093            3 :             error_at (location, "wrong type argument to increment");
    6094              :           else
    6095            2 :             error_at (location, "wrong type argument to decrement");
    6096              : 
    6097            5 :           return error_mark_node;
    6098              :         }
    6099              : 
    6100       947472 :       {
    6101       947472 :         tree inc;
    6102              : 
    6103       947472 :         argtype = TREE_TYPE (arg);
    6104              : 
    6105              :         /* Compute the increment.  */
    6106              : 
    6107       947472 :         if (typecode == POINTER_TYPE)
    6108              :           {
    6109              :             /* If pointer target is an incomplete type,
    6110              :                we just cannot know how to do the arithmetic.  */
    6111       232971 :             if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (argtype)))
    6112              :               {
    6113           27 :                 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
    6114           17 :                   error_at (location,
    6115              :                             "increment of pointer to an incomplete type %qT",
    6116           17 :                             TREE_TYPE (argtype));
    6117              :                 else
    6118           10 :                   error_at (location,
    6119              :                             "decrement of pointer to an incomplete type %qT",
    6120           10 :                             TREE_TYPE (argtype));
    6121              :               }
    6122       232944 :             else if (TREE_CODE (TREE_TYPE (argtype)) == FUNCTION_TYPE
    6123       232944 :                      || VOID_TYPE_P (TREE_TYPE (argtype)))
    6124              :               {
    6125           10 :                 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
    6126            6 :                   pedwarn (location, OPT_Wpointer_arith,
    6127              :                            "wrong type argument to increment");
    6128              :                 else
    6129            4 :                   pedwarn (location, OPT_Wpointer_arith,
    6130              :                            "wrong type argument to decrement");
    6131              :               }
    6132              :             else
    6133       465868 :               verify_type_context (location, TCTX_POINTER_ARITH,
    6134       232934 :                                    TREE_TYPE (argtype));
    6135              : 
    6136       232971 :             inc = c_size_in_bytes (TREE_TYPE (argtype));
    6137       232971 :             inc = convert_to_ptrofftype_loc (location, inc);
    6138              :           }
    6139       714501 :         else if (FRACT_MODE_P (TYPE_MODE (argtype)))
    6140              :           {
    6141              :             /* For signed fract types, we invert ++ to -- or
    6142              :                -- to ++, and change inc from 1 to -1, because
    6143              :                it is not possible to represent 1 in signed fract constants.
    6144              :                For unsigned fract types, the result always overflows and
    6145              :                we get an undefined (original) or the maximum value.  */
    6146            0 :             if (code == PREINCREMENT_EXPR)
    6147              :               code = PREDECREMENT_EXPR;
    6148              :             else if (code == PREDECREMENT_EXPR)
    6149              :               code = PREINCREMENT_EXPR;
    6150              :             else if (code == POSTINCREMENT_EXPR)
    6151              :               code = POSTDECREMENT_EXPR;
    6152              :             else /* code == POSTDECREMENT_EXPR  */
    6153            0 :               code = POSTINCREMENT_EXPR;
    6154              : 
    6155            0 :             inc = integer_minus_one_node;
    6156            0 :             inc = convert (argtype, inc);
    6157              :           }
    6158              :         else
    6159              :           {
    6160       714450 :             inc = VECTOR_TYPE_P (argtype)
    6161       714501 :               ? build_one_cst (argtype)
    6162              :               : integer_one_node;
    6163       714501 :             inc = convert (argtype, inc);
    6164              :           }
    6165              : 
    6166              :         /* If 'arg' is an Objective-C PROPERTY_REF expression, then we
    6167              :            need to ask Objective-C to build the increment or decrement
    6168              :            expression for it.  */
    6169       947472 :         if (objc_is_property_ref (arg))
    6170            0 :           return objc_build_incr_expr_for_property_ref (location, code,
    6171           20 :                                                         arg, inc);
    6172              : 
    6173              :         /* Report a read-only lvalue.  */
    6174       947472 :         if (TYPE_READONLY (argtype))
    6175              :           {
    6176           20 :             readonly_error (location, arg,
    6177           20 :                             ((code == PREINCREMENT_EXPR
    6178           20 :                               || code == POSTINCREMENT_EXPR)
    6179              :                              ? lv_increment : lv_decrement));
    6180           20 :             return error_mark_node;
    6181              :           }
    6182       947452 :         else if (TREE_READONLY (arg))
    6183            4 :           readonly_warning (arg,
    6184            4 :                             ((code == PREINCREMENT_EXPR
    6185            4 :                               || code == POSTINCREMENT_EXPR)
    6186              :                              ? lv_increment : lv_decrement));
    6187              : 
    6188              :         /* If the argument is atomic, use the special code sequences for
    6189              :            atomic compound assignment.  */
    6190       947452 :         if (atomic_op)
    6191              :           {
    6192         4469 :             arg = stabilize_reference (arg);
    6193         8938 :             ret = build_atomic_assign (location, arg,
    6194         4469 :                                        ((code == PREINCREMENT_EXPR
    6195         4469 :                                          || code == POSTINCREMENT_EXPR)
    6196              :                                         ? PLUS_EXPR
    6197              :                                         : MINUS_EXPR),
    6198         4469 :                                        (FRACT_MODE_P (TYPE_MODE (argtype))
    6199              :                                         ? inc
    6200              :                                         : integer_one_node),
    6201              :                                        (code == POSTINCREMENT_EXPR
    6202         4469 :                                         || code == POSTDECREMENT_EXPR));
    6203       947452 :             goto return_build_unary_op;
    6204              :           }
    6205              : 
    6206       942983 :         tree true_res;
    6207       942983 :         if (c_hardbool_type_attr (TREE_TYPE (arg), NULL, &true_res))
    6208              :           {
    6209          364 :             tree larg = stabilize_reference (arg);
    6210          364 :             tree sarg = save_expr (larg);
    6211          364 :             switch (code)
    6212              :               {
    6213           91 :               case PREINCREMENT_EXPR:
    6214           91 :                 val = build2 (MODIFY_EXPR, TREE_TYPE (larg), larg, true_res);
    6215           91 :                 val = build2 (COMPOUND_EXPR, TREE_TYPE (larg), sarg, val);
    6216           91 :                 break;
    6217           91 :               case POSTINCREMENT_EXPR:
    6218           91 :                 val = build2 (MODIFY_EXPR, TREE_TYPE (larg), larg, true_res);
    6219           91 :                 val = build2 (COMPOUND_EXPR, TREE_TYPE (larg), val, sarg);
    6220           91 :                 val = build2 (COMPOUND_EXPR, TREE_TYPE (larg), sarg, val);
    6221           91 :                 break;
    6222           91 :               case PREDECREMENT_EXPR:
    6223           91 :                 {
    6224           91 :                   tree rarg = convert_lvalue_to_rvalue (location, sarg,
    6225              :                                                         true, true);
    6226           91 :                   rarg = invert_truthvalue_loc (location, rarg);
    6227           91 :                   rarg = convert (TREE_TYPE (sarg), rarg);
    6228           91 :                   val = build2 (MODIFY_EXPR, TREE_TYPE (larg), larg, rarg);
    6229              :                 }
    6230           91 :                 break;
    6231           91 :               case POSTDECREMENT_EXPR:
    6232           91 :                 {
    6233           91 :                   tree rarg = convert_lvalue_to_rvalue (location, sarg,
    6234              :                                                         true, true);
    6235           91 :                   rarg = invert_truthvalue_loc (location, rarg);
    6236           91 :                   tree iarg = convert (TREE_TYPE (larg), rarg);
    6237           91 :                   val = build2 (MODIFY_EXPR, TREE_TYPE (larg), larg, iarg);
    6238           91 :                   val = build2 (COMPOUND_EXPR, TREE_TYPE (larg), val, sarg);
    6239           91 :                   val = build2 (COMPOUND_EXPR, TREE_TYPE (larg), sarg, val);
    6240              :                 }
    6241           91 :                 break;
    6242              :               default:
    6243              :                 gcc_unreachable ();
    6244              :               }
    6245          364 :             TREE_SIDE_EFFECTS (val) = 1;
    6246              :           }
    6247       942619 :         else if (C_BOOLEAN_TYPE_P (TREE_TYPE (arg)))
    6248           64 :           val = boolean_increment (code, arg);
    6249              :         else
    6250       942555 :           val = build2 (code, TREE_TYPE (arg), arg, inc);
    6251       942983 :         TREE_SIDE_EFFECTS (val) = 1;
    6252       942983 :         if (TYPE_QUALS (TREE_TYPE (val)) != TYPE_UNQUALIFIED)
    6253         3955 :           TREE_TYPE (val) = c_build_qualified_type (TREE_TYPE (val),
    6254              :                                                     TYPE_UNQUALIFIED);
    6255       942983 :         ret = val;
    6256       942983 :         goto return_build_unary_op;
    6257              :       }
    6258              : 
    6259     53784158 :     case ADDR_EXPR:
    6260              :       /* Note that this operation never does default_conversion.  */
    6261              : 
    6262              :       /* The operand of unary '&' must be an lvalue (which excludes
    6263              :          expressions of type void), or, in C99, the result of a [] or
    6264              :          unary '*' operator.  */
    6265     53784158 :       if (VOID_TYPE_P (TREE_TYPE (arg))
    6266           25 :           && TYPE_QUALS (TREE_TYPE (arg)) == TYPE_UNQUALIFIED
    6267     53784177 :           && (!INDIRECT_REF_P (arg) || !flag_isoc99))
    6268           18 :         pedwarn (location, 0, "taking address of expression of type %<void%>");
    6269              : 
    6270              :       /* Let &* cancel out to simplify resulting code.  */
    6271     53784158 :       if (INDIRECT_REF_P (arg))
    6272              :         {
    6273              :           /* Don't let this be an lvalue.  */
    6274        22446 :           if (lvalue_p (TREE_OPERAND (arg, 0)))
    6275        16920 :             return non_lvalue_loc (location, TREE_OPERAND (arg, 0));
    6276         5526 :           ret = TREE_OPERAND (arg, 0);
    6277         5526 :           goto return_build_unary_op;
    6278              :         }
    6279              : 
    6280              :       /* Anything not already handled and not a true memory reference
    6281              :          or a non-lvalue array is an error.  */
    6282     53761712 :       if (typecode != FUNCTION_TYPE && !noconvert
    6283     53761712 :           && !lvalue_or_else (location, arg, lv_addressof))
    6284           17 :         return error_mark_node;
    6285              : 
    6286              :       /* Move address operations inside C_MAYBE_CONST_EXPR to simplify
    6287              :          folding later.  */
    6288     53761695 :       if (TREE_CODE (arg) == C_MAYBE_CONST_EXPR)
    6289              :         {
    6290           14 :           tree inner = build_unary_op (location, code,
    6291           14 :                                        C_MAYBE_CONST_EXPR_EXPR (arg),
    6292              :                                        noconvert);
    6293           28 :           ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner),
    6294           14 :                         C_MAYBE_CONST_EXPR_PRE (arg), inner);
    6295           14 :           gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (arg));
    6296           14 :           C_MAYBE_CONST_EXPR_NON_CONST (ret)
    6297           14 :             = C_MAYBE_CONST_EXPR_NON_CONST (arg);
    6298           14 :           goto return_build_unary_op;
    6299              :         }
    6300              : 
    6301              :       /* Ordinary case; arg is a COMPONENT_REF or a decl.  */
    6302              : 
    6303     53761681 :       argtype = TREE_TYPE (arg);
    6304              : 
    6305              :       /* If the lvalue is const or volatile, merge that into the type
    6306              :          to which the address will point.  This is only needed
    6307              :          for function types.  */
    6308     53761681 :       if ((DECL_P (arg) || REFERENCE_CLASS_P (arg))
    6309     53268407 :           && (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg))
    6310     84882338 :           && TREE_CODE (argtype) == FUNCTION_TYPE)
    6311              :         {
    6312     31040023 :           int orig_quals = TYPE_QUALS (strip_array_types (argtype));
    6313     31040023 :           int quals = orig_quals;
    6314              : 
    6315     31040023 :           if (TREE_READONLY (arg))
    6316     30656560 :             quals |= TYPE_QUAL_CONST;
    6317     31040023 :           if (TREE_THIS_VOLATILE (arg))
    6318       384438 :             quals |= TYPE_QUAL_VOLATILE;
    6319              : 
    6320     31040023 :           argtype = c_build_qualified_type (argtype, quals);
    6321              :         }
    6322              : 
    6323     53761681 :       switch (TREE_CODE (arg))
    6324              :         {
    6325        65946 :         case COMPONENT_REF:
    6326        65946 :           if (DECL_C_BIT_FIELD (TREE_OPERAND (arg, 1)))
    6327              :             {
    6328            8 :               error_at (location, "cannot take address of bit-field %qD",
    6329            8 :                         TREE_OPERAND (arg, 1));
    6330            8 :               return error_mark_node;
    6331              :             }
    6332              : 
    6333              :           /* fall through */
    6334              : 
    6335       141775 :         case ARRAY_REF:
    6336       141775 :           if (TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (TREE_OPERAND (arg, 0))))
    6337              :             {
    6338           78 :               if (!AGGREGATE_TYPE_P (TREE_TYPE (arg))
    6339            7 :                   && !POINTER_TYPE_P (TREE_TYPE (arg))
    6340           75 :                   && !VECTOR_TYPE_P (TREE_TYPE (arg)))
    6341              :                 {
    6342            6 :                   error_at (location, "cannot take address of scalar with "
    6343              :                             "reverse storage order");
    6344            6 :                   return error_mark_node;
    6345              :                 }
    6346              : 
    6347           63 :               if (TREE_CODE (TREE_TYPE (arg)) == ARRAY_TYPE
    6348           63 :                   && TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (arg)))
    6349           58 :                 warning_at (location, OPT_Wscalar_storage_order,
    6350              :                             "address of array with reverse scalar storage "
    6351              :                             "order requested");
    6352              :             }
    6353              : 
    6354     53761667 :         default:
    6355     53761667 :           break;
    6356              :         }
    6357              : 
    6358     53761667 :       if (!c_mark_addressable (arg))
    6359           20 :         return error_mark_node;
    6360              : 
    6361     53761647 :       gcc_assert (TREE_CODE (arg) != COMPONENT_REF
    6362              :                   || !DECL_C_BIT_FIELD (TREE_OPERAND (arg, 1)));
    6363              : 
    6364     53761647 :       argtype = c_build_pointer_type (argtype);
    6365              : 
    6366              :       /* ??? Cope with user tricks that amount to offsetof.  Delete this
    6367              :          when we have proper support for integer constant expressions.  */
    6368     53761647 :       val = get_base_address (arg);
    6369     53761647 :       if (val && INDIRECT_REF_P (val)
    6370     53785991 :           && TREE_CONSTANT (TREE_OPERAND (val, 0)))
    6371              :         {
    6372          540 :           ret = fold_offsetof (arg, argtype);
    6373          540 :           goto return_build_unary_op;
    6374              :         }
    6375              : 
    6376     53761107 :       val = build1 (ADDR_EXPR, argtype, arg);
    6377              : 
    6378     53761107 :       ret = val;
    6379     53761107 :       goto return_build_unary_op;
    6380              : 
    6381           12 :     case PAREN_EXPR:
    6382           12 :       ret = build1 (code, TREE_TYPE (arg), arg);
    6383           12 :       goto return_build_unary_op;
    6384              : 
    6385            0 :     default:
    6386            0 :       gcc_unreachable ();
    6387              :     }
    6388              : 
    6389      7315691 :   if (argtype == NULL_TREE)
    6390      7315691 :     argtype = TREE_TYPE (arg);
    6391      7315691 :   if (TREE_CODE (arg) == INTEGER_CST)
    6392      6606913 :     ret = (require_constant_value
    6393      6606913 :            ? fold_build1_initializer_loc (location, code, argtype, arg)
    6394      6587950 :            : fold_build1_loc (location, code, argtype, arg));
    6395              :   else
    6396       708778 :     ret = build1 (code, argtype, arg);
    6397     62612420 :  return_build_unary_op:
    6398     62612420 :   gcc_assert (ret != error_mark_node);
    6399      6751611 :   if (TREE_CODE (ret) == INTEGER_CST && !TREE_OVERFLOW (ret)
    6400     69364022 :       && !(TREE_CODE (xarg) == INTEGER_CST && !TREE_OVERFLOW (xarg)))
    6401          562 :     ret = build1 (NOP_EXPR, TREE_TYPE (ret), ret);
    6402     62611858 :   else if (TREE_CODE (ret) != INTEGER_CST && int_operands)
    6403           74 :     ret = note_integer_operands (ret);
    6404     62612420 :   if (eptype)
    6405          244 :     ret = build1 (EXCESS_PRECISION_EXPR, eptype, ret);
    6406     62612420 :   protected_set_expr_location (ret, location);
    6407     62612420 :   return ret;
    6408              : }
    6409              : 
    6410              : /* Return nonzero if REF is an lvalue valid for this language.
    6411              :    Lvalues can be assigned, unless their type has TYPE_READONLY.
    6412              :    Lvalues can have their address taken, unless they have C_DECL_REGISTER.  */
    6413              : 
    6414              : bool
    6415    183508495 : lvalue_p (const_tree ref)
    6416              : {
    6417    185020014 :   const enum tree_code code = TREE_CODE (ref);
    6418              : 
    6419    185020014 :   switch (code)
    6420              :     {
    6421      1486502 :     case REALPART_EXPR:
    6422      1486502 :     case IMAGPART_EXPR:
    6423      1486502 :     case COMPONENT_REF:
    6424      1486502 :       return lvalue_p (TREE_OPERAND (ref, 0));
    6425              : 
    6426        25017 :     case C_MAYBE_CONST_EXPR:
    6427        25017 :       return lvalue_p (TREE_OPERAND (ref, 1));
    6428              : 
    6429              :     case COMPOUND_LITERAL_EXPR:
    6430              :     case STRING_CST:
    6431              :       return true;
    6432              : 
    6433     25764881 :     case MEM_REF:
    6434     25764881 :     case TARGET_MEM_REF:
    6435              :       /* MEM_REFs can appear from -fgimple parsing or folding, so allow them
    6436              :          here as well.  */
    6437     25764881 :     case INDIRECT_REF:
    6438     25764881 :     case ARRAY_REF:
    6439     25764881 :     case VAR_DECL:
    6440     25764881 :     case PARM_DECL:
    6441     25764881 :     case RESULT_DECL:
    6442     25764881 :     case ERROR_MARK:
    6443     25764881 :       return (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE
    6444     25764881 :               && TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE);
    6445              : 
    6446            6 :     case BIND_EXPR:
    6447            6 :       return TREE_CODE (TREE_TYPE (ref)) == ARRAY_TYPE;
    6448              : 
    6449      7247699 :     case CALL_EXPR:
    6450      7247699 :       return is_access_with_size_p (ref);
    6451              : 
    6452              :     default:
    6453              :       return false;
    6454              :     }
    6455              : }
    6456              : 
    6457              : /* Give a warning for storing in something that is read-only in GCC
    6458              :    terms but not const in ISO C terms.  */
    6459              : 
    6460              : static void
    6461            5 : readonly_warning (tree arg, enum lvalue_use use)
    6462              : {
    6463            5 :   switch (use)
    6464              :     {
    6465            1 :     case lv_assign:
    6466            1 :       warning (0, "assignment of read-only location %qE", arg);
    6467            1 :       break;
    6468            2 :     case lv_increment:
    6469            2 :       warning (0, "increment of read-only location %qE", arg);
    6470            2 :       break;
    6471            2 :     case lv_decrement:
    6472            2 :       warning (0, "decrement of read-only location %qE", arg);
    6473            2 :       break;
    6474            0 :     default:
    6475            0 :       gcc_unreachable ();
    6476              :     }
    6477            5 :   return;
    6478              : }
    6479              : 
    6480              : 
    6481              : /* Return nonzero if REF is an lvalue valid for this language;
    6482              :    otherwise, print an error message and return zero.  USE says
    6483              :    how the lvalue is being used and so selects the error message.
    6484              :    LOCATION is the location at which any error should be reported.  */
    6485              : 
    6486              : static int
    6487      4770216 : lvalue_or_else (location_t loc, const_tree ref, enum lvalue_use use)
    6488              : {
    6489      4770216 :   int win = lvalue_p (ref);
    6490              : 
    6491      4770216 :   if (!win)
    6492           75 :     lvalue_error (loc, use);
    6493              : 
    6494      4770216 :   return win;
    6495              : }
    6496              : 
    6497              : /* Mark EXP saying that we need to be able to take the
    6498              :    address of it; it should not be allocated in a register.
    6499              :    Returns true if successful.  ARRAY_REF_P is true if this
    6500              :    is for ARRAY_REF construction - in that case we don't want
    6501              :    to look through VIEW_CONVERT_EXPR from VECTOR_TYPE to ARRAY_TYPE,
    6502              :    it is fine to use ARRAY_REFs for vector subscripts on vector
    6503              :    register variables.  If OVERRIDE_REGISTER, clear DECL_REGISTER rather
    6504              :    than producing an error for taking the address of a register.  */
    6505              : 
    6506              : bool
    6507     54314777 : c_mark_addressable (tree exp, bool array_ref_p, bool override_register)
    6508              : {
    6509     54314777 :   tree x = exp;
    6510              : 
    6511     54897792 :   while (1)
    6512     54897792 :     switch (TREE_CODE (x))
    6513              :       {
    6514        10351 :       case VIEW_CONVERT_EXPR:
    6515        10351 :         if (array_ref_p
    6516        10241 :             && TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
    6517        20592 :             && VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (x, 0))))
    6518              :           return true;
    6519          110 :         x = TREE_OPERAND (x, 0);
    6520          110 :         break;
    6521              : 
    6522       397109 :       case COMPONENT_REF:
    6523       397109 :         if (DECL_C_BIT_FIELD (TREE_OPERAND (x, 1)))
    6524              :           {
    6525            6 :             error ("cannot take address of bit-field %qD",
    6526            3 :                    TREE_OPERAND (x, 1));
    6527            3 :             return false;
    6528              :           }
    6529              :         /* FALLTHRU */
    6530       582905 :       case ADDR_EXPR:
    6531       582905 :       case ARRAY_REF:
    6532       582905 :       case REALPART_EXPR:
    6533       582905 :       case IMAGPART_EXPR:
    6534       582905 :         x = TREE_OPERAND (x, 0);
    6535       582905 :         break;
    6536              : 
    6537          594 :       case COMPOUND_LITERAL_EXPR:
    6538          594 :         if (C_DECL_REGISTER (COMPOUND_LITERAL_EXPR_DECL (x)))
    6539              :           {
    6540           16 :             if (override_register)
    6541           12 :               DECL_REGISTER (COMPOUND_LITERAL_EXPR_DECL (x)) = 0;
    6542              :             else
    6543              :               {
    6544            4 :                 error ("address of register compound literal requested");
    6545            4 :                 return false;
    6546              :               }
    6547              :           }
    6548          590 :         TREE_ADDRESSABLE (x) = 1;
    6549          590 :         TREE_ADDRESSABLE (COMPOUND_LITERAL_EXPR_DECL (x)) = 1;
    6550          590 :         return true;
    6551              : 
    6552            0 :       case CONSTRUCTOR:
    6553            0 :         TREE_ADDRESSABLE (x) = 1;
    6554            0 :         return true;
    6555              : 
    6556      1339121 :       case VAR_DECL:
    6557      1339121 :       case CONST_DECL:
    6558      1339121 :       case PARM_DECL:
    6559      1339121 :       case RESULT_DECL:
    6560      1339121 :         if (C_DECL_REGISTER (x)
    6561      1339121 :             && DECL_NONLOCAL (x))
    6562              :           {
    6563            0 :             if (TREE_PUBLIC (x) || is_global_var (x))
    6564              :               {
    6565            0 :                 error
    6566            0 :                   ("global register variable %qD used in nested function", x);
    6567            0 :                 return false;
    6568              :               }
    6569            0 :             pedwarn (input_location, 0, "register variable %qD used in nested function", x);
    6570              :           }
    6571      1339121 :         else if (C_DECL_REGISTER (x))
    6572              :           {
    6573           73 :             if (TREE_PUBLIC (x) || is_global_var (x))
    6574            4 :               error ("address of global register variable %qD requested", x);
    6575          123 :             else if (override_register && !DECL_HARD_REGISTER (x))
    6576              :               {
    6577           54 :                 DECL_REGISTER (x) = 0;
    6578           54 :                 TREE_ADDRESSABLE (x) = 1;
    6579           54 :                 mark_decl_used (x, true);
    6580           54 :                 return true;
    6581              :               }
    6582              :             else
    6583           15 :               error ("address of register variable %qD requested", x);
    6584              :             return false;
    6585              :           }
    6586              : 
    6587              :         /* FALLTHRU */
    6588     53735068 :       case FUNCTION_DECL:
    6589     53735068 :         TREE_ADDRESSABLE (x) = 1;
    6590     53735068 :         mark_decl_used (x, true);
    6591              :         /* FALLTHRU */
    6592              :       default:
    6593              :         return true;
    6594              :     }
    6595              : }
    6596              : 
    6597              : /* Convert EXPR to TYPE, warning about conversion problems with
    6598              :    constants.  SEMANTIC_TYPE is the type this conversion would use
    6599              :    without excess precision. If SEMANTIC_TYPE is NULL, this function
    6600              :    is equivalent to convert_and_check. This function is a wrapper that
    6601              :    handles conversions that may be different than
    6602              :    the usual ones because of excess precision.  */
    6603              : 
    6604              : static tree
    6605     23864802 : ep_convert_and_check (location_t loc, tree type, tree expr,
    6606              :                       tree semantic_type)
    6607              : {
    6608     23864802 :   if (TREE_TYPE (expr) == type)
    6609              :     return expr;
    6610              : 
    6611              :   /* For C11, integer conversions may have results with excess
    6612              :      precision.  */
    6613      2075148 :   if (flag_isoc11 || !semantic_type)
    6614      2075144 :     return convert_and_check (loc, type, expr);
    6615              : 
    6616            4 :   if (TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
    6617            4 :       && TREE_TYPE (expr) != semantic_type)
    6618              :     {
    6619              :       /* For integers, we need to check the real conversion, not
    6620              :          the conversion to the excess precision type.  */
    6621            4 :       expr = convert_and_check (loc, semantic_type, expr);
    6622              :     }
    6623              :   /* Result type is the excess precision type, which should be
    6624              :      large enough, so do not check.  */
    6625            4 :   return convert (type, expr);
    6626              : }
    6627              : 
    6628              : /* If EXPR refers to a built-in declared without a prototype returns
    6629              :    the actual type of the built-in and, if non-null, set *BLTIN to
    6630              :    a pointer to the built-in.  Otherwise return the type of EXPR
    6631              :    and clear *BLTIN if non-null.  */
    6632              : 
    6633              : static tree
    6634      2843524 : type_or_builtin_type (tree expr, tree *bltin = NULL)
    6635              : {
    6636      2843524 :   tree dummy;
    6637      2843524 :   if (!bltin)
    6638            0 :     bltin = &dummy;
    6639              : 
    6640      2843524 :   *bltin = NULL_TREE;
    6641              : 
    6642      2843524 :   tree type = TREE_TYPE (expr);
    6643      2843524 :   if (TREE_CODE (expr) != ADDR_EXPR)
    6644              :     return type;
    6645              : 
    6646       209912 :   tree oper = TREE_OPERAND (expr, 0);
    6647       209912 :   if (!DECL_P (oper)
    6648       171203 :       || TREE_CODE (oper) != FUNCTION_DECL
    6649       246354 :       || !fndecl_built_in_p (oper, BUILT_IN_NORMAL))
    6650              :     return type;
    6651              : 
    6652         2086 :   built_in_function code = DECL_FUNCTION_CODE (oper);
    6653         2086 :   if (!C_DECL_BUILTIN_PROTOTYPE (oper))
    6654              :     return type;
    6655              : 
    6656         1977 :   if ((*bltin = builtin_decl_implicit (code)))
    6657          991 :     type = c_build_pointer_type (TREE_TYPE (*bltin));
    6658              : 
    6659              :   return type;
    6660              : }
    6661              : 
    6662              : /* Build and return a conditional expression IFEXP ? OP1 : OP2.  If
    6663              :    IFEXP_BCP then the condition is a call to __builtin_constant_p, and
    6664              :    if folded to an integer constant then the unselected half may
    6665              :    contain arbitrary operations not normally permitted in constant
    6666              :    expressions.  Set the location of the expression to LOC.  */
    6667              : 
    6668              : tree
    6669       405466 : build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp,
    6670              :                         tree op1, tree op1_original_type, location_t op1_loc,
    6671              :                         tree op2, tree op2_original_type, location_t op2_loc)
    6672              : {
    6673       405466 :   tree type1;
    6674       405466 :   tree type2;
    6675       405466 :   tree result_type = NULL;
    6676       405466 :   tree semantic_result_type = NULL;
    6677       405466 :   tree orig_op1 = op1, orig_op2 = op2;
    6678       405466 :   bool int_const, op1_int_operands, op2_int_operands, int_operands;
    6679       405466 :   bool ifexp_int_operands;
    6680       405466 :   tree ret;
    6681              : 
    6682       405466 :   op1_int_operands = EXPR_INT_CONST_OPERANDS (orig_op1);
    6683              :   if (op1_int_operands)
    6684       110811 :     op1 = remove_c_maybe_const_expr (op1);
    6685       405466 :   op2_int_operands = EXPR_INT_CONST_OPERANDS (orig_op2);
    6686              :   if (op2_int_operands)
    6687       146118 :     op2 = remove_c_maybe_const_expr (op2);
    6688       405466 :   ifexp_int_operands = EXPR_INT_CONST_OPERANDS (ifexp);
    6689              :   if (ifexp_int_operands)
    6690       242732 :     ifexp = remove_c_maybe_const_expr (ifexp);
    6691              : 
    6692              :   /* Promote both alternatives.  */
    6693              : 
    6694       405466 :   if (TREE_CODE (TREE_TYPE (op1)) != VOID_TYPE)
    6695       401542 :     op1 = default_conversion (op1);
    6696       405466 :   if (TREE_CODE (TREE_TYPE (op2)) != VOID_TYPE)
    6697       375619 :     op2 = default_conversion (op2);
    6698              : 
    6699       405466 :   if (TREE_CODE (ifexp) == ERROR_MARK
    6700       405397 :       || TREE_CODE (TREE_TYPE (op1)) == ERROR_MARK
    6701       810849 :       || TREE_CODE (TREE_TYPE (op2)) == ERROR_MARK)
    6702           83 :     return error_mark_node;
    6703              : 
    6704       405383 :   tree bltin1 = NULL_TREE;
    6705       405383 :   tree bltin2 = NULL_TREE;
    6706       405383 :   type1 = type_or_builtin_type (op1, &bltin1);
    6707       405383 :   const enum tree_code code1 = TREE_CODE (type1);
    6708       405383 :   type2 = type_or_builtin_type (op2, &bltin2);
    6709       405383 :   const enum tree_code code2 = TREE_CODE (type2);
    6710              : 
    6711       405383 :   if (code1 == POINTER_TYPE && reject_gcc_builtin (op1))
    6712            1 :     return error_mark_node;
    6713              : 
    6714       405382 :   if (code2 == POINTER_TYPE && reject_gcc_builtin (op2))
    6715            1 :     return error_mark_node;
    6716              : 
    6717              :   /* C90 does not permit non-lvalue arrays in conditional expressions.
    6718              :      In C99 they will be pointers by now.  */
    6719       405381 :   if (code1 == ARRAY_TYPE || code2 == ARRAY_TYPE)
    6720              :     {
    6721            1 :       error_at (colon_loc, "non-lvalue array in conditional expression");
    6722            1 :       return error_mark_node;
    6723              :     }
    6724              : 
    6725       405380 :   if ((TREE_CODE (op1) == EXCESS_PRECISION_EXPR
    6726       405373 :        || TREE_CODE (op2) == EXCESS_PRECISION_EXPR)
    6727            8 :       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
    6728            0 :           || code1 == COMPLEX_TYPE || code1 == BITINT_TYPE)
    6729            8 :       && (code2 == INTEGER_TYPE || code2 == REAL_TYPE
    6730            0 :           || code2 == COMPLEX_TYPE || code2 == BITINT_TYPE))
    6731              :     {
    6732            8 :       semantic_result_type = c_common_type (type1, type2);
    6733            8 :       if (TREE_CODE (op1) == EXCESS_PRECISION_EXPR)
    6734              :         {
    6735            7 :           op1 = TREE_OPERAND (op1, 0);
    6736            7 :           type1 = TREE_TYPE (op1);
    6737            7 :           gcc_assert (TREE_CODE (type1) == code1);
    6738              :         }
    6739            8 :       if (TREE_CODE (op2) == EXCESS_PRECISION_EXPR)
    6740              :         {
    6741            1 :           op2 = TREE_OPERAND (op2, 0);
    6742            1 :           type2 = TREE_TYPE (op2);
    6743            1 :           gcc_assert (TREE_CODE (type2) == code2);
    6744              :         }
    6745              :     }
    6746              : 
    6747       405380 :   if (warn_cxx_compat)
    6748              :     {
    6749          420 :       tree t1 = op1_original_type ? op1_original_type : TREE_TYPE (orig_op1);
    6750          420 :       tree t2 = op2_original_type ? op2_original_type : TREE_TYPE (orig_op2);
    6751              : 
    6752          420 :       if (TREE_CODE (t1) == ENUMERAL_TYPE
    6753            6 :           && TREE_CODE (t2) == ENUMERAL_TYPE
    6754          426 :           && TYPE_MAIN_VARIANT (t1) != TYPE_MAIN_VARIANT (t2))
    6755            2 :         warning_at (colon_loc, OPT_Wc___compat,
    6756              :                     "different enum types in conditional is "
    6757              :                     "invalid in C++: %qT vs %qT", t1, t2);
    6758              :     }
    6759              : 
    6760       405380 :   if (warn_zero_as_null_pointer_constant
    6761           20 :       && c_inhibit_evaluation_warnings == 0)
    6762              :     {
    6763           20 :       if ((code1 == POINTER_TYPE || code1 == NULLPTR_TYPE)
    6764           20 :           && INTEGRAL_TYPE_P (type2) && null_pointer_constant_p (orig_op2))
    6765            5 :         warning_at (op2_loc, OPT_Wzero_as_null_pointer_constant,
    6766              :                     "zero as null pointer constant");
    6767              : 
    6768           20 :       if ((code2 == POINTER_TYPE || code2 == NULLPTR_TYPE)
    6769           20 :           && INTEGRAL_TYPE_P (type1) && null_pointer_constant_p (orig_op1))
    6770            5 :         warning_at (op1_loc, OPT_Wzero_as_null_pointer_constant,
    6771              :                     "zero as null pointer constant");
    6772              :     }
    6773              : 
    6774              :   /* Quickly detect the usual case where op1 and op2 have the same type
    6775              :      after promotion.  */
    6776       405380 :   if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2))
    6777              :     {
    6778       270157 :       if (type1 == type2)
    6779              :         result_type = type1;
    6780              :       else
    6781         6422 :         result_type = TYPE_MAIN_VARIANT (type1);
    6782              :     }
    6783       135223 :   else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE
    6784        80426 :             || code1 == COMPLEX_TYPE || code1 == BITINT_TYPE)
    6785        54865 :            && (code2 == INTEGER_TYPE || code2 == REAL_TYPE
    6786        26161 :                || code2 == COMPLEX_TYPE || code2 == BITINT_TYPE))
    6787              :     {
    6788              :       /* In C11, a conditional expression between a floating-point
    6789              :          type and an integer type should convert the integer type to
    6790              :          the evaluation format of the floating-point type, with
    6791              :          possible excess precision.  */
    6792        28813 :       tree eptype1 = type1;
    6793        28813 :       tree eptype2 = type2;
    6794        28813 :       if (flag_isoc11)
    6795              :         {
    6796        28500 :           tree eptype;
    6797        11653 :           if (ANY_INTEGRAL_TYPE_P (type1)
    6798        28500 :               && (eptype = excess_precision_type (type2)) != NULL_TREE)
    6799              :             {
    6800            2 :               eptype2 = eptype;
    6801            2 :               if (!semantic_result_type)
    6802            2 :                 semantic_result_type = c_common_type (type1, type2);
    6803              :             }
    6804          502 :           else if (ANY_INTEGRAL_TYPE_P (type2)
    6805        28498 :                    && (eptype = excess_precision_type (type1)) != NULL_TREE)
    6806              :             {
    6807         4630 :               eptype1 = eptype;
    6808         4630 :               if (!semantic_result_type)
    6809         4630 :                 semantic_result_type = c_common_type (type1, type2);
    6810              :             }
    6811              :         }
    6812        28813 :       result_type = c_common_type (eptype1, eptype2);
    6813        28813 :       if (result_type == error_mark_node)
    6814              :         return error_mark_node;
    6815        28811 :       do_warn_double_promotion (result_type, type1, type2,
    6816              :                                 "implicit conversion from %qT to %qT to "
    6817              :                                 "match other result of conditional",
    6818              :                                 colon_loc);
    6819              : 
    6820              :       /* If -Wsign-compare, warn here if type1 and type2 have
    6821              :          different signedness.  We'll promote the signed to unsigned
    6822              :          and later code won't know it used to be different.
    6823              :          Do this check on the original types, so that explicit casts
    6824              :          will be considered, but default promotions won't.  */
    6825        28811 :       if (c_inhibit_evaluation_warnings == 0)
    6826              :         {
    6827        28620 :           int unsigned_op1 = TYPE_UNSIGNED (TREE_TYPE (orig_op1));
    6828        28620 :           int unsigned_op2 = TYPE_UNSIGNED (TREE_TYPE (orig_op2));
    6829              : 
    6830        28620 :           if (unsigned_op1 ^ unsigned_op2)
    6831              :             {
    6832              :               /* Do not warn if the result type is signed, since the
    6833              :                  signed type will only be chosen if it can represent
    6834              :                  all the values of the unsigned type.  */
    6835        13107 :               if (!TYPE_UNSIGNED (result_type))
    6836              :                 /* OK */;
    6837              :               else
    6838              :                 {
    6839        13002 :                   bool op1_maybe_const = true;
    6840        13002 :                   bool op2_maybe_const = true;
    6841              : 
    6842              :                   /* Do not warn if the signed quantity is an
    6843              :                      unsuffixed integer literal (or some static
    6844              :                      constant expression involving such literals) and
    6845              :                      it is non-negative.  This warning requires the
    6846              :                      operands to be folded for best results, so do
    6847              :                      that folding in this case even without
    6848              :                      warn_sign_compare to avoid warning options
    6849              :                      possibly affecting code generation.  */
    6850        13002 :                   c_inhibit_evaluation_warnings
    6851        13002 :                     += (ifexp == truthvalue_false_node);
    6852        13002 :                   op1 = c_fully_fold (op1, require_constant_value,
    6853              :                                       &op1_maybe_const);
    6854        13002 :                   c_inhibit_evaluation_warnings
    6855        13002 :                     -= (ifexp == truthvalue_false_node);
    6856              : 
    6857        13002 :                   c_inhibit_evaluation_warnings
    6858        13002 :                     += (ifexp == truthvalue_true_node);
    6859        13002 :                   op2 = c_fully_fold (op2, require_constant_value,
    6860              :                                       &op2_maybe_const);
    6861        13002 :                   c_inhibit_evaluation_warnings
    6862        13002 :                     -= (ifexp == truthvalue_true_node);
    6863              : 
    6864        13002 :                   if (warn_sign_compare)
    6865              :                     {
    6866         1245 :                       if ((unsigned_op2
    6867          685 :                            && tree_expr_nonnegative_p (op1))
    6868         1248 :                           || (unsigned_op1
    6869          560 :                               && tree_expr_nonnegative_p (op2)))
    6870              :                         /* OK */;
    6871           10 :                       else if (unsigned_op2)
    6872            3 :                         warning_at (op1_loc, OPT_Wsign_compare,
    6873              :                                     "operand of %<?:%> changes signedness from "
    6874              :                                     "%qT to %qT due to unsignedness of other "
    6875            3 :                                     "operand", TREE_TYPE (orig_op1),
    6876            3 :                                     TREE_TYPE (orig_op2));
    6877              :                       else
    6878            7 :                         warning_at (op2_loc, OPT_Wsign_compare,
    6879              :                                     "operand of %<?:%> changes signedness from "
    6880              :                                     "%qT to %qT due to unsignedness of other "
    6881            7 :                                     "operand", TREE_TYPE (orig_op2),
    6882            7 :                                     TREE_TYPE (orig_op1));
    6883              :                     }
    6884        13002 :                   if (!op1_maybe_const || TREE_CODE (op1) != INTEGER_CST)
    6885         7642 :                     op1 = c_wrap_maybe_const (op1, !op1_maybe_const);
    6886        13002 :                   if (!op2_maybe_const || TREE_CODE (op2) != INTEGER_CST)
    6887         4400 :                     op2 = c_wrap_maybe_const (op2, !op2_maybe_const);
    6888              :                 }
    6889              :             }
    6890              :         }
    6891              :     }
    6892       106410 :   else if (code1 == VOID_TYPE || code2 == VOID_TYPE)
    6893              :     {
    6894        25995 :       if (code1 != VOID_TYPE || code2 != VOID_TYPE)
    6895        25995 :         pedwarn (colon_loc, OPT_Wpedantic,
    6896              :                  "ISO C forbids conditional expr with only one void side");
    6897        25995 :       result_type = void_type_node;
    6898              :     }
    6899        80415 :   else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE)
    6900              :     {
    6901        79997 :       addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (type1));
    6902        79997 :       addr_space_t as2 = TYPE_ADDR_SPACE (TREE_TYPE (type2));
    6903        79997 :       addr_space_t as_common;
    6904              : 
    6905        79997 :       if (comp_target_types (colon_loc, type1, type2))
    6906              :         {
    6907         2626 :           ifexp = save_expr (ifexp);
    6908         2626 :           result_type = common_pointer_type (type1, type2, ifexp);
    6909              :         }
    6910        77371 :       else if (null_pointer_constant_p (orig_op1))
    6911              :         result_type = type2;
    6912        73209 :       else if (null_pointer_constant_p (orig_op2))
    6913              :         result_type = type1;
    6914        35281 :       else if (!addr_space_superset (as1, as2, &as_common))
    6915              :         {
    6916            0 :           error_at (colon_loc, "pointers to disjoint address spaces "
    6917              :                     "used in conditional expression");
    6918            0 :           return error_mark_node;
    6919              :         }
    6920        35281 :       else if ((VOID_TYPE_P (TREE_TYPE (type1))
    6921          326 :                 && !TYPE_ATOMIC (TREE_TYPE (type1)))
    6922        35283 :                || (VOID_TYPE_P (TREE_TYPE (type2))
    6923        34910 :                    && !TYPE_ATOMIC (TREE_TYPE (type2))))
    6924              :         {
    6925        35233 :           tree t1 = TREE_TYPE (type1);
    6926        35233 :           tree t2 = TREE_TYPE (type2);
    6927        35233 :           if (!(VOID_TYPE_P (t1)
    6928          325 :                 && !TYPE_ATOMIC (t1)))
    6929              :            {
    6930              :              /* roles are swapped */
    6931        34909 :              t1 = t2;
    6932        34909 :              t2 = TREE_TYPE (type1);
    6933              :            }
    6934        35233 :           tree t2_stripped = strip_array_types (t2);
    6935        35233 :           if ((TREE_CODE (t2) == ARRAY_TYPE)
    6936        35233 :               && (TYPE_QUALS (t2_stripped) & ~TYPE_QUALS (t1)))
    6937              :             {
    6938           18 :               if (!flag_isoc23)
    6939            6 :                 warning_at (colon_loc, OPT_Wdiscarded_array_qualifiers,
    6940              :                             "pointer to array loses qualifier "
    6941              :                             "in conditional expression");
    6942           12 :               else if (warn_c11_c23_compat > 0)
    6943            6 :                 warning_at (colon_loc, OPT_Wc11_c23_compat,
    6944              :                             "pointer to array loses qualifier "
    6945              :                             "in conditional expression in ISO C before C23");
    6946              :             }
    6947        35233 :           if (TREE_CODE (t2) == FUNCTION_TYPE)
    6948            4 :             pedwarn (colon_loc, OPT_Wpedantic,
    6949              :                      "ISO C forbids conditional expr between "
    6950              :                      "%<void *%> and function pointer");
    6951              :           /* for array, use qualifiers of element type */
    6952        35233 :           if (flag_isoc23)
    6953        11452 :             t2 = t2_stripped;
    6954        35233 :           result_type = c_build_pointer_type (qualify_type (t1, t2));
    6955              :         }
    6956              :       /* Objective-C pointer comparisons are a bit more lenient.  */
    6957           48 :       else if (objc_have_common_type (type1, type2, -3, NULL_TREE))
    6958            0 :         result_type = objc_common_type (type1, type2);
    6959              :       else
    6960              :         {
    6961           48 :           int qual = ENCODE_QUAL_ADDR_SPACE (as_common);
    6962           48 :           enum diagnostics::kind kind = diagnostics::kind::permerror;
    6963           48 :           if (!flag_isoc99)
    6964              :             /* This downgrade to a warning ensures that -std=gnu89
    6965              :                -pedantic-errors does not flag these mismatches between
    6966              :                builtins as errors (as diagnostics::kind::permerror would)
    6967              :                ISO C99 and later do not have implicit function declarations,
    6968              :                so the mismatch cannot occur naturally there.  */
    6969            5 :             kind = (bltin1 && bltin2
    6970            5 :                     ? diagnostics::kind::warning
    6971              :                     : diagnostics::kind::pedwarn);
    6972           48 :           if (emit_diagnostic (kind, colon_loc, OPT_Wincompatible_pointer_types,
    6973              :                                "pointer type mismatch "
    6974              :                                "in conditional expression"))
    6975              :             {
    6976           46 :               inform (op1_loc, "first expression has type %qT", type1);
    6977           46 :               inform (op2_loc, "second expression has type %qT", type2);
    6978              :             }
    6979           48 :           result_type = c_build_pointer_type
    6980           48 :                           (c_build_qualified_type (void_type_node, qual));
    6981              :         }
    6982              :     }
    6983          418 :   else if (code1 == POINTER_TYPE
    6984          298 :            && (code2 == INTEGER_TYPE || code2 == BITINT_TYPE))
    6985              :     {
    6986          294 :       if (!null_pointer_constant_p (orig_op2))
    6987           14 :         permerror_opt (colon_loc, OPT_Wint_conversion,
    6988              :                        "pointer/integer type mismatch "
    6989              :                        "in conditional expression");
    6990              :       else
    6991              :         {
    6992          280 :           op2 = null_pointer_node;
    6993              :         }
    6994              :       result_type = type1;
    6995              :     }
    6996          124 :   else if (code2 == POINTER_TYPE
    6997           90 :            && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
    6998              :     {
    6999           86 :       if (!null_pointer_constant_p (orig_op1))
    7000           14 :         permerror_opt (colon_loc, OPT_Wint_conversion,
    7001              :                        "pointer/integer type mismatch "
    7002              :                        "in conditional expression");
    7003              :       else
    7004              :         {
    7005           72 :           op1 = null_pointer_node;
    7006              :         }
    7007              :       result_type = type2;
    7008              :     }
    7009              :   /* 6.5.15: "if one is a null pointer constant (other than a pointer) or has
    7010              :      type nullptr_t and the other is a pointer, the result type is the pointer
    7011              :      type."  */
    7012           38 :   else if (code1 == NULLPTR_TYPE && code2 == POINTER_TYPE)
    7013              :     result_type = type2;
    7014           34 :   else if (code1 == POINTER_TYPE && code2 == NULLPTR_TYPE)
    7015              :     result_type = type1;
    7016            8 :   else if (RECORD_OR_UNION_TYPE_P (type1) && RECORD_OR_UNION_TYPE_P (type2)
    7017           38 :            && comptypes (TYPE_MAIN_VARIANT (type1),
    7018            8 :                          TYPE_MAIN_VARIANT (type2)))
    7019            8 :     result_type = composite_type (TYPE_MAIN_VARIANT (type1),
    7020            8 :                                   TYPE_MAIN_VARIANT (type2));
    7021              : 
    7022       405356 :   if (!result_type)
    7023              :     {
    7024           22 :       if (flag_cond_mismatch)
    7025            0 :         result_type = void_type_node;
    7026              :       else
    7027              :         {
    7028           22 :           error_at (colon_loc, "type mismatch in conditional expression");
    7029           22 :           return error_mark_node;
    7030              :         }
    7031              :     }
    7032              : 
    7033              :   /* Merge const and volatile flags of the incoming types.  */
    7034       405356 :   result_type
    7035       405356 :     = build_type_variant (result_type,
    7036              :                           TYPE_READONLY (type1) || TYPE_READONLY (type2),
    7037              :                           TYPE_VOLATILE (type1) || TYPE_VOLATILE (type2));
    7038              : 
    7039       405356 :   op1 = ep_convert_and_check (colon_loc, result_type, op1,
    7040              :                               semantic_result_type);
    7041       405356 :   op2 = ep_convert_and_check (colon_loc, result_type, op2,
    7042              :                               semantic_result_type);
    7043              : 
    7044       405356 :   if (ifexp_bcp && ifexp == truthvalue_true_node)
    7045              :     {
    7046           10 :       op2_int_operands = true;
    7047           10 :       op1 = c_fully_fold (op1, require_constant_value, NULL);
    7048              :     }
    7049           59 :   if (ifexp_bcp && ifexp == truthvalue_false_node)
    7050              :     {
    7051           49 :       op1_int_operands = true;
    7052           49 :       op2 = c_fully_fold (op2, require_constant_value, NULL);
    7053              :     }
    7054       907814 :   int_const = int_operands = (ifexp_int_operands
    7055       405356 :                               && op1_int_operands
    7056       405356 :                               && op2_int_operands);
    7057        97102 :   if (int_operands)
    7058              :     {
    7059        97102 :       int_const = ((ifexp == truthvalue_true_node
    7060        58800 :                     && TREE_CODE (orig_op1) == INTEGER_CST
    7061        58786 :                     && !TREE_OVERFLOW (orig_op1))
    7062        97116 :                    || (ifexp == truthvalue_false_node
    7063        38256 :                        && TREE_CODE (orig_op2) == INTEGER_CST
    7064        38240 :                        && !TREE_OVERFLOW (orig_op2)));
    7065              :     }
    7066              : 
    7067              :   /* Need to convert condition operand into a vector mask.  */
    7068       405356 :   if (VECTOR_TYPE_P (TREE_TYPE (ifexp)))
    7069              :     {
    7070            0 :       tree vectype = TREE_TYPE (ifexp);
    7071            0 :       tree elem_type = TREE_TYPE (vectype);
    7072            0 :       tree zero = build_int_cst (elem_type, 0);
    7073            0 :       tree zero_vec = build_vector_from_val (vectype, zero);
    7074            0 :       tree cmp_type = truth_type_for (vectype);
    7075            0 :       ifexp = build2 (NE_EXPR, cmp_type, ifexp, zero_vec);
    7076              :     }
    7077              : 
    7078       405356 :   if (int_const || (ifexp_bcp && TREE_CODE (ifexp) == INTEGER_CST))
    7079        97058 :     ret = fold_build3_loc (colon_loc, COND_EXPR, result_type, ifexp, op1, op2);
    7080              :   else
    7081              :     {
    7082       308298 :       if (int_operands)
    7083              :         {
    7084              :           /* Use c_fully_fold here, since C_MAYBE_CONST_EXPR might be
    7085              :              nested inside of the expression.  */
    7086           76 :           op1 = c_fully_fold (op1, false, NULL);
    7087           76 :           op2 = c_fully_fold (op2, false, NULL);
    7088              :         }
    7089       308298 :       ret = build3 (COND_EXPR, result_type, ifexp, op1, op2);
    7090       308298 :       if (int_operands)
    7091           76 :         ret = note_integer_operands (ret);
    7092              :     }
    7093       405356 :   if (semantic_result_type)
    7094         4640 :     ret = build1 (EXCESS_PRECISION_EXPR, semantic_result_type, ret);
    7095              : 
    7096       405356 :   protected_set_expr_location (ret, colon_loc);
    7097              : 
    7098              :   /* If the OP1 and OP2 are the same and don't have side-effects,
    7099              :      warn here, because the COND_EXPR will be turned into OP1.  */
    7100       405356 :   if (warn_duplicated_branches
    7101           34 :       && TREE_CODE (ret) == COND_EXPR
    7102       405390 :       && (op1 == op2 || operand_equal_p (op1, op2, OEP_ADDRESS_OF_SAME_FIELD)))
    7103           13 :     warning_at (EXPR_LOCATION (ret), OPT_Wduplicated_branches,
    7104              :                 "this condition has identical branches");
    7105              : 
    7106              :   return ret;
    7107              : }
    7108              : 
    7109              : /* EXPR is an expression, location LOC, whose result is discarded.
    7110              :    Warn if it is a call to a nodiscard function (or a COMPOUND_EXPR
    7111              :    whose right-hand operand is such a call, possibly recursively).  */
    7112              : 
    7113              : static void
    7114      6640039 : maybe_warn_nodiscard (location_t loc, tree expr)
    7115              : {
    7116      6640039 :   if (VOID_TYPE_P (TREE_TYPE (expr)))
    7117              :     return;
    7118      4009515 :   while (TREE_CODE (expr) == COMPOUND_EXPR)
    7119              :     {
    7120        52030 :       expr = TREE_OPERAND (expr, 1);
    7121        52030 :       if (EXPR_HAS_LOCATION (expr))
    7122        52030 :         loc = EXPR_LOCATION (expr);
    7123              :     }
    7124      3957485 :   if (TREE_CODE (expr) != CALL_EXPR)
    7125              :     return;
    7126       347779 :   tree fn = CALL_EXPR_FN (expr);
    7127       347779 :   if (!fn)
    7128              :     return;
    7129       347763 :   tree attr;
    7130       347763 :   if (TREE_CODE (fn) == ADDR_EXPR
    7131       347096 :       && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
    7132       694859 :       && (attr = lookup_attribute ("nodiscard",
    7133       347096 :                                    DECL_ATTRIBUTES (TREE_OPERAND (fn, 0)))))
    7134              :     {
    7135            3 :       fn = TREE_OPERAND (fn, 0);
    7136            3 :       tree args = TREE_VALUE (attr);
    7137            3 :       if (args)
    7138            1 :         args = TREE_VALUE (args);
    7139            3 :       auto_diagnostic_group d;
    7140            3 :       auto_urlify_attributes sentinel;
    7141            3 :       int warned;
    7142            3 :       if (args)
    7143            1 :         warned = warning_at (loc, OPT_Wunused_result,
    7144              :                              "ignoring return value of %qD, declared with "
    7145              :                              "attribute %<nodiscard%>: %E", fn, args);
    7146              :       else
    7147            2 :         warned = warning_at (loc, OPT_Wunused_result,
    7148              :                              "ignoring return value of %qD, declared with "
    7149              :                              "attribute %<nodiscard%>", fn);
    7150            3 :       if (warned)
    7151            3 :         inform (DECL_SOURCE_LOCATION (fn), "declared here");
    7152            3 :     }
    7153              :   else
    7154              :     {
    7155       347760 :       tree rettype = TREE_TYPE (TREE_TYPE (TREE_TYPE (fn)));
    7156       347760 :       attr = lookup_attribute ("nodiscard", TYPE_ATTRIBUTES (rettype));
    7157       347760 :       if (!attr)
    7158       347748 :         return;
    7159           12 :       tree args = TREE_VALUE (attr);
    7160           12 :       if (args)
    7161            5 :         args = TREE_VALUE (args);
    7162           12 :       auto_diagnostic_group d;
    7163           12 :       auto_urlify_attributes sentinel;
    7164           12 :       int warned;
    7165           12 :       if (args)
    7166            5 :         warned = warning_at (loc, OPT_Wunused_result,
    7167              :                              "ignoring return value of type %qT, declared "
    7168              :                              "with attribute %<nodiscard%>: %E",
    7169              :                              rettype, args);
    7170              :       else
    7171            7 :         warned = warning_at (loc, OPT_Wunused_result,
    7172              :                              "ignoring return value of type %qT, declared "
    7173              :                              "with attribute %<nodiscard%>", rettype);
    7174           12 :       if (warned)
    7175              :         {
    7176           12 :           if (TREE_CODE (fn) == ADDR_EXPR)
    7177              :             {
    7178           11 :               fn = TREE_OPERAND (fn, 0);
    7179           11 :               if (TREE_CODE (fn) == FUNCTION_DECL)
    7180           11 :                 inform (DECL_SOURCE_LOCATION (fn),
    7181              :                         "in call to %qD, declared here", fn);
    7182              :             }
    7183              :         }
    7184           12 :     }
    7185              : }
    7186              : 
    7187              : /* Return a compound expression that performs two expressions and
    7188              :    returns the value of the second of them.
    7189              : 
    7190              :    LOC is the location of the COMPOUND_EXPR.  */
    7191              : 
    7192              : tree
    7193       114323 : build_compound_expr (location_t loc, tree expr1, tree expr2)
    7194              : {
    7195       114323 :   bool expr1_int_operands, expr2_int_operands;
    7196       114323 :   tree eptype = NULL_TREE;
    7197       114323 :   tree ret;
    7198              : 
    7199       114323 :   expr1_int_operands = EXPR_INT_CONST_OPERANDS (expr1);
    7200              :   if (expr1_int_operands)
    7201          326 :     expr1 = remove_c_maybe_const_expr (expr1);
    7202       114323 :   expr2_int_operands = EXPR_INT_CONST_OPERANDS (expr2);
    7203              :   if (expr2_int_operands)
    7204        66136 :     expr2 = remove_c_maybe_const_expr (expr2);
    7205              : 
    7206       114323 :   if (TREE_CODE (expr1) == EXCESS_PRECISION_EXPR)
    7207            0 :     expr1 = TREE_OPERAND (expr1, 0);
    7208       114323 :   if (TREE_CODE (expr2) == EXCESS_PRECISION_EXPR)
    7209              :     {
    7210            1 :       eptype = TREE_TYPE (expr2);
    7211            1 :       expr2 = TREE_OPERAND (expr2, 0);
    7212              :     }
    7213              : 
    7214       114323 :   if (!TREE_SIDE_EFFECTS (expr1))
    7215              :     {
    7216              :       /* The left-hand operand of a comma expression is like an expression
    7217              :          statement: with -Wunused, we should warn if it doesn't have
    7218              :          any side-effects, unless it was explicitly cast to (void).  */
    7219         8459 :       if (warn_unused_value)
    7220              :         {
    7221         1284 :           if (VOID_TYPE_P (TREE_TYPE (expr1))
    7222         1284 :               && CONVERT_EXPR_P (expr1))
    7223              :             ; /* (void) a, b */
    7224           14 :           else if (VOID_TYPE_P (TREE_TYPE (expr1))
    7225            4 :                    && TREE_CODE (expr1) == COMPOUND_EXPR
    7226           17 :                    && CONVERT_EXPR_P (TREE_OPERAND (expr1, 1)))
    7227              :             ; /* (void) a, (void) b, c */
    7228              :           else
    7229           11 :             warning_at (loc, OPT_Wunused_value,
    7230              :                         "left-hand operand of comma expression has no effect");
    7231              :         }
    7232              :     }
    7233       105864 :   else if (TREE_CODE (expr1) == COMPOUND_EXPR
    7234        13113 :            && warn_unused_value)
    7235              :     {
    7236              :       tree r = expr1;
    7237              :       location_t cloc = loc;
    7238         4833 :       while (TREE_CODE (r) == COMPOUND_EXPR)
    7239              :         {
    7240         2417 :           if (EXPR_HAS_LOCATION (r))
    7241         2417 :             cloc = EXPR_LOCATION (r);
    7242         2417 :           r = TREE_OPERAND (r, 1);
    7243              :         }
    7244         2416 :       if (!TREE_SIDE_EFFECTS (r)
    7245            4 :           && !VOID_TYPE_P (TREE_TYPE (r))
    7246         2420 :           && !CONVERT_EXPR_P (r))
    7247            4 :         warning_at (cloc, OPT_Wunused_value,
    7248              :                     "right-hand operand of comma expression has no effect");
    7249              :     }
    7250              : 
    7251              :   /* With -Wunused, we should also warn if the left-hand operand does have
    7252              :      side-effects, but computes a value which is not used.  For example, in
    7253              :      `foo() + bar(), baz()' the result of the `+' operator is not used,
    7254              :      so we should issue a warning.  */
    7255       103448 :   else if (warn_unused_value)
    7256        35423 :     warn_if_unused_value (expr1, loc);
    7257              : 
    7258       114323 :   maybe_warn_nodiscard (loc, expr1);
    7259              : 
    7260       114323 :   if (expr2 == error_mark_node)
    7261              :     return error_mark_node;
    7262              : 
    7263       114310 :   ret = build2 (COMPOUND_EXPR, TREE_TYPE (expr2), expr1, expr2);
    7264              : 
    7265       114310 :   if (flag_isoc99
    7266              :       && expr1_int_operands
    7267       113850 :       && expr2_int_operands)
    7268          153 :     ret = note_integer_operands (ret);
    7269              : 
    7270       114310 :   if (eptype)
    7271            1 :     ret = build1 (EXCESS_PRECISION_EXPR, eptype, ret);
    7272              : 
    7273       114310 :   protected_set_expr_location (ret, loc);
    7274       114310 :   return ret;
    7275              : }
    7276              : 
    7277              : /* Issue -Wcast-qual warnings when appropriate.  TYPE is the type to
    7278              :    which we are casting.  OTYPE is the type of the expression being
    7279              :    cast.  Both TYPE and OTYPE are pointer types.  LOC is the location
    7280              :    of the cast.  -Wcast-qual appeared on the command line.  Named
    7281              :    address space qualifiers are not handled here, because they result
    7282              :    in different warnings.  */
    7283              : 
    7284              : static void
    7285        14107 : handle_warn_cast_qual (location_t loc, tree type, tree otype)
    7286              : {
    7287        14107 :   tree in_type = type;
    7288        14107 :   tree in_otype = otype;
    7289        14107 :   int added = 0;
    7290        14107 :   int discarded = 0;
    7291        14277 :   bool is_const;
    7292              : 
    7293              :   /* Check that the qualifiers on IN_TYPE are a superset of the
    7294              :      qualifiers of IN_OTYPE.  The outermost level of POINTER_TYPE
    7295              :      nodes is uninteresting and we stop as soon as we hit a
    7296              :      non-POINTER_TYPE node on either type.  */
    7297        14277 :   do
    7298              :     {
    7299        14277 :       in_otype = TREE_TYPE (in_otype);
    7300        14277 :       in_type = TREE_TYPE (in_type);
    7301              : 
    7302              :       /* GNU C allows cv-qualified function types.  'const' means the
    7303              :          function is very pure, 'volatile' means it can't return.  We
    7304              :          need to warn when such qualifiers are added, not when they're
    7305              :          taken away.  */
    7306        14277 :       if (TREE_CODE (in_otype) == FUNCTION_TYPE
    7307           26 :           && TREE_CODE (in_type) == FUNCTION_TYPE)
    7308           18 :         added |= (TYPE_QUALS_NO_ADDR_SPACE (in_type)
    7309           18 :                   & ~TYPE_QUALS_NO_ADDR_SPACE (in_otype));
    7310              :       else
    7311        14259 :         discarded |= (TYPE_QUALS_NO_ADDR_SPACE (in_otype)
    7312        14259 :                       & ~TYPE_QUALS_NO_ADDR_SPACE (in_type));
    7313              :     }
    7314        14277 :   while (TREE_CODE (in_type) == POINTER_TYPE
    7315        14277 :          && TREE_CODE (in_otype) == POINTER_TYPE);
    7316              : 
    7317        14107 :   if (added)
    7318            2 :     warning_at (loc, OPT_Wcast_qual,
    7319              :                 "cast adds %q#v qualifier to function type", added);
    7320              : 
    7321        14107 :   if (discarded)
    7322              :     /* There are qualifiers present in IN_OTYPE that are not present
    7323              :        in IN_TYPE.  */
    7324         1203 :     warning_at (loc, OPT_Wcast_qual,
    7325              :                 "cast discards %qv qualifier from pointer target type",
    7326              :                 discarded);
    7327              : 
    7328        14107 :   if (added || discarded)
    7329              :     return;
    7330              : 
    7331              :   /* A cast from **T to const **T is unsafe, because it can cause a
    7332              :      const value to be changed with no additional warning.  We only
    7333              :      issue this warning if T is the same on both sides, and we only
    7334              :      issue the warning if there are the same number of pointers on
    7335              :      both sides, as otherwise the cast is clearly unsafe anyhow.  A
    7336              :      cast is unsafe when a qualifier is added at one level and const
    7337              :      is not present at all outer levels.
    7338              : 
    7339              :      To issue this warning, we check at each level whether the cast
    7340              :      adds new qualifiers not already seen.  We don't need to special
    7341              :      case function types, as they won't have the same
    7342              :      TYPE_MAIN_VARIANT.  */
    7343              : 
    7344        12902 :   if (TYPE_MAIN_VARIANT (in_type) != TYPE_MAIN_VARIANT (in_otype))
    7345              :     return;
    7346          227 :   if (TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE)
    7347              :     return;
    7348              : 
    7349           48 :   in_type = type;
    7350           48 :   in_otype = otype;
    7351           48 :   is_const = TYPE_READONLY (TREE_TYPE (in_type));
    7352          130 :   do
    7353              :     {
    7354          130 :       in_type = TREE_TYPE (in_type);
    7355          130 :       in_otype = TREE_TYPE (in_otype);
    7356          130 :       if ((TYPE_QUALS (in_type) &~ TYPE_QUALS (in_otype)) != 0
    7357          130 :           && !is_const)
    7358              :         {
    7359           27 :           warning_at (loc, OPT_Wcast_qual,
    7360              :                       "to be safe all intermediate pointers in cast from "
    7361              :                       "%qT to %qT must be %<const%> qualified",
    7362              :                       otype, type);
    7363           27 :           break;
    7364              :         }
    7365          103 :       if (is_const)
    7366           72 :         is_const = TYPE_READONLY (in_type);
    7367              :     }
    7368          103 :   while (TREE_CODE (in_type) == POINTER_TYPE);
    7369              : }
    7370              : 
    7371              : /* Heuristic check if two parameter types can be considered ABI-equivalent.  */
    7372              : 
    7373              : static bool
    7374         1316 : c_safe_arg_type_equiv_p (tree t1, tree t2)
    7375              : {
    7376         1316 :   if (error_operand_p (t1) || error_operand_p (t2))
    7377              :     return true;
    7378              : 
    7379         1315 :   t1 = TYPE_MAIN_VARIANT (t1);
    7380         1315 :   t2 = TYPE_MAIN_VARIANT (t2);
    7381              : 
    7382         1315 :   if (TREE_CODE (t1) == POINTER_TYPE
    7383          229 :       && TREE_CODE (t2) == POINTER_TYPE)
    7384              :     return true;
    7385              : 
    7386              :   /* Only the precision of the parameter matters.  This check should
    7387              :      make sure that the callee does not see undefined values in argument
    7388              :      registers.  */
    7389         1107 :   if (INTEGRAL_TYPE_P (t1)
    7390          917 :       && INTEGRAL_TYPE_P (t2)
    7391         1452 :       && TYPE_PRECISION (t1) == TYPE_PRECISION (t2))
    7392              :     return true;
    7393              : 
    7394          942 :   return comptypes (t1, t2);
    7395              : }
    7396              : 
    7397              : /* Check if a type cast between two function types can be considered safe.  */
    7398              : 
    7399              : static bool
    7400         7563 : c_safe_function_type_cast_p (tree t1, tree t2)
    7401              : {
    7402         7563 :   if (TREE_TYPE (t1) == void_type_node &&
    7403         5561 :       TYPE_ARG_TYPES (t1) == void_list_node)
    7404              :     return true;
    7405              : 
    7406         3726 :   if (TREE_TYPE (t2) == void_type_node &&
    7407         2889 :       TYPE_ARG_TYPES (t2) == void_list_node)
    7408              :     return true;
    7409              : 
    7410          896 :   if (!c_safe_arg_type_equiv_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    7411              :     return false;
    7412              : 
    7413          197 :   for (t1 = TYPE_ARG_TYPES (t1), t2 = TYPE_ARG_TYPES (t2);
    7414          513 :        t1 && t2;
    7415          316 :        t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
    7416          420 :     if (!c_safe_arg_type_equiv_p (TREE_VALUE (t1), TREE_VALUE (t2)))
    7417              :       return false;
    7418              : 
    7419              :   return true;
    7420              : }
    7421              : 
    7422              : /* Build an expression representing a cast to type TYPE of expression EXPR.
    7423              :    LOC is the location of the cast-- typically the open paren of the cast.  */
    7424              : 
    7425              : tree
    7426    124575795 : build_c_cast (location_t loc, tree type, tree expr)
    7427              : {
    7428    124575795 :   tree value;
    7429              : 
    7430    124575795 :   bool int_operands = EXPR_INT_CONST_OPERANDS (expr);
    7431              : 
    7432    124575795 :   if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
    7433           66 :     expr = TREE_OPERAND (expr, 0);
    7434              : 
    7435    124575795 :   value = expr;
    7436    124575795 :   if (int_operands)
    7437      7159421 :     value = remove_c_maybe_const_expr (value);
    7438              : 
    7439    124575795 :   if (type == error_mark_node || expr == error_mark_node)
    7440              :     return error_mark_node;
    7441              : 
    7442              :   /* The ObjC front-end uses TYPE_MAIN_VARIANT to tie together types differing
    7443              :      only in <protocol> qualifications.  But when constructing cast expressions,
    7444              :      the protocols do matter and must be kept around.  */
    7445    124574775 :   if (objc_is_object_ptr (type) && objc_is_object_ptr (TREE_TYPE (expr)))
    7446            0 :     return build1 (NOP_EXPR, type, expr);
    7447              : 
    7448    124574775 :   type = TYPE_MAIN_VARIANT (type);
    7449              : 
    7450    124574775 :   if (TREE_CODE (type) == ARRAY_TYPE)
    7451              :     {
    7452           13 :       error_at (loc, "cast specifies array type");
    7453           13 :       return error_mark_node;
    7454              :     }
    7455              : 
    7456    124574762 :   if (TREE_CODE (type) == FUNCTION_TYPE)
    7457              :     {
    7458            6 :       error_at (loc, "cast specifies function type");
    7459            6 :       return error_mark_node;
    7460              :     }
    7461              : 
    7462    124574756 :   if (!VOID_TYPE_P (type))
    7463              :     {
    7464    124530088 :       value = require_complete_type (loc, value);
    7465    124530088 :       if (value == error_mark_node)
    7466              :         return error_mark_node;
    7467              :     }
    7468              : 
    7469    124574755 :   if (type == TYPE_MAIN_VARIANT (TREE_TYPE (value)))
    7470              :     {
    7471     18830965 :       if (RECORD_OR_UNION_TYPE_P (type)
    7472     18830965 :           && pedwarn (loc, OPT_Wpedantic,
    7473              :                       "ISO C forbids casting nonscalar to the same type"))
    7474              :               ;
    7475     18830961 :       else if (warn_useless_cast && c_inhibit_evaluation_warnings == 0)
    7476            8 :         warning_at (loc, OPT_Wuseless_cast,
    7477              :                     "useless cast to type %qT", type);
    7478              : 
    7479              :       /* Convert to remove any qualifiers from VALUE's type.  */
    7480     18830965 :       value = convert (type, value);
    7481              :     }
    7482    105743790 :   else if (TREE_CODE (type) == UNION_TYPE)
    7483              :     {
    7484          137 :       tree field;
    7485              : 
    7486          192 :       for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    7487          185 :         if (TREE_TYPE (field) != error_mark_node
    7488          369 :             && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field)),
    7489          184 :                           TYPE_MAIN_VARIANT (TREE_TYPE (value))))
    7490              :           break;
    7491              : 
    7492          137 :       if (field)
    7493              :         {
    7494          130 :           tree t;
    7495          130 :           bool maybe_const = true;
    7496              : 
    7497          130 :           pedwarn (loc, OPT_Wpedantic, "ISO C forbids casts to union type");
    7498          130 :           t = c_fully_fold (value, false, &maybe_const);
    7499          130 :           t = build_constructor_single (type, field, t);
    7500          130 :           if (!maybe_const)
    7501           15 :             t = c_wrap_maybe_const (t, true);
    7502          130 :           t = digest_init (loc, field, type, t,
    7503              :                            NULL_TREE, false, false, false, true, false, false);
    7504          130 :           TREE_CONSTANT (t) = TREE_CONSTANT (value);
    7505          130 :           return t;
    7506              :         }
    7507            7 :       error_at (loc, "cast to union type from type not present in union");
    7508            7 :       return error_mark_node;
    7509              :     }
    7510              :   else
    7511              :     {
    7512    105743653 :       tree otype, ovalue;
    7513              : 
    7514    105743653 :       if (type == void_type_node)
    7515              :         {
    7516        18698 :           tree t = build1 (CONVERT_EXPR, type, value);
    7517        18698 :           SET_EXPR_LOCATION (t, loc);
    7518        18698 :           return t;
    7519              :         }
    7520              : 
    7521    105724955 :       otype = TREE_TYPE (value);
    7522              : 
    7523              :       /* Optionally warn about potentially worrisome casts.  */
    7524    105724955 :       if (warn_cast_qual
    7525       204404 :           && TREE_CODE (type) == POINTER_TYPE
    7526        27455 :           && TREE_CODE (otype) == POINTER_TYPE)
    7527        14107 :         handle_warn_cast_qual (loc, type, otype);
    7528              : 
    7529              :       /* Warn about conversions between pointers to disjoint
    7530              :          address spaces.  */
    7531    105724955 :       if (TREE_CODE (type) == POINTER_TYPE
    7532      3368366 :           && TREE_CODE (otype) == POINTER_TYPE
    7533    108745812 :           && !null_pointer_constant_p (value))
    7534              :         {
    7535      2966659 :           addr_space_t as_to = TYPE_ADDR_SPACE (TREE_TYPE (type));
    7536      2966659 :           addr_space_t as_from = TYPE_ADDR_SPACE (TREE_TYPE (otype));
    7537      2966659 :           addr_space_t as_common;
    7538              : 
    7539      2966659 :           if (!addr_space_superset (as_to, as_from, &as_common))
    7540              :             {
    7541            0 :               if (ADDR_SPACE_GENERIC_P (as_from))
    7542            0 :                 warning_at (loc, 0, "cast to %qs address space pointer "
    7543              :                             "from disjoint generic address space pointer",
    7544              :                             c_addr_space_name (as_to));
    7545              : 
    7546            0 :               else if (ADDR_SPACE_GENERIC_P (as_to))
    7547            0 :                 warning_at (loc, 0, "cast to generic address space pointer "
    7548              :                             "from disjoint %qs address space pointer",
    7549              :                             c_addr_space_name (as_from));
    7550              : 
    7551              :               else
    7552            0 :                 warning_at (loc, 0, "cast to %qs address space pointer "
    7553              :                             "from disjoint %qs address space pointer",
    7554              :                             c_addr_space_name (as_to),
    7555              :                             c_addr_space_name (as_from));
    7556              :             }
    7557              : 
    7558              :           /* Warn of new allocations that are not big enough for the target
    7559              :              type.  */
    7560      2966659 :           if (warn_alloc_size && TREE_CODE (value) == CALL_EXPR)
    7561         1069 :             if (tree fndecl = get_callee_fndecl (value))
    7562         1065 :               if (DECL_IS_MALLOC (fndecl))
    7563              :                 {
    7564          573 :                   tree attrs = TYPE_ATTRIBUTES (TREE_TYPE (fndecl));
    7565          573 :                   tree alloc_size = lookup_attribute ("alloc_size", attrs);
    7566          573 :                   if (alloc_size)
    7567          215 :                     warn_for_alloc_size (loc, TREE_TYPE (type), value,
    7568              :                                          alloc_size);
    7569              :                 }
    7570              :         }
    7571              : 
    7572              :       /* Warn about possible alignment problems.  */
    7573    105724955 :       if ((STRICT_ALIGNMENT || warn_cast_align == 2)
    7574            7 :           && TREE_CODE (type) == POINTER_TYPE
    7575            7 :           && TREE_CODE (otype) == POINTER_TYPE
    7576            7 :           && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE
    7577            7 :           && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
    7578              :           /* Don't warn about opaque types, where the actual alignment
    7579              :              restriction is unknown.  */
    7580           12 :           && !(RECORD_OR_UNION_TYPE_P (TREE_TYPE (otype))
    7581            5 :                && TYPE_MODE (TREE_TYPE (otype)) == VOIDmode)
    7582    105724969 :           && min_align_of_type (TREE_TYPE (type))
    7583            7 :              > min_align_of_type (TREE_TYPE (otype)))
    7584            5 :         warning_at (loc, OPT_Wcast_align,
    7585              :                     "cast increases required alignment of target type");
    7586              : 
    7587    105724955 :       if ((TREE_CODE (type) == INTEGER_TYPE
    7588    105724955 :            || TREE_CODE (type) == BITINT_TYPE)
    7589      7378109 :           && TREE_CODE (otype) == POINTER_TYPE
    7590    105750419 :           && TYPE_PRECISION (type) != TYPE_PRECISION (otype))
    7591              :       /* Unlike conversion of integers to pointers, where the
    7592              :          warning is disabled for converting constants because
    7593              :          of cases such as SIG_*, warn about converting constant
    7594              :          pointers to integers. In some cases it may cause unwanted
    7595              :          sign extension, and a warning is appropriate.  */
    7596         1464 :         warning_at (loc, OPT_Wpointer_to_int_cast,
    7597              :                     "cast from pointer to integer of different size");
    7598              : 
    7599    105724955 :       if ((TREE_CODE (value) == CALL_EXPR
    7600     36201718 :            && !is_access_with_size_p (value))
    7601    141926669 :           && TREE_CODE (type) != TREE_CODE (otype))
    7602         2304 :         warning_at (loc, OPT_Wbad_function_cast,
    7603              :                     "cast from function call of type %qT "
    7604              :                     "to non-matching type %qT", otype, type);
    7605              : 
    7606    105724955 :       if (TREE_CODE (type) == POINTER_TYPE
    7607      3368366 :           && (TREE_CODE (otype) == INTEGER_TYPE
    7608      3368366 :               || TREE_CODE (otype) == BITINT_TYPE)
    7609       347420 :           && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
    7610              :           /* Don't warn about converting any constant.  */
    7611    106034378 :           && !TREE_CONSTANT (value))
    7612          407 :         warning_at (loc,
    7613          407 :                     OPT_Wint_to_pointer_cast, "cast to pointer from integer "
    7614              :                     "of different size");
    7615              : 
    7616    105724955 :       if (warn_strict_aliasing <= 2)
    7617     96947563 :         strict_aliasing_warning (EXPR_LOCATION (value), type, expr);
    7618              : 
    7619              :       /* If pedantic, warn for conversions between function and object
    7620              :          pointer types, except for converting a null pointer constant
    7621              :          to function pointer type.  */
    7622    105724955 :       if (pedantic
    7623       261493 :           && TREE_CODE (type) == POINTER_TYPE
    7624       144380 :           && TREE_CODE (otype) == POINTER_TYPE
    7625         3035 :           && TREE_CODE (TREE_TYPE (otype)) == FUNCTION_TYPE
    7626    105724976 :           && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE)
    7627           18 :         pedwarn (loc, OPT_Wpedantic, "ISO C forbids "
    7628              :                  "conversion of function pointer to object pointer type");
    7629              : 
    7630    105724955 :       if (pedantic
    7631       261493 :           && TREE_CODE (type) == POINTER_TYPE
    7632       144380 :           && TREE_CODE (otype) == POINTER_TYPE
    7633         3035 :           && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
    7634           13 :           && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
    7635    105724965 :           && !null_pointer_constant_p (value))
    7636            4 :         pedwarn (loc, OPT_Wpedantic, "ISO C forbids "
    7637              :                  "conversion of object pointer to function pointer type");
    7638              : 
    7639    105724955 :       if (TREE_CODE (type) == POINTER_TYPE
    7640      3368366 :           && TREE_CODE (otype) == POINTER_TYPE
    7641      3020857 :           && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
    7642         8684 :           && TREE_CODE (TREE_TYPE (otype)) == FUNCTION_TYPE
    7643    105732518 :           && !c_safe_function_type_cast_p (TREE_TYPE (type),
    7644         7563 :                                            TREE_TYPE (otype)))
    7645          803 :         warning_at (loc, OPT_Wcast_function_type,
    7646              :                     "cast between incompatible function types"
    7647              :                     " from %qT to %qT", otype, type);
    7648              : 
    7649    105724955 :       ovalue = value;
    7650              :       /* If converting to boolean a value with integer operands that
    7651              :          is not itself represented as an INTEGER_CST, the call below
    7652              :          to note_integer_operands may insert a C_MAYBE_CONST_EXPR, but
    7653              :          build_binary_op as called by c_common_truthvalue_conversion
    7654              :          may also insert a C_MAYBE_CONST_EXPR to indicate that a
    7655              :          subexpression has been fully folded.  To avoid nested
    7656              :          C_MAYBE_CONST_EXPR, ensure that
    7657              :          c_objc_common_truthvalue_conversion receives an argument
    7658              :          properly marked as having integer operands in that case.  */
    7659    105724955 :       if (int_operands
    7660      6968376 :           && TREE_CODE (value) != INTEGER_CST
    7661    105724997 :           && (TREE_CODE (type) == BOOLEAN_TYPE
    7662           28 :               || (TREE_CODE (type) == ENUMERAL_TYPE
    7663           14 :                   && ENUM_UNDERLYING_TYPE (type) != NULL_TREE
    7664           14 :                   && TREE_CODE (ENUM_UNDERLYING_TYPE (type)) == BOOLEAN_TYPE)))
    7665           28 :         value = note_integer_operands (value);
    7666    105724955 :       value = convert (type, value);
    7667              : 
    7668              :       /* Ignore any integer overflow caused by the cast.  */
    7669    105724955 :       if (TREE_CODE (value) == INTEGER_CST && !FLOAT_TYPE_P (otype))
    7670              :         {
    7671      6915096 :           if (TREE_OVERFLOW_P (ovalue))
    7672              :             {
    7673            9 :               if (!TREE_OVERFLOW (value))
    7674              :                 {
    7675              :                   /* Avoid clobbering a shared constant.  */
    7676            0 :                   value = copy_node (value);
    7677            0 :                   TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue);
    7678              :                 }
    7679              :             }
    7680      6915087 :           else if (TREE_OVERFLOW (value))
    7681              :             /* Reset VALUE's overflow flags, ensuring constant sharing.  */
    7682         3107 :             value = wide_int_to_tree (TREE_TYPE (value), wi::to_wide (value));
    7683              :         }
    7684              :     }
    7685              : 
    7686              :   /* Don't let a cast be an lvalue.  */
    7687    124555920 :   if (lvalue_p (value)
    7688              :       /* Also, don't let a cast be a bit-field of a bit-precise integer type,
    7689              :          otherwise it could be incorrectly subject of integer promotions.  */
    7690    124555920 :       || (TREE_CODE (value) == COMPONENT_REF
    7691           24 :           && DECL_C_BIT_FIELD (TREE_OPERAND (value, 1))
    7692           24 :           && BITINT_TYPE_P (DECL_BIT_FIELD_TYPE (TREE_OPERAND (value, 1)))))
    7693        91278 :     value = non_lvalue_loc (loc, value);
    7694              : 
    7695              :   /* Don't allow the results of casting to floating-point or complex
    7696              :      types be confused with actual constants, or casts involving
    7697              :      integer and pointer types other than direct integer-to-integer
    7698              :      and integer-to-pointer be confused with integer constant
    7699              :      expressions and null pointer constants.  */
    7700    124555920 :   if (TREE_CODE (value) == REAL_CST
    7701    124505968 :       || TREE_CODE (value) == COMPLEX_CST
    7702    249039262 :       || (TREE_CODE (value) == INTEGER_CST
    7703      7165161 :           && !((TREE_CODE (expr) == INTEGER_CST
    7704      7091223 :                 && INTEGRAL_TYPE_P (TREE_TYPE (expr)))
    7705        66535 :                || TREE_CODE (expr) == REAL_CST
    7706              :                || TREE_CODE (expr) == COMPLEX_CST)))
    7707       134746 :       value = build1 (NOP_EXPR, type, value);
    7708              : 
    7709              :   /* If the expression has integer operands and so can occur in an
    7710              :      unevaluated part of an integer constant expression, ensure the
    7711              :      return value reflects this.  */
    7712    124555920 :   if (int_operands
    7713      7145442 :       && INTEGRAL_TYPE_P (type)
    7714      6698156 :       && value != error_mark_node
    7715    131254075 :       && !EXPR_INT_CONST_OPERANDS (value))
    7716           11 :     value = note_integer_operands (value);
    7717              : 
    7718    124555920 :   protected_set_expr_location (value, loc);
    7719    124555920 :   return value;
    7720              : }
    7721              : 
    7722              : /* Interpret a cast of expression EXPR to type TYPE.  LOC is the
    7723              :    location of the open paren of the cast, or the position of the cast
    7724              :    expr.  */
    7725              : tree
    7726    124575290 : c_cast_expr (location_t loc, struct c_type_name *type_name, tree expr)
    7727              : {
    7728    124575290 :   tree type;
    7729    124575290 :   tree type_expr = NULL_TREE;
    7730    124575290 :   bool type_expr_const = true;
    7731    124575290 :   tree ret;
    7732    124575290 :   int saved_wsp = warn_strict_prototypes;
    7733              : 
    7734              :   /* This avoids warnings about unprototyped casts on
    7735              :      integers.  E.g. "#define SIG_DFL (void(*)())0".  */
    7736    124575290 :   if (TREE_CODE (expr) == INTEGER_CST)
    7737      7213724 :     warn_strict_prototypes = 0;
    7738    124575290 :   type = groktypename (type_name, &type_expr, &type_expr_const);
    7739    124575290 :   warn_strict_prototypes = saved_wsp;
    7740              : 
    7741       765536 :   if (TREE_CODE (expr) == ADDR_EXPR && !VOID_TYPE_P (type)
    7742    125340571 :       && reject_gcc_builtin (expr))
    7743            2 :     return error_mark_node;
    7744              : 
    7745    124575288 :   ret = build_c_cast (loc, type, expr);
    7746    124575288 :   if (ret == error_mark_node)
    7747              :     return error_mark_node;
    7748              : 
    7749    124574128 :   if (type_expr)
    7750              :     {
    7751          250 :       bool inner_expr_const = true;
    7752          250 :       ret = c_fully_fold (ret, require_constant_value, &inner_expr_const);
    7753          250 :       ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret), type_expr, ret);
    7754          500 :       C_MAYBE_CONST_EXPR_NON_CONST (ret) = !(type_expr_const
    7755          145 :                                              && inner_expr_const);
    7756          250 :       SET_EXPR_LOCATION (ret, loc);
    7757              :     }
    7758              : 
    7759    124574128 :   if (!EXPR_HAS_LOCATION (ret))
    7760      7091683 :     protected_set_expr_location (ret, loc);
    7761              : 
    7762              :   /* C++ does not permits types to be defined in a cast, but it
    7763              :      allows references to incomplete types.  */
    7764    124574128 :   if (warn_cxx_compat && type_name->specs->typespec_kind == ctsk_tagdef)
    7765            1 :     warning_at (loc, OPT_Wc___compat,
    7766              :                 "defining a type in a cast is invalid in C++");
    7767              : 
    7768              :   return ret;
    7769              : }
    7770              : 
    7771              : /* Build an assignment expression of lvalue LHS from value RHS.
    7772              :    If LHS_ORIGTYPE is not NULL, it is the original type of LHS, which
    7773              :    may differ from TREE_TYPE (LHS) for an enum bitfield.
    7774              :    MODIFYCODE is the code for a binary operator that we use
    7775              :    to combine the old value of LHS with RHS to get the new value.
    7776              :    Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
    7777              :    If RHS_ORIGTYPE is not NULL_TREE, it is the original type of RHS,
    7778              :    which may differ from TREE_TYPE (RHS) for an enum value.
    7779              : 
    7780              :    LOCATION is the location of the MODIFYCODE operator.
    7781              :    RHS_LOC is the location of the RHS.  */
    7782              : 
    7783              : tree
    7784      2934237 : build_modify_expr (location_t location, tree lhs, tree lhs_origtype,
    7785              :                    enum tree_code modifycode,
    7786              :                    location_t rhs_loc, tree rhs, tree rhs_origtype)
    7787              : {
    7788      2934237 :   tree result;
    7789      2934237 :   tree newrhs;
    7790      2934237 :   tree rhseval = NULL_TREE;
    7791      2934237 :   tree lhstype = TREE_TYPE (lhs);
    7792      2934237 :   tree olhstype = lhstype;
    7793      2934237 :   bool npc;
    7794      2934237 :   bool is_atomic_op;
    7795              : 
    7796              :   /* Types that aren't fully specified cannot be used in assignments.  */
    7797      2934237 :   lhs = require_complete_type (location, lhs);
    7798      2934237 :   rhs = require_complete_type (location, rhs);
    7799              : 
    7800              :   /* Avoid duplicate error messages from operands that had errors.  */
    7801      2934237 :   if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK)
    7802          473 :     return error_mark_node;
    7803              : 
    7804              :   /* Ensure an error for assigning a non-lvalue array to an array in
    7805              :      C90.  */
    7806      2933764 :   if (TREE_CODE (lhstype) == ARRAY_TYPE)
    7807              :     {
    7808            1 :       error_at (location, "assignment to expression with array type");
    7809            1 :       return error_mark_node;
    7810              :     }
    7811              : 
    7812              :   /* For ObjC properties, defer this check.  */
    7813      2933763 :   if (!objc_is_property_ref (lhs) && !lvalue_or_else (location, lhs, lv_assign))
    7814           32 :     return error_mark_node;
    7815              : 
    7816      2933731 :   is_atomic_op = really_atomic_lvalue (lhs);
    7817              : 
    7818      2933731 :   newrhs = rhs;
    7819              : 
    7820      2933731 :   if (TREE_CODE (lhs) == C_MAYBE_CONST_EXPR)
    7821              :     {
    7822            2 :       tree inner = build_modify_expr (location, C_MAYBE_CONST_EXPR_EXPR (lhs),
    7823              :                                       lhs_origtype, modifycode, rhs_loc, rhs,
    7824              :                                       rhs_origtype);
    7825            2 :       if (inner == error_mark_node)
    7826              :         return error_mark_node;
    7827            4 :       result = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner),
    7828            2 :                        C_MAYBE_CONST_EXPR_PRE (lhs), inner);
    7829            2 :       gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (lhs));
    7830            2 :       C_MAYBE_CONST_EXPR_NON_CONST (result) = 1;
    7831            2 :       protected_set_expr_location (result, location);
    7832            2 :       return result;
    7833              :     }
    7834              : 
    7835              :   /* If a binary op has been requested, combine the old LHS value with the RHS
    7836              :      producing the value we should actually store into the LHS.  */
    7837              : 
    7838      2933729 :   if (modifycode != NOP_EXPR)
    7839              :     {
    7840       218082 :       lhs = c_fully_fold (lhs, false, NULL, true);
    7841       218082 :       lhs = stabilize_reference (lhs);
    7842              : 
    7843              :       /* Construct the RHS for any non-atomic compound assignment. */
    7844       218082 :       if (!is_atomic_op)
    7845              :         {
    7846              :           /* If in LHS op= RHS the RHS has side-effects, ensure they
    7847              :              are preevaluated before the rest of the assignment expression's
    7848              :              side-effects, because RHS could contain e.g. function calls
    7849              :              that modify LHS.  */
    7850       202597 :           if (TREE_SIDE_EFFECTS (rhs))
    7851              :             {
    7852         8930 :               if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
    7853           28 :                 newrhs = save_expr (TREE_OPERAND (rhs, 0));
    7854              :               else
    7855         8902 :                 newrhs = save_expr (rhs);
    7856         8930 :               rhseval = newrhs;
    7857         8930 :               if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
    7858           28 :                 newrhs = build1 (EXCESS_PRECISION_EXPR, TREE_TYPE (rhs),
    7859              :                                  newrhs);
    7860              :             }
    7861       202597 :           bool clear_decl_read = false;
    7862        89629 :           if ((VAR_P (lhs) || TREE_CODE (lhs) == PARM_DECL)
    7863       155941 :               && !DECL_READ_P (lhs)
    7864       255669 :               && (VAR_P (lhs) ? warn_unused_but_set_variable
    7865              :                               : warn_unused_but_set_parameter) > 2)
    7866              :             {
    7867        21663 :               mark_exp_read (newrhs);
    7868        21663 :               if (!DECL_READ_P (lhs))
    7869       202597 :                 clear_decl_read = true;
    7870              :             }
    7871              : 
    7872       202597 :           newrhs = build_binary_op (location, modifycode,
    7873              :                                     convert_lvalue_to_rvalue (location, lhs,
    7874              :                                                               true, true),
    7875              :                                     newrhs, true);
    7876       202597 :           if (clear_decl_read)
    7877        21663 :             DECL_READ_P (lhs) = 0;
    7878              : 
    7879              :           /* The original type of the right hand side is no longer
    7880              :              meaningful.  */
    7881              :           rhs_origtype = NULL_TREE;
    7882              :         }
    7883              :     }
    7884              : 
    7885      2933729 :   if (c_dialect_objc ())
    7886              :     {
    7887              :       /* Check if we are modifying an Objective-C property reference;
    7888              :          if so, we need to generate setter calls.  */
    7889            0 :       if (TREE_CODE (newrhs) == EXCESS_PRECISION_EXPR)
    7890            0 :         result = objc_maybe_build_modify_expr (lhs, TREE_OPERAND (newrhs, 0));
    7891              :       else
    7892            0 :         result = objc_maybe_build_modify_expr (lhs, newrhs);
    7893            0 :       if (result)
    7894            0 :         goto return_result;
    7895              : 
    7896              :       /* Else, do the check that we postponed for Objective-C.  */
    7897            0 :       if (!lvalue_or_else (location, lhs, lv_assign))
    7898            0 :         return error_mark_node;
    7899              :     }
    7900              : 
    7901              :   /* Give an error for storing in something that is 'const'.  */
    7902              : 
    7903      2933729 :   if (TYPE_READONLY (lhstype)
    7904      2933729 :       || (RECORD_OR_UNION_TYPE_P (lhstype)
    7905        25838 :           && C_TYPE_FIELDS_READONLY (lhstype)))
    7906              :     {
    7907           88 :       readonly_error (location, lhs, lv_assign);
    7908           88 :       return error_mark_node;
    7909              :     }
    7910      2933641 :   else if (TREE_READONLY (lhs))
    7911            1 :     readonly_warning (lhs, lv_assign);
    7912              : 
    7913              :   /* If storing into a structure or union member,
    7914              :      it has probably been given type `int'.
    7915              :      Compute the type that would go with
    7916              :      the actual amount of storage the member occupies.  */
    7917              : 
    7918      2933641 :   if (TREE_CODE (lhs) == COMPONENT_REF
    7919       251074 :       && (TREE_CODE (lhstype) == INTEGER_TYPE
    7920       251074 :           || TREE_CODE (lhstype) == BOOLEAN_TYPE
    7921       110654 :           || SCALAR_FLOAT_TYPE_P (lhstype)
    7922        87209 :           || TREE_CODE (lhstype) == ENUMERAL_TYPE))
    7923       170869 :     lhstype = TREE_TYPE (get_unwidened (lhs, 0));
    7924              : 
    7925              :   /* If storing in a field that is in actuality a short or narrower than one,
    7926              :      we must store in the field in its actual type.  */
    7927              : 
    7928      2933641 :   if (lhstype != TREE_TYPE (lhs))
    7929              :     {
    7930            0 :       lhs = copy_node (lhs);
    7931            0 :       TREE_TYPE (lhs) = lhstype;
    7932              :     }
    7933              : 
    7934              :   /* Issue -Wc++-compat warnings about an assignment to an enum type
    7935              :      when LHS does not have its original type.  This happens for,
    7936              :      e.g., an enum bitfield in a struct.  */
    7937      2933641 :   if (warn_cxx_compat
    7938         3275 :       && lhs_origtype != NULL_TREE
    7939         3275 :       && lhs_origtype != lhstype
    7940            7 :       && TREE_CODE (lhs_origtype) == ENUMERAL_TYPE)
    7941              :     {
    7942            4 :       tree checktype = (rhs_origtype != NULL_TREE
    7943            4 :                         ? rhs_origtype
    7944            0 :                         : TREE_TYPE (rhs));
    7945            4 :       if (checktype != error_mark_node
    7946            4 :           && (TYPE_MAIN_VARIANT (checktype) != TYPE_MAIN_VARIANT (lhs_origtype)
    7947            2 :               || (is_atomic_op && modifycode != NOP_EXPR)))
    7948            2 :         warning_at (location, OPT_Wc___compat,
    7949              :                     "enum conversion in assignment is invalid in C++");
    7950              :     }
    7951              : 
    7952              :   /* Remove qualifiers.  */
    7953      2933641 :   lhstype = c_build_qualified_type (lhstype, TYPE_UNQUALIFIED);
    7954      2933641 :   olhstype = c_build_qualified_type (olhstype, TYPE_UNQUALIFIED);
    7955              : 
    7956              :   /* Convert new value to destination type.  Fold it first, then
    7957              :      restore any excess precision information, for the sake of
    7958              :      conversion warnings.  */
    7959              : 
    7960      2933641 :   if (!(is_atomic_op && modifycode != NOP_EXPR))
    7961              :     {
    7962      2918156 :       tree rhs_semantic_type = NULL_TREE;
    7963      2918156 :       if (!c_in_omp_for)
    7964              :         {
    7965      2901795 :           if (TREE_CODE (newrhs) == EXCESS_PRECISION_EXPR)
    7966              :             {
    7967         5081 :               rhs_semantic_type = TREE_TYPE (newrhs);
    7968         5081 :               newrhs = TREE_OPERAND (newrhs, 0);
    7969              :             }
    7970      2901795 :           npc = null_pointer_constant_p (newrhs);
    7971      2901795 :           newrhs = c_fully_fold (newrhs, false, NULL);
    7972      2901795 :           if (rhs_semantic_type)
    7973         5081 :             newrhs = build1 (EXCESS_PRECISION_EXPR, rhs_semantic_type, newrhs);
    7974              :         }
    7975              :       else
    7976        16361 :         npc = null_pointer_constant_p (newrhs);
    7977      2918156 :       newrhs = convert_for_assignment (location, rhs_loc, lhstype, newrhs,
    7978              :                                        rhs_origtype, ic_assign, npc,
    7979              :                                        NULL_TREE, NULL_TREE, 0);
    7980      2918156 :       if (TREE_CODE (newrhs) == ERROR_MARK)
    7981          127 :         return error_mark_node;
    7982              :     }
    7983              : 
    7984              :   /* Emit ObjC write barrier, if necessary.  */
    7985      2933514 :   if (c_dialect_objc () && flag_objc_gc)
    7986              :     {
    7987            0 :       result = objc_generate_write_barrier (lhs, modifycode, newrhs);
    7988            0 :       if (result)
    7989              :         {
    7990            0 :           protected_set_expr_location (result, location);
    7991            0 :           goto return_result;
    7992              :         }
    7993              :     }
    7994              : 
    7995              :   /* Scan operands.  */
    7996              : 
    7997      2933514 :   if (is_atomic_op)
    7998        25988 :     result = build_atomic_assign (location, lhs, modifycode, newrhs, false);
    7999              :   else
    8000              :     {
    8001      2907526 :       result = build2 (MODIFY_EXPR, lhstype, lhs, newrhs);
    8002      2907526 :       TREE_SIDE_EFFECTS (result) = 1;
    8003      2907526 :       protected_set_expr_location (result, location);
    8004              :     }
    8005              : 
    8006              :   /* If we got the LHS in a different type for storing in,
    8007              :      convert the result back to the nominal type of LHS
    8008              :      so that the value we return always has the same type
    8009              :      as the LHS argument.  */
    8010              : 
    8011      2933514 :   if (olhstype == TREE_TYPE (result))
    8012      2933514 :     goto return_result;
    8013              : 
    8014            0 :   result = convert_for_assignment (location, rhs_loc, olhstype, result,
    8015              :                                    rhs_origtype, ic_assign, false, NULL_TREE,
    8016              :                                    NULL_TREE, 0);
    8017            0 :   protected_set_expr_location (result, location);
    8018              : 
    8019      2933514 : return_result:
    8020      2933514 :   if (rhseval)
    8021         8930 :     result = build2 (COMPOUND_EXPR, TREE_TYPE (result), rhseval, result);
    8022              :   return result;
    8023              : }
    8024              : 
    8025              : /* Return whether STRUCT_TYPE has an anonymous field with type TYPE.
    8026              :    This is used to implement -fplan9-extensions.  */
    8027              : 
    8028              : static bool
    8029           26 : find_anonymous_field_with_type (tree struct_type, tree type)
    8030              : {
    8031           26 :   tree field;
    8032           26 :   bool found;
    8033              : 
    8034           26 :   gcc_assert (RECORD_OR_UNION_TYPE_P (struct_type));
    8035           26 :   found = false;
    8036           26 :   for (field = TYPE_FIELDS (struct_type);
    8037           68 :        field != NULL_TREE;
    8038           42 :        field = TREE_CHAIN (field))
    8039              :     {
    8040           42 :       tree fieldtype = remove_qualifiers (TREE_TYPE (field));
    8041           42 :       if (DECL_NAME (field) == NULL
    8042           42 :           && comptypes (type, fieldtype))
    8043              :         {
    8044            4 :           if (found)
    8045              :             return false;
    8046              :           found = true;
    8047              :         }
    8048           38 :       else if (DECL_NAME (field) == NULL
    8049            2 :                && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field))
    8050           40 :                && find_anonymous_field_with_type (TREE_TYPE (field), type))
    8051              :         {
    8052            0 :           if (found)
    8053              :             return false;
    8054              :           found = true;
    8055              :         }
    8056              :     }
    8057              :   return found;
    8058              : }
    8059              : 
    8060              : /* RHS is an expression whose type is pointer to struct.  If there is
    8061              :    an anonymous field in RHS with type TYPE, then return a pointer to
    8062              :    that field in RHS.  This is used with -fplan9-extensions.  This
    8063              :    returns NULL if no conversion could be found.  */
    8064              : 
    8065              : static tree
    8066           28 : convert_to_anonymous_field (location_t location, tree type, tree rhs)
    8067              : {
    8068           28 :   tree rhs_struct_type, lhs_main_type;
    8069           28 :   tree field, found_field;
    8070           28 :   bool found_sub_field;
    8071           28 :   tree ret;
    8072              : 
    8073           28 :   gcc_assert (POINTER_TYPE_P (TREE_TYPE (rhs)));
    8074           28 :   rhs_struct_type = TREE_TYPE (TREE_TYPE (rhs));
    8075           28 :   gcc_assert (RECORD_OR_UNION_TYPE_P (rhs_struct_type));
    8076              : 
    8077           28 :   gcc_assert (POINTER_TYPE_P (type));
    8078           28 :   lhs_main_type = remove_qualifiers (TREE_TYPE (type));
    8079              : 
    8080           28 :   found_field = NULL_TREE;
    8081           28 :   found_sub_field = false;
    8082           28 :   for (field = TYPE_FIELDS (rhs_struct_type);
    8083          172 :        field != NULL_TREE;
    8084          144 :        field = TREE_CHAIN (field))
    8085              :     {
    8086          148 :       if (DECL_NAME (field) != NULL_TREE
    8087          148 :           || !RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)))
    8088           96 :         continue;
    8089           52 :       tree fieldtype = remove_qualifiers (TREE_TYPE (field));
    8090           52 :       if (comptypes (lhs_main_type, fieldtype))
    8091              :         {
    8092           28 :           if (found_field != NULL_TREE)
    8093              :             return NULL_TREE;
    8094              :           found_field = field;
    8095              :         }
    8096           24 :       else if (find_anonymous_field_with_type (TREE_TYPE (field),
    8097              :                                                lhs_main_type))
    8098              :         {
    8099            4 :           if (found_field != NULL_TREE)
    8100              :             return NULL_TREE;
    8101              :           found_field = field;
    8102              :           found_sub_field = true;
    8103              :         }
    8104              :     }
    8105              : 
    8106           24 :   if (found_field == NULL_TREE)
    8107              :     return NULL_TREE;
    8108              : 
    8109           24 :   ret = fold_build3_loc (location, COMPONENT_REF, TREE_TYPE (found_field),
    8110              :                          build_fold_indirect_ref (rhs), found_field,
    8111              :                          NULL_TREE);
    8112           24 :   ret = build_fold_addr_expr_loc (location, ret);
    8113              : 
    8114           24 :   if (found_sub_field)
    8115              :     {
    8116            2 :       ret = convert_to_anonymous_field (location, type, ret);
    8117            2 :       gcc_assert (ret != NULL_TREE);
    8118              :     }
    8119              : 
    8120              :   return ret;
    8121              : }
    8122              : 
    8123              : /* Issue an error message for a bad initializer component.
    8124              :    GMSGID identifies the message.
    8125              :    The component name is taken from the spelling stack.  */
    8126              : 
    8127              : static void ATTRIBUTE_GCC_DIAG (2,0)
    8128          944 : error_init (location_t loc, const char *gmsgid, ...)
    8129              : {
    8130          944 :   char *ofwhat;
    8131              : 
    8132          944 :   auto_diagnostic_group d;
    8133              : 
    8134              :   /* The gmsgid may be a format string with %< and %>. */
    8135          944 :   va_list ap;
    8136          944 :   va_start (ap, gmsgid);
    8137          944 :   bool warned = emit_diagnostic_valist (diagnostics::kind::error,
    8138          944 :                                         loc, -1, gmsgid, &ap);
    8139          944 :   va_end (ap);
    8140              : 
    8141          944 :   ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
    8142          944 :   if (*ofwhat && warned)
    8143          220 :     inform (loc, "(near initialization for %qs)", ofwhat);
    8144          944 : }
    8145              : 
    8146              : /* Used to implement pedwarn_init and permerror_init.  */
    8147              : 
    8148              : static bool ATTRIBUTE_GCC_DIAG (3,0)
    8149         2478 : pedwarn_permerror_init (location_t loc, int opt, const char *gmsgid,
    8150              :                         va_list *ap, enum diagnostics::kind kind)
    8151              : {
    8152              :   /* Use the location where a macro was expanded rather than where
    8153              :      it was defined to make sure macros defined in system headers
    8154              :      but used incorrectly elsewhere are diagnosed.  */
    8155         2478 :   location_t exploc = expansion_point_location_if_in_system_header (loc);
    8156         2478 :   auto_diagnostic_group d;
    8157         2478 :   bool warned = emit_diagnostic_valist (kind, exploc, opt, gmsgid, ap);
    8158         2478 :   if (warned)
    8159              :     {
    8160         1815 :       char *ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
    8161         1815 :       if (*ofwhat)
    8162         1494 :         inform (exploc, "(near initialization for %qs)", ofwhat);
    8163              :     }
    8164         4956 :   return warned;
    8165         2478 : }
    8166              : 
    8167              : /* Issue a pedantic warning for a bad initializer component.  OPT is
    8168              :    the option OPT_* (from options.h) controlling this warning or 0 if
    8169              :    it is unconditionally given.  GMSGID identifies the message.  The
    8170              :    component name is taken from the spelling stack.  */
    8171              : 
    8172              : static bool ATTRIBUTE_GCC_DIAG (3,0)
    8173         2127 : pedwarn_init (location_t loc, int opt, const char *gmsgid, ...)
    8174              : {
    8175         2127 :   va_list ap;
    8176         2127 :   va_start (ap, gmsgid);
    8177         2127 :   bool warned = pedwarn_permerror_init (loc, opt, gmsgid, &ap,
    8178              :                                         diagnostics::kind::pedwarn);
    8179         2127 :   va_end (ap);
    8180         2127 :   return warned;
    8181              : }
    8182              : 
    8183              : /* Like pedwarn_init, but issue a permerror.  */
    8184              : 
    8185              : static bool ATTRIBUTE_GCC_DIAG (3,0)
    8186          351 : permerror_init (location_t loc, int opt, const char *gmsgid, ...)
    8187              : {
    8188          351 :   va_list ap;
    8189          351 :   va_start (ap, gmsgid);
    8190          351 :   bool warned = pedwarn_permerror_init (loc, opt, gmsgid, &ap,
    8191              :                                         diagnostics::kind::permerror);
    8192          351 :   va_end (ap);
    8193          351 :   return warned;
    8194              : }
    8195              : 
    8196              : /* Issue a warning for a bad initializer component.
    8197              : 
    8198              :    OPT is the OPT_W* value corresponding to the warning option that
    8199              :    controls this warning.  GMSGID identifies the message.  The
    8200              :    component name is taken from the spelling stack.  */
    8201              : 
    8202              : static void
    8203          146 : warning_init (location_t loc, int opt, const char *gmsgid)
    8204              : {
    8205          146 :   char *ofwhat;
    8206          146 :   bool warned;
    8207              : 
    8208          146 :   auto_diagnostic_group d;
    8209              : 
    8210              :   /* Use the location where a macro was expanded rather than where
    8211              :      it was defined to make sure macros defined in system headers
    8212              :      but used incorrectly elsewhere are diagnosed.  */
    8213          146 :   location_t exploc = expansion_point_location_if_in_system_header (loc);
    8214              : 
    8215              :   /* The gmsgid may be a format string with %< and %>. */
    8216          146 :   warned = warning_at (exploc, opt, gmsgid);
    8217          146 :   if (warned)
    8218              :     {
    8219          133 :       ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
    8220          133 :       if (*ofwhat)
    8221          133 :         inform (exploc, "(near initialization for %qs)", ofwhat);
    8222              :     }
    8223          146 : }
    8224              : 
    8225              : /* If TYPE is an array type and EXPR is a parenthesized string
    8226              :    constant, warn if pedantic that EXPR is being used to initialize an
    8227              :    object of type TYPE.  */
    8228              : 
    8229              : void
    8230      7330966 : maybe_warn_string_init (location_t loc, tree type, struct c_expr expr)
    8231              : {
    8232      7330966 :   if (pedantic
    8233        81875 :       && TREE_CODE (type) == ARRAY_TYPE
    8234         1207 :       && TREE_CODE (expr.value) == STRING_CST
    8235          472 :       && expr.original_code != STRING_CST)
    8236           13 :     pedwarn_init (loc, OPT_Wpedantic,
    8237              :                   "array initialized from parenthesized string constant");
    8238      7330966 : }
    8239              : 
    8240              : /* Attempt to locate the parameter with the given index within FNDECL,
    8241              :    returning DECL_SOURCE_LOCATION (FNDECL) if it can't be found.  */
    8242              : 
    8243              : static location_t
    8244          937 : get_fndecl_argument_location (tree fndecl, int argnum)
    8245              : {
    8246          937 :   int i;
    8247          937 :   tree param;
    8248              : 
    8249              :   /* Locate param by index within DECL_ARGUMENTS (fndecl).  */
    8250          937 :   for (i = 0, param = DECL_ARGUMENTS (fndecl);
    8251         1016 :        i < argnum && param;
    8252           79 :        i++, param = TREE_CHAIN (param))
    8253              :     ;
    8254              : 
    8255              :   /* If something went wrong (e.g. if we have a builtin and thus no arguments),
    8256              :      return DECL_SOURCE_LOCATION (FNDECL).  */
    8257          937 :   if (param == NULL)
    8258          653 :     return DECL_SOURCE_LOCATION (fndecl);
    8259              : 
    8260          284 :   return DECL_SOURCE_LOCATION (param);
    8261              : }
    8262              : 
    8263              : /* Issue a note about a mismatching argument for parameter PARMNUM
    8264              :    to FUNDECL, for types EXPECTED_TYPE and ACTUAL_TYPE.
    8265              :    Attempt to issue the note at the pertinent parameter of the decl;
    8266              :    failing that issue it at the location of FUNDECL; failing that
    8267              :    issue it at PLOC.
    8268              :    Use highlight_colors::actual for the ACTUAL_TYPE
    8269              :    and highlight_colors::expected for EXPECTED_TYPE and the
    8270              :    parameter of FUNDECL*/
    8271              : 
    8272              : static void
    8273         1062 : inform_for_arg (tree fundecl, location_t ploc, int parmnum,
    8274              :                 tree expected_type, tree actual_type)
    8275              : {
    8276         1062 :   location_t loc;
    8277         1062 :   if (fundecl && !DECL_IS_UNDECLARED_BUILTIN (fundecl))
    8278          937 :     loc = get_fndecl_argument_location (fundecl, parmnum - 1);
    8279              :   else
    8280              :     loc = ploc;
    8281              : 
    8282         1062 :   gcc_rich_location richloc (loc, nullptr, highlight_colors::expected);
    8283              : 
    8284         1062 :   pp_markup::element_expected_type elem_expected_type (expected_type);
    8285         1062 :   pp_markup::element_actual_type elem_actual_type (actual_type);
    8286         1062 :   inform (&richloc,
    8287              :           "expected %e but argument is of type %e",
    8288              :           &elem_expected_type, &elem_actual_type);
    8289         1062 : }
    8290              : 
    8291              : /* Issue a warning when an argument of ARGTYPE is passed to a built-in
    8292              :    function FUNDECL declared without prototype to parameter PARMNUM of
    8293              :    PARMTYPE when ARGTYPE does not promote to PARMTYPE.  */
    8294              : 
    8295              : static void
    8296          418 : maybe_warn_builtin_no_proto_arg (location_t loc, tree fundecl, int parmnum,
    8297              :                                  tree parmtype, tree argtype)
    8298              : {
    8299          418 :   tree_code parmcode = TREE_CODE (parmtype);
    8300          418 :   tree_code argcode = TREE_CODE (argtype);
    8301          418 :   tree promoted = c_type_promotes_to (argtype);
    8302              : 
    8303              :   /* Avoid warning for enum arguments that promote to an integer type
    8304              :      of the same size/mode.  */
    8305          418 :   if (parmcode == INTEGER_TYPE
    8306          418 :       && argcode == ENUMERAL_TYPE
    8307          418 :       && TYPE_MODE (parmtype) == TYPE_MODE (argtype))
    8308              :     return;
    8309              : 
    8310          417 :   if ((parmcode == argcode
    8311          222 :        || (parmcode == INTEGER_TYPE
    8312              :            && argcode == ENUMERAL_TYPE))
    8313          418 :       && TYPE_MAIN_VARIANT (parmtype) == TYPE_MAIN_VARIANT (promoted))
    8314              :     return;
    8315              : 
    8316              :   /* This diagnoses even signed/unsigned mismatches.  Those might be
    8317              :      safe in many cases but GCC may emit suboptimal code for them so
    8318              :      warning on those cases drives efficiency improvements.  */
    8319          398 :   if (warning_at (loc, OPT_Wbuiltin_declaration_mismatch,
    8320          398 :                   TYPE_MAIN_VARIANT (promoted) == argtype
    8321              :                   ? G_("%qD argument %d type is %qT where %qT is expected "
    8322              :                        "in a call to built-in function declared without "
    8323              :                        "prototype")
    8324              :                   : G_("%qD argument %d promotes to %qT where %qT is expected "
    8325              :                        "in a call to built-in function declared without "
    8326              :                        "prototype"),
    8327              :                   fundecl, parmnum, promoted, parmtype))
    8328          150 :     inform (DECL_SOURCE_LOCATION (fundecl),
    8329              :             "built-in %qD declared here",
    8330              :             fundecl);
    8331              : }
    8332              : 
    8333              : /* Print a declaration in quotes, with the given highlight_color.
    8334              :    Analogous to handler for %qD, but with a specific highlight color.  */
    8335              : 
    8336          199 : class pp_element_quoted_decl : public pp_element
    8337              : {
    8338              : public:
    8339          199 :   pp_element_quoted_decl (tree decl, const char *highlight_color)
    8340          199 :   : m_decl (decl),
    8341          199 :     m_highlight_color (highlight_color)
    8342              :   {
    8343              :   }
    8344              : 
    8345          199 :   void add_to_phase_2 (pp_markup::context &ctxt) override
    8346              :   {
    8347          199 :     ctxt.begin_quote ();
    8348          199 :     ctxt.begin_highlight_color (m_highlight_color);
    8349              : 
    8350          199 :     print_decl (ctxt);
    8351              : 
    8352          199 :     ctxt.end_highlight_color ();
    8353          199 :     ctxt.end_quote ();
    8354          199 :   }
    8355              : 
    8356          199 :   void print_decl (pp_markup::context &ctxt)
    8357              :   {
    8358          199 :     pretty_printer *const pp = &ctxt.m_pp;
    8359          199 :     pp->set_padding (pp_none);
    8360          199 :     if (DECL_NAME (m_decl))
    8361          199 :       pp_identifier (pp, lang_hooks.decl_printable_name (m_decl, 2));
    8362              :     else
    8363            0 :       pp_string (pp, _("({anonymous})"));
    8364          199 :   }
    8365              : 
    8366              : private:
    8367              :   tree m_decl;
    8368              :   const char *m_highlight_color;
    8369              : };
    8370              : 
    8371              : /* If TYPE is from a typedef, issue a note showing the location
    8372              :    to the user.
    8373              :    Use HIGHLIGHT_COLOR as the highlight color.  */
    8374              : 
    8375              : static void
    8376         1180 : maybe_inform_typedef_location (tree type, const char *highlight_color)
    8377              : {
    8378         1180 :   if (!typedef_variant_p (type))
    8379         1146 :     return;
    8380              : 
    8381           34 :   tree typedef_decl = TYPE_NAME (type);
    8382           34 :   gcc_assert (TREE_CODE (typedef_decl) == TYPE_DECL);
    8383           34 :   gcc_rich_location richloc (DECL_SOURCE_LOCATION (typedef_decl),
    8384           34 :                              nullptr, highlight_color);
    8385           34 :   pp_element_quoted_decl e_typedef_decl (typedef_decl, highlight_color);
    8386           34 :   inform (&richloc, "%e declared here", &e_typedef_decl);
    8387           34 : }
    8388              : 
    8389              : /* Convert value RHS to type TYPE as preparation for an assignment to
    8390              :    an lvalue of type TYPE.  If ORIGTYPE is not NULL_TREE, it is the
    8391              :    original type of RHS; this differs from TREE_TYPE (RHS) for enum
    8392              :    types.  NULL_POINTER_CONSTANT says whether RHS was a null pointer
    8393              :    constant before any folding.
    8394              :    The real work of conversion is done by `convert'.
    8395              :    The purpose of this function is to generate error messages
    8396              :    for assignments that are not allowed in C.
    8397              :    ERRTYPE says whether it is argument passing, assignment,
    8398              :    initialization or return.
    8399              : 
    8400              :    In the following example, '~' denotes where EXPR_LOC and '^' where
    8401              :    LOCATION point to:
    8402              : 
    8403              :      f (var);      [ic_argpass]
    8404              :      ^  ~~~
    8405              :      x = var;      [ic_assign]
    8406              :        ^ ~~~;
    8407              :      int x = var;  [ic_init]
    8408              :              ^^^
    8409              :      return x;     [ic_return]
    8410              :             ^
    8411              : 
    8412              :    FUNCTION is a tree for the function being called.
    8413              :    PARMNUM is the number of the argument, for printing in error messages.
    8414              :    WARNOPT may be set to a warning option to issue the corresponding warning
    8415              :    rather than an error for invalid conversions.  Used for calls to built-in
    8416              :    functions declared without a prototype.  */
    8417              : 
    8418              : static tree
    8419    171869524 : convert_for_assignment (location_t location, location_t expr_loc, tree type,
    8420              :                         tree rhs, tree origtype, enum impl_conv errtype,
    8421              :                         bool null_pointer_constant, tree fundecl,
    8422              :                         tree function, int parmnum, int warnopt /* = 0 */)
    8423              : {
    8424    171869524 :   enum tree_code codel = TREE_CODE (type);
    8425    171869524 :   tree orig_rhs = rhs;
    8426    171869524 :   tree rhstype;
    8427    171869524 :   enum tree_code coder;
    8428    171869524 :   tree rname = NULL_TREE;
    8429    171869524 :   bool objc_ok = false;
    8430              : 
    8431              :   /* Use the expansion point location to handle cases such as user's
    8432              :      function returning a wrong-type macro defined in a system header.  */
    8433    171869524 :   location = expansion_point_location_if_in_system_header (location);
    8434              : 
    8435    171869524 :   if (errtype == ic_argpass)
    8436              :     {
    8437    129280239 :       tree selector;
    8438              :       /* Change pointer to function to the function itself for
    8439              :          diagnostics.  */
    8440    129280239 :       if (TREE_CODE (function) == ADDR_EXPR
    8441    129280239 :           && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL)
    8442            0 :         function = TREE_OPERAND (function, 0);
    8443              : 
    8444              :       /* Handle an ObjC selector specially for diagnostics.  */
    8445    129280239 :       selector = objc_message_selector ();
    8446    129280239 :       rname = function;
    8447    129280239 :       if (selector && parmnum > 2)
    8448              :         {
    8449            0 :           rname = selector;
    8450            0 :           parmnum -= 2;
    8451              :         }
    8452              :     }
    8453              : 
    8454              :   /* This macro is used to emit diagnostics to ensure that all format
    8455              :      strings are complete sentences, visible to gettext and checked at
    8456              :      compile time.  */
    8457              : #define PEDWARN_FOR_ASSIGNMENT(LOCATION, PLOC, OPT, AR, AS, IN, RE)      \
    8458              :   do {                                                                   \
    8459              :     switch (errtype)                                                     \
    8460              :       {                                                                  \
    8461              :       case ic_argpass:                                                   \
    8462              :         {                                                               \
    8463              :           auto_diagnostic_group d;                                              \
    8464              :           if (pedwarn (PLOC, OPT, AR, parmnum, rname))          \
    8465              :             inform_for_arg (fundecl, (PLOC), parmnum, type, rhstype); \
    8466              :         }                                                               \
    8467              :         break;                                                           \
    8468              :       case ic_assign:                                                    \
    8469              :         pedwarn (LOCATION, OPT, AS);                                     \
    8470              :         break;                                                           \
    8471              :       case ic_init:                                                      \
    8472              :       case ic_init_const:                                                \
    8473              :         pedwarn_init (LOCATION, OPT, IN);                                \
    8474              :         break;                                                           \
    8475              :       case ic_return:                                                    \
    8476              :         pedwarn (LOCATION, OPT, RE);                                     \
    8477              :         break;                                                           \
    8478              :       default:                                                           \
    8479              :         gcc_unreachable ();                                              \
    8480              :       }                                                                  \
    8481              :   } while (0)
    8482              : 
    8483              :   /* This macro is used to emit diagnostics to ensure that all format
    8484              :      strings are complete sentences, visible to gettext and checked at
    8485              :      compile time.  It can be called with 'pedwarn' or 'warning_at'.  */
    8486              : #define WARNING_FOR_QUALIFIERS(PEDWARN, LOCATION, PLOC, OPT, AR, AS, IN, RE, QUALS) \
    8487              :   do {                                                                   \
    8488              :     switch (errtype)                                                     \
    8489              :       {                                                                  \
    8490              :       case ic_argpass:                                                   \
    8491              :         {                                                                \
    8492              :           auto_diagnostic_group d;                                       \
    8493              :           if (PEDWARN) {                                                 \
    8494              :             if (pedwarn (PLOC, OPT, AR, parmnum, rname, QUALS))          \
    8495              :               inform_for_arg (fundecl, (PLOC), parmnum, type, rhstype);  \
    8496              :           } else {                                                       \
    8497              :             if (warning_at (PLOC, OPT, AR, parmnum, rname, QUALS))       \
    8498              :               inform_for_arg (fundecl, (PLOC), parmnum, type, rhstype);  \
    8499              :           }                                                              \
    8500              :         }                                                                \
    8501              :         break;                                                           \
    8502              :       case ic_assign:                                                    \
    8503              :         if (PEDWARN)                                                     \
    8504              :           pedwarn (LOCATION, OPT, AS, QUALS);                            \
    8505              :         else                                                             \
    8506              :           warning_at (LOCATION, OPT, AS, QUALS);                         \
    8507              :         break;                                                           \
    8508              :       case ic_init:                                                      \
    8509              :       case ic_init_const:                                                \
    8510              :         if (PEDWARN)                                                     \
    8511              :           pedwarn (LOCATION, OPT, IN, QUALS);                            \
    8512              :         else                                                             \
    8513              :           warning_at (LOCATION, OPT, IN, QUALS);                         \
    8514              :         break;                                                           \
    8515              :       case ic_return:                                                    \
    8516              :         if (PEDWARN)                                                     \
    8517              :           pedwarn (LOCATION, OPT, RE, QUALS);                            \
    8518              :         else                                                             \
    8519              :           warning_at (LOCATION, OPT, RE, QUALS);                         \
    8520              :         break;                                                           \
    8521              :       default:                                                           \
    8522              :         gcc_unreachable ();                                              \
    8523              :       }                                                                  \
    8524              :   } while (0)
    8525              : 
    8526              :   /* This macro is used to emit diagnostics to ensure that all format
    8527              :      strings are complete sentences, visible to gettext and checked at
    8528              :      compile time.  It is the same as PEDWARN_FOR_ASSIGNMENT but with an
    8529              :      extra parameter to enumerate qualifiers.  */
    8530              : #define PEDWARN_FOR_QUALIFIERS(LOCATION, PLOC, OPT, AR, AS, IN, RE, QUALS) \
    8531              :    WARNING_FOR_QUALIFIERS (true, LOCATION, PLOC, OPT, AR, AS, IN, RE, QUALS)
    8532              : 
    8533              : 
    8534    171869524 :   if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
    8535         5990 :     rhs = TREE_OPERAND (rhs, 0);
    8536              : 
    8537    171869524 :   rhstype = TREE_TYPE (rhs);
    8538    171869524 :   coder = TREE_CODE (rhstype);
    8539              : 
    8540    171869524 :   if (coder == ERROR_MARK)
    8541          347 :     return error_mark_node;
    8542              : 
    8543    171869177 :   if (c_dialect_objc ())
    8544              :     {
    8545            0 :       int parmno;
    8546              : 
    8547            0 :       switch (errtype)
    8548              :         {
    8549              :         case ic_return:
    8550              :           parmno = 0;
    8551              :           break;
    8552              : 
    8553              :         case ic_assign:
    8554              :           parmno = -1;
    8555              :           break;
    8556              : 
    8557              :         case ic_init:
    8558              :         case ic_init_const:
    8559              :           parmno = -2;
    8560              :           break;
    8561              : 
    8562              :         default:
    8563            0 :           parmno = parmnum;
    8564              :           break;
    8565              :         }
    8566              : 
    8567            0 :       objc_ok = objc_compare_types (type, rhstype, parmno, rname);
    8568              :     }
    8569              : 
    8570    171869177 :   if (warn_cxx_compat)
    8571              :     {
    8572        29134 :       tree checktype = origtype != NULL_TREE ? origtype : rhstype;
    8573        29134 :       if (checktype != error_mark_node
    8574        29134 :           && TREE_CODE (type) == ENUMERAL_TYPE
    8575        29240 :           && TYPE_MAIN_VARIANT (checktype) != TYPE_MAIN_VARIANT (type))
    8576           45 :         switch (errtype)
    8577              :           {
    8578            8 :           case ic_argpass:
    8579            8 :             if (pedwarn (expr_loc, OPT_Wc___compat, "enum conversion when "
    8580              :                          "passing argument %d of %qE is invalid in C++",
    8581              :                          parmnum, rname))
    8582           16 :               inform ((fundecl && !DECL_IS_UNDECLARED_BUILTIN (fundecl))
    8583            8 :                       ? DECL_SOURCE_LOCATION (fundecl) : expr_loc,
    8584              :                       "expected %qT but argument is of type %qT",
    8585              :                       type, rhstype);
    8586              :             break;
    8587           10 :           case ic_assign:
    8588           10 :             pedwarn (location, OPT_Wc___compat, "enum conversion from %qT to "
    8589              :                      "%qT in assignment is invalid in C++", rhstype, type);
    8590           10 :             break;
    8591           18 :           case ic_init:
    8592           18 :           case ic_init_const:
    8593           18 :             pedwarn_init (location, OPT_Wc___compat, "enum conversion from "
    8594              :                           "%qT to %qT in initialization is invalid in C++",
    8595              :                           rhstype, type);
    8596           18 :             break;
    8597            9 :           case ic_return:
    8598            9 :             pedwarn (location, OPT_Wc___compat, "enum conversion from %qT to "
    8599              :                      "%qT in return is invalid in C++", rhstype, type);
    8600            9 :             break;
    8601            0 :           default:
    8602            0 :             gcc_unreachable ();
    8603              :           }
    8604              :     }
    8605              : 
    8606    171869177 :   if (warn_enum_conversion)
    8607              :     {
    8608     14902350 :       tree checktype = origtype != NULL_TREE ? origtype : rhstype;
    8609     14902350 :       if (checktype != error_mark_node
    8610     14902350 :           && TREE_CODE (checktype) == ENUMERAL_TYPE
    8611        12851 :           && TREE_CODE (type) == ENUMERAL_TYPE
    8612     14910654 :           && !comptypes (TYPE_MAIN_VARIANT (checktype), TYPE_MAIN_VARIANT (type)))
    8613              :        {
    8614            7 :           gcc_rich_location loc (location);
    8615            7 :           warning_at (&loc, OPT_Wenum_conversion,
    8616              :                       "implicit conversion from %qT to %qT",
    8617              :                       checktype, type);
    8618            7 :        }
    8619              :     }
    8620              : 
    8621    171869177 :   if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
    8622              :     {
    8623    152543699 :       warn_for_address_of_packed_member (type, orig_rhs);
    8624    152543699 :       if (type != rhstype)
    8625              :         /* Convert RHS to TYPE in order to not lose TYPE in diagnostics.  */
    8626     37925447 :         rhs = convert (type, rhs);
    8627              :       return rhs;
    8628              :     }
    8629              : 
    8630     19325478 :   if (coder == VOID_TYPE)
    8631              :     {
    8632              :       /* Except for passing an argument to an unprototyped function,
    8633              :          this is a constraint violation.  When passing an argument to
    8634              :          an unprototyped function, it is compile-time undefined;
    8635              :          making it a constraint in that case was rejected in
    8636              :          DR#252.  */
    8637            8 :       const char msg[] = "void value not ignored as it ought to be";
    8638            8 :       if (warnopt)
    8639            0 :         warning_at (location, warnopt, msg);
    8640              :       else
    8641            8 :         error_at (location, msg);
    8642            8 :       return error_mark_node;
    8643              :     }
    8644     19325470 :   rhs = require_complete_type (location, rhs);
    8645     19325470 :   if (rhs == error_mark_node)
    8646              :     return error_mark_node;
    8647              : 
    8648     19325470 :   if (coder == POINTER_TYPE && reject_gcc_builtin (rhs))
    8649            6 :     return error_mark_node;
    8650              : 
    8651              :   /* A non-reference type can convert to a reference.  This handles
    8652              :      va_start, va_copy and possibly port built-ins.  */
    8653     19325464 :   if (codel == REFERENCE_TYPE && coder != REFERENCE_TYPE)
    8654              :     {
    8655          290 :       if (!lvalue_p (rhs))
    8656              :         {
    8657            0 :           const char msg[] = "cannot pass rvalue to reference parameter";
    8658            0 :           if (warnopt)
    8659            0 :             warning_at (location, warnopt, msg);
    8660              :           else
    8661            0 :             error_at (location, msg);
    8662            0 :           return error_mark_node;
    8663              :         }
    8664          290 :       if (!c_mark_addressable (rhs))
    8665            0 :         return error_mark_node;
    8666          290 :       rhs = build1 (ADDR_EXPR, c_build_pointer_type (TREE_TYPE (rhs)), rhs);
    8667          290 :       SET_EXPR_LOCATION (rhs, location);
    8668              : 
    8669          290 :       rhs = convert_for_assignment (location, expr_loc,
    8670          290 :                                     c_build_pointer_type (TREE_TYPE (type)),
    8671              :                                     rhs, origtype, errtype,
    8672              :                                     null_pointer_constant, fundecl, function,
    8673              :                                     parmnum, warnopt);
    8674          290 :       if (rhs == error_mark_node)
    8675              :         return error_mark_node;
    8676              : 
    8677          290 :       rhs = build1 (NOP_EXPR, type, rhs);
    8678          290 :       SET_EXPR_LOCATION (rhs, location);
    8679          290 :       return rhs;
    8680              :     }
    8681              :   /* Some types can interconvert without explicit casts.  */
    8682     19325174 :   else if (codel == VECTOR_TYPE && coder == VECTOR_TYPE
    8683     19325174 :            && vector_types_convertible_p (type, TREE_TYPE (rhs), true))
    8684      9344530 :     return convert (type, rhs);
    8685              :   /* Arithmetic types all interconvert, and enum is treated like int.  */
    8686      9980644 :   else if ((codel == INTEGER_TYPE || codel == REAL_TYPE
    8687      2299030 :             || codel == FIXED_POINT_TYPE
    8688      2299030 :             || codel == ENUMERAL_TYPE || codel == COMPLEX_TYPE
    8689      2212468 :             || codel == BOOLEAN_TYPE || codel == BITINT_TYPE)
    8690      7869148 :            && (coder == INTEGER_TYPE || coder == REAL_TYPE
    8691        84023 :                || coder == FIXED_POINT_TYPE
    8692        84023 :                || coder == ENUMERAL_TYPE || coder == COMPLEX_TYPE
    8693        40697 :                || coder == BOOLEAN_TYPE || coder == BITINT_TYPE))
    8694              :     {
    8695      7867771 :       if (warnopt && errtype == ic_argpass)
    8696          418 :         maybe_warn_builtin_no_proto_arg (expr_loc, fundecl, parmnum, type,
    8697              :                                          rhstype);
    8698              : 
    8699      7867771 :       bool save = in_late_binary_op;
    8700      7830543 :       if (C_BOOLEAN_TYPE_P (type) || codel == COMPLEX_TYPE
    8701     15641149 :           || (coder == REAL_TYPE
    8702       277246 :               && (codel == INTEGER_TYPE || codel == ENUMERAL_TYPE)
    8703        24232 :               && sanitize_flags_p (SANITIZE_FLOAT_CAST)))
    8704       101137 :         in_late_binary_op = true;
    8705     11271114 :       tree ret = convert_and_check (expr_loc != UNKNOWN_LOCATION
    8706              :                                     ? expr_loc : location, type, orig_rhs,
    8707              :                                     errtype == ic_init_const);
    8708      7867771 :       in_late_binary_op = save;
    8709      7867771 :       return ret;
    8710              :     }
    8711              : 
    8712              :   /* Aggregates in different TUs might need conversion.  */
    8713      2112873 :   if ((codel == RECORD_TYPE || codel == UNION_TYPE)
    8714          105 :       && codel == coder
    8715      2112895 :       && comptypes (TYPE_MAIN_VARIANT (type), TYPE_MAIN_VARIANT (rhstype)))
    8716            9 :     return convert_and_check (expr_loc != UNKNOWN_LOCATION
    8717            9 :                               ? expr_loc : location, type, rhs);
    8718              : 
    8719              :   /* Conversion to a transparent union or record from its member types.
    8720              :      This applies only to function arguments.  */
    8721      2112864 :   if (((codel == UNION_TYPE || codel == RECORD_TYPE)
    8722           96 :       && TYPE_TRANSPARENT_AGGR (type))
    8723      2112903 :       && errtype == ic_argpass)
    8724              :     {
    8725           39 :       tree memb, marginal_memb = NULL_TREE;
    8726              : 
    8727           50 :       for (memb = TYPE_FIELDS (type); memb ; memb = DECL_CHAIN (memb))
    8728              :         {
    8729           50 :           tree memb_type = TREE_TYPE (memb);
    8730              : 
    8731           50 :           if (comptypes (TYPE_MAIN_VARIANT (memb_type),
    8732           50 :                          TYPE_MAIN_VARIANT (rhstype)))
    8733              :             break;
    8734              : 
    8735           27 :           if (TREE_CODE (memb_type) != POINTER_TYPE)
    8736            1 :             continue;
    8737              : 
    8738           26 :           if (coder == POINTER_TYPE)
    8739              :             {
    8740           26 :               tree ttl = TREE_TYPE (memb_type);
    8741           26 :               tree ttr = TREE_TYPE (rhstype);
    8742              : 
    8743              :               /* Any non-function converts to a [const][volatile] void *
    8744              :                  and vice versa; otherwise, targets must be the same.
    8745              :                  Meanwhile, the lhs target must have all the qualifiers of
    8746              :                  the rhs.  */
    8747            0 :               if ((VOID_TYPE_P (ttl) && !TYPE_ATOMIC (ttl))
    8748           26 :                   || (VOID_TYPE_P (ttr) && !TYPE_ATOMIC (ttr))
    8749           45 :                   || comp_target_types (location, memb_type, rhstype))
    8750              :                 {
    8751           16 :                   int lquals = TYPE_QUALS (ttl) & ~TYPE_QUAL_ATOMIC;
    8752           16 :                   int rquals = TYPE_QUALS (ttr) & ~TYPE_QUAL_ATOMIC;
    8753              :                   /* If this type won't generate any warnings, use it.  */
    8754           16 :                   if (lquals == rquals
    8755           16 :                       || ((TREE_CODE (ttr) == FUNCTION_TYPE
    8756            0 :                            && TREE_CODE (ttl) == FUNCTION_TYPE)
    8757            0 :                           ? ((lquals | rquals) == rquals)
    8758           16 :                           : ((lquals | rquals) == lquals)))
    8759              :                     break;
    8760              : 
    8761              :                   /* Keep looking for a better type, but remember this one.  */
    8762            0 :                   if (!marginal_memb)
    8763           10 :                     marginal_memb = memb;
    8764              :                 }
    8765              :             }
    8766              : 
    8767              :           /* Can convert integer zero to any pointer type.  */
    8768           10 :           if (null_pointer_constant)
    8769              :             {
    8770            0 :               rhs = null_pointer_node;
    8771            0 :               break;
    8772              :             }
    8773              :         }
    8774              : 
    8775           39 :       if (memb || marginal_memb)
    8776              :         {
    8777           39 :           if (!memb)
    8778              :             {
    8779              :               /* We have only a marginally acceptable member type;
    8780              :                  it needs a warning.  */
    8781            0 :               tree ttl = TREE_TYPE (TREE_TYPE (marginal_memb));
    8782            0 :               tree ttr = TREE_TYPE (rhstype);
    8783              : 
    8784              :               /* Const and volatile mean something different for function
    8785              :                  types, so the usual warnings are not appropriate.  */
    8786            0 :               if (TREE_CODE (ttr) == FUNCTION_TYPE
    8787            0 :                   && TREE_CODE (ttl) == FUNCTION_TYPE)
    8788              :                 {
    8789              :                   /* Because const and volatile on functions are
    8790              :                      restrictions that say the function will not do
    8791              :                      certain things, it is okay to use a const or volatile
    8792              :                      function where an ordinary one is wanted, but not
    8793              :                      vice-versa.  */
    8794            0 :                   if (TYPE_QUALS_NO_ADDR_SPACE (ttl)
    8795            0 :                       & ~TYPE_QUALS_NO_ADDR_SPACE (ttr))
    8796            0 :                     PEDWARN_FOR_QUALIFIERS (location, expr_loc,
    8797              :                                             OPT_Wdiscarded_qualifiers,
    8798              :                                             G_("passing argument %d of %qE "
    8799              :                                                "makes %q#v qualified function "
    8800              :                                                "pointer from unqualified"),
    8801              :                                             G_("assignment makes %q#v qualified "
    8802              :                                                "function pointer from "
    8803              :                                                "unqualified"),
    8804              :                                             G_("initialization makes %q#v qualified "
    8805              :                                                "function pointer from "
    8806              :                                                "unqualified"),
    8807              :                                             G_("return makes %q#v qualified function "
    8808              :                                                "pointer from unqualified"),
    8809              :                                             TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr));
    8810              :                 }
    8811            0 :               else if (TYPE_QUALS_NO_ADDR_SPACE (ttr)
    8812            0 :                        & ~TYPE_QUALS_NO_ADDR_SPACE (ttl))
    8813            0 :                 PEDWARN_FOR_QUALIFIERS (location, expr_loc,
    8814              :                                         OPT_Wdiscarded_qualifiers,
    8815              :                                         G_("passing argument %d of %qE discards "
    8816              :                                            "%qv qualifier from pointer target type"),
    8817              :                                         G_("assignment discards %qv qualifier "
    8818              :                                            "from pointer target type"),
    8819              :                                         G_("initialization discards %qv qualifier "
    8820              :                                            "from pointer target type"),
    8821              :                                         G_("return discards %qv qualifier from "
    8822              :                                            "pointer target type"),
    8823              :                                         TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl));
    8824              : 
    8825              :               memb = marginal_memb;
    8826              :             }
    8827              : 
    8828           39 :           if (!fundecl || !DECL_IN_SYSTEM_HEADER (fundecl))
    8829           31 :             pedwarn (location, OPT_Wpedantic,
    8830              :                      "ISO C prohibits argument conversion to union type");
    8831              : 
    8832           39 :           rhs = fold_convert_loc (location, TREE_TYPE (memb), rhs);
    8833           39 :           return build_constructor_single (type, memb, rhs);
    8834              :         }
    8835              :     }
    8836              : 
    8837              :   /* Conversions among pointers */
    8838      2112825 :   else if ((codel == POINTER_TYPE || codel == REFERENCE_TYPE)
    8839      2111292 :            && (coder == codel))
    8840              :     {
    8841              :       /* If RHS refers to a built-in declared without a prototype
    8842              :          BLTIN is the declaration of the built-in with a prototype
    8843              :          and RHSTYPE is set to the actual type of the built-in.  */
    8844      2032758 :       tree bltin;
    8845      2032758 :       rhstype = type_or_builtin_type (rhs, &bltin);
    8846              : 
    8847      2032758 :       tree ttl = TREE_TYPE (type);
    8848      2032758 :       tree ttr = TREE_TYPE (rhstype);
    8849      2032758 :       bool is_opaque_pointer;
    8850      2032758 :       bool target_cmp = false;   /* Cache comp_target_types () result.  */
    8851      2032758 :       addr_space_t asl;
    8852      2032758 :       addr_space_t asr;
    8853              : 
    8854      2032758 :       tree mvl = remove_qualifiers (ttl);
    8855      2032758 :       tree mvr = remove_qualifiers (ttr);
    8856              : 
    8857              :       /* Opaque pointers are treated like void pointers.  */
    8858      2032758 :       is_opaque_pointer = vector_targets_convertible_p (ttl, ttr);
    8859              : 
    8860              :       /* The Plan 9 compiler permits a pointer to a struct to be
    8861              :          automatically converted into a pointer to an anonymous field
    8862              :          within the struct.  */
    8863      2032758 :       if (flag_plan9_extensions
    8864           50 :           && RECORD_OR_UNION_TYPE_P (mvl)
    8865           26 :           && RECORD_OR_UNION_TYPE_P (mvr)
    8866           26 :           && mvl != mvr)
    8867              :         {
    8868           26 :           tree new_rhs = convert_to_anonymous_field (location, type, rhs);
    8869           26 :           if (new_rhs != NULL_TREE)
    8870              :             {
    8871           22 :               rhs = new_rhs;
    8872           22 :               rhstype = TREE_TYPE (rhs);
    8873           22 :               coder = TREE_CODE (rhstype);
    8874           22 :               ttr = TREE_TYPE (rhstype);
    8875           22 :               mvr = TYPE_MAIN_VARIANT (ttr);
    8876              :             }
    8877              :         }
    8878              : 
    8879              :       /* C++ does not allow the implicit conversion void* -> T*.  However,
    8880              :          for the purpose of reducing the number of false positives, we
    8881              :          tolerate the special case of
    8882              : 
    8883              :                 int *p = NULL;
    8884              : 
    8885              :          where NULL is typically defined in C to be '(void *) 0'.  */
    8886      2032758 :       if (VOID_TYPE_P (ttr) && rhs != null_pointer_node && !VOID_TYPE_P (ttl))
    8887        27471 :         warning_at (errtype == ic_argpass ? expr_loc : location,
    8888        14559 :                     OPT_Wc___compat,
    8889              :                     "request for implicit conversion "
    8890              :                     "from %qT to %qT not permitted in C++", rhstype, type);
    8891              : 
    8892              :       /* Warn of new allocations that are not big enough for the target
    8893              :          type.  */
    8894      2032758 :       if (warn_alloc_size && TREE_CODE (rhs) == CALL_EXPR)
    8895         5463 :         if (tree fndecl = get_callee_fndecl (rhs))
    8896         5463 :           if (DECL_IS_MALLOC (fndecl))
    8897              :             {
    8898         4614 :               tree attrs = TYPE_ATTRIBUTES (TREE_TYPE (fndecl));
    8899         4614 :               tree alloc_size = lookup_attribute ("alloc_size", attrs);
    8900         4614 :               if (alloc_size)
    8901          451 :                 warn_for_alloc_size (location, ttl, rhs, alloc_size);
    8902              :             }
    8903              : 
    8904              :       /* See if the pointers point to incompatible address spaces.  */
    8905      2032758 :       asl = TYPE_ADDR_SPACE (ttl);
    8906      2032758 :       asr = TYPE_ADDR_SPACE (ttr);
    8907      2032758 :       if (!null_pointer_constant_p (rhs)
    8908      2032758 :           && asr != asl && !targetm.addr_space.subset_p (asr, asl))
    8909              :         {
    8910            3 :           auto_diagnostic_group d;
    8911            3 :           bool diagnosed = true;
    8912            3 :           switch (errtype)
    8913              :             {
    8914            1 :             case ic_argpass:
    8915            1 :               {
    8916            1 :                 const char msg[] = G_("passing argument %d of %qE from "
    8917              :                                       "pointer to non-enclosed address space");
    8918            1 :                 if (warnopt)
    8919            0 :                   diagnosed
    8920            0 :                     = warning_at (expr_loc, warnopt, msg, parmnum, rname);
    8921              :                 else
    8922            1 :                   error_at (expr_loc, msg, parmnum, rname);
    8923            0 :               break;
    8924              :               }
    8925            0 :             case ic_assign:
    8926            0 :               {
    8927            0 :                 const char msg[] = G_("assignment from pointer to "
    8928              :                                       "non-enclosed address space");
    8929            0 :                 if (warnopt)
    8930            0 :                   diagnosed = warning_at (location, warnopt, msg);
    8931              :                 else
    8932            0 :                   error_at (location, msg);
    8933            0 :                 break;
    8934              :               }
    8935            0 :             case ic_init:
    8936            0 :             case ic_init_const:
    8937            0 :               {
    8938            0 :                 const char msg[] = G_("initialization from pointer to "
    8939              :                                       "non-enclosed address space");
    8940            0 :                 if (warnopt)
    8941            0 :                   diagnosed = warning_at (location, warnopt, msg);
    8942              :                 else
    8943            0 :                   error_at (location, msg);
    8944            0 :                 break;
    8945              :               }
    8946            2 :             case ic_return:
    8947            2 :               {
    8948            2 :                 const char msg[] = G_("return from pointer to "
    8949              :                                       "non-enclosed address space");
    8950            2 :                 if (warnopt)
    8951            0 :                   diagnosed = warning_at (location, warnopt, msg);
    8952              :                 else
    8953            2 :                   error_at (location, msg);
    8954            0 :                 break;
    8955              :               }
    8956            0 :             default:
    8957            0 :               gcc_unreachable ();
    8958              :             }
    8959            3 :           if (diagnosed)
    8960              :             {
    8961            3 :               if (errtype == ic_argpass)
    8962            1 :                 inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
    8963              :               else
    8964            2 :                 inform (location, "expected %qT but pointer is of type %qT",
    8965              :                         type, rhstype);
    8966              :             }
    8967            3 :           return error_mark_node;
    8968            3 :         }
    8969              : 
    8970              :       /* Check if the right-hand side has a format attribute but the
    8971              :          left-hand side doesn't.  */
    8972      2032755 :       if (warn_suggest_attribute_format
    8973      2032755 :           && check_missing_format_attribute (type, rhstype))
    8974              :         {
    8975           16 :           switch (errtype)
    8976              :           {
    8977            4 :           case ic_argpass:
    8978            4 :             warning_at (expr_loc, OPT_Wsuggest_attribute_format,
    8979              :                         "argument %d of %qE might be "
    8980              :                         "a candidate for a format attribute",
    8981              :                         parmnum, rname);
    8982            4 :             break;
    8983            4 :           case ic_assign:
    8984            4 :             warning_at (location, OPT_Wsuggest_attribute_format,
    8985              :                         "assignment left-hand side might be "
    8986              :                         "a candidate for a format attribute");
    8987            4 :             break;
    8988            4 :           case ic_init:
    8989            4 :           case ic_init_const:
    8990            4 :             warning_at (location, OPT_Wsuggest_attribute_format,
    8991              :                         "initialization left-hand side might be "
    8992              :                         "a candidate for a format attribute");
    8993            4 :             break;
    8994            4 :           case ic_return:
    8995            4 :             warning_at (location, OPT_Wsuggest_attribute_format,
    8996              :                         "return type might be "
    8997              :                         "a candidate for a format attribute");
    8998            4 :             break;
    8999            0 :           default:
    9000            0 :             gcc_unreachable ();
    9001              :           }
    9002              :         }
    9003              : 
    9004              :       /* See if the pointers point to incompatible scalar storage orders.  */
    9005      2032755 :       if (warn_scalar_storage_order
    9006      2029839 :           && !null_pointer_constant_p (rhs)
    9007      6023697 :           && (AGGREGATE_TYPE_P (ttl) && TYPE_REVERSE_STORAGE_ORDER (ttl))
    9008      1995471 :              != (AGGREGATE_TYPE_P (ttr) && TYPE_REVERSE_STORAGE_ORDER (ttr)))
    9009              :         {
    9010           18 :           tree t;
    9011              : 
    9012           18 :           switch (errtype)
    9013              :           {
    9014           11 :           case ic_argpass:
    9015              :             /* Do not warn for built-in functions, for example memcpy, since we
    9016              :                control how they behave and they can be useful in this area.  */
    9017           11 :             if (TREE_CODE (rname) != FUNCTION_DECL
    9018           11 :                 || !fndecl_built_in_p (rname))
    9019            1 :               warning_at (location, OPT_Wscalar_storage_order,
    9020              :                           "passing argument %d of %qE from incompatible "
    9021              :                           "scalar storage order", parmnum, rname);
    9022              :             break;
    9023            3 :           case ic_assign:
    9024              :             /* Do not warn if the RHS is a call to a function that returns a
    9025              :                pointer that is not an alias.  */
    9026            3 :             if (TREE_CODE (rhs) != CALL_EXPR
    9027            2 :                 || (t = get_callee_fndecl (rhs)) == NULL_TREE
    9028            5 :                 || !DECL_IS_MALLOC (t))
    9029            1 :               warning_at (location, OPT_Wscalar_storage_order,
    9030              :                           "assignment to %qT from pointer type %qT with "
    9031              :                           "incompatible scalar storage order", type, rhstype);
    9032              :             break;
    9033            3 :           case ic_init:
    9034            3 :           case ic_init_const:
    9035              :             /* Likewise.  */
    9036            3 :             if (TREE_CODE (rhs) != CALL_EXPR
    9037            2 :                 || (t = get_callee_fndecl (rhs)) == NULL_TREE
    9038            5 :                 || !DECL_IS_MALLOC (t))
    9039            1 :               warning_at (location, OPT_Wscalar_storage_order,
    9040              :                           "initialization of %qT from pointer type %qT with "
    9041              :                           "incompatible scalar storage order", type, rhstype);
    9042              :             break;
    9043            1 :           case ic_return:
    9044            1 :             warning_at (location, OPT_Wscalar_storage_order,
    9045              :                         "returning %qT from pointer type with incompatible "
    9046              :                         "scalar storage order %qT", rhstype, type);
    9047            1 :             break;
    9048            0 :           default:
    9049            0 :             gcc_unreachable ();
    9050              :           }
    9051              :         }
    9052              : 
    9053              :       /* Any non-function converts to a [const][volatile] void *
    9054              :          and vice versa; otherwise, targets must be the same.
    9055              :          Meanwhile, the lhs target must have all the qualifiers of the rhs.  */
    9056       420875 :       if ((VOID_TYPE_P (ttl) && !TYPE_ATOMIC (ttl))
    9057      1611881 :           || (VOID_TYPE_P (ttr) && !TYPE_ATOMIC (ttr))
    9058      1563093 :           || (target_cmp = comp_target_types (location, type, rhstype))
    9059         2502 :           || is_opaque_pointer
    9060      2037759 :           || ((c_common_unsigned_type (mvl)
    9061         2502 :                == c_common_unsigned_type (mvr))
    9062         3450 :               && (c_common_signed_type (mvl)
    9063         1725 :                   == c_common_signed_type (mvr))
    9064         1710 :               && TYPE_ATOMIC (mvl) == TYPE_ATOMIC (mvr)))
    9065              :         {
    9066              :           /* Warn about loss of qualifers from pointers to arrays with
    9067              :              qualifiers on the element type. */
    9068      2031955 :           if (TREE_CODE (ttr) == ARRAY_TYPE)
    9069              :             {
    9070         2131 :               ttr = strip_array_types (ttr);
    9071         2131 :               ttl = strip_array_types (ttl);
    9072              : 
    9073         2131 :               if (TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttr)
    9074         2131 :                   & ~TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttl))
    9075          115 :                 WARNING_FOR_QUALIFIERS (flag_isoc23,
    9076              :                                         location, expr_loc,
    9077              :                                         OPT_Wdiscarded_array_qualifiers,
    9078              :                                         G_("passing argument %d of %qE discards "
    9079              :                                            "%qv qualifier from pointer target type"),
    9080              :                                         G_("assignment discards %qv qualifier "
    9081              :                                            "from pointer target type"),
    9082              :                                         G_("initialization discards %qv qualifier "
    9083              :                                            "from pointer target type"),
    9084              :                                         G_("return discards %qv qualifier from "
    9085              :                                            "pointer target type"),
    9086              :                                         TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl));
    9087              :             }
    9088      2029824 :           else if (pedantic
    9089       146625 :               && ((VOID_TYPE_P (ttl) && TREE_CODE (ttr) == FUNCTION_TYPE)
    9090       146605 :                   ||
    9091              :                   (VOID_TYPE_P (ttr)
    9092         2923 :                    && !null_pointer_constant
    9093          184 :                    && TREE_CODE (ttl) == FUNCTION_TYPE)))
    9094           34 :             PEDWARN_FOR_ASSIGNMENT (location, expr_loc, OPT_Wpedantic,
    9095              :                                     G_("ISO C forbids passing argument %d of "
    9096              :                                        "%qE between function pointer "
    9097              :                                        "and %<void *%>"),
    9098              :                                     G_("ISO C forbids assignment between "
    9099              :                                        "function pointer and %<void *%>"),
    9100              :                                     G_("ISO C forbids initialization between "
    9101              :                                        "function pointer and %<void *%>"),
    9102              :                                     G_("ISO C forbids return between function "
    9103              :                                        "pointer and %<void *%>"));
    9104              :           /* Const and volatile mean something different for function types,
    9105              :              so the usual warnings are not appropriate.  */
    9106      2029790 :           else if (TREE_CODE (ttr) != FUNCTION_TYPE
    9107      1997350 :                    && TREE_CODE (ttl) != FUNCTION_TYPE)
    9108              :             {
    9109              :                /* Assignments between atomic and non-atomic objects are OK.  */
    9110      1996611 :                bool warn_quals_ped = TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttr)
    9111      1996611 :                                      & ~TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttl);
    9112      1996611 :                bool warn_quals = TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttr)
    9113      1996611 :                                  & ~TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (strip_array_types (ttl));
    9114              : 
    9115              :               /* Don't warn about loss of qualifier for conversions from
    9116              :                  qualified void* to pointers to arrays with corresponding
    9117              :                  qualifier on the element type (except for pedantic before C23). */
    9118      1996611 :               if (warn_quals || (warn_quals_ped && pedantic && !flag_isoc23))
    9119          697 :                 PEDWARN_FOR_QUALIFIERS (location, expr_loc,
    9120              :                                         OPT_Wdiscarded_qualifiers,
    9121              :                                         G_("passing argument %d of %qE discards "
    9122              :                                            "%qv qualifier from pointer target type"),
    9123              :                                         G_("assignment discards %qv qualifier "
    9124              :                                            "from pointer target type"),
    9125              :                                         G_("initialization discards %qv qualifier "
    9126              :                                            "from pointer target type"),
    9127              :                                         G_("return discards %qv qualifier from "
    9128              :                                            "pointer target type"),
    9129              :                                         TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl));
    9130           11 :               else if (warn_quals_ped)
    9131           11 :                 pedwarn_c11 (location, OPT_Wc11_c23_compat,
    9132              :                              "array with qualifier on the element is not qualified before C23");
    9133              : 
    9134              :               /* If this is not a case of ignoring a mismatch in signedness,
    9135              :                  no warning.  */
    9136      1995903 :               else if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr)
    9137      1558164 :                        || target_cmp)
    9138              :                 ;
    9139              :               /* If there is a mismatch, do warn.  */
    9140         1702 :               else if (warn_pointer_sign)
    9141           82 :                 switch (errtype)
    9142              :                   {
    9143           33 :                   case ic_argpass:
    9144           33 :                     {
    9145           33 :                       auto_diagnostic_group d;
    9146           33 :                       range_label_for_type_mismatch rhs_label (rhstype, type);
    9147           33 :                       gcc_rich_location richloc (expr_loc, &rhs_label,
    9148           33 :                                                  highlight_colors::actual);
    9149           33 :                       if (pedwarn (&richloc, OPT_Wpointer_sign,
    9150              :                                    "pointer targets in passing argument %d of "
    9151              :                                    "%qE differ in signedness", parmnum, rname))
    9152           33 :                         inform_for_arg (fundecl, expr_loc, parmnum, type,
    9153              :                                         rhstype);
    9154           33 :                     }
    9155           33 :                     break;
    9156           21 :                   case ic_assign:
    9157           21 :                     pedwarn (location, OPT_Wpointer_sign,
    9158              :                              "pointer targets in assignment from %qT to %qT "
    9159              :                              "differ in signedness", rhstype, type);
    9160           21 :                     break;
    9161           14 :                   case ic_init:
    9162           14 :                   case ic_init_const:
    9163           14 :                     pedwarn_init (location, OPT_Wpointer_sign,
    9164              :                                   "pointer targets in initialization of %qT "
    9165              :                                   "from %qT differ in signedness", type,
    9166              :                                   rhstype);
    9167           14 :                     break;
    9168           14 :                   case ic_return:
    9169           14 :                     pedwarn (location, OPT_Wpointer_sign, "pointer targets in "
    9170              :                              "returning %qT from a function with return type "
    9171              :                              "%qT differ in signedness", rhstype, type);
    9172           14 :                     break;
    9173            0 :                   default:
    9174            0 :                     gcc_unreachable ();
    9175              :                   }
    9176              :             }
    9177        33179 :           else if (TREE_CODE (ttl) == FUNCTION_TYPE
    9178         4197 :                    && TREE_CODE (ttr) == FUNCTION_TYPE)
    9179              :             {
    9180              :               /* Because const and volatile on functions are restrictions
    9181              :                  that say the function will not do certain things,
    9182              :                  it is okay to use a const or volatile function
    9183              :                  where an ordinary one is wanted, but not vice-versa.  */
    9184         3458 :               if (TYPE_QUALS_NO_ADDR_SPACE (ttl)
    9185         3458 :                   & ~TYPE_QUALS_NO_ADDR_SPACE (ttr))
    9186           18 :                 PEDWARN_FOR_QUALIFIERS (location, expr_loc,
    9187              :                                         OPT_Wdiscarded_qualifiers,
    9188              :                                         G_("passing argument %d of %qE makes "
    9189              :                                            "%q#v qualified function pointer "
    9190              :                                            "from unqualified"),
    9191              :                                         G_("assignment makes %q#v qualified function "
    9192              :                                            "pointer from unqualified"),
    9193              :                                         G_("initialization makes %q#v qualified "
    9194              :                                            "function pointer from unqualified"),
    9195              :                                         G_("return makes %q#v qualified function "
    9196              :                                            "pointer from unqualified"),
    9197              :                                         TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr));
    9198              :             }
    9199              :         }
    9200              :       /* Avoid warning about the volatile ObjC EH puts on decls.  */
    9201          800 :       else if (!objc_ok)
    9202              :         {
    9203          800 :           auto_diagnostic_group d;
    9204          800 :           bool warned = false;
    9205          800 :           pp_markup::element_expected_type e_type (type);
    9206          800 :           pp_markup::element_actual_type e_rhstype (rhstype);
    9207          800 :           switch (errtype)
    9208              :             {
    9209          307 :             case ic_argpass:
    9210          307 :               {
    9211          307 :                 range_label_for_type_mismatch rhs_label (rhstype, type);
    9212          307 :                 gcc_rich_location richloc (expr_loc, &rhs_label,
    9213          307 :                                            highlight_colors::actual);
    9214          307 :                 warned
    9215          307 :                   = permerror_opt (&richloc, OPT_Wincompatible_pointer_types,
    9216              :                                    "passing argument %d of %qE from "
    9217              :                                    "incompatible pointer type",
    9218              :                                    parmnum, rname);
    9219          307 :                 if (warned)
    9220          175 :                   inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
    9221          307 :               }
    9222          307 :               break;
    9223          267 :             case ic_assign:
    9224          267 :               if (bltin)
    9225           11 :                 warned
    9226           11 :                   = permerror_opt (location, OPT_Wincompatible_pointer_types,
    9227              :                                    "assignment to %e from pointer to "
    9228              :                                    "%qD with incompatible type %e",
    9229              :                                    &e_type, bltin, &e_rhstype);
    9230              :               else
    9231          256 :                 warned
    9232          256 :                   = permerror_opt (location, OPT_Wincompatible_pointer_types,
    9233              :                                    "assignment to %e from incompatible "
    9234              :                                    "pointer type %e",
    9235              :                                    &e_type, &e_rhstype);
    9236              :               break;
    9237          167 :             case ic_init:
    9238          167 :             case ic_init_const:
    9239          167 :               if (bltin)
    9240           13 :                 warned
    9241           13 :                   = permerror_init (location, OPT_Wincompatible_pointer_types,
    9242              :                                     "initialization of %e from pointer to "
    9243              :                                     "%qD with incompatible type %e",
    9244              :                                     &e_type, bltin, &e_rhstype);
    9245              :               else
    9246          154 :                 warned
    9247          154 :                   = permerror_init (location, OPT_Wincompatible_pointer_types,
    9248              :                                     "initialization of %e from incompatible "
    9249              :                                     "pointer type %e",
    9250              :                                     &e_type, &e_rhstype);
    9251              :               break;
    9252           59 :             case ic_return:
    9253           59 :               if (bltin)
    9254           11 :                 warned
    9255           11 :                   = permerror_opt (location, OPT_Wincompatible_pointer_types,
    9256              :                                    "returning pointer to %qD of type %e from "
    9257              :                                    "a function with incompatible type %e",
    9258              :                                    bltin, &e_rhstype, &e_type);
    9259              :               else
    9260           48 :                 warned
    9261           48 :                   = permerror_opt (location, OPT_Wincompatible_pointer_types,
    9262              :                                    "returning %e from a function with "
    9263              :                                    "incompatible return type %e",
    9264              :                                    &e_rhstype, &e_type);
    9265              :               break;
    9266            0 :             default:
    9267            0 :               gcc_unreachable ();
    9268              :             }
    9269          800 :           if (warned)
    9270              :             {
    9271              :               /* If the mismatching function type is a pointer to a function,
    9272              :                  try to show the decl of the function.  */
    9273          590 :               if (TREE_CODE (rhs) == ADDR_EXPR
    9274          590 :                   && TREE_CODE (TREE_OPERAND (rhs, 0)) == FUNCTION_DECL)
    9275              :                 {
    9276          191 :                   tree rhs_fndecl = TREE_OPERAND (rhs, 0);
    9277          191 :                   if (!DECL_IS_UNDECLARED_BUILTIN (rhs_fndecl))
    9278              :                     {
    9279          165 :                       gcc_rich_location richloc
    9280          165 :                         (DECL_SOURCE_LOCATION (rhs_fndecl), nullptr,
    9281          165 :                          highlight_colors::actual);
    9282          165 :                       pp_element_quoted_decl e_rhs_fndecl
    9283          165 :                         (rhs_fndecl, highlight_colors::actual);
    9284          165 :                       inform (&richloc,
    9285              :                               "%e declared here", &e_rhs_fndecl);
    9286          165 :                     }
    9287              :                 }
    9288              :               /* If either/both of the types are typedefs, show the decl.  */
    9289          590 :               maybe_inform_typedef_location (type,
    9290              :                                              highlight_colors::expected);
    9291          590 :               maybe_inform_typedef_location (rhstype,
    9292              :                                              highlight_colors::actual);
    9293              :             }
    9294          800 :         }
    9295              : 
    9296              :       /* If RHS isn't an address, check pointer or array of packed
    9297              :          struct or union.  */
    9298      2032755 :       warn_for_address_of_packed_member (type, orig_rhs);
    9299              : 
    9300      2032755 :       return convert (type, rhs);
    9301              :     }
    9302        80067 :   else if (codel == POINTER_TYPE && coder == ARRAY_TYPE)
    9303              :     {
    9304              :       /* ??? This should not be an error when inlining calls to
    9305              :          unprototyped functions.  */
    9306            4 :       const char msg[] = "invalid use of non-lvalue array";
    9307            4 :       if (warnopt)
    9308            0 :         warning_at (location, warnopt, msg);
    9309              :       else
    9310            4 :         error_at (location, msg);
    9311            4 :       return error_mark_node;
    9312              :     }
    9313        80063 :   else if (codel == POINTER_TYPE
    9314        78530 :            && (coder == INTEGER_TYPE
    9315        78530 :                || coder == ENUMERAL_TYPE
    9316          620 :                || coder == BOOLEAN_TYPE
    9317          620 :                || coder == NULLPTR_TYPE
    9318           27 :                || coder == BITINT_TYPE))
    9319              :     {
    9320        78517 :       if (null_pointer_constant && c_inhibit_evaluation_warnings == 0
    9321        77519 :           && coder != NULLPTR_TYPE)
    9322        76955 :         warning_at (location, OPT_Wzero_as_null_pointer_constant,
    9323              :                     "zero as null pointer constant");
    9324              :       /* A NULLPTR type is just a nullptr always.  */
    9325        77953 :       if (coder == NULLPTR_TYPE)
    9326          579 :         return omit_one_operand_loc (expr_loc, type, nullptr_node, rhs);
    9327              :       /* An explicit constant 0 or type nullptr_t can convert to a pointer,
    9328              :          or one that results from arithmetic, even including a cast to
    9329              :          integer type.  */
    9330        77938 :       else if (!null_pointer_constant)
    9331          972 :         switch (errtype)
    9332              :           {
    9333          800 :           case ic_argpass:
    9334          800 :             {
    9335          800 :               auto_diagnostic_group d;
    9336          800 :               range_label_for_type_mismatch rhs_label (rhstype, type);
    9337          800 :               gcc_rich_location richloc (expr_loc, &rhs_label,
    9338          800 :                                          highlight_colors::actual);
    9339          800 :               if (permerror_opt (&richloc, OPT_Wint_conversion,
    9340              :                                  "passing argument %d of %qE makes pointer "
    9341              :                                  "from integer without a cast", parmnum, rname))
    9342              :                 {
    9343          439 :                   maybe_emit_indirection_note (expr_loc, rhs, type);
    9344          439 :                   inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
    9345              :                 }
    9346          800 :             }
    9347          800 :             break;
    9348           93 :           case ic_assign:
    9349           93 :             permerror_opt (location, OPT_Wint_conversion,
    9350              :                            "assignment to %qT from %qT makes pointer from "
    9351              :                            "integer without a cast", type, rhstype);
    9352           93 :             break;
    9353           56 :           case ic_init:
    9354           56 :           case ic_init_const:
    9355           56 :             permerror_init (location, OPT_Wint_conversion,
    9356              :                             "initialization of %qT from %qT makes pointer "
    9357              :                             "from integer without a cast", type, rhstype);
    9358           56 :             break;
    9359           23 :           case ic_return:
    9360           23 :             permerror_init (location, OPT_Wint_conversion,
    9361              :                             "returning %qT from a function with return type "
    9362              :                             "%qT makes pointer from integer without a cast",
    9363              :                             rhstype, type);
    9364           23 :             break;
    9365            0 :           default:
    9366            0 :             gcc_unreachable ();
    9367              :           }
    9368              : 
    9369        77938 :       return convert (type, rhs);
    9370              :     }
    9371         1546 :   else if ((codel == INTEGER_TYPE || codel == BITINT_TYPE)
    9372          540 :            && coder == POINTER_TYPE)
    9373              :     {
    9374          514 :       switch (errtype)
    9375              :         {
    9376          344 :         case ic_argpass:
    9377          344 :           {
    9378          344 :             auto_diagnostic_group d;
    9379          344 :             range_label_for_type_mismatch rhs_label (rhstype, type);
    9380          344 :             gcc_rich_location richloc (expr_loc, &rhs_label,
    9381          344 :                                        highlight_colors::actual);
    9382          344 :             if (permerror_opt (&richloc, OPT_Wint_conversion,
    9383              :                                "passing argument %d of %qE makes integer from "
    9384              :                                "pointer without a cast", parmnum, rname))
    9385              :               {
    9386          323 :                 maybe_emit_indirection_note (expr_loc, rhs, type);
    9387          323 :                 inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
    9388              :               }
    9389          344 :           }
    9390          344 :           break;
    9391           52 :         case ic_assign:
    9392           52 :           permerror_opt (location, OPT_Wint_conversion,
    9393              :                          "assignment to %qT from %qT makes integer from "
    9394              :                          "pointer without a cast", type, rhstype);
    9395           52 :           break;
    9396           83 :         case ic_init:
    9397           83 :         case ic_init_const:
    9398           83 :           permerror_init (location, OPT_Wint_conversion,
    9399              :                           "initialization of %qT from %qT makes integer "
    9400              :                           "from pointer without a cast", type, rhstype);
    9401           83 :           break;
    9402           35 :         case ic_return:
    9403           35 :           permerror_opt (location, OPT_Wint_conversion, "returning %qT from a "
    9404              :                          "function with return type %qT makes integer from "
    9405              :                          "pointer without a cast", rhstype, type);
    9406           35 :           break;
    9407            0 :         default:
    9408            0 :           gcc_unreachable ();
    9409              :         }
    9410              : 
    9411          514 :       return convert (type, rhs);
    9412              :     }
    9413          626 :   else if (C_BOOLEAN_TYPE_P (type)
    9414              :            /* The type nullptr_t may be converted to bool.  The
    9415              :               result is false.  */
    9416         1034 :            && (coder == POINTER_TYPE || coder == NULLPTR_TYPE))
    9417              :     {
    9418          408 :       tree ret;
    9419          408 :       bool save = in_late_binary_op;
    9420          408 :       in_late_binary_op = true;
    9421          408 :       ret = convert (type, rhs);
    9422          408 :       in_late_binary_op = save;
    9423          408 :       return ret;
    9424              :     }
    9425          624 :   else if (codel == NULLPTR_TYPE && null_pointer_constant)
    9426            6 :     return convert (type, rhs);
    9427              : 
    9428          618 :   switch (errtype)
    9429              :     {
    9430           35 :     case ic_argpass:
    9431           35 :       {
    9432           35 :         auto_diagnostic_group d;
    9433           35 :         range_label_for_type_mismatch rhs_label (rhstype, type);
    9434           35 :         gcc_rich_location richloc (expr_loc, &rhs_label,
    9435           35 :                                    highlight_colors::actual);
    9436           35 :         const char msg[] = G_("incompatible type for argument %d of %qE");
    9437           35 :         if (warnopt)
    9438            8 :           warning_at (expr_loc, warnopt, msg, parmnum, rname);
    9439              :         else
    9440           27 :           error_at (&richloc, msg, parmnum, rname);
    9441           35 :         inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
    9442           35 :       }
    9443           35 :       break;
    9444          108 :     case ic_assign:
    9445          108 :       {
    9446          108 :         const char msg[]
    9447              :           = G_("incompatible types when assigning to type %qT from type %qT");
    9448          108 :         if (warnopt)
    9449            0 :           warning_at (expr_loc, 0, msg, type, rhstype);
    9450              :         else
    9451          108 :           error_at (expr_loc, msg, type, rhstype);
    9452          108 :         break;
    9453              :       }
    9454          460 :     case ic_init:
    9455          460 :     case ic_init_const:
    9456          460 :       {
    9457          460 :         const char msg[]
    9458              :           = G_("incompatible types when initializing type %qT using type %qT");
    9459          460 :         if (warnopt)
    9460            0 :           warning_at (location, 0, msg, type, rhstype);
    9461              :         else
    9462          460 :           error_at (location, msg, type, rhstype);
    9463          460 :         break;
    9464              :       }
    9465           15 :     case ic_return:
    9466           15 :       {
    9467           15 :         const char msg[]
    9468              :           = G_("incompatible types when returning type %qT but %qT was expected");
    9469           15 :         if (warnopt)
    9470            0 :           warning_at (location, 0, msg, rhstype, type);
    9471              :         else
    9472           15 :           error_at (location, msg, rhstype, type);
    9473           15 :         break;
    9474              :       }
    9475            0 :     default:
    9476            0 :       gcc_unreachable ();
    9477              :     }
    9478              : 
    9479          618 :   return error_mark_node;
    9480              : }
    9481              : 
    9482              : /* If VALUE is a compound expr all of whose expressions are constant, then
    9483              :    return its value.  Otherwise, return error_mark_node.
    9484              : 
    9485              :    This is for handling COMPOUND_EXPRs as initializer elements
    9486              :    which is allowed with a warning when -pedantic is specified.  */
    9487              : 
    9488              : static tree
    9489            2 : valid_compound_expr_initializer (tree value, tree endtype)
    9490              : {
    9491            2 :   if (TREE_CODE (value) == COMPOUND_EXPR)
    9492              :     {
    9493            1 :       if (valid_compound_expr_initializer (TREE_OPERAND (value, 0), endtype)
    9494            1 :           == error_mark_node)
    9495              :         return error_mark_node;
    9496            0 :       return valid_compound_expr_initializer (TREE_OPERAND (value, 1),
    9497            0 :                                               endtype);
    9498              :     }
    9499            1 :   else if (!initializer_constant_valid_p (value, endtype))
    9500            1 :     return error_mark_node;
    9501              :   else
    9502              :     return value;
    9503              : }
    9504              : 
    9505              : /* Perform appropriate conversions on the initial value of a variable,
    9506              :    store it in the declaration DECL,
    9507              :    and print any error messages that are appropriate.
    9508              :    If ORIGTYPE is not NULL_TREE, it is the original type of INIT.
    9509              :    If the init is invalid, store an ERROR_MARK.
    9510              : 
    9511              :    INIT_LOC is the location of the initial value.  */
    9512              : 
    9513              : void
    9514      7322062 : store_init_value (location_t init_loc, tree decl, tree init, tree origtype)
    9515              : {
    9516      7322062 :   tree value, type;
    9517      7322062 :   bool npc = false;
    9518      7322062 :   bool int_const_expr = false;
    9519      7322062 :   bool arith_const_expr = false;
    9520              : 
    9521              :   /* If variable's type was invalidly declared, just ignore it.  */
    9522              : 
    9523      7322062 :   type = TREE_TYPE (decl);
    9524      7322062 :   if (TREE_CODE (type) == ERROR_MARK)
    9525              :     return;
    9526              : 
    9527              :   /* Digest the specified initializer into an expression.  */
    9528              : 
    9529      7322054 :   if (init)
    9530              :     {
    9531      7322051 :       npc = null_pointer_constant_p (init);
    9532      7322051 :       int_const_expr = (TREE_CODE (init) == INTEGER_CST
    9533       424516 :                         && !TREE_OVERFLOW (init)
    9534      7746531 :                         && INTEGRAL_TYPE_P (TREE_TYPE (init)));
    9535              :       /* Not fully determined before folding.  */
    9536              :       arith_const_expr = true;
    9537              :     }
    9538      7322054 :   bool constexpr_p = (VAR_P (decl)
    9539      7322054 :                       && C_DECL_DECLARED_CONSTEXPR (decl));
    9540      7322054 :   value = digest_init (init_loc, decl, type, init, origtype, npc,
    9541              :                        int_const_expr, arith_const_expr, true,
    9542      7322054 :                        TREE_STATIC (decl) || constexpr_p, constexpr_p);
    9543              : 
    9544              :   /* Store the expression if valid; else report error.  */
    9545              : 
    9546      7322054 :   if (!in_system_header_at (input_location)
    9547      7322054 :       && AGGREGATE_TYPE_P (TREE_TYPE (decl)) && !TREE_STATIC (decl))
    9548        29169 :     warning (OPT_Wtraditional, "traditional C rejects automatic "
    9549              :              "aggregate initialization");
    9550              : 
    9551      7322054 :   if (value != error_mark_node || TREE_CODE (decl) != FUNCTION_DECL)
    9552      7322053 :     DECL_INITIAL (decl) = value;
    9553              : 
    9554              :   /* ANSI wants warnings about out-of-range constant initializers.  */
    9555      7322065 :   STRIP_TYPE_NOPS (value);
    9556      7322054 :   if (TREE_STATIC (decl))
    9557       181906 :     constant_expression_warning (value);
    9558              : 
    9559              :   /* Check if we need to set array size from compound literal size.  */
    9560      7322054 :   if (TREE_CODE (type) == ARRAY_TYPE
    9561        27279 :       && TYPE_DOMAIN (type) == NULL_TREE
    9562      7335056 :       && value != error_mark_node)
    9563              :     {
    9564              :       tree inside_init = init;
    9565              : 
    9566        12130 :       STRIP_TYPE_NOPS (inside_init);
    9567        12130 :       inside_init = fold (inside_init);
    9568              : 
    9569        12130 :       if (TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
    9570              :         {
    9571           13 :           tree cldecl = COMPOUND_LITERAL_EXPR_DECL (inside_init);
    9572              : 
    9573           13 :           if (TYPE_DOMAIN (TREE_TYPE (cldecl)))
    9574              :             {
    9575              :               /* For int foo[] = (int [3]){1}; we need to set array size
    9576              :                  now since later on array initializer will be just the
    9577              :                  brace enclosed list of the compound literal.  */
    9578           13 :               tree etype = strip_array_types (TREE_TYPE (decl));
    9579           13 :               type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
    9580           13 :               TYPE_DOMAIN (type) = TYPE_DOMAIN (TREE_TYPE (cldecl));
    9581           13 :               layout_type (type);
    9582           13 :               layout_decl (cldecl, 0);
    9583           13 :               TREE_TYPE (decl)
    9584           26 :                 = c_build_qualified_type (type, TYPE_QUALS (etype));
    9585              :             }
    9586              :         }
    9587              :     }
    9588              : }
    9589              : 
    9590              : /* Methods for storing and printing names for error messages.  */
    9591              : 
    9592              : /* Implement a spelling stack that allows components of a name to be pushed
    9593              :    and popped.  Each element on the stack is this structure.  */
    9594              : 
    9595              : struct spelling
    9596              : {
    9597              :   int kind;
    9598              :   union
    9599              :     {
    9600              :       unsigned HOST_WIDE_INT i;
    9601              :       const char *s;
    9602              :     } u;
    9603              : };
    9604              : 
    9605              : #define SPELLING_STRING 1
    9606              : #define SPELLING_MEMBER 2
    9607              : #define SPELLING_BOUNDS 3
    9608              : 
    9609              : static struct spelling *spelling;       /* Next stack element (unused).  */
    9610              : static struct spelling *spelling_base;  /* Spelling stack base.  */
    9611              : static int spelling_size;               /* Size of the spelling stack.  */
    9612              : 
    9613              : /* Macros to save and restore the spelling stack around push_... functions.
    9614              :    Alternative to SAVE_SPELLING_STACK.  */
    9615              : 
    9616              : #define SPELLING_DEPTH() (spelling - spelling_base)
    9617              : #define RESTORE_SPELLING_DEPTH(DEPTH) (spelling = spelling_base + (DEPTH))
    9618              : 
    9619              : /* Push an element on the spelling stack with type KIND and assign VALUE
    9620              :    to MEMBER.  */
    9621              : 
    9622              : #define PUSH_SPELLING(KIND, VALUE, MEMBER)                              \
    9623              : {                                                                       \
    9624              :   int depth = SPELLING_DEPTH ();                                        \
    9625              :                                                                         \
    9626              :   if (depth >= spelling_size)                                                \
    9627              :     {                                                                   \
    9628              :       spelling_size += 10;                                              \
    9629              :       spelling_base = XRESIZEVEC (struct spelling, spelling_base,       \
    9630              :                                   spelling_size);                       \
    9631              :       RESTORE_SPELLING_DEPTH (depth);                                   \
    9632              :     }                                                                   \
    9633              :                                                                         \
    9634              :   spelling->kind = (KIND);                                           \
    9635              :   spelling->MEMBER = (VALUE);                                                \
    9636              :   spelling++;                                                           \
    9637              : }
    9638              : 
    9639              : /* Push STRING on the stack.  Printed literally.  */
    9640              : 
    9641              : static void
    9642      7319256 : push_string (const char *string)
    9643              : {
    9644      7319256 :   PUSH_SPELLING (SPELLING_STRING, string, u.s);
    9645      7319256 : }
    9646              : 
    9647              : /* Push a member name on the stack.  Printed as '.' STRING.  */
    9648              : 
    9649              : static void
    9650      1231858 : push_member_name (tree decl)
    9651              : {
    9652      1231858 :   const char *const string
    9653      1231858 :     = (DECL_NAME (decl)
    9654      1231858 :        ? identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl)))
    9655          210 :        : _("<anonymous>"));
    9656      1231858 :   PUSH_SPELLING (SPELLING_MEMBER, string, u.s);
    9657      1231858 : }
    9658              : 
    9659              : /* Push an array bounds on the stack.  Printed as [BOUNDS].  */
    9660              : 
    9661              : static void
    9662      2612131 : push_array_bounds (unsigned HOST_WIDE_INT bounds)
    9663              : {
    9664      2612131 :   PUSH_SPELLING (SPELLING_BOUNDS, bounds, u.i);
    9665      2612131 : }
    9666              : 
    9667              : /* Compute the maximum size in bytes of the printed spelling.  */
    9668              : 
    9669              : static int
    9670         2892 : spelling_length (void)
    9671              : {
    9672         2892 :   int size = 0;
    9673         2892 :   struct spelling *p;
    9674              : 
    9675         6416 :   for (p = spelling_base; p < spelling; p++)
    9676              :     {
    9677         3524 :       if (p->kind == SPELLING_BOUNDS)
    9678         1479 :         size += 25;
    9679              :       else
    9680         2045 :         size += strlen (p->u.s) + 1;
    9681              :     }
    9682              : 
    9683         2892 :   return size;
    9684              : }
    9685              : 
    9686              : /* Print the spelling to BUFFER and return it.  */
    9687              : 
    9688              : static char *
    9689         2892 : print_spelling (char *buffer)
    9690              : {
    9691         2892 :   char *d = buffer;
    9692         2892 :   struct spelling *p;
    9693              : 
    9694         6416 :   for (p = spelling_base; p < spelling; p++)
    9695         3524 :     if (p->kind == SPELLING_BOUNDS)
    9696              :       {
    9697         1479 :         sprintf (d, "[" HOST_WIDE_INT_PRINT_UNSIGNED "]", p->u.i);
    9698         1479 :         d += strlen (d);
    9699              :       }
    9700              :     else
    9701              :       {
    9702         2045 :         const char *s;
    9703         2045 :         if (p->kind == SPELLING_MEMBER)
    9704          198 :           *d++ = '.';
    9705        16715 :         for (s = p->u.s; (*d = *s++); d++)
    9706              :           ;
    9707              :       }
    9708         2892 :   *d++ = '\0';
    9709         2892 :   return buffer;
    9710              : }
    9711              : 
    9712              : /* Check whether INIT, a floating or integer constant, is
    9713              :    representable in TYPE, a real floating type with the same radix or
    9714              :    a decimal floating type initialized with a binary floating
    9715              :    constant.  Return true if OK, false if not.  */
    9716              : static bool
    9717          362 : constexpr_init_fits_real_type (tree type, tree init)
    9718              : {
    9719          362 :   gcc_assert (SCALAR_FLOAT_TYPE_P (type));
    9720          362 :   gcc_assert (TREE_CODE (init) == INTEGER_CST || TREE_CODE (init) == REAL_CST);
    9721          362 :   if (TREE_CODE (init) == REAL_CST
    9722          362 :       && TYPE_MODE (TREE_TYPE (init)) == TYPE_MODE (type))
    9723              :     {
    9724              :       /* Same mode, no conversion required except for the case of
    9725              :          signaling NaNs if the types are incompatible (e.g. double and
    9726              :          long double with the same mode).  */
    9727          177 :       if (REAL_VALUE_ISSIGNALING_NAN (TREE_REAL_CST (init))
    9728          195 :           && !comptypes (TYPE_MAIN_VARIANT (type),
    9729           18 :                          TYPE_MAIN_VARIANT (TREE_TYPE (init))))
    9730            0 :         return false;
    9731              :       return true;
    9732              :     }
    9733          185 :   if (TREE_CODE (init) == INTEGER_CST)
    9734              :     {
    9735           54 :       tree converted = build_real_from_int_cst (type, init);
    9736           54 :       bool fail = false;
    9737          108 :       wide_int w = real_to_integer (&TREE_REAL_CST (converted), &fail,
    9738           54 :                                     TYPE_PRECISION (TREE_TYPE (init)));
    9739           68 :       return !fail && wi::eq_p (w, wi::to_wide (init));
    9740           54 :     }
    9741          131 :   if (REAL_VALUE_ISSIGNALING_NAN (TREE_REAL_CST (init)))
    9742              :     return false;
    9743          114 :   if ((REAL_VALUE_ISINF (TREE_REAL_CST (init))
    9744           34 :        && MODE_HAS_INFINITIES (TYPE_MODE (type)))
    9745          218 :       || (REAL_VALUE_ISNAN (TREE_REAL_CST (init))
    9746           44 :           && MODE_HAS_NANS (TYPE_MODE (type))))
    9747              :     return true;
    9748           94 :   if (DECIMAL_FLOAT_TYPE_P (type)
    9749          134 :       && !DECIMAL_FLOAT_TYPE_P (TREE_TYPE (init)))
    9750              :     {
    9751              :       /* This is valid if the real number represented by the
    9752              :          initializer can be exactly represented in the decimal
    9753              :          type.  Compare the values using MPFR.  */
    9754            8 :       REAL_VALUE_TYPE t;
    9755            8 :       real_convert (&t, TYPE_MODE (type), &TREE_REAL_CST (init));
    9756            8 :       mpfr_t bin_val, dec_val;
    9757            8 :       mpfr_init2 (bin_val, REAL_MODE_FORMAT (TYPE_MODE (TREE_TYPE (init)))->p);
    9758            8 :       mpfr_init2 (dec_val, REAL_MODE_FORMAT (TYPE_MODE (TREE_TYPE (init)))->p);
    9759            8 :       mpfr_from_real (bin_val, &TREE_REAL_CST (init), MPFR_RNDN);
    9760            8 :       char string[256];
    9761            8 :       real_to_decimal (string, &t, sizeof string, 0, 1);
    9762            8 :       bool res = (mpfr_strtofr (dec_val, string, NULL, 10, MPFR_RNDN) == 0
    9763            8 :                   && mpfr_equal_p (bin_val, dec_val));
    9764            8 :       mpfr_clear (bin_val);
    9765            8 :       mpfr_clear (dec_val);
    9766            8 :       return res;
    9767              :     }
    9768              :   /* exact_real_truncate is not quite right here, since it doesn't
    9769              :      allow even an exact conversion to subnormal values.  */
    9770           86 :   REAL_VALUE_TYPE t;
    9771           86 :   real_convert (&t, TYPE_MODE (type), &TREE_REAL_CST (init));
    9772           86 :   return real_identical (&t, &TREE_REAL_CST (init));
    9773              : }
    9774              : 
    9775              : /* Check whether INIT (location LOC) is valid as a 'constexpr'
    9776              :    initializer for type TYPE, and give an error if not.  INIT has
    9777              :    already been folded and verified to be constant.  INT_CONST_EXPR
    9778              :    and ARITH_CONST_EXPR say whether it is an integer constant
    9779              :    expression or arithmetic constant expression, respectively.  If
    9780              :    TYPE is not a scalar type, this function does nothing.  */
    9781              : 
    9782              : static void
    9783          942 : check_constexpr_init (location_t loc, tree type, tree init,
    9784              :                       bool int_const_expr, bool arith_const_expr)
    9785              : {
    9786          942 :   if (POINTER_TYPE_P (type))
    9787              :     {
    9788              :       /* The initializer must be null.  */
    9789           86 :       if (TREE_CODE (init) != INTEGER_CST || !integer_zerop (init))
    9790            8 :         error_at (loc, "%<constexpr%> pointer initializer is not null");
    9791              :       return;
    9792              :     }
    9793          856 :   if (INTEGRAL_TYPE_P (type))
    9794              :     {
    9795              :       /* The initializer must be an integer constant expression,
    9796              :          representable in the target type.  */
    9797          346 :       if (!int_const_expr)
    9798              :         {
    9799           13 :           if (TREE_CODE (init) == RAW_DATA_CST
    9800           13 :               && TYPE_PRECISION (type) == CHAR_BIT)
    9801              :             {
    9802            4 :               if (!TYPE_UNSIGNED (type))
    9803          137 :                 for (unsigned int i = 0;
    9804          140 :                      i < (unsigned) RAW_DATA_LENGTH (init); ++i)
    9805          138 :                   if (RAW_DATA_SCHAR_ELT (init, i) < 0)
    9806              :                     {
    9807            1 :                       error_at (loc, "%<constexpr%> initializer not "
    9808              :                                 "representable in type of object");
    9809            1 :                       break;
    9810              :                     }
    9811              :             }
    9812              :           else
    9813            9 :             error_at (loc, "%<constexpr%> integer initializer is not an "
    9814              :                       "integer constant expression");
    9815              :         }
    9816          333 :       else if (!int_fits_type_p (init, type))
    9817            6 :         error_at (loc, "%<constexpr%> initializer not representable in "
    9818              :                   "type of object");
    9819              :       return;
    9820              :     }
    9821              :   /* We don't apply any extra checks to extension types such as vector
    9822              :      or fixed-point types.  */
    9823          510 :   if (TREE_CODE (type) != REAL_TYPE && TREE_CODE (type) != COMPLEX_TYPE)
    9824              :     return;
    9825          353 :   if (!arith_const_expr)
    9826              :     {
    9827            5 :       error_at (loc, "%<constexpr%> initializer is not an arithmetic "
    9828              :                 "constant expression");
    9829            5 :       return;
    9830              :     }
    9831              :   /* We don't apply any extra checks to complex integers.  */
    9832          348 :   if (TREE_CODE (type) == COMPLEX_TYPE
    9833          348 :       && TREE_CODE (TREE_TYPE (type)) != REAL_TYPE)
    9834              :     return;
    9835              :   /* Following N3082, a real type cannot be initialized from a complex
    9836              :      type and a binary type cannot be initialized from a decimal type
    9837              :      (but initializing a decimal type from a binary type is OK).
    9838              :      Signaling NaN initializers are OK only if the types are
    9839              :      compatible (not just the same mode); all quiet NaN and infinity
    9840              :      initializations are considered to preserve the value.  */
    9841          348 :   if (TREE_CODE (TREE_TYPE (init)) == COMPLEX_TYPE
    9842          348 :       && SCALAR_FLOAT_TYPE_P (type))
    9843              :     {
    9844            6 :       error_at (loc, "%<constexpr%> initializer for a real type is of "
    9845              :                 "complex type");
    9846            6 :       return;
    9847              :     }
    9848          342 :   if (SCALAR_FLOAT_TYPE_P (type)
    9849          300 :       && SCALAR_FLOAT_TYPE_P (TREE_TYPE (init))
    9850          250 :       && DECIMAL_FLOAT_TYPE_P (TREE_TYPE (init))
    9851          481 :       && !DECIMAL_FLOAT_TYPE_P (type))
    9852              :     {
    9853            6 :       error_at (loc, "%<constexpr%> initializer for a binary "
    9854              :                 "floating-point type is of decimal type");
    9855            6 :       return;
    9856              :     }
    9857          336 :   bool fits;
    9858          336 :   if (TREE_CODE (type) == COMPLEX_TYPE)
    9859              :     {
    9860           42 :       switch (TREE_CODE (init))
    9861              :         {
    9862           10 :         case INTEGER_CST:
    9863           10 :         case REAL_CST:
    9864           10 :           fits = constexpr_init_fits_real_type (TREE_TYPE (type), init);
    9865           10 :           break;
    9866           32 :         case COMPLEX_CST:
    9867           32 :           fits = (constexpr_init_fits_real_type (TREE_TYPE (type),
    9868           32 :                                                  TREE_REALPART (init))
    9869           58 :                   && constexpr_init_fits_real_type (TREE_TYPE (type),
    9870           26 :                                                     TREE_IMAGPART (init)));
    9871              :           break;
    9872            0 :         default:
    9873            0 :           gcc_unreachable ();
    9874              :         }
    9875              :     }
    9876              :   else
    9877          294 :     fits = constexpr_init_fits_real_type (type, init);
    9878          304 :   if (!fits)
    9879           65 :     error_at (loc, "%<constexpr%> initializer not representable in "
    9880              :               "type of object");
    9881              : }
    9882              : 
    9883              : /* Digest the parser output INIT as an initializer for type TYPE
    9884              :    initializing DECL.
    9885              :    Return a C expression of type TYPE to represent the initial value.
    9886              : 
    9887              :    If ORIGTYPE is not NULL_TREE, it is the original type of INIT.
    9888              : 
    9889              :    NULL_POINTER_CONSTANT is true if INIT is a null pointer constant,
    9890              :    INT_CONST_EXPR is true if INIT is an integer constant expression,
    9891              :    and ARITH_CONST_EXPR is true if INIT is, or might be, an arithmetic
    9892              :    constant expression, false if it has already been determined in the
    9893              :    caller that it is not (but folding may have made the value passed here
    9894              :    indistinguishable from an arithmetic constant expression).
    9895              : 
    9896              :    If INIT is a string constant, STRICT_STRING is true if it is
    9897              :    unparenthesized or we should not warn here for it being parenthesized.
    9898              :    For other types of INIT, STRICT_STRING is not used.
    9899              : 
    9900              :    INIT_LOC is the location of the INIT.
    9901              : 
    9902              :    REQUIRE_CONSTANT requests an error if non-constant initializers or
    9903              :    elements are seen.  REQUIRE_CONSTEXPR means the stricter requirements
    9904              :    on initializers for 'constexpr' objects apply.  */
    9905              : 
    9906              : static tree
    9907     17005403 : digest_init (location_t init_loc, tree decl, tree type, tree init,
    9908              :              tree origtype, bool null_pointer_constant, bool int_const_expr,
    9909              :              bool arith_const_expr, bool strict_string,
    9910              :              bool require_constant, bool require_constexpr)
    9911              : {
    9912     17005403 :   enum tree_code code = TREE_CODE (type);
    9913     17005403 :   tree inside_init = init;
    9914     17005403 :   tree semantic_type = NULL_TREE;
    9915     17005403 :   bool maybe_const = true;
    9916              : 
    9917     17005403 :   if (type == error_mark_node
    9918     17005403 :       || !init
    9919     34010803 :       || error_operand_p (init))
    9920              :     return error_mark_node;
    9921              : 
    9922     17012883 :   STRIP_TYPE_NOPS (inside_init);
    9923              : 
    9924              :   /* If require_constant is TRUE,  when the initializer is a call to
    9925              :      .ACCESS_WITH_SIZE, use the first argument as the initializer.
    9926              :      For example:
    9927              :      y = (char *) .ACCESS_WITH_SIZE ((char *) &static_annotated.c,...)
    9928              :      will be converted to
    9929              :      y = &static_annotated.c.  */
    9930              : 
    9931     17004280 :   if (require_constant
    9932      2903110 :       && TREE_CODE (inside_init) == NOP_EXPR
    9933       736267 :       && TREE_CODE (TREE_OPERAND (inside_init, 0)) == CALL_EXPR
    9934     17004282 :       && is_access_with_size_p (TREE_OPERAND (inside_init, 0)))
    9935            2 :     inside_init
    9936            2 :       = get_ref_from_access_with_size (TREE_OPERAND (inside_init, 0));
    9937              : 
    9938     17004280 :   if (!c_in_omp_for)
    9939              :     {
    9940     16999508 :       if (TREE_CODE (inside_init) == EXCESS_PRECISION_EXPR)
    9941              :         {
    9942          441 :           semantic_type = TREE_TYPE (inside_init);
    9943          441 :           inside_init = TREE_OPERAND (inside_init, 0);
    9944              :         }
    9945     16999508 :       inside_init = c_fully_fold (inside_init, require_constant, &maybe_const);
    9946              :     }
    9947              :   /* TODO: this may not detect all cases of expressions folding to
    9948              :      constants that are not arithmetic constant expressions.  */
    9949     17004280 :   if (!maybe_const)
    9950              :     arith_const_expr = false;
    9951     25375631 :   else if (!INTEGRAL_TYPE_P (TREE_TYPE (inside_init))
    9952      5684380 :            && TREE_CODE (TREE_TYPE (inside_init)) != REAL_TYPE
    9953     16929208 :            && TREE_CODE (TREE_TYPE (inside_init)) != COMPLEX_TYPE)
    9954              :     arith_const_expr = false;
    9955      8475132 :   else if (TREE_CODE (inside_init) != INTEGER_CST
    9956              :            && TREE_CODE (inside_init) != REAL_CST
    9957              :            && TREE_CODE (inside_init) != COMPLEX_CST
    9958              :            && TREE_CODE (inside_init) != RAW_DATA_CST)
    9959              :     arith_const_expr = false;
    9960      5112442 :   else if (TREE_OVERFLOW (inside_init))
    9961     11891882 :     arith_const_expr = false;
    9962              : 
    9963              :   /* Initialization of an array of chars from a string constant
    9964              :      optionally enclosed in braces.  */
    9965              : 
    9966     17004280 :   if (code == ARRAY_TYPE && inside_init
    9967       190240 :       && TREE_CODE (inside_init) == STRING_CST)
    9968              :     {
    9969        11813 :       tree typ1
    9970        11813 :         = (TYPE_ATOMIC (TREE_TYPE (type))
    9971        11813 :            ? c_build_qualified_type (TYPE_MAIN_VARIANT (TREE_TYPE (type)),
    9972              :                                      TYPE_QUAL_ATOMIC)
    9973        11799 :            : TYPE_MAIN_VARIANT (TREE_TYPE (type)));
    9974              :       /* Note that an array could be both an array of character type
    9975              :          and an array of wchar_t if wchar_t is signed char or unsigned
    9976              :          char.  */
    9977        23626 :       bool char_array = (typ1 == char_type_node
    9978          516 :                          || typ1 == signed_char_type_node
    9979        12294 :                          || typ1 == unsigned_char_type_node);
    9980        11813 :       bool wchar_array = comptypes (typ1, wchar_type_node);
    9981        11813 :       bool char16_array = comptypes (typ1, char16_type_node);
    9982        11813 :       bool char32_array = comptypes (typ1, char32_type_node);
    9983              : 
    9984        11813 :       if (char_array || wchar_array || char16_array || char32_array)
    9985              :         {
    9986        11784 :           struct c_expr expr;
    9987        11784 :           tree typ2 = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init)));
    9988        11784 :           bool incompat_string_cst = false;
    9989        11784 :           expr.value = inside_init;
    9990        11784 :           expr.original_code = (strict_string ? STRING_CST : ERROR_MARK);
    9991        11784 :           expr.original_type = NULL;
    9992        11784 :           expr.m_decimal = 0;
    9993        11784 :           maybe_warn_string_init (init_loc, type, expr);
    9994              : 
    9995        11784 :           if (flexible_array_member_type_p (type))
    9996           61 :             pedwarn_init (init_loc, OPT_Wpedantic,
    9997              :                           "initialization of a flexible array member");
    9998              : 
    9999        11784 :           if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
   10000        11784 :                          TYPE_MAIN_VARIANT (type)))
   10001              :             return inside_init;
   10002              : 
   10003         4186 :           if (char_array)
   10004              :             {
   10005         4075 :               if (typ2 != char_type_node && typ2 != char8_type_node)
   10006              :                 incompat_string_cst = true;
   10007              :             }
   10008          111 :           else if (!comptypes (typ1, typ2))
   10009              :             incompat_string_cst = true;
   10010              : 
   10011              :           if (incompat_string_cst)
   10012              :             {
   10013           72 :               error_init (init_loc, "cannot initialize array of %qT from "
   10014              :                           "a string literal with type array of %qT",
   10015              :                           typ1, typ2);
   10016           72 :               return error_mark_node;
   10017              :             }
   10018              : 
   10019         4114 :           if (require_constexpr
   10020         4114 :               && TYPE_UNSIGNED (typ1) != TYPE_UNSIGNED (typ2))
   10021              :             {
   10022              :               /* Check if all characters of the string can be
   10023              :                  represented in the type of the constexpr object being
   10024              :                  initialized.  */
   10025           24 :               unsigned HOST_WIDE_INT len = TREE_STRING_LENGTH (inside_init);
   10026           24 :               const unsigned char *p =
   10027           24 :                 (const unsigned char *) TREE_STRING_POINTER (inside_init);
   10028           24 :               gcc_assert (CHAR_TYPE_SIZE == 8 && CHAR_BIT == 8);
   10029           70 :               for (unsigned i = 0; i < len; i++)
   10030           58 :                 if (p[i] > 127)
   10031              :                   {
   10032           12 :                     error_init (init_loc, "%<constexpr%> initializer not "
   10033              :                                 "representable in type of object");
   10034           12 :                     break;
   10035              :                   }
   10036              :             }
   10037              : 
   10038         4114 :           if (TYPE_DOMAIN (type) != NULL_TREE
   10039         4020 :               && TYPE_SIZE (type) != NULL_TREE
   10040         8075 :               && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
   10041              :             {
   10042         3961 :               unsigned HOST_WIDE_INT len = TREE_STRING_LENGTH (inside_init);
   10043              : 
   10044         3961 :               if (compare_tree_int (TYPE_SIZE_UNIT (type), len) < 0)
   10045              :                 {
   10046          397 :                   unsigned HOST_WIDE_INT avail
   10047          397 :                     = tree_to_uhwi (TYPE_SIZE_UNIT (type));
   10048          397 :                   unsigned unit = TYPE_PRECISION (typ1) / BITS_PER_UNIT;
   10049          397 :                   const char *p = TREE_STRING_POINTER (inside_init);
   10050              : 
   10051              :                   /* Construct truncated string.  */
   10052          397 :                   inside_init = build_string (avail, p);
   10053              : 
   10054              :                   /* Subtract the size of a single (possibly wide) character
   10055              :                      because it may be ok to ignore the terminating NUL char
   10056              :                      that is counted in the length of the constant.  */
   10057          397 :                   if (len - unit > avail)
   10058           63 :                     pedwarn_init (init_loc, 0,
   10059              :                                   "initializer-string for array of %qT "
   10060              :                                   "is too long (%wu chars into %wu "
   10061              :                                   "available)", typ1, len, avail);
   10062          334 :                   else if (warn_cxx_compat)
   10063            9 :                     warning_at (init_loc, OPT_Wc___compat,
   10064              :                                 "initializer-string for array of %qT "
   10065              :                                 "is too long for C++ (%wu chars into %wu "
   10066              :                                 "available)", typ1, len, avail);
   10067          325 :                   else if (warn_unterminated_string_initialization
   10068          325 :                            && get_attr_nonstring_decl (decl) == NULL_TREE)
   10069           22 :                     warning_at (init_loc,
   10070           22 :                                 OPT_Wunterminated_string_initialization,
   10071              :                                 "initializer-string for array of %qT "
   10072              :                                 "truncates NUL terminator but destination "
   10073              :                                 "lacks %qs attribute (%wu chars into %wu "
   10074              :                                 "available)", typ1, "nonstring", len, avail);
   10075              :                 }
   10076              :             }
   10077              : 
   10078         4114 :           TREE_TYPE (inside_init) = type;
   10079         4114 :           return inside_init;
   10080              :         }
   10081           29 :       else if (INTEGRAL_TYPE_P (typ1))
   10082              :         {
   10083           29 :           error_init (init_loc, "array of inappropriate type initialized "
   10084              :                       "from string constant");
   10085           29 :           return error_mark_node;
   10086              :         }
   10087              :     }
   10088              : 
   10089              :   /* Build a VECTOR_CST from a *constant* vector constructor.  If the
   10090              :      vector constructor is not constant (e.g. {1,2,3,foo()}) then punt
   10091              :      below and handle as a constructor.  */
   10092     16992467 :   if (code == VECTOR_TYPE
   10093      6350586 :       && VECTOR_TYPE_P (TREE_TYPE (inside_init))
   10094      6350584 :       && vector_types_convertible_p (TREE_TYPE (inside_init), type, true)
   10095     23343013 :       && TREE_CONSTANT (inside_init))
   10096              :     {
   10097       636985 :       if (TREE_CODE (inside_init) == VECTOR_CST
   10098       637082 :           && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
   10099           97 :                         TYPE_MAIN_VARIANT (type)))
   10100              :         return inside_init;
   10101              : 
   10102       636888 :       if (TREE_CODE (inside_init) == CONSTRUCTOR)
   10103              :         {
   10104              :           unsigned HOST_WIDE_INT ix;
   10105              :           tree value;
   10106      4196782 :           bool constant_p = true;
   10107              : 
   10108              :           /* Iterate through elements and check if all constructor
   10109              :              elements are *_CSTs.  */
   10110      4196782 :           FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (inside_init), ix, value)
   10111      3559951 :             if (!CONSTANT_CLASS_P (value))
   10112              :               {
   10113              :                 constant_p = false;
   10114              :                 break;
   10115              :               }
   10116              : 
   10117       636888 :           if (constant_p)
   10118       636831 :             return build_vector_from_ctor (type,
   10119       636831 :                                            CONSTRUCTOR_ELTS (inside_init));
   10120              :         }
   10121              :     }
   10122              : 
   10123     16355539 :   if (warn_sequence_point)
   10124      2449444 :     verify_sequence_points (inside_init);
   10125              : 
   10126              :   /* Any type can be initialized
   10127              :      from an expression of the same type, optionally with braces.  */
   10128              : 
   10129     16355539 :   if (inside_init && TREE_TYPE (inside_init) != NULL_TREE
   10130     32711078 :       && (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
   10131     16355539 :                      TYPE_MAIN_VARIANT (type))
   10132      3154395 :           || (code == ARRAY_TYPE
   10133          477 :               && comptypes (TREE_TYPE (inside_init), type))
   10134      3154395 :           || (gnu_vector_type_p (type)
   10135          189 :               && comptypes (TREE_TYPE (inside_init), type))
   10136      3154395 :           || (code == POINTER_TYPE
   10137       112837 :               && TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE
   10138         9302 :               && comptypes (TREE_TYPE (TREE_TYPE (inside_init)),
   10139         9302 :                             TREE_TYPE (type)))))
   10140              :     {
   10141     13203122 :       if (code == POINTER_TYPE)
   10142              :         {
   10143       785552 :           if (TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE)
   10144              :             {
   10145         1978 :               if (TREE_CODE (inside_init) == STRING_CST
   10146           68 :                   || TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
   10147         1975 :                 inside_init = array_to_pointer_conversion
   10148         1975 :                   (init_loc, inside_init);
   10149              :               else
   10150              :                 {
   10151            3 :                   error_init (init_loc, "invalid use of non-lvalue array");
   10152            3 :                   return error_mark_node;
   10153              :                 }
   10154              :             }
   10155              :         }
   10156              : 
   10157     13203119 :       if (code == VECTOR_TYPE || c_hardbool_type_attr (type))
   10158              :         /* Although the types are compatible, we may require a
   10159              :            conversion.  */
   10160      5713602 :         inside_init = convert (type, inside_init);
   10161              : 
   10162     13203119 :       if ((code == RECORD_TYPE || code == UNION_TYPE)
   10163     13203119 :           && !comptypes (TYPE_MAIN_VARIANT (type), TYPE_MAIN_VARIANT (TREE_TYPE (inside_init))))
   10164              :         {
   10165            0 :           error_init (init_loc, "invalid initializer");
   10166            0 :           return error_mark_node;
   10167              :         }
   10168              : 
   10169     13203119 :       if (require_constant
   10170      2304724 :           && TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
   10171              :         {
   10172              :           /* As an extension, allow initializing objects with static storage
   10173              :              duration with compound literals (which are then treated just as
   10174              :              the brace enclosed list they contain).  Also allow this for
   10175              :              vectors, as we can only assign them with compound literals.  */
   10176           31 :           if (flag_isoc99 && code != VECTOR_TYPE)
   10177            8 :             pedwarn_init (init_loc, OPT_Wpedantic, "initializer element "
   10178              :                           "is not constant");
   10179           31 :           tree decl = COMPOUND_LITERAL_EXPR_DECL (inside_init);
   10180           31 :           inside_init = DECL_INITIAL (decl);
   10181              :         }
   10182              : 
   10183     13203119 :       if (code == ARRAY_TYPE && TREE_CODE (inside_init) != STRING_CST
   10184       177950 :           && TREE_CODE (inside_init) != CONSTRUCTOR)
   10185              :         {
   10186            2 :           error_init (init_loc, "array initialized from non-constant array "
   10187              :                       "expression");
   10188            2 :           return error_mark_node;
   10189              :         }
   10190              : 
   10191              :       /* Compound expressions can only occur here if -Wpedantic or
   10192              :          -pedantic-errors is specified.  In the later case, we always want
   10193              :          an error.  In the former case, we simply want a warning.  */
   10194     13203117 :       if (require_constant && pedantic
   10195        20365 :           && TREE_CODE (inside_init) == COMPOUND_EXPR)
   10196              :         {
   10197            1 :           inside_init
   10198            1 :             = valid_compound_expr_initializer (inside_init,
   10199            1 :                                                TREE_TYPE (inside_init));
   10200            1 :           if (inside_init == error_mark_node)
   10201            1 :             error_init (init_loc, "initializer element is not constant");
   10202              :           else
   10203            0 :             pedwarn_init (init_loc, OPT_Wpedantic,
   10204              :                           "initializer element is not constant");
   10205            1 :           if (flag_pedantic_errors)
   10206            0 :             inside_init = error_mark_node;
   10207              :         }
   10208      2304723 :       else if (require_constant
   10209      2304723 :                && !initializer_constant_valid_p (inside_init,
   10210      2304723 :                                                  TREE_TYPE (inside_init)))
   10211              :         {
   10212           94 :           error_init (init_loc, "initializer element is not constant");
   10213           94 :           inside_init = error_mark_node;
   10214              :         }
   10215     13203022 :       else if (require_constant && !maybe_const)
   10216          219 :         pedwarn_init (init_loc, OPT_Wpedantic,
   10217              :                       "initializer element is not a constant expression");
   10218     13202803 :       else if (require_constexpr)
   10219          610 :         check_constexpr_init (init_loc, type, inside_init,
   10220              :                               int_const_expr, arith_const_expr);
   10221              : 
   10222              :       /* Added to enable additional -Wsuggest-attribute=format warnings.  */
   10223     13203117 :       if (TREE_CODE (TREE_TYPE (inside_init)) == POINTER_TYPE)
   10224       855268 :         inside_init = convert_for_assignment (init_loc, UNKNOWN_LOCATION,
   10225              :                                               type, inside_init, origtype,
   10226              :                                               (require_constant
   10227              :                                                ? ic_init_const
   10228              :                                                : ic_init), null_pointer_constant,
   10229              :                                               NULL_TREE, NULL_TREE, 0);
   10230     13203117 :       if (TREE_CODE (inside_init) == RAW_DATA_CST
   10231          254 :           && c_inhibit_evaluation_warnings == 0
   10232          254 :           && warn_conversion
   10233            1 :           && !TYPE_UNSIGNED (type)
   10234     13203118 :           && TYPE_PRECISION (type) == CHAR_BIT)
   10235          303 :         for (unsigned int i = 0;
   10236          304 :              i < (unsigned) RAW_DATA_LENGTH (inside_init); ++i)
   10237          303 :           if (RAW_DATA_SCHAR_ELT (inside_init, i) < 0)
   10238           10 :             warning_at (init_loc, OPT_Wconversion,
   10239              :                         "conversion from %qT to %qT changes value from "
   10240              :                         "%qd to %qd",
   10241              :                         integer_type_node, type,
   10242           10 :                         RAW_DATA_UCHAR_ELT (inside_init, i),
   10243           10 :                         RAW_DATA_SCHAR_ELT (inside_init, i));
   10244              :       return inside_init;
   10245              :     }
   10246              : 
   10247              :   /* Handle scalar types, including conversions.  */
   10248              : 
   10249      3152417 :   if (code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE
   10250       130457 :       || code == POINTER_TYPE || code == ENUMERAL_TYPE || code == BOOLEAN_TYPE
   10251        11919 :       || code == COMPLEX_TYPE || code == VECTOR_TYPE || code == NULLPTR_TYPE
   10252         9856 :       || code == BITINT_TYPE)
   10253              :     {
   10254      3151929 :       tree unconverted_init = inside_init;
   10255      3151929 :       if (TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE
   10256      3151929 :           && (TREE_CODE (init) == STRING_CST
   10257            2 :               || TREE_CODE (init) == COMPOUND_LITERAL_EXPR))
   10258         7325 :         inside_init = init = array_to_pointer_conversion (init_loc, init);
   10259      3151929 :       if (semantic_type)
   10260          436 :         inside_init = build1 (EXCESS_PRECISION_EXPR, semantic_type,
   10261              :                               inside_init);
   10262      3151929 :       inside_init
   10263      5720317 :         = convert_for_assignment (init_loc, UNKNOWN_LOCATION, type,
   10264              :                                   inside_init, origtype,
   10265              :                                   require_constant ? ic_init_const : ic_init,
   10266              :                                   null_pointer_constant, NULL_TREE, NULL_TREE,
   10267              :                                   0);
   10268              : 
   10269              :       /* Check to see if we have already given an error message.  */
   10270      3151929 :       if (inside_init == error_mark_node)
   10271              :         ;
   10272      3151469 :       else if (require_constant && !TREE_CONSTANT (inside_init))
   10273              :         {
   10274           36 :           error_init (init_loc, "initializer element is not constant");
   10275           36 :           inside_init = error_mark_node;
   10276              :         }
   10277      3151433 :       else if (require_constant
   10278      3734546 :                && !initializer_constant_valid_p (inside_init,
   10279       583113 :                                                  TREE_TYPE (inside_init)))
   10280              :         {
   10281           10 :           error_init (init_loc, "initializer element is not computable at "
   10282              :                       "load time");
   10283           10 :           inside_init = error_mark_node;
   10284              :         }
   10285      3151423 :       else if (require_constant && !maybe_const)
   10286            5 :         pedwarn_init (init_loc, OPT_Wpedantic,
   10287              :                       "initializer element is not a constant expression");
   10288      3151418 :       else if (require_constexpr)
   10289          332 :         check_constexpr_init (init_loc, type, unconverted_init,
   10290              :                               int_const_expr, arith_const_expr);
   10291              : 
   10292              :       return inside_init;
   10293              :     }
   10294              : 
   10295              :   /* Come here only for records and arrays.  */
   10296              : 
   10297          488 :   if (COMPLETE_TYPE_P (type) && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
   10298              :     {
   10299            0 :       error_init (init_loc,
   10300              :                   "variable-sized object may not be initialized except "
   10301              :                   "with an empty initializer");
   10302            0 :       return error_mark_node;
   10303              :     }
   10304              : 
   10305          488 :   error_init (init_loc, "invalid initializer");
   10306          488 :   return error_mark_node;
   10307              : }
   10308              : 
   10309              : /* Handle initializers that use braces.  */
   10310              : 
   10311              : /* Type of object we are accumulating a constructor for.
   10312              :    This type is always a RECORD_TYPE, UNION_TYPE or ARRAY_TYPE.  */
   10313              : static tree constructor_type;
   10314              : 
   10315              : /* For a RECORD_TYPE or UNION_TYPE, this is the chain of fields
   10316              :    left to fill.  */
   10317              : static tree constructor_fields;
   10318              : 
   10319              : /* For an ARRAY_TYPE, this is the specified index
   10320              :    at which to store the next element we get.  */
   10321              : static tree constructor_index;
   10322              : 
   10323              : /* For an ARRAY_TYPE, this is the maximum index.  */
   10324              : static tree constructor_max_index;
   10325              : 
   10326              : /* For a RECORD_TYPE, this is the first field not yet written out.  */
   10327              : static tree constructor_unfilled_fields;
   10328              : 
   10329              : /* For an ARRAY_TYPE, this is the index of the first element
   10330              :    not yet written out.  */
   10331              : static tree constructor_unfilled_index;
   10332              : 
   10333              : /* In a RECORD_TYPE, the byte index of the next consecutive field.
   10334              :    This is so we can generate gaps between fields, when appropriate.  */
   10335              : static tree constructor_bit_index;
   10336              : 
   10337              : /* If we are saving up the elements rather than allocating them,
   10338              :    this is the list of elements so far (in reverse order,
   10339              :    most recent first).  */
   10340              : static vec<constructor_elt, va_gc> *constructor_elements;
   10341              : 
   10342              : /* 1 if constructor should be incrementally stored into a constructor chain,
   10343              :    0 if all the elements should be kept in AVL tree.  */
   10344              : static int constructor_incremental;
   10345              : 
   10346              : /* 1 if so far this constructor's elements are all compile-time constants.  */
   10347              : static int constructor_constant;
   10348              : 
   10349              : /* 1 if so far this constructor's elements are all valid address constants.  */
   10350              : static int constructor_simple;
   10351              : 
   10352              : /* 1 if this constructor has an element that cannot be part of a
   10353              :    constant expression.  */
   10354              : static int constructor_nonconst;
   10355              : 
   10356              : /* 1 if this constructor is erroneous so far.  */
   10357              : static int constructor_erroneous;
   10358              : 
   10359              : /* 1 if this constructor is the universal zero initializer { 0 }.  */
   10360              : static int constructor_zeroinit;
   10361              : 
   10362              : /* 1 if this constructor should have padding bits zeroed (C23 {}.  */
   10363              : static bool constructor_zero_padding_bits;
   10364              : 
   10365              : /* 1 if this constructor is a braced scalar initializer (further nested levels
   10366              :    of braces are an error).  */
   10367              : static bool constructor_braced_scalar;
   10368              : 
   10369              : /* Structure for managing pending initializer elements, organized as an
   10370              :    AVL tree.  */
   10371              : 
   10372              : struct init_node
   10373              : {
   10374              :   struct init_node *left, *right;
   10375              :   struct init_node *parent;
   10376              :   int balance;
   10377              :   tree purpose;
   10378              :   tree value;
   10379              :   tree origtype;
   10380              : };
   10381              : 
   10382              : /* Tree of pending elements at this constructor level.
   10383              :    These are elements encountered out of order
   10384              :    which belong at places we haven't reached yet in actually
   10385              :    writing the output.
   10386              :    Will never hold tree nodes across GC runs.  */
   10387              : static struct init_node *constructor_pending_elts;
   10388              : 
   10389              : /* The SPELLING_DEPTH of this constructor.  */
   10390              : static int constructor_depth;
   10391              : 
   10392              : /* DECL node for which an initializer is being read.
   10393              :    0 means we are reading a constructor expression
   10394              :    such as (struct foo) {...}.  */
   10395              : static tree constructor_decl;
   10396              : 
   10397              : /* Nonzero if there were any member designators in this initializer.  */
   10398              : static int constructor_designated;
   10399              : 
   10400              : /* Nesting depth of designator list.  */
   10401              : static int designator_depth;
   10402              : 
   10403              : /* Nonzero if there were diagnosed errors in this designator list.  */
   10404              : static int designator_erroneous;
   10405              : 
   10406              : 
   10407              : /* This stack has a level for each implicit or explicit level of
   10408              :    structuring in the initializer, including the outermost one.  It
   10409              :    saves the values of most of the variables above.  */
   10410              : 
   10411              : struct constructor_range_stack;
   10412              : 
   10413              : struct constructor_stack
   10414              : {
   10415              :   struct constructor_stack *next;
   10416              :   tree type;
   10417              :   tree fields;
   10418              :   tree index;
   10419              :   tree max_index;
   10420              :   tree unfilled_index;
   10421              :   tree unfilled_fields;
   10422              :   tree bit_index;
   10423              :   vec<constructor_elt, va_gc> *elements;
   10424              :   struct init_node *pending_elts;
   10425              :   int offset;
   10426              :   int depth;
   10427              :   /* If value nonzero, this value should replace the entire
   10428              :      constructor at this level.  */
   10429              :   struct c_expr replacement_value;
   10430              :   struct constructor_range_stack *range_stack;
   10431              :   char constant;
   10432              :   char simple;
   10433              :   char nonconst;
   10434              :   char implicit;
   10435              :   char erroneous;
   10436              :   char outer;
   10437              :   char incremental;
   10438              :   char designated;
   10439              :   bool zero_padding_bits;
   10440              :   bool braced_scalar;
   10441              :   int designator_depth;
   10442              : };
   10443              : 
   10444              : static struct constructor_stack *constructor_stack;
   10445              : 
   10446              : /* This stack represents designators from some range designator up to
   10447              :    the last designator in the list.  */
   10448              : 
   10449              : struct constructor_range_stack
   10450              : {
   10451              :   struct constructor_range_stack *next, *prev;
   10452              :   struct constructor_stack *stack;
   10453              :   tree range_start;
   10454              :   tree index;
   10455              :   tree range_end;
   10456              :   tree fields;
   10457              : };
   10458              : 
   10459              : static struct constructor_range_stack *constructor_range_stack;
   10460              : 
   10461              : /* This stack records separate initializers that are nested.
   10462              :    Nested initializers can't happen in ANSI C, but GNU C allows them
   10463              :    in cases like { ... (struct foo) { ... } ... }.  */
   10464              : 
   10465              : struct initializer_stack
   10466              : {
   10467              :   struct initializer_stack *next;
   10468              :   tree decl;
   10469              :   struct constructor_stack *constructor_stack;
   10470              :   struct constructor_range_stack *constructor_range_stack;
   10471              :   vec<constructor_elt, va_gc> *elements;
   10472              :   struct spelling *spelling;
   10473              :   struct spelling *spelling_base;
   10474              :   int spelling_size;
   10475              :   char require_constant_value;
   10476              :   char require_constant_elements;
   10477              :   char require_constexpr_value;
   10478              :   char designated;
   10479              :   rich_location *missing_brace_richloc;
   10480              : };
   10481              : 
   10482              : static struct initializer_stack *initializer_stack;
   10483              : 
   10484              : /* Prepare to parse and output the initializer for variable DECL.  */
   10485              : 
   10486              : void
   10487      7319256 : start_init (tree decl, tree asmspec_tree ATTRIBUTE_UNUSED,
   10488              :             bool init_require_constant, bool init_require_constexpr,
   10489              :             rich_location *richloc)
   10490              : {
   10491      7319256 :   const char *locus;
   10492      7319256 :   struct initializer_stack *p = XNEW (struct initializer_stack);
   10493              : 
   10494      7319256 :   p->decl = constructor_decl;
   10495      7319256 :   p->require_constant_value = require_constant_value;
   10496      7319256 :   p->require_constant_elements = require_constant_elements;
   10497      7319256 :   p->require_constexpr_value = require_constexpr_value;
   10498      7319256 :   p->constructor_stack = constructor_stack;
   10499      7319256 :   p->constructor_range_stack = constructor_range_stack;
   10500      7319256 :   p->elements = constructor_elements;
   10501      7319256 :   p->spelling = spelling;
   10502      7319256 :   p->spelling_base = spelling_base;
   10503      7319256 :   p->spelling_size = spelling_size;
   10504      7319256 :   p->next = initializer_stack;
   10505      7319256 :   p->missing_brace_richloc = richloc;
   10506      7319256 :   p->designated = constructor_designated;
   10507      7319256 :   initializer_stack = p;
   10508              : 
   10509      7319256 :   constructor_decl = decl;
   10510      7319256 :   constructor_designated = 0;
   10511              : 
   10512      7319256 :   require_constant_value = init_require_constant;
   10513      7319256 :   require_constexpr_value = init_require_constexpr;
   10514      7319256 :   if (decl != NULL_TREE && decl != error_mark_node)
   10515              :     {
   10516      6391631 :       require_constant_elements
   10517      6212927 :         = ((init_require_constant || (pedantic && !flag_isoc99))
   10518              :            /* For a scalar, you can always use any value to initialize,
   10519              :               even within braces.  */
   10520      6404768 :            && AGGREGATE_TYPE_P (TREE_TYPE (decl)));
   10521      6391631 :       locus = identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl)));
   10522              :     }
   10523              :   else
   10524              :     {
   10525       927625 :       require_constant_elements = false;
   10526       927625 :       locus = _("(anonymous)");
   10527              :     }
   10528              : 
   10529      7319256 :   constructor_stack = 0;
   10530      7319256 :   constructor_range_stack = 0;
   10531              : 
   10532      7319256 :   found_missing_braces = 0;
   10533              : 
   10534      7319256 :   spelling_base = 0;
   10535      7319256 :   spelling_size = 0;
   10536      7319256 :   RESTORE_SPELLING_DEPTH (0);
   10537              : 
   10538      7319256 :   if (locus)
   10539      7319256 :     push_string (locus);
   10540      7319256 : }
   10541              : 
   10542              : void
   10543      7319254 : finish_init (void)
   10544              : {
   10545      7319254 :   struct initializer_stack *p = initializer_stack;
   10546              : 
   10547              :   /* Free the whole constructor stack of this initializer.  */
   10548      7319254 :   while (constructor_stack)
   10549              :     {
   10550            0 :       struct constructor_stack *q = constructor_stack;
   10551            0 :       constructor_stack = q->next;
   10552            0 :       XDELETE (q);
   10553              :     }
   10554              : 
   10555      7319254 :   gcc_assert (!constructor_range_stack);
   10556              : 
   10557              :   /* Pop back to the data of the outer initializer (if any).  */
   10558      7319254 :   XDELETE (spelling_base);
   10559              : 
   10560      7319254 :   constructor_decl = p->decl;
   10561      7319254 :   require_constant_value = p->require_constant_value;
   10562      7319254 :   require_constant_elements = p->require_constant_elements;
   10563      7319254 :   require_constexpr_value = p->require_constexpr_value;
   10564      7319254 :   constructor_stack = p->constructor_stack;
   10565      7319254 :   constructor_designated = p->designated;
   10566      7319254 :   constructor_range_stack = p->constructor_range_stack;
   10567      7319254 :   constructor_elements = p->elements;
   10568      7319254 :   spelling = p->spelling;
   10569      7319254 :   spelling_base = p->spelling_base;
   10570      7319254 :   spelling_size = p->spelling_size;
   10571      7319254 :   initializer_stack = p->next;
   10572      7319254 :   XDELETE (p);
   10573      7319254 : }
   10574              : 
   10575              : /* Call here when we see the initializer is surrounded by braces.
   10576              :    This is instead of a call to push_init_level;
   10577              :    it is matched by a call to pop_init_level.
   10578              : 
   10579              :    TYPE is the type to initialize, for a constructor expression.
   10580              :    For an initializer for a decl, TYPE is zero.  */
   10581              : 
   10582              : void
   10583      1032982 : really_start_incremental_init (tree type)
   10584              : {
   10585      1032982 :   struct constructor_stack *p = XNEW (struct constructor_stack);
   10586              : 
   10587      1032982 :   if (type == NULL_TREE)
   10588       107325 :     type = TREE_TYPE (constructor_decl);
   10589              : 
   10590      1032982 :   if (VECTOR_TYPE_P (type)
   10591      1032982 :       && TYPE_VECTOR_OPAQUE (type))
   10592            0 :     error ("opaque vector types cannot be initialized");
   10593              : 
   10594      1032982 :   p->type = constructor_type;
   10595      1032982 :   p->fields = constructor_fields;
   10596      1032982 :   p->index = constructor_index;
   10597      1032982 :   p->max_index = constructor_max_index;
   10598      1032982 :   p->unfilled_index = constructor_unfilled_index;
   10599      1032982 :   p->unfilled_fields = constructor_unfilled_fields;
   10600      1032982 :   p->bit_index = constructor_bit_index;
   10601      1032982 :   p->elements = constructor_elements;
   10602      1032982 :   p->constant = constructor_constant;
   10603      1032982 :   p->simple = constructor_simple;
   10604      1032982 :   p->nonconst = constructor_nonconst;
   10605      1032982 :   p->erroneous = constructor_erroneous;
   10606      1032982 :   p->pending_elts = constructor_pending_elts;
   10607      1032982 :   p->depth = constructor_depth;
   10608      1032982 :   p->replacement_value.value = 0;
   10609      1032982 :   p->replacement_value.original_code = ERROR_MARK;
   10610      1032982 :   p->replacement_value.original_type = NULL;
   10611      1032982 :   p->implicit = 0;
   10612      1032982 :   p->range_stack = 0;
   10613      1032982 :   p->outer = 0;
   10614      1032982 :   p->incremental = constructor_incremental;
   10615      1032982 :   p->designated = constructor_designated;
   10616      1032982 :   p->zero_padding_bits = constructor_zero_padding_bits;
   10617      1032982 :   p->braced_scalar = constructor_braced_scalar;
   10618      1032982 :   p->designator_depth = designator_depth;
   10619      1032982 :   p->next = 0;
   10620      1032982 :   constructor_stack = p;
   10621              : 
   10622      1032982 :   constructor_constant = 1;
   10623      1032982 :   constructor_simple = 1;
   10624      1032982 :   constructor_nonconst = 0;
   10625      1032982 :   constructor_depth = SPELLING_DEPTH ();
   10626      1032982 :   constructor_elements = NULL;
   10627      1032982 :   constructor_pending_elts = 0;
   10628      1032982 :   constructor_type = type;
   10629      1032982 :   constructor_incremental = 1;
   10630      1032982 :   constructor_designated = 0;
   10631      1032982 :   constructor_zero_padding_bits = false;
   10632      1032982 :   constructor_zeroinit = 1;
   10633      1032982 :   constructor_braced_scalar = false;
   10634      1032982 :   designator_depth = 0;
   10635      1032982 :   designator_erroneous = 0;
   10636              : 
   10637      1032982 :   if (RECORD_OR_UNION_TYPE_P (constructor_type))
   10638              :     {
   10639        82389 :       constructor_fields = TYPE_FIELDS (constructor_type);
   10640              :       /* Skip any nameless bit fields at the beginning.  */
   10641        82389 :       while (constructor_fields != NULL_TREE
   10642        82417 :              && DECL_UNNAMED_BIT_FIELD (constructor_fields))
   10643           28 :         constructor_fields = DECL_CHAIN (constructor_fields);
   10644              : 
   10645        82389 :       constructor_unfilled_fields = constructor_fields;
   10646        82389 :       constructor_bit_index = bitsize_zero_node;
   10647              :     }
   10648       950593 :   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   10649              :     {
   10650        18711 :       if (TYPE_DOMAIN (constructor_type))
   10651              :         {
   10652         9802 :           constructor_max_index
   10653         9802 :             = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
   10654              : 
   10655              :           /* Detect non-empty initializations of zero-length arrays.  */
   10656         9802 :           if (constructor_max_index == NULL_TREE
   10657         9802 :               && TYPE_SIZE (constructor_type))
   10658          207 :             constructor_max_index = integer_minus_one_node;
   10659              : 
   10660              :           /* constructor_max_index needs to be an INTEGER_CST.  Attempts
   10661              :              to initialize VLAs with a nonempty initializer will cause a
   10662              :              proper error; avoid tree checking errors as well by setting a
   10663              :              safe value.  */
   10664         9802 :           if (constructor_max_index
   10665         9802 :               && TREE_CODE (constructor_max_index) != INTEGER_CST)
   10666           73 :             constructor_max_index = integer_minus_one_node;
   10667              : 
   10668         9802 :           constructor_index
   10669         9802 :             = convert (bitsizetype,
   10670         9802 :                        TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
   10671              :         }
   10672              :       else
   10673              :         {
   10674         8909 :           constructor_index = bitsize_zero_node;
   10675         8909 :           constructor_max_index = NULL_TREE;
   10676              :         }
   10677              : 
   10678        18711 :       constructor_unfilled_index = constructor_index;
   10679              :     }
   10680       931882 :   else if (gnu_vector_type_p (constructor_type))
   10681              :     {
   10682              :       /* Vectors are like simple fixed-size arrays.  */
   10683      1862652 :       constructor_max_index =
   10684       931326 :         bitsize_int (TYPE_VECTOR_SUBPARTS (constructor_type) - 1);
   10685       931326 :       constructor_index = bitsize_zero_node;
   10686       931326 :       constructor_unfilled_index = constructor_index;
   10687              :     }
   10688              :   else
   10689              :     {
   10690              :       /* Handle the case of int x = {5}; */
   10691          556 :       constructor_fields = constructor_type;
   10692          556 :       constructor_unfilled_fields = constructor_type;
   10693          556 :       constructor_braced_scalar = true;
   10694              :     }
   10695      1032982 : }
   10696              : 
   10697              : extern location_t last_init_list_comma;
   10698              : 
   10699              : /* Called when we see an open brace for a nested initializer.  Finish
   10700              :    off any pending levels with implicit braces.  */
   10701              : void
   10702       342508 : finish_implicit_inits (location_t loc, struct obstack *braced_init_obstack)
   10703              : {
   10704       342510 :   while (constructor_stack->implicit)
   10705              :     {
   10706         1154 :       if (RECORD_OR_UNION_TYPE_P (constructor_type)
   10707          208 :           && constructor_fields == NULL_TREE)
   10708            0 :         process_init_element (input_location,
   10709              :                               pop_init_level (loc, 1, braced_init_obstack,
   10710              :                                               last_init_list_comma),
   10711              :                               true, braced_init_obstack);
   10712         1154 :       else if (TREE_CODE (constructor_type) == ARRAY_TYPE
   10713          946 :                && constructor_max_index
   10714         2100 :                && tree_int_cst_lt (constructor_max_index,
   10715              :                                    constructor_index))
   10716            2 :         process_init_element (input_location,
   10717              :                               pop_init_level (loc, 1, braced_init_obstack,
   10718              :                                               last_init_list_comma),
   10719              :                               true, braced_init_obstack);
   10720              :       else
   10721              :         break;
   10722              :     }
   10723       342508 : }
   10724              : 
   10725              : /* Push down into a subobject, for initialization.
   10726              :    If this is for an explicit set of braces, IMPLICIT is 0.
   10727              :    If it is because the next element belongs at a lower level,
   10728              :    IMPLICIT is 1 (or 2 if the push is because of designator list).  */
   10729              : 
   10730              : void
   10731      1045188 : push_init_level (location_t loc, int implicit,
   10732              :                  struct obstack *braced_init_obstack)
   10733              : {
   10734      1045188 :   struct constructor_stack *p;
   10735      1045188 :   tree value = NULL_TREE;
   10736              : 
   10737              :   /* Unless this is an explicit brace, we need to preserve previous
   10738              :      content if any.  */
   10739      1045188 :   if (implicit)
   10740              :     {
   10741       705323 :       if (RECORD_OR_UNION_TYPE_P (constructor_type) && constructor_fields)
   10742         1819 :         value = find_init_member (constructor_fields, braced_init_obstack);
   10743       703504 :       else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   10744       703504 :         value = find_init_member (constructor_index, braced_init_obstack);
   10745              :     }
   10746              : 
   10747      1045188 :   p = XNEW (struct constructor_stack);
   10748      1045188 :   p->type = constructor_type;
   10749      1045188 :   p->fields = constructor_fields;
   10750      1045188 :   p->index = constructor_index;
   10751      1045188 :   p->max_index = constructor_max_index;
   10752      1045188 :   p->unfilled_index = constructor_unfilled_index;
   10753      1045188 :   p->unfilled_fields = constructor_unfilled_fields;
   10754      1045188 :   p->bit_index = constructor_bit_index;
   10755      1045188 :   p->elements = constructor_elements;
   10756      1045188 :   p->constant = constructor_constant;
   10757      1045188 :   p->simple = constructor_simple;
   10758      1045188 :   p->nonconst = constructor_nonconst;
   10759      1045188 :   p->erroneous = constructor_erroneous;
   10760      1045188 :   p->pending_elts = constructor_pending_elts;
   10761      1045188 :   p->depth = constructor_depth;
   10762      1045188 :   p->replacement_value.value = NULL_TREE;
   10763      1045188 :   p->replacement_value.original_code = ERROR_MARK;
   10764      1045188 :   p->replacement_value.original_type = NULL;
   10765      1045188 :   p->implicit = implicit;
   10766      1045188 :   p->outer = 0;
   10767      1045188 :   p->incremental = constructor_incremental;
   10768      1045188 :   p->designated = constructor_designated;
   10769      1045188 :   p->zero_padding_bits = constructor_zero_padding_bits;
   10770      1045188 :   p->braced_scalar = constructor_braced_scalar;
   10771      1045188 :   p->designator_depth = designator_depth;
   10772      1045188 :   p->next = constructor_stack;
   10773      1045188 :   p->range_stack = 0;
   10774      1045188 :   constructor_stack = p;
   10775              : 
   10776      1045188 :   constructor_constant = 1;
   10777      1045188 :   constructor_simple = 1;
   10778      1045188 :   constructor_nonconst = 0;
   10779      1045188 :   constructor_depth = SPELLING_DEPTH ();
   10780      1045188 :   constructor_elements = NULL;
   10781      1045188 :   constructor_incremental = 1;
   10782              :   /* If the upper initializer is designated, then mark this as
   10783              :      designated too to prevent bogus warnings.  */
   10784      1045188 :   constructor_designated = p->designated;
   10785              :   /* If the upper initializer has padding bits zeroed, that includes
   10786              :      all nested initializers as well.  */
   10787      1045188 :   constructor_zero_padding_bits = p->zero_padding_bits;
   10788      1045188 :   constructor_braced_scalar = false;
   10789      1045188 :   constructor_pending_elts = 0;
   10790      1045188 :   if (!implicit)
   10791              :     {
   10792       339865 :       p->range_stack = constructor_range_stack;
   10793       339865 :       constructor_range_stack = 0;
   10794       339865 :       designator_depth = 0;
   10795       339865 :       designator_erroneous = 0;
   10796              :     }
   10797              : 
   10798              :   /* Don't die if an entire brace-pair level is superfluous
   10799              :      in the containing level.  */
   10800      1045188 :   if (constructor_type == NULL_TREE)
   10801              :     ;
   10802      1045188 :   else if (RECORD_OR_UNION_TYPE_P (constructor_type))
   10803              :     {
   10804              :       /* Don't die if there are extra init elts at the end.  */
   10805       160060 :       if (constructor_fields == NULL_TREE)
   10806           51 :         constructor_type = NULL_TREE;
   10807              :       else
   10808              :         {
   10809       160009 :           constructor_type = TREE_TYPE (constructor_fields);
   10810       160009 :           push_member_name (constructor_fields);
   10811       160009 :           constructor_depth++;
   10812              :         }
   10813              :     }
   10814       885128 :   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   10815              :     {
   10816       885077 :       constructor_type = TREE_TYPE (constructor_type);
   10817       885077 :       push_array_bounds (tree_to_uhwi (constructor_index));
   10818       885077 :       constructor_depth++;
   10819              :     }
   10820              : 
   10821      1045188 :   if (constructor_type == NULL_TREE)
   10822              :     {
   10823           51 :       error_init (loc, "extra brace group at end of initializer");
   10824           51 :       constructor_fields = NULL_TREE;
   10825           51 :       constructor_unfilled_fields = NULL_TREE;
   10826           51 :       return;
   10827              :     }
   10828              : 
   10829      1045137 :   if (value && TREE_CODE (value) == CONSTRUCTOR)
   10830              :     {
   10831         1686 :       constructor_constant = TREE_CONSTANT (value);
   10832         1686 :       constructor_simple = TREE_STATIC (value);
   10833         1686 :       constructor_nonconst = CONSTRUCTOR_NON_CONST (value);
   10834         1686 :       constructor_elements = CONSTRUCTOR_ELTS (value);
   10835         1686 :       constructor_zero_padding_bits |= CONSTRUCTOR_ZERO_PADDING_BITS (value);
   10836         1686 :       if (!vec_safe_is_empty (constructor_elements)
   10837         1462 :           && (TREE_CODE (constructor_type) == RECORD_TYPE
   10838         1462 :               || TREE_CODE (constructor_type) == ARRAY_TYPE))
   10839         1416 :         set_nonincremental_init (braced_init_obstack);
   10840              :     }
   10841              : 
   10842      1045137 :   if (implicit == 1)
   10843              :     {
   10844       702680 :       found_missing_braces = 1;
   10845       702680 :       if (initializer_stack->missing_brace_richloc)
   10846       702680 :         initializer_stack->missing_brace_richloc->add_fixit_insert_before
   10847       702680 :           (loc, "{");
   10848              :     }
   10849              : 
   10850      1045137 :   if (RECORD_OR_UNION_TYPE_P (constructor_type))
   10851              :     {
   10852       880926 :       constructor_fields = TYPE_FIELDS (constructor_type);
   10853              :       /* Skip any nameless bit fields at the beginning.  */
   10854       880926 :       while (constructor_fields != NULL_TREE
   10855       880990 :              && DECL_UNNAMED_BIT_FIELD (constructor_fields))
   10856           64 :         constructor_fields = DECL_CHAIN (constructor_fields);
   10857              : 
   10858       880926 :       constructor_unfilled_fields = constructor_fields;
   10859       880926 :       constructor_bit_index = bitsize_zero_node;
   10860              :     }
   10861       164211 :   else if (gnu_vector_type_p (constructor_type))
   10862              :     {
   10863              :       /* Vectors are like simple fixed-size arrays.  */
   10864         9602 :       constructor_max_index =
   10865         4801 :         bitsize_int (TYPE_VECTOR_SUBPARTS (constructor_type) - 1);
   10866         4801 :       constructor_index = bitsize_int (0);
   10867         4801 :       constructor_unfilled_index = constructor_index;
   10868              :     }
   10869       159410 :   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   10870              :     {
   10871       159330 :       if (TYPE_DOMAIN (constructor_type))
   10872              :         {
   10873       159330 :           constructor_max_index
   10874       159330 :             = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
   10875              : 
   10876              :           /* Detect non-empty initializations of zero-length arrays.  */
   10877       159330 :           if (constructor_max_index == NULL_TREE
   10878       159330 :               && TYPE_SIZE (constructor_type))
   10879          135 :             constructor_max_index = integer_minus_one_node;
   10880              : 
   10881              :           /* constructor_max_index needs to be an INTEGER_CST.  Attempts
   10882              :              to initialize VLAs will cause a proper error; avoid tree
   10883              :              checking errors as well by setting a safe value.  */
   10884       159330 :           if (constructor_max_index
   10885       159060 :               && TREE_CODE (constructor_max_index) != INTEGER_CST)
   10886            2 :             constructor_max_index = integer_minus_one_node;
   10887              : 
   10888       159330 :           constructor_index
   10889       159330 :             = convert (bitsizetype,
   10890       159330 :                        TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
   10891              :         }
   10892              :       else
   10893            0 :         constructor_index = bitsize_zero_node;
   10894              : 
   10895       159330 :       constructor_unfilled_index = constructor_index;
   10896       159330 :       if (value && TREE_CODE (value) == STRING_CST)
   10897              :         {
   10898              :           /* We need to split the char/wchar array into individual
   10899              :              characters, so that we don't have to special case it
   10900              :              everywhere.  */
   10901            7 :           set_nonincremental_init_from_string (value, braced_init_obstack);
   10902              :         }
   10903              :     }
   10904              :   else
   10905              :     {
   10906           80 :       if (constructor_type != error_mark_node)
   10907              :         {
   10908           51 :           if (p->braced_scalar)
   10909           22 :             permerror_init (input_location, 0,
   10910              :                             "braces around scalar initializer");
   10911              :           else
   10912           29 :             warning_init (input_location, 0,
   10913              :                           "braces around scalar initializer");
   10914           51 :           constructor_braced_scalar = true;
   10915              :         }
   10916           80 :       constructor_fields = constructor_type;
   10917           80 :       constructor_unfilled_fields = constructor_type;
   10918              :     }
   10919              : }
   10920              : 
   10921              : /* At the end of an implicit or explicit brace level,
   10922              :    finish up that level of constructor.  If a single expression
   10923              :    with redundant braces initialized that level, return the
   10924              :    c_expr structure for that expression.  Otherwise, the original_code
   10925              :    element is set to ERROR_MARK.
   10926              :    If we were outputting the elements as they are read, return 0 as the value
   10927              :    from inner levels (process_init_element ignores that),
   10928              :    but return error_mark_node as the value from the outermost level
   10929              :    (that's what we want to put in DECL_INITIAL).
   10930              :    Otherwise, return a CONSTRUCTOR expression as the value.  */
   10931              : 
   10932              : struct c_expr
   10933      2078170 : pop_init_level (location_t loc, int implicit,
   10934              :                 struct obstack *braced_init_obstack,
   10935              :                 location_t insert_before)
   10936              : {
   10937      2078170 :   struct constructor_stack *p;
   10938      2078170 :   struct c_expr ret;
   10939      2078170 :   ret.value = NULL_TREE;
   10940      2078170 :   ret.original_code = ERROR_MARK;
   10941      2078170 :   ret.original_type = NULL;
   10942      2078170 :   ret.m_decimal = 0;
   10943              : 
   10944      2078170 :   if (implicit == 0)
   10945              :     {
   10946              :       /* When we come to an explicit close brace,
   10947              :          pop any inner levels that didn't have explicit braces.  */
   10948      1374189 :       while (constructor_stack->implicit)
   10949         1342 :         process_init_element (input_location,
   10950              :                               pop_init_level (loc, 1, braced_init_obstack,
   10951              :                                               insert_before),
   10952              :                               true, braced_init_obstack);
   10953      1372847 :       gcc_assert (!constructor_range_stack);
   10954              :     }
   10955              :   else
   10956       705323 :     if (initializer_stack->missing_brace_richloc)
   10957       705323 :       initializer_stack->missing_brace_richloc->add_fixit_insert_before
   10958       705323 :         (insert_before, "}");
   10959              : 
   10960              :   /* Now output all pending elements.  */
   10961      2078170 :   constructor_incremental = 1;
   10962      2078170 :   output_pending_init_elements (1, braced_init_obstack);
   10963              : 
   10964      2078170 :   p = constructor_stack;
   10965              : 
   10966              :   /* Error for initializing a flexible array member.  */
   10967      2078119 :   if (constructor_type && constructor_fields
   10968      2239206 :       && flexible_array_member_type_p (constructor_type))
   10969              :     {
   10970              :       /* Silently discard empty initializations.  The parser will
   10971              :          already have pedwarned for empty brackets for C17 and earlier.  */
   10972          270 :       if (integer_zerop (constructor_unfilled_index))
   10973           54 :         constructor_type = NULL_TREE;
   10974          270 :       if (constructor_type || flag_isoc23)
   10975              :         {
   10976          266 :           gcc_assert (!constructor_type || !TYPE_SIZE (constructor_type));
   10977              : 
   10978          266 :           if (constructor_depth <= 2)
   10979          219 :             pedwarn_init (loc, OPT_Wpedantic,
   10980              :                           "initialization of a flexible array member");
   10981           47 :           else if (constructor_type)
   10982           33 :             error_init (loc, "initialization of flexible array member "
   10983              :                              "in a nested context");
   10984              :           else
   10985           14 :             pedwarn_init (loc, OPT_Wpedantic,
   10986              :                           "initialization of flexible array member "
   10987              :                           "in a nested context");
   10988              : 
   10989              :           /* We have already issued an error message for the existence
   10990              :              of a flexible array member not at the end of the structure.
   10991              :              Discard the initializer so that we do not die later.  */
   10992          266 :           if (constructor_type
   10993          216 :               && DECL_CHAIN (constructor_fields) != NULL_TREE
   10994          272 :               && (!p->type || TREE_CODE (p->type) != UNION_TYPE))
   10995            0 :             constructor_type = NULL_TREE;
   10996              :         }
   10997              :     }
   10998              : 
   10999      2078170 :   switch (vec_safe_length (constructor_elements))
   11000              :     {
   11001         5119 :     case 0:
   11002              :       /* Initialization with { } counts as zeroinit.  */
   11003         5119 :       constructor_zeroinit = 1;
   11004         5119 :       break;
   11005       916567 :     case 1:
   11006              :       /* This might be zeroinit as well.  */
   11007       916567 :       if (integer_zerop ((*constructor_elements)[0].value))
   11008         2119 :         constructor_zeroinit = 1;
   11009              :       break;
   11010      1156484 :     default:
   11011              :       /* If the constructor has more than one element, it can't be { 0 }.  */
   11012      1156484 :       constructor_zeroinit = 0;
   11013      1156484 :       break;
   11014              :     }
   11015              : 
   11016              :   /* Warn when some structs are initialized with direct aggregation.  */
   11017      2078170 :   if (!implicit && found_missing_braces && warn_missing_braces
   11018           37 :       && !constructor_zeroinit)
   11019              :     {
   11020           18 :       gcc_assert (initializer_stack->missing_brace_richloc);
   11021           18 :       warning_at (initializer_stack->missing_brace_richloc,
   11022           18 :                   OPT_Wmissing_braces,
   11023              :                   "missing braces around initializer");
   11024              :     }
   11025              : 
   11026              :   /* Warn when some struct elements are implicitly initialized to zero.  */
   11027      2078170 :   if (warn_missing_field_initializers
   11028       425477 :       && constructor_type
   11029       425463 :       && TREE_CODE (constructor_type) == RECORD_TYPE
   11030       193409 :       && constructor_unfilled_fields)
   11031              :     {
   11032              :         /* Do not warn for flexible array members or zero-length arrays.  */
   11033           43 :         while (constructor_unfilled_fields
   11034           43 :                && (!DECL_SIZE (constructor_unfilled_fields)
   11035           43 :                    || integer_zerop (DECL_SIZE (constructor_unfilled_fields))))
   11036            0 :           constructor_unfilled_fields = DECL_CHAIN (constructor_unfilled_fields);
   11037              : 
   11038           43 :         if (constructor_unfilled_fields
   11039              :             /* Do not warn if this level of the initializer uses member
   11040              :                designators; it is likely to be deliberate.  */
   11041           43 :             && !constructor_designated
   11042              :             /* Do not warn about initializing with { 0 } or with { }.  */
   11043           24 :             && !constructor_zeroinit)
   11044              :           {
   11045           10 :             if (warning_at (input_location, OPT_Wmissing_field_initializers,
   11046              :                             "missing initializer for field %qD of %qT",
   11047              :                             constructor_unfilled_fields,
   11048              :                             constructor_type))
   11049           10 :               inform (DECL_SOURCE_LOCATION (constructor_unfilled_fields),
   11050              :                       "%qD declared here", constructor_unfilled_fields);
   11051              :           }
   11052              :     }
   11053              : 
   11054              :   /* Pad out the end of the structure.  */
   11055      2078170 :   if (p->replacement_value.value)
   11056              :     /* If this closes a superfluous brace pair,
   11057              :        just pass out the element between them.  */
   11058          138 :     ret = p->replacement_value;
   11059      2078032 :   else if (constructor_type == NULL_TREE)
   11060              :     ;
   11061      2077935 :   else if (!RECORD_OR_UNION_TYPE_P (constructor_type)
   11062      2077935 :            && TREE_CODE (constructor_type) != ARRAY_TYPE
   11063      2077935 :            && !gnu_vector_type_p (constructor_type))
   11064              :     {
   11065              :       /* A nonincremental scalar initializer--just return
   11066              :          the element, after verifying there is just one.
   11067              :          Empty scalar initializers are supported in C23.  */
   11068          636 :       if (vec_safe_is_empty (constructor_elements))
   11069              :         {
   11070          201 :           if (constructor_erroneous || constructor_type == error_mark_node)
   11071           85 :             ret.value = error_mark_node;
   11072          116 :           else if (TREE_CODE (constructor_type) == FUNCTION_TYPE)
   11073              :             {
   11074            2 :               error_init (loc, "invalid initializer");
   11075            2 :               ret.value = error_mark_node;
   11076              :             }
   11077          114 :           else if (TREE_CODE (constructor_type) == POINTER_TYPE)
   11078              :             /* Ensure this is a null pointer constant in the case of a
   11079              :                'constexpr' object initialized with {}.  */
   11080           33 :             ret.value = build_zero_cst (ptr_type_node);
   11081              :           else
   11082           81 :             ret.value = build_zero_cst (constructor_type);
   11083              :         }
   11084          435 :       else if (vec_safe_length (constructor_elements) != 1)
   11085              :         {
   11086            0 :           error_init (loc, "extra elements in scalar initializer");
   11087            0 :           ret.value = (*constructor_elements)[0].value;
   11088              :         }
   11089              :       else
   11090          435 :         ret.value = (*constructor_elements)[0].value;
   11091              :     }
   11092              :   else
   11093              :     {
   11094      2077299 :       if (constructor_erroneous)
   11095          302 :         ret.value = error_mark_node;
   11096              :       else
   11097              :         {
   11098      2076997 :           ret.value = build_constructor (constructor_type,
   11099              :                                          constructor_elements);
   11100      2076997 :           if (constructor_constant)
   11101      1744515 :             TREE_CONSTANT (ret.value) = 1;
   11102      2076997 :           if (constructor_constant && constructor_simple)
   11103      1744476 :             TREE_STATIC (ret.value) = 1;
   11104      2076997 :           if (constructor_nonconst)
   11105          673 :             CONSTRUCTOR_NON_CONST (ret.value) = 1;
   11106      2076997 :           if (constructor_zero_padding_bits)
   11107          687 :             CONSTRUCTOR_ZERO_PADDING_BITS (ret.value) = 1;
   11108              :         }
   11109              :     }
   11110              : 
   11111      2078170 :   if (ret.value && TREE_CODE (ret.value) != CONSTRUCTOR)
   11112              :     {
   11113         1076 :       if (constructor_nonconst)
   11114           15 :         ret.original_code = C_MAYBE_CONST_EXPR;
   11115         1061 :       else if (ret.original_code == C_MAYBE_CONST_EXPR)
   11116            0 :         ret.original_code = ERROR_MARK;
   11117              :     }
   11118              : 
   11119      2078170 :   constructor_type = p->type;
   11120      2078170 :   constructor_fields = p->fields;
   11121      2078170 :   constructor_index = p->index;
   11122      2078170 :   constructor_max_index = p->max_index;
   11123      2078170 :   constructor_unfilled_index = p->unfilled_index;
   11124      2078170 :   constructor_unfilled_fields = p->unfilled_fields;
   11125      2078170 :   constructor_bit_index = p->bit_index;
   11126      2078170 :   constructor_elements = p->elements;
   11127      2078170 :   constructor_constant = p->constant;
   11128      2078170 :   constructor_simple = p->simple;
   11129      2078170 :   constructor_nonconst = p->nonconst;
   11130      2078170 :   constructor_erroneous = p->erroneous;
   11131      2078170 :   constructor_incremental = p->incremental;
   11132      2078170 :   constructor_designated = p->designated;
   11133      2078170 :   constructor_zero_padding_bits = p->zero_padding_bits;
   11134      2078170 :   constructor_braced_scalar = p->braced_scalar;
   11135      2078170 :   designator_depth = p->designator_depth;
   11136      2078170 :   constructor_pending_elts = p->pending_elts;
   11137      2078170 :   constructor_depth = p->depth;
   11138      2078170 :   if (!p->implicit)
   11139      1372847 :     constructor_range_stack = p->range_stack;
   11140      2078170 :   RESTORE_SPELLING_DEPTH (constructor_depth);
   11141              : 
   11142      2078170 :   constructor_stack = p->next;
   11143      2078170 :   XDELETE (p);
   11144              : 
   11145      2078170 :   if (ret.value == NULL_TREE && constructor_stack == 0)
   11146            0 :     ret.value = error_mark_node;
   11147      2078170 :   return ret;
   11148              : }
   11149              : 
   11150              : /* Common handling for both array range and field name designators.
   11151              :    ARRAY argument is nonzero for array ranges.  Returns false for success.  */
   11152              : 
   11153              : static bool
   11154        37206 : set_designator (location_t loc, bool array,
   11155              :                 struct obstack *braced_init_obstack)
   11156              : {
   11157        37206 :   tree subtype;
   11158        37206 :   enum tree_code subcode;
   11159              : 
   11160              :   /* Don't die if an entire brace-pair level is superfluous
   11161              :      in the containing level, or for an erroneous type.  */
   11162        37206 :   if (constructor_type == NULL_TREE || constructor_type == error_mark_node)
   11163              :     return true;
   11164              : 
   11165              :   /* If there were errors in this designator list already, bail out
   11166              :      silently.  */
   11167        37197 :   if (designator_erroneous)
   11168              :     return true;
   11169              : 
   11170              :   /* Likewise for an initializer for a variable-size type.  Those are
   11171              :      diagnosed in the parser, except for empty initializer braces.  */
   11172        37197 :   if (COMPLETE_TYPE_P (constructor_type)
   11173        37197 :       && TREE_CODE (TYPE_SIZE (constructor_type)) != INTEGER_CST)
   11174              :     return true;
   11175              : 
   11176        37187 :   if (!designator_depth)
   11177              :     {
   11178        34868 :       gcc_assert (!constructor_range_stack);
   11179              : 
   11180              :       /* Designator list starts at the level of closest explicit
   11181              :          braces.  */
   11182        36543 :       while (constructor_stack->implicit)
   11183         1675 :         process_init_element (input_location,
   11184              :                               pop_init_level (loc, 1, braced_init_obstack,
   11185              :                                               last_init_list_comma),
   11186              :                               true, braced_init_obstack);
   11187        34868 :       constructor_designated = 1;
   11188        34868 :       return false;
   11189              :     }
   11190              : 
   11191         2319 :   switch (TREE_CODE (constructor_type))
   11192              :     {
   11193         1442 :     case  RECORD_TYPE:
   11194         1442 :     case  UNION_TYPE:
   11195         1442 :       subtype = TREE_TYPE (constructor_fields);
   11196         1442 :       if (subtype != error_mark_node)
   11197         1442 :         subtype = TYPE_MAIN_VARIANT (subtype);
   11198              :       break;
   11199          877 :     case ARRAY_TYPE:
   11200          877 :       subtype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
   11201          877 :       break;
   11202            0 :     default:
   11203            0 :       gcc_unreachable ();
   11204              :     }
   11205              : 
   11206         2319 :   subcode = TREE_CODE (subtype);
   11207         2319 :   if (array && subcode != ARRAY_TYPE)
   11208              :     {
   11209            1 :       error_init (loc, "array index in non-array initializer");
   11210            1 :       return true;
   11211              :     }
   11212         2318 :   else if (!array && subcode != RECORD_TYPE && subcode != UNION_TYPE)
   11213              :     {
   11214            0 :       error_init (loc, "field name not in record or union initializer");
   11215            0 :       return true;
   11216              :     }
   11217              : 
   11218         2318 :   constructor_designated = 1;
   11219         2318 :   finish_implicit_inits (loc, braced_init_obstack);
   11220         2318 :   push_init_level (loc, 2, braced_init_obstack);
   11221         2318 :   return false;
   11222              : }
   11223              : 
   11224              : /* If there are range designators in designator list, push a new designator
   11225              :    to constructor_range_stack.  RANGE_END is end of such stack range or
   11226              :    NULL_TREE if there is no range designator at this level.  */
   11227              : 
   11228              : static void
   11229          390 : push_range_stack (tree range_end, struct obstack * braced_init_obstack)
   11230              : {
   11231          390 :   struct constructor_range_stack *p;
   11232              : 
   11233          780 :   p = (struct constructor_range_stack *)
   11234          390 :     obstack_alloc (braced_init_obstack,
   11235              :                    sizeof (struct constructor_range_stack));
   11236          390 :   p->prev = constructor_range_stack;
   11237          390 :   p->next = 0;
   11238          390 :   p->fields = constructor_fields;
   11239          390 :   p->range_start = constructor_index;
   11240          390 :   p->index = constructor_index;
   11241          390 :   p->stack = constructor_stack;
   11242          390 :   p->range_end = range_end;
   11243          390 :   if (constructor_range_stack)
   11244           19 :     constructor_range_stack->next = p;
   11245          390 :   constructor_range_stack = p;
   11246          390 : }
   11247              : 
   11248              : /* Within an array initializer, specify the next index to be initialized.
   11249              :    FIRST is that index.  If LAST is nonzero, then initialize a range
   11250              :    of indices, running from FIRST through LAST.  */
   11251              : 
   11252              : void
   11253         1936 : set_init_index (location_t loc, tree first, tree last,
   11254              :                 struct obstack *braced_init_obstack)
   11255              : {
   11256         1936 :   if (set_designator (loc, true, braced_init_obstack))
   11257              :     return;
   11258              : 
   11259         1933 :   designator_erroneous = 1;
   11260              : 
   11261         3866 :   if (!INTEGRAL_TYPE_P (TREE_TYPE (first))
   11262         3855 :       || (last && !INTEGRAL_TYPE_P (TREE_TYPE (last))))
   11263              :     {
   11264           12 :       error_init (loc, "array index in initializer not of integer type");
   11265           12 :       return;
   11266              :     }
   11267              : 
   11268         1921 :   if (TREE_CODE (first) != INTEGER_CST)
   11269              :     {
   11270            6 :       first = c_fully_fold (first, false, NULL);
   11271            6 :       if (TREE_CODE (first) == INTEGER_CST)
   11272            5 :         pedwarn_init (loc, OPT_Wpedantic,
   11273              :                       "array index in initializer is not "
   11274              :                       "an integer constant expression");
   11275              :     }
   11276              : 
   11277         1921 :   if (last && TREE_CODE (last) != INTEGER_CST)
   11278              :     {
   11279            2 :       last = c_fully_fold (last, false, NULL);
   11280            2 :       if (TREE_CODE (last) == INTEGER_CST)
   11281            1 :         pedwarn_init (loc, OPT_Wpedantic,
   11282              :                       "array index in initializer is not "
   11283              :                       "an integer constant expression");
   11284              :     }
   11285              : 
   11286         1921 :   if (TREE_CODE (first) != INTEGER_CST)
   11287            1 :     error_init (loc, "nonconstant array index in initializer");
   11288         1920 :   else if (last != NULL_TREE && TREE_CODE (last) != INTEGER_CST)
   11289            1 :     error_init (loc, "nonconstant array index in initializer");
   11290         1919 :   else if (TREE_CODE (constructor_type) != ARRAY_TYPE)
   11291            9 :     error_init (loc, "array index in non-array initializer");
   11292         1910 :   else if (tree_int_cst_sgn (first) == -1)
   11293           15 :     error_init (loc, "array index in initializer exceeds array bounds");
   11294         1895 :   else if (constructor_max_index
   11295         1895 :            && tree_int_cst_lt (constructor_max_index, first))
   11296            7 :     error_init (loc, "array index in initializer exceeds array bounds");
   11297              :   else
   11298              :     {
   11299         1888 :       constant_expression_warning (first);
   11300         1888 :       if (last)
   11301          385 :         constant_expression_warning (last);
   11302         1888 :       constructor_index = convert (bitsizetype, first);
   11303         1888 :       if (tree_int_cst_lt (constructor_index, first))
   11304              :         {
   11305            0 :           constructor_index = copy_node (constructor_index);
   11306            0 :           TREE_OVERFLOW (constructor_index) = 1;
   11307              :         }
   11308              : 
   11309         1888 :       if (last)
   11310              :         {
   11311          385 :           if (tree_int_cst_equal (first, last))
   11312              :             last = NULL_TREE;
   11313          384 :           else if (tree_int_cst_lt (last, first))
   11314              :             {
   11315            2 :               error_init (loc, "empty index range in initializer");
   11316            2 :               last = NULL_TREE;
   11317              :             }
   11318              :           else
   11319              :             {
   11320          382 :               last = convert (bitsizetype, last);
   11321          382 :               if (constructor_max_index != NULL_TREE
   11322          382 :                   && tree_int_cst_lt (constructor_max_index, last))
   11323              :                 {
   11324            3 :                   error_init (loc, "array index range in initializer exceeds "
   11325              :                               "array bounds");
   11326            3 :                   last = NULL_TREE;
   11327              :                 }
   11328              :             }
   11329              :         }
   11330              : 
   11331         1888 :       designator_depth++;
   11332         1888 :       designator_erroneous = 0;
   11333         1888 :       if (constructor_range_stack || last)
   11334          379 :         push_range_stack (last, braced_init_obstack);
   11335              :     }
   11336              : }
   11337              : 
   11338              : /* Within a struct initializer, specify the next field to be initialized.  */
   11339              : 
   11340              : void
   11341        35224 : set_init_label (location_t loc, tree fieldname, location_t fieldname_loc,
   11342              :                 struct obstack *braced_init_obstack)
   11343              : {
   11344        35224 :   tree field;
   11345              : 
   11346        35224 :   if (set_designator (loc, false, braced_init_obstack))
   11347              :     return;
   11348              : 
   11349        35207 :   designator_erroneous = 1;
   11350              : 
   11351        35207 :   if (!RECORD_OR_UNION_TYPE_P (constructor_type))
   11352              :     {
   11353            3 :       error_init (loc, "field name not in record or union initializer");
   11354            3 :       return;
   11355              :     }
   11356              : 
   11357        35204 :   field = lookup_field (constructor_type, fieldname);
   11358              : 
   11359        35204 :   if (field == NULL_TREE)
   11360              :     {
   11361            8 :       tree guessed_id = lookup_field_fuzzy (constructor_type, fieldname);
   11362            8 :       if (guessed_id)
   11363              :         {
   11364            4 :           gcc_rich_location rich_loc (fieldname_loc);
   11365            4 :           rich_loc.add_fixit_misspelled_id (fieldname_loc, guessed_id);
   11366            4 :           error_at (&rich_loc,
   11367              :                     "%qT has no member named %qE; did you mean %qE?",
   11368              :                     constructor_type, fieldname, guessed_id);
   11369            4 :         }
   11370              :       else
   11371            4 :         error_at (fieldname_loc, "%qT has no member named %qE",
   11372              :                   constructor_type, fieldname);
   11373              :     }
   11374              :   else
   11375        35242 :     do
   11376              :       {
   11377        35242 :         constructor_fields = TREE_VALUE (field);
   11378        35242 :         designator_depth++;
   11379        35242 :         designator_erroneous = 0;
   11380        35242 :         if (constructor_range_stack)
   11381           11 :           push_range_stack (NULL_TREE, braced_init_obstack);
   11382        35242 :         field = TREE_CHAIN (field);
   11383        35242 :         if (field)
   11384              :           {
   11385           46 :             if (set_designator (loc, false, braced_init_obstack))
   11386              :               return;
   11387              :           }
   11388              :       }
   11389        35242 :     while (field != NULL_TREE);
   11390              : }
   11391              : 
   11392              : /* Helper function for add_pending_init.  Find inorder successor of P
   11393              :    in AVL tree.  */
   11394              : static struct init_node *
   11395          129 : init_node_successor (struct init_node *p)
   11396              : {
   11397          129 :   struct init_node *r;
   11398          129 :   if (p->right)
   11399              :     {
   11400              :       r = p->right;
   11401           58 :       while (r->left)
   11402              :         r = r->left;
   11403              :       return r;
   11404              :     }
   11405           75 :   r = p->parent;
   11406          114 :   while (r && p == r->right)
   11407              :     {
   11408           39 :       p = r;
   11409           39 :       r = r->parent;
   11410              :     }
   11411              :   return r;
   11412              : }
   11413              : 
   11414              : /* Add a new initializer to the tree of pending initializers.  PURPOSE
   11415              :    identifies the initializer, either array index or field in a structure.
   11416              :    VALUE is the value of that index or field.  If ORIGTYPE is not
   11417              :    NULL_TREE, it is the original type of VALUE.
   11418              : 
   11419              :    IMPLICIT is true if value comes from pop_init_level (1),
   11420              :    the new initializer has been merged with the existing one
   11421              :    and thus no warnings should be emitted about overriding an
   11422              :    existing initializer.  */
   11423              : 
   11424              : static void
   11425         7989 : add_pending_init (location_t loc, tree purpose, tree value, tree origtype,
   11426              :                   bool implicit, struct obstack *braced_init_obstack)
   11427              : {
   11428         7989 :   struct init_node *p, **q, *r;
   11429              : 
   11430        12538 :   q = &constructor_pending_elts;
   11431         7989 :   p = 0;
   11432              : 
   11433         7989 :   if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   11434              :     {
   11435         7221 :       while (*q != 0)
   11436              :         {
   11437         4386 :           p = *q;
   11438         4386 :           if (tree_int_cst_lt (purpose, p->purpose))
   11439          419 :             q = &p->left;
   11440         3967 :           else if (tree_int_cst_lt (p->purpose, purpose))
   11441              :             {
   11442         3356 :               if (TREE_CODE (p->value) != RAW_DATA_CST
   11443         3356 :                   || (p->right
   11444          112 :                       && tree_int_cst_le (p->right->purpose, purpose)))
   11445         3226 :                 q = &p->right;
   11446              :               else
   11447              :                 {
   11448          130 :                   widest_int pp = wi::to_widest (p->purpose);
   11449          130 :                   widest_int pw = wi::to_widest (purpose);
   11450          130 :                   if (pp + RAW_DATA_LENGTH (p->value) <= pw)
   11451           98 :                     q = &p->right;
   11452              :                   else
   11453              :                     {
   11454              :                       /* Override which should split the old RAW_DATA_CST
   11455              :                          into 2 or 3 pieces.  */
   11456           32 :                       if (!implicit && warn_override_init)
   11457            9 :                         warning_init (loc, OPT_Woverride_init,
   11458              :                                       "initialized field overwritten");
   11459           32 :                       unsigned HOST_WIDE_INT start = (pw - pp).to_uhwi ();
   11460           32 :                       unsigned HOST_WIDE_INT len = 1;
   11461           32 :                       if (TREE_CODE (value) == RAW_DATA_CST)
   11462            0 :                         len = RAW_DATA_LENGTH (value);
   11463           32 :                       unsigned HOST_WIDE_INT end = 0;
   11464           32 :                       unsigned plen = RAW_DATA_LENGTH (p->value);
   11465           32 :                       gcc_checking_assert (start < plen && start);
   11466           32 :                       if (plen - start > len)
   11467           30 :                         end = plen - start - len;
   11468           32 :                       tree v = p->value;
   11469           32 :                       tree origtype = p->origtype;
   11470           32 :                       if (start == 1)
   11471            2 :                         p->value = build_int_cst (TREE_TYPE (v),
   11472            2 :                                                   RAW_DATA_UCHAR_ELT (v, 0));
   11473              :                       else
   11474              :                         {
   11475           30 :                           p->value = v;
   11476           30 :                           if (end > 1)
   11477           26 :                             v = copy_node (v);
   11478           30 :                           RAW_DATA_LENGTH (p->value) = start;
   11479              :                         }
   11480           32 :                       if (end)
   11481              :                         {
   11482           30 :                           tree epurpose
   11483           30 :                             = size_binop (PLUS_EXPR, purpose,
   11484              :                                           bitsize_int (len));
   11485           30 :                           if (end > 1)
   11486              :                             {
   11487           28 :                               RAW_DATA_LENGTH (v) -= plen - end;
   11488           28 :                               RAW_DATA_POINTER (v) += plen - end;
   11489              :                             }
   11490              :                           else
   11491            2 :                             v = build_int_cst (TREE_TYPE (v),
   11492            2 :                                                RAW_DATA_UCHAR_ELT (v, plen
   11493              :                                                                       - end));
   11494           30 :                           add_pending_init (loc, epurpose, v, origtype,
   11495              :                                             implicit, braced_init_obstack);
   11496              :                         }
   11497           32 :                       q = &constructor_pending_elts;
   11498           32 :                       continue;
   11499           32 :                     }
   11500          130 :                 }
   11501              :             }
   11502              :           else
   11503              :             {
   11504          611 :               if (TREE_CODE (p->value) == RAW_DATA_CST
   11505          621 :                   && (RAW_DATA_LENGTH (p->value)
   11506           10 :                       > (TREE_CODE (value) == RAW_DATA_CST
   11507           10 :                          ? RAW_DATA_LENGTH (value) : 1)))
   11508              :                 {
   11509              :                   /* Override which should split the old RAW_DATA_CST
   11510              :                      into 2 pieces.  */
   11511            6 :                   if (!implicit && warn_override_init)
   11512            3 :                     warning_init (loc, OPT_Woverride_init,
   11513              :                                   "initialized field overwritten");
   11514            6 :                   unsigned HOST_WIDE_INT len = 1;
   11515            6 :                   if (TREE_CODE (value) == RAW_DATA_CST)
   11516            2 :                     len = RAW_DATA_LENGTH (value);
   11517            6 :                   if ((unsigned) RAW_DATA_LENGTH (p->value) > len + 1)
   11518              :                     {
   11519            6 :                       RAW_DATA_LENGTH (p->value) -= len;
   11520            6 :                       RAW_DATA_POINTER (p->value) += len;
   11521              :                     }
   11522              :                   else
   11523              :                     {
   11524            0 :                       unsigned int l = RAW_DATA_LENGTH (p->value) - 1;
   11525            0 :                       p->value
   11526            0 :                         = build_int_cst (TREE_TYPE (p->value),
   11527            0 :                                          RAW_DATA_UCHAR_ELT (p->value, l));
   11528              :                     }
   11529            6 :                   p->purpose = size_binop (PLUS_EXPR, p->purpose,
   11530              :                                            bitsize_int (len));
   11531            6 :                   continue;
   11532            6 :                 }
   11533          605 :               if (TREE_CODE (value) == RAW_DATA_CST)
   11534              :                 {
   11535            8 :                 handle_raw_data:
   11536              :                   /* RAW_DATA_CST value might overlap various further
   11537              :                      prior initval entries.  Find out how many.  */
   11538           13 :                   unsigned cnt = 0;
   11539           13 :                   widest_int w
   11540           26 :                     = wi::to_widest (purpose) + RAW_DATA_LENGTH (value);
   11541           13 :                   struct init_node *r = p, *last = NULL;
   11542           13 :                   bool override_init = warn_override_init;
   11543           13 :                   while ((r = init_node_successor (r))
   11544           53 :                          && wi::to_widest (r->purpose) < w)
   11545              :                     {
   11546           40 :                       ++cnt;
   11547           40 :                       if (TREE_SIDE_EFFECTS (r->value))
   11548            2 :                         warning_init (loc, OPT_Woverride_init_side_effects,
   11549              :                                       "initialized field with side-effects "
   11550              :                                       "overwritten");
   11551           38 :                       else if (override_init)
   11552              :                         {
   11553            6 :                           warning_init (loc, OPT_Woverride_init,
   11554              :                                         "initialized field overwritten");
   11555            6 :                           override_init = false;
   11556              :                         }
   11557           40 :                       last = r;
   11558              :                     }
   11559           13 :                   if (cnt)
   11560              :                     {
   11561           26 :                       if (TREE_CODE (last->value) == RAW_DATA_CST
   11562           13 :                           && (wi::to_widest (last->purpose)
   11563           13 :                               + RAW_DATA_LENGTH (last->value) > w))
   11564              :                         {
   11565              :                           /* The last overlapping prior initval overlaps
   11566              :                              only partially.  Shrink it and decrease cnt.  */
   11567            0 :                           unsigned int l = (wi::to_widest (last->purpose)
   11568            0 :                                             + RAW_DATA_LENGTH (last->value)
   11569            0 :                                             - w).to_uhwi ();
   11570            0 :                           --cnt;
   11571            0 :                           RAW_DATA_LENGTH (last->value) -= l;
   11572            0 :                           RAW_DATA_POINTER (last->value) += l;
   11573            0 :                           if (RAW_DATA_LENGTH (last->value) == 1)
   11574            0 :                             last->value
   11575            0 :                               = build_int_cst (TREE_TYPE (last->value),
   11576            0 :                                                RAW_DATA_UCHAR_ELT (last->value,
   11577              :                                                                    0));
   11578            0 :                           last->purpose
   11579            0 :                             = size_binop (PLUS_EXPR, last->purpose,
   11580              :                                           bitsize_int (l));
   11581              :                         }
   11582              :                       /* Instead of deleting cnt nodes from the AVL tree
   11583              :                          and rebalancing, peel of last cnt bytes from the
   11584              :                          RAW_DATA_CST.  Overriding thousands of previously
   11585              :                          initialized array elements with #embed needs to work,
   11586              :                          but doesn't need to be super efficient.  */
   11587           13 :                       gcc_checking_assert ((unsigned) RAW_DATA_LENGTH (value)
   11588              :                                            > cnt);
   11589           13 :                       RAW_DATA_LENGTH (value) -= cnt;
   11590           13 :                       const unsigned char *s
   11591           13 :                         = &RAW_DATA_UCHAR_ELT (value, RAW_DATA_LENGTH (value));
   11592           13 :                       unsigned int o = RAW_DATA_LENGTH (value);
   11593           53 :                       for (r = p; cnt--; ++o, ++s)
   11594              :                         {
   11595           40 :                           r = init_node_successor (r);
   11596           40 :                           r->purpose = size_binop (PLUS_EXPR, purpose,
   11597              :                                                    bitsize_int (o));
   11598           40 :                           r->value = build_int_cst (TREE_TYPE (value), *s);
   11599           40 :                           r->origtype = origtype;
   11600              :                         }
   11601           13 :                       if (RAW_DATA_LENGTH (value) == 1)
   11602            0 :                         value = build_int_cst (TREE_TYPE (value),
   11603            0 :                                                RAW_DATA_UCHAR_ELT (value, 0));
   11604              :                     }
   11605              :                 }
   11606          610 :               if (!implicit)
   11607              :                 {
   11608           54 :                   if (TREE_SIDE_EFFECTS (p->value))
   11609            6 :                     warning_init (loc, OPT_Woverride_init_side_effects,
   11610              :                                   "initialized field with side-effects "
   11611              :                                   "overwritten");
   11612           48 :                   else if (warn_override_init)
   11613           13 :                     warning_init (loc, OPT_Woverride_init,
   11614              :                                   "initialized field overwritten");
   11615              :                 }
   11616          610 :               p->value = value;
   11617          610 :               p->origtype = origtype;
   11618          610 :               return;
   11619              :             }
   11620              :         }
   11621         2835 :       if (TREE_CODE (value) == RAW_DATA_CST && p)
   11622              :         {
   11623           61 :           struct init_node *r;
   11624           61 :           if (q == &p->left)
   11625              :             r = p;
   11626              :           else
   11627           36 :             r = init_node_successor (p);
   11628          131 :           if (r && wi::to_widest (r->purpose) < (wi::to_widest (purpose)
   11629          131 :                                                  + RAW_DATA_LENGTH (value)))
   11630              :             {
   11631              :               /* Overlap with at least one prior initval in the range but
   11632              :                  not at the start.  */
   11633            5 :               p = r;
   11634            5 :               p->purpose = purpose;
   11635            5 :               goto handle_raw_data;
   11636              :             }
   11637              :         }
   11638              :     }
   11639              :   else
   11640              :     {
   11641         4549 :       tree bitpos;
   11642              : 
   11643         4549 :       bitpos = bit_position (purpose);
   11644         8187 :       while (*q != NULL)
   11645              :         {
   11646         4881 :           p = *q;
   11647         4881 :           if (tree_int_cst_lt (bitpos, bit_position (p->purpose)))
   11648           81 :             q = &p->left;
   11649         4800 :           else if (p->purpose != purpose)
   11650         3557 :             q = &p->right;
   11651              :           else
   11652              :             {
   11653         1243 :               if (!implicit)
   11654              :                 {
   11655          101 :                   if (TREE_SIDE_EFFECTS (p->value))
   11656            4 :                     warning_init (loc, OPT_Woverride_init_side_effects,
   11657              :                                   "initialized field with side-effects "
   11658              :                                   "overwritten");
   11659           97 :                   else if (warn_override_init)
   11660            6 :                     warning_init (loc, OPT_Woverride_init,
   11661              :                                   "initialized field overwritten");
   11662              :                 }
   11663         1243 :               p->value = value;
   11664         1243 :               p->origtype = origtype;
   11665         1243 :               return;
   11666              :             }
   11667              :         }
   11668              :     }
   11669              : 
   11670         6136 :   r = (struct init_node *) obstack_alloc (braced_init_obstack,
   11671              :                                           sizeof (struct init_node));
   11672         6136 :   r->purpose = purpose;
   11673         6136 :   r->value = value;
   11674         6136 :   r->origtype = origtype;
   11675              : 
   11676         6136 :   *q = r;
   11677         6136 :   r->parent = p;
   11678         6136 :   r->left = 0;
   11679         6136 :   r->right = 0;
   11680         6136 :   r->balance = 0;
   11681              : 
   11682         9962 :   while (p)
   11683              :     {
   11684         5214 :       struct init_node *s;
   11685              : 
   11686         5214 :       if (r == p->left)
   11687              :         {
   11688          343 :           if (p->balance == 0)
   11689          246 :             p->balance = -1;
   11690           97 :           else if (p->balance < 0)
   11691              :             {
   11692           45 :               if (r->balance < 0)
   11693              :                 {
   11694              :                   /* L rotation.  */
   11695           40 :                   p->left = r->right;
   11696           40 :                   if (p->left)
   11697            2 :                     p->left->parent = p;
   11698           40 :                   r->right = p;
   11699              : 
   11700           40 :                   p->balance = 0;
   11701           40 :                   r->balance = 0;
   11702              : 
   11703           40 :                   s = p->parent;
   11704           40 :                   p->parent = r;
   11705           40 :                   r->parent = s;
   11706           40 :                   if (s)
   11707              :                     {
   11708           31 :                       if (s->left == p)
   11709           10 :                         s->left = r;
   11710              :                       else
   11711           21 :                         s->right = r;
   11712              :                     }
   11713              :                   else
   11714            9 :                     constructor_pending_elts = r;
   11715              :                 }
   11716              :               else
   11717              :                 {
   11718              :                   /* LR rotation.  */
   11719            5 :                   struct init_node *t = r->right;
   11720              : 
   11721            5 :                   r->right = t->left;
   11722            5 :                   if (r->right)
   11723            0 :                     r->right->parent = r;
   11724            5 :                   t->left = r;
   11725              : 
   11726            5 :                   p->left = t->right;
   11727            5 :                   if (p->left)
   11728            0 :                     p->left->parent = p;
   11729            5 :                   t->right = p;
   11730              : 
   11731            5 :                   p->balance = t->balance < 0;
   11732            5 :                   r->balance = -(t->balance > 0);
   11733            5 :                   t->balance = 0;
   11734              : 
   11735            5 :                   s = p->parent;
   11736            5 :                   p->parent = t;
   11737            5 :                   r->parent = t;
   11738            5 :                   t->parent = s;
   11739            5 :                   if (s)
   11740              :                     {
   11741            0 :                       if (s->left == p)
   11742            0 :                         s->left = t;
   11743              :                       else
   11744            0 :                         s->right = t;
   11745              :                     }
   11746              :                   else
   11747            5 :                     constructor_pending_elts = t;
   11748              :                 }
   11749              :               break;
   11750              :             }
   11751              :           else
   11752              :             {
   11753              :               /* p->balance == +1; growth of left side balances the node.  */
   11754           52 :               p->balance = 0;
   11755           52 :               break;
   11756              :             }
   11757              :         }
   11758              :       else /* r == p->right */
   11759              :         {
   11760         4871 :           if (p->balance == 0)
   11761              :             /* Growth propagation from right side.  */
   11762         3580 :             p->balance++;
   11763         1291 :           else if (p->balance > 0)
   11764              :             {
   11765         1228 :               if (r->balance > 0)
   11766              :                 {
   11767              :                   /* R rotation.  */
   11768         1222 :                   p->right = r->left;
   11769         1222 :                   if (p->right)
   11770          193 :                     p->right->parent = p;
   11771         1222 :                   r->left = p;
   11772              : 
   11773         1222 :                   p->balance = 0;
   11774         1222 :                   r->balance = 0;
   11775              : 
   11776         1222 :                   s = p->parent;
   11777         1222 :                   p->parent = r;
   11778         1222 :                   r->parent = s;
   11779         1222 :                   if (s)
   11780              :                     {
   11781          414 :                       if (s->left == p)
   11782            2 :                         s->left = r;
   11783              :                       else
   11784          412 :                         s->right = r;
   11785              :                     }
   11786              :                   else
   11787          808 :                     constructor_pending_elts = r;
   11788              :                 }
   11789              :               else /* r->balance == -1 */
   11790              :                 {
   11791              :                   /* RL rotation */
   11792            6 :                   struct init_node *t = r->left;
   11793              : 
   11794            6 :                   r->left = t->right;
   11795            6 :                   if (r->left)
   11796            2 :                     r->left->parent = r;
   11797            6 :                   t->right = r;
   11798              : 
   11799            6 :                   p->right = t->left;
   11800            6 :                   if (p->right)
   11801            2 :                     p->right->parent = p;
   11802            6 :                   t->left = p;
   11803              : 
   11804            6 :                   r->balance = (t->balance < 0);
   11805            6 :                   p->balance = -(t->balance > 0);
   11806            6 :                   t->balance = 0;
   11807              : 
   11808            6 :                   s = p->parent;
   11809            6 :                   p->parent = t;
   11810            6 :                   r->parent = t;
   11811            6 :                   t->parent = s;
   11812            6 :                   if (s)
   11813              :                     {
   11814            4 :                       if (s->left == p)
   11815            0 :                         s->left = t;
   11816              :                       else
   11817            4 :                         s->right = t;
   11818              :                     }
   11819              :                   else
   11820            2 :                     constructor_pending_elts = t;
   11821              :                 }
   11822              :               break;
   11823              :             }
   11824              :           else
   11825              :             {
   11826              :               /* p->balance == -1; growth of right side balances the node.  */
   11827           63 :               p->balance = 0;
   11828           63 :               break;
   11829              :             }
   11830              :         }
   11831              : 
   11832         3826 :       r = p;
   11833         3826 :       p = p->parent;
   11834              :     }
   11835              : }
   11836              : 
   11837              : /* Build AVL tree from a sorted chain.  */
   11838              : 
   11839              : static void
   11840         1812 : set_nonincremental_init (struct obstack * braced_init_obstack)
   11841              : {
   11842         1812 :   unsigned HOST_WIDE_INT ix;
   11843         1812 :   tree index, value;
   11844              : 
   11845         1812 :   if (TREE_CODE (constructor_type) != RECORD_TYPE
   11846         1812 :       && TREE_CODE (constructor_type) != ARRAY_TYPE)
   11847              :     return;
   11848              : 
   11849         5511 :   FOR_EACH_CONSTRUCTOR_ELT (constructor_elements, ix, index, value)
   11850         3699 :     add_pending_init (input_location, index, value, NULL_TREE, true,
   11851              :                       braced_init_obstack);
   11852         1812 :   constructor_elements = NULL;
   11853         1812 :   if (TREE_CODE (constructor_type) == RECORD_TYPE)
   11854              :     {
   11855          948 :       constructor_unfilled_fields = TYPE_FIELDS (constructor_type);
   11856              :       /* Skip any nameless bit fields at the beginning.  */
   11857          948 :       while (constructor_unfilled_fields != NULL_TREE
   11858          948 :              && DECL_UNNAMED_BIT_FIELD (constructor_unfilled_fields))
   11859            0 :         constructor_unfilled_fields = TREE_CHAIN (constructor_unfilled_fields);
   11860              : 
   11861              :     }
   11862          864 :   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   11863              :     {
   11864          864 :       if (TYPE_DOMAIN (constructor_type))
   11865          806 :         constructor_unfilled_index
   11866          806 :           = convert (bitsizetype,
   11867          806 :                      TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
   11868              :       else
   11869           58 :         constructor_unfilled_index = bitsize_zero_node;
   11870              :     }
   11871         1812 :   constructor_incremental = 0;
   11872              : }
   11873              : 
   11874              : /* Build AVL tree from a string constant.  */
   11875              : 
   11876              : static void
   11877            7 : set_nonincremental_init_from_string (tree str,
   11878              :                                      struct obstack * braced_init_obstack)
   11879              : {
   11880            7 :   tree value, purpose, type;
   11881            7 :   HOST_WIDE_INT val[2];
   11882            7 :   const char *p, *end;
   11883            7 :   int byte, wchar_bytes, charwidth, bitpos;
   11884              : 
   11885            7 :   gcc_assert (TREE_CODE (constructor_type) == ARRAY_TYPE);
   11886              : 
   11887            7 :   wchar_bytes = TYPE_PRECISION (TREE_TYPE (TREE_TYPE (str))) / BITS_PER_UNIT;
   11888            7 :   charwidth = TYPE_PRECISION (char_type_node);
   11889            7 :   gcc_assert ((size_t) wchar_bytes * charwidth
   11890              :               <= ARRAY_SIZE (val) * HOST_BITS_PER_WIDE_INT);
   11891            7 :   type = TREE_TYPE (constructor_type);
   11892            7 :   p = TREE_STRING_POINTER (str);
   11893            7 :   end = p + TREE_STRING_LENGTH (str);
   11894              : 
   11895            7 :   for (purpose = bitsize_zero_node;
   11896              :        p < end
   11897           52 :        && !(constructor_max_index
   11898           20 :             && tree_int_cst_lt (constructor_max_index, purpose));
   11899           25 :        purpose = size_binop (PLUS_EXPR, purpose, bitsize_one_node))
   11900              :     {
   11901           25 :       if (wchar_bytes == 1)
   11902              :         {
   11903            9 :           val[0] = (unsigned char) *p++;
   11904            9 :           val[1] = 0;
   11905              :         }
   11906              :       else
   11907              :         {
   11908           16 :           val[1] = 0;
   11909           16 :           val[0] = 0;
   11910           64 :           for (byte = 0; byte < wchar_bytes; byte++)
   11911              :             {
   11912           48 :               if (BYTES_BIG_ENDIAN)
   11913              :                 bitpos = (wchar_bytes - byte - 1) * charwidth;
   11914              :               else
   11915           48 :                 bitpos = byte * charwidth;
   11916           48 :               val[bitpos / HOST_BITS_PER_WIDE_INT]
   11917           48 :                 |= ((unsigned HOST_WIDE_INT) ((unsigned char) *p++))
   11918           48 :                    << (bitpos % HOST_BITS_PER_WIDE_INT);
   11919              :             }
   11920              :         }
   11921              : 
   11922           25 :       if (!TYPE_UNSIGNED (type))
   11923              :         {
   11924           13 :           bitpos = ((wchar_bytes - 1) * charwidth) + HOST_BITS_PER_CHAR;
   11925           13 :           if (bitpos < HOST_BITS_PER_WIDE_INT)
   11926              :             {
   11927           13 :               if (val[0] & (HOST_WIDE_INT_1 << (bitpos - 1)))
   11928              :                 {
   11929            0 :                   val[0] |= HOST_WIDE_INT_M1U << bitpos;
   11930            0 :                   val[1] = -1;
   11931              :                 }
   11932              :             }
   11933            0 :           else if (bitpos == HOST_BITS_PER_WIDE_INT)
   11934              :             {
   11935            0 :               if (val[0] < 0)
   11936            0 :                 val[1] = -1;
   11937              :             }
   11938            0 :           else if (val[1] & (HOST_WIDE_INT_1
   11939            0 :                              << (bitpos - 1 - HOST_BITS_PER_WIDE_INT)))
   11940            0 :             val[1] |= HOST_WIDE_INT_M1U << (bitpos - HOST_BITS_PER_WIDE_INT);
   11941              :         }
   11942              : 
   11943           25 :       value = wide_int_to_tree (type,
   11944           25 :                                 wide_int::from_array (val, 2,
   11945              :                                                       HOST_BITS_PER_WIDE_INT * 2));
   11946           25 :       add_pending_init (input_location, purpose, value, NULL_TREE, true,
   11947              :                         braced_init_obstack);
   11948              :     }
   11949              : 
   11950            7 :   constructor_incremental = 0;
   11951            7 : }
   11952              : 
   11953              : /* Return value of FIELD in pending initializer or NULL_TREE if the field was
   11954              :    not initialized yet.  */
   11955              : 
   11956              : static tree
   11957       705323 : find_init_member (tree field, struct obstack * braced_init_obstack)
   11958              : {
   11959       705323 :   struct init_node *p;
   11960              : 
   11961       705323 :   if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   11962              :     {
   11963       703504 :       if (constructor_incremental
   11964       703504 :           && tree_int_cst_lt (field, constructor_unfilled_index))
   11965           16 :         set_nonincremental_init (braced_init_obstack);
   11966              : 
   11967       703504 :       p = constructor_pending_elts;
   11968       704103 :       while (p)
   11969              :         {
   11970         1151 :           if (tree_int_cst_lt (field, p->purpose))
   11971           93 :             p = p->left;
   11972         1058 :           else if (tree_int_cst_lt (p->purpose, field))
   11973          506 :             p = p->right;
   11974              :           else
   11975          552 :             return p->value;
   11976              :         }
   11977              :     }
   11978         1819 :   else if (TREE_CODE (constructor_type) == RECORD_TYPE)
   11979              :     {
   11980         1696 :       tree bitpos = bit_position (field);
   11981              : 
   11982         1696 :       if (constructor_incremental
   11983         1696 :           && (!constructor_unfilled_fields
   11984          609 :               || tree_int_cst_lt (bitpos,
   11985          609 :                                   bit_position (constructor_unfilled_fields))))
   11986          289 :         set_nonincremental_init (braced_init_obstack);
   11987              : 
   11988         1696 :       p = constructor_pending_elts;
   11989         2652 :       while (p)
   11990              :         {
   11991         2047 :           if (field == p->purpose)
   11992         1091 :             return p->value;
   11993          956 :           else if (tree_int_cst_lt (bitpos, bit_position (p->purpose)))
   11994            7 :             p = p->left;
   11995              :           else
   11996          949 :             p = p->right;
   11997              :         }
   11998              :     }
   11999          123 :   else if (TREE_CODE (constructor_type) == UNION_TYPE)
   12000              :     {
   12001          123 :       if (!vec_safe_is_empty (constructor_elements)
   12002           50 :           && (constructor_elements->last ().index == field))
   12003           50 :         return constructor_elements->last ().value;
   12004              :     }
   12005              :   return NULL_TREE;
   12006              : }
   12007              : 
   12008              : /* "Output" the next constructor element.
   12009              :    At top level, really output it to assembler code now.
   12010              :    Otherwise, collect it in a list from which we will make a CONSTRUCTOR.
   12011              :    If ORIGTYPE is not NULL_TREE, it is the original type of VALUE.
   12012              :    TYPE is the data type that the containing data type wants here.
   12013              :    FIELD is the field (a FIELD_DECL) or the index that this element fills.
   12014              :    If VALUE is a string constant, STRICT_STRING is true if it is
   12015              :    unparenthesized or we should not warn here for it being parenthesized.
   12016              :    For other types of VALUE, STRICT_STRING is not used.
   12017              : 
   12018              :    PENDING if true means output pending elements that belong
   12019              :    right after this element.  (PENDING is normally true;
   12020              :    it is false while outputting pending elements, to avoid recursion.)
   12021              : 
   12022              :    IMPLICIT is true if value comes from pop_init_level (1),
   12023              :    the new initializer has been merged with the existing one
   12024              :    and thus no warnings should be emitted about overriding an
   12025              :    existing initializer.  */
   12026              : 
   12027              : static void
   12028      9683504 : output_init_element (location_t loc, tree value, tree origtype,
   12029              :                      bool strict_string, tree type, tree field, bool pending,
   12030              :                      bool implicit, struct obstack * braced_init_obstack)
   12031              : {
   12032      9683504 :   tree semantic_type = NULL_TREE;
   12033      9683504 :   bool maybe_const = true;
   12034      9683504 :   bool npc, int_const_expr, arith_const_expr;
   12035              : 
   12036      9683504 :   if (type == error_mark_node || value == error_mark_node)
   12037              :     {
   12038          274 :       constructor_erroneous = 1;
   12039         4613 :       return;
   12040              :     }
   12041      9683230 :   if (TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
   12042       201021 :       && (TREE_CODE (value) == STRING_CST
   12043       159590 :           || TREE_CODE (value) == COMPOUND_LITERAL_EXPR)
   12044        41439 :       && !(TREE_CODE (value) == STRING_CST
   12045        41431 :            && TREE_CODE (type) == ARRAY_TYPE
   12046         3898 :            && INTEGRAL_TYPE_P (TREE_TYPE (type)))
   12047      9720771 :       && !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (value)),
   12048        37541 :                      TYPE_MAIN_VARIANT (type)))
   12049        37541 :     value = array_to_pointer_conversion (input_location, value);
   12050              : 
   12051      9683230 :   if (TREE_CODE (value) == COMPOUND_LITERAL_EXPR
   12052          182 :       && require_constant_value && pending)
   12053              :     {
   12054              :       /* As an extension, allow initializing objects with static storage
   12055              :          duration with compound literals (which are then treated just as
   12056              :          the brace enclosed list they contain).  */
   12057          114 :       if (flag_isoc99)
   12058           24 :         pedwarn_init (loc, OPT_Wpedantic, "initializer element is not "
   12059              :                       "constant");
   12060          114 :       tree decl = COMPOUND_LITERAL_EXPR_DECL (value);
   12061          114 :       value = DECL_INITIAL (decl);
   12062              :     }
   12063              : 
   12064      9683230 :   npc = null_pointer_constant_p (value);
   12065     19366460 :   int_const_expr = (TREE_CODE (value) == INTEGER_CST
   12066      4250474 :                     && !TREE_OVERFLOW (value)
   12067     13933703 :                     && INTEGRAL_TYPE_P (TREE_TYPE (value)));
   12068              :   /* Not fully determined before folding.  */
   12069      9683230 :   arith_const_expr = true;
   12070      9683230 :   if (TREE_CODE (value) == EXCESS_PRECISION_EXPR)
   12071              :     {
   12072           16 :       semantic_type = TREE_TYPE (value);
   12073           16 :       value = TREE_OPERAND (value, 0);
   12074              :     }
   12075      9683230 :   value = c_fully_fold (value, require_constant_value, &maybe_const);
   12076              :   /* TODO: this may not detect all cases of expressions folding to
   12077              :      constants that are not arithmetic constant expressions.  */
   12078      9683230 :   if (!maybe_const)
   12079              :     arith_const_expr = false;
   12080     19363919 :   else if (!INTEGRAL_TYPE_P (TREE_TYPE (value))
   12081      3198487 :            && TREE_CODE (TREE_TYPE (value)) != REAL_TYPE
   12082     11528458 :            && TREE_CODE (TREE_TYPE (value)) != COMPLEX_TYPE)
   12083              :     arith_const_expr = false;
   12084      7850855 :   else if (TREE_CODE (value) != INTEGER_CST
   12085              :            && TREE_CODE (value) != REAL_CST
   12086              :            && TREE_CODE (value) != COMPLEX_CST
   12087              :            && TREE_CODE (value) != RAW_DATA_CST)
   12088              :     arith_const_expr = false;
   12089      4642151 :   else if (TREE_OVERFLOW (value))
   12090      5041080 :     arith_const_expr = false;
   12091              : 
   12092      9683230 :   if (value == error_mark_node)
   12093            0 :     constructor_erroneous = 1;
   12094      9683230 :   else if (!TREE_CONSTANT (value))
   12095      3229250 :     constructor_constant = 0;
   12096      6453980 :   else if (!initializer_constant_valid_p (value,
   12097      6453980 :                                           TREE_TYPE (value),
   12098      6453980 :                                           AGGREGATE_TYPE_P (constructor_type)
   12099      2767464 :                                           && TYPE_REVERSE_STORAGE_ORDER
   12100              :                                              (constructor_type))
   12101      6453980 :            || (RECORD_OR_UNION_TYPE_P (constructor_type)
   12102      1041940 :                && DECL_C_BIT_FIELD (field)
   12103         7978 :                && TREE_CODE (value) != INTEGER_CST))
   12104           77 :     constructor_simple = 0;
   12105      9683230 :   if (!maybe_const)
   12106         1174 :     constructor_nonconst = 1;
   12107              : 
   12108              :   /* Digest the initializer and issue any errors about incompatible
   12109              :      types before issuing errors about non-constant initializers.  */
   12110      9683230 :   tree new_value = value;
   12111      9683230 :   if (semantic_type)
   12112           16 :     new_value = build1 (EXCESS_PRECISION_EXPR, semantic_type, value);
   12113              :   /* In the case of braces around a scalar initializer, the result of
   12114              :      this initializer processing goes through digest_init again at the
   12115              :      outer level.  In the case of a constexpr initializer for a
   12116              :      pointer, avoid converting a null pointer constant to something
   12117              :      that is not a null pointer constant to avoid a spurious error
   12118              :      from that second processing.  */
   12119      9683230 :   if (!require_constexpr_value
   12120          398 :       || !npc
   12121           69 :       || TREE_CODE (constructor_type) != POINTER_TYPE)
   12122      9683219 :     new_value = digest_init (loc,
   12123      9683219 :                              RECORD_OR_UNION_TYPE_P (constructor_type)
   12124      8608025 :                              ? field : constructor_fields
   12125      8608025 :                              ? constructor_fields : constructor_decl,
   12126              :                              type, new_value, origtype, npc,
   12127              :                              int_const_expr, arith_const_expr, strict_string,
   12128              :                              require_constant_value, require_constexpr_value);
   12129      9683230 :   if (new_value == error_mark_node)
   12130              :     {
   12131           76 :       constructor_erroneous = 1;
   12132           76 :       return;
   12133              :     }
   12134      9683154 :   if (require_constant_value || require_constant_elements)
   12135      2721995 :     constant_expression_warning (new_value);
   12136              : 
   12137              :   /* Proceed to check the constness of the original initializer.  */
   12138      9683154 :   if (!initializer_constant_valid_p (value, TREE_TYPE (value)))
   12139              :     {
   12140      3229276 :       if (require_constant_value)
   12141              :         {
   12142            0 :           error_init (loc, "initializer element is not constant");
   12143            0 :           value = error_mark_node;
   12144              :         }
   12145      3229276 :       else if (require_constant_elements)
   12146           21 :         pedwarn (loc, OPT_Wpedantic,
   12147              :                  "initializer element is not computable at load time");
   12148              :     }
   12149      6453878 :   else if (!maybe_const
   12150           54 :            && (require_constant_value || require_constant_elements))
   12151           28 :     pedwarn_init (loc, OPT_Wpedantic,
   12152              :                   "initializer element is not a constant expression");
   12153              :   /* digest_init has already carried out the additional checks
   12154              :      required for 'constexpr' initializers (using the information
   12155              :      passed to it about whether the original initializer was certain
   12156              :      kinds of constant expression), so that check does not need to be
   12157              :      repeated here.  */
   12158              : 
   12159              :   /* Issue -Wc++-compat warnings about initializing a bitfield with
   12160              :      enum type.  */
   12161      9683154 :   if (warn_cxx_compat
   12162         6900 :       && field != NULL_TREE
   12163         6900 :       && TREE_CODE (field) == FIELD_DECL
   12164          464 :       && DECL_BIT_FIELD_TYPE (field) != NULL_TREE
   12165           21 :       && (TYPE_MAIN_VARIANT (DECL_BIT_FIELD_TYPE (field))
   12166           21 :           != TYPE_MAIN_VARIANT (type))
   12167      9683175 :       && TREE_CODE (DECL_BIT_FIELD_TYPE (field)) == ENUMERAL_TYPE)
   12168              :     {
   12169           21 :       tree checktype = origtype != NULL_TREE ? origtype : TREE_TYPE (value);
   12170           21 :       if (checktype != error_mark_node
   12171           21 :           && (TYPE_MAIN_VARIANT (checktype)
   12172           21 :               != TYPE_MAIN_VARIANT (DECL_BIT_FIELD_TYPE (field))))
   12173            9 :         warning_init (loc, OPT_Wc___compat,
   12174              :                       "enum conversion in initialization is invalid in C++");
   12175              :     }
   12176              : 
   12177              :   /* If this field is empty and does not have side effects (and is not at
   12178              :      the end of structure), don't do anything other than checking the
   12179              :      initializer.  */
   12180      9683154 :   if (field
   12181      9683154 :       && (TREE_TYPE (field) == error_mark_node
   12182      9682719 :           || (COMPLETE_TYPE_P (TREE_TYPE (field))
   12183      9682410 :               && integer_zerop (TYPE_SIZE (TREE_TYPE (field)))
   12184           92 :               && !TREE_SIDE_EFFECTS (new_value)
   12185           63 :               && (TREE_CODE (constructor_type) == ARRAY_TYPE
   12186           63 :                   || DECL_CHAIN (field)))))
   12187              :     return;
   12188              : 
   12189              :   /* Finally, set VALUE to the initializer value digested above.  */
   12190      9683126 :   value = new_value;
   12191              : 
   12192              :   /* If this element doesn't come next in sequence,
   12193              :      put it on constructor_pending_elts.  */
   12194      9683126 :   if (TREE_CODE (constructor_type) == ARRAY_TYPE
   12195      9683126 :       && (!constructor_incremental
   12196      1728713 :           || !tree_int_cst_equal (field, constructor_unfilled_index)
   12197      1728274 :           || (TREE_CODE (value) == RAW_DATA_CST
   12198          235 :               && constructor_pending_elts
   12199           66 :               && pending)))
   12200              :     {
   12201         1346 :       if (constructor_incremental
   12202         1346 :           && (tree_int_cst_lt (field, constructor_unfilled_index)
   12203          410 :               || (TREE_CODE (value) == RAW_DATA_CST
   12204           14 :                   && constructor_pending_elts
   12205           14 :                   && pending)))
   12206           48 :         set_nonincremental_init (braced_init_obstack);
   12207              : 
   12208         1346 :       add_pending_init (loc, field, value, origtype, implicit,
   12209              :                         braced_init_obstack);
   12210         1346 :       return;
   12211              :     }
   12212      9681780 :   else if (TREE_CODE (constructor_type) == RECORD_TYPE
   12213      1043654 :            && (!constructor_incremental
   12214      1041988 :                || field != constructor_unfilled_fields))
   12215              :     {
   12216              :       /* We do this for records but not for unions.  In a union,
   12217              :          no matter which field is specified, it can be initialized
   12218              :          right away since it starts at the beginning of the union.  */
   12219         2889 :       if (constructor_incremental)
   12220              :         {
   12221         1223 :           if (!constructor_unfilled_fields)
   12222           39 :             set_nonincremental_init (braced_init_obstack);
   12223              :           else
   12224              :             {
   12225         1184 :               tree bitpos, unfillpos;
   12226              : 
   12227         1184 :               bitpos = bit_position (field);
   12228         1184 :               unfillpos = bit_position (constructor_unfilled_fields);
   12229              : 
   12230         1184 :               if (tree_int_cst_lt (bitpos, unfillpos))
   12231            4 :                 set_nonincremental_init (braced_init_obstack);
   12232              :             }
   12233              :         }
   12234              : 
   12235         2889 :       add_pending_init (loc, field, value, origtype, implicit,
   12236              :                         braced_init_obstack);
   12237         2889 :       return;
   12238              :     }
   12239      9678891 :   else if (TREE_CODE (constructor_type) == UNION_TYPE
   12240      9678891 :            && !vec_safe_is_empty (constructor_elements))
   12241              :     {
   12242           62 :       if (!implicit)
   12243              :         {
   12244           12 :           if (TREE_SIDE_EFFECTS (constructor_elements->last ().value))
   12245            3 :             warning_init (loc, OPT_Woverride_init_side_effects,
   12246              :                           "initialized field with side-effects overwritten");
   12247            9 :           else if (warn_override_init)
   12248            6 :             warning_init (loc, OPT_Woverride_init,
   12249              :                           "initialized field overwritten");
   12250              :         }
   12251              : 
   12252              :       /* We can have just one union field set.  */
   12253           62 :       constructor_elements = NULL;
   12254              :     }
   12255              : 
   12256              :   /* Otherwise, output this element either to
   12257              :      constructor_elements or to the assembler file.  */
   12258              : 
   12259      9678891 :   constructor_elt celt = {field, value};
   12260      9678891 :   vec_safe_push (constructor_elements, celt);
   12261              : 
   12262              :   /* Advance the variable that indicates sequential elements output.  */
   12263      9678891 :   if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   12264              :     {
   12265      1728269 :       tree inc = bitsize_one_node;
   12266      1728269 :       if (value && TREE_CODE (value) == RAW_DATA_CST)
   12267          230 :         inc = bitsize_int (RAW_DATA_LENGTH (value));
   12268      1728269 :       constructor_unfilled_index
   12269      1728269 :         = size_binop_loc (input_location, PLUS_EXPR,
   12270              :                           constructor_unfilled_index, inc);
   12271              :     }
   12272      7950622 :   else if (TREE_CODE (constructor_type) == RECORD_TYPE)
   12273              :     {
   12274      1040765 :       constructor_unfilled_fields
   12275      1040765 :         = DECL_CHAIN (constructor_unfilled_fields);
   12276              : 
   12277              :       /* Skip any nameless bit fields.  */
   12278      1040765 :       while (constructor_unfilled_fields != NULL_TREE
   12279      1040866 :              && DECL_UNNAMED_BIT_FIELD (constructor_unfilled_fields))
   12280          101 :         constructor_unfilled_fields
   12281          101 :           = DECL_CHAIN (constructor_unfilled_fields);
   12282              :     }
   12283      6909857 :   else if (TREE_CODE (constructor_type) == UNION_TYPE)
   12284        31498 :     constructor_unfilled_fields = NULL_TREE;
   12285              : 
   12286              :   /* Now output any pending elements which have become next.  */
   12287      9678891 :   if (pending)
   12288      9672700 :     output_pending_init_elements (0, braced_init_obstack);
   12289              : }
   12290              : 
   12291              : /* For two FIELD_DECLs in the same chain, return -1 if field1
   12292              :    comes before field2, 1 if field1 comes after field2 and
   12293              :    0 if field1 == field2.  */
   12294              : 
   12295              : static int
   12296         7104 : init_field_decl_cmp (tree field1, tree field2)
   12297              : {
   12298         7104 :   if (field1 == field2)
   12299              :     return 0;
   12300              : 
   12301         3342 :   tree bitpos1 = bit_position (field1);
   12302         3342 :   tree bitpos2 = bit_position (field2);
   12303         3342 :   if (tree_int_cst_equal (bitpos1, bitpos2))
   12304              :     {
   12305              :       /* If one of the fields has non-zero bitsize, then that
   12306              :          field must be the last one in a sequence of zero
   12307              :          sized fields, fields after it will have bigger
   12308              :          bit_position.  */
   12309           32 :       if (TREE_TYPE (field1) != error_mark_node
   12310           32 :           && COMPLETE_TYPE_P (TREE_TYPE (field1))
   12311           64 :           && integer_nonzerop (TREE_TYPE (field1)))
   12312              :         return 1;
   12313           32 :       if (TREE_TYPE (field2) != error_mark_node
   12314           32 :           && COMPLETE_TYPE_P (TREE_TYPE (field2))
   12315           57 :           && integer_nonzerop (TREE_TYPE (field2)))
   12316              :         return -1;
   12317              :       /* Otherwise, fallback to DECL_CHAIN walk to find out
   12318              :          which field comes earlier.  Walk chains of both
   12319              :          fields, so that if field1 and field2 are close to each
   12320              :          other in either order, it is found soon even for large
   12321              :          sequences of zero sized fields.  */
   12322              :       tree f1 = field1, f2 = field2;
   12323           32 :       while (1)
   12324              :         {
   12325           32 :           f1 = DECL_CHAIN (f1);
   12326           32 :           f2 = DECL_CHAIN (f2);
   12327           32 :           if (f1 == NULL_TREE)
   12328              :             {
   12329            7 :               gcc_assert (f2);
   12330              :               return 1;
   12331              :             }
   12332           25 :           if (f2 == NULL_TREE)
   12333              :             return -1;
   12334            9 :           if (f1 == field2)
   12335              :             return -1;
   12336            0 :           if (f2 == field1)
   12337              :             return 1;
   12338            0 :           if (!tree_int_cst_equal (bit_position (f1), bitpos1))
   12339              :             return 1;
   12340            0 :           if (!tree_int_cst_equal (bit_position (f2), bitpos1))
   12341              :             return -1;
   12342              :         }
   12343              :     }
   12344         3310 :   else if (tree_int_cst_lt (bitpos1, bitpos2))
   12345              :     return -1;
   12346              :   else
   12347         1948 :     return 1;
   12348              : }
   12349              : 
   12350              : /* Output any pending elements which have become next.
   12351              :    As we output elements, constructor_unfilled_{fields,index}
   12352              :    advances, which may cause other elements to become next;
   12353              :    if so, they too are output.
   12354              : 
   12355              :    If ALL is 0, we return when there are
   12356              :    no more pending elements to output now.
   12357              : 
   12358              :    If ALL is 1, we output space as necessary so that
   12359              :    we can output all the pending elements.  */
   12360              : static void
   12361     11750870 : output_pending_init_elements (int all, struct obstack * braced_init_obstack)
   12362              : {
   12363     11750870 :   struct init_node *elt = constructor_pending_elts;
   12364     11752037 :   tree next;
   12365              : 
   12366     11752037 :  retry:
   12367              : 
   12368              :   /* Look through the whole pending tree.
   12369              :      If we find an element that should be output now,
   12370              :      output it.  Otherwise, set NEXT to the element
   12371              :      that comes first among those still pending.  */
   12372              : 
   12373     11752037 :   next = NULL_TREE;
   12374     11764216 :   while (elt)
   12375              :     {
   12376        15058 :       if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   12377              :         {
   12378         6827 :           if (tree_int_cst_equal (elt->purpose,
   12379              :                                   constructor_unfilled_index))
   12380         2834 :             output_init_element (input_location, elt->value, elt->origtype,
   12381         2834 :                                  true, TREE_TYPE (constructor_type),
   12382              :                                  constructor_unfilled_index, false, false,
   12383              :                                  braced_init_obstack);
   12384         3993 :           else if (tree_int_cst_lt (constructor_unfilled_index,
   12385         3993 :                                     elt->purpose))
   12386              :             {
   12387              :               /* Advance to the next smaller node.  */
   12388         1138 :               if (elt->left)
   12389              :                 elt = elt->left;
   12390              :               else
   12391              :                 {
   12392              :                   /* We have reached the smallest node bigger than the
   12393              :                      current unfilled index.  Fill the space first.  */
   12394          350 :                   next = elt->purpose;
   12395          350 :                   break;
   12396              :                 }
   12397              :             }
   12398              :           else
   12399              :             {
   12400              :               /* Advance to the next bigger node.  */
   12401         2855 :               if (elt->right)
   12402              :                 elt = elt->right;
   12403              :               else
   12404              :                 {
   12405              :                   /* We have reached the biggest node in a subtree.  Find
   12406              :                      the parent of it, which is the next bigger node.  */
   12407         2855 :                   while (elt->parent && elt->parent->right == elt)
   12408              :                     elt = elt->parent;
   12409         1899 :                   elt = elt->parent;
   12410         2682 :                   if (elt && tree_int_cst_lt (constructor_unfilled_index,
   12411          783 :                                               elt->purpose))
   12412              :                     {
   12413           22 :                       next = elt->purpose;
   12414           22 :                       break;
   12415              :                     }
   12416              :                 }
   12417              :             }
   12418              :         }
   12419         8231 :       else if (RECORD_OR_UNION_TYPE_P (constructor_type))
   12420              :         {
   12421              :           /* If the current record is complete we are done.  */
   12422         8231 :           if (constructor_unfilled_fields == NULL_TREE)
   12423              :             break;
   12424              : 
   12425         6628 :           int cmp = init_field_decl_cmp (constructor_unfilled_fields,
   12426              :                                          elt->purpose);
   12427         6628 :           if (cmp == 0)
   12428         3357 :             output_init_element (input_location, elt->value, elt->origtype,
   12429         3357 :                                  true, TREE_TYPE (elt->purpose),
   12430              :                                  elt->purpose, false, false,
   12431              :                                  braced_init_obstack);
   12432         3271 :           else if (cmp < 0)
   12433              :             {
   12434              :               /* Advance to the next smaller node.  */
   12435         1316 :               if (elt->left)
   12436              :                 elt = elt->left;
   12437              :               else
   12438              :                 {
   12439              :                   /* We have reached the smallest node bigger than the
   12440              :                      current unfilled field.  Fill the space first.  */
   12441          833 :                   next = elt->purpose;
   12442          833 :                   break;
   12443              :                 }
   12444              :             }
   12445              :           else
   12446              :             {
   12447              :               /* Advance to the next bigger node.  */
   12448         1955 :               if (elt->right)
   12449              :                 elt = elt->right;
   12450              :               else
   12451              :                 {
   12452              :                   /* We have reached the biggest node in a subtree.  Find
   12453              :                      the parent of it, which is the next bigger node.  */
   12454         1025 :                   while (elt->parent && elt->parent->right == elt)
   12455              :                     elt = elt->parent;
   12456          789 :                   elt = elt->parent;
   12457          789 :                   if (elt
   12458          789 :                       && init_field_decl_cmp (constructor_unfilled_fields,
   12459              :                                               elt->purpose) < 0)
   12460              :                     {
   12461           71 :                       next = elt->purpose;
   12462           71 :                       break;
   12463              :                     }
   12464              :                 }
   12465              :             }
   12466              :         }
   12467              :     }
   12468              : 
   12469              :   /* Ordinarily return, but not if we want to output all
   12470              :      and there are elements left.  */
   12471     11752037 :   if (!(all && next != NULL_TREE))
   12472     11750870 :     return;
   12473              : 
   12474              :   /* If it's not incremental, just skip over the gap, so that after
   12475              :      jumping to retry we will output the next successive element.  */
   12476         1167 :   if (RECORD_OR_UNION_TYPE_P (constructor_type))
   12477          834 :     constructor_unfilled_fields = next;
   12478          333 :   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   12479          333 :     constructor_unfilled_index = next;
   12480              : 
   12481              :   /* ELT now points to the node in the pending tree with the next
   12482              :      initializer to output.  */
   12483         1167 :   goto retry;
   12484              : }
   12485              : 
   12486              : /* Expression VALUE coincides with the start of type TYPE in a braced
   12487              :    initializer.  Return true if we should treat VALUE as initializing
   12488              :    the first element of TYPE, false if we should treat it as initializing
   12489              :    TYPE as a whole.
   12490              : 
   12491              :    If the initializer is clearly invalid, the question becomes:
   12492              :    which choice gives the best error message?  */
   12493              : 
   12494              : static bool
   12495      3497876 : initialize_elementwise_p (tree type, tree value)
   12496              : {
   12497      3497876 :   if (type == error_mark_node || value == error_mark_node)
   12498              :     return false;
   12499              : 
   12500      3497623 :   gcc_checking_assert (TYPE_MAIN_VARIANT (type) == type);
   12501              : 
   12502      3497623 :   tree value_type = TREE_TYPE (value);
   12503      3497623 :   if (value_type == error_mark_node)
   12504              :     return false;
   12505              : 
   12506              :   /* GNU vectors can be initialized elementwise.  However, treat any
   12507              :      kind of vector value as initializing the vector type as a whole,
   12508              :      regardless of whether the value is a GNU vector.  Such initializers
   12509              :      are valid if and only if they would have been valid in a non-braced
   12510              :      initializer like:
   12511              : 
   12512              :         TYPE foo = VALUE;
   12513              : 
   12514              :      so recursing into the vector type would be at best confusing or at
   12515              :      worst wrong.  For example, when -flax-vector-conversions is in effect,
   12516              :      it's possible to initialize a V8HI from a V4SI, even though the vectors
   12517              :      have different element types and different numbers of elements.  */
   12518      3497623 :   if (gnu_vector_type_p (type))
   12519        19623 :     return !VECTOR_TYPE_P (value_type);
   12520              : 
   12521      3478000 :   if (AGGREGATE_TYPE_P (type))
   12522      1743331 :     return !comptypes (type, TYPE_MAIN_VARIANT (value_type));
   12523              : 
   12524              :   return false;
   12525              : }
   12526              : 
   12527              : /* Helper function for process_init_element.  Split first element of
   12528              :    RAW_DATA_CST and save the rest to *RAW_DATA.  */
   12529              : 
   12530              : static inline tree
   12531      9677163 : maybe_split_raw_data (tree value, tree *raw_data)
   12532              : {
   12533      9677163 :   if (value == NULL_TREE || TREE_CODE (value) != RAW_DATA_CST)
   12534              :     return value;
   12535          211 :   *raw_data = value;
   12536          211 :   value = build_int_cst (integer_type_node,
   12537          211 :                          RAW_DATA_UCHAR_ELT (*raw_data, 0));
   12538          211 :   ++RAW_DATA_POINTER (*raw_data);
   12539          211 :   --RAW_DATA_LENGTH (*raw_data);
   12540          211 :   return value;
   12541              : }
   12542              : 
   12543              : /* Return non-zero if c_parser_initval should attempt to optimize
   12544              :    large initializers into RAW_DATA_CST.  In that case return how
   12545              :    many elements to optimize at most.  */
   12546              : 
   12547              : unsigned
   12548      3016424 : c_maybe_optimize_large_byte_initializer (void)
   12549              : {
   12550      3016424 :   if (!constructor_type
   12551      3016354 :       || TREE_CODE (constructor_type) != ARRAY_TYPE
   12552       216933 :       || constructor_stack->implicit)
   12553              :     return 0;
   12554       214168 :   tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
   12555       214168 :   if (TREE_CODE (elttype) != INTEGER_TYPE
   12556       214168 :       && TREE_CODE (elttype) != BITINT_TYPE)
   12557              :     return 0;
   12558       191192 :   if (TYPE_PRECISION (elttype) != CHAR_BIT
   12559        28895 :       || constructor_stack->replacement_value.value
   12560        28895 :       || (COMPLETE_TYPE_P (constructor_type)
   12561        27250 :           && !poly_int_tree_p (TYPE_SIZE (constructor_type)))
   12562       220087 :       || constructor_range_stack)
   12563              :     return 0;
   12564        28895 :   if (constructor_max_index == NULL_TREE)
   12565              :     return INT_MAX;
   12566        27250 :   if (tree_int_cst_le (constructor_max_index, constructor_index)
   12567        27250 :       || integer_all_onesp (constructor_max_index))
   12568              :     return 0;
   12569        22452 :   widest_int w = wi::to_widest (constructor_max_index);
   12570        22452 :   w -= wi::to_widest (constructor_index);
   12571        22452 :   w += 1;
   12572        22452 :   if (w < 64)
   12573              :     return 0;
   12574         6890 :   if (w > INT_MAX)
   12575              :     return INT_MAX;
   12576         6890 :   return w.to_uhwi ();
   12577      3016424 : }
   12578              : 
   12579              : /* Add one non-braced element to the current constructor level.
   12580              :    This adjusts the current position within the constructor's type.
   12581              :    This may also start or terminate implicit levels
   12582              :    to handle a partly-braced initializer.
   12583              : 
   12584              :    Once this has found the correct level for the new element,
   12585              :    it calls output_init_element.
   12586              : 
   12587              :    IMPLICIT is true if value comes from pop_init_level (1),
   12588              :    the new initializer has been merged with the existing one
   12589              :    and thus no warnings should be emitted about overriding an
   12590              :    existing initializer.  */
   12591              : 
   12592              : void
   12593      9667457 : process_init_element (location_t loc, struct c_expr value, bool implicit,
   12594              :                       struct obstack * braced_init_obstack)
   12595              : {
   12596      9667457 :   tree orig_value = value.value;
   12597     19334914 :   int string_flag
   12598      9667457 :     = (orig_value != NULL_TREE && TREE_CODE (orig_value) == STRING_CST);
   12599      9667457 :   bool strict_string = value.original_code == STRING_CST;
   12600      9667457 :   bool was_designated = designator_depth != 0;
   12601      9667457 :   tree raw_data = NULL_TREE;
   12602              : 
   12603      9667669 : retry:
   12604      9667669 :   designator_depth = 0;
   12605      9667669 :   designator_erroneous = 0;
   12606              : 
   12607      9667669 :   if (!implicit && value.value && !integer_zerop (value.value))
   12608      7633305 :     constructor_zeroinit = 0;
   12609              : 
   12610              :   /* Handle superfluous braces around string cst as in
   12611              :      char x[] = {"foo"}; */
   12612      9667669 :   if (constructor_type
   12613      9667541 :       && !was_designated
   12614      9630410 :       && TREE_CODE (constructor_type) == ARRAY_TYPE
   12615      1714211 :       && INTEGRAL_TYPE_P (TREE_TYPE (constructor_type))
   12616     10412132 :       && integer_zerop (constructor_unfilled_index))
   12617              :     {
   12618       163738 :       if (constructor_stack->replacement_value.value)
   12619              :         {
   12620            8 :           error_init (loc, "excess elements in %qT initializer", constructor_type);
   12621          409 :           return;
   12622              :         }
   12623       163730 :       else if (string_flag)
   12624              :         {
   12625          138 :           constructor_stack->replacement_value = value;
   12626          138 :           return;
   12627              :         }
   12628              :     }
   12629              : 
   12630      9667523 :   if (constructor_stack->replacement_value.value != NULL_TREE)
   12631              :     {
   12632            0 :       error_init (loc, "excess elements in struct initializer");
   12633            0 :       return;
   12634              :     }
   12635              : 
   12636              :   /* Ignore elements of a brace group if it is entirely superfluous
   12637              :      and has already been diagnosed, or if the type is erroneous.  */
   12638      9667523 :   if (constructor_type == NULL_TREE || constructor_type == error_mark_node)
   12639              :     return;
   12640              : 
   12641              :   /* Ignore elements of an initializer for a variable-size type.
   12642              :      Those are diagnosed in the parser (empty initializer braces are OK).  */
   12643      9667326 :   if (COMPLETE_TYPE_P (constructor_type)
   12644      9667326 :       && !poly_int_tree_p (TYPE_SIZE (constructor_type)))
   12645              :     return;
   12646              : 
   12647      8961945 :   if (!implicit && warn_designated_init && !was_designated
   12648      8927132 :       && TREE_CODE (constructor_type) == RECORD_TYPE
   12649     10703095 :       && lookup_attribute ("designated_init",
   12650      1035827 :                            TYPE_ATTRIBUTES (constructor_type)))
   12651           50 :     warning_init (loc,
   12652              :                   OPT_Wdesignated_init,
   12653              :                   "positional initialization of field "
   12654              :                   "in %<struct%> declared with %<designated_init%> attribute");
   12655              : 
   12656              :   /* If we've exhausted any levels that didn't have braces,
   12657              :      pop them now.  */
   12658     10369247 :   while (constructor_stack->implicit)
   12659              :     {
   12660       708550 :       if (RECORD_OR_UNION_TYPE_P (constructor_type)
   12661       703711 :           && constructor_fields == NULL_TREE)
   12662       701738 :         process_init_element (loc,
   12663              :                               pop_init_level (loc, 1, braced_init_obstack,
   12664              :                                               last_init_list_comma),
   12665              :                               true, braced_init_obstack);
   12666         6812 :       else if ((TREE_CODE (constructor_type) == ARRAY_TYPE
   12667         2617 :                 || gnu_vector_type_p (constructor_type))
   12668         4839 :                && constructor_max_index
   12669        11624 :                && tree_int_cst_lt (constructor_max_index,
   12670              :                                    constructor_index))
   12671          241 :         process_init_element (loc,
   12672              :                               pop_init_level (loc, 1, braced_init_obstack,
   12673              :                                               last_init_list_comma),
   12674              :                               true, braced_init_obstack);
   12675              :       else
   12676              :         break;
   12677              :     }
   12678              : 
   12679              :   /* In the case of [LO ... HI] = VALUE, only evaluate VALUE once.  */
   12680      9667268 :   if (constructor_range_stack)
   12681              :     {
   12682              :       /* If value is a compound literal and we'll be just using its
   12683              :          content, don't put it into a SAVE_EXPR.  */
   12684          371 :       if (TREE_CODE (value.value) != COMPOUND_LITERAL_EXPR
   12685            3 :           || !require_constant_value)
   12686              :         {
   12687          368 :           tree semantic_type = NULL_TREE;
   12688          368 :           if (TREE_CODE (value.value) == EXCESS_PRECISION_EXPR)
   12689              :             {
   12690            0 :               semantic_type = TREE_TYPE (value.value);
   12691            0 :               value.value = TREE_OPERAND (value.value, 0);
   12692              :             }
   12693          368 :           value.value = save_expr (value.value);
   12694          368 :           if (semantic_type)
   12695            0 :             value.value = build1 (EXCESS_PRECISION_EXPR, semantic_type,
   12696              :                                   value.value);
   12697              :         }
   12698              :     }
   12699              : 
   12700     10381512 :   while (1)
   12701              :     {
   12702     10381512 :       if (TREE_CODE (constructor_type) == RECORD_TYPE)
   12703              :         {
   12704      1042017 :           tree fieldtype;
   12705      1042017 :           enum tree_code fieldcode;
   12706              : 
   12707      1042017 :           if (constructor_fields == NULL_TREE)
   12708              :             {
   12709         1280 :               pedwarn_init (loc, 0, "excess elements in struct initializer");
   12710         1280 :               break;
   12711              :             }
   12712              : 
   12713      1040737 :           fieldtype = TREE_TYPE (constructor_fields);
   12714      1040737 :           if (fieldtype != error_mark_node)
   12715      1040736 :             fieldtype = TYPE_MAIN_VARIANT (fieldtype);
   12716      1040737 :           fieldcode = TREE_CODE (fieldtype);
   12717              : 
   12718              :           /* Error for non-static initialization of a flexible array member.  */
   12719      1040737 :           if (fieldcode == ARRAY_TYPE
   12720       156029 :               && !require_constant_value
   12721         1893 :               && TYPE_SIZE (fieldtype) == NULL_TREE
   12722      1040747 :               && DECL_CHAIN (constructor_fields) == NULL_TREE)
   12723              :             {
   12724           10 :               error_init (loc, "non-static initialization of a flexible "
   12725              :                           "array member");
   12726           10 :               break;
   12727              :             }
   12728              : 
   12729              :           /* Error for initialization of a flexible array member with
   12730              :              a string constant if the structure is in an array.  E.g.:
   12731              :              struct S { int x; char y[]; };
   12732              :              struct S s[] = { { 1, "foo" } };
   12733              :              is invalid.  */
   12734      1040727 :           if (string_flag
   12735      1040727 :               && fieldcode == ARRAY_TYPE
   12736         3353 :               && constructor_depth > 1
   12737          489 :               && TYPE_SIZE (fieldtype) == NULL_TREE
   12738      1040774 :               && DECL_CHAIN (constructor_fields) == NULL_TREE)
   12739              :             {
   12740           47 :               bool in_array_p = false;
   12741           47 :               for (struct constructor_stack *p = constructor_stack;
   12742           73 :                    p && p->type; p = p->next)
   12743           59 :                 if (TREE_CODE (p->type) == ARRAY_TYPE)
   12744              :                   {
   12745              :                     in_array_p = true;
   12746              :                     break;
   12747              :                   }
   12748           47 :               if (in_array_p)
   12749              :                 {
   12750           33 :                   error_init (loc, "initialization of flexible array "
   12751              :                               "member in a nested context");
   12752           33 :                   break;
   12753              :                 }
   12754              :             }
   12755              : 
   12756              :           /* Accept a string constant to initialize a subarray.  */
   12757      1040694 :           if (value.value != NULL_TREE
   12758      1040651 :               && fieldcode == ARRAY_TYPE
   12759       155943 :               && INTEGRAL_TYPE_P (TREE_TYPE (fieldtype))
   12760      1195326 :               && string_flag)
   12761              :             value.value = orig_value;
   12762              :           /* Otherwise, if we have come to a subaggregate,
   12763              :              and we don't have an element of its type, push into it.  */
   12764      1037678 :           else if (value.value != NULL_TREE
   12765      1037374 :                    && initialize_elementwise_p (fieldtype, value.value))
   12766              :             {
   12767          304 :               push_init_level (loc, 1, braced_init_obstack);
   12768          304 :               continue;
   12769              :             }
   12770              : 
   12771      1040390 :           value.value = maybe_split_raw_data (value.value, &raw_data);
   12772      1040390 :           if (value.value)
   12773              :             {
   12774      1040347 :               push_member_name (constructor_fields);
   12775      1040347 :               output_init_element (loc, value.value, value.original_type,
   12776              :                                    strict_string, fieldtype,
   12777              :                                    constructor_fields, true, implicit,
   12778              :                                    braced_init_obstack);
   12779      1040347 :               RESTORE_SPELLING_DEPTH (constructor_depth);
   12780              :             }
   12781              :           else
   12782              :             /* Do the bookkeeping for an element that was
   12783              :                directly output as a constructor.  */
   12784              :             {
   12785              :               /* For a record, keep track of end position of last field.  */
   12786           43 :               if (DECL_SIZE (constructor_fields))
   12787            0 :                 constructor_bit_index
   12788            0 :                   = size_binop_loc (input_location, PLUS_EXPR,
   12789              :                                     bit_position (constructor_fields),
   12790            0 :                                     DECL_SIZE (constructor_fields));
   12791              : 
   12792              :               /* If the current field was the first one not yet written out,
   12793              :                  it isn't now, so update.  */
   12794           43 :               if (constructor_unfilled_fields == constructor_fields)
   12795              :                 {
   12796           34 :                   constructor_unfilled_fields = DECL_CHAIN (constructor_fields);
   12797              :                   /* Skip any nameless bit fields.  */
   12798           34 :                   while (constructor_unfilled_fields != 0
   12799           34 :                          && (DECL_UNNAMED_BIT_FIELD
   12800              :                              (constructor_unfilled_fields)))
   12801            0 :                     constructor_unfilled_fields =
   12802            0 :                       DECL_CHAIN (constructor_unfilled_fields);
   12803              :                 }
   12804              :             }
   12805              : 
   12806      1040390 :           constructor_fields = DECL_CHAIN (constructor_fields);
   12807              :           /* Skip any nameless bit fields at the beginning.  */
   12808      1040390 :           while (constructor_fields != NULL_TREE
   12809      1040491 :                  && DECL_UNNAMED_BIT_FIELD (constructor_fields))
   12810          101 :             constructor_fields = DECL_CHAIN (constructor_fields);
   12811              :         }
   12812      9339495 :       else if (TREE_CODE (constructor_type) == UNION_TYPE)
   12813              :         {
   12814        31561 :           tree fieldtype;
   12815        31561 :           enum tree_code fieldcode;
   12816              : 
   12817        31561 :           if (constructor_fields == NULL_TREE)
   12818              :             {
   12819            3 :               pedwarn_init (loc, 0,
   12820              :                             "excess elements in union initializer");
   12821            3 :               break;
   12822              :             }
   12823              : 
   12824        31558 :           fieldtype = TREE_TYPE (constructor_fields);
   12825        31558 :           if (fieldtype != error_mark_node)
   12826        31558 :             fieldtype = TYPE_MAIN_VARIANT (fieldtype);
   12827        31558 :           fieldcode = TREE_CODE (fieldtype);
   12828              : 
   12829              :           /* Warn that traditional C rejects initialization of unions.
   12830              :              We skip the warning if the value is zero.  This is done
   12831              :              under the assumption that the zero initializer in user
   12832              :              code appears conditioned on e.g. __STDC__ to avoid
   12833              :              "missing initializer" warnings and relies on default
   12834              :              initialization to zero in the traditional C case.
   12835              :              We also skip the warning if the initializer is designated,
   12836              :              again on the assumption that this must be conditional on
   12837              :              __STDC__ anyway (and we've already complained about the
   12838              :              member-designator already).  */
   12839        34012 :           if (!in_system_header_at (input_location) && !constructor_designated
   12840        33095 :               && !(value.value && (integer_zerop (value.value)
   12841         1438 :                                    || real_zerop (value.value))))
   12842         1431 :             warning (OPT_Wtraditional, "traditional C rejects initialization "
   12843              :                      "of unions");
   12844              : 
   12845              :           /* Error for non-static initialization of a flexible array member.  */
   12846        31558 :           if (fieldcode == ARRAY_TYPE
   12847          766 :               && !require_constant_value
   12848        31615 :               && TYPE_SIZE (fieldtype) == NULL_TREE)
   12849              :             {
   12850            3 :               error_init (loc, "non-static initialization of a flexible "
   12851              :                           "array member");
   12852            3 :               break;
   12853              :             }
   12854              : 
   12855              :           /* Error for initialization of a flexible array member with
   12856              :              a string constant if the structure is in an array.  E.g.:
   12857              :              union U { int x; char y[]; };
   12858              :              union U s[] = { { 1, "foo" } };
   12859              :              is invalid.  */
   12860        31555 :           if (string_flag
   12861        31555 :               && fieldcode == ARRAY_TYPE
   12862            7 :               && constructor_depth > 1
   12863        31559 :               && TYPE_SIZE (fieldtype) == NULL_TREE)
   12864              :             {
   12865            3 :               bool in_array_p = false;
   12866            3 :               for (struct constructor_stack *p = constructor_stack;
   12867            3 :                    p && p->type; p = p->next)
   12868            3 :                 if (TREE_CODE (p->type) == ARRAY_TYPE)
   12869              :                   {
   12870              :                     in_array_p = true;
   12871              :                     break;
   12872              :                   }
   12873            3 :               if (in_array_p)
   12874              :                 {
   12875            3 :                   error_init (loc, "initialization of flexible array "
   12876              :                               "member in a nested context");
   12877            3 :                   break;
   12878              :                 }
   12879              :             }
   12880              : 
   12881              :           /* Accept a string constant to initialize a subarray.  */
   12882        31552 :           if (value.value != NULL_TREE
   12883        31552 :               && fieldcode == ARRAY_TYPE
   12884          760 :               && INTEGRAL_TYPE_P (TREE_TYPE (fieldtype))
   12885        32307 :               && string_flag)
   12886              :             value.value = orig_value;
   12887              :           /* Otherwise, if we have come to a subaggregate,
   12888              :              and we don't have an element of its type, push into it.  */
   12889        31598 :           else if (value.value != NULL_TREE
   12890        31548 :                    && initialize_elementwise_p (fieldtype, value.value))
   12891              :             {
   12892           50 :               push_init_level (loc, 1, braced_init_obstack);
   12893           50 :               continue;
   12894              :             }
   12895              : 
   12896        31502 :           value.value = maybe_split_raw_data (value.value, &raw_data);
   12897        31502 :           if (value.value)
   12898              :             {
   12899        31502 :               push_member_name (constructor_fields);
   12900        31502 :               output_init_element (loc, value.value, value.original_type,
   12901              :                                    strict_string, fieldtype,
   12902              :                                    constructor_fields, true, implicit,
   12903              :                                    braced_init_obstack);
   12904        31502 :               RESTORE_SPELLING_DEPTH (constructor_depth);
   12905              :             }
   12906              :           else
   12907              :             /* Do the bookkeeping for an element that was
   12908              :                directly output as a constructor.  */
   12909              :             {
   12910            0 :               constructor_bit_index = DECL_SIZE (constructor_fields);
   12911            0 :               constructor_unfilled_fields = DECL_CHAIN (constructor_fields);
   12912              :             }
   12913              : 
   12914        31502 :           constructor_fields = NULL_TREE;
   12915              :         }
   12916      9307934 :       else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   12917              :         {
   12918      2429493 :           tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
   12919      2429493 :           enum tree_code eltcode = TREE_CODE (elttype);
   12920              : 
   12921              :           /* Accept a string constant to initialize a subarray.  */
   12922      2429493 :           if (value.value != NULL_TREE
   12923      2429493 :               && eltcode == ARRAY_TYPE
   12924         7031 :               && INTEGRAL_TYPE_P (TREE_TYPE (elttype))
   12925      2435041 :               && string_flag)
   12926              :             value.value = orig_value;
   12927              :           /* Otherwise, if we have come to a subaggregate,
   12928              :              and we don't have an element of its type, push into it.  */
   12929      3131323 :           else if (value.value != NULL_TREE
   12930      2428997 :                    && initialize_elementwise_p (elttype, value.value))
   12931              :             {
   12932       702326 :               push_init_level (loc, 1, braced_init_obstack);
   12933       702326 :               continue;
   12934              :             }
   12935              : 
   12936      1727167 :           if (constructor_max_index != NULL_TREE
   12937       680302 :               && (tree_int_cst_lt (constructor_max_index, constructor_index)
   12938       680187 :                   || integer_all_onesp (constructor_max_index))
   12939              :               /* For VLA we got an error already.  */
   12940      1727282 :               && !C_TYPE_VARIABLE_SIZE (constructor_type))
   12941              :             {
   12942          113 :               pedwarn_init (loc, 0,
   12943              :                             "excess elements in array initializer");
   12944          113 :               break;
   12945              :             }
   12946              : 
   12947      1727054 :           if (value.value
   12948      1727054 :               && TREE_CODE (value.value) == RAW_DATA_CST
   12949          193 :               && RAW_DATA_LENGTH (value.value) > 1
   12950          193 :               && (TREE_CODE (elttype) == INTEGER_TYPE
   12951          193 :                   || TREE_CODE (elttype) == BITINT_TYPE)
   12952          193 :               && TYPE_PRECISION (elttype) == CHAR_BIT
   12953      1727247 :               && (constructor_max_index == NULL_TREE
   12954           55 :                   || tree_int_cst_lt (constructor_index,
   12955              :                                       constructor_max_index)))
   12956              :             {
   12957          193 :               unsigned int len = RAW_DATA_LENGTH (value.value);
   12958          193 :               if (constructor_max_index)
   12959              :                 {
   12960           55 :                   widest_int w = wi::to_widest (constructor_max_index);
   12961           55 :                   w -= wi::to_widest (constructor_index);
   12962           55 :                   w += 1;
   12963           55 :                   if (w < len)
   12964            3 :                     len = w.to_uhwi ();
   12965           55 :                 }
   12966          193 :               if (len < (unsigned) RAW_DATA_LENGTH (value.value))
   12967              :                 {
   12968            3 :                   raw_data = copy_node (value.value);
   12969            3 :                   RAW_DATA_LENGTH (raw_data) -= len;
   12970            3 :                   RAW_DATA_POINTER (raw_data) += len;
   12971            3 :                   RAW_DATA_LENGTH (value.value) = len;
   12972              :                 }
   12973          193 :               TREE_TYPE (value.value) = elttype;
   12974          193 :               push_array_bounds (tree_to_uhwi (constructor_index));
   12975          193 :               output_init_element (loc, value.value, value.original_type,
   12976              :                                    false, elttype, constructor_index, true,
   12977              :                                    implicit, braced_init_obstack);
   12978          193 :               RESTORE_SPELLING_DEPTH (constructor_depth);
   12979          193 :               constructor_index
   12980          193 :                 = size_binop_loc (input_location, PLUS_EXPR,
   12981          193 :                                   constructor_index, bitsize_int (len));
   12982              :             }
   12983              :           else
   12984              :             {
   12985      1726861 :               value.value = maybe_split_raw_data (value.value, &raw_data);
   12986              :               /* Now output the actual element.  */
   12987      1726861 :               if (value.value)
   12988              :                 {
   12989      1726861 :                   push_array_bounds (tree_to_uhwi (constructor_index));
   12990      1726861 :                   output_init_element (loc, value.value, value.original_type,
   12991              :                                        strict_string, elttype,
   12992              :                                        constructor_index, true, implicit,
   12993              :                                        braced_init_obstack);
   12994      1726861 :                   RESTORE_SPELLING_DEPTH (constructor_depth);
   12995              :                 }
   12996              : 
   12997      1726861 :               constructor_index
   12998      1726861 :                 = size_binop_loc (input_location, PLUS_EXPR,
   12999              :                                   constructor_index, bitsize_one_node);
   13000              : 
   13001      1726861 :               if (!value.value)
   13002              :                 /* If we are doing the bookkeeping for an element that was
   13003              :                    directly output as a constructor, we must update
   13004              :                    constructor_unfilled_index.  */
   13005            0 :                 constructor_unfilled_index = constructor_index;
   13006              :             }
   13007              :         }
   13008      6878441 :       else if (gnu_vector_type_p (constructor_type))
   13009              :         {
   13010      6877949 :           tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
   13011              : 
   13012              :           /* Do a basic check of initializer size.  Note that vectors
   13013              :              may not always have a fixed size derived from their type.  */
   13014      6877949 :           if (maybe_lt (tree_to_poly_uint64 (constructor_max_index),
   13015      6877949 :                         tree_to_poly_uint64 (constructor_index)))
   13016              :             {
   13017              :               /* Diagose VLA out-of-bounds as errors.  */
   13018            2 :               if (tree_to_poly_uint64 (constructor_max_index).is_constant())
   13019            2 :                 pedwarn_init (loc, 0,
   13020              :                               "excess elements in vector initializer");
   13021              :               else
   13022              :                 error_init (loc, "excess elements in vector initializer");
   13023              : 
   13024              :               break;
   13025              :             }
   13026              : 
   13027      6877947 :           value.value = maybe_split_raw_data (value.value, &raw_data);
   13028              :           /* Now output the actual element.  */
   13029      6877947 :           if (value.value)
   13030              :             {
   13031      6877947 :               if (TREE_CODE (value.value) == VECTOR_CST)
   13032            0 :                 elttype = TYPE_MAIN_VARIANT (constructor_type);
   13033      6877947 :               output_init_element (loc, value.value, value.original_type,
   13034              :                                    strict_string, elttype,
   13035              :                                    constructor_index, true, implicit,
   13036              :                                    braced_init_obstack);
   13037              :             }
   13038              : 
   13039      6877947 :           constructor_index
   13040      6877947 :             = size_binop_loc (input_location,
   13041              :                               PLUS_EXPR, constructor_index, bitsize_one_node);
   13042              : 
   13043      6877947 :           if (!value.value)
   13044              :             /* If we are doing the bookkeeping for an element that was
   13045              :                directly output as a constructor, we must update
   13046              :                constructor_unfilled_index.  */
   13047            0 :             constructor_unfilled_index = constructor_index;
   13048              :         }
   13049              : 
   13050              :       /* Handle the sole element allowed in a braced initializer
   13051              :          for a scalar variable.  */
   13052          492 :       else if (constructor_type != error_mark_node
   13053          492 :                && constructor_fields == NULL_TREE)
   13054              :         {
   13055           29 :           pedwarn_init (loc, 0,
   13056              :                         "excess elements in scalar initializer");
   13057           29 :           break;
   13058              :         }
   13059              :       else
   13060              :         {
   13061          463 :           value.value = maybe_split_raw_data (value.value, &raw_data);
   13062          463 :           if (value.value)
   13063          463 :             output_init_element (loc, value.value, value.original_type,
   13064              :                                  strict_string, constructor_type,
   13065              :                                  NULL_TREE, true, implicit,
   13066              :                                  braced_init_obstack);
   13067          463 :           constructor_fields = NULL_TREE;
   13068              :         }
   13069              : 
   13070              :       /* Handle range initializers either at this level or anywhere higher
   13071              :          in the designator stack.  */
   13072      9677356 :       if (constructor_range_stack)
   13073              :         {
   13074        11564 :           struct constructor_range_stack *p, *range_stack;
   13075        11564 :           int finish = 0;
   13076              : 
   13077        11564 :           range_stack = constructor_range_stack;
   13078        11564 :           constructor_range_stack = 0;
   13079        11564 :           while (constructor_stack != range_stack->stack)
   13080              :             {
   13081            0 :               gcc_assert (constructor_stack->implicit);
   13082            0 :               process_init_element (loc,
   13083              :                                     pop_init_level (loc, 1,
   13084              :                                                     braced_init_obstack,
   13085              :                                                     last_init_list_comma),
   13086              :                                     true, braced_init_obstack);
   13087              :             }
   13088          325 :           for (p = range_stack;
   13089        11889 :                !p->range_end || tree_int_cst_equal (p->index, p->range_end);
   13090          325 :                p = p->prev)
   13091              :             {
   13092          325 :               gcc_assert (constructor_stack->implicit);
   13093          325 :               process_init_element (loc,
   13094              :                                     pop_init_level (loc, 1,
   13095              :                                                     braced_init_obstack,
   13096              :                                                     last_init_list_comma),
   13097              :                                     true, braced_init_obstack);
   13098              :             }
   13099              : 
   13100        11564 :           p->index = size_binop_loc (input_location,
   13101              :                                      PLUS_EXPR, p->index, bitsize_one_node);
   13102        11564 :           if (tree_int_cst_equal (p->index, p->range_end) && !p->prev)
   13103        11564 :             finish = 1;
   13104              : 
   13105        11889 :           while (1)
   13106              :             {
   13107        11889 :               constructor_index = p->index;
   13108        11889 :               constructor_fields = p->fields;
   13109        11889 :               if (finish && p->range_end && p->index == p->range_start)
   13110              :                 {
   13111            8 :                   finish = 0;
   13112            8 :                   p->prev = 0;
   13113              :                 }
   13114        11889 :               p = p->next;
   13115        11889 :               if (!p)
   13116              :                 break;
   13117          325 :               finish_implicit_inits (loc, braced_init_obstack);
   13118          325 :               push_init_level (loc, 2, braced_init_obstack);
   13119          325 :               p->stack = constructor_stack;
   13120          325 :               if (p->range_end && tree_int_cst_equal (p->index, p->range_end))
   13121           33 :                 p->index = p->range_start;
   13122              :             }
   13123              : 
   13124        11564 :           if (!finish)
   13125        11193 :             constructor_range_stack = range_stack;
   13126        11564 :           continue;
   13127        11564 :         }
   13128              : 
   13129              :       break;
   13130              :     }
   13131              : 
   13132      9667268 :   constructor_range_stack = 0;
   13133              : 
   13134      9667268 :   if (raw_data && RAW_DATA_LENGTH (raw_data))
   13135              :     {
   13136          212 :       gcc_assert (!string_flag && !was_designated);
   13137          212 :       value.value = raw_data;
   13138          212 :       raw_data = NULL_TREE;
   13139          212 :       goto retry;
   13140              :     }
   13141              : }
   13142              : 
   13143              : /* Build a complete asm-statement, whose components are a CV_QUALIFIER
   13144              :    (guaranteed to be 'volatile' or null) and ARGS (represented using
   13145              :    an ASM_EXPR node).  */
   13146              : tree
   13147       195624 : build_asm_stmt (bool is_volatile, tree args)
   13148              : {
   13149       195624 :   if (is_volatile)
   13150       155761 :     ASM_VOLATILE_P (args) = 1;
   13151       195624 :   return add_stmt (args);
   13152              : }
   13153              : 
   13154              : /* Build an asm-expr, whose components are a STRING, some OUTPUTS,
   13155              :    some INPUTS, and some CLOBBERS.  The latter three may be NULL.
   13156              :    SIMPLE indicates whether there was anything at all after the
   13157              :    string in the asm expression -- asm("blah") and asm("blah" : )
   13158              :    are subtly different.  We use a ASM_EXPR node to represent this.
   13159              :    LOC is the location of the asm, and IS_INLINE says whether this
   13160              :    is asm inline.  */
   13161              : tree
   13162       195676 : build_asm_expr (location_t loc, tree string, tree outputs, tree inputs,
   13163              :                 tree clobbers, tree labels, bool simple, bool is_inline)
   13164              : {
   13165       195676 :   tree tail;
   13166       195676 :   tree args;
   13167       195676 :   int i;
   13168       195676 :   const char *constraint;
   13169       195676 :   const char **oconstraints;
   13170       195676 :   bool allows_mem, allows_reg, is_inout;
   13171       195676 :   int ninputs, noutputs;
   13172              : 
   13173       195676 :   ninputs = list_length (inputs);
   13174       195676 :   noutputs = list_length (outputs);
   13175       195676 :   oconstraints = (const char **) alloca (noutputs * sizeof (const char *));
   13176              : 
   13177       195676 :   string = resolve_asm_operand_names (string, outputs, inputs, labels);
   13178              : 
   13179              :   /* Remove output conversions that change the type but not the mode.  */
   13180       743578 :   for (i = 0, tail = outputs; tail; ++i, tail = TREE_CHAIN (tail))
   13181              :     {
   13182       352226 :       tree output = TREE_VALUE (tail);
   13183              : 
   13184       352226 :       output = c_fully_fold (output, false, NULL, true);
   13185              : 
   13186              :       /* ??? Really, this should not be here.  Users should be using a
   13187              :          proper lvalue, dammit.  But there's a long history of using casts
   13188              :          in the output operands.  In cases like longlong.h, this becomes a
   13189              :          primitive form of typechecking -- if the cast can be removed, then
   13190              :          the output operand had a type of the proper width; otherwise we'll
   13191              :          get an error.  Gross, but ...  */
   13192       352226 :       STRIP_NOPS (output);
   13193              : 
   13194       352226 :       if (!lvalue_or_else (loc, output, lv_asm))
   13195            4 :         output = error_mark_node;
   13196              : 
   13197       352226 :       if (output != error_mark_node
   13198       352226 :           && (TREE_READONLY (output)
   13199       352219 :               || TYPE_READONLY (TREE_TYPE (output))
   13200       352219 :               || (RECORD_OR_UNION_TYPE_P (TREE_TYPE (output))
   13201          112 :                   && C_TYPE_FIELDS_READONLY (TREE_TYPE (output)))))
   13202            2 :         readonly_error (loc, output, lv_asm);
   13203              : 
   13204       352226 :       constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail)));
   13205       352226 :       oconstraints[i] = constraint;
   13206              : 
   13207       352226 :       if (parse_output_constraint (&constraint, i, ninputs, noutputs,
   13208              :                                    &allows_mem, &allows_reg, &is_inout,
   13209              :                                    nullptr))
   13210              :         {
   13211              :           /* If the operand is going to end up in memory,
   13212              :              mark it addressable.  */
   13213       352218 :           if (!allows_reg && !c_mark_addressable (output))
   13214            3 :             output = error_mark_node;
   13215         1423 :           if (!(!allows_reg && allows_mem)
   13216       350795 :               && output != error_mark_node
   13217       703011 :               && VOID_TYPE_P (TREE_TYPE (output)))
   13218              :             {
   13219            4 :               error_at (loc, "invalid use of void expression");
   13220            4 :               output = error_mark_node;
   13221              :             }
   13222       352218 :           if (allows_reg && current_function_decl == NULL_TREE)
   13223              :             {
   13224            1 :               error_at (loc, "constraint allows registers outside of "
   13225              :                              "a function");
   13226            1 :               output = error_mark_node;
   13227              :             }
   13228              :         }
   13229              :       else
   13230            8 :         output = error_mark_node;
   13231              : 
   13232       352226 :       if (current_function_decl == NULL_TREE && output != error_mark_node)
   13233              :         {
   13234            7 :           if (TREE_SIDE_EFFECTS (output))
   13235              :             {
   13236            0 :               error_at (loc, "side-effects in output operand outside "
   13237              :                              "of a function");
   13238            0 :               output = error_mark_node;
   13239              :             }
   13240              :           else
   13241              :             {
   13242            7 :               tree addr = build_unary_op (loc, ADDR_EXPR, output, false);
   13243            7 :               if (addr == error_mark_node)
   13244              :                 output = error_mark_node;
   13245            7 :               else if (!initializer_constant_valid_p (addr, TREE_TYPE (addr)))
   13246              :                 {
   13247            1 :                   error_at (loc, "output operand outside of a function is not "
   13248              :                                  "constant");
   13249            1 :                   output = error_mark_node;
   13250              :                 }
   13251              :             }
   13252              :         }
   13253       352219 :       else if (output != error_mark_node && strstr (constraint, "-"))
   13254              :         {
   13255            1 :           error_at (loc, "%<-%> modifier used inside of a function");
   13256            1 :           output = error_mark_node;
   13257              :         }
   13258              : 
   13259       352226 :       TREE_VALUE (tail) = output;
   13260              :     }
   13261              : 
   13262       562931 :   for (i = 0, tail = inputs; tail; ++i, tail = TREE_CHAIN (tail))
   13263              :     {
   13264       367255 :       tree input;
   13265              : 
   13266       367255 :       constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail)));
   13267       367255 :       input = TREE_VALUE (tail);
   13268              : 
   13269       367255 :       if (parse_input_constraint (&constraint, i, ninputs, noutputs, 0,
   13270              :                                   oconstraints, &allows_mem, &allows_reg,
   13271              :                                   nullptr))
   13272              :         {
   13273              :           /* If the operand is going to end up in memory,
   13274              :              mark it addressable.  */
   13275       367247 :           if (!allows_reg && allows_mem)
   13276              :             {
   13277         1363 :               input = c_fully_fold (input, false, NULL, true);
   13278              : 
   13279              :               /* Strip the nops as we allow this case.  FIXME, this really
   13280              :                  should be rejected or made deprecated.  */
   13281         1363 :               STRIP_NOPS (input);
   13282         1363 :               if (!c_mark_addressable (input))
   13283            2 :                 input = error_mark_node;
   13284              :             }
   13285              :           else
   13286              :             {
   13287       365884 :               input = c_fully_fold (convert_lvalue_to_rvalue (loc, input,
   13288              :                                                               true, false),
   13289              :                                     false, NULL);
   13290              : 
   13291       365884 :               if (input != error_mark_node && VOID_TYPE_P (TREE_TYPE (input)))
   13292              :                 {
   13293            4 :                   error_at (loc, "invalid use of void expression");
   13294            4 :                   input = error_mark_node;
   13295              :                 }
   13296              :             }
   13297       367247 :           if (allows_reg && current_function_decl == NULL_TREE)
   13298              :             {
   13299            1 :               error_at (loc, "constraint allows registers outside of "
   13300              :                              "a function");
   13301            1 :               input = error_mark_node;
   13302              :             }
   13303       367247 :           if (constraint[0] == ':' && input != error_mark_node)
   13304              :             {
   13305           35 :               tree t = input;
   13306           35 :               STRIP_NOPS (t);
   13307           35 :               if (TREE_CODE (t) != ADDR_EXPR
   13308           35 :                   || !(TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
   13309           23 :                        || (VAR_P (TREE_OPERAND (t, 0))
   13310           21 :                            && is_global_var (TREE_OPERAND (t, 0)))))
   13311              :                 {
   13312            5 :                   error_at (loc, "%<:%> constraint operand is not address "
   13313              :                                  "of a function or non-automatic variable");
   13314            5 :                   input = error_mark_node;
   13315              :                 }
   13316           30 :               else if (TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL)
   13317           10 :                 suppress_warning (TREE_OPERAND (t, 0), OPT_Wunused);
   13318              :             }
   13319              :         }
   13320              :       else
   13321            8 :         input = error_mark_node;
   13322              : 
   13323       367255 :       if (current_function_decl == NULL_TREE && input != error_mark_node)
   13324              :         {
   13325           58 :           if (TREE_SIDE_EFFECTS (input))
   13326              :             {
   13327            2 :               error_at (loc, "side-effects in input operand outside "
   13328              :                              "of a function");
   13329            2 :               input = error_mark_node;
   13330              :             }
   13331              :           else
   13332              :             {
   13333           56 :               tree tem = input;
   13334           56 :               if (allows_mem && lvalue_p (input))
   13335            7 :                 tem = build_unary_op (loc, ADDR_EXPR, input, false);
   13336           56 :               if (!initializer_constant_valid_p (tem, TREE_TYPE (tem)))
   13337              :                 {
   13338            2 :                   error_at (loc, "input operand outside of a function is not "
   13339              :                                  "constant");
   13340            2 :                   input = error_mark_node;
   13341              :                 }
   13342              :             }
   13343              :         }
   13344       367197 :       else if (input != error_mark_node && strstr (constraint, "-"))
   13345              :         {
   13346            3 :           error_at (loc, "%<-%> modifier used inside of a function");
   13347            3 :           input = error_mark_node;
   13348              :         }
   13349              : 
   13350       367255 :       TREE_VALUE (tail) = input;
   13351              :     }
   13352              : 
   13353       195676 :   args = build_stmt (loc, ASM_EXPR, string, outputs, inputs, clobbers, labels);
   13354              : 
   13355              :   /* asm statements without outputs, including simple ones, are treated
   13356              :      as volatile.  */
   13357       195676 :   ASM_BASIC_P (args) = simple;
   13358       195676 :   ASM_VOLATILE_P (args) = (noutputs == 0);
   13359       195676 :   ASM_INLINE_P (args) = is_inline;
   13360              : 
   13361       195676 :   return args;
   13362              : }
   13363              : 
   13364              : /* Generate a goto statement to LABEL.  LOC is the location of the
   13365              :    GOTO.  */
   13366              : 
   13367              : tree
   13368        83474 : c_finish_goto_label (location_t loc, tree label)
   13369              : {
   13370        83474 :   tree decl = lookup_label_for_goto (loc, label);
   13371        83474 :   if (!decl)
   13372              :     return NULL_TREE;
   13373        83474 :   TREE_USED (decl) = 1;
   13374        83474 :   mark_decl_used (decl, false);
   13375        83474 :   {
   13376        83474 :     add_stmt (build_predict_expr (PRED_GOTO, NOT_TAKEN));
   13377        83474 :     tree t = build1 (GOTO_EXPR, void_type_node, decl);
   13378        83474 :     SET_EXPR_LOCATION (t, loc);
   13379        83474 :     return add_stmt (t);
   13380              :   }
   13381              : }
   13382              : 
   13383              : /* Generate a computed goto statement to EXPR.  LOC is the location of
   13384              :    the GOTO.  */
   13385              : 
   13386              : tree
   13387         1022 : c_finish_goto_ptr (location_t loc, c_expr val)
   13388              : {
   13389         1022 :   tree expr = val.value;
   13390         1022 :   tree t;
   13391         1022 :   pedwarn (loc, OPT_Wpedantic, "ISO C forbids %<goto *expr;%>");
   13392         1022 :   if (expr != error_mark_node
   13393         1021 :       && !POINTER_TYPE_P (TREE_TYPE (expr))
   13394         1027 :       && !null_pointer_constant_p (expr))
   13395              :     {
   13396            2 :       error_at (val.get_location (),
   13397              :                 "computed goto must be pointer type");
   13398            2 :       expr = build_zero_cst (ptr_type_node);
   13399              :     }
   13400         1022 :   expr = c_fully_fold (expr, false, NULL);
   13401         1022 :   expr = convert (ptr_type_node, expr);
   13402         1022 :   t = build1 (GOTO_EXPR, void_type_node, expr);
   13403         1022 :   SET_EXPR_LOCATION (t, loc);
   13404         1022 :   return add_stmt (t);
   13405              : }
   13406              : 
   13407              : /* Generate a C `return' statement.  RETVAL is the expression for what
   13408              :    to return, or a null pointer for `return;' with no value.  LOC is
   13409              :    the location of the return statement, or the location of the expression,
   13410              :    if the statement has any.  If ORIGTYPE is not NULL_TREE, it
   13411              :    is the original type of RETVAL.  MUSTTAIL_P indicates a musttail
   13412              :    attribute.  */
   13413              : 
   13414              : tree
   13415     35743317 : c_finish_return (location_t loc, tree retval, tree origtype, bool musttail_p)
   13416              : {
   13417     35743317 :   tree valtype = TREE_TYPE (TREE_TYPE (current_function_decl)), ret_stmt;
   13418     35743317 :   bool no_warning = false;
   13419     35743317 :   bool npc = false;
   13420              : 
   13421              :   /* Use the expansion point to handle cases such as returning NULL
   13422              :      in a function returning void.  */
   13423     35743317 :   location_t xloc = expansion_point_location_if_in_system_header (loc);
   13424              : 
   13425     35743317 :   if (TREE_THIS_VOLATILE (current_function_decl))
   13426           23 :     warning_at (xloc, 0,
   13427              :                 "function declared %<noreturn%> has a %<return%> statement");
   13428              : 
   13429     35743317 :   set_musttail_on_return (retval, xloc, musttail_p);
   13430              : 
   13431     35743317 :   if (retval)
   13432              :     {
   13433     35721796 :       tree semantic_type = NULL_TREE;
   13434     35721796 :       npc = null_pointer_constant_p (retval);
   13435     35721796 :       if (TREE_CODE (retval) == EXCESS_PRECISION_EXPR)
   13436              :         {
   13437           93 :           semantic_type = TREE_TYPE (retval);
   13438           93 :           retval = TREE_OPERAND (retval, 0);
   13439              :         }
   13440     35721796 :       retval = c_fully_fold (retval, false, NULL);
   13441     35721796 :       if (semantic_type
   13442     35721796 :           && valtype != NULL_TREE
   13443           93 :           && TREE_CODE (valtype) != VOID_TYPE)
   13444           93 :         retval = build1 (EXCESS_PRECISION_EXPR, semantic_type, retval);
   13445              :     }
   13446              : 
   13447     35721796 :   if (!retval)
   13448              :     {
   13449        21521 :       current_function_returns_null = 1;
   13450        21521 :       if ((warn_return_type >= 0 || flag_isoc99)
   13451        21396 :           && valtype != NULL_TREE && TREE_CODE (valtype) != VOID_TYPE)
   13452              :         {
   13453           46 :           no_warning = true;
   13454           47 :           if (emit_diagnostic (flag_isoc99
   13455              :                                ? diagnostics::kind::permerror
   13456              :                                : diagnostics::kind::warning,
   13457           46 :                                loc, OPT_Wreturn_mismatch,
   13458              :                                "%<return%> with no value,"
   13459              :                                " in function returning non-void"))
   13460           27 :             inform (DECL_SOURCE_LOCATION (current_function_decl),
   13461              :                     "declared here");
   13462              :         }
   13463              :     }
   13464     35721796 :   else if (valtype == NULL_TREE || VOID_TYPE_P (valtype))
   13465              :     {
   13466          323 :       current_function_returns_null = 1;
   13467          323 :       bool warned_here;
   13468          323 :       if (TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
   13469           64 :         warned_here = permerror_opt
   13470           64 :           (xloc, OPT_Wreturn_mismatch,
   13471              :            "%<return%> with a value, in function returning void");
   13472              :       else
   13473          259 :         warned_here = pedwarn
   13474          259 :           (xloc, OPT_Wpedantic, "ISO C forbids "
   13475              :            "%<return%> with expression, in function returning void");
   13476          323 :       if (warned_here)
   13477           43 :         inform (DECL_SOURCE_LOCATION (current_function_decl),
   13478              :                 "declared here");
   13479              :     }
   13480              :   else
   13481              :     {
   13482     35721473 :       tree t = convert_for_assignment (loc, UNKNOWN_LOCATION, valtype,
   13483              :                                        retval, origtype, ic_return,
   13484              :                                        npc, NULL_TREE, NULL_TREE, 0);
   13485     35721473 :       tree res = DECL_RESULT (current_function_decl);
   13486     35721473 :       tree inner;
   13487     35721473 :       bool save;
   13488              : 
   13489     35721473 :       current_function_returns_value = 1;
   13490     35721473 :       if (t == error_mark_node)
   13491              :         {
   13492              :           /* Suppress -Wreturn-type for this function.  */
   13493          299 :           if (warn_return_type)
   13494          298 :             suppress_warning (current_function_decl, OPT_Wreturn_type);
   13495              :           return NULL_TREE;
   13496              :         }
   13497              : 
   13498     35721174 :       save = in_late_binary_op;
   13499     71433657 :       if (C_BOOLEAN_TYPE_P (TREE_TYPE (res))
   13500     35711678 :           || TREE_CODE (TREE_TYPE (res)) == COMPLEX_TYPE
   13501     71431549 :           || (SCALAR_FLOAT_TYPE_P (TREE_TYPE (t))
   13502       334900 :               && (TREE_CODE (TREE_TYPE (res)) == INTEGER_TYPE
   13503       334900 :                   || TREE_CODE (TREE_TYPE (res)) == ENUMERAL_TYPE)
   13504            0 :               && sanitize_flags_p (SANITIZE_FLOAT_CAST)))
   13505        10799 :         in_late_binary_op = true;
   13506     35721174 :       inner = t = convert (TREE_TYPE (res), t);
   13507     35721174 :       in_late_binary_op = save;
   13508              : 
   13509              :       /* Strip any conversions, additions, and subtractions, and see if
   13510              :          we are returning the address of a local variable.  Warn if so.  */
   13511     39020831 :       while (1)
   13512              :         {
   13513     39020831 :           switch (TREE_CODE (inner))
   13514              :             {
   13515      3298099 :             CASE_CONVERT:
   13516      3298099 :             case NON_LVALUE_EXPR:
   13517      3298099 :             case PLUS_EXPR:
   13518      3298099 :             case POINTER_PLUS_EXPR:
   13519      3298099 :               inner = TREE_OPERAND (inner, 0);
   13520      3298099 :               continue;
   13521              : 
   13522         1563 :             case MINUS_EXPR:
   13523              :               /* If the second operand of the MINUS_EXPR has a pointer
   13524              :                  type (or is converted from it), this may be valid, so
   13525              :                  don't give a warning.  */
   13526         1563 :               {
   13527         1563 :                 tree op1 = TREE_OPERAND (inner, 1);
   13528              : 
   13529         3387 :                 while (!POINTER_TYPE_P (TREE_TYPE (op1))
   13530         3653 :                        && (CONVERT_EXPR_P (op1)
   13531         1558 :                            || TREE_CODE (op1) == NON_LVALUE_EXPR))
   13532          266 :                   op1 = TREE_OPERAND (op1, 0);
   13533              : 
   13534         1563 :                 if (POINTER_TYPE_P (TREE_TYPE (op1)))
   13535              :                   break;
   13536              : 
   13537         1558 :                 inner = TREE_OPERAND (inner, 0);
   13538         1558 :                 continue;
   13539         1558 :               }
   13540              : 
   13541         2968 :             case ADDR_EXPR:
   13542         2968 :               inner = TREE_OPERAND (inner, 0);
   13543              : 
   13544         2968 :               while (REFERENCE_CLASS_P (inner)
   13545         3871 :                      && !INDIRECT_REF_P (inner))
   13546          903 :                 inner = TREE_OPERAND (inner, 0);
   13547              : 
   13548         2968 :               if (DECL_P (inner)
   13549         1644 :                   && !DECL_EXTERNAL (inner)
   13550          992 :                   && DECL_CONTEXT (inner) == current_function_decl
   13551         3190 :                   && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (current_function_decl))))
   13552              :                 {
   13553          182 :                   if (TREE_CODE (inner) == LABEL_DECL)
   13554            4 :                     warning_at (loc, OPT_Wreturn_local_addr,
   13555              :                                 "function returns address of label");
   13556          178 :                   else if (TREE_CODE (inner) == FUNCTION_DECL
   13557          178 :                            && (C_FUNC_NONLOCAL_CONTEXT (inner)
   13558            9 :                                || !DECL_INITIAL (inner)))
   13559           14 :                     warning_at (loc, OPT_Wreturn_local_addr,
   13560              :                                 "function returns address of nested function "
   13561              :                                 "referencing local context");
   13562          164 :                   else if (TREE_CODE (inner) != FUNCTION_DECL
   13563          156 :                            && !TREE_STATIC (inner))
   13564              :                     {
   13565            9 :                       warning_at (loc, OPT_Wreturn_local_addr,
   13566              :                                   "function returns address of local variable");
   13567            9 :                       tree zero = build_zero_cst (TREE_TYPE (res));
   13568            9 :                       t = build2 (COMPOUND_EXPR, TREE_TYPE (res), t, zero);
   13569              :                     }
   13570              :                 }
   13571              :               break;
   13572              : 
   13573              :             default:
   13574              :               break;
   13575      3298099 :             }
   13576              : 
   13577     35721174 :           break;
   13578              :         }
   13579              : 
   13580     35721174 :       retval = build2 (MODIFY_EXPR, TREE_TYPE (res), res, t);
   13581     35721174 :       SET_EXPR_LOCATION (retval, loc);
   13582              : 
   13583     35721174 :       if (warn_sequence_point)
   13584      3037118 :         verify_sequence_points (retval);
   13585              :     }
   13586              : 
   13587     35743018 :   ret_stmt = build_stmt (loc, RETURN_EXPR, retval);
   13588     35743018 :   if (no_warning)
   13589           46 :     suppress_warning (ret_stmt, OPT_Wreturn_type);
   13590     35743018 :   return add_stmt (ret_stmt);
   13591              : }
   13592              : 
   13593              : struct c_switch {
   13594              :   /* The SWITCH_STMT being built.  */
   13595              :   tree switch_stmt;
   13596              : 
   13597              :   /* The original type of the testing expression, i.e. before the
   13598              :      default conversion is applied.  */
   13599              :   tree orig_type;
   13600              : 
   13601              :   /* A splay-tree mapping the low element of a case range to the high
   13602              :      element, or NULL_TREE if there is no high element.  Used to
   13603              :      determine whether or not a new case label duplicates an old case
   13604              :      label.  We need a tree, rather than simply a hash table, because
   13605              :      of the GNU case range extension.  */
   13606              :   splay_tree cases;
   13607              : 
   13608              :   /* The bindings at the point of the switch.  This is used for
   13609              :      warnings crossing decls when branching to a case label.  */
   13610              :   struct c_spot_bindings *bindings;
   13611              : 
   13612              :   /* Whether the switch includes any break statements.  */
   13613              :   bool break_stmt_seen_p;
   13614              : 
   13615              :   /* The next node on the stack.  */
   13616              :   struct c_switch *next;
   13617              : 
   13618              :   /* Remember whether the controlling expression had boolean type
   13619              :      before integer promotions for the sake of -Wswitch-bool.  */
   13620              :   bool bool_cond_p;
   13621              : };
   13622              : 
   13623              : /* A stack of the currently active switch statements.  The innermost
   13624              :    switch statement is on the top of the stack.  There is no need to
   13625              :    mark the stack for garbage collection because it is only active
   13626              :    during the processing of the body of a function, and we never
   13627              :    collect at that point.  */
   13628              : 
   13629              : struct c_switch *c_switch_stack;
   13630              : 
   13631              : /* Start a C switch statement, testing expression EXP.  Return the new
   13632              :    SWITCH_STMT.  SWITCH_LOC is the location of the `switch'.
   13633              :    SWITCH_COND_LOC is the location of the switch's condition.
   13634              :    EXPLICIT_CAST_P is true if the expression EXP has an explicit cast.  */
   13635              : 
   13636              : tree
   13637        37613 : c_start_switch (location_t switch_loc,
   13638              :                 location_t switch_cond_loc,
   13639              :                 tree exp, bool explicit_cast_p, tree switch_name)
   13640              : {
   13641        37613 :   tree orig_type = error_mark_node;
   13642        37613 :   bool bool_cond_p = false;
   13643        37613 :   struct c_switch *cs;
   13644              : 
   13645        37613 :   if (exp != error_mark_node)
   13646              :     {
   13647        37570 :       orig_type = TREE_TYPE (exp);
   13648              : 
   13649        37570 :       if (!INTEGRAL_TYPE_P (orig_type))
   13650              :         {
   13651           12 :           if (orig_type != error_mark_node)
   13652              :             {
   13653           12 :               error_at (switch_cond_loc, "switch quantity not an integer");
   13654           12 :               orig_type = error_mark_node;
   13655              :             }
   13656           12 :           exp = integer_zero_node;
   13657              :         }
   13658              :       else
   13659              :         {
   13660        37558 :           tree type = TYPE_MAIN_VARIANT (orig_type);
   13661        37558 :           tree e = exp;
   13662              : 
   13663              :           /* Warn if the condition has boolean value.  */
   13664        37561 :           while (TREE_CODE (e) == COMPOUND_EXPR)
   13665            3 :             e = TREE_OPERAND (e, 1);
   13666              : 
   13667        37533 :           if ((C_BOOLEAN_TYPE_P (type)
   13668        37533 :                || truth_value_p (TREE_CODE (e)))
   13669              :               /* Explicit cast to int suppresses this warning.  */
   13670        37580 :               && !(TREE_CODE (type) == INTEGER_TYPE
   13671              :                    && explicit_cast_p))
   13672              :             bool_cond_p = true;
   13673              : 
   13674        37558 :           if (!in_system_header_at (input_location)
   13675        37558 :               && (type == long_integer_type_node
   13676        12071 :                   || type == long_unsigned_type_node))
   13677          306 :             warning_at (switch_cond_loc,
   13678          306 :                         OPT_Wtraditional, "%<long%> switch expression not "
   13679              :                         "converted to %<int%> in ISO C");
   13680              : 
   13681        37558 :           exp = c_fully_fold (exp, false, NULL);
   13682        37558 :           exp = default_conversion (exp);
   13683              : 
   13684        37558 :           if (warn_sequence_point)
   13685         6054 :             verify_sequence_points (exp);
   13686              :         }
   13687              :     }
   13688              : 
   13689              :   /* Add this new SWITCH_STMT to the stack.  */
   13690        37613 :   cs = XNEW (struct c_switch);
   13691        37613 :   cs->switch_stmt = build_stmt (switch_loc, SWITCH_STMT, exp,
   13692              :                                 NULL_TREE, orig_type, NULL_TREE, switch_name);
   13693        37613 :   cs->orig_type = orig_type;
   13694        37613 :   cs->cases = splay_tree_new (case_compare, NULL, NULL);
   13695        37613 :   cs->bindings = c_get_switch_bindings ();
   13696        37613 :   cs->break_stmt_seen_p = false;
   13697        37613 :   cs->bool_cond_p = bool_cond_p;
   13698        37613 :   cs->next = c_switch_stack;
   13699        37613 :   c_switch_stack = cs;
   13700              : 
   13701        37613 :   return add_stmt (cs->switch_stmt);
   13702              : }
   13703              : 
   13704              : /* Process a case label at location LOC, with attributes ATTRS.  */
   13705              : 
   13706              : tree
   13707      1032914 : do_case (location_t loc, tree low_value, tree high_value, tree attrs)
   13708              : {
   13709      1032914 :   tree label = NULL_TREE;
   13710              : 
   13711      1032914 :   if (low_value && TREE_CODE (low_value) != INTEGER_CST)
   13712              :     {
   13713           87 :       low_value = c_fully_fold (low_value, false, NULL);
   13714           87 :       if (TREE_CODE (low_value) == INTEGER_CST)
   13715            9 :         pedwarn (loc, OPT_Wpedantic,
   13716              :                  "case label is not an integer constant expression");
   13717              :     }
   13718              : 
   13719      1032914 :   if (high_value && TREE_CODE (high_value) != INTEGER_CST)
   13720              :     {
   13721            0 :       high_value = c_fully_fold (high_value, false, NULL);
   13722            0 :       if (TREE_CODE (high_value) == INTEGER_CST)
   13723            0 :         pedwarn (input_location, OPT_Wpedantic,
   13724              :                  "case label is not an integer constant expression");
   13725              :     }
   13726              : 
   13727      1032914 :   if (c_switch_stack == NULL)
   13728              :     {
   13729            3 :       if (low_value)
   13730            2 :         error_at (loc, "case label not within a switch statement");
   13731              :       else
   13732            1 :         error_at (loc, "%<default%> label not within a switch statement");
   13733              :       return NULL_TREE;
   13734              :     }
   13735              : 
   13736      1032911 :   if (c_check_switch_jump_warnings (c_switch_stack->bindings,
   13737      1032911 :                                     EXPR_LOCATION (c_switch_stack->switch_stmt),
   13738              :                                     loc))
   13739              :     return NULL_TREE;
   13740              : 
   13741      1032899 :   label = c_add_case_label (loc, c_switch_stack->cases,
   13742      1032899 :                             SWITCH_STMT_COND (c_switch_stack->switch_stmt),
   13743              :                             low_value, high_value, attrs);
   13744      1032899 :   if (label == error_mark_node)
   13745          144 :     label = NULL_TREE;
   13746              :   return label;
   13747              : }
   13748              : 
   13749              : /* Finish the switch statement.  TYPE is the original type of the
   13750              :    controlling expression of the switch, or NULL_TREE.  */
   13751              : 
   13752              : void
   13753        37613 : c_finish_switch (tree body, tree type)
   13754              : {
   13755        37613 :   struct c_switch *cs = c_switch_stack;
   13756        37613 :   location_t switch_location;
   13757              : 
   13758        37613 :   SWITCH_STMT_BODY (cs->switch_stmt) = body;
   13759              : 
   13760              :   /* Emit warnings as needed.  */
   13761        37613 :   switch_location = EXPR_LOCATION (cs->switch_stmt);
   13762        43822 :   c_do_switch_warnings (cs->cases, switch_location,
   13763         6209 :                         type ? type : SWITCH_STMT_TYPE (cs->switch_stmt),
   13764        37613 :                         SWITCH_STMT_COND (cs->switch_stmt), cs->bool_cond_p);
   13765        37613 :   if (c_switch_covers_all_cases_p (cs->cases,
   13766        37613 :                                    SWITCH_STMT_TYPE (cs->switch_stmt)))
   13767        33644 :     SWITCH_STMT_ALL_CASES_P (cs->switch_stmt) = 1;
   13768        37613 :   SWITCH_STMT_NO_BREAK_P (cs->switch_stmt) = !cs->break_stmt_seen_p;
   13769              : 
   13770              :   /* Pop the stack.  */
   13771        37613 :   c_switch_stack = cs->next;
   13772        37613 :   splay_tree_delete (cs->cases);
   13773        37613 :   c_release_switch_bindings (cs->bindings);
   13774        37613 :   XDELETE (cs);
   13775        37613 : }
   13776              : 
   13777              : /* Emit an if statement.  IF_LOCUS is the location of the 'if'.  COND,
   13778              :    THEN_BLOCK and ELSE_BLOCK are expressions to be used; ELSE_BLOCK
   13779              :    may be null.  */
   13780              : 
   13781              : void
   13782      1286011 : c_finish_if_stmt (location_t if_locus, tree cond, tree then_block,
   13783              :                   tree else_block)
   13784              : {
   13785      1286011 :   tree stmt;
   13786              : 
   13787      1286011 :   stmt = build3 (COND_EXPR, void_type_node, cond, then_block, else_block);
   13788      1286011 :   SET_EXPR_LOCATION (stmt, if_locus);
   13789      1286011 :   add_stmt (stmt);
   13790      1286011 : }
   13791              : 
   13792              : tree
   13793       188695 : c_finish_bc_stmt (location_t loc, tree label, bool is_break, tree name)
   13794              : {
   13795              :   /* In switch statements break is sometimes stylistically used after
   13796              :      a return statement.  This can lead to spurious warnings about
   13797              :      control reaching the end of a non-void function when it is
   13798              :      inlined.  Note that we are calling block_may_fallthru with
   13799              :      language specific tree nodes; this works because
   13800              :      block_may_fallthru returns true when given something it does not
   13801              :      understand.  */
   13802       188695 :   bool skip = !block_may_fallthru (cur_stmt_list);
   13803              : 
   13804       188695 :   if (is_break)
   13805       175371 :     switch (in_statement & ~IN_NAMED_STMT)
   13806              :       {
   13807            9 :       case 0:
   13808            9 :         error_at (loc, "break statement not within loop or switch");
   13809            9 :         return NULL_TREE;
   13810            4 :       case IN_OMP_BLOCK:
   13811            4 :         error_at (loc, "invalid exit from OpenMP structured block");
   13812            4 :         return NULL_TREE;
   13813           12 :       case IN_OMP_FOR:
   13814           12 :         error_at (loc, "break statement used with OpenMP for loop");
   13815           12 :         return NULL_TREE;
   13816              :       case IN_ITERATION_STMT:
   13817              :       case IN_OBJC_FOREACH:
   13818              :         break;
   13819       159339 :       default:
   13820       159339 :         gcc_assert (in_statement & IN_SWITCH_STMT);
   13821       159339 :         c_switch_stack->break_stmt_seen_p = true;
   13822       159339 :         break;
   13823              :       }
   13824              :   else
   13825        13324 :     switch (in_statement & ~(IN_SWITCH_STMT | IN_NAMED_STMT))
   13826              :       {
   13827            7 :       case 0:
   13828            7 :         error_at (loc, "continue statement not within a loop");
   13829            7 :         return NULL_TREE;
   13830            4 :       case IN_OMP_BLOCK:
   13831            4 :         error_at (loc, "invalid exit from OpenMP structured block");
   13832            4 :         return NULL_TREE;
   13833              :       case IN_ITERATION_STMT:
   13834              :       case IN_OMP_FOR:
   13835              :       case IN_OBJC_FOREACH:
   13836              :         break;
   13837            0 :       default:
   13838            0 :         gcc_unreachable ();
   13839              :       }
   13840              : 
   13841       188659 :   if (skip)
   13842              :     return NULL_TREE;
   13843       188195 :   else if ((in_statement & IN_OBJC_FOREACH)
   13844            0 :            && !(is_break && (in_statement & IN_SWITCH_STMT))
   13845            0 :            && name == NULL_TREE)
   13846              :     {
   13847              :       /* The foreach expander produces low-level code using gotos instead
   13848              :          of a structured loop construct.  */
   13849            0 :       gcc_assert (label);
   13850            0 :       return add_stmt (build_stmt (loc, GOTO_EXPR, label));
   13851              :     }
   13852       188292 :   else if (name && C_DECL_LOOP_NAME (name) && C_DECL_SWITCH_NAME (name))
   13853              :     {
   13854            0 :       label = DECL_CHAIN (name);
   13855            0 :       if (!is_break)
   13856            0 :         label = DECL_CHAIN (label);
   13857              :       /* Foreach expander from some outer level.  */
   13858            0 :       return add_stmt (build_stmt (loc, GOTO_EXPR, label));
   13859              :     }
   13860       201508 :   return add_stmt (build_stmt (loc, is_break ? BREAK_STMT : CONTINUE_STMT,
   13861       188195 :                                name));
   13862              : }
   13863              : 
   13864              : /* A helper routine for c_process_expr_stmt and c_finish_stmt_expr.  */
   13865              : 
   13866              : static void
   13867      6525716 : emit_side_effect_warnings (location_t loc, tree expr)
   13868              : {
   13869      6525716 :   maybe_warn_nodiscard (loc, expr);
   13870      6525716 :   if (!warn_unused_value)
   13871              :     return;
   13872      1313184 :   if (expr == error_mark_node)
   13873              :     ;
   13874      1313109 :   else if (!TREE_SIDE_EFFECTS (expr))
   13875              :     {
   13876         6567 :       if (!VOID_TYPE_P (TREE_TYPE (expr))
   13877         6567 :           && !warning_suppressed_p (expr, OPT_Wunused_value))
   13878           28 :         warning_at (loc, OPT_Wunused_value, "statement with no effect");
   13879              :     }
   13880      1306542 :   else if (TREE_CODE (expr) == COMPOUND_EXPR)
   13881              :     {
   13882              :       tree r = expr;
   13883              :       location_t cloc = loc;
   13884        12011 :       while (TREE_CODE (r) == COMPOUND_EXPR)
   13885              :         {
   13886         6021 :           if (EXPR_HAS_LOCATION (r))
   13887         5479 :             cloc = EXPR_LOCATION (r);
   13888         6021 :           r = TREE_OPERAND (r, 1);
   13889              :         }
   13890         5990 :       if (!TREE_SIDE_EFFECTS (r)
   13891           33 :           && !VOID_TYPE_P (TREE_TYPE (r))
   13892           24 :           && !CONVERT_EXPR_P (r)
   13893           24 :           && !warning_suppressed_p (r, OPT_Wunused_value)
   13894         6002 :           && !warning_suppressed_p (expr, OPT_Wunused_value))
   13895            8 :         warning_at (cloc, OPT_Wunused_value,
   13896              :                     "right-hand operand of comma expression has no effect");
   13897              :     }
   13898              :   else
   13899      1300552 :     warn_if_unused_value (expr, loc);
   13900              : }
   13901              : 
   13902              : /* Process an expression as if it were a complete statement.  Emit
   13903              :    diagnostics, but do not call ADD_STMT.  LOC is the location of the
   13904              :    statement.  */
   13905              : 
   13906              : tree
   13907      6402268 : c_process_expr_stmt (location_t loc, tree expr)
   13908              : {
   13909      6402268 :   tree exprv;
   13910              : 
   13911      6402268 :   if (!expr)
   13912              :     return NULL_TREE;
   13913              : 
   13914      6397829 :   expr = c_fully_fold (expr, false, NULL);
   13915              : 
   13916      6397829 :   if (warn_sequence_point)
   13917      1308885 :     verify_sequence_points (expr);
   13918              : 
   13919      6397829 :   if (TREE_TYPE (expr) != error_mark_node
   13920      6395175 :       && !COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (expr))
   13921      6397829 :       && TREE_CODE (TREE_TYPE (expr)) != ARRAY_TYPE)
   13922            0 :     error_at (loc, "expression statement has incomplete type");
   13923              : 
   13924              :   /* If we're not processing a statement expression, warn about unused values.
   13925              :      Warnings for statement expressions will be emitted later, once we figure
   13926              :      out which is the result.  */
   13927      6397829 :   if (!STATEMENT_LIST_STMT_EXPR (cur_stmt_list)
   13928      6397829 :       && (warn_unused_value || warn_unused_result))
   13929      6275197 :     emit_side_effect_warnings (EXPR_LOC_OR_LOC (expr, loc), expr);
   13930              : 
   13931      6397828 :   exprv = expr;
   13932      6439272 :   while (TREE_CODE (exprv) == COMPOUND_EXPR)
   13933        41444 :     exprv = TREE_OPERAND (exprv, 1);
   13934      6409805 :   while (CONVERT_EXPR_P (exprv))
   13935        11977 :     exprv = TREE_OPERAND (exprv, 0);
   13936      6397828 :   if (DECL_P (exprv)
   13937      6398413 :       || handled_component_p (exprv)
   13938     12775414 :       || TREE_CODE (exprv) == ADDR_EXPR)
   13939        20827 :     mark_exp_read (exprv);
   13940              : 
   13941              :   /* If the expression is not of a type to which we cannot assign a line
   13942              :      number, wrap the thing in a no-op NOP_EXPR.  */
   13943      6397828 :   if (DECL_P (expr) || CONSTANT_CLASS_P (expr))
   13944              :     {
   13945        14897 :       expr = build1 (NOP_EXPR, TREE_TYPE (expr), expr);
   13946        14897 :       SET_EXPR_LOCATION (expr, loc);
   13947              :     }
   13948              : 
   13949              :   return expr;
   13950              : }
   13951              : 
   13952              : /* Emit an expression as a statement.  LOC is the location of the
   13953              :    expression.  */
   13954              : 
   13955              : tree
   13956      6095133 : c_finish_expr_stmt (location_t loc, tree expr)
   13957              : {
   13958      6095133 :   if (expr)
   13959      6080845 :     return add_stmt (c_process_expr_stmt (loc, expr));
   13960              :   else
   13961              :     return NULL;
   13962              : }
   13963              : 
   13964              : /* Do the opposite and emit a statement as an expression.  To begin,
   13965              :    create a new binding level and return it.  */
   13966              : 
   13967              : tree
   13968        35226 : c_begin_stmt_expr (void)
   13969              : {
   13970        35226 :   tree ret;
   13971              : 
   13972              :   /* We must force a BLOCK for this level so that, if it is not expanded
   13973              :      later, there is a way to turn off the entire subtree of blocks that
   13974              :      are contained in it.  */
   13975        35226 :   keep_next_level ();
   13976        35226 :   ret = c_begin_compound_stmt (true);
   13977              : 
   13978        35226 :   c_bindings_start_stmt_expr (c_switch_stack == NULL
   13979              :                               ? NULL
   13980              :                               : c_switch_stack->bindings);
   13981              : 
   13982              :   /* Mark the current statement list as belonging to a statement list.  */
   13983        35226 :   STATEMENT_LIST_STMT_EXPR (ret) = 1;
   13984              : 
   13985        35226 :   return ret;
   13986              : }
   13987              : 
   13988              : /* LOC is the location of the compound statement to which this body
   13989              :    belongs.  */
   13990              : 
   13991              : tree
   13992        35226 : c_finish_stmt_expr (location_t loc, tree body)
   13993              : {
   13994        35226 :   tree last, type, tmp, val;
   13995        35226 :   tree *last_p;
   13996              : 
   13997        35226 :   body = c_end_compound_stmt (loc, body, true);
   13998              : 
   13999        35226 :   c_bindings_end_stmt_expr (c_switch_stack == NULL
   14000              :                             ? NULL
   14001              :                             : c_switch_stack->bindings);
   14002              : 
   14003              :   /* Locate the last statement in BODY.  See c_end_compound_stmt
   14004              :      about always returning a BIND_EXPR.  */
   14005        35226 :   last_p = &BIND_EXPR_BODY (body);
   14006        35226 :   last = BIND_EXPR_BODY (body);
   14007              : 
   14008        35226 :  continue_searching:
   14009        35226 :   if (TREE_CODE (last) == STATEMENT_LIST)
   14010              :     {
   14011        26390 :       tree_stmt_iterator l = tsi_last (last);
   14012              : 
   14013        26396 :       while (!tsi_end_p (l) && TREE_CODE (tsi_stmt (l)) == DEBUG_BEGIN_STMT)
   14014            6 :         tsi_prev (&l);
   14015              : 
   14016              :       /* This can happen with degenerate cases like ({ }).  No value.  */
   14017        26390 :       if (tsi_end_p (l))
   14018          389 :         return body;
   14019              : 
   14020              :       /* If we're supposed to generate side effects warnings, process
   14021              :          all of the statements except the last.  */
   14022        26001 :       if (warn_unused_value || warn_unused_result)
   14023              :         {
   14024        26001 :           for (tree_stmt_iterator i = tsi_start (last);
   14025       276520 :                tsi_stmt (i) != tsi_stmt (l); tsi_next (&i))
   14026              :             {
   14027       250519 :               location_t tloc;
   14028       250519 :               tree t = tsi_stmt (i);
   14029              : 
   14030       250519 :               tloc = EXPR_HAS_LOCATION (t) ? EXPR_LOCATION (t) : loc;
   14031       250519 :               emit_side_effect_warnings (tloc, t);
   14032              :             }
   14033              :         }
   14034        26001 :       last_p = tsi_stmt_ptr (l);
   14035        26001 :       last = *last_p;
   14036              :     }
   14037              : 
   14038              :   /* If the end of the list is exception related, then the list was split
   14039              :      by a call to push_cleanup.  Continue searching.  */
   14040        34837 :   if (TREE_CODE (last) == TRY_FINALLY_EXPR
   14041        34837 :       || TREE_CODE (last) == TRY_CATCH_EXPR)
   14042              :     {
   14043            0 :       last_p = &TREE_OPERAND (last, 0);
   14044            0 :       last = *last_p;
   14045            0 :       goto continue_searching;
   14046              :     }
   14047              : 
   14048        34837 :   if (last == error_mark_node)
   14049              :     return last;
   14050              : 
   14051              :   /* In the case that the BIND_EXPR is not necessary, return the
   14052              :      expression out from inside it.  */
   14053        34828 :   if ((last == BIND_EXPR_BODY (body)
   14054              :        /* Skip nested debug stmts.  */
   14055        26000 :        || last == expr_first (BIND_EXPR_BODY (body)))
   14056        45888 :       && BIND_EXPR_VARS (body) == NULL)
   14057              :     {
   14058              :       /* Even if this looks constant, do not allow it in a constant
   14059              :          expression.  */
   14060        11048 :       last = c_wrap_maybe_const (last, true);
   14061              :       /* Do not warn if the return value of a statement expression is
   14062              :          unused.  */
   14063        11048 :       suppress_warning (last, OPT_Wunused);
   14064        11048 :       return last;
   14065              :     }
   14066              : 
   14067              :   /* Extract the type of said expression.  */
   14068        23780 :   type = TREE_TYPE (last);
   14069              : 
   14070              :   /* If we're not returning a value at all, then the BIND_EXPR that
   14071              :      we already have is a fine expression to return.  */
   14072        23780 :   if (!type || VOID_TYPE_P (type))
   14073              :     return body;
   14074              : 
   14075              :   /* Now that we've located the expression containing the value, it seems
   14076              :      silly to make voidify_wrapper_expr repeat the process.  Create a
   14077              :      temporary of the appropriate type and stick it in a TARGET_EXPR.  */
   14078        18456 :   tmp = create_tmp_var_raw (type);
   14079              : 
   14080              :   /* Unwrap a no-op NOP_EXPR as added by c_finish_expr_stmt.  This avoids
   14081              :      tree_expr_nonnegative_p giving up immediately.  */
   14082        18456 :   val = last;
   14083        18456 :   if (TREE_CODE (val) == NOP_EXPR
   14084        18456 :       && TREE_TYPE (val) == TREE_TYPE (TREE_OPERAND (val, 0)))
   14085         3794 :     val = TREE_OPERAND (val, 0);
   14086              : 
   14087        18456 :   *last_p = build2 (MODIFY_EXPR, void_type_node, tmp, val);
   14088        18456 :   SET_EXPR_LOCATION (*last_p, EXPR_LOCATION (last));
   14089              : 
   14090        18456 :   {
   14091        18456 :     tree t = build4 (TARGET_EXPR, type, tmp, body, NULL_TREE, NULL_TREE);
   14092        18456 :     SET_EXPR_LOCATION (t, loc);
   14093        18456 :     return t;
   14094              :   }
   14095              : }
   14096              : 
   14097              : /* Begin and end compound statements.  This is as simple as pushing
   14098              :    and popping new statement lists from the tree.  */
   14099              : 
   14100              : tree
   14101     42441108 : c_begin_compound_stmt (bool do_scope)
   14102              : {
   14103     42441108 :   tree stmt = push_stmt_list ();
   14104     42441108 :   if (do_scope)
   14105     42344922 :     push_scope ();
   14106     42441108 :   return stmt;
   14107              : }
   14108              : 
   14109              : /* End a compound statement.  STMT is the statement.  LOC is the
   14110              :    location of the compound statement-- this is usually the location
   14111              :    of the opening brace.  */
   14112              : 
   14113              : tree
   14114     42441107 : c_end_compound_stmt (location_t loc, tree stmt, bool do_scope)
   14115              : {
   14116     42441107 :   tree block = NULL;
   14117              : 
   14118     42441107 :   if (do_scope)
   14119              :     {
   14120     42344921 :       if (c_dialect_objc ())
   14121            0 :         objc_clear_super_receiver ();
   14122     42344921 :       block = pop_scope ();
   14123              :     }
   14124              : 
   14125     42441107 :   stmt = pop_stmt_list (stmt);
   14126     42441107 :   stmt = c_build_bind_expr (loc, block, stmt);
   14127              : 
   14128              :   /* If this compound statement is nested immediately inside a statement
   14129              :      expression, then force a BIND_EXPR to be created.  Otherwise we'll
   14130              :      do the wrong thing for ({ { 1; } }) or ({ 1; { } }).  In particular,
   14131              :      STATEMENT_LISTs merge, and thus we can lose track of what statement
   14132              :      was really last.  */
   14133     84882214 :   if (building_stmt_list_p ()
   14134     42441022 :       && STATEMENT_LIST_STMT_EXPR (cur_stmt_list)
   14135     42563825 :       && TREE_CODE (stmt) != BIND_EXPR)
   14136              :     {
   14137       120975 :       stmt = build3 (BIND_EXPR, void_type_node, NULL, stmt, NULL);
   14138       120975 :       TREE_SIDE_EFFECTS (stmt) = 1;
   14139       120975 :       SET_EXPR_LOCATION (stmt, loc);
   14140              :     }
   14141              : 
   14142     42441107 :   return stmt;
   14143              : }
   14144              : 
   14145              : /* Queue a cleanup.  CLEANUP is an expression/statement to be executed
   14146              :    when the current scope is exited.  EH_ONLY is true when this is not
   14147              :    meant to apply to normal control flow transfer.  */
   14148              : 
   14149              : void
   14150          131 : push_cleanup (tree decl, tree cleanup, bool eh_only)
   14151              : {
   14152          131 :   enum tree_code code;
   14153          131 :   tree stmt, list;
   14154          131 :   bool stmt_expr;
   14155              : 
   14156          131 :   code = eh_only ? TRY_CATCH_EXPR : TRY_FINALLY_EXPR;
   14157          131 :   stmt = build_stmt (DECL_SOURCE_LOCATION (decl), code, NULL, cleanup);
   14158          131 :   add_stmt (stmt);
   14159          131 :   stmt_expr = STATEMENT_LIST_STMT_EXPR (cur_stmt_list);
   14160          131 :   list = push_stmt_list ();
   14161          131 :   TREE_OPERAND (stmt, 0) = list;
   14162          131 :   STATEMENT_LIST_STMT_EXPR (list) = stmt_expr;
   14163          131 : }
   14164              : 
   14165              : /* Build a vector comparison of ARG0 and ARG1 using CODE opcode
   14166              :    into a value of TYPE type.  Comparison is done via VEC_COND_EXPR.  */
   14167              : 
   14168              : static tree
   14169       101653 : build_vec_cmp (tree_code code, tree type,
   14170              :                tree arg0, tree arg1)
   14171              : {
   14172       101653 :   tree zero_vec = build_zero_cst (type);
   14173       101653 :   tree minus_one_vec = build_minus_one_cst (type);
   14174       101653 :   tree cmp_type = truth_type_for (TREE_TYPE (arg0));
   14175       101653 :   tree cmp = build2 (code, cmp_type, arg0, arg1);
   14176       101653 :   return build3 (VEC_COND_EXPR, type, cmp, minus_one_vec, zero_vec);
   14177              : }
   14178              : 
   14179              : /* Possibly warn about an address of OP never being NULL in a comparison
   14180              :    operation CODE involving null.  */
   14181              : 
   14182              : static void
   14183        52283 : maybe_warn_for_null_address (location_t loc, tree op, tree_code code)
   14184              : {
   14185              :   /* Prevent warnings issued for macro expansion.  */
   14186        52283 :   if (!warn_address
   14187        30678 :       || warning_suppressed_p (op, OPT_Waddress)
   14188        82585 :       || from_macro_expansion_at (loc))
   14189              :     return;
   14190              : 
   14191        27555 :   if (TREE_CODE (op) == NOP_EXPR)
   14192              :     {
   14193              :       /* Allow casts to intptr_t to suppress the warning.  */
   14194         1135 :       tree type = TREE_TYPE (op);
   14195         1135 :       if (TREE_CODE (type) == INTEGER_TYPE)
   14196              :         return;
   14197         1135 :       op = TREE_OPERAND (op, 0);
   14198              :     }
   14199              : 
   14200        27555 :   if (TREE_CODE (op) == POINTER_PLUS_EXPR)
   14201              :     {
   14202              :       /* Allow a cast to void* to suppress the warning.  */
   14203           24 :       tree type = TREE_TYPE (TREE_TYPE (op));
   14204           24 :       if (VOID_TYPE_P (type))
   14205              :         return;
   14206              : 
   14207              :       /* Adding any value to a null pointer, including zero, is undefined
   14208              :          in C.  This includes the expression &p[0] where p is the null
   14209              :          pointer, although &p[0] will have been folded to p by this point
   14210              :          and so not diagnosed.  */
   14211           24 :       if (code == EQ_EXPR)
   14212           22 :         warning_at (loc, OPT_Waddress,
   14213              :                     "the comparison will always evaluate as %<false%> "
   14214              :                     "for the pointer operand in %qE must not be NULL",
   14215              :                     op);
   14216              :       else
   14217            2 :         warning_at (loc, OPT_Waddress,
   14218              :                     "the comparison will always evaluate as %<true%> "
   14219              :                     "for the pointer operand in %qE must not be NULL",
   14220              :                     op);
   14221              : 
   14222              :       return;
   14223              :     }
   14224              : 
   14225        27531 :   if (TREE_CODE (op) != ADDR_EXPR)
   14226              :     return;
   14227              : 
   14228          254 :   op = TREE_OPERAND (op, 0);
   14229              : 
   14230          254 :   if (TREE_CODE (op) == IMAGPART_EXPR
   14231          254 :       || TREE_CODE (op) == REALPART_EXPR)
   14232              :     {
   14233              :       /* The address of either complex part may not be null.  */
   14234           14 :       if (code == EQ_EXPR)
   14235            9 :         warning_at (loc, OPT_Waddress,
   14236              :                     "the comparison will always evaluate as %<false%> "
   14237              :                     "for the address of %qE will never be NULL",
   14238              :                     op);
   14239              :       else
   14240            5 :         warning_at (loc, OPT_Waddress,
   14241              :                     "the comparison will always evaluate as %<true%> "
   14242              :                     "for the address of %qE will never be NULL",
   14243              :                     op);
   14244              :       return;
   14245              :     }
   14246              : 
   14247              :   /* Set to true in the loop below if OP dereferences is operand.
   14248              :      In such a case the ultimate target need not be a decl for
   14249              :      the null [in]equality test to be constant.  */
   14250              :   bool deref = false;
   14251              : 
   14252              :   /* Get the outermost array or object, or member.  */
   14253          294 :   while (handled_component_p (op))
   14254              :     {
   14255           72 :       if (TREE_CODE (op) == COMPONENT_REF)
   14256              :         {
   14257              :           /* Get the member (its address is never null).  */
   14258           18 :           op = TREE_OPERAND (op, 1);
   14259           18 :           break;
   14260              :         }
   14261              : 
   14262              :       /* Get the outer array/object to refer to in the warning.  */
   14263           54 :       op = TREE_OPERAND (op, 0);
   14264           54 :       deref = true;
   14265              :     }
   14266              : 
   14267          192 :   if ((!deref && !decl_with_nonnull_addr_p (op))
   14268          371 :       || from_macro_expansion_at (loc))
   14269              :     return;
   14270              : 
   14271          131 :   bool w;
   14272          131 :   if (code == EQ_EXPR)
   14273           93 :     w = warning_at (loc, OPT_Waddress,
   14274              :                     "the comparison will always evaluate as %<false%> "
   14275              :                     "for the address of %qE will never be NULL",
   14276              :                     op);
   14277              :   else
   14278           38 :     w = warning_at (loc, OPT_Waddress,
   14279              :                     "the comparison will always evaluate as %<true%> "
   14280              :                     "for the address of %qE will never be NULL",
   14281              :                     op);
   14282              : 
   14283          131 :   if (w && DECL_P (op))
   14284          120 :     inform (DECL_SOURCE_LOCATION (op), "%qD declared here", op);
   14285              : }
   14286              : 
   14287              : /* Build a binary-operation expression without default conversions.
   14288              :    CODE is the kind of expression to build.
   14289              :    LOCATION is the operator's location.
   14290              :    This function differs from `build' in several ways:
   14291              :    the data type of the result is computed and recorded in it,
   14292              :    warnings are generated if arg data types are invalid,
   14293              :    special handling for addition and subtraction of pointers is known,
   14294              :    and some optimization is done (operations on narrow ints
   14295              :    are done in the narrower type when that gives the same result).
   14296              :    Constant folding is also done before the result is returned.
   14297              : 
   14298              :    Note that the operands will never have enumeral types, or function
   14299              :    or array types, because either they will have the default conversions
   14300              :    performed or they have both just been converted to some other type in which
   14301              :    the arithmetic is to be done.  */
   14302              : 
   14303              : tree
   14304     17007845 : build_binary_op (location_t location, enum tree_code code,
   14305              :                  tree orig_op0, tree orig_op1, bool convert_p)
   14306              : {
   14307     17007845 :   tree type0, type1, orig_type0, orig_type1;
   14308     17007845 :   tree eptype;
   14309     17007845 :   enum tree_code code0, code1;
   14310     17007845 :   tree op0, op1;
   14311     17007845 :   tree ret = error_mark_node;
   14312     17007845 :   const char *invalid_op_diag;
   14313     17007845 :   bool op0_int_operands, op1_int_operands;
   14314     17007845 :   bool int_const, int_const_or_overflow, int_operands;
   14315              : 
   14316              :   /* Expression code to give to the expression when it is built.
   14317              :      Normally this is CODE, which is what the caller asked for,
   14318              :      but in some special cases we change it.  */
   14319     17007845 :   enum tree_code resultcode = code;
   14320              : 
   14321              :   /* Data type in which the computation is to be performed.
   14322              :      In the simplest cases this is the common type of the arguments.  */
   14323     17007845 :   tree result_type = NULL;
   14324              : 
   14325              :   /* When the computation is in excess precision, the type of the
   14326              :      final EXCESS_PRECISION_EXPR.  */
   14327     17007845 :   tree semantic_result_type = NULL;
   14328              : 
   14329              :   /* Nonzero means operands have already been type-converted
   14330              :      in whatever way is necessary.
   14331              :      Zero means they need to be converted to RESULT_TYPE.  */
   14332     17007845 :   int converted = 0;
   14333              : 
   14334              :   /* Nonzero means create the expression with this type, rather than
   14335              :      RESULT_TYPE.  */
   14336     17007845 :   tree build_type = NULL_TREE;
   14337              : 
   14338              :   /* Nonzero means after finally constructing the expression
   14339              :      convert it to this type.  */
   14340     17007845 :   tree final_type = NULL_TREE;
   14341              : 
   14342              :   /* Nonzero if this is an operation like MIN or MAX which can
   14343              :      safely be computed in short if both args are promoted shorts.
   14344              :      Also implies COMMON.
   14345              :      -1 indicates a bitwise operation; this makes a difference
   14346              :      in the exact conditions for when it is safe to do the operation
   14347              :      in a narrower mode.  */
   14348     17007845 :   int shorten = 0;
   14349              : 
   14350              :   /* Nonzero if this is a comparison operation;
   14351              :      if both args are promoted shorts, compare the original shorts.
   14352              :      Also implies COMMON.  */
   14353     17007845 :   int short_compare = 0;
   14354              : 
   14355              :   /* Nonzero if this is a right-shift operation, which can be computed on the
   14356              :      original short and then promoted if the operand is a promoted short.  */
   14357     17007845 :   int short_shift = 0;
   14358              : 
   14359              :   /* Nonzero means set RESULT_TYPE to the common type of the args.  */
   14360     17007845 :   int common = 0;
   14361              : 
   14362              :   /* True means types are compatible as far as ObjC is concerned.  */
   14363     17007845 :   bool objc_ok;
   14364              : 
   14365              :   /* True means this is an arithmetic operation that may need excess
   14366              :      precision.  */
   14367     17007845 :   bool may_need_excess_precision;
   14368              : 
   14369              :   /* True means this is a boolean operation that converts both its
   14370              :      operands to truth-values.  */
   14371     17007845 :   bool boolean_op = false;
   14372              : 
   14373              :   /* Remember whether we're doing / or %.  */
   14374     17007845 :   bool doing_div_or_mod = false;
   14375              : 
   14376              :   /* Remember whether we're doing << or >>.  */
   14377     17007845 :   bool doing_shift = false;
   14378              : 
   14379              :   /* Tree holding instrumentation expression.  */
   14380     17007845 :   tree instrument_expr = NULL;
   14381              : 
   14382     17007845 :   if (location == UNKNOWN_LOCATION)
   14383           80 :     location = input_location;
   14384              : 
   14385     17007845 :   op0 = orig_op0;
   14386     17007845 :   op1 = orig_op1;
   14387              : 
   14388     17007845 :   op0_int_operands = EXPR_INT_CONST_OPERANDS (orig_op0);
   14389              :   if (op0_int_operands)
   14390      8233622 :     op0 = remove_c_maybe_const_expr (op0);
   14391     17007845 :   op1_int_operands = EXPR_INT_CONST_OPERANDS (orig_op1);
   14392              :   if (op1_int_operands)
   14393     11536871 :     op1 = remove_c_maybe_const_expr (op1);
   14394     28544716 :   int_operands = (op0_int_operands && op1_int_operands);
   14395     11536871 :   if (int_operands)
   14396              :     {
   14397     16108703 :       int_const_or_overflow = (TREE_CODE (orig_op0) == INTEGER_CST
   14398      8069522 :                                && TREE_CODE (orig_op1) == INTEGER_CST);
   14399      8039181 :       int_const = (int_const_or_overflow
   14400      8039181 :                    && !TREE_OVERFLOW (orig_op0)
   14401      8039112 :                    && !TREE_OVERFLOW (orig_op1));
   14402              :     }
   14403              :   else
   14404              :     int_const = int_const_or_overflow = false;
   14405              : 
   14406              :   /* Do not apply default conversion in mixed vector/scalar expression.  */
   14407     17007845 :   if (convert_p
   14408     17007845 :       && VECTOR_TYPE_P (TREE_TYPE (op0)) == VECTOR_TYPE_P (TREE_TYPE (op1)))
   14409              :     {
   14410     10219442 :       op0 = default_conversion (op0);
   14411     10219442 :       op1 = default_conversion (op1);
   14412              :     }
   14413              : 
   14414     17007845 :   orig_type0 = type0 = TREE_TYPE (op0);
   14415              : 
   14416     17007845 :   orig_type1 = type1 = TREE_TYPE (op1);
   14417              : 
   14418              :   /* The expression codes of the data types of the arguments tell us
   14419              :      whether the arguments are integers, floating, pointers, etc.  */
   14420     17007845 :   code0 = TREE_CODE (type0);
   14421     17007845 :   code1 = TREE_CODE (type1);
   14422              : 
   14423              :   /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
   14424     17007847 :   STRIP_TYPE_NOPS (op0);
   14425     17007848 :   STRIP_TYPE_NOPS (op1);
   14426              : 
   14427              :   /* If an error was already reported for one of the arguments,
   14428              :      avoid reporting another error.  */
   14429              : 
   14430     17007845 :   if (code0 == ERROR_MARK || code1 == ERROR_MARK)
   14431          710 :     return error_mark_node;
   14432              : 
   14433     17007135 :   if (code0 == POINTER_TYPE
   14434     17007135 :       && reject_gcc_builtin (op0, EXPR_LOCATION (orig_op0)))
   14435           11 :     return error_mark_node;
   14436              : 
   14437     17007124 :   if (code1 == POINTER_TYPE
   14438     17007124 :       && reject_gcc_builtin (op1, EXPR_LOCATION (orig_op1)))
   14439           11 :     return error_mark_node;
   14440              : 
   14441     34014226 :   if ((invalid_op_diag
   14442     17007113 :        = targetm.invalid_binary_op (code, type0, type1)))
   14443              :     {
   14444            0 :       error_at (location, invalid_op_diag);
   14445            0 :       return error_mark_node;
   14446              :     }
   14447              : 
   14448     17007113 :   switch (code)
   14449              :     {
   14450              :     case PLUS_EXPR:
   14451              :     case MINUS_EXPR:
   14452              :     case MULT_EXPR:
   14453              :     case TRUNC_DIV_EXPR:
   14454              :     case CEIL_DIV_EXPR:
   14455              :     case FLOOR_DIV_EXPR:
   14456              :     case ROUND_DIV_EXPR:
   14457              :     case EXACT_DIV_EXPR:
   14458              :       may_need_excess_precision = true;
   14459              :       break;
   14460              : 
   14461      2766449 :     case EQ_EXPR:
   14462      2766449 :     case NE_EXPR:
   14463      2766449 :     case LE_EXPR:
   14464      2766449 :     case GE_EXPR:
   14465      2766449 :     case LT_EXPR:
   14466      2766449 :     case GT_EXPR:
   14467              :       /* Excess precision for implicit conversions of integers to
   14468              :          floating point in C11 and later.  */
   14469      2766449 :       may_need_excess_precision = (flag_isoc11
   14470      2766449 :                                    && (ANY_INTEGRAL_TYPE_P (type0)
   14471       488211 :                                        || ANY_INTEGRAL_TYPE_P (type1)));
   14472              :       break;
   14473              : 
   14474              :     default:
   14475     17007113 :       may_need_excess_precision = false;
   14476              :       break;
   14477              :     }
   14478     17007113 :   if (TREE_CODE (op0) == EXCESS_PRECISION_EXPR)
   14479              :     {
   14480          184 :       op0 = TREE_OPERAND (op0, 0);
   14481          184 :       type0 = TREE_TYPE (op0);
   14482              :     }
   14483     17006929 :   else if (may_need_excess_precision
   14484     17006929 :            && (eptype = excess_precision_type (type0)) != NULL_TREE)
   14485              :     {
   14486          778 :       type0 = eptype;
   14487          778 :       op0 = convert (eptype, op0);
   14488              :     }
   14489     17007113 :   if (TREE_CODE (op1) == EXCESS_PRECISION_EXPR)
   14490              :     {
   14491          896 :       op1 = TREE_OPERAND (op1, 0);
   14492          896 :       type1 = TREE_TYPE (op1);
   14493              :     }
   14494     17006217 :   else if (may_need_excess_precision
   14495     17006217 :            && (eptype = excess_precision_type (type1)) != NULL_TREE)
   14496              :     {
   14497          598 :       type1 = eptype;
   14498          598 :       op1 = convert (eptype, op1);
   14499              :     }
   14500              : 
   14501     17007113 :   objc_ok = objc_compare_types (type0, type1, -3, NULL_TREE);
   14502              : 
   14503              :   /* In case when one of the operands of the binary operation is
   14504              :      a vector and another is a scalar -- convert scalar to vector.  */
   14505     18596900 :   if ((gnu_vector_type_p (type0) && code1 != VECTOR_TYPE)
   14506     18594931 :       || (gnu_vector_type_p (type1) && code0 != VECTOR_TYPE))
   14507              :     {
   14508         2595 :       enum stv_conv convert_flag = scalar_to_vector (location, code, orig_op0,
   14509              :                                                      orig_op1, true);
   14510              : 
   14511         2595 :       switch (convert_flag)
   14512              :         {
   14513           12 :           case stv_error:
   14514           12 :             return error_mark_node;
   14515          613 :           case stv_firstarg:
   14516          613 :             {
   14517          613 :               bool maybe_const = true;
   14518          613 :               tree sc;
   14519          613 :               sc = c_fully_fold (op0, false, &maybe_const);
   14520          613 :               sc = save_expr (sc);
   14521          613 :               sc = convert (TREE_TYPE (type1), sc);
   14522          613 :               op0 = build_vector_from_val (type1, sc);
   14523          613 :               if (!maybe_const)
   14524           93 :                 op0 = c_wrap_maybe_const (op0, true);
   14525          613 :               orig_type0 = type0 = TREE_TYPE (op0);
   14526          613 :               code0 = TREE_CODE (type0);
   14527          613 :               converted = 1;
   14528          613 :               break;
   14529              :             }
   14530         1102 :           case stv_secondarg:
   14531         1102 :             {
   14532         1102 :               bool maybe_const = true;
   14533         1102 :               tree sc;
   14534         1102 :               sc = c_fully_fold (op1, false, &maybe_const);
   14535         1102 :               sc = save_expr (sc);
   14536         1102 :               sc = convert (TREE_TYPE (type0), sc);
   14537         1102 :               op1 = build_vector_from_val (type0, sc);
   14538         1102 :               if (!maybe_const)
   14539           38 :                 op1 = c_wrap_maybe_const (op1, true);
   14540         1102 :               orig_type1 = type1 = TREE_TYPE (op1);
   14541         1102 :               code1 = TREE_CODE (type1);
   14542         1102 :               converted = 1;
   14543         1102 :               break;
   14544              :             }
   14545              :           default:
   14546              :             break;
   14547              :         }
   14548              :     }
   14549              : 
   14550     17007101 :   switch (code)
   14551              :     {
   14552      8724952 :     case PLUS_EXPR:
   14553              :       /* Handle the pointer + int case.  */
   14554      8724952 :       if (code0 == POINTER_TYPE
   14555      1259238 :           && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
   14556              :         {
   14557      1259232 :           ret = pointer_int_sum (location, PLUS_EXPR, op0, op1);
   14558      1259232 :           goto return_build_binary_op;
   14559              :         }
   14560      7465720 :       else if (code1 == POINTER_TYPE
   14561         1539 :                && (code0 == INTEGER_TYPE || code0 == BITINT_TYPE))
   14562              :         {
   14563         1533 :           ret = pointer_int_sum (location, PLUS_EXPR, op1, op0);
   14564         1533 :           goto return_build_binary_op;
   14565              :         }
   14566              :       else
   14567              :         common = 1;
   14568              :       break;
   14569              : 
   14570       801527 :     case MINUS_EXPR:
   14571              :       /* Subtraction of two similar pointers.
   14572              :          We must subtract them as integers, then divide by object size.  */
   14573       801527 :       if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
   14574       801527 :           && comp_target_types (location, type0, type1))
   14575              :         {
   14576         3730 :           ret = pointer_diff (location, op0, op1, &instrument_expr);
   14577         3730 :           goto return_build_binary_op;
   14578              :         }
   14579              :       /* Handle pointer minus int.  Just like pointer plus int.  */
   14580       797797 :       else if (code0 == POINTER_TYPE
   14581        16971 :                && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
   14582              :         {
   14583        16959 :           ret = pointer_int_sum (location, MINUS_EXPR, op0, op1);
   14584        16959 :           goto return_build_binary_op;
   14585              :         }
   14586              :       else
   14587              :         common = 1;
   14588              :       break;
   14589              : 
   14590              :     case MULT_EXPR:
   14591              :       common = 1;
   14592              :       break;
   14593              : 
   14594       276367 :     case TRUNC_DIV_EXPR:
   14595       276367 :     case CEIL_DIV_EXPR:
   14596       276367 :     case FLOOR_DIV_EXPR:
   14597       276367 :     case ROUND_DIV_EXPR:
   14598       276367 :     case EXACT_DIV_EXPR:
   14599       276367 :       doing_div_or_mod = true;
   14600       276367 :       warn_for_div_by_zero (location, op1);
   14601              : 
   14602       276366 :       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
   14603        49929 :            || code0 == FIXED_POINT_TYPE || code0 == BITINT_TYPE
   14604        47914 :            || code0 == COMPLEX_TYPE
   14605        45859 :            || gnu_vector_type_p (type0))
   14606       326294 :           && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
   14607        47488 :               || code1 == FIXED_POINT_TYPE || code1 == BITINT_TYPE
   14608        47321 :               || code1 == COMPLEX_TYPE
   14609        45861 :               || gnu_vector_type_p (type1)))
   14610              :         {
   14611       276362 :           enum tree_code tcode0 = code0, tcode1 = code1;
   14612              : 
   14613       276362 :           if (code0 == COMPLEX_TYPE || code0 == VECTOR_TYPE)
   14614        47913 :             tcode0 = TREE_CODE (TREE_TYPE (TREE_TYPE (op0)));
   14615       276362 :           if (code1 == COMPLEX_TYPE || code1 == VECTOR_TYPE)
   14616        47318 :             tcode1 = TREE_CODE (TREE_TYPE (TREE_TYPE (op1)));
   14617              : 
   14618       276362 :           if (!(((tcode0 == INTEGER_TYPE || tcode0 == BITINT_TYPE
   14619        69992 :                   || (tcode0 == ENUMERAL_TYPE && code0 == VECTOR_TYPE))
   14620       206371 :                  && (tcode1 == INTEGER_TYPE || tcode1 == BITINT_TYPE
   14621        12988 :                      || (tcode1 == ENUMERAL_TYPE && code1 == VECTOR_TYPE)))
   14622        82978 :                 || (tcode0 == FIXED_POINT_TYPE && tcode1 == FIXED_POINT_TYPE)))
   14623              :             resultcode = RDIV_EXPR;
   14624              :           else
   14625              :             /* Although it would be tempting to shorten always here, that
   14626              :                loses on some targets, since the modulo instruction is
   14627              :                undefined if the quotient can't be represented in the
   14628              :                computation mode.  We shorten only if unsigned or if
   14629              :                dividing by something we know != -1.  */
   14630       193384 :             shorten = may_shorten_divmod (op0, op1);
   14631              :           common = 1;
   14632              :         }
   14633              :       break;
   14634              : 
   14635      1600659 :     case BIT_AND_EXPR:
   14636      1600659 :     case BIT_IOR_EXPR:
   14637      1600659 :     case BIT_XOR_EXPR:
   14638      1600659 :       if ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE)
   14639      1061866 :           && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
   14640              :         shorten = -1;
   14641              :       /* Allow vector types which are not floating point types.   */
   14642       538829 :       else if (gnu_vector_type_p (type0)
   14643       538752 :                && gnu_vector_type_p (type1)
   14644       538752 :                && !VECTOR_FLOAT_TYPE_P (type0)
   14645      1077578 :                && !VECTOR_FLOAT_TYPE_P (type1))
   14646              :         common = 1;
   14647              :       break;
   14648              : 
   14649        59006 :     case TRUNC_MOD_EXPR:
   14650        59006 :     case FLOOR_MOD_EXPR:
   14651        59006 :       doing_div_or_mod = true;
   14652        59006 :       warn_for_div_by_zero (location, op1);
   14653              : 
   14654        59006 :       if (gnu_vector_type_p (type0)
   14655          301 :           && gnu_vector_type_p (type1)
   14656          301 :           && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
   14657        59307 :           && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE)
   14658              :         common = 1;
   14659        58705 :       else if ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE)
   14660        58704 :                && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
   14661              :         {
   14662              :           /* Although it would be tempting to shorten always here, that loses
   14663              :              on some targets, since the modulo instruction is undefined if the
   14664              :              quotient can't be represented in the computation mode.  We shorten
   14665              :              only if unsigned or if dividing by something we know != -1.  */
   14666        58704 :           shorten = may_shorten_divmod (op0, op1);
   14667        58704 :           common = 1;
   14668              :         }
   14669              :       break;
   14670              : 
   14671       513708 :     case TRUTH_ANDIF_EXPR:
   14672       513708 :     case TRUTH_ORIF_EXPR:
   14673       513708 :     case TRUTH_AND_EXPR:
   14674       513708 :     case TRUTH_OR_EXPR:
   14675       513708 :     case TRUTH_XOR_EXPR:
   14676       513708 :       if ((code0 == INTEGER_TYPE || code0 == POINTER_TYPE
   14677            0 :            || code0 == REAL_TYPE || code0 == COMPLEX_TYPE
   14678            0 :            || code0 == FIXED_POINT_TYPE || code0 == NULLPTR_TYPE
   14679            0 :            || code0 == BITINT_TYPE)
   14680       513708 :           && (code1 == INTEGER_TYPE || code1 == POINTER_TYPE
   14681          165 :               || code1 == REAL_TYPE || code1 == COMPLEX_TYPE
   14682           24 :               || code1 == FIXED_POINT_TYPE || code1 == NULLPTR_TYPE
   14683           22 :               || code1 == BITINT_TYPE))
   14684              :         {
   14685              :           /* Result of these operations is always an int,
   14686              :              but that does not mean the operands should be
   14687              :              converted to ints!  */
   14688       513708 :           result_type = integer_type_node;
   14689       513708 :           if (op0_int_operands)
   14690              :             {
   14691       110465 :               op0 = c_objc_common_truthvalue_conversion (location, orig_op0);
   14692       110465 :               op0 = remove_c_maybe_const_expr (op0);
   14693              :             }
   14694              :           else
   14695       403243 :             op0 = c_objc_common_truthvalue_conversion (location, op0);
   14696       513708 :           if (op1_int_operands)
   14697              :             {
   14698        71433 :               op1 = c_objc_common_truthvalue_conversion (location, orig_op1);
   14699        71433 :               op1 = remove_c_maybe_const_expr (op1);
   14700              :             }
   14701              :           else
   14702       442275 :             op1 = c_objc_common_truthvalue_conversion (location, op1);
   14703              :           converted = 1;
   14704              :           boolean_op = true;
   14705              :         }
   14706       513708 :       if (code == TRUTH_ANDIF_EXPR)
   14707              :         {
   14708       250626 :           int_const_or_overflow = (int_operands
   14709        63243 :                                    && TREE_CODE (orig_op0) == INTEGER_CST
   14710       250642 :                                    && (op0 == truthvalue_false_node
   14711        13185 :                                        || TREE_CODE (orig_op1) == INTEGER_CST));
   14712              :           int_const = (int_const_or_overflow
   14713        63216 :                        && !TREE_OVERFLOW (orig_op0)
   14714        63216 :                        && (op0 == truthvalue_false_node
   14715        13169 :                            || !TREE_OVERFLOW (orig_op1)));
   14716              :         }
   14717       326298 :       else if (code == TRUTH_ORIF_EXPR)
   14718              :         {
   14719       332978 :           int_const_or_overflow = (int_operands
   14720         6831 :                                    && TREE_CODE (orig_op0) == INTEGER_CST
   14721       333001 :                                    && (op0 == truthvalue_true_node
   14722         2146 :                                        || TREE_CODE (orig_op1) == INTEGER_CST));
   14723              :           int_const = (int_const_or_overflow
   14724         6801 :                        && !TREE_OVERFLOW (orig_op0)
   14725         6801 :                        && (op0 == truthvalue_true_node
   14726         2123 :                            || !TREE_OVERFLOW (orig_op1)));
   14727              :         }
   14728              :       break;
   14729              : 
   14730              :       /* Shift operations: result has same type as first operand;
   14731              :          always convert second operand to int.
   14732              :          Also set SHORT_SHIFT if shifting rightward.  */
   14733              : 
   14734       234053 :     case RSHIFT_EXPR:
   14735       234053 :       if (gnu_vector_type_p (type0)
   14736          837 :           && gnu_vector_type_p (type1)
   14737          258 :           && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
   14738          256 :           && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE
   14739       234309 :           && known_eq (TYPE_VECTOR_SUBPARTS (type0),
   14740              :                        TYPE_VECTOR_SUBPARTS (type1)))
   14741              :         {
   14742              :           result_type = type0;
   14743              :           converted = 1;
   14744              :         }
   14745       233799 :       else if ((code0 == INTEGER_TYPE || code0 == FIXED_POINT_TYPE
   14746         1272 :                 || code0 == BITINT_TYPE
   14747          587 :                 || (gnu_vector_type_p (type0)
   14748          583 :                     && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE))
   14749       235064 :                && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
   14750              :         {
   14751       233790 :           doing_shift = true;
   14752       233790 :           if (TREE_CODE (op1) == INTEGER_CST)
   14753              :             {
   14754       204172 :               if (tree_int_cst_sgn (op1) < 0)
   14755              :                 {
   14756          269 :                   int_const = false;
   14757          269 :                   if (c_inhibit_evaluation_warnings == 0)
   14758          129 :                     warning_at (location, OPT_Wshift_count_negative,
   14759              :                                 "right shift count is negative");
   14760              :                 }
   14761       203903 :               else if (code0 == VECTOR_TYPE)
   14762              :                 {
   14763          479 :                   if (compare_tree_int (op1,
   14764          479 :                                         TYPE_PRECISION (TREE_TYPE (type0)))
   14765              :                       >= 0)
   14766              :                     {
   14767           16 :                       int_const = false;
   14768           16 :                       if (c_inhibit_evaluation_warnings == 0)
   14769           16 :                         warning_at (location, OPT_Wshift_count_overflow,
   14770              :                                     "right shift count >= width of vector element");
   14771              :                     }
   14772              :                 }
   14773              :               else
   14774              :                 {
   14775       203424 :                   if (!integer_zerop (op1))
   14776       203062 :                     short_shift = 1;
   14777              : 
   14778       203424 :                   if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0)
   14779              :                     {
   14780          586 :                       int_const = false;
   14781          586 :                       if (c_inhibit_evaluation_warnings == 0)
   14782           52 :                         warning_at (location, OPT_Wshift_count_overflow,
   14783              :                                     "right shift count >= width of type");
   14784              :                     }
   14785              :                 }
   14786              :             }
   14787              : 
   14788              :           /* Use the type of the value to be shifted.  */
   14789              :           result_type = type0;
   14790              :           /* Avoid converting op1 to result_type later.  */
   14791              :           converted = 1;
   14792              :         }
   14793              :       break;
   14794              : 
   14795       808740 :     case LSHIFT_EXPR:
   14796       808740 :       if (gnu_vector_type_p (type0)
   14797          599 :           && gnu_vector_type_p (type1)
   14798          316 :           && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
   14799          314 :           && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE
   14800       809053 :           && known_eq (TYPE_VECTOR_SUBPARTS (type0),
   14801              :                        TYPE_VECTOR_SUBPARTS (type1)))
   14802              :         {
   14803              :           result_type = type0;
   14804              :           converted = 1;
   14805              :         }
   14806       808429 :       else if ((code0 == INTEGER_TYPE || code0 == FIXED_POINT_TYPE
   14807          928 :                 || code0 == BITINT_TYPE
   14808          294 :                 || (gnu_vector_type_p (type0)
   14809          288 :                     && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE))
   14810       809348 :                && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
   14811              :         {
   14812       808415 :           doing_shift = true;
   14813       808415 :           if (TREE_CODE (op0) == INTEGER_CST
   14814       441797 :               && tree_int_cst_sgn (op0) < 0
   14815       809164 :               && !TYPE_OVERFLOW_WRAPS (type0))
   14816              :             {
   14817              :               /* Don't reject a left shift of a negative value in a context
   14818              :                  where a constant expression is needed in C90.  */
   14819          712 :               if (flag_isoc99)
   14820          666 :                 int_const = false;
   14821          712 :               if (c_inhibit_evaluation_warnings == 0)
   14822          712 :                 warning_at (location, OPT_Wshift_negative_value,
   14823              :                             "left shift of negative value");
   14824              :             }
   14825       808415 :           if (TREE_CODE (op1) == INTEGER_CST)
   14826              :             {
   14827       735626 :               if (tree_int_cst_sgn (op1) < 0)
   14828              :                 {
   14829          313 :                   int_const = false;
   14830          313 :                   if (c_inhibit_evaluation_warnings == 0)
   14831          135 :                     warning_at (location, OPT_Wshift_count_negative,
   14832              :                                 "left shift count is negative");
   14833              :                 }
   14834       735313 :               else if (code0 == VECTOR_TYPE)
   14835              :                 {
   14836          216 :                   if (compare_tree_int (op1,
   14837          216 :                                         TYPE_PRECISION (TREE_TYPE (type0)))
   14838              :                       >= 0)
   14839              :                     {
   14840            6 :                       int_const = false;
   14841            6 :                       if (c_inhibit_evaluation_warnings == 0)
   14842            6 :                         warning_at (location, OPT_Wshift_count_overflow,
   14843              :                                     "left shift count >= width of vector element");
   14844              :                     }
   14845              :                 }
   14846       735097 :               else if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0)
   14847              :                 {
   14848        29733 :                   int_const = false;
   14849        29733 :                   if (c_inhibit_evaluation_warnings == 0)
   14850          113 :                     warning_at (location, OPT_Wshift_count_overflow,
   14851              :                                 "left shift count >= width of type");
   14852              :                 }
   14853       705364 :               else if (TREE_CODE (op0) == INTEGER_CST
   14854       367846 :                        && maybe_warn_shift_overflow (location, op0, op1)
   14855       705992 :                        && flag_isoc99)
   14856              :                 int_const = false;
   14857              :             }
   14858              : 
   14859              :           /* Use the type of the value to be shifted.  */
   14860              :           result_type = type0;
   14861              :           /* Avoid converting op1 to result_type later.  */
   14862              :           converted = 1;
   14863              :         }
   14864              :       break;
   14865              : 
   14866      1754134 :     case EQ_EXPR:
   14867      1754134 :     case NE_EXPR:
   14868      1754134 :       if (gnu_vector_type_p (type0) && gnu_vector_type_p (type1))
   14869              :         {
   14870        42153 :           tree intt;
   14871        42153 :           if (!vector_types_compatible_elements_p (type0, type1))
   14872              :             {
   14873            4 :               error_at (location, "comparing vectors with different "
   14874              :                                   "element types");
   14875            4 :               return error_mark_node;
   14876              :             }
   14877              : 
   14878        42149 :           if (maybe_ne (TYPE_VECTOR_SUBPARTS (type0),
   14879        84298 :                         TYPE_VECTOR_SUBPARTS (type1)))
   14880              :             {
   14881            1 :               error_at (location, "comparing vectors with different "
   14882              :                                   "number of elements");
   14883            1 :               return error_mark_node;
   14884              :             }
   14885              : 
   14886              :           /* It's not precisely specified how the usual arithmetic
   14887              :              conversions apply to the vector types.  Here, we use
   14888              :              the unsigned type if one of the operands is signed and
   14889              :              the other one is unsigned.  */
   14890        42148 :           if (TYPE_UNSIGNED (type0) != TYPE_UNSIGNED (type1))
   14891              :             {
   14892            4 :               if (!TYPE_UNSIGNED (type0))
   14893            4 :                 op0 = build1 (VIEW_CONVERT_EXPR, type1, op0);
   14894              :               else
   14895            0 :                 op1 = build1 (VIEW_CONVERT_EXPR, type0, op1);
   14896            4 :               warning_at (location, OPT_Wsign_compare, "comparison between "
   14897              :                           "types %qT and %qT", type0, type1);
   14898              :             }
   14899              : 
   14900              :           /* Always construct signed integer vector type.  */
   14901        42148 :           if (VECTOR_BOOLEAN_TYPE_P (type0) && VECTOR_BOOLEAN_TYPE_P (type1))
   14902              :             result_type = type0;
   14903              :           else
   14904              :             {
   14905        42148 :               auto nelts = TYPE_VECTOR_SUBPARTS (type0);
   14906              : 
   14907       126444 :               intt = c_common_type_for_size (GET_MODE_BITSIZE
   14908        84296 :                                              (SCALAR_TYPE_MODE
   14909              :                                                 (TREE_TYPE (type0))), 0);
   14910        42148 :               if (!intt)
   14911              :                 {
   14912            0 :                   error_at (location, "could not find an integer type "
   14913              :                                       "of the same size as %qT",
   14914            0 :                             TREE_TYPE (type0));
   14915            0 :                   return error_mark_node;
   14916              :                 }
   14917        42148 :               result_type = build_opaque_vector_type (intt, nelts);
   14918              :             }
   14919        42148 :           converted = 1;
   14920        42148 :           ret = build_vec_cmp (resultcode, result_type, op0, op1);
   14921        42148 :           goto return_build_binary_op;
   14922              :         }
   14923      1711981 :       if (FLOAT_TYPE_P (type0) || FLOAT_TYPE_P (type1))
   14924       254979 :         warning_at (location,
   14925       254979 :                     OPT_Wfloat_equal,
   14926              :                     "comparing floating-point with %<==%> or %<!=%> is unsafe");
   14927              :       /* Result of comparison is always int,
   14928              :          but don't convert the args to int!  */
   14929      1711981 :       build_type = integer_type_node;
   14930      1711981 :       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == BITINT_TYPE
   14931       159235 :            || code0 == FIXED_POINT_TYPE || code0 == COMPLEX_TYPE)
   14932      1588654 :           && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
   14933              :               || code1 == BITINT_TYPE
   14934              :               || code1 == FIXED_POINT_TYPE || code1 == COMPLEX_TYPE))
   14935              :         short_compare = 1;
   14936       123593 :       else if (code0 == POINTER_TYPE
   14937       123593 :                && (code1 == NULLPTR_TYPE
   14938       123210 :                    || null_pointer_constant_p (orig_op1)))
   14939              :         {
   14940        51989 :           maybe_warn_for_null_address (location, op0, code);
   14941        51989 :           result_type = type0;
   14942              :         }
   14943        71604 :       else if (code1 == POINTER_TYPE
   14944        71604 :                && (code0 == NULLPTR_TYPE
   14945        71502 :                    || null_pointer_constant_p (orig_op0)))
   14946              :         {
   14947          294 :           maybe_warn_for_null_address (location, op1, code);
   14948          294 :           result_type = type1;
   14949              :         }
   14950        71310 :       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
   14951              :         {
   14952        71220 :           tree tt0 = TREE_TYPE (type0);
   14953        71220 :           tree tt1 = TREE_TYPE (type1);
   14954        71220 :           addr_space_t as0 = TYPE_ADDR_SPACE (tt0);
   14955        71220 :           addr_space_t as1 = TYPE_ADDR_SPACE (tt1);
   14956        71220 :           addr_space_t as_common = ADDR_SPACE_GENERIC;
   14957              : 
   14958              :           /* Anything compares with void *.  void * compares with anything.
   14959              :              Otherwise, the targets must be compatible
   14960              :              and both must be object or both incomplete.  */
   14961        71220 :           if (comp_target_types (location, type0, type1))
   14962        49857 :             result_type = common_pointer_type (type0, type1, NULL_TREE);
   14963        21363 :           else if (!addr_space_superset (as0, as1, &as_common))
   14964              :             {
   14965            0 :               error_at (location, "comparison of pointers to "
   14966              :                         "disjoint address spaces");
   14967            0 :               return error_mark_node;
   14968              :             }
   14969        21363 :           else if (VOID_TYPE_P (tt0) && !TYPE_ATOMIC (tt0))
   14970              :             {
   14971        21111 :               if (pedantic && TREE_CODE (tt1) == FUNCTION_TYPE)
   14972            4 :                 pedwarn (location, OPT_Wpedantic, "ISO C forbids "
   14973              :                          "comparison of %<void *%> with function pointer");
   14974              :             }
   14975          252 :           else if (VOID_TYPE_P (tt1) && !TYPE_ATOMIC (tt1))
   14976              :             {
   14977          204 :               if (pedantic && TREE_CODE (tt0) == FUNCTION_TYPE)
   14978            4 :                 pedwarn (location, OPT_Wpedantic, "ISO C forbids "
   14979              :                          "comparison of %<void *%> with function pointer");
   14980              :             }
   14981              :           else
   14982              :             /* Avoid warning about the volatile ObjC EH puts on decls.  */
   14983           48 :             if (!objc_ok)
   14984           48 :               pedwarn (location, OPT_Wcompare_distinct_pointer_types,
   14985              :                        "comparison of distinct pointer types lacks a cast");
   14986              : 
   14987        49913 :           if (result_type == NULL_TREE)
   14988              :             {
   14989        21363 :               int qual = ENCODE_QUAL_ADDR_SPACE (as_common);
   14990        21363 :               result_type = c_build_pointer_type
   14991        21363 :                               (c_build_qualified_type (void_type_node, qual));
   14992              :             }
   14993              :         }
   14994           90 :       else if (code0 == POINTER_TYPE
   14995           26 :                && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
   14996              :         {
   14997           26 :           result_type = type0;
   14998           26 :           pedwarn (location, 0, "comparison between pointer and integer");
   14999              :         }
   15000           64 :       else if ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE)
   15001           21 :                && code1 == POINTER_TYPE)
   15002              :         {
   15003            8 :           result_type = type1;
   15004            8 :           pedwarn (location, 0, "comparison between pointer and integer");
   15005              :         }
   15006              :       /* 6.5.9: One of the following shall hold:
   15007              :          -- both operands have type nullptr_t;  */
   15008           56 :       else if (code0 == NULLPTR_TYPE && code1 == NULLPTR_TYPE)
   15009              :         {
   15010           22 :           result_type = nullptr_type_node;
   15011              :           /* No need to convert the operands to result_type later.  */
   15012           22 :           converted = 1;
   15013              :         }
   15014              :     /* -- one operand has type nullptr_t and the other is a null pointer
   15015              :        constant.  We will have to convert the former to the type of the
   15016              :        latter, because during gimplification we can't have mismatching
   15017              :        comparison operand type.  We convert from nullptr_t to the other
   15018              :        type, since only nullptr_t can be converted to nullptr_t.  Also,
   15019              :        even a constant 0 is a null pointer constant, so we may have to
   15020              :        create a pointer type from its type.  */
   15021           34 :       else if (code0 == NULLPTR_TYPE && null_pointer_constant_p (orig_op1))
   15022           19 :         result_type = (INTEGRAL_TYPE_P (type1)
   15023           19 :                        ? c_build_pointer_type (type1) : type1);
   15024           15 :       else if (code1 == NULLPTR_TYPE && null_pointer_constant_p (orig_op0))
   15025           11 :         result_type = (INTEGRAL_TYPE_P (type0)
   15026           11 :                        ? c_build_pointer_type (type0) : type0);
   15027      5060544 :       if ((C_BOOLEAN_TYPE_P (TREE_TYPE (orig_op0))
   15028      3348538 :            || truth_value_p (TREE_CODE (orig_op0)))
   15029      3416533 :           ^ (C_BOOLEAN_TYPE_P (TREE_TYPE (orig_op1))
   15030      3416529 :              || truth_value_p (TREE_CODE (orig_op1))))
   15031        72287 :         maybe_warn_bool_compare (location, code, orig_op0, orig_op1);
   15032              :       break;
   15033              : 
   15034      1012311 :     case LE_EXPR:
   15035      1012311 :     case GE_EXPR:
   15036      1012311 :     case LT_EXPR:
   15037      1012311 :     case GT_EXPR:
   15038      1012311 :       if (gnu_vector_type_p (type0) && gnu_vector_type_p (type1))
   15039              :         {
   15040        59510 :           tree intt;
   15041        59510 :           if (!vector_types_compatible_elements_p (type0, type1))
   15042              :             {
   15043            5 :               error_at (location, "comparing vectors with different "
   15044              :                                   "element types");
   15045            5 :               return error_mark_node;
   15046              :             }
   15047              : 
   15048        59505 :           if (maybe_ne (TYPE_VECTOR_SUBPARTS (type0),
   15049       119010 :                         TYPE_VECTOR_SUBPARTS (type1)))
   15050              :             {
   15051            0 :               error_at (location, "comparing vectors with different "
   15052              :                                   "number of elements");
   15053            0 :               return error_mark_node;
   15054              :             }
   15055              : 
   15056              :           /* It's not precisely specified how the usual arithmetic
   15057              :              conversions apply to the vector types.  Here, we use
   15058              :              the unsigned type if one of the operands is signed and
   15059              :              the other one is unsigned.  */
   15060        59505 :           if (TYPE_UNSIGNED (type0) != TYPE_UNSIGNED (type1))
   15061              :             {
   15062           15 :               if (!TYPE_UNSIGNED (type0))
   15063            8 :                 op0 = build1 (VIEW_CONVERT_EXPR, type1, op0);
   15064              :               else
   15065            7 :                 op1 = build1 (VIEW_CONVERT_EXPR, type0, op1);
   15066           15 :               warning_at (location, OPT_Wsign_compare, "comparison between "
   15067              :                           "types %qT and %qT", type0, type1);
   15068              :             }
   15069              : 
   15070              :           /* Always construct signed integer vector type.  */
   15071       178515 :           intt = c_common_type_for_size (GET_MODE_BITSIZE
   15072       119010 :                                          (SCALAR_TYPE_MODE
   15073              :                                           (TREE_TYPE (type0))), 0);
   15074        59505 :           if (!intt)
   15075              :             {
   15076            0 :               error_at (location, "could not find an integer type "
   15077              :                                   "of the same size as %qT",
   15078            0 :                         TREE_TYPE (type0));
   15079            0 :               return error_mark_node;
   15080              :             }
   15081        59505 :           result_type = build_opaque_vector_type (intt,
   15082        59505 :                                                   TYPE_VECTOR_SUBPARTS (type0));
   15083        59505 :           converted = 1;
   15084        59505 :           ret = build_vec_cmp (resultcode, result_type, op0, op1);
   15085        59505 :           goto return_build_binary_op;
   15086              :         }
   15087       952801 :       build_type = integer_type_node;
   15088       952801 :       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
   15089        65090 :            || code0 == BITINT_TYPE || code0 == FIXED_POINT_TYPE)
   15090       888316 :           && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
   15091              :               || code1 == BITINT_TYPE || code1 == FIXED_POINT_TYPE))
   15092              :         short_compare = 1;
   15093        64517 :       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
   15094              :         {
   15095        64450 :           addr_space_t as0 = TYPE_ADDR_SPACE (TREE_TYPE (type0));
   15096        64450 :           addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (type1));
   15097        64450 :           addr_space_t as_common;
   15098              : 
   15099        64450 :           if (comp_target_types (location, type0, type1))
   15100              :             {
   15101        64285 :               result_type = common_pointer_type (type0, type1, NULL_TREE);
   15102        64285 :               if (!COMPLETE_TYPE_P (TREE_TYPE (type0))
   15103        64285 :                   != !COMPLETE_TYPE_P (TREE_TYPE (type1)))
   15104           32 :                 pedwarn_c99 (location, OPT_Wpedantic,
   15105              :                              "comparison of complete and incomplete pointers");
   15106        64253 :               else if (TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE)
   15107            0 :                 pedwarn (location, OPT_Wpedantic, "ISO C forbids "
   15108              :                          "ordered comparisons of pointers to functions");
   15109        64253 :               else if (null_pointer_constant_p (orig_op0)
   15110        64253 :                        || null_pointer_constant_p (orig_op1))
   15111            8 :                 warning_at (location, OPT_Wextra,
   15112              :                             "ordered comparison of pointer with null pointer");
   15113              : 
   15114              :             }
   15115          165 :           else if (!addr_space_superset (as0, as1, &as_common))
   15116              :             {
   15117            0 :               error_at (location, "comparison of pointers to "
   15118              :                         "disjoint address spaces");
   15119            0 :               return error_mark_node;
   15120              :             }
   15121              :           else
   15122              :             {
   15123          165 :               int qual = ENCODE_QUAL_ADDR_SPACE (as_common);
   15124          165 :               result_type = c_build_pointer_type
   15125          165 :                               (c_build_qualified_type (void_type_node, qual));
   15126          165 :               pedwarn (location, OPT_Wcompare_distinct_pointer_types,
   15127              :                        "comparison of distinct pointer types lacks a cast");
   15128              :             }
   15129              :         }
   15130           67 :       else if (code0 == POINTER_TYPE && null_pointer_constant_p (orig_op1))
   15131              :         {
   15132           17 :           result_type = type0;
   15133           17 :           if (pedantic)
   15134           11 :             pedwarn (location, OPT_Wpedantic,
   15135              :                      "ordered comparison of pointer with integer zero");
   15136            6 :           else if (extra_warnings)
   15137            1 :             warning_at (location, OPT_Wextra,
   15138              :                         "ordered comparison of pointer with integer zero");
   15139              :         }
   15140           50 :       else if (code1 == POINTER_TYPE && null_pointer_constant_p (orig_op0))
   15141              :         {
   15142           12 :           result_type = type1;
   15143           12 :           if (pedantic)
   15144            2 :             pedwarn (location, OPT_Wpedantic,
   15145              :                      "ordered comparison of pointer with integer zero");
   15146           10 :           else if (extra_warnings)
   15147            1 :             warning_at (location, OPT_Wextra,
   15148              :                         "ordered comparison of pointer with integer zero");
   15149              :         }
   15150           38 :       else if (code0 == POINTER_TYPE
   15151           18 :                && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
   15152              :         {
   15153           18 :           result_type = type0;
   15154           18 :           pedwarn (location, 0, "comparison between pointer and integer");
   15155              :         }
   15156           20 :       else if ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE)
   15157           20 :                && code1 == POINTER_TYPE)
   15158              :         {
   15159           18 :           result_type = type1;
   15160           18 :           pedwarn (location, 0, "comparison between pointer and integer");
   15161              :         }
   15162              : 
   15163       952801 :       if ((code0 == POINTER_TYPE || code1 == POINTER_TYPE)
   15164        64515 :           && current_function_decl != NULL_TREE
   15165      1017305 :           && sanitize_flags_p (SANITIZE_POINTER_COMPARE))
   15166              :         {
   15167           35 :           op0 = save_expr (c_fully_fold (op0, false, NULL));
   15168           35 :           op1 = save_expr (c_fully_fold (op1, false, NULL));
   15169              : 
   15170           35 :           tree tt = builtin_decl_explicit (BUILT_IN_ASAN_POINTER_COMPARE);
   15171           35 :           instrument_expr = build_call_expr_loc (location, tt, 2, op0, op1);
   15172              :         }
   15173              : 
   15174      2858305 :       if ((C_BOOLEAN_TYPE_P (TREE_TYPE (orig_op0))
   15175      1905504 :            || truth_value_p (TREE_CODE (orig_op0)))
   15176      1905521 :           ^ (C_BOOLEAN_TYPE_P (TREE_TYPE (orig_op1))
   15177      1905521 :              || truth_value_p (TREE_CODE (orig_op1))))
   15178          526 :         maybe_warn_bool_compare (location, code, orig_op0, orig_op1);
   15179              :       break;
   15180              : 
   15181           43 :     case MIN_EXPR:
   15182           43 :     case MAX_EXPR:
   15183              :       /* Used for OpenMP atomics.  */
   15184           43 :       gcc_assert (flag_openmp);
   15185              :       common = 1;
   15186              :       break;
   15187              : 
   15188            0 :     default:
   15189            0 :       gcc_unreachable ();
   15190              :     }
   15191              : 
   15192     15623983 :   if (code0 == ERROR_MARK || code1 == ERROR_MARK)
   15193            0 :     return error_mark_node;
   15194              : 
   15195     15623983 :   if (gnu_vector_type_p (type0)
   15196      1488733 :       && gnu_vector_type_p (type1)
   15197     17111853 :       && (!tree_int_cst_equal (TYPE_SIZE (type0), TYPE_SIZE (type1))
   15198      1487850 :           || !vector_types_compatible_elements_p (type0, type1)))
   15199              :     {
   15200           26 :       gcc_rich_location richloc (location);
   15201           26 :       maybe_range_label_for_tree_type_mismatch
   15202           26 :         label_for_op0 (orig_op0, orig_op1),
   15203           26 :         label_for_op1 (orig_op1, orig_op0);
   15204           26 :       richloc.maybe_add_expr (orig_op0, &label_for_op0, highlight_colors::lhs);
   15205           26 :       richloc.maybe_add_expr (orig_op1, &label_for_op1, highlight_colors::rhs);
   15206           26 :       binary_op_error (&richloc, code, type0, type1);
   15207           26 :       return error_mark_node;
   15208           26 :     }
   15209              : 
   15210     15623957 :   if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE
   15211      1746642 :        || code0 == FIXED_POINT_TYPE || code0 == BITINT_TYPE
   15212      1676934 :        || gnu_vector_type_p (type0))
   15213     17182372 :       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE || code1 == COMPLEX_TYPE
   15214      1582552 :           || code1 == FIXED_POINT_TYPE || code1 == BITINT_TYPE
   15215      1489978 :           || gnu_vector_type_p (type1)))
   15216              :     {
   15217     15433601 :       bool first_complex = (code0 == COMPLEX_TYPE);
   15218     15433601 :       bool second_complex = (code1 == COMPLEX_TYPE);
   15219     15433601 :       int none_complex = (!first_complex && !second_complex);
   15220              : 
   15221     15433601 :       if (shorten || common || short_compare)
   15222              :         {
   15223     13878863 :           result_type = c_common_type (type0, type1);
   15224     13878863 :           do_warn_double_promotion (result_type, type0, type1,
   15225              :                                     "implicit conversion from %qT to %qT "
   15226              :                                     "to match other operand of binary "
   15227              :                                     "expression",
   15228              :                                     location);
   15229     13878863 :           if (result_type == error_mark_node)
   15230              :             return error_mark_node;
   15231              :         }
   15232              : 
   15233     15433579 :       if (first_complex != second_complex
   15234        82085 :           && (code == PLUS_EXPR
   15235              :               || code == MINUS_EXPR
   15236        82085 :               || code == MULT_EXPR
   15237        17533 :               || (code == TRUNC_DIV_EXPR && first_complex))
   15238        65973 :           && TREE_CODE (TREE_TYPE (result_type)) == REAL_TYPE
   15239     15495834 :           && flag_signed_zeros)
   15240              :         {
   15241              :           /* An operation on mixed real/complex operands must be
   15242              :              handled specially, but the language-independent code can
   15243              :              more easily optimize the plain complex arithmetic if
   15244              :              -fno-signed-zeros.  */
   15245        61943 :           tree real_type = TREE_TYPE (result_type);
   15246        61943 :           tree real, imag;
   15247        61943 :           if (type0 != orig_type0 || type1 != orig_type1)
   15248              :             {
   15249           94 :               gcc_assert (may_need_excess_precision && common);
   15250           94 :               semantic_result_type = c_common_type (orig_type0, orig_type1);
   15251              :             }
   15252        61943 :           if (first_complex)
   15253              :             {
   15254         8253 :               if (TREE_TYPE (op0) != result_type)
   15255         1787 :                 op0 = convert_and_check (location, result_type, op0);
   15256         8253 :               if (TREE_TYPE (op1) != real_type)
   15257         4601 :                 op1 = convert_and_check (location, real_type, op1);
   15258              :             }
   15259              :           else
   15260              :             {
   15261        53690 :               if (TREE_TYPE (op0) != real_type)
   15262         2698 :                 op0 = convert_and_check (location, real_type, op0);
   15263        53690 :               if (TREE_TYPE (op1) != result_type)
   15264         1866 :                 op1 = convert_and_check (location, result_type, op1);
   15265              :             }
   15266        61943 :           if (TREE_CODE (op0) == ERROR_MARK || TREE_CODE (op1) == ERROR_MARK)
   15267            0 :             return error_mark_node;
   15268        61943 :           if (first_complex)
   15269              :             {
   15270         8253 :               op0 = save_expr (op0);
   15271         8253 :               real = build_unary_op (EXPR_LOCATION (orig_op0), REALPART_EXPR,
   15272              :                                      op0, true);
   15273         8253 :               imag = build_unary_op (EXPR_LOCATION (orig_op0), IMAGPART_EXPR,
   15274              :                                      op0, true);
   15275         8253 :               switch (code)
   15276              :                 {
   15277         3488 :                 case MULT_EXPR:
   15278         3488 :                 case TRUNC_DIV_EXPR:
   15279         3488 :                   op1 = save_expr (op1);
   15280         3488 :                   imag = build2 (resultcode, real_type, imag, op1);
   15281              :                   /* Fall through.  */
   15282         8253 :                 case PLUS_EXPR:
   15283         8253 :                 case MINUS_EXPR:
   15284         8253 :                   real = build2 (resultcode, real_type, real, op1);
   15285         8253 :                   break;
   15286              :                 default:
   15287              :                   gcc_unreachable();
   15288              :                 }
   15289              :             }
   15290              :           else
   15291              :             {
   15292        53690 :               op1 = save_expr (op1);
   15293        53690 :               real = build_unary_op (EXPR_LOCATION (orig_op1), REALPART_EXPR,
   15294              :                                      op1, true);
   15295        53690 :               imag = build_unary_op (EXPR_LOCATION (orig_op1), IMAGPART_EXPR,
   15296              :                                      op1, true);
   15297        53690 :               switch (code)
   15298              :                 {
   15299         2008 :                 case MULT_EXPR:
   15300         2008 :                   op0 = save_expr (op0);
   15301         2008 :                   imag = build2 (resultcode, real_type, op0, imag);
   15302              :                   /* Fall through.  */
   15303        31958 :                 case PLUS_EXPR:
   15304        31958 :                   real = build2 (resultcode, real_type, op0, real);
   15305        31958 :                   break;
   15306        21732 :                 case MINUS_EXPR:
   15307        21732 :                   real = build2 (resultcode, real_type, op0, real);
   15308        21732 :                   imag = build1 (NEGATE_EXPR, real_type, imag);
   15309        21732 :                   break;
   15310            0 :                 default:
   15311            0 :                   gcc_unreachable();
   15312              :                 }
   15313              :             }
   15314        61943 :           ret = build2 (COMPLEX_EXPR, result_type, real, imag);
   15315        61943 :           goto return_build_binary_op;
   15316              :         }
   15317              : 
   15318              :       /* For certain operations (which identify themselves by shorten != 0)
   15319              :          if both args were extended from the same smaller type,
   15320              :          do the arithmetic in that type and then extend.
   15321              : 
   15322              :          shorten !=0 and !=1 indicates a bitwise operation.
   15323              :          For them, this optimization is safe only if
   15324              :          both args are zero-extended or both are sign-extended.
   15325              :          Otherwise, we might change the result.
   15326              :          Eg, (short)-1 | (unsigned short)-1 is (int)-1
   15327              :          but calculated in (unsigned short) it would be (unsigned short)-1.  */
   15328              : 
   15329     15371636 :       if (shorten && none_complex)
   15330              :         {
   15331      1306966 :           final_type = result_type;
   15332      1306966 :           result_type = shorten_binary_op (result_type, op0, op1,
   15333              :                                            shorten == -1);
   15334              :         }
   15335              : 
   15336              :       /* Shifts can be shortened if shifting right.  */
   15337              : 
   15338     15371636 :       if (short_shift)
   15339              :         {
   15340       203062 :           int unsigned_arg;
   15341       203062 :           tree arg0 = get_narrower (op0, &unsigned_arg);
   15342              : 
   15343       203062 :           final_type = result_type;
   15344              : 
   15345       203062 :           if (arg0 == op0 && final_type == TREE_TYPE (op0))
   15346       143129 :             unsigned_arg = TYPE_UNSIGNED (TREE_TYPE (op0));
   15347              : 
   15348       203062 :           if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type)
   15349         3060 :               && tree_int_cst_sgn (op1) > 0
   15350              :               /* We can shorten only if the shift count is less than the
   15351              :                  number of bits in the smaller type size.  */
   15352         3060 :               && compare_tree_int (op1, TYPE_PRECISION (TREE_TYPE (arg0))) < 0
   15353              :               /* We cannot drop an unsigned shift after sign-extension.  */
   15354       205981 :               && (!TYPE_UNSIGNED (final_type) || unsigned_arg))
   15355              :             {
   15356              :               /* Do an unsigned shift if the operand was zero-extended.  */
   15357         2904 :               result_type
   15358         2904 :                 = c_common_signed_or_unsigned_type (unsigned_arg,
   15359         2904 :                                                     TREE_TYPE (arg0));
   15360              :               /* Convert value-to-be-shifted to that type.  */
   15361         2904 :               if (TREE_TYPE (op0) != result_type)
   15362         2904 :                 op0 = convert (result_type, op0);
   15363              :               converted = 1;
   15364              :             }
   15365              :         }
   15366              : 
   15367              :       /* Comparison operations are shortened too but differently.
   15368              :          They identify themselves by setting short_compare = 1.  */
   15369              : 
   15370     15371636 :       if (short_compare)
   15371              :         {
   15372              :           /* Don't write &op0, etc., because that would prevent op0
   15373              :              from being kept in a register.
   15374              :              Instead, make copies of the our local variables and
   15375              :              pass the copies by reference, then copy them back afterward.  */
   15376      2476670 :           tree xop0 = op0, xop1 = op1, xresult_type = result_type;
   15377      2476670 :           enum tree_code xresultcode = resultcode;
   15378      2476670 :           tree val
   15379      2476670 :             = shorten_compare (location, &xop0, &xop1, &xresult_type,
   15380              :                                &xresultcode);
   15381              : 
   15382      2476670 :           if (val != NULL_TREE)
   15383              :             {
   15384        15887 :               ret = val;
   15385        15887 :               goto return_build_binary_op;
   15386              :             }
   15387              : 
   15388      2460783 :           op0 = xop0, op1 = xop1;
   15389      2460783 :           converted = 1;
   15390      2460783 :           resultcode = xresultcode;
   15391              : 
   15392      2460783 :           if (c_inhibit_evaluation_warnings == 0 && !c_in_omp_for)
   15393              :             {
   15394      2313204 :               bool op0_maybe_const = true;
   15395      2313204 :               bool op1_maybe_const = true;
   15396      2313204 :               tree orig_op0_folded, orig_op1_folded;
   15397              : 
   15398      2313204 :               if (in_late_binary_op)
   15399              :                 {
   15400              :                   orig_op0_folded = orig_op0;
   15401              :                   orig_op1_folded = orig_op1;
   15402              :                 }
   15403              :               else
   15404              :                 {
   15405              :                   /* Fold for the sake of possible warnings, as in
   15406              :                      build_conditional_expr.  This requires the
   15407              :                      "original" values to be folded, not just op0 and
   15408              :                      op1.  */
   15409      2304545 :                   c_inhibit_evaluation_warnings++;
   15410      2304545 :                   op0 = c_fully_fold (op0, require_constant_value,
   15411              :                                       &op0_maybe_const);
   15412      2304545 :                   op1 = c_fully_fold (op1, require_constant_value,
   15413              :                                       &op1_maybe_const);
   15414      2304545 :                   c_inhibit_evaluation_warnings--;
   15415      2304545 :                   orig_op0_folded = c_fully_fold (orig_op0,
   15416              :                                                   require_constant_value,
   15417              :                                                   NULL);
   15418      2304545 :                   orig_op1_folded = c_fully_fold (orig_op1,
   15419              :                                                   require_constant_value,
   15420              :                                                   NULL);
   15421              :                 }
   15422              : 
   15423      2313204 :               if (warn_sign_compare)
   15424       377562 :                 warn_for_sign_compare (location, orig_op0_folded,
   15425              :                                        orig_op1_folded, op0, op1,
   15426              :                                        result_type, resultcode);
   15427      2313204 :               if (!in_late_binary_op && !int_operands)
   15428              :                 {
   15429      2126881 :                   if (!op0_maybe_const || TREE_CODE (op0) != INTEGER_CST)
   15430      2123371 :                     op0 = c_wrap_maybe_const (op0, !op0_maybe_const);
   15431      2126881 :                   if (!op1_maybe_const || TREE_CODE (op1) != INTEGER_CST)
   15432       833723 :                     op1 = c_wrap_maybe_const (op1, !op1_maybe_const);
   15433              :                 }
   15434              :             }
   15435              :         }
   15436              :     }
   15437              : 
   15438              :   /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
   15439              :      If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
   15440              :      Then the expression will be built.
   15441              :      It will be given type FINAL_TYPE if that is nonzero;
   15442              :      otherwise, it will be given type RESULT_TYPE.  */
   15443              : 
   15444     15546105 :   if (!result_type)
   15445              :     {
   15446              :       /* Favor showing any expression locations that are available. */
   15447          514 :       op_location_t oploc (location, UNKNOWN_LOCATION);
   15448          514 :       binary_op_rich_location richloc (oploc, orig_op0, orig_op1, true);
   15449          514 :       binary_op_error (&richloc, code, TREE_TYPE (op0), TREE_TYPE (op1));
   15450          514 :       return error_mark_node;
   15451          514 :     }
   15452              : 
   15453     15545591 :   if (build_type == NULL_TREE)
   15454              :     {
   15455     12896704 :       build_type = result_type;
   15456     12896704 :       if ((type0 != orig_type0 || type1 != orig_type1)
   15457          804 :           && !boolean_op)
   15458              :         {
   15459          804 :           gcc_assert (may_need_excess_precision && common);
   15460          804 :           semantic_result_type = c_common_type (orig_type0, orig_type1);
   15461              :         }
   15462              :     }
   15463              : 
   15464     15545591 :   if (!converted)
   15465              :     {
   15466     11527045 :       op0 = ep_convert_and_check (location, result_type, op0,
   15467              :                                   semantic_result_type);
   15468     11527045 :       op1 = ep_convert_and_check (location, result_type, op1,
   15469              :                                   semantic_result_type);
   15470              : 
   15471              :       /* This can happen if one operand has a vector type, and the other
   15472              :          has a different type.  */
   15473     11527045 :       if (TREE_CODE (op0) == ERROR_MARK || TREE_CODE (op1) == ERROR_MARK)
   15474            3 :         return error_mark_node;
   15475              :     }
   15476              : 
   15477     15545588 :   if (sanitize_flags_p ((SANITIZE_SHIFT
   15478              :                          | SANITIZE_DIVIDE
   15479              :                          | SANITIZE_FLOAT_DIVIDE
   15480              :                          | SANITIZE_SI_OVERFLOW))
   15481        23437 :       && current_function_decl != NULL_TREE
   15482        19967 :       && (doing_div_or_mod || doing_shift)
   15483     15548519 :       && !require_constant_value)
   15484              :     {
   15485              :       /* OP0 and/or OP1 might have side-effects.  */
   15486         2875 :       op0 = save_expr (op0);
   15487         2875 :       op1 = save_expr (op1);
   15488         2875 :       op0 = c_fully_fold (op0, false, NULL);
   15489         2875 :       op1 = c_fully_fold (op1, false, NULL);
   15490         2875 :       if (doing_div_or_mod && (sanitize_flags_p ((SANITIZE_DIVIDE
   15491              :                                                   | SANITIZE_FLOAT_DIVIDE
   15492              :                                                   | SANITIZE_SI_OVERFLOW))))
   15493          916 :         instrument_expr = ubsan_instrument_division (location, op0, op1);
   15494         1959 :       else if (doing_shift && sanitize_flags_p (SANITIZE_SHIFT))
   15495         1778 :         instrument_expr = ubsan_instrument_shift (location, code, op0, op1);
   15496              :     }
   15497              : 
   15498              :   /* Treat expressions in initializers specially as they can't trap.  */
   15499     15545588 :   if (int_const_or_overflow)
   15500      8023752 :     ret = (require_constant_value
   15501      8023752 :            ? fold_build2_initializer_loc (location, resultcode, build_type,
   15502              :                                           op0, op1)
   15503      7977544 :            : fold_build2_loc (location, resultcode, build_type, op0, op1));
   15504              :   else
   15505      7521836 :     ret = build2 (resultcode, build_type, op0, op1);
   15506     15545588 :   if (final_type != NULL_TREE)
   15507      1510028 :     ret = convert (final_type, ret);
   15508              : 
   15509     14035560 :  return_build_binary_op:
   15510     17006525 :   gcc_assert (ret != error_mark_node);
   15511     17006525 :   if (TREE_CODE (ret) == INTEGER_CST && !TREE_OVERFLOW (ret) && !int_const)
   15512         1852 :     ret = (int_operands
   15513         1852 :            ? note_integer_operands (ret)
   15514          530 :            : build1 (NOP_EXPR, TREE_TYPE (ret), ret));
   15515     17004673 :   else if (TREE_CODE (ret) != INTEGER_CST && int_operands
   15516        60311 :            && !in_late_binary_op)
   15517        60311 :     ret = note_integer_operands (ret);
   15518     17006525 :   protected_set_expr_location (ret, location);
   15519              : 
   15520     17006525 :   if (instrument_expr != NULL)
   15521         1425 :     ret = fold_build2 (COMPOUND_EXPR, TREE_TYPE (ret),
   15522              :                        instrument_expr, ret);
   15523              : 
   15524     17006525 :   if (semantic_result_type)
   15525          898 :     ret = build1_loc (location, EXCESS_PRECISION_EXPR,
   15526              :                       semantic_result_type, ret);
   15527              : 
   15528              :   return ret;
   15529              : }
   15530              : 
   15531              : 
   15532              : /* Convert EXPR to be a truth-value (type TYPE), validating its type for this
   15533              :    purpose.  LOCATION is the source location for the expression.  */
   15534              : 
   15535              : tree
   15536      4165089 : c_objc_common_truthvalue_conversion (location_t location, tree expr, tree type)
   15537              : {
   15538      4165089 :   bool int_const, int_operands;
   15539              : 
   15540      4165089 :   switch (TREE_CODE (TREE_TYPE (expr)))
   15541              :     {
   15542           72 :     case ARRAY_TYPE:
   15543           72 :       error_at (location, "used array that cannot be converted to pointer where scalar is required");
   15544           72 :       return error_mark_node;
   15545              : 
   15546           86 :     case RECORD_TYPE:
   15547           86 :       error_at (location, "used struct type value where scalar is required");
   15548           86 :       return error_mark_node;
   15549              : 
   15550           83 :     case UNION_TYPE:
   15551           83 :       error_at (location, "used union type value where scalar is required");
   15552           83 :       return error_mark_node;
   15553              : 
   15554           22 :     case VOID_TYPE:
   15555           22 :       error_at (location, "void value not ignored as it ought to be");
   15556           22 :       return error_mark_node;
   15557              : 
   15558        30964 :     case POINTER_TYPE:
   15559        30964 :       if (reject_gcc_builtin (expr))
   15560            3 :         return error_mark_node;
   15561              :       break;
   15562              : 
   15563            0 :     case FUNCTION_TYPE:
   15564            0 :       gcc_unreachable ();
   15565              : 
   15566            8 :     case VECTOR_TYPE:
   15567            8 :       error_at (location, "used vector type where scalar is required");
   15568            8 :       return error_mark_node;
   15569              : 
   15570              :     default:
   15571              :       break;
   15572              :     }
   15573              : 
   15574              :   /* Conversion of a floating constant to boolean goes through here
   15575              :      and yields an integer constant expression.  Otherwise, the result
   15576              :      is only an integer constant expression if the argument is.  */
   15577       900202 :   int_const = ((TREE_CODE (expr) == INTEGER_CST && !TREE_OVERFLOW (expr))
   15578      4164891 :                || ((TREE_CODE (expr) == REAL_CST
   15579      3264315 :                     || TREE_CODE (expr) == COMPLEX_CST)
   15580          374 :                    && (TREE_CODE (type) == BOOLEAN_TYPE
   15581           15 :                        || (TREE_CODE (type) == ENUMERAL_TYPE
   15582            5 :                            && ENUM_UNDERLYING_TYPE (type) != NULL_TREE
   15583            5 :                            && (TREE_CODE (ENUM_UNDERLYING_TYPE (type))
   15584              :                                == BOOLEAN_TYPE)))));
   15585      4164815 :   int_operands = EXPR_INT_CONST_OPERANDS (expr);
   15586       900364 :   if (int_operands && TREE_CODE (expr) != INTEGER_CST)
   15587              :     {
   15588          319 :       expr = remove_c_maybe_const_expr (expr);
   15589          319 :       expr = build2 (NE_EXPR, type, expr,
   15590          319 :                      convert (TREE_TYPE (expr), integer_zero_node));
   15591          319 :       expr = note_integer_operands (expr);
   15592              :     }
   15593              :   else
   15594              :     {
   15595              :       /* ??? Should we also give an error for vectors rather than leaving
   15596              :          those to give errors later?  */
   15597      4164496 :       expr = c_common_truthvalue_conversion (location, expr);
   15598      4164496 :       expr = fold_convert_loc (location, type, expr);
   15599              :     }
   15600              : 
   15601      4164815 :   if (TREE_CODE (expr) == INTEGER_CST && int_operands && !int_const)
   15602              :     {
   15603           76 :       if (TREE_OVERFLOW (expr))
   15604              :         return expr;
   15605              :       else
   15606           76 :         return note_integer_operands (expr);
   15607              :     }
   15608      4164739 :   if (TREE_CODE (expr) == INTEGER_CST && !int_const)
   15609          857 :     return build1 (NOP_EXPR, TREE_TYPE (expr), expr);
   15610              :   return expr;
   15611              : }
   15612              : 
   15613              : 
   15614              : /* Convert EXPR to a contained DECL, updating *TC, *TI and *SE as
   15615              :    required.  */
   15616              : 
   15617              : tree
   15618    126949708 : c_expr_to_decl (tree expr, bool *tc ATTRIBUTE_UNUSED, bool *se)
   15619              : {
   15620    126949708 :   if (TREE_CODE (expr) == COMPOUND_LITERAL_EXPR)
   15621              :     {
   15622          706 :       tree decl = COMPOUND_LITERAL_EXPR_DECL (expr);
   15623              :       /* Executing a compound literal inside a function reinitializes
   15624              :          it.  */
   15625          706 :       if (!TREE_STATIC (decl))
   15626          440 :         *se = true;
   15627              :       return decl;
   15628              :     }
   15629              :   else
   15630              :     return expr;
   15631              : }
   15632              : 
   15633              : /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
   15634              :    statement.  LOC is the location of the construct.  */
   15635              : 
   15636              : tree
   15637         2154 : c_finish_omp_construct (location_t loc, enum tree_code code, tree body,
   15638              :                         tree clauses)
   15639              : {
   15640         2154 :   body = c_end_compound_stmt (loc, body, true);
   15641              : 
   15642         2154 :   tree stmt = make_node (code);
   15643         2154 :   TREE_TYPE (stmt) = void_type_node;
   15644         2154 :   OMP_BODY (stmt) = body;
   15645         2154 :   OMP_CLAUSES (stmt) = clauses;
   15646         2154 :   SET_EXPR_LOCATION (stmt, loc);
   15647              : 
   15648         2154 :   return add_stmt (stmt);
   15649              : }
   15650              : 
   15651              : /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
   15652              :    statement.  LOC is the location of the OACC_DATA.  */
   15653              : 
   15654              : tree
   15655          497 : c_finish_oacc_data (location_t loc, tree clauses, tree block)
   15656              : {
   15657          497 :   tree stmt;
   15658              : 
   15659          497 :   block = c_end_compound_stmt (loc, block, true);
   15660              : 
   15661          497 :   stmt = make_node (OACC_DATA);
   15662          497 :   TREE_TYPE (stmt) = void_type_node;
   15663          497 :   OACC_DATA_CLAUSES (stmt) = clauses;
   15664          497 :   OACC_DATA_BODY (stmt) = block;
   15665          497 :   SET_EXPR_LOCATION (stmt, loc);
   15666              : 
   15667          497 :   return add_stmt (stmt);
   15668              : }
   15669              : 
   15670              : /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
   15671              :    statement.  LOC is the location of the OACC_HOST_DATA.  */
   15672              : 
   15673              : tree
   15674           21 : c_finish_oacc_host_data (location_t loc, tree clauses, tree block)
   15675              : {
   15676           21 :   tree stmt;
   15677              : 
   15678           21 :   block = c_end_compound_stmt (loc, block, true);
   15679              : 
   15680           21 :   stmt = make_node (OACC_HOST_DATA);
   15681           21 :   TREE_TYPE (stmt) = void_type_node;
   15682           21 :   OACC_HOST_DATA_CLAUSES (stmt) = clauses;
   15683           21 :   OACC_HOST_DATA_BODY (stmt) = block;
   15684           21 :   SET_EXPR_LOCATION (stmt, loc);
   15685              : 
   15686           21 :   return add_stmt (stmt);
   15687              : }
   15688              : 
   15689              : /* Like c_begin_compound_stmt, except force the retention of the BLOCK.  */
   15690              : 
   15691              : tree
   15692        12031 : c_begin_omp_parallel (void)
   15693              : {
   15694        12031 :   tree block;
   15695              : 
   15696        12031 :   keep_next_level ();
   15697        12031 :   block = c_begin_compound_stmt (true);
   15698              : 
   15699        12031 :   return block;
   15700              : }
   15701              : 
   15702              : /* Generate OMP_PARALLEL, with CLAUSES and BLOCK as its compound
   15703              :    statement.  LOC is the location of the OMP_PARALLEL.  */
   15704              : 
   15705              : tree
   15706         5694 : c_finish_omp_parallel (location_t loc, tree clauses, tree block)
   15707              : {
   15708         5694 :   tree stmt;
   15709              : 
   15710         5694 :   block = c_end_compound_stmt (loc, block, true);
   15711              : 
   15712         5694 :   stmt = make_node (OMP_PARALLEL);
   15713         5694 :   TREE_TYPE (stmt) = void_type_node;
   15714         5694 :   OMP_PARALLEL_CLAUSES (stmt) = clauses;
   15715         5694 :   OMP_PARALLEL_BODY (stmt) = block;
   15716         5694 :   SET_EXPR_LOCATION (stmt, loc);
   15717              : 
   15718         5694 :   return add_stmt (stmt);
   15719              : }
   15720              : 
   15721              : /* Like c_begin_compound_stmt, except force the retention of the BLOCK.  */
   15722              : 
   15723              : tree
   15724          903 : c_begin_omp_task (void)
   15725              : {
   15726          903 :   tree block;
   15727              : 
   15728          903 :   keep_next_level ();
   15729          903 :   block = c_begin_compound_stmt (true);
   15730              : 
   15731          903 :   return block;
   15732              : }
   15733              : 
   15734              : /* Generate OMP_TASK, with CLAUSES and BLOCK as its compound
   15735              :    statement.  LOC is the location of the #pragma.  */
   15736              : 
   15737              : tree
   15738          903 : c_finish_omp_task (location_t loc, tree clauses, tree block)
   15739              : {
   15740          903 :   tree stmt;
   15741              : 
   15742          903 :   block = c_end_compound_stmt (loc, block, true);
   15743              : 
   15744          903 :   stmt = make_node (OMP_TASK);
   15745          903 :   TREE_TYPE (stmt) = void_type_node;
   15746          903 :   OMP_TASK_CLAUSES (stmt) = clauses;
   15747          903 :   OMP_TASK_BODY (stmt) = block;
   15748          903 :   SET_EXPR_LOCATION (stmt, loc);
   15749              : 
   15750          903 :   return add_stmt (stmt);
   15751              : }
   15752              : 
   15753              : /* Generate GOMP_cancel call for #pragma omp cancel.  */
   15754              : 
   15755              : void
   15756          213 : c_finish_omp_cancel (location_t loc, tree clauses)
   15757              : {
   15758          213 :   tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL);
   15759          213 :   int mask = 0;
   15760          213 :   if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
   15761              :     mask = 1;
   15762          150 :   else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
   15763              :     mask = 2;
   15764          101 :   else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
   15765              :     mask = 4;
   15766           58 :   else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
   15767              :     mask = 8;
   15768              :   else
   15769              :     {
   15770            0 :       error_at (loc, "%<#pragma omp cancel%> must specify one of "
   15771              :                      "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> "
   15772              :                      "clauses");
   15773            0 :       return;
   15774              :     }
   15775          213 :   tree ifc = omp_find_clause (clauses, OMP_CLAUSE_IF);
   15776          213 :   if (ifc != NULL_TREE)
   15777              :     {
   15778           31 :       if (OMP_CLAUSE_IF_MODIFIER (ifc) != ERROR_MARK
   15779           31 :           && OMP_CLAUSE_IF_MODIFIER (ifc) != VOID_CST)
   15780            2 :         error_at (OMP_CLAUSE_LOCATION (ifc),
   15781              :                   "expected %<cancel%> %<if%> clause modifier");
   15782              :       else
   15783              :         {
   15784           29 :           tree ifc2 = omp_find_clause (OMP_CLAUSE_CHAIN (ifc), OMP_CLAUSE_IF);
   15785           29 :           if (ifc2 != NULL_TREE)
   15786              :             {
   15787            1 :               gcc_assert (OMP_CLAUSE_IF_MODIFIER (ifc) == VOID_CST
   15788              :                           && OMP_CLAUSE_IF_MODIFIER (ifc2) != ERROR_MARK
   15789              :                           && OMP_CLAUSE_IF_MODIFIER (ifc2) != VOID_CST);
   15790            1 :               error_at (OMP_CLAUSE_LOCATION (ifc2),
   15791              :                         "expected %<cancel%> %<if%> clause modifier");
   15792              :             }
   15793              :         }
   15794              : 
   15795           31 :       tree type = TREE_TYPE (OMP_CLAUSE_IF_EXPR (ifc));
   15796           62 :       ifc = fold_build2_loc (OMP_CLAUSE_LOCATION (ifc), NE_EXPR,
   15797           31 :                              boolean_type_node, OMP_CLAUSE_IF_EXPR (ifc),
   15798              :                              build_zero_cst (type));
   15799              :     }
   15800              :   else
   15801          182 :     ifc = boolean_true_node;
   15802          213 :   tree stmt = build_call_expr_loc (loc, fn, 2,
   15803          213 :                                    build_int_cst (integer_type_node, mask),
   15804              :                                    ifc);
   15805          213 :   add_stmt (stmt);
   15806              : }
   15807              : 
   15808              : /* Generate GOMP_cancellation_point call for
   15809              :    #pragma omp cancellation point.  */
   15810              : 
   15811              : void
   15812          167 : c_finish_omp_cancellation_point (location_t loc, tree clauses)
   15813              : {
   15814          167 :   tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT);
   15815          167 :   int mask = 0;
   15816          167 :   if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
   15817              :     mask = 1;
   15818          123 :   else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
   15819              :     mask = 2;
   15820           88 :   else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
   15821              :     mask = 4;
   15822           53 :   else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
   15823              :     mask = 8;
   15824              :   else
   15825              :     {
   15826            1 :       error_at (loc, "%<#pragma omp cancellation point%> must specify one of "
   15827              :                      "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> "
   15828              :                      "clauses");
   15829            1 :       return;
   15830              :     }
   15831          166 :   tree stmt = build_call_expr_loc (loc, fn, 1,
   15832          166 :                                    build_int_cst (integer_type_node, mask));
   15833          166 :   add_stmt (stmt);
   15834              : }
   15835              : 
   15836              : /* Helper function for handle_omp_array_sections.  Called recursively
   15837              :    to handle multiple array-section-subscripts.  C is the clause,
   15838              :    T current expression (initially OMP_CLAUSE_DECL), which is either
   15839              :    a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
   15840              :    expression if specified, TREE_VALUE length expression if specified,
   15841              :    TREE_CHAIN is what it has been specified after, or some decl.
   15842              :    TYPES vector is populated with array section types, MAYBE_ZERO_LEN
   15843              :    set to true if any of the array-section-subscript could have length
   15844              :    of zero (explicit or implicit), FIRST_NON_ONE is the index of the
   15845              :    first array-section-subscript which is known not to have length
   15846              :    of one.  Given say:
   15847              :    map(a[:b][2:1][:c][:2][:d][e:f][2:5])
   15848              :    FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
   15849              :    all are or may have length of 1, array-section-subscript [:2] is the
   15850              :    first one known not to have length 1.  For array-section-subscript
   15851              :    <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
   15852              :    0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
   15853              :    can if MAYBE_ZERO_LEN is false.  MAYBE_ZERO_LEN will be true in the above
   15854              :    case though, as some lengths could be zero.  */
   15855              : 
   15856              : static tree
   15857         6443 : handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types,
   15858              :                              bool &maybe_zero_len, unsigned int &first_non_one,
   15859              :                              enum c_omp_region_type ort)
   15860              : {
   15861         6443 :   tree ret, low_bound, length, type;
   15862         6443 :   bool openacc = (ort & C_ORT_ACC) != 0;
   15863         6443 :   if (TREE_CODE (t) != OMP_ARRAY_SECTION)
   15864              :     {
   15865         3001 :       if (error_operand_p (t))
   15866            2 :         return error_mark_node;
   15867         2999 :       c_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
   15868         2999 :       ret = t;
   15869         2999 :       if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
   15870         2895 :           && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
   15871         5580 :           && TYPE_ATOMIC (strip_array_types (TREE_TYPE (t))))
   15872              :         {
   15873            6 :           error_at (OMP_CLAUSE_LOCATION (c), "%<_Atomic%> %qE in %qs clause",
   15874            6 :                     t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   15875            6 :           return error_mark_node;
   15876              :         }
   15877         2993 :       if (!ai.check_clause (c))
   15878            0 :         return error_mark_node;
   15879         2993 :       else if (ai.component_access_p ()
   15880         3296 :                && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   15881           16 :                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO
   15882           11 :                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM))
   15883          303 :         t = ai.get_root_term (true);
   15884              :       else
   15885         2690 :         t = ai.unconverted_ref_origin ();
   15886         2993 :       if (t == error_mark_node)
   15887              :         return error_mark_node;
   15888         2993 :       if (!VAR_P (t)
   15889          751 :           && (ort == C_ORT_ACC || !EXPR_P (t))
   15890          744 :           && TREE_CODE (t) != PARM_DECL)
   15891              :         {
   15892            5 :           if (DECL_P (t))
   15893            5 :             error_at (OMP_CLAUSE_LOCATION (c),
   15894              :                       "%qD is not a variable in %qs clause", t,
   15895            5 :                       omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   15896              :           else
   15897            0 :             error_at (OMP_CLAUSE_LOCATION (c),
   15898              :                       "%qE is not a variable in %qs clause", t,
   15899            0 :                       omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   15900            5 :           return error_mark_node;
   15901              :         }
   15902         2988 :       else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
   15903         2885 :                && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
   15904         5560 :                && TYPE_ATOMIC (TREE_TYPE (t)))
   15905              :         {
   15906            0 :           error_at (OMP_CLAUSE_LOCATION (c), "%<_Atomic%> %qD in %qs clause",
   15907            0 :                     t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   15908            0 :           return error_mark_node;
   15909              :         }
   15910         2988 :       else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
   15911         2885 :                && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
   15912         2572 :                && VAR_P (t)
   15913         5004 :                && DECL_THREAD_LOCAL_P (t))
   15914              :         {
   15915            3 :           error_at (OMP_CLAUSE_LOCATION (c),
   15916              :                     "%qD is threadprivate variable in %qs clause", t,
   15917            3 :                     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   15918            3 :           return error_mark_node;
   15919              :         }
   15920         2985 :       if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
   15921         2882 :            || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND)
   15922          416 :           && TYPE_ATOMIC (TREE_TYPE (t))
   15923         2987 :           && POINTER_TYPE_P (TREE_TYPE (t)))
   15924              :         {
   15925              :           /* If the array section is pointer based and the pointer
   15926              :              itself is _Atomic qualified, we need to atomically load
   15927              :              the pointer.  */
   15928            2 :           ret = convert_lvalue_to_rvalue (OMP_CLAUSE_LOCATION (c),
   15929              :                                           ret, false, false);
   15930              :         }
   15931              :       return ret;
   15932         2999 :     }
   15933              : 
   15934         3442 :   ret = handle_omp_array_sections_1 (c, TREE_OPERAND (t, 0), types,
   15935              :                                      maybe_zero_len, first_non_one, ort);
   15936         3442 :   if (ret == error_mark_node || ret == NULL_TREE)
   15937              :     return ret;
   15938              : 
   15939         3374 :   type = TREE_TYPE (ret);
   15940         3374 :   low_bound = TREE_OPERAND (t, 1);
   15941         3374 :   length = TREE_OPERAND (t, 2);
   15942              : 
   15943         3374 :   if (low_bound == error_mark_node || length == error_mark_node)
   15944              :     return error_mark_node;
   15945              : 
   15946         3374 :   if (low_bound && !INTEGRAL_TYPE_P (TREE_TYPE (low_bound)))
   15947              :     {
   15948           13 :       error_at (OMP_CLAUSE_LOCATION (c),
   15949              :                 "low bound %qE of array section does not have integral type",
   15950              :                 low_bound);
   15951           13 :       return error_mark_node;
   15952              :     }
   15953         3361 :   if (length && !INTEGRAL_TYPE_P (TREE_TYPE (length)))
   15954              :     {
   15955           12 :       error_at (OMP_CLAUSE_LOCATION (c),
   15956              :                 "length %qE of array section does not have integral type",
   15957              :                 length);
   15958           12 :       return error_mark_node;
   15959              :     }
   15960         3349 :   if (low_bound
   15961         2758 :       && TREE_CODE (low_bound) == INTEGER_CST
   15962         5815 :       && TYPE_PRECISION (TREE_TYPE (low_bound))
   15963         2466 :          > TYPE_PRECISION (sizetype))
   15964            0 :     low_bound = fold_convert (sizetype, low_bound);
   15965         3349 :   if (length
   15966         3157 :       && TREE_CODE (length) == INTEGER_CST
   15967         5559 :       && TYPE_PRECISION (TREE_TYPE (length))
   15968         2210 :          > TYPE_PRECISION (sizetype))
   15969            0 :     length = fold_convert (sizetype, length);
   15970         3349 :   if (low_bound == NULL_TREE)
   15971          591 :     low_bound = integer_zero_node;
   15972         3349 :   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   15973         3349 :       && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
   15974         1948 :           || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH))
   15975              :     {
   15976           10 :       if (length != integer_one_node)
   15977              :         {
   15978            6 :           error_at (OMP_CLAUSE_LOCATION (c),
   15979              :                     "expected single pointer in %qs clause",
   15980              :                     user_omp_clause_code_name (c, openacc));
   15981            6 :           return error_mark_node;
   15982              :         }
   15983              :     }
   15984         3343 :   if (length != NULL_TREE)
   15985              :     {
   15986         3155 :       if (!integer_nonzerop (length))
   15987              :         {
   15988          978 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
   15989              :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   15990              :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   15991              :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   15992              :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
   15993              :             {
   15994          180 :               if (integer_zerop (length))
   15995              :                 {
   15996           12 :                   error_at (OMP_CLAUSE_LOCATION (c),
   15997              :                             "zero length array section in %qs clause",
   15998           12 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   15999           12 :                   return error_mark_node;
   16000              :                 }
   16001              :             }
   16002              :           else
   16003          798 :             maybe_zero_len = true;
   16004              :         }
   16005         3143 :       if (first_non_one == types.length ()
   16006         3143 :           && (TREE_CODE (length) != INTEGER_CST || integer_onep (length)))
   16007         1609 :         first_non_one++;
   16008              :     }
   16009         3331 :   if (TREE_CODE (type) == ARRAY_TYPE)
   16010              :     {
   16011         1503 :       if (length == NULL_TREE
   16012         1503 :           && (TYPE_DOMAIN (type) == NULL_TREE
   16013          170 :               || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE))
   16014              :         {
   16015            8 :           error_at (OMP_CLAUSE_LOCATION (c),
   16016              :                     "for unknown bound array type length expression must "
   16017              :                     "be specified");
   16018            8 :           return error_mark_node;
   16019              :         }
   16020         1495 :       if (TREE_CODE (low_bound) == INTEGER_CST
   16021         1495 :           && tree_int_cst_sgn (low_bound) == -1)
   16022              :         {
   16023           36 :           error_at (OMP_CLAUSE_LOCATION (c),
   16024              :                     "negative low bound in array section in %qs clause",
   16025           36 :                     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16026           36 :           return error_mark_node;
   16027              :         }
   16028         1459 :       if (length != NULL_TREE
   16029         1302 :           && TREE_CODE (length) == INTEGER_CST
   16030         2321 :           && tree_int_cst_sgn (length) == -1)
   16031              :         {
   16032           36 :           error_at (OMP_CLAUSE_LOCATION (c),
   16033              :                     "negative length in array section in %qs clause",
   16034           36 :                     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16035           36 :           return error_mark_node;
   16036              :         }
   16037         1423 :       if (TYPE_DOMAIN (type)
   16038         1412 :           && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
   16039         2835 :           && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
   16040              :                         == INTEGER_CST)
   16041              :         {
   16042         1066 :           tree size
   16043         1066 :             = fold_convert (sizetype, TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
   16044         1066 :           size = size_binop (PLUS_EXPR, size, size_one_node);
   16045         1066 :           if (TREE_CODE (low_bound) == INTEGER_CST)
   16046              :             {
   16047          879 :               if (tree_int_cst_lt (size, low_bound))
   16048              :                 {
   16049           11 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16050              :                             "low bound %qE above array section size "
   16051              :                             "in %qs clause", low_bound,
   16052           11 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16053           11 :                   return error_mark_node;
   16054              :                 }
   16055          868 :               if (tree_int_cst_equal (size, low_bound))
   16056              :                 {
   16057            5 :                   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
   16058              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   16059              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   16060              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   16061              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
   16062              :                     {
   16063            5 :                       error_at (OMP_CLAUSE_LOCATION (c),
   16064              :                                 "zero length array section in %qs clause",
   16065            5 :                                 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16066            5 :                       return error_mark_node;
   16067              :                     }
   16068            0 :                   maybe_zero_len = true;
   16069              :                 }
   16070          863 :               else if (length == NULL_TREE
   16071          256 :                        && first_non_one == types.length ()
   16072          918 :                        && tree_int_cst_equal
   16073           55 :                             (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
   16074              :                              low_bound))
   16075           30 :                 first_non_one++;
   16076              :             }
   16077          187 :           else if (length == NULL_TREE)
   16078              :             {
   16079            3 :               if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
   16080              :                   && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
   16081              :                   && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
   16082              :                   && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
   16083              :                   && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
   16084            0 :                 maybe_zero_len = true;
   16085            6 :               if (first_non_one == types.length ())
   16086            1 :                 first_non_one++;
   16087              :             }
   16088         1050 :           if (length && TREE_CODE (length) == INTEGER_CST)
   16089              :             {
   16090          803 :               if (tree_int_cst_lt (size, length))
   16091              :                 {
   16092           11 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16093              :                             "length %qE above array section size "
   16094              :                             "in %qs clause", length,
   16095           11 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16096           11 :                   return error_mark_node;
   16097              :                 }
   16098          792 :               if (TREE_CODE (low_bound) == INTEGER_CST)
   16099              :                 {
   16100          692 :                   tree lbpluslen
   16101          692 :                     = size_binop (PLUS_EXPR,
   16102              :                                   fold_convert (sizetype, low_bound),
   16103              :                                   fold_convert (sizetype, length));
   16104          692 :                   if (TREE_CODE (lbpluslen) == INTEGER_CST
   16105          692 :                       && tree_int_cst_lt (size, lbpluslen))
   16106              :                     {
   16107           10 :                       error_at (OMP_CLAUSE_LOCATION (c),
   16108              :                                 "high bound %qE above array section size "
   16109              :                                 "in %qs clause", lbpluslen,
   16110           10 :                                 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16111           10 :                       return error_mark_node;
   16112              :                     }
   16113              :                 }
   16114              :             }
   16115              :         }
   16116          357 :       else if (length == NULL_TREE)
   16117              :         {
   16118           10 :           if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
   16119              :               && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
   16120              :               && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
   16121              :               && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
   16122              :               && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
   16123            0 :             maybe_zero_len = true;
   16124           20 :           if (first_non_one == types.length ())
   16125           10 :             first_non_one++;
   16126              :         }
   16127              : 
   16128              :       /* For [lb:] we will need to evaluate lb more than once.  */
   16129          933 :       if (length == NULL_TREE && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
   16130              :         {
   16131          127 :           tree lb = save_expr (low_bound);
   16132          127 :           if (lb != low_bound)
   16133              :             {
   16134            2 :               TREE_OPERAND (t, 1) = lb;
   16135            2 :               low_bound = lb;
   16136              :             }
   16137              :         }
   16138              :     }
   16139         1828 :   else if (TREE_CODE (type) == POINTER_TYPE)
   16140              :     {
   16141         1817 :       if (length == NULL_TREE)
   16142              :         {
   16143           12 :           if (TREE_CODE (ret) == PARM_DECL && C_ARRAY_PARAMETER (ret))
   16144           10 :             error_at (OMP_CLAUSE_LOCATION (c),
   16145              :                       "for array function parameter length expression "
   16146              :                       "must be specified");
   16147              :           else
   16148            2 :             error_at (OMP_CLAUSE_LOCATION (c),
   16149              :                       "for pointer type length expression must be specified");
   16150           12 :           return error_mark_node;
   16151              :         }
   16152         1805 :       if (length != NULL_TREE
   16153         1805 :           && TREE_CODE (length) == INTEGER_CST
   16154         1298 :           && tree_int_cst_sgn (length) == -1)
   16155              :         {
   16156           20 :           error_at (OMP_CLAUSE_LOCATION (c),
   16157              :                     "negative length in array section in %qs clause",
   16158           20 :                     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16159           20 :           return error_mark_node;
   16160              :         }
   16161              :       /* If there is a pointer type anywhere but in the very first
   16162              :          array-section-subscript, the array section could be non-contiguous.  */
   16163         1785 :       if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
   16164         1624 :           && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
   16165         3380 :           && TREE_CODE (TREE_OPERAND (t, 0)) == OMP_ARRAY_SECTION)
   16166              :         {
   16167              :           /* If any prior dimension has a non-one length, then deem this
   16168              :              array section as non-contiguous.  */
   16169           42 :           for (tree d = TREE_OPERAND (t, 0);
   16170           82 :                TREE_CODE (d) == OMP_ARRAY_SECTION;
   16171           40 :                d = TREE_OPERAND (d, 0))
   16172              :             {
   16173           44 :               tree d_length = TREE_OPERAND (d, 2);
   16174           44 :               if (d_length == NULL_TREE || !integer_onep (d_length))
   16175              :                 {
   16176            4 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16177              :                             "array section is not contiguous in %qs clause",
   16178            4 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16179            4 :                   return error_mark_node;
   16180              :                 }
   16181              :             }
   16182              :         }
   16183              :     }
   16184              :   else
   16185              :     {
   16186           11 :       error_at (OMP_CLAUSE_LOCATION (c),
   16187              :                 "%qE does not have pointer or array type", ret);
   16188           11 :       return error_mark_node;
   16189              :     }
   16190         3167 :   if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
   16191         2851 :     types.safe_push (TREE_TYPE (ret));
   16192              :   /* We will need to evaluate lb more than once.  */
   16193         3167 :   tree lb = save_expr (low_bound);
   16194         3167 :   if (lb != low_bound)
   16195              :     {
   16196          276 :       TREE_OPERAND (t, 1) = lb;
   16197          276 :       low_bound = lb;
   16198              :     }
   16199         3167 :   ret = build_array_ref (OMP_CLAUSE_LOCATION (c), ret, low_bound);
   16200         3167 :   return ret;
   16201              : }
   16202              : 
   16203              : /* Handle array sections for clause C.  */
   16204              : 
   16205              : static bool
   16206         3001 : handle_omp_array_sections (tree &c, enum c_omp_region_type ort)
   16207              : {
   16208         3001 :   bool maybe_zero_len = false;
   16209         3001 :   unsigned int first_non_one = 0;
   16210         3001 :   auto_vec<tree, 10> types;
   16211         3001 :   tree *tp = &OMP_CLAUSE_DECL (c);
   16212         3001 :   if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   16213         2687 :        || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
   16214         3105 :       && OMP_ITERATOR_DECL_P (*tp))
   16215           66 :     tp = &TREE_VALUE (*tp);
   16216         3001 :   tree first = handle_omp_array_sections_1 (c, *tp, types,
   16217              :                                             maybe_zero_len, first_non_one,
   16218              :                                             ort);
   16219         3001 :   if (first == error_mark_node)
   16220              :     return true;
   16221         2778 :   if (first == NULL_TREE)
   16222              :     return false;
   16223         2778 :   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   16224         2778 :       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
   16225              :     {
   16226          336 :       tree t = *tp;
   16227          336 :       tree tem = NULL_TREE;
   16228              :       /* Need to evaluate side effects in the length expressions
   16229              :          if any.  */
   16230          336 :       while (TREE_CODE (t) == TREE_LIST)
   16231              :         {
   16232            0 :           if (TREE_VALUE (t) && TREE_SIDE_EFFECTS (TREE_VALUE (t)))
   16233              :             {
   16234            0 :               if (tem == NULL_TREE)
   16235              :                 tem = TREE_VALUE (t);
   16236              :               else
   16237            0 :                 tem = build2 (COMPOUND_EXPR, TREE_TYPE (tem),
   16238            0 :                               TREE_VALUE (t), tem);
   16239              :             }
   16240            0 :           t = TREE_CHAIN (t);
   16241              :         }
   16242          336 :       if (tem)
   16243            0 :         first = build2 (COMPOUND_EXPR, TREE_TYPE (first), tem, first);
   16244          336 :       first = c_fully_fold (first, false, NULL, true);
   16245          336 :       *tp = first;
   16246              :     }
   16247              :   else
   16248              :     {
   16249         2442 :       unsigned int num = types.length (), i;
   16250         2442 :       tree t, side_effects = NULL_TREE, size = NULL_TREE;
   16251         2442 :       tree condition = NULL_TREE;
   16252              : 
   16253         2442 :       if (int_size_in_bytes (TREE_TYPE (first)) <= 0)
   16254            3 :         maybe_zero_len = true;
   16255              : 
   16256         5084 :       for (i = num, t = OMP_CLAUSE_DECL (c); i > 0;
   16257         2642 :            t = TREE_OPERAND (t, 0))
   16258              :         {
   16259         2657 :           tree low_bound = TREE_OPERAND (t, 1);
   16260         2657 :           tree length = TREE_OPERAND (t, 2);
   16261              : 
   16262         2657 :           i--;
   16263         2657 :           if (low_bound
   16264         2189 :               && TREE_CODE (low_bound) == INTEGER_CST
   16265         4657 :               && TYPE_PRECISION (TREE_TYPE (low_bound))
   16266         2000 :                  > TYPE_PRECISION (sizetype))
   16267            0 :             low_bound = fold_convert (sizetype, low_bound);
   16268         2657 :           if (length
   16269         2565 :               && TREE_CODE (length) == INTEGER_CST
   16270         4293 :               && TYPE_PRECISION (TREE_TYPE (length))
   16271         1636 :                  > TYPE_PRECISION (sizetype))
   16272            0 :             length = fold_convert (sizetype, length);
   16273         2657 :           if (low_bound == NULL_TREE)
   16274          468 :             low_bound = integer_zero_node;
   16275         2657 :           if (!maybe_zero_len && i > first_non_one)
   16276              :             {
   16277          109 :               if (integer_nonzerop (low_bound))
   16278            6 :                 goto do_warn_noncontiguous;
   16279          103 :               if (length != NULL_TREE
   16280           50 :                   && TREE_CODE (length) == INTEGER_CST
   16281           50 :                   && TYPE_DOMAIN (types[i])
   16282           50 :                   && TYPE_MAX_VALUE (TYPE_DOMAIN (types[i]))
   16283          153 :                   && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])))
   16284              :                      == INTEGER_CST)
   16285              :                 {
   16286           50 :                   tree size;
   16287           50 :                   size = size_binop (PLUS_EXPR,
   16288              :                                      TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
   16289              :                                      size_one_node);
   16290           50 :                   if (!tree_int_cst_equal (length, size))
   16291              :                     {
   16292            7 :                      do_warn_noncontiguous:
   16293           26 :                       error_at (OMP_CLAUSE_LOCATION (c),
   16294              :                                 "array section is not contiguous in %qs "
   16295              :                                 "clause",
   16296           13 :                                 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16297         2442 :                       return true;
   16298              :                     }
   16299              :                 }
   16300           96 :               if (length != NULL_TREE
   16301           96 :                   && TREE_SIDE_EFFECTS (length))
   16302              :                 {
   16303            0 :                   if (side_effects == NULL_TREE)
   16304              :                     side_effects = length;
   16305              :                   else
   16306            0 :                     side_effects = build2 (COMPOUND_EXPR,
   16307            0 :                                            TREE_TYPE (side_effects),
   16308              :                                            length, side_effects);
   16309              :                 }
   16310              :             }
   16311              :           else
   16312              :             {
   16313         2548 :               tree l;
   16314              : 
   16315         2548 :               if (i > first_non_one
   16316         2548 :                   && ((length && integer_nonzerop (length))
   16317            0 :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   16318              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   16319              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION))
   16320            0 :                 continue;
   16321         2548 :               if (length)
   16322         2515 :                 l = fold_convert (sizetype, length);
   16323              :               else
   16324              :                 {
   16325           33 :                   l = size_binop (PLUS_EXPR,
   16326              :                                   TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
   16327              :                                   size_one_node);
   16328           33 :                   l = size_binop (MINUS_EXPR, l,
   16329              :                                   fold_convert (sizetype, low_bound));
   16330              :                 }
   16331         2548 :               if (i > first_non_one)
   16332              :                 {
   16333            0 :                   l = fold_build2 (NE_EXPR, boolean_type_node, l,
   16334              :                                    size_zero_node);
   16335            0 :                   if (condition == NULL_TREE)
   16336              :                     condition = l;
   16337              :                   else
   16338            0 :                     condition = fold_build2 (BIT_AND_EXPR, boolean_type_node,
   16339              :                                              l, condition);
   16340              :                 }
   16341         2548 :               else if (size == NULL_TREE)
   16342              :                 {
   16343         2429 :                   size = size_in_bytes (TREE_TYPE (types[i]));
   16344         2429 :                   tree eltype = TREE_TYPE (types[num - 1]);
   16345         2449 :                   while (TREE_CODE (eltype) == ARRAY_TYPE)
   16346           20 :                     eltype = TREE_TYPE (eltype);
   16347         2429 :                   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   16348         2194 :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   16349         4363 :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
   16350              :                     {
   16351          539 :                       if (integer_zerop (size)
   16352         1076 :                           || integer_zerop (size_in_bytes (eltype)))
   16353              :                         {
   16354            4 :                           error_at (OMP_CLAUSE_LOCATION (c),
   16355              :                                     "zero length array section in %qs clause",
   16356            2 :                                     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16357            2 :                           return error_mark_node;
   16358              :                         }
   16359          537 :                       size = size_binop (EXACT_DIV_EXPR, size,
   16360              :                                          size_in_bytes (eltype));
   16361              :                     }
   16362         2427 :                   size = size_binop (MULT_EXPR, size, l);
   16363         2427 :                   if (condition)
   16364            0 :                     size = fold_build3 (COND_EXPR, sizetype, condition,
   16365              :                                         size, size_zero_node);
   16366              :                 }
   16367              :               else
   16368          119 :                 size = size_binop (MULT_EXPR, size, l);
   16369              :             }
   16370              :         }
   16371         2427 :       if (side_effects)
   16372            0 :         size = build2 (COMPOUND_EXPR, sizetype, side_effects, size);
   16373         2427 :       if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   16374         2194 :           || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   16375         4361 :           || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
   16376              :         {
   16377          537 :           size = size_binop (MINUS_EXPR, size, size_one_node);
   16378          537 :           size = c_fully_fold (size, false, NULL);
   16379          537 :           size = save_expr (size);
   16380          537 :           tree index_type = build_index_type (size);
   16381          537 :           tree eltype = TREE_TYPE (first);
   16382          549 :           while (TREE_CODE (eltype) == ARRAY_TYPE)
   16383           12 :             eltype = TREE_TYPE (eltype);
   16384          537 :           tree type = c_build_array_type (eltype, index_type);
   16385          537 :           tree ptype = c_build_pointer_type (eltype);
   16386          537 :           if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
   16387          296 :             t = build_fold_addr_expr (t);
   16388          537 :           tree t2 = build_fold_addr_expr (first);
   16389          537 :           t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
   16390              :                                  ptrdiff_type_node, t2);
   16391          537 :           t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
   16392              :                                 ptrdiff_type_node, t2,
   16393          537 :                                 fold_convert_loc (OMP_CLAUSE_LOCATION (c),
   16394              :                                                   ptrdiff_type_node, t));
   16395          537 :           t2 = c_fully_fold (t2, false, NULL);
   16396          537 :           if (tree_fits_shwi_p (t2))
   16397          398 :             t = build2 (MEM_REF, type, t,
   16398          398 :                         build_int_cst (ptype, tree_to_shwi (t2)));
   16399              :           else
   16400              :             {
   16401          139 :               t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c), sizetype, t2);
   16402          139 :               t = build2_loc (OMP_CLAUSE_LOCATION (c), POINTER_PLUS_EXPR,
   16403          139 :                               TREE_TYPE (t), t, t2);
   16404          139 :               t = build2 (MEM_REF, type, t, build_int_cst (ptype, 0));
   16405              :             }
   16406          537 :           OMP_CLAUSE_DECL (c) = t;
   16407          537 :           return false;
   16408              :         }
   16409         1890 :       first = c_fully_fold (first, false, NULL);
   16410         1890 :       OMP_CLAUSE_DECL (c) = first;
   16411         1890 :       if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
   16412              :         return false;
   16413              :       /* Don't set OMP_CLAUSE_SIZE for bare attach/detach clauses.  */
   16414         1879 :       if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
   16415         1879 :           || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
   16416         1733 :               && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH
   16417         1731 :               && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FORCE_DETACH))
   16418              :         {
   16419         1875 :           if (size)
   16420         1875 :             size = c_fully_fold (size, false, NULL);
   16421         1875 :           OMP_CLAUSE_SIZE (c) = size;
   16422              :         }
   16423              : 
   16424         1879 :       if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
   16425              :         return false;
   16426              : 
   16427         1735 :       auto_vec<omp_addr_token *, 10> addr_tokens;
   16428              : 
   16429         1735 :       if (!omp_parse_expr (addr_tokens, first))
   16430         1735 :         return true;
   16431              : 
   16432         1735 :       c_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
   16433              : 
   16434         1735 :       tree nc = ai.expand_map_clause (c, first, addr_tokens, ort);
   16435         1735 :       if (nc != error_mark_node)
   16436              :         {
   16437         1735 :           using namespace omp_addr_tokenizer;
   16438              : 
   16439         1735 :           if (ai.maybe_zero_length_array_section (c))
   16440         1731 :             OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
   16441              : 
   16442              :           /* !!! If we're accessing a base decl via chained access
   16443              :              methods (e.g. multiple indirections), duplicate clause
   16444              :              detection won't work properly.  Skip it in that case.  */
   16445         1735 :           if ((addr_tokens[0]->type == STRUCTURE_BASE
   16446         1445 :                || addr_tokens[0]->type == ARRAY_BASE)
   16447         1735 :               && addr_tokens[0]->u.structure_base_kind == BASE_DECL
   16448         1735 :               && addr_tokens[1]->type == ACCESS_METHOD
   16449         3470 :               && omp_access_chain_p (addr_tokens, 1))
   16450           36 :             c = nc;
   16451              : 
   16452         1735 :           return false;
   16453              :         }
   16454              :     }
   16455              :   return false;
   16456         3001 : }
   16457              : 
   16458              : /* Helper function of finish_omp_clauses.  Clone STMT as if we were making
   16459              :    an inline call.  But, remap
   16460              :    the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
   16461              :    and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL.  */
   16462              : 
   16463              : static tree
   16464          516 : c_clone_omp_udr (tree stmt, tree omp_decl1, tree omp_decl2,
   16465              :                  tree decl, tree placeholder)
   16466              : {
   16467          516 :   copy_body_data id;
   16468          516 :   hash_map<tree, tree> decl_map;
   16469              : 
   16470          516 :   decl_map.put (omp_decl1, placeholder);
   16471          516 :   decl_map.put (omp_decl2, decl);
   16472          516 :   memset (&id, 0, sizeof (id));
   16473          516 :   id.src_fn = DECL_CONTEXT (omp_decl1);
   16474          516 :   id.dst_fn = current_function_decl;
   16475          516 :   id.src_cfun = DECL_STRUCT_FUNCTION (id.src_fn);
   16476          516 :   id.decl_map = &decl_map;
   16477              : 
   16478          516 :   id.copy_decl = copy_decl_no_change;
   16479          516 :   id.transform_call_graph_edges = CB_CGE_DUPLICATE;
   16480          516 :   id.transform_new_cfg = true;
   16481          516 :   id.transform_return_to_modify = false;
   16482          516 :   id.eh_lp_nr = 0;
   16483          516 :   walk_tree (&stmt, copy_tree_body_r, &id, NULL);
   16484          516 :   return stmt;
   16485          516 : }
   16486              : 
   16487              : /* Helper function of c_finish_omp_clauses, called via walk_tree.
   16488              :    Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP.  */
   16489              : 
   16490              : static tree
   16491         1147 : c_find_omp_placeholder_r (tree *tp, int *, void *data)
   16492              : {
   16493         1147 :   if (*tp == (tree) data)
   16494           31 :     return *tp;
   16495              :   return NULL_TREE;
   16496              : }
   16497              : 
   16498              : /* Similarly, but also walk aggregate fields.  */
   16499              : 
   16500              : struct c_find_omp_var_s { tree var; hash_set<tree> *pset; };
   16501              : 
   16502              : static tree
   16503          288 : c_find_omp_var_r (tree *tp, int *, void *data)
   16504              : {
   16505          288 :   if (*tp == ((struct c_find_omp_var_s *) data)->var)
   16506              :     return *tp;
   16507          280 :   if (RECORD_OR_UNION_TYPE_P (*tp))
   16508              :     {
   16509            2 :       tree field;
   16510            2 :       hash_set<tree> *pset = ((struct c_find_omp_var_s *) data)->pset;
   16511              : 
   16512            2 :       for (field = TYPE_FIELDS (*tp); field;
   16513            0 :            field = DECL_CHAIN (field))
   16514            2 :         if (TREE_CODE (field) == FIELD_DECL)
   16515              :           {
   16516            2 :             tree ret = walk_tree (&DECL_FIELD_OFFSET (field),
   16517              :                                   c_find_omp_var_r, data, pset);
   16518            2 :             if (ret)
   16519              :               return ret;
   16520            2 :             ret = walk_tree (&DECL_SIZE (field), c_find_omp_var_r, data, pset);
   16521            2 :             if (ret)
   16522              :               return ret;
   16523            2 :             ret = walk_tree (&DECL_SIZE_UNIT (field), c_find_omp_var_r, data,
   16524              :                              pset);
   16525            2 :             if (ret)
   16526              :               return ret;
   16527            2 :             ret = walk_tree (&TREE_TYPE (field), c_find_omp_var_r, data, pset);
   16528            2 :             if (ret)
   16529              :               return ret;
   16530              :           }
   16531              :     }
   16532          278 :   else if (INTEGRAL_TYPE_P (*tp))
   16533           45 :     return walk_tree (&TYPE_MAX_VALUE (*tp), c_find_omp_var_r, data,
   16534              :                       ((struct c_find_omp_var_s *) data)->pset);
   16535              :   return NULL_TREE;
   16536              : }
   16537              : 
   16538              : /* Finish OpenMP iterators ITER.  Return true if they are erroneous
   16539              :    and clauses containing them should be removed.  */
   16540              : 
   16541              : static bool
   16542          146 : c_omp_finish_iterators (tree iter)
   16543              : {
   16544          146 :   bool ret = false;
   16545          331 :   for (tree it = iter; it; it = TREE_CHAIN (it))
   16546              :     {
   16547          185 :       tree var = OMP_ITERATOR_VAR (it);
   16548          185 :       tree begin = OMP_ITERATOR_BEGIN (it);
   16549          185 :       tree end = OMP_ITERATOR_END (it);
   16550          185 :       tree step = OMP_ITERATOR_STEP (it);
   16551          185 :       tree orig_step;
   16552          185 :       tree type = TREE_TYPE (var);
   16553          185 :       location_t loc = DECL_SOURCE_LOCATION (var);
   16554          185 :       if (type == error_mark_node)
   16555              :         {
   16556            0 :           ret = true;
   16557           34 :           continue;
   16558              :         }
   16559          185 :       if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type))
   16560              :         {
   16561            6 :           error_at (loc, "iterator %qD has neither integral nor pointer type",
   16562              :                     var);
   16563            6 :           ret = true;
   16564            6 :           continue;
   16565              :         }
   16566          179 :       else if (TYPE_ATOMIC (type))
   16567              :         {
   16568            2 :           error_at (loc, "iterator %qD has %<_Atomic%> qualified type", var);
   16569            2 :           ret = true;
   16570            2 :           continue;
   16571              :         }
   16572          177 :       else if (TYPE_READONLY (type))
   16573              :         {
   16574            4 :           error_at (loc, "iterator %qD has const qualified type", var);
   16575            4 :           ret = true;
   16576            4 :           continue;
   16577              :         }
   16578          173 :       else if (step == error_mark_node
   16579          173 :                || TREE_TYPE (step) == error_mark_node)
   16580              :         {
   16581            0 :           ret = true;
   16582            0 :           continue;
   16583              :         }
   16584          173 :       else if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
   16585              :         {
   16586            4 :           error_at (EXPR_LOC_OR_LOC (step, loc),
   16587              :                     "iterator step with non-integral type");
   16588            4 :           ret = true;
   16589            4 :           continue;
   16590              :         }
   16591          169 :       begin = c_fully_fold (build_c_cast (loc, type, begin), false, NULL);
   16592          169 :       end = c_fully_fold (build_c_cast (loc, type, end), false, NULL);
   16593          169 :       orig_step = save_expr (c_fully_fold (step, false, NULL));
   16594          169 :       tree stype = POINTER_TYPE_P (type) ? sizetype : type;
   16595          169 :       step = c_fully_fold (build_c_cast (loc, stype, orig_step), false, NULL);
   16596          169 :       if (POINTER_TYPE_P (type))
   16597              :         {
   16598           14 :           begin = save_expr (begin);
   16599           14 :           step = pointer_int_sum (loc, PLUS_EXPR, begin, step);
   16600           14 :           step = fold_build2_loc (loc, MINUS_EXPR, sizetype,
   16601              :                                   fold_convert (sizetype, step),
   16602              :                                   fold_convert (sizetype, begin));
   16603           14 :           step = fold_convert (ssizetype, step);
   16604              :         }
   16605          169 :       if (integer_zerop (step))
   16606              :         {
   16607            6 :           error_at (loc, "iterator %qD has zero step", var);
   16608            6 :           ret = true;
   16609            6 :           continue;
   16610              :         }
   16611              : 
   16612          163 :       if (begin == error_mark_node
   16613          161 :           || end == error_mark_node
   16614          159 :           || step == error_mark_node
   16615          159 :           || orig_step == error_mark_node)
   16616              :         {
   16617            4 :           ret = true;
   16618            4 :           continue;
   16619              :         }
   16620          159 :       hash_set<tree> pset;
   16621          159 :       tree it2;
   16622          200 :       for (it2 = TREE_CHAIN (it); it2; it2 = TREE_CHAIN (it2))
   16623              :         {
   16624           49 :           tree var2 = OMP_ITERATOR_VAR (it2);
   16625           49 :           tree begin2 = OMP_ITERATOR_BEGIN (it2);
   16626           49 :           tree end2 = OMP_ITERATOR_END (it2);
   16627           49 :           tree step2 = OMP_ITERATOR_STEP (it2);
   16628           49 :           tree type2 = TREE_TYPE (var2);
   16629           49 :           location_t loc2 = DECL_SOURCE_LOCATION (var2);
   16630           49 :           struct c_find_omp_var_s data = { var, &pset };
   16631           49 :           if (walk_tree (&type2, c_find_omp_var_r, &data, &pset))
   16632              :             {
   16633            2 :               error_at (loc2,
   16634              :                         "type of iterator %qD refers to outer iterator %qD",
   16635              :                         var2, var);
   16636           10 :               break;
   16637              :             }
   16638           47 :           else if (walk_tree (&begin2, c_find_omp_var_r, &data, &pset))
   16639              :             {
   16640            2 :               error_at (EXPR_LOC_OR_LOC (begin2, loc2),
   16641              :                         "begin expression refers to outer iterator %qD", var);
   16642            2 :               break;
   16643              :             }
   16644           45 :           else if (walk_tree (&end2, c_find_omp_var_r, &data, &pset))
   16645              :             {
   16646            2 :               error_at (EXPR_LOC_OR_LOC (end2, loc2),
   16647              :                         "end expression refers to outer iterator %qD", var);
   16648            2 :               break;
   16649              :             }
   16650           43 :           else if (walk_tree (&step2, c_find_omp_var_r, &data, &pset))
   16651              :             {
   16652            2 :               error_at (EXPR_LOC_OR_LOC (step2, loc2),
   16653              :                         "step expression refers to outer iterator %qD", var);
   16654            2 :               break;
   16655              :             }
   16656              :         }
   16657          159 :       if (it2)
   16658              :         {
   16659            8 :           ret = true;
   16660            8 :           continue;
   16661              :         }
   16662          151 :       OMP_ITERATOR_BEGIN (it) = begin;
   16663          151 :       OMP_ITERATOR_END (it) = end;
   16664          151 :       OMP_ITERATOR_STEP (it) = step;
   16665          151 :       OMP_ITERATOR_ORIG_STEP (it) = orig_step;
   16666          159 :     }
   16667          146 :   return ret;
   16668              : }
   16669              : 
   16670              : /* Ensure that pointers are used in OpenACC attach and detach clauses.
   16671              :    Return true if an error has been detected.  */
   16672              : 
   16673              : static bool
   16674         9726 : c_oacc_check_attachments (tree c)
   16675              : {
   16676         9726 :   if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
   16677              :     return false;
   16678              : 
   16679              :   /* OpenACC attach / detach clauses must be pointers.  */
   16680         6680 :   if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
   16681         6680 :       || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
   16682              :     {
   16683           75 :       tree t = OMP_CLAUSE_DECL (c);
   16684              : 
   16685           81 :       while (TREE_CODE (t) == OMP_ARRAY_SECTION)
   16686            6 :         t = TREE_OPERAND (t, 0);
   16687              : 
   16688           75 :       if (TREE_CODE (TREE_TYPE (t)) != POINTER_TYPE)
   16689              :         {
   16690            6 :           error_at (OMP_CLAUSE_LOCATION (c), "expected pointer in %qs clause",
   16691              :                     user_omp_clause_code_name (c, true));
   16692            6 :           return true;
   16693              :         }
   16694              :     }
   16695              : 
   16696              :   return false;
   16697              : }
   16698              : 
   16699              : /* For all elements of CLAUSES, validate them against their constraints.
   16700              :    Remove any elements from the list that are invalid.  */
   16701              : 
   16702              : tree
   16703        29789 : c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
   16704              : {
   16705        29789 :   bitmap_head generic_head, firstprivate_head, lastprivate_head;
   16706        29789 :   bitmap_head aligned_head, map_head, map_field_head, map_firstprivate_head;
   16707        29789 :   bitmap_head oacc_reduction_head, is_on_device_head;
   16708        29789 :   tree c, t, type, *pc;
   16709        29789 :   tree simdlen = NULL_TREE, safelen = NULL_TREE;
   16710        29789 :   bool branch_seen = false;
   16711        29789 :   bool copyprivate_seen = false;
   16712        29789 :   bool mergeable_seen = false;
   16713        29789 :   tree *detach_seen = NULL;
   16714        29789 :   bool linear_variable_step_check = false;
   16715        29789 :   tree *nowait_clause = NULL;
   16716        29789 :   tree *grainsize_seen = NULL;
   16717        29789 :   bool num_tasks_seen = false;
   16718        29789 :   tree ordered_clause = NULL_TREE;
   16719        29789 :   tree schedule_clause = NULL_TREE;
   16720        29789 :   bool oacc_async = false;
   16721        29789 :   tree last_iterators = NULL_TREE;
   16722        29789 :   bool last_iterators_remove = false;
   16723        29789 :   tree *nogroup_seen = NULL;
   16724        29789 :   tree *order_clause = NULL;
   16725              :   /* 1 if normal/task reduction has been seen, -1 if inscan reduction
   16726              :      has been seen, -2 if mixed inscan/normal reduction diagnosed.  */
   16727        29789 :   int reduction_seen = 0;
   16728        29789 :   bool allocate_seen = false;
   16729        29789 :   bool implicit_moved = false;
   16730        29789 :   bool target_in_reduction_seen = false;
   16731        29789 :   tree *full_seen = NULL;
   16732        29789 :   bool partial_seen = false;
   16733        29789 :   bool openacc = (ort & C_ORT_ACC) != 0;
   16734        29789 :   bool init_seen = false;
   16735        29789 :   bool init_use_destroy_seen = false;
   16736        29789 :   tree init_no_targetsync_clause = NULL_TREE;
   16737        29789 :   tree depend_clause = NULL_TREE;
   16738              : 
   16739        29789 :   if (!openacc)
   16740        24552 :     clauses = omp_remove_duplicate_maps (clauses, true);
   16741              : 
   16742        29789 :   bitmap_obstack_initialize (NULL);
   16743        29789 :   bitmap_initialize (&generic_head, &bitmap_default_obstack);
   16744        29789 :   bitmap_initialize (&firstprivate_head, &bitmap_default_obstack);
   16745        29789 :   bitmap_initialize (&lastprivate_head, &bitmap_default_obstack);
   16746        29789 :   bitmap_initialize (&aligned_head, &bitmap_default_obstack);
   16747              :   /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead.  */
   16748        29789 :   bitmap_initialize (&map_head, &bitmap_default_obstack);
   16749        29789 :   bitmap_initialize (&map_field_head, &bitmap_default_obstack);
   16750        29789 :   bitmap_initialize (&map_firstprivate_head, &bitmap_default_obstack);
   16751              :   /* If ort == C_ORT_OMP used as nontemporal_head or use_device_xxx_head
   16752              :      instead and for ort == C_ORT_OMP_TARGET used as in_reduction_head.  */
   16753        29789 :   bitmap_initialize (&oacc_reduction_head, &bitmap_default_obstack);
   16754        29789 :   bitmap_initialize (&is_on_device_head, &bitmap_default_obstack);
   16755              : 
   16756        29789 :   if (openacc)
   16757        12269 :     for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
   16758         7258 :       if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ASYNC)
   16759              :         {
   16760              :           oacc_async = true;
   16761              :           break;
   16762              :         }
   16763              : 
   16764        29789 :   tree *grp_start_p = NULL, grp_sentinel = NULL_TREE;
   16765              : 
   16766        78131 :   for (pc = &clauses, c = clauses; c ; c = *pc)
   16767              :     {
   16768        48342 :       bool remove = false;
   16769        48342 :       bool need_complete = false;
   16770        48342 :       bool need_implicitly_determined = false;
   16771              : 
   16772              :       /* We've reached the end of a list of expanded nodes.  Reset the group
   16773              :          start pointer.  */
   16774        48342 :       if (c == grp_sentinel)
   16775              :         {
   16776         2542 :           if (grp_start_p
   16777         2542 :               && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
   16778           32 :             for (tree gc = *grp_start_p; gc != grp_sentinel;
   16779           22 :                  gc = OMP_CLAUSE_CHAIN (gc))
   16780           22 :               OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
   16781              :           grp_start_p = NULL;
   16782              :         }
   16783              : 
   16784        48342 :       switch (OMP_CLAUSE_CODE (c))
   16785              :         {
   16786         1139 :         case OMP_CLAUSE_SHARED:
   16787         1139 :           need_implicitly_determined = true;
   16788         1139 :           goto check_dup_generic;
   16789              : 
   16790          851 :         case OMP_CLAUSE_PRIVATE:
   16791          851 :           need_complete = true;
   16792          851 :           need_implicitly_determined = true;
   16793          851 :           goto check_dup_generic;
   16794              : 
   16795         3539 :         case OMP_CLAUSE_REDUCTION:
   16796         3539 :           if (reduction_seen == 0)
   16797         2935 :             reduction_seen = OMP_CLAUSE_REDUCTION_INSCAN (c) ? -1 : 1;
   16798          604 :           else if (reduction_seen != -2
   16799         1208 :                    && reduction_seen != (OMP_CLAUSE_REDUCTION_INSCAN (c)
   16800          604 :                                          ? -1 : 1))
   16801              :             {
   16802            2 :               error_at (OMP_CLAUSE_LOCATION (c),
   16803              :                         "%<inscan%> and non-%<inscan%> %<reduction%> clauses "
   16804              :                         "on the same construct");
   16805            2 :               reduction_seen = -2;
   16806              :             }
   16807              :           /* FALLTHRU */
   16808         4203 :         case OMP_CLAUSE_IN_REDUCTION:
   16809         4203 :         case OMP_CLAUSE_TASK_REDUCTION:
   16810         4203 :           need_implicitly_determined = true;
   16811         4203 :           t = OMP_CLAUSE_DECL (c);
   16812         4203 :           if (TREE_CODE (t) == OMP_ARRAY_SECTION)
   16813              :             {
   16814          553 :               if (handle_omp_array_sections (c, ort))
   16815              :                 {
   16816              :                   remove = true;
   16817              :                   break;
   16818              :                 }
   16819              : 
   16820          537 :               t = OMP_CLAUSE_DECL (c);
   16821          537 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   16822          537 :                   && OMP_CLAUSE_REDUCTION_INSCAN (c))
   16823              :                 {
   16824            1 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16825              :                             "%<inscan%> %<reduction%> clause with array "
   16826              :                             "section");
   16827            1 :                   remove = true;
   16828            1 :                   break;
   16829              :                 }
   16830              :             }
   16831         4186 :           t = require_complete_type (OMP_CLAUSE_LOCATION (c), t);
   16832         4186 :           if (t == error_mark_node)
   16833              :             {
   16834              :               remove = true;
   16835              :               break;
   16836              :             }
   16837         4184 :           if (oacc_async)
   16838            3 :             c_mark_addressable (t);
   16839         4184 :           type = TREE_TYPE (t);
   16840         4184 :           if (TREE_CODE (t) == MEM_REF)
   16841          536 :             type = TREE_TYPE (type);
   16842         4184 :           if (TREE_CODE (type) == ARRAY_TYPE)
   16843              :             {
   16844           74 :               tree oatype = type;
   16845           74 :               gcc_assert (TREE_CODE (t) != MEM_REF);
   16846          148 :               while (TREE_CODE (type) == ARRAY_TYPE)
   16847           74 :                 type = TREE_TYPE (type);
   16848           74 :               if (integer_zerop (TYPE_SIZE_UNIT (type)))
   16849              :                 {
   16850            1 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16851              :                             "%qD in %<reduction%> clause is a zero size array",
   16852              :                             t);
   16853            1 :                   remove = true;
   16854            1 :                   break;
   16855              :                 }
   16856           73 :               tree size = size_binop (EXACT_DIV_EXPR, TYPE_SIZE_UNIT (oatype),
   16857              :                                       TYPE_SIZE_UNIT (type));
   16858           73 :               if (integer_zerop (size))
   16859              :                 {
   16860            1 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16861              :                             "%qD in %<reduction%> clause is a zero size array",
   16862              :                             t);
   16863            1 :                   remove = true;
   16864            1 :                   break;
   16865              :                 }
   16866           72 :               size = size_binop (MINUS_EXPR, size, size_one_node);
   16867           72 :               size = save_expr (size);
   16868           72 :               tree index_type = build_index_type (size);
   16869           72 :               tree atype = c_build_array_type (TYPE_MAIN_VARIANT (type),
   16870              :                                                index_type);
   16871           72 :               atype = c_build_qualified_type (atype, TYPE_QUALS (type));
   16872           72 :               tree ptype = c_build_pointer_type (type);
   16873           72 :               if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
   16874           72 :                 t = build_fold_addr_expr (t);
   16875           72 :               t = build2 (MEM_REF, atype, t, build_int_cst (ptype, 0));
   16876           72 :               OMP_CLAUSE_DECL (c) = t;
   16877              :             }
   16878         4182 :           if (TYPE_ATOMIC (type))
   16879              :             {
   16880            3 :               error_at (OMP_CLAUSE_LOCATION (c),
   16881              :                         "%<_Atomic%> %qE in %<reduction%> clause", t);
   16882            3 :               remove = true;
   16883            3 :               break;
   16884              :             }
   16885         4179 :           if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
   16886         4179 :               || OMP_CLAUSE_REDUCTION_TASK (c))
   16887              :             {
   16888              :               /* Disallow zero sized or potentially zero sized task
   16889              :                  reductions.  */
   16890          873 :               if (integer_zerop (TYPE_SIZE_UNIT (type)))
   16891              :                 {
   16892            6 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16893              :                             "zero sized type %qT in %qs clause", type,
   16894            3 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16895            3 :                   remove = true;
   16896            3 :                   break;
   16897              :                 }
   16898          870 :               else if (TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST)
   16899              :                 {
   16900            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16901              :                             "variable sized type %qT in %qs clause", type,
   16902            0 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16903            0 :                   remove = true;
   16904            0 :                   break;
   16905              :                 }
   16906              :             }
   16907         4176 :           if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == NULL_TREE
   16908         4176 :               && (FLOAT_TYPE_P (type)
   16909         3621 :                   || TREE_CODE (type) == COMPLEX_TYPE))
   16910              :             {
   16911          340 :               enum tree_code r_code = OMP_CLAUSE_REDUCTION_CODE (c);
   16912          340 :               const char *r_name = NULL;
   16913              : 
   16914          340 :               switch (r_code)
   16915              :                 {
   16916              :                 case PLUS_EXPR:
   16917              :                 case MULT_EXPR:
   16918              :                 case MINUS_EXPR:
   16919              :                 case TRUTH_ANDIF_EXPR:
   16920              :                 case TRUTH_ORIF_EXPR:
   16921              :                   break;
   16922           13 :                 case MIN_EXPR:
   16923           13 :                   if (TREE_CODE (type) == COMPLEX_TYPE)
   16924              :                     r_name = "min";
   16925              :                   break;
   16926           38 :                 case MAX_EXPR:
   16927           38 :                   if (TREE_CODE (type) == COMPLEX_TYPE)
   16928              :                     r_name = "max";
   16929              :                   break;
   16930            3 :                 case BIT_AND_EXPR:
   16931            3 :                   r_name = "&";
   16932            3 :                   break;
   16933            2 :                 case BIT_XOR_EXPR:
   16934            2 :                   r_name = "^";
   16935            2 :                   break;
   16936              :                 case BIT_IOR_EXPR:
   16937              :                   r_name = "|";
   16938              :                   break;
   16939            0 :                 default:
   16940            0 :                   gcc_unreachable ();
   16941              :                 }
   16942            5 :               if (r_name)
   16943              :                 {
   16944           12 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16945              :                             "%qE has invalid type for %<reduction(%s)%>",
   16946              :                             t, r_name);
   16947           12 :                   remove = true;
   16948           12 :                   break;
   16949              :                 }
   16950              :             }
   16951         3836 :           else if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == error_mark_node)
   16952              :             {
   16953            2 :               error_at (OMP_CLAUSE_LOCATION (c),
   16954              :                         "user defined reduction not found for %qE", t);
   16955            2 :               remove = true;
   16956            2 :               break;
   16957              :             }
   16958         3834 :           else if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
   16959              :             {
   16960          280 :               tree list = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c);
   16961          280 :               type = TYPE_MAIN_VARIANT (type);
   16962          280 :               tree placeholder = build_decl (OMP_CLAUSE_LOCATION (c),
   16963              :                                              VAR_DECL, NULL_TREE, type);
   16964          280 :               tree decl_placeholder = NULL_TREE;
   16965          280 :               OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = placeholder;
   16966          280 :               DECL_ARTIFICIAL (placeholder) = 1;
   16967          280 :               DECL_IGNORED_P (placeholder) = 1;
   16968          280 :               if (TREE_CODE (t) == MEM_REF)
   16969              :                 {
   16970           56 :                   decl_placeholder = build_decl (OMP_CLAUSE_LOCATION (c),
   16971              :                                                  VAR_DECL, NULL_TREE, type);
   16972           56 :                   OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c) = decl_placeholder;
   16973           56 :                   DECL_ARTIFICIAL (decl_placeholder) = 1;
   16974           56 :                   DECL_IGNORED_P (decl_placeholder) = 1;
   16975              :                 }
   16976          280 :               if (TREE_ADDRESSABLE (TREE_VEC_ELT (list, 0)))
   16977           45 :                 c_mark_addressable (placeholder);
   16978          280 :               if (TREE_ADDRESSABLE (TREE_VEC_ELT (list, 1)))
   16979           82 :                 c_mark_addressable (decl_placeholder ? decl_placeholder
   16980           37 :                                     : OMP_CLAUSE_DECL (c));
   16981          280 :               OMP_CLAUSE_REDUCTION_MERGE (c)
   16982          784 :                 = c_clone_omp_udr (TREE_VEC_ELT (list, 2),
   16983          280 :                                    TREE_VEC_ELT (list, 0),
   16984          280 :                                    TREE_VEC_ELT (list, 1),
   16985              :                                    decl_placeholder ? decl_placeholder
   16986          224 :                                    : OMP_CLAUSE_DECL (c), placeholder);
   16987          280 :               OMP_CLAUSE_REDUCTION_MERGE (c)
   16988          280 :                 = build3_loc (OMP_CLAUSE_LOCATION (c), BIND_EXPR,
   16989              :                               void_type_node, NULL_TREE,
   16990          280 :                               OMP_CLAUSE_REDUCTION_MERGE (c), NULL_TREE);
   16991          280 :               TREE_SIDE_EFFECTS (OMP_CLAUSE_REDUCTION_MERGE (c)) = 1;
   16992          280 :               if (TREE_VEC_LENGTH (list) == 6)
   16993              :                 {
   16994          236 :                   if (TREE_ADDRESSABLE (TREE_VEC_ELT (list, 3)))
   16995           70 :                     c_mark_addressable (decl_placeholder ? decl_placeholder
   16996           33 :                                         : OMP_CLAUSE_DECL (c));
   16997          236 :                   if (TREE_ADDRESSABLE (TREE_VEC_ELT (list, 4)))
   16998           30 :                     c_mark_addressable (placeholder);
   16999          236 :                   tree init = TREE_VEC_ELT (list, 5);
   17000          236 :                   if (init == error_mark_node)
   17001          200 :                     init = DECL_INITIAL (TREE_VEC_ELT (list, 3));
   17002          236 :                   OMP_CLAUSE_REDUCTION_INIT (c)
   17003          660 :                     = c_clone_omp_udr (init, TREE_VEC_ELT (list, 4),
   17004          236 :                                        TREE_VEC_ELT (list, 3),
   17005              :                                        decl_placeholder ? decl_placeholder
   17006          188 :                                        : OMP_CLAUSE_DECL (c), placeholder);
   17007          236 :                   if (TREE_VEC_ELT (list, 5) == error_mark_node)
   17008              :                     {
   17009          200 :                       tree v = decl_placeholder ? decl_placeholder : t;
   17010          200 :                       OMP_CLAUSE_REDUCTION_INIT (c)
   17011          400 :                         = build2 (INIT_EXPR, TREE_TYPE (v), v,
   17012          200 :                                   OMP_CLAUSE_REDUCTION_INIT (c));
   17013              :                     }
   17014          236 :                   if (walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c),
   17015              :                                  c_find_omp_placeholder_r,
   17016              :                                  placeholder, NULL))
   17017           31 :                     OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c) = 1;
   17018              :                 }
   17019              :               else
   17020              :                 {
   17021           44 :                   tree init;
   17022           44 :                   tree v = decl_placeholder ? decl_placeholder : t;
   17023           44 :                   if (AGGREGATE_TYPE_P (TREE_TYPE (v)))
   17024           34 :                     init = build_constructor (TREE_TYPE (v), NULL);
   17025              :                   else
   17026           10 :                     init = fold_convert (TREE_TYPE (v), integer_zero_node);
   17027           44 :                   OMP_CLAUSE_REDUCTION_INIT (c)
   17028           88 :                     = build2 (INIT_EXPR, TREE_TYPE (v), v, init);
   17029              :                 }
   17030          280 :               OMP_CLAUSE_REDUCTION_INIT (c)
   17031          280 :                 = build3_loc (OMP_CLAUSE_LOCATION (c), BIND_EXPR,
   17032              :                               void_type_node, NULL_TREE,
   17033          280 :                                OMP_CLAUSE_REDUCTION_INIT (c), NULL_TREE);
   17034          280 :               TREE_SIDE_EFFECTS (OMP_CLAUSE_REDUCTION_INIT (c)) = 1;
   17035              :             }
   17036         4162 :           if (TREE_CODE (t) == MEM_REF)
   17037              :             {
   17038          607 :               if (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t))) == NULL_TREE
   17039          607 :                   || TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t))))
   17040              :                      != INTEGER_CST)
   17041              :                 {
   17042            0 :                   sorry ("variable length element type in array "
   17043              :                          "%<reduction%> clause");
   17044            0 :                   remove = true;
   17045            0 :                   break;
   17046              :                 }
   17047          607 :               t = TREE_OPERAND (t, 0);
   17048          607 :               if (TREE_CODE (t) == POINTER_PLUS_EXPR)
   17049          139 :                 t = TREE_OPERAND (t, 0);
   17050          607 :               if (TREE_CODE (t) == ADDR_EXPR)
   17051          367 :                 t = TREE_OPERAND (t, 0);
   17052              :             }
   17053         4162 :           goto check_dup_generic_t;
   17054              : 
   17055           24 :         case OMP_CLAUSE_COPYPRIVATE:
   17056           24 :           copyprivate_seen = true;
   17057           24 :           if (nowait_clause)
   17058              :             {
   17059            1 :               error_at (OMP_CLAUSE_LOCATION (*nowait_clause),
   17060              :                         "%<nowait%> clause must not be used together "
   17061              :                         "with %<copyprivate%> clause");
   17062            1 :               *nowait_clause = OMP_CLAUSE_CHAIN (*nowait_clause);
   17063            1 :               nowait_clause = NULL;
   17064              :             }
   17065           24 :           goto check_dup_generic;
   17066              : 
   17067          100 :         case OMP_CLAUSE_COPYIN:
   17068          100 :           t = OMP_CLAUSE_DECL (c);
   17069          100 :           if (!VAR_P (t) || !DECL_THREAD_LOCAL_P (t))
   17070              :             {
   17071            5 :               error_at (OMP_CLAUSE_LOCATION (c),
   17072              :                         "%qE must be %<threadprivate%> for %<copyin%>", t);
   17073            5 :               remove = true;
   17074            5 :               break;
   17075              :             }
   17076           95 :           goto check_dup_generic;
   17077              : 
   17078          480 :         case OMP_CLAUSE_LINEAR:
   17079          480 :           if (ort != C_ORT_OMP_DECLARE_SIMD)
   17080          327 :             need_implicitly_determined = true;
   17081          480 :           t = OMP_CLAUSE_DECL (c);
   17082          480 :           if (ort != C_ORT_OMP_DECLARE_SIMD
   17083          327 :               && OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_DEFAULT
   17084          485 :               && OMP_CLAUSE_LINEAR_OLD_LINEAR_MODIFIER (c))
   17085              :             {
   17086            5 :               error_at (OMP_CLAUSE_LOCATION (c),
   17087              :                         "modifier should not be specified in %<linear%> "
   17088              :                         "clause on %<simd%> or %<for%> constructs when not "
   17089              :                         "using OpenMP 5.2 modifiers");
   17090            5 :               OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
   17091              :             }
   17092          960 :           if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
   17093          503 :               && TREE_CODE (TREE_TYPE (t)) != POINTER_TYPE)
   17094              :             {
   17095            1 :               error_at (OMP_CLAUSE_LOCATION (c),
   17096              :                         "linear clause applied to non-integral non-pointer "
   17097            1 :                         "variable with type %qT", TREE_TYPE (t));
   17098            1 :               remove = true;
   17099            1 :               break;
   17100              :             }
   17101          479 :           if (TYPE_ATOMIC (TREE_TYPE (t)))
   17102              :             {
   17103            3 :               error_at (OMP_CLAUSE_LOCATION (c),
   17104              :                         "%<_Atomic%> %qD in %<linear%> clause", t);
   17105            3 :               remove = true;
   17106            3 :               break;
   17107              :             }
   17108          476 :           if (ort == C_ORT_OMP_DECLARE_SIMD)
   17109              :             {
   17110          152 :               tree s = OMP_CLAUSE_LINEAR_STEP (c);
   17111          152 :               if (TREE_CODE (s) == PARM_DECL)
   17112              :                 {
   17113            9 :                   OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c) = 1;
   17114              :                   /* map_head bitmap is used as uniform_head if
   17115              :                      declare_simd.  */
   17116            9 :                   if (!bitmap_bit_p (&map_head, DECL_UID (s)))
   17117            5 :                     linear_variable_step_check = true;
   17118            9 :                   goto check_dup_generic;
   17119              :                 }
   17120          143 :               if (TREE_CODE (s) != INTEGER_CST)
   17121              :                 {
   17122            7 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17123              :                             "%<linear%> clause step %qE is neither constant "
   17124              :                             "nor a parameter", s);
   17125            7 :                   remove = true;
   17126            7 :                   break;
   17127              :                 }
   17128              :             }
   17129          460 :           if (TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c))) == POINTER_TYPE)
   17130              :             {
   17131           20 :               tree s = OMP_CLAUSE_LINEAR_STEP (c);
   17132           20 :               s = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
   17133           20 :                                    OMP_CLAUSE_DECL (c), s);
   17134           20 :               s = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
   17135              :                                    sizetype, fold_convert (sizetype, s),
   17136           20 :                                    fold_convert
   17137              :                                      (sizetype, OMP_CLAUSE_DECL (c)));
   17138           20 :               if (s == error_mark_node)
   17139            0 :                 s = size_one_node;
   17140           20 :               OMP_CLAUSE_LINEAR_STEP (c) = s;
   17141              :             }
   17142              :           else
   17143          440 :             OMP_CLAUSE_LINEAR_STEP (c)
   17144          880 :               = fold_convert (TREE_TYPE (t), OMP_CLAUSE_LINEAR_STEP (c));
   17145          460 :           goto check_dup_generic;
   17146              : 
   17147         2892 :         check_dup_generic:
   17148         2892 :           t = OMP_CLAUSE_DECL (c);
   17149         7143 :         check_dup_generic_t:
   17150         7143 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   17151              :             {
   17152            4 :               error_at (OMP_CLAUSE_LOCATION (c),
   17153              :                         "%qE is not a variable in clause %qs", t,
   17154            2 :                         omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17155            2 :               remove = true;
   17156              :             }
   17157         1149 :           else if ((openacc && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
   17158         6102 :                    || (ort == C_ORT_OMP
   17159         5381 :                        && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
   17160         5370 :                            || (OMP_CLAUSE_CODE (c)
   17161              :                                == OMP_CLAUSE_USE_DEVICE_ADDR)))
   17162        13196 :                    || (ort == C_ORT_OMP_TARGET
   17163          349 :                        && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION))
   17164              :             {
   17165         1196 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   17166         1196 :                   && (bitmap_bit_p (&generic_head, DECL_UID (t))
   17167          109 :                       || bitmap_bit_p (&firstprivate_head, DECL_UID (t))))
   17168              :                 {
   17169            2 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17170              :                             "%qD appears more than once in data-sharing "
   17171              :                             "clauses", t);
   17172            2 :                   remove = true;
   17173            2 :                   break;
   17174              :                 }
   17175         1194 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION)
   17176          108 :                 target_in_reduction_seen = true;
   17177         1194 :               if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
   17178              :                 {
   17179            4 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17180              :                             openacc
   17181              :                             ? "%qD appears more than once in reduction clauses"
   17182              :                             : "%qD appears more than once in data clauses",
   17183              :                             t);
   17184            2 :                   remove = true;
   17185              :                 }
   17186              :               else
   17187         1192 :                 bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
   17188              :             }
   17189         5945 :           else if (bitmap_bit_p (&generic_head, DECL_UID (t))
   17190         5922 :                    || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
   17191         5921 :                    || bitmap_bit_p (&lastprivate_head, DECL_UID (t))
   17192        11866 :                    || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
   17193              :             {
   17194           24 :               error_at (OMP_CLAUSE_LOCATION (c),
   17195              :                         "%qE appears more than once in data clauses", t);
   17196           24 :               remove = true;
   17197              :             }
   17198         5921 :           else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
   17199              :                     || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR
   17200              :                     || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
   17201         1051 :                    && bitmap_bit_p (&map_head, DECL_UID (t)))
   17202              :             {
   17203            3 :               if (openacc)
   17204            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17205              :                           "%qD appears more than once in data clauses", t);
   17206              :               else
   17207            3 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17208              :                           "%qD appears both in data and map clauses", t);
   17209              :               remove = true;
   17210              :             }
   17211              :           else
   17212         5918 :             bitmap_set_bit (&generic_head, DECL_UID (t));
   17213              :           break;
   17214              : 
   17215         1350 :         case OMP_CLAUSE_FIRSTPRIVATE:
   17216         1350 :           if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c) && !implicit_moved)
   17217              :             {
   17218          153 :             move_implicit:
   17219          153 :               implicit_moved = true;
   17220              :               /* Move firstprivate and map clauses with
   17221              :                  OMP_CLAUSE_{FIRSTPRIVATE,MAP}_IMPLICIT set to the end of
   17222              :                  clauses chain.  */
   17223          153 :               tree cl1 = NULL_TREE, cl2 = NULL_TREE;
   17224          153 :               tree *pc1 = pc, *pc2 = &cl1, *pc3 = &cl2;
   17225          972 :               while (*pc1)
   17226          819 :                 if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_FIRSTPRIVATE
   17227          819 :                     && OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (*pc1))
   17228              :                   {
   17229          113 :                     *pc3 = *pc1;
   17230          113 :                     pc3 = &OMP_CLAUSE_CHAIN (*pc3);
   17231          113 :                     *pc1 = OMP_CLAUSE_CHAIN (*pc1);
   17232              :                   }
   17233          706 :                 else if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_MAP
   17234          706 :                          && OMP_CLAUSE_MAP_IMPLICIT (*pc1))
   17235              :                   {
   17236          131 :                     *pc2 = *pc1;
   17237          131 :                     pc2 = &OMP_CLAUSE_CHAIN (*pc2);
   17238          131 :                     *pc1 = OMP_CLAUSE_CHAIN (*pc1);
   17239              :                   }
   17240              :                 else
   17241          575 :                   pc1 = &OMP_CLAUSE_CHAIN (*pc1);
   17242          153 :               *pc3 = NULL;
   17243          153 :               *pc2 = cl2;
   17244          153 :               *pc1 = cl1;
   17245          153 :               continue;
   17246          153 :             }
   17247         1255 :           t = OMP_CLAUSE_DECL (c);
   17248         1255 :           need_complete = true;
   17249         1255 :           need_implicitly_determined = true;
   17250         1255 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   17251              :             {
   17252            1 :               error_at (OMP_CLAUSE_LOCATION (c),
   17253              :                         "%qE is not a variable in clause %<firstprivate%>", t);
   17254            1 :               remove = true;
   17255              :             }
   17256         1254 :           else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
   17257          113 :                    && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c)
   17258         1360 :                    && bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
   17259              :             remove = true;
   17260         1254 :           else if (bitmap_bit_p (&generic_head, DECL_UID (t))
   17261         1252 :                    || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
   17262         2505 :                    || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
   17263              :             {
   17264            4 :               error_at (OMP_CLAUSE_LOCATION (c),
   17265              :                         "%qE appears more than once in data clauses", t);
   17266            4 :               remove = true;
   17267              :             }
   17268         1250 :           else if (bitmap_bit_p (&map_head, DECL_UID (t))
   17269         1250 :                    || bitmap_bit_p (&map_field_head, DECL_UID (t)))
   17270              :             {
   17271            7 :               if (openacc)
   17272            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17273              :                           "%qD appears more than once in data clauses", t);
   17274            7 :               else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
   17275            7 :                        && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c))
   17276              :                 /* Silently drop the clause.  */;
   17277              :               else
   17278            6 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17279              :                           "%qD appears both in data and map clauses", t);
   17280              :               remove = true;
   17281              :             }
   17282              :           else
   17283         1243 :             bitmap_set_bit (&firstprivate_head, DECL_UID (t));
   17284              :           break;
   17285              : 
   17286         1524 :         case OMP_CLAUSE_LASTPRIVATE:
   17287         1524 :           t = OMP_CLAUSE_DECL (c);
   17288         1524 :           need_complete = true;
   17289         1524 :           need_implicitly_determined = true;
   17290         1524 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   17291              :             {
   17292            0 :               error_at (OMP_CLAUSE_LOCATION (c),
   17293              :                         "%qE is not a variable in clause %<lastprivate%>", t);
   17294            0 :               remove = true;
   17295              :             }
   17296         1524 :           else if (bitmap_bit_p (&generic_head, DECL_UID (t))
   17297         1524 :                    || bitmap_bit_p (&lastprivate_head, DECL_UID (t)))
   17298              :             {
   17299            3 :               error_at (OMP_CLAUSE_LOCATION (c),
   17300              :                      "%qE appears more than once in data clauses", t);
   17301            3 :               remove = true;
   17302              :             }
   17303              :           else
   17304         1521 :             bitmap_set_bit (&lastprivate_head, DECL_UID (t));
   17305              :           break;
   17306              : 
   17307          253 :         case OMP_CLAUSE_ALIGNED:
   17308          253 :           t = OMP_CLAUSE_DECL (c);
   17309          253 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   17310              :             {
   17311            0 :               error_at (OMP_CLAUSE_LOCATION (c),
   17312              :                         "%qE is not a variable in %<aligned%> clause", t);
   17313            0 :               remove = true;
   17314              :             }
   17315          289 :           else if (!POINTER_TYPE_P (TREE_TYPE (t))
   17316          289 :                    && TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE)
   17317              :             {
   17318            7 :               error_at (OMP_CLAUSE_LOCATION (c),
   17319              :                         "%qE in %<aligned%> clause is neither a pointer nor "
   17320              :                         "an array", t);
   17321            7 :               remove = true;
   17322              :             }
   17323          246 :           else if (TYPE_ATOMIC (TREE_TYPE (t)))
   17324              :             {
   17325            1 :               error_at (OMP_CLAUSE_LOCATION (c),
   17326              :                         "%<_Atomic%> %qD in %<aligned%> clause", t);
   17327            1 :               remove = true;
   17328            1 :               break;
   17329              :             }
   17330          245 :           else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
   17331              :             {
   17332            0 :               error_at (OMP_CLAUSE_LOCATION (c),
   17333              :                         "%qE appears more than once in %<aligned%> clauses",
   17334              :                         t);
   17335            0 :               remove = true;
   17336              :             }
   17337              :           else
   17338          245 :             bitmap_set_bit (&aligned_head, DECL_UID (t));
   17339              :           break;
   17340              : 
   17341          125 :         case OMP_CLAUSE_NONTEMPORAL:
   17342          125 :           t = OMP_CLAUSE_DECL (c);
   17343          125 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   17344              :             {
   17345            0 :               error_at (OMP_CLAUSE_LOCATION (c),
   17346              :                         "%qE is not a variable in %<nontemporal%> clause", t);
   17347            0 :               remove = true;
   17348              :             }
   17349          125 :           else if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
   17350              :             {
   17351            2 :               error_at (OMP_CLAUSE_LOCATION (c),
   17352              :                         "%qE appears more than once in %<nontemporal%> "
   17353              :                         "clauses", t);
   17354            2 :               remove = true;
   17355              :             }
   17356              :           else
   17357          123 :             bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
   17358              :           break;
   17359              : 
   17360          814 :         case OMP_CLAUSE_ALLOCATE:
   17361          814 :           t = OMP_CLAUSE_DECL (c);
   17362          814 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   17363              :             {
   17364            1 :               error_at (OMP_CLAUSE_LOCATION (c),
   17365              :                         "%qE is not a variable in %<allocate%> clause", t);
   17366            1 :               remove = true;
   17367              :             }
   17368          813 :           else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
   17369              :             {
   17370            2 :               warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
   17371              :                           "%qE appears more than once in %<allocate%> clauses",
   17372              :                           t);
   17373            2 :               remove = true;
   17374              :             }
   17375              :           else
   17376              :             {
   17377          811 :               bitmap_set_bit (&aligned_head, DECL_UID (t));
   17378          811 :               if (!OMP_CLAUSE_ALLOCATE_COMBINED (c))
   17379          711 :                 allocate_seen = true;
   17380              :             }
   17381              :           break;
   17382              : 
   17383          357 :         case OMP_CLAUSE_DOACROSS:
   17384          357 :           t = OMP_CLAUSE_DECL (c);
   17385          357 :           if (t == NULL_TREE)
   17386              :             break;
   17387          169 :           if (OMP_CLAUSE_DOACROSS_KIND (c) == OMP_CLAUSE_DOACROSS_SINK)
   17388              :             {
   17389          169 :               gcc_assert (TREE_CODE (t) == TREE_LIST);
   17390         1315 :               for (; t; t = TREE_CHAIN (t))
   17391              :                 {
   17392         1146 :                   tree decl = TREE_VALUE (t);
   17393         1146 :                   if (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE)
   17394              :                     {
   17395            3 :                       tree offset = TREE_PURPOSE (t);
   17396            3 :                       bool neg = wi::neg_p (wi::to_wide (offset));
   17397            3 :                       offset = fold_unary (ABS_EXPR, TREE_TYPE (offset), offset);
   17398            6 :                       tree t2 = pointer_int_sum (OMP_CLAUSE_LOCATION (c),
   17399              :                                                  neg ? MINUS_EXPR : PLUS_EXPR,
   17400              :                                                  decl, offset);
   17401            3 :                       t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
   17402              :                                             sizetype,
   17403              :                                             fold_convert (sizetype, t2),
   17404              :                                             fold_convert (sizetype, decl));
   17405            3 :                       if (t2 == error_mark_node)
   17406              :                         {
   17407              :                           remove = true;
   17408              :                           break;
   17409              :                         }
   17410            3 :                       TREE_PURPOSE (t) = t2;
   17411              :                     }
   17412              :                 }
   17413              :               break;
   17414              :             }
   17415            0 :           gcc_unreachable ();
   17416              : 
   17417           64 :         case OMP_CLAUSE_USES_ALLOCATORS:
   17418           64 :           t = OMP_CLAUSE_USES_ALLOCATORS_ALLOCATOR (c);
   17419           64 :           if (t == error_mark_node)
   17420              :             {
   17421              :               remove = true;
   17422              :               break;
   17423              :             }
   17424            8 :           if ((VAR_P (t) || TREE_CODE (t) == PARM_DECL)
   17425           60 :               && (bitmap_bit_p (&generic_head, DECL_UID (t))
   17426           52 :                   || bitmap_bit_p (&map_head, DECL_UID (t))
   17427           52 :                   || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
   17428           51 :                   || bitmap_bit_p (&lastprivate_head, DECL_UID (t))))
   17429              :             {
   17430            1 :               error_at (OMP_CLAUSE_LOCATION (c),
   17431              :                         "%qE appears more than once in data clauses", t);
   17432            1 :               remove = true;
   17433            1 :               break;
   17434              :             }
   17435              :           else
   17436           58 :             bitmap_set_bit (&generic_head, DECL_UID (t));
   17437           58 :           if (TREE_CODE (TREE_TYPE (t)) != ENUMERAL_TYPE
   17438          113 :               || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (TREE_TYPE (t))),
   17439              :                          "omp_allocator_handle_t") != 0)
   17440              :             {
   17441            3 :               error_at (OMP_CLAUSE_LOCATION (c),
   17442              :                         "allocator %qE must be of %<omp_allocator_handle_t%> "
   17443              :                         "type", t);
   17444            3 :               remove = true;
   17445            3 :               break;
   17446              :             }
   17447           55 :           tree init;
   17448           55 :           if (!DECL_P (t)
   17449           55 :               || (TREE_CODE (t) == CONST_DECL
   17450            7 :                   && ((init = DECL_INITIAL(t)) == nullptr
   17451            7 :                       || TREE_CODE (init) != INTEGER_CST
   17452            7 :                       || ((wi::to_widest (init) < 0
   17453            7 :                            || wi::to_widest (init) > GOMP_OMP_PREDEF_ALLOC_MAX)
   17454            0 :                           && (wi::to_widest (init) < GOMP_OMPX_PREDEF_ALLOC_MIN
   17455            0 :                               || (wi::to_widest (init)
   17456            0 :                                   > GOMP_OMPX_PREDEF_ALLOC_MAX))))))
   17457              :             {
   17458            0 :               remove = true;
   17459            0 :               error_at (OMP_CLAUSE_LOCATION (c),
   17460              :                         "allocator %qE must be either a variable or a "
   17461              :                         "predefined allocator", t);
   17462            0 :               break;
   17463              :             }
   17464           55 :           else if (TREE_CODE (t) == CONST_DECL)
   17465              :             {
   17466              :               /* omp_null_allocator is ignored and for predefined allocators,
   17467              :                  no special handling is required; thus, mark them removed. */
   17468            7 :               remove = true;
   17469              : 
   17470            7 :               if (OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE (c)
   17471            7 :                   || OMP_CLAUSE_USES_ALLOCATORS_TRAITS (c))
   17472              :                 {
   17473            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17474              :                             "modifiers cannot be used with predefined "
   17475              :                             "allocator %qE", t);
   17476            0 :                   break;
   17477              :                 }
   17478              :             }
   17479           55 :           t = OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE (c);
   17480           55 :           if (t == error_mark_node)
   17481              :             {
   17482              :               remove = true;
   17483              :               break;
   17484              :             }
   17485           55 :           if (t != NULL_TREE
   17486           55 :               && ((TREE_CODE (t) != CONST_DECL && TREE_CODE (t) != INTEGER_CST)
   17487           11 :                   || TREE_CODE (TREE_TYPE (t)) != ENUMERAL_TYPE
   17488           20 :                   || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (TREE_TYPE (t))),
   17489              :                              "omp_memspace_handle_t") != 0))
   17490              :             {
   17491            1 :               error_at (OMP_CLAUSE_LOCATION (c), "memspace modifier %qE must be"
   17492              :                         " constant enum of %<omp_memspace_handle_t%> type", t);
   17493            1 :               remove = true;
   17494            1 :               break;
   17495              :             }
   17496           54 :           t = OMP_CLAUSE_USES_ALLOCATORS_TRAITS (c);
   17497           54 :           if (t == error_mark_node)
   17498              :             {
   17499              :               remove = true;
   17500              :               break;
   17501              :             }
   17502           54 :           if (t != NULL_TREE
   17503              :               && t != error_mark_node
   17504           54 :               && (DECL_EXTERNAL (t)
   17505           25 :                   || TREE_CODE (t) == PARM_DECL))
   17506              :             {
   17507            3 :               error_at (OMP_CLAUSE_LOCATION (c), "traits array %qE must be "
   17508              :                         "defined in same scope as the construct on which the "
   17509              :                         "clause appears", t);
   17510            3 :               remove = true;
   17511              :             }
   17512           54 :           if (t != NULL_TREE)
   17513              :             {
   17514           27 :               bool type_err = false;
   17515              : 
   17516           27 :               if (TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE
   17517           26 :                   || DECL_SIZE (t) == NULL_TREE
   17518           52 :                   || !COMPLETE_TYPE_P (TREE_TYPE (t)))
   17519              :                 type_err = true;
   17520              :               else
   17521              :                 {
   17522           25 :                   tree elem_t = TREE_TYPE (TREE_TYPE (t));
   17523           25 :                   if (TREE_CODE (elem_t) != RECORD_TYPE
   17524           50 :                       || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (elem_t)),
   17525              :                                  "omp_alloctrait_t") != 0
   17526           50 :                       || !TYPE_READONLY (elem_t))
   17527              :                     type_err = true;
   17528              :                 }
   17529           24 :               if (type_err)
   17530              :                 {
   17531            3 :                   if (t != error_mark_node)
   17532            3 :                     error_at (OMP_CLAUSE_LOCATION (c), "traits array %qE must "
   17533              :                               "be of %<const omp_alloctrait_t []%> type", t);
   17534              :                   else
   17535            0 :                     error_at (OMP_CLAUSE_LOCATION (c), "traits array must "
   17536              :                               "be of %<const omp_alloctrait_t []%> type");
   17537              :                   remove = true;
   17538              :                 }
   17539              :               else
   17540              :                 {
   17541           24 :                   tree cst_val = decl_constant_value_1 (t, true);
   17542           24 :                   if (cst_val == t)
   17543              :                     {
   17544            1 :                       error_at (OMP_CLAUSE_LOCATION (c), "traits array must be "
   17545              :                                 "initialized with constants");
   17546              : 
   17547            1 :                       remove = true;
   17548              :                     }
   17549              :                 }
   17550              :             }
   17551           54 :           if (remove)
   17552              :             break;
   17553           43 :           pc = &OMP_CLAUSE_CHAIN (c);
   17554           43 :           continue;
   17555          713 :         case OMP_CLAUSE_DEPEND:
   17556          713 :           depend_clause = c;
   17557              :           /* FALLTHRU */
   17558          875 :         case OMP_CLAUSE_AFFINITY:
   17559          875 :           t = OMP_CLAUSE_DECL (c);
   17560          875 :           if (OMP_ITERATOR_DECL_P (t))
   17561              :             {
   17562          131 :               if (TREE_PURPOSE (t) != last_iterators)
   17563          111 :                 last_iterators_remove
   17564          111 :                   = c_omp_finish_iterators (TREE_PURPOSE (t));
   17565          131 :               last_iterators = TREE_PURPOSE (t);
   17566          131 :               t = TREE_VALUE (t);
   17567          131 :               if (last_iterators_remove)
   17568           34 :                 t = error_mark_node;
   17569              :             }
   17570              :           else
   17571              :             last_iterators = NULL_TREE;
   17572          875 :           if (TREE_CODE (t) == OMP_ARRAY_SECTION)
   17573              :             {
   17574          418 :               if (handle_omp_array_sections (c, ort))
   17575              :                 remove = true;
   17576          336 :               else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   17577          336 :                        && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ)
   17578              :                 {
   17579            1 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17580              :                             "%<depend%> clause with %<depobj%> dependence "
   17581              :                             "type on array section");
   17582            1 :                   remove = true;
   17583              :                 }
   17584              :               break;
   17585              :             }
   17586          457 :           if (t == error_mark_node)
   17587              :             remove = true;
   17588          423 :           else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   17589          423 :                    && t == ridpointers[RID_OMP_ALL_MEMORY])
   17590              :             {
   17591           15 :               if (OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_OUT
   17592           15 :                   && OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_INOUT)
   17593              :                 {
   17594            3 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17595              :                             "%<omp_all_memory%> used with %<depend%> kind "
   17596              :                             "other than %<out%> or %<inout%>");
   17597            3 :                   remove = true;
   17598              :                 }
   17599              :             }
   17600          408 :           else if (!lvalue_p (t))
   17601              :             {
   17602            6 :               error_at (OMP_CLAUSE_LOCATION (c),
   17603              :                         "%qE is not lvalue expression nor array section in "
   17604              :                         "%qs clause", t,
   17605            3 :                         omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17606            3 :               remove = true;
   17607              :             }
   17608          405 :           else if (TREE_CODE (t) == COMPONENT_REF
   17609          405 :                    && DECL_C_BIT_FIELD (TREE_OPERAND (t, 1)))
   17610              :             {
   17611            2 :               gcc_assert (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   17612              :                           || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY);
   17613            2 :               error_at (OMP_CLAUSE_LOCATION (c),
   17614              :                         "bit-field %qE in %qs clause", t,
   17615            2 :                         omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17616            2 :               remove = true;
   17617              :             }
   17618          403 :           else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   17619          403 :                    && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ)
   17620              :             {
   17621           20 :               if (!c_omp_depend_t_p (TREE_TYPE (t)))
   17622              :                 {
   17623            2 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17624              :                             "%qE does not have %<omp_depend_t%> type in "
   17625              :                             "%<depend%> clause with %<depobj%> dependence "
   17626              :                             "type", t);
   17627            2 :                   remove = true;
   17628              :                 }
   17629              :             }
   17630          383 :           else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   17631          383 :                    && c_omp_depend_t_p (TREE_TYPE (t)))
   17632              :             {
   17633            2 :               error_at (OMP_CLAUSE_LOCATION (c),
   17634              :                         "%qE should not have %<omp_depend_t%> type in "
   17635              :                         "%<depend%> clause with dependence type other than "
   17636              :                         "%<depobj%>", t);
   17637            2 :               remove = true;
   17638              :             }
   17639           12 :           if (!remove)
   17640              :             {
   17641          411 :               if (t == ridpointers[RID_OMP_ALL_MEMORY])
   17642           12 :                 t = null_pointer_node;
   17643              :               else
   17644              :                 {
   17645          399 :                   tree addr = build_unary_op (OMP_CLAUSE_LOCATION (c),
   17646              :                                               ADDR_EXPR, t, false);
   17647          399 :                   if (addr == error_mark_node)
   17648              :                     {
   17649              :                       remove = true;
   17650              :                       break;
   17651              :                     }
   17652          399 :                   t = build_indirect_ref (OMP_CLAUSE_LOCATION (c), addr,
   17653              :                                           RO_UNARY_STAR);
   17654          399 :                   if (t == error_mark_node)
   17655              :                     {
   17656              :                       remove = true;
   17657              :                       break;
   17658              :                     }
   17659              :                 }
   17660          411 :               if (OMP_ITERATOR_DECL_P (OMP_CLAUSE_DECL (c)))
   17661           31 :                 TREE_VALUE (OMP_CLAUSE_DECL (c)) = t;
   17662              :               else
   17663          380 :                 OMP_CLAUSE_DECL (c) = t;
   17664              :             }
   17665              :           break;
   17666              : 
   17667         6786 :         case OMP_CLAUSE_MAP:
   17668         6786 :           if (OMP_CLAUSE_MAP_IMPLICIT (c) && !implicit_moved)
   17669           58 :             goto move_implicit;
   17670         6728 :           if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_PUSH_MAPPER_NAME
   17671         6728 :               || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POP_MAPPER_NAME)
   17672              :             {
   17673              :               remove = true;
   17674              :               break;
   17675              :             }
   17676              :           /* FALLTHRU */
   17677         9620 :         case OMP_CLAUSE_TO:
   17678         9620 :         case OMP_CLAUSE_FROM:
   17679         9620 :           if (OMP_CLAUSE_ITERATORS (c)
   17680         9620 :               && c_omp_finish_iterators (OMP_CLAUSE_ITERATORS (c)))
   17681              :             {
   17682        23160 :               t = error_mark_node;
   17683              :               break;
   17684              :             }
   17685              :           /* FALLTHRU */
   17686         9756 :         case OMP_CLAUSE__CACHE_:
   17687         9756 :           {
   17688         9756 :             using namespace omp_addr_tokenizer;
   17689         9756 :             auto_vec<omp_addr_token *, 10> addr_tokens;
   17690              : 
   17691         9756 :             t = OMP_CLAUSE_DECL (c);
   17692         9756 :             if (TREE_CODE (t) == OMP_ARRAY_SECTION)
   17693              :               {
   17694         2019 :                 grp_start_p = pc;
   17695         2019 :                 grp_sentinel = OMP_CLAUSE_CHAIN (c);
   17696              : 
   17697         2019 :                 if (handle_omp_array_sections (c, ort))
   17698              :                   remove = true;
   17699              :                 else
   17700              :                   {
   17701         1879 :                     t = OMP_CLAUSE_DECL (c);
   17702         1879 :                     if (!omp_mappable_type (TREE_TYPE (t)))
   17703              :                       {
   17704            2 :                         error_at (OMP_CLAUSE_LOCATION (c),
   17705              :                                   "array section does not have mappable type "
   17706              :                                   "in %qs clause",
   17707            1 :                                   omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17708            1 :                         remove = true;
   17709              :                       }
   17710         1878 :                     else if (TYPE_ATOMIC (TREE_TYPE (t)))
   17711              :                       {
   17712            2 :                         error_at (OMP_CLAUSE_LOCATION (c),
   17713              :                                   "%<_Atomic%> %qE in %qs clause", t,
   17714            1 :                                   omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17715            1 :                         remove = true;
   17716              :                       }
   17717         2534 :                     while (TREE_CODE (t) == ARRAY_REF)
   17718          655 :                       t = TREE_OPERAND (t, 0);
   17719              : 
   17720         1879 :                     c_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
   17721              : 
   17722         1879 :                     if (!omp_parse_expr (addr_tokens, t))
   17723              :                       {
   17724            0 :                         sorry_at (OMP_CLAUSE_LOCATION (c),
   17725              :                                   "unsupported map expression %qE",
   17726            0 :                                   OMP_CLAUSE_DECL (c));
   17727            0 :                         remove = true;
   17728            0 :                         break;
   17729              :                       }
   17730              : 
   17731              :                     /* This check is to determine if this will be the only map
   17732              :                        node created for this clause.  Otherwise, we'll check
   17733              :                        the following FIRSTPRIVATE_POINTER or ATTACH_DETACH
   17734              :                        node on the next iteration(s) of the loop.   */
   17735         1879 :                     if (addr_tokens.length () >= 4
   17736          308 :                         && addr_tokens[0]->type == STRUCTURE_BASE
   17737          306 :                         && addr_tokens[0]->u.structure_base_kind == BASE_DECL
   17738          306 :                         && addr_tokens[1]->type == ACCESS_METHOD
   17739          306 :                         && addr_tokens[2]->type == COMPONENT_SELECTOR
   17740          306 :                         && addr_tokens[3]->type == ACCESS_METHOD
   17741         2124 :                         && (addr_tokens[3]->u.access_kind == ACCESS_DIRECT
   17742          192 :                             || (addr_tokens[3]->u.access_kind
   17743              :                                 == ACCESS_INDEXED_ARRAY)))
   17744              :                       {
   17745           57 :                         tree rt = addr_tokens[1]->expr;
   17746              : 
   17747           57 :                         gcc_assert (DECL_P (rt));
   17748              : 
   17749           57 :                         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   17750           52 :                             && OMP_CLAUSE_MAP_IMPLICIT (c)
   17751           57 :                             && (bitmap_bit_p (&map_head, DECL_UID (rt))
   17752            0 :                                 || bitmap_bit_p (&map_field_head, DECL_UID (rt))
   17753            0 :                                 || bitmap_bit_p (&map_firstprivate_head,
   17754            0 :                                                  DECL_UID (rt))))
   17755              :                           {
   17756              :                             remove = true;
   17757              :                             break;
   17758              :                           }
   17759           57 :                         if (bitmap_bit_p (&map_field_head, DECL_UID (rt)))
   17760              :                           break;
   17761           39 :                         if (bitmap_bit_p (&map_head, DECL_UID (rt)))
   17762              :                           {
   17763            0 :                             if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
   17764            0 :                               error_at (OMP_CLAUSE_LOCATION (c),
   17765              :                                         "%qD appears more than once in motion "
   17766              :                                         "clauses", rt);
   17767            0 :                             else if (openacc)
   17768            0 :                               error_at (OMP_CLAUSE_LOCATION (c),
   17769              :                                         "%qD appears more than once in data "
   17770              :                                         "clauses", rt);
   17771              :                             else
   17772            0 :                               error_at (OMP_CLAUSE_LOCATION (c),
   17773              :                                         "%qD appears more than once in map "
   17774              :                                         "clauses", rt);
   17775              :                             remove = true;
   17776              :                           }
   17777              :                         else
   17778              :                           {
   17779           39 :                             bitmap_set_bit (&map_head, DECL_UID (rt));
   17780           39 :                             bitmap_set_bit (&map_field_head, DECL_UID (rt));
   17781              :                           }
   17782              :                       }
   17783              :                   }
   17784         2001 :                 if (c_oacc_check_attachments (c))
   17785            2 :                   remove = true;
   17786         2001 :                 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   17787         1819 :                     && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
   17788         1799 :                         || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
   17789         2028 :                     && !OMP_CLAUSE_SIZE (c))
   17790              :                   /* In this case, we have a single array element which is a
   17791              :                      pointer, and we already set OMP_CLAUSE_SIZE in
   17792              :                      handle_omp_array_sections above.  For attach/detach
   17793              :                      clauses, reset the OMP_CLAUSE_SIZE (representing a bias)
   17794              :                      to zero here.  */
   17795           10 :                   OMP_CLAUSE_SIZE (c) = size_zero_node;
   17796              :                 break;
   17797              :               }
   17798         7737 :             else if (!omp_parse_expr (addr_tokens, t))
   17799              :               {
   17800            0 :                 sorry_at (OMP_CLAUSE_LOCATION (c),
   17801              :                           "unsupported map expression %qE",
   17802            0 :                           OMP_CLAUSE_DECL (c));
   17803            0 :                 remove = true;
   17804            0 :                 break;
   17805              :               }
   17806         7737 :             if (t == error_mark_node)
   17807              :               {
   17808              :                 remove = true;
   17809              :                 break;
   17810              :               }
   17811              : 
   17812         7725 :             tree attr;
   17813         7725 :             if (DECL_P (t)
   17814         7136 :                 && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   17815         4313 :                 && (attr = lookup_attribute ("omp declare target",
   17816         4313 :                                              DECL_ATTRIBUTES (t)))
   17817         7965 :                 && value_member (get_identifier ("local"),
   17818          240 :                                  TREE_VALUE (attr)))
   17819              :               {
   17820            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17821              :                           "device-local variable %qD cannot appear "
   17822              :                           "in map clause", t);
   17823            0 :                 remove = true;
   17824            0 :                 break;
   17825              :               }
   17826              : 
   17827              :             /* OpenACC attach / detach clauses must be pointers.  */
   17828         7725 :             if (c_oacc_check_attachments (c))
   17829              :               {
   17830              :                 remove = true;
   17831              :                 break;
   17832              :               }
   17833         7721 :             if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   17834         4857 :                 && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
   17835         4828 :                     || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
   17836         7765 :                 && !OMP_CLAUSE_SIZE (c))
   17837              :               /* For attach/detach clauses, set OMP_CLAUSE_SIZE (representing a
   17838              :                  bias) to zero here, so it is not set erroneously to the pointer
   17839              :                  size later on in gimplify.cc.  */
   17840           28 :               OMP_CLAUSE_SIZE (c) = size_zero_node;
   17841              : 
   17842         7721 :             c_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
   17843              : 
   17844         7721 :             if (!ai.check_clause (c))
   17845              :               {
   17846              :                 remove = true;
   17847              :                 break;
   17848              :               }
   17849              : 
   17850         7713 :             if (!ai.map_supported_p ())
   17851              :               {
   17852           14 :                 sorry_at (OMP_CLAUSE_LOCATION (c),
   17853              :                           "unsupported map expression %qE",
   17854            7 :                           OMP_CLAUSE_DECL (c));
   17855            7 :                 remove = true;
   17856            7 :                 break;
   17857              :               }
   17858              : 
   17859        15412 :             gcc_assert ((addr_tokens[0]->type == ARRAY_BASE
   17860              :                          || addr_tokens[0]->type == STRUCTURE_BASE)
   17861              :                         && addr_tokens[1]->type == ACCESS_METHOD);
   17862              : 
   17863         7706 :             t = addr_tokens[1]->expr;
   17864              : 
   17865         7706 :             if (addr_tokens[0]->u.structure_base_kind != BASE_DECL)
   17866            0 :               goto skip_decl_checks;
   17867              : 
   17868              :             /* For OpenMP, we can access a struct "t" and "t.d" on the same
   17869              :                mapping.  OpenACC allows multiple fields of the same structure
   17870              :                to be written.  */
   17871         7706 :             if (addr_tokens[0]->type == STRUCTURE_BASE
   17872         7706 :                 && (bitmap_bit_p (&map_field_head, DECL_UID (t))
   17873          267 :                     || (!openacc && bitmap_bit_p (&map_head, DECL_UID (t)))))
   17874          309 :               goto skip_decl_checks;
   17875              : 
   17876         7397 :             if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   17877              :               {
   17878            3 :                 if (ort != C_ORT_ACC && EXPR_P (t))
   17879              :                   break;
   17880              : 
   17881            6 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17882              :                           "%qE is not a variable in %qs clause", t,
   17883            3 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17884            3 :                 remove = true;
   17885              :               }
   17886         7394 :             else if (VAR_P (t) && DECL_THREAD_LOCAL_P (t))
   17887              :               {
   17888            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17889              :                           "%qD is threadprivate variable in %qs clause", t,
   17890            0 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17891            0 :                 remove = true;
   17892              :               }
   17893         7394 :             else if ((OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
   17894         4557 :                       || (OMP_CLAUSE_MAP_KIND (c)
   17895              :                           != GOMP_MAP_FIRSTPRIVATE_POINTER))
   17896        10907 :                      && !c_mark_addressable (t))
   17897              :               remove = true;
   17898         7394 :             else if (!(OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   17899         4557 :                        && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
   17900         4557 :                            || (OMP_CLAUSE_MAP_KIND (c)
   17901              :                                == GOMP_MAP_FIRSTPRIVATE_POINTER)
   17902         3513 :                            || (OMP_CLAUSE_MAP_KIND (c)
   17903              :                                == GOMP_MAP_FORCE_DEVICEPTR)))
   17904         6292 :                      && t == OMP_CLAUSE_DECL (c)
   17905        13421 :                      && !omp_mappable_type (TREE_TYPE (t)))
   17906              :               {
   17907           16 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17908              :                           "%qD does not have a mappable type in %qs clause", t,
   17909            8 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17910            8 :                 remove = true;
   17911              :               }
   17912         7386 :             else if (TREE_TYPE (t) == error_mark_node)
   17913              :               remove = true;
   17914         7385 :             else if (TYPE_ATOMIC (strip_array_types (TREE_TYPE (t))))
   17915              :               {
   17916            8 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17917              :                           "%<_Atomic%> %qE in %qs clause", t,
   17918            4 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17919            4 :                 remove = true;
   17920              :               }
   17921         7381 :             else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   17922         4547 :                      && OMP_CLAUSE_MAP_IMPLICIT (c)
   17923         7512 :                      && (bitmap_bit_p (&map_head, DECL_UID (t))
   17924          130 :                          || bitmap_bit_p (&map_field_head, DECL_UID (t))
   17925          130 :                          || bitmap_bit_p (&map_firstprivate_head,
   17926          130 :                                           DECL_UID (t))))
   17927              :               remove = true;
   17928         7379 :             else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   17929         7379 :                      && (OMP_CLAUSE_MAP_KIND (c)
   17930              :                          == GOMP_MAP_FIRSTPRIVATE_POINTER))
   17931              :               {
   17932         1042 :                 if (bitmap_bit_p (&generic_head, DECL_UID (t))
   17933         1042 :                     || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
   17934         2083 :                     || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
   17935              :                   {
   17936            4 :                     error_at (OMP_CLAUSE_LOCATION (c),
   17937              :                               "%qD appears more than once in data clauses", t);
   17938            4 :                     remove = true;
   17939              :                   }
   17940         1038 :                 else if (bitmap_bit_p (&map_head, DECL_UID (t))
   17941            4 :                          && !bitmap_bit_p (&map_field_head, DECL_UID (t))
   17942         1040 :                          && openacc)
   17943              :                   {
   17944            1 :                     error_at (OMP_CLAUSE_LOCATION (c),
   17945              :                               "%qD appears more than once in data clauses", t);
   17946            1 :                     remove = true;
   17947              :                   }
   17948              :                 else
   17949         1037 :                   bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
   17950              :               }
   17951         6337 :             else if (bitmap_bit_p (&map_head, DECL_UID (t))
   17952           67 :                      && !bitmap_bit_p (&map_field_head, DECL_UID (t))
   17953           20 :                      && ort != C_ORT_OMP
   17954           20 :                      && ort != C_ORT_OMP_TARGET
   17955         6347 :                      && ort != C_ORT_OMP_EXIT_DATA)
   17956              :               {
   17957            7 :                 if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
   17958            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17959              :                             "%qD appears more than once in motion clauses", t);
   17960            7 :                 else if (openacc)
   17961            7 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17962              :                             "%qD appears more than once in data clauses", t);
   17963              :                 else
   17964            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17965              :                             "%qD appears more than once in map clauses", t);
   17966              :                 remove = true;
   17967              :               }
   17968         6330 :             else if (openacc && bitmap_bit_p (&generic_head, DECL_UID (t)))
   17969              :               {
   17970            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17971              :                           "%qD appears more than once in data clauses", t);
   17972            0 :                 remove = true;
   17973              :               }
   17974         6330 :             else if (bitmap_bit_p (&firstprivate_head, DECL_UID (t))
   17975         6330 :                      || bitmap_bit_p (&is_on_device_head, DECL_UID (t)))
   17976              :               {
   17977            9 :                 if (openacc)
   17978            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17979              :                             "%qD appears more than once in data clauses", t);
   17980              :                 else
   17981            9 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17982              :                             "%qD appears both in data and map clauses", t);
   17983              :                 remove = true;
   17984              :               }
   17985         6321 :             else if (!omp_access_chain_p (addr_tokens, 1))
   17986              :               {
   17987         6321 :                 bitmap_set_bit (&map_head, DECL_UID (t));
   17988         6321 :                 if (t != OMP_CLAUSE_DECL (c)
   17989         6321 :                     && TREE_CODE (OMP_CLAUSE_DECL (c)) == COMPONENT_REF)
   17990          261 :                   bitmap_set_bit (&map_field_head, DECL_UID (t));
   17991              :               }
   17992              : 
   17993            0 :           skip_decl_checks:
   17994              :             /* If we call omp_expand_map_clause in handle_omp_array_sections,
   17995              :                the containing loop (here) iterates through the new nodes
   17996              :                created by that expansion.  Avoid expanding those again (just
   17997              :                by checking the node type).  */
   17998         7706 :             if (!remove
   17999         7706 :                 && ort != C_ORT_DECLARE_SIMD
   18000         7706 :                 && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
   18001         4807 :                     || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FIRSTPRIVATE_POINTER
   18002         3770 :                         && (OMP_CLAUSE_MAP_KIND (c)
   18003              :                             != GOMP_MAP_FIRSTPRIVATE_REFERENCE)
   18004         3770 :                         && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ALWAYS_POINTER
   18005         3770 :                         && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH
   18006         3465 :                         && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
   18007         3436 :                         && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH)))
   18008              :               {
   18009         6281 :                 grp_start_p = pc;
   18010         6281 :                 grp_sentinel = OMP_CLAUSE_CHAIN (c);
   18011         6281 :                 tree nc = ai.expand_map_clause (c, OMP_CLAUSE_DECL (c),
   18012              :                                                 addr_tokens, ort);
   18013         6281 :                 if (nc != error_mark_node)
   18014         6281 :                   c = nc;
   18015              :               }
   18016         9771 :           }
   18017         7706 :           break;
   18018              : 
   18019          276 :         case OMP_CLAUSE_ENTER:
   18020          276 :         case OMP_CLAUSE_LINK:
   18021          276 :         case OMP_CLAUSE_LOCAL:
   18022          276 :           t = OMP_CLAUSE_DECL (c);
   18023          276 :           const char *cname;
   18024          276 :           cname = omp_clause_code_name[OMP_CLAUSE_CODE (c)];
   18025          276 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER
   18026          276 :               && OMP_CLAUSE_ENTER_TO (c))
   18027              :             cname = "to";
   18028          276 :           if (TREE_CODE (t) == FUNCTION_DECL
   18029          276 :               && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
   18030              :             ;
   18031          194 :           else if (!VAR_P (t))
   18032              :             {
   18033            1 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
   18034            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   18035              :                           "%qE is neither a variable nor a function name in "
   18036              :                           "clause %qs", t, cname);
   18037              :               else
   18038            1 :                 error_at (OMP_CLAUSE_LOCATION (c),
   18039              :                           "%qE is not a variable in clause %qs", t, cname);
   18040              :               remove = true;
   18041              :             }
   18042          193 :           else if (DECL_THREAD_LOCAL_P (t))
   18043              :             {
   18044            2 :               error_at (OMP_CLAUSE_LOCATION (c),
   18045              :                         "%qD is threadprivate variable in %qs clause", t,
   18046              :                         cname);
   18047            2 :               remove = true;
   18048              :             }
   18049          191 :           else if (!omp_mappable_type (TREE_TYPE (t)))
   18050              :             {
   18051            6 :               error_at (OMP_CLAUSE_LOCATION (c),
   18052              :                         "%qD does not have a mappable type in %qs clause", t,
   18053              :                         cname);
   18054            6 :               remove = true;
   18055              :             }
   18056            9 :           if (remove)
   18057              :             break;
   18058          267 :           if (bitmap_bit_p (&generic_head, DECL_UID (t)))
   18059              :             {
   18060           10 :               error_at (OMP_CLAUSE_LOCATION (c),
   18061              :                         "%qE appears more than once on the same "
   18062              :                         "%<declare target%> directive", t);
   18063           10 :               remove = true;
   18064              :             }
   18065              :           else
   18066          257 :             bitmap_set_bit (&generic_head, DECL_UID (t));
   18067              :           break;
   18068              : 
   18069          117 :         case OMP_CLAUSE_UNIFORM:
   18070          117 :           t = OMP_CLAUSE_DECL (c);
   18071          117 :           if (TREE_CODE (t) != PARM_DECL)
   18072              :             {
   18073            0 :               if (DECL_P (t))
   18074            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   18075              :                           "%qD is not an argument in %<uniform%> clause", t);
   18076              :               else
   18077            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   18078              :                           "%qE is not an argument in %<uniform%> clause", t);
   18079              :               remove = true;
   18080              :               break;
   18081              :             }
   18082              :           /* map_head bitmap is used as uniform_head if declare_simd.  */
   18083          117 :           bitmap_set_bit (&map_head, DECL_UID (t));
   18084          117 :           goto check_dup_generic;
   18085              : 
   18086          161 :         case OMP_CLAUSE_IS_DEVICE_PTR:
   18087          161 :         case OMP_CLAUSE_USE_DEVICE_PTR:
   18088          161 :           t = OMP_CLAUSE_DECL (c);
   18089          161 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
   18090          123 :             bitmap_set_bit (&is_on_device_head, DECL_UID (t));
   18091          161 :           if (TREE_CODE (TREE_TYPE (t)) != POINTER_TYPE)
   18092              :             {
   18093           21 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
   18094           21 :                   && !openacc)
   18095              :                 {
   18096            1 :                   error_at (OMP_CLAUSE_LOCATION (c),
   18097              :                             "%qs variable is not a pointer",
   18098            1 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   18099            1 :                   remove = true;
   18100              :                 }
   18101           20 :               else if (TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE)
   18102              :                 {
   18103            4 :                   error_at (OMP_CLAUSE_LOCATION (c),
   18104              :                             "%qs variable is neither a pointer nor an array",
   18105            4 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   18106            4 :                   remove = true;
   18107              :                 }
   18108              :             }
   18109          161 :           goto check_dup_generic;
   18110              : 
   18111           89 :         case OMP_CLAUSE_HAS_DEVICE_ADDR:
   18112           89 :           t = OMP_CLAUSE_DECL (c);
   18113           89 :           if (TREE_CODE (t) == OMP_ARRAY_SECTION)
   18114              :             {
   18115           11 :               if (handle_omp_array_sections (c, ort))
   18116              :                 remove = true;
   18117              :               else
   18118              :                 {
   18119           11 :                   t = OMP_CLAUSE_DECL (c);
   18120           24 :                   while (TREE_CODE (t) == ARRAY_REF)
   18121           13 :                     t = TREE_OPERAND (t, 0);
   18122              :                 }
   18123              :             }
   18124           89 :           bitmap_set_bit (&is_on_device_head, DECL_UID (t));
   18125           89 :           if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
   18126           89 :             c_mark_addressable (t);
   18127           89 :           goto check_dup_generic_t;
   18128              : 
   18129           36 :         case OMP_CLAUSE_USE_DEVICE_ADDR:
   18130           36 :           t = OMP_CLAUSE_DECL (c);
   18131           36 :           if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
   18132           36 :             c_mark_addressable (t);
   18133           36 :           goto check_dup_generic;
   18134              : 
   18135         4793 :         case OMP_CLAUSE_NOWAIT:
   18136         4793 :           if (copyprivate_seen)
   18137              :             {
   18138            1 :               error_at (OMP_CLAUSE_LOCATION (c),
   18139              :                         "%<nowait%> clause must not be used together "
   18140              :                         "with %<copyprivate%> clause");
   18141            1 :               remove = true;
   18142            1 :               break;
   18143              :             }
   18144         4792 :           nowait_clause = pc;
   18145         4792 :           pc = &OMP_CLAUSE_CHAIN (c);
   18146         4792 :           continue;
   18147              : 
   18148          523 :         case OMP_CLAUSE_ORDER:
   18149          523 :           if (ordered_clause)
   18150              :             {
   18151            2 :               error_at (OMP_CLAUSE_LOCATION (c),
   18152              :                         "%<order%> clause must not be used together "
   18153              :                         "with %<ordered%> clause");
   18154            2 :               remove = true;
   18155            2 :               break;
   18156              :             }
   18157          521 :           else if (order_clause)
   18158              :             {
   18159              :               /* Silently remove duplicates.  */
   18160              :               remove = true;
   18161              :               break;
   18162              :             }
   18163          513 :           order_clause = pc;
   18164          513 :           pc = &OMP_CLAUSE_CHAIN (c);
   18165          513 :           continue;
   18166              : 
   18167           32 :         case OMP_CLAUSE_DETACH:
   18168           32 :           t = OMP_CLAUSE_DECL (c);
   18169           32 :           if (detach_seen)
   18170              :             {
   18171            1 :               error_at (OMP_CLAUSE_LOCATION (c),
   18172              :                         "too many %qs clauses on a task construct",
   18173              :                         "detach");
   18174            1 :               remove = true;
   18175            1 :               break;
   18176              :             }
   18177           31 :           detach_seen = pc;
   18178           31 :           pc = &OMP_CLAUSE_CHAIN (c);
   18179           31 :           c_mark_addressable (t);
   18180           31 :           continue;
   18181              : 
   18182        14601 :         case OMP_CLAUSE_IF:
   18183        14601 :         case OMP_CLAUSE_SELF:
   18184        14601 :         case OMP_CLAUSE_NUM_THREADS:
   18185        14601 :         case OMP_CLAUSE_NUM_TEAMS:
   18186        14601 :         case OMP_CLAUSE_THREAD_LIMIT:
   18187        14601 :         case OMP_CLAUSE_DEFAULT:
   18188        14601 :         case OMP_CLAUSE_UNTIED:
   18189        14601 :         case OMP_CLAUSE_COLLAPSE:
   18190        14601 :         case OMP_CLAUSE_FINAL:
   18191        14601 :         case OMP_CLAUSE_DEVICE:
   18192        14601 :         case OMP_CLAUSE_DIST_SCHEDULE:
   18193        14601 :         case OMP_CLAUSE_DYN_GROUPPRIVATE:
   18194        14601 :         case OMP_CLAUSE_PARALLEL:
   18195        14601 :         case OMP_CLAUSE_FOR:
   18196        14601 :         case OMP_CLAUSE_SECTIONS:
   18197        14601 :         case OMP_CLAUSE_TASKGROUP:
   18198        14601 :         case OMP_CLAUSE_PROC_BIND:
   18199        14601 :         case OMP_CLAUSE_DEVICE_TYPE:
   18200        14601 :         case OMP_CLAUSE_PRIORITY:
   18201        14601 :         case OMP_CLAUSE_THREADS:
   18202        14601 :         case OMP_CLAUSE_SIMD:
   18203        14601 :         case OMP_CLAUSE_HINT:
   18204        14601 :         case OMP_CLAUSE_FILTER:
   18205        14601 :         case OMP_CLAUSE_DEFAULTMAP:
   18206        14601 :         case OMP_CLAUSE_BIND:
   18207        14601 :         case OMP_CLAUSE_NUM_GANGS:
   18208        14601 :         case OMP_CLAUSE_NUM_WORKERS:
   18209        14601 :         case OMP_CLAUSE_VECTOR_LENGTH:
   18210        14601 :         case OMP_CLAUSE_ASYNC:
   18211        14601 :         case OMP_CLAUSE_WAIT:
   18212        14601 :         case OMP_CLAUSE_AUTO:
   18213        14601 :         case OMP_CLAUSE_INDEPENDENT:
   18214        14601 :         case OMP_CLAUSE_SEQ:
   18215        14601 :         case OMP_CLAUSE_GANG:
   18216        14601 :         case OMP_CLAUSE_WORKER:
   18217        14601 :         case OMP_CLAUSE_VECTOR:
   18218        14601 :         case OMP_CLAUSE_TILE:
   18219        14601 :         case OMP_CLAUSE_IF_PRESENT:
   18220        14601 :         case OMP_CLAUSE_FINALIZE:
   18221        14601 :         case OMP_CLAUSE_NOHOST:
   18222        14601 :         case OMP_CLAUSE_INDIRECT:
   18223        14601 :         case OMP_CLAUSE_NOVARIANTS:
   18224        14601 :         case OMP_CLAUSE_NOCONTEXT:
   18225        14601 :           pc = &OMP_CLAUSE_CHAIN (c);
   18226        14601 :           continue;
   18227              : 
   18228           62 :         case OMP_CLAUSE_GRAINSIZE:
   18229           62 :           grainsize_seen = pc;
   18230           62 :           pc = &OMP_CLAUSE_CHAIN (c);
   18231           62 :           continue;
   18232              : 
   18233           50 :         case OMP_CLAUSE_NUM_TASKS:
   18234           50 :           num_tasks_seen = true;
   18235           50 :           pc = &OMP_CLAUSE_CHAIN (c);
   18236           50 :           continue;
   18237              : 
   18238           79 :         case OMP_CLAUSE_MERGEABLE:
   18239           79 :           mergeable_seen = true;
   18240           79 :           pc = &OMP_CLAUSE_CHAIN (c);
   18241           79 :           continue;
   18242              : 
   18243           18 :         case OMP_CLAUSE_NOGROUP:
   18244           18 :           nogroup_seen = pc;
   18245           18 :           pc = &OMP_CLAUSE_CHAIN (c);
   18246           18 :           continue;
   18247              : 
   18248         3475 :         case OMP_CLAUSE_SCHEDULE:
   18249         3475 :           schedule_clause = c;
   18250         3475 :           pc = &OMP_CLAUSE_CHAIN (c);
   18251         3475 :           continue;
   18252              : 
   18253          304 :         case OMP_CLAUSE_ORDERED:
   18254          304 :           ordered_clause = c;
   18255          304 :           if (order_clause)
   18256              :             {
   18257            2 :               error_at (OMP_CLAUSE_LOCATION (*order_clause),
   18258              :                         "%<order%> clause must not be used together "
   18259              :                         "with %<ordered%> clause");
   18260            2 :               *order_clause = OMP_CLAUSE_CHAIN (*order_clause);
   18261            2 :               order_clause = NULL;
   18262              :             }
   18263          304 :           pc = &OMP_CLAUSE_CHAIN (c);
   18264          304 :           continue;
   18265              : 
   18266          223 :         case OMP_CLAUSE_SAFELEN:
   18267          223 :           safelen = c;
   18268          223 :           pc = &OMP_CLAUSE_CHAIN (c);
   18269          223 :           continue;
   18270          339 :         case OMP_CLAUSE_SIMDLEN:
   18271          339 :           simdlen = c;
   18272          339 :           pc = &OMP_CLAUSE_CHAIN (c);
   18273          339 :           continue;
   18274              : 
   18275           69 :         case OMP_CLAUSE_FULL:
   18276           69 :           full_seen = pc;
   18277           69 :           pc = &OMP_CLAUSE_CHAIN (c);
   18278           69 :           continue;
   18279              : 
   18280          223 :         case OMP_CLAUSE_PARTIAL:
   18281          223 :           partial_seen = true;
   18282          223 :           pc = &OMP_CLAUSE_CHAIN (c);
   18283          223 :           continue;
   18284              : 
   18285            0 :         case OMP_CLAUSE_SIZES:
   18286            0 :           pc = &OMP_CLAUSE_CHAIN (c);
   18287            0 :           continue;
   18288              : 
   18289          208 :         case OMP_CLAUSE_INBRANCH:
   18290          208 :         case OMP_CLAUSE_NOTINBRANCH:
   18291          208 :           if (branch_seen)
   18292              :             {
   18293            1 :               error_at (OMP_CLAUSE_LOCATION (c),
   18294              :                         "%<inbranch%> clause is incompatible with "
   18295              :                         "%<notinbranch%>");
   18296            1 :               remove = true;
   18297            1 :               break;
   18298              :             }
   18299          207 :           branch_seen = true;
   18300          207 :           pc = &OMP_CLAUSE_CHAIN (c);
   18301          207 :           continue;
   18302              : 
   18303          370 :         case OMP_CLAUSE_INCLUSIVE:
   18304          370 :         case OMP_CLAUSE_EXCLUSIVE:
   18305          370 :           need_complete = true;
   18306          370 :           need_implicitly_determined = true;
   18307          370 :           t = OMP_CLAUSE_DECL (c);
   18308          370 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   18309              :             {
   18310            0 :               error_at (OMP_CLAUSE_LOCATION (c),
   18311              :                         "%qE is not a variable in clause %qs", t,
   18312            0 :                         omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   18313            0 :               remove = true;
   18314              :             }
   18315              :           break;
   18316              : 
   18317          152 :         case OMP_CLAUSE_INIT:
   18318          152 :           init_seen = true;
   18319          152 :           if (!OMP_CLAUSE_INIT_TARGETSYNC (c))
   18320           71 :             init_no_targetsync_clause = c;
   18321              :           /* FALLTHRU */
   18322          242 :         case OMP_CLAUSE_DESTROY:
   18323          242 :         case OMP_CLAUSE_USE:
   18324          242 :           init_use_destroy_seen = true;
   18325          242 :           t = OMP_CLAUSE_DECL (c);
   18326          242 :           if (bitmap_bit_p (&generic_head, DECL_UID (t)))
   18327              :             {
   18328            3 :               error_at (OMP_CLAUSE_LOCATION (c),
   18329              :                         "%qD appears more than once in action clauses", t);
   18330            3 :               remove = true;
   18331            3 :               break;
   18332              :             }
   18333          239 :           bitmap_set_bit (&generic_head, DECL_UID (t));
   18334              :           /* FALLTHRU */
   18335          298 :         case OMP_CLAUSE_INTEROP:
   18336          298 :           if (/* ort == C_ORT_OMP_INTEROP [uncomment for depobj init]  */
   18337          298 :                    !c_omp_interop_t_p (TREE_TYPE (OMP_CLAUSE_DECL (c))))
   18338              :             {
   18339           40 :               error_at (OMP_CLAUSE_LOCATION (c),
   18340              :                         "%qD must be of %<omp_interop_t%>",
   18341           20 :                         OMP_CLAUSE_DECL (c));
   18342           20 :               remove = true;
   18343              :             }
   18344          278 :           else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INIT
   18345          133 :                     || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DESTROY)
   18346          318 :                    && TREE_READONLY (OMP_CLAUSE_DECL (c)))
   18347              :             {
   18348           12 :               error_at (OMP_CLAUSE_LOCATION (c),
   18349            6 :                       "%qD shall not be const", OMP_CLAUSE_DECL (c));
   18350            6 :               remove = true;
   18351              :             }
   18352          298 :           pc = &OMP_CLAUSE_CHAIN (c);
   18353          298 :           break;
   18354            0 :         default:
   18355            0 :           gcc_unreachable ();
   18356        25029 :         }
   18357              : 
   18358        23160 :       if (!remove)
   18359              :         {
   18360        22592 :           t = OMP_CLAUSE_DECL (c);
   18361              : 
   18362        22592 :           if (need_complete)
   18363              :             {
   18364         3978 :               t = require_complete_type (OMP_CLAUSE_LOCATION (c), t);
   18365         3978 :               if (t == error_mark_node)
   18366            7 :                 remove = true;
   18367              :             }
   18368              : 
   18369        22592 :           if (need_implicitly_determined)
   18370              :             {
   18371         9597 :               const char *share_name = NULL;
   18372              : 
   18373         9597 :               if (VAR_P (t) && DECL_THREAD_LOCAL_P (t))
   18374              :                 share_name = "threadprivate";
   18375         9591 :               else switch (c_omp_predetermined_sharing (t))
   18376              :                 {
   18377              :                 case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
   18378              :                   break;
   18379           20 :                 case OMP_CLAUSE_DEFAULT_SHARED:
   18380           20 :                   if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
   18381           12 :                        || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE)
   18382           28 :                       && c_omp_predefined_variable (t))
   18383              :                     /* The __func__ variable and similar function-local
   18384              :                        predefined variables may be listed in a shared or
   18385              :                        firstprivate clause.  */
   18386              :                     break;
   18387              :                   share_name = "shared";
   18388              :                   break;
   18389              :                 case OMP_CLAUSE_DEFAULT_PRIVATE:
   18390              :                   share_name = "private";
   18391              :                   break;
   18392            0 :                 default:
   18393            0 :                   gcc_unreachable ();
   18394              :                 }
   18395              :               if (share_name)
   18396              :                 {
   18397           20 :                   error_at (OMP_CLAUSE_LOCATION (c),
   18398              :                             "%qE is predetermined %qs for %qs",
   18399              :                             t, share_name,
   18400           10 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   18401           10 :                   remove = true;
   18402              :                 }
   18403         9587 :               else if (TREE_READONLY (t)
   18404           23 :                        && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
   18405         9600 :                        && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE)
   18406              :                 {
   18407            4 :                   error_at (OMP_CLAUSE_LOCATION (c),
   18408              :                             "%<const%> qualified %qE may appear only in "
   18409              :                             "%<shared%> or %<firstprivate%> clauses", t);
   18410            4 :                   remove = true;
   18411              :                 }
   18412              :             }
   18413              :         }
   18414              : 
   18415        22592 :       if (remove)
   18416              :         {
   18417          589 :           if (grp_start_p)
   18418              :             {
   18419              :               /* If we found a clause to remove, we want to remove the whole
   18420              :                  expanded group, otherwise gimplify
   18421              :                  (omp_resolve_clause_dependencies) can get confused.  */
   18422          153 :               *grp_start_p = grp_sentinel;
   18423          153 :               pc = grp_start_p;
   18424          153 :               grp_start_p = NULL;
   18425              :             }
   18426              :           else
   18427          436 :             *pc = OMP_CLAUSE_CHAIN (c);
   18428              :         }
   18429              :       else
   18430        22571 :         pc = &OMP_CLAUSE_CHAIN (c);
   18431              :     }
   18432              : 
   18433        29789 :   if (grp_start_p
   18434        29789 :       && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
   18435           58 :     for (tree gc = *grp_start_p; gc; gc = OMP_CLAUSE_CHAIN (gc))
   18436           35 :       OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
   18437              : 
   18438        29789 :   if (simdlen
   18439        29789 :       && safelen
   18440        29906 :       && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen),
   18441          117 :                           OMP_CLAUSE_SIMDLEN_EXPR (simdlen)))
   18442              :     {
   18443              :       /* Note: How a scaling factor affects this, is underspecified in OpenMP;
   18444              :          cf. OpenMP spec issue #5160.  Presumably, it means:
   18445              :            savelen >= simdlen * scale_factor
   18446              :          with
   18447              :            scale_factor = MAX (1, FLOOR_DIV_EXPR (VL(type), divisor))
   18448              :          and OpenMP states that VL(type) might be only known at runtime.
   18449              :          Hence scale_factor >= 1 and, conservatively, assume == 1 for this
   18450              :          error check.  */
   18451            0 :       error_at (OMP_CLAUSE_LOCATION (simdlen),
   18452              :                 "%<simdlen%> clause value is bigger than "
   18453              :                 "%<safelen%> clause value");
   18454            0 :       OMP_CLAUSE_SIMDLEN_EXPR (simdlen)
   18455            0 :         = OMP_CLAUSE_SAFELEN_EXPR (safelen);
   18456              :     }
   18457              : 
   18458        29789 :   if (ordered_clause
   18459        29789 :       && schedule_clause
   18460        29789 :       && (OMP_CLAUSE_SCHEDULE_KIND (schedule_clause)
   18461              :           & OMP_CLAUSE_SCHEDULE_NONMONOTONIC))
   18462              :     {
   18463            7 :       error_at (OMP_CLAUSE_LOCATION (schedule_clause),
   18464              :                 "%<nonmonotonic%> schedule modifier specified together "
   18465              :                 "with %<ordered%> clause");
   18466           14 :       OMP_CLAUSE_SCHEDULE_KIND (schedule_clause)
   18467            7 :         = (enum omp_clause_schedule_kind)
   18468            7 :           (OMP_CLAUSE_SCHEDULE_KIND (schedule_clause)
   18469              :            & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC);
   18470              :     }
   18471              : 
   18472        29789 :   if (reduction_seen < 0 && ordered_clause)
   18473              :     {
   18474            2 :       error_at (OMP_CLAUSE_LOCATION (ordered_clause),
   18475              :                 "%qs clause specified together with %<inscan%> "
   18476              :                 "%<reduction%> clause", "ordered");
   18477            2 :       reduction_seen = -2;
   18478              :     }
   18479              : 
   18480        29789 :   if (reduction_seen < 0 && schedule_clause)
   18481              :     {
   18482            3 :       error_at (OMP_CLAUSE_LOCATION (schedule_clause),
   18483              :                 "%qs clause specified together with %<inscan%> "
   18484              :                 "%<reduction%> clause", "schedule");
   18485            3 :       reduction_seen = -2;
   18486              :     }
   18487              : 
   18488        29789 :   if (linear_variable_step_check
   18489        29789 :       || reduction_seen == -2
   18490              :       || allocate_seen
   18491        29777 :       || target_in_reduction_seen)
   18492         5225 :     for (pc = &clauses, c = clauses; c ; c = *pc)
   18493              :       {
   18494         4618 :         bool remove = false;
   18495         4618 :         if (allocate_seen)
   18496         4460 :           switch (OMP_CLAUSE_CODE (c))
   18497              :             {
   18498          430 :             case OMP_CLAUSE_REDUCTION:
   18499          430 :             case OMP_CLAUSE_IN_REDUCTION:
   18500          430 :             case OMP_CLAUSE_TASK_REDUCTION:
   18501          430 :               if (TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF)
   18502              :                 {
   18503           23 :                   t = TREE_OPERAND (OMP_CLAUSE_DECL (c), 0);
   18504           23 :                   if (TREE_CODE (t) == POINTER_PLUS_EXPR)
   18505            0 :                     t = TREE_OPERAND (t, 0);
   18506           23 :                   if (TREE_CODE (t) == ADDR_EXPR
   18507           10 :                       || INDIRECT_REF_P (t))
   18508           13 :                     t = TREE_OPERAND (t, 0);
   18509           23 :                   if (DECL_P (t))
   18510           23 :                     bitmap_clear_bit (&aligned_head, DECL_UID (t));
   18511              :                   break;
   18512              :                 }
   18513              :               /* FALLTHRU */
   18514         1329 :             case OMP_CLAUSE_PRIVATE:
   18515         1329 :             case OMP_CLAUSE_FIRSTPRIVATE:
   18516         1329 :             case OMP_CLAUSE_LASTPRIVATE:
   18517         1329 :             case OMP_CLAUSE_LINEAR:
   18518         1329 :               if (DECL_P (OMP_CLAUSE_DECL (c)))
   18519         2658 :                 bitmap_clear_bit (&aligned_head,
   18520         1329 :                                   DECL_UID (OMP_CLAUSE_DECL (c)));
   18521              :               break;
   18522              :             default:
   18523              :               break;
   18524              :             }
   18525         4618 :         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
   18526           29 :             && OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c)
   18527         4625 :             && !bitmap_bit_p (&map_head,
   18528            7 :                               DECL_UID (OMP_CLAUSE_LINEAR_STEP (c))))
   18529              :           {
   18530            2 :             error_at (OMP_CLAUSE_LOCATION (c),
   18531              :                       "%<linear%> clause step is a parameter %qD not "
   18532              :                       "specified in %<uniform%> clause",
   18533            2 :                       OMP_CLAUSE_LINEAR_STEP (c));
   18534            2 :             remove = true;
   18535              :           }
   18536         4616 :         else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   18537         4616 :                  && reduction_seen == -2)
   18538            9 :           OMP_CLAUSE_REDUCTION_INSCAN (c) = 0;
   18539         4618 :         if (target_in_reduction_seen
   18540         4618 :             && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
   18541              :           {
   18542          256 :             tree t = OMP_CLAUSE_DECL (c);
   18543          256 :             while (handled_component_p (t)
   18544              :                    || INDIRECT_REF_P (t)
   18545              :                    || TREE_CODE (t) == ADDR_EXPR
   18546              :                    || TREE_CODE (t) == MEM_REF
   18547          288 :                    || TREE_CODE (t) == NON_LVALUE_EXPR)
   18548           32 :               t = TREE_OPERAND (t, 0);
   18549          256 :             if (DECL_P (t)
   18550          256 :                 && bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
   18551          138 :               OMP_CLAUSE_MAP_IN_REDUCTION (c) = 1;
   18552              :           }
   18553              : 
   18554         4618 :         if (remove)
   18555            2 :           *pc = OMP_CLAUSE_CHAIN (c);
   18556              :         else
   18557         4616 :           pc = &OMP_CLAUSE_CHAIN (c);
   18558              :       }
   18559              : 
   18560          607 :   if (allocate_seen)
   18561         5041 :     for (pc = &clauses, c = clauses; c ; c = *pc)
   18562              :       {
   18563         4460 :         bool remove = false;
   18564         4460 :         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ALLOCATE
   18565          731 :             && !OMP_CLAUSE_ALLOCATE_COMBINED (c)
   18566         5171 :             && bitmap_bit_p (&aligned_head, DECL_UID (OMP_CLAUSE_DECL (c))))
   18567              :           {
   18568            3 :             error_at (OMP_CLAUSE_LOCATION (c),
   18569              :                       "%qD specified in %<allocate%> clause but not in "
   18570            3 :                       "an explicit privatization clause", OMP_CLAUSE_DECL (c));
   18571            3 :             remove = true;
   18572              :           }
   18573         4460 :         if (remove)
   18574            3 :           *pc = OMP_CLAUSE_CHAIN (c);
   18575              :         else
   18576         4457 :           pc = &OMP_CLAUSE_CHAIN (c);
   18577              :       }
   18578              : 
   18579        29789 :   if (nogroup_seen && reduction_seen)
   18580              :     {
   18581            1 :       error_at (OMP_CLAUSE_LOCATION (*nogroup_seen),
   18582              :                 "%<nogroup%> clause must not be used together with "
   18583              :                 "%<reduction%> clause");
   18584            1 :       *nogroup_seen = OMP_CLAUSE_CHAIN (*nogroup_seen);
   18585              :     }
   18586              : 
   18587        29789 :   if (grainsize_seen && num_tasks_seen)
   18588              :     {
   18589            2 :       error_at (OMP_CLAUSE_LOCATION (*grainsize_seen),
   18590              :                 "%<grainsize%> clause must not be used together with "
   18591              :                 "%<num_tasks%> clause");
   18592            2 :       *grainsize_seen = OMP_CLAUSE_CHAIN (*grainsize_seen);
   18593              :     }
   18594              : 
   18595        29789 :   if (full_seen && partial_seen)
   18596              :     {
   18597            4 :       error_at (OMP_CLAUSE_LOCATION (*full_seen),
   18598              :                 "%<full%> clause must not be used together with "
   18599              :                 "%<partial%> clause");
   18600            4 :       *full_seen = OMP_CLAUSE_CHAIN (*full_seen);
   18601              :     }
   18602              : 
   18603        29789 :   if (detach_seen)
   18604              :     {
   18605           31 :       if (mergeable_seen)
   18606              :         {
   18607            2 :           error_at (OMP_CLAUSE_LOCATION (*detach_seen),
   18608              :                     "%<detach%> clause must not be used together with "
   18609              :                     "%<mergeable%> clause");
   18610            2 :           *detach_seen = OMP_CLAUSE_CHAIN (*detach_seen);
   18611              :         }
   18612              :       else
   18613              :         {
   18614           29 :           tree detach_decl = OMP_CLAUSE_DECL (*detach_seen);
   18615              : 
   18616           79 :           for (pc = &clauses, c = clauses; c ; c = *pc)
   18617              :             {
   18618           50 :               bool remove = false;
   18619           50 :               if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
   18620           48 :                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
   18621           48 :                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
   18622           44 :                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE)
   18623           54 :                   && OMP_CLAUSE_DECL (c) == detach_decl)
   18624              :                 {
   18625            2 :                   error_at (OMP_CLAUSE_LOCATION (c),
   18626              :                             "the event handle of a %<detach%> clause "
   18627              :                             "should not be in a data-sharing clause");
   18628            2 :                   remove = true;
   18629              :                 }
   18630           50 :               if (remove)
   18631            2 :                 *pc = OMP_CLAUSE_CHAIN (c);
   18632              :               else
   18633           48 :                 pc = &OMP_CLAUSE_CHAIN (c);
   18634              :             }
   18635              :         }
   18636              :     }
   18637              : 
   18638        29789 :   if (ort == C_ORT_OMP_INTEROP
   18639        29789 :       && depend_clause
   18640           21 :       && (!init_use_destroy_seen
   18641           20 :           || (init_seen && init_no_targetsync_clause)))
   18642              :     {
   18643            3 :       error_at (OMP_CLAUSE_LOCATION (depend_clause),
   18644              :                 "%<depend%> clause requires action clauses with "
   18645              :                 "%<targetsync%> interop-type");
   18646            3 :       if (init_no_targetsync_clause)
   18647            2 :         inform (OMP_CLAUSE_LOCATION (init_no_targetsync_clause),
   18648              :                 "%<init%> clause lacks the %<targetsync%> modifier");
   18649              :     }
   18650              : 
   18651        29789 :   bitmap_obstack_release (NULL);
   18652        29789 :   return clauses;
   18653              : }
   18654              : 
   18655              : /* Do processing necessary to make CLAUSES well-formed, where CLAUSES result
   18656              :    from implicit instantiation of user-defined mappers (in gimplify.cc).  */
   18657              : 
   18658              : tree
   18659           15 : c_omp_finish_mapper_clauses (tree clauses)
   18660              : {
   18661           15 :   return c_finish_omp_clauses (clauses, C_ORT_OMP);
   18662              : }
   18663              : 
   18664              : /* Return code to initialize DST with a copy constructor from SRC.
   18665              :    C doesn't have copy constructors nor assignment operators, only for
   18666              :    _Atomic vars we need to perform __atomic_load from src into a temporary
   18667              :    followed by __atomic_store of the temporary to dst.  */
   18668              : 
   18669              : tree
   18670        18755 : c_omp_clause_copy_ctor (tree clause, tree dst, tree src)
   18671              : {
   18672        18755 :   if (!really_atomic_lvalue (dst) && !really_atomic_lvalue (src))
   18673        18751 :     return build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src);
   18674              : 
   18675            4 :   location_t loc = OMP_CLAUSE_LOCATION (clause);
   18676            4 :   tree type = TREE_TYPE (dst);
   18677            4 :   tree nonatomic_type = build_qualified_type (type, TYPE_UNQUALIFIED);
   18678            4 :   tree tmp = create_tmp_var (nonatomic_type);
   18679            4 :   tree tmp_addr = build_fold_addr_expr (tmp);
   18680            4 :   TREE_ADDRESSABLE (tmp) = 1;
   18681            4 :   suppress_warning (tmp);
   18682            4 :   tree src_addr = build_fold_addr_expr (src);
   18683            4 :   tree dst_addr = build_fold_addr_expr (dst);
   18684            4 :   tree seq_cst = build_int_cst (integer_type_node, MEMMODEL_SEQ_CST);
   18685            4 :   vec<tree, va_gc> *params;
   18686              :   /* Expansion of a generic atomic load may require an addition
   18687              :      element, so allocate enough to prevent a resize.  */
   18688            4 :   vec_alloc (params, 4);
   18689              : 
   18690              :   /* Build __atomic_load (&src, &tmp, SEQ_CST);  */
   18691            4 :   tree fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_LOAD);
   18692            4 :   params->quick_push (src_addr);
   18693            4 :   params->quick_push (tmp_addr);
   18694            4 :   params->quick_push (seq_cst);
   18695            4 :   tree load = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
   18696              : 
   18697            4 :   vec_alloc (params, 4);
   18698              : 
   18699              :   /* Build __atomic_store (&dst, &tmp, SEQ_CST);  */
   18700            4 :   fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_STORE);
   18701            4 :   params->quick_push (dst_addr);
   18702            4 :   params->quick_push (tmp_addr);
   18703            4 :   params->quick_push (seq_cst);
   18704            4 :   tree store = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
   18705            4 :   return build2 (COMPOUND_EXPR, void_type_node, load, store);
   18706              : }
   18707              : 
   18708              : /* Create a transaction node.  */
   18709              : 
   18710              : tree
   18711          135 : c_finish_transaction (location_t loc, tree block, int flags)
   18712              : {
   18713          135 :   tree stmt = build_stmt (loc, TRANSACTION_EXPR, block);
   18714          135 :   if (flags & TM_STMT_ATTR_OUTER)
   18715           10 :     TRANSACTION_EXPR_OUTER (stmt) = 1;
   18716          135 :   if (flags & TM_STMT_ATTR_RELAXED)
   18717           31 :     TRANSACTION_EXPR_RELAXED (stmt) = 1;
   18718          135 :   return add_stmt (stmt);
   18719              : }
   18720              : 
   18721              : /* Make a variant type in the proper way for C/C++, propagating qualifiers
   18722              :    down to the element type of an array.  If ORIG_QUAL_TYPE is not
   18723              :    NULL, then it should be used as the qualified type
   18724              :    ORIG_QUAL_INDIRECT levels down in array type derivation (to
   18725              :    preserve information about the typedef name from which an array
   18726              :    type was derived).  */
   18727              : 
   18728              : tree
   18729     76625655 : c_build_qualified_type (tree type, int type_quals, tree orig_qual_type,
   18730              :                         size_t orig_qual_indirect)
   18731              : {
   18732     76625655 :   if (type == error_mark_node)
   18733              :     return type;
   18734              : 
   18735     76625503 :   if (TREE_CODE (type) == ARRAY_TYPE)
   18736              :     {
   18737      3156838 :       tree t;
   18738      3156838 :       tree element_type = c_build_qualified_type (TREE_TYPE (type),
   18739              :                                                   type_quals, orig_qual_type,
   18740              :                                                   orig_qual_indirect - 1);
   18741              : 
   18742              :       /* See if we already have an identically qualified type.  */
   18743      3156838 :       if (orig_qual_type && orig_qual_indirect == 0)
   18744              :         t = orig_qual_type;
   18745              :       else
   18746      4601225 :         for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
   18747              :           {
   18748      4459934 :             if (TYPE_QUALS (strip_array_types (t)) == type_quals
   18749      3036566 :                 && TYPE_NAME (t) == TYPE_NAME (type)
   18750      3015506 :                 && TYPE_CONTEXT (t) == TYPE_CONTEXT (type)
   18751      7475440 :                 && attribute_list_equal (TYPE_ATTRIBUTES (t),
   18752      3015506 :                                          TYPE_ATTRIBUTES (type)))
   18753              :               break;
   18754              :           }
   18755      3156797 :       if (!t)
   18756              :         {
   18757       141291 :           tree domain = TYPE_DOMAIN (type);
   18758              : 
   18759       141291 :           t = build_variant_type_copy (type);
   18760       141291 :           TREE_TYPE (t) = element_type;
   18761       141291 :           TYPE_ADDR_SPACE (t) = TYPE_ADDR_SPACE (element_type);
   18762              : 
   18763       141291 :           if (TYPE_STRUCTURAL_EQUALITY_P (element_type)
   18764       141291 :               || (domain && TYPE_STRUCTURAL_EQUALITY_P (domain)))
   18765          196 :             SET_TYPE_STRUCTURAL_EQUALITY (t);
   18766       141095 :           else if (TYPE_CANONICAL (element_type) != element_type
   18767       141095 :                    || (domain && TYPE_CANONICAL (domain) != domain))
   18768              :             {
   18769         2831 :               tree unqualified_canon
   18770         5403 :                 = c_build_array_type (TYPE_CANONICAL (element_type),
   18771         2572 :                                       domain ? TYPE_CANONICAL (domain)
   18772              :                                              : NULL_TREE);
   18773         2831 :               if (TYPE_REVERSE_STORAGE_ORDER (type))
   18774              :                 {
   18775            0 :                   unqualified_canon
   18776            0 :                     = build_distinct_type_copy (unqualified_canon);
   18777            0 :                   TYPE_REVERSE_STORAGE_ORDER (unqualified_canon) = 1;
   18778              :                 }
   18779         2831 :               TYPE_CANONICAL (t)
   18780         5662 :                 = c_build_qualified_type (unqualified_canon, type_quals);
   18781              :             }
   18782              :           else
   18783       138264 :             TYPE_CANONICAL (t) = t;
   18784              :         }
   18785              :       return t;
   18786              :     }
   18787              : 
   18788              :   /* A restrict-qualified pointer type must be a pointer to object or
   18789              :      incomplete type.  Note that the use of POINTER_TYPE_P also allows
   18790              :      REFERENCE_TYPEs, which is appropriate for C++.  */
   18791     73468665 :   if ((type_quals & TYPE_QUAL_RESTRICT)
   18792     73468665 :       && (!POINTER_TYPE_P (type)
   18793      3486917 :           || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type))))
   18794              :     {
   18795            3 :       error ("invalid use of %<restrict%>");
   18796            3 :       type_quals &= ~TYPE_QUAL_RESTRICT;
   18797              :     }
   18798              : 
   18799     73468665 :   tree var_type = (orig_qual_type && orig_qual_indirect == 0
   18800     73468665 :                    ? orig_qual_type
   18801     73468634 :                    : build_qualified_type (type, type_quals));
   18802              : 
   18803     73468665 :   gcc_checking_assert (C_TYPE_VARIABLE_SIZE (var_type)
   18804              :                        == C_TYPE_VARIABLE_SIZE (type));
   18805     73468665 :   gcc_checking_assert (c_type_variably_modified_p (var_type)
   18806              :                        == c_type_variably_modified_p (type));
   18807              : 
   18808              :   /* A variant type does not inherit the list of incomplete vars from the
   18809              :      type main variant.  */
   18810     73468665 :   if ((RECORD_OR_UNION_TYPE_P (var_type)
   18811     71377545 :        || TREE_CODE (var_type) == ENUMERAL_TYPE)
   18812     73574779 :       && TYPE_MAIN_VARIANT (var_type) != var_type)
   18813      1415286 :     C_TYPE_INCOMPLETE_VARS (var_type) = 0;
   18814              :   return var_type;
   18815              : }
   18816              : 
   18817              : /* Build a VA_ARG_EXPR for the C parser.  */
   18818              : 
   18819              : tree
   18820        19990 : c_build_va_arg (location_t loc1, tree expr, location_t loc2, tree type,
   18821              :                 tree type_expr)
   18822              : {
   18823        19990 :   if (error_operand_p (type))
   18824            2 :     return error_mark_node;
   18825              :   /* VA_ARG_EXPR cannot be used for a scalar va_list with reverse storage
   18826              :      order because it takes the address of the expression.  */
   18827        19988 :   else if (handled_component_p (expr)
   18828           31 :            && reverse_storage_order_for_component_p (expr))
   18829              :     {
   18830            0 :       error_at (loc1, "cannot use %<va_arg%> with reverse storage order");
   18831            0 :       return error_mark_node;
   18832              :     }
   18833        19988 :   else if (!COMPLETE_TYPE_P (type))
   18834              :     {
   18835           11 :       error_at (loc2, "second argument to %<va_arg%> is of incomplete "
   18836              :                 "type %qT", type);
   18837           11 :       return error_mark_node;
   18838              :     }
   18839        19977 :   else if (TREE_CODE (type) == FUNCTION_TYPE)
   18840              :     {
   18841            1 :       error_at (loc2, "second argument to %<va_arg%> is a function type %qT",
   18842              :                 type);
   18843            1 :       return error_mark_node;
   18844              :     }
   18845            6 :   else if (TREE_CODE (type) == ARRAY_TYPE && C_TYPE_VARIABLE_SIZE (type)
   18846        19979 :            && !flag_isoc99)
   18847              :     {
   18848            1 :       error_at (loc2, "second argument to %<va_arg%> is an array type %qT",
   18849              :                 type);
   18850            1 :       return error_mark_node;
   18851              :     }
   18852        19975 :   else if (warn_cxx_compat && TREE_CODE (type) == ENUMERAL_TYPE)
   18853            1 :     warning_at (loc2, OPT_Wc___compat,
   18854              :                 "C++ requires promoted type, not enum type, in %<va_arg%>");
   18855              : 
   18856        19975 :   if (flag_isoc99 && TREE_CODE (type) == ARRAY_TYPE)
   18857              :     {
   18858            3 :       warning_at (loc2, 0, "second argument to %<va_arg%> is an array type %qT",
   18859              :                   type);
   18860              :       /* We create a trap but evaluate side effects first.  */
   18861            3 :       tree trapfn = builtin_decl_explicit (BUILT_IN_TRAP);
   18862            3 :       trapfn = build_call_expr_loc (loc2, trapfn, 0);
   18863            3 :       tree e2 = build2 (COMPOUND_EXPR, void_type_node, expr, trapfn);
   18864              :       /* Return a compound literal of the right type.  */
   18865            3 :       tree e1 = build_compound_literal (loc2, type, NULL, true, 0, NULL);
   18866            3 :       expr = build2 (COMPOUND_EXPR, type, e2, e1);
   18867            3 :     }
   18868              :   else
   18869        19972 :     expr = build_va_arg (loc2, expr, type);
   18870              : 
   18871        19975 :   if (type_expr)
   18872           26 :     expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr), type_expr, expr);
   18873              : 
   18874              :   return expr;
   18875              : }
   18876              : 
   18877              : /* Return truthvalue of whether T1 is the same tree structure as T2.
   18878              :    Return 1 if they are the same. Return false if they are different.  */
   18879              : 
   18880              : bool
   18881         1854 : c_tree_equal (tree t1, tree t2)
   18882              : {
   18883         1883 :   enum tree_code code1, code2;
   18884              : 
   18885         1883 :   if (t1 == t2)
   18886              :     return true;
   18887          661 :   if (!t1 || !t2)
   18888              :     return false;
   18889              : 
   18890          681 :   for (code1 = TREE_CODE (t1); code1 == NON_LVALUE_EXPR;
   18891           20 :        code1 = TREE_CODE (t1))
   18892           20 :     t1 = TREE_OPERAND (t1, 0);
   18893          682 :   for (code2 = TREE_CODE (t2); code2 == NON_LVALUE_EXPR;
   18894           21 :        code2 = TREE_CODE (t2))
   18895           21 :     t2 = TREE_OPERAND (t2, 0);
   18896              : 
   18897              :   /* They might have become equal now.  */
   18898          661 :   if (t1 == t2)
   18899              :     return true;
   18900              : 
   18901          640 :   if (code1 != code2)
   18902              :     return false;
   18903              : 
   18904          379 :   if (CONSTANT_CLASS_P (t1) && !comptypes (TREE_TYPE (t1), TREE_TYPE (t2)))
   18905              :     return false;
   18906              : 
   18907          379 :   switch (code1)
   18908              :     {
   18909            2 :     case INTEGER_CST:
   18910            2 :       return wi::to_wide (t1) == wi::to_wide (t2);
   18911              : 
   18912           10 :     case REAL_CST:
   18913           10 :       return real_equal (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
   18914              : 
   18915            0 :     case STRING_CST:
   18916            0 :       return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
   18917            0 :         && !memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
   18918            0 :                     TREE_STRING_LENGTH (t1));
   18919              : 
   18920            0 :     case FIXED_CST:
   18921            0 :       return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1),
   18922              :                                      TREE_FIXED_CST (t2));
   18923              : 
   18924            0 :     case COMPLEX_CST:
   18925            0 :       return c_tree_equal (TREE_REALPART (t1), TREE_REALPART (t2))
   18926            0 :              && c_tree_equal (TREE_IMAGPART (t1), TREE_IMAGPART (t2));
   18927              : 
   18928            0 :     case VECTOR_CST:
   18929            0 :       return operand_equal_p (t1, t2, OEP_ONLY_CONST);
   18930              : 
   18931            0 :     case CONSTRUCTOR:
   18932              :       /* We need to do this when determining whether or not two
   18933              :          non-type pointer to member function template arguments
   18934              :          are the same.  */
   18935            0 :       if (!comptypes (TREE_TYPE (t1), TREE_TYPE (t2))
   18936            0 :           || CONSTRUCTOR_NELTS (t1) != CONSTRUCTOR_NELTS (t2))
   18937              :         return false;
   18938              :       {
   18939              :         tree field, value;
   18940              :         unsigned int i;
   18941            0 :         FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t1), i, field, value)
   18942              :           {
   18943            0 :             constructor_elt *elt2 = CONSTRUCTOR_ELT (t2, i);
   18944            0 :             if (!c_tree_equal (field, elt2->index)
   18945            0 :                 || !c_tree_equal (value, elt2->value))
   18946              :               return false;
   18947              :           }
   18948              :       }
   18949              :       return true;
   18950              : 
   18951            0 :     case TREE_LIST:
   18952            0 :       if (!c_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)))
   18953              :         return false;
   18954            0 :       if (!c_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2)))
   18955              :         return false;
   18956            0 :       return c_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2));
   18957              : 
   18958            0 :     case SAVE_EXPR:
   18959            0 :       return c_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
   18960              : 
   18961           25 :     case CALL_EXPR:
   18962           25 :       {
   18963           25 :         tree arg1, arg2;
   18964           25 :         call_expr_arg_iterator iter1, iter2;
   18965           25 :         if (!c_tree_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2)))
   18966              :           return false;
   18967           50 :         for (arg1 = first_call_expr_arg (t1, &iter1),
   18968           25 :                arg2 = first_call_expr_arg (t2, &iter2);
   18969           25 :              arg1 && arg2;
   18970            0 :              arg1 = next_call_expr_arg (&iter1),
   18971            0 :                arg2 = next_call_expr_arg (&iter2))
   18972            0 :           if (!c_tree_equal (arg1, arg2))
   18973              :             return false;
   18974           25 :         if (arg1 || arg2)
   18975            0 :           return false;
   18976              :         return true;
   18977              :       }
   18978              : 
   18979            0 :     case TARGET_EXPR:
   18980            0 :       {
   18981            0 :         tree o1 = TREE_OPERAND (t1, 0);
   18982            0 :         tree o2 = TREE_OPERAND (t2, 0);
   18983              : 
   18984              :         /* Special case: if either target is an unallocated VAR_DECL,
   18985              :            it means that it's going to be unified with whatever the
   18986              :            TARGET_EXPR is really supposed to initialize, so treat it
   18987              :            as being equivalent to anything.  */
   18988            0 :         if (VAR_P (o1) && DECL_NAME (o1) == NULL_TREE
   18989            0 :             && !DECL_RTL_SET_P (o1))
   18990              :           /*Nop*/;
   18991            0 :         else if (VAR_P (o2) && DECL_NAME (o2) == NULL_TREE
   18992            0 :                  && !DECL_RTL_SET_P (o2))
   18993              :           /*Nop*/;
   18994            0 :         else if (!c_tree_equal (o1, o2))
   18995              :           return false;
   18996              : 
   18997            0 :         return c_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
   18998              :       }
   18999              : 
   19000           29 :     case COMPONENT_REF:
   19001           29 :       if (TREE_OPERAND (t1, 1) != TREE_OPERAND (t2, 1))
   19002              :         return false;
   19003           29 :       return c_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
   19004              : 
   19005              :     case PARM_DECL:
   19006              :     case VAR_DECL:
   19007              :     case CONST_DECL:
   19008              :     case FIELD_DECL:
   19009              :     case FUNCTION_DECL:
   19010              :     case IDENTIFIER_NODE:
   19011              :     case SSA_NAME:
   19012              :       return false;
   19013              : 
   19014            0 :     case TREE_VEC:
   19015            0 :       {
   19016            0 :         unsigned ix;
   19017            0 :         if (TREE_VEC_LENGTH (t1) != TREE_VEC_LENGTH (t2))
   19018              :           return false;
   19019            0 :         for (ix = TREE_VEC_LENGTH (t1); ix--;)
   19020            0 :           if (!c_tree_equal (TREE_VEC_ELT (t1, ix),
   19021            0 :                              TREE_VEC_ELT (t2, ix)))
   19022              :             return false;
   19023              :         return true;
   19024              :       }
   19025              : 
   19026           22 :     CASE_CONVERT:
   19027           22 :       if (!comptypes (TREE_TYPE (t1), TREE_TYPE (t2)))
   19028              :         return false;
   19029              :       break;
   19030              : 
   19031              :     default:
   19032              :       break;
   19033              :     }
   19034              : 
   19035          131 :   switch (TREE_CODE_CLASS (code1))
   19036              :     {
   19037          131 :     case tcc_unary:
   19038          131 :     case tcc_binary:
   19039          131 :     case tcc_comparison:
   19040          131 :     case tcc_expression:
   19041          131 :     case tcc_vl_exp:
   19042          131 :     case tcc_reference:
   19043          131 :     case tcc_statement:
   19044          131 :       {
   19045          131 :         int i, n = TREE_OPERAND_LENGTH (t1);
   19046              : 
   19047          131 :         switch (code1)
   19048              :           {
   19049            0 :           case PREINCREMENT_EXPR:
   19050            0 :           case PREDECREMENT_EXPR:
   19051            0 :           case POSTINCREMENT_EXPR:
   19052            0 :           case POSTDECREMENT_EXPR:
   19053            0 :             n = 1;
   19054            0 :             break;
   19055           16 :           case ARRAY_REF:
   19056           16 :             n = 2;
   19057           16 :             break;
   19058              :           default:
   19059              :             break;
   19060              :           }
   19061              : 
   19062          131 :         if (TREE_CODE_CLASS (code1) == tcc_vl_exp
   19063          131 :             && n != TREE_OPERAND_LENGTH (t2))
   19064              :           return false;
   19065              : 
   19066          305 :         for (i = 0; i < n; ++i)
   19067          186 :           if (!c_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i)))
   19068              :             return false;
   19069              : 
   19070              :         return true;
   19071              :       }
   19072              : 
   19073            0 :     case tcc_type:
   19074            0 :       return comptypes (t1, t2);
   19075            0 :     default:
   19076            0 :       gcc_unreachable ();
   19077              :     }
   19078              : }
   19079              : 
   19080              : /* Returns true when the function declaration FNDECL is implicit,
   19081              :    introduced as a result of a call to an otherwise undeclared
   19082              :    function, and false otherwise.  */
   19083              : 
   19084              : bool
   19085         2013 : c_decl_implicit (const_tree fndecl)
   19086              : {
   19087         2013 :   return C_DECL_IMPLICIT (fndecl);
   19088              : }
        

Generated by: LCOV version 2.5.0-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.