LCOV - code coverage report
Current view: top level - gcc/c - c-typeck.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 93.7 % 9220 8642
Test Date: 2026-11-14 16:39:50 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    194386865 : 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    194386865 :   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    194386865 :   if (expr == nullptr_node)
     160              :     return true;
     161              : 
     162    194386163 :   return (TREE_CODE (expr) == INTEGER_CST
     163     19642050 :           && !TREE_OVERFLOW (expr)
     164     19641953 :           && integer_zerop (expr)
     165    198372619 :           && (INTEGRAL_TYPE_P (type)
     166       339893 :               || (TREE_CODE (type) == POINTER_TYPE
     167       339891 :                   && VOID_TYPE_P (TREE_TYPE (type))
     168       264498 :                   && 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     35905676 : remove_c_maybe_const_expr (tree expr)
     200              : {
     201     35905676 :   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    801467065 : require_complete_type (location_t loc, tree value)
     221              : {
     222    801467065 :   tree type = TREE_TYPE (value);
     223              : 
     224    801467065 :   if (error_operand_p (value))
     225         9027 :     return error_mark_node;
     226              : 
     227              :   /* First, detect a valid value with a complete type.  */
     228    801458038 :   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    128824759 : c_type_promotes_to (tree type)
     296              : {
     297    128824759 :   tree ret = NULL_TREE;
     298              : 
     299    128824759 :   if (TYPE_MAIN_VARIANT (type) == float_type_node)
     300      1642906 :     ret = double_type_node;
     301    127181853 :   else if (c_promoting_integer_type_p (type))
     302              :     {
     303              :       /* Preserve unsignedness if not really getting any wider.  */
     304     19279052 :       if (TYPE_UNSIGNED (type)
     305     19279052 :           && (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)))
     306            0 :         ret = unsigned_type_node;
     307              :       else
     308     19279052 :         ret = integer_type_node;
     309              :     }
     310              : 
     311     20921958 :   if (ret != NULL_TREE)
     312     20921958 :     return (TYPE_ATOMIC (type)
     313     20921958 :             ? 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      7736095 : addr_space_superset (addr_space_t as1, addr_space_t as2, addr_space_t *common)
     325              : {
     326      7736095 :   if (as1 == as2)
     327              :     {
     328      7736095 :       *common = as1;
     329      7736095 :       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      2912931 : qualify_type (tree type, tree like)
     350              : {
     351      2912931 :   addr_space_t as_type = TYPE_ADDR_SPACE (type);
     352      2912931 :   addr_space_t as_like = TYPE_ADDR_SPACE (like);
     353      2912931 :   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      2912931 :   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     11651724 :   return c_build_qualified_type (type,
     365      2912931 :                                  {TYPE_QUALS_NO_ADDR_SPACE (type)
     366      2912931 :                                   | TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (like),
     367      2912931 :                                   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    145820986 : c_verify_type (tree type)
     379              : {
     380    145820986 :   switch (TREE_CODE (type))
     381              :     {
     382     69803883 :     case POINTER_TYPE:
     383     69803883 :     case FUNCTION_TYPE:
     384     69803883 :     case ARRAY_TYPE:
     385              :       /* Pointer, array, functions are variably modified if and only if the
     386              :          target, element, return type is variably modified.  */
     387     69803883 :       if (!TYPE_STRUCTURAL_EQUALITY_P (type)
     388     69803883 :           && (C_TYPE_VARIABLY_MODIFIED (type)
     389     69416076 :               != C_TYPE_VARIABLY_MODIFIED (TREE_TYPE (type))))
     390              :         return false;
     391              :       /* If the target type is structural equality, the type should also. */
     392     69803883 :       if (!TYPE_STRUCTURAL_EQUALITY_P (type)
     393     69803883 :           && TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (type)))
     394              :         return false;
     395    145820986 :     default:
     396    145820986 :        break;
     397              :     }
     398              : 
     399    145820986 :   switch (TREE_CODE (type))
     400              :     {
     401     68881184 :     case POINTER_TYPE:
     402     68881184 :     case FUNCTION_TYPE:
     403              :       /* Pointer and functions can not have variable size.  */
     404     68881184 :       if (C_TYPE_VARIABLE_SIZE (type))
     405            0 :         return false;
     406              :       break;
     407       922699 :     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       922699 :       if ((C_TYPE_VARIABLE_SIZE (TREE_TYPE (type))
     411       922699 :            || top_array_vla_p (type))
     412       922699 :           != 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       922699 :       if (C_TYPE_VARIABLE_SIZE (TREE_TYPE (type))
     417       922699 :           || C_TYPE_VARIABLE_SIZE (type))
     418              :         {
     419        27705 :           if (!C_TYPE_VARIABLE_SIZE (type))
     420              :             return false;
     421        27705 :           if (!C_TYPE_VARIABLY_MODIFIED (type))
     422              :             return false;
     423              :         }
     424              : 
     425              :       /* va_list violates this, accept such types here.  */
     426       922699 :       if (!COMPLETE_TYPE_P (TREE_TYPE (type)))
     427              :         return true;
     428              : 
     429       922693 :       if (COMPLETE_TYPE_P (type))
     430              :         {
     431              :           /* If the size is unknown, it can not be complete.  */
     432       914434 :           if (NULL_TREE == TYPE_DOMAIN (type))
     433              :             return false;
     434              : 
     435              :           /* Zero-length arrays must have size zero.  */
     436       914434 :           if (zero_length_array_type_p (type)
     437       914434 :               && !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         8259 :           if (NULL_TREE != TYPE_DOMAIN (type)
     444         8259 :               && !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    138540354 : c_set_type_bits (tree new_type, tree old_type)
     458              : {
     459    138540354 :   gcc_checking_assert (c_verify_type (old_type));
     460              : 
     461    138540354 :   if (c_type_variably_modified_p (old_type))
     462        28355 :     C_TYPE_VARIABLY_MODIFIED (new_type) = true;
     463              : 
     464    138540354 :   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    138540354 :   return new_type;
     470              : }
     471              : 
     472              : /* Build a pointer type using the default pointer mode.  */
     473              : 
     474              : tree
     475     74091759 : c_build_pointer_type (tree to_type)
     476              : {
     477     74091759 :   addr_space_t as = to_type == error_mark_node ? ADDR_SPACE_GENERIC
     478     74091759 :                                                : TYPE_ADDR_SPACE (to_type);
     479     74091759 :   machine_mode pointer_mode;
     480              : 
     481     74091759 :   if (as != ADDR_SPACE_GENERIC || c_default_pointer_mode == VOIDmode)
     482     74091759 :     pointer_mode = targetm.addr_space.pointer_mode (as);
     483              :   else
     484              :     pointer_mode = c_default_pointer_mode;
     485              : 
     486     74091759 :   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     74342403 : c_build_pointer_type_for_mode (tree type, machine_mode mode, bool m)
     493              : {
     494     74342403 :   tree ret = build_pointer_type_for_mode (type, mode, m);
     495     74342403 :   return c_set_type_bits (ret, type);
     496              : }
     497              : 
     498              : /* Build a function type.  */
     499              : 
     500              : tree
     501     55451813 : c_build_function_type (tree type, tree args, bool no)
     502              : {
     503     55451813 :   tree ret = build_function_type (type, args, no);
     504     55451813 :   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      1170468 : c_build_array_type (tree type, tree domain)
     513              : {
     514      1170468 :   auto type_quals = TYPE_QUALS (type);
     515              : 
     516              :   /* Identify typeless storage as introduced in C2Y
     517              :      and supported also in earlier language modes.  */
     518      1738894 :   bool typeless = (char_type_p (type) && !(type_quals.has (TYPE_QUAL_ATOMIC)))
     519      1170468 :                   || (AGGREGATE_TYPE_P (type) && TYPE_TYPELESS_STORAGE (type));
     520              : 
     521      1170468 :   tree ret = build_array_type (type, domain, typeless);
     522              : 
     523      1170468 :   if (top_array_vla_p (ret))
     524              :     {
     525        24284 :       C_TYPE_VARIABLE_SIZE (ret) = 1;
     526        24284 :       C_TYPE_VARIABLY_MODIFIED (ret) = 1;
     527              :     }
     528              : 
     529      1170468 :   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         2613 : 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         2613 :   type = c_build_array_type (type, build_index_type (NULL_TREE));
     549         2613 :   type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
     550         2613 :   TYPE_SIZE (type) = bitsize_zero_node;
     551         2613 :   TYPE_SIZE_UNIT (type) = size_zero_node;
     552         2613 :   SET_TYPE_STRUCTURAL_EQUALITY (type);
     553         2613 :   return type;
     554              : }
     555              : 
     556              : tree
     557      7575670 : c_build_type_attribute_qual_variant (tree type, tree attrs, qualifier_set quals)
     558              : {
     559      7575670 :   tree ret = build_type_attribute_qual_variant (type, attrs, quals);
     560      7575670 :   return c_set_type_bits (ret, type);
     561              : }
     562              : 
     563              : tree
     564      7384590 : c_build_type_attribute_variant (tree type, tree attrs)
     565              : {
     566      7384590 :   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       849624 : c_reconstruct_complex_type (tree type, tree bottom)
     574              : {
     575       849624 :   tree inner, outer;
     576              : 
     577       849624 :   if (TREE_CODE (type) == POINTER_TYPE)
     578              :     {
     579       176713 :       inner = c_reconstruct_complex_type (TREE_TYPE (type), bottom);
     580       176713 :       outer = c_build_pointer_type_for_mode (inner, TYPE_MODE (type),
     581       176713 :                                              TYPE_REF_CAN_ALIAS_ALL (type));
     582              :     }
     583              :   else if (TREE_CODE (type) == ARRAY_TYPE)
     584              :     {
     585         7389 :       bool rso = TYPE_REVERSE_STORAGE_ORDER (type);
     586         7389 :       inner = c_reconstruct_complex_type (TREE_TYPE (type), bottom);
     587         7389 :       outer = c_build_array_type (inner, TYPE_DOMAIN (type));
     588         7389 :       if (rso)
     589              :         {
     590            1 :           outer = build_distinct_type_copy (outer);
     591            1 :           TYPE_REVERSE_STORAGE_ORDER (outer) = 1;
     592              :         }
     593              : 
     594         7389 :       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       184704 :   return c_build_type_attribute_qual_variant (outer, TYPE_ATTRIBUTES (type),
     610       184704 :                                               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      3479340 : ptr_to_tagged_member (tree field)
     620              : {
     621      3479340 :   gcc_assert (FIELD_DECL == TREE_CODE (field));
     622      3479340 :   tree type = TREE_TYPE (field);
     623      3479340 :   bool ptr_seen = false;
     624      3479340 :   while (TREE_CODE (type) == ARRAY_TYPE
     625              :          || TREE_CODE (type) == FUNCTION_TYPE
     626      4768558 :          || TREE_CODE (type) == POINTER_TYPE)
     627              :     {
     628      1289218 :       if (TREE_CODE (type) == POINTER_TYPE)
     629       706163 :         ptr_seen = true;
     630      1289218 :       type = TREE_TYPE (type);
     631              :     }
     632              : 
     633      3479340 :   if (ptr_seen
     634       685853 :       && RECORD_OR_UNION_TYPE_P (type)
     635      3730977 :       && NULL_TREE != c_type_tag (type))
     636       247294 :     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       897170 : c_type_canonical (tree type)
     653              : {
     654       897170 :   gcc_assert (RECORD_OR_UNION_TYPE_P (type));
     655              : 
     656       897170 :   bool needs_mod = false;
     657      3673981 :   for (tree x = TYPE_FIELDS (type); x; x = DECL_CHAIN (x))
     658              :     {
     659      2859751 :       if (!ptr_to_tagged_member (x))
     660      2776811 :         continue;
     661              :       needs_mod = true;
     662              :       break;
     663              :     }
     664       897170 :   if (!needs_mod)
     665              :     return type;
     666              : 
     667              :   /* Construct new version with such members replaced.  */
     668        82940 :   tree n = build_distinct_type_copy (type);
     669        82940 :   tree *fields = &TYPE_FIELDS (n);
     670       702529 :   for (tree x = TYPE_FIELDS (type); x; x = DECL_CHAIN (x))
     671              :     {
     672       619589 :       tree f = copy_node (x);
     673       619589 :       if (tree m = ptr_to_tagged_member (x))
     674              :         {
     675       164354 :           tree new_node = make_node (TREE_CODE (m));
     676       164354 :           TYPE_NAME (new_node) = TYPE_NAME (m);
     677       164354 :           SET_TYPE_STRUCTURAL_EQUALITY (new_node);
     678       164354 :           new_node = qualify_type (new_node, m);
     679       164354 :           TREE_TYPE (f) = c_reconstruct_complex_type (TREE_TYPE (x),
     680              :                                                       new_node);
     681              :         }
     682       619589 :       *fields = f;
     683       619589 :       fields = &DECL_CHAIN (f);
     684              :     }
     685        82940 :   TYPE_CANONICAL (n) = n;
     686        82940 :   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        10789 : c_build_functype_attribute_variant (tree ntype, tree otype, tree attrs)
     698              : {
     699        10789 :   if (!prototype_p (otype)
     700        10777 :       && prototype_p (ntype)
     701        21536 :       && 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        10789 :   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     62853906 : 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     62853906 :   while (TYPE_NAME (t)
     721     32260026 :          && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL
     722     62898850 :          && DECL_ORIGINAL_TYPE (TYPE_NAME (t)))
     723        22470 :     t = DECL_ORIGINAL_TYPE (TYPE_NAME (t));
     724     62853906 :   return t;
     725              : }
     726              : 
     727              : /* Return the tag for a tagged type.  */
     728              : tree
     729     62853906 : c_type_tag (const_tree t)
     730              : {
     731     62853906 :   gcc_assert (RECORD_OR_UNION_TYPE_P (t) || TREE_CODE (t) == ENUMERAL_TYPE);
     732     62853906 :   const_tree orig = c_type_original (t);
     733     62853906 :   tree name = TYPE_NAME (orig);
     734     62853906 :   if (!name)
     735              :     return NULL_TREE;
     736     32237556 :   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     32237554 :   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     66285035 : remove_qualifiers (tree t)
     750              : {
     751     66285035 :   if (!t || t == error_mark_node)
     752              :     return t;
     753     66285010 :   return TYPE_ATOMIC (strip_array_types (t))
     754    132554437 :          ? c_build_qualified_type (TYPE_MAIN_VARIANT (t), TYPE_QUAL_ATOMIC)
     755     66269427 :          : 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      8734002 : transparent_union_replacement (tree u, tree t)
     764              : {
     765      8733997 :   if (u == error_mark_node || t == error_mark_node
     766      8733992 :       || TREE_CODE (u) != UNION_TYPE
     767           64 :       || !(TYPE_TRANSPARENT_AGGR (u) || TYPE_NAME (u) == NULL_TREE)
     768      8734066 :       || 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     13779270 : composite_type_internal (tree t1, tree t2, tree cond,
     802              :                          struct composite_cache* cache)
     803              : {
     804     13779270 :   enum tree_code code1;
     805     13779270 :   enum tree_code code2;
     806     13779270 :   tree attributes;
     807              : 
     808              :   /* Save time if the two types are the same.  */
     809              : 
     810     13779270 :   if (t1 == t2) return t1;
     811              : 
     812              :   /* If one type is nonsense, use the other.  */
     813      2791036 :   if (t1 == error_mark_node)
     814              :     return t2;
     815      2791032 :   if (t2 == error_mark_node)
     816              :     return t1;
     817              : 
     818      2791030 :   code1 = TREE_CODE (t1);
     819      2791030 :   code2 = TREE_CODE (t2);
     820              : 
     821              :   /* Merge the attributes.  */
     822      2791030 :   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      2791030 :   if (code1 == ENUMERAL_TYPE
     830          195 :       && (code2 == INTEGER_TYPE
     831          195 :           || code2 == BOOLEAN_TYPE))
     832              :     return t1;
     833      2790835 :   if (code2 == ENUMERAL_TYPE
     834           69 :       && (code1 == INTEGER_TYPE
     835           69 :           || code1 == BOOLEAN_TYPE))
     836              :     return t2;
     837              : 
     838      2790766 :   gcc_assert (code1 == code2);
     839              : 
     840      2790766 :   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         6376 :         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 :         auto 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      2724001 :     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      2724001 :       {
    1044      2724001 :         tree valtype = composite_type_internal (TREE_TYPE (t1), TREE_TYPE (t2),
    1045              :                                                 cond, cache);
    1046      2724001 :         tree p1 = TYPE_ARG_TYPES (t1);
    1047      2724001 :         tree p2 = TYPE_ARG_TYPES (t2);
    1048              : 
    1049              :         /* Save space: see if the result is identical to one of the args.  */
    1050      2724001 :         if (valtype == TREE_TYPE (t1) && !TYPE_ARG_TYPES (t2))
    1051        10799 :           return c_build_functype_attribute_variant (t1, t2, attributes);
    1052      2713737 :         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      2713212 :         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      2713203 :         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      2713202 :         tree newargs = NULL_TREE;
    1074      2713202 :         tree *endp = &newargs;
    1075              : 
    1076      7080203 :         for (; p1; p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2))
    1077              :           {
    1078      6911446 :             if (p1 == void_list_node)
    1079              :               {
    1080      2544445 :                 *endp = void_list_node;
    1081      2544445 :                 break;
    1082              :               }
    1083      4367001 :             tree mv1 = remove_qualifiers (TREE_VALUE (p1));
    1084      4367001 :             tree mv2 = remove_qualifiers (TREE_VALUE (p2));
    1085              : 
    1086      4367001 :             gcc_assert (mv1);
    1087      4367001 :             gcc_assert (mv2);
    1088              : 
    1089      4367001 :             mv1 = transparent_union_replacement (mv1, mv2);
    1090      4367001 :             mv2 = transparent_union_replacement (mv2, mv1);
    1091              : 
    1092      4367001 :             *endp = tree_cons (NULL_TREE,
    1093              :                                composite_type_internal (mv1, mv2, cond, cache),
    1094              :                                NULL_TREE);
    1095              : 
    1096      4367001 :             endp = &TREE_CHAIN (*endp);
    1097              :           }
    1098              : 
    1099      2713202 :         t1 = c_build_function_type (valtype, newargs);
    1100      2713202 :         t1 = qualify_type (t1, t2);
    1101              :       }
    1102              :       /* FALLTHRU */
    1103              : 
    1104      2762342 :     default:
    1105      2762342 :       return c_build_type_attribute_variant (t1, attributes);
    1106              :     }
    1107              : }
    1108              : 
    1109              : tree
    1110      6670705 : composite_type_cond (tree t1, tree t2, tree cond)
    1111              : {
    1112      6670705 :   gcc_checking_assert (comptypes_check_for_composite (t1, t2));
    1113              : 
    1114      6670705 :   struct composite_cache cache = { };
    1115      6670705 :   tree n = composite_type_internal (t1, t2, cond, &cache);
    1116              : 
    1117      6670705 :   gcc_checking_assert (comptypes_check_for_composite (n, t1));
    1118      6670705 :   gcc_checking_assert (comptypes_check_for_composite (n, t2));
    1119      6670705 :   return n;
    1120              : }
    1121              : 
    1122              : 
    1123              : tree
    1124      6666221 : composite_type (tree t1, tree t2)
    1125              : {
    1126      6666221 :   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       116937 : common_pointer_type (tree t1, tree t2, tree cond)
    1137              : {
    1138       116937 :   tree attributes;
    1139       116937 :   qualifier_set target_quals;
    1140       116937 :   addr_space_t as1, as2, as_common;
    1141       116937 :   cv_qualifier quals1, quals2;
    1142              : 
    1143              :   /* Save time if the two types are the same.  */
    1144              : 
    1145       116937 :   if (t1 == t2) return t1;
    1146              : 
    1147              :   /* If one type is nonsense, use the other.  */
    1148         4484 :   if (t1 == error_mark_node)
    1149              :     return t2;
    1150         4484 :   if (t2 == error_mark_node)
    1151              :     return t1;
    1152              : 
    1153         4484 :   gcc_assert (TREE_CODE (t1) == POINTER_TYPE
    1154              :               && TREE_CODE (t2) == POINTER_TYPE);
    1155              : 
    1156              :   /* Merge the attributes.  */
    1157         4484 :   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         4484 :   tree pointed_to_1 = TREE_TYPE (t1);
    1162         4484 :   tree pointed_to_2 = TREE_TYPE (t2);
    1163         4484 :   tree target = composite_type_cond (TYPE_MAIN_VARIANT (pointed_to_1),
    1164         4484 :                                      TYPE_MAIN_VARIANT (pointed_to_2), cond);
    1165              : 
    1166              :   /* Strip array types to get correct qualifier for pointers to arrays */
    1167         4484 :   quals1 = TYPE_QUALS_NO_ADDR_SPACE (strip_array_types (pointed_to_1));
    1168         4484 :   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         4484 :   if (TREE_CODE (pointed_to_1) == FUNCTION_TYPE)
    1174         2136 :     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         4484 :   as1 = TYPE_ADDR_SPACE (pointed_to_1);
    1182         4484 :   as2 = TYPE_ADDR_SPACE (pointed_to_2);
    1183         4484 :   if (!addr_space_superset (as1, as2, &as_common))
    1184            0 :     gcc_unreachable ();
    1185              : 
    1186         4484 :   target_quals.set_as (as_common);
    1187              : 
    1188         4484 :   t1 = c_build_pointer_type (c_build_qualified_type (target, target_quals));
    1189         4484 :   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     14741991 : c_common_type (tree t1, tree t2)
    1202              : {
    1203     14741991 :   enum tree_code code1;
    1204     14741991 :   enum tree_code code2;
    1205              : 
    1206              :   /* If one type is nonsense, use the other.  */
    1207     14741991 :   if (t1 == error_mark_node)
    1208              :     return t2;
    1209     14741991 :   if (t2 == error_mark_node)
    1210              :     return t1;
    1211              : 
    1212     14741991 :   if (TYPE_QUALS (t1) != TYPE_UNQUALIFIED)
    1213        38173 :     t1 = TYPE_MAIN_VARIANT (t1);
    1214              : 
    1215     14741991 :   if (TYPE_QUALS (t2) != TYPE_UNQUALIFIED)
    1216        49624 :     t2 = TYPE_MAIN_VARIANT (t2);
    1217              : 
    1218     14741991 :   if (TYPE_ATTRIBUTES (t1) != NULL_TREE)
    1219              :     {
    1220       190170 :       tree attrs = affects_type_identity_attributes (TYPE_ATTRIBUTES (t1));
    1221       190170 :       t1 = c_build_type_attribute_variant (t1, attrs);
    1222              :     }
    1223              : 
    1224     14741991 :   if (TYPE_ATTRIBUTES (t2) != NULL_TREE)
    1225              :     {
    1226       189648 :       tree attrs = affects_type_identity_attributes (TYPE_ATTRIBUTES (t2));
    1227       189648 :       t2 = c_build_type_attribute_variant (t2, attrs);
    1228              :     }
    1229              : 
    1230              :   /* Save time if the two types are the same.  */
    1231              : 
    1232     14741991 :   if (t1 == t2) return t1;
    1233              : 
    1234      2414579 :   code1 = TREE_CODE (t1);
    1235      2414579 :   code2 = TREE_CODE (t2);
    1236              : 
    1237      2414579 :   gcc_assert (code1 == VECTOR_TYPE || code1 == COMPLEX_TYPE
    1238              :               || code1 == FIXED_POINT_TYPE || code1 == REAL_TYPE
    1239              :               || code1 == INTEGER_TYPE || code1 == BITINT_TYPE);
    1240      2414579 :   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      2414579 :   if ((DECIMAL_FLOAT_TYPE_P (t1) || DECIMAL_FLOAT_TYPE_P (t2))
    1248      2417002 :       && !(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      2414555 :   if (code1 == VECTOR_TYPE)
    1272              :     return t1;
    1273              : 
    1274      2414263 :   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      2414260 :   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      2324895 :   if (code1 == REAL_TYPE && code2 != REAL_TYPE)
    1303              :     return t1;
    1304              : 
    1305      2195561 :   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      2164152 :   if (code1 == REAL_TYPE && code2 == REAL_TYPE)
    1312              :     {
    1313       107833 :       if (TYPE_MAIN_VARIANT (t1) == dfloat128_type_node
    1314       107833 :           || 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       107284 :       else if (TYPE_MAIN_VARIANT (t1) == dfloat64x_type_node
    1319       107284 :                || TYPE_MAIN_VARIANT (t2) == dfloat64x_type_node)
    1320              :         return dfloat64x_type_node;
    1321       107280 :       else if (TYPE_MAIN_VARIANT (t1) == dfloat64_type_node
    1322       107280 :                || TYPE_MAIN_VARIANT (t2) == dfloat64_type_node)
    1323              :         return dfloat64_type_node;
    1324       106835 :       else if (TYPE_MAIN_VARIANT (t1) == dfloat32_type_node
    1325       106835 :                || TYPE_MAIN_VARIANT (t2) == dfloat32_type_node)
    1326              :         return dfloat32_type_node;
    1327              :     }
    1328              : 
    1329              :   /* Deal with fixed-point types.  */
    1330      2162809 :   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      2162809 :   if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2))
    1419              :     return t1;
    1420      1183882 :   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       816310 :   if (TYPE_MAIN_VARIANT (t1) == long_long_unsigned_type_node
    1428       816310 :       || TYPE_MAIN_VARIANT (t2) == long_long_unsigned_type_node)
    1429              :     return long_long_unsigned_type_node;
    1430              : 
    1431       726633 :   if (TYPE_MAIN_VARIANT (t1) == long_long_integer_type_node
    1432       726633 :       || TYPE_MAIN_VARIANT (t2) == long_long_integer_type_node)
    1433              :     {
    1434        15352 :       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       711281 :   if (TYPE_MAIN_VARIANT (t1) == long_unsigned_type_node
    1441       711281 :       || TYPE_MAIN_VARIANT (t2) == long_unsigned_type_node)
    1442              :     return long_unsigned_type_node;
    1443              : 
    1444       611676 :   if (TYPE_MAIN_VARIANT (t1) == long_integer_type_node
    1445       611676 :       || 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        26705 :       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       584971 :   tree mv1 = TYPE_MAIN_VARIANT (t1);
    1467       584971 :   tree mv2 = TYPE_MAIN_VARIANT (t2);
    1468              : 
    1469      2924206 :   for (int i = NUM_FLOATN_TYPES - 1; i >= 0; i--)
    1470      2339419 :     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       584787 :   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       584529 :   if (mv1 == double_type_node || mv2 == double_type_node)
    1481              :     return double_type_node;
    1482              : 
    1483       583957 :   if (mv1 == float_type_node || mv2 == float_type_node)
    1484              :     return float_type_node;
    1485              : 
    1486      2327088 :   for (int i = NUM_FLOATNX_TYPES - 1; i >= 0; i--)
    1487      1745316 :     if (mv1 == FLOATNX_TYPE_NODE (i) || mv2 == FLOATNX_TYPE_NODE (i))
    1488              :       return FLOATNX_TYPE_NODE (i);
    1489              : 
    1490       581772 :   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       581741 :   if (TYPE_UNSIGNED (t1))
    1507              :     return t1;
    1508              :   else
    1509       270104 :     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       104545 : common_type (tree t1, tree t2)
    1519              : {
    1520       104545 :   if (TREE_CODE (t1) == ENUMERAL_TYPE)
    1521            0 :     t1 = ENUM_UNDERLYING_TYPE (t1);
    1522       104545 :   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       104545 :   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       103961 :   if (TREE_CODE (t1) == BOOLEAN_TYPE)
    1532              :     return t2;
    1533       103961 :   if (TREE_CODE (t2) == BOOLEAN_TYPE)
    1534              :     return t1;
    1535              : 
    1536       103961 :   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     43663615 : comptypes_verify (tree type1, tree type2)
    1547              : {
    1548     43663615 :   if (type1 == type2 || !type1 || !type2
    1549      3640317 :       || TREE_CODE (type1) == ERROR_MARK || TREE_CODE (type2) == ERROR_MARK)
    1550              :     return true;
    1551              : 
    1552      3640316 :   gcc_checking_assert (c_verify_type (type1));
    1553      3640316 :   gcc_checking_assert (c_verify_type (type2));
    1554              : 
    1555      3640316 :   if (TYPE_CANONICAL (type1) != TYPE_CANONICAL (type2)
    1556       403324 :       && !TYPE_STRUCTURAL_EQUALITY_P (type1)
    1557      4042131 :       && !TYPE_STRUCTURAL_EQUALITY_P (type2))
    1558              :     {
    1559              :       /* FIXME: check other types. */
    1560       401504 :       if (RECORD_OR_UNION_TYPE_P (type1)
    1561       401504 :           || TREE_CODE (type1) == ENUMERAL_TYPE
    1562       401504 :           || 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     20012115 : comptypes_check_for_composite (tree t1, tree t2)
    1595              : {
    1596     20012115 :   struct comptypes_data data = { };
    1597     20012115 :   data.ignore_promoting_args = FUNCTION_TYPE == TREE_CODE (t1);
    1598     20012115 :   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     57190984 : comptypes (tree type1, tree type2)
    1615              : {
    1616     57190984 :   struct comptypes_data data = { };
    1617     57190984 :   bool ret = comptypes_internal (type1, type2, &data);
    1618              : 
    1619     57190984 :   gcc_checking_assert (!ret || comptypes_verify (type1, type2));
    1620              : 
    1621     57190984 :   return ret;
    1622              : }
    1623              : 
    1624              : 
    1625              : /* Like comptypes, but it returns non-zero only for identical
    1626              :    types.  */
    1627              : 
    1628              : bool
    1629        46938 : comptypes_same_p (tree type1, tree type2)
    1630              : {
    1631        46938 :   struct comptypes_data data = { };
    1632        46938 :   bool ret = comptypes_internal (type1, type2, &data);
    1633              : 
    1634        46938 :   gcc_checking_assert (!ret || comptypes_verify (type1, type2));
    1635              : 
    1636        46938 :   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      5251063 : comptypes_check_enum_int (tree type1, tree type2, bool *enum_and_int_p)
    1648              : {
    1649      5251063 :   struct comptypes_data data = { };
    1650      5251063 :   bool ret = comptypes_internal (type1, type2, &data);
    1651      5251063 :   *enum_and_int_p = data.enum_and_int_p;
    1652              : 
    1653      5251063 :   gcc_checking_assert (!ret || comptypes_verify (type1, type2));
    1654              : 
    1655      5251063 :   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     14776846 : comptypes_equiv_p (tree type1, tree type2)
    1693              : {
    1694     14776846 :   struct comptypes_data data = { };
    1695     14776846 :   data.equiv = true;
    1696     14776846 :   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     14776846 :   gcc_checking_assert (ret || !comptypes (type1, type2));
    1701              : 
    1702     14776846 :   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    137231044 : comptypes_internal (const_tree type1, const_tree type2,
    1722              :                     struct comptypes_data *data)
    1723              : {
    1724    137516003 :   const_tree t1 = type1;
    1725    137516003 :   const_tree t2 = type2;
    1726              : 
    1727              :   /* Suppress errors caused by previously reported errors.  */
    1728              : 
    1729    137516003 :   if (t1 == t2 || !t1 || !t2
    1730     46006687 :       || TREE_CODE (t1) == ERROR_MARK || TREE_CODE (t2) == ERROR_MARK)
    1731              :     return true;
    1732              : 
    1733              :   /* Qualifiers must match. C99 6.7.3p9 */
    1734              : 
    1735     46006684 :   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     45966346 :   if (TREE_CODE (t1) == ENUMERAL_TYPE
    1743         1017 :       && COMPLETE_TYPE_P (t1)
    1744     45967319 :       && TREE_CODE (t2) != ENUMERAL_TYPE)
    1745              :     {
    1746          845 :       t1 = ENUM_UNDERLYING_TYPE (t1);
    1747          845 :       if (TREE_CODE (t2) != VOID_TYPE)
    1748              :         {
    1749          841 :           data->enum_and_int_p = true;
    1750          841 :           data->different_types_p = true;
    1751              :         }
    1752              :     }
    1753     45965501 :   else if (TREE_CODE (t2) == ENUMERAL_TYPE
    1754         4949 :            && COMPLETE_TYPE_P (t2)
    1755     45970444 :            && TREE_CODE (t1) != ENUMERAL_TYPE)
    1756              :     {
    1757         4815 :       t2 = ENUM_UNDERLYING_TYPE (t2);
    1758         4815 :       if (TREE_CODE (t1) != VOID_TYPE)
    1759              :         {
    1760         3916 :           data->enum_and_int_p = true;
    1761         3916 :           data->different_types_p = true;
    1762              :         }
    1763              :     }
    1764              : 
    1765     45966346 :   if (t1 == t2)
    1766              :     return true;
    1767              : 
    1768              :   /* Different classes of types can't be compatible.  */
    1769              : 
    1770     45964778 :   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     37881015 :   if (TREE_CODE (t1) != ARRAY_TYPE
    1778     37881015 :       && TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
    1779              :     return true;
    1780              : 
    1781     37512049 :   int attrval;
    1782              : 
    1783              :   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
    1784     37512049 :   if (!(attrval = comp_type_attributes (t1, t2)))
    1785              :     return false;
    1786              : 
    1787     37511672 :   if (2 == attrval)
    1788          336 :     data->warning_needed = true;
    1789              : 
    1790     37511672 :   switch (TREE_CODE (t1))
    1791              :     {
    1792      3393045 :     case INTEGER_TYPE:
    1793      3393045 :     case FIXED_POINT_TYPE:
    1794      3393045 :     case REAL_TYPE:
    1795      3393045 :     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      3393045 :       return TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2);
    1811              : 
    1812       284959 :     case POINTER_TYPE:
    1813              :       /* Do not remove mode information.  */
    1814       284959 :       if (TYPE_MODE (t1) != TYPE_MODE (t2))
    1815              :         return false;
    1816       284959 :       data->pointedto = true;
    1817       284959 :       return comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2), data);
    1818              : 
    1819      9478307 :     case FUNCTION_TYPE:
    1820      9478307 :       return function_types_compatible_p (t1, t2, data);
    1821              : 
    1822       155591 :     case ARRAY_TYPE:
    1823       155591 :       {
    1824       155591 :         tree d1 = TYPE_DOMAIN (t1);
    1825       155591 :         tree d2 = TYPE_DOMAIN (t2);
    1826              : 
    1827              :         /* Target types must match incl. qualifiers.  */
    1828       155591 :         if (!comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2), data))
    1829              :           return false;
    1830              : 
    1831       120494 :         if ((d1 == NULL_TREE) != (d2 == NULL_TREE))
    1832         6353 :           data->different_types_p = true;
    1833              :         /* Ignore size mismatches when forming equivalence classes.  */
    1834       120494 :         if (data->equiv)
    1835              :           return true;
    1836              :         /* Sizes must match unless one is missing or variable.  */
    1837        50405 :         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     23657624 :     case ENUMERAL_TYPE:
    1867     23657624 :     case RECORD_TYPE:
    1868     23657624 :     case UNION_TYPE:
    1869              : 
    1870     23657624 :       if (!flag_isoc23)
    1871              :         return false;
    1872              : 
    1873     23657577 :       return tagged_types_tu_compatible_p (t1, t2, data);
    1874              : 
    1875       541341 :     case VECTOR_TYPE:
    1876      1082682 :       return known_eq (TYPE_VECTOR_SUBPARTS (t1), TYPE_VECTOR_SUBPARTS (t2))
    1877       541341 :              && 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      1787396 : comp_target_types (location_t location, tree ttl, tree ttr)
    1892              : {
    1893      1787396 :   tree mvl = TREE_TYPE (ttl);
    1894      1787396 :   tree mvr = TREE_TYPE (ttr);
    1895      1787396 :   addr_space_t asl = TYPE_ADDR_SPACE (mvl);
    1896      1787396 :   addr_space_t asr = TYPE_ADDR_SPACE (mvr);
    1897      1787396 :   addr_space_t as_common;
    1898              : 
    1899              :   /* Fail if pointers point to incompatible address spaces.  */
    1900      1787396 :   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      1787396 :   struct comptypes_data data = { };
    1906      1787396 :   if (!comptypes_internal (remove_qualifiers (mvl),
    1907      1787396 :                            remove_qualifiers (mvr), &data))
    1908              :     return false;
    1909              : 
    1910              :   /* For pedantic use comptypes on arrays before removing
    1911              :      qualifiers on the element type. */
    1912      1685947 :   if (TREE_CODE (mvl) == ARRAY_TYPE
    1913         1891 :       && TREE_CODE (mvr) == ARRAY_TYPE
    1914      1687838 :       && !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      1685947 :   if (data.warning_needed)
    1920          126 :     pedwarn (location, OPT_Wpedantic, "types are not quite compatible");
    1921              : 
    1922      1685947 :   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     23657577 : tagged_types_tu_compatible_p (const_tree t1, const_tree t2,
    1937              :                               struct comptypes_data *data)
    1938              : {
    1939     23657577 :   tree s1, s2;
    1940              : 
    1941     23657577 :   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     19510011 :   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     19509949 :   if (!data->anon_field && !data->equiv && NULL_TREE == c_type_tag (t1))
    1953              :     return false;
    1954              : 
    1955     14317089 :   if (!data->anon_field && TYPE_STUB_DECL (t1) != TYPE_STUB_DECL (t2))
    1956     14316026 :     data->different_types_p = true;
    1957              : 
    1958              :   /* Incomplete types are incompatible inside a TU.  */
    1959     14317089 :   if (TYPE_SIZE (t1) == NULL || TYPE_SIZE (t2) == NULL)
    1960              :     return false;
    1961              : 
    1962     14317079 :   if (ENUMERAL_TYPE != TREE_CODE (t1)
    1963     14317079 :       && (TYPE_REVERSE_STORAGE_ORDER (t1)
    1964     14317022 :           != TYPE_REVERSE_STORAGE_ORDER (t2)))
    1965              :     return false;
    1966              : 
    1967     14317069 :   if (TYPE_USER_ALIGN (t1) != TYPE_USER_ALIGN (t2))
    1968       145419 :     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     14317069 :   for (const struct tagged_tu_seen_cache *t = data->cache;
    1975     14326762 :        t != NULL; t = t->next)
    1976         9988 :     if (t->t1 == t1 && t->t2 == t2)
    1977              :       return true;
    1978              : 
    1979     14316774 :   const struct tagged_tu_seen_cache entry = { data->cache, t1, t2 };
    1980              : 
    1981     14316774 :   switch (TREE_CODE (t1))
    1982              :     {
    1983           57 :     case ENUMERAL_TYPE:
    1984           57 :       {
    1985           57 :         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           53 :         tree tv1 = TYPE_VALUES (t1);
    1990           53 :         tree tv2 = TYPE_VALUES (t2);
    1991              : 
    1992           53 :         if (tv1 == tv2)
    1993              :           return true;
    1994              : 
    1995          103 :         for (;tv1 && tv2; tv1 = TREE_CHAIN (tv1), tv2 = TREE_CHAIN (tv2))
    1996              :           {
    1997           62 :             if (TREE_PURPOSE (tv1) != TREE_PURPOSE (tv2))
    1998              :               break;
    1999              : 
    2000           55 :             if (simple_cst_equal (DECL_INITIAL (TREE_VALUE (tv1)),
    2001           55 :                                   DECL_INITIAL (TREE_VALUE (tv2))) != 1)
    2002              :               break;
    2003              :           }
    2004              : 
    2005           53 :         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     14316717 :     case UNION_TYPE:
    2028     14316717 :     case RECORD_TYPE:
    2029              : 
    2030     14316717 :         if (list_length (TYPE_FIELDS (t1)) != list_length (TYPE_FIELDS (t2)))
    2031              :           return false;
    2032              : 
    2033     12351492 :         for (s1 = TYPE_FIELDS (t1), s2 = TYPE_FIELDS (t2);
    2034     13876166 :              s1 && s2;
    2035      1524674 :              s1 = DECL_CHAIN (s1), s2 = DECL_CHAIN (s2))
    2036              :           {
    2037     13810093 :             gcc_assert (TREE_CODE (s1) == FIELD_DECL);
    2038     13810093 :             gcc_assert (TREE_CODE (s2) == FIELD_DECL);
    2039              : 
    2040     13810093 :             tree ft1 = TREE_TYPE (s1);
    2041     13810093 :             tree ft2 = TREE_TYPE (s2);
    2042              : 
    2043     13810093 :             if (DECL_NAME (s1) != DECL_NAME (s2))
    2044              :               return false;
    2045              : 
    2046     12147471 :             if (DECL_ALIGN (s1) != DECL_ALIGN (s2))
    2047              :               return false;
    2048              : 
    2049      3238669 :             if (DECL_C_BIT_FIELD (s1) != DECL_C_BIT_FIELD (s2))
    2050              :                return false;
    2051              : 
    2052      3238649 :             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      3238453 :             if (!ft1 || !ft2)
    2062              :               return false;
    2063              : 
    2064      3238453 :             if (TREE_CODE (ft1) == ERROR_MARK || TREE_CODE (ft2) == ERROR_MARK)
    2065              :               return false;
    2066              : 
    2067      3238452 :             data->anon_field = !DECL_NAME (s1);
    2068      3238452 :             data->pointedto = false;
    2069              : 
    2070      3238452 :             const struct tagged_tu_seen_cache *cache = data->cache;
    2071      3238452 :             data->cache = &entry;
    2072      3238452 :             bool ret = comptypes_internal (ft1, ft2, data);
    2073      3238452 :             data->cache = cache;
    2074      3238452 :             if (!ret)
    2075              :               return false;
    2076              : 
    2077      1594651 :             tree st1 = TYPE_SIZE (TREE_TYPE (s1));
    2078      1594651 :             tree st2 = TYPE_SIZE (TREE_TYPE (s2));
    2079              : 
    2080      1594651 :             if (data->equiv
    2081      1000367 :                 && st1 && TREE_CODE (st1) == INTEGER_CST
    2082       999885 :                 && st2 && TREE_CODE (st2) == INTEGER_CST
    2083      2594530 :                 && !tree_int_cst_equal (st1, st2))
    2084              :              return false;
    2085              : 
    2086      1524708 :             tree counted_by1 = lookup_attribute ("counted_by",
    2087      1524708 :                                                  DECL_ATTRIBUTES (s1));
    2088      1524708 :             tree counted_by2 = lookup_attribute ("counted_by",
    2089      1524708 :                                                  DECL_ATTRIBUTES (s2));
    2090              :             /* If there is no counted_by attribute for both fields.  */
    2091      1524708 :             if (!counted_by1 && !counted_by2)
    2092      1524644 :               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      9478307 : function_types_compatible_p (const_tree f1, const_tree f2,
    2134              :                              struct comptypes_data *data)
    2135              : {
    2136      9478307 :   tree ret1 = TREE_TYPE (f1);
    2137      9478307 :   tree ret2 = TREE_TYPE (f2);
    2138              : 
    2139              :   /* 'volatile' qualifiers on a function's return type used to mean
    2140              :      the function is noreturn.  */
    2141      9478307 :   if (TYPE_VOLATILE (ret1) != TYPE_VOLATILE (ret2))
    2142           29 :     pedwarn (input_location, 0, "function return types not compatible due to %<volatile%>");
    2143      9478307 :   if (TYPE_VOLATILE (ret1))
    2144           15 :     ret1 = build_qualified_type (TYPE_MAIN_VARIANT (ret1),
    2145           15 :                                  TYPE_QUALS (ret1)
    2146              :                                  .without (TYPE_QUAL_VOLATILE));
    2147      9478307 :   if (TYPE_VOLATILE (ret2))
    2148           18 :     ret2 = build_qualified_type (TYPE_MAIN_VARIANT (ret2),
    2149           18 :                                  TYPE_QUALS (ret2)
    2150              :                                  .without (TYPE_QUAL_VOLATILE));
    2151              : 
    2152      9478307 :   bool ignore_pargs = data->ignore_promoting_args;
    2153      9478307 :   data->ignore_promoting_args = false;
    2154              : 
    2155      9478307 :   if (!comptypes_internal (ret1, ret2, data))
    2156              :     return false;
    2157              : 
    2158      9475718 :   data->ignore_promoting_args = ignore_pargs;
    2159              : 
    2160      9475718 :   tree args1 = TYPE_ARG_TYPES (f1);
    2161      9475718 :   tree args2 = TYPE_ARG_TYPES (f2);
    2162              : 
    2163      9475718 :   if ((args1 == NULL_TREE) != (args2 == NULL_TREE))
    2164        45337 :     data->different_types_p = true;
    2165              : 
    2166              :   /* An unspecified parmlist matches any specified parmlist
    2167              :      whose argument types don't need default promotions.  */
    2168              : 
    2169      9475718 :   if (args1 == NULL_TREE)
    2170              :     {
    2171        23809 :       if (TYPE_NO_NAMED_ARGS_STDARG_P (f1) != TYPE_NO_NAMED_ARGS_STDARG_P (f2))
    2172              :         return false;
    2173        23806 :       if (!(data->ignore_promoting_args || self_promoting_args_p (args2)))
    2174              :         return false;
    2175        23334 :       data->ignore_promoting_args = false;
    2176              :       /* If one of these types comes from a non-prototype fn definition,
    2177              :          compare that with the other type's arglist.
    2178              :          If they don't match, ask for a warning (but no error).  */
    2179        23334 :       if (TYPE_ACTUAL_ARG_TYPES (f1)
    2180        23334 :           && !type_lists_compatible_p (args2, TYPE_ACTUAL_ARG_TYPES (f1), data))
    2181           12 :          data->warning_needed = true;
    2182              :       return true;
    2183              :     }
    2184      9451909 :   if (args2 == NULL_TREE)
    2185              :     {
    2186        21610 :       if (TYPE_NO_NAMED_ARGS_STDARG_P (f1) != TYPE_NO_NAMED_ARGS_STDARG_P (f2))
    2187              :         return false;
    2188        21608 :       if (!(data->ignore_promoting_args || self_promoting_args_p (args1)))
    2189              :         return false;
    2190        21547 :       data->ignore_promoting_args = false;
    2191        21547 :       if (TYPE_ACTUAL_ARG_TYPES (f2)
    2192        21547 :           && !type_lists_compatible_p (args1, TYPE_ACTUAL_ARG_TYPES (f2), data))
    2193            1 :         data->warning_needed = true;
    2194              :       return true;
    2195              :     }
    2196              : 
    2197              :   /* Both types have argument lists: compare them and propagate results.  */
    2198      9430299 :   return type_lists_compatible_p (args1, args2, data);
    2199              : }
    2200              : 
    2201              : /* Check two lists of types for compatibility, returning false for
    2202              :    incompatible, true for compatible.  */
    2203              : 
    2204              : static bool
    2205      9430375 : type_lists_compatible_p (const_tree args1, const_tree args2,
    2206              :                          struct comptypes_data *data)
    2207              : {
    2208     59035823 :   while (1)
    2209              :     {
    2210     34233099 :       if (args1 == NULL_TREE && args2 == NULL_TREE)
    2211              :         return true;
    2212              :       /* If one list is shorter than the other,
    2213              :          they fail to match.  */
    2214     24948629 :       if (args1 == NULL_TREE || args2 == NULL_TREE)
    2215              :         return false;
    2216     24948622 :       tree a1 = TREE_VALUE (args1);
    2217     24948622 :       tree a2 = TREE_VALUE (args2);
    2218     24948622 :       tree mv1 = remove_qualifiers (a1);
    2219     24948622 :       tree mv2 = remove_qualifiers (a2);
    2220              : 
    2221     24948622 :       gcc_assert (mv2);
    2222     24948622 :       gcc_assert (mv2);
    2223              : 
    2224              :       /* If one of the lists has an error marker, ignore this arg.  */
    2225     24948622 :       if (TREE_CODE (a1) == ERROR_MARK
    2226     24948618 :                || TREE_CODE (a2) == ERROR_MARK)
    2227              :         ;
    2228     24948602 :       else if (!comptypes_internal (mv1, mv2, data))
    2229              :         {
    2230       146129 :           data->different_types_p = true;
    2231              :           /* Allow  wait (union {union wait *u; int *i} *)
    2232              :              and  wait (union wait *)  to be compatible.  */
    2233       146129 :           if (TREE_CODE (a1) == UNION_TYPE
    2234          130 :               && (TYPE_NAME (a1) == NULL_TREE
    2235           98 :                   || TYPE_TRANSPARENT_AGGR (a1))
    2236          130 :               && TREE_CODE (TYPE_SIZE (a1)) == INTEGER_CST
    2237       146259 :               && tree_int_cst_equal (TYPE_SIZE (a1),
    2238          130 :                                      TYPE_SIZE (a2)))
    2239              :             {
    2240          130 :               tree memb;
    2241          130 :               for (memb = TYPE_FIELDS (a1);
    2242          166 :                    memb; memb = DECL_CHAIN (memb))
    2243              :                 {
    2244          164 :                   tree mv3 = remove_qualifiers (TREE_TYPE (memb));
    2245          164 :                   if (comptypes_internal (mv3, mv2, data))
    2246              :                     break;
    2247              :                 }
    2248              :               if (memb == NULL_TREE)
    2249              :                 return false;
    2250              :             }
    2251       145999 :           else if (TREE_CODE (a2) == UNION_TYPE
    2252          105 :                    && (TYPE_NAME (a2) == NULL_TREE
    2253           74 :                        || TYPE_TRANSPARENT_AGGR (a2))
    2254          105 :                    && TREE_CODE (TYPE_SIZE (a2)) == INTEGER_CST
    2255       146104 :                    && tree_int_cst_equal (TYPE_SIZE (a2),
    2256          105 :                                           TYPE_SIZE (a1)))
    2257              :             {
    2258          105 :               tree memb;
    2259          105 :               for (memb = TYPE_FIELDS (a2);
    2260          133 :                    memb; memb = DECL_CHAIN (memb))
    2261              :                 {
    2262          131 :                   tree mv3 = remove_qualifiers (TREE_TYPE (memb));
    2263          131 :                   if (comptypes_internal (mv3, mv1, data))
    2264              :                     break;
    2265              :                 }
    2266              :               if (memb == NULL_TREE)
    2267              :                 return false;
    2268              :             }
    2269              :           else
    2270              :             return false;
    2271              :         }
    2272              : 
    2273     24802724 :       args1 = TREE_CHAIN (args1);
    2274     24802724 :       args2 = TREE_CHAIN (args2);
    2275     24802724 :     }
    2276              : }
    2277              : 
    2278              : /* Compute the size to increment a pointer by.  When a function type or void
    2279              :    type or incomplete type is passed, size_one_node is returned.
    2280              :    This function does not emit any diagnostics; the caller is responsible
    2281              :    for that.  */
    2282              : 
    2283              : static tree
    2284       237056 : c_size_in_bytes (const_tree type)
    2285              : {
    2286       237056 :   enum tree_code code = TREE_CODE (type);
    2287              : 
    2288       237056 :   if (code == FUNCTION_TYPE || code == VOID_TYPE || code == ERROR_MARK
    2289       237056 :       || !COMPLETE_TYPE_P (type))
    2290          195 :     return size_one_node;
    2291              : 
    2292              :   /* Convert in case a char is more than one unit.  */
    2293       236861 :   return size_binop_loc (input_location, CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
    2294       236861 :                          size_int (TYPE_PRECISION (char_type_node)
    2295              :                                    / BITS_PER_UNIT));
    2296              : }
    2297              : 
    2298              : /* Return either DECL or its known constant value (if it has one).  */
    2299              : 
    2300              : tree
    2301     14516098 : decl_constant_value_1 (tree decl, bool in_init)
    2302              : {
    2303     14516098 :   if (/* Note that DECL_INITIAL isn't valid for a PARM_DECL.  */
    2304     14516098 :       TREE_CODE (decl) != PARM_DECL
    2305     14516098 :       && !TREE_THIS_VOLATILE (decl)
    2306     14168679 :       && TREE_READONLY (decl)
    2307        38931 :       && DECL_INITIAL (decl) != NULL_TREE
    2308        37917 :       && !error_operand_p (DECL_INITIAL (decl))
    2309              :       /* This is invalid if initial value is not constant.
    2310              :          If it has either a function call, a memory reference,
    2311              :          or a variable, then re-evaluating it could give different results.  */
    2312        37908 :       && TREE_CONSTANT (DECL_INITIAL (decl))
    2313              :       /* Check for cases where this is sub-optimal, even though valid.  */
    2314     14540697 :       && (in_init || TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR))
    2315        17884 :     return DECL_INITIAL (decl);
    2316              :   return decl;
    2317              : }
    2318              : 
    2319              : /* Return either DECL or its known constant value (if it has one).
    2320              :    Like the above, but always return decl outside of functions.  */
    2321              : 
    2322              : tree
    2323     14515836 : decl_constant_value (tree decl)
    2324              : {
    2325              :   /* Don't change a variable array bound or initial value to a constant
    2326              :      in a place where a variable is invalid.  */
    2327     14515836 :   return current_function_decl ? decl_constant_value_1 (decl, false) : decl;
    2328              : }
    2329              : 
    2330              : /* Convert the array expression EXP to a pointer.  */
    2331              : static tree
    2332       833065 : array_to_pointer_conversion (location_t loc, tree exp)
    2333              : {
    2334       833065 :   tree orig_exp = exp;
    2335       833065 :   tree type = TREE_TYPE (exp);
    2336       833065 :   tree adr;
    2337       833065 :   tree restype = TREE_TYPE (type);
    2338       833065 :   tree ptrtype;
    2339              : 
    2340       833065 :   gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
    2341              : 
    2342       833065 :   STRIP_TYPE_NOPS (exp);
    2343              : 
    2344       833065 :   copy_warning (exp, orig_exp);
    2345              : 
    2346       833065 :   ptrtype = c_build_pointer_type (restype);
    2347              : 
    2348       833065 :   if (INDIRECT_REF_P (exp))
    2349         2914 :     return convert (ptrtype, TREE_OPERAND (exp, 0));
    2350              : 
    2351              :   /* In C++ array compound literals are temporary objects unless they are
    2352              :      const or appear in namespace scope, so they are destroyed too soon
    2353              :      to use them for much of anything  (c++/53220).  */
    2354       830151 :   if (warn_cxx_compat && TREE_CODE (exp) == COMPOUND_LITERAL_EXPR)
    2355              :     {
    2356           48 :       tree decl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
    2357           48 :       if (!TREE_READONLY (decl) && !TREE_STATIC (decl))
    2358           46 :         warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat,
    2359              :                     "converting an array compound literal to a pointer "
    2360              :                     "leads to a dangling pointer in C++");
    2361              :     }
    2362              : 
    2363       830151 :   adr = build_unary_op (loc, ADDR_EXPR, exp, true);
    2364       830151 :   return convert (ptrtype, adr);
    2365              : }
    2366              : 
    2367              : /* Convert the function expression EXP to a pointer.  */
    2368              : static tree
    2369     52578350 : function_to_pointer_conversion (location_t loc, tree exp)
    2370              : {
    2371     52578350 :   tree orig_exp = exp;
    2372              : 
    2373     52578350 :   gcc_assert (TREE_CODE (TREE_TYPE (exp)) == FUNCTION_TYPE);
    2374              : 
    2375     52578350 :   STRIP_TYPE_NOPS (exp);
    2376              : 
    2377     52578350 :   copy_warning (exp, orig_exp);
    2378              : 
    2379     52578350 :   tree exp2 = build_unary_op (loc, ADDR_EXPR, exp, false);
    2380              : 
    2381              :   /* If the function is defined and known to not require a non-local
    2382              :      context, make sure no trampoline is generated.  */
    2383     52578350 :   if (TREE_CODE (exp) == FUNCTION_DECL
    2384     52578350 :       && DECL_INITIAL (exp) && !C_FUNC_NONLOCAL_CONTEXT (exp))
    2385     16727459 :    TREE_NO_TRAMPOLINE (exp2) = 1;
    2386              : 
    2387     52578350 :   return exp2;
    2388              : }
    2389              : 
    2390              : /* Mark EXP as read, not just set, for set but not used -Wunused
    2391              :    warning purposes.  */
    2392              : 
    2393              : void
    2394    507819062 : mark_exp_read (tree exp)
    2395              : {
    2396    638736596 :   switch (TREE_CODE (exp))
    2397              :     {
    2398    209597737 :     case VAR_DECL:
    2399    209597737 :     case PARM_DECL:
    2400    209597737 :       DECL_READ_P (exp) = 1;
    2401    209597737 :       break;
    2402     20472565 :     CASE_CONVERT:
    2403     20472565 :       if (VOID_TYPE_P (TREE_TYPE (exp)))
    2404         3808 :         switch (TREE_CODE (TREE_OPERAND (exp, 0)))
    2405              :           {
    2406              :           case PREINCREMENT_EXPR:
    2407              :           case PREDECREMENT_EXPR:
    2408              :           case POSTINCREMENT_EXPR:
    2409              :           case POSTDECREMENT_EXPR:
    2410              :             return;
    2411              :           default:
    2412              :             break;
    2413              :           }
    2414              :       /* FALLTHRU */
    2415    128148199 :     case ARRAY_REF:
    2416    128148199 :     case COMPONENT_REF:
    2417    128148199 :     case MODIFY_EXPR:
    2418    128148199 :     case REALPART_EXPR:
    2419    128148199 :     case IMAGPART_EXPR:
    2420    128148199 :     case ADDR_EXPR:
    2421    128148199 :     case VIEW_CONVERT_EXPR:
    2422    128148199 :     case PREINCREMENT_EXPR:
    2423    128148199 :     case PREDECREMENT_EXPR:
    2424    128148199 :     case POSTINCREMENT_EXPR:
    2425    128148199 :     case POSTDECREMENT_EXPR:
    2426    128148199 :       mark_exp_read (TREE_OPERAND (exp, 0));
    2427    128148199 :       break;
    2428       236354 :     case COMPOUND_EXPR:
    2429              :       /* Pattern match what build_atomic_assign produces with modifycode
    2430              :          NOP_EXPR.  */
    2431       236354 :       if (VAR_P (TREE_OPERAND (exp, 1))
    2432        27227 :           && DECL_ARTIFICIAL (TREE_OPERAND (exp, 1))
    2433       263497 :           && TREE_CODE (TREE_OPERAND (exp, 0)) == COMPOUND_EXPR)
    2434              :         {
    2435         2210 :           tree t1 = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
    2436         2210 :           tree t2 = TREE_OPERAND (TREE_OPERAND (exp, 0), 1);
    2437         2210 :           if (TREE_CODE (t1) == TARGET_EXPR
    2438         2202 :               && TARGET_EXPR_SLOT (t1) == TREE_OPERAND (exp, 1)
    2439         4410 :               && TREE_CODE (t2) == CALL_EXPR)
    2440              :             {
    2441         2200 :               tree fndecl = get_callee_fndecl (t2);
    2442         2200 :               tree arg = NULL_TREE;
    2443         2200 :               if (fndecl
    2444         2200 :                   && TREE_CODE (fndecl) == FUNCTION_DECL
    2445         2200 :                   && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)
    2446         4400 :                   && call_expr_nargs (t2) >= 2)
    2447         2200 :                 switch (DECL_FUNCTION_CODE (fndecl))
    2448              :                   {
    2449          130 :                   case BUILT_IN_ATOMIC_STORE:
    2450          130 :                     arg = CALL_EXPR_ARG (t2, 1);
    2451          130 :                     break;
    2452         2070 :                   case BUILT_IN_ATOMIC_STORE_1:
    2453         2070 :                   case BUILT_IN_ATOMIC_STORE_2:
    2454         2070 :                   case BUILT_IN_ATOMIC_STORE_4:
    2455         2070 :                   case BUILT_IN_ATOMIC_STORE_8:
    2456         2070 :                   case BUILT_IN_ATOMIC_STORE_16:
    2457         2070 :                     arg = CALL_EXPR_ARG (t2, 0);
    2458         2070 :                     break;
    2459              :                   default:
    2460              :                     break;
    2461              :                   }
    2462         2200 :               if (arg)
    2463              :                 {
    2464         2200 :                   STRIP_NOPS (arg);
    2465         2200 :                   if (TREE_CODE (arg) == ADDR_EXPR
    2466         2200 :                       && DECL_P (TREE_OPERAND (arg, 0))
    2467         4400 :                       && TYPE_ATOMIC (TREE_TYPE (TREE_OPERAND (arg, 0))))
    2468         2200 :                     mark_exp_read (TREE_OPERAND (arg, 0));
    2469              :                 }
    2470              :             }
    2471              :         }
    2472              :       /* FALLTHRU */
    2473      2768784 :     case C_MAYBE_CONST_EXPR:
    2474      2768784 :       mark_exp_read (TREE_OPERAND (exp, 1));
    2475      2768784 :       break;
    2476          586 :     case OMP_ARRAY_SECTION:
    2477          586 :       mark_exp_read (TREE_OPERAND (exp, 0));
    2478          586 :       if (TREE_OPERAND (exp, 1))
    2479          388 :         mark_exp_read (TREE_OPERAND (exp, 1));
    2480          586 :       if (TREE_OPERAND (exp, 2))
    2481          551 :         mark_exp_read (TREE_OPERAND (exp, 2));
    2482              :       break;
    2483              :     default:
    2484              :       break;
    2485              :     }
    2486              : }
    2487              : 
    2488              : /* Perform the default conversion of arrays and functions to pointers.
    2489              :    Return the result of converting EXP.  For any other expression, just
    2490              :    return EXP.
    2491              : 
    2492              :    LOC is the location of the expression.  */
    2493              : 
    2494              : struct c_expr
    2495    374993847 : default_function_array_conversion (location_t loc, struct c_expr exp)
    2496              : {
    2497    374993847 :   tree orig_exp = exp.value;
    2498    374993847 :   tree type = TREE_TYPE (exp.value);
    2499    374993847 :   enum tree_code code = TREE_CODE (type);
    2500              : 
    2501    374993847 :   switch (code)
    2502              :     {
    2503              :     case ARRAY_TYPE:
    2504              :       {
    2505              :         bool not_lvalue = false;
    2506              :         bool lvalue_array_p;
    2507              : 
    2508       786131 :         while ((TREE_CODE (exp.value) == NON_LVALUE_EXPR
    2509       786131 :                 || CONVERT_EXPR_P (exp.value))
    2510       786131 :                && TREE_TYPE (TREE_OPERAND (exp.value, 0)) == type)
    2511              :           {
    2512            0 :             if (TREE_CODE (exp.value) == NON_LVALUE_EXPR)
    2513            0 :               not_lvalue = true;
    2514            0 :             exp.value = TREE_OPERAND (exp.value, 0);
    2515              :           }
    2516              : 
    2517       786131 :         copy_warning (exp.value, orig_exp);
    2518              : 
    2519       786131 :         lvalue_array_p = !not_lvalue && lvalue_p (exp.value);
    2520       786131 :         if (!flag_isoc99 && !lvalue_array_p)
    2521              :           {
    2522              :             /* Before C99, non-lvalue arrays do not decay to pointers.
    2523              :                Normally, using such an array would be invalid; but it can
    2524              :                be used correctly inside sizeof or as a statement expression.
    2525              :                Thus, do not give an error here; an error will result later.  */
    2526          109 :             return exp;
    2527              :           }
    2528              : 
    2529       786022 :         exp.value = array_to_pointer_conversion (loc, exp.value);
    2530              :       }
    2531       786022 :       break;
    2532       762690 :     case FUNCTION_TYPE:
    2533       762690 :       exp.value = function_to_pointer_conversion (loc, exp.value);
    2534       762690 :       break;
    2535              :     default:
    2536              :       break;
    2537              :     }
    2538              : 
    2539    374993738 :   return exp;
    2540              : }
    2541              : 
    2542              : struct c_expr
    2543        12701 : default_function_array_read_conversion (location_t loc, struct c_expr exp)
    2544              : {
    2545        12701 :   mark_exp_read (exp.value);
    2546              :   /* We only generate a call to .ACCESS_WITH_SIZE when it is a read.  */
    2547        12701 :   if (TREE_CODE (exp.value) == COMPONENT_REF
    2548        12701 :       && handle_counted_by_p (exp.value))
    2549            4 :     exp.value = handle_counted_by_for_component_ref (loc, exp.value);
    2550        12701 :   return default_function_array_conversion (loc, exp);
    2551              : }
    2552              : 
    2553              : /* Return whether EXPR should be treated as an atomic lvalue for the
    2554              :    purposes of load and store handling.  */
    2555              : 
    2556              : static bool
    2557    376181946 : really_atomic_lvalue (tree expr)
    2558              : {
    2559    376181946 :   if (error_operand_p (expr))
    2560              :     return false;
    2561    376174311 :   if (!TYPE_ATOMIC (TREE_TYPE (expr)))
    2562              :     return false;
    2563        57412 :   if (!COMPLETE_TYPE_P (TREE_TYPE (expr)))
    2564              :     return false;
    2565        57409 :   if (!lvalue_p (expr))
    2566              :     return false;
    2567              : 
    2568              :   /* Ignore _Atomic on register variables, since their addresses can't
    2569              :      be taken so (a) atomicity is irrelevant and (b) the normal atomic
    2570              :      sequences wouldn't work.  Ignore _Atomic on structures containing
    2571              :      bit-fields, since accessing elements of atomic structures or
    2572              :      unions is undefined behavior (C11 6.5.2.3#5), but it's unclear if
    2573              :      it's undefined at translation time or execution time, and the
    2574              :      normal atomic sequences again wouldn't work.  */
    2575        57535 :   while (handled_component_p (expr))
    2576              :     {
    2577          128 :       if (TREE_CODE (expr) == COMPONENT_REF
    2578          128 :           && DECL_C_BIT_FIELD (TREE_OPERAND (expr, 1)))
    2579              :         return false;
    2580          128 :       expr = TREE_OPERAND (expr, 0);
    2581              :     }
    2582        57407 :   if (TREE_CODE (expr) == COMPOUND_LITERAL_EXPR)
    2583            1 :     expr = COMPOUND_LITERAL_EXPR_DECL (expr);
    2584       112621 :   if (DECL_P (expr) && C_DECL_REGISTER (expr))
    2585            7 :     return false;
    2586              :   return true;
    2587              : }
    2588              : 
    2589              : /* If EXPR is a named constant (C23) derived from a constexpr variable
    2590              :    - that is, a reference to such a variable, or a member extracted by
    2591              :    a sequence of structure and union (but not array) member accesses
    2592              :    (where union member accesses must access the same member as
    2593              :    initialized) - then return the corresponding initializer;
    2594              :    otherwise, return NULL_TREE.  */
    2595              : 
    2596              : static tree
    2597    372881433 : maybe_get_constexpr_init (tree expr)
    2598              : {
    2599    372881433 :   tree decl = NULL_TREE;
    2600    372881433 :   if (TREE_CODE (expr) == VAR_DECL)
    2601              :     decl = expr;
    2602    361029479 :   else if (TREE_CODE (expr) == COMPOUND_LITERAL_EXPR)
    2603       830519 :     decl = COMPOUND_LITERAL_EXPR_DECL (expr);
    2604       830519 :   if (decl
    2605     12682473 :       && C_DECL_DECLARED_CONSTEXPR (decl)
    2606          498 :       && DECL_INITIAL (decl) != NULL_TREE
    2607       831017 :       && !error_operand_p (DECL_INITIAL (decl)))
    2608          498 :     return DECL_INITIAL (decl);
    2609    372880935 :   if (TREE_CODE (expr) != COMPONENT_REF)
    2610              :     return NULL_TREE;
    2611       880885 :   tree inner = maybe_get_constexpr_init (TREE_OPERAND (expr, 0));
    2612       880885 :   if (inner == NULL_TREE)
    2613              :     return NULL_TREE;
    2614          126 :   while ((CONVERT_EXPR_P (inner) || TREE_CODE (inner) == NON_LVALUE_EXPR)
    2615           47 :          && !error_operand_p (inner)
    2616          220 :          && (TYPE_MAIN_VARIANT (TREE_TYPE (inner))
    2617           47 :              == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (inner, 0)))))
    2618           47 :     inner = TREE_OPERAND (inner, 0);
    2619          126 :   if (TREE_CODE (inner) != CONSTRUCTOR)
    2620              :     return NULL_TREE;
    2621          126 :   tree field = TREE_OPERAND (expr, 1);
    2622          126 :   unsigned HOST_WIDE_INT cidx;
    2623          126 :   tree cfield, cvalue;
    2624          126 :   bool have_other_init = false;
    2625          266 :   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (inner), cidx, cfield, cvalue)
    2626              :     {
    2627          250 :       if (cfield == field)
    2628              :         return cvalue;
    2629          140 :       have_other_init = true;
    2630              :     }
    2631           16 :   if (TREE_CODE (TREE_TYPE (inner)) == UNION_TYPE
    2632           16 :       && (have_other_init || field != TYPE_FIELDS (TREE_TYPE (inner))))
    2633              :     return NULL_TREE;
    2634              :   /* Return a default initializer.  */
    2635           13 :   if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (expr)))
    2636            5 :     return build_constructor (TREE_TYPE (expr), NULL);
    2637            8 :   return build_zero_cst (TREE_TYPE (expr));
    2638              : }
    2639              : 
    2640              : /* Helper function for convert_lvalue_to_rvalue called via
    2641              :    walk_tree_without_duplicates.  Find DATA inside of the expression.  */
    2642              : 
    2643              : static tree
    2644       230165 : c_find_var_r (tree *tp, int *walk_subtrees, void *data)
    2645              : {
    2646       230165 :   if (TYPE_P (*tp))
    2647            0 :     *walk_subtrees = 0;
    2648       230165 :   else if (*tp == (tree) data)
    2649            0 :     return *tp;
    2650              :   return NULL_TREE;
    2651              : }
    2652              : 
    2653              : /* Convert expression EXP (location LOC) from lvalue to rvalue,
    2654              :    including converting functions and arrays to pointers if CONVERT_P.
    2655              :    If READ_P, also mark the expression as having been read.  If
    2656              :    FOR_INIT, constexpr expressions of structure and union type should
    2657              :    be replaced by the corresponding CONSTRUCTOR; otherwise, only
    2658              :    constexpr scalars (including elements of structures and unions) are
    2659              :    replaced by their initializers.  */
    2660              : 
    2661              : struct c_expr
    2662    372188741 : convert_lvalue_to_rvalue (location_t loc, struct c_expr exp,
    2663              :                           bool convert_p, bool read_p, bool for_init)
    2664              : {
    2665    372188741 :   bool force_non_npc = false;
    2666    372188741 :   if (read_p)
    2667    326624230 :     mark_exp_read (exp.value);
    2668              :   /* We only generate a call to .ACCESS_WITH_SIZE when it is a read.  */
    2669    326624230 :   if (read_p && TREE_CODE (exp.value) == COMPONENT_REF
    2670       787056 :       && handle_counted_by_p (exp.value))
    2671       787027 :     exp.value = handle_counted_by_for_component_ref (loc, exp.value);
    2672              : 
    2673    372188741 :   if (convert_p)
    2674    372175224 :     exp = default_function_array_conversion (loc, exp);
    2675    372188741 :   if (!VOID_TYPE_P (TREE_TYPE (exp.value))
    2676    372188741 :       || (flag_isoc2y
    2677         1574 :           && TYPE_QUALS (TREE_TYPE (exp.value)) != TYPE_UNQUALIFIED))
    2678    369580573 :     exp.value = require_complete_type (loc, exp.value);
    2679    372188741 :   if (for_init || !RECORD_OR_UNION_TYPE_P (TREE_TYPE (exp.value)))
    2680              :     {
    2681    372000548 :       tree init = maybe_get_constexpr_init (exp.value);
    2682    372000548 :       if (init != NULL_TREE)
    2683              :         {
    2684              :           /* A named constant of pointer type or type nullptr_t is not
    2685              :              a null pointer constant even if the initializer is
    2686              :              one.  */
    2687          495 :           if (TREE_CODE (init) == INTEGER_CST
    2688          360 :               && !INTEGRAL_TYPE_P (TREE_TYPE (init))
    2689          521 :               && integer_zerop (init))
    2690              :             force_non_npc = true;
    2691              :           exp.value = init;
    2692              :         }
    2693              :     }
    2694    372188741 :   if (really_atomic_lvalue (exp.value))
    2695              :     {
    2696        26933 :       vec<tree, va_gc> *params;
    2697        26933 :       tree nonatomic_type, tmp, tmp_addr, fndecl, func_call;
    2698        26933 :       tree expr_type = TREE_TYPE (exp.value);
    2699        26933 :       tree expr_addr = build_unary_op (loc, ADDR_EXPR, exp.value, false);
    2700        26933 :       tree seq_cst = build_int_cst (integer_type_node, MEMMODEL_SEQ_CST);
    2701              : 
    2702        26933 :       gcc_assert (TYPE_ATOMIC (expr_type));
    2703              : 
    2704              :       /* Expansion of a generic atomic load may require an addition
    2705              :          element, so allocate enough to prevent a resize.  */
    2706        26933 :       vec_alloc (params, 4);
    2707              : 
    2708              :       /* Remove the qualifiers for the rest of the expressions and
    2709              :          create the VAL temp variable to hold the RHS.  */
    2710        26933 :       nonatomic_type = build_qualified_type (expr_type, TYPE_UNQUALIFIED);
    2711        26933 :       tmp = create_tmp_var_raw (nonatomic_type);
    2712        26933 :       tmp_addr = build_unary_op (loc, ADDR_EXPR, tmp, false);
    2713        26933 :       TREE_ADDRESSABLE (tmp) = 1;
    2714              :       /* Do not disable warnings for TMP even though it's artificial.
    2715              :          -Winvalid-memory-model depends on it.  */
    2716              : 
    2717              :       /* Issue __atomic_load (&expr, &tmp, SEQ_CST);  */
    2718        26933 :       fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_LOAD);
    2719        26933 :       params->quick_push (expr_addr);
    2720        26933 :       params->quick_push (tmp_addr);
    2721        26933 :       params->quick_push (seq_cst);
    2722        26933 :       func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
    2723              : 
    2724              :       /* EXPR is always read.  */
    2725        26933 :       mark_exp_read (exp.value);
    2726              : 
    2727              :       /* Optimize the common case where c_build_function_call_vec
    2728              :          immediately folds __atomic_load (&expr, &tmp, SEQ_CST); into
    2729              :          tmp = __atomic_load_<N> (&expr, SEQ_CST);
    2730              :          In that case tmp is not addressable and can be initialized
    2731              :          fully by the rhs of the MODIFY_EXPR.  */
    2732        26933 :       tree tem = func_call;
    2733        26933 :       if (CONVERT_EXPR_P (tem) && VOID_TYPE_P (TREE_TYPE (tem)))
    2734              :         {
    2735        25678 :           tem = TREE_OPERAND (tem, 0);
    2736        25678 :           if (TREE_CODE (tem) == MODIFY_EXPR
    2737        25678 :               && TREE_OPERAND (tem, 0) == tmp
    2738        51356 :               && !walk_tree_without_duplicates (&TREE_OPERAND (tem, 1),
    2739              :                                                 c_find_var_r, tmp))
    2740              :             {
    2741        25678 :               TREE_ADDRESSABLE (tmp) = 0;
    2742        25678 :               func_call = TREE_OPERAND (tem, 1);
    2743              :             }
    2744              :         }
    2745              : 
    2746              :       /* Return tmp which contains the value loaded.  */
    2747        26933 :       exp.value = build4 (TARGET_EXPR, nonatomic_type, tmp, func_call,
    2748              :                           NULL_TREE, NULL_TREE);
    2749              :     }
    2750    372175224 :   if (convert_p && !error_operand_p (exp.value)
    2751    744356376 :       && (TREE_CODE (TREE_TYPE (exp.value)) != ARRAY_TYPE))
    2752    372167526 :     exp.value = convert (build_qualified_type (TREE_TYPE (exp.value), TYPE_UNQUALIFIED), exp.value);
    2753    372188741 :   if (force_non_npc)
    2754           24 :     exp.value = build1 (NOP_EXPR, TREE_TYPE (exp.value), exp.value);
    2755              : 
    2756    372188741 :   {
    2757    372188741 :     tree false_value, true_value;
    2758    372175224 :     if (convert_p && !error_operand_p (exp.value)
    2759    744356376 :         && c_hardbool_type_attr (TREE_TYPE (exp.value),
    2760              :                                  &false_value, &true_value))
    2761              :       {
    2762         9721 :         tree t = save_expr (exp.value);
    2763              : 
    2764         9721 :         mark_exp_read (exp.value);
    2765              : 
    2766         9721 :         tree trapfn = builtin_decl_explicit (BUILT_IN_TRAP);
    2767         9721 :         tree expr = build_call_expr_loc (loc, trapfn, 0);
    2768         9721 :         expr = build_compound_expr (loc, expr, boolean_true_node);
    2769         9721 :         expr = fold_build3_loc (loc, COND_EXPR, boolean_type_node,
    2770              :                                 fold_build2_loc (loc, NE_EXPR,
    2771              :                                                  boolean_type_node,
    2772              :                                                  t, true_value),
    2773              :                                 expr, boolean_true_node);
    2774         9721 :         expr = fold_build3_loc (loc, COND_EXPR, boolean_type_node,
    2775              :                                 fold_build2_loc (loc, NE_EXPR,
    2776              :                                                  boolean_type_node,
    2777              :                                                  t, false_value),
    2778              :                                 expr, boolean_false_node);
    2779              : 
    2780         9721 :         exp.value = expr;
    2781              :       }
    2782              :   }
    2783              : 
    2784    372188741 :   return exp;
    2785              : }
    2786              : 
    2787              : /* Wrapper for the overload above, same arguments but for tree rather than
    2788              :    c_expr.  This is important for hardbools to decay to bools.  */
    2789              : 
    2790              : static inline tree
    2791       582826 : convert_lvalue_to_rvalue (location_t loc, tree val,
    2792              :                           bool convert_p, bool read_p, bool for_init = false)
    2793              : {
    2794       582826 :   struct c_expr expr;
    2795       582826 :   memset (&expr, 0, sizeof (expr));
    2796       582826 :   expr.value = val;
    2797       582826 :   expr = convert_lvalue_to_rvalue (loc, expr, convert_p, read_p, for_init);
    2798       582826 :   return expr.value;
    2799              : }
    2800              : 
    2801              : /* EXP is an expression of integer type.  Apply the integer promotions
    2802              :    to it and return the promoted value.  */
    2803              : 
    2804              : tree
    2805     80269067 : perform_integral_promotions (tree exp)
    2806              : {
    2807     80269067 :   tree type = TREE_TYPE (exp);
    2808     80269067 :   enum tree_code code = TREE_CODE (type);
    2809              : 
    2810     80269067 :   gcc_assert (INTEGRAL_TYPE_P (type));
    2811              : 
    2812              :   /* Convert enums to the result of applying the integer promotions to
    2813              :      their underlying type.  */
    2814     80269067 :   if (code == ENUMERAL_TYPE)
    2815              :     {
    2816       658575 :       type = ENUM_UNDERLYING_TYPE (type);
    2817       658575 :       if (c_promoting_integer_type_p (type))
    2818              :         {
    2819           94 :           if (TYPE_UNSIGNED (type)
    2820           94 :               && TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
    2821            0 :             type = unsigned_type_node;
    2822              :           else
    2823           94 :             type = integer_type_node;
    2824              :         }
    2825              : 
    2826       658575 :       return convert (type, exp);
    2827              :     }
    2828              : 
    2829              :   /* ??? This should no longer be needed now bit-fields have their
    2830              :      proper types.  */
    2831     79610492 :   if (TREE_CODE (exp) == COMPONENT_REF
    2832     79610492 :       && DECL_C_BIT_FIELD (TREE_OPERAND (exp, 1)))
    2833              :     {
    2834        62438 :       if (BITINT_TYPE_P (DECL_BIT_FIELD_TYPE (TREE_OPERAND (exp, 1))))
    2835              :         {
    2836          584 :           tree btype = DECL_BIT_FIELD_TYPE (TREE_OPERAND (exp, 1));
    2837          584 :           if (TREE_CODE (btype) == BITINT_TYPE)
    2838          546 :             return convert (btype, exp);
    2839              :           else
    2840           38 :             return convert (ENUM_UNDERLYING_TYPE (btype), exp);
    2841              :         }
    2842              :       /* If it's thinner than an int, promote it like a
    2843              :          c_promoting_integer_type_p, otherwise leave it alone.  */
    2844        61854 :       if (compare_tree_int (DECL_SIZE (TREE_OPERAND (exp, 1)),
    2845        61854 :                             TYPE_PRECISION (integer_type_node)) < 0)
    2846        53592 :         return convert (integer_type_node, exp);
    2847              :     }
    2848              : 
    2849     79556316 :   if (c_promoting_integer_type_p (type))
    2850              :     {
    2851              :       /* Preserve unsignedness if not really getting any wider.  */
    2852       657540 :       if (TYPE_UNSIGNED (type)
    2853       657540 :           && TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
    2854            0 :         return convert (unsigned_type_node, exp);
    2855              : 
    2856       657540 :       return convert (integer_type_node, exp);
    2857              :     }
    2858              : 
    2859              :   return exp;
    2860              : }
    2861              : 
    2862              : 
    2863              : /* Perform default promotions for C data used in expressions.
    2864              :    Enumeral types or short or char are converted to int.
    2865              :    In addition, manifest constants symbols are replaced by their values.  */
    2866              : 
    2867              : tree
    2868     89891144 : default_conversion (tree exp)
    2869              : {
    2870     89891144 :   tree orig_exp;
    2871     89891144 :   tree type = TREE_TYPE (exp);
    2872     89891144 :   enum tree_code code = TREE_CODE (type);
    2873     89891144 :   tree promoted_type;
    2874              : 
    2875     89891144 :   mark_exp_read (exp);
    2876              :   /* We only generate a call to .ACCESS_WITH_SIZE when it is a read.  */
    2877     89891144 :   if (TREE_CODE (exp) == COMPONENT_REF
    2878     89891144 :       && handle_counted_by_p (exp))
    2879       602757 :     exp = handle_counted_by_for_component_ref (EXPR_LOCATION (exp), exp);
    2880              : 
    2881              :   /* Functions and arrays have been converted during parsing.  */
    2882     89891144 :   gcc_assert (code != FUNCTION_TYPE);
    2883     89891144 :   if (code == ARRAY_TYPE)
    2884              :     return exp;
    2885              : 
    2886              :   /* Constants can be used directly unless they're not loadable.  */
    2887     89890984 :   if (TREE_CODE (exp) == CONST_DECL)
    2888            0 :     exp = DECL_INITIAL (exp);
    2889              : 
    2890              :   /* Strip no-op conversions.  */
    2891     89890984 :   orig_exp = exp;
    2892     90255357 :   STRIP_TYPE_NOPS (exp);
    2893              : 
    2894     89890984 :   copy_warning (exp, orig_exp);
    2895              : 
    2896     89890984 :   if (code == VOID_TYPE)
    2897              :     {
    2898            2 :       error_at (EXPR_LOC_OR_LOC (exp, input_location),
    2899              :                 "void value not ignored as it ought to be");
    2900            2 :       return error_mark_node;
    2901              :     }
    2902              : 
    2903     89890982 :   exp = require_complete_type (EXPR_LOC_OR_LOC (exp, input_location), exp);
    2904     89890982 :   if (exp == error_mark_node)
    2905              :     return error_mark_node;
    2906              : 
    2907     89890077 :   promoted_type = targetm.promoted_type (type);
    2908     89890077 :   if (promoted_type)
    2909            0 :     return convert (promoted_type, exp);
    2910              : 
    2911     89890077 :   if (INTEGRAL_TYPE_P (type))
    2912              :     {
    2913              :       /* Avoid performing integral promotion of bit-precise integer
    2914              :          type bit-field to its corresponding bit-precise integer if
    2915              :          orig_exp is a cast to it to its underlying type.  */
    2916     79264335 :       if (orig_exp != exp
    2917        13031 :           && TREE_CODE (exp) == COMPONENT_REF
    2918           42 :           && DECL_C_BIT_FIELD (TREE_OPERAND (exp, 1))
    2919     79264366 :           && BITINT_TYPE_P (DECL_BIT_FIELD_TYPE (TREE_OPERAND (exp, 1))))
    2920           31 :         return perform_integral_promotions (orig_exp);
    2921     79264304 :       return perform_integral_promotions (exp);
    2922              :     }
    2923              : 
    2924              :   return exp;
    2925              : }
    2926              : 
    2927              : /* Look up COMPONENT in a structure or union TYPE.
    2928              : 
    2929              :    If the component name is not found, returns NULL_TREE.  Otherwise,
    2930              :    the return value is a TREE_LIST, with each TREE_VALUE a FIELD_DECL
    2931              :    stepping down the chain to the component, which is in the last
    2932              :    TREE_VALUE of the list.  Normally the list is of length one, but if
    2933              :    the component is embedded within (nested) anonymous structures or
    2934              :    unions, the list steps down the chain to the component.  */
    2935              : 
    2936              : tree
    2937      2336021 : lookup_field (const_tree type, tree component)
    2938              : {
    2939      2336021 :   tree field;
    2940              : 
    2941              :   /* If TYPE_LANG_SPECIFIC is set, then it is a sorted array of pointers
    2942              :      to the field elements.  Use a binary search on this array to quickly
    2943              :      find the element.  Otherwise, do a linear search.  TYPE_LANG_SPECIFIC
    2944              :      will always be set for structures which have many elements.
    2945              : 
    2946              :      Duplicate field checking replaces duplicates with NULL_TREE so
    2947              :      TYPE_LANG_SPECIFIC arrays are potentially no longer sorted.  In that
    2948              :      case just iterate using DECL_CHAIN.  */
    2949              : 
    2950      2638926 :   if (TYPE_LANG_SPECIFIC (type) && TYPE_LANG_SPECIFIC (type)->s
    2951      2638926 :       && !seen_error ())
    2952              :     {
    2953       302884 :       int bot, top, half;
    2954       302884 :       tree *field_array = &TYPE_LANG_SPECIFIC (type)->s->elts[0];
    2955              : 
    2956       302884 :       field = TYPE_FIELDS (type);
    2957       302884 :       bot = 0;
    2958       302884 :       top = TYPE_LANG_SPECIFIC (type)->s->len;
    2959      1396075 :       while (top - bot > 1)
    2960              :         {
    2961      1366845 :           half = (top - bot + 1) >> 1;
    2962      1366845 :           field = field_array[bot+half];
    2963              : 
    2964      1366845 :           if (DECL_NAME (field) == NULL_TREE)
    2965              :             {
    2966              :               /* Step through all anon unions in linear fashion.  */
    2967            0 :               while (DECL_NAME (field_array[bot]) == NULL_TREE)
    2968              :                 {
    2969            0 :                   field = field_array[bot++];
    2970            0 :                   if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)))
    2971              :                     {
    2972            0 :                       tree anon = lookup_field (TREE_TYPE (field), component);
    2973              : 
    2974            0 :                       if (anon)
    2975            0 :                         return tree_cons (NULL_TREE, field, anon);
    2976              : 
    2977              :                       /* The Plan 9 compiler permits referring
    2978              :                          directly to an anonymous struct/union field
    2979              :                          using a typedef name.  */
    2980            0 :                       if (flag_plan9_extensions
    2981            0 :                           && TYPE_NAME (TREE_TYPE (field)) != NULL_TREE
    2982            0 :                           && (TREE_CODE (TYPE_NAME (TREE_TYPE (field)))
    2983              :                               == TYPE_DECL)
    2984            0 :                           && (DECL_NAME (TYPE_NAME (TREE_TYPE (field)))
    2985              :                               == component))
    2986              :                         break;
    2987              :                     }
    2988              :                 }
    2989              : 
    2990              :               /* Entire record is only anon unions.  */
    2991            0 :               if (bot > top)
    2992              :                 return NULL_TREE;
    2993              : 
    2994              :               /* Restart the binary search, with new lower bound.  */
    2995            0 :               continue;
    2996            0 :             }
    2997              : 
    2998      1366845 :           if (DECL_NAME (field) == component)
    2999              :             break;
    3000      1093191 :           if (DECL_NAME (field) < component)
    3001              :             bot += half;
    3002              :           else
    3003       903786 :             top = bot + half;
    3004              :         }
    3005              : 
    3006       302884 :       if (DECL_NAME (field_array[bot]) == component)
    3007              :         field = field_array[bot];
    3008       273654 :       else if (DECL_NAME (field) != component)
    3009              :         return NULL_TREE;
    3010              :     }
    3011              :   else
    3012              :     {
    3013      5301411 :       for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    3014              :         {
    3015      5291930 :           if (DECL_NAME (field) == NULL_TREE
    3016      5291930 :               && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)))
    3017              :             {
    3018        12394 :               tree anon = lookup_field (TREE_TYPE (field), component);
    3019              : 
    3020        12394 :               if (anon)
    3021         3008 :                 return tree_cons (NULL_TREE, field, anon);
    3022              : 
    3023              :               /* The Plan 9 compiler permits referring directly to an
    3024              :                  anonymous struct/union field using a typedef
    3025              :                  name.  */
    3026         9386 :               if (flag_plan9_extensions
    3027          174 :                   && TYPE_NAME (TREE_TYPE (field)) != NULL_TREE
    3028          172 :                   && TREE_CODE (TYPE_NAME (TREE_TYPE (field))) == TYPE_DECL
    3029         9448 :                   && (DECL_NAME (TYPE_NAME (TREE_TYPE (field)))
    3030              :                       == component))
    3031              :                 break;
    3032              :             }
    3033              : 
    3034      5288918 :           if (DECL_NAME (field) == component)
    3035              :             break;
    3036              :         }
    3037              : 
    3038      2030129 :       if (field == NULL_TREE)
    3039              :         return NULL_TREE;
    3040              :     }
    3041              : 
    3042      2323532 :   return tree_cons (NULL_TREE, field, NULL_TREE);
    3043              : }
    3044              : 
    3045              : /* Recursively append candidate IDENTIFIER_NODEs to CANDIDATES.  */
    3046              : 
    3047              : static void
    3048          101 : lookup_field_fuzzy_find_candidates (tree type, tree component,
    3049              :                                     vec<tree> *candidates)
    3050              : {
    3051          101 :   tree field;
    3052          258 :   for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    3053              :     {
    3054          157 :       if (DECL_NAME (field) == NULL_TREE
    3055          157 :           && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)))
    3056           30 :         lookup_field_fuzzy_find_candidates (TREE_TYPE (field), component,
    3057              :                                             candidates);
    3058              : 
    3059          157 :       if (DECL_NAME (field))
    3060          111 :         candidates->safe_push (DECL_NAME (field));
    3061              :     }
    3062          101 : }
    3063              : 
    3064              : /* Like "lookup_field", but find the closest matching IDENTIFIER_NODE,
    3065              :    rather than returning a TREE_LIST for an exact match.  */
    3066              : 
    3067              : static tree
    3068           71 : lookup_field_fuzzy (tree type, tree component)
    3069              : {
    3070           71 :   gcc_assert (TREE_CODE (component) == IDENTIFIER_NODE);
    3071              : 
    3072              :   /* First, gather a list of candidates.  */
    3073           71 :   auto_vec <tree> candidates;
    3074              : 
    3075           71 :   lookup_field_fuzzy_find_candidates (type, component,
    3076              :                                       &candidates);
    3077              : 
    3078           71 :   return find_closest_identifier (component, &candidates);
    3079           71 : }
    3080              : 
    3081              : /* Support function for build_component_ref's error-handling.
    3082              : 
    3083              :    Given DATUM_TYPE, and "DATUM.COMPONENT", where DATUM is *not* a
    3084              :    struct or union, should we suggest "DATUM->COMPONENT" as a hint?  */
    3085              : 
    3086              : static bool
    3087           72 : should_suggest_deref_p (tree datum_type)
    3088              : {
    3089              :   /* We don't do it for Objective-C, since Objective-C 2.0 dot-syntax
    3090              :      allows "." for ptrs; we could be handling a failed attempt
    3091              :      to access a property.  */
    3092           72 :   if (c_dialect_objc ())
    3093              :     return false;
    3094              : 
    3095              :   /* Only suggest it for pointers...  */
    3096           72 :   if (TREE_CODE (datum_type) != POINTER_TYPE)
    3097              :     return false;
    3098              : 
    3099              :   /* ...to structs/unions.  */
    3100            8 :   tree underlying_type = TREE_TYPE (datum_type);
    3101            8 :   enum tree_code code = TREE_CODE (underlying_type);
    3102            8 :   if (code == RECORD_TYPE || code == UNION_TYPE)
    3103              :     return true;
    3104              :   else
    3105            1 :     return false;
    3106              : }
    3107              : 
    3108              : /* Give a component ref REF, decide whether we should handle its counted_by
    3109              :    attribute based on its context:
    3110              :    Do not handle counted_by when in offsetof, typeof and alignof operator.  */
    3111              : 
    3112              : static bool
    3113      2217122 : handle_counted_by_p (tree ref)
    3114              : {
    3115      2217122 :   gcc_assert (TREE_CODE (ref) == COMPONENT_REF);
    3116      2217122 :   tree datum = TREE_OPERAND (ref, 0);
    3117              :   /* If the component_ref is build for a offsetof, i.e., the datum
    3118              :      of the component_ref is a indirect_ref of null_pointer_node,
    3119              :      we should not generate call to .ACCESS_WITH_SIZE.  */
    3120      2217122 :   if (TREE_CODE (datum) == INDIRECT_REF
    3121      2217122 :       && TREE_OPERAND (datum, 0) == null_pointer_node)
    3122              :     return false;
    3123      2216784 :   if (in_typeof || in_alignof)
    3124         8786 :     return false;
    3125              :   return true;
    3126              : }
    3127              : 
    3128              : /* Given a component ref REF, if there is a counted_by attribute attached,
    3129              :    issue error when the element_type is a structure or union including a
    3130              :    flexible array member.  */
    3131              : 
    3132              : static void
    3133      2289353 : check_counted_by_attribute (location_t loc, tree ref)
    3134              : {
    3135      2289353 :   tree subdatum = TREE_OPERAND (ref, 1);
    3136      2289353 :   tree sub_type = TREE_TYPE (subdatum);
    3137              : 
    3138      2289353 :   if (!flexible_array_member_type_p (sub_type)
    3139      2289353 :       && TREE_CODE (sub_type) != POINTER_TYPE)
    3140              :     return;
    3141              : 
    3142       391382 :   tree element_type = TREE_TYPE (sub_type);
    3143              : 
    3144       391382 :   tree attr_counted_by = lookup_attribute ("counted_by",
    3145       391382 :                                            DECL_ATTRIBUTES (subdatum));
    3146       391382 :   if (attr_counted_by)
    3147              :     {
    3148              :       /* Issue error when the element_type is a structure or
    3149              :         union including a flexible array member.  */
    3150          883 :       if (RECORD_OR_UNION_TYPE_P (element_type)
    3151          883 :           && TYPE_INCLUDES_FLEXARRAY (element_type))
    3152              :         {
    3153            2 :           error_at (loc,
    3154              :                     "%<counted_by%> attribute is not allowed for a pointer to"
    3155              :                     " structure or union with flexible array member");
    3156            2 :           return;
    3157              :         }
    3158              :     }
    3159              : }
    3160              : 
    3161              : /* For a SUBDATUM field of a structure or union DATUM, generate a REF
    3162              :    to the object that represents its counted_by per the attribute
    3163              :    counted_by attached to this field if it's a flexible array member
    3164              :    or a pointer field, otherwise return NULL_TREE.
    3165              :    Set COUNTED_BY_TYPE to the TYPE of the counted_by field.
    3166              :    For example, if:
    3167              : 
    3168              :     struct P {
    3169              :       int k;
    3170              :       int x[] __attribute__ ((counted_by (k)));
    3171              :     } *p;
    3172              : 
    3173              :     for:
    3174              :     p->x
    3175              : 
    3176              :     the ref to the object that represents its element count will be:
    3177              : 
    3178              :     &(p->k)
    3179              : */
    3180              : 
    3181              : static tree
    3182       442935 : build_counted_by_ref (tree datum, tree subdatum,
    3183              :                       tree *counted_by_type)
    3184              : {
    3185       442935 :   tree sub_type = TREE_TYPE (subdatum);
    3186       442935 :   if (!flexible_array_member_type_p (sub_type)
    3187       442935 :       && TREE_CODE (sub_type) != POINTER_TYPE)
    3188              :     return NULL_TREE;
    3189              : 
    3190       442935 :   tree attr_counted_by = lookup_attribute ("counted_by",
    3191       442935 :                                            DECL_ATTRIBUTES (subdatum));
    3192       442935 :   if (!attr_counted_by)
    3193              :     return NULL_TREE;
    3194              : 
    3195          661 :   tree counted_by_ref = NULL_TREE;
    3196          661 :   *counted_by_type = NULL_TREE;
    3197              : 
    3198          661 :   tree type = TREE_TYPE (datum);
    3199              : 
    3200              :   /* If the type of the containing structure is an anonymous struct/union,
    3201              :      and this anonymous struct/union is not a root type, get the first
    3202              :      outer named structure/union type.  */
    3203          661 :   while (TREE_CODE (datum) == COMPONENT_REF
    3204           35 :          && c_type_tag (type) == NULL_TREE
    3205          731 :          && DECL_NAME (TREE_OPERAND (datum, 1)) == NULL_TREE)
    3206              :     {
    3207           35 :       datum = TREE_OPERAND (datum, 0);
    3208           35 :       type = TREE_TYPE (datum);
    3209              :     }
    3210              : 
    3211          661 :   tree field_id = TREE_VALUE (TREE_VALUE (attr_counted_by));
    3212          661 :   tree counted_by_field = lookup_field (type, field_id);
    3213          661 :   gcc_assert (counted_by_field);
    3214              : 
    3215         1073 :   tree counted_by_subdatum;
    3216         1073 :   do
    3217              :     {
    3218         1073 :       counted_by_subdatum = TREE_VALUE (counted_by_field);
    3219              :       /* Get the TYPE of the counted_by field.  */
    3220         1073 :       *counted_by_type = TREE_TYPE (counted_by_subdatum);
    3221              : 
    3222         1073 :       counted_by_ref
    3223         1073 :         = build3 (COMPONENT_REF, TREE_TYPE (counted_by_subdatum),
    3224              :                   datum, counted_by_subdatum, NULL_TREE);
    3225              : 
    3226         1073 :       datum = counted_by_ref;
    3227         1073 :       counted_by_field = TREE_CHAIN (counted_by_field);
    3228              :     }
    3229         1073 :   while (counted_by_field);
    3230              : 
    3231          661 :   counted_by_ref = build_fold_addr_expr (counted_by_ref);
    3232          661 :   return counted_by_ref;
    3233              : }
    3234              : 
    3235              : /* Given a COMPONENT_REF REF with the location LOC, the corresponding
    3236              :    COUNTED_BY_REF, and the COUNTED_BY_TYPE, generate the corresponding
    3237              :    call to the internal function .ACCESS_WITH_SIZE.
    3238              : 
    3239              :    A: For the Flexible Array Member, Generate an INDIRECT_REF to a call to
    3240              :    the internal function .ACCESS_WITH_SIZE.
    3241              : 
    3242              :    REF
    3243              : 
    3244              :    to:
    3245              : 
    3246              :    (*.ACCESS_WITH_SIZE (REF, COUNTED_BY_REF, (* TYPE_OF_SIZE)0,
    3247              :                         TYPE_SIZE_UNIT for element)
    3248              : 
    3249              :    NOTE: The return type of this function is the POINTER type pointing
    3250              :    to the original flexible array type.  Then the type of the INDIRECT_REF
    3251              :    is the original flexible array type.
    3252              :    The type of the first argument of this function is a POINTER type
    3253              :    to the original flexible array type.
    3254              : 
    3255              :    B: For pointers with counted_by, generate a call to the internal function
    3256              :    .ACCESS_WITH_SIZE.
    3257              : 
    3258              :     REF
    3259              : 
    3260              :     to:
    3261              : 
    3262              :     .ACCESS_WITH_SIZE (REF, COUNTED_BY_REF, (* TYPE_OF_SIZE)0,
    3263              :                        TYPE_SIZE_UNIT for element)
    3264              : 
    3265              :    NOTE: The return type of this function is the original pointer type.
    3266              :    The type of the first argument of this function is the original
    3267              :    pointer type.
    3268              : 
    3269              :    The 3rd argument of the call is a constant 0 with the pointer TYPE whose
    3270              :    pointee type is the TYPE of the object pointed by COUNTED_BY_REF.
    3271              : 
    3272              :    The 4th argument of the call is the TYPE_SIZE_UNIT of the element TYPE
    3273              :    of the array.
    3274              : 
    3275              :   */
    3276              : static tree
    3277          661 : build_access_with_size_for_counted_by (location_t loc, tree ref,
    3278              :                                        tree counted_by_ref,
    3279              :                                        tree counted_by_type)
    3280              : {
    3281          661 :   gcc_assert (flexible_array_member_type_p (TREE_TYPE (ref))
    3282              :               || TREE_CODE (TREE_TYPE (ref)) == POINTER_TYPE);
    3283              : 
    3284          661 :   bool is_fam = flexible_array_member_type_p (TREE_TYPE (ref));
    3285              : 
    3286              :   /* The result type of the call is a pointer to the flexible array type;
    3287              :      or is the original pointer type to the pointer field with counted_by.  */
    3288          661 :   tree result_type = is_fam ? c_build_pointer_type (TREE_TYPE (ref))
    3289          459 :                      : TREE_TYPE (ref);
    3290              : 
    3291          661 :   tree element_type = TREE_TYPE (TREE_TYPE (ref));
    3292          661 :   tree element_size = VOID_TYPE_P (element_type)
    3293          661 :                       ? size_one_node
    3294          661 :                       : TYPE_SIZE_UNIT (element_type);
    3295          661 :   if (element_size == NULL_TREE)
    3296              :     return ref;
    3297              : 
    3298          647 :   tree first_param = is_fam
    3299          647 :                      ? c_fully_fold (array_to_pointer_conversion (loc, ref),
    3300              :                                      false, NULL)
    3301          445 :                      : c_fully_fold (ref, false, NULL);
    3302          647 :   tree second_param
    3303          647 :     = c_fully_fold (counted_by_ref, false, NULL);
    3304          647 :   tree third_param = build_int_cst (c_build_pointer_type (counted_by_type), 0);
    3305              : 
    3306          647 :   tree call
    3307          647 :     = build_call_expr_internal_loc (loc, IFN_ACCESS_WITH_SIZE,
    3308              :                                     result_type, 4,
    3309              :                                     first_param,
    3310              :                                     second_param,
    3311              :                                     third_param,
    3312              :                                     element_size);
    3313              : 
    3314              :   /* Wrap the call with an INDIRECT_REF with the flexible array type.  */
    3315          647 :   if (is_fam)
    3316          202 :     call = build1 (INDIRECT_REF, TREE_TYPE (ref), call);
    3317          647 :   SET_EXPR_LOCATION (call, loc);
    3318          647 :   return call;
    3319              : }
    3320              : 
    3321              : /* For the COMPONENT_REF ref, check whether it has a counted_by attribute,
    3322              :    if so, wrap this COMPONENT_REF with the corresponding CALL to the
    3323              :    function .ACCESS_WITH_SIZE.
    3324              :    Otherwise, return the ref itself.  */
    3325              : 
    3326              : tree
    3327      2208078 : handle_counted_by_for_component_ref (location_t loc, tree ref)
    3328              : {
    3329      2208078 :   gcc_assert (TREE_CODE (ref) == COMPONENT_REF);
    3330      2208078 :   tree datum = TREE_OPERAND (ref, 0);
    3331      2208078 :   tree subdatum = TREE_OPERAND (ref, 1);
    3332      2208078 :   tree counted_by_type = NULL_TREE;
    3333              : 
    3334      2208078 :   if (!(flexible_array_member_type_p (TREE_TYPE (ref))
    3335      2137547 :         || TREE_CODE (TREE_TYPE (ref)) == POINTER_TYPE))
    3336              :     return ref;
    3337              : 
    3338       442935 :   tree counted_by_ref = build_counted_by_ref (datum, subdatum,
    3339              :                                               &counted_by_type);
    3340       442935 :   if (counted_by_ref)
    3341          661 :     ref = build_access_with_size_for_counted_by (loc, ref,
    3342              :                                                  counted_by_ref,
    3343              :                                                  counted_by_type);
    3344              :   return ref;
    3345              : }
    3346              : 
    3347              : /* Make an expression to refer to the COMPONENT field of structure or
    3348              :    union value DATUM.  COMPONENT is an IDENTIFIER_NODE.  LOC is the
    3349              :    location of the COMPONENT_REF.  COMPONENT_LOC is the location
    3350              :    of COMPONENT.  ARROW_LOC is the location of the first -> operand if
    3351              :    it is from -> operator.
    3352              :    If HANDLE_COUNTED_BY is true, check the counted_by attribute and generate
    3353              :    a call to .ACCESS_WITH_SIZE.  Otherwise, ignore the attribute.  */
    3354              : 
    3355              : tree
    3356      2287234 : build_component_ref (location_t loc, tree datum, tree component,
    3357              :                      location_t component_loc, location_t arrow_loc)
    3358              : {
    3359      2287234 :   tree type = TREE_TYPE (datum);
    3360      2287234 :   enum tree_code code = TREE_CODE (type);
    3361      2287234 :   tree field = NULL;
    3362      2287234 :   tree ref;
    3363      2287234 :   bool datum_lvalue = lvalue_p (datum);
    3364              : 
    3365      2287234 :   if (!objc_is_public (datum, component))
    3366            0 :     return error_mark_node;
    3367              : 
    3368              :   /* Detect Objective-C property syntax object.property.  */
    3369      2287234 :   if (c_dialect_objc ()
    3370      2287234 :       && (ref = objc_maybe_build_component_ref (datum, component)))
    3371              :     return ref;
    3372              : 
    3373              :   /* See if there is a field or component with name COMPONENT.  */
    3374              : 
    3375      2287234 :   if (code == RECORD_TYPE || code == UNION_TYPE)
    3376              :     {
    3377      2287162 :       if (!COMPLETE_TYPE_P (type))
    3378              :         {
    3379           19 :           c_incomplete_type_error (loc, NULL_TREE, type);
    3380           19 :           return error_mark_node;
    3381              :         }
    3382              : 
    3383      2287143 :       field = lookup_field (type, component);
    3384              : 
    3385      2287143 :       if (!field)
    3386              :         {
    3387           63 :           tree guessed_id = lookup_field_fuzzy (type, component);
    3388           63 :           if (guessed_id)
    3389              :             {
    3390              :               /* Attempt to provide a fixit replacement hint, if
    3391              :                  we have a valid range for the component.  */
    3392            0 :               location_t reported_loc
    3393           26 :                 = (component_loc != UNKNOWN_LOCATION) ? component_loc : loc;
    3394           26 :               gcc_rich_location rich_loc (reported_loc);
    3395           26 :               if (component_loc != UNKNOWN_LOCATION)
    3396           26 :                 rich_loc.add_fixit_misspelled_id (component_loc, guessed_id);
    3397           26 :               error_at (&rich_loc,
    3398              :                         "%qT has no member named %qE; did you mean %qE?",
    3399              :                         type, component, guessed_id);
    3400           26 :             }
    3401              :           else
    3402           37 :             error_at (loc, "%qT has no member named %qE", type, component);
    3403           63 :           return error_mark_node;
    3404              :         }
    3405              : 
    3406              :       /* Accessing elements of atomic structures or unions is undefined
    3407              :          behavior (C11 6.5.2.3#5).  */
    3408      2287080 :       if (TYPE_ATOMIC (type) && c_inhibit_evaluation_warnings == 0)
    3409              :         {
    3410           18 :           if (code == RECORD_TYPE)
    3411           12 :             warning_at (loc, 0, "accessing a member %qE of an atomic "
    3412              :                         "structure %qE", component, datum);
    3413              :           else
    3414            6 :             warning_at (loc, 0, "accessing a member %qE of an atomic "
    3415              :                         "union %qE", component, datum);
    3416              :         }
    3417              : 
    3418              :       /* Chain the COMPONENT_REFs if necessary down to the FIELD.
    3419              :          This might be better solved in future the way the C++ front
    3420              :          end does it - by giving the anonymous entities each a
    3421              :          separate name and type, and then have build_component_ref
    3422              :          recursively call itself.  We can't do that here.  */
    3423      2289353 :       do
    3424              :         {
    3425      2289353 :           tree subdatum = TREE_VALUE (field);
    3426      2289353 :           qualifier_set quals;
    3427      2289353 :           tree subtype;
    3428      2289353 :           bool use_datum_quals;
    3429              : 
    3430      2289353 :           if (TREE_TYPE (subdatum) == error_mark_node)
    3431      2287234 :             return error_mark_node;
    3432              : 
    3433              :           /* If this is an rvalue, it does not have qualifiers in C
    3434              :              standard terms and we must avoid propagating such
    3435              :              qualifiers down to a non-lvalue array that is then
    3436              :              converted to a pointer.  */
    3437      4578706 :           use_datum_quals = (datum_lvalue
    3438      2289353 :                              || TREE_CODE (TREE_TYPE (subdatum)) != ARRAY_TYPE);
    3439              : 
    3440      2289353 :           quals = TYPE_QUALS (strip_array_types (TREE_TYPE (subdatum)));
    3441      2289353 :           if (use_datum_quals)
    3442              :             {
    3443              :               /* SUBDATUM refers to a field, which lack their own address
    3444              :                  space.  */
    3445      2289091 :               gcc_assert (ADDR_SPACE_GENERIC_P (quals.addr_space ()));
    3446      2289091 :               addr_space_t datum_as;
    3447      2289091 :               cv_qualifier datum_cv;
    3448      2289091 :               std::tie (datum_cv, datum_as)
    3449      2289091 :                 = TYPE_QUALS (TREE_TYPE (datum)).split ();
    3450      2289091 :               quals |= datum_cv;
    3451      2289091 :               quals.set_as (datum_as);
    3452              :             }
    3453      2289353 :           subtype = c_build_qualified_type (TREE_TYPE (subdatum), quals);
    3454              : 
    3455      2289353 :           ref = build3 (COMPONENT_REF, subtype, datum, subdatum,
    3456              :                         NULL_TREE);
    3457      2289353 :           SET_EXPR_LOCATION (ref, loc);
    3458              : 
    3459      2289353 :           check_counted_by_attribute (loc, ref);
    3460              : 
    3461      2289353 :           if (TREE_READONLY (subdatum)
    3462      2289353 :               || (use_datum_quals && TREE_READONLY (datum)))
    3463        30912 :             TREE_READONLY (ref) = 1;
    3464      2289353 :           if (TREE_THIS_VOLATILE (subdatum)
    3465      2288327 :               || (use_datum_quals && TREE_THIS_VOLATILE (datum)))
    3466         2476 :             TREE_THIS_VOLATILE (ref) = 1;
    3467              : 
    3468      2289353 :           if (TREE_UNAVAILABLE (subdatum))
    3469           10 :             error_unavailable_use (subdatum, NULL_TREE);
    3470      2289343 :           else if (TREE_DEPRECATED (subdatum))
    3471           16 :             warn_deprecated_use (subdatum, NULL_TREE);
    3472              : 
    3473      2289353 :           datum = ref;
    3474              : 
    3475      2289353 :           field = TREE_CHAIN (field);
    3476              :         }
    3477      2289353 :       while (field);
    3478              : 
    3479              :       return ref;
    3480              :     }
    3481           72 :   else if (should_suggest_deref_p (type))
    3482              :     {
    3483              :       /* Special-case the error message for "ptr.field" for the case
    3484              :          where the user has confused "." vs "->".  */
    3485            7 :       rich_location richloc (line_table, loc);
    3486            7 :       if (INDIRECT_REF_P (datum) && arrow_loc != UNKNOWN_LOCATION)
    3487              :         {
    3488            2 :           richloc.add_fixit_insert_before (arrow_loc, "(*");
    3489            2 :           richloc.add_fixit_insert_after (arrow_loc, ")");
    3490            2 :           error_at (&richloc,
    3491              :                     "%qE is a pointer to pointer; did you mean to dereference "
    3492              :                     "it before applying %<->%> to it?",
    3493            2 :                     TREE_OPERAND (datum, 0));
    3494              :         }
    3495              :       else
    3496              :         {
    3497              :           /* "loc" should be the "." token.  */
    3498            5 :           richloc.add_fixit_replace ("->");
    3499            5 :           error_at (&richloc,
    3500              :                     "%qE is a pointer; did you mean to use %<->%>?",
    3501              :                     datum);
    3502              :         }
    3503            7 :       return error_mark_node;
    3504            7 :     }
    3505           65 :   else if (code != ERROR_MARK)
    3506            1 :     error_at (loc,
    3507              :               "request for member %qE in something not a structure or union",
    3508              :               component);
    3509              : 
    3510           65 :   return error_mark_node;
    3511              : }
    3512              : 
    3513              : /* Given an expression PTR for a pointer, return an expression
    3514              :    for the value pointed to.
    3515              :    ERRORSTRING is the name of the operator to appear in error messages.
    3516              : 
    3517              :    LOC is the location to use for the generated tree.  */
    3518              : 
    3519              : tree
    3520      2780856 : build_indirect_ref (location_t loc, tree ptr, ref_operator errstring)
    3521              : {
    3522      2780856 :   tree pointer = default_conversion (ptr);
    3523      2780856 :   tree type = TREE_TYPE (pointer);
    3524      2780856 :   tree ref;
    3525              : 
    3526      2780856 :   if (TREE_CODE (type) == POINTER_TYPE)
    3527              :     {
    3528      2780502 :       if (CONVERT_EXPR_P (pointer)
    3529      1995100 :           || TREE_CODE (pointer) == VIEW_CONVERT_EXPR)
    3530              :         {
    3531              :           /* If a warning is issued, mark it to avoid duplicates from
    3532              :              the backend.  This only needs to be done at
    3533              :              warn_strict_aliasing > 2.  */
    3534       785402 :           if (warn_strict_aliasing > 2)
    3535       335156 :             if (strict_aliasing_warning (EXPR_LOCATION (pointer),
    3536       335156 :                                          type, TREE_OPERAND (pointer, 0)))
    3537            8 :               suppress_warning (pointer, OPT_Wstrict_aliasing_);
    3538              :         }
    3539              : 
    3540      2780502 :       if (TREE_CODE (pointer) == ADDR_EXPR
    3541      2780502 :           && (TREE_TYPE (TREE_OPERAND (pointer, 0))
    3542        67506 :               == TREE_TYPE (type)))
    3543              :         {
    3544        67497 :           ref = TREE_OPERAND (pointer, 0);
    3545        67497 :           protected_set_expr_location (ref, loc);
    3546        67497 :           return ref;
    3547              :         }
    3548              :       else
    3549              :         {
    3550      2713005 :           tree t = TREE_TYPE (type);
    3551              : 
    3552      2713005 :           ref = build1 (INDIRECT_REF, t, pointer);
    3553              : 
    3554      2713005 :           if (VOID_TYPE_P (t) && c_inhibit_evaluation_warnings == 0)
    3555          151 :             warning_at (loc, 0, "dereferencing %<void *%> pointer");
    3556              : 
    3557              :           /* We *must* set TREE_READONLY when dereferencing a pointer to const,
    3558              :              so that we get the proper error message if the result is used
    3559              :              to assign to.  Also, &* is supposed to be a no-op.
    3560              :              And ANSI C seems to specify that the type of the result
    3561              :              should be the const type.  */
    3562              :           /* A de-reference of a pointer to const is not a const.  It is valid
    3563              :              to change it via some other pointer.  */
    3564      2713005 :           TREE_READONLY (ref) = TYPE_READONLY (t);
    3565      2713005 :           TREE_SIDE_EFFECTS (ref)
    3566      2713005 :             = TYPE_VOLATILE (t) || TREE_SIDE_EFFECTS (pointer);
    3567      2713005 :           TREE_THIS_VOLATILE (ref) = TYPE_VOLATILE (t);
    3568      2713005 :           protected_set_expr_location (ref, loc);
    3569      2713005 :           return ref;
    3570              :         }
    3571              :     }
    3572          354 :   else if (TREE_CODE (pointer) != ERROR_MARK)
    3573          278 :     invalid_indirection_error (loc, type, errstring);
    3574              : 
    3575          354 :   return error_mark_node;
    3576              : }
    3577              : 
    3578              : /* This handles expressions of the form "a[i]", which denotes
    3579              :    an array reference.
    3580              : 
    3581              :    This is logically equivalent in C to *(a+i), but we may do it differently.
    3582              :    If A is a variable or a member, we generate a primitive ARRAY_REF.
    3583              :    This avoids forcing the array out of registers, and can work on
    3584              :    arrays that are not lvalues (for example, members of structures returned
    3585              :    by functions).
    3586              : 
    3587              :    For vector types, allow vector[i] but not i[vector], and create
    3588              :    *(((type*)&vectortype) + i) for the expression.
    3589              : 
    3590              :    LOC is the location to use for the returned expression.  */
    3591              : 
    3592              : tree
    3593      3565849 : build_array_ref (location_t loc, tree array, tree index)
    3594              : {
    3595      3565849 :   tree ret;
    3596      3565849 :   bool swapped = false;
    3597      3565849 :   if (TREE_TYPE (array) == error_mark_node
    3598      3565849 :       || TREE_TYPE (index) == error_mark_node)
    3599              :     return error_mark_node;
    3600              : 
    3601      3565741 :   if (TREE_CODE (TREE_TYPE (array)) != ARRAY_TYPE
    3602      2018314 :       && TREE_CODE (TREE_TYPE (array)) != POINTER_TYPE
    3603              :       /* Allow vector[index] but not index[vector].  */
    3604      4600832 :       && !gnu_vector_type_p (TREE_TYPE (array)))
    3605              :     {
    3606          194 :       if (TREE_CODE (TREE_TYPE (index)) != ARRAY_TYPE
    3607          194 :           && TREE_CODE (TREE_TYPE (index)) != POINTER_TYPE)
    3608              :         {
    3609            2 :           error_at (loc,
    3610              :             "subscripted value is neither array nor pointer nor vector");
    3611              : 
    3612            2 :           return error_mark_node;
    3613              :         }
    3614          192 :       std::swap (array, index);
    3615          192 :       swapped = true;
    3616              :     }
    3617              : 
    3618      3565739 :   if (!INTEGRAL_TYPE_P (TREE_TYPE (index)))
    3619              :     {
    3620            2 :       error_at (loc, "array subscript is not an integer");
    3621            2 :       return error_mark_node;
    3622              :     }
    3623              : 
    3624      3565737 :   if (TREE_CODE (TREE_TYPE (TREE_TYPE (array))) == FUNCTION_TYPE)
    3625              :     {
    3626           10 :       error_at (loc, "subscripted value is pointer to function");
    3627           10 :       return error_mark_node;
    3628              :     }
    3629              : 
    3630              :   /* ??? Existing practice has been to warn only when the char
    3631              :      index is syntactically the index, not for char[array].  */
    3632      3565727 :   if (!swapped)
    3633      3565541 :      warn_array_subscript_with_type_char (loc, index);
    3634              : 
    3635              :   /* Apply default promotions *after* noticing character types.  */
    3636      3565727 :   index = default_conversion (index);
    3637      3565727 :   if (index == error_mark_node)
    3638              :     return error_mark_node;
    3639              : 
    3640      3565726 :   gcc_assert (TREE_CODE (TREE_TYPE (index)) == INTEGER_TYPE
    3641              :               || TREE_CODE (TREE_TYPE (index)) == BITINT_TYPE);
    3642              : 
    3643      3565726 :   bool was_vector = VECTOR_TYPE_P (TREE_TYPE (array));
    3644      3565726 :   bool non_lvalue = convert_vector_to_array_for_subscript (loc, &array, index);
    3645              : 
    3646              :   /* We only generate a call to .ACCESS_WITH_SIZE when it is a read.  */
    3647      3565726 :   if (TREE_CODE (array) == COMPONENT_REF
    3648      3565726 :       && handle_counted_by_p (array))
    3649       818210 :     array = handle_counted_by_for_component_ref (loc, array);
    3650              : 
    3651      3565726 :   if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE)
    3652              :     {
    3653      2582331 :       tree rval, type;
    3654              : 
    3655              :       /* An array that is indexed by a non-constant
    3656              :          cannot be stored in a register; we must be able to do
    3657              :          address arithmetic on its address.
    3658              :          Likewise an array of elements of variable size.  */
    3659      2582331 :       if (TREE_CODE (index) != INTEGER_CST
    3660      2582331 :           || (COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (array)))
    3661      2096589 :               && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array)))) != INTEGER_CST))
    3662              :         {
    3663       486482 :           if (!c_mark_addressable (array, true, true))
    3664            1 :             return error_mark_node;
    3665              :         }
    3666              :       /* An array that is indexed by a constant value which is not within
    3667              :          the array bounds cannot be stored in a register either; because we
    3668              :          would get a crash in store_bit_field/extract_bit_field when trying
    3669              :          to access a non-existent part of the register.  */
    3670      2582330 :       if (TREE_CODE (index) == INTEGER_CST
    3671      2096589 :           && TYPE_DOMAIN (TREE_TYPE (array))
    3672      4675560 :           && !int_fits_type_p (index, TYPE_DOMAIN (TREE_TYPE (array))))
    3673              :         {
    3674        60657 :           if (!c_mark_addressable (array, false, true))
    3675            0 :             return error_mark_node;
    3676              :           /* ISO C2Y disallows a negative integer constant expression index
    3677              :              when array subscripting has an operand of array type.  */
    3678        60657 :           if (flag_isoc2y
    3679           26 :               && !TREE_OVERFLOW (index)
    3680        60680 :               && tree_int_cst_sgn (index) < 0)
    3681           10 :             error_at (loc, "array subscript is negative");
    3682              :         }
    3683              : 
    3684      2582330 :       if ((pedantic || warn_c90_c99_compat || warn_c23_c2y_compat)
    3685      2558773 :           && ! was_vector)
    3686              :         {
    3687      1546705 :           tree foo = array;
    3688      2383780 :           while (TREE_CODE (foo) == COMPONENT_REF)
    3689       837075 :             foo = TREE_OPERAND (foo, 0);
    3690      1045732 :           if ((VAR_P (foo) && C_DECL_REGISTER (foo))
    3691      2592371 :               || (TREE_CODE (foo) == COMPOUND_LITERAL_EXPR
    3692           72 :                   && C_DECL_REGISTER (COMPOUND_LITERAL_EXPR_DECL (foo))))
    3693           78 :             pedwarn_c23 (loc, OPT_Wpedantic,
    3694              :                          "ISO C forbids subscripting %<register%> array "
    3695              :                          "before C2Y");
    3696      1546627 :           else if (!lvalue_p (foo))
    3697          118 :             pedwarn_c90 (loc, OPT_Wpedantic,
    3698              :                          "ISO C90 forbids subscripting non-lvalue "
    3699              :                          "array");
    3700              :         }
    3701              : 
    3702      2582330 :       if (TREE_CODE (TREE_TYPE (index)) == BITINT_TYPE
    3703      2582330 :           && TYPE_PRECISION (TREE_TYPE (index)) > TYPE_PRECISION (sizetype))
    3704            3 :         index = fold_convert (sizetype, index);
    3705              : 
    3706      2582330 :       type = TREE_TYPE (TREE_TYPE (array));
    3707      2582330 :       rval = build4 (ARRAY_REF, type, array, index, NULL_TREE, NULL_TREE);
    3708              :       /* Array ref is const/volatile if the array elements are
    3709              :          or if the array is.  */
    3710      7746990 :       TREE_READONLY (rval)
    3711      2582330 :         |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array)))
    3712      2582330 :             | TREE_READONLY (array));
    3713      7746990 :       TREE_SIDE_EFFECTS (rval)
    3714      2582330 :         |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
    3715      2582330 :             | TREE_SIDE_EFFECTS (array));
    3716      5164660 :       TREE_THIS_VOLATILE (rval)
    3717      2582330 :         |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
    3718              :             /* This was added by rms on 16 Nov 91.
    3719              :                It fixes  vol struct foo *a;  a->elts[1]
    3720              :                in an inline function.
    3721              :                Hope it doesn't break something else.  */
    3722      2582330 :             | TREE_THIS_VOLATILE (array));
    3723      2582330 :       ret = require_complete_type (loc, rval);
    3724      2582330 :       protected_set_expr_location (ret, loc);
    3725      2582330 :       if (non_lvalue)
    3726       106094 :         ret = non_lvalue_loc (loc, ret);
    3727              :       return ret;
    3728              :     }
    3729              :   else
    3730              :     {
    3731       983395 :       tree ar = default_conversion (array);
    3732              : 
    3733       983395 :       if (ar == error_mark_node)
    3734              :         return ar;
    3735              : 
    3736       983395 :       gcc_assert (TREE_CODE (TREE_TYPE (ar)) == POINTER_TYPE);
    3737       983395 :       gcc_assert (TREE_CODE (TREE_TYPE (TREE_TYPE (ar))) != FUNCTION_TYPE);
    3738              : 
    3739       983395 :       ret = build_indirect_ref (loc, build_binary_op (loc, PLUS_EXPR, ar,
    3740              :                                                       index, false),
    3741              :                                 RO_ARRAY_INDEXING);
    3742       983395 :       if (non_lvalue)
    3743            0 :         ret = non_lvalue_loc (loc, ret);
    3744              :       return ret;
    3745              :     }
    3746              : }
    3747              : 
    3748              : /* Build an OpenMP array section reference, creating an exact type for the
    3749              :    resulting expression based on the element type and bounds if possible.  If
    3750              :    we have variable bounds, create an incomplete array type for the result
    3751              :    instead.  */
    3752              : 
    3753              : tree
    3754         3984 : build_omp_array_section (location_t loc, tree array, tree index, tree length)
    3755              : {
    3756         3984 :   tree type = TREE_TYPE (array);
    3757         3984 :   gcc_assert (type);
    3758              : 
    3759         3984 :   tree sectype, eltype = TREE_TYPE (type);
    3760              : 
    3761              :   /* It's not an array or pointer type.  Just reuse the type of the original
    3762              :      expression as the type of the array section (an error will be raised
    3763              :      anyway, later).  */
    3764         3984 :   if (eltype == NULL_TREE || error_operand_p (eltype))
    3765           12 :     sectype = TREE_TYPE (array);
    3766              :   else
    3767              :     {
    3768         3972 :       tree idxtype = NULL_TREE;
    3769              : 
    3770         3972 :       if (index != NULL_TREE
    3771         3972 :           && length != NULL_TREE
    3772         3032 :           && INTEGRAL_TYPE_P (TREE_TYPE (index))
    3773         6999 :           && INTEGRAL_TYPE_P (TREE_TYPE (length)))
    3774              :         {
    3775         3020 :           tree low = fold_convert (sizetype, index);
    3776         3020 :           tree high = fold_convert (sizetype, length);
    3777         3020 :           high = size_binop (PLUS_EXPR, low, high);
    3778         3020 :           high = size_binop (MINUS_EXPR, high, size_one_node);
    3779         3020 :           idxtype = build_range_type (sizetype, low, high);
    3780              :         }
    3781          137 :       else if ((index == NULL_TREE || integer_zerop (index))
    3782          840 :                && length != NULL_TREE
    3783         1638 :                && INTEGRAL_TYPE_P (TREE_TYPE (length)))
    3784          669 :         idxtype = build_index_type (length);
    3785              : 
    3786         3972 :       gcc_assert (!error_operand_p (idxtype));
    3787              : 
    3788         3972 :       sectype = c_build_array_type (eltype, idxtype);
    3789              :     }
    3790              : 
    3791         3984 :   return build3_loc (loc, OMP_ARRAY_SECTION, sectype, array, index, length);
    3792              : }
    3793              : 
    3794              : 
    3795              : /* Record that REF is used.  This is relevant for undeclared static
    3796              :    function and declarations referenced from a non-local context.
    3797              :    ADDRESS indicates whether the address is taken.  */
    3798              : 
    3799              : void
    3800    491554771 : mark_decl_used (tree ref, bool address)
    3801              : {
    3802    491554771 :   if (!ref || !DECL_P (ref) || in_alignof)
    3803              :     return;
    3804              : 
    3805              :   /* Non-file-scope and non-local reference in nested function.  */
    3806    360553273 :   bool nonloc_p = current_function_decl && DECL_CONTEXT (ref)
    3807    125595815 :                   && DECL_CONTEXT (current_function_decl)
    3808    491520573 :                   && DECL_CONTEXT (ref) != current_function_decl;
    3809              : 
    3810              :   /* An undeclared static function.  */
    3811    491510446 :   bool static_p = TREE_CODE (ref) == FUNCTION_DECL
    3812    105879989 :                   && DECL_INITIAL (ref) == NULL_TREE
    3813     72361413 :                   && DECL_EXTERNAL (ref)
    3814    563869163 :                   && !TREE_PUBLIC (ref);
    3815              : 
    3816    491376586 :   if (!static_p && !nonloc_p)
    3817              :     return;
    3818              : 
    3819              :   /* If we may be in an unevaluated context, delay the decision.  */
    3820       136524 :   if (in_sizeof || in_typeof || in_countof || in_generic)
    3821          273 :     return record_maybe_used_decl (ref, address);
    3822              : 
    3823       136251 :   if (static_p)
    3824       133604 :     C_DECL_USED (ref) = 1;
    3825              : 
    3826       136251 :   if (nonloc_p && (VAR_OR_FUNCTION_DECL_P (ref)
    3827              :                    || TREE_CODE (ref) == PARM_DECL))
    3828         2066 :     DECL_NONLOCAL (ref) = 1;
    3829              : 
    3830              :   /* Nothing to do anymore.  */
    3831         2647 :   if (!nonloc_p)
    3832              :     return;
    3833              : 
    3834              :   /* Even when this function is already marked as requiring a non-local
    3835              :      context we need to do the check because we may need to mark more
    3836              :      parents.  */
    3837              : 
    3838              :   /* Filter out the cases where referencing a non-local variable does not
    3839              :      require a non-local context passed via the static chain.  */
    3840         2647 :   if (!c_type_variably_modified_p (TREE_TYPE (ref)))
    3841         2531 :     switch (TREE_CODE (ref))
    3842              :       {
    3843          435 :       case FUNCTION_DECL:
    3844              :         /* Use of another local function that requires no context is ok.  */
    3845          435 :         if (!C_FUNC_NONLOCAL_CONTEXT (ref) && DECL_INITIAL (ref))
    3846              :           return;
    3847              :         break;
    3848         1379 :       case VAR_DECL:
    3849              :         /* Static variables and constexpr are ok, but for the later only
    3850              :            when the address is not taken.  */
    3851         1379 :         if (TREE_STATIC (ref) || (C_DECL_DECLARED_CONSTEXPR (ref) && !address))
    3852              :           return;
    3853              :         break;
    3854              :       case TYPE_DECL:
    3855              :         /* A typedef is ok when not for a variably-modified type. */
    3856              :         return;
    3857              :       case CONST_DECL:
    3858              :         /* An enumeration constant is ok. */
    3859              :         return;
    3860              :       case PARM_DECL:
    3861              :         break;
    3862              :       case LABEL_DECL:
    3863              :         break;
    3864            0 :       default:
    3865            0 :         gcc_unreachable ();
    3866              :     }
    3867              : 
    3868              :   /* Mark all parent functions up to the nesting level of the variable as
    3869              :      as needing the non-local context.  */
    3870         4962 :   for (tree cont = current_function_decl; cont; cont = DECL_CONTEXT (cont))
    3871              :     {
    3872         4962 :       if (cont == DECL_CONTEXT (ref))
    3873              :         break;
    3874              : 
    3875              :       /* There should not be any other type of context used for function
    3876              :          except TRANSLATION_UNIT_DECL which we should be able to reach.  */
    3877         2528 :       gcc_checking_assert (TREE_CODE (cont) == FUNCTION_DECL);
    3878              : 
    3879         2528 :       if (TREE_CODE (cont) == FUNCTION_DECL)
    3880         2528 :         C_FUNC_NONLOCAL_CONTEXT (cont) = 1;
    3881              :     }
    3882              : }
    3883              : 
    3884              : 
    3885              : /* Build an external reference to identifier ID.  FUN indicates
    3886              :    whether this will be used for a function call.  LOC is the source
    3887              :    location of the identifier.  This sets *TYPE to the type of the
    3888              :    identifier, which is not the same as the type of the returned value
    3889              :    for CONST_DECLs defined as enum constants.  If the type of the
    3890              :    identifier is not available, *TYPE is set to NULL.  */
    3891              : tree
    3892    180422721 : build_external_ref (location_t loc, tree id, bool fun, tree *type)
    3893              : {
    3894    180422721 :   tree ref;
    3895    180422721 :   tree decl = lookup_name (id);
    3896              : 
    3897              :   /* In Objective-C, an instance variable (ivar) may be preferred to
    3898              :      whatever lookup_name() found.  */
    3899    180422721 :   decl = objc_lookup_ivar (decl, id);
    3900              : 
    3901    180422721 :   *type = NULL;
    3902    180422721 :   if (decl && decl != error_mark_node)
    3903              :     {
    3904    180416520 :       ref = decl;
    3905    180416520 :       *type = TREE_TYPE (ref);
    3906    180416520 :       if (DECL_P (decl) && C_DECL_UNDERSPECIFIED (decl))
    3907            4 :         error_at (loc, "underspecified %qD referenced in its initializer",
    3908              :                   decl);
    3909              :     }
    3910         6201 :   else if (fun)
    3911              :     /* Implicit function declaration.  */
    3912         4730 :     ref = implicitly_declare (loc, id);
    3913         1471 :   else if (decl == error_mark_node)
    3914              :     /* Don't complain about something that's already been
    3915              :        complained about.  */
    3916              :     return error_mark_node;
    3917              :   else
    3918              :     {
    3919         1235 :       undeclared_variable (loc, id);
    3920         1235 :       return error_mark_node;
    3921              :     }
    3922              : 
    3923              :   /* For an OpenMP map clause, we can get better diagnostics for decls with
    3924              :      unmappable types if we return the decl with an error_mark_node type,
    3925              :      rather than returning error_mark_node for the decl itself.  */
    3926    180421250 :   if (TREE_TYPE (ref) == error_mark_node
    3927    180421250 :       && !c_omp_array_section_p)
    3928              :     return error_mark_node;
    3929              : 
    3930    180421232 :   if (TREE_UNAVAILABLE (ref))
    3931           14 :     error_unavailable_use (ref, NULL_TREE);
    3932    180421218 :   else if (TREE_DEPRECATED (ref))
    3933          100 :     warn_deprecated_use (ref, NULL_TREE);
    3934              : 
    3935              :   /* Recursive call does not count as usage.  */
    3936    180421232 :   if (ref != current_function_decl)
    3937              :     {
    3938    180418532 :       TREE_USED (ref) = 1;
    3939              :     }
    3940              : 
    3941    180421232 :   mark_decl_used (ref, false);
    3942              : 
    3943    180421232 :   if (TREE_CODE (ref) == CONST_DECL)
    3944              :     {
    3945       425131 :       used_types_insert (TREE_TYPE (ref));
    3946              : 
    3947       425131 :       if (warn_cxx_compat
    3948          433 :           && TREE_CODE (TREE_TYPE (ref)) == ENUMERAL_TYPE
    3949       425562 :           && C_TYPE_DEFINED_IN_STRUCT (TREE_TYPE (ref)))
    3950              :         {
    3951            1 :           warning_at (loc, OPT_Wc___compat,
    3952              :                       "enum constant defined in struct or union "
    3953              :                       "is not visible in C++");
    3954            1 :           inform (DECL_SOURCE_LOCATION (ref), "enum constant defined here");
    3955              :         }
    3956              : 
    3957       425131 :       ref = DECL_INITIAL (ref);
    3958       425131 :       TREE_CONSTANT (ref) = 1;
    3959              :     }
    3960              :   /* C99 6.7.4p3: An inline definition of a function with external
    3961              :      linkage ... shall not contain a reference to an identifier with
    3962              :      internal linkage.  */
    3963    179996101 :   else if (current_function_decl != NULL_TREE
    3964    178480524 :            && DECL_DECLARED_INLINE_P (current_function_decl)
    3965    164561876 :            && DECL_EXTERNAL (current_function_decl)
    3966    163753247 :            && VAR_OR_FUNCTION_DECL_P (ref)
    3967     58538977 :            && (!VAR_P (ref) || TREE_STATIC (ref))
    3968     49300480 :            && ! TREE_PUBLIC (ref)
    3969    179996135 :            && DECL_CONTEXT (ref) != current_function_decl)
    3970           25 :     record_inline_static (loc, current_function_decl, ref,
    3971              :                           csi_internal);
    3972              : 
    3973              :   return ref;
    3974              : }
    3975              : 
    3976              : static struct maybe_used_decl *maybe_used_decls;
    3977              : 
    3978              : /* Record that DECL, a reference seen inside sizeof or typeof or _Countof or
    3979              :    _Generic, might be used if the operand of sizeof is a VLA type or the
    3980              :    operand of typeof is a variably modified type or the operand of _Countof has
    3981              :    a variable number of elements or the operand of _Generic is the one selected
    3982              :    as the result.  */
    3983              : 
    3984              : static void
    3985          273 : record_maybe_used_decl (tree decl, bool address)
    3986              : {
    3987          273 :   struct maybe_used_decl *t = XOBNEW (&parser_obstack, struct maybe_used_decl);
    3988          273 :   t->decl = decl;
    3989          273 :   t->level = in_sizeof + in_typeof + in_countof + in_generic;
    3990          273 :   t->address = address;
    3991          273 :   t->next = maybe_used_decls;
    3992          273 :   maybe_used_decls = t;
    3993          273 : }
    3994              : 
    3995              : /* Pop the stack of decls possibly used inside sizeof or typeof or _Countof or
    3996              :    _Generic.  If USED is false, just discard them.  If it is true, mark them
    3997              :    used (if no longer inside sizeof or typeof or _Countof or _Generic) or move
    3998              :    them to the next level up (if still inside sizeof or typeof or _Countof or
    3999              :    _Generic).  */
    4000              : 
    4001              : void
    4002      1475223 : pop_maybe_used (bool used)
    4003              : {
    4004      1475223 :   struct maybe_used_decl *p = maybe_used_decls;
    4005      1475223 :   int cur_level = in_sizeof + in_typeof + in_countof + in_generic;
    4006      1475520 :   while (p && p->level > cur_level)
    4007              :     {
    4008          297 :       if (used)
    4009              :         {
    4010           77 :           if (cur_level == 0)
    4011           53 :             mark_decl_used (p->decl, p->address);
    4012              :           else
    4013           24 :             p->level = cur_level;
    4014              :         }
    4015          297 :       p = p->next;
    4016              :     }
    4017      1475223 :   if (!used || cur_level == 0)
    4018      1475142 :     maybe_used_decls = p;
    4019      1475223 : }
    4020              : 
    4021              : /* Pop the stack of decls possibly used inside sizeof or typeof or _Countof or
    4022              :    _Generic, without acting on them, and return the pointer to the previous top
    4023              :    of the stack.  This for use at the end of a default generic association when
    4024              :    it is not yet known whether the expression is used.  If it later turns out
    4025              :    the expression is used (or treated as used before C23), restore_maybe_used
    4026              :    should be called on the return value followed by pop_maybe_used (true);
    4027              :    otherwise, the return value can be discarded.  */
    4028              : 
    4029              : struct maybe_used_decl *
    4030         1210 : save_maybe_used ()
    4031              : {
    4032         1210 :   struct maybe_used_decl *p = maybe_used_decls, *orig = p;
    4033         1210 :   int cur_level = in_sizeof + in_typeof + in_countof + in_generic;
    4034         1242 :   while (p && p->level > cur_level)
    4035           32 :     p = p->next;
    4036         1210 :   maybe_used_decls = p;
    4037         1210 :   return orig;
    4038              : }
    4039              : 
    4040              : /* Restore the stack of decls possibly used inside sizeof or typeof or _Countof
    4041              :    or _Generic returned by save_maybe_used.  It is required that the stack is
    4042              :    at exactly the point where it was left by save_maybe_used.  */
    4043              : 
    4044              : void
    4045          279 : restore_maybe_used (struct maybe_used_decl *stack)
    4046              : {
    4047          279 :   maybe_used_decls = stack;
    4048          279 : }
    4049              : 
    4050              : /* Return the result of sizeof applied to EXPR.  */
    4051              : 
    4052              : struct c_expr
    4053       315271 : c_expr_sizeof_expr (location_t loc, struct c_expr expr)
    4054              : {
    4055       315271 :   struct c_expr ret;
    4056       315271 :   if (expr.value == error_mark_node)
    4057              :     {
    4058          111 :       ret.value = error_mark_node;
    4059          111 :       ret.original_code = ERROR_MARK;
    4060          111 :       ret.original_type = NULL;
    4061          111 :       ret.m_decimal = 0;
    4062          111 :       pop_maybe_used (false);
    4063              :     }
    4064              :   else
    4065              :     {
    4066       315160 :       bool expr_const_operands = true;
    4067              : 
    4068       315160 :       if (TREE_CODE (expr.value) == PARM_DECL
    4069       315160 :           && C_ARRAY_PARAMETER (expr.value))
    4070              :         {
    4071           55 :           auto_diagnostic_group d;
    4072           55 :           if (warning_at (loc, OPT_Wsizeof_array_argument,
    4073              :                           "%<sizeof%> on array function parameter %qE will "
    4074              :                           "return size of %qT", expr.value,
    4075           55 :                           TREE_TYPE (expr.value)))
    4076           19 :             inform (DECL_SOURCE_LOCATION (expr.value), "declared here");
    4077           55 :         }
    4078       315160 :       tree folded_expr = c_fully_fold (expr.value, require_constant_value,
    4079              :                                        &expr_const_operands);
    4080       315160 :       ret.value = c_sizeof (loc, TREE_TYPE (folded_expr));
    4081       315160 :       c_last_sizeof_arg = expr.value;
    4082       315160 :       c_last_sizeof_loc = loc;
    4083       315160 :       ret.original_code = SIZEOF_EXPR;
    4084       315160 :       ret.original_type = NULL;
    4085       315160 :       ret.m_decimal = 0;
    4086       315160 :       if (C_TYPE_VARIABLE_SIZE (TREE_TYPE (folded_expr)))
    4087              :         {
    4088              :           /* sizeof is evaluated when given a vla (C99 6.5.3.4p2).  */
    4089          292 :           ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
    4090              :                               folded_expr, ret.value);
    4091          292 :           C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !expr_const_operands;
    4092          292 :           SET_EXPR_LOCATION (ret.value, loc);
    4093              :         }
    4094       315160 :       pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (folded_expr)));
    4095              :     }
    4096       315271 :   return ret;
    4097              : }
    4098              : 
    4099              : /* Return the result of sizeof applied to T, a structure for the type
    4100              :    name passed to sizeof (rather than the type itself).  LOC is the
    4101              :    location of the original expression.  */
    4102              : 
    4103              : struct c_expr
    4104       333642 : c_expr_sizeof_type (location_t loc, struct c_type_name *t)
    4105              : {
    4106       333642 :   tree type;
    4107       333642 :   struct c_expr ret;
    4108       333642 :   tree type_expr = NULL_TREE;
    4109       333642 :   bool type_expr_const = true;
    4110       333642 :   type = groktypename (t, &type_expr, &type_expr_const);
    4111       333642 :   ret.value = c_sizeof (loc, type);
    4112       333642 :   c_last_sizeof_arg = type;
    4113       333642 :   c_last_sizeof_loc = loc;
    4114       333642 :   ret.original_code = SIZEOF_EXPR;
    4115       333642 :   ret.original_type = NULL;
    4116       333642 :   ret.m_decimal = 0;
    4117       333642 :   if (type == error_mark_node)
    4118              :     {
    4119            5 :       ret.value = error_mark_node;
    4120            5 :       ret.original_code = ERROR_MARK;
    4121              :     }
    4122              :   else
    4123       333595 :   if ((type_expr || TREE_CODE (ret.value) == INTEGER_CST)
    4124       667147 :       && C_TYPE_VARIABLE_SIZE (type))
    4125              :     {
    4126              :       /* If the type is a [*] array, it is a VLA but is represented as
    4127              :          having a size of zero.  In such a case we must ensure that
    4128              :          the result of sizeof does not get folded to a constant by
    4129              :          c_fully_fold, because if the size is evaluated the result is
    4130              :          not constant and so constraints on zero or negative size
    4131              :          arrays must not be applied when this sizeof call is inside
    4132              :          another array declarator.  */
    4133           41 :       if (!type_expr)
    4134           16 :         type_expr = integer_zero_node;
    4135           41 :       ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
    4136              :                           type_expr, ret.value);
    4137           41 :       C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !type_expr_const;
    4138              :     }
    4139       333642 :   pop_maybe_used (type != error_mark_node
    4140       333642 :                   ? C_TYPE_VARIABLE_SIZE (type) : false);
    4141       333642 :   return ret;
    4142              : }
    4143              : 
    4144              : static bool
    4145      2167268 : top_array_vla_p (const_tree type)
    4146              : {
    4147      2167268 :   if (TREE_CODE (type) != ARRAY_TYPE)
    4148              :     return false;
    4149              : 
    4150      2167250 :   tree d = TYPE_DOMAIN (type);
    4151              : 
    4152      2167250 :   if (!d)
    4153              :     return false;
    4154      2072941 :   if (!TYPE_MAX_VALUE (d))
    4155              :     return false;
    4156              : 
    4157      1980584 :   return TREE_CODE (TYPE_MAX_VALUE (d)) != INTEGER_CST
    4158      1980584 :          || TREE_CODE (TYPE_MIN_VALUE (d)) != INTEGER_CST;
    4159              : }
    4160              : 
    4161              : /* Return the result of countof applied to EXPR.  */
    4162              : 
    4163              : struct c_expr
    4164           54 : c_expr_countof_expr (location_t loc, struct c_expr expr)
    4165              : {
    4166           54 :   struct c_expr ret;
    4167           54 :   if (expr.value == error_mark_node)
    4168              :     {
    4169            1 :       ret.value = error_mark_node;
    4170            1 :       ret.original_code = ERROR_MARK;
    4171            1 :       ret.original_type = NULL;
    4172            1 :       ret.m_decimal = 0;
    4173            1 :       pop_maybe_used (false);
    4174              :     }
    4175              :   else
    4176              :     {
    4177           53 :       bool expr_const_operands = true;
    4178              : 
    4179           53 :       tree folded_expr = c_fully_fold (expr.value, require_constant_value,
    4180              :                                        &expr_const_operands);
    4181           53 :       ret.value = c_countof_type (loc, TREE_TYPE (folded_expr));
    4182           53 :       c_last_sizeof_arg = expr.value;
    4183           53 :       c_last_sizeof_loc = loc;
    4184           53 :       ret.original_code = COUNTOF_EXPR;
    4185           53 :       ret.original_type = NULL;
    4186           53 :       ret.m_decimal = 0;
    4187           53 :       if (top_array_vla_p (TREE_TYPE (folded_expr)))
    4188              :         {
    4189              :           /* countof is evaluated when given a vla.  */
    4190           11 :           ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
    4191              :                               folded_expr, ret.value);
    4192           11 :           C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !expr_const_operands;
    4193           11 :           SET_EXPR_LOCATION (ret.value, loc);
    4194              :         }
    4195           53 :       pop_maybe_used (top_array_vla_p (TREE_TYPE (folded_expr)));
    4196              :     }
    4197           54 :   return ret;
    4198              : }
    4199              : 
    4200              : /* Return the result of countof applied to T, a structure for the type
    4201              :    name passed to countof (rather than the type itself).  LOC is the
    4202              :    location of the original expression.  */
    4203              : 
    4204              : struct c_expr
    4205           18 : c_expr_countof_type (location_t loc, struct c_type_name *t)
    4206              : {
    4207           18 :   tree type;
    4208           18 :   struct c_expr ret;
    4209           18 :   tree type_expr = NULL_TREE;
    4210           18 :   bool type_expr_const = true;
    4211           18 :   type = groktypename (t, &type_expr, &type_expr_const);
    4212           18 :   ret.value = c_countof_type (loc, type);
    4213           18 :   c_last_sizeof_arg = type;
    4214           18 :   c_last_sizeof_loc = loc;
    4215           18 :   ret.original_code = COUNTOF_EXPR;
    4216           18 :   ret.original_type = NULL;
    4217           18 :   ret.m_decimal = 0;
    4218           18 :   if (type == error_mark_node)
    4219              :     {
    4220            0 :       ret.value = error_mark_node;
    4221            0 :       ret.original_code = ERROR_MARK;
    4222              :     }
    4223              :   else
    4224            8 :   if ((type_expr || TREE_CODE (ret.value) == INTEGER_CST)
    4225           22 :       && top_array_vla_p (type))
    4226              :     {
    4227              :       /* If the type is a [*] array, it is a VLA but is represented as
    4228              :          having a size of zero.  In such a case we must ensure that
    4229              :          the result of countof does not get folded to a constant by
    4230              :          c_fully_fold, because if the number of elements is evaluated
    4231              :          the result is not constant and so
    4232              :          constraints on zero or negative size arrays must not be applied
    4233              :          when this countof call is inside another array declarator.  */
    4234            6 :       if (!type_expr)
    4235            0 :         type_expr = integer_zero_node;
    4236            6 :       ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
    4237              :                           type_expr, ret.value);
    4238            6 :       C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !type_expr_const;
    4239              :     }
    4240           18 :   pop_maybe_used (type != error_mark_node ? top_array_vla_p (type) : false);
    4241           18 :   return ret;
    4242              : }
    4243              : 
    4244              : /* Return the result of maxof applied to T, a structure for the type
    4245              :    name passed to maxof (rather than the type itself).  LOC is the
    4246              :    location of the original expression.  */
    4247              : 
    4248              : struct c_expr
    4249           46 : c_expr_maxof_type (location_t loc, struct c_type_name *t)
    4250              : {
    4251           46 :   tree type;
    4252           46 :   struct c_expr ret;
    4253           46 :   tree type_expr = NULL_TREE;
    4254           46 :   bool type_expr_const = true;
    4255           46 :   type = groktypename (t, &type_expr, &type_expr_const);
    4256           46 :   ret.value = c_maxof_type (loc, type);
    4257           46 :   c_last_sizeof_arg = type;
    4258           46 :   c_last_sizeof_loc = loc;
    4259           46 :   ret.original_code = MAXOF_EXPR;
    4260           46 :   ret.original_type = NULL;
    4261           46 :   ret.m_decimal = 0;
    4262           46 :   if (type == error_mark_node)
    4263              :     {
    4264            0 :       ret.value = error_mark_node;
    4265            0 :       ret.original_code = ERROR_MARK;
    4266              :     }
    4267           46 :   pop_maybe_used (type != error_mark_node);
    4268           46 :   return ret;
    4269              : }
    4270              : 
    4271              : /* Return the result of minof applied to T, a structure for the type
    4272              :    name passed to minof (rather than the type itself).  LOC is the
    4273              :    location of the original expression.  */
    4274              : 
    4275              : struct c_expr
    4276           46 : c_expr_minof_type (location_t loc, struct c_type_name *t)
    4277              : {
    4278           46 :   tree type;
    4279           46 :   struct c_expr ret;
    4280           46 :   tree type_expr = NULL_TREE;
    4281           46 :   bool type_expr_const = true;
    4282           46 :   type = groktypename (t, &type_expr, &type_expr_const);
    4283           46 :   ret.value = c_minof_type (loc, type);
    4284           46 :   c_last_sizeof_arg = type;
    4285           46 :   c_last_sizeof_loc = loc;
    4286           46 :   ret.original_code = MINOF_EXPR;
    4287           46 :   ret.original_type = NULL;
    4288           46 :   ret.m_decimal = 0;
    4289           46 :   if (type == error_mark_node)
    4290              :     {
    4291            0 :       ret.value = error_mark_node;
    4292            0 :       ret.original_code = ERROR_MARK;
    4293              :     }
    4294           46 :   pop_maybe_used (type != error_mark_node);
    4295           46 :   return ret;
    4296              : }
    4297              : 
    4298              : /* Build a function call to function FUNCTION with parameters PARAMS.
    4299              :    The function call is at LOC.
    4300              :    PARAMS is a list--a chain of TREE_LIST nodes--in which the
    4301              :    TREE_VALUE of each node is a parameter-expression.
    4302              :    FUNCTION's data type may be a function type or a pointer-to-function.  */
    4303              : 
    4304              : tree
    4305            0 : build_function_call (location_t loc, tree function, tree params)
    4306              : {
    4307            0 :   vec<tree, va_gc> *v;
    4308            0 :   tree ret;
    4309              : 
    4310            0 :   vec_alloc (v, list_length (params));
    4311            0 :   for (; params; params = TREE_CHAIN (params))
    4312            0 :     v->quick_push (TREE_VALUE (params));
    4313            0 :   ret = c_build_function_call_vec (loc, vNULL, function, v, NULL);
    4314            0 :   vec_free (v);
    4315            0 :   return ret;
    4316              : }
    4317              : 
    4318              : /* Give a note about the location of the declaration of DECL,
    4319              :    or, failing that, a pertinent declaration for FUNCTION_EXPR.  */
    4320              : 
    4321              : static void
    4322          299 : inform_declaration (tree decl, tree function_expr)
    4323              : {
    4324          299 :   if (decl && (TREE_CODE (decl) != FUNCTION_DECL
    4325          278 :                || !DECL_IS_UNDECLARED_BUILTIN (decl)))
    4326          207 :     inform (DECL_SOURCE_LOCATION (decl), "declared here");
    4327           92 :   else if (function_expr)
    4328           92 :     switch (TREE_CODE (function_expr))
    4329              :       {
    4330              :       default:
    4331              :         break;
    4332           13 :       case COMPONENT_REF:
    4333              :         /* Show the decl of the pertinent field (e.g. for callback
    4334              :            fields in a struct.  */
    4335           13 :         {
    4336           13 :           tree field_decl = TREE_OPERAND (function_expr, 1);
    4337           13 :           if (location_t loc = DECL_SOURCE_LOCATION (field_decl))
    4338           13 :             inform (loc, "declared here");
    4339              :         }
    4340              :         break;
    4341              :       }
    4342          299 : }
    4343              : 
    4344              : 
    4345              : /* Build a function call to function FUNCTION with parameters PARAMS.
    4346              :    If FUNCTION is the result of resolving an overloaded target built-in,
    4347              :    ORIG_FUNDECL is the original function decl, otherwise it is null.
    4348              :    ORIGTYPES, if not NULL, is a vector of types; each element is
    4349              :    either NULL or the original type of the corresponding element in
    4350              :    PARAMS.  The original type may differ from TREE_TYPE of the
    4351              :    parameter for enums.  FUNCTION's data type may be a function type
    4352              :    or pointer-to-function.  This function changes the elements of
    4353              :    PARAMS.  */
    4354              : 
    4355              : tree
    4356     51878791 : build_function_call_vec (location_t loc, vec<location_t> arg_loc,
    4357              :                          tree function, vec<tree, va_gc> *params,
    4358              :                          vec<tree, va_gc> *origtypes, tree orig_fundecl)
    4359              : {
    4360     51878791 :   tree fntype, fundecl = NULL_TREE;
    4361     51878791 :   tree name = NULL_TREE, result;
    4362     51878791 :   tree tem;
    4363     51878791 :   int nargs;
    4364     51878791 :   tree *argarray;
    4365              : 
    4366              : 
    4367              :   /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
    4368     51878791 :   STRIP_TYPE_NOPS (function);
    4369              : 
    4370              :   /* Convert anything with function type to a pointer-to-function.  */
    4371     51878791 :   if (TREE_CODE (function) == FUNCTION_DECL)
    4372              :     {
    4373     51801000 :       name = DECL_NAME (function);
    4374              : 
    4375     51801000 :       if (flag_tm)
    4376          422 :         tm_malloc_replacement (function);
    4377     51801000 :       fundecl = function;
    4378     51801000 :       if (!orig_fundecl)
    4379     51801000 :         orig_fundecl = fundecl;
    4380              :       /* Atomic functions have type checking/casting already done.  They are
    4381              :          often rewritten and don't match the original parameter list.  */
    4382    103602000 :       if (name && startswith (IDENTIFIER_POINTER (name), "__atomic_"))
    4383              :         origtypes = NULL;
    4384              :     }
    4385     51878791 :   if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE)
    4386     51815660 :     function = function_to_pointer_conversion (loc, function);
    4387              : 
    4388              :   /* For Objective-C, convert any calls via a cast to OBJC_TYPE_REF
    4389              :      expressions, like those used for ObjC messenger dispatches.  */
    4390     51878791 :   if (params && !params->is_empty ())
    4391     39529261 :     function = objc_rewrite_function_call (function, (*params)[0]);
    4392              : 
    4393     51878791 :   function = c_fully_fold (function, false, NULL);
    4394              : 
    4395     51878791 :   fntype = TREE_TYPE (function);
    4396              : 
    4397     51878791 :   if (TREE_CODE (fntype) == ERROR_MARK)
    4398            5 :     return error_mark_node;
    4399              : 
    4400     51878786 :   if (!(TREE_CODE (fntype) == POINTER_TYPE
    4401     51878752 :         && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE))
    4402              :     {
    4403           37 :       if (!flag_diagnostics_show_caret && !STATEMENT_CLASS_P (function))
    4404           33 :         error_at (loc,
    4405              :                   "called object %qE is not a function or function pointer",
    4406              :                   function);
    4407            4 :       else if (DECL_P (function))
    4408              :         {
    4409            1 :           auto_diagnostic_group d;
    4410            1 :           error_at (loc,
    4411              :                     "called object %qD is not a function or function pointer",
    4412              :                     function);
    4413            1 :           inform_declaration (function, NULL_TREE);
    4414            1 :         }
    4415              :       else
    4416            3 :         error_at (loc,
    4417              :                   "called object is not a function or function pointer");
    4418           37 :       return error_mark_node;
    4419              :     }
    4420              : 
    4421     51878749 :   if (fundecl && TREE_THIS_VOLATILE (fundecl))
    4422       386546 :     current_function_returns_abnormally = 1;
    4423              : 
    4424              :   /* fntype now gets the type of function pointed to.  */
    4425     51878749 :   fntype = TREE_TYPE (fntype);
    4426     51878749 :   tree return_type = TREE_TYPE (fntype);
    4427              : 
    4428              :   /* Convert the parameters to the types declared in the
    4429              :      function prototype, or apply default promotions.  */
    4430              : 
    4431     51878749 :   nargs = convert_arguments (loc, arg_loc, fntype, params,
    4432              :                              origtypes, function, fundecl);
    4433     51878749 :   if (nargs < 0)
    4434          179 :     return error_mark_node;
    4435              : 
    4436              :   /* Check that the function is called through a compatible prototype.
    4437              :      If it is not, warn.  */
    4438     51877655 :   if (CONVERT_EXPR_P (function)
    4439          931 :       && TREE_CODE (tem = TREE_OPERAND (function, 0)) == ADDR_EXPR
    4440          215 :       && TREE_CODE (tem = TREE_OPERAND (tem, 0)) == FUNCTION_DECL
    4441     51878755 :       && !comptypes (fntype, TREE_TYPE (tem)))
    4442              :     {
    4443              :       /* This situation leads to run-time undefined behavior.  We can't,
    4444              :          therefore, simply error unless we can prove that all possible
    4445              :          executions of the program must execute the code.  */
    4446           20 :       warning_at (loc, 0, "function called through a non-compatible type");
    4447              : 
    4448           20 :       if (VOID_TYPE_P (return_type)
    4449           20 :           && TYPE_QUALS (return_type) != TYPE_UNQUALIFIED)
    4450            1 :         pedwarn (loc, 0,
    4451              :                  "function with qualified void return type called");
    4452              :      }
    4453              : 
    4454     51878570 :   argarray = vec_safe_address (params);
    4455              : 
    4456              :   /* Check that arguments to builtin functions match the expectations.  */
    4457     51878570 :   if (fundecl
    4458     51800836 :       && fndecl_built_in_p (fundecl)
    4459     86435526 :       && !check_builtin_function_arguments (loc, arg_loc, fundecl,
    4460              :                                             orig_fundecl, nargs, argarray))
    4461          338 :     return error_mark_node;
    4462              : 
    4463              :   /* Check that the arguments to the function are valid.  */
    4464     51878232 :   bool warned_p = check_function_arguments (loc, fundecl, fntype,
    4465              :                                             nargs, argarray, &arg_loc,
    4466              :                                             comptypes);
    4467              : 
    4468     51878232 :   if (TYPE_QUALS (return_type) != TYPE_UNQUALIFIED
    4469           13 :       && !VOID_TYPE_P (return_type))
    4470           11 :     return_type = c_build_qualified_type (return_type, TYPE_UNQUALIFIED);
    4471     51878232 :   if (name != NULL_TREE
    4472    103678730 :       && startswith (IDENTIFIER_POINTER (name), "__builtin_"))
    4473              :     {
    4474     33822734 :       if (require_constant_value)
    4475         3484 :         result
    4476         3484 :           = fold_build_call_array_initializer_loc (loc, return_type,
    4477              :                                                    function, nargs, argarray);
    4478              :       else
    4479     33819250 :         result = fold_build_call_array_loc (loc, return_type,
    4480              :                                             function, nargs, argarray);
    4481     33822734 :       if (TREE_CODE (result) == NOP_EXPR
    4482     33822734 :           && TREE_CODE (TREE_OPERAND (result, 0)) == INTEGER_CST)
    4483        26570 :         STRIP_TYPE_NOPS (result);
    4484              :     }
    4485              :   else
    4486     18055498 :     result = build_call_array_loc (loc, return_type,
    4487              :                                    function, nargs, argarray);
    4488              :   /* If -Wnonnull warning has been diagnosed, avoid diagnosing it again
    4489              :      later.  */
    4490     51878232 :   if (warned_p && TREE_CODE (result) == CALL_EXPR)
    4491          215 :     suppress_warning (result, OPT_Wnonnull);
    4492              : 
    4493              :   /* In this improbable scenario, a nested function returns a VM type.
    4494              :      Create a TARGET_EXPR so that the call always has a LHS, much as
    4495              :      what the C++ FE does for functions returning non-PODs.  */
    4496     51878232 :   if (c_type_variably_modified_p (TREE_TYPE (fntype)))
    4497              :     {
    4498           83 :       tree tmp = create_tmp_var_raw (TREE_TYPE (fntype));
    4499           83 :       result = build4 (TARGET_EXPR, TREE_TYPE (fntype), tmp, result,
    4500              :                        NULL_TREE, NULL_TREE);
    4501              :     }
    4502              : 
    4503     51878232 :   if (VOID_TYPE_P (TREE_TYPE (result)))
    4504              :     {
    4505      2517796 :       if (TYPE_QUALS (TREE_TYPE (result)) != TYPE_UNQUALIFIED)
    4506            2 :         pedwarn (loc, 0,
    4507              :                  "function with qualified void return type called");
    4508              :       return result;
    4509              :     }
    4510     49360436 :   return require_complete_type (loc, result);
    4511              : }
    4512              : 
    4513              : /* Like build_function_call_vec, but call also resolve_overloaded_builtin.  */
    4514              : 
    4515              : tree
    4516     51878347 : c_build_function_call_vec (location_t loc, const vec<location_t> &arg_loc,
    4517              :                            tree function, vec<tree, va_gc> *params,
    4518              :                            vec<tree, va_gc> *origtypes)
    4519              : {
    4520              :   /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
    4521     51878358 :   STRIP_TYPE_NOPS (function);
    4522              : 
    4523              :   /* Convert anything with function type to a pointer-to-function.  */
    4524     51878347 :   if (TREE_CODE (function) == FUNCTION_DECL)
    4525              :     {
    4526              :       /* Implement type-directed function overloading for builtins.
    4527              :          resolve_overloaded_builtin and targetm.resolve_overloaded_builtin
    4528              :          handle all the type checking.  The result is a complete expression
    4529              :          that implements this function call.  */
    4530     51800556 :       tree tem = resolve_overloaded_builtin (loc, function, params);
    4531     51800556 :       if (tem)
    4532              :         return tem;
    4533              :     }
    4534     51790986 :   return build_function_call_vec (loc, arg_loc, function, params, origtypes);
    4535              : }
    4536              : 
    4537              : /* Helper for convert_arguments called to convert the VALue of argument
    4538              :    number ARGNUM from ORIGTYPE to the corresponding parameter number
    4539              :    PARMNUM and TYPE.
    4540              :    PLOC is the location where the conversion is being performed.
    4541              :    FUNCTION and FUNDECL are the same as in convert_arguments.
    4542              :    VALTYPE is the original type of VAL before the conversion and,
    4543              :    for EXCESS_PRECISION_EXPR, the operand of the expression.
    4544              :    NPC is true if VAL represents the null pointer constant (VAL itself
    4545              :    will have been folded to an integer constant).
    4546              :    RNAME is the same as FUNCTION except in Objective C when it's
    4547              :    the function selector.
    4548              :    EXCESS_PRECISION is true when VAL was originally represented
    4549              :    as EXCESS_PRECISION_EXPR.
    4550              :    WARNOPT is the same as in convert_for_assignment.  */
    4551              : 
    4552              : static tree
    4553    129770868 : convert_argument (location_t ploc, tree function, tree fundecl,
    4554              :                   tree type, tree origtype, tree val, tree valtype,
    4555              :                   bool npc, tree rname, int parmnum, int argnum,
    4556              :                   bool excess_precision, int warnopt)
    4557              : {
    4558              :   /* Formal parm type is specified by a function prototype.  */
    4559              : 
    4560    129770868 :   if (type == error_mark_node || !COMPLETE_TYPE_P (type))
    4561              :     {
    4562            3 :       error_at (ploc, "type of formal parameter %d is incomplete",
    4563              :                 parmnum + 1);
    4564            3 :       return error_mark_node;
    4565              :     }
    4566              : 
    4567              :   /* Optionally warn about conversions that differ from the default
    4568              :      conversions.  */
    4569    129770865 :   if (warn_traditional_conversion || warn_traditional)
    4570              :     {
    4571          193 :       if (INTEGRAL_TYPE_P (type)
    4572          107 :           && SCALAR_FLOAT_TYPE_P (valtype))
    4573           19 :         warning_at (ploc, OPT_Wtraditional_conversion,
    4574              :                     "passing argument %d of %qE as integer rather "
    4575              :                     "than floating due to prototype",
    4576              :                     argnum, rname);
    4577          193 :       if (INTEGRAL_TYPE_P (type)
    4578          107 :           && TREE_CODE (valtype) == COMPLEX_TYPE)
    4579            5 :         warning_at (ploc, OPT_Wtraditional_conversion,
    4580              :                     "passing argument %d of %qE as integer rather "
    4581              :                     "than complex due to prototype",
    4582              :                     argnum, rname);
    4583          188 :       else if (TREE_CODE (type) == COMPLEX_TYPE
    4584           14 :                && SCALAR_FLOAT_TYPE_P (valtype))
    4585            7 :         warning_at (ploc, OPT_Wtraditional_conversion,
    4586              :                     "passing argument %d of %qE as complex rather "
    4587              :                     "than floating due to prototype",
    4588              :                     argnum, rname);
    4589          181 :       else if (SCALAR_FLOAT_TYPE_P (type)
    4590           71 :                && INTEGRAL_TYPE_P (valtype))
    4591           19 :         warning_at (ploc, OPT_Wtraditional_conversion,
    4592              :                     "passing argument %d of %qE as floating rather "
    4593              :                     "than integer due to prototype",
    4594              :                     argnum, rname);
    4595          162 :       else if (TREE_CODE (type) == COMPLEX_TYPE
    4596            7 :                && INTEGRAL_TYPE_P (valtype))
    4597            5 :         warning_at (ploc, OPT_Wtraditional_conversion,
    4598              :                     "passing argument %d of %qE as complex rather "
    4599              :                     "than integer due to prototype",
    4600              :                     argnum, rname);
    4601          157 :       else if (SCALAR_FLOAT_TYPE_P (type)
    4602           52 :                && TREE_CODE (valtype) == COMPLEX_TYPE)
    4603            7 :         warning_at (ploc, OPT_Wtraditional_conversion,
    4604              :                     "passing argument %d of %qE as floating rather "
    4605              :                     "than complex due to prototype",
    4606              :                     argnum, rname);
    4607              :       /* ??? At some point, messages should be written about
    4608              :          conversions between complex types, but that's too messy
    4609              :          to do now.  */
    4610          150 :       else if (SCALAR_FLOAT_TYPE_P (type)
    4611           45 :                && SCALAR_FLOAT_TYPE_P (valtype))
    4612              :         {
    4613           45 :           unsigned int formal_prec = TYPE_PRECISION (type);
    4614              : 
    4615              :           /* Warn if any argument is passed as `float',
    4616              :              since without a prototype it would be `double'.  */
    4617           45 :           if (formal_prec == TYPE_PRECISION (float_type_node)
    4618           45 :               && type != dfloat32_type_node)
    4619            7 :             warning_at (ploc, 0,
    4620              :                         "passing argument %d of %qE as %<float%> "
    4621              :                         "rather than %<double%> due to prototype",
    4622              :                         argnum, rname);
    4623              : 
    4624              :           /* Warn if mismatch between argument and prototype
    4625              :              for decimal float types.  Warn of conversions with
    4626              :              binary float types and of precision narrowing due to
    4627              :              prototype.  */
    4628           38 :           else if (type != valtype
    4629           32 :                    && (type == dfloat32_type_node
    4630           22 :                        || type == dfloat64_type_node
    4631           12 :                        || type == dfloat128_type_node
    4632            2 :                        || valtype == dfloat32_type_node
    4633            2 :                        || valtype == dfloat64_type_node
    4634            2 :                        || valtype == dfloat128_type_node)
    4635           38 :                    && (formal_prec
    4636           30 :                        <= TYPE_PRECISION (valtype)
    4637           14 :                        || (type == dfloat128_type_node
    4638           10 :                            && (valtype
    4639           10 :                                != dfloat64_type_node
    4640            8 :                                && (valtype
    4641              :                                    != dfloat32_type_node)))
    4642            8 :                        || (type == dfloat64_type_node
    4643            4 :                            && (valtype
    4644              :                                != dfloat32_type_node))))
    4645           24 :             warning_at (ploc, 0,
    4646              :                         "passing argument %d of %qE as %qT "
    4647              :                         "rather than %qT due to prototype",
    4648              :                         argnum, rname, type, valtype);
    4649              : 
    4650              :         }
    4651              :       /* Detect integer changing in width or signedness.
    4652              :          These warnings are only activated with
    4653              :          -Wtraditional-conversion, not with -Wtraditional.  */
    4654          105 :       else if (warn_traditional_conversion
    4655          105 :                && INTEGRAL_TYPE_P (type)
    4656          102 :                && INTEGRAL_TYPE_P (valtype))
    4657              :         {
    4658           83 :           unsigned int formal_prec = TYPE_PRECISION (type);
    4659           83 :           tree would_have_been = default_conversion (val);
    4660           83 :           tree type1 = TREE_TYPE (would_have_been);
    4661              : 
    4662           83 :           if (val == error_mark_node)
    4663              :             /* VAL could have been of incomplete type.  */;
    4664           83 :           else if (TREE_CODE (type) == ENUMERAL_TYPE
    4665           83 :                    && (TYPE_MAIN_VARIANT (type)
    4666            2 :                        == TYPE_MAIN_VARIANT (valtype)))
    4667              :             /* No warning if function asks for enum
    4668              :                and the actual arg is that enum type.  */
    4669              :             ;
    4670           81 :           else if (formal_prec != TYPE_PRECISION (type1))
    4671           14 :             warning_at (ploc, OPT_Wtraditional_conversion,
    4672              :                         "passing argument %d of %qE "
    4673              :                         "with different width due to prototype",
    4674              :                         argnum, rname);
    4675           67 :           else if (TYPE_UNSIGNED (type) == TYPE_UNSIGNED (type1))
    4676              :             ;
    4677              :           /* Don't complain if the formal parameter type
    4678              :              is an enum, because we can't tell now whether
    4679              :              the value was an enum--even the same enum.  */
    4680           32 :           else if (TREE_CODE (type) == ENUMERAL_TYPE)
    4681              :             ;
    4682           32 :           else if (TREE_CODE (val) == INTEGER_CST
    4683            5 :                    && int_fits_type_p (val, type))
    4684              :             /* Change in signedness doesn't matter
    4685              :                if a constant value is unaffected.  */
    4686              :             ;
    4687              :           /* If the value is extended from a narrower
    4688              :              unsigned type, it doesn't matter whether we
    4689              :              pass it as signed or unsigned; the value
    4690              :              certainly is the same either way.  */
    4691           32 :           else if (TYPE_PRECISION (valtype) < TYPE_PRECISION (type)
    4692           32 :                    && TYPE_UNSIGNED (valtype))
    4693              :             ;
    4694           32 :           else if (TYPE_UNSIGNED (type))
    4695           17 :             warning_at (ploc, OPT_Wtraditional_conversion,
    4696              :                         "passing argument %d of %qE "
    4697              :                         "as unsigned due to prototype",
    4698              :                         argnum, rname);
    4699              :           else
    4700           15 :             warning_at (ploc, OPT_Wtraditional_conversion,
    4701              :                         "passing argument %d of %qE "
    4702              :                         "as signed due to prototype",
    4703              :                         argnum, rname);
    4704              :         }
    4705              :     }
    4706              : 
    4707              :   /* Possibly restore an EXCESS_PRECISION_EXPR for the
    4708              :      sake of better warnings from convert_and_check.  */
    4709    129770865 :   if (excess_precision)
    4710          380 :     val = build1 (EXCESS_PRECISION_EXPR, valtype, val);
    4711              : 
    4712    129770865 :   tree parmval = convert_for_assignment (ploc, ploc, type,
    4713              :                                          val, origtype, ic_argpass,
    4714              :                                          npc, fundecl, function,
    4715              :                                          parmnum + 1, warnopt);
    4716    129770865 :   return parmval;
    4717              : }
    4718              : 
    4719              : /* Convert the argument expressions in the vector VALUES
    4720              :    to the types in the list TYPE_ARG_TYPES (FNTYPE).
    4721              : 
    4722              :    If the list is exhausted, or when an element has NULL as its type,
    4723              :    perform the default conversions.
    4724              : 
    4725              :    ORIGTYPES is the original types of the expressions in VALUES.  This
    4726              :    holds the type of enum values which have been converted to integral
    4727              :    types.  It may be NULL.
    4728              : 
    4729              :    FUNCTION is a tree for the called function.  It is used only for
    4730              :    error messages, where it is formatted with %qE.
    4731              : 
    4732              :    This is also where warnings about wrong number of args are generated.
    4733              : 
    4734              :    ARG_LOC are locations of function arguments (if any).
    4735              : 
    4736              :    Returns the actual number of arguments processed (which may be less
    4737              :    than the length of VALUES in some error situations), or -1 on
    4738              :    failure.  */
    4739              : 
    4740              : static int
    4741     51878749 : convert_arguments (location_t loc, vec<location_t> arg_loc, tree fntype,
    4742              :                    vec<tree, va_gc> *values, vec<tree, va_gc> *origtypes,
    4743              :                    tree function, tree fundecl)
    4744              : {
    4745     51878749 :   tree typelist = TYPE_ARG_TYPES (fntype);
    4746     51878749 :   unsigned int parmnum;
    4747     51878749 :   bool error_args = false;
    4748     51878749 :   const bool type_generic = fundecl
    4749     51878749 :     && lookup_attribute ("type generic", TYPE_ATTRIBUTES (TREE_TYPE (fundecl)));
    4750     51878749 :   bool type_generic_remove_excess_precision = false;
    4751     51878749 :   bool type_generic_overflow_p = false;
    4752     51878749 :   bool type_generic_bit_query = false;
    4753     51878749 :   tree selector;
    4754              : 
    4755              :   /* Change pointer to function to the function itself for
    4756              :      diagnostics.  */
    4757     51878749 :   if (TREE_CODE (function) == ADDR_EXPR
    4758     51878749 :       && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL)
    4759     51803098 :     function = TREE_OPERAND (function, 0);
    4760              : 
    4761              :   /* Handle an ObjC selector specially for diagnostics.  */
    4762     51878749 :   selector = objc_message_selector ();
    4763              : 
    4764              :   /* For a call to a built-in function declared without a prototype,
    4765              :      set to the built-in function's argument list.  */
    4766     51878749 :   tree builtin_typelist = NULL_TREE;
    4767              : 
    4768              :   /* For type-generic built-in functions, determine whether excess
    4769              :      precision should be removed (classification) or not
    4770              :      (comparison).  */
    4771     51878749 :   if (fundecl
    4772     51878749 :       && fndecl_built_in_p (fundecl, BUILT_IN_NORMAL))
    4773              :     {
    4774      1420637 :       built_in_function code = DECL_FUNCTION_CODE (fundecl);
    4775      1420637 :       if (C_DECL_BUILTIN_PROTOTYPE (fundecl))
    4776              :         {
    4777              :           /* For a call to a built-in function declared without a prototype
    4778              :              use the types of the parameters of the internal built-in to
    4779              :              match those of the arguments to.  */
    4780       700411 :           if (tree bdecl = builtin_decl_explicit (code))
    4781       700411 :             builtin_typelist = TYPE_ARG_TYPES (TREE_TYPE (bdecl));
    4782              :         }
    4783              : 
    4784              :       /* For type-generic built-in functions, determine whether excess
    4785              :          precision should be removed (classification) or not
    4786              :          (comparison).  */
    4787      1420637 :       if (type_generic)
    4788        61423 :         switch (code)
    4789              :           {
    4790         5441 :           case BUILT_IN_ISFINITE:
    4791         5441 :           case BUILT_IN_ISINF:
    4792         5441 :           case BUILT_IN_ISINF_SIGN:
    4793         5441 :           case BUILT_IN_ISNAN:
    4794         5441 :           case BUILT_IN_ISNORMAL:
    4795         5441 :           case BUILT_IN_ISSIGNALING:
    4796         5441 :           case BUILT_IN_FPCLASSIFY:
    4797         5441 :             type_generic_remove_excess_precision = true;
    4798         5441 :             break;
    4799              : 
    4800        21047 :           case BUILT_IN_ADD_OVERFLOW_P:
    4801        21047 :           case BUILT_IN_SUB_OVERFLOW_P:
    4802        21047 :           case BUILT_IN_MUL_OVERFLOW_P:
    4803              :             /* The last argument of these type-generic builtins
    4804              :                should not be promoted.  */
    4805        21047 :             type_generic_overflow_p = true;
    4806        21047 :             break;
    4807              : 
    4808         1386 :           case BUILT_IN_CLZG:
    4809         1386 :           case BUILT_IN_CTZG:
    4810         1386 :           case BUILT_IN_CLRSBG:
    4811         1386 :           case BUILT_IN_FFSG:
    4812         1386 :           case BUILT_IN_PARITYG:
    4813         1386 :           case BUILT_IN_POPCOUNTG:
    4814              :             /* The first argument of these type-generic builtins
    4815              :                should not be promoted.  */
    4816         1386 :             type_generic_bit_query = true;
    4817         1386 :             break;
    4818              : 
    4819              :           default:
    4820              :             break;
    4821              :           }
    4822              :     }
    4823              : 
    4824              :   /* Scan the given expressions (VALUES) and types (TYPELIST), producing
    4825              :      individual converted arguments.  */
    4826              : 
    4827     51878749 :   tree typetail, builtin_typetail, val;
    4828    130710997 :   for (typetail = typelist,
    4829     51878749 :          builtin_typetail = builtin_typelist,
    4830     51878749 :          parmnum = 0;
    4831    182589746 :        values && values->iterate (parmnum, &val);
    4832              :        ++parmnum)
    4833              :     {
    4834              :       /* The type of the function parameter (if it was declared with one).  */
    4835    260480015 :       tree type = typetail ? TREE_VALUE (typetail) : NULL_TREE;
    4836              :       /* The type of the built-in function parameter (if the function
    4837              :          is a built-in).  Used to detect type incompatibilities in
    4838              :          calls to built-ins declared without a prototype.  */
    4839    130711033 :       tree builtin_type = (builtin_typetail
    4840    131757721 :                            ? TREE_VALUE (builtin_typetail) : NULL_TREE);
    4841              :       /* The original type of the argument being passed to the function.  */
    4842    130711033 :       tree valtype = TREE_TYPE (val);
    4843              :       /* The called function (or function selector in Objective C).  */
    4844    130711033 :       tree rname = function;
    4845    130711033 :       int argnum = parmnum + 1;
    4846    130711033 :       const char *invalid_func_diag;
    4847              :       /* Set for EXCESS_PRECISION_EXPR arguments.  */
    4848    130711033 :       bool excess_precision = false;
    4849              :       /* The value of the argument after conversion to the type
    4850              :          of the function parameter it is passed to.  */
    4851    130711033 :       tree parmval;
    4852              :       /* Some __atomic_* builtins have additional hidden argument at
    4853              :          position 0.  */
    4854    130711033 :       location_t ploc
    4855    130438544 :         = !arg_loc.is_empty () && values->length () == arg_loc.length ()
    4856    130437944 :           ? expansion_point_location_if_in_system_header (arg_loc[parmnum])
    4857    130711033 :           : input_location;
    4858              : 
    4859    130711033 :       if (type == void_type_node)
    4860              :         {
    4861           33 :           auto_diagnostic_group d;
    4862           33 :           int num_expected = parmnum;
    4863           33 :           int num_actual = values->length ();
    4864           33 :           gcc_rich_location rich_loc (loc);
    4865           33 :           if (ploc != input_location)
    4866           32 :             rich_loc.add_range (ploc);
    4867           33 :           if (selector)
    4868            0 :             error_at (&rich_loc,
    4869              :                       "too many arguments to method %qE; expected %i, have %i",
    4870              :                       selector, num_expected, num_actual);
    4871              :           else
    4872           33 :             error_at (&rich_loc,
    4873              :                       "too many arguments to function %qE; expected %i, have %i",
    4874              :                       function, num_expected, num_actual);
    4875           33 :           inform_declaration (fundecl, function);
    4876           65 :           return error_args ? -1 : (int) parmnum;
    4877           33 :         }
    4878              : 
    4879    130711000 :       if (builtin_type == void_type_node)
    4880              :         {
    4881           12 :           auto_diagnostic_group d;
    4882           12 :           if (warning_at (loc, OPT_Wbuiltin_declaration_mismatch,
    4883              :                           "too many arguments to built-in function %qE "
    4884              :                           "expecting %d", function, parmnum))
    4885           12 :             inform_declaration (fundecl, function);
    4886           12 :           builtin_typetail = NULL_TREE;
    4887           12 :         }
    4888              : 
    4889        91138 :       if (!typetail && parmnum == 0 && !TYPE_NO_NAMED_ARGS_STDARG_P (fntype)
    4890    130802019 :           && !(fundecl && fndecl_built_in_p (fundecl)))
    4891              :         {
    4892         6962 :           auto_diagnostic_group d;
    4893         6962 :           bool warned;
    4894         6962 :           if (selector)
    4895            0 :             warned = warning_at (loc, OPT_Wdeprecated_non_prototype,
    4896              :                                  "ISO C23 does not allow arguments"
    4897              :                                  " for method %qE declared without parameters",
    4898              :                                  function);
    4899              :           else
    4900         6962 :             warned = warning_at (loc, OPT_Wdeprecated_non_prototype,
    4901              :                                  "ISO C23 does not allow arguments"
    4902              :                                  " for function %qE declared without parameters",
    4903              :                                  function);
    4904         6962 :           if (warned)
    4905            4 :             inform_declaration (fundecl, function);
    4906         6962 :         }
    4907              : 
    4908    130711000 :       if (selector && argnum > 2)
    4909              :         {
    4910            0 :           rname = selector;
    4911            0 :           argnum -= 2;
    4912              :         }
    4913              : 
    4914              :       /* Determine if VAL is a null pointer constant before folding it.  */
    4915    130711000 :       bool npc = null_pointer_constant_p (val);
    4916              : 
    4917              :       /* If there is excess precision and a prototype, convert once to
    4918              :          the required type rather than converting via the semantic
    4919              :          type.  Likewise without a prototype a float value represented
    4920              :          as long double should be converted once to double.  But for
    4921              :          type-generic classification functions excess precision must
    4922              :          be removed here.  */
    4923    130711000 :       if (TREE_CODE (val) == EXCESS_PRECISION_EXPR
    4924          433 :           && (type || !type_generic || !type_generic_remove_excess_precision))
    4925              :         {
    4926          413 :           val = TREE_OPERAND (val, 0);
    4927          413 :           excess_precision = true;
    4928              :         }
    4929    130711000 :       val = c_fully_fold (val, false, NULL);
    4930    261422001 :       STRIP_TYPE_NOPS (val);
    4931              : 
    4932    130711000 :       val = require_complete_type (ploc, val);
    4933              : 
    4934              :       /* Some floating-point arguments must be promoted to double when
    4935              :          no type is specified by a prototype.  This applies to
    4936              :          arguments of type float, and to architecture-specific types
    4937              :          (ARM __fp16), but not to _FloatN or _FloatNx types.  */
    4938    130711000 :       bool promote_float_arg = false;
    4939    130711000 :       if (type == NULL_TREE
    4940       942051 :           && TREE_CODE (valtype) == REAL_TYPE
    4941       269997 :           && (TYPE_PRECISION (valtype)
    4942       269997 :               <= TYPE_PRECISION (double_type_node))
    4943       262743 :           && TYPE_MAIN_VARIANT (valtype) != double_type_node
    4944       131507 :           && TYPE_MAIN_VARIANT (valtype) != long_double_type_node
    4945    130842507 :           && !DECIMAL_FLOAT_MODE_P (TYPE_MODE (valtype)))
    4946              :         {
    4947              :           /* Promote this argument, unless it has a _FloatN or
    4948              :              _FloatNx type.  */
    4949      1028558 :           promote_float_arg = true;
    4950      1028558 :           for (int i = 0; i < NUM_FLOATN_NX_TYPES; i++)
    4951       901061 :             if (TYPE_MAIN_VARIANT (valtype) == FLOATN_NX_TYPE_NODE (i))
    4952              :               {
    4953              :                 promote_float_arg = false;
    4954              :                 break;
    4955              :               }
    4956              :           /* Don't promote __bf16 either.  */
    4957       130774 :           if (TYPE_MAIN_VARIANT (valtype) == bfloat16_type_node)
    4958    130580296 :             promote_float_arg = false;
    4959              :         }
    4960              : 
    4961    130711000 :       if (type != NULL_TREE)
    4962              :         {
    4963    129768949 :           tree origtype = (!origtypes) ? NULL_TREE : (*origtypes)[parmnum];
    4964    129768949 :           parmval = convert_argument (ploc, function, fundecl, type, origtype,
    4965              :                                       val, valtype, npc, rname, parmnum, argnum,
    4966              :                                       excess_precision, 0);
    4967              :         }
    4968              :       /* A NULLPTR type is just a nullptr always.  */
    4969       942051 :       else if (TREE_CODE (TREE_TYPE (val)) == NULLPTR_TYPE)
    4970            9 :         parmval = omit_one_operand_loc (ploc, TREE_TYPE (val), nullptr_node, val);
    4971       942042 :       else if (promote_float_arg)
    4972              :         {
    4973       127427 :           if (type_generic)
    4974              :             parmval = val;
    4975              :           else
    4976              :             {
    4977              :               /* Convert `float' to `double'.  */
    4978       124528 :               if (warn_double_promotion && !c_inhibit_evaluation_warnings)
    4979            6 :                 warning_at (ploc, OPT_Wdouble_promotion,
    4980              :                             "implicit conversion from %qT to %qT when passing "
    4981              :                             "argument to function",
    4982              :                             valtype, double_type_node);
    4983       124528 :               parmval = convert (double_type_node, val);
    4984              :             }
    4985              :         }
    4986       814615 :       else if ((excess_precision && !type_generic)
    4987       814613 :                || (type_generic_overflow_p && parmnum == 2)
    4988       793570 :                || (type_generic_bit_query && parmnum == 0))
    4989              :         /* A "double" argument with excess precision being passed
    4990              :            without a prototype or in variable arguments.
    4991              :            The last argument of __builtin_*_overflow_p should not be
    4992              :            promoted, similarly the first argument of
    4993              :            __builtin_{clz,ctz,clrsb,ffs,parity,popcount}g.  */
    4994        22425 :         parmval = convert (valtype, val);
    4995      1584380 :       else if ((invalid_func_diag =
    4996       792190 :                 targetm.calls.invalid_arg_for_unprototyped_fn (typelist, fundecl, val)))
    4997              :         {
    4998            0 :           error (invalid_func_diag);
    4999            0 :           return -1;
    5000              :         }
    5001       792190 :       else if (TREE_CODE (val) == ADDR_EXPR && reject_gcc_builtin (val))
    5002              :         {
    5003              :           return -1;
    5004              :         }
    5005              :       else
    5006              :         /* Convert `short' and `char' to full-size `int'.  */
    5007       792187 :         parmval = default_conversion (val);
    5008              : 
    5009    130710997 :       (*values)[parmnum] = parmval;
    5010    130710997 :       if (parmval == error_mark_node)
    5011          106 :         error_args = true;
    5012              : 
    5013    130710997 :       if (!type && builtin_type && TREE_CODE (builtin_type) != VOID_TYPE)
    5014              :         {
    5015              :           /* For a call to a built-in function declared without a prototype,
    5016              :              perform the conversions from the argument to the expected type
    5017              :              but issue warnings rather than errors for any mismatches.
    5018              :              Ignore the converted argument and use the PARMVAL obtained
    5019              :              above by applying default conversions instead.  */
    5020         1919 :           tree origtype = (!origtypes) ? NULL_TREE : (*origtypes)[parmnum];
    5021         1919 :           convert_argument (ploc, function, fundecl, builtin_type, origtype,
    5022              :                             val, valtype, npc, rname, parmnum, argnum,
    5023              :                             excess_precision,
    5024              :                             OPT_Wbuiltin_declaration_mismatch);
    5025              :         }
    5026              : 
    5027    130710997 :       if (typetail)
    5028    129768949 :         typetail = TREE_CHAIN (typetail);
    5029              : 
    5030    130710997 :       if (builtin_typetail)
    5031      1046671 :         builtin_typetail = TREE_CHAIN (builtin_typetail);
    5032              :     }
    5033              : 
    5034     91407927 :   gcc_assert (parmnum == vec_safe_length (values));
    5035              : 
    5036    103423354 :   if (typetail != NULL_TREE && TREE_VALUE (typetail) != void_type_node)
    5037              :     {
    5038              :       /* Not enough args.
    5039              :          Determine minimum number of arguments required.  */
    5040              :       int min_expected_num = 0;
    5041          231 :       bool at_least_p = false;
    5042              :       tree iter = typelist;
    5043          386 :       while (true)
    5044              :         {
    5045          231 :           if (!iter)
    5046              :             {
    5047              :               /* Variadic arguments; stop iterating.  */
    5048              :               at_least_p = true;
    5049              :               break;
    5050              :             }
    5051          222 :           if (iter == void_list_node)
    5052              :             /* End of arguments; stop iterating.  */
    5053              :             break;
    5054          155 :           ++min_expected_num;
    5055          155 :           iter = TREE_CHAIN (iter);
    5056              :         }
    5057           76 :       auto_diagnostic_group d;
    5058           76 :       int actual_num = vec_safe_length (values);
    5059          143 :       error_at (loc,
    5060              :                 at_least_p
    5061              :                 ? G_("too few arguments to function %qE; expected at least %i, have %i")
    5062              :                 : G_("too few arguments to function %qE; expected %i, have %i"),
    5063              :                 function, min_expected_num, actual_num);
    5064           76 :       inform_declaration (fundecl, function);
    5065           76 :       return -1;
    5066           76 :     }
    5067              : 
    5068     52542683 :   if (builtin_typetail && TREE_VALUE (builtin_typetail) != void_type_node)
    5069              :     {
    5070          616 :       unsigned nargs = parmnum;
    5071          616 :       for (tree t = builtin_typetail; t; t = TREE_CHAIN (t))
    5072          428 :         ++nargs;
    5073              : 
    5074          188 :       auto_diagnostic_group d;
    5075          188 :       if (warning_at (loc, OPT_Wbuiltin_declaration_mismatch,
    5076              :                       "too few arguments to built-in function %qE "
    5077              :                       "expecting %u", function, nargs - 1))
    5078          173 :         inform_declaration (fundecl, function);
    5079          188 :     }
    5080              : 
    5081     51878637 :   return error_args ? -1 : (int) parmnum;
    5082              : }
    5083              : 
    5084              : /* This is the entry point used by the parser to build unary operators
    5085              :    in the input.  CODE, a tree_code, specifies the unary operator, and
    5086              :    ARG is the operand.  For unary plus, the C parser currently uses
    5087              :    CONVERT_EXPR for code.
    5088              : 
    5089              :    LOC is the location to use for the tree generated.
    5090              : */
    5091              : 
    5092              : struct c_expr
    5093      8498418 : parser_build_unary_op (location_t loc, enum tree_code code, struct c_expr arg)
    5094              : {
    5095      8498418 :   struct c_expr result;
    5096              : 
    5097      8498418 :   result.original_code = code;
    5098      8498418 :   result.original_type = NULL;
    5099      8498418 :   result.m_decimal = 0;
    5100              : 
    5101      8498418 :   if (reject_gcc_builtin (arg.value))
    5102              :     {
    5103            2 :       result.value = error_mark_node;
    5104              :     }
    5105              :   else
    5106              :     {
    5107      8498416 :       result.value = build_unary_op (loc, code, arg.value, false);
    5108              : 
    5109      8498416 :       if (TREE_OVERFLOW_P (result.value) && !TREE_OVERFLOW_P (arg.value))
    5110            5 :         overflow_warning (loc, result.value, arg.value);
    5111              :     }
    5112              : 
    5113              :   /* We are typically called when parsing a prefix token at LOC acting on
    5114              :      ARG.  Reflect this by updating the source range of the result to
    5115              :      start at LOC and end at the end of ARG.  */
    5116      8498418 :   set_c_expr_source_range (&result,
    5117              :                            loc, arg.get_finish ());
    5118              : 
    5119      8498418 :   return result;
    5120              : }
    5121              : 
    5122              : /* Returns true if TYPE is a character type, *not* including wchar_t.  */
    5123              : 
    5124              : bool
    5125      1282214 : char_type_p (tree type)
    5126              : {
    5127      1282214 :   return (type == char_type_node
    5128       988992 :           || type == unsigned_char_type_node
    5129       969567 :           || type == signed_char_type_node
    5130       968599 :           || type == char16_type_node
    5131      2028026 :           || type == char32_type_node);
    5132              : }
    5133              : 
    5134              : /* This is the entry point used by the parser to build binary operators
    5135              :    in the input.  CODE, a tree_code, specifies the binary operator, and
    5136              :    ARG1 and ARG2 are the operands.  In addition to constructing the
    5137              :    expression, we check for operands that were written with other binary
    5138              :    operators in a way that is likely to confuse the user.  ORIG_ARG1 is
    5139              :    the original first operand for TRUTH_{AND,OR}IF_EXPR before it is
    5140              :    converted to truth value, otherwise NULL_TREE.
    5141              : 
    5142              :    LOCATION is the location of the binary operator.  */
    5143              : 
    5144              : struct c_expr
    5145     10027348 : parser_build_binary_op (location_t location, enum tree_code code,
    5146              :                         struct c_expr arg1, struct c_expr arg2, tree orig_arg1)
    5147              : {
    5148     10027348 :   struct c_expr result;
    5149     10027348 :   result.m_decimal = 0;
    5150              : 
    5151     10027348 :   enum tree_code code1 = arg1.original_code;
    5152     10027348 :   enum tree_code code2 = arg2.original_code;
    5153     10027348 :   tree type1 = (arg1.original_type
    5154     10027348 :                 ? arg1.original_type
    5155      6633758 :                 : TREE_TYPE (arg1.value));
    5156     10027348 :   tree type2 = (arg2.original_type
    5157     10027348 :                 ? arg2.original_type
    5158      7551118 :                 : TREE_TYPE (arg2.value));
    5159              : 
    5160     10027348 :   result.value = build_binary_op (location, code,
    5161              :                                   arg1.value, arg2.value, true);
    5162     10027347 :   result.original_code = code;
    5163     10027347 :   result.original_type = NULL;
    5164     10027347 :   result.m_decimal = 0;
    5165              : 
    5166     10027347 :   if (TREE_CODE (result.value) == ERROR_MARK)
    5167              :     {
    5168         1297 :       set_c_expr_source_range (&result,
    5169              :                                arg1.get_start (),
    5170              :                                arg2.get_finish ());
    5171         1297 :       return result;
    5172              :     }
    5173              : 
    5174     10026050 :   if (location != UNKNOWN_LOCATION)
    5175     10026050 :     protected_set_expr_location (result.value, location);
    5176              : 
    5177     10026050 :   set_c_expr_source_range (&result,
    5178              :                            arg1.get_start (),
    5179              :                            arg2.get_finish ());
    5180              : 
    5181              :   /* Check for cases such as x+y<<z which users are likely
    5182              :      to misinterpret.  */
    5183     10026050 :   if (warn_parentheses)
    5184      2017935 :     warn_about_parentheses (location, code, code1, arg1.value, code2,
    5185              :                             arg2.value);
    5186              : 
    5187     10026050 :   if (warn_logical_op)
    5188          340 :     warn_logical_operator (location, code, TREE_TYPE (result.value),
    5189              :                            code1, arg1.value, code2, arg2.value);
    5190              : 
    5191     10026050 :   if (warn_constant_logical_operand
    5192      2016350 :       && (code == TRUTH_ANDIF_EXPR || code == TRUTH_ORIF_EXPR)
    5193        74918 :       && INTEGRAL_NB_TYPE_P (type1)
    5194        73097 :       && INTEGRAL_NB_TYPE_P (type2))
    5195              :     {
    5196        71488 :       const char *name = code == TRUTH_ANDIF_EXPR ? "&&" : "||";
    5197        71488 :       if (orig_arg1 == NULL_TREE)
    5198            0 :         orig_arg1 = arg1.value;
    5199        76881 :       auto enum_other_than_0_1 = [] (tree type) {
    5200         5393 :         if (TREE_CODE (type) != ENUMERAL_TYPE)
    5201              :           return false;
    5202           48 :         for (tree l = TYPE_VALUES (type); l; l = TREE_CHAIN (l))
    5203              :           {
    5204           40 :             tree v = DECL_INITIAL (TREE_VALUE (l));
    5205           40 :             if (!integer_zerop (v) && !integer_onep (v))
    5206              :               return true;
    5207              :           }
    5208              :         return false;
    5209              :       };
    5210       214448 :       auto diagnose_constant_logical_operand = [=] (tree val, tree type) {
    5211       142960 :         if (TREE_CODE (val) != INTEGER_CST || integer_zerop (val))
    5212              :           return false;
    5213         5417 :         if (integer_onep (val) && !enum_other_than_0_1 (type))
    5214              :           return false;
    5215           32 :         gcc_rich_location richloc (location);
    5216           32 :         richloc.add_fixit_replace (name + 1);
    5217           32 :         auto_diagnostic_group d;
    5218           32 :         if (warning_at (location, OPT_Wconstant_logical_operand,
    5219              :                         "use of logical %qs with constant operand %qE",
    5220              :                         name, val))
    5221           32 :           inform (&richloc, "use %qs for bitwise operation", name + 1);
    5222           32 :         return true;
    5223           32 :       };
    5224        71488 :       if (!diagnose_constant_logical_operand (arg2.value, type2))
    5225        71472 :         diagnose_constant_logical_operand (orig_arg1, type1);
    5226              :     }
    5227              : 
    5228     10026050 :   if (warn_tautological_compare)
    5229              :     {
    5230      2016448 :       tree lhs = arg1.value;
    5231      2016448 :       tree rhs = arg2.value;
    5232      2016448 :       if (TREE_CODE (lhs) == C_MAYBE_CONST_EXPR)
    5233              :         {
    5234            2 :           if (C_MAYBE_CONST_EXPR_PRE (lhs) != NULL_TREE
    5235            2 :               && TREE_SIDE_EFFECTS (C_MAYBE_CONST_EXPR_PRE (lhs)))
    5236              :             lhs = NULL_TREE;
    5237              :           else
    5238            2 :             lhs = C_MAYBE_CONST_EXPR_EXPR (lhs);
    5239              :         }
    5240      2016448 :       if (TREE_CODE (rhs) == C_MAYBE_CONST_EXPR)
    5241              :         {
    5242           12 :           if (C_MAYBE_CONST_EXPR_PRE (rhs) != NULL_TREE
    5243           12 :               && TREE_SIDE_EFFECTS (C_MAYBE_CONST_EXPR_PRE (rhs)))
    5244              :             rhs = NULL_TREE;
    5245              :           else
    5246           12 :             rhs = C_MAYBE_CONST_EXPR_EXPR (rhs);
    5247              :         }
    5248      2016448 :       if (lhs != NULL_TREE && rhs != NULL_TREE)
    5249      2016448 :         warn_tautological_cmp (location, code, lhs, rhs);
    5250              :     }
    5251              : 
    5252     10026050 :   if (warn_logical_not_paren
    5253      2016531 :       && TREE_CODE_CLASS (code) == tcc_comparison
    5254       412319 :       && code1 == TRUTH_NOT_EXPR
    5255       412319 :       && code2 != TRUTH_NOT_EXPR
    5256              :       /* Avoid warning for !!x == y.  */
    5257     10026184 :       && (TREE_CODE (arg1.value) != NE_EXPR
    5258           27 :           || !integer_zerop (TREE_OPERAND (arg1.value, 1))))
    5259              :     {
    5260              :       /* Avoid warning for !b == y where b has _Bool type.  */
    5261          107 :       tree t = integer_zero_node;
    5262          107 :       if (TREE_CODE (arg1.value) == EQ_EXPR
    5263           98 :           && integer_zerop (TREE_OPERAND (arg1.value, 1))
    5264          205 :           && TREE_TYPE (TREE_OPERAND (arg1.value, 0)) == integer_type_node)
    5265              :         {
    5266           90 :           t = TREE_OPERAND (arg1.value, 0);
    5267          199 :           do
    5268              :             {
    5269          199 :               if (TREE_TYPE (t) != integer_type_node)
    5270              :                 break;
    5271          180 :               if (TREE_CODE (t) == C_MAYBE_CONST_EXPR)
    5272           90 :                 t = C_MAYBE_CONST_EXPR_EXPR (t);
    5273           90 :               else if (CONVERT_EXPR_P (t))
    5274           19 :                 t = TREE_OPERAND (t, 0);
    5275              :               else
    5276              :                 break;
    5277              :             }
    5278              :           while (1);
    5279              :         }
    5280          107 :       if (!C_BOOLEAN_TYPE_P (TREE_TYPE (t)))
    5281           88 :         warn_logical_not_parentheses (location, code, arg1.value, arg2.value);
    5282              :     }
    5283              : 
    5284              :   /* Warn about comparisons against string literals, with the exception
    5285              :      of testing for equality or inequality of a string literal with NULL.  */
    5286     10026050 :   if (code == EQ_EXPR || code == NE_EXPR)
    5287              :     {
    5288      1189481 :       if ((code1 == STRING_CST
    5289           16 :            && !integer_zerop (tree_strip_nop_conversions (arg2.value)))
    5290      1189492 :           || (code2 == STRING_CST
    5291           39 :               && !integer_zerop (tree_strip_nop_conversions (arg1.value))))
    5292           36 :         warning_at (location, OPT_Waddress,
    5293              :                     "comparison with string literal results in unspecified behavior");
    5294              :       /* Warn for ptr == '\0', it's likely that it should've been ptr[0].  */
    5295      1189481 :       if (POINTER_TYPE_P (type1)
    5296        92663 :           && null_pointer_constant_p (arg2.value)
    5297      1210872 :           && char_type_p (type2))
    5298              :         {
    5299           18 :           auto_diagnostic_group d;
    5300           18 :           if (warning_at (location, OPT_Wpointer_compare,
    5301              :                             "comparison between pointer and zero character "
    5302              :                             "constant"))
    5303           10 :             inform (arg1.get_start (),
    5304              :                       "did you mean to dereference the pointer?");
    5305           18 :         }
    5306      1189463 :       else if (POINTER_TYPE_P (type2)
    5307        89986 :                && null_pointer_constant_p (arg1.value)
    5308      1189735 :                && char_type_p (type1))
    5309              :         {
    5310           10 :           auto_diagnostic_group d;
    5311           10 :           if (warning_at (location, OPT_Wpointer_compare,
    5312              :                             "comparison between pointer and zero character "
    5313              :                             "constant"))
    5314           10 :             inform (arg2.get_start (),
    5315              :                       "did you mean to dereference the pointer?");
    5316           10 :         }
    5317              :     }
    5318      8836569 :   else if (TREE_CODE_CLASS (code) == tcc_comparison
    5319      1016020 :            && (code1 == STRING_CST || code2 == STRING_CST))
    5320            0 :     warning_at (location, OPT_Waddress,
    5321              :                 "comparison with string literal results in unspecified "
    5322              :                 "behavior");
    5323              : 
    5324     10026050 :   if (warn_zero_as_null_pointer_constant
    5325           24 :       && c_inhibit_evaluation_warnings == 0
    5326           24 :       && TREE_CODE_CLASS (code) == tcc_comparison)
    5327              :     {
    5328           24 :       if ((TREE_CODE (type1) == POINTER_TYPE
    5329           17 :            || TREE_CODE (type1) == NULLPTR_TYPE)
    5330            9 :           && INTEGRAL_TYPE_P (type2)
    5331           33 :           && null_pointer_constant_p (arg2.value))
    5332            9 :         warning_at (arg2.get_location(), OPT_Wzero_as_null_pointer_constant,
    5333              :                     "zero as null pointer constant");
    5334              : 
    5335           24 :       if ((TREE_CODE (type2) == POINTER_TYPE
    5336           15 :            || TREE_CODE (type2) == NULLPTR_TYPE)
    5337           11 :           && INTEGRAL_TYPE_P (type1)
    5338           35 :           && null_pointer_constant_p (arg1.value))
    5339           11 :         warning_at (arg1.get_location(), OPT_Wzero_as_null_pointer_constant,
    5340              :                     "zero as null pointer constant");
    5341              :     }
    5342              : 
    5343     10026050 :   if (warn_array_compare
    5344      2016286 :       && TREE_CODE_CLASS (code) == tcc_comparison
    5345       412104 :       && TREE_CODE (type1) == ARRAY_TYPE
    5346           38 :       && TREE_CODE (type2) == ARRAY_TYPE)
    5347           15 :     do_warn_array_compare (location, code, arg1.value, arg2.value);
    5348              : 
    5349      2784164 :   if (TREE_OVERFLOW_P (result.value)
    5350          299 :       && !TREE_OVERFLOW_P (arg1.value)
    5351     10026342 :       && !TREE_OVERFLOW_P (arg2.value))
    5352          249 :     overflow_warning (location, result.value);
    5353              : 
    5354              :   /* Warn about comparisons of different enum types.  */
    5355     10026049 :   if (warn_enum_compare
    5356      2036677 :       && TREE_CODE_CLASS (code) == tcc_comparison
    5357       416775 :       && TREE_CODE (type1) == ENUMERAL_TYPE
    5358         7901 :       && TREE_CODE (type2) == ENUMERAL_TYPE
    5359     10033886 :       && TYPE_MAIN_VARIANT (type1) != TYPE_MAIN_VARIANT (type2))
    5360            2 :     warning_at (location, OPT_Wenum_compare,
    5361              :                 "comparison between %qT and %qT",
    5362              :                 type1, type2);
    5363              : 
    5364     10026049 :   if (warn_xor_used_as_pow
    5365     10026049 :       && code == BIT_XOR_EXPR
    5366        84801 :       && arg1.m_decimal
    5367          737 :       && arg2.m_decimal)
    5368          427 :     check_for_xor_used_as_pow (arg1.get_location (), arg1.value,
    5369              :                                location,
    5370              :                                arg2.get_location (), arg2.value);
    5371              : 
    5372              :   return result;
    5373              : }
    5374              : 
    5375              : /* Return a tree for the difference of pointers OP0 and OP1.
    5376              :    The resulting tree has type ptrdiff_t.  If POINTER_SUBTRACT sanitization is
    5377              :    enabled, assign to INSTRUMENT_EXPR call to libsanitizer.  */
    5378              : 
    5379              : static tree
    5380         3744 : pointer_diff (location_t loc, tree op0, tree op1, tree *instrument_expr)
    5381              : {
    5382         3744 :   tree restype = ptrdiff_type_node;
    5383         3744 :   tree result, inttype;
    5384              : 
    5385         3744 :   addr_space_t as0 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (op0)));
    5386         3744 :   addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (op1)));
    5387         3744 :   tree target_type = TREE_TYPE (TREE_TYPE (op0));
    5388         3744 :   tree orig_op0 = op0;
    5389         3744 :   tree orig_op1 = op1;
    5390              : 
    5391              :   /* If the operands point into different address spaces, we need to
    5392              :      explicitly convert them to pointers into the common address space
    5393              :      before we can subtract the numerical address values.  */
    5394         3744 :   if (as0 != as1)
    5395              :     {
    5396            0 :       addr_space_t as_common;
    5397            0 :       tree common_type;
    5398              : 
    5399              :       /* Determine the common superset address space.  This is guaranteed
    5400              :          to exist because the caller verified that comp_target_types
    5401              :          returned non-zero.  */
    5402            0 :       if (!addr_space_superset (as0, as1, &as_common))
    5403            0 :         gcc_unreachable ();
    5404              : 
    5405            0 :       common_type = common_pointer_type (TREE_TYPE (op0), TREE_TYPE (op1), NULL_TREE);
    5406            0 :       op0 = convert (common_type, op0);
    5407            0 :       op1 = convert (common_type, op1);
    5408              :     }
    5409              : 
    5410              :   /* Determine integer type result of the subtraction.  This will usually
    5411              :      be the same as the result type (ptrdiff_t), but may need to be a wider
    5412              :      type if pointers for the address space are wider than ptrdiff_t.  */
    5413         3744 :   if (TYPE_PRECISION (restype) < TYPE_PRECISION (TREE_TYPE (op0)))
    5414            0 :     inttype = c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op0)), 0);
    5415              :   else
    5416              :     inttype = restype;
    5417              : 
    5418         3744 :   if (VOID_TYPE_P (target_type))
    5419          150 :     pedwarn (loc, OPT_Wpointer_arith,
    5420              :              "pointer of type %<void *%> used in subtraction");
    5421         3744 :   if (TREE_CODE (target_type) == FUNCTION_TYPE)
    5422            4 :     pedwarn (loc, OPT_Wpointer_arith,
    5423              :              "pointer to a function used in subtraction");
    5424              : 
    5425         3744 :   if (current_function_decl != NULL_TREE
    5426         3744 :       && sanitize_flags_p (SANITIZE_POINTER_SUBTRACT))
    5427              :     {
    5428           70 :       op0 = save_expr (c_fully_fold (op0, false, NULL));
    5429           70 :       op1 = save_expr (c_fully_fold (op1, false, NULL));
    5430              : 
    5431           70 :       tree tt = builtin_decl_explicit (BUILT_IN_ASAN_POINTER_SUBTRACT);
    5432           70 :       *instrument_expr = build_call_expr_loc (loc, tt, 2, op0, op1);
    5433              :     }
    5434              : 
    5435              :   /* First do the subtraction, then build the divide operator
    5436              :      and only convert at the very end.
    5437              :      Do not do default conversions in case restype is a short type.  */
    5438              : 
    5439              :   /* POINTER_DIFF_EXPR requires a signed integer type of the same size as
    5440              :      pointers.  If some platform cannot provide that, or has a larger
    5441              :      ptrdiff_type to support differences larger than half the address
    5442              :      space, cast the pointers to some larger integer type and do the
    5443              :      computations in that type.  */
    5444         3744 :   if (TYPE_PRECISION (inttype) > TYPE_PRECISION (TREE_TYPE (op0)))
    5445            0 :     op0 = build_binary_op (loc, MINUS_EXPR, convert (inttype, op0),
    5446              :                            convert (inttype, op1), false);
    5447              :   else
    5448              :     {
    5449              :       /* Cast away qualifiers.  */
    5450         3744 :       op0 = convert (c_common_type (TREE_TYPE (op0), TREE_TYPE (op0)), op0);
    5451         3744 :       op1 = convert (c_common_type (TREE_TYPE (op1), TREE_TYPE (op1)), op1);
    5452         3744 :       op0 = build2_loc (loc, POINTER_DIFF_EXPR, inttype, op0, op1);
    5453              :     }
    5454              : 
    5455              :   /* This generates an error if op1 is pointer to incomplete type.  */
    5456         3744 :   if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (orig_op1))))
    5457            4 :     error_at (loc, "arithmetic on pointer to an incomplete type");
    5458         3740 :   else if (verify_type_context (loc, TCTX_POINTER_ARITH,
    5459         3740 :                                 TREE_TYPE (TREE_TYPE (orig_op0))))
    5460         7480 :     verify_type_context (loc, TCTX_POINTER_ARITH,
    5461         3740 :                          TREE_TYPE (TREE_TYPE (orig_op1)));
    5462              : 
    5463         3744 :   op1 = c_size_in_bytes (target_type);
    5464              : 
    5465         3744 :   if (pointer_to_zero_sized_aggr_p (TREE_TYPE (orig_op1)))
    5466            4 :     error_at (loc, "arithmetic on pointer to an empty aggregate");
    5467              : 
    5468              :   /* Divide by the size, in easiest possible way.  */
    5469         3744 :   result = fold_build2_loc (loc, EXACT_DIV_EXPR, inttype,
    5470              :                             op0, convert (inttype, op1));
    5471              : 
    5472              :   /* Convert to final result type if necessary.  */
    5473         3744 :   return convert (restype, result);
    5474              : }
    5475              : 
    5476              : /* Expand atomic compound assignments into an appropriate sequence as
    5477              :    specified by the C11 standard section 6.5.16.2.
    5478              : 
    5479              :        _Atomic T1 E1
    5480              :        T2 E2
    5481              :        E1 op= E2
    5482              : 
    5483              :   This sequence is used for all types for which these operations are
    5484              :   supported.
    5485              : 
    5486              :   In addition, built-in versions of the 'fe' prefixed routines may
    5487              :   need to be invoked for floating point (real, complex or vector) when
    5488              :   floating-point exceptions are supported.  See 6.5.16.2 footnote 113.
    5489              : 
    5490              :   T1 newval;
    5491              :   T1 old;
    5492              :   T1 *addr
    5493              :   T2 val
    5494              :   fenv_t fenv
    5495              : 
    5496              :   addr = &E1;
    5497              :   val = (E2);
    5498              :   __atomic_load (addr, &old, SEQ_CST);
    5499              :   feholdexcept (&fenv);
    5500              : loop:
    5501              :     newval = old op val;
    5502              :     if (__atomic_compare_exchange_strong (addr, &old, &newval, SEQ_CST,
    5503              :                                           SEQ_CST))
    5504              :       goto done;
    5505              :     feclearexcept (FE_ALL_EXCEPT);
    5506              :     goto loop:
    5507              : done:
    5508              :   feupdateenv (&fenv);
    5509              : 
    5510              :   The compiler will issue the __atomic_fetch_* built-in when possible,
    5511              :   otherwise it will generate the generic form of the atomic operations.
    5512              :   This requires temp(s) and has their address taken.  The atomic processing
    5513              :   is smart enough to figure out when the size of an object can utilize
    5514              :   a lock-free version, and convert the built-in call to the appropriate
    5515              :   lock-free routine.  The optimizers will then dispose of any temps that
    5516              :   are no longer required, and lock-free implementations are utilized as
    5517              :   long as there is target support for the required size.
    5518              : 
    5519              :   If the operator is NOP_EXPR, then this is a simple assignment, and
    5520              :   an __atomic_store is issued to perform the assignment rather than
    5521              :   the above loop.  */
    5522              : 
    5523              : /* Build an atomic assignment at LOC, expanding into the proper
    5524              :    sequence to store LHS MODIFYCODE= RHS.  Return a value representing
    5525              :    the result of the operation, unless RETURN_OLD_P, in which case
    5526              :    return the old value of LHS (this is only for postincrement and
    5527              :    postdecrement).  */
    5528              : 
    5529              : static tree
    5530        30457 : build_atomic_assign (location_t loc, tree lhs, enum tree_code modifycode,
    5531              :                      tree rhs, bool return_old_p)
    5532              : {
    5533        30457 :   tree fndecl, func_call;
    5534        30457 :   vec<tree, va_gc> *params;
    5535        30457 :   tree val, nonatomic_lhs_type, nonatomic_rhs_type, newval, newval_addr;
    5536        30457 :   tree old, old_addr;
    5537        30457 :   tree compound_stmt = NULL_TREE;
    5538        30457 :   tree stmt, goto_stmt;
    5539        30457 :   tree loop_label, loop_decl, done_label, done_decl;
    5540              : 
    5541        30457 :   tree lhs_type = TREE_TYPE (lhs);
    5542        30457 :   tree lhs_addr = build_unary_op (loc, ADDR_EXPR, lhs, false);
    5543        30457 :   tree seq_cst = build_int_cst (integer_type_node, MEMMODEL_SEQ_CST);
    5544        30457 :   tree rhs_semantic_type = TREE_TYPE (rhs);
    5545        30457 :   tree nonatomic_rhs_semantic_type;
    5546        30457 :   tree rhs_type;
    5547              : 
    5548        30457 :   gcc_assert (TYPE_ATOMIC (lhs_type));
    5549              : 
    5550        30457 :   if (return_old_p)
    5551         2313 :     gcc_assert (modifycode == PLUS_EXPR || modifycode == MINUS_EXPR);
    5552              : 
    5553              :   /* Allocate enough vector items for a compare_exchange.  */
    5554        30457 :   vec_alloc (params, 6);
    5555              : 
    5556              :   /* Create a compound statement to hold the sequence of statements
    5557              :      with a loop.  */
    5558        30457 :   if (modifycode != NOP_EXPR)
    5559              :     {
    5560        19954 :       compound_stmt = c_begin_compound_stmt (false);
    5561              : 
    5562              :       /* For consistency with build_modify_expr on non-_Atomic,
    5563              :          mark the lhs as read.  Also, it would be very hard to match
    5564              :          such expressions in mark_exp_read.  */
    5565        19954 :       mark_exp_read (lhs);
    5566              :     }
    5567              : 
    5568              :   /* Remove any excess precision (which is only present here in the
    5569              :      case of compound assignments).  */
    5570        30457 :   if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
    5571              :     {
    5572            0 :       gcc_assert (modifycode != NOP_EXPR);
    5573            0 :       rhs = TREE_OPERAND (rhs, 0);
    5574              :     }
    5575        30457 :   rhs_type = TREE_TYPE (rhs);
    5576              : 
    5577              :   /* Fold the RHS if it hasn't already been folded.  */
    5578        30457 :   if (modifycode != NOP_EXPR)
    5579        19954 :     rhs = c_fully_fold (rhs, false, NULL);
    5580              : 
    5581              :   /* Remove the qualifiers for the rest of the expressions and create
    5582              :      the VAL temp variable to hold the RHS.  */
    5583        30457 :   nonatomic_lhs_type = build_qualified_type (lhs_type, TYPE_UNQUALIFIED);
    5584        30457 :   nonatomic_rhs_type = build_qualified_type (rhs_type, TYPE_UNQUALIFIED);
    5585        30457 :   nonatomic_rhs_semantic_type = build_qualified_type (rhs_semantic_type,
    5586              :                                                       TYPE_UNQUALIFIED);
    5587        30457 :   val = create_tmp_var_raw (nonatomic_rhs_type);
    5588        30457 :   TREE_ADDRESSABLE (val) = 1;
    5589        30457 :   suppress_warning (val);
    5590        30457 :   rhs = build4 (TARGET_EXPR, nonatomic_rhs_type, val, rhs, NULL_TREE,
    5591              :                 NULL_TREE);
    5592        30457 :   TREE_SIDE_EFFECTS (rhs) = 1;
    5593        30457 :   SET_EXPR_LOCATION (rhs, loc);
    5594        30457 :   if (modifycode != NOP_EXPR)
    5595        19954 :     add_stmt (rhs);
    5596              : 
    5597              :   /* NOP_EXPR indicates it's a straight store of the RHS. Simply issue
    5598              :      an atomic_store.  */
    5599        19954 :   if (modifycode == NOP_EXPR)
    5600              :     {
    5601        10503 :       compound_stmt = rhs;
    5602              :       /* Build __atomic_store (&lhs, &val, SEQ_CST)  */
    5603        10503 :       rhs = build_unary_op (loc, ADDR_EXPR, val, false);
    5604        10503 :       fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_STORE);
    5605        10503 :       params->quick_push (lhs_addr);
    5606        10503 :       params->quick_push (rhs);
    5607        10503 :       params->quick_push (seq_cst);
    5608        10503 :       func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
    5609              : 
    5610        10503 :       compound_stmt = build2 (COMPOUND_EXPR, void_type_node,
    5611              :                               compound_stmt, func_call);
    5612              : 
    5613              :       /* VAL is the value which was stored, return a COMPOUND_STMT of
    5614              :          the statement and that value.  */
    5615        10503 :       return build2 (COMPOUND_EXPR, nonatomic_lhs_type, compound_stmt, val);
    5616              :     }
    5617              : 
    5618              :   /* Attempt to implement the atomic operation as an __atomic_fetch_* or
    5619              :      __atomic_*_fetch built-in rather than a CAS loop.  atomic_bool type
    5620              :      isn't applicable for such builtins.  ??? Do we want to handle enums?  */
    5621        19954 :   if ((TREE_CODE (lhs_type) == INTEGER_TYPE || POINTER_TYPE_P (lhs_type))
    5622        13941 :       && TREE_CODE (rhs_type) == INTEGER_TYPE)
    5623              :     {
    5624        11713 :       built_in_function fncode;
    5625        11713 :       switch (modifycode)
    5626              :         {
    5627         3075 :         case PLUS_EXPR:
    5628         3075 :         case POINTER_PLUS_EXPR:
    5629         2124 :           fncode = (return_old_p
    5630         3075 :                     ? BUILT_IN_ATOMIC_FETCH_ADD_N
    5631              :                     : BUILT_IN_ATOMIC_ADD_FETCH_N);
    5632              :           break;
    5633         2889 :         case MINUS_EXPR:
    5634         2094 :           fncode = (return_old_p
    5635         2889 :                     ? BUILT_IN_ATOMIC_FETCH_SUB_N
    5636              :                     : BUILT_IN_ATOMIC_SUB_FETCH_N);
    5637              :           break;
    5638          609 :         case BIT_AND_EXPR:
    5639          609 :           fncode = (return_old_p
    5640          609 :                     ? BUILT_IN_ATOMIC_FETCH_AND_N
    5641              :                     : BUILT_IN_ATOMIC_AND_FETCH_N);
    5642              :           break;
    5643          609 :         case BIT_IOR_EXPR:
    5644          609 :           fncode = (return_old_p
    5645          609 :                     ? BUILT_IN_ATOMIC_FETCH_OR_N
    5646              :                     : BUILT_IN_ATOMIC_OR_FETCH_N);
    5647              :           break;
    5648          609 :         case BIT_XOR_EXPR:
    5649          609 :           fncode = (return_old_p
    5650          609 :                     ? BUILT_IN_ATOMIC_FETCH_XOR_N
    5651              :                     : BUILT_IN_ATOMIC_XOR_FETCH_N);
    5652              :           break;
    5653         3922 :         default:
    5654         3922 :           goto cas_loop;
    5655              :         }
    5656              : 
    5657              :       /* We can only use "_1" through "_16" variants of the atomic fetch
    5658              :          built-ins.  */
    5659         7791 :       unsigned HOST_WIDE_INT size = tree_to_uhwi (TYPE_SIZE_UNIT (lhs_type));
    5660         7791 :       if (size != 1 && size != 2 && size != 4 && size != 8 && size != 16)
    5661            0 :         goto cas_loop;
    5662              : 
    5663              :       /* If this is a pointer type, we need to multiply by the size of
    5664              :          the pointer target type.  */
    5665         7791 :       if (POINTER_TYPE_P (lhs_type))
    5666              :         {
    5667         1018 :           if (!COMPLETE_TYPE_P (TREE_TYPE (lhs_type))
    5668              :               /* ??? This would introduce -Wdiscarded-qualifiers
    5669              :                  warning: __atomic_fetch_* expect volatile void *
    5670              :                  type as the first argument.  (Assignments between
    5671              :                  atomic and non-atomic objects are OK.) */
    5672         1018 :               || TYPE_RESTRICT (lhs_type))
    5673           17 :             goto cas_loop;
    5674         1001 :           tree sz = TYPE_SIZE_UNIT (TREE_TYPE (lhs_type));
    5675         1001 :           rhs = fold_build2_loc (loc, MULT_EXPR, ptrdiff_type_node,
    5676              :                                  convert (ptrdiff_type_node, rhs),
    5677              :                                  convert (ptrdiff_type_node, sz));
    5678              :         }
    5679              : 
    5680              :       /* Build __atomic_fetch_* (&lhs, &val, SEQ_CST), or
    5681              :          __atomic_*_fetch (&lhs, &val, SEQ_CST).  */
    5682         7774 :       fndecl = builtin_decl_explicit (fncode);
    5683         7774 :       params->quick_push (lhs_addr);
    5684         7774 :       params->quick_push (rhs);
    5685         7774 :       params->quick_push (seq_cst);
    5686         7774 :       func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
    5687              : 
    5688         7774 :       newval = create_tmp_var_raw (nonatomic_lhs_type);
    5689         7774 :       TREE_ADDRESSABLE (newval) = 1;
    5690         7774 :       suppress_warning (newval);
    5691         7774 :       rhs = build4 (TARGET_EXPR, nonatomic_lhs_type, newval, func_call,
    5692              :                     NULL_TREE, NULL_TREE);
    5693         7774 :       SET_EXPR_LOCATION (rhs, loc);
    5694         7774 :       add_stmt (rhs);
    5695              : 
    5696              :       /* Finish the compound statement.  */
    5697         7774 :       compound_stmt = c_end_compound_stmt (loc, compound_stmt, false);
    5698              : 
    5699              :       /* NEWVAL is the value which was stored, return a COMPOUND_STMT of
    5700              :          the statement and that value.  */
    5701         7774 :       return build2 (COMPOUND_EXPR, nonatomic_lhs_type, compound_stmt, newval);
    5702              :     }
    5703              : 
    5704         8241 : cas_loop:
    5705              :   /* Create the variables and labels required for the op= form.  */
    5706        12180 :   old = create_tmp_var_raw (nonatomic_lhs_type);
    5707        12180 :   old_addr = build_unary_op (loc, ADDR_EXPR, old, false);
    5708        12180 :   TREE_ADDRESSABLE (old) = 1;
    5709        12180 :   suppress_warning (old);
    5710              : 
    5711        12180 :   newval = create_tmp_var_raw (nonatomic_lhs_type);
    5712        12180 :   newval_addr = build_unary_op (loc, ADDR_EXPR, newval, false);
    5713        12180 :   TREE_ADDRESSABLE (newval) = 1;
    5714        12180 :   suppress_warning (newval);
    5715              : 
    5716        12180 :   loop_decl = create_artificial_label (loc);
    5717        12180 :   loop_label = build1 (LABEL_EXPR, void_type_node, loop_decl);
    5718              : 
    5719        12180 :   done_decl = create_artificial_label (loc);
    5720        12180 :   done_label = build1 (LABEL_EXPR, void_type_node, done_decl);
    5721              : 
    5722              :   /* __atomic_load (addr, &old, SEQ_CST).  */
    5723        12180 :   fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_LOAD);
    5724        12180 :   params->quick_push (lhs_addr);
    5725        12180 :   params->quick_push (old_addr);
    5726        12180 :   params->quick_push (seq_cst);
    5727        12180 :   func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
    5728        12180 :   old = build4 (TARGET_EXPR, nonatomic_lhs_type, old, func_call, NULL_TREE,
    5729              :                 NULL_TREE);
    5730        12180 :   add_stmt (old);
    5731        12180 :   params->truncate (0);
    5732              : 
    5733              :   /* Create the expressions for floating-point environment
    5734              :      manipulation, if required.  */
    5735        12180 :   bool need_fenv = (flag_trapping_math
    5736        12180 :                     && (FLOAT_TYPE_P (lhs_type) || FLOAT_TYPE_P (rhs_type)));
    5737        12180 :   tree hold_call = NULL_TREE, clear_call = NULL_TREE, update_call = NULL_TREE;
    5738        12180 :   if (need_fenv)
    5739         7054 :     targetm.atomic_assign_expand_fenv (&hold_call, &clear_call, &update_call);
    5740              : 
    5741        12180 :   if (hold_call)
    5742         7054 :     add_stmt (hold_call);
    5743              : 
    5744              :   /* loop:  */
    5745        12180 :   add_stmt (loop_label);
    5746              : 
    5747              :   /* newval = old + val;  */
    5748        12180 :   if (rhs_type != rhs_semantic_type)
    5749            0 :     val = build1 (EXCESS_PRECISION_EXPR, nonatomic_rhs_semantic_type, val);
    5750        12180 :   rhs = build_binary_op (loc, modifycode,
    5751              :                          convert_lvalue_to_rvalue (loc, old, true, true),
    5752              :                          val, true);
    5753        12180 :   if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
    5754              :     {
    5755            0 :       tree eptype = TREE_TYPE (rhs);
    5756            0 :       rhs = c_fully_fold (TREE_OPERAND (rhs, 0), false, NULL);
    5757            0 :       rhs = build1 (EXCESS_PRECISION_EXPR, eptype, rhs);
    5758              :     }
    5759              :   else
    5760        12180 :     rhs = c_fully_fold (rhs, false, NULL);
    5761        12180 :   rhs = convert_for_assignment (loc, UNKNOWN_LOCATION, nonatomic_lhs_type,
    5762              :                                 rhs, NULL_TREE, ic_assign, false, NULL_TREE,
    5763              :                                 NULL_TREE, 0);
    5764              :   /* The temporary variable for NEWVAL is only gimplified correctly (in
    5765              :      particular, given a DECL_CONTEXT) if used in a TARGET_EXPR.  To avoid
    5766              :      subsequent ICEs in nested function processing after an error, ensure such
    5767              :      a TARGET_EXPR is built even after an error.  */
    5768        12180 :   if (rhs == error_mark_node)
    5769           10 :     rhs = old;
    5770        12180 :   rhs = build4 (TARGET_EXPR, nonatomic_lhs_type, newval, rhs, NULL_TREE,
    5771              :                 NULL_TREE);
    5772        12180 :   SET_EXPR_LOCATION (rhs, loc);
    5773        12180 :   add_stmt (rhs);
    5774              : 
    5775              :   /* if (__atomic_compare_exchange (addr, &old, &new, false, SEQ_CST, SEQ_CST))
    5776              :        goto done;  */
    5777        12180 :   fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_COMPARE_EXCHANGE);
    5778        12180 :   params->quick_push (lhs_addr);
    5779        12180 :   params->quick_push (old_addr);
    5780        12180 :   params->quick_push (newval_addr);
    5781        12180 :   params->quick_push (integer_zero_node);
    5782        12180 :   params->quick_push (seq_cst);
    5783        12180 :   params->quick_push (seq_cst);
    5784        12180 :   func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
    5785              : 
    5786        12180 :   goto_stmt = build1 (GOTO_EXPR, void_type_node, done_decl);
    5787        12180 :   SET_EXPR_LOCATION (goto_stmt, loc);
    5788              : 
    5789        12180 :   stmt = build3 (COND_EXPR, void_type_node, func_call, goto_stmt, NULL_TREE);
    5790        12180 :   SET_EXPR_LOCATION (stmt, loc);
    5791        12180 :   add_stmt (stmt);
    5792              : 
    5793        12180 :   if (clear_call)
    5794         7054 :     add_stmt (clear_call);
    5795              : 
    5796              :   /* goto loop;  */
    5797        12180 :   goto_stmt  = build1 (GOTO_EXPR, void_type_node, loop_decl);
    5798        12180 :   SET_EXPR_LOCATION (goto_stmt, loc);
    5799        12180 :   add_stmt (goto_stmt);
    5800              : 
    5801              :   /* done:  */
    5802        12180 :   add_stmt (done_label);
    5803              : 
    5804        12180 :   if (update_call)
    5805         7054 :     add_stmt (update_call);
    5806              : 
    5807              :   /* Finish the compound statement.  */
    5808        12180 :   compound_stmt = c_end_compound_stmt (loc, compound_stmt, false);
    5809              : 
    5810              :   /* NEWVAL is the value that was successfully stored, return a
    5811              :      COMPOUND_EXPR of the statement and the appropriate value.  */
    5812        23787 :   return build2 (COMPOUND_EXPR, nonatomic_lhs_type, compound_stmt,
    5813        12180 :                  return_old_p ? old : newval);
    5814              : }
    5815              : 
    5816              : /* Construct and perhaps optimize a tree representation
    5817              :    for a unary operation.  CODE, a tree_code, specifies the operation
    5818              :    and XARG is the operand.
    5819              :    For any CODE other than ADDR_EXPR, NOCONVERT suppresses the default
    5820              :    promotions (such as from short to int).
    5821              :    For ADDR_EXPR, the default promotions are not applied; NOCONVERT allows
    5822              :    non-lvalues; this is only used to handle conversion of non-lvalue arrays
    5823              :    to pointers in C99.
    5824              : 
    5825              :    LOCATION is the location of the operator.  */
    5826              : 
    5827              : tree
    5828     62863795 : build_unary_op (location_t location, enum tree_code code, tree xarg,
    5829              :                 bool noconvert)
    5830              : {
    5831              :   /* No default_conversion here.  It causes trouble for ADDR_EXPR.  */
    5832     62863795 :   tree arg = xarg;
    5833     62863795 :   tree argtype = NULL_TREE;
    5834     62863795 :   enum tree_code typecode;
    5835     62863795 :   tree val;
    5836     62863795 :   tree ret = error_mark_node;
    5837     62863795 :   tree eptype = NULL_TREE;
    5838     62863795 :   const char *invalid_op_diag;
    5839              : 
    5840              :   /* If ARG is wrapped in a call to .ACCESS_WITH_SIZE — created when the
    5841              :      C parser rvalue-converts a counted_by-annotated member access (see
    5842              :      PR123569) — unwrap it here.  Unary operators that consume an rvalue
    5843              :      (!, -, +) read the value itself rather than dereferencing into the
    5844              :      pointed-to data, so the bounds-checking wrapper is unnecessary and
    5845              :      would otherwise reach build_unary_op while it is not equipped to
    5846              :      handle the wrapped form.  PR123569 fixed the ++/-- side of this by
    5847              :      suppressing wrapper creation in the parser; the rvalue-consuming
    5848              :      ops still receive the wrapper and need to strip it here.  */
    5849     62863795 :   if (is_access_with_size_p (arg))
    5850            1 :     xarg = arg = get_ref_from_access_with_size (arg);
    5851              : 
    5852     62863795 :   gcc_checking_assert (!is_access_with_size_p (arg));
    5853              : 
    5854     62863795 :   bool int_operands = EXPR_INT_CONST_OPERANDS (xarg);
    5855              :   if (int_operands)
    5856      6778626 :     arg = remove_c_maybe_const_expr (arg);
    5857              : 
    5858     62863795 :   if (code != ADDR_EXPR)
    5859      8879509 :     arg = require_complete_type (location, arg);
    5860              : 
    5861     62863795 :   typecode = TREE_CODE (TREE_TYPE (arg));
    5862     62863795 :   if (typecode == ERROR_MARK)
    5863           74 :     return error_mark_node;
    5864     62863721 :   if (typecode == ENUMERAL_TYPE || typecode == BOOLEAN_TYPE)
    5865        32480 :     typecode = INTEGER_TYPE;
    5866              : 
    5867    125727442 :   if ((invalid_op_diag
    5868     62863721 :        = targetm.invalid_unary_op (code, TREE_TYPE (xarg))))
    5869              :     {
    5870            0 :       error_at (location, invalid_op_diag);
    5871            0 :       return error_mark_node;
    5872              :     }
    5873              : 
    5874     62863721 :   if (TREE_CODE (arg) == EXCESS_PRECISION_EXPR)
    5875              :     {
    5876          251 :       eptype = TREE_TYPE (arg);
    5877          251 :       arg = TREE_OPERAND (arg, 0);
    5878              :     }
    5879              : 
    5880     62863721 :   switch (code)
    5881              :     {
    5882        28807 :     case CONVERT_EXPR:
    5883              :       /* This is used for unary plus, because a CONVERT_EXPR
    5884              :          is enough to prevent anybody from looking inside for
    5885              :          associativity, but won't generate any code.  */
    5886        28812 :       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
    5887           53 :             || typecode == FIXED_POINT_TYPE || typecode == COMPLEX_TYPE
    5888           50 :             || typecode == BITINT_TYPE
    5889            5 :             || gnu_vector_type_p (TREE_TYPE (arg))))
    5890              :         {
    5891            1 :           error_at (location, "wrong type argument to unary plus");
    5892            1 :           return error_mark_node;
    5893              :         }
    5894        28806 :       else if (!noconvert)
    5895        28806 :         arg = default_conversion (arg);
    5896        28806 :       arg = non_lvalue_loc (location, arg);
    5897        28806 :       break;
    5898              : 
    5899      7017554 :     case NEGATE_EXPR:
    5900      7469465 :       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
    5901       488670 :             || typecode == FIXED_POINT_TYPE || typecode == COMPLEX_TYPE
    5902       457395 :             || typecode == BITINT_TYPE
    5903       451911 :             || gnu_vector_type_p (TREE_TYPE (arg))))
    5904              :         {
    5905            1 :           error_at (location, "wrong type argument to unary minus");
    5906            1 :           return error_mark_node;
    5907              :         }
    5908      7017553 :       else if (!noconvert)
    5909      7017502 :         arg = default_conversion (arg);
    5910              :       break;
    5911              : 
    5912       299056 :     case BIT_NOT_EXPR:
    5913              :       /* ~ works on integer types and non float vectors. */
    5914       299056 :       if (typecode == INTEGER_TYPE
    5915       299056 :           || typecode == BITINT_TYPE
    5916       299056 :           || (gnu_vector_type_p (TREE_TYPE (arg))
    5917         2132 :               && !VECTOR_FLOAT_TYPE_P (TREE_TYPE (arg))))
    5918              :         {
    5919              :           tree e = arg;
    5920              : 
    5921              :           /* Warn if the expression has boolean value.  */
    5922       298450 :           while (TREE_CODE (e) == COMPOUND_EXPR)
    5923           11 :             e = TREE_OPERAND (e, 1);
    5924              : 
    5925       596862 :           if ((C_BOOLEAN_TYPE_P (TREE_TYPE (arg))
    5926       596862 :                || truth_value_p (TREE_CODE (e))))
    5927              :             {
    5928          149 :               auto_diagnostic_group d;
    5929          149 :               if (warning_at (location, OPT_Wbool_operation,
    5930              :                                 "%<~%> on a boolean expression"))
    5931              :                 {
    5932           12 :                   gcc_rich_location richloc (location);
    5933           12 :                   richloc.add_fixit_insert_before (location, "!");
    5934           12 :                   inform (&richloc, "did you mean to use logical not?");
    5935           12 :                 }
    5936          149 :             }
    5937       298439 :           if (!noconvert)
    5938       298436 :             arg = default_conversion (arg);
    5939              :         }
    5940          617 :       else if (typecode == COMPLEX_TYPE)
    5941              :         {
    5942          612 :           code = CONJ_EXPR;
    5943          612 :           pedwarn (location, OPT_Wpedantic,
    5944              :                    "ISO C does not support %<~%> for complex conjugation");
    5945          612 :           if (!noconvert)
    5946          612 :             arg = default_conversion (arg);
    5947              :         }
    5948              :       else
    5949              :         {
    5950            5 :           error_at (location, "wrong type argument to bit-complement");
    5951            5 :           return error_mark_node;
    5952              :         }
    5953              :       break;
    5954              : 
    5955            3 :     case ABS_EXPR:
    5956            3 :       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE))
    5957              :         {
    5958            0 :           error_at (location, "wrong type argument to abs");
    5959            0 :           return error_mark_node;
    5960              :         }
    5961            3 :       else if (!noconvert)
    5962            0 :         arg = default_conversion (arg);
    5963              :       break;
    5964              : 
    5965            7 :     case ABSU_EXPR:
    5966            7 :       if (!(typecode == INTEGER_TYPE))
    5967              :         {
    5968            0 :           error_at (location, "wrong type argument to absu");
    5969            0 :           return error_mark_node;
    5970              :         }
    5971            7 :       else if (!noconvert)
    5972            0 :         arg = default_conversion (arg);
    5973              :       break;
    5974              : 
    5975            0 :     case CONJ_EXPR:
    5976              :       /* Conjugating a real value is a no-op, but allow it anyway.  */
    5977            0 :       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
    5978              :             || typecode == COMPLEX_TYPE))
    5979              :         {
    5980            0 :           error_at (location, "wrong type argument to conjugation");
    5981            0 :           return error_mark_node;
    5982              :         }
    5983            0 :       else if (!noconvert)
    5984            0 :         arg = default_conversion (arg);
    5985              :       break;
    5986              : 
    5987       379374 :     case TRUTH_NOT_EXPR:
    5988       379374 :       if (typecode != INTEGER_TYPE && typecode != FIXED_POINT_TYPE
    5989         7264 :           && typecode != REAL_TYPE && typecode != POINTER_TYPE
    5990           21 :           && typecode != COMPLEX_TYPE && typecode != NULLPTR_TYPE
    5991           18 :           && typecode != BITINT_TYPE)
    5992              :         {
    5993           10 :           error_at (location,
    5994              :                     "wrong type argument to unary exclamation mark");
    5995           10 :           return error_mark_node;
    5996              :         }
    5997       379364 :       if (int_operands)
    5998              :         {
    5999       139886 :           arg = c_objc_common_truthvalue_conversion (location, xarg);
    6000       139886 :           arg = remove_c_maybe_const_expr (arg);
    6001              :         }
    6002              :       else
    6003       239478 :         arg = c_objc_common_truthvalue_conversion (location, arg);
    6004       379364 :       ret = invert_truthvalue_loc (location, arg);
    6005       379364 :       eptype = NULL_TREE;
    6006              :       /* If the TRUTH_NOT_EXPR has been folded, reset the location.  */
    6007       379364 :       if (EXPR_P (ret) && EXPR_HAS_LOCATION (ret))
    6008       239071 :         location = EXPR_LOCATION (ret);
    6009       379364 :       goto return_build_unary_op;
    6010              : 
    6011       203172 :     case REALPART_EXPR:
    6012       203172 :     case IMAGPART_EXPR:
    6013       203172 :       ret = build_real_imag_expr (location, code, arg);
    6014       203172 :       if (ret == error_mark_node)
    6015              :         return error_mark_node;
    6016       203164 :       if (eptype && TREE_CODE (eptype) == COMPLEX_TYPE)
    6017            2 :         eptype = TREE_TYPE (eptype);
    6018       203164 :       goto return_build_unary_op;
    6019              : 
    6020       951491 :     case PREINCREMENT_EXPR:
    6021       951491 :     case POSTINCREMENT_EXPR:
    6022       951491 :     case PREDECREMENT_EXPR:
    6023       951491 :     case POSTDECREMENT_EXPR:
    6024              : 
    6025       951491 :       if (TREE_CODE (arg) == C_MAYBE_CONST_EXPR)
    6026              :         {
    6027            2 :           tree inner = build_unary_op (location, code,
    6028            2 :                                        C_MAYBE_CONST_EXPR_EXPR (arg),
    6029              :                                        noconvert);
    6030            2 :           if (inner == error_mark_node)
    6031              :             return error_mark_node;
    6032            4 :           ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner),
    6033            2 :                         C_MAYBE_CONST_EXPR_PRE (arg), inner);
    6034            2 :           gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (arg));
    6035            2 :           C_MAYBE_CONST_EXPR_NON_CONST (ret) = 1;
    6036            2 :           goto return_build_unary_op;
    6037              :         }
    6038              : 
    6039              :       /* Complain about anything that is not a true lvalue.  In
    6040              :          Objective-C, skip this check for property_refs.  */
    6041       951489 :       if (!objc_is_property_ref (arg)
    6042      1902978 :           && !lvalue_or_else (location,
    6043       951489 :                               arg, ((code == PREINCREMENT_EXPR
    6044       951489 :                                      || code == POSTINCREMENT_EXPR)
    6045              :                                     ? lv_increment
    6046              :                                     : lv_decrement)))
    6047           22 :         return error_mark_node;
    6048              : 
    6049       951467 :       if (warn_cxx_compat && TREE_CODE (TREE_TYPE (arg)) == ENUMERAL_TYPE)
    6050              :         {
    6051            4 :           if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
    6052            2 :             warning_at (location, OPT_Wc___compat,
    6053              :                         "increment of enumeration value is invalid in C++");
    6054              :           else
    6055            2 :             warning_at (location, OPT_Wc___compat,
    6056              :                         "decrement of enumeration value is invalid in C++");
    6057              :         }
    6058              : 
    6059       951467 :       if (C_BOOLEAN_TYPE_P (TREE_TYPE (arg)))
    6060              :         {
    6061          664 :           if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
    6062          328 :             warning_at (location, OPT_Wbool_operation,
    6063              :                         "increment of a boolean expression");
    6064              :           else
    6065          336 :             warning_at (location, OPT_Wbool_operation,
    6066              :                         "decrement of a boolean expression");
    6067              :         }
    6068              : 
    6069              :       /* Ensure the argument is fully folded inside any SAVE_EXPR.  */
    6070       951467 :       arg = c_fully_fold (arg, false, NULL, true);
    6071              : 
    6072       951467 :       bool atomic_op;
    6073       951467 :       atomic_op = really_atomic_lvalue (arg);
    6074              : 
    6075              :       /* Increment or decrement the real part of the value,
    6076              :          and don't change the imaginary part.  */
    6077       951467 :       if (typecode == COMPLEX_TYPE)
    6078              :         {
    6079           57 :           tree real, imag;
    6080              : 
    6081           57 :           pedwarn_c23 (location, OPT_Wpedantic,
    6082              :                        "ISO C does not support %<++%> and %<--%> on complex "
    6083              :                        "types before C2Y");
    6084              : 
    6085           57 :           if (!atomic_op)
    6086              :             {
    6087           53 :               arg = stabilize_reference (arg);
    6088           53 :               real = build_unary_op (EXPR_LOCATION (arg), REALPART_EXPR, arg,
    6089              :                                      true);
    6090           53 :               imag = build_unary_op (EXPR_LOCATION (arg), IMAGPART_EXPR, arg,
    6091              :                                      true);
    6092           53 :               real = build_unary_op (EXPR_LOCATION (arg), code, real, true);
    6093           53 :               if (real == error_mark_node || imag == error_mark_node)
    6094              :                 return error_mark_node;
    6095           53 :               ret = build2 (COMPLEX_EXPR, TREE_TYPE (arg),
    6096              :                             real, imag);
    6097           53 :               goto return_build_unary_op;
    6098              :             }
    6099              :         }
    6100              : 
    6101              :       /* Report invalid types.  */
    6102              : 
    6103       951414 :       if (typecode != POINTER_TYPE && typecode != FIXED_POINT_TYPE
    6104       718102 :           && typecode != INTEGER_TYPE && typecode != REAL_TYPE
    6105          208 :           && typecode != COMPLEX_TYPE && typecode != BITINT_TYPE
    6106       951470 :           && !gnu_vector_type_p (TREE_TYPE (arg)))
    6107              :         {
    6108            5 :           if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
    6109            3 :             error_at (location, "wrong type argument to increment");
    6110              :           else
    6111            2 :             error_at (location, "wrong type argument to decrement");
    6112              : 
    6113            5 :           return error_mark_node;
    6114              :         }
    6115              : 
    6116       951409 :       {
    6117       951409 :         tree inc;
    6118              : 
    6119       951409 :         argtype = TREE_TYPE (arg);
    6120              : 
    6121              :         /* Compute the increment.  */
    6122              : 
    6123       951409 :         if (typecode == POINTER_TYPE)
    6124              :           {
    6125              :             /* If pointer target is an incomplete type,
    6126              :                we just cannot know how to do the arithmetic.  */
    6127       233312 :             if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (argtype)))
    6128              :               {
    6129           27 :                 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
    6130           17 :                   error_at (location,
    6131              :                             "increment of pointer to an incomplete type %qT",
    6132           17 :                             TREE_TYPE (argtype));
    6133              :                 else
    6134           10 :                   error_at (location,
    6135              :                             "decrement of pointer to an incomplete type %qT",
    6136           10 :                             TREE_TYPE (argtype));
    6137              :               }
    6138       233285 :             else if (TREE_CODE (TREE_TYPE (argtype)) == FUNCTION_TYPE
    6139       233285 :                      || VOID_TYPE_P (TREE_TYPE (argtype)))
    6140              :               {
    6141           10 :                 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
    6142            6 :                   pedwarn (location, OPT_Wpointer_arith,
    6143              :                            "wrong type argument to increment");
    6144              :                 else
    6145            4 :                   pedwarn (location, OPT_Wpointer_arith,
    6146              :                            "wrong type argument to decrement");
    6147              :               }
    6148              :             else
    6149       466550 :               verify_type_context (location, TCTX_POINTER_ARITH,
    6150       233275 :                                    TREE_TYPE (argtype));
    6151              : 
    6152       233312 :             inc = c_size_in_bytes (TREE_TYPE (argtype));
    6153       233312 :             inc = convert_to_ptrofftype_loc (location, inc);
    6154              :           }
    6155       718097 :         else if (FRACT_MODE_P (TYPE_MODE (argtype)))
    6156              :           {
    6157              :             /* For signed fract types, we invert ++ to -- or
    6158              :                -- to ++, and change inc from 1 to -1, because
    6159              :                it is not possible to represent 1 in signed fract constants.
    6160              :                For unsigned fract types, the result always overflows and
    6161              :                we get an undefined (original) or the maximum value.  */
    6162            0 :             if (code == PREINCREMENT_EXPR)
    6163              :               code = PREDECREMENT_EXPR;
    6164              :             else if (code == PREDECREMENT_EXPR)
    6165              :               code = PREINCREMENT_EXPR;
    6166              :             else if (code == POSTINCREMENT_EXPR)
    6167              :               code = POSTDECREMENT_EXPR;
    6168              :             else /* code == POSTDECREMENT_EXPR  */
    6169            0 :               code = POSTINCREMENT_EXPR;
    6170              : 
    6171            0 :             inc = integer_minus_one_node;
    6172            0 :             inc = convert (argtype, inc);
    6173              :           }
    6174              :         else
    6175              :           {
    6176       718046 :             inc = VECTOR_TYPE_P (argtype)
    6177       718097 :               ? build_one_cst (argtype)
    6178              :               : integer_one_node;
    6179       718097 :             inc = convert (argtype, inc);
    6180              :           }
    6181              : 
    6182              :         /* If 'arg' is an Objective-C PROPERTY_REF expression, then we
    6183              :            need to ask Objective-C to build the increment or decrement
    6184              :            expression for it.  */
    6185       951409 :         if (objc_is_property_ref (arg))
    6186            0 :           return objc_build_incr_expr_for_property_ref (location, code,
    6187           20 :                                                         arg, inc);
    6188              : 
    6189              :         /* Report a read-only lvalue.  */
    6190       951409 :         if (TYPE_READONLY (argtype))
    6191              :           {
    6192           20 :             readonly_error (location, arg,
    6193           20 :                             ((code == PREINCREMENT_EXPR
    6194           20 :                               || code == POSTINCREMENT_EXPR)
    6195              :                              ? lv_increment : lv_decrement));
    6196           20 :             return error_mark_node;
    6197              :           }
    6198       951389 :         else if (TREE_READONLY (arg))
    6199            4 :           readonly_warning (arg,
    6200            4 :                             ((code == PREINCREMENT_EXPR
    6201            4 :                               || code == POSTINCREMENT_EXPR)
    6202              :                              ? lv_increment : lv_decrement));
    6203              : 
    6204              :         /* If the argument is atomic, use the special code sequences for
    6205              :            atomic compound assignment.  */
    6206       951389 :         if (atomic_op)
    6207              :           {
    6208         4469 :             arg = stabilize_reference (arg);
    6209         8938 :             ret = build_atomic_assign (location, arg,
    6210         4469 :                                        ((code == PREINCREMENT_EXPR
    6211         4469 :                                          || code == POSTINCREMENT_EXPR)
    6212              :                                         ? PLUS_EXPR
    6213              :                                         : MINUS_EXPR),
    6214         4469 :                                        (FRACT_MODE_P (TYPE_MODE (argtype))
    6215              :                                         ? inc
    6216              :                                         : integer_one_node),
    6217              :                                        (code == POSTINCREMENT_EXPR
    6218         4469 :                                         || code == POSTDECREMENT_EXPR));
    6219       951389 :             goto return_build_unary_op;
    6220              :           }
    6221              : 
    6222       946920 :         tree true_res;
    6223       946920 :         if (c_hardbool_type_attr (TREE_TYPE (arg), NULL, &true_res))
    6224              :           {
    6225          364 :             tree larg = stabilize_reference (arg);
    6226          364 :             tree sarg = save_expr (larg);
    6227          364 :             switch (code)
    6228              :               {
    6229           91 :               case PREINCREMENT_EXPR:
    6230           91 :                 val = build2 (MODIFY_EXPR, TREE_TYPE (larg), larg, true_res);
    6231           91 :                 val = build2 (COMPOUND_EXPR, TREE_TYPE (larg), sarg, val);
    6232           91 :                 break;
    6233           91 :               case POSTINCREMENT_EXPR:
    6234           91 :                 val = build2 (MODIFY_EXPR, TREE_TYPE (larg), larg, true_res);
    6235           91 :                 val = build2 (COMPOUND_EXPR, TREE_TYPE (larg), val, sarg);
    6236           91 :                 val = build2 (COMPOUND_EXPR, TREE_TYPE (larg), sarg, val);
    6237           91 :                 break;
    6238           91 :               case PREDECREMENT_EXPR:
    6239           91 :                 {
    6240           91 :                   tree rarg = convert_lvalue_to_rvalue (location, sarg,
    6241              :                                                         true, true);
    6242           91 :                   rarg = invert_truthvalue_loc (location, rarg);
    6243           91 :                   rarg = convert (TREE_TYPE (sarg), rarg);
    6244           91 :                   val = build2 (MODIFY_EXPR, TREE_TYPE (larg), larg, rarg);
    6245              :                 }
    6246           91 :                 break;
    6247           91 :               case POSTDECREMENT_EXPR:
    6248           91 :                 {
    6249           91 :                   tree rarg = convert_lvalue_to_rvalue (location, sarg,
    6250              :                                                         true, true);
    6251           91 :                   rarg = invert_truthvalue_loc (location, rarg);
    6252           91 :                   tree iarg = convert (TREE_TYPE (larg), rarg);
    6253           91 :                   val = build2 (MODIFY_EXPR, TREE_TYPE (larg), larg, iarg);
    6254           91 :                   val = build2 (COMPOUND_EXPR, TREE_TYPE (larg), val, sarg);
    6255           91 :                   val = build2 (COMPOUND_EXPR, TREE_TYPE (larg), sarg, val);
    6256              :                 }
    6257           91 :                 break;
    6258              :               default:
    6259              :                 gcc_unreachable ();
    6260              :               }
    6261          364 :             TREE_SIDE_EFFECTS (val) = 1;
    6262              :           }
    6263       946556 :         else if (C_BOOLEAN_TYPE_P (TREE_TYPE (arg)))
    6264           64 :           val = boolean_increment (code, arg);
    6265              :         else
    6266       946492 :           val = build2 (code, TREE_TYPE (arg), arg, inc);
    6267       946920 :         TREE_SIDE_EFFECTS (val) = 1;
    6268       946920 :         if (TYPE_QUALS (TREE_TYPE (val)) != TYPE_UNQUALIFIED)
    6269         3974 :           TREE_TYPE (val) = c_build_qualified_type (TREE_TYPE (val),
    6270              :                                                     TYPE_UNQUALIFIED);
    6271       946920 :         ret = val;
    6272       946920 :         goto return_build_unary_op;
    6273              :       }
    6274              : 
    6275     53984245 :     case ADDR_EXPR:
    6276              :       /* Note that this operation never does default_conversion.  */
    6277              : 
    6278              :       /* The operand of unary '&' must be an lvalue (which excludes
    6279              :          expressions of type void), or, in C99, the result of a [] or
    6280              :          unary '*' operator.  */
    6281     53984245 :       if (VOID_TYPE_P (TREE_TYPE (arg))
    6282           25 :           && TYPE_QUALS (TREE_TYPE (arg)) == TYPE_UNQUALIFIED
    6283     53984264 :           && (!INDIRECT_REF_P (arg) || !flag_isoc99))
    6284           18 :         pedwarn (location, 0, "taking address of expression of type %<void%>");
    6285              : 
    6286              :       /* Let &* cancel out to simplify resulting code.  */
    6287     53984245 :       if (INDIRECT_REF_P (arg))
    6288              :         {
    6289              :           /* Don't let this be an lvalue.  */
    6290        22516 :           if (lvalue_p (TREE_OPERAND (arg, 0)))
    6291        16980 :             return non_lvalue_loc (location, TREE_OPERAND (arg, 0));
    6292         5536 :           ret = TREE_OPERAND (arg, 0);
    6293         5536 :           goto return_build_unary_op;
    6294              :         }
    6295              : 
    6296              :       /* Anything not already handled and not a true memory reference
    6297              :          or a non-lvalue array is an error.  */
    6298     53961729 :       if (typecode != FUNCTION_TYPE && !noconvert
    6299     53961729 :           && !lvalue_or_else (location, arg, lv_addressof))
    6300           17 :         return error_mark_node;
    6301              : 
    6302              :       /* Move address operations inside C_MAYBE_CONST_EXPR to simplify
    6303              :          folding later.  */
    6304     53961712 :       if (TREE_CODE (arg) == C_MAYBE_CONST_EXPR)
    6305              :         {
    6306           14 :           tree inner = build_unary_op (location, code,
    6307           14 :                                        C_MAYBE_CONST_EXPR_EXPR (arg),
    6308              :                                        noconvert);
    6309           28 :           ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner),
    6310           14 :                         C_MAYBE_CONST_EXPR_PRE (arg), inner);
    6311           14 :           gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (arg));
    6312           14 :           C_MAYBE_CONST_EXPR_NON_CONST (ret)
    6313           14 :             = C_MAYBE_CONST_EXPR_NON_CONST (arg);
    6314           14 :           goto return_build_unary_op;
    6315              :         }
    6316              : 
    6317              :       /* Ordinary case; arg is a COMPONENT_REF or a decl.  */
    6318              : 
    6319     53961698 :       argtype = TREE_TYPE (arg);
    6320              : 
    6321              :       /* If the lvalue is const or volatile, merge that into the type
    6322              :          to which the address will point.  This is only needed
    6323              :          for function types.  */
    6324     53961698 :       if ((DECL_P (arg) || REFERENCE_CLASS_P (arg))
    6325     53467996 :           && (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg))
    6326     85198176 :           && TREE_CODE (argtype) == FUNCTION_TYPE)
    6327              :         {
    6328     31155632 :           auto quals = TYPE_QUALS (strip_array_types (argtype));
    6329              : 
    6330     31155632 :           if (TREE_READONLY (arg))
    6331     30770678 :             quals |= TYPE_QUAL_CONST;
    6332     31155632 :           if (TREE_THIS_VOLATILE (arg))
    6333       386733 :             quals |= TYPE_QUAL_VOLATILE;
    6334              : 
    6335     31155632 :           argtype = c_build_qualified_type (argtype, quals);
    6336              :         }
    6337              : 
    6338     53961698 :       switch (TREE_CODE (arg))
    6339              :         {
    6340        66822 :         case COMPONENT_REF:
    6341        66822 :           if (DECL_C_BIT_FIELD (TREE_OPERAND (arg, 1)))
    6342              :             {
    6343            8 :               error_at (location, "cannot take address of bit-field %qD",
    6344            8 :                         TREE_OPERAND (arg, 1));
    6345            8 :               return error_mark_node;
    6346              :             }
    6347              : 
    6348              :           /* fall through */
    6349              : 
    6350       142727 :         case ARRAY_REF:
    6351       142727 :           if (TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (TREE_OPERAND (arg, 0))))
    6352              :             {
    6353           78 :               if (!AGGREGATE_TYPE_P (TREE_TYPE (arg))
    6354            7 :                   && !POINTER_TYPE_P (TREE_TYPE (arg))
    6355           75 :                   && !VECTOR_TYPE_P (TREE_TYPE (arg)))
    6356              :                 {
    6357            6 :                   error_at (location, "cannot take address of scalar with "
    6358              :                             "reverse storage order");
    6359            6 :                   return error_mark_node;
    6360              :                 }
    6361              : 
    6362           63 :               if (TREE_CODE (TREE_TYPE (arg)) == ARRAY_TYPE
    6363           63 :                   && TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (arg)))
    6364           58 :                 warning_at (location, OPT_Wscalar_storage_order,
    6365              :                             "address of array with reverse scalar storage "
    6366              :                             "order requested");
    6367              :             }
    6368              : 
    6369     53961684 :         default:
    6370     53961684 :           break;
    6371              :         }
    6372              : 
    6373     53961684 :       if (!c_mark_addressable (arg))
    6374           20 :         return error_mark_node;
    6375              : 
    6376     53961664 :       gcc_assert (TREE_CODE (arg) != COMPONENT_REF
    6377              :                   || !DECL_C_BIT_FIELD (TREE_OPERAND (arg, 1)));
    6378              : 
    6379     53961664 :       argtype = c_build_pointer_type (argtype);
    6380              : 
    6381              :       /* ??? Cope with user tricks that amount to offsetof.  Delete this
    6382              :          when we have proper support for integer constant expressions.  */
    6383     53961664 :       val = get_base_address (arg);
    6384     53961664 :       if (val && INDIRECT_REF_P (val)
    6385     53986872 :           && TREE_CONSTANT (TREE_OPERAND (val, 0)))
    6386              :         {
    6387          540 :           ret = fold_offsetof (arg, argtype);
    6388          540 :           goto return_build_unary_op;
    6389              :         }
    6390              : 
    6391     53961124 :       val = build1 (ADDR_EXPR, argtype, arg);
    6392              : 
    6393     53961124 :       ret = val;
    6394     53961124 :       goto return_build_unary_op;
    6395              : 
    6396           12 :     case PAREN_EXPR:
    6397           12 :       ret = build1 (code, TREE_TYPE (arg), arg);
    6398           12 :       goto return_build_unary_op;
    6399              : 
    6400            0 :     default:
    6401            0 :       gcc_unreachable ();
    6402              :     }
    6403              : 
    6404      7345420 :   if (argtype == NULL_TREE)
    6405      7345420 :     argtype = TREE_TYPE (arg);
    6406      7345420 :   if (TREE_CODE (arg) == INTEGER_CST)
    6407      6634397 :     ret = (require_constant_value
    6408      6634397 :            ? fold_build1_initializer_loc (location, code, argtype, arg)
    6409      6614766 :            : fold_build1_loc (location, code, argtype, arg));
    6410              :   else
    6411       711023 :     ret = build1 (code, argtype, arg);
    6412     62846618 :  return_build_unary_op:
    6413     62846618 :   gcc_assert (ret != error_mark_node);
    6414      6779102 :   if (TREE_CODE (ret) == INTEGER_CST && !TREE_OVERFLOW (ret)
    6415     69625711 :       && !(TREE_CODE (xarg) == INTEGER_CST && !TREE_OVERFLOW (xarg)))
    6416          562 :     ret = build1 (NOP_EXPR, TREE_TYPE (ret), ret);
    6417     62846056 :   else if (TREE_CODE (ret) != INTEGER_CST && int_operands)
    6418           74 :     ret = note_integer_operands (ret);
    6419     62846618 :   if (eptype)
    6420          244 :     ret = build1 (EXCESS_PRECISION_EXPR, eptype, ret);
    6421     62846618 :   protected_set_expr_location (ret, location);
    6422     62846618 :   return ret;
    6423              : }
    6424              : 
    6425              : /* Return nonzero if REF is an lvalue valid for this language.
    6426              :    Lvalues can be assigned, unless their type has TYPE_READONLY.
    6427              :    Lvalues can have their address taken, unless they have C_DECL_REGISTER.  */
    6428              : 
    6429              : bool
    6430    184252135 : lvalue_p (const_tree ref)
    6431              : {
    6432    185771793 :   const enum tree_code code = TREE_CODE (ref);
    6433              : 
    6434    185771793 :   switch (code)
    6435              :     {
    6436      1494557 :     case REALPART_EXPR:
    6437      1494557 :     case IMAGPART_EXPR:
    6438      1494557 :     case COMPONENT_REF:
    6439      1494557 :       return lvalue_p (TREE_OPERAND (ref, 0));
    6440              : 
    6441        25101 :     case C_MAYBE_CONST_EXPR:
    6442        25101 :       return lvalue_p (TREE_OPERAND (ref, 1));
    6443              : 
    6444              :     case COMPOUND_LITERAL_EXPR:
    6445              :     case STRING_CST:
    6446              :       return true;
    6447              : 
    6448     25949078 :     case MEM_REF:
    6449     25949078 :     case TARGET_MEM_REF:
    6450              :       /* MEM_REFs can appear from -fgimple parsing or folding, so allow them
    6451              :          here as well.  */
    6452     25949078 :     case INDIRECT_REF:
    6453     25949078 :     case ARRAY_REF:
    6454     25949078 :     case VAR_DECL:
    6455     25949078 :     case PARM_DECL:
    6456     25949078 :     case RESULT_DECL:
    6457     25949078 :     case ERROR_MARK:
    6458     25949078 :       return (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE
    6459     25949078 :               && TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE);
    6460              : 
    6461            6 :     case BIND_EXPR:
    6462            6 :       return TREE_CODE (TREE_TYPE (ref)) == ARRAY_TYPE;
    6463              : 
    6464      7265063 :     case CALL_EXPR:
    6465      7265063 :       return is_access_with_size_p (ref);
    6466              : 
    6467              :     default:
    6468              :       return false;
    6469              :     }
    6470              : }
    6471              : 
    6472              : /* Give a warning for storing in something that is read-only in GCC
    6473              :    terms but not const in ISO C terms.  */
    6474              : 
    6475              : static void
    6476            5 : readonly_warning (tree arg, enum lvalue_use use)
    6477              : {
    6478            5 :   switch (use)
    6479              :     {
    6480            1 :     case lv_assign:
    6481            1 :       warning (0, "assignment of read-only location %qE", arg);
    6482            1 :       break;
    6483            2 :     case lv_increment:
    6484            2 :       warning (0, "increment of read-only location %qE", arg);
    6485            2 :       break;
    6486            2 :     case lv_decrement:
    6487            2 :       warning (0, "decrement of read-only location %qE", arg);
    6488            2 :       break;
    6489            0 :     default:
    6490            0 :       gcc_unreachable ();
    6491              :     }
    6492            5 :   return;
    6493              : }
    6494              : 
    6495              : 
    6496              : /* Return nonzero if REF is an lvalue valid for this language;
    6497              :    otherwise, print an error message and return zero.  USE says
    6498              :    how the lvalue is being used and so selects the error message.
    6499              :    LOCATION is the location at which any error should be reported.  */
    6500              : 
    6501              : static int
    6502      4847892 : lvalue_or_else (location_t loc, const_tree ref, enum lvalue_use use)
    6503              : {
    6504      4847892 :   int win = lvalue_p (ref);
    6505              : 
    6506      4847892 :   if (!win)
    6507           75 :     lvalue_error (loc, use);
    6508              : 
    6509      4847892 :   return win;
    6510              : }
    6511              : 
    6512              : /* Mark EXP saying that we need to be able to take the
    6513              :    address of it; it should not be allocated in a register.
    6514              :    Returns true if successful.  ARRAY_REF_P is true if this
    6515              :    is for ARRAY_REF construction - in that case we don't want
    6516              :    to look through VIEW_CONVERT_EXPR from VECTOR_TYPE to ARRAY_TYPE,
    6517              :    it is fine to use ARRAY_REFs for vector subscripts on vector
    6518              :    register variables.  If OVERRIDE_REGISTER, clear DECL_REGISTER rather
    6519              :    than producing an error for taking the address of a register.  */
    6520              : 
    6521              : bool
    6522     54518756 : c_mark_addressable (tree exp, bool array_ref_p, bool override_register)
    6523              : {
    6524     54518756 :   tree x = exp;
    6525              : 
    6526     55103467 :   while (1)
    6527     55103467 :     switch (TREE_CODE (x))
    6528              :       {
    6529        11527 :       case VIEW_CONVERT_EXPR:
    6530        11527 :         if (array_ref_p
    6531        11417 :             && TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
    6532        22944 :             && VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (x, 0))))
    6533              :           return true;
    6534          110 :         x = TREE_OPERAND (x, 0);
    6535          110 :         break;
    6536              : 
    6537       398529 :       case COMPONENT_REF:
    6538       398529 :         if (DECL_C_BIT_FIELD (TREE_OPERAND (x, 1)))
    6539              :           {
    6540            6 :             error ("cannot take address of bit-field %qD",
    6541            3 :                    TREE_OPERAND (x, 1));
    6542            3 :             return false;
    6543              :           }
    6544              :         /* FALLTHRU */
    6545       584601 :       case ADDR_EXPR:
    6546       584601 :       case ARRAY_REF:
    6547       584601 :       case REALPART_EXPR:
    6548       584601 :       case IMAGPART_EXPR:
    6549       584601 :         x = TREE_OPERAND (x, 0);
    6550       584601 :         break;
    6551              : 
    6552          594 :       case COMPOUND_LITERAL_EXPR:
    6553          594 :         if (C_DECL_REGISTER (COMPOUND_LITERAL_EXPR_DECL (x)))
    6554              :           {
    6555           16 :             if (override_register)
    6556           12 :               DECL_REGISTER (COMPOUND_LITERAL_EXPR_DECL (x)) = 0;
    6557              :             else
    6558              :               {
    6559            4 :                 error ("address of register compound literal requested");
    6560            4 :                 return false;
    6561              :               }
    6562              :           }
    6563          590 :         TREE_ADDRESSABLE (x) = 1;
    6564          590 :         TREE_ADDRESSABLE (COMPOUND_LITERAL_EXPR_DECL (x)) = 1;
    6565          590 :         return true;
    6566              : 
    6567            0 :       case CONSTRUCTOR:
    6568            0 :         TREE_ADDRESSABLE (x) = 1;
    6569            0 :         return true;
    6570              : 
    6571      1343776 :       case VAR_DECL:
    6572      1343776 :       case CONST_DECL:
    6573      1343776 :       case PARM_DECL:
    6574      1343776 :       case RESULT_DECL:
    6575      1343776 :         if (C_DECL_REGISTER (x)
    6576      1343776 :             && DECL_NONLOCAL (x))
    6577              :           {
    6578            0 :             if (TREE_PUBLIC (x) || is_global_var (x))
    6579              :               {
    6580            0 :                 error
    6581            0 :                   ("global register variable %qD used in nested function", x);
    6582            0 :                 return false;
    6583              :               }
    6584            0 :             pedwarn (input_location, 0, "register variable %qD used in nested function", x);
    6585              :           }
    6586      1343776 :         else if (C_DECL_REGISTER (x))
    6587              :           {
    6588           73 :             if (TREE_PUBLIC (x) || is_global_var (x))
    6589            4 :               error ("address of global register variable %qD requested", x);
    6590          123 :             else if (override_register && !DECL_HARD_REGISTER (x))
    6591              :               {
    6592           54 :                 DECL_REGISTER (x) = 0;
    6593           54 :                 TREE_ADDRESSABLE (x) = 1;
    6594           54 :                 mark_decl_used (x, true);
    6595           54 :                 return true;
    6596              :               }
    6597              :             else
    6598           15 :               error ("address of register variable %qD requested", x);
    6599              :             return false;
    6600              :           }
    6601              : 
    6602              :         /* FALLTHRU */
    6603     53936563 :       case FUNCTION_DECL:
    6604     53936563 :         TREE_ADDRESSABLE (x) = 1;
    6605     53936563 :         mark_decl_used (x, true);
    6606              :         /* FALLTHRU */
    6607              :       default:
    6608              :         return true;
    6609              :     }
    6610              : }
    6611              : 
    6612              : /* Convert EXPR to TYPE, warning about conversion problems with
    6613              :    constants.  SEMANTIC_TYPE is the type this conversion would use
    6614              :    without excess precision. If SEMANTIC_TYPE is NULL, this function
    6615              :    is equivalent to convert_and_check. This function is a wrapper that
    6616              :    handles conversions that may be different than
    6617              :    the usual ones because of excess precision.  */
    6618              : 
    6619              : static tree
    6620     25101410 : ep_convert_and_check (location_t loc, tree type, tree expr,
    6621              :                       tree semantic_type)
    6622              : {
    6623     25101410 :   if (TREE_TYPE (expr) == type)
    6624              :     return expr;
    6625              : 
    6626              :   /* For C11, integer conversions may have results with excess
    6627              :      precision.  */
    6628      2140332 :   if (flag_isoc11 || !semantic_type)
    6629      2140328 :     return convert_and_check (loc, type, expr);
    6630              : 
    6631            4 :   if (TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
    6632            4 :       && TREE_TYPE (expr) != semantic_type)
    6633              :     {
    6634              :       /* For integers, we need to check the real conversion, not
    6635              :          the conversion to the excess precision type.  */
    6636            4 :       expr = convert_and_check (loc, semantic_type, expr);
    6637              :     }
    6638              :   /* Result type is the excess precision type, which should be
    6639              :      large enough, so do not check.  */
    6640            4 :   return convert (type, expr);
    6641              : }
    6642              : 
    6643              : /* If EXPR refers to a built-in declared without a prototype returns
    6644              :    the actual type of the built-in and, if non-null, set *BLTIN to
    6645              :    a pointer to the built-in.  Otherwise return the type of EXPR
    6646              :    and clear *BLTIN if non-null.  */
    6647              : 
    6648              : static tree
    6649      2856938 : type_or_builtin_type (tree expr, tree *bltin = NULL)
    6650              : {
    6651      2856938 :   tree dummy;
    6652      2856938 :   if (!bltin)
    6653            0 :     bltin = &dummy;
    6654              : 
    6655      2856938 :   *bltin = NULL_TREE;
    6656              : 
    6657      2856938 :   tree type = TREE_TYPE (expr);
    6658      2856938 :   if (TREE_CODE (expr) != ADDR_EXPR)
    6659              :     return type;
    6660              : 
    6661       211065 :   tree oper = TREE_OPERAND (expr, 0);
    6662       211065 :   if (!DECL_P (oper)
    6663       171427 :       || TREE_CODE (oper) != FUNCTION_DECL
    6664       247500 :       || !fndecl_built_in_p (oper, BUILT_IN_NORMAL))
    6665              :     return type;
    6666              : 
    6667         2085 :   built_in_function code = DECL_FUNCTION_CODE (oper);
    6668         2085 :   if (!C_DECL_BUILTIN_PROTOTYPE (oper))
    6669              :     return type;
    6670              : 
    6671         1977 :   if ((*bltin = builtin_decl_implicit (code)))
    6672          991 :     type = c_build_pointer_type (TREE_TYPE (*bltin));
    6673              : 
    6674              :   return type;
    6675              : }
    6676              : 
    6677              : /* Build and return a conditional expression IFEXP ? OP1 : OP2.  If
    6678              :    IFEXP_BCP then the condition is a call to __builtin_constant_p, and
    6679              :    if folded to an integer constant then the unselected half may
    6680              :    contain arbitrary operations not normally permitted in constant
    6681              :    expressions.  Set the location of the expression to LOC.  */
    6682              : 
    6683              : tree
    6684       408927 : build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp,
    6685              :                         tree op1, tree op1_original_type, location_t op1_loc,
    6686              :                         tree op2, tree op2_original_type, location_t op2_loc)
    6687              : {
    6688       408927 :   tree type1;
    6689       408927 :   tree type2;
    6690       408927 :   tree result_type = NULL;
    6691       408927 :   tree semantic_result_type = NULL;
    6692       408927 :   tree orig_op1 = op1, orig_op2 = op2;
    6693       408927 :   bool int_const, op1_int_operands, op2_int_operands, int_operands;
    6694       408927 :   bool ifexp_int_operands;
    6695       408927 :   tree ret;
    6696              : 
    6697       408927 :   op1_int_operands = EXPR_INT_CONST_OPERANDS (orig_op1);
    6698              :   if (op1_int_operands)
    6699       113656 :     op1 = remove_c_maybe_const_expr (op1);
    6700       408927 :   op2_int_operands = EXPR_INT_CONST_OPERANDS (orig_op2);
    6701              :   if (op2_int_operands)
    6702       148884 :     op2 = remove_c_maybe_const_expr (op2);
    6703       408927 :   ifexp_int_operands = EXPR_INT_CONST_OPERANDS (ifexp);
    6704              :   if (ifexp_int_operands)
    6705       244807 :     ifexp = remove_c_maybe_const_expr (ifexp);
    6706              : 
    6707              :   /* Promote both alternatives.  */
    6708              : 
    6709       408927 :   if (TREE_CODE (TREE_TYPE (op1)) != VOID_TYPE)
    6710       405002 :     op1 = default_conversion (op1);
    6711       408927 :   if (TREE_CODE (TREE_TYPE (op2)) != VOID_TYPE)
    6712       379079 :     op2 = default_conversion (op2);
    6713              : 
    6714       408927 :   if (TREE_CODE (ifexp) == ERROR_MARK
    6715       408858 :       || TREE_CODE (TREE_TYPE (op1)) == ERROR_MARK
    6716       817771 :       || TREE_CODE (TREE_TYPE (op2)) == ERROR_MARK)
    6717           83 :     return error_mark_node;
    6718              : 
    6719       408844 :   tree bltin1 = NULL_TREE;
    6720       408844 :   tree bltin2 = NULL_TREE;
    6721       408844 :   type1 = type_or_builtin_type (op1, &bltin1);
    6722       408844 :   const enum tree_code code1 = TREE_CODE (type1);
    6723       408844 :   type2 = type_or_builtin_type (op2, &bltin2);
    6724       408844 :   const enum tree_code code2 = TREE_CODE (type2);
    6725              : 
    6726       408844 :   if (code1 == POINTER_TYPE && reject_gcc_builtin (op1))
    6727            1 :     return error_mark_node;
    6728              : 
    6729       408843 :   if (code2 == POINTER_TYPE && reject_gcc_builtin (op2))
    6730            1 :     return error_mark_node;
    6731              : 
    6732              :   /* C90 does not permit non-lvalue arrays in conditional expressions.
    6733              :      In C99 they will be pointers by now.  */
    6734       408842 :   if (code1 == ARRAY_TYPE || code2 == ARRAY_TYPE)
    6735              :     {
    6736            1 :       error_at (colon_loc, "non-lvalue array in conditional expression");
    6737            1 :       return error_mark_node;
    6738              :     }
    6739              : 
    6740       408841 :   if ((TREE_CODE (op1) == EXCESS_PRECISION_EXPR
    6741       408834 :        || TREE_CODE (op2) == EXCESS_PRECISION_EXPR)
    6742            8 :       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
    6743            0 :           || code1 == COMPLEX_TYPE || code1 == BITINT_TYPE)
    6744            8 :       && (code2 == INTEGER_TYPE || code2 == REAL_TYPE
    6745            0 :           || code2 == COMPLEX_TYPE || code2 == BITINT_TYPE))
    6746              :     {
    6747            8 :       semantic_result_type = c_common_type (type1, type2);
    6748            8 :       if (TREE_CODE (op1) == EXCESS_PRECISION_EXPR)
    6749              :         {
    6750            7 :           op1 = TREE_OPERAND (op1, 0);
    6751            7 :           type1 = TREE_TYPE (op1);
    6752            7 :           gcc_assert (TREE_CODE (type1) == code1);
    6753              :         }
    6754            8 :       if (TREE_CODE (op2) == EXCESS_PRECISION_EXPR)
    6755              :         {
    6756            1 :           op2 = TREE_OPERAND (op2, 0);
    6757            1 :           type2 = TREE_TYPE (op2);
    6758            1 :           gcc_assert (TREE_CODE (type2) == code2);
    6759              :         }
    6760              :     }
    6761              : 
    6762       408841 :   if (warn_cxx_compat)
    6763              :     {
    6764          420 :       tree t1 = op1_original_type ? op1_original_type : TREE_TYPE (orig_op1);
    6765          420 :       tree t2 = op2_original_type ? op2_original_type : TREE_TYPE (orig_op2);
    6766              : 
    6767          420 :       if (TREE_CODE (t1) == ENUMERAL_TYPE
    6768            6 :           && TREE_CODE (t2) == ENUMERAL_TYPE
    6769          426 :           && TYPE_MAIN_VARIANT (t1) != TYPE_MAIN_VARIANT (t2))
    6770            2 :         warning_at (colon_loc, OPT_Wc___compat,
    6771              :                     "different enum types in conditional is "
    6772              :                     "invalid in C++: %qT vs %qT", t1, t2);
    6773              :     }
    6774              : 
    6775       408841 :   if (warn_zero_as_null_pointer_constant
    6776           20 :       && c_inhibit_evaluation_warnings == 0)
    6777              :     {
    6778           20 :       if ((code1 == POINTER_TYPE || code1 == NULLPTR_TYPE)
    6779           20 :           && INTEGRAL_TYPE_P (type2) && null_pointer_constant_p (orig_op2))
    6780            5 :         warning_at (op2_loc, OPT_Wzero_as_null_pointer_constant,
    6781              :                     "zero as null pointer constant");
    6782              : 
    6783           20 :       if ((code2 == POINTER_TYPE || code2 == NULLPTR_TYPE)
    6784           20 :           && INTEGRAL_TYPE_P (type1) && null_pointer_constant_p (orig_op1))
    6785            5 :         warning_at (op1_loc, OPT_Wzero_as_null_pointer_constant,
    6786              :                     "zero as null pointer constant");
    6787              :     }
    6788              : 
    6789              :   /* Quickly detect the usual case where op1 and op2 have the same type
    6790              :      after promotion.  */
    6791       408841 :   if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2))
    6792              :     {
    6793       273537 :       if (type1 == type2)
    6794              :         result_type = type1;
    6795              :       else
    6796         6431 :         result_type = TYPE_MAIN_VARIANT (type1);
    6797              :     }
    6798       135304 :   else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE
    6799        80444 :             || code1 == COMPLEX_TYPE || code1 == BITINT_TYPE)
    6800        54928 :            && (code2 == INTEGER_TYPE || code2 == REAL_TYPE
    6801        26161 :                || code2 == COMPLEX_TYPE || code2 == BITINT_TYPE))
    6802              :     {
    6803              :       /* In C11, a conditional expression between a floating-point
    6804              :          type and an integer type should convert the integer type to
    6805              :          the evaluation format of the floating-point type, with
    6806              :          possible excess precision.  */
    6807        28876 :       tree eptype1 = type1;
    6808        28876 :       tree eptype2 = type2;
    6809        28876 :       if (flag_isoc11)
    6810              :         {
    6811        28563 :           tree eptype;
    6812        11685 :           if (ANY_INTEGRAL_TYPE_P (type1)
    6813        28563 :               && (eptype = excess_precision_type (type2)) != NULL_TREE)
    6814              :             {
    6815            2 :               eptype2 = eptype;
    6816            2 :               if (!semantic_result_type)
    6817            2 :                 semantic_result_type = c_common_type (type1, type2);
    6818              :             }
    6819          502 :           else if (ANY_INTEGRAL_TYPE_P (type2)
    6820        28561 :                    && (eptype = excess_precision_type (type1)) != NULL_TREE)
    6821              :             {
    6822         4646 :               eptype1 = eptype;
    6823         4646 :               if (!semantic_result_type)
    6824         4646 :                 semantic_result_type = c_common_type (type1, type2);
    6825              :             }
    6826              :         }
    6827        28876 :       result_type = c_common_type (eptype1, eptype2);
    6828        28876 :       if (result_type == error_mark_node)
    6829              :         return error_mark_node;
    6830        28874 :       do_warn_double_promotion (result_type, type1, type2,
    6831              :                                 "implicit conversion from %qT to %qT to "
    6832              :                                 "match other result of conditional",
    6833              :                                 colon_loc);
    6834              : 
    6835              :       /* If -Wsign-compare, warn here if type1 and type2 have
    6836              :          different signedness.  We'll promote the signed to unsigned
    6837              :          and later code won't know it used to be different.
    6838              :          Do this check on the original types, so that explicit casts
    6839              :          will be considered, but default promotions won't.  */
    6840        28874 :       if (c_inhibit_evaluation_warnings == 0)
    6841              :         {
    6842        28683 :           int unsigned_op1 = TYPE_UNSIGNED (TREE_TYPE (orig_op1));
    6843        28683 :           int unsigned_op2 = TYPE_UNSIGNED (TREE_TYPE (orig_op2));
    6844              : 
    6845        28683 :           if (unsigned_op1 ^ unsigned_op2)
    6846              :             {
    6847              :               /* Do not warn if the result type is signed, since the
    6848              :                  signed type will only be chosen if it can represent
    6849              :                  all the values of the unsigned type.  */
    6850        13130 :               if (!TYPE_UNSIGNED (result_type))
    6851              :                 /* OK */;
    6852              :               else
    6853              :                 {
    6854        13025 :                   bool op1_maybe_const = true;
    6855        13025 :                   bool op2_maybe_const = true;
    6856              : 
    6857              :                   /* Do not warn if the signed quantity is an
    6858              :                      unsuffixed integer literal (or some static
    6859              :                      constant expression involving such literals) and
    6860              :                      it is non-negative.  This warning requires the
    6861              :                      operands to be folded for best results, so do
    6862              :                      that folding in this case even without
    6863              :                      warn_sign_compare to avoid warning options
    6864              :                      possibly affecting code generation.  */
    6865        13025 :                   c_inhibit_evaluation_warnings
    6866        13025 :                     += (ifexp == truthvalue_false_node);
    6867        13025 :                   op1 = c_fully_fold (op1, require_constant_value,
    6868              :                                       &op1_maybe_const);
    6869        13025 :                   c_inhibit_evaluation_warnings
    6870        13025 :                     -= (ifexp == truthvalue_false_node);
    6871              : 
    6872        13025 :                   c_inhibit_evaluation_warnings
    6873        13025 :                     += (ifexp == truthvalue_true_node);
    6874        13025 :                   op2 = c_fully_fold (op2, require_constant_value,
    6875              :                                       &op2_maybe_const);
    6876        13025 :                   c_inhibit_evaluation_warnings
    6877        13025 :                     -= (ifexp == truthvalue_true_node);
    6878              : 
    6879        13025 :                   if (warn_sign_compare)
    6880              :                     {
    6881         1245 :                       if ((unsigned_op2
    6882          685 :                            && tree_expr_nonnegative_p (op1))
    6883         1248 :                           || (unsigned_op1
    6884          560 :                               && tree_expr_nonnegative_p (op2)))
    6885              :                         /* OK */;
    6886           10 :                       else if (unsigned_op2)
    6887            3 :                         warning_at (op1_loc, OPT_Wsign_compare,
    6888              :                                     "operand of %<?:%> changes signedness from "
    6889              :                                     "%qT to %qT due to unsignedness of other "
    6890            3 :                                     "operand", TREE_TYPE (orig_op1),
    6891            3 :                                     TREE_TYPE (orig_op2));
    6892              :                       else
    6893            7 :                         warning_at (op2_loc, OPT_Wsign_compare,
    6894              :                                     "operand of %<?:%> changes signedness from "
    6895              :                                     "%qT to %qT due to unsignedness of other "
    6896            7 :                                     "operand", TREE_TYPE (orig_op2),
    6897            7 :                                     TREE_TYPE (orig_op1));
    6898              :                     }
    6899        13025 :                   if (!op1_maybe_const || TREE_CODE (op1) != INTEGER_CST)
    6900         7663 :                     op1 = c_wrap_maybe_const (op1, !op1_maybe_const);
    6901        13025 :                   if (!op2_maybe_const || TREE_CODE (op2) != INTEGER_CST)
    6902         4402 :                     op2 = c_wrap_maybe_const (op2, !op2_maybe_const);
    6903              :                 }
    6904              :             }
    6905              :         }
    6906              :     }
    6907       106428 :   else if (code1 == VOID_TYPE || code2 == VOID_TYPE)
    6908              :     {
    6909        25995 :       if (code1 != VOID_TYPE || code2 != VOID_TYPE)
    6910        25995 :         pedwarn (colon_loc, OPT_Wpedantic,
    6911              :                  "ISO C forbids conditional expr with only one void side");
    6912        25995 :       result_type = void_type_node;
    6913              :     }
    6914        80433 :   else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE)
    6915              :     {
    6916        80015 :       addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (type1));
    6917        80015 :       addr_space_t as2 = TYPE_ADDR_SPACE (TREE_TYPE (type2));
    6918        80015 :       addr_space_t as_common;
    6919              : 
    6920        80015 :       if (comp_target_types (colon_loc, type1, type2))
    6921              :         {
    6922         2626 :           ifexp = save_expr (ifexp);
    6923         2626 :           result_type = common_pointer_type (type1, type2, ifexp);
    6924              :         }
    6925        77389 :       else if (null_pointer_constant_p (orig_op1))
    6926              :         result_type = type2;
    6927        73227 :       else if (null_pointer_constant_p (orig_op2))
    6928              :         result_type = type1;
    6929        35283 :       else if (!addr_space_superset (as1, as2, &as_common))
    6930              :         {
    6931            0 :           error_at (colon_loc, "pointers to disjoint address spaces "
    6932              :                     "used in conditional expression");
    6933            0 :           return error_mark_node;
    6934              :         }
    6935        35283 :       else if ((VOID_TYPE_P (TREE_TYPE (type1))
    6936          326 :                 && !TYPE_ATOMIC (TREE_TYPE (type1)))
    6937        35285 :                || (VOID_TYPE_P (TREE_TYPE (type2))
    6938        34912 :                    && !TYPE_ATOMIC (TREE_TYPE (type2))))
    6939              :         {
    6940        35235 :           tree t1 = TREE_TYPE (type1);
    6941        35235 :           tree t2 = TREE_TYPE (type2);
    6942        35235 :           if (!(VOID_TYPE_P (t1)
    6943          325 :                 && !TYPE_ATOMIC (t1)))
    6944              :            {
    6945              :              /* roles are swapped */
    6946        34911 :              t1 = t2;
    6947        34911 :              t2 = TREE_TYPE (type1);
    6948              :            }
    6949        35235 :           tree t2_stripped = strip_array_types (t2);
    6950        35235 :           if ((TREE_CODE (t2) == ARRAY_TYPE)
    6951        35235 :               && !TYPE_QUALS (t1).superset_of (TYPE_QUALS (t2_stripped)))
    6952              :             {
    6953           18 :               if (!flag_isoc23)
    6954            6 :                 warning_at (colon_loc, OPT_Wdiscarded_array_qualifiers,
    6955              :                             "pointer to array loses qualifier "
    6956              :                             "in conditional expression");
    6957           12 :               else if (warn_c11_c23_compat > 0)
    6958            6 :                 warning_at (colon_loc, OPT_Wc11_c23_compat,
    6959              :                             "pointer to array loses qualifier "
    6960              :                             "in conditional expression in ISO C before C23");
    6961              :             }
    6962        35235 :           if (TREE_CODE (t2) == FUNCTION_TYPE)
    6963            4 :             pedwarn (colon_loc, OPT_Wpedantic,
    6964              :                      "ISO C forbids conditional expr between "
    6965              :                      "%<void *%> and function pointer");
    6966              :           /* for array, use qualifiers of element type */
    6967        35235 :           if (flag_isoc23)
    6968        11454 :             t2 = t2_stripped;
    6969        35235 :           result_type = c_build_pointer_type (qualify_type (t1, t2));
    6970              :         }
    6971              :       /* Objective-C pointer comparisons are a bit more lenient.  */
    6972           48 :       else if (objc_have_common_type (type1, type2, -3, NULL_TREE))
    6973            0 :         result_type = objc_common_type (type1, type2);
    6974              :       else
    6975              :         {
    6976           48 :           qualifier_set qual {TYPE_UNQUALIFIED, as_common};
    6977           48 :           enum diagnostics::kind kind = diagnostics::kind::permerror;
    6978           48 :           if (!flag_isoc99)
    6979              :             /* This downgrade to a warning ensures that -std=gnu89
    6980              :                -pedantic-errors does not flag these mismatches between
    6981              :                builtins as errors (as diagnostics::kind::permerror would)
    6982              :                ISO C99 and later do not have implicit function declarations,
    6983              :                so the mismatch cannot occur naturally there.  */
    6984            5 :             kind = (bltin1 && bltin2
    6985            5 :                     ? diagnostics::kind::warning
    6986              :                     : diagnostics::kind::pedwarn);
    6987           48 :           if (emit_diagnostic (kind, colon_loc, OPT_Wincompatible_pointer_types,
    6988              :                                "pointer type mismatch "
    6989              :                                "in conditional expression"))
    6990              :             {
    6991           46 :               inform (op1_loc, "first expression has type %qT", type1);
    6992           46 :               inform (op2_loc, "second expression has type %qT", type2);
    6993              :             }
    6994           48 :           result_type = c_build_pointer_type
    6995           48 :                           (c_build_qualified_type (void_type_node, qual));
    6996              :         }
    6997              :     }
    6998          418 :   else if (code1 == POINTER_TYPE
    6999          298 :            && (code2 == INTEGER_TYPE || code2 == BITINT_TYPE))
    7000              :     {
    7001          294 :       if (!null_pointer_constant_p (orig_op2))
    7002           14 :         permerror_opt (colon_loc, OPT_Wint_conversion,
    7003              :                        "pointer/integer type mismatch "
    7004              :                        "in conditional expression");
    7005              :       else
    7006              :         {
    7007          280 :           op2 = null_pointer_node;
    7008              :         }
    7009              :       result_type = type1;
    7010              :     }
    7011          124 :   else if (code2 == POINTER_TYPE
    7012           90 :            && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
    7013              :     {
    7014           86 :       if (!null_pointer_constant_p (orig_op1))
    7015           14 :         permerror_opt (colon_loc, OPT_Wint_conversion,
    7016              :                        "pointer/integer type mismatch "
    7017              :                        "in conditional expression");
    7018              :       else
    7019              :         {
    7020           72 :           op1 = null_pointer_node;
    7021              :         }
    7022              :       result_type = type2;
    7023              :     }
    7024              :   /* 6.5.15: "if one is a null pointer constant (other than a pointer) or has
    7025              :      type nullptr_t and the other is a pointer, the result type is the pointer
    7026              :      type."  */
    7027           38 :   else if (code1 == NULLPTR_TYPE && code2 == POINTER_TYPE)
    7028              :     result_type = type2;
    7029           34 :   else if (code1 == POINTER_TYPE && code2 == NULLPTR_TYPE)
    7030              :     result_type = type1;
    7031            8 :   else if (RECORD_OR_UNION_TYPE_P (type1) && RECORD_OR_UNION_TYPE_P (type2)
    7032           38 :            && comptypes (TYPE_MAIN_VARIANT (type1),
    7033            8 :                          TYPE_MAIN_VARIANT (type2)))
    7034            8 :     result_type = composite_type (TYPE_MAIN_VARIANT (type1),
    7035            8 :                                   TYPE_MAIN_VARIANT (type2));
    7036              : 
    7037       408817 :   if (!result_type)
    7038              :     {
    7039           22 :       if (flag_cond_mismatch)
    7040            0 :         result_type = void_type_node;
    7041              :       else
    7042              :         {
    7043           22 :           error_at (colon_loc, "type mismatch in conditional expression");
    7044           22 :           return error_mark_node;
    7045              :         }
    7046              :     }
    7047              : 
    7048              :   /* Merge const and volatile flags of the incoming types.  */
    7049       408817 :   result_type
    7050       408817 :     = build_type_variant (result_type,
    7051              :                           TYPE_READONLY (type1) || TYPE_READONLY (type2),
    7052              :                           TYPE_VOLATILE (type1) || TYPE_VOLATILE (type2));
    7053              : 
    7054       408817 :   op1 = ep_convert_and_check (colon_loc, result_type, op1,
    7055              :                               semantic_result_type);
    7056       408817 :   op2 = ep_convert_and_check (colon_loc, result_type, op2,
    7057              :                               semantic_result_type);
    7058              : 
    7059       408817 :   if (ifexp_bcp && ifexp == truthvalue_true_node)
    7060              :     {
    7061           10 :       op2_int_operands = true;
    7062           10 :       op1 = c_fully_fold (op1, require_constant_value, NULL);
    7063              :     }
    7064           59 :   if (ifexp_bcp && ifexp == truthvalue_false_node)
    7065              :     {
    7066           49 :       op1_int_operands = true;
    7067           49 :       op2 = c_fully_fold (op2, require_constant_value, NULL);
    7068              :     }
    7069       916809 :   int_const = int_operands = (ifexp_int_operands
    7070       408817 :                               && op1_int_operands
    7071       408817 :                               && op2_int_operands);
    7072        99175 :   if (int_operands)
    7073              :     {
    7074        99175 :       int_const = ((ifexp == truthvalue_true_node
    7075        58820 :                     && TREE_CODE (orig_op1) == INTEGER_CST
    7076        58806 :                     && !TREE_OVERFLOW (orig_op1))
    7077        99189 :                    || (ifexp == truthvalue_false_node
    7078        40309 :                        && TREE_CODE (orig_op2) == INTEGER_CST
    7079        40293 :                        && !TREE_OVERFLOW (orig_op2)));
    7080              :     }
    7081              : 
    7082              :   /* Need to convert condition operand into a vector mask.  */
    7083       408817 :   if (VECTOR_TYPE_P (TREE_TYPE (ifexp)))
    7084              :     {
    7085            0 :       tree vectype = TREE_TYPE (ifexp);
    7086            0 :       tree elem_type = TREE_TYPE (vectype);
    7087            0 :       tree zero = build_int_cst (elem_type, 0);
    7088            0 :       tree zero_vec = build_vector_from_val (vectype, zero);
    7089            0 :       tree cmp_type = truth_type_for (vectype);
    7090            0 :       ifexp = build2 (NE_EXPR, cmp_type, ifexp, zero_vec);
    7091              :     }
    7092              : 
    7093       408817 :   if (int_const || (ifexp_bcp && TREE_CODE (ifexp) == INTEGER_CST))
    7094        99131 :     ret = fold_build3_loc (colon_loc, COND_EXPR, result_type, ifexp, op1, op2);
    7095              :   else
    7096              :     {
    7097       309686 :       if (int_operands)
    7098              :         {
    7099              :           /* Use c_fully_fold here, since C_MAYBE_CONST_EXPR might be
    7100              :              nested inside of the expression.  */
    7101           76 :           op1 = c_fully_fold (op1, false, NULL);
    7102           76 :           op2 = c_fully_fold (op2, false, NULL);
    7103              :         }
    7104       309686 :       ret = build3 (COND_EXPR, result_type, ifexp, op1, op2);
    7105       309686 :       if (int_operands)
    7106           76 :         ret = note_integer_operands (ret);
    7107              :     }
    7108       408817 :   if (semantic_result_type)
    7109         4656 :     ret = build1 (EXCESS_PRECISION_EXPR, semantic_result_type, ret);
    7110              : 
    7111       408817 :   protected_set_expr_location (ret, colon_loc);
    7112              : 
    7113              :   /* If the OP1 and OP2 are the same and don't have side-effects,
    7114              :      warn here, because the COND_EXPR will be turned into OP1.  */
    7115       408817 :   if (warn_duplicated_branches
    7116           34 :       && TREE_CODE (ret) == COND_EXPR
    7117       408851 :       && (op1 == op2 || operand_equal_p (op1, op2, OEP_ADDRESS_OF_SAME_FIELD)))
    7118           13 :     warning_at (EXPR_LOCATION (ret), OPT_Wduplicated_branches,
    7119              :                 "this condition has identical branches");
    7120              : 
    7121              :   return ret;
    7122              : }
    7123              : 
    7124              : /* EXPR is an expression, location LOC, whose result is discarded.
    7125              :    Warn if it is a call to a nodiscard function (or a COMPOUND_EXPR
    7126              :    whose right-hand operand is such a call, possibly recursively).  */
    7127              : 
    7128              : static void
    7129      6725247 : maybe_warn_nodiscard (location_t loc, tree expr)
    7130              : {
    7131      6725247 :   if (VOID_TYPE_P (TREE_TYPE (expr)))
    7132              :     return;
    7133      4083932 :   while (TREE_CODE (expr) == COMPOUND_EXPR)
    7134              :     {
    7135        52198 :       expr = TREE_OPERAND (expr, 1);
    7136        52198 :       if (EXPR_HAS_LOCATION (expr))
    7137        52198 :         loc = EXPR_LOCATION (expr);
    7138              :     }
    7139      4031734 :   if (TREE_CODE (expr) != CALL_EXPR)
    7140              :     return;
    7141       348763 :   tree fn = CALL_EXPR_FN (expr);
    7142       348763 :   if (!fn)
    7143              :     return;
    7144       348747 :   tree attr;
    7145       348747 :   if (TREE_CODE (fn) == ADDR_EXPR
    7146       348080 :       && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
    7147       696827 :       && (attr = lookup_attribute ("nodiscard",
    7148       348080 :                                    DECL_ATTRIBUTES (TREE_OPERAND (fn, 0)))))
    7149              :     {
    7150            3 :       fn = TREE_OPERAND (fn, 0);
    7151            3 :       tree args = TREE_VALUE (attr);
    7152            3 :       if (args)
    7153            1 :         args = TREE_VALUE (args);
    7154            3 :       auto_diagnostic_group d;
    7155            3 :       auto_urlify_attributes sentinel;
    7156            3 :       int warned;
    7157            3 :       if (args)
    7158            1 :         warned = warning_at (loc, OPT_Wunused_result,
    7159              :                              "ignoring return value of %qD, declared with "
    7160              :                              "attribute %<nodiscard%>: %E", fn, args);
    7161              :       else
    7162            2 :         warned = warning_at (loc, OPT_Wunused_result,
    7163              :                              "ignoring return value of %qD, declared with "
    7164              :                              "attribute %<nodiscard%>", fn);
    7165            3 :       if (warned)
    7166            3 :         inform (DECL_SOURCE_LOCATION (fn), "declared here");
    7167            3 :     }
    7168              :   else
    7169              :     {
    7170       348744 :       tree rettype = TREE_TYPE (TREE_TYPE (TREE_TYPE (fn)));
    7171       348744 :       attr = lookup_attribute ("nodiscard", TYPE_ATTRIBUTES (rettype));
    7172       348744 :       if (!attr)
    7173       348732 :         return;
    7174           12 :       tree args = TREE_VALUE (attr);
    7175           12 :       if (args)
    7176            5 :         args = TREE_VALUE (args);
    7177           12 :       auto_diagnostic_group d;
    7178           12 :       auto_urlify_attributes sentinel;
    7179           12 :       int warned;
    7180           12 :       if (args)
    7181            5 :         warned = warning_at (loc, OPT_Wunused_result,
    7182              :                              "ignoring return value of type %qT, declared "
    7183              :                              "with attribute %<nodiscard%>: %E",
    7184              :                              rettype, args);
    7185              :       else
    7186            7 :         warned = warning_at (loc, OPT_Wunused_result,
    7187              :                              "ignoring return value of type %qT, declared "
    7188              :                              "with attribute %<nodiscard%>", rettype);
    7189           12 :       if (warned)
    7190              :         {
    7191           12 :           if (TREE_CODE (fn) == ADDR_EXPR)
    7192              :             {
    7193           11 :               fn = TREE_OPERAND (fn, 0);
    7194           11 :               if (TREE_CODE (fn) == FUNCTION_DECL)
    7195           11 :                 inform (DECL_SOURCE_LOCATION (fn),
    7196              :                         "in call to %qD, declared here", fn);
    7197              :             }
    7198              :         }
    7199           12 :     }
    7200              : }
    7201              : 
    7202              : /* Return a compound expression that performs two expressions and
    7203              :    returns the value of the second of them.
    7204              : 
    7205              :    LOC is the location of the COMPOUND_EXPR.  */
    7206              : 
    7207              : tree
    7208       114460 : build_compound_expr (location_t loc, tree expr1, tree expr2)
    7209              : {
    7210       114460 :   bool expr1_int_operands, expr2_int_operands;
    7211       114460 :   tree eptype = NULL_TREE;
    7212       114460 :   tree ret;
    7213              : 
    7214       114460 :   expr1_int_operands = EXPR_INT_CONST_OPERANDS (expr1);
    7215              :   if (expr1_int_operands)
    7216          326 :     expr1 = remove_c_maybe_const_expr (expr1);
    7217       114460 :   expr2_int_operands = EXPR_INT_CONST_OPERANDS (expr2);
    7218              :   if (expr2_int_operands)
    7219        66140 :     expr2 = remove_c_maybe_const_expr (expr2);
    7220              : 
    7221       114460 :   if (TREE_CODE (expr1) == EXCESS_PRECISION_EXPR)
    7222            0 :     expr1 = TREE_OPERAND (expr1, 0);
    7223       114460 :   if (TREE_CODE (expr2) == EXCESS_PRECISION_EXPR)
    7224              :     {
    7225            1 :       eptype = TREE_TYPE (expr2);
    7226            1 :       expr2 = TREE_OPERAND (expr2, 0);
    7227              :     }
    7228              : 
    7229       114460 :   if (!TREE_SIDE_EFFECTS (expr1))
    7230              :     {
    7231              :       /* The left-hand operand of a comma expression is like an expression
    7232              :          statement: with -Wunused, we should warn if it doesn't have
    7233              :          any side-effects, unless it was explicitly cast to (void).  */
    7234         8464 :       if (warn_unused_value)
    7235              :         {
    7236         1284 :           if (VOID_TYPE_P (TREE_TYPE (expr1))
    7237         1284 :               && CONVERT_EXPR_P (expr1))
    7238              :             ; /* (void) a, b */
    7239           14 :           else if (VOID_TYPE_P (TREE_TYPE (expr1))
    7240            4 :                    && TREE_CODE (expr1) == COMPOUND_EXPR
    7241           17 :                    && CONVERT_EXPR_P (TREE_OPERAND (expr1, 1)))
    7242              :             ; /* (void) a, (void) b, c */
    7243              :           else
    7244           11 :             warning_at (loc, OPT_Wunused_value,
    7245              :                         "left-hand operand of comma expression has no effect");
    7246              :         }
    7247              :     }
    7248       105996 :   else if (TREE_CODE (expr1) == COMPOUND_EXPR
    7249        13113 :            && warn_unused_value)
    7250              :     {
    7251              :       tree r = expr1;
    7252              :       location_t cloc = loc;
    7253         4833 :       while (TREE_CODE (r) == COMPOUND_EXPR)
    7254              :         {
    7255         2417 :           if (EXPR_HAS_LOCATION (r))
    7256         2417 :             cloc = EXPR_LOCATION (r);
    7257         2417 :           r = TREE_OPERAND (r, 1);
    7258              :         }
    7259         2416 :       if (!TREE_SIDE_EFFECTS (r)
    7260            4 :           && !VOID_TYPE_P (TREE_TYPE (r))
    7261         2420 :           && !CONVERT_EXPR_P (r))
    7262            4 :         warning_at (cloc, OPT_Wunused_value,
    7263              :                     "right-hand operand of comma expression has no effect");
    7264              :     }
    7265              : 
    7266              :   /* With -Wunused, we should also warn if the left-hand operand does have
    7267              :      side-effects, but computes a value which is not used.  For example, in
    7268              :      `foo() + bar(), baz()' the result of the `+' operator is not used,
    7269              :      so we should issue a warning.  */
    7270       103580 :   else if (warn_unused_value)
    7271        35475 :     warn_if_unused_value (expr1, loc);
    7272              : 
    7273       114460 :   maybe_warn_nodiscard (loc, expr1);
    7274              : 
    7275       114460 :   if (expr2 == error_mark_node)
    7276              :     return error_mark_node;
    7277              : 
    7278       114447 :   ret = build2 (COMPOUND_EXPR, TREE_TYPE (expr2), expr1, expr2);
    7279              : 
    7280       114447 :   if (flag_isoc99
    7281              :       && expr1_int_operands
    7282       113987 :       && expr2_int_operands)
    7283          153 :     ret = note_integer_operands (ret);
    7284              : 
    7285       114447 :   if (eptype)
    7286            1 :     ret = build1 (EXCESS_PRECISION_EXPR, eptype, ret);
    7287              : 
    7288       114447 :   protected_set_expr_location (ret, loc);
    7289       114447 :   return ret;
    7290              : }
    7291              : 
    7292              : /* Issue -Wcast-qual warnings when appropriate.  TYPE is the type to
    7293              :    which we are casting.  OTYPE is the type of the expression being
    7294              :    cast.  Both TYPE and OTYPE are pointer types.  LOC is the location
    7295              :    of the cast.  -Wcast-qual appeared on the command line.  Named
    7296              :    address space qualifiers are not handled here, because they result
    7297              :    in different warnings.  */
    7298              : 
    7299              : static void
    7300        14107 : handle_warn_cast_qual (location_t loc, tree type, tree otype)
    7301              : {
    7302        14107 :   tree in_type = type;
    7303        14107 :   tree in_otype = otype;
    7304        14107 :   int added = 0;
    7305        14107 :   int discarded = 0;
    7306        14277 :   bool is_const;
    7307              : 
    7308              :   /* Check that the qualifiers on IN_TYPE are a superset of the
    7309              :      qualifiers of IN_OTYPE.  The outermost level of POINTER_TYPE
    7310              :      nodes is uninteresting and we stop as soon as we hit a
    7311              :      non-POINTER_TYPE node on either type.  */
    7312        14277 :   do
    7313              :     {
    7314        14277 :       in_otype = TREE_TYPE (in_otype);
    7315        14277 :       in_type = TREE_TYPE (in_type);
    7316              : 
    7317              :       /* GNU C allows cv-qualified function types.  'const' means the
    7318              :          function is very pure, 'volatile' means it can't return.  We
    7319              :          need to warn when such qualifiers are added, not when they're
    7320              :          taken away.  */
    7321        14277 :       if (TREE_CODE (in_otype) == FUNCTION_TYPE
    7322           26 :           && TREE_CODE (in_type) == FUNCTION_TYPE)
    7323           18 :         added |= (TYPE_QUALS_NO_ADDR_SPACE (in_type)
    7324           18 :                   & ~TYPE_QUALS_NO_ADDR_SPACE (in_otype));
    7325              :       else
    7326        14259 :         discarded |= (TYPE_QUALS_NO_ADDR_SPACE (in_otype)
    7327        14259 :                       & ~TYPE_QUALS_NO_ADDR_SPACE (in_type));
    7328              :     }
    7329        14277 :   while (TREE_CODE (in_type) == POINTER_TYPE
    7330        14277 :          && TREE_CODE (in_otype) == POINTER_TYPE);
    7331              : 
    7332        14107 :   if (added)
    7333            2 :     warning_at (loc, OPT_Wcast_qual,
    7334              :                 "cast adds %q#v qualifier to function type", added);
    7335              : 
    7336        14107 :   if (discarded)
    7337              :     /* There are qualifiers present in IN_OTYPE that are not present
    7338              :        in IN_TYPE.  */
    7339         1203 :     warning_at (loc, OPT_Wcast_qual,
    7340              :                 "cast discards %qv qualifier from pointer target type",
    7341              :                 discarded);
    7342              : 
    7343        14107 :   if (added || discarded)
    7344              :     return;
    7345              : 
    7346              :   /* A cast from **T to const **T is unsafe, because it can cause a
    7347              :      const value to be changed with no additional warning.  We only
    7348              :      issue this warning if T is the same on both sides, and we only
    7349              :      issue the warning if there are the same number of pointers on
    7350              :      both sides, as otherwise the cast is clearly unsafe anyhow.  A
    7351              :      cast is unsafe when a qualifier is added at one level and const
    7352              :      is not present at all outer levels.
    7353              : 
    7354              :      To issue this warning, we check at each level whether the cast
    7355              :      adds new qualifiers not already seen.  We don't need to special
    7356              :      case function types, as they won't have the same
    7357              :      TYPE_MAIN_VARIANT.  */
    7358              : 
    7359        12902 :   if (TYPE_MAIN_VARIANT (in_type) != TYPE_MAIN_VARIANT (in_otype))
    7360              :     return;
    7361          227 :   if (TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE)
    7362              :     return;
    7363              : 
    7364           48 :   in_type = type;
    7365           48 :   in_otype = otype;
    7366           48 :   is_const = TYPE_READONLY (TREE_TYPE (in_type));
    7367          130 :   do
    7368              :     {
    7369          130 :       in_type = TREE_TYPE (in_type);
    7370          130 :       in_otype = TREE_TYPE (in_otype);
    7371          130 :       if (!TYPE_QUALS (in_otype).superset_of (TYPE_QUALS (in_type))
    7372          130 :           && !is_const)
    7373              :         {
    7374           27 :           warning_at (loc, OPT_Wcast_qual,
    7375              :                       "to be safe all intermediate pointers in cast from "
    7376              :                       "%qT to %qT must be %<const%> qualified",
    7377              :                       otype, type);
    7378           27 :           break;
    7379              :         }
    7380          103 :       if (is_const)
    7381           72 :         is_const = TYPE_READONLY (in_type);
    7382              :     }
    7383          103 :   while (TREE_CODE (in_type) == POINTER_TYPE);
    7384              : }
    7385              : 
    7386              : /* Heuristic check if two parameter types can be considered ABI-equivalent.  */
    7387              : 
    7388              : static bool
    7389         1316 : c_safe_arg_type_equiv_p (tree t1, tree t2)
    7390              : {
    7391         1316 :   if (error_operand_p (t1) || error_operand_p (t2))
    7392              :     return true;
    7393              : 
    7394         1315 :   t1 = TYPE_MAIN_VARIANT (t1);
    7395         1315 :   t2 = TYPE_MAIN_VARIANT (t2);
    7396              : 
    7397         1315 :   if (TREE_CODE (t1) == POINTER_TYPE
    7398          229 :       && TREE_CODE (t2) == POINTER_TYPE)
    7399              :     return true;
    7400              : 
    7401              :   /* Only the precision of the parameter matters.  This check should
    7402              :      make sure that the callee does not see undefined values in argument
    7403              :      registers.  */
    7404         1107 :   if (INTEGRAL_TYPE_P (t1)
    7405          917 :       && INTEGRAL_TYPE_P (t2)
    7406         1452 :       && TYPE_PRECISION (t1) == TYPE_PRECISION (t2))
    7407              :     return true;
    7408              : 
    7409          942 :   return comptypes (t1, t2);
    7410              : }
    7411              : 
    7412              : /* Check if a type cast between two function types can be considered safe.  */
    7413              : 
    7414              : static bool
    7415         7563 : c_safe_function_type_cast_p (tree t1, tree t2)
    7416              : {
    7417         7563 :   if (TREE_TYPE (t1) == void_type_node &&
    7418         5561 :       TYPE_ARG_TYPES (t1) == void_list_node)
    7419              :     return true;
    7420              : 
    7421         3726 :   if (TREE_TYPE (t2) == void_type_node &&
    7422         2889 :       TYPE_ARG_TYPES (t2) == void_list_node)
    7423              :     return true;
    7424              : 
    7425          896 :   if (!c_safe_arg_type_equiv_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    7426              :     return false;
    7427              : 
    7428          197 :   for (t1 = TYPE_ARG_TYPES (t1), t2 = TYPE_ARG_TYPES (t2);
    7429          513 :        t1 && t2;
    7430          316 :        t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
    7431          420 :     if (!c_safe_arg_type_equiv_p (TREE_VALUE (t1), TREE_VALUE (t2)))
    7432              :       return false;
    7433              : 
    7434              :   return true;
    7435              : }
    7436              : 
    7437              : /* Build an expression representing a cast to type TYPE of expression EXPR.
    7438              :    LOC is the location of the cast-- typically the open paren of the cast.  */
    7439              : 
    7440              : tree
    7441    125090682 : build_c_cast (location_t loc, tree type, tree expr)
    7442              : {
    7443    125090682 :   tree value;
    7444              : 
    7445    125090682 :   bool int_operands = EXPR_INT_CONST_OPERANDS (expr);
    7446              : 
    7447    125090682 :   if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
    7448           66 :     expr = TREE_OPERAND (expr, 0);
    7449              : 
    7450    125090682 :   value = expr;
    7451    125090682 :   if (int_operands)
    7452      7241515 :     value = remove_c_maybe_const_expr (value);
    7453              : 
    7454    125090682 :   if (type == error_mark_node || expr == error_mark_node)
    7455              :     return error_mark_node;
    7456              : 
    7457              :   /* The ObjC front-end uses TYPE_MAIN_VARIANT to tie together types differing
    7458              :      only in <protocol> qualifications.  But when constructing cast expressions,
    7459              :      the protocols do matter and must be kept around.  */
    7460    125089662 :   if (objc_is_object_ptr (type) && objc_is_object_ptr (TREE_TYPE (expr)))
    7461            0 :     return build1 (NOP_EXPR, type, expr);
    7462              : 
    7463    125089662 :   type = TYPE_MAIN_VARIANT (type);
    7464              : 
    7465    125089662 :   if (TREE_CODE (type) == ARRAY_TYPE)
    7466              :     {
    7467           13 :       error_at (loc, "cast specifies array type");
    7468           13 :       return error_mark_node;
    7469              :     }
    7470              : 
    7471    125089649 :   if (TREE_CODE (type) == FUNCTION_TYPE)
    7472              :     {
    7473            6 :       error_at (loc, "cast specifies function type");
    7474            6 :       return error_mark_node;
    7475              :     }
    7476              : 
    7477    125089643 :   if (!VOID_TYPE_P (type))
    7478              :     {
    7479    125044965 :       value = require_complete_type (loc, value);
    7480    125044965 :       if (value == error_mark_node)
    7481              :         return error_mark_node;
    7482              :     }
    7483              : 
    7484    125089642 :   if (type == TYPE_MAIN_VARIANT (TREE_TYPE (value)))
    7485              :     {
    7486     18958343 :       if (RECORD_OR_UNION_TYPE_P (type)
    7487     18958343 :           && pedwarn (loc, OPT_Wpedantic,
    7488              :                       "ISO C forbids casting nonscalar to the same type"))
    7489              :               ;
    7490     18958339 :       else if (warn_useless_cast && c_inhibit_evaluation_warnings == 0)
    7491            8 :         warning_at (loc, OPT_Wuseless_cast,
    7492              :                     "useless cast to type %qT", type);
    7493              : 
    7494              :       /* Convert to remove any qualifiers from VALUE's type.  */
    7495     18958343 :       value = convert (type, value);
    7496              :     }
    7497    106131299 :   else if (TREE_CODE (type) == UNION_TYPE)
    7498              :     {
    7499          137 :       tree field;
    7500              : 
    7501          192 :       for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    7502          185 :         if (TREE_TYPE (field) != error_mark_node
    7503          369 :             && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field)),
    7504          184 :                           TYPE_MAIN_VARIANT (TREE_TYPE (value))))
    7505              :           break;
    7506              : 
    7507          137 :       if (field)
    7508              :         {
    7509          130 :           tree t;
    7510          130 :           bool maybe_const = true;
    7511              : 
    7512          130 :           pedwarn (loc, OPT_Wpedantic, "ISO C forbids casts to union type");
    7513          130 :           t = c_fully_fold (value, false, &maybe_const);
    7514          130 :           t = build_constructor_single (type, field, t);
    7515          130 :           if (!maybe_const)
    7516           15 :             t = c_wrap_maybe_const (t, true);
    7517          130 :           t = digest_init (loc, field, type, t,
    7518              :                            NULL_TREE, false, false, false, true, false, false);
    7519          130 :           TREE_CONSTANT (t) = TREE_CONSTANT (value);
    7520          130 :           return t;
    7521              :         }
    7522            7 :       error_at (loc, "cast to union type from type not present in union");
    7523            7 :       return error_mark_node;
    7524              :     }
    7525              :   else
    7526              :     {
    7527    106131162 :       tree otype, ovalue;
    7528              : 
    7529    106131162 :       if (type == void_type_node)
    7530              :         {
    7531        18708 :           tree t = build1 (CONVERT_EXPR, type, value);
    7532        18708 :           SET_EXPR_LOCATION (t, loc);
    7533        18708 :           return t;
    7534              :         }
    7535              : 
    7536    106112454 :       otype = TREE_TYPE (value);
    7537              : 
    7538              :       /* Optionally warn about potentially worrisome casts.  */
    7539    106112454 :       if (warn_cast_qual
    7540       204404 :           && TREE_CODE (type) == POINTER_TYPE
    7541        27455 :           && TREE_CODE (otype) == POINTER_TYPE)
    7542        14107 :         handle_warn_cast_qual (loc, type, otype);
    7543              : 
    7544              :       /* Warn about conversions between pointers to disjoint
    7545              :          address spaces.  */
    7546    106112454 :       if (TREE_CODE (type) == POINTER_TYPE
    7547      3377051 :           && TREE_CODE (otype) == POINTER_TYPE
    7548    109141318 :           && !null_pointer_constant_p (value))
    7549              :         {
    7550      2974470 :           addr_space_t as_to = TYPE_ADDR_SPACE (TREE_TYPE (type));
    7551      2974470 :           addr_space_t as_from = TYPE_ADDR_SPACE (TREE_TYPE (otype));
    7552      2974470 :           addr_space_t as_common;
    7553              : 
    7554      2974470 :           if (!addr_space_superset (as_to, as_from, &as_common))
    7555              :             {
    7556            0 :               if (ADDR_SPACE_GENERIC_P (as_from))
    7557            0 :                 warning_at (loc, 0, "cast to %qs address space pointer "
    7558              :                             "from disjoint generic address space pointer",
    7559              :                             c_addr_space_name (as_to));
    7560              : 
    7561            0 :               else if (ADDR_SPACE_GENERIC_P (as_to))
    7562            0 :                 warning_at (loc, 0, "cast to generic address space pointer "
    7563              :                             "from disjoint %qs address space pointer",
    7564              :                             c_addr_space_name (as_from));
    7565              : 
    7566              :               else
    7567            0 :                 warning_at (loc, 0, "cast to %qs address space pointer "
    7568              :                             "from disjoint %qs address space pointer",
    7569              :                             c_addr_space_name (as_to),
    7570              :                             c_addr_space_name (as_from));
    7571              :             }
    7572              : 
    7573              :           /* Warn of new allocations that are not big enough for the target
    7574              :              type.  */
    7575      2974470 :           if (warn_alloc_size && TREE_CODE (value) == CALL_EXPR)
    7576         1069 :             if (tree fndecl = get_callee_fndecl (value))
    7577         1065 :               if (DECL_IS_MALLOC (fndecl))
    7578              :                 {
    7579          573 :                   tree attrs = TYPE_ATTRIBUTES (TREE_TYPE (fndecl));
    7580          573 :                   tree alloc_size = lookup_attribute ("alloc_size", attrs);
    7581          573 :                   if (alloc_size)
    7582          215 :                     warn_for_alloc_size (loc, TREE_TYPE (type), value,
    7583              :                                          alloc_size);
    7584              :                 }
    7585              :         }
    7586              : 
    7587              :       /* Warn about possible alignment problems.  */
    7588    106112454 :       if ((STRICT_ALIGNMENT || warn_cast_align == 2)
    7589            7 :           && TREE_CODE (type) == POINTER_TYPE
    7590            7 :           && TREE_CODE (otype) == POINTER_TYPE
    7591            7 :           && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE
    7592            7 :           && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
    7593              :           /* Don't warn about opaque types, where the actual alignment
    7594              :              restriction is unknown.  */
    7595           12 :           && !(RECORD_OR_UNION_TYPE_P (TREE_TYPE (otype))
    7596            5 :                && TYPE_MODE (TREE_TYPE (otype)) == VOIDmode)
    7597    106112468 :           && min_align_of_type (TREE_TYPE (type))
    7598            7 :              > min_align_of_type (TREE_TYPE (otype)))
    7599            5 :         warning_at (loc, OPT_Wcast_align,
    7600              :                     "cast increases required alignment of target type");
    7601              : 
    7602    106112454 :       if ((TREE_CODE (type) == INTEGER_TYPE
    7603    106112454 :            || TREE_CODE (type) == BITINT_TYPE)
    7604      7404862 :           && TREE_CODE (otype) == POINTER_TYPE
    7605    106138006 :           && TYPE_PRECISION (type) != TYPE_PRECISION (otype))
    7606              :       /* Unlike conversion of integers to pointers, where the
    7607              :          warning is disabled for converting constants because
    7608              :          of cases such as SIG_*, warn about converting constant
    7609              :          pointers to integers. In some cases it may cause unwanted
    7610              :          sign extension, and a warning is appropriate.  */
    7611         1464 :         warning_at (loc, OPT_Wpointer_to_int_cast,
    7612              :                     "cast from pointer to integer of different size");
    7613              : 
    7614    106112454 :       if ((TREE_CODE (value) == CALL_EXPR
    7615     36336507 :            && !is_access_with_size_p (value))
    7616    142448957 :           && TREE_CODE (type) != TREE_CODE (otype))
    7617         2304 :         warning_at (loc, OPT_Wbad_function_cast,
    7618              :                     "cast from function call of type %qT "
    7619              :                     "to non-matching type %qT", otype, type);
    7620              : 
    7621    106112454 :       if (TREE_CODE (type) == POINTER_TYPE
    7622      3377051 :           && (TREE_CODE (otype) == INTEGER_TYPE
    7623      3377051 :               || TREE_CODE (otype) == BITINT_TYPE)
    7624       348098 :           && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
    7625              :           /* Don't warn about converting any constant.  */
    7626    106422372 :           && !TREE_CONSTANT (value))
    7627          407 :         warning_at (loc,
    7628          407 :                     OPT_Wint_to_pointer_cast, "cast to pointer from integer "
    7629              :                     "of different size");
    7630              : 
    7631    106112454 :       if (warn_strict_aliasing <= 2)
    7632     97334492 :         strict_aliasing_warning (EXPR_LOCATION (value), type, expr);
    7633              : 
    7634              :       /* If pedantic, warn for conversions between function and object
    7635              :          pointer types, except for converting a null pointer constant
    7636              :          to function pointer type.  */
    7637    106112454 :       if (pedantic
    7638       261509 :           && TREE_CODE (type) == POINTER_TYPE
    7639       144380 :           && TREE_CODE (otype) == POINTER_TYPE
    7640         3035 :           && TREE_CODE (TREE_TYPE (otype)) == FUNCTION_TYPE
    7641    106112475 :           && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE)
    7642           18 :         pedwarn (loc, OPT_Wpedantic, "ISO C forbids "
    7643              :                  "conversion of function pointer to object pointer type");
    7644              : 
    7645    106112454 :       if (pedantic
    7646       261509 :           && TREE_CODE (type) == POINTER_TYPE
    7647       144380 :           && TREE_CODE (otype) == POINTER_TYPE
    7648         3035 :           && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
    7649           13 :           && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
    7650    106112464 :           && !null_pointer_constant_p (value))
    7651            4 :         pedwarn (loc, OPT_Wpedantic, "ISO C forbids "
    7652              :                  "conversion of object pointer to function pointer type");
    7653              : 
    7654    106112454 :       if (TREE_CODE (type) == POINTER_TYPE
    7655      3377051 :           && TREE_CODE (otype) == POINTER_TYPE
    7656      3028864 :           && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
    7657         8684 :           && TREE_CODE (TREE_TYPE (otype)) == FUNCTION_TYPE
    7658    106120017 :           && !c_safe_function_type_cast_p (TREE_TYPE (type),
    7659         7563 :                                            TREE_TYPE (otype)))
    7660          803 :         warning_at (loc, OPT_Wcast_function_type,
    7661              :                     "cast between incompatible function types"
    7662              :                     " from %qT to %qT", otype, type);
    7663              : 
    7664    106112454 :       ovalue = value;
    7665              :       /* If converting to boolean a value with integer operands that
    7666              :          is not itself represented as an INTEGER_CST, the call below
    7667              :          to note_integer_operands may insert a C_MAYBE_CONST_EXPR, but
    7668              :          build_binary_op as called by c_common_truthvalue_conversion
    7669              :          may also insert a C_MAYBE_CONST_EXPR to indicate that a
    7670              :          subexpression has been fully folded.  To avoid nested
    7671              :          C_MAYBE_CONST_EXPR, ensure that
    7672              :          c_objc_common_truthvalue_conversion receives an argument
    7673              :          properly marked as having integer operands in that case.  */
    7674    106112454 :       if (int_operands
    7675      6992676 :           && TREE_CODE (value) != INTEGER_CST
    7676    106112496 :           && (TREE_CODE (type) == BOOLEAN_TYPE
    7677           28 :               || (TREE_CODE (type) == ENUMERAL_TYPE
    7678           14 :                   && ENUM_UNDERLYING_TYPE (type) != NULL_TREE
    7679           14 :                   && TREE_CODE (ENUM_UNDERLYING_TYPE (type)) == BOOLEAN_TYPE)))
    7680           28 :         value = note_integer_operands (value);
    7681    106112454 :       value = convert (type, value);
    7682              : 
    7683              :       /* Ignore any integer overflow caused by the cast.  */
    7684    106112454 :       if (TREE_CODE (value) == INTEGER_CST && !FLOAT_TYPE_P (otype))
    7685              :         {
    7686      6939421 :           if (TREE_OVERFLOW_P (ovalue))
    7687              :             {
    7688            9 :               if (!TREE_OVERFLOW (value))
    7689              :                 {
    7690              :                   /* Avoid clobbering a shared constant.  */
    7691            0 :                   value = copy_node (value);
    7692            0 :                   TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue);
    7693              :                 }
    7694              :             }
    7695      6939412 :           else if (TREE_OVERFLOW (value))
    7696              :             /* Reset VALUE's overflow flags, ensuring constant sharing.  */
    7697         3107 :             value = wide_int_to_tree (TREE_TYPE (value), wi::to_wide (value));
    7698              :         }
    7699              :     }
    7700              : 
    7701              :   /* Don't let a cast be an lvalue.  */
    7702    125070797 :   if (lvalue_p (value)
    7703              :       /* Also, don't let a cast be a bit-field of a bit-precise integer type,
    7704              :          otherwise it could be incorrectly subject of integer promotions.  */
    7705    125070797 :       || (TREE_CODE (value) == COMPONENT_REF
    7706           24 :           && DECL_C_BIT_FIELD (TREE_OPERAND (value, 1))
    7707           24 :           && BITINT_TYPE_P (DECL_BIT_FIELD_TYPE (TREE_OPERAND (value, 1)))))
    7708        91648 :     value = non_lvalue_loc (loc, value);
    7709              : 
    7710              :   /* Don't allow the results of casting to floating-point or complex
    7711              :      types be confused with actual constants, or casts involving
    7712              :      integer and pointer types other than direct integer-to-integer
    7713              :      and integer-to-pointer be confused with integer constant
    7714              :      expressions and null pointer constants.  */
    7715    125070797 :   if (TREE_CODE (value) == REAL_CST
    7716    125020845 :       || TREE_CODE (value) == COMPLEX_CST
    7717    250069016 :       || (TREE_CODE (value) == INTEGER_CST
    7718      7247470 :           && !((TREE_CODE (expr) == INTEGER_CST
    7719      7173336 :                 && INTEGRAL_TYPE_P (TREE_TYPE (expr)))
    7720        66731 :                || TREE_CODE (expr) == REAL_CST
    7721              :                || TREE_CODE (expr) == COMPLEX_CST)))
    7722       134942 :       value = build1 (NOP_EXPR, type, value);
    7723              : 
    7724              :   /* If the expression has integer operands and so can occur in an
    7725              :      unevaluated part of an integer constant expression, ensure the
    7726              :      return value reflects this.  */
    7727    125070797 :   if (int_operands
    7728      7227530 :       && INTEGRAL_TYPE_P (type)
    7729      6779432 :       && value != error_mark_node
    7730    131850228 :       && !EXPR_INT_CONST_OPERANDS (value))
    7731           11 :     value = note_integer_operands (value);
    7732              : 
    7733    125070797 :   protected_set_expr_location (value, loc);
    7734    125070797 :   return value;
    7735              : }
    7736              : 
    7737              : /* Interpret a cast of expression EXPR to type TYPE.  LOC is the
    7738              :    location of the open paren of the cast, or the position of the cast
    7739              :    expr.  */
    7740              : tree
    7741    125090177 : c_cast_expr (location_t loc, struct c_type_name *type_name, tree expr)
    7742              : {
    7743    125090177 :   tree type;
    7744    125090177 :   tree type_expr = NULL_TREE;
    7745    125090177 :   bool type_expr_const = true;
    7746    125090177 :   tree ret;
    7747    125090177 :   int saved_wsp = warn_strict_prototypes;
    7748              : 
    7749              :   /* This avoids warnings about unprototyped casts on
    7750              :      integers.  E.g. "#define SIG_DFL (void(*)())0".  */
    7751    125090177 :   if (TREE_CODE (expr) == INTEGER_CST)
    7752      7296014 :     warn_strict_prototypes = 0;
    7753    125090177 :   type = groktypename (type_name, &type_expr, &type_expr_const);
    7754    125090177 :   warn_strict_prototypes = saved_wsp;
    7755              : 
    7756       765682 :   if (TREE_CODE (expr) == ADDR_EXPR && !VOID_TYPE_P (type)
    7757    125855604 :       && reject_gcc_builtin (expr))
    7758            2 :     return error_mark_node;
    7759              : 
    7760    125090175 :   ret = build_c_cast (loc, type, expr);
    7761    125090175 :   if (ret == error_mark_node)
    7762              :     return error_mark_node;
    7763              : 
    7764    125089015 :   if (type_expr)
    7765              :     {
    7766          250 :       bool inner_expr_const = true;
    7767          250 :       ret = c_fully_fold (ret, require_constant_value, &inner_expr_const);
    7768          250 :       ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret), type_expr, ret);
    7769          500 :       C_MAYBE_CONST_EXPR_NON_CONST (ret) = !(type_expr_const
    7770          145 :                                              && inner_expr_const);
    7771          250 :       SET_EXPR_LOCATION (ret, loc);
    7772              :     }
    7773              : 
    7774    125089015 :   if (!EXPR_HAS_LOCATION (ret))
    7775      7173771 :     protected_set_expr_location (ret, loc);
    7776              : 
    7777              :   /* C++ does not permits types to be defined in a cast, but it
    7778              :      allows references to incomplete types.  */
    7779    125089015 :   if (warn_cxx_compat && type_name->specs->typespec_kind == ctsk_tagdef)
    7780            1 :     warning_at (loc, OPT_Wc___compat,
    7781              :                 "defining a type in a cast is invalid in C++");
    7782              : 
    7783              :   return ret;
    7784              : }
    7785              : 
    7786              : /* Build an assignment expression of lvalue LHS from value RHS.
    7787              :    If LHS_ORIGTYPE is not NULL, it is the original type of LHS, which
    7788              :    may differ from TREE_TYPE (LHS) for an enum bitfield.
    7789              :    MODIFYCODE is the code for a binary operator that we use
    7790              :    to combine the old value of LHS with RHS to get the new value.
    7791              :    Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
    7792              :    If RHS_ORIGTYPE is not NULL_TREE, it is the original type of RHS,
    7793              :    which may differ from TREE_TYPE (RHS) for an enum value.
    7794              : 
    7795              :    LOCATION is the location of the MODIFYCODE operator.
    7796              :    RHS_LOC is the location of the RHS.  */
    7797              : 
    7798              : tree
    7799      3004680 : build_modify_expr (location_t location, tree lhs, tree lhs_origtype,
    7800              :                    enum tree_code modifycode,
    7801              :                    location_t rhs_loc, tree rhs, tree rhs_origtype)
    7802              : {
    7803      3004680 :   tree result;
    7804      3004680 :   tree newrhs;
    7805      3004680 :   tree rhseval = NULL_TREE;
    7806      3004680 :   tree lhstype = TREE_TYPE (lhs);
    7807      3004680 :   tree olhstype = lhstype;
    7808      3004680 :   bool npc;
    7809      3004680 :   bool is_atomic_op;
    7810              : 
    7811              :   /* Types that aren't fully specified cannot be used in assignments.  */
    7812      3004680 :   lhs = require_complete_type (location, lhs);
    7813      3004680 :   rhs = require_complete_type (location, rhs);
    7814              : 
    7815              :   /* Avoid duplicate error messages from operands that had errors.  */
    7816      3004680 :   if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK)
    7817          473 :     return error_mark_node;
    7818              : 
    7819              :   /* Ensure an error for assigning a non-lvalue array to an array in
    7820              :      C90.  */
    7821      3004207 :   if (TREE_CODE (lhstype) == ARRAY_TYPE)
    7822              :     {
    7823            1 :       error_at (location, "assignment to expression with array type");
    7824            1 :       return error_mark_node;
    7825              :     }
    7826              : 
    7827              :   /* For ObjC properties, defer this check.  */
    7828      3004206 :   if (!objc_is_property_ref (lhs) && !lvalue_or_else (location, lhs, lv_assign))
    7829           32 :     return error_mark_node;
    7830              : 
    7831      3004174 :   is_atomic_op = really_atomic_lvalue (lhs);
    7832              : 
    7833      3004174 :   newrhs = rhs;
    7834              : 
    7835      3004174 :   if (TREE_CODE (lhs) == C_MAYBE_CONST_EXPR)
    7836              :     {
    7837            2 :       tree inner = build_modify_expr (location, C_MAYBE_CONST_EXPR_EXPR (lhs),
    7838              :                                       lhs_origtype, modifycode, rhs_loc, rhs,
    7839              :                                       rhs_origtype);
    7840            2 :       if (inner == error_mark_node)
    7841              :         return error_mark_node;
    7842            4 :       result = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner),
    7843            2 :                        C_MAYBE_CONST_EXPR_PRE (lhs), inner);
    7844            2 :       gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (lhs));
    7845            2 :       C_MAYBE_CONST_EXPR_NON_CONST (result) = 1;
    7846            2 :       protected_set_expr_location (result, location);
    7847            2 :       return result;
    7848              :     }
    7849              : 
    7850              :   /* If a binary op has been requested, combine the old LHS value with the RHS
    7851              :      producing the value we should actually store into the LHS.  */
    7852              : 
    7853      3004172 :   if (modifycode != NOP_EXPR)
    7854              :     {
    7855       218735 :       lhs = c_fully_fold (lhs, false, NULL, true);
    7856       218735 :       lhs = stabilize_reference (lhs);
    7857              : 
    7858              :       /* Construct the RHS for any non-atomic compound assignment. */
    7859       218735 :       if (!is_atomic_op)
    7860              :         {
    7861              :           /* If in LHS op= RHS the RHS has side-effects, ensure they
    7862              :              are preevaluated before the rest of the assignment expression's
    7863              :              side-effects, because RHS could contain e.g. function calls
    7864              :              that modify LHS.  */
    7865       203250 :           if (TREE_SIDE_EFFECTS (rhs))
    7866              :             {
    7867         8978 :               if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
    7868           28 :                 newrhs = save_expr (TREE_OPERAND (rhs, 0));
    7869              :               else
    7870         8950 :                 newrhs = save_expr (rhs);
    7871         8978 :               rhseval = newrhs;
    7872         8978 :               if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
    7873           28 :                 newrhs = build1 (EXCESS_PRECISION_EXPR, TREE_TYPE (rhs),
    7874              :                                  newrhs);
    7875              :             }
    7876       203250 :           bool clear_decl_read = false;
    7877        90288 :           if ((VAR_P (lhs) || TREE_CODE (lhs) == PARM_DECL)
    7878       156430 :               && !DECL_READ_P (lhs)
    7879       255994 :               && (VAR_P (lhs) ? warn_unused_but_set_variable
    7880              :                               : warn_unused_but_set_parameter) > 2)
    7881              :             {
    7882        20963 :               mark_exp_read (newrhs);
    7883        20963 :               if (!DECL_READ_P (lhs))
    7884       203250 :                 clear_decl_read = true;
    7885              :             }
    7886              : 
    7887       203250 :           newrhs = build_binary_op (location, modifycode,
    7888              :                                     convert_lvalue_to_rvalue (location, lhs,
    7889              :                                                               true, true),
    7890              :                                     newrhs, true);
    7891       203250 :           if (clear_decl_read)
    7892        20963 :             DECL_READ_P (lhs) = 0;
    7893              : 
    7894              :           /* The original type of the right hand side is no longer
    7895              :              meaningful.  */
    7896              :           rhs_origtype = NULL_TREE;
    7897              :         }
    7898              :     }
    7899              : 
    7900      3004172 :   if (c_dialect_objc ())
    7901              :     {
    7902              :       /* Check if we are modifying an Objective-C property reference;
    7903              :          if so, we need to generate setter calls.  */
    7904            0 :       if (TREE_CODE (newrhs) == EXCESS_PRECISION_EXPR)
    7905            0 :         result = objc_maybe_build_modify_expr (lhs, TREE_OPERAND (newrhs, 0));
    7906              :       else
    7907            0 :         result = objc_maybe_build_modify_expr (lhs, newrhs);
    7908            0 :       if (result)
    7909            0 :         goto return_result;
    7910              : 
    7911              :       /* Else, do the check that we postponed for Objective-C.  */
    7912            0 :       if (!lvalue_or_else (location, lhs, lv_assign))
    7913            0 :         return error_mark_node;
    7914              :     }
    7915              : 
    7916              :   /* Give an error for storing in something that is 'const'.  */
    7917              : 
    7918      3004172 :   if (TYPE_READONLY (lhstype)
    7919      3004172 :       || (RECORD_OR_UNION_TYPE_P (lhstype)
    7920        25847 :           && C_TYPE_FIELDS_READONLY (lhstype)))
    7921              :     {
    7922           88 :       readonly_error (location, lhs, lv_assign);
    7923           88 :       return error_mark_node;
    7924              :     }
    7925      3004084 :   else if (TREE_READONLY (lhs))
    7926            1 :     readonly_warning (lhs, lv_assign);
    7927              : 
    7928              :   /* If storing into a structure or union member,
    7929              :      it has probably been given type `int'.
    7930              :      Compute the type that would go with
    7931              :      the actual amount of storage the member occupies.  */
    7932              : 
    7933      3004084 :   if (TREE_CODE (lhs) == COMPONENT_REF
    7934       253034 :       && (TREE_CODE (lhstype) == INTEGER_TYPE
    7935       253034 :           || TREE_CODE (lhstype) == BOOLEAN_TYPE
    7936       111239 :           || SCALAR_FLOAT_TYPE_P (lhstype)
    7937        87768 :           || TREE_CODE (lhstype) == ENUMERAL_TYPE))
    7938       172270 :     lhstype = TREE_TYPE (get_unwidened (lhs, 0));
    7939              : 
    7940              :   /* If storing in a field that is in actuality a short or narrower than one,
    7941              :      we must store in the field in its actual type.  */
    7942              : 
    7943      3004084 :   if (lhstype != TREE_TYPE (lhs))
    7944              :     {
    7945            0 :       lhs = copy_node (lhs);
    7946            0 :       TREE_TYPE (lhs) = lhstype;
    7947              :     }
    7948              : 
    7949              :   /* Issue -Wc++-compat warnings about an assignment to an enum type
    7950              :      when LHS does not have its original type.  This happens for,
    7951              :      e.g., an enum bitfield in a struct.  */
    7952      3004084 :   if (warn_cxx_compat
    7953         3276 :       && lhs_origtype != NULL_TREE
    7954         3276 :       && lhs_origtype != lhstype
    7955            7 :       && TREE_CODE (lhs_origtype) == ENUMERAL_TYPE)
    7956              :     {
    7957            4 :       tree checktype = (rhs_origtype != NULL_TREE
    7958            4 :                         ? rhs_origtype
    7959            0 :                         : TREE_TYPE (rhs));
    7960            4 :       if (checktype != error_mark_node
    7961            4 :           && (TYPE_MAIN_VARIANT (checktype) != TYPE_MAIN_VARIANT (lhs_origtype)
    7962            2 :               || (is_atomic_op && modifycode != NOP_EXPR)))
    7963            2 :         warning_at (location, OPT_Wc___compat,
    7964              :                     "enum conversion in assignment is invalid in C++");
    7965              :     }
    7966              : 
    7967              :   /* Remove qualifiers.  */
    7968      3004084 :   lhstype = c_build_qualified_type (lhstype, TYPE_UNQUALIFIED);
    7969      3004084 :   olhstype = c_build_qualified_type (olhstype, TYPE_UNQUALIFIED);
    7970              : 
    7971              :   /* Convert new value to destination type.  Fold it first, then
    7972              :      restore any excess precision information, for the sake of
    7973              :      conversion warnings.  */
    7974              : 
    7975      3004084 :   if (!(is_atomic_op && modifycode != NOP_EXPR))
    7976              :     {
    7977      2988599 :       tree rhs_semantic_type = NULL_TREE;
    7978      2988599 :       if (!c_in_omp_for)
    7979              :         {
    7980      2972217 :           if (TREE_CODE (newrhs) == EXCESS_PRECISION_EXPR)
    7981              :             {
    7982         5097 :               rhs_semantic_type = TREE_TYPE (newrhs);
    7983         5097 :               newrhs = TREE_OPERAND (newrhs, 0);
    7984              :             }
    7985      2972217 :           npc = null_pointer_constant_p (newrhs);
    7986      2972217 :           newrhs = c_fully_fold (newrhs, false, NULL);
    7987      2972217 :           if (rhs_semantic_type)
    7988         5097 :             newrhs = build1 (EXCESS_PRECISION_EXPR, rhs_semantic_type, newrhs);
    7989              :         }
    7990              :       else
    7991        16382 :         npc = null_pointer_constant_p (newrhs);
    7992      2988599 :       newrhs = convert_for_assignment (location, rhs_loc, lhstype, newrhs,
    7993              :                                        rhs_origtype, ic_assign, npc,
    7994              :                                        NULL_TREE, NULL_TREE, 0);
    7995      2988599 :       if (TREE_CODE (newrhs) == ERROR_MARK)
    7996          127 :         return error_mark_node;
    7997              :     }
    7998              : 
    7999              :   /* Emit ObjC write barrier, if necessary.  */
    8000      3003957 :   if (c_dialect_objc () && flag_objc_gc)
    8001              :     {
    8002            0 :       result = objc_generate_write_barrier (lhs, modifycode, newrhs);
    8003            0 :       if (result)
    8004              :         {
    8005            0 :           protected_set_expr_location (result, location);
    8006            0 :           goto return_result;
    8007              :         }
    8008              :     }
    8009              : 
    8010              :   /* Scan operands.  */
    8011              : 
    8012      3003957 :   if (is_atomic_op)
    8013        25988 :     result = build_atomic_assign (location, lhs, modifycode, newrhs, false);
    8014              :   else
    8015              :     {
    8016      2977969 :       result = build2 (MODIFY_EXPR, lhstype, lhs, newrhs);
    8017      2977969 :       TREE_SIDE_EFFECTS (result) = 1;
    8018      2977969 :       protected_set_expr_location (result, location);
    8019              :     }
    8020              : 
    8021              :   /* If we got the LHS in a different type for storing in,
    8022              :      convert the result back to the nominal type of LHS
    8023              :      so that the value we return always has the same type
    8024              :      as the LHS argument.  */
    8025              : 
    8026      3003957 :   if (olhstype == TREE_TYPE (result))
    8027      3003957 :     goto return_result;
    8028              : 
    8029            0 :   result = convert_for_assignment (location, rhs_loc, olhstype, result,
    8030              :                                    rhs_origtype, ic_assign, false, NULL_TREE,
    8031              :                                    NULL_TREE, 0);
    8032            0 :   protected_set_expr_location (result, location);
    8033              : 
    8034      3003957 : return_result:
    8035      3003957 :   if (rhseval)
    8036         8978 :     result = build2 (COMPOUND_EXPR, TREE_TYPE (result), rhseval, result);
    8037              :   return result;
    8038              : }
    8039              : 
    8040              : /* Return whether STRUCT_TYPE has an anonymous field with type TYPE.
    8041              :    This is used to implement -fplan9-extensions.  */
    8042              : 
    8043              : static bool
    8044           26 : find_anonymous_field_with_type (tree struct_type, tree type)
    8045              : {
    8046           26 :   tree field;
    8047           26 :   bool found;
    8048              : 
    8049           26 :   gcc_assert (RECORD_OR_UNION_TYPE_P (struct_type));
    8050           26 :   found = false;
    8051           26 :   for (field = TYPE_FIELDS (struct_type);
    8052           68 :        field != NULL_TREE;
    8053           42 :        field = TREE_CHAIN (field))
    8054              :     {
    8055           42 :       tree fieldtype = remove_qualifiers (TREE_TYPE (field));
    8056           42 :       if (DECL_NAME (field) == NULL
    8057           42 :           && comptypes (type, fieldtype))
    8058              :         {
    8059            4 :           if (found)
    8060              :             return false;
    8061              :           found = true;
    8062              :         }
    8063           38 :       else if (DECL_NAME (field) == NULL
    8064            2 :                && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field))
    8065           40 :                && find_anonymous_field_with_type (TREE_TYPE (field), type))
    8066              :         {
    8067            0 :           if (found)
    8068              :             return false;
    8069              :           found = true;
    8070              :         }
    8071              :     }
    8072              :   return found;
    8073              : }
    8074              : 
    8075              : /* RHS is an expression whose type is pointer to struct.  If there is
    8076              :    an anonymous field in RHS with type TYPE, then return a pointer to
    8077              :    that field in RHS.  This is used with -fplan9-extensions.  This
    8078              :    returns NULL if no conversion could be found.  */
    8079              : 
    8080              : static tree
    8081           28 : convert_to_anonymous_field (location_t location, tree type, tree rhs)
    8082              : {
    8083           28 :   tree rhs_struct_type, lhs_main_type;
    8084           28 :   tree field, found_field;
    8085           28 :   bool found_sub_field;
    8086           28 :   tree ret;
    8087              : 
    8088           28 :   gcc_assert (POINTER_TYPE_P (TREE_TYPE (rhs)));
    8089           28 :   rhs_struct_type = TREE_TYPE (TREE_TYPE (rhs));
    8090           28 :   gcc_assert (RECORD_OR_UNION_TYPE_P (rhs_struct_type));
    8091              : 
    8092           28 :   gcc_assert (POINTER_TYPE_P (type));
    8093           28 :   lhs_main_type = remove_qualifiers (TREE_TYPE (type));
    8094              : 
    8095           28 :   found_field = NULL_TREE;
    8096           28 :   found_sub_field = false;
    8097           28 :   for (field = TYPE_FIELDS (rhs_struct_type);
    8098          172 :        field != NULL_TREE;
    8099          144 :        field = TREE_CHAIN (field))
    8100              :     {
    8101          148 :       if (DECL_NAME (field) != NULL_TREE
    8102          148 :           || !RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)))
    8103           96 :         continue;
    8104           52 :       tree fieldtype = remove_qualifiers (TREE_TYPE (field));
    8105           52 :       if (comptypes (lhs_main_type, fieldtype))
    8106              :         {
    8107           28 :           if (found_field != NULL_TREE)
    8108              :             return NULL_TREE;
    8109              :           found_field = field;
    8110              :         }
    8111           24 :       else if (find_anonymous_field_with_type (TREE_TYPE (field),
    8112              :                                                lhs_main_type))
    8113              :         {
    8114            4 :           if (found_field != NULL_TREE)
    8115              :             return NULL_TREE;
    8116              :           found_field = field;
    8117              :           found_sub_field = true;
    8118              :         }
    8119              :     }
    8120              : 
    8121           24 :   if (found_field == NULL_TREE)
    8122              :     return NULL_TREE;
    8123              : 
    8124           24 :   ret = fold_build3_loc (location, COMPONENT_REF, TREE_TYPE (found_field),
    8125              :                          build_fold_indirect_ref (rhs), found_field,
    8126              :                          NULL_TREE);
    8127           24 :   ret = build_fold_addr_expr_loc (location, ret);
    8128              : 
    8129           24 :   if (found_sub_field)
    8130              :     {
    8131            2 :       ret = convert_to_anonymous_field (location, type, ret);
    8132            2 :       gcc_assert (ret != NULL_TREE);
    8133              :     }
    8134              : 
    8135              :   return ret;
    8136              : }
    8137              : 
    8138              : /* Issue an error message for a bad initializer component.
    8139              :    GMSGID identifies the message.
    8140              :    The component name is taken from the spelling stack.  */
    8141              : 
    8142              : static void ATTRIBUTE_GCC_DIAG (2,0)
    8143          944 : error_init (location_t loc, const char *gmsgid, ...)
    8144              : {
    8145          944 :   char *ofwhat;
    8146              : 
    8147          944 :   auto_diagnostic_group d;
    8148              : 
    8149              :   /* The gmsgid may be a format string with %< and %>. */
    8150          944 :   va_list ap;
    8151          944 :   va_start (ap, gmsgid);
    8152          944 :   bool warned = emit_diagnostic_valist (diagnostics::kind::error,
    8153          944 :                                         loc, -1, gmsgid, &ap);
    8154          944 :   va_end (ap);
    8155              : 
    8156          944 :   ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
    8157          944 :   if (*ofwhat && warned)
    8158          220 :     inform (loc, "(near initialization for %qs)", ofwhat);
    8159          944 : }
    8160              : 
    8161              : /* Used to implement pedwarn_init and permerror_init.  */
    8162              : 
    8163              : static bool ATTRIBUTE_GCC_DIAG (3,0)
    8164         2484 : pedwarn_permerror_init (location_t loc, int opt, const char *gmsgid,
    8165              :                         va_list *ap, enum diagnostics::kind kind)
    8166              : {
    8167              :   /* Use the location where a macro was expanded rather than where
    8168              :      it was defined to make sure macros defined in system headers
    8169              :      but used incorrectly elsewhere are diagnosed.  */
    8170         2484 :   location_t exploc = expansion_point_location_if_in_system_header (loc);
    8171         2484 :   auto_diagnostic_group d;
    8172         2484 :   bool warned = emit_diagnostic_valist (kind, exploc, opt, gmsgid, ap);
    8173         2484 :   if (warned)
    8174              :     {
    8175         1815 :       char *ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
    8176         1815 :       if (*ofwhat)
    8177         1494 :         inform (exploc, "(near initialization for %qs)", ofwhat);
    8178              :     }
    8179         4968 :   return warned;
    8180         2484 : }
    8181              : 
    8182              : /* Issue a pedantic warning for a bad initializer component.  OPT is
    8183              :    the option OPT_* (from options.h) controlling this warning or 0 if
    8184              :    it is unconditionally given.  GMSGID identifies the message.  The
    8185              :    component name is taken from the spelling stack.  */
    8186              : 
    8187              : static bool ATTRIBUTE_GCC_DIAG (3,0)
    8188         2133 : pedwarn_init (location_t loc, int opt, const char *gmsgid, ...)
    8189              : {
    8190         2133 :   va_list ap;
    8191         2133 :   va_start (ap, gmsgid);
    8192         2133 :   bool warned = pedwarn_permerror_init (loc, opt, gmsgid, &ap,
    8193              :                                         diagnostics::kind::pedwarn);
    8194         2133 :   va_end (ap);
    8195         2133 :   return warned;
    8196              : }
    8197              : 
    8198              : /* Like pedwarn_init, but issue a permerror.  */
    8199              : 
    8200              : static bool ATTRIBUTE_GCC_DIAG (3,0)
    8201          351 : permerror_init (location_t loc, int opt, const char *gmsgid, ...)
    8202              : {
    8203          351 :   va_list ap;
    8204          351 :   va_start (ap, gmsgid);
    8205          351 :   bool warned = pedwarn_permerror_init (loc, opt, gmsgid, &ap,
    8206              :                                         diagnostics::kind::permerror);
    8207          351 :   va_end (ap);
    8208          351 :   return warned;
    8209              : }
    8210              : 
    8211              : /* Issue a warning for a bad initializer component.
    8212              : 
    8213              :    OPT is the OPT_W* value corresponding to the warning option that
    8214              :    controls this warning.  GMSGID identifies the message.  The
    8215              :    component name is taken from the spelling stack.  */
    8216              : 
    8217              : static void
    8218          146 : warning_init (location_t loc, int opt, const char *gmsgid)
    8219              : {
    8220          146 :   char *ofwhat;
    8221          146 :   bool warned;
    8222              : 
    8223          146 :   auto_diagnostic_group d;
    8224              : 
    8225              :   /* Use the location where a macro was expanded rather than where
    8226              :      it was defined to make sure macros defined in system headers
    8227              :      but used incorrectly elsewhere are diagnosed.  */
    8228          146 :   location_t exploc = expansion_point_location_if_in_system_header (loc);
    8229              : 
    8230              :   /* The gmsgid may be a format string with %< and %>. */
    8231          146 :   warned = warning_at (exploc, opt, gmsgid);
    8232          146 :   if (warned)
    8233              :     {
    8234          133 :       ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
    8235          133 :       if (*ofwhat)
    8236          133 :         inform (exploc, "(near initialization for %qs)", ofwhat);
    8237              :     }
    8238          146 : }
    8239              : 
    8240              : /* If TYPE is an array type and EXPR is a parenthesized string
    8241              :    constant, warn if pedantic that EXPR is being used to initialize an
    8242              :    object of type TYPE.  */
    8243              : 
    8244              : void
    8245      7361498 : maybe_warn_string_init (location_t loc, tree type, struct c_expr expr)
    8246              : {
    8247      7361498 :   if (pedantic
    8248        81877 :       && TREE_CODE (type) == ARRAY_TYPE
    8249         1207 :       && TREE_CODE (expr.value) == STRING_CST
    8250          472 :       && expr.original_code != STRING_CST)
    8251           13 :     pedwarn_init (loc, OPT_Wpedantic,
    8252              :                   "array initialized from parenthesized string constant");
    8253      7361498 : }
    8254              : 
    8255              : /* Attempt to locate the parameter with the given index within FNDECL,
    8256              :    returning DECL_SOURCE_LOCATION (FNDECL) if it can't be found.  */
    8257              : 
    8258              : static location_t
    8259          937 : get_fndecl_argument_location (tree fndecl, int argnum)
    8260              : {
    8261          937 :   int i;
    8262          937 :   tree param;
    8263              : 
    8264              :   /* Locate param by index within DECL_ARGUMENTS (fndecl).  */
    8265          937 :   for (i = 0, param = DECL_ARGUMENTS (fndecl);
    8266         1016 :        i < argnum && param;
    8267           79 :        i++, param = TREE_CHAIN (param))
    8268              :     ;
    8269              : 
    8270              :   /* If something went wrong (e.g. if we have a builtin and thus no arguments),
    8271              :      return DECL_SOURCE_LOCATION (FNDECL).  */
    8272          937 :   if (param == NULL)
    8273          653 :     return DECL_SOURCE_LOCATION (fndecl);
    8274              : 
    8275          284 :   return DECL_SOURCE_LOCATION (param);
    8276              : }
    8277              : 
    8278              : /* Issue a note about a mismatching argument for parameter PARMNUM
    8279              :    to FUNDECL, for types EXPECTED_TYPE and ACTUAL_TYPE.
    8280              :    Attempt to issue the note at the pertinent parameter of the decl;
    8281              :    failing that issue it at the location of FUNDECL; failing that
    8282              :    issue it at PLOC.
    8283              :    Use highlight_colors::actual for the ACTUAL_TYPE
    8284              :    and highlight_colors::expected for EXPECTED_TYPE and the
    8285              :    parameter of FUNDECL*/
    8286              : 
    8287              : static void
    8288         1062 : inform_for_arg (tree fundecl, location_t ploc, int parmnum,
    8289              :                 tree expected_type, tree actual_type)
    8290              : {
    8291         1062 :   location_t loc;
    8292         1062 :   if (fundecl && !DECL_IS_UNDECLARED_BUILTIN (fundecl))
    8293          937 :     loc = get_fndecl_argument_location (fundecl, parmnum - 1);
    8294              :   else
    8295              :     loc = ploc;
    8296              : 
    8297         1062 :   gcc_rich_location richloc (loc, nullptr, highlight_colors::expected);
    8298              : 
    8299         1062 :   pp_markup::element_expected_type elem_expected_type (expected_type);
    8300         1062 :   pp_markup::element_actual_type elem_actual_type (actual_type);
    8301         1062 :   inform (&richloc,
    8302              :           "expected %e but argument is of type %e",
    8303              :           &elem_expected_type, &elem_actual_type);
    8304         1062 : }
    8305              : 
    8306              : /* Issue a warning when an argument of ARGTYPE is passed to a built-in
    8307              :    function FUNDECL declared without prototype to parameter PARMNUM of
    8308              :    PARMTYPE when ARGTYPE does not promote to PARMTYPE.  */
    8309              : 
    8310              : static void
    8311          418 : maybe_warn_builtin_no_proto_arg (location_t loc, tree fundecl, int parmnum,
    8312              :                                  tree parmtype, tree argtype)
    8313              : {
    8314          418 :   tree_code parmcode = TREE_CODE (parmtype);
    8315          418 :   tree_code argcode = TREE_CODE (argtype);
    8316          418 :   tree promoted = c_type_promotes_to (argtype);
    8317              : 
    8318              :   /* Avoid warning for enum arguments that promote to an integer type
    8319              :      of the same size/mode.  */
    8320          418 :   if (parmcode == INTEGER_TYPE
    8321          418 :       && argcode == ENUMERAL_TYPE
    8322          418 :       && TYPE_MODE (parmtype) == TYPE_MODE (argtype))
    8323              :     return;
    8324              : 
    8325          417 :   if ((parmcode == argcode
    8326          222 :        || (parmcode == INTEGER_TYPE
    8327              :            && argcode == ENUMERAL_TYPE))
    8328          418 :       && TYPE_MAIN_VARIANT (parmtype) == TYPE_MAIN_VARIANT (promoted))
    8329              :     return;
    8330              : 
    8331              :   /* This diagnoses even signed/unsigned mismatches.  Those might be
    8332              :      safe in many cases but GCC may emit suboptimal code for them so
    8333              :      warning on those cases drives efficiency improvements.  */
    8334          398 :   if (warning_at (loc, OPT_Wbuiltin_declaration_mismatch,
    8335          398 :                   TYPE_MAIN_VARIANT (promoted) == argtype
    8336              :                   ? G_("%qD argument %d type is %qT where %qT is expected "
    8337              :                        "in a call to built-in function declared without "
    8338              :                        "prototype")
    8339              :                   : G_("%qD argument %d promotes to %qT where %qT is expected "
    8340              :                        "in a call to built-in function declared without "
    8341              :                        "prototype"),
    8342              :                   fundecl, parmnum, promoted, parmtype))
    8343          150 :     inform (DECL_SOURCE_LOCATION (fundecl),
    8344              :             "built-in %qD declared here",
    8345              :             fundecl);
    8346              : }
    8347              : 
    8348              : /* Print a declaration in quotes, with the given highlight_color.
    8349              :    Analogous to handler for %qD, but with a specific highlight color.  */
    8350              : 
    8351          199 : class pp_element_quoted_decl : public pp_element
    8352              : {
    8353              : public:
    8354          199 :   pp_element_quoted_decl (tree decl, const char *highlight_color)
    8355          199 :   : m_decl (decl),
    8356          199 :     m_highlight_color (highlight_color)
    8357              :   {
    8358              :   }
    8359              : 
    8360          199 :   void add_to_phase_2 (pp_markup::context &ctxt) override
    8361              :   {
    8362          199 :     ctxt.begin_quote ();
    8363          199 :     ctxt.begin_highlight_color (m_highlight_color);
    8364              : 
    8365          199 :     print_decl (ctxt);
    8366              : 
    8367          199 :     ctxt.end_highlight_color ();
    8368          199 :     ctxt.end_quote ();
    8369          199 :   }
    8370              : 
    8371          199 :   void print_decl (pp_markup::context &ctxt)
    8372              :   {
    8373          199 :     pretty_printer *const pp = &ctxt.m_pp;
    8374          199 :     pp->set_padding (pp_none);
    8375          199 :     if (DECL_NAME (m_decl))
    8376          199 :       pp_identifier (pp, lang_hooks.decl_printable_name (m_decl, 2));
    8377              :     else
    8378            0 :       pp_string (pp, _("({anonymous})"));
    8379          199 :   }
    8380              : 
    8381              : private:
    8382              :   tree m_decl;
    8383              :   const char *m_highlight_color;
    8384              : };
    8385              : 
    8386              : /* If TYPE is from a typedef, issue a note showing the location
    8387              :    to the user.
    8388              :    Use HIGHLIGHT_COLOR as the highlight color.  */
    8389              : 
    8390              : static void
    8391         1180 : maybe_inform_typedef_location (tree type, const char *highlight_color)
    8392              : {
    8393         1180 :   if (!typedef_variant_p (type))
    8394         1146 :     return;
    8395              : 
    8396           34 :   tree typedef_decl = TYPE_NAME (type);
    8397           34 :   gcc_assert (TREE_CODE (typedef_decl) == TYPE_DECL);
    8398           34 :   gcc_rich_location richloc (DECL_SOURCE_LOCATION (typedef_decl),
    8399           34 :                              nullptr, highlight_color);
    8400           34 :   pp_element_quoted_decl e_typedef_decl (typedef_decl, highlight_color);
    8401           34 :   inform (&richloc, "%e declared here", &e_typedef_decl);
    8402           34 : }
    8403              : 
    8404              : /* Convert value RHS to type TYPE as preparation for an assignment to
    8405              :    an lvalue of type TYPE.  If ORIGTYPE is not NULL_TREE, it is the
    8406              :    original type of RHS; this differs from TREE_TYPE (RHS) for enum
    8407              :    types.  NULL_POINTER_CONSTANT says whether RHS was a null pointer
    8408              :    constant before any folding.
    8409              :    The real work of conversion is done by `convert'.
    8410              :    The purpose of this function is to generate error messages
    8411              :    for assignments that are not allowed in C.
    8412              :    ERRTYPE says whether it is argument passing, assignment,
    8413              :    initialization or return.
    8414              : 
    8415              :    In the following example, '~' denotes where EXPR_LOC and '^' where
    8416              :    LOCATION point to:
    8417              : 
    8418              :      f (var);      [ic_argpass]
    8419              :      ^  ~~~
    8420              :      x = var;      [ic_assign]
    8421              :        ^ ~~~;
    8422              :      int x = var;  [ic_init]
    8423              :              ^^^
    8424              :      return x;     [ic_return]
    8425              :             ^
    8426              : 
    8427              :    FUNCTION is a tree for the function being called.
    8428              :    PARMNUM is the number of the argument, for printing in error messages.
    8429              :    WARNOPT may be set to a warning option to issue the corresponding warning
    8430              :    rather than an error for invalid conversions.  Used for calls to built-in
    8431              :    functions declared without a prototype.  */
    8432              : 
    8433              : static tree
    8434    172580669 : convert_for_assignment (location_t location, location_t expr_loc, tree type,
    8435              :                         tree rhs, tree origtype, enum impl_conv errtype,
    8436              :                         bool null_pointer_constant, tree fundecl,
    8437              :                         tree function, int parmnum, int warnopt /* = 0 */)
    8438              : {
    8439    172580669 :   enum tree_code codel = TREE_CODE (type);
    8440    172580669 :   tree orig_rhs = rhs;
    8441    172580669 :   tree rhstype;
    8442    172580669 :   enum tree_code coder;
    8443    172580669 :   tree rname = NULL_TREE;
    8444    172580669 :   bool objc_ok = false;
    8445              : 
    8446              :   /* Use the expansion point location to handle cases such as user's
    8447              :      function returning a wrong-type macro defined in a system header.  */
    8448    172580669 :   location = expansion_point_location_if_in_system_header (location);
    8449              : 
    8450    172580669 :   if (errtype == ic_argpass)
    8451              :     {
    8452    129771155 :       tree selector;
    8453              :       /* Change pointer to function to the function itself for
    8454              :          diagnostics.  */
    8455    129771155 :       if (TREE_CODE (function) == ADDR_EXPR
    8456    129771155 :           && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL)
    8457            0 :         function = TREE_OPERAND (function, 0);
    8458              : 
    8459              :       /* Handle an ObjC selector specially for diagnostics.  */
    8460    129771155 :       selector = objc_message_selector ();
    8461    129771155 :       rname = function;
    8462    129771155 :       if (selector && parmnum > 2)
    8463              :         {
    8464            0 :           rname = selector;
    8465            0 :           parmnum -= 2;
    8466              :         }
    8467              :     }
    8468              : 
    8469              :   /* This macro is used to emit diagnostics to ensure that all format
    8470              :      strings are complete sentences, visible to gettext and checked at
    8471              :      compile time.  */
    8472              : #define PEDWARN_FOR_ASSIGNMENT(LOCATION, PLOC, OPT, AR, AS, IN, RE)      \
    8473              :   do {                                                                   \
    8474              :     switch (errtype)                                                     \
    8475              :       {                                                                  \
    8476              :       case ic_argpass:                                                   \
    8477              :         {                                                               \
    8478              :           auto_diagnostic_group d;                                              \
    8479              :           if (pedwarn (PLOC, OPT, AR, parmnum, rname))          \
    8480              :             inform_for_arg (fundecl, (PLOC), parmnum, type, rhstype); \
    8481              :         }                                                               \
    8482              :         break;                                                           \
    8483              :       case ic_assign:                                                    \
    8484              :         pedwarn (LOCATION, OPT, AS);                                     \
    8485              :         break;                                                           \
    8486              :       case ic_init:                                                      \
    8487              :       case ic_init_const:                                                \
    8488              :         pedwarn_init (LOCATION, OPT, IN);                                \
    8489              :         break;                                                           \
    8490              :       case ic_return:                                                    \
    8491              :         pedwarn (LOCATION, OPT, RE);                                     \
    8492              :         break;                                                           \
    8493              :       default:                                                           \
    8494              :         gcc_unreachable ();                                              \
    8495              :       }                                                                  \
    8496              :   } while (0)
    8497              : 
    8498              :   /* This macro is used to emit diagnostics to ensure that all format
    8499              :      strings are complete sentences, visible to gettext and checked at
    8500              :      compile time.  It can be called with 'pedwarn' or 'warning_at'.  */
    8501              : #define WARNING_FOR_QUALIFIERS(PEDWARN, LOCATION, PLOC, OPT, AR, AS, IN, RE, QUALS) \
    8502              :   do {                                                                   \
    8503              :     switch (errtype)                                                     \
    8504              :       {                                                                  \
    8505              :       case ic_argpass:                                                   \
    8506              :         {                                                                \
    8507              :           auto_diagnostic_group d;                                       \
    8508              :           if (PEDWARN) {                                                 \
    8509              :             if (pedwarn (PLOC, OPT, AR, parmnum, rname, QUALS))          \
    8510              :               inform_for_arg (fundecl, (PLOC), parmnum, type, rhstype);  \
    8511              :           } else {                                                       \
    8512              :             if (warning_at (PLOC, OPT, AR, parmnum, rname, QUALS))       \
    8513              :               inform_for_arg (fundecl, (PLOC), parmnum, type, rhstype);  \
    8514              :           }                                                              \
    8515              :         }                                                                \
    8516              :         break;                                                           \
    8517              :       case ic_assign:                                                    \
    8518              :         if (PEDWARN)                                                     \
    8519              :           pedwarn (LOCATION, OPT, AS, QUALS);                            \
    8520              :         else                                                             \
    8521              :           warning_at (LOCATION, OPT, AS, QUALS);                         \
    8522              :         break;                                                           \
    8523              :       case ic_init:                                                      \
    8524              :       case ic_init_const:                                                \
    8525              :         if (PEDWARN)                                                     \
    8526              :           pedwarn (LOCATION, OPT, IN, QUALS);                            \
    8527              :         else                                                             \
    8528              :           warning_at (LOCATION, OPT, IN, QUALS);                         \
    8529              :         break;                                                           \
    8530              :       case ic_return:                                                    \
    8531              :         if (PEDWARN)                                                     \
    8532              :           pedwarn (LOCATION, OPT, RE, QUALS);                            \
    8533              :         else                                                             \
    8534              :           warning_at (LOCATION, OPT, RE, QUALS);                         \
    8535              :         break;                                                           \
    8536              :       default:                                                           \
    8537              :         gcc_unreachable ();                                              \
    8538              :       }                                                                  \
    8539              :   } while (0)
    8540              : 
    8541              :   /* This macro is used to emit diagnostics to ensure that all format
    8542              :      strings are complete sentences, visible to gettext and checked at
    8543              :      compile time.  It is the same as PEDWARN_FOR_ASSIGNMENT but with an
    8544              :      extra parameter to enumerate qualifiers.  */
    8545              : #define PEDWARN_FOR_QUALIFIERS(LOCATION, PLOC, OPT, AR, AS, IN, RE, QUALS) \
    8546              :    WARNING_FOR_QUALIFIERS (true, LOCATION, PLOC, OPT, AR, AS, IN, RE, QUALS)
    8547              : 
    8548              : 
    8549    172580669 :   if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
    8550         6008 :     rhs = TREE_OPERAND (rhs, 0);
    8551              : 
    8552    172580669 :   rhstype = TREE_TYPE (rhs);
    8553    172580669 :   coder = TREE_CODE (rhstype);
    8554              : 
    8555    172580669 :   if (coder == ERROR_MARK)
    8556          347 :     return error_mark_node;
    8557              : 
    8558    172580322 :   if (c_dialect_objc ())
    8559              :     {
    8560            0 :       int parmno;
    8561              : 
    8562            0 :       switch (errtype)
    8563              :         {
    8564              :         case ic_return:
    8565              :           parmno = 0;
    8566              :           break;
    8567              : 
    8568              :         case ic_assign:
    8569              :           parmno = -1;
    8570              :           break;
    8571              : 
    8572              :         case ic_init:
    8573              :         case ic_init_const:
    8574              :           parmno = -2;
    8575              :           break;
    8576              : 
    8577              :         default:
    8578            0 :           parmno = parmnum;
    8579              :           break;
    8580              :         }
    8581              : 
    8582            0 :       objc_ok = objc_compare_types (type, rhstype, parmno, rname);
    8583              :     }
    8584              : 
    8585    172580322 :   if (warn_cxx_compat)
    8586              :     {
    8587        29369 :       tree checktype = origtype != NULL_TREE ? origtype : rhstype;
    8588        29369 :       if (checktype != error_mark_node
    8589        29369 :           && TREE_CODE (type) == ENUMERAL_TYPE
    8590        29475 :           && TYPE_MAIN_VARIANT (checktype) != TYPE_MAIN_VARIANT (type))
    8591           45 :         switch (errtype)
    8592              :           {
    8593            8 :           case ic_argpass:
    8594            8 :             if (pedwarn (expr_loc, OPT_Wc___compat, "enum conversion when "
    8595              :                          "passing argument %d of %qE is invalid in C++",
    8596              :                          parmnum, rname))
    8597           16 :               inform ((fundecl && !DECL_IS_UNDECLARED_BUILTIN (fundecl))
    8598            8 :                       ? DECL_SOURCE_LOCATION (fundecl) : expr_loc,
    8599              :                       "expected %qT but argument is of type %qT",
    8600              :                       type, rhstype);
    8601              :             break;
    8602           10 :           case ic_assign:
    8603           10 :             pedwarn (location, OPT_Wc___compat, "enum conversion from %qT to "
    8604              :                      "%qT in assignment is invalid in C++", rhstype, type);
    8605           10 :             break;
    8606           18 :           case ic_init:
    8607           18 :           case ic_init_const:
    8608           18 :             pedwarn_init (location, OPT_Wc___compat, "enum conversion from "
    8609              :                           "%qT to %qT in initialization is invalid in C++",
    8610              :                           rhstype, type);
    8611           18 :             break;
    8612            9 :           case ic_return:
    8613            9 :             pedwarn (location, OPT_Wc___compat, "enum conversion from %qT to "
    8614              :                      "%qT in return is invalid in C++", rhstype, type);
    8615            9 :             break;
    8616            0 :           default:
    8617            0 :             gcc_unreachable ();
    8618              :           }
    8619              :     }
    8620              : 
    8621    172580322 :   if (warn_enum_conversion)
    8622              :     {
    8623     14903866 :       tree checktype = origtype != NULL_TREE ? origtype : rhstype;
    8624     14903866 :       if (checktype != error_mark_node
    8625     14903866 :           && TREE_CODE (checktype) == ENUMERAL_TYPE
    8626        12855 :           && TREE_CODE (type) == ENUMERAL_TYPE
    8627     14912174 :           && !comptypes (TYPE_MAIN_VARIANT (checktype), TYPE_MAIN_VARIANT (type)))
    8628              :        {
    8629            7 :           gcc_rich_location loc (location);
    8630            7 :           warning_at (&loc, OPT_Wenum_conversion,
    8631              :                       "implicit conversion from %qT to %qT",
    8632              :                       checktype, type);
    8633            7 :        }
    8634              :     }
    8635              : 
    8636    172580322 :   if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
    8637              :     {
    8638    153180589 :       warn_for_address_of_packed_member (type, orig_rhs);
    8639    153180589 :       if (type != rhstype)
    8640              :         /* Convert RHS to TYPE in order to not lose TYPE in diagnostics.  */
    8641     38065262 :         rhs = convert (type, rhs);
    8642              :       return rhs;
    8643              :     }
    8644              : 
    8645     19399733 :   if (coder == VOID_TYPE)
    8646              :     {
    8647              :       /* Except for passing an argument to an unprototyped function,
    8648              :          this is a constraint violation.  When passing an argument to
    8649              :          an unprototyped function, it is compile-time undefined;
    8650              :          making it a constraint in that case was rejected in
    8651              :          DR#252.  */
    8652            8 :       const char msg[] = "void value not ignored as it ought to be";
    8653            8 :       if (warnopt)
    8654            0 :         warning_at (location, warnopt, msg);
    8655              :       else
    8656            8 :         error_at (location, msg);
    8657            8 :       return error_mark_node;
    8658              :     }
    8659     19399725 :   rhs = require_complete_type (location, rhs);
    8660     19399725 :   if (rhs == error_mark_node)
    8661              :     return error_mark_node;
    8662              : 
    8663     19399725 :   if (coder == POINTER_TYPE && reject_gcc_builtin (rhs))
    8664            6 :     return error_mark_node;
    8665              : 
    8666              :   /* A non-reference type can convert to a reference.  This handles
    8667              :      va_start, va_copy and possibly port built-ins.  */
    8668     19399719 :   if (codel == REFERENCE_TYPE && coder != REFERENCE_TYPE)
    8669              :     {
    8670          290 :       if (!lvalue_p (rhs))
    8671              :         {
    8672            0 :           const char msg[] = "cannot pass rvalue to reference parameter";
    8673            0 :           if (warnopt)
    8674            0 :             warning_at (location, warnopt, msg);
    8675              :           else
    8676            0 :             error_at (location, msg);
    8677            0 :           return error_mark_node;
    8678              :         }
    8679          290 :       if (!c_mark_addressable (rhs))
    8680            0 :         return error_mark_node;
    8681          290 :       rhs = build1 (ADDR_EXPR, c_build_pointer_type (TREE_TYPE (rhs)), rhs);
    8682          290 :       SET_EXPR_LOCATION (rhs, location);
    8683              : 
    8684          290 :       rhs = convert_for_assignment (location, expr_loc,
    8685          290 :                                     c_build_pointer_type (TREE_TYPE (type)),
    8686              :                                     rhs, origtype, errtype,
    8687              :                                     null_pointer_constant, fundecl, function,
    8688              :                                     parmnum, warnopt);
    8689          290 :       if (rhs == error_mark_node)
    8690              :         return error_mark_node;
    8691              : 
    8692          290 :       rhs = build1 (NOP_EXPR, type, rhs);
    8693          290 :       SET_EXPR_LOCATION (rhs, location);
    8694          290 :       return rhs;
    8695              :     }
    8696              :   /* Some types can interconvert without explicit casts.  */
    8697     19399429 :   else if (codel == VECTOR_TYPE && coder == VECTOR_TYPE
    8698     19399429 :            && vector_types_convertible_p (type, TREE_TYPE (rhs), true))
    8699      9379439 :     return convert (type, rhs);
    8700              :   /* Arithmetic types all interconvert, and enum is treated like int.  */
    8701     10019990 :   else if ((codel == INTEGER_TYPE || codel == REAL_TYPE
    8702      2306562 :             || codel == FIXED_POINT_TYPE
    8703      2306562 :             || codel == ENUMERAL_TYPE || codel == COMPLEX_TYPE
    8704      2219738 :             || codel == BOOLEAN_TYPE || codel == BITINT_TYPE)
    8705      7901872 :            && (coder == INTEGER_TYPE || coder == REAL_TYPE
    8706        84281 :                || coder == FIXED_POINT_TYPE
    8707        84281 :                || coder == ENUMERAL_TYPE || coder == COMPLEX_TYPE
    8708        40788 :                || coder == BOOLEAN_TYPE || coder == BITINT_TYPE))
    8709              :     {
    8710      7900495 :       if (warnopt && errtype == ic_argpass)
    8711          418 :         maybe_warn_builtin_no_proto_arg (expr_loc, fundecl, parmnum, type,
    8712              :                                          rhstype);
    8713              : 
    8714      7900495 :       bool save = in_late_binary_op;
    8715      7862791 :       if (C_BOOLEAN_TYPE_P (type) || codel == COMPLEX_TYPE
    8716     15706107 :           || (coder == REAL_TYPE
    8717       277932 :               && (codel == INTEGER_TYPE || codel == ENUMERAL_TYPE)
    8718        24240 :               && sanitize_flags_p (SANITIZE_FLOAT_CAST)))
    8719       101627 :         in_late_binary_op = true;
    8720     11318260 :       tree ret = convert_and_check (expr_loc != UNKNOWN_LOCATION
    8721              :                                     ? expr_loc : location, type, orig_rhs,
    8722              :                                     errtype == ic_init_const);
    8723      7900495 :       in_late_binary_op = save;
    8724      7900495 :       return ret;
    8725              :     }
    8726              : 
    8727              :   /* Aggregates in different TUs might need conversion.  */
    8728      2119495 :   if ((codel == RECORD_TYPE || codel == UNION_TYPE)
    8729          105 :       && codel == coder
    8730      2119517 :       && comptypes (TYPE_MAIN_VARIANT (type), TYPE_MAIN_VARIANT (rhstype)))
    8731            9 :     return convert_and_check (expr_loc != UNKNOWN_LOCATION
    8732            9 :                               ? expr_loc : location, type, rhs);
    8733              : 
    8734              :   /* Conversion to a transparent union or record from its member types.
    8735              :      This applies only to function arguments.  */
    8736      2119486 :   if (((codel == UNION_TYPE || codel == RECORD_TYPE)
    8737           96 :       && TYPE_TRANSPARENT_AGGR (type))
    8738      2119525 :       && errtype == ic_argpass)
    8739              :     {
    8740           39 :       tree memb, marginal_memb = NULL_TREE;
    8741              : 
    8742           50 :       for (memb = TYPE_FIELDS (type); memb ; memb = DECL_CHAIN (memb))
    8743              :         {
    8744           50 :           tree memb_type = TREE_TYPE (memb);
    8745              : 
    8746           50 :           if (comptypes (TYPE_MAIN_VARIANT (memb_type),
    8747           50 :                          TYPE_MAIN_VARIANT (rhstype)))
    8748              :             break;
    8749              : 
    8750           27 :           if (TREE_CODE (memb_type) != POINTER_TYPE)
    8751            1 :             continue;
    8752              : 
    8753           26 :           if (coder == POINTER_TYPE)
    8754              :             {
    8755           26 :               tree ttl = TREE_TYPE (memb_type);
    8756           26 :               tree ttr = TREE_TYPE (rhstype);
    8757              : 
    8758              :               /* Any non-function converts to a [const][volatile] void *
    8759              :                  and vice versa; otherwise, targets must be the same.
    8760              :                  Meanwhile, the lhs target must have all the qualifiers of
    8761              :                  the rhs.  */
    8762            0 :               if ((VOID_TYPE_P (ttl) && !TYPE_ATOMIC (ttl))
    8763           26 :                   || (VOID_TYPE_P (ttr) && !TYPE_ATOMIC (ttr))
    8764           45 :                   || comp_target_types (location, memb_type, rhstype))
    8765              :                 {
    8766           16 :                   auto lquals = TYPE_QUALS (ttl).without (TYPE_QUAL_ATOMIC);
    8767           16 :                   auto rquals = TYPE_QUALS (ttr).without (TYPE_QUAL_ATOMIC);
    8768              :                   /* If this type won't generate any warnings, use it.  */
    8769           32 :                   if (lquals == rquals
    8770           16 :                       || ((TREE_CODE (ttr) == FUNCTION_TYPE
    8771            0 :                            && TREE_CODE (ttl) == FUNCTION_TYPE)
    8772           16 :                           ? (rquals.superset_of (lquals))
    8773           16 :                           : (lquals.superset_of (rquals))))
    8774              :                     break;
    8775              : 
    8776              :                   /* Keep looking for a better type, but remember this one.  */
    8777            0 :                   if (!marginal_memb)
    8778            0 :                     marginal_memb = memb;
    8779              :                 }
    8780              :             }
    8781              : 
    8782              :           /* Can convert integer zero to any pointer type.  */
    8783           10 :           if (null_pointer_constant)
    8784              :             {
    8785            0 :               rhs = null_pointer_node;
    8786            0 :               break;
    8787              :             }
    8788              :         }
    8789              : 
    8790           39 :       if (memb || marginal_memb)
    8791              :         {
    8792           39 :           if (!memb)
    8793              :             {
    8794              :               /* We have only a marginally acceptable member type;
    8795              :                  it needs a warning.  */
    8796            0 :               tree ttl = TREE_TYPE (TREE_TYPE (marginal_memb));
    8797            0 :               tree ttr = TREE_TYPE (rhstype);
    8798              : 
    8799              :               /* Const and volatile mean something different for function
    8800              :                  types, so the usual warnings are not appropriate.  */
    8801            0 :               if (TREE_CODE (ttr) == FUNCTION_TYPE
    8802            0 :                   && TREE_CODE (ttl) == FUNCTION_TYPE)
    8803              :                 {
    8804              :                   /* Because const and volatile on functions are
    8805              :                      restrictions that say the function will not do
    8806              :                      certain things, it is okay to use a const or volatile
    8807              :                      function where an ordinary one is wanted, but not
    8808              :                      vice-versa.  */
    8809            0 :                   if (TYPE_QUALS_NO_ADDR_SPACE (ttl)
    8810            0 :                       & ~TYPE_QUALS_NO_ADDR_SPACE (ttr))
    8811            0 :                     PEDWARN_FOR_QUALIFIERS (location, expr_loc,
    8812              :                                             OPT_Wdiscarded_qualifiers,
    8813              :                                             G_("passing argument %d of %qE "
    8814              :                                                "makes %q#v qualified function "
    8815              :                                                "pointer from unqualified"),
    8816              :                                             G_("assignment makes %q#v qualified "
    8817              :                                                "function pointer from "
    8818              :                                                "unqualified"),
    8819              :                                             G_("initialization makes %q#v qualified "
    8820              :                                                "function pointer from "
    8821              :                                                "unqualified"),
    8822              :                                             G_("return makes %q#v qualified function "
    8823              :                                                "pointer from unqualified"),
    8824              :                                             TYPE_QUALS_NO_ADDR_SPACE (ttl)
    8825              :                                             & ~TYPE_QUALS_NO_ADDR_SPACE (ttr));
    8826              :                 }
    8827            0 :               else if (TYPE_QUALS_NO_ADDR_SPACE (ttr)
    8828            0 :                        & ~TYPE_QUALS_NO_ADDR_SPACE (ttl))
    8829            0 :                 PEDWARN_FOR_QUALIFIERS (location, expr_loc,
    8830              :                                         OPT_Wdiscarded_qualifiers,
    8831              :                                         G_("passing argument %d of %qE discards "
    8832              :                                            "%qv qualifier from pointer target type"),
    8833              :                                         G_("assignment discards %qv qualifier "
    8834              :                                            "from pointer target type"),
    8835              :                                         G_("initialization discards %qv qualifier "
    8836              :                                            "from pointer target type"),
    8837              :                                         G_("return discards %qv qualifier from "
    8838              :                                            "pointer target type"),
    8839              :                                         TYPE_QUALS_NO_ADDR_SPACE (ttr)
    8840              :                                         & ~TYPE_QUALS_NO_ADDR_SPACE (ttl));
    8841              : 
    8842              :               memb = marginal_memb;
    8843              :             }
    8844              : 
    8845           39 :           if (!fundecl || !DECL_IN_SYSTEM_HEADER (fundecl))
    8846           31 :             pedwarn (location, OPT_Wpedantic,
    8847              :                      "ISO C prohibits argument conversion to union type");
    8848              : 
    8849           39 :           rhs = fold_convert_loc (location, TREE_TYPE (memb), rhs);
    8850           39 :           return build_constructor_single (type, memb, rhs);
    8851              :         }
    8852              :     }
    8853              : 
    8854              :   /* Conversions among pointers */
    8855      2119447 :   else if ((codel == POINTER_TYPE || codel == REFERENCE_TYPE)
    8856      2117914 :            && (coder == codel))
    8857              :     {
    8858              :       /* If RHS refers to a built-in declared without a prototype
    8859              :          BLTIN is the declaration of the built-in with a prototype
    8860              :          and RHSTYPE is set to the actual type of the built-in.  */
    8861      2039250 :       tree bltin;
    8862      2039250 :       rhstype = type_or_builtin_type (rhs, &bltin);
    8863              : 
    8864      2039250 :       tree ttl = TREE_TYPE (type);
    8865      2039250 :       tree ttr = TREE_TYPE (rhstype);
    8866      2039250 :       bool is_opaque_pointer;
    8867      2039250 :       bool target_cmp = false;   /* Cache comp_target_types () result.  */
    8868      2039250 :       addr_space_t asl;
    8869      2039250 :       addr_space_t asr;
    8870              : 
    8871      2039250 :       tree mvl = remove_qualifiers (ttl);
    8872      2039250 :       tree mvr = remove_qualifiers (ttr);
    8873              : 
    8874              :       /* Opaque pointers are treated like void pointers.  */
    8875      2039250 :       is_opaque_pointer = vector_targets_convertible_p (ttl, ttr);
    8876              : 
    8877              :       /* The Plan 9 compiler permits a pointer to a struct to be
    8878              :          automatically converted into a pointer to an anonymous field
    8879              :          within the struct.  */
    8880      2039250 :       if (flag_plan9_extensions
    8881           50 :           && RECORD_OR_UNION_TYPE_P (mvl)
    8882           26 :           && RECORD_OR_UNION_TYPE_P (mvr)
    8883           26 :           && mvl != mvr)
    8884              :         {
    8885           26 :           tree new_rhs = convert_to_anonymous_field (location, type, rhs);
    8886           26 :           if (new_rhs != NULL_TREE)
    8887              :             {
    8888           22 :               rhs = new_rhs;
    8889           22 :               rhstype = TREE_TYPE (rhs);
    8890           22 :               coder = TREE_CODE (rhstype);
    8891           22 :               ttr = TREE_TYPE (rhstype);
    8892           22 :               mvr = TYPE_MAIN_VARIANT (ttr);
    8893              :             }
    8894              :         }
    8895              : 
    8896              :       /* C++ does not allow the implicit conversion void* -> T*.  However,
    8897              :          for the purpose of reducing the number of false positives, we
    8898              :          tolerate the special case of
    8899              : 
    8900              :                 int *p = NULL;
    8901              : 
    8902              :          where NULL is typically defined in C to be '(void *) 0'.  */
    8903      2039250 :       if (VOID_TYPE_P (ttr) && rhs != null_pointer_node && !VOID_TYPE_P (ttl))
    8904        27501 :         warning_at (errtype == ic_argpass ? expr_loc : location,
    8905        14574 :                     OPT_Wc___compat,
    8906              :                     "request for implicit conversion "
    8907              :                     "from %qT to %qT not permitted in C++", rhstype, type);
    8908              : 
    8909              :       /* Warn of new allocations that are not big enough for the target
    8910              :          type.  */
    8911      2039250 :       if (warn_alloc_size && TREE_CODE (rhs) == CALL_EXPR)
    8912         5463 :         if (tree fndecl = get_callee_fndecl (rhs))
    8913         5463 :           if (DECL_IS_MALLOC (fndecl))
    8914              :             {
    8915         4614 :               tree attrs = TYPE_ATTRIBUTES (TREE_TYPE (fndecl));
    8916         4614 :               tree alloc_size = lookup_attribute ("alloc_size", attrs);
    8917         4614 :               if (alloc_size)
    8918          451 :                 warn_for_alloc_size (location, ttl, rhs, alloc_size);
    8919              :             }
    8920              : 
    8921              :       /* See if the pointers point to incompatible address spaces.  */
    8922      2039250 :       asl = TYPE_ADDR_SPACE (ttl);
    8923      2039250 :       asr = TYPE_ADDR_SPACE (ttr);
    8924      2039250 :       if (!null_pointer_constant_p (rhs)
    8925      2039250 :           && asr != asl && !targetm.addr_space.subset_p (asr, asl))
    8926              :         {
    8927            3 :           auto_diagnostic_group d;
    8928            3 :           bool diagnosed = true;
    8929            3 :           switch (errtype)
    8930              :             {
    8931            1 :             case ic_argpass:
    8932            1 :               {
    8933            1 :                 const char msg[] = G_("passing argument %d of %qE from "
    8934              :                                       "pointer to non-enclosed address space");
    8935            1 :                 if (warnopt)
    8936            0 :                   diagnosed
    8937            0 :                     = warning_at (expr_loc, warnopt, msg, parmnum, rname);
    8938              :                 else
    8939            1 :                   error_at (expr_loc, msg, parmnum, rname);
    8940            0 :               break;
    8941              :               }
    8942            0 :             case ic_assign:
    8943            0 :               {
    8944            0 :                 const char msg[] = G_("assignment from pointer to "
    8945              :                                       "non-enclosed address space");
    8946            0 :                 if (warnopt)
    8947            0 :                   diagnosed = warning_at (location, warnopt, msg);
    8948              :                 else
    8949            0 :                   error_at (location, msg);
    8950            0 :                 break;
    8951              :               }
    8952            0 :             case ic_init:
    8953            0 :             case ic_init_const:
    8954            0 :               {
    8955            0 :                 const char msg[] = G_("initialization from pointer to "
    8956              :                                       "non-enclosed address space");
    8957            0 :                 if (warnopt)
    8958            0 :                   diagnosed = warning_at (location, warnopt, msg);
    8959              :                 else
    8960            0 :                   error_at (location, msg);
    8961            0 :                 break;
    8962              :               }
    8963            2 :             case ic_return:
    8964            2 :               {
    8965            2 :                 const char msg[] = G_("return from pointer to "
    8966              :                                       "non-enclosed address space");
    8967            2 :                 if (warnopt)
    8968            0 :                   diagnosed = warning_at (location, warnopt, msg);
    8969              :                 else
    8970            2 :                   error_at (location, msg);
    8971            0 :                 break;
    8972              :               }
    8973            0 :             default:
    8974            0 :               gcc_unreachable ();
    8975              :             }
    8976            3 :           if (diagnosed)
    8977              :             {
    8978            3 :               if (errtype == ic_argpass)
    8979            1 :                 inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
    8980              :               else
    8981            2 :                 inform (location, "expected %qT but pointer is of type %qT",
    8982              :                         type, rhstype);
    8983              :             }
    8984            3 :           return error_mark_node;
    8985            3 :         }
    8986              : 
    8987              :       /* Check if the right-hand side has a format attribute but the
    8988              :          left-hand side doesn't.  */
    8989      2039247 :       if (warn_suggest_attribute_format
    8990      2039247 :           && check_missing_format_attribute (type, rhstype))
    8991              :         {
    8992           16 :           switch (errtype)
    8993              :           {
    8994            4 :           case ic_argpass:
    8995            4 :             warning_at (expr_loc, OPT_Wsuggest_attribute_format,
    8996              :                         "argument %d of %qE might be "
    8997              :                         "a candidate for a format attribute",
    8998              :                         parmnum, rname);
    8999            4 :             break;
    9000            4 :           case ic_assign:
    9001            4 :             warning_at (location, OPT_Wsuggest_attribute_format,
    9002              :                         "assignment left-hand side might be "
    9003              :                         "a candidate for a format attribute");
    9004            4 :             break;
    9005            4 :           case ic_init:
    9006            4 :           case ic_init_const:
    9007            4 :             warning_at (location, OPT_Wsuggest_attribute_format,
    9008              :                         "initialization left-hand side might be "
    9009              :                         "a candidate for a format attribute");
    9010            4 :             break;
    9011            4 :           case ic_return:
    9012            4 :             warning_at (location, OPT_Wsuggest_attribute_format,
    9013              :                         "return type might be "
    9014              :                         "a candidate for a format attribute");
    9015            4 :             break;
    9016            0 :           default:
    9017            0 :             gcc_unreachable ();
    9018              :           }
    9019              :         }
    9020              : 
    9021              :       /* See if the pointers point to incompatible scalar storage orders.  */
    9022      2039247 :       if (warn_scalar_storage_order
    9023      2036331 :           && !null_pointer_constant_p (rhs)
    9024      6042691 :           && (AGGREGATE_TYPE_P (ttl) && TYPE_REVERSE_STORAGE_ORDER (ttl))
    9025      2001722 :              != (AGGREGATE_TYPE_P (ttr) && TYPE_REVERSE_STORAGE_ORDER (ttr)))
    9026              :         {
    9027           18 :           tree t;
    9028              : 
    9029           18 :           switch (errtype)
    9030              :           {
    9031           11 :           case ic_argpass:
    9032              :             /* Do not warn for built-in functions, for example memcpy, since we
    9033              :                control how they behave and they can be useful in this area.  */
    9034           11 :             if (TREE_CODE (rname) != FUNCTION_DECL
    9035           11 :                 || !fndecl_built_in_p (rname))
    9036            1 :               warning_at (location, OPT_Wscalar_storage_order,
    9037              :                           "passing argument %d of %qE from incompatible "
    9038              :                           "scalar storage order", parmnum, rname);
    9039              :             break;
    9040            3 :           case ic_assign:
    9041              :             /* Do not warn if the RHS is a call to a function that returns a
    9042              :                pointer that is not an alias.  */
    9043            3 :             if (TREE_CODE (rhs) != CALL_EXPR
    9044            2 :                 || (t = get_callee_fndecl (rhs)) == NULL_TREE
    9045            5 :                 || !DECL_IS_MALLOC (t))
    9046            1 :               warning_at (location, OPT_Wscalar_storage_order,
    9047              :                           "assignment to %qT from pointer type %qT with "
    9048              :                           "incompatible scalar storage order", type, rhstype);
    9049              :             break;
    9050            3 :           case ic_init:
    9051            3 :           case ic_init_const:
    9052              :             /* Likewise.  */
    9053            3 :             if (TREE_CODE (rhs) != CALL_EXPR
    9054            2 :                 || (t = get_callee_fndecl (rhs)) == NULL_TREE
    9055            5 :                 || !DECL_IS_MALLOC (t))
    9056            1 :               warning_at (location, OPT_Wscalar_storage_order,
    9057              :                           "initialization of %qT from pointer type %qT with "
    9058              :                           "incompatible scalar storage order", type, rhstype);
    9059              :             break;
    9060            1 :           case ic_return:
    9061            1 :             warning_at (location, OPT_Wscalar_storage_order,
    9062              :                         "returning %qT from pointer type with incompatible "
    9063              :                         "scalar storage order %qT", rhstype, type);
    9064            1 :             break;
    9065            0 :           default:
    9066            0 :             gcc_unreachable ();
    9067              :           }
    9068              :         }
    9069              : 
    9070              :       /* Any non-function converts to a [const][volatile] void *
    9071              :          and vice versa; otherwise, targets must be the same.
    9072              :          Meanwhile, the lhs target must have all the qualifiers of the rhs.  */
    9073       422440 :       if ((VOID_TYPE_P (ttl) && !TYPE_ATOMIC (ttl))
    9074      1616808 :           || (VOID_TYPE_P (ttr) && !TYPE_ATOMIC (ttr))
    9075      1567764 :           || (target_cmp = comp_target_types (location, type, rhstype))
    9076         2507 :           || is_opaque_pointer
    9077      2044261 :           || ((c_common_unsigned_type (mvl)
    9078         2507 :                == c_common_unsigned_type (mvr))
    9079         3460 :               && (c_common_signed_type (mvl)
    9080         1730 :                   == c_common_signed_type (mvr))
    9081         1715 :               && TYPE_ATOMIC (mvl) == TYPE_ATOMIC (mvr)))
    9082              :         {
    9083              :           /* Warn about loss of qualifers from pointers to arrays with
    9084              :              qualifiers on the element type. */
    9085      2038447 :           if (TREE_CODE (ttr) == ARRAY_TYPE)
    9086              :             {
    9087         2131 :               ttr = strip_array_types (ttr);
    9088         2131 :               ttl = strip_array_types (ttl);
    9089              : 
    9090         2131 :               if (TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttr)
    9091         2131 :                   & ~TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttl))
    9092          115 :                 WARNING_FOR_QUALIFIERS (flag_isoc23,
    9093              :                                         location, expr_loc,
    9094              :                                         OPT_Wdiscarded_array_qualifiers,
    9095              :                                         G_("passing argument %d of %qE discards "
    9096              :                                            "%qv qualifier from pointer target type"),
    9097              :                                         G_("assignment discards %qv qualifier "
    9098              :                                            "from pointer target type"),
    9099              :                                         G_("initialization discards %qv qualifier "
    9100              :                                            "from pointer target type"),
    9101              :                                         G_("return discards %qv qualifier from "
    9102              :                                            "pointer target type"),
    9103              :                                         TYPE_QUALS_NO_ADDR_SPACE (ttr)
    9104              :                                         & ~TYPE_QUALS_NO_ADDR_SPACE (ttl));
    9105              :             }
    9106      2036316 :           else if (pedantic
    9107       146628 :               && ((VOID_TYPE_P (ttl) && TREE_CODE (ttr) == FUNCTION_TYPE)
    9108       146608 :                   ||
    9109              :                   (VOID_TYPE_P (ttr)
    9110         2923 :                    && !null_pointer_constant
    9111          184 :                    && TREE_CODE (ttl) == FUNCTION_TYPE)))
    9112           34 :             PEDWARN_FOR_ASSIGNMENT (location, expr_loc, OPT_Wpedantic,
    9113              :                                     G_("ISO C forbids passing argument %d of "
    9114              :                                        "%qE between function pointer "
    9115              :                                        "and %<void *%>"),
    9116              :                                     G_("ISO C forbids assignment between "
    9117              :                                        "function pointer and %<void *%>"),
    9118              :                                     G_("ISO C forbids initialization between "
    9119              :                                        "function pointer and %<void *%>"),
    9120              :                                     G_("ISO C forbids return between function "
    9121              :                                        "pointer and %<void *%>"));
    9122              :           /* Const and volatile mean something different for function types,
    9123              :              so the usual warnings are not appropriate.  */
    9124      2036282 :           else if (TREE_CODE (ttr) != FUNCTION_TYPE
    9125      2003849 :                    && TREE_CODE (ttl) != FUNCTION_TYPE)
    9126              :             {
    9127              :                /* Assignments between atomic and non-atomic objects are OK.  */
    9128      2003106 :                bool warn_quals_ped = TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttr)
    9129      2003106 :                                      & ~TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttl);
    9130      2003106 :                bool warn_quals = TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttr)
    9131      2003106 :                                  & ~TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (strip_array_types (ttl));
    9132              : 
    9133              :               /* Don't warn about loss of qualifier for conversions from
    9134              :                  qualified void* to pointers to arrays with corresponding
    9135              :                  qualifier on the element type (except for pedantic before C23). */
    9136      2003106 :               if (warn_quals || (warn_quals_ped && pedantic && !flag_isoc23))
    9137          697 :                 PEDWARN_FOR_QUALIFIERS (location, expr_loc,
    9138              :                                         OPT_Wdiscarded_qualifiers,
    9139              :                                         G_("passing argument %d of %qE discards "
    9140              :                                            "%qv qualifier from pointer target type"),
    9141              :                                         G_("assignment discards %qv qualifier "
    9142              :                                            "from pointer target type"),
    9143              :                                         G_("initialization discards %qv qualifier "
    9144              :                                            "from pointer target type"),
    9145              :                                         G_("return discards %qv qualifier from "
    9146              :                                            "pointer target type"),
    9147              :                                         TYPE_QUALS_NO_ADDR_SPACE (ttr)
    9148              :                                         & ~TYPE_QUALS_NO_ADDR_SPACE (ttl));
    9149           11 :               else if (warn_quals_ped)
    9150           11 :                 pedwarn_c11 (location, OPT_Wc11_c23_compat,
    9151              :                              "array with qualifier on the element is not qualified before C23");
    9152              : 
    9153              :               /* If this is not a case of ignoring a mismatch in signedness,
    9154              :                  no warning.  */
    9155      2002398 :               else if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr)
    9156      1562842 :                        || target_cmp)
    9157              :                 ;
    9158              :               /* If there is a mismatch, do warn.  */
    9159         1707 :               else if (warn_pointer_sign)
    9160           82 :                 switch (errtype)
    9161              :                   {
    9162           33 :                   case ic_argpass:
    9163           33 :                     {
    9164           33 :                       auto_diagnostic_group d;
    9165           33 :                       range_label_for_type_mismatch rhs_label (rhstype, type);
    9166           33 :                       gcc_rich_location richloc (expr_loc, &rhs_label,
    9167           33 :                                                  highlight_colors::actual);
    9168           33 :                       if (pedwarn (&richloc, OPT_Wpointer_sign,
    9169              :                                    "pointer targets in passing argument %d of "
    9170              :                                    "%qE differ in signedness", parmnum, rname))
    9171           33 :                         inform_for_arg (fundecl, expr_loc, parmnum, type,
    9172              :                                         rhstype);
    9173           33 :                     }
    9174           33 :                     break;
    9175           21 :                   case ic_assign:
    9176           21 :                     pedwarn (location, OPT_Wpointer_sign,
    9177              :                              "pointer targets in assignment from %qT to %qT "
    9178              :                              "differ in signedness", rhstype, type);
    9179           21 :                     break;
    9180           14 :                   case ic_init:
    9181           14 :                   case ic_init_const:
    9182           14 :                     pedwarn_init (location, OPT_Wpointer_sign,
    9183              :                                   "pointer targets in initialization of %qT "
    9184              :                                   "from %qT differ in signedness", type,
    9185              :                                   rhstype);
    9186           14 :                     break;
    9187           14 :                   case ic_return:
    9188           14 :                     pedwarn (location, OPT_Wpointer_sign, "pointer targets in "
    9189              :                              "returning %qT from a function with return type "
    9190              :                              "%qT differ in signedness", rhstype, type);
    9191           14 :                     break;
    9192            0 :                   default:
    9193            0 :                     gcc_unreachable ();
    9194              :                   }
    9195              :             }
    9196        33176 :           else if (TREE_CODE (ttl) == FUNCTION_TYPE
    9197         4194 :                    && TREE_CODE (ttr) == FUNCTION_TYPE)
    9198              :             {
    9199              :               /* Because const and volatile on functions are restrictions
    9200              :                  that say the function will not do certain things,
    9201              :                  it is okay to use a const or volatile function
    9202              :                  where an ordinary one is wanted, but not vice-versa.  */
    9203         3451 :               if (TYPE_QUALS_NO_ADDR_SPACE (ttl)
    9204         3451 :                   & ~TYPE_QUALS_NO_ADDR_SPACE (ttr))
    9205           18 :                 PEDWARN_FOR_QUALIFIERS (location, expr_loc,
    9206              :                                         OPT_Wdiscarded_qualifiers,
    9207              :                                         G_("passing argument %d of %qE makes "
    9208              :                                            "%q#v qualified function pointer "
    9209              :                                            "from unqualified"),
    9210              :                                         G_("assignment makes %q#v qualified function "
    9211              :                                            "pointer from unqualified"),
    9212              :                                         G_("initialization makes %q#v qualified "
    9213              :                                            "function pointer from unqualified"),
    9214              :                                         G_("return makes %q#v qualified function "
    9215              :                                            "pointer from unqualified"),
    9216              :                                         TYPE_QUALS_NO_ADDR_SPACE (ttl)
    9217              :                                         & ~TYPE_QUALS_NO_ADDR_SPACE (ttr));
    9218              :             }
    9219              :         }
    9220              :       /* Avoid warning about the volatile ObjC EH puts on decls.  */
    9221          800 :       else if (!objc_ok)
    9222              :         {
    9223          800 :           auto_diagnostic_group d;
    9224          800 :           bool warned = false;
    9225          800 :           pp_markup::element_expected_type e_type (type);
    9226          800 :           pp_markup::element_actual_type e_rhstype (rhstype);
    9227          800 :           switch (errtype)
    9228              :             {
    9229          307 :             case ic_argpass:
    9230          307 :               {
    9231          307 :                 range_label_for_type_mismatch rhs_label (rhstype, type);
    9232          307 :                 gcc_rich_location richloc (expr_loc, &rhs_label,
    9233          307 :                                            highlight_colors::actual);
    9234          307 :                 warned
    9235          307 :                   = permerror_opt (&richloc, OPT_Wincompatible_pointer_types,
    9236              :                                    "passing argument %d of %qE from "
    9237              :                                    "incompatible pointer type",
    9238              :                                    parmnum, rname);
    9239          307 :                 if (warned)
    9240          175 :                   inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
    9241          307 :               }
    9242          307 :               break;
    9243          267 :             case ic_assign:
    9244          267 :               if (bltin)
    9245           11 :                 warned
    9246           11 :                   = permerror_opt (location, OPT_Wincompatible_pointer_types,
    9247              :                                    "assignment to %e from pointer to "
    9248              :                                    "%qD with incompatible type %e",
    9249              :                                    &e_type, bltin, &e_rhstype);
    9250              :               else
    9251          256 :                 warned
    9252          256 :                   = permerror_opt (location, OPT_Wincompatible_pointer_types,
    9253              :                                    "assignment to %e from incompatible "
    9254              :                                    "pointer type %e",
    9255              :                                    &e_type, &e_rhstype);
    9256              :               break;
    9257          167 :             case ic_init:
    9258          167 :             case ic_init_const:
    9259          167 :               if (bltin)
    9260           13 :                 warned
    9261           13 :                   = permerror_init (location, OPT_Wincompatible_pointer_types,
    9262              :                                     "initialization of %e from pointer to "
    9263              :                                     "%qD with incompatible type %e",
    9264              :                                     &e_type, bltin, &e_rhstype);
    9265              :               else
    9266          154 :                 warned
    9267          154 :                   = permerror_init (location, OPT_Wincompatible_pointer_types,
    9268              :                                     "initialization of %e from incompatible "
    9269              :                                     "pointer type %e",
    9270              :                                     &e_type, &e_rhstype);
    9271              :               break;
    9272           59 :             case ic_return:
    9273           59 :               if (bltin)
    9274           11 :                 warned
    9275           11 :                   = permerror_opt (location, OPT_Wincompatible_pointer_types,
    9276              :                                    "returning pointer to %qD of type %e from "
    9277              :                                    "a function with incompatible type %e",
    9278              :                                    bltin, &e_rhstype, &e_type);
    9279              :               else
    9280           48 :                 warned
    9281           48 :                   = permerror_opt (location, OPT_Wincompatible_pointer_types,
    9282              :                                    "returning %e from a function with "
    9283              :                                    "incompatible return type %e",
    9284              :                                    &e_rhstype, &e_type);
    9285              :               break;
    9286            0 :             default:
    9287            0 :               gcc_unreachable ();
    9288              :             }
    9289          800 :           if (warned)
    9290              :             {
    9291              :               /* If the mismatching function type is a pointer to a function,
    9292              :                  try to show the decl of the function.  */
    9293          590 :               if (TREE_CODE (rhs) == ADDR_EXPR
    9294          590 :                   && TREE_CODE (TREE_OPERAND (rhs, 0)) == FUNCTION_DECL)
    9295              :                 {
    9296          191 :                   tree rhs_fndecl = TREE_OPERAND (rhs, 0);
    9297          191 :                   if (!DECL_IS_UNDECLARED_BUILTIN (rhs_fndecl))
    9298              :                     {
    9299          165 :                       gcc_rich_location richloc
    9300          165 :                         (DECL_SOURCE_LOCATION (rhs_fndecl), nullptr,
    9301          165 :                          highlight_colors::actual);
    9302          165 :                       pp_element_quoted_decl e_rhs_fndecl
    9303          165 :                         (rhs_fndecl, highlight_colors::actual);
    9304          165 :                       inform (&richloc,
    9305              :                               "%e declared here", &e_rhs_fndecl);
    9306          165 :                     }
    9307              :                 }
    9308              :               /* If either/both of the types are typedefs, show the decl.  */
    9309          590 :               maybe_inform_typedef_location (type,
    9310              :                                              highlight_colors::expected);
    9311          590 :               maybe_inform_typedef_location (rhstype,
    9312              :                                              highlight_colors::actual);
    9313              :             }
    9314          800 :         }
    9315              : 
    9316              :       /* If RHS isn't an address, check pointer or array of packed
    9317              :          struct or union.  */
    9318      2039247 :       warn_for_address_of_packed_member (type, orig_rhs);
    9319              : 
    9320      2039247 :       return convert (type, rhs);
    9321              :     }
    9322        80197 :   else if (codel == POINTER_TYPE && coder == ARRAY_TYPE)
    9323              :     {
    9324              :       /* ??? This should not be an error when inlining calls to
    9325              :          unprototyped functions.  */
    9326            4 :       const char msg[] = "invalid use of non-lvalue array";
    9327            4 :       if (warnopt)
    9328            0 :         warning_at (location, warnopt, msg);
    9329              :       else
    9330            4 :         error_at (location, msg);
    9331            4 :       return error_mark_node;
    9332              :     }
    9333        80193 :   else if (codel == POINTER_TYPE
    9334        78660 :            && (coder == INTEGER_TYPE
    9335        78660 :                || coder == ENUMERAL_TYPE
    9336          628 :                || coder == BOOLEAN_TYPE
    9337          628 :                || coder == NULLPTR_TYPE
    9338           27 :                || coder == BITINT_TYPE))
    9339              :     {
    9340        78647 :       if (null_pointer_constant && c_inhibit_evaluation_warnings == 0
    9341        77649 :           && coder != NULLPTR_TYPE)
    9342        77077 :         warning_at (location, OPT_Wzero_as_null_pointer_constant,
    9343              :                     "zero as null pointer constant");
    9344              :       /* A NULLPTR type is just a nullptr always.  */
    9345        78075 :       if (coder == NULLPTR_TYPE)
    9346          587 :         return omit_one_operand_loc (expr_loc, type, nullptr_node, rhs);
    9347              :       /* An explicit constant 0 or type nullptr_t can convert to a pointer,
    9348              :          or one that results from arithmetic, even including a cast to
    9349              :          integer type.  */
    9350        78060 :       else if (!null_pointer_constant)
    9351          972 :         switch (errtype)
    9352              :           {
    9353          800 :           case ic_argpass:
    9354          800 :             {
    9355          800 :               auto_diagnostic_group d;
    9356          800 :               range_label_for_type_mismatch rhs_label (rhstype, type);
    9357          800 :               gcc_rich_location richloc (expr_loc, &rhs_label,
    9358          800 :                                          highlight_colors::actual);
    9359          800 :               if (permerror_opt (&richloc, OPT_Wint_conversion,
    9360              :                                  "passing argument %d of %qE makes pointer "
    9361              :                                  "from integer without a cast", parmnum, rname))
    9362              :                 {
    9363          439 :                   maybe_emit_indirection_note (expr_loc, rhs, type);
    9364          439 :                   inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
    9365              :                 }
    9366          800 :             }
    9367          800 :             break;
    9368           93 :           case ic_assign:
    9369           93 :             permerror_opt (location, OPT_Wint_conversion,
    9370              :                            "assignment to %qT from %qT makes pointer from "
    9371              :                            "integer without a cast", type, rhstype);
    9372           93 :             break;
    9373           56 :           case ic_init:
    9374           56 :           case ic_init_const:
    9375           56 :             permerror_init (location, OPT_Wint_conversion,
    9376              :                             "initialization of %qT from %qT makes pointer "
    9377              :                             "from integer without a cast", type, rhstype);
    9378           56 :             break;
    9379           23 :           case ic_return:
    9380           23 :             permerror_init (location, OPT_Wint_conversion,
    9381              :                             "returning %qT from a function with return type "
    9382              :                             "%qT makes pointer from integer without a cast",
    9383              :                             rhstype, type);
    9384           23 :             break;
    9385            0 :           default:
    9386            0 :             gcc_unreachable ();
    9387              :           }
    9388              : 
    9389        78060 :       return convert (type, rhs);
    9390              :     }
    9391         1546 :   else if ((codel == INTEGER_TYPE || codel == BITINT_TYPE)
    9392          540 :            && coder == POINTER_TYPE)
    9393              :     {
    9394          514 :       switch (errtype)
    9395              :         {
    9396          344 :         case ic_argpass:
    9397          344 :           {
    9398          344 :             auto_diagnostic_group d;
    9399          344 :             range_label_for_type_mismatch rhs_label (rhstype, type);
    9400          344 :             gcc_rich_location richloc (expr_loc, &rhs_label,
    9401          344 :                                        highlight_colors::actual);
    9402          344 :             if (permerror_opt (&richloc, OPT_Wint_conversion,
    9403              :                                "passing argument %d of %qE makes integer from "
    9404              :                                "pointer without a cast", parmnum, rname))
    9405              :               {
    9406          323 :                 maybe_emit_indirection_note (expr_loc, rhs, type);
    9407          323 :                 inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
    9408              :               }
    9409          344 :           }
    9410          344 :           break;
    9411           52 :         case ic_assign:
    9412           52 :           permerror_opt (location, OPT_Wint_conversion,
    9413              :                          "assignment to %qT from %qT makes integer from "
    9414              :                          "pointer without a cast", type, rhstype);
    9415           52 :           break;
    9416           83 :         case ic_init:
    9417           83 :         case ic_init_const:
    9418           83 :           permerror_init (location, OPT_Wint_conversion,
    9419              :                           "initialization of %qT from %qT makes integer "
    9420              :                           "from pointer without a cast", type, rhstype);
    9421           83 :           break;
    9422           35 :         case ic_return:
    9423           35 :           permerror_opt (location, OPT_Wint_conversion, "returning %qT from a "
    9424              :                          "function with return type %qT makes integer from "
    9425              :                          "pointer without a cast", rhstype, type);
    9426           35 :           break;
    9427            0 :         default:
    9428            0 :           gcc_unreachable ();
    9429              :         }
    9430              : 
    9431          514 :       return convert (type, rhs);
    9432              :     }
    9433          626 :   else if (C_BOOLEAN_TYPE_P (type)
    9434              :            /* The type nullptr_t may be converted to bool.  The
    9435              :               result is false.  */
    9436         1034 :            && (coder == POINTER_TYPE || coder == NULLPTR_TYPE))
    9437              :     {
    9438          408 :       tree ret;
    9439          408 :       bool save = in_late_binary_op;
    9440          408 :       in_late_binary_op = true;
    9441          408 :       ret = convert (type, rhs);
    9442          408 :       in_late_binary_op = save;
    9443          408 :       return ret;
    9444              :     }
    9445          624 :   else if (codel == NULLPTR_TYPE && null_pointer_constant)
    9446            6 :     return convert (type, rhs);
    9447              : 
    9448          618 :   switch (errtype)
    9449              :     {
    9450           35 :     case ic_argpass:
    9451           35 :       {
    9452           35 :         auto_diagnostic_group d;
    9453           35 :         range_label_for_type_mismatch rhs_label (rhstype, type);
    9454           35 :         gcc_rich_location richloc (expr_loc, &rhs_label,
    9455           35 :                                    highlight_colors::actual);
    9456           35 :         const char msg[] = G_("incompatible type for argument %d of %qE");
    9457           35 :         if (warnopt)
    9458            8 :           warning_at (expr_loc, warnopt, msg, parmnum, rname);
    9459              :         else
    9460           27 :           error_at (&richloc, msg, parmnum, rname);
    9461           35 :         inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
    9462           35 :       }
    9463           35 :       break;
    9464          108 :     case ic_assign:
    9465          108 :       {
    9466          108 :         const char msg[]
    9467              :           = G_("incompatible types when assigning to type %qT from type %qT");
    9468          108 :         if (warnopt)
    9469            0 :           warning_at (expr_loc, 0, msg, type, rhstype);
    9470              :         else
    9471          108 :           error_at (expr_loc, msg, type, rhstype);
    9472          108 :         break;
    9473              :       }
    9474          460 :     case ic_init:
    9475          460 :     case ic_init_const:
    9476          460 :       {
    9477          460 :         const char msg[]
    9478              :           = G_("incompatible types when initializing type %qT using type %qT");
    9479          460 :         if (warnopt)
    9480            0 :           warning_at (location, 0, msg, type, rhstype);
    9481              :         else
    9482          460 :           error_at (location, msg, type, rhstype);
    9483          460 :         break;
    9484              :       }
    9485           15 :     case ic_return:
    9486           15 :       {
    9487           15 :         const char msg[]
    9488              :           = G_("incompatible types when returning type %qT but %qT was expected");
    9489           15 :         if (warnopt)
    9490            0 :           warning_at (location, 0, msg, rhstype, type);
    9491              :         else
    9492           15 :           error_at (location, msg, rhstype, type);
    9493           15 :         break;
    9494              :       }
    9495            0 :     default:
    9496            0 :       gcc_unreachable ();
    9497              :     }
    9498              : 
    9499          618 :   return error_mark_node;
    9500              : }
    9501              : 
    9502              : /* If VALUE is a compound expr all of whose expressions are constant, then
    9503              :    return its value.  Otherwise, return error_mark_node.
    9504              : 
    9505              :    This is for handling COMPOUND_EXPRs as initializer elements
    9506              :    which is allowed with a warning when -pedantic is specified.  */
    9507              : 
    9508              : static tree
    9509            2 : valid_compound_expr_initializer (tree value, tree endtype)
    9510              : {
    9511            2 :   if (TREE_CODE (value) == COMPOUND_EXPR)
    9512              :     {
    9513            1 :       if (valid_compound_expr_initializer (TREE_OPERAND (value, 0), endtype)
    9514            1 :           == error_mark_node)
    9515              :         return error_mark_node;
    9516            0 :       return valid_compound_expr_initializer (TREE_OPERAND (value, 1),
    9517            0 :                                               endtype);
    9518              :     }
    9519            1 :   else if (!initializer_constant_valid_p (value, endtype))
    9520            1 :     return error_mark_node;
    9521              :   else
    9522              :     return value;
    9523              : }
    9524              : 
    9525              : /* Perform appropriate conversions on the initial value of a variable,
    9526              :    store it in the declaration DECL,
    9527              :    and print any error messages that are appropriate.
    9528              :    If ORIGTYPE is not NULL_TREE, it is the original type of INIT.
    9529              :    If the init is invalid, store an ERROR_MARK.
    9530              : 
    9531              :    INIT_LOC is the location of the initial value.  */
    9532              : 
    9533              : void
    9534      7352593 : store_init_value (location_t init_loc, tree decl, tree init, tree origtype)
    9535              : {
    9536      7352593 :   tree value, type;
    9537      7352593 :   bool npc = false;
    9538      7352593 :   bool int_const_expr = false;
    9539      7352593 :   bool arith_const_expr = false;
    9540              : 
    9541              :   /* If variable's type was invalidly declared, just ignore it.  */
    9542              : 
    9543      7352593 :   type = TREE_TYPE (decl);
    9544      7352593 :   if (TREE_CODE (type) == ERROR_MARK)
    9545              :     return;
    9546              : 
    9547              :   /* Digest the specified initializer into an expression.  */
    9548              : 
    9549      7352585 :   if (init)
    9550              :     {
    9551      7352582 :       npc = null_pointer_constant_p (init);
    9552      7352582 :       int_const_expr = (TREE_CODE (init) == INTEGER_CST
    9553       427494 :                         && !TREE_OVERFLOW (init)
    9554      7780040 :                         && INTEGRAL_TYPE_P (TREE_TYPE (init)));
    9555              :       /* Not fully determined before folding.  */
    9556              :       arith_const_expr = true;
    9557              :     }
    9558      7352585 :   bool constexpr_p = (VAR_P (decl)
    9559      7352585 :                       && C_DECL_DECLARED_CONSTEXPR (decl));
    9560      7352585 :   value = digest_init (init_loc, decl, type, init, origtype, npc,
    9561              :                        int_const_expr, arith_const_expr, true,
    9562      7352585 :                        TREE_STATIC (decl) || constexpr_p, constexpr_p);
    9563              : 
    9564              :   /* Store the expression if valid; else report error.  */
    9565              : 
    9566      7352585 :   if (!in_system_header_at (input_location)
    9567      7352585 :       && AGGREGATE_TYPE_P (TREE_TYPE (decl)) && !TREE_STATIC (decl))
    9568        29495 :     warning (OPT_Wtraditional, "traditional C rejects automatic "
    9569              :              "aggregate initialization");
    9570              : 
    9571      7352585 :   if (value != error_mark_node || TREE_CODE (decl) != FUNCTION_DECL)
    9572      7352584 :     DECL_INITIAL (decl) = value;
    9573              : 
    9574              :   /* ANSI wants warnings about out-of-range constant initializers.  */
    9575      7352596 :   STRIP_TYPE_NOPS (value);
    9576      7352585 :   if (TREE_STATIC (decl))
    9577       182381 :     constant_expression_warning (value);
    9578              : 
    9579              :   /* Check if we need to set array size from compound literal size.  */
    9580      7352585 :   if (TREE_CODE (type) == ARRAY_TYPE
    9581        27763 :       && TYPE_DOMAIN (type) == NULL_TREE
    9582      7365727 :       && value != error_mark_node)
    9583              :     {
    9584              :       tree inside_init = init;
    9585              : 
    9586        12270 :       STRIP_TYPE_NOPS (inside_init);
    9587        12270 :       inside_init = fold (inside_init);
    9588              : 
    9589        12270 :       if (TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
    9590              :         {
    9591           13 :           tree cldecl = COMPOUND_LITERAL_EXPR_DECL (inside_init);
    9592              : 
    9593           13 :           if (TYPE_DOMAIN (TREE_TYPE (cldecl)))
    9594              :             {
    9595              :               /* For int foo[] = (int [3]){1}; we need to set array size
    9596              :                  now since later on array initializer will be just the
    9597              :                  brace enclosed list of the compound literal.  */
    9598           13 :               tree etype = strip_array_types (TREE_TYPE (decl));
    9599           13 :               type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
    9600           13 :               TYPE_DOMAIN (type) = TYPE_DOMAIN (TREE_TYPE (cldecl));
    9601           13 :               layout_type (type);
    9602           13 :               layout_decl (cldecl, 0);
    9603           13 :               TREE_TYPE (decl)
    9604           26 :                 = c_build_qualified_type (type, TYPE_QUALS (etype));
    9605              :             }
    9606              :         }
    9607              :     }
    9608              : }
    9609              : 
    9610              : /* Methods for storing and printing names for error messages.  */
    9611              : 
    9612              : /* Implement a spelling stack that allows components of a name to be pushed
    9613              :    and popped.  Each element on the stack is this structure.  */
    9614              : 
    9615              : struct spelling
    9616              : {
    9617              :   int kind;
    9618              :   union
    9619              :     {
    9620              :       unsigned HOST_WIDE_INT i;
    9621              :       const char *s;
    9622              :     } u;
    9623              : };
    9624              : 
    9625              : #define SPELLING_STRING 1
    9626              : #define SPELLING_MEMBER 2
    9627              : #define SPELLING_BOUNDS 3
    9628              : 
    9629              : static struct spelling *spelling;       /* Next stack element (unused).  */
    9630              : static struct spelling *spelling_base;  /* Spelling stack base.  */
    9631              : static int spelling_size;               /* Size of the spelling stack.  */
    9632              : 
    9633              : /* Macros to save and restore the spelling stack around push_... functions.
    9634              :    Alternative to SAVE_SPELLING_STACK.  */
    9635              : 
    9636              : #define SPELLING_DEPTH() (spelling - spelling_base)
    9637              : #define RESTORE_SPELLING_DEPTH(DEPTH) (spelling = spelling_base + (DEPTH))
    9638              : 
    9639              : /* Push an element on the spelling stack with type KIND and assign VALUE
    9640              :    to MEMBER.  */
    9641              : 
    9642              : #define PUSH_SPELLING(KIND, VALUE, MEMBER)                              \
    9643              : {                                                                       \
    9644              :   int depth = SPELLING_DEPTH ();                                        \
    9645              :                                                                         \
    9646              :   if (depth >= spelling_size)                                                \
    9647              :     {                                                                   \
    9648              :       spelling_size += 10;                                              \
    9649              :       spelling_base = XRESIZEVEC (struct spelling, spelling_base,       \
    9650              :                                   spelling_size);                       \
    9651              :       RESTORE_SPELLING_DEPTH (depth);                                   \
    9652              :     }                                                                   \
    9653              :                                                                         \
    9654              :   spelling->kind = (KIND);                                           \
    9655              :   spelling->MEMBER = (VALUE);                                                \
    9656              :   spelling++;                                                           \
    9657              : }
    9658              : 
    9659              : /* Push STRING on the stack.  Printed literally.  */
    9660              : 
    9661              : static void
    9662      7349787 : push_string (const char *string)
    9663              : {
    9664      7349787 :   PUSH_SPELLING (SPELLING_STRING, string, u.s);
    9665      7349787 : }
    9666              : 
    9667              : /* Push a member name on the stack.  Printed as '.' STRING.  */
    9668              : 
    9669              : static void
    9670      1232868 : push_member_name (tree decl)
    9671              : {
    9672      1232868 :   const char *const string
    9673      1232868 :     = (DECL_NAME (decl)
    9674      1232868 :        ? identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl)))
    9675          210 :        : _("<anonymous>"));
    9676      1232868 :   PUSH_SPELLING (SPELLING_MEMBER, string, u.s);
    9677      1232868 : }
    9678              : 
    9679              : /* Push an array bounds on the stack.  Printed as [BOUNDS].  */
    9680              : 
    9681              : static void
    9682      2616253 : push_array_bounds (unsigned HOST_WIDE_INT bounds)
    9683              : {
    9684      2616253 :   PUSH_SPELLING (SPELLING_BOUNDS, bounds, u.i);
    9685      2616253 : }
    9686              : 
    9687              : /* Compute the maximum size in bytes of the printed spelling.  */
    9688              : 
    9689              : static int
    9690         2892 : spelling_length (void)
    9691              : {
    9692         2892 :   int size = 0;
    9693         2892 :   struct spelling *p;
    9694              : 
    9695         6416 :   for (p = spelling_base; p < spelling; p++)
    9696              :     {
    9697         3524 :       if (p->kind == SPELLING_BOUNDS)
    9698         1479 :         size += 25;
    9699              :       else
    9700         2045 :         size += strlen (p->u.s) + 1;
    9701              :     }
    9702              : 
    9703         2892 :   return size;
    9704              : }
    9705              : 
    9706              : /* Print the spelling to BUFFER and return it.  */
    9707              : 
    9708              : static char *
    9709         2892 : print_spelling (char *buffer)
    9710              : {
    9711         2892 :   char *d = buffer;
    9712         2892 :   struct spelling *p;
    9713              : 
    9714         6416 :   for (p = spelling_base; p < spelling; p++)
    9715         3524 :     if (p->kind == SPELLING_BOUNDS)
    9716              :       {
    9717         1479 :         sprintf (d, "[" HOST_WIDE_INT_PRINT_UNSIGNED "]", p->u.i);
    9718         1479 :         d += strlen (d);
    9719              :       }
    9720              :     else
    9721              :       {
    9722         2045 :         const char *s;
    9723         2045 :         if (p->kind == SPELLING_MEMBER)
    9724          198 :           *d++ = '.';
    9725        16715 :         for (s = p->u.s; (*d = *s++); d++)
    9726              :           ;
    9727              :       }
    9728         2892 :   *d++ = '\0';
    9729         2892 :   return buffer;
    9730              : }
    9731              : 
    9732              : /* Check whether INIT, a floating or integer constant, is
    9733              :    representable in TYPE, a real floating type with the same radix or
    9734              :    a decimal floating type initialized with a binary floating
    9735              :    constant.  Return true if OK, false if not.  */
    9736              : static bool
    9737          362 : constexpr_init_fits_real_type (tree type, tree init)
    9738              : {
    9739          362 :   gcc_assert (SCALAR_FLOAT_TYPE_P (type));
    9740          362 :   gcc_assert (TREE_CODE (init) == INTEGER_CST || TREE_CODE (init) == REAL_CST);
    9741          362 :   if (TREE_CODE (init) == REAL_CST
    9742          362 :       && TYPE_MODE (TREE_TYPE (init)) == TYPE_MODE (type))
    9743              :     {
    9744              :       /* Same mode, no conversion required except for the case of
    9745              :          signaling NaNs if the types are incompatible (e.g. double and
    9746              :          long double with the same mode).  */
    9747          177 :       if (REAL_VALUE_ISSIGNALING_NAN (TREE_REAL_CST (init))
    9748          195 :           && !comptypes (TYPE_MAIN_VARIANT (type),
    9749           18 :                          TYPE_MAIN_VARIANT (TREE_TYPE (init))))
    9750            0 :         return false;
    9751              :       return true;
    9752              :     }
    9753          185 :   if (TREE_CODE (init) == INTEGER_CST)
    9754              :     {
    9755           54 :       tree converted = build_real_from_int_cst (type, init);
    9756           54 :       bool fail = false;
    9757          108 :       wide_int w = real_to_integer (&TREE_REAL_CST (converted), &fail,
    9758           54 :                                     TYPE_PRECISION (TREE_TYPE (init)));
    9759           68 :       return !fail && wi::eq_p (w, wi::to_wide (init));
    9760           54 :     }
    9761          131 :   if (REAL_VALUE_ISSIGNALING_NAN (TREE_REAL_CST (init)))
    9762              :     return false;
    9763          114 :   if ((REAL_VALUE_ISINF (TREE_REAL_CST (init))
    9764           34 :        && MODE_HAS_INFINITIES (TYPE_MODE (type)))
    9765          218 :       || (REAL_VALUE_ISNAN (TREE_REAL_CST (init))
    9766           44 :           && MODE_HAS_NANS (TYPE_MODE (type))))
    9767              :     return true;
    9768           94 :   if (DECIMAL_FLOAT_TYPE_P (type)
    9769          134 :       && !DECIMAL_FLOAT_TYPE_P (TREE_TYPE (init)))
    9770              :     {
    9771              :       /* This is valid if the real number represented by the
    9772              :          initializer can be exactly represented in the decimal
    9773              :          type.  Compare the values using MPFR.  */
    9774            8 :       REAL_VALUE_TYPE t;
    9775            8 :       real_convert (&t, TYPE_MODE (type), &TREE_REAL_CST (init));
    9776            8 :       mpfr_t bin_val, dec_val;
    9777            8 :       mpfr_init2 (bin_val, REAL_MODE_FORMAT (TYPE_MODE (TREE_TYPE (init)))->p);
    9778            8 :       mpfr_init2 (dec_val, REAL_MODE_FORMAT (TYPE_MODE (TREE_TYPE (init)))->p);
    9779            8 :       mpfr_from_real (bin_val, &TREE_REAL_CST (init), MPFR_RNDN);
    9780            8 :       char string[256];
    9781            8 :       real_to_decimal (string, &t, sizeof string, 0, 1);
    9782            8 :       bool res = (mpfr_strtofr (dec_val, string, NULL, 10, MPFR_RNDN) == 0
    9783            8 :                   && mpfr_equal_p (bin_val, dec_val));
    9784            8 :       mpfr_clear (bin_val);
    9785            8 :       mpfr_clear (dec_val);
    9786            8 :       return res;
    9787              :     }
    9788              :   /* exact_real_truncate is not quite right here, since it doesn't
    9789              :      allow even an exact conversion to subnormal values.  */
    9790           86 :   REAL_VALUE_TYPE t;
    9791           86 :   real_convert (&t, TYPE_MODE (type), &TREE_REAL_CST (init));
    9792           86 :   return real_identical (&t, &TREE_REAL_CST (init));
    9793              : }
    9794              : 
    9795              : /* Check whether INIT (location LOC) is valid as a 'constexpr'
    9796              :    initializer for type TYPE, and give an error if not.  INIT has
    9797              :    already been folded and verified to be constant.  INT_CONST_EXPR
    9798              :    and ARITH_CONST_EXPR say whether it is an integer constant
    9799              :    expression or arithmetic constant expression, respectively.  If
    9800              :    TYPE is not a scalar type, this function does nothing.  */
    9801              : 
    9802              : static void
    9803          942 : check_constexpr_init (location_t loc, tree type, tree init,
    9804              :                       bool int_const_expr, bool arith_const_expr)
    9805              : {
    9806          942 :   if (POINTER_TYPE_P (type))
    9807              :     {
    9808              :       /* The initializer must be null.  */
    9809           86 :       if (TREE_CODE (init) != INTEGER_CST || !integer_zerop (init))
    9810            8 :         error_at (loc, "%<constexpr%> pointer initializer is not null");
    9811              :       return;
    9812              :     }
    9813          856 :   if (INTEGRAL_TYPE_P (type))
    9814              :     {
    9815              :       /* The initializer must be an integer constant expression,
    9816              :          representable in the target type.  */
    9817          346 :       if (!int_const_expr)
    9818              :         {
    9819           13 :           if (TREE_CODE (init) == RAW_DATA_CST
    9820           13 :               && TYPE_PRECISION (type) == CHAR_BIT)
    9821              :             {
    9822            4 :               if (!TYPE_UNSIGNED (type))
    9823          137 :                 for (unsigned int i = 0;
    9824          140 :                      i < (unsigned) RAW_DATA_LENGTH (init); ++i)
    9825          138 :                   if (RAW_DATA_SCHAR_ELT (init, i) < 0)
    9826              :                     {
    9827            1 :                       error_at (loc, "%<constexpr%> initializer not "
    9828              :                                 "representable in type of object");
    9829            1 :                       break;
    9830              :                     }
    9831              :             }
    9832              :           else
    9833            9 :             error_at (loc, "%<constexpr%> integer initializer is not an "
    9834              :                       "integer constant expression");
    9835              :         }
    9836          333 :       else if (!int_fits_type_p (init, type))
    9837            6 :         error_at (loc, "%<constexpr%> initializer not representable in "
    9838              :                   "type of object");
    9839              :       return;
    9840              :     }
    9841              :   /* We don't apply any extra checks to extension types such as vector
    9842              :      or fixed-point types.  */
    9843          510 :   if (TREE_CODE (type) != REAL_TYPE && TREE_CODE (type) != COMPLEX_TYPE)
    9844              :     return;
    9845          353 :   if (!arith_const_expr)
    9846              :     {
    9847            5 :       error_at (loc, "%<constexpr%> initializer is not an arithmetic "
    9848              :                 "constant expression");
    9849            5 :       return;
    9850              :     }
    9851              :   /* We don't apply any extra checks to complex integers.  */
    9852          348 :   if (TREE_CODE (type) == COMPLEX_TYPE
    9853          348 :       && TREE_CODE (TREE_TYPE (type)) != REAL_TYPE)
    9854              :     return;
    9855              :   /* Following N3082, a real type cannot be initialized from a complex
    9856              :      type and a binary type cannot be initialized from a decimal type
    9857              :      (but initializing a decimal type from a binary type is OK).
    9858              :      Signaling NaN initializers are OK only if the types are
    9859              :      compatible (not just the same mode); all quiet NaN and infinity
    9860              :      initializations are considered to preserve the value.  */
    9861          348 :   if (TREE_CODE (TREE_TYPE (init)) == COMPLEX_TYPE
    9862          348 :       && SCALAR_FLOAT_TYPE_P (type))
    9863              :     {
    9864            6 :       error_at (loc, "%<constexpr%> initializer for a real type is of "
    9865              :                 "complex type");
    9866            6 :       return;
    9867              :     }
    9868          342 :   if (SCALAR_FLOAT_TYPE_P (type)
    9869          300 :       && SCALAR_FLOAT_TYPE_P (TREE_TYPE (init))
    9870          250 :       && DECIMAL_FLOAT_TYPE_P (TREE_TYPE (init))
    9871          481 :       && !DECIMAL_FLOAT_TYPE_P (type))
    9872              :     {
    9873            6 :       error_at (loc, "%<constexpr%> initializer for a binary "
    9874              :                 "floating-point type is of decimal type");
    9875            6 :       return;
    9876              :     }
    9877          336 :   bool fits;
    9878          336 :   if (TREE_CODE (type) == COMPLEX_TYPE)
    9879              :     {
    9880           42 :       switch (TREE_CODE (init))
    9881              :         {
    9882           10 :         case INTEGER_CST:
    9883           10 :         case REAL_CST:
    9884           10 :           fits = constexpr_init_fits_real_type (TREE_TYPE (type), init);
    9885           10 :           break;
    9886           32 :         case COMPLEX_CST:
    9887           32 :           fits = (constexpr_init_fits_real_type (TREE_TYPE (type),
    9888           32 :                                                  TREE_REALPART (init))
    9889           58 :                   && constexpr_init_fits_real_type (TREE_TYPE (type),
    9890           26 :                                                     TREE_IMAGPART (init)));
    9891              :           break;
    9892            0 :         default:
    9893            0 :           gcc_unreachable ();
    9894              :         }
    9895              :     }
    9896              :   else
    9897          294 :     fits = constexpr_init_fits_real_type (type, init);
    9898          304 :   if (!fits)
    9899           65 :     error_at (loc, "%<constexpr%> initializer not representable in "
    9900              :               "type of object");
    9901              : }
    9902              : 
    9903              : /* Digest the parser output INIT as an initializer for type TYPE
    9904              :    initializing DECL.
    9905              :    Return a C expression of type TYPE to represent the initial value.
    9906              : 
    9907              :    If ORIGTYPE is not NULL_TREE, it is the original type of INIT.
    9908              : 
    9909              :    NULL_POINTER_CONSTANT is true if INIT is a null pointer constant,
    9910              :    INT_CONST_EXPR is true if INIT is an integer constant expression,
    9911              :    and ARITH_CONST_EXPR is true if INIT is, or might be, an arithmetic
    9912              :    constant expression, false if it has already been determined in the
    9913              :    caller that it is not (but folding may have made the value passed here
    9914              :    indistinguishable from an arithmetic constant expression).
    9915              : 
    9916              :    If INIT is a string constant, STRICT_STRING is true if it is
    9917              :    unparenthesized or we should not warn here for it being parenthesized.
    9918              :    For other types of INIT, STRICT_STRING is not used.
    9919              : 
    9920              :    INIT_LOC is the location of the INIT.
    9921              : 
    9922              :    REQUIRE_CONSTANT requests an error if non-constant initializers or
    9923              :    elements are seen.  REQUIRE_CONSTEXPR means the stricter requirements
    9924              :    on initializers for 'constexpr' objects apply.  */
    9925              : 
    9926              : static tree
    9927     17066735 : digest_init (location_t init_loc, tree decl, tree type, tree init,
    9928              :              tree origtype, bool null_pointer_constant, bool int_const_expr,
    9929              :              bool arith_const_expr, bool strict_string,
    9930              :              bool require_constant, bool require_constexpr)
    9931              : {
    9932     17066735 :   enum tree_code code = TREE_CODE (type);
    9933     17066735 :   tree inside_init = init;
    9934     17066735 :   tree semantic_type = NULL_TREE;
    9935     17066735 :   bool maybe_const = true;
    9936              : 
    9937     17066735 :   if (type == error_mark_node
    9938     17066735 :       || !init
    9939     34133467 :       || error_operand_p (init))
    9940              :     return error_mark_node;
    9941              : 
    9942     17074212 :   STRIP_TYPE_NOPS (inside_init);
    9943              : 
    9944              :   /* If require_constant is TRUE,  when the initializer is a call to
    9945              :      .ACCESS_WITH_SIZE, use the first argument as the initializer.
    9946              :      For example:
    9947              :      y = (char *) .ACCESS_WITH_SIZE ((char *) &static_annotated.c,...)
    9948              :      will be converted to
    9949              :      y = &static_annotated.c.  */
    9950              : 
    9951     17065596 :   if (require_constant
    9952      2907612 :       && TREE_CODE (inside_init) == NOP_EXPR
    9953       736267 :       && TREE_CODE (TREE_OPERAND (inside_init, 0)) == CALL_EXPR
    9954     17065598 :       && is_access_with_size_p (TREE_OPERAND (inside_init, 0)))
    9955            2 :     inside_init
    9956            2 :       = get_ref_from_access_with_size (TREE_OPERAND (inside_init, 0));
    9957              : 
    9958     17065596 :   if (!c_in_omp_for)
    9959              :     {
    9960     17060803 :       if (TREE_CODE (inside_init) == EXCESS_PRECISION_EXPR)
    9961              :         {
    9962          443 :           semantic_type = TREE_TYPE (inside_init);
    9963          443 :           inside_init = TREE_OPERAND (inside_init, 0);
    9964              :         }
    9965     17060803 :       inside_init = c_fully_fold (inside_init, require_constant, &maybe_const);
    9966              :     }
    9967              :   /* TODO: this may not detect all cases of expressions folding to
    9968              :      constants that are not arithmetic constant expressions.  */
    9969     17065596 :   if (!maybe_const)
    9970              :     arith_const_expr = false;
    9971     25464659 :   else if (!INTEGRAL_TYPE_P (TREE_TYPE (inside_init))
    9972      5699230 :            && TREE_CODE (TREE_TYPE (inside_init)) != REAL_TYPE
    9973     16983614 :            && TREE_CODE (TREE_TYPE (inside_init)) != COMPLEX_TYPE)
    9974              :     arith_const_expr = false;
    9975      8509869 :   else if (TREE_CODE (inside_init) != INTEGER_CST
    9976              :            && TREE_CODE (inside_init) != REAL_CST
    9977              :            && TREE_CODE (inside_init) != COMPLEX_CST
    9978              :            && TREE_CODE (inside_init) != RAW_DATA_CST)
    9979              :     arith_const_expr = false;
    9980      5133743 :   else if (TREE_OVERFLOW (inside_init))
    9981     11931897 :     arith_const_expr = false;
    9982              : 
    9983              :   /* Initialization of an array of chars from a string constant
    9984              :      optionally enclosed in braces.  */
    9985              : 
    9986     17065596 :   if (code == ARRAY_TYPE && inside_init
    9987       190811 :       && TREE_CODE (inside_init) == STRING_CST)
    9988              :     {
    9989        11814 :       tree typ1
    9990        11814 :         = (TYPE_ATOMIC (TREE_TYPE (type))
    9991        11814 :            ? c_build_qualified_type (TYPE_MAIN_VARIANT (TREE_TYPE (type)),
    9992              :                                      TYPE_QUAL_ATOMIC)
    9993        11800 :            : TYPE_MAIN_VARIANT (TREE_TYPE (type)));
    9994              :       /* Note that an array could be both an array of character type
    9995              :          and an array of wchar_t if wchar_t is signed char or unsigned
    9996              :          char.  */
    9997        23628 :       bool char_array = (typ1 == char_type_node
    9998          520 :                          || typ1 == signed_char_type_node
    9999        12299 :                          || typ1 == unsigned_char_type_node);
   10000        11814 :       bool wchar_array = comptypes (typ1, wchar_type_node);
   10001        11814 :       bool char16_array = comptypes (typ1, char16_type_node);
   10002        11814 :       bool char32_array = comptypes (typ1, char32_type_node);
   10003              : 
   10004        11814 :       if (char_array || wchar_array || char16_array || char32_array)
   10005              :         {
   10006        11785 :           struct c_expr expr;
   10007        11785 :           tree typ2 = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init)));
   10008        11785 :           bool incompat_string_cst = false;
   10009        11785 :           expr.value = inside_init;
   10010        11785 :           expr.original_code = (strict_string ? STRING_CST : ERROR_MARK);
   10011        11785 :           expr.original_type = NULL;
   10012        11785 :           expr.m_decimal = 0;
   10013        11785 :           maybe_warn_string_init (init_loc, type, expr);
   10014              : 
   10015        11785 :           if (flexible_array_member_type_p (type))
   10016           63 :             pedwarn_init (init_loc, OPT_Wpedantic,
   10017              :                           "initialization of a flexible array member");
   10018              : 
   10019        11785 :           if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
   10020        11785 :                          TYPE_MAIN_VARIANT (type)))
   10021              :             return inside_init;
   10022              : 
   10023         4190 :           if (char_array)
   10024              :             {
   10025         4079 :               if (typ2 != char_type_node && typ2 != char8_type_node)
   10026              :                 incompat_string_cst = true;
   10027              :             }
   10028          111 :           else if (!comptypes (typ1, typ2))
   10029              :             incompat_string_cst = true;
   10030              : 
   10031              :           if (incompat_string_cst)
   10032              :             {
   10033           72 :               error_init (init_loc, "cannot initialize array of %qT from "
   10034              :                           "a string literal with type array of %qT",
   10035              :                           typ1, typ2);
   10036           72 :               return error_mark_node;
   10037              :             }
   10038              : 
   10039         4118 :           if (require_constexpr
   10040         4118 :               && TYPE_UNSIGNED (typ1) != TYPE_UNSIGNED (typ2))
   10041              :             {
   10042              :               /* Check if all characters of the string can be
   10043              :                  represented in the type of the constexpr object being
   10044              :                  initialized.  */
   10045           24 :               unsigned HOST_WIDE_INT len = TREE_STRING_LENGTH (inside_init);
   10046           24 :               const unsigned char *p =
   10047           24 :                 (const unsigned char *) TREE_STRING_POINTER (inside_init);
   10048           24 :               gcc_assert (CHAR_TYPE_SIZE == 8 && CHAR_BIT == 8);
   10049           70 :               for (unsigned i = 0; i < len; i++)
   10050           58 :                 if (p[i] > 127)
   10051              :                   {
   10052           12 :                     error_init (init_loc, "%<constexpr%> initializer not "
   10053              :                                 "representable in type of object");
   10054           12 :                     break;
   10055              :                   }
   10056              :             }
   10057              : 
   10058         4118 :           if (TYPE_DOMAIN (type) != NULL_TREE
   10059         4022 :               && TYPE_SIZE (type) != NULL_TREE
   10060         8079 :               && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
   10061              :             {
   10062         3961 :               unsigned HOST_WIDE_INT len = TREE_STRING_LENGTH (inside_init);
   10063              : 
   10064         3961 :               if (compare_tree_int (TYPE_SIZE_UNIT (type), len) < 0)
   10065              :                 {
   10066          397 :                   unsigned HOST_WIDE_INT avail
   10067          397 :                     = tree_to_uhwi (TYPE_SIZE_UNIT (type));
   10068          397 :                   unsigned unit = TYPE_PRECISION (typ1) / BITS_PER_UNIT;
   10069          397 :                   const char *p = TREE_STRING_POINTER (inside_init);
   10070              : 
   10071              :                   /* Construct truncated string.  */
   10072          397 :                   inside_init = build_string (avail, p);
   10073              : 
   10074              :                   /* Subtract the size of a single (possibly wide) character
   10075              :                      because it may be ok to ignore the terminating NUL char
   10076              :                      that is counted in the length of the constant.  */
   10077          397 :                   if (len - unit > avail)
   10078           63 :                     pedwarn_init (init_loc, 0,
   10079              :                                   "initializer-string for array of %qT "
   10080              :                                   "is too long (%wu chars into %wu "
   10081              :                                   "available)", typ1, len, avail);
   10082          334 :                   else if (warn_cxx_compat)
   10083            9 :                     warning_at (init_loc, OPT_Wc___compat,
   10084              :                                 "initializer-string for array of %qT "
   10085              :                                 "is too long for C++ (%wu chars into %wu "
   10086              :                                 "available)", typ1, len, avail);
   10087          325 :                   else if (warn_unterminated_string_initialization
   10088          325 :                            && get_attr_nonstring_decl (decl) == NULL_TREE)
   10089           22 :                     warning_at (init_loc,
   10090           22 :                                 OPT_Wunterminated_string_initialization,
   10091              :                                 "initializer-string for array of %qT "
   10092              :                                 "truncates NUL terminator but destination "
   10093              :                                 "lacks %qs attribute (%wu chars into %wu "
   10094              :                                 "available)", typ1, "nonstring", len, avail);
   10095              :                 }
   10096              :             }
   10097              : 
   10098         4118 :           TREE_TYPE (inside_init) = type;
   10099         4118 :           return inside_init;
   10100              :         }
   10101           29 :       else if (INTEGRAL_TYPE_P (typ1))
   10102              :         {
   10103           29 :           error_init (init_loc, "array of inappropriate type initialized "
   10104              :                       "from string constant");
   10105           29 :           return error_mark_node;
   10106              :         }
   10107              :     }
   10108              : 
   10109              :   /* Build a VECTOR_CST from a *constant* vector constructor.  If the
   10110              :      vector constructor is not constant (e.g. {1,2,3,foo()}) then punt
   10111              :      below and handle as a constructor.  */
   10112     17053782 :   if (code == VECTOR_TYPE
   10113      6374212 :       && VECTOR_TYPE_P (TREE_TYPE (inside_init))
   10114      6374210 :       && vector_types_convertible_p (TREE_TYPE (inside_init), type, true)
   10115     23427954 :       && TREE_CONSTANT (inside_init))
   10116              :     {
   10117       639439 :       if (TREE_CODE (inside_init) == VECTOR_CST
   10118       639536 :           && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
   10119           97 :                         TYPE_MAIN_VARIANT (type)))
   10120              :         return inside_init;
   10121              : 
   10122       639342 :       if (TREE_CODE (inside_init) == CONSTRUCTOR)
   10123              :         {
   10124              :           unsigned HOST_WIDE_INT ix;
   10125              :           tree value;
   10126      4213066 :           bool constant_p = true;
   10127              : 
   10128              :           /* Iterate through elements and check if all constructor
   10129              :              elements are *_CSTs.  */
   10130      4213066 :           FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (inside_init), ix, value)
   10131      3573781 :             if (!CONSTANT_CLASS_P (value))
   10132              :               {
   10133              :                 constant_p = false;
   10134              :                 break;
   10135              :               }
   10136              : 
   10137       639342 :           if (constant_p)
   10138       639285 :             return build_vector_from_ctor (type,
   10139       639285 :                                            CONSTRUCTOR_ELTS (inside_init));
   10140              :         }
   10141              :     }
   10142              : 
   10143     16414400 :   if (warn_sequence_point)
   10144      2452320 :     verify_sequence_points (inside_init);
   10145              : 
   10146              :   /* Any type can be initialized
   10147              :      from an expression of the same type, optionally with braces.  */
   10148              : 
   10149     16414400 :   if (inside_init && TREE_TYPE (inside_init) != NULL_TREE
   10150     32828800 :       && (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
   10151     16414400 :                      TYPE_MAIN_VARIANT (type))
   10152      3167005 :           || (code == ARRAY_TYPE
   10153          477 :               && comptypes (TREE_TYPE (inside_init), type))
   10154      3167005 :           || (gnu_vector_type_p (type)
   10155          193 :               && comptypes (TREE_TYPE (inside_init), type))
   10156      3167005 :           || (code == POINTER_TYPE
   10157       112934 :               && TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE
   10158         9302 :               && comptypes (TREE_TYPE (TREE_TYPE (inside_init)),
   10159         9302 :                             TREE_TYPE (type)))))
   10160              :     {
   10161     13249373 :       if (code == POINTER_TYPE)
   10162              :         {
   10163       785944 :           if (TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE)
   10164              :             {
   10165         1978 :               if (TREE_CODE (inside_init) == STRING_CST
   10166           68 :                   || TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
   10167         1975 :                 inside_init = array_to_pointer_conversion
   10168         1975 :                   (init_loc, inside_init);
   10169              :               else
   10170              :                 {
   10171            3 :                   error_init (init_loc, "invalid use of non-lvalue array");
   10172            3 :                   return error_mark_node;
   10173              :                 }
   10174              :             }
   10175              :         }
   10176              : 
   10177     13249370 :       if (code == VECTOR_TYPE || c_hardbool_type_attr (type))
   10178              :         /* Although the types are compatible, we may require a
   10179              :            conversion.  */
   10180      5734770 :         inside_init = convert (type, inside_init);
   10181              : 
   10182     13249370 :       if ((code == RECORD_TYPE || code == UNION_TYPE)
   10183     13249370 :           && !comptypes (TYPE_MAIN_VARIANT (type), TYPE_MAIN_VARIANT (TREE_TYPE (inside_init))))
   10184              :         {
   10185            0 :           error_init (init_loc, "invalid initializer");
   10186            0 :           return error_mark_node;
   10187              :         }
   10188              : 
   10189     13249370 :       if (require_constant
   10190      2307244 :           && TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
   10191              :         {
   10192              :           /* As an extension, allow initializing objects with static storage
   10193              :              duration with compound literals (which are then treated just as
   10194              :              the brace enclosed list they contain).  Also allow this for
   10195              :              vectors, as we can only assign them with compound literals.  */
   10196           31 :           if (flag_isoc99 && code != VECTOR_TYPE)
   10197            8 :             pedwarn_init (init_loc, OPT_Wpedantic, "initializer element "
   10198              :                           "is not constant");
   10199           31 :           tree decl = COMPOUND_LITERAL_EXPR_DECL (inside_init);
   10200           31 :           inside_init = DECL_INITIAL (decl);
   10201              :         }
   10202              : 
   10203     13249370 :       if (code == ARRAY_TYPE && TREE_CODE (inside_init) != STRING_CST
   10204       178520 :           && TREE_CODE (inside_init) != CONSTRUCTOR)
   10205              :         {
   10206            2 :           error_init (init_loc, "array initialized from non-constant array "
   10207              :                       "expression");
   10208            2 :           return error_mark_node;
   10209              :         }
   10210              : 
   10211              :       /* Compound expressions can only occur here if -Wpedantic or
   10212              :          -pedantic-errors is specified.  In the later case, we always want
   10213              :          an error.  In the former case, we simply want a warning.  */
   10214     13249368 :       if (require_constant && pedantic
   10215        20365 :           && TREE_CODE (inside_init) == COMPOUND_EXPR)
   10216              :         {
   10217            1 :           inside_init
   10218            1 :             = valid_compound_expr_initializer (inside_init,
   10219            1 :                                                TREE_TYPE (inside_init));
   10220            1 :           if (inside_init == error_mark_node)
   10221            1 :             error_init (init_loc, "initializer element is not constant");
   10222              :           else
   10223            0 :             pedwarn_init (init_loc, OPT_Wpedantic,
   10224              :                           "initializer element is not constant");
   10225            1 :           if (flag_pedantic_errors)
   10226            0 :             inside_init = error_mark_node;
   10227              :         }
   10228      2307243 :       else if (require_constant
   10229      2307243 :                && !initializer_constant_valid_p (inside_init,
   10230      2307243 :                                                  TREE_TYPE (inside_init)))
   10231              :         {
   10232           94 :           error_init (init_loc, "initializer element is not constant");
   10233           94 :           inside_init = error_mark_node;
   10234              :         }
   10235     13249273 :       else if (require_constant && !maybe_const)
   10236          219 :         pedwarn_init (init_loc, OPT_Wpedantic,
   10237              :                       "initializer element is not a constant expression");
   10238     13249054 :       else if (require_constexpr)
   10239          610 :         check_constexpr_init (init_loc, type, inside_init,
   10240              :                               int_const_expr, arith_const_expr);
   10241              : 
   10242              :       /* Added to enable additional -Wsuggest-attribute=format warnings.  */
   10243     13249368 :       if (TREE_CODE (TREE_TYPE (inside_init)) == POINTER_TYPE)
   10244       855955 :         inside_init = convert_for_assignment (init_loc, UNKNOWN_LOCATION,
   10245              :                                               type, inside_init, origtype,
   10246              :                                               (require_constant
   10247              :                                                ? ic_init_const
   10248              :                                                : ic_init), null_pointer_constant,
   10249              :                                               NULL_TREE, NULL_TREE, 0);
   10250     13249368 :       if (TREE_CODE (inside_init) == RAW_DATA_CST
   10251          257 :           && c_inhibit_evaluation_warnings == 0
   10252          257 :           && warn_conversion
   10253            1 :           && !TYPE_UNSIGNED (type)
   10254     13249369 :           && TYPE_PRECISION (type) == CHAR_BIT)
   10255          303 :         for (unsigned int i = 0;
   10256          304 :              i < (unsigned) RAW_DATA_LENGTH (inside_init); ++i)
   10257          303 :           if (RAW_DATA_SCHAR_ELT (inside_init, i) < 0)
   10258           10 :             warning_at (init_loc, OPT_Wconversion,
   10259              :                         "conversion from %qT to %qT changes value from "
   10260              :                         "%qd to %qd",
   10261              :                         integer_type_node, type,
   10262           10 :                         RAW_DATA_UCHAR_ELT (inside_init, i),
   10263           10 :                         RAW_DATA_SCHAR_ELT (inside_init, i));
   10264              :       return inside_init;
   10265              :     }
   10266              : 
   10267              :   /* Handle scalar types, including conversions.  */
   10268              : 
   10269      3165027 :   if (code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE
   10270       130599 :       || code == POINTER_TYPE || code == ENUMERAL_TYPE || code == BOOLEAN_TYPE
   10271        11949 :       || code == COMPLEX_TYPE || code == VECTOR_TYPE || code == NULLPTR_TYPE
   10272         9868 :       || code == BITINT_TYPE)
   10273              :     {
   10274      3164539 :       tree unconverted_init = inside_init;
   10275      3164539 :       if (TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE
   10276      3164539 :           && (TREE_CODE (init) == STRING_CST
   10277            2 :               || TREE_CODE (init) == COMPOUND_LITERAL_EXPR))
   10278         7325 :         inside_init = init = array_to_pointer_conversion (init_loc, init);
   10279      3164539 :       if (semantic_type)
   10280          438 :         inside_init = build1 (EXCESS_PRECISION_EXPR, semantic_type,
   10281              :                               inside_init);
   10282      3164539 :       inside_init
   10283      5743559 :         = convert_for_assignment (init_loc, UNKNOWN_LOCATION, type,
   10284              :                                   inside_init, origtype,
   10285              :                                   require_constant ? ic_init_const : ic_init,
   10286              :                                   null_pointer_constant, NULL_TREE, NULL_TREE,
   10287              :                                   0);
   10288              : 
   10289              :       /* Check to see if we have already given an error message.  */
   10290      3164539 :       if (inside_init == error_mark_node)
   10291              :         ;
   10292      3164079 :       else if (require_constant && !TREE_CONSTANT (inside_init))
   10293              :         {
   10294           36 :           error_init (init_loc, "initializer element is not constant");
   10295           36 :           inside_init = error_mark_node;
   10296              :         }
   10297      3164043 :       else if (require_constant
   10298      3749134 :                && !initializer_constant_valid_p (inside_init,
   10299       585091 :                                                  TREE_TYPE (inside_init)))
   10300              :         {
   10301           10 :           error_init (init_loc, "initializer element is not computable at "
   10302              :                       "load time");
   10303           10 :           inside_init = error_mark_node;
   10304              :         }
   10305      3164033 :       else if (require_constant && !maybe_const)
   10306            5 :         pedwarn_init (init_loc, OPT_Wpedantic,
   10307              :                       "initializer element is not a constant expression");
   10308      3164028 :       else if (require_constexpr)
   10309          332 :         check_constexpr_init (init_loc, type, unconverted_init,
   10310              :                               int_const_expr, arith_const_expr);
   10311              : 
   10312              :       return inside_init;
   10313              :     }
   10314              : 
   10315              :   /* Come here only for records and arrays.  */
   10316              : 
   10317          488 :   if (COMPLETE_TYPE_P (type) && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
   10318              :     {
   10319            0 :       error_init (init_loc,
   10320              :                   "variable-sized object may not be initialized except "
   10321              :                   "with an empty initializer");
   10322            0 :       return error_mark_node;
   10323              :     }
   10324              : 
   10325          488 :   error_init (init_loc, "invalid initializer");
   10326          488 :   return error_mark_node;
   10327              : }
   10328              : 
   10329              : /* Handle initializers that use braces.  */
   10330              : 
   10331              : /* Type of object we are accumulating a constructor for.
   10332              :    This type is always a RECORD_TYPE, UNION_TYPE or ARRAY_TYPE.  */
   10333              : static tree constructor_type;
   10334              : 
   10335              : /* For a RECORD_TYPE or UNION_TYPE, this is the chain of fields
   10336              :    left to fill.  */
   10337              : static tree constructor_fields;
   10338              : 
   10339              : /* For an ARRAY_TYPE, this is the specified index
   10340              :    at which to store the next element we get.  */
   10341              : static tree constructor_index;
   10342              : 
   10343              : /* For an ARRAY_TYPE, this is the maximum index.  */
   10344              : static tree constructor_max_index;
   10345              : 
   10346              : /* For a RECORD_TYPE, this is the first field not yet written out.  */
   10347              : static tree constructor_unfilled_fields;
   10348              : 
   10349              : /* For an ARRAY_TYPE, this is the index of the first element
   10350              :    not yet written out.  */
   10351              : static tree constructor_unfilled_index;
   10352              : 
   10353              : /* In a RECORD_TYPE, the byte index of the next consecutive field.
   10354              :    This is so we can generate gaps between fields, when appropriate.  */
   10355              : static tree constructor_bit_index;
   10356              : 
   10357              : /* If we are saving up the elements rather than allocating them,
   10358              :    this is the list of elements so far (in reverse order,
   10359              :    most recent first).  */
   10360              : static vec<constructor_elt, va_gc> *constructor_elements;
   10361              : 
   10362              : /* 1 if constructor should be incrementally stored into a constructor chain,
   10363              :    0 if all the elements should be kept in AVL tree.  */
   10364              : static int constructor_incremental;
   10365              : 
   10366              : /* 1 if so far this constructor's elements are all compile-time constants.  */
   10367              : static int constructor_constant;
   10368              : 
   10369              : /* 1 if so far this constructor's elements are all valid address constants.  */
   10370              : static int constructor_simple;
   10371              : 
   10372              : /* 1 if this constructor has an element that cannot be part of a
   10373              :    constant expression.  */
   10374              : static int constructor_nonconst;
   10375              : 
   10376              : /* 1 if this constructor is erroneous so far.  */
   10377              : static int constructor_erroneous;
   10378              : 
   10379              : /* 1 if this constructor is the universal zero initializer { 0 }.  */
   10380              : static int constructor_zeroinit;
   10381              : 
   10382              : /* 1 if this constructor should have padding bits zeroed (C23 {}.  */
   10383              : static bool constructor_zero_padding_bits;
   10384              : 
   10385              : /* 1 if this constructor is a braced scalar initializer (further nested levels
   10386              :    of braces are an error).  */
   10387              : static bool constructor_braced_scalar;
   10388              : 
   10389              : /* Structure for managing pending initializer elements, organized as an
   10390              :    AVL tree.  */
   10391              : 
   10392              : struct init_node
   10393              : {
   10394              :   struct init_node *left, *right;
   10395              :   struct init_node *parent;
   10396              :   int balance;
   10397              :   tree purpose;
   10398              :   tree value;
   10399              :   tree origtype;
   10400              : };
   10401              : 
   10402              : /* Tree of pending elements at this constructor level.
   10403              :    These are elements encountered out of order
   10404              :    which belong at places we haven't reached yet in actually
   10405              :    writing the output.
   10406              :    Will never hold tree nodes across GC runs.  */
   10407              : static struct init_node *constructor_pending_elts;
   10408              : 
   10409              : /* The SPELLING_DEPTH of this constructor.  */
   10410              : static int constructor_depth;
   10411              : 
   10412              : /* DECL node for which an initializer is being read.
   10413              :    0 means we are reading a constructor expression
   10414              :    such as (struct foo) {...}.  */
   10415              : static tree constructor_decl;
   10416              : 
   10417              : /* Nonzero if there were any member designators in this initializer.  */
   10418              : static int constructor_designated;
   10419              : 
   10420              : /* Nesting depth of designator list.  */
   10421              : static int designator_depth;
   10422              : 
   10423              : /* Nonzero if there were diagnosed errors in this designator list.  */
   10424              : static int designator_erroneous;
   10425              : 
   10426              : 
   10427              : /* This stack has a level for each implicit or explicit level of
   10428              :    structuring in the initializer, including the outermost one.  It
   10429              :    saves the values of most of the variables above.  */
   10430              : 
   10431              : struct constructor_range_stack;
   10432              : 
   10433              : struct constructor_stack
   10434              : {
   10435              :   struct constructor_stack *next;
   10436              :   tree type;
   10437              :   tree fields;
   10438              :   tree index;
   10439              :   tree max_index;
   10440              :   tree unfilled_index;
   10441              :   tree unfilled_fields;
   10442              :   tree bit_index;
   10443              :   vec<constructor_elt, va_gc> *elements;
   10444              :   struct init_node *pending_elts;
   10445              :   int offset;
   10446              :   int depth;
   10447              :   /* If value nonzero, this value should replace the entire
   10448              :      constructor at this level.  */
   10449              :   struct c_expr replacement_value;
   10450              :   struct constructor_range_stack *range_stack;
   10451              :   char constant;
   10452              :   char simple;
   10453              :   char nonconst;
   10454              :   char implicit;
   10455              :   char erroneous;
   10456              :   char outer;
   10457              :   char incremental;
   10458              :   char designated;
   10459              :   bool zero_padding_bits;
   10460              :   bool braced_scalar;
   10461              :   int designator_depth;
   10462              : };
   10463              : 
   10464              : static struct constructor_stack *constructor_stack;
   10465              : 
   10466              : /* This stack represents designators from some range designator up to
   10467              :    the last designator in the list.  */
   10468              : 
   10469              : struct constructor_range_stack
   10470              : {
   10471              :   struct constructor_range_stack *next, *prev;
   10472              :   struct constructor_stack *stack;
   10473              :   tree range_start;
   10474              :   tree index;
   10475              :   tree range_end;
   10476              :   tree fields;
   10477              : };
   10478              : 
   10479              : static struct constructor_range_stack *constructor_range_stack;
   10480              : 
   10481              : /* This stack records separate initializers that are nested.
   10482              :    Nested initializers can't happen in ANSI C, but GNU C allows them
   10483              :    in cases like { ... (struct foo) { ... } ... }.  */
   10484              : 
   10485              : struct initializer_stack
   10486              : {
   10487              :   struct initializer_stack *next;
   10488              :   tree decl;
   10489              :   struct constructor_stack *constructor_stack;
   10490              :   struct constructor_range_stack *constructor_range_stack;
   10491              :   vec<constructor_elt, va_gc> *elements;
   10492              :   struct spelling *spelling;
   10493              :   struct spelling *spelling_base;
   10494              :   int spelling_size;
   10495              :   char require_constant_value;
   10496              :   char require_constant_elements;
   10497              :   char require_constexpr_value;
   10498              :   char designated;
   10499              :   rich_location *missing_brace_richloc;
   10500              : };
   10501              : 
   10502              : static struct initializer_stack *initializer_stack;
   10503              : 
   10504              : /* Prepare to parse and output the initializer for variable DECL.  */
   10505              : 
   10506              : void
   10507      7349787 : start_init (tree decl, tree asmspec_tree ATTRIBUTE_UNUSED,
   10508              :             bool init_require_constant, bool init_require_constexpr,
   10509              :             rich_location *richloc)
   10510              : {
   10511      7349787 :   const char *locus;
   10512      7349787 :   struct initializer_stack *p = XNEW (struct initializer_stack);
   10513              : 
   10514      7349787 :   p->decl = constructor_decl;
   10515      7349787 :   p->require_constant_value = require_constant_value;
   10516      7349787 :   p->require_constant_elements = require_constant_elements;
   10517      7349787 :   p->require_constexpr_value = require_constexpr_value;
   10518      7349787 :   p->constructor_stack = constructor_stack;
   10519      7349787 :   p->constructor_range_stack = constructor_range_stack;
   10520      7349787 :   p->elements = constructor_elements;
   10521      7349787 :   p->spelling = spelling;
   10522      7349787 :   p->spelling_base = spelling_base;
   10523      7349787 :   p->spelling_size = spelling_size;
   10524      7349787 :   p->next = initializer_stack;
   10525      7349787 :   p->missing_brace_richloc = richloc;
   10526      7349787 :   p->designated = constructor_designated;
   10527      7349787 :   initializer_stack = p;
   10528              : 
   10529      7349787 :   constructor_decl = decl;
   10530      7349787 :   constructor_designated = 0;
   10531              : 
   10532      7349787 :   require_constant_value = init_require_constant;
   10533      7349787 :   require_constexpr_value = init_require_constexpr;
   10534      7349787 :   if (decl != NULL_TREE && decl != error_mark_node)
   10535              :     {
   10536      6418501 :       require_constant_elements
   10537      6239322 :         = ((init_require_constant || (pedantic && !flag_isoc99))
   10538              :            /* For a scalar, you can always use any value to initialize,
   10539              :               even within braces.  */
   10540      6431639 :            && AGGREGATE_TYPE_P (TREE_TYPE (decl)));
   10541      6418501 :       locus = identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl)));
   10542              :     }
   10543              :   else
   10544              :     {
   10545       931286 :       require_constant_elements = false;
   10546       931286 :       locus = _("(anonymous)");
   10547              :     }
   10548              : 
   10549      7349787 :   constructor_stack = 0;
   10550      7349787 :   constructor_range_stack = 0;
   10551              : 
   10552      7349787 :   found_missing_braces = 0;
   10553              : 
   10554      7349787 :   spelling_base = 0;
   10555      7349787 :   spelling_size = 0;
   10556      7349787 :   RESTORE_SPELLING_DEPTH (0);
   10557              : 
   10558      7349787 :   if (locus)
   10559      7349787 :     push_string (locus);
   10560      7349787 : }
   10561              : 
   10562              : void
   10563      7349785 : finish_init (void)
   10564              : {
   10565      7349785 :   struct initializer_stack *p = initializer_stack;
   10566              : 
   10567              :   /* Free the whole constructor stack of this initializer.  */
   10568      7349785 :   while (constructor_stack)
   10569              :     {
   10570            0 :       struct constructor_stack *q = constructor_stack;
   10571            0 :       constructor_stack = q->next;
   10572            0 :       XDELETE (q);
   10573              :     }
   10574              : 
   10575      7349785 :   gcc_assert (!constructor_range_stack);
   10576              : 
   10577              :   /* Pop back to the data of the outer initializer (if any).  */
   10578      7349785 :   XDELETE (spelling_base);
   10579              : 
   10580      7349785 :   constructor_decl = p->decl;
   10581      7349785 :   require_constant_value = p->require_constant_value;
   10582      7349785 :   require_constant_elements = p->require_constant_elements;
   10583      7349785 :   require_constexpr_value = p->require_constexpr_value;
   10584      7349785 :   constructor_stack = p->constructor_stack;
   10585      7349785 :   constructor_designated = p->designated;
   10586      7349785 :   constructor_range_stack = p->constructor_range_stack;
   10587      7349785 :   constructor_elements = p->elements;
   10588      7349785 :   spelling = p->spelling;
   10589      7349785 :   spelling_base = p->spelling_base;
   10590      7349785 :   spelling_size = p->spelling_size;
   10591      7349785 :   initializer_stack = p->next;
   10592      7349785 :   XDELETE (p);
   10593      7349785 : }
   10594              : 
   10595              : /* Call here when we see the initializer is surrounded by braces.
   10596              :    This is instead of a call to push_init_level;
   10597              :    it is matched by a call to pop_init_level.
   10598              : 
   10599              :    TYPE is the type to initialize, for a constructor expression.
   10600              :    For an initializer for a decl, TYPE is zero.  */
   10601              : 
   10602              : void
   10603      1037311 : really_start_incremental_init (tree type)
   10604              : {
   10605      1037311 :   struct constructor_stack *p = XNEW (struct constructor_stack);
   10606              : 
   10607      1037311 :   if (type == NULL_TREE)
   10608       107998 :     type = TREE_TYPE (constructor_decl);
   10609              : 
   10610      1037311 :   if (VECTOR_TYPE_P (type)
   10611      1037311 :       && TYPE_VECTOR_OPAQUE (type))
   10612            0 :     error ("opaque vector types cannot be initialized");
   10613              : 
   10614      1037311 :   p->type = constructor_type;
   10615      1037311 :   p->fields = constructor_fields;
   10616      1037311 :   p->index = constructor_index;
   10617      1037311 :   p->max_index = constructor_max_index;
   10618      1037311 :   p->unfilled_index = constructor_unfilled_index;
   10619      1037311 :   p->unfilled_fields = constructor_unfilled_fields;
   10620      1037311 :   p->bit_index = constructor_bit_index;
   10621      1037311 :   p->elements = constructor_elements;
   10622      1037311 :   p->constant = constructor_constant;
   10623      1037311 :   p->simple = constructor_simple;
   10624      1037311 :   p->nonconst = constructor_nonconst;
   10625      1037311 :   p->erroneous = constructor_erroneous;
   10626      1037311 :   p->pending_elts = constructor_pending_elts;
   10627      1037311 :   p->depth = constructor_depth;
   10628      1037311 :   p->replacement_value.value = 0;
   10629      1037311 :   p->replacement_value.original_code = ERROR_MARK;
   10630      1037311 :   p->replacement_value.original_type = NULL;
   10631      1037311 :   p->implicit = 0;
   10632      1037311 :   p->range_stack = 0;
   10633      1037311 :   p->outer = 0;
   10634      1037311 :   p->incremental = constructor_incremental;
   10635      1037311 :   p->designated = constructor_designated;
   10636      1037311 :   p->zero_padding_bits = constructor_zero_padding_bits;
   10637      1037311 :   p->braced_scalar = constructor_braced_scalar;
   10638      1037311 :   p->designator_depth = designator_depth;
   10639      1037311 :   p->next = 0;
   10640      1037311 :   constructor_stack = p;
   10641              : 
   10642      1037311 :   constructor_constant = 1;
   10643      1037311 :   constructor_simple = 1;
   10644      1037311 :   constructor_nonconst = 0;
   10645      1037311 :   constructor_depth = SPELLING_DEPTH ();
   10646      1037311 :   constructor_elements = NULL;
   10647      1037311 :   constructor_pending_elts = 0;
   10648      1037311 :   constructor_type = type;
   10649      1037311 :   constructor_incremental = 1;
   10650      1037311 :   constructor_designated = 0;
   10651      1037311 :   constructor_zero_padding_bits = false;
   10652      1037311 :   constructor_zeroinit = 1;
   10653      1037311 :   constructor_braced_scalar = false;
   10654      1037311 :   designator_depth = 0;
   10655      1037311 :   designator_erroneous = 0;
   10656              : 
   10657      1037311 :   if (RECORD_OR_UNION_TYPE_P (constructor_type))
   10658              :     {
   10659        82717 :       constructor_fields = TYPE_FIELDS (constructor_type);
   10660              :       /* Skip any nameless bit fields at the beginning.  */
   10661        82717 :       while (constructor_fields != NULL_TREE
   10662        82745 :              && DECL_UNNAMED_BIT_FIELD (constructor_fields))
   10663           28 :         constructor_fields = DECL_CHAIN (constructor_fields);
   10664              : 
   10665        82717 :       constructor_unfilled_fields = constructor_fields;
   10666        82717 :       constructor_bit_index = bitsize_zero_node;
   10667              :     }
   10668       954594 :   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   10669              :     {
   10670        19196 :       if (TYPE_DOMAIN (constructor_type))
   10671              :         {
   10672        10146 :           constructor_max_index
   10673        10146 :             = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
   10674              : 
   10675              :           /* Detect non-empty initializations of zero-length arrays.  */
   10676        10146 :           if (constructor_max_index == NULL_TREE
   10677        10146 :               && TYPE_SIZE (constructor_type))
   10678          207 :             constructor_max_index = integer_minus_one_node;
   10679              : 
   10680              :           /* constructor_max_index needs to be an INTEGER_CST.  Attempts
   10681              :              to initialize VLAs with a nonempty initializer will cause a
   10682              :              proper error; avoid tree checking errors as well by setting a
   10683              :              safe value.  */
   10684        10146 :           if (constructor_max_index
   10685        10146 :               && TREE_CODE (constructor_max_index) != INTEGER_CST)
   10686           73 :             constructor_max_index = integer_minus_one_node;
   10687              : 
   10688        10146 :           constructor_index
   10689        10146 :             = convert (bitsizetype,
   10690        10146 :                        TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
   10691              :         }
   10692              :       else
   10693              :         {
   10694         9050 :           constructor_index = bitsize_zero_node;
   10695         9050 :           constructor_max_index = NULL_TREE;
   10696              :         }
   10697              : 
   10698        19196 :       constructor_unfilled_index = constructor_index;
   10699              :     }
   10700       935398 :   else if (gnu_vector_type_p (constructor_type))
   10701              :     {
   10702              :       /* Vectors are like simple fixed-size arrays.  */
   10703      1869684 :       constructor_max_index =
   10704       934842 :         bitsize_int (TYPE_VECTOR_SUBPARTS (constructor_type) - 1);
   10705       934842 :       constructor_index = bitsize_zero_node;
   10706       934842 :       constructor_unfilled_index = constructor_index;
   10707              :     }
   10708              :   else
   10709              :     {
   10710              :       /* Handle the case of int x = {5}; */
   10711          556 :       constructor_fields = constructor_type;
   10712          556 :       constructor_unfilled_fields = constructor_type;
   10713          556 :       constructor_braced_scalar = true;
   10714              :     }
   10715      1037311 : }
   10716              : 
   10717              : extern location_t last_init_list_comma;
   10718              : 
   10719              : /* Called when we see an open brace for a nested initializer.  Finish
   10720              :    off any pending levels with implicit braces.  */
   10721              : void
   10722       342783 : finish_implicit_inits (location_t loc, struct obstack *braced_init_obstack)
   10723              : {
   10724       342785 :   while (constructor_stack->implicit)
   10725              :     {
   10726         1154 :       if (RECORD_OR_UNION_TYPE_P (constructor_type)
   10727          208 :           && constructor_fields == NULL_TREE)
   10728            0 :         process_init_element (input_location,
   10729              :                               pop_init_level (loc, 1, braced_init_obstack,
   10730              :                                               last_init_list_comma),
   10731              :                               true, braced_init_obstack);
   10732         1154 :       else if (TREE_CODE (constructor_type) == ARRAY_TYPE
   10733          946 :                && constructor_max_index
   10734         2100 :                && tree_int_cst_lt (constructor_max_index,
   10735              :                                    constructor_index))
   10736            2 :         process_init_element (input_location,
   10737              :                               pop_init_level (loc, 1, braced_init_obstack,
   10738              :                                               last_init_list_comma),
   10739              :                               true, braced_init_obstack);
   10740              :       else
   10741              :         break;
   10742              :     }
   10743       342783 : }
   10744              : 
   10745              : /* Push down into a subobject, for initialization.
   10746              :    If this is for an explicit set of braces, IMPLICIT is 0.
   10747              :    If it is because the next element belongs at a lower level,
   10748              :    IMPLICIT is 1 (or 2 if the push is because of designator list).  */
   10749              : 
   10750              : void
   10751      1045463 : push_init_level (location_t loc, int implicit,
   10752              :                  struct obstack *braced_init_obstack)
   10753              : {
   10754      1045463 :   struct constructor_stack *p;
   10755      1045463 :   tree value = NULL_TREE;
   10756              : 
   10757              :   /* Unless this is an explicit brace, we need to preserve previous
   10758              :      content if any.  */
   10759      1045463 :   if (implicit)
   10760              :     {
   10761       705323 :       if (RECORD_OR_UNION_TYPE_P (constructor_type) && constructor_fields)
   10762         1819 :         value = find_init_member (constructor_fields, braced_init_obstack);
   10763       703504 :       else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   10764       703504 :         value = find_init_member (constructor_index, braced_init_obstack);
   10765              :     }
   10766              : 
   10767      1045463 :   p = XNEW (struct constructor_stack);
   10768      1045463 :   p->type = constructor_type;
   10769      1045463 :   p->fields = constructor_fields;
   10770      1045463 :   p->index = constructor_index;
   10771      1045463 :   p->max_index = constructor_max_index;
   10772      1045463 :   p->unfilled_index = constructor_unfilled_index;
   10773      1045463 :   p->unfilled_fields = constructor_unfilled_fields;
   10774      1045463 :   p->bit_index = constructor_bit_index;
   10775      1045463 :   p->elements = constructor_elements;
   10776      1045463 :   p->constant = constructor_constant;
   10777      1045463 :   p->simple = constructor_simple;
   10778      1045463 :   p->nonconst = constructor_nonconst;
   10779      1045463 :   p->erroneous = constructor_erroneous;
   10780      1045463 :   p->pending_elts = constructor_pending_elts;
   10781      1045463 :   p->depth = constructor_depth;
   10782      1045463 :   p->replacement_value.value = NULL_TREE;
   10783      1045463 :   p->replacement_value.original_code = ERROR_MARK;
   10784      1045463 :   p->replacement_value.original_type = NULL;
   10785      1045463 :   p->implicit = implicit;
   10786      1045463 :   p->outer = 0;
   10787      1045463 :   p->incremental = constructor_incremental;
   10788      1045463 :   p->designated = constructor_designated;
   10789      1045463 :   p->zero_padding_bits = constructor_zero_padding_bits;
   10790      1045463 :   p->braced_scalar = constructor_braced_scalar;
   10791      1045463 :   p->designator_depth = designator_depth;
   10792      1045463 :   p->next = constructor_stack;
   10793      1045463 :   p->range_stack = 0;
   10794      1045463 :   constructor_stack = p;
   10795              : 
   10796      1045463 :   constructor_constant = 1;
   10797      1045463 :   constructor_simple = 1;
   10798      1045463 :   constructor_nonconst = 0;
   10799      1045463 :   constructor_depth = SPELLING_DEPTH ();
   10800      1045463 :   constructor_elements = NULL;
   10801      1045463 :   constructor_incremental = 1;
   10802              :   /* If the upper initializer is designated, then mark this as
   10803              :      designated too to prevent bogus warnings.  */
   10804      1045463 :   constructor_designated = p->designated;
   10805              :   /* If the upper initializer has padding bits zeroed, that includes
   10806              :      all nested initializers as well.  */
   10807      1045463 :   constructor_zero_padding_bits = p->zero_padding_bits;
   10808      1045463 :   constructor_braced_scalar = false;
   10809      1045463 :   constructor_pending_elts = 0;
   10810      1045463 :   if (!implicit)
   10811              :     {
   10812       340140 :       p->range_stack = constructor_range_stack;
   10813       340140 :       constructor_range_stack = 0;
   10814       340140 :       designator_depth = 0;
   10815       340140 :       designator_erroneous = 0;
   10816              :     }
   10817              : 
   10818              :   /* Don't die if an entire brace-pair level is superfluous
   10819              :      in the containing level.  */
   10820      1045463 :   if (constructor_type == NULL_TREE)
   10821              :     ;
   10822      1045463 :   else if (RECORD_OR_UNION_TYPE_P (constructor_type))
   10823              :     {
   10824              :       /* Don't die if there are extra init elts at the end.  */
   10825       160173 :       if (constructor_fields == NULL_TREE)
   10826           51 :         constructor_type = NULL_TREE;
   10827              :       else
   10828              :         {
   10829       160122 :           constructor_type = TREE_TYPE (constructor_fields);
   10830       160122 :           push_member_name (constructor_fields);
   10831       160122 :           constructor_depth++;
   10832              :         }
   10833              :     }
   10834       885290 :   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   10835              :     {
   10836       885239 :       constructor_type = TREE_TYPE (constructor_type);
   10837       885239 :       push_array_bounds (tree_to_uhwi (constructor_index));
   10838       885239 :       constructor_depth++;
   10839              :     }
   10840              : 
   10841      1045463 :   if (constructor_type == NULL_TREE)
   10842              :     {
   10843           51 :       error_init (loc, "extra brace group at end of initializer");
   10844           51 :       constructor_fields = NULL_TREE;
   10845           51 :       constructor_unfilled_fields = NULL_TREE;
   10846           51 :       return;
   10847              :     }
   10848              : 
   10849      1045412 :   if (value && TREE_CODE (value) == CONSTRUCTOR)
   10850              :     {
   10851         1686 :       constructor_constant = TREE_CONSTANT (value);
   10852         1686 :       constructor_simple = TREE_STATIC (value);
   10853         1686 :       constructor_nonconst = CONSTRUCTOR_NON_CONST (value);
   10854         1686 :       constructor_elements = CONSTRUCTOR_ELTS (value);
   10855         1686 :       constructor_zero_padding_bits |= CONSTRUCTOR_ZERO_PADDING_BITS (value);
   10856         1686 :       if (!vec_safe_is_empty (constructor_elements)
   10857         1462 :           && (TREE_CODE (constructor_type) == RECORD_TYPE
   10858         1462 :               || TREE_CODE (constructor_type) == ARRAY_TYPE))
   10859         1416 :         set_nonincremental_init (braced_init_obstack);
   10860              :     }
   10861              : 
   10862      1045412 :   if (implicit == 1)
   10863              :     {
   10864       702680 :       found_missing_braces = 1;
   10865       702680 :       if (initializer_stack->missing_brace_richloc)
   10866       702680 :         initializer_stack->missing_brace_richloc->add_fixit_insert_before
   10867       702680 :           (loc, "{");
   10868              :     }
   10869              : 
   10870      1045412 :   if (RECORD_OR_UNION_TYPE_P (constructor_type))
   10871              :     {
   10872       881090 :       constructor_fields = TYPE_FIELDS (constructor_type);
   10873              :       /* Skip any nameless bit fields at the beginning.  */
   10874       881090 :       while (constructor_fields != NULL_TREE
   10875       881154 :              && DECL_UNNAMED_BIT_FIELD (constructor_fields))
   10876           64 :         constructor_fields = DECL_CHAIN (constructor_fields);
   10877              : 
   10878       881090 :       constructor_unfilled_fields = constructor_fields;
   10879       881090 :       constructor_bit_index = bitsize_zero_node;
   10880              :     }
   10881       164322 :   else if (gnu_vector_type_p (constructor_type))
   10882              :     {
   10883              :       /* Vectors are like simple fixed-size arrays.  */
   10884         9622 :       constructor_max_index =
   10885         4811 :         bitsize_int (TYPE_VECTOR_SUBPARTS (constructor_type) - 1);
   10886         4811 :       constructor_index = bitsize_int (0);
   10887         4811 :       constructor_unfilled_index = constructor_index;
   10888              :     }
   10889       159511 :   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   10890              :     {
   10891       159431 :       if (TYPE_DOMAIN (constructor_type))
   10892              :         {
   10893       159431 :           constructor_max_index
   10894       159431 :             = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
   10895              : 
   10896              :           /* Detect non-empty initializations of zero-length arrays.  */
   10897       159431 :           if (constructor_max_index == NULL_TREE
   10898       159431 :               && TYPE_SIZE (constructor_type))
   10899          135 :             constructor_max_index = integer_minus_one_node;
   10900              : 
   10901              :           /* constructor_max_index needs to be an INTEGER_CST.  Attempts
   10902              :              to initialize VLAs will cause a proper error; avoid tree
   10903              :              checking errors as well by setting a safe value.  */
   10904       159431 :           if (constructor_max_index
   10905       159157 :               && TREE_CODE (constructor_max_index) != INTEGER_CST)
   10906            2 :             constructor_max_index = integer_minus_one_node;
   10907              : 
   10908       159431 :           constructor_index
   10909       159431 :             = convert (bitsizetype,
   10910       159431 :                        TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
   10911              :         }
   10912              :       else
   10913            0 :         constructor_index = bitsize_zero_node;
   10914              : 
   10915       159431 :       constructor_unfilled_index = constructor_index;
   10916       159431 :       if (value && TREE_CODE (value) == STRING_CST)
   10917              :         {
   10918              :           /* We need to split the char/wchar array into individual
   10919              :              characters, so that we don't have to special case it
   10920              :              everywhere.  */
   10921            7 :           set_nonincremental_init_from_string (value, braced_init_obstack);
   10922              :         }
   10923              :     }
   10924              :   else
   10925              :     {
   10926           80 :       if (constructor_type != error_mark_node)
   10927              :         {
   10928           51 :           if (p->braced_scalar)
   10929           22 :             permerror_init (input_location, 0,
   10930              :                             "braces around scalar initializer");
   10931              :           else
   10932           29 :             warning_init (input_location, 0,
   10933              :                           "braces around scalar initializer");
   10934           51 :           constructor_braced_scalar = true;
   10935              :         }
   10936           80 :       constructor_fields = constructor_type;
   10937           80 :       constructor_unfilled_fields = constructor_type;
   10938              :     }
   10939              : }
   10940              : 
   10941              : /* At the end of an implicit or explicit brace level,
   10942              :    finish up that level of constructor.  If a single expression
   10943              :    with redundant braces initialized that level, return the
   10944              :    c_expr structure for that expression.  Otherwise, the original_code
   10945              :    element is set to ERROR_MARK.
   10946              :    If we were outputting the elements as they are read, return 0 as the value
   10947              :    from inner levels (process_init_element ignores that),
   10948              :    but return error_mark_node as the value from the outermost level
   10949              :    (that's what we want to put in DECL_INITIAL).
   10950              :    Otherwise, return a CONSTRUCTOR expression as the value.  */
   10951              : 
   10952              : struct c_expr
   10953      2082774 : pop_init_level (location_t loc, int implicit,
   10954              :                 struct obstack *braced_init_obstack,
   10955              :                 location_t insert_before)
   10956              : {
   10957      2082774 :   struct constructor_stack *p;
   10958      2082774 :   struct c_expr ret;
   10959      2082774 :   ret.value = NULL_TREE;
   10960      2082774 :   ret.original_code = ERROR_MARK;
   10961      2082774 :   ret.original_type = NULL;
   10962      2082774 :   ret.m_decimal = 0;
   10963              : 
   10964      2082774 :   if (implicit == 0)
   10965              :     {
   10966              :       /* When we come to an explicit close brace,
   10967              :          pop any inner levels that didn't have explicit braces.  */
   10968      1378793 :       while (constructor_stack->implicit)
   10969         1342 :         process_init_element (input_location,
   10970              :                               pop_init_level (loc, 1, braced_init_obstack,
   10971              :                                               insert_before),
   10972              :                               true, braced_init_obstack);
   10973      1377451 :       gcc_assert (!constructor_range_stack);
   10974              :     }
   10975              :   else
   10976       705323 :     if (initializer_stack->missing_brace_richloc)
   10977       705323 :       initializer_stack->missing_brace_richloc->add_fixit_insert_before
   10978       705323 :         (insert_before, "}");
   10979              : 
   10980              :   /* Now output all pending elements.  */
   10981      2082774 :   constructor_incremental = 1;
   10982      2082774 :   output_pending_init_elements (1, braced_init_obstack);
   10983              : 
   10984      2082774 :   p = constructor_stack;
   10985              : 
   10986              :   /* Error for initializing a flexible array member.  */
   10987      2082723 :   if (constructor_type && constructor_fields
   10988      2243922 :       && flexible_array_member_type_p (constructor_type))
   10989              :     {
   10990              :       /* Silently discard empty initializations.  The parser will
   10991              :          already have pedwarned for empty brackets for C17 and earlier.  */
   10992          274 :       if (integer_zerop (constructor_unfilled_index))
   10993           54 :         constructor_type = NULL_TREE;
   10994          274 :       if (constructor_type || flag_isoc23)
   10995              :         {
   10996          270 :           gcc_assert (!constructor_type || !TYPE_SIZE (constructor_type));
   10997              : 
   10998          270 :           if (constructor_depth <= 2)
   10999          223 :             pedwarn_init (loc, OPT_Wpedantic,
   11000              :                           "initialization of a flexible array member");
   11001           47 :           else if (constructor_type)
   11002           33 :             error_init (loc, "initialization of flexible array member "
   11003              :                              "in a nested context");
   11004              :           else
   11005           14 :             pedwarn_init (loc, OPT_Wpedantic,
   11006              :                           "initialization of flexible array member "
   11007              :                           "in a nested context");
   11008              : 
   11009              :           /* We have already issued an error message for the existence
   11010              :              of a flexible array member not at the end of the structure.
   11011              :              Discard the initializer so that we do not die later.  */
   11012          270 :           if (constructor_type
   11013          220 :               && DECL_CHAIN (constructor_fields) != NULL_TREE
   11014          276 :               && (!p->type || TREE_CODE (p->type) != UNION_TYPE))
   11015            0 :             constructor_type = NULL_TREE;
   11016              :         }
   11017              :     }
   11018              : 
   11019      2082774 :   switch (vec_safe_length (constructor_elements))
   11020              :     {
   11021         5135 :     case 0:
   11022              :       /* Initialization with { } counts as zeroinit.  */
   11023         5135 :       constructor_zeroinit = 1;
   11024         5135 :       break;
   11025       916804 :     case 1:
   11026              :       /* This might be zeroinit as well.  */
   11027       916804 :       if (integer_zerop ((*constructor_elements)[0].value))
   11028         2196 :         constructor_zeroinit = 1;
   11029              :       break;
   11030      1160835 :     default:
   11031              :       /* If the constructor has more than one element, it can't be { 0 }.  */
   11032      1160835 :       constructor_zeroinit = 0;
   11033      1160835 :       break;
   11034              :     }
   11035              : 
   11036              :   /* Warn when some structs are initialized with direct aggregation.  */
   11037      2082774 :   if (!implicit && found_missing_braces && warn_missing_braces
   11038           37 :       && !constructor_zeroinit)
   11039              :     {
   11040           18 :       gcc_assert (initializer_stack->missing_brace_richloc);
   11041           18 :       warning_at (initializer_stack->missing_brace_richloc,
   11042           18 :                   OPT_Wmissing_braces,
   11043              :                   "missing braces around initializer");
   11044              :     }
   11045              : 
   11046              :   /* Warn when some struct elements are implicitly initialized to zero.  */
   11047      2082774 :   if (warn_missing_field_initializers
   11048       425477 :       && constructor_type
   11049       425463 :       && TREE_CODE (constructor_type) == RECORD_TYPE
   11050       193409 :       && constructor_unfilled_fields)
   11051              :     {
   11052              :         /* Do not warn for flexible array members or zero-length arrays.  */
   11053           43 :         while (constructor_unfilled_fields
   11054           43 :                && (!DECL_SIZE (constructor_unfilled_fields)
   11055           43 :                    || integer_zerop (DECL_SIZE (constructor_unfilled_fields))))
   11056            0 :           constructor_unfilled_fields = DECL_CHAIN (constructor_unfilled_fields);
   11057              : 
   11058           43 :         if (constructor_unfilled_fields
   11059              :             /* Do not warn if this level of the initializer uses member
   11060              :                designators; it is likely to be deliberate.  */
   11061           43 :             && !constructor_designated
   11062              :             /* Do not warn about initializing with { 0 } or with { }.  */
   11063           24 :             && !constructor_zeroinit)
   11064              :           {
   11065           10 :             if (warning_at (input_location, OPT_Wmissing_field_initializers,
   11066              :                             "missing initializer for field %qD of %qT",
   11067              :                             constructor_unfilled_fields,
   11068              :                             constructor_type))
   11069           10 :               inform (DECL_SOURCE_LOCATION (constructor_unfilled_fields),
   11070              :                       "%qD declared here", constructor_unfilled_fields);
   11071              :           }
   11072              :     }
   11073              : 
   11074              :   /* Pad out the end of the structure.  */
   11075      2082774 :   if (p->replacement_value.value)
   11076              :     /* If this closes a superfluous brace pair,
   11077              :        just pass out the element between them.  */
   11078          138 :     ret = p->replacement_value;
   11079      2082636 :   else if (constructor_type == NULL_TREE)
   11080              :     ;
   11081      2082539 :   else if (!RECORD_OR_UNION_TYPE_P (constructor_type)
   11082      2082539 :            && TREE_CODE (constructor_type) != ARRAY_TYPE
   11083      2082539 :            && !gnu_vector_type_p (constructor_type))
   11084              :     {
   11085              :       /* A nonincremental scalar initializer--just return
   11086              :          the element, after verifying there is just one.
   11087              :          Empty scalar initializers are supported in C23.  */
   11088          636 :       if (vec_safe_is_empty (constructor_elements))
   11089              :         {
   11090          201 :           if (constructor_erroneous || constructor_type == error_mark_node)
   11091           85 :             ret.value = error_mark_node;
   11092          116 :           else if (TREE_CODE (constructor_type) == FUNCTION_TYPE)
   11093              :             {
   11094            2 :               error_init (loc, "invalid initializer");
   11095            2 :               ret.value = error_mark_node;
   11096              :             }
   11097          114 :           else if (TREE_CODE (constructor_type) == POINTER_TYPE)
   11098              :             /* Ensure this is a null pointer constant in the case of a
   11099              :                'constexpr' object initialized with {}.  */
   11100           33 :             ret.value = build_zero_cst (ptr_type_node);
   11101              :           else
   11102           81 :             ret.value = build_zero_cst (constructor_type);
   11103              :         }
   11104          435 :       else if (vec_safe_length (constructor_elements) != 1)
   11105              :         {
   11106            0 :           error_init (loc, "extra elements in scalar initializer");
   11107            0 :           ret.value = (*constructor_elements)[0].value;
   11108              :         }
   11109              :       else
   11110          435 :         ret.value = (*constructor_elements)[0].value;
   11111              :     }
   11112              :   else
   11113              :     {
   11114      2081903 :       if (constructor_erroneous)
   11115          318 :         ret.value = error_mark_node;
   11116              :       else
   11117              :         {
   11118      2081585 :           ret.value = build_constructor (constructor_type,
   11119              :                                          constructor_elements);
   11120      2081585 :           if (constructor_constant)
   11121      1747682 :             TREE_CONSTANT (ret.value) = 1;
   11122      2081585 :           if (constructor_constant && constructor_simple)
   11123      1747643 :             TREE_STATIC (ret.value) = 1;
   11124      2081585 :           if (constructor_nonconst)
   11125          673 :             CONSTRUCTOR_NON_CONST (ret.value) = 1;
   11126      2081585 :           if (constructor_zero_padding_bits)
   11127          687 :             CONSTRUCTOR_ZERO_PADDING_BITS (ret.value) = 1;
   11128              :         }
   11129              :     }
   11130              : 
   11131      2082774 :   if (ret.value && TREE_CODE (ret.value) != CONSTRUCTOR)
   11132              :     {
   11133         1092 :       if (constructor_nonconst)
   11134           15 :         ret.original_code = C_MAYBE_CONST_EXPR;
   11135         1077 :       else if (ret.original_code == C_MAYBE_CONST_EXPR)
   11136            0 :         ret.original_code = ERROR_MARK;
   11137              :     }
   11138              : 
   11139      2082774 :   constructor_type = p->type;
   11140      2082774 :   constructor_fields = p->fields;
   11141      2082774 :   constructor_index = p->index;
   11142      2082774 :   constructor_max_index = p->max_index;
   11143      2082774 :   constructor_unfilled_index = p->unfilled_index;
   11144      2082774 :   constructor_unfilled_fields = p->unfilled_fields;
   11145      2082774 :   constructor_bit_index = p->bit_index;
   11146      2082774 :   constructor_elements = p->elements;
   11147      2082774 :   constructor_constant = p->constant;
   11148      2082774 :   constructor_simple = p->simple;
   11149      2082774 :   constructor_nonconst = p->nonconst;
   11150      2082774 :   constructor_erroneous = p->erroneous;
   11151      2082774 :   constructor_incremental = p->incremental;
   11152      2082774 :   constructor_designated = p->designated;
   11153      2082774 :   constructor_zero_padding_bits = p->zero_padding_bits;
   11154      2082774 :   constructor_braced_scalar = p->braced_scalar;
   11155      2082774 :   designator_depth = p->designator_depth;
   11156      2082774 :   constructor_pending_elts = p->pending_elts;
   11157      2082774 :   constructor_depth = p->depth;
   11158      2082774 :   if (!p->implicit)
   11159      1377451 :     constructor_range_stack = p->range_stack;
   11160      2082774 :   RESTORE_SPELLING_DEPTH (constructor_depth);
   11161              : 
   11162      2082774 :   constructor_stack = p->next;
   11163      2082774 :   XDELETE (p);
   11164              : 
   11165      2082774 :   if (ret.value == NULL_TREE && constructor_stack == 0)
   11166            0 :     ret.value = error_mark_node;
   11167      2082774 :   return ret;
   11168              : }
   11169              : 
   11170              : /* Common handling for both array range and field name designators.
   11171              :    ARRAY argument is nonzero for array ranges.  Returns false for success.  */
   11172              : 
   11173              : static bool
   11174        37320 : set_designator (location_t loc, bool array,
   11175              :                 struct obstack *braced_init_obstack)
   11176              : {
   11177        37320 :   tree subtype;
   11178        37320 :   enum tree_code subcode;
   11179              : 
   11180              :   /* Don't die if an entire brace-pair level is superfluous
   11181              :      in the containing level, or for an erroneous type.  */
   11182        37320 :   if (constructor_type == NULL_TREE || constructor_type == error_mark_node)
   11183              :     return true;
   11184              : 
   11185              :   /* If there were errors in this designator list already, bail out
   11186              :      silently.  */
   11187        37311 :   if (designator_erroneous)
   11188              :     return true;
   11189              : 
   11190              :   /* Likewise for an initializer for a variable-size type.  Those are
   11191              :      diagnosed in the parser, except for empty initializer braces.  */
   11192        37311 :   if (COMPLETE_TYPE_P (constructor_type)
   11193        37311 :       && TREE_CODE (TYPE_SIZE (constructor_type)) != INTEGER_CST)
   11194              :     return true;
   11195              : 
   11196        37301 :   if (!designator_depth)
   11197              :     {
   11198        34982 :       gcc_assert (!constructor_range_stack);
   11199              : 
   11200              :       /* Designator list starts at the level of closest explicit
   11201              :          braces.  */
   11202        36657 :       while (constructor_stack->implicit)
   11203         1675 :         process_init_element (input_location,
   11204              :                               pop_init_level (loc, 1, braced_init_obstack,
   11205              :                                               last_init_list_comma),
   11206              :                               true, braced_init_obstack);
   11207        34982 :       constructor_designated = 1;
   11208        34982 :       return false;
   11209              :     }
   11210              : 
   11211         2319 :   switch (TREE_CODE (constructor_type))
   11212              :     {
   11213         1442 :     case  RECORD_TYPE:
   11214         1442 :     case  UNION_TYPE:
   11215         1442 :       subtype = TREE_TYPE (constructor_fields);
   11216         1442 :       if (subtype != error_mark_node)
   11217         1442 :         subtype = TYPE_MAIN_VARIANT (subtype);
   11218              :       break;
   11219          877 :     case ARRAY_TYPE:
   11220          877 :       subtype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
   11221          877 :       break;
   11222            0 :     default:
   11223            0 :       gcc_unreachable ();
   11224              :     }
   11225              : 
   11226         2319 :   subcode = TREE_CODE (subtype);
   11227         2319 :   if (array && subcode != ARRAY_TYPE)
   11228              :     {
   11229            1 :       error_init (loc, "array index in non-array initializer");
   11230            1 :       return true;
   11231              :     }
   11232         2318 :   else if (!array && subcode != RECORD_TYPE && subcode != UNION_TYPE)
   11233              :     {
   11234            0 :       error_init (loc, "field name not in record or union initializer");
   11235            0 :       return true;
   11236              :     }
   11237              : 
   11238         2318 :   constructor_designated = 1;
   11239         2318 :   finish_implicit_inits (loc, braced_init_obstack);
   11240         2318 :   push_init_level (loc, 2, braced_init_obstack);
   11241         2318 :   return false;
   11242              : }
   11243              : 
   11244              : /* If there are range designators in designator list, push a new designator
   11245              :    to constructor_range_stack.  RANGE_END is end of such stack range or
   11246              :    NULL_TREE if there is no range designator at this level.  */
   11247              : 
   11248              : static void
   11249          390 : push_range_stack (tree range_end, struct obstack * braced_init_obstack)
   11250              : {
   11251          390 :   struct constructor_range_stack *p;
   11252              : 
   11253          780 :   p = (struct constructor_range_stack *)
   11254          390 :     obstack_alloc (braced_init_obstack,
   11255              :                    sizeof (struct constructor_range_stack));
   11256          390 :   p->prev = constructor_range_stack;
   11257          390 :   p->next = 0;
   11258          390 :   p->fields = constructor_fields;
   11259          390 :   p->range_start = constructor_index;
   11260          390 :   p->index = constructor_index;
   11261          390 :   p->stack = constructor_stack;
   11262          390 :   p->range_end = range_end;
   11263          390 :   if (constructor_range_stack)
   11264           19 :     constructor_range_stack->next = p;
   11265          390 :   constructor_range_stack = p;
   11266          390 : }
   11267              : 
   11268              : /* Within an array initializer, specify the next index to be initialized.
   11269              :    FIRST is that index.  If LAST is nonzero, then initialize a range
   11270              :    of indices, running from FIRST through LAST.  */
   11271              : 
   11272              : void
   11273         1936 : set_init_index (location_t loc, tree first, tree last,
   11274              :                 struct obstack *braced_init_obstack)
   11275              : {
   11276         1936 :   if (set_designator (loc, true, braced_init_obstack))
   11277              :     return;
   11278              : 
   11279         1933 :   designator_erroneous = 1;
   11280              : 
   11281         3866 :   if (!INTEGRAL_TYPE_P (TREE_TYPE (first))
   11282         3855 :       || (last && !INTEGRAL_TYPE_P (TREE_TYPE (last))))
   11283              :     {
   11284           12 :       error_init (loc, "array index in initializer not of integer type");
   11285           12 :       return;
   11286              :     }
   11287              : 
   11288         1921 :   if (TREE_CODE (first) != INTEGER_CST)
   11289              :     {
   11290            6 :       first = c_fully_fold (first, false, NULL);
   11291            6 :       if (TREE_CODE (first) == INTEGER_CST)
   11292            5 :         pedwarn_init (loc, OPT_Wpedantic,
   11293              :                       "array index in initializer is not "
   11294              :                       "an integer constant expression");
   11295              :     }
   11296              : 
   11297         1921 :   if (last && TREE_CODE (last) != INTEGER_CST)
   11298              :     {
   11299            2 :       last = c_fully_fold (last, false, NULL);
   11300            2 :       if (TREE_CODE (last) == INTEGER_CST)
   11301            1 :         pedwarn_init (loc, OPT_Wpedantic,
   11302              :                       "array index in initializer is not "
   11303              :                       "an integer constant expression");
   11304              :     }
   11305              : 
   11306         1921 :   if (TREE_CODE (first) != INTEGER_CST)
   11307            1 :     error_init (loc, "nonconstant array index in initializer");
   11308         1920 :   else if (last != NULL_TREE && TREE_CODE (last) != INTEGER_CST)
   11309            1 :     error_init (loc, "nonconstant array index in initializer");
   11310         1919 :   else if (TREE_CODE (constructor_type) != ARRAY_TYPE)
   11311            9 :     error_init (loc, "array index in non-array initializer");
   11312         1910 :   else if (tree_int_cst_sgn (first) == -1)
   11313           15 :     error_init (loc, "array index in initializer exceeds array bounds");
   11314         1895 :   else if (constructor_max_index
   11315         1895 :            && tree_int_cst_lt (constructor_max_index, first))
   11316            7 :     error_init (loc, "array index in initializer exceeds array bounds");
   11317              :   else
   11318              :     {
   11319         1888 :       constant_expression_warning (first);
   11320         1888 :       if (last)
   11321          385 :         constant_expression_warning (last);
   11322         1888 :       constructor_index = convert (bitsizetype, first);
   11323         1888 :       if (tree_int_cst_lt (constructor_index, first))
   11324              :         {
   11325            0 :           constructor_index = copy_node (constructor_index);
   11326            0 :           TREE_OVERFLOW (constructor_index) = 1;
   11327              :         }
   11328              : 
   11329         1888 :       if (last)
   11330              :         {
   11331          385 :           if (tree_int_cst_equal (first, last))
   11332              :             last = NULL_TREE;
   11333          384 :           else if (tree_int_cst_lt (last, first))
   11334              :             {
   11335            2 :               error_init (loc, "empty index range in initializer");
   11336            2 :               last = NULL_TREE;
   11337              :             }
   11338              :           else
   11339              :             {
   11340          382 :               last = convert (bitsizetype, last);
   11341          382 :               if (constructor_max_index != NULL_TREE
   11342          382 :                   && tree_int_cst_lt (constructor_max_index, last))
   11343              :                 {
   11344            3 :                   error_init (loc, "array index range in initializer exceeds "
   11345              :                               "array bounds");
   11346            3 :                   last = NULL_TREE;
   11347              :                 }
   11348              :             }
   11349              :         }
   11350              : 
   11351         1888 :       designator_depth++;
   11352         1888 :       designator_erroneous = 0;
   11353         1888 :       if (constructor_range_stack || last)
   11354          379 :         push_range_stack (last, braced_init_obstack);
   11355              :     }
   11356              : }
   11357              : 
   11358              : /* Within a struct initializer, specify the next field to be initialized.  */
   11359              : 
   11360              : void
   11361        35338 : set_init_label (location_t loc, tree fieldname, location_t fieldname_loc,
   11362              :                 struct obstack *braced_init_obstack)
   11363              : {
   11364        35338 :   tree field;
   11365              : 
   11366        35338 :   if (set_designator (loc, false, braced_init_obstack))
   11367              :     return;
   11368              : 
   11369        35321 :   designator_erroneous = 1;
   11370              : 
   11371        35321 :   if (!RECORD_OR_UNION_TYPE_P (constructor_type))
   11372              :     {
   11373            3 :       error_init (loc, "field name not in record or union initializer");
   11374            3 :       return;
   11375              :     }
   11376              : 
   11377        35318 :   field = lookup_field (constructor_type, fieldname);
   11378              : 
   11379        35318 :   if (field == NULL_TREE)
   11380              :     {
   11381            8 :       tree guessed_id = lookup_field_fuzzy (constructor_type, fieldname);
   11382            8 :       if (guessed_id)
   11383              :         {
   11384            4 :           gcc_rich_location rich_loc (fieldname_loc);
   11385            4 :           rich_loc.add_fixit_misspelled_id (fieldname_loc, guessed_id);
   11386            4 :           error_at (&rich_loc,
   11387              :                     "%qT has no member named %qE; did you mean %qE?",
   11388              :                     constructor_type, fieldname, guessed_id);
   11389            4 :         }
   11390              :       else
   11391            4 :         error_at (fieldname_loc, "%qT has no member named %qE",
   11392              :                   constructor_type, fieldname);
   11393              :     }
   11394              :   else
   11395        35356 :     do
   11396              :       {
   11397        35356 :         constructor_fields = TREE_VALUE (field);
   11398        35356 :         designator_depth++;
   11399        35356 :         designator_erroneous = 0;
   11400        35356 :         if (constructor_range_stack)
   11401           11 :           push_range_stack (NULL_TREE, braced_init_obstack);
   11402        35356 :         field = TREE_CHAIN (field);
   11403        35356 :         if (field)
   11404              :           {
   11405           46 :             if (set_designator (loc, false, braced_init_obstack))
   11406              :               return;
   11407              :           }
   11408              :       }
   11409        35356 :     while (field != NULL_TREE);
   11410              : }
   11411              : 
   11412              : /* Helper function for add_pending_init.  Find inorder successor of P
   11413              :    in AVL tree.  */
   11414              : static struct init_node *
   11415          129 : init_node_successor (struct init_node *p)
   11416              : {
   11417          129 :   struct init_node *r;
   11418          129 :   if (p->right)
   11419              :     {
   11420              :       r = p->right;
   11421           58 :       while (r->left)
   11422              :         r = r->left;
   11423              :       return r;
   11424              :     }
   11425           75 :   r = p->parent;
   11426          114 :   while (r && p == r->right)
   11427              :     {
   11428           39 :       p = r;
   11429           39 :       r = r->parent;
   11430              :     }
   11431              :   return r;
   11432              : }
   11433              : 
   11434              : /* Add a new initializer to the tree of pending initializers.  PURPOSE
   11435              :    identifies the initializer, either array index or field in a structure.
   11436              :    VALUE is the value of that index or field.  If ORIGTYPE is not
   11437              :    NULL_TREE, it is the original type of VALUE.
   11438              : 
   11439              :    IMPLICIT is true if value comes from pop_init_level (1),
   11440              :    the new initializer has been merged with the existing one
   11441              :    and thus no warnings should be emitted about overriding an
   11442              :    existing initializer.  */
   11443              : 
   11444              : static void
   11445         7989 : add_pending_init (location_t loc, tree purpose, tree value, tree origtype,
   11446              :                   bool implicit, struct obstack *braced_init_obstack)
   11447              : {
   11448         7989 :   struct init_node *p, **q, *r;
   11449              : 
   11450        12538 :   q = &constructor_pending_elts;
   11451         7989 :   p = 0;
   11452              : 
   11453         7989 :   if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   11454              :     {
   11455         7221 :       while (*q != 0)
   11456              :         {
   11457         4386 :           p = *q;
   11458         4386 :           if (tree_int_cst_lt (purpose, p->purpose))
   11459          419 :             q = &p->left;
   11460         3967 :           else if (tree_int_cst_lt (p->purpose, purpose))
   11461              :             {
   11462         3356 :               if (TREE_CODE (p->value) != RAW_DATA_CST
   11463         3356 :                   || (p->right
   11464          112 :                       && tree_int_cst_le (p->right->purpose, purpose)))
   11465         3226 :                 q = &p->right;
   11466              :               else
   11467              :                 {
   11468          130 :                   widest_int pp = wi::to_widest (p->purpose);
   11469          130 :                   widest_int pw = wi::to_widest (purpose);
   11470          130 :                   if (pp + RAW_DATA_LENGTH (p->value) <= pw)
   11471           98 :                     q = &p->right;
   11472              :                   else
   11473              :                     {
   11474              :                       /* Override which should split the old RAW_DATA_CST
   11475              :                          into 2 or 3 pieces.  */
   11476           32 :                       if (!implicit && warn_override_init)
   11477            9 :                         warning_init (loc, OPT_Woverride_init,
   11478              :                                       "initialized field overwritten");
   11479           32 :                       unsigned HOST_WIDE_INT start = (pw - pp).to_uhwi ();
   11480           32 :                       unsigned HOST_WIDE_INT len = 1;
   11481           32 :                       if (TREE_CODE (value) == RAW_DATA_CST)
   11482            0 :                         len = RAW_DATA_LENGTH (value);
   11483           32 :                       unsigned HOST_WIDE_INT end = 0;
   11484           32 :                       unsigned plen = RAW_DATA_LENGTH (p->value);
   11485           32 :                       gcc_checking_assert (start < plen && start);
   11486           32 :                       if (plen - start > len)
   11487           30 :                         end = plen - start - len;
   11488           32 :                       tree v = p->value;
   11489           32 :                       tree origtype = p->origtype;
   11490           32 :                       if (start == 1)
   11491            2 :                         p->value = build_int_cst (TREE_TYPE (v),
   11492            2 :                                                   RAW_DATA_UCHAR_ELT (v, 0));
   11493              :                       else
   11494              :                         {
   11495           30 :                           p->value = v;
   11496           30 :                           if (end > 1)
   11497           26 :                             v = copy_node (v);
   11498           30 :                           RAW_DATA_LENGTH (p->value) = start;
   11499              :                         }
   11500           32 :                       if (end)
   11501              :                         {
   11502           30 :                           tree epurpose
   11503           30 :                             = size_binop (PLUS_EXPR, purpose,
   11504              :                                           bitsize_int (len));
   11505           30 :                           if (end > 1)
   11506              :                             {
   11507           28 :                               RAW_DATA_LENGTH (v) -= plen - end;
   11508           28 :                               RAW_DATA_POINTER (v) += plen - end;
   11509              :                             }
   11510              :                           else
   11511            2 :                             v = build_int_cst (TREE_TYPE (v),
   11512            2 :                                                RAW_DATA_UCHAR_ELT (v, plen
   11513              :                                                                       - end));
   11514           30 :                           add_pending_init (loc, epurpose, v, origtype,
   11515              :                                             implicit, braced_init_obstack);
   11516              :                         }
   11517           32 :                       q = &constructor_pending_elts;
   11518           32 :                       continue;
   11519           32 :                     }
   11520          130 :                 }
   11521              :             }
   11522              :           else
   11523              :             {
   11524          611 :               if (TREE_CODE (p->value) == RAW_DATA_CST
   11525          621 :                   && (RAW_DATA_LENGTH (p->value)
   11526           10 :                       > (TREE_CODE (value) == RAW_DATA_CST
   11527           10 :                          ? RAW_DATA_LENGTH (value) : 1)))
   11528              :                 {
   11529              :                   /* Override which should split the old RAW_DATA_CST
   11530              :                      into 2 pieces.  */
   11531            6 :                   if (!implicit && warn_override_init)
   11532            3 :                     warning_init (loc, OPT_Woverride_init,
   11533              :                                   "initialized field overwritten");
   11534            6 :                   unsigned HOST_WIDE_INT len = 1;
   11535            6 :                   if (TREE_CODE (value) == RAW_DATA_CST)
   11536            2 :                     len = RAW_DATA_LENGTH (value);
   11537            6 :                   if ((unsigned) RAW_DATA_LENGTH (p->value) > len + 1)
   11538              :                     {
   11539            6 :                       RAW_DATA_LENGTH (p->value) -= len;
   11540            6 :                       RAW_DATA_POINTER (p->value) += len;
   11541              :                     }
   11542              :                   else
   11543              :                     {
   11544            0 :                       unsigned int l = RAW_DATA_LENGTH (p->value) - 1;
   11545            0 :                       p->value
   11546            0 :                         = build_int_cst (TREE_TYPE (p->value),
   11547            0 :                                          RAW_DATA_UCHAR_ELT (p->value, l));
   11548              :                     }
   11549            6 :                   p->purpose = size_binop (PLUS_EXPR, p->purpose,
   11550              :                                            bitsize_int (len));
   11551            6 :                   continue;
   11552            6 :                 }
   11553          605 :               if (TREE_CODE (value) == RAW_DATA_CST)
   11554              :                 {
   11555            8 :                 handle_raw_data:
   11556              :                   /* RAW_DATA_CST value might overlap various further
   11557              :                      prior initval entries.  Find out how many.  */
   11558           13 :                   unsigned cnt = 0;
   11559           13 :                   widest_int w
   11560           26 :                     = wi::to_widest (purpose) + RAW_DATA_LENGTH (value);
   11561           13 :                   struct init_node *r = p, *last = NULL;
   11562           13 :                   bool override_init = warn_override_init;
   11563           13 :                   while ((r = init_node_successor (r))
   11564           53 :                          && wi::to_widest (r->purpose) < w)
   11565              :                     {
   11566           40 :                       ++cnt;
   11567           40 :                       if (TREE_SIDE_EFFECTS (r->value))
   11568            2 :                         warning_init (loc, OPT_Woverride_init_side_effects,
   11569              :                                       "initialized field with side-effects "
   11570              :                                       "overwritten");
   11571           38 :                       else if (override_init)
   11572              :                         {
   11573            6 :                           warning_init (loc, OPT_Woverride_init,
   11574              :                                         "initialized field overwritten");
   11575            6 :                           override_init = false;
   11576              :                         }
   11577           40 :                       last = r;
   11578              :                     }
   11579           13 :                   if (cnt)
   11580              :                     {
   11581           26 :                       if (TREE_CODE (last->value) == RAW_DATA_CST
   11582           13 :                           && (wi::to_widest (last->purpose)
   11583           13 :                               + RAW_DATA_LENGTH (last->value) > w))
   11584              :                         {
   11585              :                           /* The last overlapping prior initval overlaps
   11586              :                              only partially.  Shrink it and decrease cnt.  */
   11587            0 :                           unsigned int l = (wi::to_widest (last->purpose)
   11588            0 :                                             + RAW_DATA_LENGTH (last->value)
   11589            0 :                                             - w).to_uhwi ();
   11590            0 :                           --cnt;
   11591            0 :                           RAW_DATA_LENGTH (last->value) -= l;
   11592            0 :                           RAW_DATA_POINTER (last->value) += l;
   11593            0 :                           if (RAW_DATA_LENGTH (last->value) == 1)
   11594            0 :                             last->value
   11595            0 :                               = build_int_cst (TREE_TYPE (last->value),
   11596            0 :                                                RAW_DATA_UCHAR_ELT (last->value,
   11597              :                                                                    0));
   11598            0 :                           last->purpose
   11599            0 :                             = size_binop (PLUS_EXPR, last->purpose,
   11600              :                                           bitsize_int (l));
   11601              :                         }
   11602              :                       /* Instead of deleting cnt nodes from the AVL tree
   11603              :                          and rebalancing, peel of last cnt bytes from the
   11604              :                          RAW_DATA_CST.  Overriding thousands of previously
   11605              :                          initialized array elements with #embed needs to work,
   11606              :                          but doesn't need to be super efficient.  */
   11607           13 :                       gcc_checking_assert ((unsigned) RAW_DATA_LENGTH (value)
   11608              :                                            > cnt);
   11609           13 :                       RAW_DATA_LENGTH (value) -= cnt;
   11610           13 :                       const unsigned char *s
   11611           13 :                         = &RAW_DATA_UCHAR_ELT (value, RAW_DATA_LENGTH (value));
   11612           13 :                       unsigned int o = RAW_DATA_LENGTH (value);
   11613           53 :                       for (r = p; cnt--; ++o, ++s)
   11614              :                         {
   11615           40 :                           r = init_node_successor (r);
   11616           40 :                           r->purpose = size_binop (PLUS_EXPR, purpose,
   11617              :                                                    bitsize_int (o));
   11618           40 :                           r->value = build_int_cst (TREE_TYPE (value), *s);
   11619           40 :                           r->origtype = origtype;
   11620              :                         }
   11621           13 :                       if (RAW_DATA_LENGTH (value) == 1)
   11622            0 :                         value = build_int_cst (TREE_TYPE (value),
   11623            0 :                                                RAW_DATA_UCHAR_ELT (value, 0));
   11624              :                     }
   11625              :                 }
   11626          610 :               if (!implicit)
   11627              :                 {
   11628           54 :                   if (TREE_SIDE_EFFECTS (p->value))
   11629            6 :                     warning_init (loc, OPT_Woverride_init_side_effects,
   11630              :                                   "initialized field with side-effects "
   11631              :                                   "overwritten");
   11632           48 :                   else if (warn_override_init)
   11633           13 :                     warning_init (loc, OPT_Woverride_init,
   11634              :                                   "initialized field overwritten");
   11635              :                 }
   11636          610 :               p->value = value;
   11637          610 :               p->origtype = origtype;
   11638          610 :               return;
   11639              :             }
   11640              :         }
   11641         2835 :       if (TREE_CODE (value) == RAW_DATA_CST && p)
   11642              :         {
   11643           61 :           struct init_node *r;
   11644           61 :           if (q == &p->left)
   11645              :             r = p;
   11646              :           else
   11647           36 :             r = init_node_successor (p);
   11648          131 :           if (r && wi::to_widest (r->purpose) < (wi::to_widest (purpose)
   11649          131 :                                                  + RAW_DATA_LENGTH (value)))
   11650              :             {
   11651              :               /* Overlap with at least one prior initval in the range but
   11652              :                  not at the start.  */
   11653            5 :               p = r;
   11654            5 :               p->purpose = purpose;
   11655            5 :               goto handle_raw_data;
   11656              :             }
   11657              :         }
   11658              :     }
   11659              :   else
   11660              :     {
   11661         4549 :       tree bitpos;
   11662              : 
   11663         4549 :       bitpos = bit_position (purpose);
   11664         8187 :       while (*q != NULL)
   11665              :         {
   11666         4881 :           p = *q;
   11667         4881 :           if (tree_int_cst_lt (bitpos, bit_position (p->purpose)))
   11668           81 :             q = &p->left;
   11669         4800 :           else if (p->purpose != purpose)
   11670         3557 :             q = &p->right;
   11671              :           else
   11672              :             {
   11673         1243 :               if (!implicit)
   11674              :                 {
   11675          101 :                   if (TREE_SIDE_EFFECTS (p->value))
   11676            4 :                     warning_init (loc, OPT_Woverride_init_side_effects,
   11677              :                                   "initialized field with side-effects "
   11678              :                                   "overwritten");
   11679           97 :                   else if (warn_override_init)
   11680            6 :                     warning_init (loc, OPT_Woverride_init,
   11681              :                                   "initialized field overwritten");
   11682              :                 }
   11683         1243 :               p->value = value;
   11684         1243 :               p->origtype = origtype;
   11685         1243 :               return;
   11686              :             }
   11687              :         }
   11688              :     }
   11689              : 
   11690         6136 :   r = (struct init_node *) obstack_alloc (braced_init_obstack,
   11691              :                                           sizeof (struct init_node));
   11692         6136 :   r->purpose = purpose;
   11693         6136 :   r->value = value;
   11694         6136 :   r->origtype = origtype;
   11695              : 
   11696         6136 :   *q = r;
   11697         6136 :   r->parent = p;
   11698         6136 :   r->left = 0;
   11699         6136 :   r->right = 0;
   11700         6136 :   r->balance = 0;
   11701              : 
   11702         9962 :   while (p)
   11703              :     {
   11704         5214 :       struct init_node *s;
   11705              : 
   11706         5214 :       if (r == p->left)
   11707              :         {
   11708          343 :           if (p->balance == 0)
   11709          246 :             p->balance = -1;
   11710           97 :           else if (p->balance < 0)
   11711              :             {
   11712           45 :               if (r->balance < 0)
   11713              :                 {
   11714              :                   /* L rotation.  */
   11715           40 :                   p->left = r->right;
   11716           40 :                   if (p->left)
   11717            2 :                     p->left->parent = p;
   11718           40 :                   r->right = p;
   11719              : 
   11720           40 :                   p->balance = 0;
   11721           40 :                   r->balance = 0;
   11722              : 
   11723           40 :                   s = p->parent;
   11724           40 :                   p->parent = r;
   11725           40 :                   r->parent = s;
   11726           40 :                   if (s)
   11727              :                     {
   11728           31 :                       if (s->left == p)
   11729           10 :                         s->left = r;
   11730              :                       else
   11731           21 :                         s->right = r;
   11732              :                     }
   11733              :                   else
   11734            9 :                     constructor_pending_elts = r;
   11735              :                 }
   11736              :               else
   11737              :                 {
   11738              :                   /* LR rotation.  */
   11739            5 :                   struct init_node *t = r->right;
   11740              : 
   11741            5 :                   r->right = t->left;
   11742            5 :                   if (r->right)
   11743            0 :                     r->right->parent = r;
   11744            5 :                   t->left = r;
   11745              : 
   11746            5 :                   p->left = t->right;
   11747            5 :                   if (p->left)
   11748            0 :                     p->left->parent = p;
   11749            5 :                   t->right = p;
   11750              : 
   11751            5 :                   p->balance = t->balance < 0;
   11752            5 :                   r->balance = -(t->balance > 0);
   11753            5 :                   t->balance = 0;
   11754              : 
   11755            5 :                   s = p->parent;
   11756            5 :                   p->parent = t;
   11757            5 :                   r->parent = t;
   11758            5 :                   t->parent = s;
   11759            5 :                   if (s)
   11760              :                     {
   11761            0 :                       if (s->left == p)
   11762            0 :                         s->left = t;
   11763              :                       else
   11764            0 :                         s->right = t;
   11765              :                     }
   11766              :                   else
   11767            5 :                     constructor_pending_elts = t;
   11768              :                 }
   11769              :               break;
   11770              :             }
   11771              :           else
   11772              :             {
   11773              :               /* p->balance == +1; growth of left side balances the node.  */
   11774           52 :               p->balance = 0;
   11775           52 :               break;
   11776              :             }
   11777              :         }
   11778              :       else /* r == p->right */
   11779              :         {
   11780         4871 :           if (p->balance == 0)
   11781              :             /* Growth propagation from right side.  */
   11782         3580 :             p->balance++;
   11783         1291 :           else if (p->balance > 0)
   11784              :             {
   11785         1228 :               if (r->balance > 0)
   11786              :                 {
   11787              :                   /* R rotation.  */
   11788         1222 :                   p->right = r->left;
   11789         1222 :                   if (p->right)
   11790          193 :                     p->right->parent = p;
   11791         1222 :                   r->left = p;
   11792              : 
   11793         1222 :                   p->balance = 0;
   11794         1222 :                   r->balance = 0;
   11795              : 
   11796         1222 :                   s = p->parent;
   11797         1222 :                   p->parent = r;
   11798         1222 :                   r->parent = s;
   11799         1222 :                   if (s)
   11800              :                     {
   11801          414 :                       if (s->left == p)
   11802            2 :                         s->left = r;
   11803              :                       else
   11804          412 :                         s->right = r;
   11805              :                     }
   11806              :                   else
   11807          808 :                     constructor_pending_elts = r;
   11808              :                 }
   11809              :               else /* r->balance == -1 */
   11810              :                 {
   11811              :                   /* RL rotation */
   11812            6 :                   struct init_node *t = r->left;
   11813              : 
   11814            6 :                   r->left = t->right;
   11815            6 :                   if (r->left)
   11816            2 :                     r->left->parent = r;
   11817            6 :                   t->right = r;
   11818              : 
   11819            6 :                   p->right = t->left;
   11820            6 :                   if (p->right)
   11821            2 :                     p->right->parent = p;
   11822            6 :                   t->left = p;
   11823              : 
   11824            6 :                   r->balance = (t->balance < 0);
   11825            6 :                   p->balance = -(t->balance > 0);
   11826            6 :                   t->balance = 0;
   11827              : 
   11828            6 :                   s = p->parent;
   11829            6 :                   p->parent = t;
   11830            6 :                   r->parent = t;
   11831            6 :                   t->parent = s;
   11832            6 :                   if (s)
   11833              :                     {
   11834            4 :                       if (s->left == p)
   11835            0 :                         s->left = t;
   11836              :                       else
   11837            4 :                         s->right = t;
   11838              :                     }
   11839              :                   else
   11840            2 :                     constructor_pending_elts = t;
   11841              :                 }
   11842              :               break;
   11843              :             }
   11844              :           else
   11845              :             {
   11846              :               /* p->balance == -1; growth of right side balances the node.  */
   11847           63 :               p->balance = 0;
   11848           63 :               break;
   11849              :             }
   11850              :         }
   11851              : 
   11852         3826 :       r = p;
   11853         3826 :       p = p->parent;
   11854              :     }
   11855              : }
   11856              : 
   11857              : /* Build AVL tree from a sorted chain.  */
   11858              : 
   11859              : static void
   11860         1812 : set_nonincremental_init (struct obstack * braced_init_obstack)
   11861              : {
   11862         1812 :   unsigned HOST_WIDE_INT ix;
   11863         1812 :   tree index, value;
   11864              : 
   11865         1812 :   if (TREE_CODE (constructor_type) != RECORD_TYPE
   11866         1812 :       && TREE_CODE (constructor_type) != ARRAY_TYPE)
   11867              :     return;
   11868              : 
   11869         5511 :   FOR_EACH_CONSTRUCTOR_ELT (constructor_elements, ix, index, value)
   11870         3699 :     add_pending_init (input_location, index, value, NULL_TREE, true,
   11871              :                       braced_init_obstack);
   11872         1812 :   constructor_elements = NULL;
   11873         1812 :   if (TREE_CODE (constructor_type) == RECORD_TYPE)
   11874              :     {
   11875          948 :       constructor_unfilled_fields = TYPE_FIELDS (constructor_type);
   11876              :       /* Skip any nameless bit fields at the beginning.  */
   11877          948 :       while (constructor_unfilled_fields != NULL_TREE
   11878          948 :              && DECL_UNNAMED_BIT_FIELD (constructor_unfilled_fields))
   11879            0 :         constructor_unfilled_fields = TREE_CHAIN (constructor_unfilled_fields);
   11880              : 
   11881              :     }
   11882          864 :   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   11883              :     {
   11884          864 :       if (TYPE_DOMAIN (constructor_type))
   11885          806 :         constructor_unfilled_index
   11886          806 :           = convert (bitsizetype,
   11887          806 :                      TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
   11888              :       else
   11889           58 :         constructor_unfilled_index = bitsize_zero_node;
   11890              :     }
   11891         1812 :   constructor_incremental = 0;
   11892              : }
   11893              : 
   11894              : /* Build AVL tree from a string constant.  */
   11895              : 
   11896              : static void
   11897            7 : set_nonincremental_init_from_string (tree str,
   11898              :                                      struct obstack * braced_init_obstack)
   11899              : {
   11900            7 :   tree value, purpose, type;
   11901            7 :   HOST_WIDE_INT val[2];
   11902            7 :   const char *p, *end;
   11903            7 :   int byte, wchar_bytes, charwidth, bitpos;
   11904              : 
   11905            7 :   gcc_assert (TREE_CODE (constructor_type) == ARRAY_TYPE);
   11906              : 
   11907            7 :   wchar_bytes = TYPE_PRECISION (TREE_TYPE (TREE_TYPE (str))) / BITS_PER_UNIT;
   11908            7 :   charwidth = TYPE_PRECISION (char_type_node);
   11909            7 :   gcc_assert ((size_t) wchar_bytes * charwidth
   11910              :               <= ARRAY_SIZE (val) * HOST_BITS_PER_WIDE_INT);
   11911            7 :   type = TREE_TYPE (constructor_type);
   11912            7 :   p = TREE_STRING_POINTER (str);
   11913            7 :   end = p + TREE_STRING_LENGTH (str);
   11914              : 
   11915            7 :   for (purpose = bitsize_zero_node;
   11916              :        p < end
   11917           52 :        && !(constructor_max_index
   11918           20 :             && tree_int_cst_lt (constructor_max_index, purpose));
   11919           25 :        purpose = size_binop (PLUS_EXPR, purpose, bitsize_one_node))
   11920              :     {
   11921           25 :       if (wchar_bytes == 1)
   11922              :         {
   11923            9 :           val[0] = (unsigned char) *p++;
   11924            9 :           val[1] = 0;
   11925              :         }
   11926              :       else
   11927              :         {
   11928           16 :           val[1] = 0;
   11929           16 :           val[0] = 0;
   11930           64 :           for (byte = 0; byte < wchar_bytes; byte++)
   11931              :             {
   11932           48 :               if (BYTES_BIG_ENDIAN)
   11933              :                 bitpos = (wchar_bytes - byte - 1) * charwidth;
   11934              :               else
   11935           48 :                 bitpos = byte * charwidth;
   11936           48 :               val[bitpos / HOST_BITS_PER_WIDE_INT]
   11937           48 :                 |= ((unsigned HOST_WIDE_INT) ((unsigned char) *p++))
   11938           48 :                    << (bitpos % HOST_BITS_PER_WIDE_INT);
   11939              :             }
   11940              :         }
   11941              : 
   11942           25 :       if (!TYPE_UNSIGNED (type))
   11943              :         {
   11944           13 :           bitpos = ((wchar_bytes - 1) * charwidth) + HOST_BITS_PER_CHAR;
   11945           13 :           if (bitpos < HOST_BITS_PER_WIDE_INT)
   11946              :             {
   11947           13 :               if (val[0] & (HOST_WIDE_INT_1 << (bitpos - 1)))
   11948              :                 {
   11949            0 :                   val[0] |= HOST_WIDE_INT_M1U << bitpos;
   11950            0 :                   val[1] = -1;
   11951              :                 }
   11952              :             }
   11953            0 :           else if (bitpos == HOST_BITS_PER_WIDE_INT)
   11954              :             {
   11955            0 :               if (val[0] < 0)
   11956            0 :                 val[1] = -1;
   11957              :             }
   11958            0 :           else if (val[1] & (HOST_WIDE_INT_1
   11959            0 :                              << (bitpos - 1 - HOST_BITS_PER_WIDE_INT)))
   11960            0 :             val[1] |= HOST_WIDE_INT_M1U << (bitpos - HOST_BITS_PER_WIDE_INT);
   11961              :         }
   11962              : 
   11963           25 :       value = wide_int_to_tree (type,
   11964           25 :                                 wide_int::from_array (val, 2,
   11965              :                                                       HOST_BITS_PER_WIDE_INT * 2));
   11966           25 :       add_pending_init (input_location, purpose, value, NULL_TREE, true,
   11967              :                         braced_init_obstack);
   11968              :     }
   11969              : 
   11970            7 :   constructor_incremental = 0;
   11971            7 : }
   11972              : 
   11973              : /* Return value of FIELD in pending initializer or NULL_TREE if the field was
   11974              :    not initialized yet.  */
   11975              : 
   11976              : static tree
   11977       705323 : find_init_member (tree field, struct obstack * braced_init_obstack)
   11978              : {
   11979       705323 :   struct init_node *p;
   11980              : 
   11981       705323 :   if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   11982              :     {
   11983       703504 :       if (constructor_incremental
   11984       703504 :           && tree_int_cst_lt (field, constructor_unfilled_index))
   11985           16 :         set_nonincremental_init (braced_init_obstack);
   11986              : 
   11987       703504 :       p = constructor_pending_elts;
   11988       704103 :       while (p)
   11989              :         {
   11990         1151 :           if (tree_int_cst_lt (field, p->purpose))
   11991           93 :             p = p->left;
   11992         1058 :           else if (tree_int_cst_lt (p->purpose, field))
   11993          506 :             p = p->right;
   11994              :           else
   11995          552 :             return p->value;
   11996              :         }
   11997              :     }
   11998         1819 :   else if (TREE_CODE (constructor_type) == RECORD_TYPE)
   11999              :     {
   12000         1696 :       tree bitpos = bit_position (field);
   12001              : 
   12002         1696 :       if (constructor_incremental
   12003         1696 :           && (!constructor_unfilled_fields
   12004          609 :               || tree_int_cst_lt (bitpos,
   12005          609 :                                   bit_position (constructor_unfilled_fields))))
   12006          289 :         set_nonincremental_init (braced_init_obstack);
   12007              : 
   12008         1696 :       p = constructor_pending_elts;
   12009         2652 :       while (p)
   12010              :         {
   12011         2047 :           if (field == p->purpose)
   12012         1091 :             return p->value;
   12013          956 :           else if (tree_int_cst_lt (bitpos, bit_position (p->purpose)))
   12014            7 :             p = p->left;
   12015              :           else
   12016          949 :             p = p->right;
   12017              :         }
   12018              :     }
   12019          123 :   else if (TREE_CODE (constructor_type) == UNION_TYPE)
   12020              :     {
   12021          123 :       if (!vec_safe_is_empty (constructor_elements)
   12022           50 :           && (constructor_elements->last ().index == field))
   12023           50 :         return constructor_elements->last ().value;
   12024              :     }
   12025              :   return NULL_TREE;
   12026              : }
   12027              : 
   12028              : /* "Output" the next constructor element.
   12029              :    At top level, really output it to assembler code now.
   12030              :    Otherwise, collect it in a list from which we will make a CONSTRUCTOR.
   12031              :    If ORIGTYPE is not NULL_TREE, it is the original type of VALUE.
   12032              :    TYPE is the data type that the containing data type wants here.
   12033              :    FIELD is the field (a FIELD_DECL) or the index that this element fills.
   12034              :    If VALUE is a string constant, STRICT_STRING is true if it is
   12035              :    unparenthesized or we should not warn here for it being parenthesized.
   12036              :    For other types of VALUE, STRICT_STRING is not used.
   12037              : 
   12038              :    PENDING if true means output pending elements that belong
   12039              :    right after this element.  (PENDING is normally true;
   12040              :    it is false while outputting pending elements, to avoid recursion.)
   12041              : 
   12042              :    IMPLICIT is true if value comes from pop_init_level (1),
   12043              :    the new initializer has been merged with the existing one
   12044              :    and thus no warnings should be emitted about overriding an
   12045              :    existing initializer.  */
   12046              : 
   12047              : static void
   12048      9714321 : output_init_element (location_t loc, tree value, tree origtype,
   12049              :                      bool strict_string, tree type, tree field, bool pending,
   12050              :                      bool implicit, struct obstack * braced_init_obstack)
   12051              : {
   12052      9714321 :   tree semantic_type = NULL_TREE;
   12053      9714321 :   bool maybe_const = true;
   12054      9714321 :   bool npc, int_const_expr, arith_const_expr;
   12055              : 
   12056      9714321 :   if (type == error_mark_node || value == error_mark_node)
   12057              :     {
   12058          290 :       constructor_erroneous = 1;
   12059         4629 :       return;
   12060              :     }
   12061      9714031 :   if (TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
   12062       201124 :       && (TREE_CODE (value) == STRING_CST
   12063       159691 :           || TREE_CODE (value) == COMPOUND_LITERAL_EXPR)
   12064        41441 :       && !(TREE_CODE (value) == STRING_CST
   12065        41433 :            && TREE_CODE (type) == ARRAY_TYPE
   12066         3900 :            && INTEGRAL_TYPE_P (TREE_TYPE (type)))
   12067      9751572 :       && !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (value)),
   12068        37541 :                      TYPE_MAIN_VARIANT (type)))
   12069        37541 :     value = array_to_pointer_conversion (input_location, value);
   12070              : 
   12071      9714031 :   if (TREE_CODE (value) == COMPOUND_LITERAL_EXPR
   12072          182 :       && require_constant_value && pending)
   12073              :     {
   12074              :       /* As an extension, allow initializing objects with static storage
   12075              :          duration with compound literals (which are then treated just as
   12076              :          the brace enclosed list they contain).  */
   12077          114 :       if (flag_isoc99)
   12078           24 :         pedwarn_init (loc, OPT_Wpedantic, "initializer element is not "
   12079              :                       "constant");
   12080          114 :       tree decl = COMPOUND_LITERAL_EXPR_DECL (value);
   12081          114 :       value = DECL_INITIAL (decl);
   12082              :     }
   12083              : 
   12084      9714031 :   npc = null_pointer_constant_p (value);
   12085     19428062 :   int_const_expr = (TREE_CODE (value) == INTEGER_CST
   12086      4267402 :                     && !TREE_OVERFLOW (value)
   12087     13981432 :                     && INTEGRAL_TYPE_P (TREE_TYPE (value)));
   12088              :   /* Not fully determined before folding.  */
   12089      9714031 :   arith_const_expr = true;
   12090      9714031 :   if (TREE_CODE (value) == EXCESS_PRECISION_EXPR)
   12091              :     {
   12092           16 :       semantic_type = TREE_TYPE (value);
   12093           16 :       value = TREE_OPERAND (value, 0);
   12094              :     }
   12095      9714031 :   value = c_fully_fold (value, require_constant_value, &maybe_const);
   12096              :   /* TODO: this may not detect all cases of expressions folding to
   12097              :      constants that are not arithmetic constant expressions.  */
   12098      9714031 :   if (!maybe_const)
   12099              :     arith_const_expr = false;
   12100     19425521 :   else if (!INTEGRAL_TYPE_P (TREE_TYPE (value))
   12101      3203853 :            && TREE_CODE (TREE_TYPE (value)) != REAL_TYPE
   12102     11559801 :            && TREE_CODE (TREE_TYPE (value)) != COMPLEX_TYPE)
   12103              :     arith_const_expr = false;
   12104      7881168 :   else if (TREE_CODE (value) != INTEGER_CST
   12105              :            && TREE_CODE (value) != REAL_CST
   12106              :            && TREE_CODE (value) != COMPLEX_CST
   12107              :            && TREE_CODE (value) != RAW_DATA_CST)
   12108              :     arith_const_expr = false;
   12109      4660416 :   else if (TREE_OVERFLOW (value))
   12110      5053616 :     arith_const_expr = false;
   12111              : 
   12112      9714031 :   if (value == error_mark_node)
   12113            0 :     constructor_erroneous = 1;
   12114      9714031 :   else if (!TREE_CONSTANT (value))
   12115      3241354 :     constructor_constant = 0;
   12116      6472677 :   else if (!initializer_constant_valid_p (value,
   12117      6472677 :                                           TREE_TYPE (value),
   12118      6472677 :                                           AGGREGATE_TYPE_P (constructor_type)
   12119      2771907 :                                           && TYPE_REVERSE_STORAGE_ORDER
   12120              :                                              (constructor_type))
   12121      6472677 :            || (RECORD_OR_UNION_TYPE_P (constructor_type)
   12122      1042538 :                && DECL_C_BIT_FIELD (field)
   12123         7978 :                && TREE_CODE (value) != INTEGER_CST))
   12124           77 :     constructor_simple = 0;
   12125      9714031 :   if (!maybe_const)
   12126         1174 :     constructor_nonconst = 1;
   12127              : 
   12128              :   /* Digest the initializer and issue any errors about incompatible
   12129              :      types before issuing errors about non-constant initializers.  */
   12130      9714031 :   tree new_value = value;
   12131      9714031 :   if (semantic_type)
   12132           16 :     new_value = build1 (EXCESS_PRECISION_EXPR, semantic_type, value);
   12133              :   /* In the case of braces around a scalar initializer, the result of
   12134              :      this initializer processing goes through digest_init again at the
   12135              :      outer level.  In the case of a constexpr initializer for a
   12136              :      pointer, avoid converting a null pointer constant to something
   12137              :      that is not a null pointer constant to avoid a spurious error
   12138              :      from that second processing.  */
   12139      9714031 :   if (!require_constexpr_value
   12140          398 :       || !npc
   12141           69 :       || TREE_CODE (constructor_type) != POINTER_TYPE)
   12142      9714020 :     new_value = digest_init (loc,
   12143      9714020 :                              RECORD_OR_UNION_TYPE_P (constructor_type)
   12144      8637929 :                              ? field : constructor_fields
   12145      8637929 :                              ? constructor_fields : constructor_decl,
   12146              :                              type, new_value, origtype, npc,
   12147              :                              int_const_expr, arith_const_expr, strict_string,
   12148              :                              require_constant_value, require_constexpr_value);
   12149      9714031 :   if (new_value == error_mark_node)
   12150              :     {
   12151           76 :       constructor_erroneous = 1;
   12152           76 :       return;
   12153              :     }
   12154      9713955 :   if (require_constant_value || require_constant_elements)
   12155      2726038 :     constant_expression_warning (new_value);
   12156              : 
   12157              :   /* Proceed to check the constness of the original initializer.  */
   12158      9713955 :   if (!initializer_constant_valid_p (value, TREE_TYPE (value)))
   12159              :     {
   12160      3241380 :       if (require_constant_value)
   12161              :         {
   12162            0 :           error_init (loc, "initializer element is not constant");
   12163            0 :           value = error_mark_node;
   12164              :         }
   12165      3241380 :       else if (require_constant_elements)
   12166           21 :         pedwarn (loc, OPT_Wpedantic,
   12167              :                  "initializer element is not computable at load time");
   12168              :     }
   12169      6472575 :   else if (!maybe_const
   12170           54 :            && (require_constant_value || require_constant_elements))
   12171           28 :     pedwarn_init (loc, OPT_Wpedantic,
   12172              :                   "initializer element is not a constant expression");
   12173              :   /* digest_init has already carried out the additional checks
   12174              :      required for 'constexpr' initializers (using the information
   12175              :      passed to it about whether the original initializer was certain
   12176              :      kinds of constant expression), so that check does not need to be
   12177              :      repeated here.  */
   12178              : 
   12179              :   /* Issue -Wc++-compat warnings about initializing a bitfield with
   12180              :      enum type.  */
   12181      9713955 :   if (warn_cxx_compat
   12182         6902 :       && field != NULL_TREE
   12183         6902 :       && TREE_CODE (field) == FIELD_DECL
   12184          466 :       && DECL_BIT_FIELD_TYPE (field) != NULL_TREE
   12185           21 :       && (TYPE_MAIN_VARIANT (DECL_BIT_FIELD_TYPE (field))
   12186           21 :           != TYPE_MAIN_VARIANT (type))
   12187      9713976 :       && TREE_CODE (DECL_BIT_FIELD_TYPE (field)) == ENUMERAL_TYPE)
   12188              :     {
   12189           21 :       tree checktype = origtype != NULL_TREE ? origtype : TREE_TYPE (value);
   12190           21 :       if (checktype != error_mark_node
   12191           21 :           && (TYPE_MAIN_VARIANT (checktype)
   12192           21 :               != TYPE_MAIN_VARIANT (DECL_BIT_FIELD_TYPE (field))))
   12193            9 :         warning_init (loc, OPT_Wc___compat,
   12194              :                       "enum conversion in initialization is invalid in C++");
   12195              :     }
   12196              : 
   12197              :   /* If this field is empty and does not have side effects (and is not at
   12198              :      the end of structure), don't do anything other than checking the
   12199              :      initializer.  */
   12200      9713955 :   if (field
   12201      9713955 :       && (TREE_TYPE (field) == error_mark_node
   12202      9713520 :           || (COMPLETE_TYPE_P (TREE_TYPE (field))
   12203      9713205 :               && integer_zerop (TYPE_SIZE (TREE_TYPE (field)))
   12204           92 :               && !TREE_SIDE_EFFECTS (new_value)
   12205           63 :               && (TREE_CODE (constructor_type) == ARRAY_TYPE
   12206           63 :                   || DECL_CHAIN (field)))))
   12207              :     return;
   12208              : 
   12209              :   /* Finally, set VALUE to the initializer value digested above.  */
   12210      9713927 :   value = new_value;
   12211              : 
   12212              :   /* If this element doesn't come next in sequence,
   12213              :      put it on constructor_pending_elts.  */
   12214      9713927 :   if (TREE_CODE (constructor_type) == ARRAY_TYPE
   12215      9713927 :       && (!constructor_incremental
   12216      1732657 :           || !tree_int_cst_equal (field, constructor_unfilled_index)
   12217      1732218 :           || (TREE_CODE (value) == RAW_DATA_CST
   12218          238 :               && constructor_pending_elts
   12219           66 :               && pending)))
   12220              :     {
   12221         1346 :       if (constructor_incremental
   12222         1346 :           && (tree_int_cst_lt (field, constructor_unfilled_index)
   12223          410 :               || (TREE_CODE (value) == RAW_DATA_CST
   12224           14 :                   && constructor_pending_elts
   12225           14 :                   && pending)))
   12226           48 :         set_nonincremental_init (braced_init_obstack);
   12227              : 
   12228         1346 :       add_pending_init (loc, field, value, origtype, implicit,
   12229              :                         braced_init_obstack);
   12230         1346 :       return;
   12231              :     }
   12232      9712581 :   else if (TREE_CODE (constructor_type) == RECORD_TYPE
   12233      1044434 :            && (!constructor_incremental
   12234      1042768 :                || field != constructor_unfilled_fields))
   12235              :     {
   12236              :       /* We do this for records but not for unions.  In a union,
   12237              :          no matter which field is specified, it can be initialized
   12238              :          right away since it starts at the beginning of the union.  */
   12239         2889 :       if (constructor_incremental)
   12240              :         {
   12241         1223 :           if (!constructor_unfilled_fields)
   12242           39 :             set_nonincremental_init (braced_init_obstack);
   12243              :           else
   12244              :             {
   12245         1184 :               tree bitpos, unfillpos;
   12246              : 
   12247         1184 :               bitpos = bit_position (field);
   12248         1184 :               unfillpos = bit_position (constructor_unfilled_fields);
   12249              : 
   12250         1184 :               if (tree_int_cst_lt (bitpos, unfillpos))
   12251            4 :                 set_nonincremental_init (braced_init_obstack);
   12252              :             }
   12253              :         }
   12254              : 
   12255         2889 :       add_pending_init (loc, field, value, origtype, implicit,
   12256              :                         braced_init_obstack);
   12257         2889 :       return;
   12258              :     }
   12259      9709692 :   else if (TREE_CODE (constructor_type) == UNION_TYPE
   12260      9709692 :            && !vec_safe_is_empty (constructor_elements))
   12261              :     {
   12262           62 :       if (!implicit)
   12263              :         {
   12264           12 :           if (TREE_SIDE_EFFECTS (constructor_elements->last ().value))
   12265            3 :             warning_init (loc, OPT_Woverride_init_side_effects,
   12266              :                           "initialized field with side-effects overwritten");
   12267            9 :           else if (warn_override_init)
   12268            6 :             warning_init (loc, OPT_Woverride_init,
   12269              :                           "initialized field overwritten");
   12270              :         }
   12271              : 
   12272              :       /* We can have just one union field set.  */
   12273           62 :       constructor_elements = NULL;
   12274              :     }
   12275              : 
   12276              :   /* Otherwise, output this element either to
   12277              :      constructor_elements or to the assembler file.  */
   12278              : 
   12279      9709692 :   constructor_elt celt = {field, value};
   12280      9709692 :   vec_safe_push (constructor_elements, celt);
   12281              : 
   12282              :   /* Advance the variable that indicates sequential elements output.  */
   12283      9709692 :   if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   12284              :     {
   12285      1732213 :       tree inc = bitsize_one_node;
   12286      1732213 :       if (value && TREE_CODE (value) == RAW_DATA_CST)
   12287          233 :         inc = bitsize_int (RAW_DATA_LENGTH (value));
   12288      1732213 :       constructor_unfilled_index
   12289      1732213 :         = size_binop_loc (input_location, PLUS_EXPR,
   12290              :                           constructor_unfilled_index, inc);
   12291              :     }
   12292      7977479 :   else if (TREE_CODE (constructor_type) == RECORD_TYPE)
   12293              :     {
   12294      1041545 :       constructor_unfilled_fields
   12295      1041545 :         = DECL_CHAIN (constructor_unfilled_fields);
   12296              : 
   12297              :       /* Skip any nameless bit fields.  */
   12298      1041545 :       while (constructor_unfilled_fields != NULL_TREE
   12299      1041646 :              && DECL_UNNAMED_BIT_FIELD (constructor_unfilled_fields))
   12300          101 :         constructor_unfilled_fields
   12301          101 :           = DECL_CHAIN (constructor_unfilled_fields);
   12302              :     }
   12303      6935934 :   else if (TREE_CODE (constructor_type) == UNION_TYPE)
   12304        31615 :     constructor_unfilled_fields = NULL_TREE;
   12305              : 
   12306              :   /* Now output any pending elements which have become next.  */
   12307      9709692 :   if (pending)
   12308      9703501 :     output_pending_init_elements (0, braced_init_obstack);
   12309              : }
   12310              : 
   12311              : /* For two FIELD_DECLs in the same chain, return -1 if field1
   12312              :    comes before field2, 1 if field1 comes after field2 and
   12313              :    0 if field1 == field2.  */
   12314              : 
   12315              : static int
   12316         7104 : init_field_decl_cmp (tree field1, tree field2)
   12317              : {
   12318         7104 :   if (field1 == field2)
   12319              :     return 0;
   12320              : 
   12321         3342 :   tree bitpos1 = bit_position (field1);
   12322         3342 :   tree bitpos2 = bit_position (field2);
   12323         3342 :   if (tree_int_cst_equal (bitpos1, bitpos2))
   12324              :     {
   12325              :       /* If one of the fields has non-zero bitsize, then that
   12326              :          field must be the last one in a sequence of zero
   12327              :          sized fields, fields after it will have bigger
   12328              :          bit_position.  */
   12329           32 :       if (TREE_TYPE (field1) != error_mark_node
   12330           32 :           && COMPLETE_TYPE_P (TREE_TYPE (field1))
   12331           64 :           && integer_nonzerop (TREE_TYPE (field1)))
   12332              :         return 1;
   12333           32 :       if (TREE_TYPE (field2) != error_mark_node
   12334           32 :           && COMPLETE_TYPE_P (TREE_TYPE (field2))
   12335           57 :           && integer_nonzerop (TREE_TYPE (field2)))
   12336              :         return -1;
   12337              :       /* Otherwise, fallback to DECL_CHAIN walk to find out
   12338              :          which field comes earlier.  Walk chains of both
   12339              :          fields, so that if field1 and field2 are close to each
   12340              :          other in either order, it is found soon even for large
   12341              :          sequences of zero sized fields.  */
   12342              :       tree f1 = field1, f2 = field2;
   12343           32 :       while (1)
   12344              :         {
   12345           32 :           f1 = DECL_CHAIN (f1);
   12346           32 :           f2 = DECL_CHAIN (f2);
   12347           32 :           if (f1 == NULL_TREE)
   12348              :             {
   12349            7 :               gcc_assert (f2);
   12350              :               return 1;
   12351              :             }
   12352           25 :           if (f2 == NULL_TREE)
   12353              :             return -1;
   12354            9 :           if (f1 == field2)
   12355              :             return -1;
   12356            0 :           if (f2 == field1)
   12357              :             return 1;
   12358            0 :           if (!tree_int_cst_equal (bit_position (f1), bitpos1))
   12359              :             return 1;
   12360            0 :           if (!tree_int_cst_equal (bit_position (f2), bitpos1))
   12361              :             return -1;
   12362              :         }
   12363              :     }
   12364         3310 :   else if (tree_int_cst_lt (bitpos1, bitpos2))
   12365              :     return -1;
   12366              :   else
   12367         1948 :     return 1;
   12368              : }
   12369              : 
   12370              : /* Output any pending elements which have become next.
   12371              :    As we output elements, constructor_unfilled_{fields,index}
   12372              :    advances, which may cause other elements to become next;
   12373              :    if so, they too are output.
   12374              : 
   12375              :    If ALL is 0, we return when there are
   12376              :    no more pending elements to output now.
   12377              : 
   12378              :    If ALL is 1, we output space as necessary so that
   12379              :    we can output all the pending elements.  */
   12380              : static void
   12381     11786275 : output_pending_init_elements (int all, struct obstack * braced_init_obstack)
   12382              : {
   12383     11786275 :   struct init_node *elt = constructor_pending_elts;
   12384     11787442 :   tree next;
   12385              : 
   12386     11787442 :  retry:
   12387              : 
   12388              :   /* Look through the whole pending tree.
   12389              :      If we find an element that should be output now,
   12390              :      output it.  Otherwise, set NEXT to the element
   12391              :      that comes first among those still pending.  */
   12392              : 
   12393     11787442 :   next = NULL_TREE;
   12394     11799621 :   while (elt)
   12395              :     {
   12396        15058 :       if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   12397              :         {
   12398         6827 :           if (tree_int_cst_equal (elt->purpose,
   12399              :                                   constructor_unfilled_index))
   12400         2834 :             output_init_element (input_location, elt->value, elt->origtype,
   12401         2834 :                                  true, TREE_TYPE (constructor_type),
   12402              :                                  constructor_unfilled_index, false, false,
   12403              :                                  braced_init_obstack);
   12404         3993 :           else if (tree_int_cst_lt (constructor_unfilled_index,
   12405         3993 :                                     elt->purpose))
   12406              :             {
   12407              :               /* Advance to the next smaller node.  */
   12408         1138 :               if (elt->left)
   12409              :                 elt = elt->left;
   12410              :               else
   12411              :                 {
   12412              :                   /* We have reached the smallest node bigger than the
   12413              :                      current unfilled index.  Fill the space first.  */
   12414          350 :                   next = elt->purpose;
   12415          350 :                   break;
   12416              :                 }
   12417              :             }
   12418              :           else
   12419              :             {
   12420              :               /* Advance to the next bigger node.  */
   12421         2855 :               if (elt->right)
   12422              :                 elt = elt->right;
   12423              :               else
   12424              :                 {
   12425              :                   /* We have reached the biggest node in a subtree.  Find
   12426              :                      the parent of it, which is the next bigger node.  */
   12427         2855 :                   while (elt->parent && elt->parent->right == elt)
   12428              :                     elt = elt->parent;
   12429         1899 :                   elt = elt->parent;
   12430         2682 :                   if (elt && tree_int_cst_lt (constructor_unfilled_index,
   12431          783 :                                               elt->purpose))
   12432              :                     {
   12433           22 :                       next = elt->purpose;
   12434           22 :                       break;
   12435              :                     }
   12436              :                 }
   12437              :             }
   12438              :         }
   12439         8231 :       else if (RECORD_OR_UNION_TYPE_P (constructor_type))
   12440              :         {
   12441              :           /* If the current record is complete we are done.  */
   12442         8231 :           if (constructor_unfilled_fields == NULL_TREE)
   12443              :             break;
   12444              : 
   12445         6628 :           int cmp = init_field_decl_cmp (constructor_unfilled_fields,
   12446              :                                          elt->purpose);
   12447         6628 :           if (cmp == 0)
   12448         3357 :             output_init_element (input_location, elt->value, elt->origtype,
   12449         3357 :                                  true, TREE_TYPE (elt->purpose),
   12450              :                                  elt->purpose, false, false,
   12451              :                                  braced_init_obstack);
   12452         3271 :           else if (cmp < 0)
   12453              :             {
   12454              :               /* Advance to the next smaller node.  */
   12455         1316 :               if (elt->left)
   12456              :                 elt = elt->left;
   12457              :               else
   12458              :                 {
   12459              :                   /* We have reached the smallest node bigger than the
   12460              :                      current unfilled field.  Fill the space first.  */
   12461          833 :                   next = elt->purpose;
   12462          833 :                   break;
   12463              :                 }
   12464              :             }
   12465              :           else
   12466              :             {
   12467              :               /* Advance to the next bigger node.  */
   12468         1955 :               if (elt->right)
   12469              :                 elt = elt->right;
   12470              :               else
   12471              :                 {
   12472              :                   /* We have reached the biggest node in a subtree.  Find
   12473              :                      the parent of it, which is the next bigger node.  */
   12474         1025 :                   while (elt->parent && elt->parent->right == elt)
   12475              :                     elt = elt->parent;
   12476          789 :                   elt = elt->parent;
   12477          789 :                   if (elt
   12478          789 :                       && init_field_decl_cmp (constructor_unfilled_fields,
   12479              :                                               elt->purpose) < 0)
   12480              :                     {
   12481           71 :                       next = elt->purpose;
   12482           71 :                       break;
   12483              :                     }
   12484              :                 }
   12485              :             }
   12486              :         }
   12487              :     }
   12488              : 
   12489              :   /* Ordinarily return, but not if we want to output all
   12490              :      and there are elements left.  */
   12491     11787442 :   if (!(all && next != NULL_TREE))
   12492     11786275 :     return;
   12493              : 
   12494              :   /* If it's not incremental, just skip over the gap, so that after
   12495              :      jumping to retry we will output the next successive element.  */
   12496         1167 :   if (RECORD_OR_UNION_TYPE_P (constructor_type))
   12497          834 :     constructor_unfilled_fields = next;
   12498          333 :   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   12499          333 :     constructor_unfilled_index = next;
   12500              : 
   12501              :   /* ELT now points to the node in the pending tree with the next
   12502              :      initializer to output.  */
   12503         1167 :   goto retry;
   12504              : }
   12505              : 
   12506              : /* Expression VALUE coincides with the start of type TYPE in a braced
   12507              :    initializer.  Return true if we should treat VALUE as initializing
   12508              :    the first element of TYPE, false if we should treat it as initializing
   12509              :    TYPE as a whole.
   12510              : 
   12511              :    If the initializer is clearly invalid, the question becomes:
   12512              :    which choice gives the best error message?  */
   12513              : 
   12514              : static bool
   12515      3502731 : initialize_elementwise_p (tree type, tree value)
   12516              : {
   12517      3502731 :   if (type == error_mark_node || value == error_mark_node)
   12518              :     return false;
   12519              : 
   12520      3502462 :   gcc_checking_assert (TYPE_MAIN_VARIANT (type) == type);
   12521              : 
   12522      3502462 :   tree value_type = TREE_TYPE (value);
   12523      3502462 :   if (value_type == error_mark_node)
   12524              :     return false;
   12525              : 
   12526              :   /* GNU vectors can be initialized elementwise.  However, treat any
   12527              :      kind of vector value as initializing the vector type as a whole,
   12528              :      regardless of whether the value is a GNU vector.  Such initializers
   12529              :      are valid if and only if they would have been valid in a non-braced
   12530              :      initializer like:
   12531              : 
   12532              :         TYPE foo = VALUE;
   12533              : 
   12534              :      so recursing into the vector type would be at best confusing or at
   12535              :      worst wrong.  For example, when -flax-vector-conversions is in effect,
   12536              :      it's possible to initialize a V8HI from a V4SI, even though the vectors
   12537              :      have different element types and different numbers of elements.  */
   12538      3502462 :   if (gnu_vector_type_p (type))
   12539        19687 :     return !VECTOR_TYPE_P (value_type);
   12540              : 
   12541      3482775 :   if (AGGREGATE_TYPE_P (type))
   12542      1743596 :     return !comptypes (type, TYPE_MAIN_VARIANT (value_type));
   12543              : 
   12544              :   return false;
   12545              : }
   12546              : 
   12547              : /* Helper function for process_init_element.  Split first element of
   12548              :    RAW_DATA_CST and save the rest to *RAW_DATA.  */
   12549              : 
   12550              : static inline tree
   12551      9707977 : maybe_split_raw_data (tree value, tree *raw_data)
   12552              : {
   12553      9707977 :   if (value == NULL_TREE || TREE_CODE (value) != RAW_DATA_CST)
   12554              :     return value;
   12555          211 :   *raw_data = value;
   12556          211 :   value = build_int_cst (integer_type_node,
   12557          211 :                          RAW_DATA_UCHAR_ELT (*raw_data, 0));
   12558          211 :   ++RAW_DATA_POINTER (*raw_data);
   12559          211 :   --RAW_DATA_LENGTH (*raw_data);
   12560          211 :   return value;
   12561              : }
   12562              : 
   12563              : /* Return non-zero if c_parser_initval should attempt to optimize
   12564              :    large initializers into RAW_DATA_CST.  In that case return how
   12565              :    many elements to optimize at most.  */
   12566              : 
   12567              : unsigned
   12568      3029407 : c_maybe_optimize_large_byte_initializer (void)
   12569              : {
   12570      3029407 :   if (!constructor_type
   12571      3029337 :       || TREE_CODE (constructor_type) != ARRAY_TYPE
   12572       219160 :       || constructor_stack->implicit)
   12573              :     return 0;
   12574       216395 :   tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
   12575       216395 :   if (TREE_CODE (elttype) != INTEGER_TYPE
   12576       216395 :       && TREE_CODE (elttype) != BITINT_TYPE)
   12577              :     return 0;
   12578       193416 :   if (TYPE_PRECISION (elttype) != CHAR_BIT
   12579        29146 :       || constructor_stack->replacement_value.value
   12580        29146 :       || (COMPLETE_TYPE_P (constructor_type)
   12581        27271 :           && !poly_int_tree_p (TYPE_SIZE (constructor_type)))
   12582       222562 :       || constructor_range_stack)
   12583              :     return 0;
   12584        29146 :   if (constructor_max_index == NULL_TREE)
   12585              :     return INT_MAX;
   12586        27271 :   if (tree_int_cst_le (constructor_max_index, constructor_index)
   12587        27271 :       || integer_all_onesp (constructor_max_index))
   12588              :     return 0;
   12589        22472 :   widest_int w = wi::to_widest (constructor_max_index);
   12590        22472 :   w -= wi::to_widest (constructor_index);
   12591        22472 :   w += 1;
   12592        22472 :   if (w < 64)
   12593              :     return 0;
   12594         6891 :   if (w > INT_MAX)
   12595              :     return INT_MAX;
   12596         6891 :   return w.to_uhwi ();
   12597      3029407 : }
   12598              : 
   12599              : /* Add one non-braced element to the current constructor level.
   12600              :    This adjusts the current position within the constructor's type.
   12601              :    This may also start or terminate implicit levels
   12602              :    to handle a partly-braced initializer.
   12603              : 
   12604              :    Once this has found the correct level for the new element,
   12605              :    it calls output_init_element.
   12606              : 
   12607              :    IMPLICIT is true if value comes from pop_init_level (1),
   12608              :    the new initializer has been merged with the existing one
   12609              :    and thus no warnings should be emitted about overriding an
   12610              :    existing initializer.  */
   12611              : 
   12612              : void
   12613      9698274 : process_init_element (location_t loc, struct c_expr value, bool implicit,
   12614              :                       struct obstack * braced_init_obstack)
   12615              : {
   12616      9698274 :   tree orig_value = value.value;
   12617     19396548 :   int string_flag
   12618      9698274 :     = (orig_value != NULL_TREE && TREE_CODE (orig_value) == STRING_CST);
   12619      9698274 :   bool strict_string = value.original_code == STRING_CST;
   12620      9698274 :   bool was_designated = designator_depth != 0;
   12621      9698274 :   tree raw_data = NULL_TREE;
   12622              : 
   12623      9698486 : retry:
   12624      9698486 :   designator_depth = 0;
   12625      9698486 :   designator_erroneous = 0;
   12626              : 
   12627      9698486 :   if (!implicit && value.value && !integer_zerop (value.value))
   12628      7658508 :     constructor_zeroinit = 0;
   12629              : 
   12630              :   /* Handle superfluous braces around string cst as in
   12631              :      char x[] = {"foo"}; */
   12632      9698486 :   if (constructor_type
   12633      9698358 :       && !was_designated
   12634      9661113 :       && TREE_CODE (constructor_type) == ARRAY_TYPE
   12635      1718171 :       && INTEGRAL_TYPE_P (TREE_TYPE (constructor_type))
   12636     10446584 :       && integer_zerop (constructor_unfilled_index))
   12637              :     {
   12638       164254 :       if (constructor_stack->replacement_value.value)
   12639              :         {
   12640            8 :           error_init (loc, "excess elements in %qT initializer", constructor_type);
   12641          409 :           return;
   12642              :         }
   12643       164246 :       else if (string_flag)
   12644              :         {
   12645          138 :           constructor_stack->replacement_value = value;
   12646          138 :           return;
   12647              :         }
   12648              :     }
   12649              : 
   12650      9698340 :   if (constructor_stack->replacement_value.value != NULL_TREE)
   12651              :     {
   12652            0 :       error_init (loc, "excess elements in struct initializer");
   12653            0 :       return;
   12654              :     }
   12655              : 
   12656              :   /* Ignore elements of a brace group if it is entirely superfluous
   12657              :      and has already been diagnosed, or if the type is erroneous.  */
   12658      9698340 :   if (constructor_type == NULL_TREE || constructor_type == error_mark_node)
   12659              :     return;
   12660              : 
   12661              :   /* Ignore elements of an initializer for a variable-size type.
   12662              :      Those are diagnosed in the parser (empty initializer braces are OK).  */
   12663      9698143 :   if (COMPLETE_TYPE_P (constructor_type)
   12664      9698143 :       && !poly_int_tree_p (TYPE_SIZE (constructor_type)))
   12665              :     return;
   12666              : 
   12667      8992762 :   if (!implicit && warn_designated_init && !was_designated
   12668      8957835 :       && TREE_CODE (constructor_type) == RECORD_TYPE
   12669     10734686 :       && lookup_attribute ("designated_init",
   12670      1036601 :                            TYPE_ATTRIBUTES (constructor_type)))
   12671           50 :     warning_init (loc,
   12672              :                   OPT_Wdesignated_init,
   12673              :                   "positional initialization of field "
   12674              :                   "in %<struct%> declared with %<designated_init%> attribute");
   12675              : 
   12676              :   /* If we've exhausted any levels that didn't have braces,
   12677              :      pop them now.  */
   12678     10400064 :   while (constructor_stack->implicit)
   12679              :     {
   12680       708550 :       if (RECORD_OR_UNION_TYPE_P (constructor_type)
   12681       703711 :           && constructor_fields == NULL_TREE)
   12682       701738 :         process_init_element (loc,
   12683              :                               pop_init_level (loc, 1, braced_init_obstack,
   12684              :                                               last_init_list_comma),
   12685              :                               true, braced_init_obstack);
   12686         6812 :       else if ((TREE_CODE (constructor_type) == ARRAY_TYPE
   12687         2617 :                 || gnu_vector_type_p (constructor_type))
   12688         4839 :                && constructor_max_index
   12689        11624 :                && tree_int_cst_lt (constructor_max_index,
   12690              :                                    constructor_index))
   12691          241 :         process_init_element (loc,
   12692              :                               pop_init_level (loc, 1, braced_init_obstack,
   12693              :                                               last_init_list_comma),
   12694              :                               true, braced_init_obstack);
   12695              :       else
   12696              :         break;
   12697              :     }
   12698              : 
   12699              :   /* In the case of [LO ... HI] = VALUE, only evaluate VALUE once.  */
   12700      9698085 :   if (constructor_range_stack)
   12701              :     {
   12702              :       /* If value is a compound literal and we'll be just using its
   12703              :          content, don't put it into a SAVE_EXPR.  */
   12704          371 :       if (TREE_CODE (value.value) != COMPOUND_LITERAL_EXPR
   12705            3 :           || !require_constant_value)
   12706              :         {
   12707          368 :           tree semantic_type = NULL_TREE;
   12708          368 :           if (TREE_CODE (value.value) == EXCESS_PRECISION_EXPR)
   12709              :             {
   12710            0 :               semantic_type = TREE_TYPE (value.value);
   12711            0 :               value.value = TREE_OPERAND (value.value, 0);
   12712              :             }
   12713          368 :           value.value = save_expr (value.value);
   12714          368 :           if (semantic_type)
   12715            0 :             value.value = build1 (EXCESS_PRECISION_EXPR, semantic_type,
   12716              :                                   value.value);
   12717              :         }
   12718              :     }
   12719              : 
   12720     10412329 :   while (1)
   12721              :     {
   12722     10412329 :       if (TREE_CODE (constructor_type) == RECORD_TYPE)
   12723              :         {
   12724      1042797 :           tree fieldtype;
   12725      1042797 :           enum tree_code fieldcode;
   12726              : 
   12727      1042797 :           if (constructor_fields == NULL_TREE)
   12728              :             {
   12729         1280 :               pedwarn_init (loc, 0, "excess elements in struct initializer");
   12730         1280 :               break;
   12731              :             }
   12732              : 
   12733      1041517 :           fieldtype = TREE_TYPE (constructor_fields);
   12734      1041517 :           if (fieldtype != error_mark_node)
   12735      1041516 :             fieldtype = TYPE_MAIN_VARIANT (fieldtype);
   12736      1041517 :           fieldcode = TREE_CODE (fieldtype);
   12737              : 
   12738              :           /* Error for non-static initialization of a flexible array member.  */
   12739      1041517 :           if (fieldcode == ARRAY_TYPE
   12740       156131 :               && !require_constant_value
   12741         1893 :               && TYPE_SIZE (fieldtype) == NULL_TREE
   12742      1041527 :               && DECL_CHAIN (constructor_fields) == NULL_TREE)
   12743              :             {
   12744           10 :               error_init (loc, "non-static initialization of a flexible "
   12745              :                           "array member");
   12746           10 :               break;
   12747              :             }
   12748              : 
   12749              :           /* Error for initialization of a flexible array member with
   12750              :              a string constant if the structure is in an array.  E.g.:
   12751              :              struct S { int x; char y[]; };
   12752              :              struct S s[] = { { 1, "foo" } };
   12753              :              is invalid.  */
   12754      1041507 :           if (string_flag
   12755      1041507 :               && fieldcode == ARRAY_TYPE
   12756         3355 :               && constructor_depth > 1
   12757          489 :               && TYPE_SIZE (fieldtype) == NULL_TREE
   12758      1041554 :               && DECL_CHAIN (constructor_fields) == NULL_TREE)
   12759              :             {
   12760           47 :               bool in_array_p = false;
   12761           47 :               for (struct constructor_stack *p = constructor_stack;
   12762           73 :                    p && p->type; p = p->next)
   12763           59 :                 if (TREE_CODE (p->type) == ARRAY_TYPE)
   12764              :                   {
   12765              :                     in_array_p = true;
   12766              :                     break;
   12767              :                   }
   12768           47 :               if (in_array_p)
   12769              :                 {
   12770           33 :                   error_init (loc, "initialization of flexible array "
   12771              :                               "member in a nested context");
   12772           33 :                   break;
   12773              :                 }
   12774              :             }
   12775              : 
   12776              :           /* Accept a string constant to initialize a subarray.  */
   12777      1041474 :           if (value.value != NULL_TREE
   12778      1041431 :               && fieldcode == ARRAY_TYPE
   12779       156045 :               && INTEGRAL_TYPE_P (TREE_TYPE (fieldtype))
   12780      1196208 :               && string_flag)
   12781              :             value.value = orig_value;
   12782              :           /* Otherwise, if we have come to a subaggregate,
   12783              :              and we don't have an element of its type, push into it.  */
   12784      1038456 :           else if (value.value != NULL_TREE
   12785      1038152 :                    && initialize_elementwise_p (fieldtype, value.value))
   12786              :             {
   12787          304 :               push_init_level (loc, 1, braced_init_obstack);
   12788          304 :               continue;
   12789              :             }
   12790              : 
   12791      1041170 :           value.value = maybe_split_raw_data (value.value, &raw_data);
   12792      1041170 :           if (value.value)
   12793              :             {
   12794      1041127 :               push_member_name (constructor_fields);
   12795      1041127 :               output_init_element (loc, value.value, value.original_type,
   12796              :                                    strict_string, fieldtype,
   12797              :                                    constructor_fields, true, implicit,
   12798              :                                    braced_init_obstack);
   12799      1041127 :               RESTORE_SPELLING_DEPTH (constructor_depth);
   12800              :             }
   12801              :           else
   12802              :             /* Do the bookkeeping for an element that was
   12803              :                directly output as a constructor.  */
   12804              :             {
   12805              :               /* For a record, keep track of end position of last field.  */
   12806           43 :               if (DECL_SIZE (constructor_fields))
   12807            0 :                 constructor_bit_index
   12808            0 :                   = size_binop_loc (input_location, PLUS_EXPR,
   12809              :                                     bit_position (constructor_fields),
   12810            0 :                                     DECL_SIZE (constructor_fields));
   12811              : 
   12812              :               /* If the current field was the first one not yet written out,
   12813              :                  it isn't now, so update.  */
   12814           43 :               if (constructor_unfilled_fields == constructor_fields)
   12815              :                 {
   12816           34 :                   constructor_unfilled_fields = DECL_CHAIN (constructor_fields);
   12817              :                   /* Skip any nameless bit fields.  */
   12818           34 :                   while (constructor_unfilled_fields != 0
   12819           34 :                          && (DECL_UNNAMED_BIT_FIELD
   12820              :                              (constructor_unfilled_fields)))
   12821            0 :                     constructor_unfilled_fields =
   12822            0 :                       DECL_CHAIN (constructor_unfilled_fields);
   12823              :                 }
   12824              :             }
   12825              : 
   12826      1041170 :           constructor_fields = DECL_CHAIN (constructor_fields);
   12827              :           /* Skip any nameless bit fields at the beginning.  */
   12828      1041170 :           while (constructor_fields != NULL_TREE
   12829      1041271 :                  && DECL_UNNAMED_BIT_FIELD (constructor_fields))
   12830          101 :             constructor_fields = DECL_CHAIN (constructor_fields);
   12831              :         }
   12832      9369532 :       else if (TREE_CODE (constructor_type) == UNION_TYPE)
   12833              :         {
   12834        31678 :           tree fieldtype;
   12835        31678 :           enum tree_code fieldcode;
   12836              : 
   12837        31678 :           if (constructor_fields == NULL_TREE)
   12838              :             {
   12839            3 :               pedwarn_init (loc, 0,
   12840              :                             "excess elements in union initializer");
   12841            3 :               break;
   12842              :             }
   12843              : 
   12844        31675 :           fieldtype = TREE_TYPE (constructor_fields);
   12845        31675 :           if (fieldtype != error_mark_node)
   12846        31675 :             fieldtype = TYPE_MAIN_VARIANT (fieldtype);
   12847        31675 :           fieldcode = TREE_CODE (fieldtype);
   12848              : 
   12849              :           /* Warn that traditional C rejects initialization of unions.
   12850              :              We skip the warning if the value is zero.  This is done
   12851              :              under the assumption that the zero initializer in user
   12852              :              code appears conditioned on e.g. __STDC__ to avoid
   12853              :              "missing initializer" warnings and relies on default
   12854              :              initialization to zero in the traditional C case.
   12855              :              We also skip the warning if the initializer is designated,
   12856              :              again on the assumption that this must be conditional on
   12857              :              __STDC__ anyway (and we've already complained about the
   12858              :              member-designator already).  */
   12859        34138 :           if (!in_system_header_at (input_location) && !constructor_designated
   12860        33221 :               && !(value.value && (integer_zerop (value.value)
   12861         1447 :                                    || real_zerop (value.value))))
   12862         1440 :             warning (OPT_Wtraditional, "traditional C rejects initialization "
   12863              :                      "of unions");
   12864              : 
   12865              :           /* Error for non-static initialization of a flexible array member.  */
   12866        31675 :           if (fieldcode == ARRAY_TYPE
   12867          767 :               && !require_constant_value
   12868        31733 :               && TYPE_SIZE (fieldtype) == NULL_TREE)
   12869              :             {
   12870            3 :               error_init (loc, "non-static initialization of a flexible "
   12871              :                           "array member");
   12872            3 :               break;
   12873              :             }
   12874              : 
   12875              :           /* Error for initialization of a flexible array member with
   12876              :              a string constant if the structure is in an array.  E.g.:
   12877              :              union U { int x; char y[]; };
   12878              :              union U s[] = { { 1, "foo" } };
   12879              :              is invalid.  */
   12880        31672 :           if (string_flag
   12881        31672 :               && fieldcode == ARRAY_TYPE
   12882            7 :               && constructor_depth > 1
   12883        31676 :               && TYPE_SIZE (fieldtype) == NULL_TREE)
   12884              :             {
   12885            3 :               bool in_array_p = false;
   12886            3 :               for (struct constructor_stack *p = constructor_stack;
   12887            3 :                    p && p->type; p = p->next)
   12888            3 :                 if (TREE_CODE (p->type) == ARRAY_TYPE)
   12889              :                   {
   12890              :                     in_array_p = true;
   12891              :                     break;
   12892              :                   }
   12893            3 :               if (in_array_p)
   12894              :                 {
   12895            3 :                   error_init (loc, "initialization of flexible array "
   12896              :                               "member in a nested context");
   12897            3 :                   break;
   12898              :                 }
   12899              :             }
   12900              : 
   12901              :           /* Accept a string constant to initialize a subarray.  */
   12902        31669 :           if (value.value != NULL_TREE
   12903        31669 :               && fieldcode == ARRAY_TYPE
   12904          761 :               && INTEGRAL_TYPE_P (TREE_TYPE (fieldtype))
   12905        32425 :               && string_flag)
   12906              :             value.value = orig_value;
   12907              :           /* Otherwise, if we have come to a subaggregate,
   12908              :              and we don't have an element of its type, push into it.  */
   12909        31715 :           else if (value.value != NULL_TREE
   12910        31665 :                    && initialize_elementwise_p (fieldtype, value.value))
   12911              :             {
   12912           50 :               push_init_level (loc, 1, braced_init_obstack);
   12913           50 :               continue;
   12914              :             }
   12915              : 
   12916        31619 :           value.value = maybe_split_raw_data (value.value, &raw_data);
   12917        31619 :           if (value.value)
   12918              :             {
   12919        31619 :               push_member_name (constructor_fields);
   12920        31619 :               output_init_element (loc, value.value, value.original_type,
   12921              :                                    strict_string, fieldtype,
   12922              :                                    constructor_fields, true, implicit,
   12923              :                                    braced_init_obstack);
   12924        31619 :               RESTORE_SPELLING_DEPTH (constructor_depth);
   12925              :             }
   12926              :           else
   12927              :             /* Do the bookkeeping for an element that was
   12928              :                directly output as a constructor.  */
   12929              :             {
   12930            0 :               constructor_bit_index = DECL_SIZE (constructor_fields);
   12931            0 :               constructor_unfilled_fields = DECL_CHAIN (constructor_fields);
   12932              :             }
   12933              : 
   12934        31619 :           constructor_fields = NULL_TREE;
   12935              :         }
   12936      9337854 :       else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   12937              :         {
   12938      2433453 :           tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
   12939      2433453 :           enum tree_code eltcode = TREE_CODE (elttype);
   12940              : 
   12941              :           /* Accept a string constant to initialize a subarray.  */
   12942      2433453 :           if (value.value != NULL_TREE
   12943      2433453 :               && eltcode == ARRAY_TYPE
   12944         7031 :               && INTEGRAL_TYPE_P (TREE_TYPE (elttype))
   12945      2439001 :               && string_flag)
   12946              :             value.value = orig_value;
   12947              :           /* Otherwise, if we have come to a subaggregate,
   12948              :              and we don't have an element of its type, push into it.  */
   12949      3135283 :           else if (value.value != NULL_TREE
   12950      2432957 :                    && initialize_elementwise_p (elttype, value.value))
   12951              :             {
   12952       702326 :               push_init_level (loc, 1, braced_init_obstack);
   12953       702326 :               continue;
   12954              :             }
   12955              : 
   12956      1731127 :           if (constructor_max_index != NULL_TREE
   12957       682228 :               && (tree_int_cst_lt (constructor_max_index, constructor_index)
   12958       682113 :                   || integer_all_onesp (constructor_max_index))
   12959              :               /* For VLA we got an error already.  */
   12960      1731242 :               && !C_TYPE_VARIABLE_SIZE (constructor_type))
   12961              :             {
   12962          113 :               pedwarn_init (loc, 0,
   12963              :                             "excess elements in array initializer");
   12964          113 :               break;
   12965              :             }
   12966              : 
   12967      1731014 :           if (value.value
   12968      1731014 :               && TREE_CODE (value.value) == RAW_DATA_CST
   12969          196 :               && RAW_DATA_LENGTH (value.value) > 1
   12970          196 :               && (TREE_CODE (elttype) == INTEGER_TYPE
   12971          196 :                   || TREE_CODE (elttype) == BITINT_TYPE)
   12972          196 :               && TYPE_PRECISION (elttype) == CHAR_BIT
   12973      1731210 :               && (constructor_max_index == NULL_TREE
   12974           56 :                   || tree_int_cst_lt (constructor_index,
   12975              :                                       constructor_max_index)))
   12976              :             {
   12977          196 :               unsigned int len = RAW_DATA_LENGTH (value.value);
   12978          196 :               if (constructor_max_index)
   12979              :                 {
   12980           56 :                   widest_int w = wi::to_widest (constructor_max_index);
   12981           56 :                   w -= wi::to_widest (constructor_index);
   12982           56 :                   w += 1;
   12983           56 :                   if (w < len)
   12984            3 :                     len = w.to_uhwi ();
   12985           56 :                 }
   12986          196 :               if (len < (unsigned) RAW_DATA_LENGTH (value.value))
   12987              :                 {
   12988            3 :                   raw_data = copy_node (value.value);
   12989            3 :                   RAW_DATA_LENGTH (raw_data) -= len;
   12990            3 :                   RAW_DATA_POINTER (raw_data) += len;
   12991            3 :                   RAW_DATA_LENGTH (value.value) = len;
   12992              :                 }
   12993          196 :               TREE_TYPE (value.value) = elttype;
   12994          196 :               push_array_bounds (tree_to_uhwi (constructor_index));
   12995          196 :               output_init_element (loc, value.value, value.original_type,
   12996              :                                    false, elttype, constructor_index, true,
   12997              :                                    implicit, braced_init_obstack);
   12998          196 :               RESTORE_SPELLING_DEPTH (constructor_depth);
   12999          196 :               constructor_index
   13000          196 :                 = size_binop_loc (input_location, PLUS_EXPR,
   13001          196 :                                   constructor_index, bitsize_int (len));
   13002              :             }
   13003              :           else
   13004              :             {
   13005      1730818 :               value.value = maybe_split_raw_data (value.value, &raw_data);
   13006              :               /* Now output the actual element.  */
   13007      1730818 :               if (value.value)
   13008              :                 {
   13009      1730818 :                   push_array_bounds (tree_to_uhwi (constructor_index));
   13010      1730818 :                   output_init_element (loc, value.value, value.original_type,
   13011              :                                        strict_string, elttype,
   13012              :                                        constructor_index, true, implicit,
   13013              :                                        braced_init_obstack);
   13014      1730818 :                   RESTORE_SPELLING_DEPTH (constructor_depth);
   13015              :                 }
   13016              : 
   13017      1730818 :               constructor_index
   13018      1730818 :                 = size_binop_loc (input_location, PLUS_EXPR,
   13019              :                                   constructor_index, bitsize_one_node);
   13020              : 
   13021      1730818 :               if (!value.value)
   13022              :                 /* If we are doing the bookkeeping for an element that was
   13023              :                    directly output as a constructor, we must update
   13024              :                    constructor_unfilled_index.  */
   13025            0 :                 constructor_unfilled_index = constructor_index;
   13026              :             }
   13027              :         }
   13028      6904401 :       else if (gnu_vector_type_p (constructor_type))
   13029              :         {
   13030      6903909 :           tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
   13031              : 
   13032              :           /* Do a basic check of initializer size.  Note that vectors
   13033              :              may not always have a fixed size derived from their type.  */
   13034      6903909 :           if (maybe_lt (tree_to_poly_uint64 (constructor_max_index),
   13035      6903909 :                         tree_to_poly_uint64 (constructor_index)))
   13036              :             {
   13037              :               /* Diagose VLA out-of-bounds as errors.  */
   13038            2 :               if (tree_to_poly_uint64 (constructor_max_index).is_constant())
   13039            2 :                 pedwarn_init (loc, 0,
   13040              :                               "excess elements in vector initializer");
   13041              :               else
   13042              :                 error_init (loc, "excess elements in vector initializer");
   13043              : 
   13044              :               break;
   13045              :             }
   13046              : 
   13047      6903907 :           value.value = maybe_split_raw_data (value.value, &raw_data);
   13048              :           /* Now output the actual element.  */
   13049      6903907 :           if (value.value)
   13050              :             {
   13051      6903907 :               if (TREE_CODE (value.value) == VECTOR_CST)
   13052            0 :                 elttype = TYPE_MAIN_VARIANT (constructor_type);
   13053      6903907 :               output_init_element (loc, value.value, value.original_type,
   13054              :                                    strict_string, elttype,
   13055              :                                    constructor_index, true, implicit,
   13056              :                                    braced_init_obstack);
   13057              :             }
   13058              : 
   13059      6903907 :           constructor_index
   13060      6903907 :             = size_binop_loc (input_location,
   13061              :                               PLUS_EXPR, constructor_index, bitsize_one_node);
   13062              : 
   13063      6903907 :           if (!value.value)
   13064              :             /* If we are doing the bookkeeping for an element that was
   13065              :                directly output as a constructor, we must update
   13066              :                constructor_unfilled_index.  */
   13067            0 :             constructor_unfilled_index = constructor_index;
   13068              :         }
   13069              : 
   13070              :       /* Handle the sole element allowed in a braced initializer
   13071              :          for a scalar variable.  */
   13072          492 :       else if (constructor_type != error_mark_node
   13073          492 :                && constructor_fields == NULL_TREE)
   13074              :         {
   13075           29 :           pedwarn_init (loc, 0,
   13076              :                         "excess elements in scalar initializer");
   13077           29 :           break;
   13078              :         }
   13079              :       else
   13080              :         {
   13081          463 :           value.value = maybe_split_raw_data (value.value, &raw_data);
   13082          463 :           if (value.value)
   13083          463 :             output_init_element (loc, value.value, value.original_type,
   13084              :                                  strict_string, constructor_type,
   13085              :                                  NULL_TREE, true, implicit,
   13086              :                                  braced_init_obstack);
   13087          463 :           constructor_fields = NULL_TREE;
   13088              :         }
   13089              : 
   13090              :       /* Handle range initializers either at this level or anywhere higher
   13091              :          in the designator stack.  */
   13092      9708173 :       if (constructor_range_stack)
   13093              :         {
   13094        11564 :           struct constructor_range_stack *p, *range_stack;
   13095        11564 :           int finish = 0;
   13096              : 
   13097        11564 :           range_stack = constructor_range_stack;
   13098        11564 :           constructor_range_stack = 0;
   13099        11564 :           while (constructor_stack != range_stack->stack)
   13100              :             {
   13101            0 :               gcc_assert (constructor_stack->implicit);
   13102            0 :               process_init_element (loc,
   13103              :                                     pop_init_level (loc, 1,
   13104              :                                                     braced_init_obstack,
   13105              :                                                     last_init_list_comma),
   13106              :                                     true, braced_init_obstack);
   13107              :             }
   13108          325 :           for (p = range_stack;
   13109        11889 :                !p->range_end || tree_int_cst_equal (p->index, p->range_end);
   13110          325 :                p = p->prev)
   13111              :             {
   13112          325 :               gcc_assert (constructor_stack->implicit);
   13113          325 :               process_init_element (loc,
   13114              :                                     pop_init_level (loc, 1,
   13115              :                                                     braced_init_obstack,
   13116              :                                                     last_init_list_comma),
   13117              :                                     true, braced_init_obstack);
   13118              :             }
   13119              : 
   13120        11564 :           p->index = size_binop_loc (input_location,
   13121              :                                      PLUS_EXPR, p->index, bitsize_one_node);
   13122        11564 :           if (tree_int_cst_equal (p->index, p->range_end) && !p->prev)
   13123        11564 :             finish = 1;
   13124              : 
   13125        11889 :           while (1)
   13126              :             {
   13127        11889 :               constructor_index = p->index;
   13128        11889 :               constructor_fields = p->fields;
   13129        11889 :               if (finish && p->range_end && p->index == p->range_start)
   13130              :                 {
   13131            8 :                   finish = 0;
   13132            8 :                   p->prev = 0;
   13133              :                 }
   13134        11889 :               p = p->next;
   13135        11889 :               if (!p)
   13136              :                 break;
   13137          325 :               finish_implicit_inits (loc, braced_init_obstack);
   13138          325 :               push_init_level (loc, 2, braced_init_obstack);
   13139          325 :               p->stack = constructor_stack;
   13140          325 :               if (p->range_end && tree_int_cst_equal (p->index, p->range_end))
   13141           33 :                 p->index = p->range_start;
   13142              :             }
   13143              : 
   13144        11564 :           if (!finish)
   13145        11193 :             constructor_range_stack = range_stack;
   13146        11564 :           continue;
   13147        11564 :         }
   13148              : 
   13149              :       break;
   13150              :     }
   13151              : 
   13152      9698085 :   constructor_range_stack = 0;
   13153              : 
   13154      9698085 :   if (raw_data && RAW_DATA_LENGTH (raw_data))
   13155              :     {
   13156          212 :       gcc_assert (!string_flag && !was_designated);
   13157          212 :       value.value = raw_data;
   13158          212 :       raw_data = NULL_TREE;
   13159          212 :       goto retry;
   13160              :     }
   13161              : }
   13162              : 
   13163              : /* Build a complete asm-statement, whose components are a CV_QUALIFIER
   13164              :    (guaranteed to be 'volatile' or null) and ARGS (represented using
   13165              :    an ASM_EXPR node).  */
   13166              : tree
   13167       196167 : build_asm_stmt (bool is_volatile, tree args)
   13168              : {
   13169       196167 :   if (is_volatile)
   13170       156290 :     ASM_VOLATILE_P (args) = 1;
   13171       196167 :   return add_stmt (args);
   13172              : }
   13173              : 
   13174              : /* Build an asm-expr, whose components are a STRING, some OUTPUTS,
   13175              :    some INPUTS, and some CLOBBERS.  The latter three may be NULL.
   13176              :    SIMPLE indicates whether there was anything at all after the
   13177              :    string in the asm expression -- asm("blah") and asm("blah" : )
   13178              :    are subtly different.  We use a ASM_EXPR node to represent this.
   13179              :    LOC is the location of the asm, and IS_INLINE says whether this
   13180              :    is asm inline.  */
   13181              : tree
   13182       196219 : build_asm_expr (location_t loc, tree string, tree outputs, tree inputs,
   13183              :                 tree clobbers, tree labels, bool simple, bool is_inline)
   13184              : {
   13185       196219 :   tree tail;
   13186       196219 :   tree args;
   13187       196219 :   int i;
   13188       196219 :   const char *constraint;
   13189       196219 :   const char **oconstraints;
   13190       196219 :   bool allows_mem, allows_reg, is_inout;
   13191       196219 :   int ninputs, noutputs;
   13192              : 
   13193       196219 :   ninputs = list_length (inputs);
   13194       196219 :   noutputs = list_length (outputs);
   13195       196219 :   oconstraints = (const char **) alloca (noutputs * sizeof (const char *));
   13196              : 
   13197       196219 :   string = resolve_asm_operand_names (string, outputs, inputs, labels);
   13198              : 
   13199              :   /* Remove output conversions that change the type but not the mode.  */
   13200       745996 :   for (i = 0, tail = outputs; tail; ++i, tail = TREE_CHAIN (tail))
   13201              :     {
   13202       353558 :       tree output = TREE_VALUE (tail);
   13203              : 
   13204       353558 :       output = c_fully_fold (output, false, NULL, true);
   13205              : 
   13206              :       /* ??? Really, this should not be here.  Users should be using a
   13207              :          proper lvalue, dammit.  But there's a long history of using casts
   13208              :          in the output operands.  In cases like longlong.h, this becomes a
   13209              :          primitive form of typechecking -- if the cast can be removed, then
   13210              :          the output operand had a type of the proper width; otherwise we'll
   13211              :          get an error.  Gross, but ...  */
   13212       353558 :       STRIP_NOPS (output);
   13213              : 
   13214       353558 :       if (!lvalue_or_else (loc, output, lv_asm))
   13215            4 :         output = error_mark_node;
   13216              : 
   13217       353558 :       if (output != error_mark_node
   13218       353558 :           && (TREE_READONLY (output)
   13219       353551 :               || TYPE_READONLY (TREE_TYPE (output))
   13220       353551 :               || (RECORD_OR_UNION_TYPE_P (TREE_TYPE (output))
   13221          112 :                   && C_TYPE_FIELDS_READONLY (TREE_TYPE (output)))))
   13222            2 :         readonly_error (loc, output, lv_asm);
   13223              : 
   13224       353558 :       constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail)));
   13225       353558 :       oconstraints[i] = constraint;
   13226              : 
   13227       353558 :       if (parse_output_constraint (&constraint, i, ninputs, noutputs,
   13228              :                                    &allows_mem, &allows_reg, &is_inout,
   13229              :                                    nullptr))
   13230              :         {
   13231              :           /* If the operand is going to end up in memory,
   13232              :              mark it addressable.  */
   13233       353550 :           if (!allows_reg && !c_mark_addressable (output))
   13234            3 :             output = error_mark_node;
   13235         1423 :           if (!(!allows_reg && allows_mem)
   13236       352127 :               && output != error_mark_node
   13237       705675 :               && VOID_TYPE_P (TREE_TYPE (output)))
   13238              :             {
   13239            4 :               error_at (loc, "invalid use of void expression");
   13240            4 :               output = error_mark_node;
   13241              :             }
   13242       353550 :           if (allows_reg && current_function_decl == NULL_TREE)
   13243              :             {
   13244            1 :               error_at (loc, "constraint allows registers outside of "
   13245              :                              "a function");
   13246            1 :               output = error_mark_node;
   13247              :             }
   13248              :         }
   13249              :       else
   13250            8 :         output = error_mark_node;
   13251              : 
   13252       353558 :       if (current_function_decl == NULL_TREE && output != error_mark_node)
   13253              :         {
   13254            7 :           if (TREE_SIDE_EFFECTS (output))
   13255              :             {
   13256            0 :               error_at (loc, "side-effects in output operand outside "
   13257              :                              "of a function");
   13258            0 :               output = error_mark_node;
   13259              :             }
   13260              :           else
   13261              :             {
   13262            7 :               tree addr = build_unary_op (loc, ADDR_EXPR, output, false);
   13263            7 :               if (addr == error_mark_node)
   13264              :                 output = error_mark_node;
   13265            7 :               else if (!initializer_constant_valid_p (addr, TREE_TYPE (addr)))
   13266              :                 {
   13267            1 :                   error_at (loc, "output operand outside of a function is not "
   13268              :                                  "constant");
   13269            1 :                   output = error_mark_node;
   13270              :                 }
   13271              :             }
   13272              :         }
   13273       353551 :       else if (output != error_mark_node && strstr (constraint, "-"))
   13274              :         {
   13275            1 :           error_at (loc, "%<-%> modifier used inside of a function");
   13276            1 :           output = error_mark_node;
   13277              :         }
   13278              : 
   13279       353558 :       TREE_VALUE (tail) = output;
   13280              :     }
   13281              : 
   13282       564805 :   for (i = 0, tail = inputs; tail; ++i, tail = TREE_CHAIN (tail))
   13283              :     {
   13284       368586 :       tree input;
   13285              : 
   13286       368586 :       constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail)));
   13287       368586 :       input = TREE_VALUE (tail);
   13288              : 
   13289       368586 :       if (parse_input_constraint (&constraint, i, ninputs, noutputs, 0,
   13290              :                                   oconstraints, &allows_mem, &allows_reg,
   13291              :                                   nullptr))
   13292              :         {
   13293              :           /* If the operand is going to end up in memory,
   13294              :              mark it addressable.  */
   13295       368578 :           if (!allows_reg && allows_mem)
   13296              :             {
   13297         1366 :               input = c_fully_fold (input, false, NULL, true);
   13298              : 
   13299              :               /* Strip the nops as we allow this case.  FIXME, this really
   13300              :                  should be rejected or made deprecated.  */
   13301         1366 :               STRIP_NOPS (input);
   13302         1366 :               if (!c_mark_addressable (input))
   13303            2 :                 input = error_mark_node;
   13304              :             }
   13305              :           else
   13306              :             {
   13307       367212 :               input = c_fully_fold (convert_lvalue_to_rvalue (loc, input,
   13308              :                                                               true, false),
   13309              :                                     false, NULL);
   13310              : 
   13311       367212 :               if (input != error_mark_node && VOID_TYPE_P (TREE_TYPE (input)))
   13312              :                 {
   13313            4 :                   error_at (loc, "invalid use of void expression");
   13314            4 :                   input = error_mark_node;
   13315              :                 }
   13316              :             }
   13317       368578 :           if (allows_reg && current_function_decl == NULL_TREE)
   13318              :             {
   13319            1 :               error_at (loc, "constraint allows registers outside of "
   13320              :                              "a function");
   13321            1 :               input = error_mark_node;
   13322              :             }
   13323       368578 :           if (constraint[0] == ':' && input != error_mark_node)
   13324              :             {
   13325           35 :               tree t = input;
   13326           35 :               STRIP_NOPS (t);
   13327           35 :               if (TREE_CODE (t) != ADDR_EXPR
   13328           35 :                   || !(TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
   13329           23 :                        || (VAR_P (TREE_OPERAND (t, 0))
   13330           21 :                            && is_global_var (TREE_OPERAND (t, 0)))))
   13331              :                 {
   13332            5 :                   error_at (loc, "%<:%> constraint operand is not address "
   13333              :                                  "of a function or non-automatic variable");
   13334            5 :                   input = error_mark_node;
   13335              :                 }
   13336           30 :               else if (TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL)
   13337           10 :                 suppress_warning (TREE_OPERAND (t, 0), OPT_Wunused);
   13338              :             }
   13339              :         }
   13340              :       else
   13341            8 :         input = error_mark_node;
   13342              : 
   13343       368586 :       if (current_function_decl == NULL_TREE && input != error_mark_node)
   13344              :         {
   13345           58 :           if (TREE_SIDE_EFFECTS (input))
   13346              :             {
   13347            2 :               error_at (loc, "side-effects in input operand outside "
   13348              :                              "of a function");
   13349            2 :               input = error_mark_node;
   13350              :             }
   13351              :           else
   13352              :             {
   13353           56 :               tree tem = input;
   13354           56 :               if (allows_mem && lvalue_p (input))
   13355            7 :                 tem = build_unary_op (loc, ADDR_EXPR, input, false);
   13356           56 :               if (!initializer_constant_valid_p (tem, TREE_TYPE (tem)))
   13357              :                 {
   13358            2 :                   error_at (loc, "input operand outside of a function is not "
   13359              :                                  "constant");
   13360            2 :                   input = error_mark_node;
   13361              :                 }
   13362              :             }
   13363              :         }
   13364       368528 :       else if (input != error_mark_node && strstr (constraint, "-"))
   13365              :         {
   13366            3 :           error_at (loc, "%<-%> modifier used inside of a function");
   13367            3 :           input = error_mark_node;
   13368              :         }
   13369              : 
   13370       368586 :       TREE_VALUE (tail) = input;
   13371              :     }
   13372              : 
   13373       196219 :   args = build_stmt (loc, ASM_EXPR, string, outputs, inputs, clobbers, labels);
   13374              : 
   13375              :   /* asm statements without outputs, including simple ones, are treated
   13376              :      as volatile.  */
   13377       196219 :   ASM_BASIC_P (args) = simple;
   13378       196219 :   ASM_VOLATILE_P (args) = (noutputs == 0);
   13379       196219 :   ASM_INLINE_P (args) = is_inline;
   13380              : 
   13381       196219 :   return args;
   13382              : }
   13383              : 
   13384              : /* Generate a goto statement to LABEL.  LOC is the location of the
   13385              :    GOTO.  */
   13386              : 
   13387              : tree
   13388        83636 : c_finish_goto_label (location_t loc, tree label)
   13389              : {
   13390        83636 :   tree decl = lookup_label_for_goto (loc, label);
   13391        83636 :   if (!decl)
   13392              :     return NULL_TREE;
   13393        83636 :   TREE_USED (decl) = 1;
   13394        83636 :   mark_decl_used (decl, false);
   13395        83636 :   {
   13396        83636 :     add_stmt (build_predict_expr (PRED_GOTO, NOT_TAKEN));
   13397        83636 :     tree t = build1 (GOTO_EXPR, void_type_node, decl);
   13398        83636 :     SET_EXPR_LOCATION (t, loc);
   13399        83636 :     return add_stmt (t);
   13400              :   }
   13401              : }
   13402              : 
   13403              : /* Generate a computed goto statement to EXPR.  LOC is the location of
   13404              :    the GOTO.  */
   13405              : 
   13406              : tree
   13407         1073 : c_finish_goto_ptr (location_t loc, c_expr val)
   13408              : {
   13409         1073 :   tree expr = val.value;
   13410         1073 :   tree t;
   13411         1073 :   pedwarn (loc, OPT_Wpedantic, "ISO C forbids %<goto *expr;%>");
   13412         1073 :   if (expr != error_mark_node
   13413         1072 :       && !POINTER_TYPE_P (TREE_TYPE (expr))
   13414         1078 :       && !null_pointer_constant_p (expr))
   13415              :     {
   13416            2 :       error_at (val.get_location (),
   13417              :                 "computed goto must be pointer type");
   13418            2 :       expr = build_zero_cst (ptr_type_node);
   13419              :     }
   13420         1073 :   expr = c_fully_fold (expr, false, NULL);
   13421         1073 :   expr = convert (ptr_type_node, expr);
   13422         1073 :   t = build1 (GOTO_EXPR, void_type_node, expr);
   13423         1073 :   SET_EXPR_LOCATION (t, loc);
   13424         1073 :   return add_stmt (t);
   13425              : }
   13426              : 
   13427              : /* Generate a C `return' statement.  RETVAL is the expression for what
   13428              :    to return, or a null pointer for `return;' with no value.  LOC is
   13429              :    the location of the return statement, or the location of the expression,
   13430              :    if the statement has any.  If ORIGTYPE is not NULL_TREE, it
   13431              :    is the original type of RETVAL.  MUSTTAIL_P indicates a musttail
   13432              :    attribute.  */
   13433              : 
   13434              : tree
   13435     35880229 : c_finish_return (location_t loc, tree retval, tree origtype, bool musttail_p)
   13436              : {
   13437     35880229 :   tree valtype = TREE_TYPE (TREE_TYPE (current_function_decl)), ret_stmt;
   13438     35880229 :   bool no_warning = false;
   13439     35880229 :   bool npc = false;
   13440              : 
   13441              :   /* Use the expansion point to handle cases such as returning NULL
   13442              :      in a function returning void.  */
   13443     35880229 :   location_t xloc = expansion_point_location_if_in_system_header (loc);
   13444              : 
   13445     35880229 :   if (TREE_THIS_VOLATILE (current_function_decl))
   13446           23 :     warning_at (xloc, 0,
   13447              :                 "function declared %<noreturn%> has a %<return%> statement");
   13448              : 
   13449     35880229 :   set_musttail_on_return (retval, xloc, musttail_p);
   13450              : 
   13451     35880229 :   if (retval)
   13452              :     {
   13453     35858579 :       tree semantic_type = NULL_TREE;
   13454     35858579 :       npc = null_pointer_constant_p (retval);
   13455     35858579 :       if (TREE_CODE (retval) == EXCESS_PRECISION_EXPR)
   13456              :         {
   13457           93 :           semantic_type = TREE_TYPE (retval);
   13458           93 :           retval = TREE_OPERAND (retval, 0);
   13459              :         }
   13460     35858579 :       retval = c_fully_fold (retval, false, NULL);
   13461     35858579 :       if (semantic_type
   13462     35858579 :           && valtype != NULL_TREE
   13463           93 :           && TREE_CODE (valtype) != VOID_TYPE)
   13464           93 :         retval = build1 (EXCESS_PRECISION_EXPR, semantic_type, retval);
   13465              :     }
   13466              : 
   13467     35858579 :   if (!retval)
   13468              :     {
   13469        21650 :       current_function_returns_null = 1;
   13470        21650 :       if ((warn_return_type >= 0 || flag_isoc99)
   13471        21525 :           && valtype != NULL_TREE && TREE_CODE (valtype) != VOID_TYPE)
   13472              :         {
   13473           46 :           no_warning = true;
   13474           47 :           if (emit_diagnostic (flag_isoc99
   13475              :                                ? diagnostics::kind::permerror
   13476              :                                : diagnostics::kind::warning,
   13477           46 :                                loc, OPT_Wreturn_mismatch,
   13478              :                                "%<return%> with no value,"
   13479              :                                " in function returning non-void"))
   13480           27 :             inform (DECL_SOURCE_LOCATION (current_function_decl),
   13481              :                     "declared here");
   13482              :         }
   13483              :     }
   13484     35858579 :   else if (valtype == NULL_TREE || VOID_TYPE_P (valtype))
   13485              :     {
   13486          322 :       current_function_returns_null = 1;
   13487          322 :       bool warned_here;
   13488          322 :       if (TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
   13489           64 :         warned_here = permerror_opt
   13490           64 :           (xloc, OPT_Wreturn_mismatch,
   13491              :            "%<return%> with a value, in function returning void");
   13492              :       else
   13493          258 :         warned_here = pedwarn
   13494          258 :           (xloc, OPT_Wpedantic, "ISO C forbids "
   13495              :            "%<return%> with expression, in function returning void");
   13496          322 :       if (warned_here)
   13497           43 :         inform (DECL_SOURCE_LOCATION (current_function_decl),
   13498              :                 "declared here");
   13499              :     }
   13500              :   else
   13501              :     {
   13502     35858257 :       tree t = convert_for_assignment (loc, UNKNOWN_LOCATION, valtype,
   13503              :                                        retval, origtype, ic_return,
   13504              :                                        npc, NULL_TREE, NULL_TREE, 0);
   13505     35858257 :       tree res = DECL_RESULT (current_function_decl);
   13506     35858257 :       tree inner;
   13507     35858257 :       bool save;
   13508              : 
   13509     35858257 :       current_function_returns_value = 1;
   13510     35858257 :       if (t == error_mark_node)
   13511              :         {
   13512              :           /* Suppress -Wreturn-type for this function.  */
   13513          299 :           if (warn_return_type)
   13514          298 :             suppress_warning (current_function_decl, OPT_Wreturn_type);
   13515              :           return NULL_TREE;
   13516              :         }
   13517              : 
   13518     35857958 :       save = in_late_binary_op;
   13519     71705785 :       if (C_BOOLEAN_TYPE_P (TREE_TYPE (res))
   13520     35847022 :           || TREE_CODE (TREE_TYPE (res)) == COMPLEX_TYPE
   13521     71703677 :           || (SCALAR_FLOAT_TYPE_P (TREE_TYPE (t))
   13522       335739 :               && (TREE_CODE (TREE_TYPE (res)) == INTEGER_TYPE
   13523       335739 :                   || TREE_CODE (TREE_TYPE (res)) == ENUMERAL_TYPE)
   13524            0 :               && sanitize_flags_p (SANITIZE_FLOAT_CAST)))
   13525        12239 :         in_late_binary_op = true;
   13526     35857958 :       inner = t = convert (TREE_TYPE (res), t);
   13527     35857958 :       in_late_binary_op = save;
   13528              : 
   13529              :       /* Strip any conversions, additions, and subtractions, and see if
   13530              :          we are returning the address of a local variable.  Warn if so.  */
   13531     39170304 :       while (1)
   13532              :         {
   13533     39170304 :           switch (TREE_CODE (inner))
   13534              :             {
   13535      3310737 :             CASE_CONVERT:
   13536      3310737 :             case NON_LVALUE_EXPR:
   13537      3310737 :             case PLUS_EXPR:
   13538      3310737 :             case POINTER_PLUS_EXPR:
   13539      3310737 :               inner = TREE_OPERAND (inner, 0);
   13540      3310737 :               continue;
   13541              : 
   13542         1614 :             case MINUS_EXPR:
   13543              :               /* If the second operand of the MINUS_EXPR has a pointer
   13544              :                  type (or is converted from it), this may be valid, so
   13545              :                  don't give a warning.  */
   13546         1614 :               {
   13547         1614 :                 tree op1 = TREE_OPERAND (inner, 1);
   13548              : 
   13549         3489 :                 while (!POINTER_TYPE_P (TREE_TYPE (op1))
   13550         3755 :                        && (CONVERT_EXPR_P (op1)
   13551         1609 :                            || TREE_CODE (op1) == NON_LVALUE_EXPR))
   13552          266 :                   op1 = TREE_OPERAND (op1, 0);
   13553              : 
   13554         1614 :                 if (POINTER_TYPE_P (TREE_TYPE (op1)))
   13555              :                   break;
   13556              : 
   13557         1609 :                 inner = TREE_OPERAND (inner, 0);
   13558         1609 :                 continue;
   13559         1609 :               }
   13560              : 
   13561         2985 :             case ADDR_EXPR:
   13562         2985 :               inner = TREE_OPERAND (inner, 0);
   13563              : 
   13564         2985 :               while (REFERENCE_CLASS_P (inner)
   13565         3892 :                      && !INDIRECT_REF_P (inner))
   13566          907 :                 inner = TREE_OPERAND (inner, 0);
   13567              : 
   13568         2985 :               if (DECL_P (inner)
   13569         1657 :                   && !DECL_EXTERNAL (inner)
   13570         1001 :                   && DECL_CONTEXT (inner) == current_function_decl
   13571         3207 :                   && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (current_function_decl))))
   13572              :                 {
   13573          182 :                   if (TREE_CODE (inner) == LABEL_DECL)
   13574            4 :                     warning_at (loc, OPT_Wreturn_local_addr,
   13575              :                                 "function returns address of label");
   13576          178 :                   else if (TREE_CODE (inner) == FUNCTION_DECL
   13577          178 :                            && (C_FUNC_NONLOCAL_CONTEXT (inner)
   13578            9 :                                || !DECL_INITIAL (inner)))
   13579           14 :                     warning_at (loc, OPT_Wreturn_local_addr,
   13580              :                                 "function returns address of nested function "
   13581              :                                 "referencing local context");
   13582          164 :                   else if (TREE_CODE (inner) != FUNCTION_DECL
   13583          156 :                            && !TREE_STATIC (inner))
   13584              :                     {
   13585            9 :                       warning_at (loc, OPT_Wreturn_local_addr,
   13586              :                                   "function returns address of local variable");
   13587            9 :                       tree zero = build_zero_cst (TREE_TYPE (res));
   13588            9 :                       t = build2 (COMPOUND_EXPR, TREE_TYPE (res), t, zero);
   13589              :                     }
   13590              :                 }
   13591              :               break;
   13592              : 
   13593              :             default:
   13594              :               break;
   13595      3310737 :             }
   13596              : 
   13597     35857958 :           break;
   13598              :         }
   13599              : 
   13600     35857958 :       retval = build2 (MODIFY_EXPR, TREE_TYPE (res), res, t);
   13601     35857958 :       SET_EXPR_LOCATION (retval, loc);
   13602              : 
   13603     35857958 :       if (warn_sequence_point)
   13604      3040634 :         verify_sequence_points (retval);
   13605              :     }
   13606              : 
   13607     35879930 :   ret_stmt = build_stmt (loc, RETURN_EXPR, retval);
   13608     35879930 :   if (no_warning)
   13609           46 :     suppress_warning (ret_stmt, OPT_Wreturn_type);
   13610     35879930 :   return add_stmt (ret_stmt);
   13611              : }
   13612              : 
   13613              : struct c_switch {
   13614              :   /* The SWITCH_STMT being built.  */
   13615              :   tree switch_stmt;
   13616              : 
   13617              :   /* The original type of the testing expression, i.e. before the
   13618              :      default conversion is applied.  */
   13619              :   tree orig_type;
   13620              : 
   13621              :   /* A splay-tree mapping the low element of a case range to the high
   13622              :      element, or NULL_TREE if there is no high element.  Used to
   13623              :      determine whether or not a new case label duplicates an old case
   13624              :      label.  We need a tree, rather than simply a hash table, because
   13625              :      of the GNU case range extension.  */
   13626              :   splay_tree cases;
   13627              : 
   13628              :   /* The bindings at the point of the switch.  This is used for
   13629              :      warnings crossing decls when branching to a case label.  */
   13630              :   struct c_spot_bindings *bindings;
   13631              : 
   13632              :   /* Whether the switch includes any break statements.  */
   13633              :   bool break_stmt_seen_p;
   13634              : 
   13635              :   /* The next node on the stack.  */
   13636              :   struct c_switch *next;
   13637              : 
   13638              :   /* Remember whether the controlling expression had boolean type
   13639              :      before integer promotions for the sake of -Wswitch-bool.  */
   13640              :   bool bool_cond_p;
   13641              : };
   13642              : 
   13643              : /* A stack of the currently active switch statements.  The innermost
   13644              :    switch statement is on the top of the stack.  There is no need to
   13645              :    mark the stack for garbage collection because it is only active
   13646              :    during the processing of the body of a function, and we never
   13647              :    collect at that point.  */
   13648              : 
   13649              : struct c_switch *c_switch_stack;
   13650              : 
   13651              : /* Start a C switch statement, testing expression EXP.  Return the new
   13652              :    SWITCH_STMT.  SWITCH_LOC is the location of the `switch'.
   13653              :    SWITCH_COND_LOC is the location of the switch's condition.
   13654              :    EXPLICIT_CAST_P is true if the expression EXP has an explicit cast.  */
   13655              : 
   13656              : tree
   13657        38806 : c_start_switch (location_t switch_loc,
   13658              :                 location_t switch_cond_loc,
   13659              :                 tree exp, bool explicit_cast_p, tree switch_name)
   13660              : {
   13661        38806 :   tree orig_type = error_mark_node;
   13662        38806 :   bool bool_cond_p = false;
   13663        38806 :   struct c_switch *cs;
   13664              : 
   13665        38806 :   if (exp != error_mark_node)
   13666              :     {
   13667        38763 :       orig_type = TREE_TYPE (exp);
   13668              : 
   13669        38763 :       if (!INTEGRAL_TYPE_P (orig_type))
   13670              :         {
   13671           12 :           if (orig_type != error_mark_node)
   13672              :             {
   13673           12 :               error_at (switch_cond_loc, "switch quantity not an integer");
   13674           12 :               orig_type = error_mark_node;
   13675              :             }
   13676           12 :           exp = integer_zero_node;
   13677              :         }
   13678              :       else
   13679              :         {
   13680        38751 :           tree type = TYPE_MAIN_VARIANT (orig_type);
   13681        38751 :           tree e = exp;
   13682              : 
   13683              :           /* Warn if the condition has boolean value.  */
   13684        38754 :           while (TREE_CODE (e) == COMPOUND_EXPR)
   13685            3 :             e = TREE_OPERAND (e, 1);
   13686              : 
   13687        38726 :           if ((C_BOOLEAN_TYPE_P (type)
   13688        38726 :                || truth_value_p (TREE_CODE (e)))
   13689              :               /* Explicit cast to int suppresses this warning.  */
   13690        38773 :               && !(TREE_CODE (type) == INTEGER_TYPE
   13691              :                    && explicit_cast_p))
   13692              :             bool_cond_p = true;
   13693              : 
   13694        38751 :           if (!in_system_header_at (input_location)
   13695        38751 :               && (type == long_integer_type_node
   13696        13173 :                   || type == long_unsigned_type_node))
   13697          306 :             warning_at (switch_cond_loc,
   13698          306 :                         OPT_Wtraditional, "%<long%> switch expression not "
   13699              :                         "converted to %<int%> in ISO C");
   13700              : 
   13701        38751 :           exp = c_fully_fold (exp, false, NULL);
   13702        38751 :           exp = default_conversion (exp);
   13703              : 
   13704        38751 :           if (warn_sequence_point)
   13705         6994 :             verify_sequence_points (exp);
   13706              :         }
   13707              :     }
   13708              : 
   13709              :   /* Add this new SWITCH_STMT to the stack.  */
   13710        38806 :   cs = XNEW (struct c_switch);
   13711        38806 :   cs->switch_stmt = build_stmt (switch_loc, SWITCH_STMT, exp,
   13712              :                                 NULL_TREE, orig_type, NULL_TREE, switch_name);
   13713        38806 :   cs->orig_type = orig_type;
   13714        38806 :   cs->cases = splay_tree_new (case_compare, NULL, NULL);
   13715        38806 :   cs->bindings = c_get_switch_bindings ();
   13716        38806 :   cs->break_stmt_seen_p = false;
   13717        38806 :   cs->bool_cond_p = bool_cond_p;
   13718        38806 :   cs->next = c_switch_stack;
   13719        38806 :   c_switch_stack = cs;
   13720              : 
   13721        38806 :   return add_stmt (cs->switch_stmt);
   13722              : }
   13723              : 
   13724              : /* Process a case label at location LOC, with attributes ATTRS.  */
   13725              : 
   13726              : tree
   13727      1039318 : do_case (location_t loc, tree low_value, tree high_value, tree attrs)
   13728              : {
   13729      1039318 :   tree label = NULL_TREE;
   13730              : 
   13731      1039318 :   if (low_value && TREE_CODE (low_value) != INTEGER_CST)
   13732              :     {
   13733           87 :       low_value = c_fully_fold (low_value, false, NULL);
   13734           87 :       if (TREE_CODE (low_value) == INTEGER_CST)
   13735            9 :         pedwarn (loc, OPT_Wpedantic,
   13736              :                  "case label is not an integer constant expression");
   13737              :     }
   13738              : 
   13739      1039318 :   if (high_value && TREE_CODE (high_value) != INTEGER_CST)
   13740              :     {
   13741            0 :       high_value = c_fully_fold (high_value, false, NULL);
   13742            0 :       if (TREE_CODE (high_value) == INTEGER_CST)
   13743            0 :         pedwarn (input_location, OPT_Wpedantic,
   13744              :                  "case label is not an integer constant expression");
   13745              :     }
   13746              : 
   13747      1039318 :   if (c_switch_stack == NULL)
   13748              :     {
   13749            3 :       if (low_value)
   13750            2 :         error_at (loc, "case label not within a switch statement");
   13751              :       else
   13752            1 :         error_at (loc, "%<default%> label not within a switch statement");
   13753              :       return NULL_TREE;
   13754              :     }
   13755              : 
   13756      1039315 :   if (c_check_switch_jump_warnings (c_switch_stack->bindings,
   13757      1039315 :                                     EXPR_LOCATION (c_switch_stack->switch_stmt),
   13758              :                                     loc))
   13759              :     return NULL_TREE;
   13760              : 
   13761      1039303 :   label = c_add_case_label (loc, c_switch_stack->cases,
   13762      1039303 :                             SWITCH_STMT_COND (c_switch_stack->switch_stmt),
   13763              :                             low_value, high_value, attrs);
   13764      1039303 :   if (label == error_mark_node)
   13765          144 :     label = NULL_TREE;
   13766              :   return label;
   13767              : }
   13768              : 
   13769              : /* Finish the switch statement.  TYPE is the original type of the
   13770              :    controlling expression of the switch, or NULL_TREE.  */
   13771              : 
   13772              : void
   13773        38806 : c_finish_switch (tree body, tree type)
   13774              : {
   13775        38806 :   struct c_switch *cs = c_switch_stack;
   13776        38806 :   location_t switch_location;
   13777              : 
   13778        38806 :   SWITCH_STMT_BODY (cs->switch_stmt) = body;
   13779              : 
   13780              :   /* Emit warnings as needed.  */
   13781        38806 :   switch_location = EXPR_LOCATION (cs->switch_stmt);
   13782        45718 :   c_do_switch_warnings (cs->cases, switch_location,
   13783         6912 :                         type ? type : SWITCH_STMT_TYPE (cs->switch_stmt),
   13784        38806 :                         SWITCH_STMT_COND (cs->switch_stmt), cs->bool_cond_p);
   13785        38806 :   if (c_switch_covers_all_cases_p (cs->cases,
   13786        38806 :                                    SWITCH_STMT_TYPE (cs->switch_stmt)))
   13787        34813 :     SWITCH_STMT_ALL_CASES_P (cs->switch_stmt) = 1;
   13788        38806 :   SWITCH_STMT_NO_BREAK_P (cs->switch_stmt) = !cs->break_stmt_seen_p;
   13789              : 
   13790              :   /* Pop the stack.  */
   13791        38806 :   c_switch_stack = cs->next;
   13792        38806 :   splay_tree_delete (cs->cases);
   13793        38806 :   c_release_switch_bindings (cs->bindings);
   13794        38806 :   XDELETE (cs);
   13795        38806 : }
   13796              : 
   13797              : /* Emit an if statement.  IF_LOCUS is the location of the 'if'.  COND,
   13798              :    THEN_BLOCK and ELSE_BLOCK are expressions to be used; ELSE_BLOCK
   13799              :    may be null.  */
   13800              : 
   13801              : void
   13802      1291141 : c_finish_if_stmt (location_t if_locus, tree cond, tree then_block,
   13803              :                   tree else_block)
   13804              : {
   13805      1291141 :   tree stmt;
   13806              : 
   13807      1291141 :   stmt = build3 (COND_EXPR, void_type_node, cond, then_block, else_block);
   13808      1291141 :   SET_EXPR_LOCATION (stmt, if_locus);
   13809      1291141 :   add_stmt (stmt);
   13810      1291141 : }
   13811              : 
   13812              : tree
   13813       191621 : c_finish_bc_stmt (location_t loc, tree label, bool is_break, tree name)
   13814              : {
   13815              :   /* In switch statements break is sometimes stylistically used after
   13816              :      a return statement.  This can lead to spurious warnings about
   13817              :      control reaching the end of a non-void function when it is
   13818              :      inlined.  Note that we are calling block_may_fallthru with
   13819              :      language specific tree nodes; this works because
   13820              :      block_may_fallthru returns true when given something it does not
   13821              :      understand.  */
   13822       191621 :   bool skip = !block_may_fallthru (cur_stmt_list);
   13823              : 
   13824       191621 :   if (is_break)
   13825       178256 :     switch (in_statement & ~IN_NAMED_STMT)
   13826              :       {
   13827            9 :       case 0:
   13828            9 :         error_at (loc, "break statement not within loop or switch");
   13829            9 :         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           12 :       case IN_OMP_FOR:
   13834           12 :         error_at (loc, "break statement used with OpenMP for loop");
   13835           12 :         return NULL_TREE;
   13836              :       case IN_ITERATION_STMT:
   13837              :       case IN_OBJC_FOREACH:
   13838              :         break;
   13839       162202 :       default:
   13840       162202 :         gcc_assert (in_statement & IN_SWITCH_STMT);
   13841       162202 :         c_switch_stack->break_stmt_seen_p = true;
   13842       162202 :         break;
   13843              :       }
   13844              :   else
   13845        13365 :     switch (in_statement & ~(IN_SWITCH_STMT | IN_NAMED_STMT))
   13846              :       {
   13847            7 :       case 0:
   13848            7 :         error_at (loc, "continue statement not within a loop");
   13849            7 :         return NULL_TREE;
   13850            4 :       case IN_OMP_BLOCK:
   13851            4 :         error_at (loc, "invalid exit from OpenMP structured block");
   13852            4 :         return NULL_TREE;
   13853              :       case IN_ITERATION_STMT:
   13854              :       case IN_OMP_FOR:
   13855              :       case IN_OBJC_FOREACH:
   13856              :         break;
   13857            0 :       default:
   13858            0 :         gcc_unreachable ();
   13859              :       }
   13860              : 
   13861       191585 :   if (skip)
   13862              :     return NULL_TREE;
   13863       191103 :   else if ((in_statement & IN_OBJC_FOREACH)
   13864            0 :            && !(is_break && (in_statement & IN_SWITCH_STMT))
   13865            0 :            && name == NULL_TREE)
   13866              :     {
   13867              :       /* The foreach expander produces low-level code using gotos instead
   13868              :          of a structured loop construct.  */
   13869            0 :       gcc_assert (label);
   13870            0 :       return add_stmt (build_stmt (loc, GOTO_EXPR, label));
   13871              :     }
   13872       191200 :   else if (name && C_DECL_LOOP_NAME (name) && C_DECL_SWITCH_NAME (name))
   13873              :     {
   13874            0 :       label = DECL_CHAIN (name);
   13875            0 :       if (!is_break)
   13876            0 :         label = DECL_CHAIN (label);
   13877              :       /* Foreach expander from some outer level.  */
   13878            0 :       return add_stmt (build_stmt (loc, GOTO_EXPR, label));
   13879              :     }
   13880       204457 :   return add_stmt (build_stmt (loc, is_break ? BREAK_STMT : CONTINUE_STMT,
   13881       191103 :                                name));
   13882              : }
   13883              : 
   13884              : /* A helper routine for c_process_expr_stmt and c_finish_stmt_expr.  */
   13885              : 
   13886              : static void
   13887      6610787 : emit_side_effect_warnings (location_t loc, tree expr)
   13888              : {
   13889      6610787 :   maybe_warn_nodiscard (loc, expr);
   13890      6610787 :   if (!warn_unused_value)
   13891              :     return;
   13892      1319716 :   if (expr == error_mark_node)
   13893              :     ;
   13894      1319641 :   else if (!TREE_SIDE_EFFECTS (expr))
   13895              :     {
   13896         6979 :       if (!VOID_TYPE_P (TREE_TYPE (expr))
   13897         6979 :           && !warning_suppressed_p (expr, OPT_Wunused_value))
   13898           28 :         warning_at (loc, OPT_Wunused_value, "statement with no effect");
   13899              :     }
   13900      1312662 :   else if (TREE_CODE (expr) == COMPOUND_EXPR)
   13901              :     {
   13902              :       tree r = expr;
   13903              :       location_t cloc = loc;
   13904        12107 :       while (TREE_CODE (r) == COMPOUND_EXPR)
   13905              :         {
   13906         6069 :           if (EXPR_HAS_LOCATION (r))
   13907         5527 :             cloc = EXPR_LOCATION (r);
   13908         6069 :           r = TREE_OPERAND (r, 1);
   13909              :         }
   13910         6038 :       if (!TREE_SIDE_EFFECTS (r)
   13911           33 :           && !VOID_TYPE_P (TREE_TYPE (r))
   13912           24 :           && !CONVERT_EXPR_P (r)
   13913           24 :           && !warning_suppressed_p (r, OPT_Wunused_value)
   13914         6050 :           && !warning_suppressed_p (expr, OPT_Wunused_value))
   13915            8 :         warning_at (cloc, OPT_Wunused_value,
   13916              :                     "right-hand operand of comma expression has no effect");
   13917              :     }
   13918              :   else
   13919      1306624 :     warn_if_unused_value (expr, loc);
   13920              : }
   13921              : 
   13922              : /* Process an expression as if it were a complete statement.  Emit
   13923              :    diagnostics, but do not call ADD_STMT.  LOC is the location of the
   13924              :    statement.  */
   13925              : 
   13926              : tree
   13927      6487047 : c_process_expr_stmt (location_t loc, tree expr)
   13928              : {
   13929      6487047 :   tree exprv;
   13930              : 
   13931      6487047 :   if (!expr)
   13932              :     return NULL_TREE;
   13933              : 
   13934      6482479 :   expr = c_fully_fold (expr, false, NULL);
   13935              : 
   13936      6482479 :   if (warn_sequence_point)
   13937      1315001 :     verify_sequence_points (expr);
   13938              : 
   13939      6482479 :   if (TREE_TYPE (expr) != error_mark_node
   13940      6479794 :       && !COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (expr))
   13941      6482479 :       && TREE_CODE (TREE_TYPE (expr)) != ARRAY_TYPE)
   13942            0 :     error_at (loc, "expression statement has incomplete type");
   13943              : 
   13944              :   /* If we're not processing a statement expression, warn about unused values.
   13945              :      Warnings for statement expressions will be emitted later, once we figure
   13946              :      out which is the result.  */
   13947      6482479 :   if (!STATEMENT_LIST_STMT_EXPR (cur_stmt_list)
   13948      6482479 :       && (warn_unused_value || warn_unused_result))
   13949      6359632 :     emit_side_effect_warnings (EXPR_LOC_OR_LOC (expr, loc), expr);
   13950              : 
   13951      6482478 :   exprv = expr;
   13952      6524090 :   while (TREE_CODE (exprv) == COMPOUND_EXPR)
   13953        41612 :     exprv = TREE_OPERAND (exprv, 1);
   13954      6494461 :   while (CONVERT_EXPR_P (exprv))
   13955        11983 :     exprv = TREE_OPERAND (exprv, 0);
   13956      6482478 :   if (DECL_P (exprv)
   13957      6483065 :       || handled_component_p (exprv)
   13958     12944704 :       || TREE_CODE (exprv) == ADDR_EXPR)
   13959        20839 :     mark_exp_read (exprv);
   13960              : 
   13961              :   /* If the expression is not of a type to which we cannot assign a line
   13962              :      number, wrap the thing in a no-op NOP_EXPR.  */
   13963      6482478 :   if (DECL_P (expr) || CONSTANT_CLASS_P (expr))
   13964              :     {
   13965        14903 :       expr = build1 (NOP_EXPR, TREE_TYPE (expr), expr);
   13966        14903 :       SET_EXPR_LOCATION (expr, loc);
   13967              :     }
   13968              : 
   13969              :   return expr;
   13970              : }
   13971              : 
   13972              : /* Emit an expression as a statement.  LOC is the location of the
   13973              :    expression.  */
   13974              : 
   13975              : tree
   13976      6177585 : c_finish_expr_stmt (location_t loc, tree expr)
   13977              : {
   13978      6177585 :   if (expr)
   13979      6163168 :     return add_stmt (c_process_expr_stmt (loc, expr));
   13980              :   else
   13981              :     return NULL;
   13982              : }
   13983              : 
   13984              : /* Do the opposite and emit a statement as an expression.  To begin,
   13985              :    create a new binding level and return it.  */
   13986              : 
   13987              : tree
   13988        35440 : c_begin_stmt_expr (void)
   13989              : {
   13990        35440 :   tree ret;
   13991              : 
   13992              :   /* We must force a BLOCK for this level so that, if it is not expanded
   13993              :      later, there is a way to turn off the entire subtree of blocks that
   13994              :      are contained in it.  */
   13995        35440 :   keep_next_level ();
   13996        35440 :   ret = c_begin_compound_stmt (true);
   13997              : 
   13998        35440 :   c_bindings_start_stmt_expr (c_switch_stack == NULL
   13999              :                               ? NULL
   14000              :                               : c_switch_stack->bindings);
   14001              : 
   14002              :   /* Mark the current statement list as belonging to a statement list.  */
   14003        35440 :   STATEMENT_LIST_STMT_EXPR (ret) = 1;
   14004              : 
   14005        35440 :   return ret;
   14006              : }
   14007              : 
   14008              : /* LOC is the location of the compound statement to which this body
   14009              :    belongs.  */
   14010              : 
   14011              : tree
   14012        35440 : c_finish_stmt_expr (location_t loc, tree body)
   14013              : {
   14014        35440 :   tree last, type, tmp, val;
   14015        35440 :   tree *last_p;
   14016              : 
   14017        35440 :   body = c_end_compound_stmt (loc, body, true);
   14018              : 
   14019        35440 :   c_bindings_end_stmt_expr (c_switch_stack == NULL
   14020              :                             ? NULL
   14021              :                             : c_switch_stack->bindings);
   14022              : 
   14023              :   /* Locate the last statement in BODY.  See c_end_compound_stmt
   14024              :      about always returning a BIND_EXPR.  */
   14025        35440 :   last_p = &BIND_EXPR_BODY (body);
   14026        35440 :   last = BIND_EXPR_BODY (body);
   14027              : 
   14028        35440 :  continue_searching:
   14029        35440 :   if (TREE_CODE (last) == STATEMENT_LIST)
   14030              :     {
   14031        26604 :       tree_stmt_iterator l = tsi_last (last);
   14032              : 
   14033        26610 :       while (!tsi_end_p (l) && TREE_CODE (tsi_stmt (l)) == DEBUG_BEGIN_STMT)
   14034            6 :         tsi_prev (&l);
   14035              : 
   14036              :       /* This can happen with degenerate cases like ({ }).  No value.  */
   14037        26604 :       if (tsi_end_p (l))
   14038          389 :         return body;
   14039              : 
   14040              :       /* If we're supposed to generate side effects warnings, process
   14041              :          all of the statements except the last.  */
   14042        26215 :       if (warn_unused_value || warn_unused_result)
   14043              :         {
   14044        26215 :           for (tree_stmt_iterator i = tsi_start (last);
   14045       277370 :                tsi_stmt (i) != tsi_stmt (l); tsi_next (&i))
   14046              :             {
   14047       251155 :               location_t tloc;
   14048       251155 :               tree t = tsi_stmt (i);
   14049              : 
   14050       251155 :               tloc = EXPR_HAS_LOCATION (t) ? EXPR_LOCATION (t) : loc;
   14051       251155 :               emit_side_effect_warnings (tloc, t);
   14052              :             }
   14053              :         }
   14054        26215 :       last_p = tsi_stmt_ptr (l);
   14055        26215 :       last = *last_p;
   14056              :     }
   14057              : 
   14058              :   /* If the end of the list is exception related, then the list was split
   14059              :      by a call to push_cleanup.  Continue searching.  */
   14060        35051 :   if (TREE_CODE (last) == TRY_FINALLY_EXPR
   14061        35051 :       || TREE_CODE (last) == TRY_CATCH_EXPR)
   14062              :     {
   14063            0 :       last_p = &TREE_OPERAND (last, 0);
   14064            0 :       last = *last_p;
   14065            0 :       goto continue_searching;
   14066              :     }
   14067              : 
   14068        35051 :   if (last == error_mark_node)
   14069              :     return last;
   14070              : 
   14071              :   /* In the case that the BIND_EXPR is not necessary, return the
   14072              :      expression out from inside it.  */
   14073        35042 :   if ((last == BIND_EXPR_BODY (body)
   14074              :        /* Skip nested debug stmts.  */
   14075        26214 :        || last == expr_first (BIND_EXPR_BODY (body)))
   14076        46102 :       && BIND_EXPR_VARS (body) == NULL)
   14077              :     {
   14078              :       /* Even if this looks constant, do not allow it in a constant
   14079              :          expression.  */
   14080        11048 :       last = c_wrap_maybe_const (last, true);
   14081              :       /* Do not warn if the return value of a statement expression is
   14082              :          unused.  */
   14083        11048 :       suppress_warning (last, OPT_Wunused);
   14084        11048 :       return last;
   14085              :     }
   14086              : 
   14087              :   /* Extract the type of said expression.  */
   14088        23994 :   type = TREE_TYPE (last);
   14089              : 
   14090              :   /* If we're not returning a value at all, then the BIND_EXPR that
   14091              :      we already have is a fine expression to return.  */
   14092        23994 :   if (!type || VOID_TYPE_P (type))
   14093              :     return body;
   14094              : 
   14095              :   /* Now that we've located the expression containing the value, it seems
   14096              :      silly to make voidify_wrapper_expr repeat the process.  Create a
   14097              :      temporary of the appropriate type and stick it in a TARGET_EXPR.  */
   14098        18666 :   tmp = create_tmp_var_raw (type);
   14099              : 
   14100              :   /* Unwrap a no-op NOP_EXPR as added by c_finish_expr_stmt.  This avoids
   14101              :      tree_expr_nonnegative_p giving up immediately.  */
   14102        18666 :   val = last;
   14103        18666 :   if (TREE_CODE (val) == NOP_EXPR
   14104        18666 :       && TREE_TYPE (val) == TREE_TYPE (TREE_OPERAND (val, 0)))
   14105         3799 :     val = TREE_OPERAND (val, 0);
   14106              : 
   14107        18666 :   *last_p = build2 (MODIFY_EXPR, void_type_node, tmp, val);
   14108        18666 :   SET_EXPR_LOCATION (*last_p, EXPR_LOCATION (last));
   14109              : 
   14110        18666 :   {
   14111        18666 :     tree t = build4 (TARGET_EXPR, type, tmp, body, NULL_TREE, NULL_TREE);
   14112        18666 :     SET_EXPR_LOCATION (t, loc);
   14113        18666 :     return t;
   14114              :   }
   14115              : }
   14116              : 
   14117              : /* Begin and end compound statements.  This is as simple as pushing
   14118              :    and popping new statement lists from the tree.  */
   14119              : 
   14120              : tree
   14121     42608740 : c_begin_compound_stmt (bool do_scope)
   14122              : {
   14123     42608740 :   tree stmt = push_stmt_list ();
   14124     42608740 :   if (do_scope)
   14125     42512552 :     push_scope ();
   14126     42608740 :   return stmt;
   14127              : }
   14128              : 
   14129              : /* End a compound statement.  STMT is the statement.  LOC is the
   14130              :    location of the compound statement-- this is usually the location
   14131              :    of the opening brace.  */
   14132              : 
   14133              : tree
   14134     42608739 : c_end_compound_stmt (location_t loc, tree stmt, bool do_scope)
   14135              : {
   14136     42608739 :   tree block = NULL;
   14137              : 
   14138     42608739 :   if (do_scope)
   14139              :     {
   14140     42512551 :       if (c_dialect_objc ())
   14141            0 :         objc_clear_super_receiver ();
   14142     42512551 :       block = pop_scope ();
   14143              :     }
   14144              : 
   14145     42608739 :   stmt = pop_stmt_list (stmt);
   14146     42608739 :   stmt = c_build_bind_expr (loc, block, stmt);
   14147              : 
   14148              :   /* If this compound statement is nested immediately inside a statement
   14149              :      expression, then force a BIND_EXPR to be created.  Otherwise we'll
   14150              :      do the wrong thing for ({ { 1; } }) or ({ 1; { } }).  In particular,
   14151              :      STATEMENT_LISTs merge, and thus we can lose track of what statement
   14152              :      was really last.  */
   14153     85217478 :   if (building_stmt_list_p ()
   14154     42608654 :       && STATEMENT_LIST_STMT_EXPR (cur_stmt_list)
   14155     42731461 :       && TREE_CODE (stmt) != BIND_EXPR)
   14156              :     {
   14157       120979 :       stmt = build3 (BIND_EXPR, void_type_node, NULL, stmt, NULL);
   14158       120979 :       TREE_SIDE_EFFECTS (stmt) = 1;
   14159       120979 :       SET_EXPR_LOCATION (stmt, loc);
   14160              :     }
   14161              : 
   14162     42608739 :   return stmt;
   14163              : }
   14164              : 
   14165              : /* Queue a cleanup.  CLEANUP is an expression/statement to be executed
   14166              :    when the current scope is exited.  EH_ONLY is true when this is not
   14167              :    meant to apply to normal control flow transfer.  */
   14168              : 
   14169              : void
   14170          140 : push_cleanup (tree decl, tree cleanup, bool eh_only)
   14171              : {
   14172          140 :   enum tree_code code;
   14173          140 :   tree stmt, list;
   14174          140 :   bool stmt_expr;
   14175              : 
   14176          140 :   code = eh_only ? TRY_CATCH_EXPR : TRY_FINALLY_EXPR;
   14177          140 :   stmt = build_stmt (DECL_SOURCE_LOCATION (decl), code, NULL, cleanup);
   14178          140 :   add_stmt (stmt);
   14179          140 :   stmt_expr = STATEMENT_LIST_STMT_EXPR (cur_stmt_list);
   14180          140 :   list = push_stmt_list ();
   14181          140 :   TREE_OPERAND (stmt, 0) = list;
   14182          140 :   STATEMENT_LIST_STMT_EXPR (list) = stmt_expr;
   14183          140 : }
   14184              : 
   14185              : /* Build a vector comparison of ARG0 and ARG1 using CODE opcode
   14186              :    into a value of TYPE type.  Comparison is done via VEC_COND_EXPR.  */
   14187              : 
   14188              : static tree
   14189       102010 : build_vec_cmp (tree_code code, tree type,
   14190              :                tree arg0, tree arg1)
   14191              : {
   14192       102010 :   tree zero_vec = build_zero_cst (type);
   14193       102010 :   tree minus_one_vec = build_minus_one_cst (type);
   14194       102010 :   tree cmp_type = truth_type_for (TREE_TYPE (arg0));
   14195       102010 :   tree cmp = build2 (code, cmp_type, arg0, arg1);
   14196       102010 :   return build3 (VEC_COND_EXPR, type, cmp, minus_one_vec, zero_vec);
   14197              : }
   14198              : 
   14199              : /* Possibly warn about an address of OP never being NULL in a comparison
   14200              :    operation CODE involving null.  */
   14201              : 
   14202              : static void
   14203        52555 : maybe_warn_for_null_address (location_t loc, tree op, tree_code code)
   14204              : {
   14205              :   /* Prevent warnings issued for macro expansion.  */
   14206        52555 :   if (!warn_address
   14207        30758 :       || warning_suppressed_p (op, OPT_Waddress)
   14208        82933 :       || from_macro_expansion_at (loc))
   14209              :     return;
   14210              : 
   14211        27631 :   if (TREE_CODE (op) == NOP_EXPR)
   14212              :     {
   14213              :       /* Allow casts to intptr_t to suppress the warning.  */
   14214         1135 :       tree type = TREE_TYPE (op);
   14215         1135 :       if (TREE_CODE (type) == INTEGER_TYPE)
   14216              :         return;
   14217         1135 :       op = TREE_OPERAND (op, 0);
   14218              :     }
   14219              : 
   14220        27631 :   if (TREE_CODE (op) == POINTER_PLUS_EXPR)
   14221              :     {
   14222              :       /* Allow a cast to void* to suppress the warning.  */
   14223           24 :       tree type = TREE_TYPE (TREE_TYPE (op));
   14224           24 :       if (VOID_TYPE_P (type))
   14225              :         return;
   14226              : 
   14227              :       /* Adding any value to a null pointer, including zero, is undefined
   14228              :          in C.  This includes the expression &p[0] where p is the null
   14229              :          pointer, although &p[0] will have been folded to p by this point
   14230              :          and so not diagnosed.  */
   14231           24 :       if (code == EQ_EXPR)
   14232           22 :         warning_at (loc, OPT_Waddress,
   14233              :                     "the comparison will always evaluate as %<false%> "
   14234              :                     "for the pointer operand in %qE must not be NULL",
   14235              :                     op);
   14236              :       else
   14237            2 :         warning_at (loc, OPT_Waddress,
   14238              :                     "the comparison will always evaluate as %<true%> "
   14239              :                     "for the pointer operand in %qE must not be NULL",
   14240              :                     op);
   14241              : 
   14242              :       return;
   14243              :     }
   14244              : 
   14245        27607 :   if (TREE_CODE (op) != ADDR_EXPR)
   14246              :     return;
   14247              : 
   14248          254 :   op = TREE_OPERAND (op, 0);
   14249              : 
   14250          254 :   if (TREE_CODE (op) == IMAGPART_EXPR
   14251          254 :       || TREE_CODE (op) == REALPART_EXPR)
   14252              :     {
   14253              :       /* The address of either complex part may not be null.  */
   14254           14 :       if (code == EQ_EXPR)
   14255            9 :         warning_at (loc, OPT_Waddress,
   14256              :                     "the comparison will always evaluate as %<false%> "
   14257              :                     "for the address of %qE will never be NULL",
   14258              :                     op);
   14259              :       else
   14260            5 :         warning_at (loc, OPT_Waddress,
   14261              :                     "the comparison will always evaluate as %<true%> "
   14262              :                     "for the address of %qE will never be NULL",
   14263              :                     op);
   14264              :       return;
   14265              :     }
   14266              : 
   14267              :   /* Set to true in the loop below if OP dereferences is operand.
   14268              :      In such a case the ultimate target need not be a decl for
   14269              :      the null [in]equality test to be constant.  */
   14270              :   bool deref = false;
   14271              : 
   14272              :   /* Get the outermost array or object, or member.  */
   14273          294 :   while (handled_component_p (op))
   14274              :     {
   14275           72 :       if (TREE_CODE (op) == COMPONENT_REF)
   14276              :         {
   14277              :           /* Get the member (its address is never null).  */
   14278           18 :           op = TREE_OPERAND (op, 1);
   14279           18 :           break;
   14280              :         }
   14281              : 
   14282              :       /* Get the outer array/object to refer to in the warning.  */
   14283           54 :       op = TREE_OPERAND (op, 0);
   14284           54 :       deref = true;
   14285              :     }
   14286              : 
   14287          192 :   if ((!deref && !decl_with_nonnull_addr_p (op))
   14288          371 :       || from_macro_expansion_at (loc))
   14289              :     return;
   14290              : 
   14291          131 :   bool w;
   14292          131 :   if (code == EQ_EXPR)
   14293           93 :     w = warning_at (loc, OPT_Waddress,
   14294              :                     "the comparison will always evaluate as %<false%> "
   14295              :                     "for the address of %qE will never be NULL",
   14296              :                     op);
   14297              :   else
   14298           38 :     w = warning_at (loc, OPT_Waddress,
   14299              :                     "the comparison will always evaluate as %<true%> "
   14300              :                     "for the address of %qE will never be NULL",
   14301              :                     op);
   14302              : 
   14303          131 :   if (w && DECL_P (op))
   14304          120 :     inform (DECL_SOURCE_LOCATION (op), "%qD declared here", op);
   14305              : }
   14306              : 
   14307              : /* Build a binary-operation expression without default conversions.
   14308              :    CODE is the kind of expression to build.
   14309              :    LOCATION is the operator's location.
   14310              :    This function differs from `build' in several ways:
   14311              :    the data type of the result is computed and recorded in it,
   14312              :    warnings are generated if arg data types are invalid,
   14313              :    special handling for addition and subtraction of pointers is known,
   14314              :    and some optimization is done (operations on narrow ints
   14315              :    are done in the narrower type when that gives the same result).
   14316              :    Constant folding is also done before the result is returned.
   14317              : 
   14318              :    Note that the operands will never have enumeral types, or function
   14319              :    or array types, because either they will have the default conversions
   14320              :    performed or they have both just been converted to some other type in which
   14321              :    the arithmetic is to be done.  */
   14322              : 
   14323              : tree
   14324     17645176 : build_binary_op (location_t location, enum tree_code code,
   14325              :                  tree orig_op0, tree orig_op1, bool convert_p)
   14326              : {
   14327     17645176 :   tree type0, type1, orig_type0, orig_type1;
   14328     17645176 :   tree eptype;
   14329     17645176 :   enum tree_code code0, code1;
   14330     17645176 :   tree op0, op1;
   14331     17645176 :   tree ret = error_mark_node;
   14332     17645176 :   const char *invalid_op_diag;
   14333     17645176 :   bool op0_int_operands, op1_int_operands;
   14334     17645176 :   bool int_const, int_const_or_overflow, int_operands;
   14335              : 
   14336              :   /* Expression code to give to the expression when it is built.
   14337              :      Normally this is CODE, which is what the caller asked for,
   14338              :      but in some special cases we change it.  */
   14339     17645176 :   enum tree_code resultcode = code;
   14340              : 
   14341              :   /* Data type in which the computation is to be performed.
   14342              :      In the simplest cases this is the common type of the arguments.  */
   14343     17645176 :   tree result_type = NULL;
   14344              : 
   14345              :   /* When the computation is in excess precision, the type of the
   14346              :      final EXCESS_PRECISION_EXPR.  */
   14347     17645176 :   tree semantic_result_type = NULL;
   14348              : 
   14349              :   /* Nonzero means operands have already been type-converted
   14350              :      in whatever way is necessary.
   14351              :      Zero means they need to be converted to RESULT_TYPE.  */
   14352     17645176 :   int converted = 0;
   14353              : 
   14354              :   /* Nonzero means create the expression with this type, rather than
   14355              :      RESULT_TYPE.  */
   14356     17645176 :   tree build_type = NULL_TREE;
   14357              : 
   14358              :   /* Nonzero means after finally constructing the expression
   14359              :      convert it to this type.  */
   14360     17645176 :   tree final_type = NULL_TREE;
   14361              : 
   14362              :   /* Nonzero if this is an operation like MIN or MAX which can
   14363              :      safely be computed in short if both args are promoted shorts.
   14364              :      Also implies COMMON.
   14365              :      -1 indicates a bitwise operation; this makes a difference
   14366              :      in the exact conditions for when it is safe to do the operation
   14367              :      in a narrower mode.  */
   14368     17645176 :   int shorten = 0;
   14369              : 
   14370              :   /* Nonzero if this is a comparison operation;
   14371              :      if both args are promoted shorts, compare the original shorts.
   14372              :      Also implies COMMON.  */
   14373     17645176 :   int short_compare = 0;
   14374              : 
   14375              :   /* Nonzero if this is a right-shift operation, which can be computed on the
   14376              :      original short and then promoted if the operand is a promoted short.  */
   14377     17645176 :   int short_shift = 0;
   14378              : 
   14379              :   /* Nonzero means set RESULT_TYPE to the common type of the args.  */
   14380     17645176 :   int common = 0;
   14381              : 
   14382              :   /* True means types are compatible as far as ObjC is concerned.  */
   14383     17645176 :   bool objc_ok;
   14384              : 
   14385              :   /* True means this is an arithmetic operation that may need excess
   14386              :      precision.  */
   14387     17645176 :   bool may_need_excess_precision;
   14388              : 
   14389              :   /* True means this is a boolean operation that converts both its
   14390              :      operands to truth-values.  */
   14391     17645176 :   bool boolean_op = false;
   14392              : 
   14393              :   /* Remember whether we're doing / or %.  */
   14394     17645176 :   bool doing_div_or_mod = false;
   14395              : 
   14396              :   /* Remember whether we're doing << or >>.  */
   14397     17645176 :   bool doing_shift = false;
   14398              : 
   14399              :   /* Tree holding instrumentation expression.  */
   14400     17645176 :   tree instrument_expr = NULL;
   14401              : 
   14402     17645176 :   if (location == UNKNOWN_LOCATION)
   14403           80 :     location = input_location;
   14404              : 
   14405     17645176 :   op0 = orig_op0;
   14406     17645176 :   op1 = orig_op1;
   14407              : 
   14408     17645176 :   op0_int_operands = EXPR_INT_CONST_OPERANDS (orig_op0);
   14409              :   if (op0_int_operands)
   14410      8834064 :     op0 = remove_c_maybe_const_expr (op0);
   14411     17645176 :   op1_int_operands = EXPR_INT_CONST_OPERANDS (orig_op1);
   14412              :   if (op1_int_operands)
   14413     12155389 :     op1 = remove_c_maybe_const_expr (op1);
   14414     29800565 :   int_operands = (op0_int_operands && op1_int_operands);
   14415     12155389 :   if (int_operands)
   14416              :     {
   14417     17308307 :       int_const_or_overflow = (TREE_CODE (orig_op0) == INTEGER_CST
   14418      8669324 :                                && TREE_CODE (orig_op1) == INTEGER_CST);
   14419      8638983 :       int_const = (int_const_or_overflow
   14420      8638983 :                    && !TREE_OVERFLOW (orig_op0)
   14421      8638914 :                    && !TREE_OVERFLOW (orig_op1));
   14422              :     }
   14423              :   else
   14424              :     int_const = int_const_or_overflow = false;
   14425              : 
   14426              :   /* Do not apply default conversion in mixed vector/scalar expression.  */
   14427     17645176 :   if (convert_p
   14428     17645176 :       && VECTOR_TYPE_P (TREE_TYPE (op0)) == VECTOR_TYPE_P (TREE_TYPE (op1)))
   14429              :     {
   14430     10835082 :       op0 = default_conversion (op0);
   14431     10835082 :       op1 = default_conversion (op1);
   14432              :     }
   14433              : 
   14434     17645176 :   orig_type0 = type0 = TREE_TYPE (op0);
   14435              : 
   14436     17645176 :   orig_type1 = type1 = TREE_TYPE (op1);
   14437              : 
   14438              :   /* The expression codes of the data types of the arguments tell us
   14439              :      whether the arguments are integers, floating, pointers, etc.  */
   14440     17645176 :   code0 = TREE_CODE (type0);
   14441     17645176 :   code1 = TREE_CODE (type1);
   14442              : 
   14443              :   /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
   14444     17645178 :   STRIP_TYPE_NOPS (op0);
   14445     17645179 :   STRIP_TYPE_NOPS (op1);
   14446              : 
   14447              :   /* If an error was already reported for one of the arguments,
   14448              :      avoid reporting another error.  */
   14449              : 
   14450     17645176 :   if (code0 == ERROR_MARK || code1 == ERROR_MARK)
   14451          710 :     return error_mark_node;
   14452              : 
   14453     17644466 :   if (code0 == POINTER_TYPE
   14454     17644466 :       && reject_gcc_builtin (op0, EXPR_LOCATION (orig_op0)))
   14455           11 :     return error_mark_node;
   14456              : 
   14457     17644455 :   if (code1 == POINTER_TYPE
   14458     17644455 :       && reject_gcc_builtin (op1, EXPR_LOCATION (orig_op1)))
   14459           11 :     return error_mark_node;
   14460              : 
   14461     35288888 :   if ((invalid_op_diag
   14462     17644444 :        = targetm.invalid_binary_op (code, type0, type1)))
   14463              :     {
   14464            0 :       error_at (location, invalid_op_diag);
   14465            0 :       return error_mark_node;
   14466              :     }
   14467              : 
   14468     17644444 :   switch (code)
   14469              :     {
   14470              :     case PLUS_EXPR:
   14471              :     case MINUS_EXPR:
   14472              :     case MULT_EXPR:
   14473              :     case TRUNC_DIV_EXPR:
   14474              :     case CEIL_DIV_EXPR:
   14475              :     case FLOOR_DIV_EXPR:
   14476              :     case ROUND_DIV_EXPR:
   14477              :     case EXACT_DIV_EXPR:
   14478              :       may_need_excess_precision = true;
   14479              :       break;
   14480              : 
   14481      2780571 :     case EQ_EXPR:
   14482      2780571 :     case NE_EXPR:
   14483      2780571 :     case LE_EXPR:
   14484      2780571 :     case GE_EXPR:
   14485      2780571 :     case LT_EXPR:
   14486      2780571 :     case GT_EXPR:
   14487              :       /* Excess precision for implicit conversions of integers to
   14488              :          floating point in C11 and later.  */
   14489      2780571 :       may_need_excess_precision = (flag_isoc11
   14490      2780571 :                                    && (ANY_INTEGRAL_TYPE_P (type0)
   14491       489375 :                                        || ANY_INTEGRAL_TYPE_P (type1)));
   14492              :       break;
   14493              : 
   14494              :     default:
   14495     17644444 :       may_need_excess_precision = false;
   14496              :       break;
   14497              :     }
   14498     17644444 :   if (TREE_CODE (op0) == EXCESS_PRECISION_EXPR)
   14499              :     {
   14500          184 :       op0 = TREE_OPERAND (op0, 0);
   14501          184 :       type0 = TREE_TYPE (op0);
   14502              :     }
   14503     17644260 :   else if (may_need_excess_precision
   14504     17644260 :            && (eptype = excess_precision_type (type0)) != NULL_TREE)
   14505              :     {
   14506          780 :       type0 = eptype;
   14507          780 :       op0 = convert (eptype, op0);
   14508              :     }
   14509     17644444 :   if (TREE_CODE (op1) == EXCESS_PRECISION_EXPR)
   14510              :     {
   14511          896 :       op1 = TREE_OPERAND (op1, 0);
   14512          896 :       type1 = TREE_TYPE (op1);
   14513              :     }
   14514     17643548 :   else if (may_need_excess_precision
   14515     17643548 :            && (eptype = excess_precision_type (type1)) != NULL_TREE)
   14516              :     {
   14517          600 :       type1 = eptype;
   14518          600 :       op1 = convert (eptype, op1);
   14519              :     }
   14520              : 
   14521     17644444 :   objc_ok = objc_compare_types (type0, type1, -3, NULL_TREE);
   14522              : 
   14523              :   /* In case when one of the operands of the binary operation is
   14524              :      a vector and another is a scalar -- convert scalar to vector.  */
   14525     19240455 :   if ((gnu_vector_type_p (type0) && code1 != VECTOR_TYPE)
   14526     19238313 :       || (gnu_vector_type_p (type1) && code0 != VECTOR_TYPE))
   14527              :     {
   14528         2768 :       enum stv_conv convert_flag = scalar_to_vector (location, code, orig_op0,
   14529              :                                                      orig_op1, true);
   14530              : 
   14531         2768 :       switch (convert_flag)
   14532              :         {
   14533           12 :           case stv_error:
   14534           12 :             return error_mark_node;
   14535          613 :           case stv_firstarg:
   14536          613 :             {
   14537          613 :               bool maybe_const = true;
   14538          613 :               tree sc;
   14539          613 :               sc = c_fully_fold (op0, false, &maybe_const);
   14540          613 :               sc = save_expr (sc);
   14541          613 :               sc = convert (TREE_TYPE (type1), sc);
   14542          613 :               op0 = build_vector_from_val (type1, sc);
   14543          613 :               if (!maybe_const)
   14544           93 :                 op0 = c_wrap_maybe_const (op0, true);
   14545          613 :               orig_type0 = type0 = TREE_TYPE (op0);
   14546          613 :               code0 = TREE_CODE (type0);
   14547          613 :               converted = 1;
   14548          613 :               break;
   14549              :             }
   14550         1264 :           case stv_secondarg:
   14551         1264 :             {
   14552         1264 :               bool maybe_const = true;
   14553         1264 :               tree sc;
   14554         1264 :               sc = c_fully_fold (op1, false, &maybe_const);
   14555         1264 :               sc = save_expr (sc);
   14556         1264 :               sc = convert (TREE_TYPE (type0), sc);
   14557         1264 :               op1 = build_vector_from_val (type0, sc);
   14558         1264 :               if (!maybe_const)
   14559           38 :                 op1 = c_wrap_maybe_const (op1, true);
   14560         1264 :               orig_type1 = type1 = TREE_TYPE (op1);
   14561         1264 :               code1 = TREE_CODE (type1);
   14562         1264 :               converted = 1;
   14563         1264 :               break;
   14564              :             }
   14565              :           default:
   14566              :             break;
   14567              :         }
   14568              :     }
   14569              : 
   14570     17644432 :   switch (code)
   14571              :     {
   14572      9211320 :     case PLUS_EXPR:
   14573              :       /* Handle the pointer + int case.  */
   14574      9211320 :       if (code0 == POINTER_TYPE
   14575      1263106 :           && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
   14576              :         {
   14577      1263100 :           ret = pointer_int_sum (location, PLUS_EXPR, op0, op1);
   14578      1263100 :           goto return_build_binary_op;
   14579              :         }
   14580      7948220 :       else if (code1 == POINTER_TYPE
   14581         1538 :                && (code0 == INTEGER_TYPE || code0 == BITINT_TYPE))
   14582              :         {
   14583         1532 :           ret = pointer_int_sum (location, PLUS_EXPR, op1, op0);
   14584         1532 :           goto return_build_binary_op;
   14585              :         }
   14586              :       else
   14587              :         common = 1;
   14588              :       break;
   14589              : 
   14590       805122 :     case MINUS_EXPR:
   14591              :       /* Subtraction of two similar pointers.
   14592              :          We must subtract them as integers, then divide by object size.  */
   14593       805122 :       if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
   14594       805122 :           && comp_target_types (location, type0, type1))
   14595              :         {
   14596         3744 :           ret = pointer_diff (location, op0, op1, &instrument_expr);
   14597         3744 :           goto return_build_binary_op;
   14598              :         }
   14599              :       /* Handle pointer minus int.  Just like pointer plus int.  */
   14600       801378 :       else if (code0 == POINTER_TYPE
   14601        17017 :                && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
   14602              :         {
   14603        17005 :           ret = pointer_int_sum (location, MINUS_EXPR, op0, op1);
   14604        17005 :           goto return_build_binary_op;
   14605              :         }
   14606              :       else
   14607              :         common = 1;
   14608              :       break;
   14609              : 
   14610              :     case MULT_EXPR:
   14611              :       common = 1;
   14612              :       break;
   14613              : 
   14614       277671 :     case TRUNC_DIV_EXPR:
   14615       277671 :     case CEIL_DIV_EXPR:
   14616       277671 :     case FLOOR_DIV_EXPR:
   14617       277671 :     case ROUND_DIV_EXPR:
   14618       277671 :     case EXACT_DIV_EXPR:
   14619       277671 :       doing_div_or_mod = true;
   14620       277671 :       warn_for_div_by_zero (location, op1);
   14621              : 
   14622       277670 :       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
   14623        50221 :            || code0 == FIXED_POINT_TYPE || code0 == BITINT_TYPE
   14624        48182 :            || code0 == COMPLEX_TYPE
   14625        46113 :            || gnu_vector_type_p (type0))
   14626       327890 :           && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
   14627        47780 :               || code1 == FIXED_POINT_TYPE || code1 == BITINT_TYPE
   14628        47589 :               || code1 == COMPLEX_TYPE
   14629        46115 :               || gnu_vector_type_p (type1)))
   14630              :         {
   14631       277666 :           enum tree_code tcode0 = code0, tcode1 = code1;
   14632              : 
   14633       277666 :           if (code0 == COMPLEX_TYPE || code0 == VECTOR_TYPE)
   14634        48181 :             tcode0 = TREE_CODE (TREE_TYPE (TREE_TYPE (op0)));
   14635       277666 :           if (code1 == COMPLEX_TYPE || code1 == VECTOR_TYPE)
   14636        47586 :             tcode1 = TREE_CODE (TREE_TYPE (TREE_TYPE (op1)));
   14637              : 
   14638       277666 :           if (!(((tcode0 == INTEGER_TYPE || tcode0 == BITINT_TYPE
   14639        70229 :                   || (tcode0 == ENUMERAL_TYPE && code0 == VECTOR_TYPE))
   14640       207438 :                  && (tcode1 == INTEGER_TYPE || tcode1 == BITINT_TYPE
   14641        12988 :                      || (tcode1 == ENUMERAL_TYPE && code1 == VECTOR_TYPE)))
   14642        83215 :                 || (tcode0 == FIXED_POINT_TYPE && tcode1 == FIXED_POINT_TYPE)))
   14643              :             resultcode = RDIV_EXPR;
   14644              :           else
   14645              :             /* Although it would be tempting to shorten always here, that
   14646              :                loses on some targets, since the modulo instruction is
   14647              :                undefined if the quotient can't be represented in the
   14648              :                computation mode.  We shorten only if unsigned or if
   14649              :                dividing by something we know != -1.  */
   14650       194451 :             shorten = may_shorten_divmod (op0, op1);
   14651              :           common = 1;
   14652              :         }
   14653              :       break;
   14654              : 
   14655      1665945 :     case BIT_AND_EXPR:
   14656      1665945 :     case BIT_IOR_EXPR:
   14657      1665945 :     case BIT_XOR_EXPR:
   14658      1665945 :       if ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE)
   14659      1125037 :           && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
   14660              :         shorten = -1;
   14661              :       /* Allow vector types which are not floating point types.   */
   14662       540944 :       else if (gnu_vector_type_p (type0)
   14663       540867 :                && gnu_vector_type_p (type1)
   14664       540867 :                && !VECTOR_FLOAT_TYPE_P (type0)
   14665      1081808 :                && !VECTOR_FLOAT_TYPE_P (type1))
   14666              :         common = 1;
   14667              :       break;
   14668              : 
   14669        59413 :     case TRUNC_MOD_EXPR:
   14670        59413 :     case FLOOR_MOD_EXPR:
   14671        59413 :       doing_div_or_mod = true;
   14672        59413 :       warn_for_div_by_zero (location, op1);
   14673              : 
   14674        59413 :       if (gnu_vector_type_p (type0)
   14675          391 :           && gnu_vector_type_p (type1)
   14676          391 :           && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
   14677        59804 :           && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE)
   14678              :         common = 1;
   14679        59022 :       else if ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE)
   14680        59021 :                && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
   14681              :         {
   14682              :           /* Although it would be tempting to shorten always here, that loses
   14683              :              on some targets, since the modulo instruction is undefined if the
   14684              :              quotient can't be represented in the computation mode.  We shorten
   14685              :              only if unsigned or if dividing by something we know != -1.  */
   14686        59021 :           shorten = may_shorten_divmod (op0, op1);
   14687        59021 :           common = 1;
   14688              :         }
   14689              :       break;
   14690              : 
   14691       515481 :     case TRUTH_ANDIF_EXPR:
   14692       515481 :     case TRUTH_ORIF_EXPR:
   14693       515481 :     case TRUTH_AND_EXPR:
   14694       515481 :     case TRUTH_OR_EXPR:
   14695       515481 :     case TRUTH_XOR_EXPR:
   14696       515481 :       if ((code0 == INTEGER_TYPE || code0 == POINTER_TYPE
   14697            0 :            || code0 == REAL_TYPE || code0 == COMPLEX_TYPE
   14698            0 :            || code0 == FIXED_POINT_TYPE || code0 == NULLPTR_TYPE
   14699            0 :            || code0 == BITINT_TYPE)
   14700       515481 :           && (code1 == INTEGER_TYPE || code1 == POINTER_TYPE
   14701          165 :               || code1 == REAL_TYPE || code1 == COMPLEX_TYPE
   14702           24 :               || code1 == FIXED_POINT_TYPE || code1 == NULLPTR_TYPE
   14703           22 :               || code1 == BITINT_TYPE))
   14704              :         {
   14705              :           /* Result of these operations is always an int,
   14706              :              but that does not mean the operands should be
   14707              :              converted to ints!  */
   14708       515481 :           result_type = integer_type_node;
   14709       515481 :           if (op0_int_operands)
   14710              :             {
   14711       110565 :               op0 = c_objc_common_truthvalue_conversion (location, orig_op0);
   14712       110565 :               op0 = remove_c_maybe_const_expr (op0);
   14713              :             }
   14714              :           else
   14715       404916 :             op0 = c_objc_common_truthvalue_conversion (location, op0);
   14716       515481 :           if (op1_int_operands)
   14717              :             {
   14718        71499 :               op1 = c_objc_common_truthvalue_conversion (location, orig_op1);
   14719        71499 :               op1 = remove_c_maybe_const_expr (op1);
   14720              :             }
   14721              :           else
   14722       443982 :             op1 = c_objc_common_truthvalue_conversion (location, op1);
   14723              :           converted = 1;
   14724              :           boolean_op = true;
   14725              :         }
   14726       515481 :       if (code == TRUTH_ANDIF_EXPR)
   14727              :         {
   14728       251205 :           int_const_or_overflow = (int_operands
   14729        63308 :                                    && TREE_CODE (orig_op0) == INTEGER_CST
   14730       251221 :                                    && (op0 == truthvalue_false_node
   14731        13232 :                                        || TREE_CODE (orig_op1) == INTEGER_CST));
   14732              :           int_const = (int_const_or_overflow
   14733        63281 :                        && !TREE_OVERFLOW (orig_op0)
   14734        63281 :                        && (op0 == truthvalue_false_node
   14735        13216 :                            || !TREE_OVERFLOW (orig_op1)));
   14736              :         }
   14737       327557 :       else if (code == TRUTH_ORIF_EXPR)
   14738              :         {
   14739       334238 :           int_const_or_overflow = (int_operands
   14740         6832 :                                    && TREE_CODE (orig_op0) == INTEGER_CST
   14741       334261 :                                    && (op0 == truthvalue_true_node
   14742         2147 :                                        || TREE_CODE (orig_op1) == INTEGER_CST));
   14743              :           int_const = (int_const_or_overflow
   14744         6802 :                        && !TREE_OVERFLOW (orig_op0)
   14745         6802 :                        && (op0 == truthvalue_true_node
   14746         2124 :                            || !TREE_OVERFLOW (orig_op1)));
   14747              :         }
   14748              :       break;
   14749              : 
   14750              :       /* Shift operations: result has same type as first operand;
   14751              :          always convert second operand to int.
   14752              :          Also set SHORT_SHIFT if shifting rightward.  */
   14753              : 
   14754       234989 :     case RSHIFT_EXPR:
   14755       234989 :       if (gnu_vector_type_p (type0)
   14756          848 :           && gnu_vector_type_p (type1)
   14757          258 :           && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
   14758          256 :           && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE
   14759       235245 :           && known_eq (TYPE_VECTOR_SUBPARTS (type0),
   14760              :                        TYPE_VECTOR_SUBPARTS (type1)))
   14761              :         {
   14762              :           result_type = type0;
   14763              :           converted = 1;
   14764              :         }
   14765       234735 :       else if ((code0 == INTEGER_TYPE || code0 == FIXED_POINT_TYPE
   14766         1303 :                 || code0 == BITINT_TYPE
   14767          598 :                 || (gnu_vector_type_p (type0)
   14768          594 :                     && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE))
   14769       236031 :                && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
   14770              :         {
   14771       234726 :           doing_shift = true;
   14772       234726 :           if (TREE_CODE (op1) == INTEGER_CST)
   14773              :             {
   14774       205018 :               if (tree_int_cst_sgn (op1) < 0)
   14775              :                 {
   14776          269 :                   int_const = false;
   14777          269 :                   if (c_inhibit_evaluation_warnings == 0)
   14778          129 :                     warning_at (location, OPT_Wshift_count_negative,
   14779              :                                 "right shift count is negative");
   14780              :                 }
   14781       204749 :               else if (code0 == VECTOR_TYPE)
   14782              :                 {
   14783          490 :                   if (compare_tree_int (op1,
   14784          490 :                                         TYPE_PRECISION (TREE_TYPE (type0)))
   14785              :                       >= 0)
   14786              :                     {
   14787           16 :                       int_const = false;
   14788           16 :                       if (c_inhibit_evaluation_warnings == 0)
   14789           16 :                         warning_at (location, OPT_Wshift_count_overflow,
   14790              :                                     "right shift count >= width of vector element");
   14791              :                     }
   14792              :                 }
   14793              :               else
   14794              :                 {
   14795       204259 :                   if (!integer_zerop (op1))
   14796       203896 :                     short_shift = 1;
   14797              : 
   14798       204259 :                   if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0)
   14799              :                     {
   14800          586 :                       int_const = false;
   14801          586 :                       if (c_inhibit_evaluation_warnings == 0)
   14802           52 :                         warning_at (location, OPT_Wshift_count_overflow,
   14803              :                                     "right shift count >= width of type");
   14804              :                     }
   14805              :                 }
   14806              :             }
   14807              : 
   14808              :           /* Use the type of the value to be shifted.  */
   14809              :           result_type = type0;
   14810              :           /* Avoid converting op1 to result_type later.  */
   14811              :           converted = 1;
   14812              :         }
   14813              :       break;
   14814              : 
   14815       810752 :     case LSHIFT_EXPR:
   14816       810752 :       if (gnu_vector_type_p (type0)
   14817          599 :           && gnu_vector_type_p (type1)
   14818          316 :           && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
   14819          314 :           && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE
   14820       811065 :           && known_eq (TYPE_VECTOR_SUBPARTS (type0),
   14821              :                        TYPE_VECTOR_SUBPARTS (type1)))
   14822              :         {
   14823              :           result_type = type0;
   14824              :           converted = 1;
   14825              :         }
   14826       810441 :       else if ((code0 == INTEGER_TYPE || code0 == FIXED_POINT_TYPE
   14827          963 :                 || code0 == BITINT_TYPE
   14828          294 :                 || (gnu_vector_type_p (type0)
   14829          288 :                     && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE))
   14830       811395 :                && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
   14831              :         {
   14832       810427 :           doing_shift = true;
   14833       810427 :           if (TREE_CODE (op0) == INTEGER_CST
   14834       442379 :               && tree_int_cst_sgn (op0) < 0
   14835       811176 :               && !TYPE_OVERFLOW_WRAPS (type0))
   14836              :             {
   14837              :               /* Don't reject a left shift of a negative value in a context
   14838              :                  where a constant expression is needed in C90.  */
   14839          712 :               if (flag_isoc99)
   14840          666 :                 int_const = false;
   14841          712 :               if (c_inhibit_evaluation_warnings == 0)
   14842          712 :                 warning_at (location, OPT_Wshift_negative_value,
   14843              :                             "left shift of negative value");
   14844              :             }
   14845       810427 :           if (TREE_CODE (op1) == INTEGER_CST)
   14846              :             {
   14847       737406 :               if (tree_int_cst_sgn (op1) < 0)
   14848              :                 {
   14849          313 :                   int_const = false;
   14850          313 :                   if (c_inhibit_evaluation_warnings == 0)
   14851          135 :                     warning_at (location, OPT_Wshift_count_negative,
   14852              :                                 "left shift count is negative");
   14853              :                 }
   14854       737093 :               else if (code0 == VECTOR_TYPE)
   14855              :                 {
   14856          216 :                   if (compare_tree_int (op1,
   14857          216 :                                         TYPE_PRECISION (TREE_TYPE (type0)))
   14858              :                       >= 0)
   14859              :                     {
   14860            6 :                       int_const = false;
   14861            6 :                       if (c_inhibit_evaluation_warnings == 0)
   14862            6 :                         warning_at (location, OPT_Wshift_count_overflow,
   14863              :                                     "left shift count >= width of vector element");
   14864              :                     }
   14865              :                 }
   14866       736877 :               else if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0)
   14867              :                 {
   14868        29733 :                   int_const = false;
   14869        29733 :                   if (c_inhibit_evaluation_warnings == 0)
   14870          113 :                     warning_at (location, OPT_Wshift_count_overflow,
   14871              :                                 "left shift count >= width of type");
   14872              :                 }
   14873       707144 :               else if (TREE_CODE (op0) == INTEGER_CST
   14874       368286 :                        && maybe_warn_shift_overflow (location, op0, op1)
   14875       707772 :                        && flag_isoc99)
   14876              :                 int_const = false;
   14877              :             }
   14878              : 
   14879              :           /* Use the type of the value to be shifted.  */
   14880              :           result_type = type0;
   14881              :           /* Avoid converting op1 to result_type later.  */
   14882              :           converted = 1;
   14883              :         }
   14884              :       break;
   14885              : 
   14886      1764495 :     case EQ_EXPR:
   14887      1764495 :     case NE_EXPR:
   14888      1764495 :       if (gnu_vector_type_p (type0) && gnu_vector_type_p (type1))
   14889              :         {
   14890        42300 :           tree intt;
   14891        42300 :           if (!vector_types_compatible_elements_p (type0, type1))
   14892              :             {
   14893            4 :               error_at (location, "comparing vectors with different "
   14894              :                                   "element types");
   14895            4 :               return error_mark_node;
   14896              :             }
   14897              : 
   14898        42296 :           if (maybe_ne (TYPE_VECTOR_SUBPARTS (type0),
   14899        84592 :                         TYPE_VECTOR_SUBPARTS (type1)))
   14900              :             {
   14901            1 :               error_at (location, "comparing vectors with different "
   14902              :                                   "number of elements");
   14903            1 :               return error_mark_node;
   14904              :             }
   14905              : 
   14906              :           /* It's not precisely specified how the usual arithmetic
   14907              :              conversions apply to the vector types.  Here, we use
   14908              :              the unsigned type if one of the operands is signed and
   14909              :              the other one is unsigned.  */
   14910        42295 :           if (TYPE_UNSIGNED (type0) != TYPE_UNSIGNED (type1))
   14911              :             {
   14912            4 :               if (!TYPE_UNSIGNED (type0))
   14913            4 :                 op0 = build1 (VIEW_CONVERT_EXPR, type1, op0);
   14914              :               else
   14915            0 :                 op1 = build1 (VIEW_CONVERT_EXPR, type0, op1);
   14916            4 :               warning_at (location, OPT_Wsign_compare, "comparison between "
   14917              :                           "types %qT and %qT", type0, type1);
   14918              :             }
   14919              : 
   14920              :           /* Always construct signed integer vector type.  */
   14921        42295 :           if (VECTOR_BOOLEAN_TYPE_P (type0) && VECTOR_BOOLEAN_TYPE_P (type1))
   14922              :             result_type = type0;
   14923              :           else
   14924              :             {
   14925        42295 :               auto nelts = TYPE_VECTOR_SUBPARTS (type0);
   14926              : 
   14927       126885 :               intt = c_common_type_for_size (GET_MODE_BITSIZE
   14928        84590 :                                              (SCALAR_TYPE_MODE
   14929              :                                                 (TREE_TYPE (type0))), 0);
   14930        42295 :               if (!intt)
   14931              :                 {
   14932            0 :                   error_at (location, "could not find an integer type "
   14933              :                                       "of the same size as %qT",
   14934            0 :                             TREE_TYPE (type0));
   14935            0 :                   return error_mark_node;
   14936              :                 }
   14937        42295 :               result_type = build_opaque_vector_type (intt, nelts);
   14938              :             }
   14939        42295 :           converted = 1;
   14940        42295 :           ret = build_vec_cmp (resultcode, result_type, op0, op1);
   14941        42295 :           goto return_build_binary_op;
   14942              :         }
   14943      1722195 :       if (FLOAT_TYPE_P (type0) || FLOAT_TYPE_P (type1))
   14944       255341 :         warning_at (location,
   14945       255341 :                     OPT_Wfloat_equal,
   14946              :                     "comparing floating-point with %<==%> or %<!=%> is unsafe");
   14947              :       /* Result of comparison is always int,
   14948              :          but don't convert the args to int!  */
   14949      1722195 :       build_type = integer_type_node;
   14950      1722195 :       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == BITINT_TYPE
   14951       159718 :            || code0 == FIXED_POINT_TYPE || code0 == COMPLEX_TYPE)
   14952      1598524 :           && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
   14953              :               || code1 == BITINT_TYPE
   14954              :               || code1 == FIXED_POINT_TYPE || code1 == COMPLEX_TYPE))
   14955              :         short_compare = 1;
   14956       123937 :       else if (code0 == POINTER_TYPE
   14957       123937 :                && (code1 == NULLPTR_TYPE
   14958       123554 :                    || null_pointer_constant_p (orig_op1)))
   14959              :         {
   14960        52261 :           maybe_warn_for_null_address (location, op0, code);
   14961        52261 :           result_type = type0;
   14962              :         }
   14963        71676 :       else if (code1 == POINTER_TYPE
   14964        71676 :                && (code0 == NULLPTR_TYPE
   14965        71574 :                    || null_pointer_constant_p (orig_op0)))
   14966              :         {
   14967          294 :           maybe_warn_for_null_address (location, op1, code);
   14968          294 :           result_type = type1;
   14969              :         }
   14970        71382 :       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
   14971              :         {
   14972        71292 :           tree tt0 = TREE_TYPE (type0);
   14973        71292 :           tree tt1 = TREE_TYPE (type1);
   14974        71292 :           addr_space_t as0 = TYPE_ADDR_SPACE (tt0);
   14975        71292 :           addr_space_t as1 = TYPE_ADDR_SPACE (tt1);
   14976        71292 :           addr_space_t as_common = ADDR_SPACE_GENERIC;
   14977              : 
   14978              :           /* Anything compares with void *.  void * compares with anything.
   14979              :              Otherwise, the targets must be compatible
   14980              :              and both must be object or both incomplete.  */
   14981        71292 :           if (comp_target_types (location, type0, type1))
   14982        49926 :             result_type = common_pointer_type (type0, type1, NULL_TREE);
   14983        21366 :           else if (!addr_space_superset (as0, as1, &as_common))
   14984              :             {
   14985            0 :               error_at (location, "comparison of pointers to "
   14986              :                         "disjoint address spaces");
   14987            0 :               return error_mark_node;
   14988              :             }
   14989        21366 :           else if (VOID_TYPE_P (tt0) && !TYPE_ATOMIC (tt0))
   14990              :             {
   14991        21111 :               if (pedantic && TREE_CODE (tt1) == FUNCTION_TYPE)
   14992            4 :                 pedwarn (location, OPT_Wpedantic, "ISO C forbids "
   14993              :                          "comparison of %<void *%> with function pointer");
   14994              :             }
   14995          255 :           else if (VOID_TYPE_P (tt1) && !TYPE_ATOMIC (tt1))
   14996              :             {
   14997          207 :               if (pedantic && TREE_CODE (tt0) == FUNCTION_TYPE)
   14998            4 :                 pedwarn (location, OPT_Wpedantic, "ISO C forbids "
   14999              :                          "comparison of %<void *%> with function pointer");
   15000              :             }
   15001              :           else
   15002              :             /* Avoid warning about the volatile ObjC EH puts on decls.  */
   15003           48 :             if (!objc_ok)
   15004           48 :               pedwarn (location, OPT_Wcompare_distinct_pointer_types,
   15005              :                        "comparison of distinct pointer types lacks a cast");
   15006              : 
   15007        49982 :           if (result_type == NULL_TREE)
   15008              :             {
   15009        21366 :               qualifier_set qual {TYPE_UNQUALIFIED, as_common};
   15010        21366 :               result_type = c_build_pointer_type
   15011        21366 :                               (c_build_qualified_type (void_type_node, qual));
   15012              :             }
   15013              :         }
   15014           90 :       else if (code0 == POINTER_TYPE
   15015           26 :                && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
   15016              :         {
   15017           26 :           result_type = type0;
   15018           26 :           pedwarn (location, 0, "comparison between pointer and integer");
   15019              :         }
   15020           64 :       else if ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE)
   15021           21 :                && code1 == POINTER_TYPE)
   15022              :         {
   15023            8 :           result_type = type1;
   15024            8 :           pedwarn (location, 0, "comparison between pointer and integer");
   15025              :         }
   15026              :       /* 6.5.9: One of the following shall hold:
   15027              :          -- both operands have type nullptr_t;  */
   15028           56 :       else if (code0 == NULLPTR_TYPE && code1 == NULLPTR_TYPE)
   15029              :         {
   15030           22 :           result_type = nullptr_type_node;
   15031              :           /* No need to convert the operands to result_type later.  */
   15032           22 :           converted = 1;
   15033              :         }
   15034              :     /* -- one operand has type nullptr_t and the other is a null pointer
   15035              :        constant.  We will have to convert the former to the type of the
   15036              :        latter, because during gimplification we can't have mismatching
   15037              :        comparison operand type.  We convert from nullptr_t to the other
   15038              :        type, since only nullptr_t can be converted to nullptr_t.  Also,
   15039              :        even a constant 0 is a null pointer constant, so we may have to
   15040              :        create a pointer type from its type.  */
   15041           34 :       else if (code0 == NULLPTR_TYPE && null_pointer_constant_p (orig_op1))
   15042           19 :         result_type = (INTEGRAL_TYPE_P (type1)
   15043           19 :                        ? c_build_pointer_type (type1) : type1);
   15044           15 :       else if (code1 == NULLPTR_TYPE && null_pointer_constant_p (orig_op0))
   15045           11 :         result_type = (INTEGRAL_TYPE_P (type0)
   15046           11 :                        ? c_build_pointer_type (type0) : type0);
   15047      5090676 :       if ((C_BOOLEAN_TYPE_P (TREE_TYPE (orig_op0))
   15048      3368456 :            || truth_value_p (TREE_CODE (orig_op0)))
   15049      3436957 :           ^ (C_BOOLEAN_TYPE_P (TREE_TYPE (orig_op1))
   15050      3436953 :              || truth_value_p (TREE_CODE (orig_op1))))
   15051        72810 :         maybe_warn_bool_compare (location, code, orig_op0, orig_op1);
   15052              :       break;
   15053              : 
   15054      1016072 :     case LE_EXPR:
   15055      1016072 :     case GE_EXPR:
   15056      1016072 :     case LT_EXPR:
   15057      1016072 :     case GT_EXPR:
   15058      1016072 :       if (gnu_vector_type_p (type0) && gnu_vector_type_p (type1))
   15059              :         {
   15060        59720 :           tree intt;
   15061        59720 :           if (!vector_types_compatible_elements_p (type0, type1))
   15062              :             {
   15063            5 :               error_at (location, "comparing vectors with different "
   15064              :                                   "element types");
   15065            5 :               return error_mark_node;
   15066              :             }
   15067              : 
   15068        59715 :           if (maybe_ne (TYPE_VECTOR_SUBPARTS (type0),
   15069       119430 :                         TYPE_VECTOR_SUBPARTS (type1)))
   15070              :             {
   15071            0 :               error_at (location, "comparing vectors with different "
   15072              :                                   "number of elements");
   15073            0 :               return error_mark_node;
   15074              :             }
   15075              : 
   15076              :           /* It's not precisely specified how the usual arithmetic
   15077              :              conversions apply to the vector types.  Here, we use
   15078              :              the unsigned type if one of the operands is signed and
   15079              :              the other one is unsigned.  */
   15080        59715 :           if (TYPE_UNSIGNED (type0) != TYPE_UNSIGNED (type1))
   15081              :             {
   15082           15 :               if (!TYPE_UNSIGNED (type0))
   15083            8 :                 op0 = build1 (VIEW_CONVERT_EXPR, type1, op0);
   15084              :               else
   15085            7 :                 op1 = build1 (VIEW_CONVERT_EXPR, type0, op1);
   15086           15 :               warning_at (location, OPT_Wsign_compare, "comparison between "
   15087              :                           "types %qT and %qT", type0, type1);
   15088              :             }
   15089              : 
   15090              :           /* Always construct signed integer vector type.  */
   15091       179145 :           intt = c_common_type_for_size (GET_MODE_BITSIZE
   15092       119430 :                                          (SCALAR_TYPE_MODE
   15093              :                                           (TREE_TYPE (type0))), 0);
   15094        59715 :           if (!intt)
   15095              :             {
   15096            0 :               error_at (location, "could not find an integer type "
   15097              :                                   "of the same size as %qT",
   15098            0 :                         TREE_TYPE (type0));
   15099            0 :               return error_mark_node;
   15100              :             }
   15101        59715 :           result_type = build_opaque_vector_type (intt,
   15102        59715 :                                                   TYPE_VECTOR_SUBPARTS (type0));
   15103        59715 :           converted = 1;
   15104        59715 :           ret = build_vec_cmp (resultcode, result_type, op0, op1);
   15105        59715 :           goto return_build_binary_op;
   15106              :         }
   15107       956352 :       build_type = integer_type_node;
   15108       956352 :       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
   15109        65190 :            || code0 == BITINT_TYPE || code0 == FIXED_POINT_TYPE)
   15110       891767 :           && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
   15111              :               || code1 == BITINT_TYPE || code1 == FIXED_POINT_TYPE))
   15112              :         short_compare = 1;
   15113        64617 :       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
   15114              :         {
   15115        64550 :           addr_space_t as0 = TYPE_ADDR_SPACE (TREE_TYPE (type0));
   15116        64550 :           addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (type1));
   15117        64550 :           addr_space_t as_common;
   15118              : 
   15119        64550 :           if (comp_target_types (location, type0, type1))
   15120              :             {
   15121        64385 :               result_type = common_pointer_type (type0, type1, NULL_TREE);
   15122        64385 :               if (!COMPLETE_TYPE_P (TREE_TYPE (type0))
   15123        64385 :                   != !COMPLETE_TYPE_P (TREE_TYPE (type1)))
   15124           32 :                 pedwarn_c99 (location, OPT_Wpedantic,
   15125              :                              "comparison of complete and incomplete pointers");
   15126        64353 :               else if (TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE)
   15127            0 :                 pedwarn (location, OPT_Wpedantic, "ISO C forbids "
   15128              :                          "ordered comparisons of pointers to functions");
   15129        64353 :               else if (null_pointer_constant_p (orig_op0)
   15130        64353 :                        || null_pointer_constant_p (orig_op1))
   15131            8 :                 warning_at (location, OPT_Wextra,
   15132              :                             "ordered comparison of pointer with null pointer");
   15133              : 
   15134              :             }
   15135          165 :           else if (!addr_space_superset (as0, as1, &as_common))
   15136              :             {
   15137            0 :               error_at (location, "comparison of pointers to "
   15138              :                         "disjoint address spaces");
   15139            0 :               return error_mark_node;
   15140              :             }
   15141              :           else
   15142              :             {
   15143          165 :               qualifier_set qual {TYPE_UNQUALIFIED, as_common};
   15144          165 :               result_type = c_build_pointer_type
   15145          165 :                               (c_build_qualified_type (void_type_node, qual));
   15146          165 :               pedwarn (location, OPT_Wcompare_distinct_pointer_types,
   15147              :                        "comparison of distinct pointer types lacks a cast");
   15148              :             }
   15149              :         }
   15150           67 :       else if (code0 == POINTER_TYPE && null_pointer_constant_p (orig_op1))
   15151              :         {
   15152           17 :           result_type = type0;
   15153           17 :           if (pedantic)
   15154           11 :             pedwarn (location, OPT_Wpedantic,
   15155              :                      "ordered comparison of pointer with integer zero");
   15156            6 :           else if (extra_warnings)
   15157            1 :             warning_at (location, OPT_Wextra,
   15158              :                         "ordered comparison of pointer with integer zero");
   15159              :         }
   15160           50 :       else if (code1 == POINTER_TYPE && null_pointer_constant_p (orig_op0))
   15161              :         {
   15162           12 :           result_type = type1;
   15163           12 :           if (pedantic)
   15164            2 :             pedwarn (location, OPT_Wpedantic,
   15165              :                      "ordered comparison of pointer with integer zero");
   15166           10 :           else if (extra_warnings)
   15167            1 :             warning_at (location, OPT_Wextra,
   15168              :                         "ordered comparison of pointer with integer zero");
   15169              :         }
   15170           38 :       else if (code0 == POINTER_TYPE
   15171           18 :                && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
   15172              :         {
   15173           18 :           result_type = type0;
   15174           18 :           pedwarn (location, 0, "comparison between pointer and integer");
   15175              :         }
   15176           20 :       else if ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE)
   15177           20 :                && code1 == POINTER_TYPE)
   15178              :         {
   15179           18 :           result_type = type1;
   15180           18 :           pedwarn (location, 0, "comparison between pointer and integer");
   15181              :         }
   15182              : 
   15183       956352 :       if ((code0 == POINTER_TYPE || code1 == POINTER_TYPE)
   15184        64615 :           && current_function_decl != NULL_TREE
   15185      1020956 :           && sanitize_flags_p (SANITIZE_POINTER_COMPARE))
   15186              :         {
   15187           35 :           op0 = save_expr (c_fully_fold (op0, false, NULL));
   15188           35 :           op1 = save_expr (c_fully_fold (op1, false, NULL));
   15189              : 
   15190           35 :           tree tt = builtin_decl_explicit (BUILT_IN_ASAN_POINTER_COMPARE);
   15191           35 :           instrument_expr = build_call_expr_loc (location, tt, 2, op0, op1);
   15192              :         }
   15193              : 
   15194      2868958 :       if ((C_BOOLEAN_TYPE_P (TREE_TYPE (orig_op0))
   15195      1912606 :            || truth_value_p (TREE_CODE (orig_op0)))
   15196      1912623 :           ^ (C_BOOLEAN_TYPE_P (TREE_TYPE (orig_op1))
   15197      1912623 :              || truth_value_p (TREE_CODE (orig_op1))))
   15198          526 :         maybe_warn_bool_compare (location, code, orig_op0, orig_op1);
   15199              :       break;
   15200              : 
   15201           43 :     case MIN_EXPR:
   15202           43 :     case MAX_EXPR:
   15203              :       /* Used for OpenMP atomics.  */
   15204           43 :       gcc_assert (flag_openmp);
   15205              :       common = 1;
   15206              :       break;
   15207              : 
   15208            0 :     default:
   15209            0 :       gcc_unreachable ();
   15210              :     }
   15211              : 
   15212     16257030 :   if (code0 == ERROR_MARK || code1 == ERROR_MARK)
   15213            0 :     return error_mark_node;
   15214              : 
   15215     16257030 :   if (gnu_vector_type_p (type0)
   15216      1494600 :       && gnu_vector_type_p (type1)
   15217     17750756 :       && (!tree_int_cst_equal (TYPE_SIZE (type0), TYPE_SIZE (type1))
   15218      1493706 :           || !vector_types_compatible_elements_p (type0, type1)))
   15219              :     {
   15220           26 :       gcc_rich_location richloc (location);
   15221           26 :       maybe_range_label_for_tree_type_mismatch
   15222           26 :         label_for_op0 (orig_op0, orig_op1),
   15223           26 :         label_for_op1 (orig_op1, orig_op0);
   15224           26 :       richloc.maybe_add_expr (orig_op0, &label_for_op0, highlight_colors::lhs);
   15225           26 :       richloc.maybe_add_expr (orig_op1, &label_for_op1, highlight_colors::rhs);
   15226           26 :       binary_op_error (&richloc, code, type0, type1);
   15227           26 :       return error_mark_node;
   15228           26 :     }
   15229              : 
   15230     16257004 :   if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE
   15231      1753324 :        || code0 == FIXED_POINT_TYPE || code0 == BITINT_TYPE
   15232      1683245 :        || gnu_vector_type_p (type0))
   15233     17821657 :       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE || code1 == COMPLEX_TYPE
   15234      1588666 :           || code1 == FIXED_POINT_TYPE || code1 == BITINT_TYPE
   15235      1495834 :           || gnu_vector_type_p (type1)))
   15236              :     {
   15237     16066204 :       bool first_complex = (code0 == COMPLEX_TYPE);
   15238     16066204 :       bool second_complex = (code1 == COMPLEX_TYPE);
   15239     16066204 :       int none_complex = (!first_complex && !second_complex);
   15240              : 
   15241     16066204 :       if (shorten || common || short_compare)
   15242              :         {
   15243     14506745 :           result_type = c_common_type (type0, type1);
   15244     14506745 :           do_warn_double_promotion (result_type, type0, type1,
   15245              :                                     "implicit conversion from %qT to %qT "
   15246              :                                     "to match other operand of binary "
   15247              :                                     "expression",
   15248              :                                     location);
   15249     14506745 :           if (result_type == error_mark_node)
   15250              :             return error_mark_node;
   15251              :         }
   15252              : 
   15253     16066182 :       if (first_complex != second_complex
   15254        82085 :           && (code == PLUS_EXPR
   15255              :               || code == MINUS_EXPR
   15256        82085 :               || code == MULT_EXPR
   15257        17533 :               || (code == TRUNC_DIV_EXPR && first_complex))
   15258        65973 :           && TREE_CODE (TREE_TYPE (result_type)) == REAL_TYPE
   15259     16128437 :           && flag_signed_zeros)
   15260              :         {
   15261              :           /* An operation on mixed real/complex operands must be
   15262              :              handled specially, but the language-independent code can
   15263              :              more easily optimize the plain complex arithmetic if
   15264              :              -fno-signed-zeros.  */
   15265        61943 :           tree real_type = TREE_TYPE (result_type);
   15266        61943 :           tree real, imag;
   15267        61943 :           if (type0 != orig_type0 || type1 != orig_type1)
   15268              :             {
   15269           94 :               gcc_assert (may_need_excess_precision && common);
   15270           94 :               semantic_result_type = c_common_type (orig_type0, orig_type1);
   15271              :             }
   15272        61943 :           if (first_complex)
   15273              :             {
   15274         8253 :               if (TREE_TYPE (op0) != result_type)
   15275         1787 :                 op0 = convert_and_check (location, result_type, op0);
   15276         8253 :               if (TREE_TYPE (op1) != real_type)
   15277         4601 :                 op1 = convert_and_check (location, real_type, op1);
   15278              :             }
   15279              :           else
   15280              :             {
   15281        53690 :               if (TREE_TYPE (op0) != real_type)
   15282         2698 :                 op0 = convert_and_check (location, real_type, op0);
   15283        53690 :               if (TREE_TYPE (op1) != result_type)
   15284         1866 :                 op1 = convert_and_check (location, result_type, op1);
   15285              :             }
   15286        61943 :           if (TREE_CODE (op0) == ERROR_MARK || TREE_CODE (op1) == ERROR_MARK)
   15287            0 :             return error_mark_node;
   15288        61943 :           if (first_complex)
   15289              :             {
   15290         8253 :               op0 = save_expr (op0);
   15291         8253 :               real = build_unary_op (EXPR_LOCATION (orig_op0), REALPART_EXPR,
   15292              :                                      op0, true);
   15293         8253 :               imag = build_unary_op (EXPR_LOCATION (orig_op0), IMAGPART_EXPR,
   15294              :                                      op0, true);
   15295         8253 :               switch (code)
   15296              :                 {
   15297         3488 :                 case MULT_EXPR:
   15298         3488 :                 case TRUNC_DIV_EXPR:
   15299         3488 :                   op1 = save_expr (op1);
   15300         3488 :                   imag = build2 (resultcode, real_type, imag, op1);
   15301              :                   /* Fall through.  */
   15302         8253 :                 case PLUS_EXPR:
   15303         8253 :                 case MINUS_EXPR:
   15304         8253 :                   real = build2 (resultcode, real_type, real, op1);
   15305         8253 :                   break;
   15306              :                 default:
   15307              :                   gcc_unreachable();
   15308              :                 }
   15309              :             }
   15310              :           else
   15311              :             {
   15312        53690 :               op1 = save_expr (op1);
   15313        53690 :               real = build_unary_op (EXPR_LOCATION (orig_op1), REALPART_EXPR,
   15314              :                                      op1, true);
   15315        53690 :               imag = build_unary_op (EXPR_LOCATION (orig_op1), IMAGPART_EXPR,
   15316              :                                      op1, true);
   15317        53690 :               switch (code)
   15318              :                 {
   15319         2008 :                 case MULT_EXPR:
   15320         2008 :                   op0 = save_expr (op0);
   15321         2008 :                   imag = build2 (resultcode, real_type, op0, imag);
   15322              :                   /* Fall through.  */
   15323        31958 :                 case PLUS_EXPR:
   15324        31958 :                   real = build2 (resultcode, real_type, op0, real);
   15325        31958 :                   break;
   15326        21732 :                 case MINUS_EXPR:
   15327        21732 :                   real = build2 (resultcode, real_type, op0, real);
   15328        21732 :                   imag = build1 (NEGATE_EXPR, real_type, imag);
   15329        21732 :                   break;
   15330            0 :                 default:
   15331            0 :                   gcc_unreachable();
   15332              :                 }
   15333              :             }
   15334        61943 :           ret = build2 (COMPLEX_EXPR, result_type, real, imag);
   15335        61943 :           goto return_build_binary_op;
   15336              :         }
   15337              : 
   15338              :       /* For certain operations (which identify themselves by shorten != 0)
   15339              :          if both args were extended from the same smaller type,
   15340              :          do the arithmetic in that type and then extend.
   15341              : 
   15342              :          shorten !=0 and !=1 indicates a bitwise operation.
   15343              :          For them, this optimization is safe only if
   15344              :          both args are zero-extended or both are sign-extended.
   15345              :          Otherwise, we might change the result.
   15346              :          Eg, (short)-1 | (unsigned short)-1 is (int)-1
   15347              :          but calculated in (unsigned short) it would be (unsigned short)-1.  */
   15348              : 
   15349     16004239 :       if (shorten && none_complex)
   15350              :         {
   15351      1371357 :           final_type = result_type;
   15352      1371357 :           result_type = shorten_binary_op (result_type, op0, op1,
   15353              :                                            shorten == -1);
   15354              :         }
   15355              : 
   15356              :       /* Shifts can be shortened if shifting right.  */
   15357              : 
   15358     16004239 :       if (short_shift)
   15359              :         {
   15360       203896 :           int unsigned_arg;
   15361       203896 :           tree arg0 = get_narrower (op0, &unsigned_arg);
   15362              : 
   15363       203896 :           final_type = result_type;
   15364              : 
   15365       203896 :           if (arg0 == op0 && final_type == TREE_TYPE (op0))
   15366       143735 :             unsigned_arg = TYPE_UNSIGNED (TREE_TYPE (op0));
   15367              : 
   15368       203896 :           if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type)
   15369         3072 :               && tree_int_cst_sgn (op1) > 0
   15370              :               /* We can shorten only if the shift count is less than the
   15371              :                  number of bits in the smaller type size.  */
   15372         3072 :               && compare_tree_int (op1, TYPE_PRECISION (TREE_TYPE (arg0))) < 0
   15373              :               /* We cannot drop an unsigned shift after sign-extension.  */
   15374       206827 :               && (!TYPE_UNSIGNED (final_type) || unsigned_arg))
   15375              :             {
   15376              :               /* Do an unsigned shift if the operand was zero-extended.  */
   15377         2916 :               result_type
   15378         2916 :                 = c_common_signed_or_unsigned_type (unsigned_arg,
   15379         2916 :                                                     TREE_TYPE (arg0));
   15380              :               /* Convert value-to-be-shifted to that type.  */
   15381         2916 :               if (TREE_TYPE (op0) != result_type)
   15382         2916 :                 op0 = convert (result_type, op0);
   15383              :               converted = 1;
   15384              :             }
   15385              :         }
   15386              : 
   15387              :       /* Comparison operations are shortened too but differently.
   15388              :          They identify themselves by setting short_compare = 1.  */
   15389              : 
   15390     16004239 :       if (short_compare)
   15391              :         {
   15392              :           /* Don't write &op0, etc., because that would prevent op0
   15393              :              from being kept in a register.
   15394              :              Instead, make copies of the our local variables and
   15395              :              pass the copies by reference, then copy them back afterward.  */
   15396      2489991 :           tree xop0 = op0, xop1 = op1, xresult_type = result_type;
   15397      2489991 :           enum tree_code xresultcode = resultcode;
   15398      2489991 :           tree val
   15399      2489991 :             = shorten_compare (location, &xop0, &xop1, &xresult_type,
   15400              :                                &xresultcode);
   15401              : 
   15402      2489991 :           if (val != NULL_TREE)
   15403              :             {
   15404        15927 :               ret = val;
   15405        15927 :               goto return_build_binary_op;
   15406              :             }
   15407              : 
   15408      2474064 :           op0 = xop0, op1 = xop1;
   15409      2474064 :           converted = 1;
   15410      2474064 :           resultcode = xresultcode;
   15411              : 
   15412      2474064 :           if (c_inhibit_evaluation_warnings == 0 && !c_in_omp_for)
   15413              :             {
   15414      2326446 :               bool op0_maybe_const = true;
   15415      2326446 :               bool op1_maybe_const = true;
   15416      2326446 :               tree orig_op0_folded, orig_op1_folded;
   15417              : 
   15418      2326446 :               if (in_late_binary_op)
   15419              :                 {
   15420              :                   orig_op0_folded = orig_op0;
   15421              :                   orig_op1_folded = orig_op1;
   15422              :                 }
   15423              :               else
   15424              :                 {
   15425              :                   /* Fold for the sake of possible warnings, as in
   15426              :                      build_conditional_expr.  This requires the
   15427              :                      "original" values to be folded, not just op0 and
   15428              :                      op1.  */
   15429      2317782 :                   c_inhibit_evaluation_warnings++;
   15430      2317782 :                   op0 = c_fully_fold (op0, require_constant_value,
   15431              :                                       &op0_maybe_const);
   15432      2317782 :                   op1 = c_fully_fold (op1, require_constant_value,
   15433              :                                       &op1_maybe_const);
   15434      2317782 :                   c_inhibit_evaluation_warnings--;
   15435      2317782 :                   orig_op0_folded = c_fully_fold (orig_op0,
   15436              :                                                   require_constant_value,
   15437              :                                                   NULL);
   15438      2317782 :                   orig_op1_folded = c_fully_fold (orig_op1,
   15439              :                                                   require_constant_value,
   15440              :                                                   NULL);
   15441              :                 }
   15442              : 
   15443      2326446 :               if (warn_sign_compare)
   15444       377742 :                 warn_for_sign_compare (location, orig_op0_folded,
   15445              :                                        orig_op1_folded, op0, op1,
   15446              :                                        result_type, resultcode);
   15447      2326446 :               if (!in_late_binary_op && !int_operands)
   15448              :                 {
   15449      2137904 :                   if (!op0_maybe_const || TREE_CODE (op0) != INTEGER_CST)
   15450      2134394 :                     op0 = c_wrap_maybe_const (op0, !op0_maybe_const);
   15451      2137904 :                   if (!op1_maybe_const || TREE_CODE (op1) != INTEGER_CST)
   15452       836778 :                     op1 = c_wrap_maybe_const (op1, !op1_maybe_const);
   15453              :                 }
   15454              :             }
   15455              :         }
   15456              :     }
   15457              : 
   15458              :   /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
   15459              :      If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
   15460              :      Then the expression will be built.
   15461              :      It will be given type FINAL_TYPE if that is nonzero;
   15462              :      otherwise, it will be given type RESULT_TYPE.  */
   15463              : 
   15464     16179112 :   if (!result_type)
   15465              :     {
   15466              :       /* Favor showing any expression locations that are available. */
   15467          514 :       op_location_t oploc (location, UNKNOWN_LOCATION);
   15468          514 :       binary_op_rich_location richloc (oploc, orig_op0, orig_op1, true);
   15469          514 :       binary_op_error (&richloc, code, TREE_TYPE (op0), TREE_TYPE (op1));
   15470          514 :       return error_mark_node;
   15471          514 :     }
   15472              : 
   15473     16178598 :   if (build_type == NULL_TREE)
   15474              :     {
   15475     13515986 :       build_type = result_type;
   15476     13515986 :       if ((type0 != orig_type0 || type1 != orig_type1)
   15477          806 :           && !boolean_op)
   15478              :         {
   15479          806 :           gcc_assert (may_need_excess_precision && common);
   15480          806 :           semantic_result_type = c_common_type (orig_type0, orig_type1);
   15481              :         }
   15482              :     }
   15483              : 
   15484     16178598 :   if (!converted)
   15485              :     {
   15486     12141888 :       op0 = ep_convert_and_check (location, result_type, op0,
   15487              :                                   semantic_result_type);
   15488     12141888 :       op1 = ep_convert_and_check (location, result_type, op1,
   15489              :                                   semantic_result_type);
   15490              : 
   15491              :       /* This can happen if one operand has a vector type, and the other
   15492              :          has a different type.  */
   15493     12141888 :       if (TREE_CODE (op0) == ERROR_MARK || TREE_CODE (op1) == ERROR_MARK)
   15494            3 :         return error_mark_node;
   15495              :     }
   15496              : 
   15497     16178595 :   if (sanitize_flags_p ((SANITIZE_SHIFT
   15498              :                          | SANITIZE_DIVIDE
   15499              :                          | SANITIZE_FLOAT_DIVIDE
   15500              :                          | SANITIZE_SI_OVERFLOW))
   15501        23437 :       && current_function_decl != NULL_TREE
   15502        19967 :       && (doing_div_or_mod || doing_shift)
   15503     16181526 :       && !require_constant_value)
   15504              :     {
   15505              :       /* OP0 and/or OP1 might have side-effects.  */
   15506         2875 :       op0 = save_expr (op0);
   15507         2875 :       op1 = save_expr (op1);
   15508         2875 :       op0 = c_fully_fold (op0, false, NULL);
   15509         2875 :       op1 = c_fully_fold (op1, false, NULL);
   15510         2875 :       if (doing_div_or_mod && (sanitize_flags_p ((SANITIZE_DIVIDE
   15511              :                                                   | SANITIZE_FLOAT_DIVIDE
   15512              :                                                   | SANITIZE_SI_OVERFLOW))))
   15513          916 :         instrument_expr = ubsan_instrument_division (location, op0, op1);
   15514         1959 :       else if (doing_shift && sanitize_flags_p (SANITIZE_SHIFT))
   15515         1778 :         instrument_expr = ubsan_instrument_shift (location, code, op0, op1);
   15516              :     }
   15517              : 
   15518              :   /* Treat expressions in initializers specially as they can't trap.  */
   15519     16178595 :   if (int_const_or_overflow)
   15520      8623514 :     ret = (require_constant_value
   15521      8623514 :            ? fold_build2_initializer_loc (location, resultcode, build_type,
   15522              :                                           op0, op1)
   15523      8577178 :            : fold_build2_loc (location, resultcode, build_type, op0, op1));
   15524              :   else
   15525      7555081 :     ret = build2 (resultcode, build_type, op0, op1);
   15526     16178595 :   if (final_type != NULL_TREE)
   15527      1575253 :     ret = convert (final_type, ret);
   15528              : 
   15529     14603342 :  return_build_binary_op:
   15530     17643856 :   gcc_assert (ret != error_mark_node);
   15531     17643856 :   if (TREE_CODE (ret) == INTEGER_CST && !TREE_OVERFLOW (ret) && !int_const)
   15532         1852 :     ret = (int_operands
   15533         1852 :            ? note_integer_operands (ret)
   15534          530 :            : build1 (NOP_EXPR, TREE_TYPE (ret), ret));
   15535     17642004 :   else if (TREE_CODE (ret) != INTEGER_CST && int_operands
   15536        60311 :            && !in_late_binary_op)
   15537        60311 :     ret = note_integer_operands (ret);
   15538     17643856 :   protected_set_expr_location (ret, location);
   15539              : 
   15540     17643856 :   if (instrument_expr != NULL)
   15541         1425 :     ret = fold_build2 (COMPOUND_EXPR, TREE_TYPE (ret),
   15542              :                        instrument_expr, ret);
   15543              : 
   15544     17643856 :   if (semantic_result_type)
   15545          900 :     ret = build1_loc (location, EXCESS_PRECISION_EXPR,
   15546              :                       semantic_result_type, ret);
   15547              : 
   15548              :   return ret;
   15549              : }
   15550              : 
   15551              : 
   15552              : /* Convert EXPR to be a truth-value (type TYPE), validating its type for this
   15553              :    purpose.  LOCATION is the source location for the expression.  */
   15554              : 
   15555              : tree
   15556      4183390 : c_objc_common_truthvalue_conversion (location_t location, tree expr, tree type)
   15557              : {
   15558      4183390 :   bool int_const, int_operands;
   15559              : 
   15560      4183390 :   switch (TREE_CODE (TREE_TYPE (expr)))
   15561              :     {
   15562           72 :     case ARRAY_TYPE:
   15563           72 :       error_at (location, "used array that cannot be converted to pointer where scalar is required");
   15564           72 :       return error_mark_node;
   15565              : 
   15566           86 :     case RECORD_TYPE:
   15567           86 :       error_at (location, "used struct type value where scalar is required");
   15568           86 :       return error_mark_node;
   15569              : 
   15570           83 :     case UNION_TYPE:
   15571           83 :       error_at (location, "used union type value where scalar is required");
   15572           83 :       return error_mark_node;
   15573              : 
   15574           22 :     case VOID_TYPE:
   15575           22 :       error_at (location, "void value not ignored as it ought to be");
   15576           22 :       return error_mark_node;
   15577              : 
   15578        31166 :     case POINTER_TYPE:
   15579        31166 :       if (reject_gcc_builtin (expr))
   15580            3 :         return error_mark_node;
   15581              :       break;
   15582              : 
   15583            0 :     case FUNCTION_TYPE:
   15584            0 :       gcc_unreachable ();
   15585              : 
   15586            8 :     case VECTOR_TYPE:
   15587            8 :       error_at (location, "used vector type where scalar is required");
   15588            8 :       return error_mark_node;
   15589              : 
   15590              :     default:
   15591              :       break;
   15592              :     }
   15593              : 
   15594              :   /* Conversion of a floating constant to boolean goes through here
   15595              :      and yields an integer constant expression.  Otherwise, the result
   15596              :      is only an integer constant expression if the argument is.  */
   15597       903608 :   int_const = ((TREE_CODE (expr) == INTEGER_CST && !TREE_OVERFLOW (expr))
   15598      4183192 :                || ((TREE_CODE (expr) == REAL_CST
   15599      3279210 :                     || TREE_CODE (expr) == COMPLEX_CST)
   15600          374 :                    && (TREE_CODE (type) == BOOLEAN_TYPE
   15601           15 :                        || (TREE_CODE (type) == ENUMERAL_TYPE
   15602            5 :                            && ENUM_UNDERLYING_TYPE (type) != NULL_TREE
   15603            5 :                            && (TREE_CODE (ENUM_UNDERLYING_TYPE (type))
   15604              :                                == BOOLEAN_TYPE)))));
   15605      4183116 :   int_operands = EXPR_INT_CONST_OPERANDS (expr);
   15606       903770 :   if (int_operands && TREE_CODE (expr) != INTEGER_CST)
   15607              :     {
   15608          319 :       expr = remove_c_maybe_const_expr (expr);
   15609          319 :       expr = build2 (NE_EXPR, type, expr,
   15610          319 :                      convert (TREE_TYPE (expr), integer_zero_node));
   15611          319 :       expr = note_integer_operands (expr);
   15612              :     }
   15613              :   else
   15614              :     {
   15615              :       /* ??? Should we also give an error for vectors rather than leaving
   15616              :          those to give errors later?  */
   15617      4182797 :       expr = c_common_truthvalue_conversion (location, expr);
   15618      4182797 :       expr = fold_convert_loc (location, type, expr);
   15619              :     }
   15620              : 
   15621      4183116 :   if (TREE_CODE (expr) == INTEGER_CST && int_operands && !int_const)
   15622              :     {
   15623           76 :       if (TREE_OVERFLOW (expr))
   15624              :         return expr;
   15625              :       else
   15626           76 :         return note_integer_operands (expr);
   15627              :     }
   15628      4183040 :   if (TREE_CODE (expr) == INTEGER_CST && !int_const)
   15629          857 :     return build1 (NOP_EXPR, TREE_TYPE (expr), expr);
   15630              :   return expr;
   15631              : }
   15632              : 
   15633              : 
   15634              : /* Convert EXPR to a contained DECL, updating *TC, *TI and *SE as
   15635              :    required.  */
   15636              : 
   15637              : tree
   15638    127540137 : c_expr_to_decl (tree expr, bool *tc ATTRIBUTE_UNUSED, bool *se)
   15639              : {
   15640    127540137 :   if (TREE_CODE (expr) == COMPOUND_LITERAL_EXPR)
   15641              :     {
   15642          706 :       tree decl = COMPOUND_LITERAL_EXPR_DECL (expr);
   15643              :       /* Executing a compound literal inside a function reinitializes
   15644              :          it.  */
   15645          706 :       if (!TREE_STATIC (decl))
   15646          440 :         *se = true;
   15647              :       return decl;
   15648              :     }
   15649              :   else
   15650              :     return expr;
   15651              : }
   15652              : 
   15653              : /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
   15654              :    statement.  LOC is the location of the construct.  */
   15655              : 
   15656              : tree
   15657         2154 : c_finish_omp_construct (location_t loc, enum tree_code code, tree body,
   15658              :                         tree clauses)
   15659              : {
   15660         2154 :   body = c_end_compound_stmt (loc, body, true);
   15661              : 
   15662         2154 :   tree stmt = make_node (code);
   15663         2154 :   TREE_TYPE (stmt) = void_type_node;
   15664         2154 :   OMP_BODY (stmt) = body;
   15665         2154 :   OMP_CLAUSES (stmt) = clauses;
   15666         2154 :   SET_EXPR_LOCATION (stmt, loc);
   15667              : 
   15668         2154 :   return add_stmt (stmt);
   15669              : }
   15670              : 
   15671              : /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
   15672              :    statement.  LOC is the location of the OACC_DATA.  */
   15673              : 
   15674              : tree
   15675          497 : c_finish_oacc_data (location_t loc, tree clauses, tree block)
   15676              : {
   15677          497 :   tree stmt;
   15678              : 
   15679          497 :   block = c_end_compound_stmt (loc, block, true);
   15680              : 
   15681          497 :   stmt = make_node (OACC_DATA);
   15682          497 :   TREE_TYPE (stmt) = void_type_node;
   15683          497 :   OACC_DATA_CLAUSES (stmt) = clauses;
   15684          497 :   OACC_DATA_BODY (stmt) = block;
   15685          497 :   SET_EXPR_LOCATION (stmt, loc);
   15686              : 
   15687          497 :   return add_stmt (stmt);
   15688              : }
   15689              : 
   15690              : /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
   15691              :    statement.  LOC is the location of the OACC_HOST_DATA.  */
   15692              : 
   15693              : tree
   15694           21 : c_finish_oacc_host_data (location_t loc, tree clauses, tree block)
   15695              : {
   15696           21 :   tree stmt;
   15697              : 
   15698           21 :   block = c_end_compound_stmt (loc, block, true);
   15699              : 
   15700           21 :   stmt = make_node (OACC_HOST_DATA);
   15701           21 :   TREE_TYPE (stmt) = void_type_node;
   15702           21 :   OACC_HOST_DATA_CLAUSES (stmt) = clauses;
   15703           21 :   OACC_HOST_DATA_BODY (stmt) = block;
   15704           21 :   SET_EXPR_LOCATION (stmt, loc);
   15705              : 
   15706           21 :   return add_stmt (stmt);
   15707              : }
   15708              : 
   15709              : /* Like c_begin_compound_stmt, except force the retention of the BLOCK.  */
   15710              : 
   15711              : tree
   15712        12063 : c_begin_omp_parallel (void)
   15713              : {
   15714        12063 :   tree block;
   15715              : 
   15716        12063 :   keep_next_level ();
   15717        12063 :   block = c_begin_compound_stmt (true);
   15718              : 
   15719        12063 :   return block;
   15720              : }
   15721              : 
   15722              : /* Generate OMP_PARALLEL, with CLAUSES and BLOCK as its compound
   15723              :    statement.  LOC is the location of the OMP_PARALLEL.  */
   15724              : 
   15725              : tree
   15726         5723 : c_finish_omp_parallel (location_t loc, tree clauses, tree block)
   15727              : {
   15728         5723 :   tree stmt;
   15729              : 
   15730         5723 :   block = c_end_compound_stmt (loc, block, true);
   15731              : 
   15732         5723 :   stmt = make_node (OMP_PARALLEL);
   15733         5723 :   TREE_TYPE (stmt) = void_type_node;
   15734         5723 :   OMP_PARALLEL_CLAUSES (stmt) = clauses;
   15735         5723 :   OMP_PARALLEL_BODY (stmt) = block;
   15736         5723 :   SET_EXPR_LOCATION (stmt, loc);
   15737              : 
   15738         5723 :   return add_stmt (stmt);
   15739              : }
   15740              : 
   15741              : /* Like c_begin_compound_stmt, except force the retention of the BLOCK.  */
   15742              : 
   15743              : tree
   15744          917 : c_begin_omp_task (void)
   15745              : {
   15746          917 :   tree block;
   15747              : 
   15748          917 :   keep_next_level ();
   15749          917 :   block = c_begin_compound_stmt (true);
   15750              : 
   15751          917 :   return block;
   15752              : }
   15753              : 
   15754              : /* Generate OMP_TASK, with CLAUSES and BLOCK as its compound
   15755              :    statement.  LOC is the location of the #pragma.  */
   15756              : 
   15757              : tree
   15758          917 : c_finish_omp_task (location_t loc, tree clauses, tree block)
   15759              : {
   15760          917 :   tree stmt;
   15761              : 
   15762          917 :   block = c_end_compound_stmt (loc, block, true);
   15763              : 
   15764          917 :   stmt = make_node (OMP_TASK);
   15765          917 :   TREE_TYPE (stmt) = void_type_node;
   15766          917 :   OMP_TASK_CLAUSES (stmt) = clauses;
   15767          917 :   OMP_TASK_BODY (stmt) = block;
   15768          917 :   SET_EXPR_LOCATION (stmt, loc);
   15769              : 
   15770          917 :   return add_stmt (stmt);
   15771              : }
   15772              : 
   15773              : /* Generate GOMP_cancel call for #pragma omp cancel.  */
   15774              : 
   15775              : void
   15776          221 : c_finish_omp_cancel (location_t loc, tree clauses)
   15777              : {
   15778          221 :   tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL);
   15779          221 :   int mask = 0;
   15780          221 :   if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
   15781              :     mask = 1;
   15782          150 :   else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
   15783              :     mask = 2;
   15784          101 :   else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
   15785              :     mask = 4;
   15786           58 :   else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
   15787              :     mask = 8;
   15788              :   else
   15789              :     {
   15790            0 :       error_at (loc, "%<#pragma omp cancel%> must specify one of "
   15791              :                      "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> "
   15792              :                      "clauses");
   15793            0 :       return;
   15794              :     }
   15795          221 :   tree ifc = omp_find_clause (clauses, OMP_CLAUSE_IF);
   15796          221 :   if (ifc != NULL_TREE)
   15797              :     {
   15798           35 :       if (OMP_CLAUSE_IF_MODIFIER (ifc) != ERROR_MARK
   15799           35 :           && OMP_CLAUSE_IF_MODIFIER (ifc) != VOID_CST)
   15800            2 :         error_at (OMP_CLAUSE_LOCATION (ifc),
   15801              :                   "expected %<cancel%> %<if%> clause modifier");
   15802              :       else
   15803              :         {
   15804           33 :           tree ifc2 = omp_find_clause (OMP_CLAUSE_CHAIN (ifc), OMP_CLAUSE_IF);
   15805           33 :           if (ifc2 != NULL_TREE)
   15806              :             {
   15807            1 :               gcc_assert (OMP_CLAUSE_IF_MODIFIER (ifc) == VOID_CST
   15808              :                           && OMP_CLAUSE_IF_MODIFIER (ifc2) != ERROR_MARK
   15809              :                           && OMP_CLAUSE_IF_MODIFIER (ifc2) != VOID_CST);
   15810            1 :               error_at (OMP_CLAUSE_LOCATION (ifc2),
   15811              :                         "expected %<cancel%> %<if%> clause modifier");
   15812              :             }
   15813              :         }
   15814              : 
   15815           35 :       tree type = TREE_TYPE (OMP_CLAUSE_IF_EXPR (ifc));
   15816           70 :       ifc = fold_build2_loc (OMP_CLAUSE_LOCATION (ifc), NE_EXPR,
   15817           35 :                              boolean_type_node, OMP_CLAUSE_IF_EXPR (ifc),
   15818              :                              build_zero_cst (type));
   15819              :     }
   15820              :   else
   15821          186 :     ifc = boolean_true_node;
   15822          221 :   tree stmt = build_call_expr_loc (loc, fn, 2,
   15823          221 :                                    build_int_cst (integer_type_node, mask),
   15824              :                                    ifc);
   15825          221 :   add_stmt (stmt);
   15826              : }
   15827              : 
   15828              : /* Generate GOMP_cancellation_point call for
   15829              :    #pragma omp cancellation point.  */
   15830              : 
   15831              : void
   15832          167 : c_finish_omp_cancellation_point (location_t loc, tree clauses)
   15833              : {
   15834          167 :   tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT);
   15835          167 :   int mask = 0;
   15836          167 :   if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
   15837              :     mask = 1;
   15838          123 :   else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
   15839              :     mask = 2;
   15840           88 :   else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
   15841              :     mask = 4;
   15842           53 :   else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
   15843              :     mask = 8;
   15844              :   else
   15845              :     {
   15846            1 :       error_at (loc, "%<#pragma omp cancellation point%> must specify one of "
   15847              :                      "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> "
   15848              :                      "clauses");
   15849            1 :       return;
   15850              :     }
   15851          166 :   tree stmt = build_call_expr_loc (loc, fn, 1,
   15852          166 :                                    build_int_cst (integer_type_node, mask));
   15853          166 :   add_stmt (stmt);
   15854              : }
   15855              : 
   15856              : /* Helper function for handle_omp_array_sections.  Called recursively
   15857              :    to handle multiple array-section-subscripts.  C is the clause,
   15858              :    T current expression (initially OMP_CLAUSE_DECL), which is either
   15859              :    a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
   15860              :    expression if specified, TREE_VALUE length expression if specified,
   15861              :    TREE_CHAIN is what it has been specified after, or some decl.
   15862              :    TYPES vector is populated with array section types, MAYBE_ZERO_LEN
   15863              :    set to true if any of the array-section-subscript could have length
   15864              :    of zero (explicit or implicit), FIRST_NON_ONE is the index of the
   15865              :    first array-section-subscript which is known not to have length
   15866              :    of one.  Given say:
   15867              :    map(a[:b][2:1][:c][:2][:d][e:f][2:5])
   15868              :    FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
   15869              :    all are or may have length of 1, array-section-subscript [:2] is the
   15870              :    first one known not to have length 1.  For array-section-subscript
   15871              :    <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
   15872              :    0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
   15873              :    can if MAYBE_ZERO_LEN is false.  MAYBE_ZERO_LEN will be true in the above
   15874              :    case though, as some lengths could be zero.  */
   15875              : 
   15876              : static tree
   15877         6443 : handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types,
   15878              :                              bool &maybe_zero_len, unsigned int &first_non_one,
   15879              :                              enum c_omp_region_type ort)
   15880              : {
   15881         6443 :   tree ret, low_bound, length, type;
   15882         6443 :   bool openacc = (ort & C_ORT_ACC) != 0;
   15883         6443 :   if (TREE_CODE (t) != OMP_ARRAY_SECTION)
   15884              :     {
   15885         3001 :       if (error_operand_p (t))
   15886            2 :         return error_mark_node;
   15887         2999 :       c_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
   15888         2999 :       ret = t;
   15889         2999 :       if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
   15890         2895 :           && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
   15891         5580 :           && TYPE_ATOMIC (strip_array_types (TREE_TYPE (t))))
   15892              :         {
   15893            6 :           error_at (OMP_CLAUSE_LOCATION (c), "%<_Atomic%> %qE in %qs clause",
   15894            6 :                     t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   15895            6 :           return error_mark_node;
   15896              :         }
   15897         2993 :       if (!ai.check_clause (c))
   15898            0 :         return error_mark_node;
   15899         2993 :       else if (ai.component_access_p ()
   15900         3296 :                && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   15901           16 :                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO
   15902           11 :                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM))
   15903          303 :         t = ai.get_root_term (true);
   15904              :       else
   15905         2690 :         t = ai.unconverted_ref_origin ();
   15906         2993 :       if (t == error_mark_node)
   15907              :         return error_mark_node;
   15908         2993 :       if (!VAR_P (t)
   15909          751 :           && (ort == C_ORT_ACC || !EXPR_P (t))
   15910          744 :           && TREE_CODE (t) != PARM_DECL)
   15911              :         {
   15912            5 :           if (DECL_P (t))
   15913            5 :             error_at (OMP_CLAUSE_LOCATION (c),
   15914              :                       "%qD is not a variable in %qs clause", t,
   15915            5 :                       omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   15916              :           else
   15917            0 :             error_at (OMP_CLAUSE_LOCATION (c),
   15918              :                       "%qE is not a variable in %qs clause", t,
   15919            0 :                       omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   15920            5 :           return error_mark_node;
   15921              :         }
   15922         2988 :       else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
   15923         2885 :                && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
   15924         5560 :                && TYPE_ATOMIC (TREE_TYPE (t)))
   15925              :         {
   15926            0 :           error_at (OMP_CLAUSE_LOCATION (c), "%<_Atomic%> %qD in %qs clause",
   15927            0 :                     t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   15928            0 :           return error_mark_node;
   15929              :         }
   15930         2988 :       else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
   15931         2885 :                && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
   15932         2572 :                && VAR_P (t)
   15933         5004 :                && DECL_THREAD_LOCAL_P (t))
   15934              :         {
   15935            3 :           error_at (OMP_CLAUSE_LOCATION (c),
   15936              :                     "%qD is threadprivate variable in %qs clause", t,
   15937            3 :                     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   15938            3 :           return error_mark_node;
   15939              :         }
   15940         2985 :       if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
   15941         2882 :            || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND)
   15942          416 :           && TYPE_ATOMIC (TREE_TYPE (t))
   15943         2987 :           && POINTER_TYPE_P (TREE_TYPE (t)))
   15944              :         {
   15945              :           /* If the array section is pointer based and the pointer
   15946              :              itself is _Atomic qualified, we need to atomically load
   15947              :              the pointer.  */
   15948            2 :           ret = convert_lvalue_to_rvalue (OMP_CLAUSE_LOCATION (c),
   15949              :                                           ret, false, false);
   15950              :         }
   15951              :       return ret;
   15952         2999 :     }
   15953              : 
   15954         3442 :   ret = handle_omp_array_sections_1 (c, TREE_OPERAND (t, 0), types,
   15955              :                                      maybe_zero_len, first_non_one, ort);
   15956         3442 :   if (ret == error_mark_node || ret == NULL_TREE)
   15957              :     return ret;
   15958              : 
   15959         3374 :   type = TREE_TYPE (ret);
   15960         3374 :   low_bound = TREE_OPERAND (t, 1);
   15961         3374 :   length = TREE_OPERAND (t, 2);
   15962              : 
   15963         3374 :   if (low_bound == error_mark_node || length == error_mark_node)
   15964              :     return error_mark_node;
   15965              : 
   15966         3374 :   if (low_bound && !INTEGRAL_TYPE_P (TREE_TYPE (low_bound)))
   15967              :     {
   15968           13 :       error_at (OMP_CLAUSE_LOCATION (c),
   15969              :                 "low bound %qE of array section does not have integral type",
   15970              :                 low_bound);
   15971           13 :       return error_mark_node;
   15972              :     }
   15973         3361 :   if (length && !INTEGRAL_TYPE_P (TREE_TYPE (length)))
   15974              :     {
   15975           12 :       error_at (OMP_CLAUSE_LOCATION (c),
   15976              :                 "length %qE of array section does not have integral type",
   15977              :                 length);
   15978           12 :       return error_mark_node;
   15979              :     }
   15980         3349 :   if (low_bound
   15981         2758 :       && TREE_CODE (low_bound) == INTEGER_CST
   15982         5815 :       && TYPE_PRECISION (TREE_TYPE (low_bound))
   15983         2466 :          > TYPE_PRECISION (sizetype))
   15984            0 :     low_bound = fold_convert (sizetype, low_bound);
   15985         3349 :   if (length
   15986         3157 :       && TREE_CODE (length) == INTEGER_CST
   15987         5559 :       && TYPE_PRECISION (TREE_TYPE (length))
   15988         2210 :          > TYPE_PRECISION (sizetype))
   15989            0 :     length = fold_convert (sizetype, length);
   15990         3349 :   if (low_bound == NULL_TREE)
   15991          591 :     low_bound = integer_zero_node;
   15992         3349 :   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   15993         3349 :       && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
   15994         1948 :           || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH))
   15995              :     {
   15996           10 :       if (length != integer_one_node)
   15997              :         {
   15998            6 :           error_at (OMP_CLAUSE_LOCATION (c),
   15999              :                     "expected single pointer in %qs clause",
   16000              :                     user_omp_clause_code_name (c, openacc));
   16001            6 :           return error_mark_node;
   16002              :         }
   16003              :     }
   16004         3343 :   if (length != NULL_TREE)
   16005              :     {
   16006         3155 :       if (!integer_nonzerop (length))
   16007              :         {
   16008          978 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
   16009              :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   16010              :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   16011              :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   16012              :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
   16013              :             {
   16014          180 :               if (integer_zerop (length))
   16015              :                 {
   16016           12 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16017              :                             "zero length array section in %qs clause",
   16018           12 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16019           12 :                   return error_mark_node;
   16020              :                 }
   16021              :             }
   16022              :           else
   16023          798 :             maybe_zero_len = true;
   16024              :         }
   16025         3143 :       if (first_non_one == types.length ()
   16026         3143 :           && (TREE_CODE (length) != INTEGER_CST || integer_onep (length)))
   16027         1609 :         first_non_one++;
   16028              :     }
   16029         3331 :   if (TREE_CODE (type) == ARRAY_TYPE)
   16030              :     {
   16031         1503 :       if (length == NULL_TREE
   16032         1503 :           && (TYPE_DOMAIN (type) == NULL_TREE
   16033          170 :               || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE))
   16034              :         {
   16035            8 :           error_at (OMP_CLAUSE_LOCATION (c),
   16036              :                     "for unknown bound array type length expression must "
   16037              :                     "be specified");
   16038            8 :           return error_mark_node;
   16039              :         }
   16040         1495 :       if (TREE_CODE (low_bound) == INTEGER_CST
   16041         1495 :           && tree_int_cst_sgn (low_bound) == -1)
   16042              :         {
   16043           36 :           error_at (OMP_CLAUSE_LOCATION (c),
   16044              :                     "negative low bound in array section in %qs clause",
   16045           36 :                     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16046           36 :           return error_mark_node;
   16047              :         }
   16048         1459 :       if (length != NULL_TREE
   16049         1302 :           && TREE_CODE (length) == INTEGER_CST
   16050         2321 :           && tree_int_cst_sgn (length) == -1)
   16051              :         {
   16052           36 :           error_at (OMP_CLAUSE_LOCATION (c),
   16053              :                     "negative length in array section in %qs clause",
   16054           36 :                     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16055           36 :           return error_mark_node;
   16056              :         }
   16057         1423 :       if (TYPE_DOMAIN (type)
   16058         1412 :           && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
   16059         2835 :           && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
   16060              :                         == INTEGER_CST)
   16061              :         {
   16062         1066 :           tree size
   16063         1066 :             = fold_convert (sizetype, TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
   16064         1066 :           size = size_binop (PLUS_EXPR, size, size_one_node);
   16065         1066 :           if (TREE_CODE (low_bound) == INTEGER_CST)
   16066              :             {
   16067          879 :               if (tree_int_cst_lt (size, low_bound))
   16068              :                 {
   16069           11 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16070              :                             "low bound %qE above array section size "
   16071              :                             "in %qs clause", low_bound,
   16072           11 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16073           11 :                   return error_mark_node;
   16074              :                 }
   16075          868 :               if (tree_int_cst_equal (size, low_bound))
   16076              :                 {
   16077            5 :                   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
   16078              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   16079              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   16080              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   16081              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
   16082              :                     {
   16083            5 :                       error_at (OMP_CLAUSE_LOCATION (c),
   16084              :                                 "zero length array section in %qs clause",
   16085            5 :                                 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16086            5 :                       return error_mark_node;
   16087              :                     }
   16088            0 :                   maybe_zero_len = true;
   16089              :                 }
   16090          863 :               else if (length == NULL_TREE
   16091          256 :                        && first_non_one == types.length ()
   16092          918 :                        && tree_int_cst_equal
   16093           55 :                             (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
   16094              :                              low_bound))
   16095           30 :                 first_non_one++;
   16096              :             }
   16097          187 :           else if (length == NULL_TREE)
   16098              :             {
   16099            3 :               if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
   16100              :                   && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
   16101              :                   && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
   16102              :                   && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
   16103              :                   && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
   16104            0 :                 maybe_zero_len = true;
   16105            6 :               if (first_non_one == types.length ())
   16106            1 :                 first_non_one++;
   16107              :             }
   16108         1050 :           if (length && TREE_CODE (length) == INTEGER_CST)
   16109              :             {
   16110          803 :               if (tree_int_cst_lt (size, length))
   16111              :                 {
   16112           11 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16113              :                             "length %qE above array section size "
   16114              :                             "in %qs clause", length,
   16115           11 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16116           11 :                   return error_mark_node;
   16117              :                 }
   16118          792 :               if (TREE_CODE (low_bound) == INTEGER_CST)
   16119              :                 {
   16120          692 :                   tree lbpluslen
   16121          692 :                     = size_binop (PLUS_EXPR,
   16122              :                                   fold_convert (sizetype, low_bound),
   16123              :                                   fold_convert (sizetype, length));
   16124          692 :                   if (TREE_CODE (lbpluslen) == INTEGER_CST
   16125          692 :                       && tree_int_cst_lt (size, lbpluslen))
   16126              :                     {
   16127           10 :                       error_at (OMP_CLAUSE_LOCATION (c),
   16128              :                                 "high bound %qE above array section size "
   16129              :                                 "in %qs clause", lbpluslen,
   16130           10 :                                 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16131           10 :                       return error_mark_node;
   16132              :                     }
   16133              :                 }
   16134              :             }
   16135              :         }
   16136          357 :       else if (length == NULL_TREE)
   16137              :         {
   16138           10 :           if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
   16139              :               && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
   16140              :               && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
   16141              :               && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
   16142              :               && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
   16143            0 :             maybe_zero_len = true;
   16144           20 :           if (first_non_one == types.length ())
   16145           10 :             first_non_one++;
   16146              :         }
   16147              : 
   16148              :       /* For [lb:] we will need to evaluate lb more than once.  */
   16149          933 :       if (length == NULL_TREE && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
   16150              :         {
   16151          127 :           tree lb = save_expr (low_bound);
   16152          127 :           if (lb != low_bound)
   16153              :             {
   16154            2 :               TREE_OPERAND (t, 1) = lb;
   16155            2 :               low_bound = lb;
   16156              :             }
   16157              :         }
   16158              :     }
   16159         1828 :   else if (TREE_CODE (type) == POINTER_TYPE)
   16160              :     {
   16161         1817 :       if (length == NULL_TREE)
   16162              :         {
   16163           12 :           if (TREE_CODE (ret) == PARM_DECL && C_ARRAY_PARAMETER (ret))
   16164           10 :             error_at (OMP_CLAUSE_LOCATION (c),
   16165              :                       "for array function parameter length expression "
   16166              :                       "must be specified");
   16167              :           else
   16168            2 :             error_at (OMP_CLAUSE_LOCATION (c),
   16169              :                       "for pointer type length expression must be specified");
   16170           12 :           return error_mark_node;
   16171              :         }
   16172         1805 :       if (length != NULL_TREE
   16173         1805 :           && TREE_CODE (length) == INTEGER_CST
   16174         1298 :           && tree_int_cst_sgn (length) == -1)
   16175              :         {
   16176           20 :           error_at (OMP_CLAUSE_LOCATION (c),
   16177              :                     "negative length in array section in %qs clause",
   16178           20 :                     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16179           20 :           return error_mark_node;
   16180              :         }
   16181              :       /* If there is a pointer type anywhere but in the very first
   16182              :          array-section-subscript, the array section could be non-contiguous.  */
   16183         1785 :       if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
   16184         1624 :           && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
   16185         3380 :           && TREE_CODE (TREE_OPERAND (t, 0)) == OMP_ARRAY_SECTION)
   16186              :         {
   16187              :           /* If any prior dimension has a non-one length, then deem this
   16188              :              array section as non-contiguous.  */
   16189           42 :           for (tree d = TREE_OPERAND (t, 0);
   16190           82 :                TREE_CODE (d) == OMP_ARRAY_SECTION;
   16191           40 :                d = TREE_OPERAND (d, 0))
   16192              :             {
   16193           44 :               tree d_length = TREE_OPERAND (d, 2);
   16194           44 :               if (d_length == NULL_TREE || !integer_onep (d_length))
   16195              :                 {
   16196            4 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16197              :                             "array section is not contiguous in %qs clause",
   16198            4 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16199            4 :                   return error_mark_node;
   16200              :                 }
   16201              :             }
   16202              :         }
   16203              :     }
   16204              :   else
   16205              :     {
   16206           11 :       error_at (OMP_CLAUSE_LOCATION (c),
   16207              :                 "%qE does not have pointer or array type", ret);
   16208           11 :       return error_mark_node;
   16209              :     }
   16210         3167 :   if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
   16211         2851 :     types.safe_push (TREE_TYPE (ret));
   16212              :   /* We will need to evaluate lb more than once.  */
   16213         3167 :   tree lb = save_expr (low_bound);
   16214         3167 :   if (lb != low_bound)
   16215              :     {
   16216          276 :       TREE_OPERAND (t, 1) = lb;
   16217          276 :       low_bound = lb;
   16218              :     }
   16219         3167 :   ret = build_array_ref (OMP_CLAUSE_LOCATION (c), ret, low_bound);
   16220         3167 :   return ret;
   16221              : }
   16222              : 
   16223              : /* Handle array sections for clause C.  */
   16224              : 
   16225              : static bool
   16226         3001 : handle_omp_array_sections (tree &c, enum c_omp_region_type ort)
   16227              : {
   16228         3001 :   bool maybe_zero_len = false;
   16229         3001 :   unsigned int first_non_one = 0;
   16230         3001 :   auto_vec<tree, 10> types;
   16231         3001 :   tree *tp = &OMP_CLAUSE_DECL (c);
   16232         3001 :   if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   16233         2687 :        || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
   16234         3105 :       && OMP_ITERATOR_DECL_P (*tp))
   16235           66 :     tp = &TREE_VALUE (*tp);
   16236         3001 :   tree first = handle_omp_array_sections_1 (c, *tp, types,
   16237              :                                             maybe_zero_len, first_non_one,
   16238              :                                             ort);
   16239         3001 :   if (first == error_mark_node)
   16240              :     return true;
   16241         2778 :   if (first == NULL_TREE)
   16242              :     return false;
   16243         2778 :   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   16244         2778 :       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
   16245              :     {
   16246          336 :       tree t = *tp;
   16247          336 :       tree tem = NULL_TREE;
   16248              :       /* Need to evaluate side effects in the length expressions
   16249              :          if any.  */
   16250          336 :       while (TREE_CODE (t) == TREE_LIST)
   16251              :         {
   16252            0 :           if (TREE_VALUE (t) && TREE_SIDE_EFFECTS (TREE_VALUE (t)))
   16253              :             {
   16254            0 :               if (tem == NULL_TREE)
   16255              :                 tem = TREE_VALUE (t);
   16256              :               else
   16257            0 :                 tem = build2 (COMPOUND_EXPR, TREE_TYPE (tem),
   16258            0 :                               TREE_VALUE (t), tem);
   16259              :             }
   16260            0 :           t = TREE_CHAIN (t);
   16261              :         }
   16262          336 :       if (tem)
   16263            0 :         first = build2 (COMPOUND_EXPR, TREE_TYPE (first), tem, first);
   16264          336 :       first = c_fully_fold (first, false, NULL, true);
   16265          336 :       *tp = first;
   16266              :     }
   16267              :   else
   16268              :     {
   16269         2442 :       unsigned int num = types.length (), i;
   16270         2442 :       tree t, side_effects = NULL_TREE, size = NULL_TREE;
   16271         2442 :       tree condition = NULL_TREE;
   16272              : 
   16273         2442 :       if (int_size_in_bytes (TREE_TYPE (first)) <= 0)
   16274            3 :         maybe_zero_len = true;
   16275              : 
   16276         5084 :       for (i = num, t = OMP_CLAUSE_DECL (c); i > 0;
   16277         2642 :            t = TREE_OPERAND (t, 0))
   16278              :         {
   16279         2657 :           tree low_bound = TREE_OPERAND (t, 1);
   16280         2657 :           tree length = TREE_OPERAND (t, 2);
   16281              : 
   16282         2657 :           i--;
   16283         2657 :           if (low_bound
   16284         2189 :               && TREE_CODE (low_bound) == INTEGER_CST
   16285         4657 :               && TYPE_PRECISION (TREE_TYPE (low_bound))
   16286         2000 :                  > TYPE_PRECISION (sizetype))
   16287            0 :             low_bound = fold_convert (sizetype, low_bound);
   16288         2657 :           if (length
   16289         2565 :               && TREE_CODE (length) == INTEGER_CST
   16290         4293 :               && TYPE_PRECISION (TREE_TYPE (length))
   16291         1636 :                  > TYPE_PRECISION (sizetype))
   16292            0 :             length = fold_convert (sizetype, length);
   16293         2657 :           if (low_bound == NULL_TREE)
   16294          468 :             low_bound = integer_zero_node;
   16295         2657 :           if (!maybe_zero_len && i > first_non_one)
   16296              :             {
   16297          109 :               if (integer_nonzerop (low_bound))
   16298            6 :                 goto do_warn_noncontiguous;
   16299          103 :               if (length != NULL_TREE
   16300           50 :                   && TREE_CODE (length) == INTEGER_CST
   16301           50 :                   && TYPE_DOMAIN (types[i])
   16302           50 :                   && TYPE_MAX_VALUE (TYPE_DOMAIN (types[i]))
   16303          153 :                   && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])))
   16304              :                      == INTEGER_CST)
   16305              :                 {
   16306           50 :                   tree size;
   16307           50 :                   size = size_binop (PLUS_EXPR,
   16308              :                                      TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
   16309              :                                      size_one_node);
   16310           50 :                   if (!tree_int_cst_equal (length, size))
   16311              :                     {
   16312            7 :                      do_warn_noncontiguous:
   16313           26 :                       error_at (OMP_CLAUSE_LOCATION (c),
   16314              :                                 "array section is not contiguous in %qs "
   16315              :                                 "clause",
   16316           13 :                                 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16317         2442 :                       return true;
   16318              :                     }
   16319              :                 }
   16320           96 :               if (length != NULL_TREE
   16321           96 :                   && TREE_SIDE_EFFECTS (length))
   16322              :                 {
   16323            0 :                   if (side_effects == NULL_TREE)
   16324              :                     side_effects = length;
   16325              :                   else
   16326            0 :                     side_effects = build2 (COMPOUND_EXPR,
   16327            0 :                                            TREE_TYPE (side_effects),
   16328              :                                            length, side_effects);
   16329              :                 }
   16330              :             }
   16331              :           else
   16332              :             {
   16333         2548 :               tree l;
   16334              : 
   16335         2548 :               if (i > first_non_one
   16336         2548 :                   && ((length && integer_nonzerop (length))
   16337            0 :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   16338              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   16339              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION))
   16340            0 :                 continue;
   16341         2548 :               if (length)
   16342         2515 :                 l = fold_convert (sizetype, length);
   16343              :               else
   16344              :                 {
   16345           33 :                   l = size_binop (PLUS_EXPR,
   16346              :                                   TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
   16347              :                                   size_one_node);
   16348           33 :                   l = size_binop (MINUS_EXPR, l,
   16349              :                                   fold_convert (sizetype, low_bound));
   16350              :                 }
   16351         2548 :               if (i > first_non_one)
   16352              :                 {
   16353            0 :                   l = fold_build2 (NE_EXPR, boolean_type_node, l,
   16354              :                                    size_zero_node);
   16355            0 :                   if (condition == NULL_TREE)
   16356              :                     condition = l;
   16357              :                   else
   16358            0 :                     condition = fold_build2 (BIT_AND_EXPR, boolean_type_node,
   16359              :                                              l, condition);
   16360              :                 }
   16361         2548 :               else if (size == NULL_TREE)
   16362              :                 {
   16363         2429 :                   size = size_in_bytes (TREE_TYPE (types[i]));
   16364         2429 :                   tree eltype = TREE_TYPE (types[num - 1]);
   16365         2449 :                   while (TREE_CODE (eltype) == ARRAY_TYPE)
   16366           20 :                     eltype = TREE_TYPE (eltype);
   16367         2429 :                   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   16368         2194 :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   16369         4363 :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
   16370              :                     {
   16371          539 :                       if (integer_zerop (size)
   16372         1076 :                           || integer_zerop (size_in_bytes (eltype)))
   16373              :                         {
   16374            4 :                           error_at (OMP_CLAUSE_LOCATION (c),
   16375              :                                     "zero length array section in %qs clause",
   16376            2 :                                     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16377            2 :                           return error_mark_node;
   16378              :                         }
   16379          537 :                       size = size_binop (EXACT_DIV_EXPR, size,
   16380              :                                          size_in_bytes (eltype));
   16381              :                     }
   16382         2427 :                   size = size_binop (MULT_EXPR, size, l);
   16383         2427 :                   if (condition)
   16384            0 :                     size = fold_build3 (COND_EXPR, sizetype, condition,
   16385              :                                         size, size_zero_node);
   16386              :                 }
   16387              :               else
   16388          119 :                 size = size_binop (MULT_EXPR, size, l);
   16389              :             }
   16390              :         }
   16391         2427 :       if (side_effects)
   16392            0 :         size = build2 (COMPOUND_EXPR, sizetype, side_effects, size);
   16393         2427 :       if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   16394         2194 :           || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   16395         4361 :           || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
   16396              :         {
   16397          537 :           size = size_binop (MINUS_EXPR, size, size_one_node);
   16398          537 :           size = c_fully_fold (size, false, NULL);
   16399          537 :           size = save_expr (size);
   16400          537 :           tree index_type = build_index_type (size);
   16401          537 :           tree eltype = TREE_TYPE (first);
   16402          549 :           while (TREE_CODE (eltype) == ARRAY_TYPE)
   16403           12 :             eltype = TREE_TYPE (eltype);
   16404          537 :           tree type = c_build_array_type (eltype, index_type);
   16405          537 :           tree ptype = c_build_pointer_type (eltype);
   16406          537 :           if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
   16407          296 :             t = build_fold_addr_expr (t);
   16408          537 :           tree t2 = build_fold_addr_expr (first);
   16409          537 :           t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
   16410              :                                  ptrdiff_type_node, t2);
   16411          537 :           t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
   16412              :                                 ptrdiff_type_node, t2,
   16413          537 :                                 fold_convert_loc (OMP_CLAUSE_LOCATION (c),
   16414              :                                                   ptrdiff_type_node, t));
   16415          537 :           t2 = c_fully_fold (t2, false, NULL);
   16416          537 :           if (tree_fits_shwi_p (t2))
   16417          398 :             t = build2 (MEM_REF, type, t,
   16418          398 :                         build_int_cst (ptype, tree_to_shwi (t2)));
   16419              :           else
   16420              :             {
   16421          139 :               t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c), sizetype, t2);
   16422          139 :               t = build2_loc (OMP_CLAUSE_LOCATION (c), POINTER_PLUS_EXPR,
   16423          139 :                               TREE_TYPE (t), t, t2);
   16424          139 :               t = build2 (MEM_REF, type, t, build_int_cst (ptype, 0));
   16425              :             }
   16426          537 :           OMP_CLAUSE_DECL (c) = t;
   16427          537 :           return false;
   16428              :         }
   16429         1890 :       first = c_fully_fold (first, false, NULL);
   16430         1890 :       OMP_CLAUSE_DECL (c) = first;
   16431         1890 :       if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
   16432              :         return false;
   16433              :       /* Don't set OMP_CLAUSE_SIZE for bare attach/detach clauses.  */
   16434         1879 :       if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
   16435         1879 :           || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
   16436         1733 :               && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH
   16437         1731 :               && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FORCE_DETACH))
   16438              :         {
   16439         1875 :           if (size)
   16440         1875 :             size = c_fully_fold (size, false, NULL);
   16441         1875 :           OMP_CLAUSE_SIZE (c) = size;
   16442              :         }
   16443              : 
   16444         1879 :       if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
   16445              :         return false;
   16446              : 
   16447         1735 :       auto_vec<omp_addr_token *, 10> addr_tokens;
   16448              : 
   16449         1735 :       if (!omp_parse_expr (addr_tokens, first))
   16450         1735 :         return true;
   16451              : 
   16452         1735 :       c_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
   16453              : 
   16454         1735 :       tree nc = ai.expand_map_clause (c, first, addr_tokens, ort);
   16455         1735 :       if (nc != error_mark_node)
   16456              :         {
   16457         1735 :           using namespace omp_addr_tokenizer;
   16458              : 
   16459         1735 :           if (ai.maybe_zero_length_array_section (c))
   16460         1731 :             OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
   16461              : 
   16462              :           /* !!! If we're accessing a base decl via chained access
   16463              :              methods (e.g. multiple indirections), duplicate clause
   16464              :              detection won't work properly.  Skip it in that case.  */
   16465         1735 :           if ((addr_tokens[0]->type == STRUCTURE_BASE
   16466         1445 :                || addr_tokens[0]->type == ARRAY_BASE)
   16467         1735 :               && addr_tokens[0]->u.structure_base_kind == BASE_DECL
   16468         1735 :               && addr_tokens[1]->type == ACCESS_METHOD
   16469         3470 :               && omp_access_chain_p (addr_tokens, 1))
   16470           36 :             c = nc;
   16471              : 
   16472         1735 :           return false;
   16473              :         }
   16474              :     }
   16475              :   return false;
   16476         3001 : }
   16477              : 
   16478              : /* Helper function of finish_omp_clauses.  Clone STMT as if we were making
   16479              :    an inline call.  But, remap
   16480              :    the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
   16481              :    and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL.  */
   16482              : 
   16483              : static tree
   16484          516 : c_clone_omp_udr (tree stmt, tree omp_decl1, tree omp_decl2,
   16485              :                  tree decl, tree placeholder)
   16486              : {
   16487          516 :   copy_body_data id;
   16488          516 :   hash_map<tree, tree> decl_map;
   16489              : 
   16490          516 :   decl_map.put (omp_decl1, placeholder);
   16491          516 :   decl_map.put (omp_decl2, decl);
   16492          516 :   memset (&id, 0, sizeof (id));
   16493          516 :   id.src_fn = DECL_CONTEXT (omp_decl1);
   16494          516 :   id.dst_fn = current_function_decl;
   16495          516 :   id.src_cfun = DECL_STRUCT_FUNCTION (id.src_fn);
   16496          516 :   id.decl_map = &decl_map;
   16497              : 
   16498          516 :   id.copy_decl = copy_decl_no_change;
   16499          516 :   id.transform_call_graph_edges = CB_CGE_DUPLICATE;
   16500          516 :   id.transform_new_cfg = true;
   16501          516 :   id.transform_return_to_modify = false;
   16502          516 :   id.eh_lp_nr = 0;
   16503          516 :   walk_tree (&stmt, copy_tree_body_r, &id, NULL);
   16504          516 :   return stmt;
   16505          516 : }
   16506              : 
   16507              : /* Helper function of c_finish_omp_clauses, called via walk_tree.
   16508              :    Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP.  */
   16509              : 
   16510              : static tree
   16511         1147 : c_find_omp_placeholder_r (tree *tp, int *, void *data)
   16512              : {
   16513         1147 :   if (*tp == (tree) data)
   16514           31 :     return *tp;
   16515              :   return NULL_TREE;
   16516              : }
   16517              : 
   16518              : /* Similarly, but also walk aggregate fields.  */
   16519              : 
   16520              : struct c_find_omp_var_s { tree var; hash_set<tree> *pset; };
   16521              : 
   16522              : static tree
   16523          288 : c_find_omp_var_r (tree *tp, int *, void *data)
   16524              : {
   16525          288 :   if (*tp == ((struct c_find_omp_var_s *) data)->var)
   16526              :     return *tp;
   16527          280 :   if (RECORD_OR_UNION_TYPE_P (*tp))
   16528              :     {
   16529            2 :       tree field;
   16530            2 :       hash_set<tree> *pset = ((struct c_find_omp_var_s *) data)->pset;
   16531              : 
   16532            2 :       for (field = TYPE_FIELDS (*tp); field;
   16533            0 :            field = DECL_CHAIN (field))
   16534            2 :         if (TREE_CODE (field) == FIELD_DECL)
   16535              :           {
   16536            2 :             tree ret = walk_tree (&DECL_FIELD_OFFSET (field),
   16537              :                                   c_find_omp_var_r, data, pset);
   16538            2 :             if (ret)
   16539              :               return ret;
   16540            2 :             ret = walk_tree (&DECL_SIZE (field), c_find_omp_var_r, data, pset);
   16541            2 :             if (ret)
   16542              :               return ret;
   16543            2 :             ret = walk_tree (&DECL_SIZE_UNIT (field), c_find_omp_var_r, data,
   16544              :                              pset);
   16545            2 :             if (ret)
   16546              :               return ret;
   16547            2 :             ret = walk_tree (&TREE_TYPE (field), c_find_omp_var_r, data, pset);
   16548            2 :             if (ret)
   16549              :               return ret;
   16550              :           }
   16551              :     }
   16552          278 :   else if (INTEGRAL_TYPE_P (*tp))
   16553           45 :     return walk_tree (&TYPE_MAX_VALUE (*tp), c_find_omp_var_r, data,
   16554              :                       ((struct c_find_omp_var_s *) data)->pset);
   16555              :   return NULL_TREE;
   16556              : }
   16557              : 
   16558              : /* Finish OpenMP iterators ITER.  Return true if they are erroneous
   16559              :    and clauses containing them should be removed.  */
   16560              : 
   16561              : static bool
   16562          146 : c_omp_finish_iterators (tree iter)
   16563              : {
   16564          146 :   bool ret = false;
   16565          331 :   for (tree it = iter; it; it = TREE_CHAIN (it))
   16566              :     {
   16567          185 :       tree var = OMP_ITERATOR_VAR (it);
   16568          185 :       tree begin = OMP_ITERATOR_BEGIN (it);
   16569          185 :       tree end = OMP_ITERATOR_END (it);
   16570          185 :       tree step = OMP_ITERATOR_STEP (it);
   16571          185 :       tree orig_step;
   16572          185 :       tree type = TREE_TYPE (var);
   16573          185 :       location_t loc = DECL_SOURCE_LOCATION (var);
   16574          185 :       if (type == error_mark_node)
   16575              :         {
   16576            0 :           ret = true;
   16577           34 :           continue;
   16578              :         }
   16579          185 :       if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type))
   16580              :         {
   16581            6 :           error_at (loc, "iterator %qD has neither integral nor pointer type",
   16582              :                     var);
   16583            6 :           ret = true;
   16584            6 :           continue;
   16585              :         }
   16586          179 :       else if (TYPE_ATOMIC (type))
   16587              :         {
   16588            2 :           error_at (loc, "iterator %qD has %<_Atomic%> qualified type", var);
   16589            2 :           ret = true;
   16590            2 :           continue;
   16591              :         }
   16592          177 :       else if (TYPE_READONLY (type))
   16593              :         {
   16594            4 :           error_at (loc, "iterator %qD has const qualified type", var);
   16595            4 :           ret = true;
   16596            4 :           continue;
   16597              :         }
   16598          173 :       else if (step == error_mark_node
   16599          173 :                || TREE_TYPE (step) == error_mark_node)
   16600              :         {
   16601            0 :           ret = true;
   16602            0 :           continue;
   16603              :         }
   16604          173 :       else if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
   16605              :         {
   16606            4 :           error_at (EXPR_LOC_OR_LOC (step, loc),
   16607              :                     "iterator step with non-integral type");
   16608            4 :           ret = true;
   16609            4 :           continue;
   16610              :         }
   16611          169 :       begin = c_fully_fold (build_c_cast (loc, type, begin), false, NULL);
   16612          169 :       end = c_fully_fold (build_c_cast (loc, type, end), false, NULL);
   16613          169 :       orig_step = save_expr (c_fully_fold (step, false, NULL));
   16614          169 :       tree stype = POINTER_TYPE_P (type) ? sizetype : type;
   16615          169 :       step = c_fully_fold (build_c_cast (loc, stype, orig_step), false, NULL);
   16616          169 :       if (POINTER_TYPE_P (type))
   16617              :         {
   16618           14 :           begin = save_expr (begin);
   16619           14 :           step = pointer_int_sum (loc, PLUS_EXPR, begin, step);
   16620           14 :           step = fold_build2_loc (loc, MINUS_EXPR, sizetype,
   16621              :                                   fold_convert (sizetype, step),
   16622              :                                   fold_convert (sizetype, begin));
   16623           14 :           step = fold_convert (ssizetype, step);
   16624              :         }
   16625          169 :       if (integer_zerop (step))
   16626              :         {
   16627            6 :           error_at (loc, "iterator %qD has zero step", var);
   16628            6 :           ret = true;
   16629            6 :           continue;
   16630              :         }
   16631              : 
   16632          163 :       if (begin == error_mark_node
   16633          161 :           || end == error_mark_node
   16634          159 :           || step == error_mark_node
   16635          159 :           || orig_step == error_mark_node)
   16636              :         {
   16637            4 :           ret = true;
   16638            4 :           continue;
   16639              :         }
   16640          159 :       hash_set<tree> pset;
   16641          159 :       tree it2;
   16642          200 :       for (it2 = TREE_CHAIN (it); it2; it2 = TREE_CHAIN (it2))
   16643              :         {
   16644           49 :           tree var2 = OMP_ITERATOR_VAR (it2);
   16645           49 :           tree begin2 = OMP_ITERATOR_BEGIN (it2);
   16646           49 :           tree end2 = OMP_ITERATOR_END (it2);
   16647           49 :           tree step2 = OMP_ITERATOR_STEP (it2);
   16648           49 :           tree type2 = TREE_TYPE (var2);
   16649           49 :           location_t loc2 = DECL_SOURCE_LOCATION (var2);
   16650           49 :           struct c_find_omp_var_s data = { var, &pset };
   16651           49 :           if (walk_tree (&type2, c_find_omp_var_r, &data, &pset))
   16652              :             {
   16653            2 :               error_at (loc2,
   16654              :                         "type of iterator %qD refers to outer iterator %qD",
   16655              :                         var2, var);
   16656           10 :               break;
   16657              :             }
   16658           47 :           else if (walk_tree (&begin2, c_find_omp_var_r, &data, &pset))
   16659              :             {
   16660            2 :               error_at (EXPR_LOC_OR_LOC (begin2, loc2),
   16661              :                         "begin expression refers to outer iterator %qD", var);
   16662            2 :               break;
   16663              :             }
   16664           45 :           else if (walk_tree (&end2, c_find_omp_var_r, &data, &pset))
   16665              :             {
   16666            2 :               error_at (EXPR_LOC_OR_LOC (end2, loc2),
   16667              :                         "end expression refers to outer iterator %qD", var);
   16668            2 :               break;
   16669              :             }
   16670           43 :           else if (walk_tree (&step2, c_find_omp_var_r, &data, &pset))
   16671              :             {
   16672            2 :               error_at (EXPR_LOC_OR_LOC (step2, loc2),
   16673              :                         "step expression refers to outer iterator %qD", var);
   16674            2 :               break;
   16675              :             }
   16676              :         }
   16677          159 :       if (it2)
   16678              :         {
   16679            8 :           ret = true;
   16680            8 :           continue;
   16681              :         }
   16682          151 :       OMP_ITERATOR_BEGIN (it) = begin;
   16683          151 :       OMP_ITERATOR_END (it) = end;
   16684          151 :       OMP_ITERATOR_STEP (it) = step;
   16685          151 :       OMP_ITERATOR_ORIG_STEP (it) = orig_step;
   16686          159 :     }
   16687          146 :   return ret;
   16688              : }
   16689              : 
   16690              : /* Ensure that pointers are used in OpenACC attach and detach clauses.
   16691              :    Return true if an error has been detected.  */
   16692              : 
   16693              : static bool
   16694         9728 : c_oacc_check_attachments (tree c)
   16695              : {
   16696         9728 :   if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
   16697              :     return false;
   16698              : 
   16699              :   /* OpenACC attach / detach clauses must be pointers.  */
   16700         6682 :   if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
   16701         6682 :       || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
   16702              :     {
   16703           75 :       tree t = OMP_CLAUSE_DECL (c);
   16704              : 
   16705           81 :       while (TREE_CODE (t) == OMP_ARRAY_SECTION)
   16706            6 :         t = TREE_OPERAND (t, 0);
   16707              : 
   16708           75 :       if (TREE_CODE (TREE_TYPE (t)) != POINTER_TYPE)
   16709              :         {
   16710            6 :           error_at (OMP_CLAUSE_LOCATION (c), "expected pointer in %qs clause",
   16711              :                     user_omp_clause_code_name (c, true));
   16712            6 :           return true;
   16713              :         }
   16714              :     }
   16715              : 
   16716              :   return false;
   16717              : }
   16718              : 
   16719              : /* For all elements of CLAUSES, validate them against their constraints.
   16720              :    Remove any elements from the list that are invalid.  */
   16721              : 
   16722              : tree
   16723        29889 : c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
   16724              : {
   16725        29889 :   bitmap_head generic_head, firstprivate_head, lastprivate_head;
   16726        29889 :   bitmap_head aligned_head, map_head, map_field_head, map_firstprivate_head;
   16727        29889 :   bitmap_head oacc_reduction_head, is_on_device_head;
   16728        29889 :   tree c, t, type, *pc;
   16729        29889 :   tree simdlen = NULL_TREE, safelen = NULL_TREE;
   16730        29889 :   bool branch_seen = false;
   16731        29889 :   bool copyprivate_seen = false;
   16732        29889 :   bool mergeable_seen = false;
   16733        29889 :   tree *detach_seen = NULL;
   16734        29889 :   bool linear_variable_step_check = false;
   16735        29889 :   tree *nowait_clause = NULL;
   16736        29889 :   tree *grainsize_seen = NULL;
   16737        29889 :   bool num_tasks_seen = false;
   16738        29889 :   tree ordered_clause = NULL_TREE;
   16739        29889 :   tree schedule_clause = NULL_TREE;
   16740        29889 :   bool oacc_async = false;
   16741        29889 :   tree last_iterators = NULL_TREE;
   16742        29889 :   bool last_iterators_remove = false;
   16743        29889 :   tree *nogroup_seen = NULL;
   16744        29889 :   tree *order_clause = NULL;
   16745              :   /* 1 if normal/task reduction has been seen, -1 if inscan reduction
   16746              :      has been seen, -2 if mixed inscan/normal reduction diagnosed.  */
   16747        29889 :   int reduction_seen = 0;
   16748        29889 :   bool allocate_seen = false;
   16749        29889 :   bool implicit_moved = false;
   16750        29889 :   bool target_in_reduction_seen = false;
   16751        29889 :   tree *full_seen = NULL;
   16752        29889 :   bool partial_seen = false;
   16753        29889 :   bool openacc = (ort & C_ORT_ACC) != 0;
   16754        29889 :   bool init_seen = false;
   16755        29889 :   bool init_use_destroy_seen = false;
   16756        29889 :   tree init_no_targetsync_clause = NULL_TREE;
   16757        29889 :   tree depend_clause = NULL_TREE;
   16758              : 
   16759        29889 :   if (!openacc)
   16760        24652 :     clauses = omp_remove_duplicate_maps (clauses, true);
   16761              : 
   16762        29889 :   bitmap_obstack_initialize (NULL);
   16763        29889 :   bitmap_initialize (&generic_head, &bitmap_default_obstack);
   16764        29889 :   bitmap_initialize (&firstprivate_head, &bitmap_default_obstack);
   16765        29889 :   bitmap_initialize (&lastprivate_head, &bitmap_default_obstack);
   16766        29889 :   bitmap_initialize (&aligned_head, &bitmap_default_obstack);
   16767              :   /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead.  */
   16768        29889 :   bitmap_initialize (&map_head, &bitmap_default_obstack);
   16769        29889 :   bitmap_initialize (&map_field_head, &bitmap_default_obstack);
   16770        29889 :   bitmap_initialize (&map_firstprivate_head, &bitmap_default_obstack);
   16771              :   /* If ort == C_ORT_OMP used as nontemporal_head or use_device_xxx_head
   16772              :      instead and for ort == C_ORT_OMP_TARGET used as in_reduction_head.  */
   16773        29889 :   bitmap_initialize (&oacc_reduction_head, &bitmap_default_obstack);
   16774        29889 :   bitmap_initialize (&is_on_device_head, &bitmap_default_obstack);
   16775              : 
   16776        29889 :   if (openacc)
   16777        12269 :     for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
   16778         7258 :       if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ASYNC)
   16779              :         {
   16780              :           oacc_async = true;
   16781              :           break;
   16782              :         }
   16783              : 
   16784        29889 :   tree *grp_start_p = NULL, grp_sentinel = NULL_TREE;
   16785              : 
   16786        78372 :   for (pc = &clauses, c = clauses; c ; c = *pc)
   16787              :     {
   16788        48483 :       bool remove = false;
   16789        48483 :       bool need_complete = false;
   16790        48483 :       bool need_implicitly_determined = false;
   16791              : 
   16792              :       /* We've reached the end of a list of expanded nodes.  Reset the group
   16793              :          start pointer.  */
   16794        48483 :       if (c == grp_sentinel)
   16795              :         {
   16796         2543 :           if (grp_start_p
   16797         2543 :               && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
   16798           32 :             for (tree gc = *grp_start_p; gc != grp_sentinel;
   16799           22 :                  gc = OMP_CLAUSE_CHAIN (gc))
   16800           22 :               OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
   16801              :           grp_start_p = NULL;
   16802              :         }
   16803              : 
   16804        48483 :       switch (OMP_CLAUSE_CODE (c))
   16805              :         {
   16806         1174 :         case OMP_CLAUSE_SHARED:
   16807         1174 :           need_implicitly_determined = true;
   16808         1174 :           goto check_dup_generic;
   16809              : 
   16810          851 :         case OMP_CLAUSE_PRIVATE:
   16811          851 :           need_complete = true;
   16812          851 :           need_implicitly_determined = true;
   16813          851 :           goto check_dup_generic;
   16814              : 
   16815         3542 :         case OMP_CLAUSE_REDUCTION:
   16816         3542 :           if (reduction_seen == 0)
   16817         2938 :             reduction_seen = OMP_CLAUSE_REDUCTION_INSCAN (c) ? -1 : 1;
   16818          604 :           else if (reduction_seen != -2
   16819         1208 :                    && reduction_seen != (OMP_CLAUSE_REDUCTION_INSCAN (c)
   16820          604 :                                          ? -1 : 1))
   16821              :             {
   16822            2 :               error_at (OMP_CLAUSE_LOCATION (c),
   16823              :                         "%<inscan%> and non-%<inscan%> %<reduction%> clauses "
   16824              :                         "on the same construct");
   16825            2 :               reduction_seen = -2;
   16826              :             }
   16827              :           /* FALLTHRU */
   16828         4207 :         case OMP_CLAUSE_IN_REDUCTION:
   16829         4207 :         case OMP_CLAUSE_TASK_REDUCTION:
   16830         4207 :           need_implicitly_determined = true;
   16831         4207 :           t = OMP_CLAUSE_DECL (c);
   16832         4207 :           if (TREE_CODE (t) == OMP_ARRAY_SECTION)
   16833              :             {
   16834          553 :               if (handle_omp_array_sections (c, ort))
   16835              :                 {
   16836              :                   remove = true;
   16837              :                   break;
   16838              :                 }
   16839              : 
   16840          537 :               t = OMP_CLAUSE_DECL (c);
   16841          537 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   16842          537 :                   && OMP_CLAUSE_REDUCTION_INSCAN (c))
   16843              :                 {
   16844            1 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16845              :                             "%<inscan%> %<reduction%> clause with array "
   16846              :                             "section");
   16847            1 :                   remove = true;
   16848            1 :                   break;
   16849              :                 }
   16850              :             }
   16851         4190 :           t = require_complete_type (OMP_CLAUSE_LOCATION (c), t);
   16852         4190 :           if (t == error_mark_node)
   16853              :             {
   16854              :               remove = true;
   16855              :               break;
   16856              :             }
   16857         4188 :           if (oacc_async)
   16858            3 :             c_mark_addressable (t);
   16859         4188 :           type = TREE_TYPE (t);
   16860         4188 :           if (TREE_CODE (t) == MEM_REF)
   16861          536 :             type = TREE_TYPE (type);
   16862         4188 :           if (TREE_CODE (type) == ARRAY_TYPE)
   16863              :             {
   16864           74 :               tree oatype = type;
   16865           74 :               gcc_assert (TREE_CODE (t) != MEM_REF);
   16866          148 :               while (TREE_CODE (type) == ARRAY_TYPE)
   16867           74 :                 type = TREE_TYPE (type);
   16868           74 :               if (integer_zerop (TYPE_SIZE_UNIT (type)))
   16869              :                 {
   16870            1 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16871              :                             "%qD in %<reduction%> clause is a zero size array",
   16872              :                             t);
   16873            1 :                   remove = true;
   16874            1 :                   break;
   16875              :                 }
   16876           73 :               tree size = size_binop (EXACT_DIV_EXPR, TYPE_SIZE_UNIT (oatype),
   16877              :                                       TYPE_SIZE_UNIT (type));
   16878           73 :               if (integer_zerop (size))
   16879              :                 {
   16880            1 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16881              :                             "%qD in %<reduction%> clause is a zero size array",
   16882              :                             t);
   16883            1 :                   remove = true;
   16884            1 :                   break;
   16885              :                 }
   16886           72 :               size = size_binop (MINUS_EXPR, size, size_one_node);
   16887           72 :               size = save_expr (size);
   16888           72 :               tree index_type = build_index_type (size);
   16889           72 :               tree atype = c_build_array_type (TYPE_MAIN_VARIANT (type),
   16890              :                                                index_type);
   16891           72 :               atype = c_build_qualified_type (atype, TYPE_QUALS (type));
   16892           72 :               tree ptype = c_build_pointer_type (type);
   16893           72 :               if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
   16894           72 :                 t = build_fold_addr_expr (t);
   16895           72 :               t = build2 (MEM_REF, atype, t, build_int_cst (ptype, 0));
   16896           72 :               OMP_CLAUSE_DECL (c) = t;
   16897              :             }
   16898         4186 :           if (TYPE_ATOMIC (type))
   16899              :             {
   16900            3 :               error_at (OMP_CLAUSE_LOCATION (c),
   16901              :                         "%<_Atomic%> %qE in %<reduction%> clause", t);
   16902            3 :               remove = true;
   16903            3 :               break;
   16904              :             }
   16905         4183 :           if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
   16906         4183 :               || OMP_CLAUSE_REDUCTION_TASK (c))
   16907              :             {
   16908              :               /* Disallow zero sized or potentially zero sized task
   16909              :                  reductions.  */
   16910          875 :               if (integer_zerop (TYPE_SIZE_UNIT (type)))
   16911              :                 {
   16912            6 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16913              :                             "zero sized type %qT in %qs clause", type,
   16914            3 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16915            3 :                   remove = true;
   16916            3 :                   break;
   16917              :                 }
   16918          872 :               else if (TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST)
   16919              :                 {
   16920            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16921              :                             "variable sized type %qT in %qs clause", type,
   16922            0 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16923            0 :                   remove = true;
   16924            0 :                   break;
   16925              :                 }
   16926              :             }
   16927         4180 :           if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == NULL_TREE
   16928         4180 :               && (FLOAT_TYPE_P (type)
   16929         3625 :                   || TREE_CODE (type) == COMPLEX_TYPE))
   16930              :             {
   16931          340 :               enum tree_code r_code = OMP_CLAUSE_REDUCTION_CODE (c);
   16932          340 :               const char *r_name = NULL;
   16933              : 
   16934          340 :               switch (r_code)
   16935              :                 {
   16936              :                 case PLUS_EXPR:
   16937              :                 case MULT_EXPR:
   16938              :                 case MINUS_EXPR:
   16939              :                 case TRUTH_ANDIF_EXPR:
   16940              :                 case TRUTH_ORIF_EXPR:
   16941              :                   break;
   16942           13 :                 case MIN_EXPR:
   16943           13 :                   if (TREE_CODE (type) == COMPLEX_TYPE)
   16944              :                     r_name = "min";
   16945              :                   break;
   16946           38 :                 case MAX_EXPR:
   16947           38 :                   if (TREE_CODE (type) == COMPLEX_TYPE)
   16948              :                     r_name = "max";
   16949              :                   break;
   16950            3 :                 case BIT_AND_EXPR:
   16951            3 :                   r_name = "&";
   16952            3 :                   break;
   16953            2 :                 case BIT_XOR_EXPR:
   16954            2 :                   r_name = "^";
   16955            2 :                   break;
   16956              :                 case BIT_IOR_EXPR:
   16957              :                   r_name = "|";
   16958              :                   break;
   16959            0 :                 default:
   16960            0 :                   gcc_unreachable ();
   16961              :                 }
   16962            5 :               if (r_name)
   16963              :                 {
   16964           12 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16965              :                             "%qE has invalid type for %<reduction(%s)%>",
   16966              :                             t, r_name);
   16967           12 :                   remove = true;
   16968           12 :                   break;
   16969              :                 }
   16970              :             }
   16971         3840 :           else if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == error_mark_node)
   16972              :             {
   16973            2 :               error_at (OMP_CLAUSE_LOCATION (c),
   16974              :                         "user defined reduction not found for %qE", t);
   16975            2 :               remove = true;
   16976            2 :               break;
   16977              :             }
   16978         3838 :           else if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
   16979              :             {
   16980          280 :               tree list = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c);
   16981          280 :               type = TYPE_MAIN_VARIANT (type);
   16982          280 :               tree placeholder = build_decl (OMP_CLAUSE_LOCATION (c),
   16983              :                                              VAR_DECL, NULL_TREE, type);
   16984          280 :               tree decl_placeholder = NULL_TREE;
   16985          280 :               OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = placeholder;
   16986          280 :               DECL_ARTIFICIAL (placeholder) = 1;
   16987          280 :               DECL_IGNORED_P (placeholder) = 1;
   16988          280 :               if (TREE_CODE (t) == MEM_REF)
   16989              :                 {
   16990           56 :                   decl_placeholder = build_decl (OMP_CLAUSE_LOCATION (c),
   16991              :                                                  VAR_DECL, NULL_TREE, type);
   16992           56 :                   OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c) = decl_placeholder;
   16993           56 :                   DECL_ARTIFICIAL (decl_placeholder) = 1;
   16994           56 :                   DECL_IGNORED_P (decl_placeholder) = 1;
   16995              :                 }
   16996          280 :               if (TREE_ADDRESSABLE (TREE_VEC_ELT (list, 0)))
   16997           45 :                 c_mark_addressable (placeholder);
   16998          280 :               if (TREE_ADDRESSABLE (TREE_VEC_ELT (list, 1)))
   16999           82 :                 c_mark_addressable (decl_placeholder ? decl_placeholder
   17000           37 :                                     : OMP_CLAUSE_DECL (c));
   17001          280 :               OMP_CLAUSE_REDUCTION_MERGE (c)
   17002          784 :                 = c_clone_omp_udr (TREE_VEC_ELT (list, 2),
   17003          280 :                                    TREE_VEC_ELT (list, 0),
   17004          280 :                                    TREE_VEC_ELT (list, 1),
   17005              :                                    decl_placeholder ? decl_placeholder
   17006          224 :                                    : OMP_CLAUSE_DECL (c), placeholder);
   17007          280 :               OMP_CLAUSE_REDUCTION_MERGE (c)
   17008          280 :                 = build3_loc (OMP_CLAUSE_LOCATION (c), BIND_EXPR,
   17009              :                               void_type_node, NULL_TREE,
   17010          280 :                               OMP_CLAUSE_REDUCTION_MERGE (c), NULL_TREE);
   17011          280 :               TREE_SIDE_EFFECTS (OMP_CLAUSE_REDUCTION_MERGE (c)) = 1;
   17012          280 :               if (TREE_VEC_LENGTH (list) == 6)
   17013              :                 {
   17014          236 :                   if (TREE_ADDRESSABLE (TREE_VEC_ELT (list, 3)))
   17015           70 :                     c_mark_addressable (decl_placeholder ? decl_placeholder
   17016           33 :                                         : OMP_CLAUSE_DECL (c));
   17017          236 :                   if (TREE_ADDRESSABLE (TREE_VEC_ELT (list, 4)))
   17018           30 :                     c_mark_addressable (placeholder);
   17019          236 :                   tree init = TREE_VEC_ELT (list, 5);
   17020          236 :                   if (init == error_mark_node)
   17021          200 :                     init = DECL_INITIAL (TREE_VEC_ELT (list, 3));
   17022          236 :                   OMP_CLAUSE_REDUCTION_INIT (c)
   17023          660 :                     = c_clone_omp_udr (init, TREE_VEC_ELT (list, 4),
   17024          236 :                                        TREE_VEC_ELT (list, 3),
   17025              :                                        decl_placeholder ? decl_placeholder
   17026          188 :                                        : OMP_CLAUSE_DECL (c), placeholder);
   17027          236 :                   if (TREE_VEC_ELT (list, 5) == error_mark_node)
   17028              :                     {
   17029          200 :                       tree v = decl_placeholder ? decl_placeholder : t;
   17030          200 :                       OMP_CLAUSE_REDUCTION_INIT (c)
   17031          400 :                         = build2 (INIT_EXPR, TREE_TYPE (v), v,
   17032          200 :                                   OMP_CLAUSE_REDUCTION_INIT (c));
   17033              :                     }
   17034          236 :                   if (walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c),
   17035              :                                  c_find_omp_placeholder_r,
   17036              :                                  placeholder, NULL))
   17037           31 :                     OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c) = 1;
   17038              :                 }
   17039              :               else
   17040              :                 {
   17041           44 :                   tree init;
   17042           44 :                   tree v = decl_placeholder ? decl_placeholder : t;
   17043           44 :                   if (AGGREGATE_TYPE_P (TREE_TYPE (v)))
   17044           34 :                     init = build_constructor (TREE_TYPE (v), NULL);
   17045              :                   else
   17046           10 :                     init = fold_convert (TREE_TYPE (v), integer_zero_node);
   17047           44 :                   OMP_CLAUSE_REDUCTION_INIT (c)
   17048           88 :                     = build2 (INIT_EXPR, TREE_TYPE (v), v, init);
   17049              :                 }
   17050          280 :               OMP_CLAUSE_REDUCTION_INIT (c)
   17051          280 :                 = build3_loc (OMP_CLAUSE_LOCATION (c), BIND_EXPR,
   17052              :                               void_type_node, NULL_TREE,
   17053          280 :                                OMP_CLAUSE_REDUCTION_INIT (c), NULL_TREE);
   17054          280 :               TREE_SIDE_EFFECTS (OMP_CLAUSE_REDUCTION_INIT (c)) = 1;
   17055              :             }
   17056         4166 :           if (TREE_CODE (t) == MEM_REF)
   17057              :             {
   17058          607 :               if (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t))) == NULL_TREE
   17059          607 :                   || TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t))))
   17060              :                      != INTEGER_CST)
   17061              :                 {
   17062            0 :                   sorry ("variable length element type in array "
   17063              :                          "%<reduction%> clause");
   17064            0 :                   remove = true;
   17065            0 :                   break;
   17066              :                 }
   17067          607 :               t = TREE_OPERAND (t, 0);
   17068          607 :               if (TREE_CODE (t) == POINTER_PLUS_EXPR)
   17069          139 :                 t = TREE_OPERAND (t, 0);
   17070          607 :               if (TREE_CODE (t) == ADDR_EXPR)
   17071          367 :                 t = TREE_OPERAND (t, 0);
   17072              :             }
   17073         4166 :           goto check_dup_generic_t;
   17074              : 
   17075           27 :         case OMP_CLAUSE_COPYPRIVATE:
   17076           27 :           copyprivate_seen = true;
   17077           27 :           if (nowait_clause)
   17078              :             {
   17079            1 :               error_at (OMP_CLAUSE_LOCATION (*nowait_clause),
   17080              :                         "%<nowait%> clause must not be used together "
   17081              :                         "with %<copyprivate%> clause");
   17082            1 :               *nowait_clause = OMP_CLAUSE_CHAIN (*nowait_clause);
   17083            1 :               nowait_clause = NULL;
   17084              :             }
   17085           27 :           goto check_dup_generic;
   17086              : 
   17087          100 :         case OMP_CLAUSE_COPYIN:
   17088          100 :           t = OMP_CLAUSE_DECL (c);
   17089          100 :           if (!VAR_P (t) || !DECL_THREAD_LOCAL_P (t))
   17090              :             {
   17091            5 :               error_at (OMP_CLAUSE_LOCATION (c),
   17092              :                         "%qE must be %<threadprivate%> for %<copyin%>", t);
   17093            5 :               remove = true;
   17094            5 :               break;
   17095              :             }
   17096           95 :           goto check_dup_generic;
   17097              : 
   17098          482 :         case OMP_CLAUSE_LINEAR:
   17099          482 :           if (ort != C_ORT_OMP_DECLARE_SIMD)
   17100          327 :             need_implicitly_determined = true;
   17101          482 :           t = OMP_CLAUSE_DECL (c);
   17102          482 :           if (ort != C_ORT_OMP_DECLARE_SIMD
   17103          327 :               && OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_DEFAULT
   17104          487 :               && OMP_CLAUSE_LINEAR_OLD_LINEAR_MODIFIER (c))
   17105              :             {
   17106            5 :               error_at (OMP_CLAUSE_LOCATION (c),
   17107              :                         "modifier should not be specified in %<linear%> "
   17108              :                         "clause on %<simd%> or %<for%> constructs when not "
   17109              :                         "using OpenMP 5.2 modifiers");
   17110            5 :               OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
   17111              :             }
   17112          964 :           if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
   17113          507 :               && TREE_CODE (TREE_TYPE (t)) != POINTER_TYPE)
   17114              :             {
   17115            1 :               error_at (OMP_CLAUSE_LOCATION (c),
   17116              :                         "linear clause applied to non-integral non-pointer "
   17117            1 :                         "variable with type %qT", TREE_TYPE (t));
   17118            1 :               remove = true;
   17119            1 :               break;
   17120              :             }
   17121          481 :           if (TYPE_ATOMIC (TREE_TYPE (t)))
   17122              :             {
   17123            3 :               error_at (OMP_CLAUSE_LOCATION (c),
   17124              :                         "%<_Atomic%> %qD in %<linear%> clause", t);
   17125            3 :               remove = true;
   17126            3 :               break;
   17127              :             }
   17128          478 :           if (ort == C_ORT_OMP_DECLARE_SIMD)
   17129              :             {
   17130          154 :               tree s = OMP_CLAUSE_LINEAR_STEP (c);
   17131          154 :               if (TREE_CODE (s) == PARM_DECL)
   17132              :                 {
   17133            9 :                   OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c) = 1;
   17134              :                   /* map_head bitmap is used as uniform_head if
   17135              :                      declare_simd.  */
   17136            9 :                   if (!bitmap_bit_p (&map_head, DECL_UID (s)))
   17137            5 :                     linear_variable_step_check = true;
   17138            9 :                   goto check_dup_generic;
   17139              :                 }
   17140          145 :               if (TREE_CODE (s) != INTEGER_CST)
   17141              :                 {
   17142            7 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17143              :                             "%<linear%> clause step %qE is neither constant "
   17144              :                             "nor a parameter", s);
   17145            7 :                   remove = true;
   17146            7 :                   break;
   17147              :                 }
   17148              :             }
   17149          462 :           if (TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c))) == POINTER_TYPE)
   17150              :             {
   17151           22 :               tree s = OMP_CLAUSE_LINEAR_STEP (c);
   17152           22 :               s = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
   17153           22 :                                    OMP_CLAUSE_DECL (c), s);
   17154           22 :               s = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
   17155              :                                    sizetype, fold_convert (sizetype, s),
   17156           22 :                                    fold_convert
   17157              :                                      (sizetype, OMP_CLAUSE_DECL (c)));
   17158           22 :               if (s == error_mark_node)
   17159            0 :                 s = size_one_node;
   17160           22 :               OMP_CLAUSE_LINEAR_STEP (c) = s;
   17161              :             }
   17162              :           else
   17163          440 :             OMP_CLAUSE_LINEAR_STEP (c)
   17164          880 :               = fold_convert (TREE_TYPE (t), OMP_CLAUSE_LINEAR_STEP (c));
   17165          462 :           goto check_dup_generic;
   17166              : 
   17167         2934 :         check_dup_generic:
   17168         2934 :           t = OMP_CLAUSE_DECL (c);
   17169         7189 :         check_dup_generic_t:
   17170         7189 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   17171              :             {
   17172            4 :               error_at (OMP_CLAUSE_LOCATION (c),
   17173              :                         "%qE is not a variable in clause %qs", t,
   17174            2 :                         omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17175            2 :               remove = true;
   17176              :             }
   17177         1149 :           else if ((openacc && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
   17178         6148 :                    || (ort == C_ORT_OMP
   17179         5423 :                        && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
   17180         5412 :                            || (OMP_CLAUSE_CODE (c)
   17181              :                                == OMP_CLAUSE_USE_DEVICE_ADDR)))
   17182        13288 :                    || (ort == C_ORT_OMP_TARGET
   17183          349 :                        && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION))
   17184              :             {
   17185         1196 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   17186         1196 :                   && (bitmap_bit_p (&generic_head, DECL_UID (t))
   17187          109 :                       || bitmap_bit_p (&firstprivate_head, DECL_UID (t))))
   17188              :                 {
   17189            2 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17190              :                             "%qD appears more than once in data-sharing "
   17191              :                             "clauses", t);
   17192            2 :                   remove = true;
   17193            2 :                   break;
   17194              :                 }
   17195         1194 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION)
   17196          108 :                 target_in_reduction_seen = true;
   17197         1194 :               if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
   17198              :                 {
   17199            4 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17200              :                             openacc
   17201              :                             ? "%qD appears more than once in reduction clauses"
   17202              :                             : "%qD appears more than once in data clauses",
   17203              :                             t);
   17204            2 :                   remove = true;
   17205              :                 }
   17206              :               else
   17207         1192 :                 bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
   17208              :             }
   17209         5991 :           else if (bitmap_bit_p (&generic_head, DECL_UID (t))
   17210         5968 :                    || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
   17211         5967 :                    || bitmap_bit_p (&lastprivate_head, DECL_UID (t))
   17212        11958 :                    || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
   17213              :             {
   17214           24 :               error_at (OMP_CLAUSE_LOCATION (c),
   17215              :                         "%qE appears more than once in data clauses", t);
   17216           24 :               remove = true;
   17217              :             }
   17218         5967 :           else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
   17219              :                     || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR
   17220              :                     || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
   17221         1051 :                    && bitmap_bit_p (&map_head, DECL_UID (t)))
   17222              :             {
   17223            3 :               if (openacc)
   17224            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17225              :                           "%qD appears more than once in data clauses", t);
   17226              :               else
   17227            3 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17228              :                           "%qD appears both in data and map clauses", t);
   17229              :               remove = true;
   17230              :             }
   17231              :           else
   17232         5964 :             bitmap_set_bit (&generic_head, DECL_UID (t));
   17233              :           break;
   17234              : 
   17235         1367 :         case OMP_CLAUSE_FIRSTPRIVATE:
   17236         1367 :           if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c) && !implicit_moved)
   17237              :             {
   17238          153 :             move_implicit:
   17239          153 :               implicit_moved = true;
   17240              :               /* Move firstprivate and map clauses with
   17241              :                  OMP_CLAUSE_{FIRSTPRIVATE,MAP}_IMPLICIT set to the end of
   17242              :                  clauses chain.  */
   17243          153 :               tree cl1 = NULL_TREE, cl2 = NULL_TREE;
   17244          153 :               tree *pc1 = pc, *pc2 = &cl1, *pc3 = &cl2;
   17245          972 :               while (*pc1)
   17246          819 :                 if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_FIRSTPRIVATE
   17247          819 :                     && OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (*pc1))
   17248              :                   {
   17249          113 :                     *pc3 = *pc1;
   17250          113 :                     pc3 = &OMP_CLAUSE_CHAIN (*pc3);
   17251          113 :                     *pc1 = OMP_CLAUSE_CHAIN (*pc1);
   17252              :                   }
   17253          706 :                 else if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_MAP
   17254          706 :                          && OMP_CLAUSE_MAP_IMPLICIT (*pc1))
   17255              :                   {
   17256          131 :                     *pc2 = *pc1;
   17257          131 :                     pc2 = &OMP_CLAUSE_CHAIN (*pc2);
   17258          131 :                     *pc1 = OMP_CLAUSE_CHAIN (*pc1);
   17259              :                   }
   17260              :                 else
   17261          575 :                   pc1 = &OMP_CLAUSE_CHAIN (*pc1);
   17262          153 :               *pc3 = NULL;
   17263          153 :               *pc2 = cl2;
   17264          153 :               *pc1 = cl1;
   17265          153 :               continue;
   17266          153 :             }
   17267         1272 :           t = OMP_CLAUSE_DECL (c);
   17268         1272 :           need_complete = true;
   17269         1272 :           need_implicitly_determined = true;
   17270         1272 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   17271              :             {
   17272            1 :               error_at (OMP_CLAUSE_LOCATION (c),
   17273              :                         "%qE is not a variable in clause %<firstprivate%>", t);
   17274            1 :               remove = true;
   17275              :             }
   17276         1271 :           else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
   17277          113 :                    && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c)
   17278         1377 :                    && bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
   17279              :             remove = true;
   17280         1271 :           else if (bitmap_bit_p (&generic_head, DECL_UID (t))
   17281         1269 :                    || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
   17282         2539 :                    || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
   17283              :             {
   17284            4 :               error_at (OMP_CLAUSE_LOCATION (c),
   17285              :                         "%qE appears more than once in data clauses", t);
   17286            4 :               remove = true;
   17287              :             }
   17288         1267 :           else if (bitmap_bit_p (&map_head, DECL_UID (t))
   17289         1267 :                    || bitmap_bit_p (&map_field_head, DECL_UID (t)))
   17290              :             {
   17291            7 :               if (openacc)
   17292            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17293              :                           "%qD appears more than once in data clauses", t);
   17294            7 :               else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
   17295            7 :                        && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c))
   17296              :                 /* Silently drop the clause.  */;
   17297              :               else
   17298            6 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17299              :                           "%qD appears both in data and map clauses", t);
   17300              :               remove = true;
   17301              :             }
   17302              :           else
   17303         1260 :             bitmap_set_bit (&firstprivate_head, DECL_UID (t));
   17304              :           break;
   17305              : 
   17306         1524 :         case OMP_CLAUSE_LASTPRIVATE:
   17307         1524 :           t = OMP_CLAUSE_DECL (c);
   17308         1524 :           need_complete = true;
   17309         1524 :           need_implicitly_determined = true;
   17310         1524 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   17311              :             {
   17312            0 :               error_at (OMP_CLAUSE_LOCATION (c),
   17313              :                         "%qE is not a variable in clause %<lastprivate%>", t);
   17314            0 :               remove = true;
   17315              :             }
   17316         1524 :           else if (bitmap_bit_p (&generic_head, DECL_UID (t))
   17317         1524 :                    || bitmap_bit_p (&lastprivate_head, DECL_UID (t)))
   17318              :             {
   17319            3 :               error_at (OMP_CLAUSE_LOCATION (c),
   17320              :                      "%qE appears more than once in data clauses", t);
   17321            3 :               remove = true;
   17322              :             }
   17323              :           else
   17324         1521 :             bitmap_set_bit (&lastprivate_head, DECL_UID (t));
   17325              :           break;
   17326              : 
   17327          253 :         case OMP_CLAUSE_ALIGNED:
   17328          253 :           t = OMP_CLAUSE_DECL (c);
   17329          253 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   17330              :             {
   17331            0 :               error_at (OMP_CLAUSE_LOCATION (c),
   17332              :                         "%qE is not a variable in %<aligned%> clause", t);
   17333            0 :               remove = true;
   17334              :             }
   17335          289 :           else if (!POINTER_TYPE_P (TREE_TYPE (t))
   17336          289 :                    && TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE)
   17337              :             {
   17338            7 :               error_at (OMP_CLAUSE_LOCATION (c),
   17339              :                         "%qE in %<aligned%> clause is neither a pointer nor "
   17340              :                         "an array", t);
   17341            7 :               remove = true;
   17342              :             }
   17343          246 :           else if (TYPE_ATOMIC (TREE_TYPE (t)))
   17344              :             {
   17345            1 :               error_at (OMP_CLAUSE_LOCATION (c),
   17346              :                         "%<_Atomic%> %qD in %<aligned%> clause", t);
   17347            1 :               remove = true;
   17348            1 :               break;
   17349              :             }
   17350          245 :           else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
   17351              :             {
   17352            0 :               error_at (OMP_CLAUSE_LOCATION (c),
   17353              :                         "%qE appears more than once in %<aligned%> clauses",
   17354              :                         t);
   17355            0 :               remove = true;
   17356              :             }
   17357              :           else
   17358          245 :             bitmap_set_bit (&aligned_head, DECL_UID (t));
   17359              :           break;
   17360              : 
   17361          125 :         case OMP_CLAUSE_NONTEMPORAL:
   17362          125 :           t = OMP_CLAUSE_DECL (c);
   17363          125 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   17364              :             {
   17365            0 :               error_at (OMP_CLAUSE_LOCATION (c),
   17366              :                         "%qE is not a variable in %<nontemporal%> clause", t);
   17367            0 :               remove = true;
   17368              :             }
   17369          125 :           else if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
   17370              :             {
   17371            2 :               error_at (OMP_CLAUSE_LOCATION (c),
   17372              :                         "%qE appears more than once in %<nontemporal%> "
   17373              :                         "clauses", t);
   17374            2 :               remove = true;
   17375              :             }
   17376              :           else
   17377          123 :             bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
   17378              :           break;
   17379              : 
   17380          814 :         case OMP_CLAUSE_ALLOCATE:
   17381          814 :           t = OMP_CLAUSE_DECL (c);
   17382          814 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   17383              :             {
   17384            1 :               error_at (OMP_CLAUSE_LOCATION (c),
   17385              :                         "%qE is not a variable in %<allocate%> clause", t);
   17386            1 :               remove = true;
   17387              :             }
   17388          813 :           else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
   17389              :             {
   17390            2 :               warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
   17391              :                           "%qE appears more than once in %<allocate%> clauses",
   17392              :                           t);
   17393            2 :               remove = true;
   17394              :             }
   17395              :           else
   17396              :             {
   17397          811 :               bitmap_set_bit (&aligned_head, DECL_UID (t));
   17398          811 :               if (!OMP_CLAUSE_ALLOCATE_COMBINED (c))
   17399          711 :                 allocate_seen = true;
   17400              :             }
   17401              :           break;
   17402              : 
   17403          357 :         case OMP_CLAUSE_DOACROSS:
   17404          357 :           t = OMP_CLAUSE_DECL (c);
   17405          357 :           if (t == NULL_TREE)
   17406              :             break;
   17407          169 :           if (OMP_CLAUSE_DOACROSS_KIND (c) == OMP_CLAUSE_DOACROSS_SINK)
   17408              :             {
   17409          169 :               gcc_assert (TREE_CODE (t) == TREE_LIST);
   17410         1315 :               for (; t; t = TREE_CHAIN (t))
   17411              :                 {
   17412         1146 :                   tree decl = TREE_VALUE (t);
   17413         1146 :                   if (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE)
   17414              :                     {
   17415            3 :                       tree offset = TREE_PURPOSE (t);
   17416            3 :                       bool neg = wi::neg_p (wi::to_wide (offset));
   17417            3 :                       offset = fold_unary (ABS_EXPR, TREE_TYPE (offset), offset);
   17418            6 :                       tree t2 = pointer_int_sum (OMP_CLAUSE_LOCATION (c),
   17419              :                                                  neg ? MINUS_EXPR : PLUS_EXPR,
   17420              :                                                  decl, offset);
   17421            3 :                       t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
   17422              :                                             sizetype,
   17423              :                                             fold_convert (sizetype, t2),
   17424              :                                             fold_convert (sizetype, decl));
   17425            3 :                       if (t2 == error_mark_node)
   17426              :                         {
   17427              :                           remove = true;
   17428              :                           break;
   17429              :                         }
   17430            3 :                       TREE_PURPOSE (t) = t2;
   17431              :                     }
   17432              :                 }
   17433              :               break;
   17434              :             }
   17435            0 :           gcc_unreachable ();
   17436              : 
   17437           64 :         case OMP_CLAUSE_USES_ALLOCATORS:
   17438           64 :           t = OMP_CLAUSE_USES_ALLOCATORS_ALLOCATOR (c);
   17439           64 :           if (t == error_mark_node)
   17440              :             {
   17441              :               remove = true;
   17442              :               break;
   17443              :             }
   17444            8 :           if ((VAR_P (t) || TREE_CODE (t) == PARM_DECL)
   17445           60 :               && (bitmap_bit_p (&generic_head, DECL_UID (t))
   17446           52 :                   || bitmap_bit_p (&map_head, DECL_UID (t))
   17447           52 :                   || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
   17448           51 :                   || bitmap_bit_p (&lastprivate_head, DECL_UID (t))))
   17449              :             {
   17450            1 :               error_at (OMP_CLAUSE_LOCATION (c),
   17451              :                         "%qE appears more than once in data clauses", t);
   17452            1 :               remove = true;
   17453            1 :               break;
   17454              :             }
   17455              :           else
   17456           58 :             bitmap_set_bit (&generic_head, DECL_UID (t));
   17457           58 :           if (TREE_CODE (TREE_TYPE (t)) != ENUMERAL_TYPE
   17458          113 :               || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (TREE_TYPE (t))),
   17459              :                          "omp_allocator_handle_t") != 0)
   17460              :             {
   17461            3 :               error_at (OMP_CLAUSE_LOCATION (c),
   17462              :                         "allocator %qE must be of %<omp_allocator_handle_t%> "
   17463              :                         "type", t);
   17464            3 :               remove = true;
   17465            3 :               break;
   17466              :             }
   17467           55 :           tree init;
   17468           55 :           if (!DECL_P (t)
   17469           55 :               || (TREE_CODE (t) == CONST_DECL
   17470            7 :                   && ((init = DECL_INITIAL(t)) == nullptr
   17471            7 :                       || TREE_CODE (init) != INTEGER_CST
   17472            7 :                       || ((wi::to_widest (init) < 0
   17473            7 :                            || wi::to_widest (init) > GOMP_OMP_PREDEF_ALLOC_MAX)
   17474            0 :                           && (wi::to_widest (init) < GOMP_OMPX_PREDEF_ALLOC_MIN
   17475            0 :                               || (wi::to_widest (init)
   17476            0 :                                   > GOMP_OMPX_PREDEF_ALLOC_MAX))))))
   17477              :             {
   17478            0 :               remove = true;
   17479            0 :               error_at (OMP_CLAUSE_LOCATION (c),
   17480              :                         "allocator %qE must be either a variable or a "
   17481              :                         "predefined allocator", t);
   17482            0 :               break;
   17483              :             }
   17484           55 :           else if (TREE_CODE (t) == CONST_DECL)
   17485              :             {
   17486              :               /* omp_null_allocator is ignored and for predefined allocators,
   17487              :                  no special handling is required; thus, mark them removed. */
   17488            7 :               remove = true;
   17489              : 
   17490            7 :               if (OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE (c)
   17491            7 :                   || OMP_CLAUSE_USES_ALLOCATORS_TRAITS (c))
   17492              :                 {
   17493            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17494              :                             "modifiers cannot be used with predefined "
   17495              :                             "allocator %qE", t);
   17496            0 :                   break;
   17497              :                 }
   17498              :             }
   17499           55 :           t = OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE (c);
   17500           55 :           if (t == error_mark_node)
   17501              :             {
   17502              :               remove = true;
   17503              :               break;
   17504              :             }
   17505           55 :           if (t != NULL_TREE
   17506           55 :               && ((TREE_CODE (t) != CONST_DECL && TREE_CODE (t) != INTEGER_CST)
   17507           11 :                   || TREE_CODE (TREE_TYPE (t)) != ENUMERAL_TYPE
   17508           20 :                   || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (TREE_TYPE (t))),
   17509              :                              "omp_memspace_handle_t") != 0))
   17510              :             {
   17511            1 :               error_at (OMP_CLAUSE_LOCATION (c), "memspace modifier %qE must be"
   17512              :                         " constant enum of %<omp_memspace_handle_t%> type", t);
   17513            1 :               remove = true;
   17514            1 :               break;
   17515              :             }
   17516           54 :           t = OMP_CLAUSE_USES_ALLOCATORS_TRAITS (c);
   17517           54 :           if (t == error_mark_node)
   17518              :             {
   17519              :               remove = true;
   17520              :               break;
   17521              :             }
   17522           54 :           if (t != NULL_TREE
   17523              :               && t != error_mark_node
   17524           54 :               && (DECL_EXTERNAL (t)
   17525           25 :                   || TREE_CODE (t) == PARM_DECL))
   17526              :             {
   17527            3 :               error_at (OMP_CLAUSE_LOCATION (c), "traits array %qE must be "
   17528              :                         "defined in same scope as the construct on which the "
   17529              :                         "clause appears", t);
   17530            3 :               remove = true;
   17531              :             }
   17532           54 :           if (t != NULL_TREE)
   17533              :             {
   17534           27 :               bool type_err = false;
   17535              : 
   17536           27 :               if (TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE
   17537           26 :                   || DECL_SIZE (t) == NULL_TREE
   17538           52 :                   || !COMPLETE_TYPE_P (TREE_TYPE (t)))
   17539              :                 type_err = true;
   17540              :               else
   17541              :                 {
   17542           25 :                   tree elem_t = TREE_TYPE (TREE_TYPE (t));
   17543           25 :                   if (TREE_CODE (elem_t) != RECORD_TYPE
   17544           50 :                       || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (elem_t)),
   17545              :                                  "omp_alloctrait_t") != 0
   17546           50 :                       || !TYPE_READONLY (elem_t))
   17547              :                     type_err = true;
   17548              :                 }
   17549           24 :               if (type_err)
   17550              :                 {
   17551            3 :                   if (t != error_mark_node)
   17552            3 :                     error_at (OMP_CLAUSE_LOCATION (c), "traits array %qE must "
   17553              :                               "be of %<const omp_alloctrait_t []%> type", t);
   17554              :                   else
   17555            0 :                     error_at (OMP_CLAUSE_LOCATION (c), "traits array must "
   17556              :                               "be of %<const omp_alloctrait_t []%> type");
   17557              :                   remove = true;
   17558              :                 }
   17559              :               else
   17560              :                 {
   17561           24 :                   tree cst_val = decl_constant_value_1 (t, true);
   17562           24 :                   if (cst_val == t)
   17563              :                     {
   17564            1 :                       error_at (OMP_CLAUSE_LOCATION (c), "traits array must be "
   17565              :                                 "initialized with constants");
   17566              : 
   17567            1 :                       remove = true;
   17568              :                     }
   17569              :                 }
   17570              :             }
   17571           54 :           if (remove)
   17572              :             break;
   17573           43 :           pc = &OMP_CLAUSE_CHAIN (c);
   17574           43 :           continue;
   17575          713 :         case OMP_CLAUSE_DEPEND:
   17576          713 :           depend_clause = c;
   17577              :           /* FALLTHRU */
   17578          875 :         case OMP_CLAUSE_AFFINITY:
   17579          875 :           t = OMP_CLAUSE_DECL (c);
   17580          875 :           if (OMP_ITERATOR_DECL_P (t))
   17581              :             {
   17582          131 :               if (TREE_PURPOSE (t) != last_iterators)
   17583          111 :                 last_iterators_remove
   17584          111 :                   = c_omp_finish_iterators (TREE_PURPOSE (t));
   17585          131 :               last_iterators = TREE_PURPOSE (t);
   17586          131 :               t = TREE_VALUE (t);
   17587          131 :               if (last_iterators_remove)
   17588           34 :                 t = error_mark_node;
   17589              :             }
   17590              :           else
   17591              :             last_iterators = NULL_TREE;
   17592          875 :           if (TREE_CODE (t) == OMP_ARRAY_SECTION)
   17593              :             {
   17594          418 :               if (handle_omp_array_sections (c, ort))
   17595              :                 remove = true;
   17596          336 :               else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   17597          336 :                        && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ)
   17598              :                 {
   17599            1 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17600              :                             "%<depend%> clause with %<depobj%> dependence "
   17601              :                             "type on array section");
   17602            1 :                   remove = true;
   17603              :                 }
   17604              :               break;
   17605              :             }
   17606          457 :           if (t == error_mark_node)
   17607              :             remove = true;
   17608          423 :           else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   17609          423 :                    && t == ridpointers[RID_OMP_ALL_MEMORY])
   17610              :             {
   17611           15 :               if (OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_OUT
   17612           15 :                   && OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_INOUT)
   17613              :                 {
   17614            3 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17615              :                             "%<omp_all_memory%> used with %<depend%> kind "
   17616              :                             "other than %<out%> or %<inout%>");
   17617            3 :                   remove = true;
   17618              :                 }
   17619              :             }
   17620          408 :           else if (!lvalue_p (t))
   17621              :             {
   17622            6 :               error_at (OMP_CLAUSE_LOCATION (c),
   17623              :                         "%qE is not lvalue expression nor array section in "
   17624              :                         "%qs clause", t,
   17625            3 :                         omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17626            3 :               remove = true;
   17627              :             }
   17628          405 :           else if (TREE_CODE (t) == COMPONENT_REF
   17629          405 :                    && DECL_C_BIT_FIELD (TREE_OPERAND (t, 1)))
   17630              :             {
   17631            2 :               gcc_assert (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   17632              :                           || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY);
   17633            2 :               error_at (OMP_CLAUSE_LOCATION (c),
   17634              :                         "bit-field %qE in %qs clause", t,
   17635            2 :                         omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17636            2 :               remove = true;
   17637              :             }
   17638          403 :           else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   17639          403 :                    && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ)
   17640              :             {
   17641           20 :               if (!c_omp_depend_t_p (TREE_TYPE (t)))
   17642              :                 {
   17643            2 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17644              :                             "%qE does not have %<omp_depend_t%> type in "
   17645              :                             "%<depend%> clause with %<depobj%> dependence "
   17646              :                             "type", t);
   17647            2 :                   remove = true;
   17648              :                 }
   17649              :             }
   17650          383 :           else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   17651          383 :                    && c_omp_depend_t_p (TREE_TYPE (t)))
   17652              :             {
   17653            2 :               error_at (OMP_CLAUSE_LOCATION (c),
   17654              :                         "%qE should not have %<omp_depend_t%> type in "
   17655              :                         "%<depend%> clause with dependence type other than "
   17656              :                         "%<depobj%>", t);
   17657            2 :               remove = true;
   17658              :             }
   17659           12 :           if (!remove)
   17660              :             {
   17661          411 :               if (t == ridpointers[RID_OMP_ALL_MEMORY])
   17662           12 :                 t = null_pointer_node;
   17663              :               else
   17664              :                 {
   17665          399 :                   tree addr = build_unary_op (OMP_CLAUSE_LOCATION (c),
   17666              :                                               ADDR_EXPR, t, false);
   17667          399 :                   if (addr == error_mark_node)
   17668              :                     {
   17669              :                       remove = true;
   17670              :                       break;
   17671              :                     }
   17672          399 :                   t = build_indirect_ref (OMP_CLAUSE_LOCATION (c), addr,
   17673              :                                           RO_UNARY_STAR);
   17674          399 :                   if (t == error_mark_node)
   17675              :                     {
   17676              :                       remove = true;
   17677              :                       break;
   17678              :                     }
   17679              :                 }
   17680          411 :               if (OMP_ITERATOR_DECL_P (OMP_CLAUSE_DECL (c)))
   17681           31 :                 TREE_VALUE (OMP_CLAUSE_DECL (c)) = t;
   17682              :               else
   17683          380 :                 OMP_CLAUSE_DECL (c) = t;
   17684              :             }
   17685              :           break;
   17686              : 
   17687         6788 :         case OMP_CLAUSE_MAP:
   17688         6788 :           if (OMP_CLAUSE_MAP_IMPLICIT (c) && !implicit_moved)
   17689           58 :             goto move_implicit;
   17690         6730 :           if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_PUSH_MAPPER_NAME
   17691         6730 :               || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POP_MAPPER_NAME)
   17692              :             {
   17693              :               remove = true;
   17694              :               break;
   17695              :             }
   17696              :           /* FALLTHRU */
   17697         9622 :         case OMP_CLAUSE_TO:
   17698         9622 :         case OMP_CLAUSE_FROM:
   17699         9622 :           if (OMP_CLAUSE_ITERATORS (c)
   17700         9622 :               && c_omp_finish_iterators (OMP_CLAUSE_ITERATORS (c)))
   17701              :             {
   17702        23225 :               t = error_mark_node;
   17703              :               break;
   17704              :             }
   17705              :           /* FALLTHRU */
   17706         9758 :         case OMP_CLAUSE__CACHE_:
   17707         9758 :           {
   17708         9758 :             using namespace omp_addr_tokenizer;
   17709         9758 :             auto_vec<omp_addr_token *, 10> addr_tokens;
   17710              : 
   17711         9758 :             t = OMP_CLAUSE_DECL (c);
   17712         9758 :             if (TREE_CODE (t) == OMP_ARRAY_SECTION)
   17713              :               {
   17714         2019 :                 grp_start_p = pc;
   17715         2019 :                 grp_sentinel = OMP_CLAUSE_CHAIN (c);
   17716              : 
   17717         2019 :                 if (handle_omp_array_sections (c, ort))
   17718              :                   remove = true;
   17719              :                 else
   17720              :                   {
   17721         1879 :                     t = OMP_CLAUSE_DECL (c);
   17722         1879 :                     if (!omp_mappable_type (TREE_TYPE (t)))
   17723              :                       {
   17724            2 :                         error_at (OMP_CLAUSE_LOCATION (c),
   17725              :                                   "array section does not have mappable type "
   17726              :                                   "in %qs clause",
   17727            1 :                                   omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17728            1 :                         remove = true;
   17729              :                       }
   17730         1878 :                     else if (TYPE_ATOMIC (TREE_TYPE (t)))
   17731              :                       {
   17732            2 :                         error_at (OMP_CLAUSE_LOCATION (c),
   17733              :                                   "%<_Atomic%> %qE in %qs clause", t,
   17734            1 :                                   omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17735            1 :                         remove = true;
   17736              :                       }
   17737         2534 :                     while (TREE_CODE (t) == ARRAY_REF)
   17738          655 :                       t = TREE_OPERAND (t, 0);
   17739              : 
   17740         1879 :                     c_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
   17741              : 
   17742         1879 :                     if (!omp_parse_expr (addr_tokens, t))
   17743              :                       {
   17744            0 :                         sorry_at (OMP_CLAUSE_LOCATION (c),
   17745              :                                   "unsupported map expression %qE",
   17746            0 :                                   OMP_CLAUSE_DECL (c));
   17747            0 :                         remove = true;
   17748            0 :                         break;
   17749              :                       }
   17750              : 
   17751              :                     /* This check is to determine if this will be the only map
   17752              :                        node created for this clause.  Otherwise, we'll check
   17753              :                        the following FIRSTPRIVATE_POINTER or ATTACH_DETACH
   17754              :                        node on the next iteration(s) of the loop.   */
   17755         1879 :                     if (addr_tokens.length () >= 4
   17756          308 :                         && addr_tokens[0]->type == STRUCTURE_BASE
   17757          306 :                         && addr_tokens[0]->u.structure_base_kind == BASE_DECL
   17758          306 :                         && addr_tokens[1]->type == ACCESS_METHOD
   17759          306 :                         && addr_tokens[2]->type == COMPONENT_SELECTOR
   17760          306 :                         && addr_tokens[3]->type == ACCESS_METHOD
   17761         2124 :                         && (addr_tokens[3]->u.access_kind == ACCESS_DIRECT
   17762          192 :                             || (addr_tokens[3]->u.access_kind
   17763              :                                 == ACCESS_INDEXED_ARRAY)))
   17764              :                       {
   17765           57 :                         tree rt = addr_tokens[1]->expr;
   17766              : 
   17767           57 :                         gcc_assert (DECL_P (rt));
   17768              : 
   17769           57 :                         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   17770           52 :                             && OMP_CLAUSE_MAP_IMPLICIT (c)
   17771           57 :                             && (bitmap_bit_p (&map_head, DECL_UID (rt))
   17772            0 :                                 || bitmap_bit_p (&map_field_head, DECL_UID (rt))
   17773            0 :                                 || bitmap_bit_p (&map_firstprivate_head,
   17774            0 :                                                  DECL_UID (rt))))
   17775              :                           {
   17776              :                             remove = true;
   17777              :                             break;
   17778              :                           }
   17779           57 :                         if (bitmap_bit_p (&map_field_head, DECL_UID (rt)))
   17780              :                           break;
   17781           39 :                         if (bitmap_bit_p (&map_head, DECL_UID (rt)))
   17782              :                           {
   17783            0 :                             if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
   17784            0 :                               error_at (OMP_CLAUSE_LOCATION (c),
   17785              :                                         "%qD appears more than once in motion "
   17786              :                                         "clauses", rt);
   17787            0 :                             else if (openacc)
   17788            0 :                               error_at (OMP_CLAUSE_LOCATION (c),
   17789              :                                         "%qD appears more than once in data "
   17790              :                                         "clauses", rt);
   17791              :                             else
   17792            0 :                               error_at (OMP_CLAUSE_LOCATION (c),
   17793              :                                         "%qD appears more than once in map "
   17794              :                                         "clauses", rt);
   17795              :                             remove = true;
   17796              :                           }
   17797              :                         else
   17798              :                           {
   17799           39 :                             bitmap_set_bit (&map_head, DECL_UID (rt));
   17800           39 :                             bitmap_set_bit (&map_field_head, DECL_UID (rt));
   17801              :                           }
   17802              :                       }
   17803              :                   }
   17804         2001 :                 if (c_oacc_check_attachments (c))
   17805            2 :                   remove = true;
   17806         2001 :                 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   17807         1819 :                     && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
   17808         1799 :                         || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
   17809         2028 :                     && !OMP_CLAUSE_SIZE (c))
   17810              :                   /* In this case, we have a single array element which is a
   17811              :                      pointer, and we already set OMP_CLAUSE_SIZE in
   17812              :                      handle_omp_array_sections above.  For attach/detach
   17813              :                      clauses, reset the OMP_CLAUSE_SIZE (representing a bias)
   17814              :                      to zero here.  */
   17815           10 :                   OMP_CLAUSE_SIZE (c) = size_zero_node;
   17816              :                 break;
   17817              :               }
   17818         7739 :             else if (!omp_parse_expr (addr_tokens, t))
   17819              :               {
   17820            0 :                 sorry_at (OMP_CLAUSE_LOCATION (c),
   17821              :                           "unsupported map expression %qE",
   17822            0 :                           OMP_CLAUSE_DECL (c));
   17823            0 :                 remove = true;
   17824            0 :                 break;
   17825              :               }
   17826         7739 :             if (t == error_mark_node)
   17827              :               {
   17828              :                 remove = true;
   17829              :                 break;
   17830              :               }
   17831              : 
   17832         7727 :             tree attr;
   17833         7727 :             if (DECL_P (t)
   17834         7138 :                 && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   17835         4315 :                 && (attr = lookup_attribute ("omp declare target",
   17836         4315 :                                              DECL_ATTRIBUTES (t)))
   17837         7967 :                 && value_member (get_identifier ("local"),
   17838          240 :                                  TREE_VALUE (attr)))
   17839              :               {
   17840            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17841              :                           "device-local variable %qD cannot appear "
   17842              :                           "in map clause", t);
   17843            0 :                 remove = true;
   17844            0 :                 break;
   17845              :               }
   17846              : 
   17847              :             /* OpenACC attach / detach clauses must be pointers.  */
   17848         7727 :             if (c_oacc_check_attachments (c))
   17849              :               {
   17850              :                 remove = true;
   17851              :                 break;
   17852              :               }
   17853         7723 :             if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   17854         4859 :                 && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
   17855         4830 :                     || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
   17856         7767 :                 && !OMP_CLAUSE_SIZE (c))
   17857              :               /* For attach/detach clauses, set OMP_CLAUSE_SIZE (representing a
   17858              :                  bias) to zero here, so it is not set erroneously to the pointer
   17859              :                  size later on in gimplify.cc.  */
   17860           28 :               OMP_CLAUSE_SIZE (c) = size_zero_node;
   17861              : 
   17862         7723 :             c_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
   17863              : 
   17864         7723 :             if (!ai.check_clause (c))
   17865              :               {
   17866              :                 remove = true;
   17867              :                 break;
   17868              :               }
   17869              : 
   17870         7715 :             if (!ai.map_supported_p ())
   17871              :               {
   17872           14 :                 sorry_at (OMP_CLAUSE_LOCATION (c),
   17873              :                           "unsupported map expression %qE",
   17874            7 :                           OMP_CLAUSE_DECL (c));
   17875            7 :                 remove = true;
   17876            7 :                 break;
   17877              :               }
   17878              : 
   17879        15416 :             gcc_assert ((addr_tokens[0]->type == ARRAY_BASE
   17880              :                          || addr_tokens[0]->type == STRUCTURE_BASE)
   17881              :                         && addr_tokens[1]->type == ACCESS_METHOD);
   17882              : 
   17883         7708 :             t = addr_tokens[1]->expr;
   17884              : 
   17885         7708 :             if (addr_tokens[0]->u.structure_base_kind != BASE_DECL)
   17886            0 :               goto skip_decl_checks;
   17887              : 
   17888              :             /* For OpenMP, we can access a struct "t" and "t.d" on the same
   17889              :                mapping.  OpenACC allows multiple fields of the same structure
   17890              :                to be written.  */
   17891         7708 :             if (addr_tokens[0]->type == STRUCTURE_BASE
   17892         7708 :                 && (bitmap_bit_p (&map_field_head, DECL_UID (t))
   17893          267 :                     || (!openacc && bitmap_bit_p (&map_head, DECL_UID (t)))))
   17894          309 :               goto skip_decl_checks;
   17895              : 
   17896         7399 :             if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   17897              :               {
   17898            3 :                 if (ort != C_ORT_ACC && EXPR_P (t))
   17899              :                   break;
   17900              : 
   17901            6 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17902              :                           "%qE is not a variable in %qs clause", t,
   17903            3 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17904            3 :                 remove = true;
   17905              :               }
   17906         7396 :             else if (VAR_P (t) && DECL_THREAD_LOCAL_P (t))
   17907              :               {
   17908            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17909              :                           "%qD is threadprivate variable in %qs clause", t,
   17910            0 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17911            0 :                 remove = true;
   17912              :               }
   17913         7396 :             else if ((OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
   17914         4559 :                       || (OMP_CLAUSE_MAP_KIND (c)
   17915              :                           != GOMP_MAP_FIRSTPRIVATE_POINTER))
   17916        10911 :                      && !c_mark_addressable (t))
   17917              :               remove = true;
   17918         7396 :             else if (!(OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   17919         4559 :                        && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
   17920         4559 :                            || (OMP_CLAUSE_MAP_KIND (c)
   17921              :                                == GOMP_MAP_FIRSTPRIVATE_POINTER)
   17922         3515 :                            || (OMP_CLAUSE_MAP_KIND (c)
   17923              :                                == GOMP_MAP_FORCE_DEVICEPTR)))
   17924         6294 :                      && t == OMP_CLAUSE_DECL (c)
   17925        13425 :                      && !omp_mappable_type (TREE_TYPE (t)))
   17926              :               {
   17927           16 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17928              :                           "%qD does not have a mappable type in %qs clause", t,
   17929            8 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17930            8 :                 remove = true;
   17931              :               }
   17932         7388 :             else if (TREE_TYPE (t) == error_mark_node)
   17933              :               remove = true;
   17934         7387 :             else if (TYPE_ATOMIC (strip_array_types (TREE_TYPE (t))))
   17935              :               {
   17936            8 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17937              :                           "%<_Atomic%> %qE in %qs clause", t,
   17938            4 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17939            4 :                 remove = true;
   17940              :               }
   17941         7383 :             else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   17942         4549 :                      && OMP_CLAUSE_MAP_IMPLICIT (c)
   17943         7514 :                      && (bitmap_bit_p (&map_head, DECL_UID (t))
   17944          130 :                          || bitmap_bit_p (&map_field_head, DECL_UID (t))
   17945          130 :                          || bitmap_bit_p (&map_firstprivate_head,
   17946          130 :                                           DECL_UID (t))))
   17947              :               remove = true;
   17948         7381 :             else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   17949         7381 :                      && (OMP_CLAUSE_MAP_KIND (c)
   17950              :                          == GOMP_MAP_FIRSTPRIVATE_POINTER))
   17951              :               {
   17952         1042 :                 if (bitmap_bit_p (&generic_head, DECL_UID (t))
   17953         1042 :                     || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
   17954         2083 :                     || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
   17955              :                   {
   17956            4 :                     error_at (OMP_CLAUSE_LOCATION (c),
   17957              :                               "%qD appears more than once in data clauses", t);
   17958            4 :                     remove = true;
   17959              :                   }
   17960         1038 :                 else if (bitmap_bit_p (&map_head, DECL_UID (t))
   17961            4 :                          && !bitmap_bit_p (&map_field_head, DECL_UID (t))
   17962         1040 :                          && openacc)
   17963              :                   {
   17964            1 :                     error_at (OMP_CLAUSE_LOCATION (c),
   17965              :                               "%qD appears more than once in data clauses", t);
   17966            1 :                     remove = true;
   17967              :                   }
   17968              :                 else
   17969         1037 :                   bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
   17970              :               }
   17971         6339 :             else if (bitmap_bit_p (&map_head, DECL_UID (t))
   17972           67 :                      && !bitmap_bit_p (&map_field_head, DECL_UID (t))
   17973           20 :                      && ort != C_ORT_OMP
   17974           20 :                      && ort != C_ORT_OMP_TARGET
   17975         6349 :                      && ort != C_ORT_OMP_EXIT_DATA)
   17976              :               {
   17977            7 :                 if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
   17978            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17979              :                             "%qD appears more than once in motion clauses", t);
   17980            7 :                 else if (openacc)
   17981            7 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17982              :                             "%qD appears more than once in data clauses", t);
   17983              :                 else
   17984            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17985              :                             "%qD appears more than once in map clauses", t);
   17986              :                 remove = true;
   17987              :               }
   17988         6332 :             else if (openacc && bitmap_bit_p (&generic_head, DECL_UID (t)))
   17989              :               {
   17990            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17991              :                           "%qD appears more than once in data clauses", t);
   17992            0 :                 remove = true;
   17993              :               }
   17994         6332 :             else if (bitmap_bit_p (&firstprivate_head, DECL_UID (t))
   17995         6332 :                      || bitmap_bit_p (&is_on_device_head, DECL_UID (t)))
   17996              :               {
   17997            9 :                 if (openacc)
   17998            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17999              :                             "%qD appears more than once in data clauses", t);
   18000              :                 else
   18001            9 :                   error_at (OMP_CLAUSE_LOCATION (c),
   18002              :                             "%qD appears both in data and map clauses", t);
   18003              :                 remove = true;
   18004              :               }
   18005         6323 :             else if (!omp_access_chain_p (addr_tokens, 1))
   18006              :               {
   18007         6323 :                 bitmap_set_bit (&map_head, DECL_UID (t));
   18008         6323 :                 if (t != OMP_CLAUSE_DECL (c)
   18009         6323 :                     && TREE_CODE (OMP_CLAUSE_DECL (c)) == COMPONENT_REF)
   18010          261 :                   bitmap_set_bit (&map_field_head, DECL_UID (t));
   18011              :               }
   18012              : 
   18013            0 :           skip_decl_checks:
   18014              :             /* If we call omp_expand_map_clause in handle_omp_array_sections,
   18015              :                the containing loop (here) iterates through the new nodes
   18016              :                created by that expansion.  Avoid expanding those again (just
   18017              :                by checking the node type).  */
   18018         7708 :             if (!remove
   18019         7708 :                 && ort != C_ORT_DECLARE_SIMD
   18020         7708 :                 && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
   18021         4809 :                     || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FIRSTPRIVATE_POINTER
   18022         3772 :                         && (OMP_CLAUSE_MAP_KIND (c)
   18023              :                             != GOMP_MAP_FIRSTPRIVATE_REFERENCE)
   18024         3772 :                         && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ALWAYS_POINTER
   18025         3772 :                         && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH
   18026         3467 :                         && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
   18027         3438 :                         && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH)))
   18028              :               {
   18029         6283 :                 grp_start_p = pc;
   18030         6283 :                 grp_sentinel = OMP_CLAUSE_CHAIN (c);
   18031         6283 :                 tree nc = ai.expand_map_clause (c, OMP_CLAUSE_DECL (c),
   18032              :                                                 addr_tokens, ort);
   18033         6283 :                 if (nc != error_mark_node)
   18034         6283 :                   c = nc;
   18035              :               }
   18036         9773 :           }
   18037         7708 :           break;
   18038              : 
   18039          276 :         case OMP_CLAUSE_ENTER:
   18040          276 :         case OMP_CLAUSE_LINK:
   18041          276 :         case OMP_CLAUSE_LOCAL:
   18042          276 :           t = OMP_CLAUSE_DECL (c);
   18043          276 :           const char *cname;
   18044          276 :           cname = omp_clause_code_name[OMP_CLAUSE_CODE (c)];
   18045          276 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER
   18046          276 :               && OMP_CLAUSE_ENTER_TO (c))
   18047              :             cname = "to";
   18048          276 :           if (TREE_CODE (t) == FUNCTION_DECL
   18049          276 :               && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
   18050              :             ;
   18051          194 :           else if (!VAR_P (t))
   18052              :             {
   18053            1 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
   18054            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   18055              :                           "%qE is neither a variable nor a function name in "
   18056              :                           "clause %qs", t, cname);
   18057              :               else
   18058            1 :                 error_at (OMP_CLAUSE_LOCATION (c),
   18059              :                           "%qE is not a variable in clause %qs", t, cname);
   18060              :               remove = true;
   18061              :             }
   18062          193 :           else if (DECL_THREAD_LOCAL_P (t))
   18063              :             {
   18064            2 :               error_at (OMP_CLAUSE_LOCATION (c),
   18065              :                         "%qD is threadprivate variable in %qs clause", t,
   18066              :                         cname);
   18067            2 :               remove = true;
   18068              :             }
   18069          191 :           else if (!omp_mappable_type (TREE_TYPE (t)))
   18070              :             {
   18071            6 :               error_at (OMP_CLAUSE_LOCATION (c),
   18072              :                         "%qD does not have a mappable type in %qs clause", t,
   18073              :                         cname);
   18074            6 :               remove = true;
   18075              :             }
   18076            9 :           if (remove)
   18077              :             break;
   18078          267 :           if (bitmap_bit_p (&generic_head, DECL_UID (t)))
   18079              :             {
   18080           10 :               error_at (OMP_CLAUSE_LOCATION (c),
   18081              :                         "%qE appears more than once on the same "
   18082              :                         "%<declare target%> directive", t);
   18083           10 :               remove = true;
   18084              :             }
   18085              :           else
   18086          257 :             bitmap_set_bit (&generic_head, DECL_UID (t));
   18087              :           break;
   18088              : 
   18089          119 :         case OMP_CLAUSE_UNIFORM:
   18090          119 :           t = OMP_CLAUSE_DECL (c);
   18091          119 :           if (TREE_CODE (t) != PARM_DECL)
   18092              :             {
   18093            0 :               if (DECL_P (t))
   18094            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   18095              :                           "%qD is not an argument in %<uniform%> clause", t);
   18096              :               else
   18097            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   18098              :                           "%qE is not an argument in %<uniform%> clause", t);
   18099              :               remove = true;
   18100              :               break;
   18101              :             }
   18102              :           /* map_head bitmap is used as uniform_head if declare_simd.  */
   18103          119 :           bitmap_set_bit (&map_head, DECL_UID (t));
   18104          119 :           goto check_dup_generic;
   18105              : 
   18106          161 :         case OMP_CLAUSE_IS_DEVICE_PTR:
   18107          161 :         case OMP_CLAUSE_USE_DEVICE_PTR:
   18108          161 :           t = OMP_CLAUSE_DECL (c);
   18109          161 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
   18110          123 :             bitmap_set_bit (&is_on_device_head, DECL_UID (t));
   18111          161 :           if (TREE_CODE (TREE_TYPE (t)) != POINTER_TYPE)
   18112              :             {
   18113           21 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
   18114           21 :                   && !openacc)
   18115              :                 {
   18116            1 :                   error_at (OMP_CLAUSE_LOCATION (c),
   18117              :                             "%qs variable is not a pointer",
   18118            1 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   18119            1 :                   remove = true;
   18120              :                 }
   18121           20 :               else if (TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE)
   18122              :                 {
   18123            4 :                   error_at (OMP_CLAUSE_LOCATION (c),
   18124              :                             "%qs variable is neither a pointer nor an array",
   18125            4 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   18126            4 :                   remove = true;
   18127              :                 }
   18128              :             }
   18129          161 :           goto check_dup_generic;
   18130              : 
   18131           89 :         case OMP_CLAUSE_HAS_DEVICE_ADDR:
   18132           89 :           t = OMP_CLAUSE_DECL (c);
   18133           89 :           if (TREE_CODE (t) == OMP_ARRAY_SECTION)
   18134              :             {
   18135           11 :               if (handle_omp_array_sections (c, ort))
   18136              :                 remove = true;
   18137              :               else
   18138              :                 {
   18139           11 :                   t = OMP_CLAUSE_DECL (c);
   18140           24 :                   while (TREE_CODE (t) == ARRAY_REF)
   18141           13 :                     t = TREE_OPERAND (t, 0);
   18142              :                 }
   18143              :             }
   18144           89 :           bitmap_set_bit (&is_on_device_head, DECL_UID (t));
   18145           89 :           if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
   18146           89 :             c_mark_addressable (t);
   18147           89 :           goto check_dup_generic_t;
   18148              : 
   18149           36 :         case OMP_CLAUSE_USE_DEVICE_ADDR:
   18150           36 :           t = OMP_CLAUSE_DECL (c);
   18151           36 :           if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
   18152           36 :             c_mark_addressable (t);
   18153           36 :           goto check_dup_generic;
   18154              : 
   18155         4797 :         case OMP_CLAUSE_NOWAIT:
   18156         4797 :           if (copyprivate_seen)
   18157              :             {
   18158            1 :               error_at (OMP_CLAUSE_LOCATION (c),
   18159              :                         "%<nowait%> clause must not be used together "
   18160              :                         "with %<copyprivate%> clause");
   18161            1 :               remove = true;
   18162            1 :               break;
   18163              :             }
   18164         4796 :           nowait_clause = pc;
   18165         4796 :           pc = &OMP_CLAUSE_CHAIN (c);
   18166         4796 :           continue;
   18167              : 
   18168          523 :         case OMP_CLAUSE_ORDER:
   18169          523 :           if (ordered_clause)
   18170              :             {
   18171            2 :               error_at (OMP_CLAUSE_LOCATION (c),
   18172              :                         "%<order%> clause must not be used together "
   18173              :                         "with %<ordered%> clause");
   18174            2 :               remove = true;
   18175            2 :               break;
   18176              :             }
   18177          521 :           else if (order_clause)
   18178              :             {
   18179              :               /* Silently remove duplicates.  */
   18180              :               remove = true;
   18181              :               break;
   18182              :             }
   18183          513 :           order_clause = pc;
   18184          513 :           pc = &OMP_CLAUSE_CHAIN (c);
   18185          513 :           continue;
   18186              : 
   18187           32 :         case OMP_CLAUSE_DETACH:
   18188           32 :           t = OMP_CLAUSE_DECL (c);
   18189           32 :           if (detach_seen)
   18190              :             {
   18191            1 :               error_at (OMP_CLAUSE_LOCATION (c),
   18192              :                         "too many %qs clauses on a task construct",
   18193              :                         "detach");
   18194            1 :               remove = true;
   18195            1 :               break;
   18196              :             }
   18197           31 :           detach_seen = pc;
   18198           31 :           pc = &OMP_CLAUSE_CHAIN (c);
   18199           31 :           c_mark_addressable (t);
   18200           31 :           continue;
   18201              : 
   18202        14641 :         case OMP_CLAUSE_IF:
   18203        14641 :         case OMP_CLAUSE_SELF:
   18204        14641 :         case OMP_CLAUSE_NUM_THREADS:
   18205        14641 :         case OMP_CLAUSE_NUM_TEAMS:
   18206        14641 :         case OMP_CLAUSE_THREAD_LIMIT:
   18207        14641 :         case OMP_CLAUSE_DEFAULT:
   18208        14641 :         case OMP_CLAUSE_UNTIED:
   18209        14641 :         case OMP_CLAUSE_COLLAPSE:
   18210        14641 :         case OMP_CLAUSE_FINAL:
   18211        14641 :         case OMP_CLAUSE_DEVICE:
   18212        14641 :         case OMP_CLAUSE_DIST_SCHEDULE:
   18213        14641 :         case OMP_CLAUSE_DYN_GROUPPRIVATE:
   18214        14641 :         case OMP_CLAUSE_PARALLEL:
   18215        14641 :         case OMP_CLAUSE_FOR:
   18216        14641 :         case OMP_CLAUSE_SECTIONS:
   18217        14641 :         case OMP_CLAUSE_TASKGROUP:
   18218        14641 :         case OMP_CLAUSE_PROC_BIND:
   18219        14641 :         case OMP_CLAUSE_DEVICE_TYPE:
   18220        14641 :         case OMP_CLAUSE_PRIORITY:
   18221        14641 :         case OMP_CLAUSE_THREADS:
   18222        14641 :         case OMP_CLAUSE_SIMD:
   18223        14641 :         case OMP_CLAUSE_HINT:
   18224        14641 :         case OMP_CLAUSE_FILTER:
   18225        14641 :         case OMP_CLAUSE_DEFAULTMAP:
   18226        14641 :         case OMP_CLAUSE_BIND:
   18227        14641 :         case OMP_CLAUSE_NUM_GANGS:
   18228        14641 :         case OMP_CLAUSE_NUM_WORKERS:
   18229        14641 :         case OMP_CLAUSE_VECTOR_LENGTH:
   18230        14641 :         case OMP_CLAUSE_ASYNC:
   18231        14641 :         case OMP_CLAUSE_WAIT:
   18232        14641 :         case OMP_CLAUSE_AUTO:
   18233        14641 :         case OMP_CLAUSE_INDEPENDENT:
   18234        14641 :         case OMP_CLAUSE_SEQ:
   18235        14641 :         case OMP_CLAUSE_GANG:
   18236        14641 :         case OMP_CLAUSE_WORKER:
   18237        14641 :         case OMP_CLAUSE_VECTOR:
   18238        14641 :         case OMP_CLAUSE_TILE:
   18239        14641 :         case OMP_CLAUSE_IF_PRESENT:
   18240        14641 :         case OMP_CLAUSE_FINALIZE:
   18241        14641 :         case OMP_CLAUSE_NOHOST:
   18242        14641 :         case OMP_CLAUSE_INDIRECT:
   18243        14641 :         case OMP_CLAUSE_NOVARIANTS:
   18244        14641 :         case OMP_CLAUSE_NOCONTEXT:
   18245        14641 :           pc = &OMP_CLAUSE_CHAIN (c);
   18246        14641 :           continue;
   18247              : 
   18248           62 :         case OMP_CLAUSE_GRAINSIZE:
   18249           62 :           grainsize_seen = pc;
   18250           62 :           pc = &OMP_CLAUSE_CHAIN (c);
   18251           62 :           continue;
   18252              : 
   18253           50 :         case OMP_CLAUSE_NUM_TASKS:
   18254           50 :           num_tasks_seen = true;
   18255           50 :           pc = &OMP_CLAUSE_CHAIN (c);
   18256           50 :           continue;
   18257              : 
   18258           79 :         case OMP_CLAUSE_MERGEABLE:
   18259           79 :           mergeable_seen = true;
   18260           79 :           pc = &OMP_CLAUSE_CHAIN (c);
   18261           79 :           continue;
   18262              : 
   18263           18 :         case OMP_CLAUSE_NOGROUP:
   18264           18 :           nogroup_seen = pc;
   18265           18 :           pc = &OMP_CLAUSE_CHAIN (c);
   18266           18 :           continue;
   18267              : 
   18268         3479 :         case OMP_CLAUSE_SCHEDULE:
   18269         3479 :           schedule_clause = c;
   18270         3479 :           pc = &OMP_CLAUSE_CHAIN (c);
   18271         3479 :           continue;
   18272              : 
   18273          304 :         case OMP_CLAUSE_ORDERED:
   18274          304 :           ordered_clause = c;
   18275          304 :           if (order_clause)
   18276              :             {
   18277            2 :               error_at (OMP_CLAUSE_LOCATION (*order_clause),
   18278              :                         "%<order%> clause must not be used together "
   18279              :                         "with %<ordered%> clause");
   18280            2 :               *order_clause = OMP_CLAUSE_CHAIN (*order_clause);
   18281            2 :               order_clause = NULL;
   18282              :             }
   18283          304 :           pc = &OMP_CLAUSE_CHAIN (c);
   18284          304 :           continue;
   18285              : 
   18286          223 :         case OMP_CLAUSE_SAFELEN:
   18287          223 :           safelen = c;
   18288          223 :           pc = &OMP_CLAUSE_CHAIN (c);
   18289          223 :           continue;
   18290          352 :         case OMP_CLAUSE_SIMDLEN:
   18291          352 :           simdlen = c;
   18292          352 :           pc = &OMP_CLAUSE_CHAIN (c);
   18293          352 :           continue;
   18294              : 
   18295           69 :         case OMP_CLAUSE_FULL:
   18296           69 :           full_seen = pc;
   18297           69 :           pc = &OMP_CLAUSE_CHAIN (c);
   18298           69 :           continue;
   18299              : 
   18300          223 :         case OMP_CLAUSE_PARTIAL:
   18301          223 :           partial_seen = true;
   18302          223 :           pc = &OMP_CLAUSE_CHAIN (c);
   18303          223 :           continue;
   18304              : 
   18305            0 :         case OMP_CLAUSE_SIZES:
   18306            0 :           pc = &OMP_CLAUSE_CHAIN (c);
   18307            0 :           continue;
   18308              : 
   18309          223 :         case OMP_CLAUSE_INBRANCH:
   18310          223 :         case OMP_CLAUSE_NOTINBRANCH:
   18311          223 :           if (branch_seen)
   18312              :             {
   18313            1 :               error_at (OMP_CLAUSE_LOCATION (c),
   18314              :                         "%<inbranch%> clause is incompatible with "
   18315              :                         "%<notinbranch%>");
   18316            1 :               remove = true;
   18317            1 :               break;
   18318              :             }
   18319          222 :           branch_seen = true;
   18320          222 :           pc = &OMP_CLAUSE_CHAIN (c);
   18321          222 :           continue;
   18322              : 
   18323          370 :         case OMP_CLAUSE_INCLUSIVE:
   18324          370 :         case OMP_CLAUSE_EXCLUSIVE:
   18325          370 :           need_complete = true;
   18326          370 :           need_implicitly_determined = true;
   18327          370 :           t = OMP_CLAUSE_DECL (c);
   18328          370 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   18329              :             {
   18330            0 :               error_at (OMP_CLAUSE_LOCATION (c),
   18331              :                         "%qE is not a variable in clause %qs", t,
   18332            0 :                         omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   18333            0 :               remove = true;
   18334              :             }
   18335              :           break;
   18336              : 
   18337          152 :         case OMP_CLAUSE_INIT:
   18338          152 :           init_seen = true;
   18339          152 :           if (!OMP_CLAUSE_INIT_TARGETSYNC (c))
   18340           71 :             init_no_targetsync_clause = c;
   18341              :           /* FALLTHRU */
   18342          242 :         case OMP_CLAUSE_DESTROY:
   18343          242 :         case OMP_CLAUSE_USE:
   18344          242 :           init_use_destroy_seen = true;
   18345          242 :           t = OMP_CLAUSE_DECL (c);
   18346          242 :           if (bitmap_bit_p (&generic_head, DECL_UID (t)))
   18347              :             {
   18348            3 :               error_at (OMP_CLAUSE_LOCATION (c),
   18349              :                         "%qD appears more than once in action clauses", t);
   18350            3 :               remove = true;
   18351            3 :               break;
   18352              :             }
   18353          239 :           bitmap_set_bit (&generic_head, DECL_UID (t));
   18354              :           /* FALLTHRU */
   18355          298 :         case OMP_CLAUSE_INTEROP:
   18356          298 :           if (/* ort == C_ORT_OMP_INTEROP [uncomment for depobj init]  */
   18357          298 :                    !c_omp_interop_t_p (TREE_TYPE (OMP_CLAUSE_DECL (c))))
   18358              :             {
   18359           40 :               error_at (OMP_CLAUSE_LOCATION (c),
   18360              :                         "%qD must be of %<omp_interop_t%>",
   18361           20 :                         OMP_CLAUSE_DECL (c));
   18362           20 :               remove = true;
   18363              :             }
   18364          278 :           else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INIT
   18365          133 :                     || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DESTROY)
   18366          318 :                    && TREE_READONLY (OMP_CLAUSE_DECL (c)))
   18367              :             {
   18368           12 :               error_at (OMP_CLAUSE_LOCATION (c),
   18369            6 :                       "%qD shall not be const", OMP_CLAUSE_DECL (c));
   18370            6 :               remove = true;
   18371              :             }
   18372          298 :           pc = &OMP_CLAUSE_CHAIN (c);
   18373          298 :           break;
   18374            0 :         default:
   18375            0 :           gcc_unreachable ();
   18376        25105 :         }
   18377              : 
   18378        23225 :       if (!remove)
   18379              :         {
   18380        22657 :           t = OMP_CLAUSE_DECL (c);
   18381              : 
   18382        22657 :           if (need_complete)
   18383              :             {
   18384         3995 :               t = require_complete_type (OMP_CLAUSE_LOCATION (c), t);
   18385         3995 :               if (t == error_mark_node)
   18386            7 :                 remove = true;
   18387              :             }
   18388              : 
   18389        22657 :           if (need_implicitly_determined)
   18390              :             {
   18391         9653 :               const char *share_name = NULL;
   18392              : 
   18393         9653 :               if (VAR_P (t) && DECL_THREAD_LOCAL_P (t))
   18394              :                 share_name = "threadprivate";
   18395         9647 :               else switch (c_omp_predetermined_sharing (t))
   18396              :                 {
   18397              :                 case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
   18398              :                   break;
   18399           20 :                 case OMP_CLAUSE_DEFAULT_SHARED:
   18400           20 :                   if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
   18401           12 :                        || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE)
   18402           28 :                       && c_omp_predefined_variable (t))
   18403              :                     /* The __func__ variable and similar function-local
   18404              :                        predefined variables may be listed in a shared or
   18405              :                        firstprivate clause.  */
   18406              :                     break;
   18407              :                   share_name = "shared";
   18408              :                   break;
   18409              :                 case OMP_CLAUSE_DEFAULT_PRIVATE:
   18410              :                   share_name = "private";
   18411              :                   break;
   18412            0 :                 default:
   18413            0 :                   gcc_unreachable ();
   18414              :                 }
   18415              :               if (share_name)
   18416              :                 {
   18417           20 :                   error_at (OMP_CLAUSE_LOCATION (c),
   18418              :                             "%qE is predetermined %qs for %qs",
   18419              :                             t, share_name,
   18420           10 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   18421           10 :                   remove = true;
   18422              :                 }
   18423         9643 :               else if (TREE_READONLY (t)
   18424           23 :                        && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
   18425         9656 :                        && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE)
   18426              :                 {
   18427            4 :                   error_at (OMP_CLAUSE_LOCATION (c),
   18428              :                             "%<const%> qualified %qE may appear only in "
   18429              :                             "%<shared%> or %<firstprivate%> clauses", t);
   18430            4 :                   remove = true;
   18431              :                 }
   18432              :             }
   18433              :         }
   18434              : 
   18435        22657 :       if (remove)
   18436              :         {
   18437          589 :           if (grp_start_p)
   18438              :             {
   18439              :               /* If we found a clause to remove, we want to remove the whole
   18440              :                  expanded group, otherwise gimplify
   18441              :                  (omp_resolve_clause_dependencies) can get confused.  */
   18442          153 :               *grp_start_p = grp_sentinel;
   18443          153 :               pc = grp_start_p;
   18444          153 :               grp_start_p = NULL;
   18445              :             }
   18446              :           else
   18447          436 :             *pc = OMP_CLAUSE_CHAIN (c);
   18448              :         }
   18449              :       else
   18450        22636 :         pc = &OMP_CLAUSE_CHAIN (c);
   18451              :     }
   18452              : 
   18453        29889 :   if (grp_start_p
   18454        29889 :       && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
   18455           58 :     for (tree gc = *grp_start_p; gc; gc = OMP_CLAUSE_CHAIN (gc))
   18456           35 :       OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
   18457              : 
   18458        29889 :   if (simdlen
   18459        29889 :       && safelen
   18460        30006 :       && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen),
   18461          117 :                           OMP_CLAUSE_SIMDLEN_EXPR (simdlen)))
   18462              :     {
   18463              :       /* Note: How a scaling factor affects this, is underspecified in OpenMP;
   18464              :          cf. OpenMP spec issue #5160.  Presumably, it means:
   18465              :            savelen >= simdlen * scale_factor
   18466              :          with
   18467              :            scale_factor = MAX (1, FLOOR_DIV_EXPR (VL(type), divisor))
   18468              :          and OpenMP states that VL(type) might be only known at runtime.
   18469              :          Hence scale_factor >= 1 and, conservatively, assume == 1 for this
   18470              :          error check.  */
   18471            0 :       error_at (OMP_CLAUSE_LOCATION (simdlen),
   18472              :                 "%<simdlen%> clause value is bigger than "
   18473              :                 "%<safelen%> clause value");
   18474            0 :       OMP_CLAUSE_SIMDLEN_EXPR (simdlen)
   18475            0 :         = OMP_CLAUSE_SAFELEN_EXPR (safelen);
   18476              :     }
   18477              : 
   18478        29889 :   if (ordered_clause
   18479        29889 :       && schedule_clause
   18480        29889 :       && (OMP_CLAUSE_SCHEDULE_KIND (schedule_clause)
   18481              :           & OMP_CLAUSE_SCHEDULE_NONMONOTONIC))
   18482              :     {
   18483            7 :       error_at (OMP_CLAUSE_LOCATION (schedule_clause),
   18484              :                 "%<nonmonotonic%> schedule modifier specified together "
   18485              :                 "with %<ordered%> clause");
   18486           14 :       OMP_CLAUSE_SCHEDULE_KIND (schedule_clause)
   18487            7 :         = (enum omp_clause_schedule_kind)
   18488            7 :           (OMP_CLAUSE_SCHEDULE_KIND (schedule_clause)
   18489              :            & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC);
   18490              :     }
   18491              : 
   18492        29889 :   if (reduction_seen < 0 && ordered_clause)
   18493              :     {
   18494            2 :       error_at (OMP_CLAUSE_LOCATION (ordered_clause),
   18495              :                 "%qs clause specified together with %<inscan%> "
   18496              :                 "%<reduction%> clause", "ordered");
   18497            2 :       reduction_seen = -2;
   18498              :     }
   18499              : 
   18500        29889 :   if (reduction_seen < 0 && schedule_clause)
   18501              :     {
   18502            3 :       error_at (OMP_CLAUSE_LOCATION (schedule_clause),
   18503              :                 "%qs clause specified together with %<inscan%> "
   18504              :                 "%<reduction%> clause", "schedule");
   18505            3 :       reduction_seen = -2;
   18506              :     }
   18507              : 
   18508        29889 :   if (linear_variable_step_check
   18509        29889 :       || reduction_seen == -2
   18510              :       || allocate_seen
   18511        29877 :       || target_in_reduction_seen)
   18512         5225 :     for (pc = &clauses, c = clauses; c ; c = *pc)
   18513              :       {
   18514         4618 :         bool remove = false;
   18515         4618 :         if (allocate_seen)
   18516         4460 :           switch (OMP_CLAUSE_CODE (c))
   18517              :             {
   18518          430 :             case OMP_CLAUSE_REDUCTION:
   18519          430 :             case OMP_CLAUSE_IN_REDUCTION:
   18520          430 :             case OMP_CLAUSE_TASK_REDUCTION:
   18521          430 :               if (TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF)
   18522              :                 {
   18523           23 :                   t = TREE_OPERAND (OMP_CLAUSE_DECL (c), 0);
   18524           23 :                   if (TREE_CODE (t) == POINTER_PLUS_EXPR)
   18525            0 :                     t = TREE_OPERAND (t, 0);
   18526           23 :                   if (TREE_CODE (t) == ADDR_EXPR
   18527           10 :                       || INDIRECT_REF_P (t))
   18528           13 :                     t = TREE_OPERAND (t, 0);
   18529           23 :                   if (DECL_P (t))
   18530           23 :                     bitmap_clear_bit (&aligned_head, DECL_UID (t));
   18531              :                   break;
   18532              :                 }
   18533              :               /* FALLTHRU */
   18534         1329 :             case OMP_CLAUSE_PRIVATE:
   18535         1329 :             case OMP_CLAUSE_FIRSTPRIVATE:
   18536         1329 :             case OMP_CLAUSE_LASTPRIVATE:
   18537         1329 :             case OMP_CLAUSE_LINEAR:
   18538         1329 :               if (DECL_P (OMP_CLAUSE_DECL (c)))
   18539         2658 :                 bitmap_clear_bit (&aligned_head,
   18540         1329 :                                   DECL_UID (OMP_CLAUSE_DECL (c)));
   18541              :               break;
   18542              :             default:
   18543              :               break;
   18544              :             }
   18545         4618 :         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
   18546           29 :             && OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c)
   18547         4625 :             && !bitmap_bit_p (&map_head,
   18548            7 :                               DECL_UID (OMP_CLAUSE_LINEAR_STEP (c))))
   18549              :           {
   18550            2 :             error_at (OMP_CLAUSE_LOCATION (c),
   18551              :                       "%<linear%> clause step is a parameter %qD not "
   18552              :                       "specified in %<uniform%> clause",
   18553            2 :                       OMP_CLAUSE_LINEAR_STEP (c));
   18554            2 :             remove = true;
   18555              :           }
   18556         4616 :         else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   18557         4616 :                  && reduction_seen == -2)
   18558            9 :           OMP_CLAUSE_REDUCTION_INSCAN (c) = 0;
   18559         4618 :         if (target_in_reduction_seen
   18560         4618 :             && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
   18561              :           {
   18562          256 :             tree t = OMP_CLAUSE_DECL (c);
   18563          256 :             while (handled_component_p (t)
   18564              :                    || INDIRECT_REF_P (t)
   18565              :                    || TREE_CODE (t) == ADDR_EXPR
   18566              :                    || TREE_CODE (t) == MEM_REF
   18567          288 :                    || TREE_CODE (t) == NON_LVALUE_EXPR)
   18568           32 :               t = TREE_OPERAND (t, 0);
   18569          256 :             if (DECL_P (t)
   18570          256 :                 && bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
   18571          138 :               OMP_CLAUSE_MAP_IN_REDUCTION (c) = 1;
   18572              :           }
   18573              : 
   18574         4618 :         if (remove)
   18575            2 :           *pc = OMP_CLAUSE_CHAIN (c);
   18576              :         else
   18577         4616 :           pc = &OMP_CLAUSE_CHAIN (c);
   18578              :       }
   18579              : 
   18580          607 :   if (allocate_seen)
   18581         5041 :     for (pc = &clauses, c = clauses; c ; c = *pc)
   18582              :       {
   18583         4460 :         bool remove = false;
   18584         4460 :         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ALLOCATE
   18585          731 :             && !OMP_CLAUSE_ALLOCATE_COMBINED (c)
   18586         5171 :             && bitmap_bit_p (&aligned_head, DECL_UID (OMP_CLAUSE_DECL (c))))
   18587              :           {
   18588            3 :             error_at (OMP_CLAUSE_LOCATION (c),
   18589              :                       "%qD specified in %<allocate%> clause but not in "
   18590            3 :                       "an explicit privatization clause", OMP_CLAUSE_DECL (c));
   18591            3 :             remove = true;
   18592              :           }
   18593         4460 :         if (remove)
   18594            3 :           *pc = OMP_CLAUSE_CHAIN (c);
   18595              :         else
   18596         4457 :           pc = &OMP_CLAUSE_CHAIN (c);
   18597              :       }
   18598              : 
   18599        29889 :   if (nogroup_seen && reduction_seen)
   18600              :     {
   18601            1 :       error_at (OMP_CLAUSE_LOCATION (*nogroup_seen),
   18602              :                 "%<nogroup%> clause must not be used together with "
   18603              :                 "%<reduction%> clause");
   18604            1 :       *nogroup_seen = OMP_CLAUSE_CHAIN (*nogroup_seen);
   18605              :     }
   18606              : 
   18607        29889 :   if (grainsize_seen && num_tasks_seen)
   18608              :     {
   18609            2 :       error_at (OMP_CLAUSE_LOCATION (*grainsize_seen),
   18610              :                 "%<grainsize%> clause must not be used together with "
   18611              :                 "%<num_tasks%> clause");
   18612            2 :       *grainsize_seen = OMP_CLAUSE_CHAIN (*grainsize_seen);
   18613              :     }
   18614              : 
   18615        29889 :   if (full_seen && partial_seen)
   18616              :     {
   18617            4 :       error_at (OMP_CLAUSE_LOCATION (*full_seen),
   18618              :                 "%<full%> clause must not be used together with "
   18619              :                 "%<partial%> clause");
   18620            4 :       *full_seen = OMP_CLAUSE_CHAIN (*full_seen);
   18621              :     }
   18622              : 
   18623        29889 :   if (detach_seen)
   18624              :     {
   18625           31 :       if (mergeable_seen)
   18626              :         {
   18627            2 :           error_at (OMP_CLAUSE_LOCATION (*detach_seen),
   18628              :                     "%<detach%> clause must not be used together with "
   18629              :                     "%<mergeable%> clause");
   18630            2 :           *detach_seen = OMP_CLAUSE_CHAIN (*detach_seen);
   18631              :         }
   18632              :       else
   18633              :         {
   18634           29 :           tree detach_decl = OMP_CLAUSE_DECL (*detach_seen);
   18635              : 
   18636           79 :           for (pc = &clauses, c = clauses; c ; c = *pc)
   18637              :             {
   18638           50 :               bool remove = false;
   18639           50 :               if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
   18640           48 :                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
   18641           48 :                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
   18642           44 :                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE)
   18643           54 :                   && OMP_CLAUSE_DECL (c) == detach_decl)
   18644              :                 {
   18645            2 :                   error_at (OMP_CLAUSE_LOCATION (c),
   18646              :                             "the event handle of a %<detach%> clause "
   18647              :                             "should not be in a data-sharing clause");
   18648            2 :                   remove = true;
   18649              :                 }
   18650           50 :               if (remove)
   18651            2 :                 *pc = OMP_CLAUSE_CHAIN (c);
   18652              :               else
   18653           48 :                 pc = &OMP_CLAUSE_CHAIN (c);
   18654              :             }
   18655              :         }
   18656              :     }
   18657              : 
   18658        29889 :   if (ort == C_ORT_OMP_INTEROP
   18659        29889 :       && depend_clause
   18660           21 :       && (!init_use_destroy_seen
   18661           20 :           || (init_seen && init_no_targetsync_clause)))
   18662              :     {
   18663            3 :       error_at (OMP_CLAUSE_LOCATION (depend_clause),
   18664              :                 "%<depend%> clause requires action clauses with "
   18665              :                 "%<targetsync%> interop-type");
   18666            3 :       if (init_no_targetsync_clause)
   18667            2 :         inform (OMP_CLAUSE_LOCATION (init_no_targetsync_clause),
   18668              :                 "%<init%> clause lacks the %<targetsync%> modifier");
   18669              :     }
   18670              : 
   18671        29889 :   bitmap_obstack_release (NULL);
   18672        29889 :   return clauses;
   18673              : }
   18674              : 
   18675              : /* Do processing necessary to make CLAUSES well-formed, where CLAUSES result
   18676              :    from implicit instantiation of user-defined mappers (in gimplify.cc).  */
   18677              : 
   18678              : tree
   18679           15 : c_omp_finish_mapper_clauses (tree clauses)
   18680              : {
   18681           15 :   return c_finish_omp_clauses (clauses, C_ORT_OMP);
   18682              : }
   18683              : 
   18684              : /* Return code to initialize DST with a copy constructor from SRC.
   18685              :    C doesn't have copy constructors nor assignment operators, only for
   18686              :    _Atomic vars we need to perform __atomic_load from src into a temporary
   18687              :    followed by __atomic_store of the temporary to dst.  */
   18688              : 
   18689              : tree
   18690        18784 : c_omp_clause_copy_ctor (tree clause, tree dst, tree src)
   18691              : {
   18692        18784 :   if (!really_atomic_lvalue (dst) && !really_atomic_lvalue (src))
   18693        18780 :     return build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src);
   18694              : 
   18695            4 :   location_t loc = OMP_CLAUSE_LOCATION (clause);
   18696            4 :   tree type = TREE_TYPE (dst);
   18697            4 :   tree nonatomic_type = build_qualified_type (type, TYPE_UNQUALIFIED);
   18698            4 :   tree tmp = create_tmp_var (nonatomic_type);
   18699            4 :   tree tmp_addr = build_fold_addr_expr (tmp);
   18700            4 :   TREE_ADDRESSABLE (tmp) = 1;
   18701            4 :   suppress_warning (tmp);
   18702            4 :   tree src_addr = build_fold_addr_expr (src);
   18703            4 :   tree dst_addr = build_fold_addr_expr (dst);
   18704            4 :   tree seq_cst = build_int_cst (integer_type_node, MEMMODEL_SEQ_CST);
   18705            4 :   vec<tree, va_gc> *params;
   18706              :   /* Expansion of a generic atomic load may require an addition
   18707              :      element, so allocate enough to prevent a resize.  */
   18708            4 :   vec_alloc (params, 4);
   18709              : 
   18710              :   /* Build __atomic_load (&src, &tmp, SEQ_CST);  */
   18711            4 :   tree fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_LOAD);
   18712            4 :   params->quick_push (src_addr);
   18713            4 :   params->quick_push (tmp_addr);
   18714            4 :   params->quick_push (seq_cst);
   18715            4 :   tree load = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
   18716              : 
   18717            4 :   vec_alloc (params, 4);
   18718              : 
   18719              :   /* Build __atomic_store (&dst, &tmp, SEQ_CST);  */
   18720            4 :   fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_STORE);
   18721            4 :   params->quick_push (dst_addr);
   18722            4 :   params->quick_push (tmp_addr);
   18723            4 :   params->quick_push (seq_cst);
   18724            4 :   tree store = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
   18725            4 :   return build2 (COMPOUND_EXPR, void_type_node, load, store);
   18726              : }
   18727              : 
   18728              : /* Create a transaction node.  */
   18729              : 
   18730              : tree
   18731          135 : c_finish_transaction (location_t loc, tree block, int flags)
   18732              : {
   18733          135 :   tree stmt = build_stmt (loc, TRANSACTION_EXPR, block);
   18734          135 :   if (flags & TM_STMT_ATTR_OUTER)
   18735           10 :     TRANSACTION_EXPR_OUTER (stmt) = 1;
   18736          135 :   if (flags & TM_STMT_ATTR_RELAXED)
   18737           31 :     TRANSACTION_EXPR_RELAXED (stmt) = 1;
   18738          135 :   return add_stmt (stmt);
   18739              : }
   18740              : 
   18741              : /* Make a variant type in the proper way for C/C++, propagating qualifiers
   18742              :    down to the element type of an array.  If ORIG_QUAL_TYPE is not
   18743              :    NULL, then it should be used as the qualified type
   18744              :    ORIG_QUAL_INDIRECT levels down in array type derivation (to
   18745              :    preserve information about the typedef name from which an array
   18746              :    type was derived).  */
   18747              : 
   18748              : tree
   18749     77009531 : c_build_qualified_type (tree type, qualifier_set type_quals,
   18750              :                         tree orig_qual_type, size_t orig_qual_indirect)
   18751              : {
   18752     77009531 :   if (type == error_mark_node)
   18753              :     return type;
   18754              : 
   18755     77009379 :   if (TREE_CODE (type) == ARRAY_TYPE)
   18756              :     {
   18757      3167064 :       tree t;
   18758      3167064 :       tree element_type = c_build_qualified_type (TREE_TYPE (type),
   18759              :                                                   type_quals, orig_qual_type,
   18760              :                                                   orig_qual_indirect - 1);
   18761              : 
   18762              :       /* See if we already have an identically qualified type.  */
   18763      3167064 :       if (orig_qual_type && orig_qual_indirect == 0)
   18764              :         t = orig_qual_type;
   18765              :       else
   18766      4617371 :         for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
   18767              :           {
   18768      4496378 :             if (TYPE_QUALS (strip_array_types (t)) == type_quals
   18769      3046020 :                 && TYPE_NAME (t) == TYPE_NAME (type)
   18770      3024893 :                 && TYPE_CONTEXT (t) == TYPE_CONTEXT (type)
   18771      3024893 :                 && attribute_list_equal (TYPE_ATTRIBUTES (t),
   18772      3024893 :                                          TYPE_ATTRIBUTES (type)))
   18773              :               break;
   18774              :           }
   18775      3167023 :       if (!t)
   18776              :         {
   18777       142130 :           tree domain = TYPE_DOMAIN (type);
   18778              : 
   18779       142130 :           t = build_variant_type_copy (type);
   18780       142130 :           TREE_TYPE (t) = element_type;
   18781       142130 :           TYPE_ADDR_SPACE (t) = TYPE_ADDR_SPACE (element_type);
   18782              : 
   18783       142130 :           if (TYPE_STRUCTURAL_EQUALITY_P (element_type)
   18784       142130 :               || (domain && TYPE_STRUCTURAL_EQUALITY_P (domain)))
   18785          196 :             SET_TYPE_STRUCTURAL_EQUALITY (t);
   18786       141934 :           else if (TYPE_CANONICAL (element_type) != element_type
   18787       141934 :                    || (domain && TYPE_CANONICAL (domain) != domain))
   18788              :             {
   18789         2836 :               tree unqualified_canon
   18790         5413 :                 = c_build_array_type (TYPE_CANONICAL (element_type),
   18791         2577 :                                       domain ? TYPE_CANONICAL (domain)
   18792              :                                              : NULL_TREE);
   18793         2836 :               if (TYPE_REVERSE_STORAGE_ORDER (type))
   18794              :                 {
   18795            0 :                   unqualified_canon
   18796            0 :                     = build_distinct_type_copy (unqualified_canon);
   18797            0 :                   TYPE_REVERSE_STORAGE_ORDER (unqualified_canon) = 1;
   18798              :                 }
   18799         2836 :               TYPE_CANONICAL (t)
   18800         5672 :                 = c_build_qualified_type (unqualified_canon, type_quals);
   18801              :             }
   18802              :           else
   18803       139098 :             TYPE_CANONICAL (t) = t;
   18804              :         }
   18805              :       return t;
   18806              :     }
   18807              : 
   18808              :   /* A restrict-qualified pointer type must be a pointer to object or
   18809              :      incomplete type.  Note that the use of POINTER_TYPE_P also allows
   18810              :      REFERENCE_TYPEs, which is appropriate for C++.  */
   18811     73842315 :   if ((type_quals.has (TYPE_QUAL_RESTRICT))
   18812     73842315 :       && (!POINTER_TYPE_P (type)
   18813      3495256 :           || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type))))
   18814              :     {
   18815            3 :       error ("invalid use of %<restrict%>");
   18816            3 :       type_quals.remove (TYPE_QUAL_RESTRICT);
   18817              :     }
   18818              : 
   18819     73842315 :   tree var_type = (orig_qual_type && orig_qual_indirect == 0
   18820     73842315 :                    ? orig_qual_type
   18821     73842284 :                    : build_qualified_type (type, type_quals));
   18822              : 
   18823     73842315 :   gcc_checking_assert (C_TYPE_VARIABLE_SIZE (var_type)
   18824              :                        == C_TYPE_VARIABLE_SIZE (type));
   18825     73842315 :   gcc_checking_assert (c_type_variably_modified_p (var_type)
   18826              :                        == c_type_variably_modified_p (type));
   18827              : 
   18828              :   /* A variant type does not inherit the list of incomplete vars from the
   18829              :      type main variant.  */
   18830     73842315 :   if ((RECORD_OR_UNION_TYPE_P (var_type)
   18831     71746826 :        || TREE_CODE (var_type) == ENUMERAL_TYPE)
   18832     73949544 :       && TYPE_MAIN_VARIANT (var_type) != var_type)
   18833      1416825 :     C_TYPE_INCOMPLETE_VARS (var_type) = 0;
   18834              :   return var_type;
   18835              : }
   18836              : 
   18837              : /* Build a VA_ARG_EXPR for the C parser.  */
   18838              : 
   18839              : tree
   18840        20008 : c_build_va_arg (location_t loc1, tree expr, location_t loc2, tree type,
   18841              :                 tree type_expr)
   18842              : {
   18843        20008 :   if (error_operand_p (type))
   18844            2 :     return error_mark_node;
   18845              :   /* VA_ARG_EXPR cannot be used for a scalar va_list with reverse storage
   18846              :      order because it takes the address of the expression.  */
   18847        20006 :   else if (handled_component_p (expr)
   18848           31 :            && reverse_storage_order_for_component_p (expr))
   18849              :     {
   18850            0 :       error_at (loc1, "cannot use %<va_arg%> with reverse storage order");
   18851            0 :       return error_mark_node;
   18852              :     }
   18853        20006 :   else if (!COMPLETE_TYPE_P (type))
   18854              :     {
   18855           11 :       error_at (loc2, "second argument to %<va_arg%> is of incomplete "
   18856              :                 "type %qT", type);
   18857           11 :       return error_mark_node;
   18858              :     }
   18859        19995 :   else if (TREE_CODE (type) == FUNCTION_TYPE)
   18860              :     {
   18861            1 :       error_at (loc2, "second argument to %<va_arg%> is a function type %qT",
   18862              :                 type);
   18863            1 :       return error_mark_node;
   18864              :     }
   18865            6 :   else if (TREE_CODE (type) == ARRAY_TYPE && C_TYPE_VARIABLE_SIZE (type)
   18866        19997 :            && !flag_isoc99)
   18867              :     {
   18868            1 :       error_at (loc2, "second argument to %<va_arg%> is an array type %qT",
   18869              :                 type);
   18870            1 :       return error_mark_node;
   18871              :     }
   18872        19993 :   else if (warn_cxx_compat && TREE_CODE (type) == ENUMERAL_TYPE)
   18873            1 :     warning_at (loc2, OPT_Wc___compat,
   18874              :                 "C++ requires promoted type, not enum type, in %<va_arg%>");
   18875              : 
   18876        19993 :   if (flag_isoc99 && TREE_CODE (type) == ARRAY_TYPE)
   18877              :     {
   18878            3 :       warning_at (loc2, 0, "second argument to %<va_arg%> is an array type %qT",
   18879              :                   type);
   18880              :       /* We create a trap but evaluate side effects first.  */
   18881            3 :       tree trapfn = builtin_decl_explicit (BUILT_IN_TRAP);
   18882            3 :       trapfn = build_call_expr_loc (loc2, trapfn, 0);
   18883            3 :       tree e2 = build2 (COMPOUND_EXPR, void_type_node, expr, trapfn);
   18884              :       /* Return a compound literal of the right type.  */
   18885            3 :       tree e1 = build_compound_literal (loc2, type, NULL, true, 0, NULL);
   18886            3 :       expr = build2 (COMPOUND_EXPR, type, e2, e1);
   18887            3 :     }
   18888              :   else
   18889        19990 :     expr = build_va_arg (loc2, expr, type);
   18890              : 
   18891        19993 :   if (type_expr)
   18892           26 :     expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr), type_expr, expr);
   18893              : 
   18894              :   return expr;
   18895              : }
   18896              : 
   18897              : /* Return truthvalue of whether T1 is the same tree structure as T2.
   18898              :    Return 1 if they are the same. Return false if they are different.  */
   18899              : 
   18900              : bool
   18901         1854 : c_tree_equal (tree t1, tree t2)
   18902              : {
   18903         1883 :   enum tree_code code1, code2;
   18904              : 
   18905         1883 :   if (t1 == t2)
   18906              :     return true;
   18907          661 :   if (!t1 || !t2)
   18908              :     return false;
   18909              : 
   18910          681 :   for (code1 = TREE_CODE (t1); code1 == NON_LVALUE_EXPR;
   18911           20 :        code1 = TREE_CODE (t1))
   18912           20 :     t1 = TREE_OPERAND (t1, 0);
   18913          682 :   for (code2 = TREE_CODE (t2); code2 == NON_LVALUE_EXPR;
   18914           21 :        code2 = TREE_CODE (t2))
   18915           21 :     t2 = TREE_OPERAND (t2, 0);
   18916              : 
   18917              :   /* They might have become equal now.  */
   18918          661 :   if (t1 == t2)
   18919              :     return true;
   18920              : 
   18921          640 :   if (code1 != code2)
   18922              :     return false;
   18923              : 
   18924          379 :   if (CONSTANT_CLASS_P (t1) && !comptypes (TREE_TYPE (t1), TREE_TYPE (t2)))
   18925              :     return false;
   18926              : 
   18927          379 :   switch (code1)
   18928              :     {
   18929            2 :     case INTEGER_CST:
   18930            2 :       return wi::to_wide (t1) == wi::to_wide (t2);
   18931              : 
   18932           10 :     case REAL_CST:
   18933           10 :       return real_equal (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
   18934              : 
   18935            0 :     case STRING_CST:
   18936            0 :       return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
   18937            0 :         && !memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
   18938            0 :                     TREE_STRING_LENGTH (t1));
   18939              : 
   18940            0 :     case FIXED_CST:
   18941            0 :       return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1),
   18942              :                                      TREE_FIXED_CST (t2));
   18943              : 
   18944            0 :     case COMPLEX_CST:
   18945            0 :       return c_tree_equal (TREE_REALPART (t1), TREE_REALPART (t2))
   18946            0 :              && c_tree_equal (TREE_IMAGPART (t1), TREE_IMAGPART (t2));
   18947              : 
   18948            0 :     case VECTOR_CST:
   18949            0 :       return operand_equal_p (t1, t2, OEP_ONLY_CONST);
   18950              : 
   18951            0 :     case CONSTRUCTOR:
   18952              :       /* We need to do this when determining whether or not two
   18953              :          non-type pointer to member function template arguments
   18954              :          are the same.  */
   18955            0 :       if (!comptypes (TREE_TYPE (t1), TREE_TYPE (t2))
   18956            0 :           || CONSTRUCTOR_NELTS (t1) != CONSTRUCTOR_NELTS (t2))
   18957              :         return false;
   18958              :       {
   18959              :         tree field, value;
   18960              :         unsigned int i;
   18961            0 :         FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t1), i, field, value)
   18962              :           {
   18963            0 :             constructor_elt *elt2 = CONSTRUCTOR_ELT (t2, i);
   18964            0 :             if (!c_tree_equal (field, elt2->index)
   18965            0 :                 || !c_tree_equal (value, elt2->value))
   18966              :               return false;
   18967              :           }
   18968              :       }
   18969              :       return true;
   18970              : 
   18971            0 :     case TREE_LIST:
   18972            0 :       if (!c_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)))
   18973              :         return false;
   18974            0 :       if (!c_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2)))
   18975              :         return false;
   18976            0 :       return c_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2));
   18977              : 
   18978            0 :     case SAVE_EXPR:
   18979            0 :       return c_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
   18980              : 
   18981           25 :     case CALL_EXPR:
   18982           25 :       {
   18983           25 :         tree arg1, arg2;
   18984           25 :         call_expr_arg_iterator iter1, iter2;
   18985           25 :         if (!c_tree_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2)))
   18986              :           return false;
   18987           50 :         for (arg1 = first_call_expr_arg (t1, &iter1),
   18988           25 :                arg2 = first_call_expr_arg (t2, &iter2);
   18989           25 :              arg1 && arg2;
   18990            0 :              arg1 = next_call_expr_arg (&iter1),
   18991            0 :                arg2 = next_call_expr_arg (&iter2))
   18992            0 :           if (!c_tree_equal (arg1, arg2))
   18993              :             return false;
   18994           25 :         if (arg1 || arg2)
   18995            0 :           return false;
   18996              :         return true;
   18997              :       }
   18998              : 
   18999            0 :     case TARGET_EXPR:
   19000            0 :       {
   19001            0 :         tree o1 = TREE_OPERAND (t1, 0);
   19002            0 :         tree o2 = TREE_OPERAND (t2, 0);
   19003              : 
   19004              :         /* Special case: if either target is an unallocated VAR_DECL,
   19005              :            it means that it's going to be unified with whatever the
   19006              :            TARGET_EXPR is really supposed to initialize, so treat it
   19007              :            as being equivalent to anything.  */
   19008            0 :         if (VAR_P (o1) && DECL_NAME (o1) == NULL_TREE
   19009            0 :             && !DECL_RTL_SET_P (o1))
   19010              :           /*Nop*/;
   19011            0 :         else if (VAR_P (o2) && DECL_NAME (o2) == NULL_TREE
   19012            0 :                  && !DECL_RTL_SET_P (o2))
   19013              :           /*Nop*/;
   19014            0 :         else if (!c_tree_equal (o1, o2))
   19015              :           return false;
   19016              : 
   19017            0 :         return c_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
   19018              :       }
   19019              : 
   19020           29 :     case COMPONENT_REF:
   19021           29 :       if (TREE_OPERAND (t1, 1) != TREE_OPERAND (t2, 1))
   19022              :         return false;
   19023           29 :       return c_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
   19024              : 
   19025              :     case PARM_DECL:
   19026              :     case VAR_DECL:
   19027              :     case CONST_DECL:
   19028              :     case FIELD_DECL:
   19029              :     case FUNCTION_DECL:
   19030              :     case IDENTIFIER_NODE:
   19031              :     case SSA_NAME:
   19032              :       return false;
   19033              : 
   19034            0 :     case TREE_VEC:
   19035            0 :       {
   19036            0 :         unsigned ix;
   19037            0 :         if (TREE_VEC_LENGTH (t1) != TREE_VEC_LENGTH (t2))
   19038              :           return false;
   19039            0 :         for (ix = TREE_VEC_LENGTH (t1); ix--;)
   19040            0 :           if (!c_tree_equal (TREE_VEC_ELT (t1, ix),
   19041            0 :                              TREE_VEC_ELT (t2, ix)))
   19042              :             return false;
   19043              :         return true;
   19044              :       }
   19045              : 
   19046           22 :     CASE_CONVERT:
   19047           22 :       if (!comptypes (TREE_TYPE (t1), TREE_TYPE (t2)))
   19048              :         return false;
   19049              :       break;
   19050              : 
   19051              :     default:
   19052              :       break;
   19053              :     }
   19054              : 
   19055          131 :   switch (TREE_CODE_CLASS (code1))
   19056              :     {
   19057          131 :     case tcc_unary:
   19058          131 :     case tcc_binary:
   19059          131 :     case tcc_comparison:
   19060          131 :     case tcc_expression:
   19061          131 :     case tcc_vl_exp:
   19062          131 :     case tcc_reference:
   19063          131 :     case tcc_statement:
   19064          131 :       {
   19065          131 :         int i, n = TREE_OPERAND_LENGTH (t1);
   19066              : 
   19067          131 :         switch (code1)
   19068              :           {
   19069            0 :           case PREINCREMENT_EXPR:
   19070            0 :           case PREDECREMENT_EXPR:
   19071            0 :           case POSTINCREMENT_EXPR:
   19072            0 :           case POSTDECREMENT_EXPR:
   19073            0 :             n = 1;
   19074            0 :             break;
   19075           16 :           case ARRAY_REF:
   19076           16 :             n = 2;
   19077           16 :             break;
   19078              :           default:
   19079              :             break;
   19080              :           }
   19081              : 
   19082          131 :         if (TREE_CODE_CLASS (code1) == tcc_vl_exp
   19083          131 :             && n != TREE_OPERAND_LENGTH (t2))
   19084              :           return false;
   19085              : 
   19086          305 :         for (i = 0; i < n; ++i)
   19087          186 :           if (!c_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i)))
   19088              :             return false;
   19089              : 
   19090              :         return true;
   19091              :       }
   19092              : 
   19093            0 :     case tcc_type:
   19094            0 :       return comptypes (t1, t2);
   19095            0 :     default:
   19096            0 :       gcc_unreachable ();
   19097              :     }
   19098              : }
   19099              : 
   19100              : /* Returns true when the function declaration FNDECL is implicit,
   19101              :    introduced as a result of a call to an otherwise undeclared
   19102              :    function, and false otherwise.  */
   19103              : 
   19104              : bool
   19105         2013 : c_decl_implicit (const_tree fndecl)
   19106              : {
   19107         2013 :   return C_DECL_IMPLICIT (fndecl);
   19108              : }
        

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.