LCOV - code coverage report
Current view: top level - gcc/c - c-typeck.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 93.7 % 9172 8596
Test Date: 2026-02-28 14:20:25 Functions: 99.5 % 205 204
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              : 
     145              : /* Return true if EXP is a null pointer constant, false otherwise.  */
     146              : 
     147              : bool
     148    188247487 : null_pointer_constant_p (const_tree expr)
     149              : {
     150              :   /* This should really operate on c_expr structures, but they aren't
     151              :      yet available everywhere required.  */
     152    188247487 :   tree type = TREE_TYPE (expr);
     153              : 
     154              :   /* An integer constant expression with the value 0, such an expression
     155              :      cast to type void*, or the predefined constant nullptr, are a null
     156              :      pointer constant.  */
     157    188247487 :   if (expr == nullptr_node)
     158              :     return true;
     159              : 
     160    188246828 :   return (TREE_CODE (expr) == INTEGER_CST
     161     19063419 :           && !TREE_OVERFLOW (expr)
     162     19063322 :           && integer_zerop (expr)
     163    192172682 :           && (INTEGRAL_TYPE_P (type)
     164       333325 :               || (TREE_CODE (type) == POINTER_TYPE
     165       333323 :                   && VOID_TYPE_P (TREE_TYPE (type))
     166       258044 :                   && TYPE_QUALS (TREE_TYPE (type)) == TYPE_UNQUALIFIED)));
     167              : }
     168              : 
     169              : /* EXPR may appear in an unevaluated part of an integer constant
     170              :    expression, but not in an evaluated part.  Wrap it in a
     171              :    C_MAYBE_CONST_EXPR, or mark it with TREE_OVERFLOW if it is just an
     172              :    INTEGER_CST and we cannot create a C_MAYBE_CONST_EXPR.  */
     173              : 
     174              : static tree
     175        62357 : note_integer_operands (tree expr)
     176              : {
     177        62357 :   tree ret;
     178        62357 :   if (TREE_CODE (expr) == INTEGER_CST && in_late_binary_op)
     179              :     {
     180           22 :       ret = copy_node (expr);
     181           22 :       TREE_OVERFLOW (ret) = 1;
     182              :     }
     183              :   else
     184              :     {
     185        62335 :       ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (expr), NULL_TREE, expr);
     186        62335 :       C_MAYBE_CONST_EXPR_INT_OPERANDS (ret) = 1;
     187              :     }
     188        62357 :   return ret;
     189              : }
     190              : 
     191              : /* Having checked whether EXPR may appear in an unevaluated part of an
     192              :    integer constant expression and found that it may, remove any
     193              :    C_MAYBE_CONST_EXPR noting this fact and return the resulting
     194              :    expression.  */
     195              : 
     196              : static inline tree
     197     33694977 : remove_c_maybe_const_expr (tree expr)
     198              : {
     199     33694977 :   if (TREE_CODE (expr) == C_MAYBE_CONST_EXPR)
     200        61507 :     return C_MAYBE_CONST_EXPR_EXPR (expr);
     201              :   else
     202              :     return expr;
     203              : }
     204              : 
     205              : /* This is a cache to hold if two types are seen.  */
     206              : 
     207              : struct tagged_tu_seen_cache {
     208              :   const struct tagged_tu_seen_cache * next;
     209              :   const_tree t1;
     210              :   const_tree t2;
     211              : };
     212              : 
     213              : /* Do `exp = require_complete_type (loc, exp);' to make sure exp
     214              :    does not have an incomplete type.  (That includes void types.)
     215              :    LOC is the location of the use.  */
     216              : 
     217              : tree
     218    771808124 : require_complete_type (location_t loc, tree value)
     219              : {
     220    771808124 :   tree type = TREE_TYPE (value);
     221              : 
     222    771808124 :   if (error_operand_p (value))
     223         8910 :     return error_mark_node;
     224              : 
     225              :   /* First, detect a valid value with a complete type.  */
     226    771799214 :   if (COMPLETE_TYPE_P (type))
     227              :     return value;
     228              : 
     229          164 :   c_incomplete_type_error (loc, value, type);
     230          164 :   return error_mark_node;
     231              : }
     232              : 
     233              : /* Print an error message for invalid use of an incomplete type.
     234              :    VALUE is the expression that was used (or 0 if that isn't known)
     235              :    and TYPE is the type that was invalid.  LOC is the location for
     236              :    the error.  */
     237              : 
     238              : void
     239          224 : c_incomplete_type_error (location_t loc, const_tree value, const_tree type)
     240              : {
     241              :   /* Avoid duplicate error message.  */
     242          224 :   if (TREE_CODE (type) == ERROR_MARK)
     243              :     return;
     244              : 
     245          224 :   if (value != NULL_TREE && (VAR_P (value) || TREE_CODE (value) == PARM_DECL))
     246           98 :     error_at (loc, "%qD has an incomplete type %qT", value, type);
     247              :   else
     248              :     {
     249          126 :     retry:
     250              :       /* We must print an error message.  Be clever about what it says.  */
     251              : 
     252          126 :       switch (TREE_CODE (type))
     253              :         {
     254           82 :         case RECORD_TYPE:
     255           82 :         case UNION_TYPE:
     256           82 :         case ENUMERAL_TYPE:
     257           82 :           break;
     258              : 
     259           38 :         case VOID_TYPE:
     260           38 :           error_at (loc, "invalid use of void expression");
     261           38 :           return;
     262              : 
     263            6 :         case ARRAY_TYPE:
     264            6 :           if (TYPE_DOMAIN (type))
     265              :             {
     266            3 :               if (TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL)
     267              :                 {
     268            3 :                   error_at (loc, "invalid use of flexible array member");
     269            3 :                   return;
     270              :                 }
     271            0 :               type = TREE_TYPE (type);
     272            0 :               goto retry;
     273              :             }
     274            3 :           error_at (loc, "invalid use of array with unspecified bounds");
     275            3 :           return;
     276              : 
     277            0 :         default:
     278            0 :           gcc_unreachable ();
     279              :         }
     280              : 
     281           82 :       if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
     282           80 :         error_at (loc, "invalid use of undefined type %qT", type);
     283              :       else
     284              :         /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL.  */
     285            2 :         error_at (loc, "invalid use of incomplete typedef %qT", type);
     286              :     }
     287              : }
     288              : 
     289              : /* Given a type, apply default promotions wrt unnamed function
     290              :    arguments and return the new type.  */
     291              : 
     292              : tree
     293    124297926 : c_type_promotes_to (tree type)
     294              : {
     295    124297926 :   tree ret = NULL_TREE;
     296              : 
     297    124297926 :   if (TYPE_MAIN_VARIANT (type) == float_type_node)
     298      1503628 :     ret = double_type_node;
     299    122794298 :   else if (c_promoting_integer_type_p (type))
     300              :     {
     301              :       /* Preserve unsignedness if not really getting any wider.  */
     302     18620070 :       if (TYPE_UNSIGNED (type)
     303     18620070 :           && (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)))
     304            0 :         ret = unsigned_type_node;
     305              :       else
     306     18620070 :         ret = integer_type_node;
     307              :     }
     308              : 
     309     20123698 :   if (ret != NULL_TREE)
     310     20123698 :     return (TYPE_ATOMIC (type)
     311     20123698 :             ? c_build_qualified_type (ret, TYPE_QUAL_ATOMIC)
     312              :             : ret);
     313              : 
     314              :   return type;
     315              : }
     316              : 
     317              : /* Return true if between two named address spaces, whether there is a superset
     318              :    named address space that encompasses both address spaces.  If there is a
     319              :    superset, return which address space is the superset.  */
     320              : 
     321              : static bool
     322      7347962 : addr_space_superset (addr_space_t as1, addr_space_t as2, addr_space_t *common)
     323              : {
     324      7347962 :   if (as1 == as2)
     325              :     {
     326      7347962 :       *common = as1;
     327      7347962 :       return true;
     328              :     }
     329            0 :   else if (targetm.addr_space.subset_p (as1, as2))
     330              :     {
     331            0 :       *common = as2;
     332            0 :       return true;
     333              :     }
     334            0 :   else if (targetm.addr_space.subset_p (as2, as1))
     335              :     {
     336            0 :       *common = as1;
     337            0 :       return true;
     338              :     }
     339              :   else
     340              :     return false;
     341              : }
     342              : 
     343              : /* Return a variant of TYPE which has all the type qualifiers of LIKE
     344              :    as well as those of TYPE.  */
     345              : 
     346              : static tree
     347      2596279 : qualify_type (tree type, tree like)
     348              : {
     349      2596279 :   addr_space_t as_type = TYPE_ADDR_SPACE (type);
     350      2596279 :   addr_space_t as_like = TYPE_ADDR_SPACE (like);
     351      2596279 :   addr_space_t as_common;
     352              : 
     353              :   /* If the two named address spaces are different, determine the common
     354              :      superset address space.  If there isn't one, raise an error.  */
     355      2596279 :   if (!addr_space_superset (as_type, as_like, &as_common))
     356              :     {
     357            0 :       as_common = as_type;
     358            0 :       error ("%qT and %qT are in disjoint named address spaces",
     359              :              type, like);
     360              :     }
     361              : 
     362      5192558 :   return c_build_qualified_type (type,
     363      2596279 :                                  TYPE_QUALS_NO_ADDR_SPACE (type)
     364      2596279 :                                  | TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (like)
     365      2596279 :                                  | ENCODE_QUAL_ADDR_SPACE (as_common));
     366              : }
     367              : 
     368              : 
     369              : /* Check consistency of type TYPE.  For derived types, we test that
     370              :    C_TYPE_VARIABLE_SIZE and C_TYPE_VARIABLY_MODIFIED are consistent with
     371              :    the requirements of the base type.  We also check that arrays with a
     372              :    non-constant length are marked with C_TYPE_VARIABLE_SIZE. If any
     373              :    inconsistency is detected false is returned and true otherwise.  */
     374              : 
     375              : static bool
     376    139762398 : c_verify_type (tree type)
     377              : {
     378    139762398 :   switch (TREE_CODE (type))
     379              :     {
     380     65750506 :     case POINTER_TYPE:
     381     65750506 :     case FUNCTION_TYPE:
     382              :       /* Pointer and funcions can not have variable size.  */
     383     65750506 :       if (C_TYPE_VARIABLE_SIZE (type))
     384              :         return false;
     385              :       /* Pointer and funcions are variably modified if and only if the
     386              :          return / target type is variably modified.  */
     387     65750506 :       if (C_TYPE_VARIABLY_MODIFIED (type)
     388     65750506 :           != C_TYPE_VARIABLY_MODIFIED (TREE_TYPE (type)))
     389            0 :         return false;
     390              :       break;
     391       903757 :     case ARRAY_TYPE:
     392              :       /* An array has variable size if and only if it has a non-constant
     393              :          dimensions or its element type has variable size.  */
     394       903757 :       if ((C_TYPE_VARIABLE_SIZE (TREE_TYPE (type))
     395       903757 :            || (TYPE_DOMAIN (type) && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
     396       878306 :                && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
     397              :                   != INTEGER_CST))
     398       903757 :           != C_TYPE_VARIABLE_SIZE (type))
     399              :         return false;
     400              :       /* If the element type or the array has variable size, then the
     401              :          array has variable size and is variably modified.  */
     402       903757 :       if (C_TYPE_VARIABLE_SIZE (TREE_TYPE (type))
     403       903757 :           || C_TYPE_VARIABLE_SIZE (type))
     404              :         {
     405        28612 :           if (!C_TYPE_VARIABLE_SIZE (type))
     406              :             return false;
     407        28612 :           if (!C_TYPE_VARIABLY_MODIFIED (type))
     408              :             return false;
     409              :         }
     410              :       /* If the element type is variably modified, then also the array.  */
     411       903757 :       if (C_TYPE_VARIABLY_MODIFIED (TREE_TYPE (type))
     412       903757 :           && !C_TYPE_VARIABLY_MODIFIED (type))
     413            0 :         return false;
     414              :       break;
     415              :     default:
     416              :       break;
     417              :     }
     418              :   return true;
     419              : }
     420              : 
     421              : /* Propagate C_TYPE_VARIABLY_MODIFIED and C_TYPE_VARIABLE_SIZE
     422              :    from a base type to a newly built derived or qualified type.  */
     423              : 
     424              : static tree
     425    132784626 : c_set_type_bits (tree new_type, tree old_type)
     426              : {
     427    132784626 :   gcc_checking_assert (c_verify_type (old_type));
     428              : 
     429    132784626 :   if (C_TYPE_VARIABLY_MODIFIED (old_type))
     430        28214 :     C_TYPE_VARIABLY_MODIFIED (new_type) = true;
     431              : 
     432    132784626 :   if (TREE_CODE (new_type) == ARRAY_TYPE && C_TYPE_VARIABLE_SIZE (old_type))
     433              :     {
     434        16778 :       C_TYPE_VARIABLY_MODIFIED (new_type) = true;
     435        16778 :       C_TYPE_VARIABLE_SIZE (new_type) = true;
     436              :     }
     437    132784626 :   return new_type;
     438              : }
     439              : 
     440              : /* Build a pointer type using the default pointer mode.  */
     441              : 
     442              : tree
     443     71386699 : c_build_pointer_type (tree to_type)
     444              : {
     445     71386699 :   addr_space_t as = to_type == error_mark_node ? ADDR_SPACE_GENERIC
     446     71386699 :                                                : TYPE_ADDR_SPACE (to_type);
     447     71386699 :   machine_mode pointer_mode;
     448              : 
     449     71386699 :   if (as != ADDR_SPACE_GENERIC || c_default_pointer_mode == VOIDmode)
     450     71386699 :     pointer_mode = targetm.addr_space.pointer_mode (as);
     451              :   else
     452              :     pointer_mode = c_default_pointer_mode;
     453              : 
     454     71386699 :   return c_build_pointer_type_for_mode (to_type, pointer_mode, false);
     455              : }
     456              : 
     457              : /* Build a pointer type using the given mode.  */
     458              : 
     459              : tree
     460     71395657 : c_build_pointer_type_for_mode (tree type, machine_mode mode, bool m)
     461              : {
     462     71395657 :   tree ret = build_pointer_type_for_mode (type, mode, m);
     463     71395657 :   return c_set_type_bits (ret, type);
     464              : }
     465              : 
     466              : /* Build a function type.  */
     467              : 
     468              : tree
     469     53201995 : c_build_function_type (tree type, tree args, bool no)
     470              : {
     471     53201995 :   tree ret = build_function_type (type, args, no);
     472     53201995 :   return c_set_type_bits (ret, type);
     473              : }
     474              : 
     475              : /* Build an array type.  This sets typeless storage as required
     476              :    by C2Y and C_TYPE_VARIABLY_MODIFIED and C_TYPE_VARIABLE_SIZE
     477              :    based on the element type and domain.  */
     478              : 
     479              : tree
     480      1161679 : c_build_array_type (tree type, tree domain)
     481              : {
     482      1161679 :   int type_quals = TYPE_QUALS (type);
     483              : 
     484              :   /* Identify typeless storage as introduced in C2Y
     485              :      and supported also in earlier language modes.  */
     486      1737068 :   bool typeless = (char_type_p (type) && !(type_quals & TYPE_QUAL_ATOMIC))
     487      1161679 :                   || (AGGREGATE_TYPE_P (type) && TYPE_TYPELESS_STORAGE (type));
     488              : 
     489      1161679 :   tree ret = build_array_type (type, domain, typeless);
     490              : 
     491      1076227 :   if (domain && TYPE_MAX_VALUE (domain)
     492      2148849 :       && TREE_CODE (TYPE_MAX_VALUE (domain)) != INTEGER_CST)
     493              :     {
     494        24212 :       C_TYPE_VARIABLE_SIZE (ret) = 1;
     495        24212 :       C_TYPE_VARIABLY_MODIFIED (ret) = 1;
     496              :     }
     497              : 
     498      1161679 :   return c_set_type_bits (ret, type);
     499              : }
     500              : 
     501              : 
     502              : /* Build an array type of unspecified size.  */
     503              : tree
     504          150 : c_build_array_type_unspecified (tree type)
     505              : {
     506          150 :   tree upper = build2 (COMPOUND_EXPR, TREE_TYPE (size_zero_node),
     507              :                        integer_zero_node, size_zero_node);
     508          150 :   return c_build_array_type (type, build_index_type (upper));
     509              : }
     510              : 
     511              : 
     512              : tree
     513      7025295 : c_build_type_attribute_qual_variant (tree type, tree attrs, int quals)
     514              : {
     515      7025295 :   tree ret = build_type_attribute_qual_variant (type, attrs, quals);
     516      7025295 :   return c_set_type_bits (ret, type);
     517              : }
     518              : 
     519              : tree
     520      7018760 : c_build_type_attribute_variant (tree type, tree attrs)
     521              : {
     522      7018760 :   return c_build_type_attribute_qual_variant (type, attrs, TYPE_QUALS (type));
     523              : }
     524              : 
     525              : /* Reconstruct a complex derived type.  This is used to re-construct types
     526              :    with the vector attribute.  It is called via a langhook.  */
     527              : 
     528              : tree
     529       494281 : c_reconstruct_complex_type (tree type, tree bottom)
     530              : {
     531       494281 :   tree inner, outer;
     532              : 
     533       494281 :   if (TREE_CODE (type) == POINTER_TYPE)
     534              :     {
     535           17 :       inner = c_reconstruct_complex_type (TREE_TYPE (type), bottom);
     536           17 :       outer = c_build_pointer_type_for_mode (inner, TYPE_MODE (type),
     537           17 :                                              TYPE_REF_CAN_ALIAS_ALL (type));
     538              :     }
     539              :   else if (TREE_CODE (type) == ARRAY_TYPE)
     540              :     {
     541           15 :       inner = c_reconstruct_complex_type (TREE_TYPE (type), bottom);
     542           15 :       outer = c_build_array_type (inner, TYPE_DOMAIN (type));
     543              : 
     544           15 :       gcc_checking_assert (C_TYPE_VARIABLE_SIZE (type)
     545              :                            == C_TYPE_VARIABLE_SIZE (outer));
     546           15 :       gcc_checking_assert (C_TYPE_VARIABLY_MODIFIED (outer)
     547              :                            == C_TYPE_VARIABLY_MODIFIED (type));
     548              :     }
     549              :   else if (TREE_CODE (type) == FUNCTION_TYPE)
     550              :     {
     551          172 :       inner = c_reconstruct_complex_type (TREE_TYPE (type), bottom);
     552          172 :       outer = c_build_function_type (inner, TYPE_ARG_TYPES (type),
     553          172 :                                      TYPE_NO_NAMED_ARGS_STDARG_P (type));
     554              :     }
     555              :   else if (TREE_CODE (type) == REFERENCE_TYPE
     556              :            || TREE_CODE (type) == OFFSET_TYPE)
     557            0 :     gcc_unreachable ();
     558              :   else
     559              :     return bottom;
     560              : 
     561          204 :   return c_build_type_attribute_qual_variant (outer, TYPE_ATTRIBUTES (type),
     562          408 :                                               TYPE_QUALS (type));
     563              : }
     564              : 
     565              : /* If NTYPE is a type of a non-variadic function with a prototype
     566              :    and OTYPE is a type of a function without a prototype and ATTRS
     567              :    contains attribute format, diagnosess and removes it from ATTRS.
     568              :    Returns the result of build_type_attribute_variant of NTYPE and
     569              :    the (possibly) modified ATTRS.  */
     570              : 
     571              : static tree
     572         9835 : c_build_functype_attribute_variant (tree ntype, tree otype, tree attrs)
     573              : {
     574         9835 :   if (!prototype_p (otype)
     575         9823 :       && prototype_p (ntype)
     576        19626 :       && lookup_attribute ("format", attrs))
     577              :     {
     578           14 :       warning_at (input_location, OPT_Wattributes,
     579              :                   "%qs attribute can only be applied to variadic functions",
     580              :                   "format");
     581           14 :       attrs = remove_attribute ("format", attrs);
     582              :     }
     583         9835 :   return c_build_type_attribute_variant (ntype, attrs);
     584              : 
     585              : }
     586              : 
     587              : /* Given a type which could be a typedef name, make sure to return the
     588              :    original type.  See set_underlying_type. */
     589              : static const_tree
     590     61942808 : c_type_original (const_tree t)
     591              : {
     592              :   /* It may even be a typedef of a typedef...
     593              :      In the case of compiler-created builtin structs the TYPE_DECL
     594              :      may be a dummy, with no DECL_ORIGINAL_TYPE.  Don't fault.  */
     595     61942808 :   while (TYPE_NAME (t)
     596     31750408 :          && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL
     597     61946688 :          && DECL_ORIGINAL_TYPE (TYPE_NAME (t)))
     598         1939 :     t = DECL_ORIGINAL_TYPE (TYPE_NAME (t));
     599     61942808 :   return t;
     600              : }
     601              : 
     602              : /* Return the tag for a tagged type.  */
     603              : tree
     604     61942808 : c_type_tag (const_tree t)
     605              : {
     606     61942808 :   gcc_assert (RECORD_OR_UNION_TYPE_P (t) || TREE_CODE (t) == ENUMERAL_TYPE);
     607     61942808 :   const_tree orig = c_type_original (t);
     608     61942808 :   tree name = TYPE_NAME (orig);
     609     61942808 :   if (!name)
     610              :     return NULL_TREE;
     611     31748469 :   if (TREE_CODE (name) == TYPE_DECL)
     612              :     {
     613            2 :       if (!DECL_NAME (name))
     614              :         return NULL_TREE;
     615            0 :       name = DECL_NAME (name);
     616              :     }
     617     31748467 :   gcc_checking_assert (TREE_CODE (name) == IDENTIFIER_NODE);
     618              :   return name;
     619              : }
     620              : 
     621              : /* Remove qualifiers but not atomic.  For arrays remove qualifiers
     622              :    on the element type but also do not remove atomic.  */
     623              : static tree
     624     62262403 : remove_qualifiers (tree t)
     625              : {
     626     62262403 :   if (!t || t == error_mark_node)
     627              :     return t;
     628     62262378 :   return TYPE_ATOMIC (strip_array_types (t))
     629     62262378 :          ? c_build_qualified_type (TYPE_MAIN_VARIANT (t), TYPE_QUAL_ATOMIC)
     630     62246803 :          : TYPE_MAIN_VARIANT (t);
     631              : }
     632              : 
     633              : 
     634              : /* Helper function for composite_type_internal.  Find a compatible type
     635              :    in a (transparent) union U compatible to T.  If found, return the
     636              :    type of the corresponding member.  Otherwise, return the union type U.  */
     637              : static tree
     638      8200488 : transparent_union_replacement (tree u, tree t)
     639              : {
     640      8200483 :   if (u == error_mark_node || t == error_mark_node
     641      8200478 :       || TREE_CODE (u) != UNION_TYPE
     642           64 :       || !(TYPE_TRANSPARENT_AGGR (u) || TYPE_NAME (u) == NULL_TREE)
     643      8200552 :       || comptypes (u, t))
     644      8200424 :     return u;
     645              : 
     646           80 :   for (tree memb = TYPE_FIELDS (u); memb; memb = DECL_CHAIN (memb))
     647              :     {
     648           80 :       tree m = remove_qualifiers (TREE_TYPE (memb));
     649           80 :       if (comptypes (m, t))
     650              :         {
     651           64 :           pedwarn (input_location, OPT_Wpedantic,
     652              :                     "function types not truly compatible in ISO C");
     653           64 :           return m;
     654              :         }
     655              :     }
     656              : 
     657              :   return u;
     658              : }
     659              : 
     660              : 
     661              : 
     662              : /* Return the composite type of two compatible types.
     663              : 
     664              :    We assume that comptypes has already been done and returned
     665              :    nonzero; if that isn't so, this may crash.  In particular, we
     666              :    assume that qualifiers match.  */
     667              : 
     668              : struct composite_cache {
     669              :   tree t1;
     670              :   tree t2;
     671              :   tree composite;
     672              :   struct composite_cache* next;
     673              : };
     674              : 
     675              : tree
     676     13005130 : composite_type_internal (tree t1, tree t2, tree cond,
     677              :                          struct composite_cache* cache)
     678              : {
     679     13005130 :   enum tree_code code1;
     680     13005130 :   enum tree_code code2;
     681     13005130 :   tree attributes;
     682              : 
     683              :   /* Save time if the two types are the same.  */
     684              : 
     685     13005130 :   if (t1 == t2) return t1;
     686              : 
     687              :   /* If one type is nonsense, use the other.  */
     688      2629875 :   if (t1 == error_mark_node)
     689              :     return t2;
     690      2629871 :   if (t2 == error_mark_node)
     691              :     return t1;
     692              : 
     693      2629869 :   code1 = TREE_CODE (t1);
     694      2629869 :   code2 = TREE_CODE (t2);
     695              : 
     696              :   /* Merge the attributes.  */
     697      2629869 :   attributes = targetm.merge_type_attributes (t1, t2);
     698              : 
     699              :   /* If one is an enumerated type and the other is the compatible
     700              :      integer type, the composite type might be either of the two
     701              :      (DR#013 question 3).  For consistency, use the enumerated type as
     702              :      the composite type.  */
     703              : 
     704      2629869 :   if (code1 == ENUMERAL_TYPE
     705          194 :       && (code2 == INTEGER_TYPE
     706          194 :           || code2 == BOOLEAN_TYPE))
     707              :     return t1;
     708      2629675 :   if (code2 == ENUMERAL_TYPE
     709           69 :       && (code1 == INTEGER_TYPE
     710           69 :           || code1 == BOOLEAN_TYPE))
     711              :     return t2;
     712              : 
     713      2629606 :   gcc_assert (code1 == code2);
     714              : 
     715      2629606 :   switch (code1)
     716              :     {
     717         6331 :     case POINTER_TYPE:
     718              :       /* For two pointers, do this recursively on the target type.  */
     719         6331 :       {
     720         6331 :         gcc_checking_assert (TYPE_QUALS (t1) == TYPE_QUALS (t2));
     721         6331 :         tree target = composite_type_internal (TREE_TYPE (t1), TREE_TYPE (t2),
     722              :                                                cond, cache);
     723         6331 :         tree n = c_build_pointer_type_for_mode (target, TYPE_MODE (t1), false);
     724        12662 :         return c_build_type_attribute_qual_variant (n, attributes,
     725         6331 :                                                     TYPE_QUALS (t2));
     726              :       }
     727              : 
     728        10958 :     case ARRAY_TYPE:
     729        10958 :       {
     730        10958 :         tree d1 = TYPE_DOMAIN (t1);
     731        10958 :         tree d2 = TYPE_DOMAIN (t2);
     732              : 
     733              :         /* We should not have any type quals on arrays at all.  */
     734        10958 :         gcc_assert (!TYPE_QUALS_NO_ADDR_SPACE (t1)
     735              :                     && !TYPE_QUALS_NO_ADDR_SPACE (t2));
     736              : 
     737        10958 :         bool t1_complete = COMPLETE_TYPE_P (t1);
     738        10958 :         bool t2_complete = COMPLETE_TYPE_P (t2);
     739              : 
     740        10958 :         bool d1_zero = d1 == NULL_TREE || !TYPE_MAX_VALUE (d1);
     741        10958 :         bool d2_zero = d2 == NULL_TREE || !TYPE_MAX_VALUE (d2);
     742              : 
     743        10958 :         bool d1_variable, d2_variable;
     744              : 
     745        21916 :         d1_variable = (!d1_zero
     746        10958 :                        && (TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST
     747        10365 :                            || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST));
     748        21916 :         d2_variable = (!d2_zero
     749        10958 :                        && (TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
     750        10618 :                            || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST));
     751              : 
     752        10958 :         bool use1 = d1 && (d2_variable || d2_zero || !d1_variable);
     753        10958 :         bool use2 = d2 && (d1_variable || d1_zero || !d2_variable);
     754              : 
     755              :         /* If the first is an unspecified size pick the other one.  */
     756         8976 :         if (d2_variable && c_type_unspecified_p (t1))
     757              :           {
     758           28 :             gcc_assert (use1 && use2);
     759              :             use1 = false;
     760              :           }
     761              : 
     762              :         /* If both are VLAs but not unspecified and we are in the
     763              :            conditional operator, we create a conditional to select
     764              :            the size of the active branch.  */
     765          202 :         bool use0 = cond && d1_variable && !c_type_unspecified_p (t1)
     766        11157 :                          && d2_variable && !c_type_unspecified_p (t2);
     767              : 
     768        10958 :         tree td;
     769        10958 :         tree elt = composite_type_internal (TREE_TYPE (t1), TREE_TYPE (t2),
     770              :                                             cond, cache);
     771              : 
     772        10958 :         if (!use0)
     773              :           {
     774              :             /* Save space: see if the result is identical to one of the args.  */
     775        10865 :             if (elt == TREE_TYPE (t1) && use1)
     776        10079 :               return c_build_type_attribute_variant (t1, attributes);
     777          786 :             if (elt == TREE_TYPE (t2) && use2)
     778          668 :               return c_build_type_attribute_variant (t2, attributes);
     779              : 
     780          161 :             if (elt == TREE_TYPE (t1) && !TYPE_DOMAIN (t2) && !TYPE_DOMAIN (t1))
     781           10 :               return c_build_type_attribute_variant (t1, attributes);
     782          116 :             if (elt == TREE_TYPE (t2) && !TYPE_DOMAIN (t2) && !TYPE_DOMAIN (t1))
     783            2 :               return c_build_type_attribute_variant (t2, attributes);
     784              : 
     785          212 :             td = TYPE_DOMAIN (use1 ? t1 : t2);
     786              :           }
     787              :         else
     788              :           {
     789              :             /* Not used in C.  */
     790           93 :             gcc_assert (size_zero_node == TYPE_MIN_VALUE (d1));
     791           93 :             gcc_assert (size_zero_node == TYPE_MIN_VALUE (d2));
     792              : 
     793           93 :             tree d = fold_build3_loc (UNKNOWN_LOCATION, COND_EXPR, sizetype,
     794           93 :                                       cond, TYPE_MAX_VALUE (d1),
     795           93 :                                       TYPE_MAX_VALUE (d2));
     796              : 
     797           93 :             td = build_index_type (d);
     798              :           }
     799              : 
     800              :         /* Merge the element types, and have a size if either arg has
     801              :            one.  We may have qualifiers on the element types.  To set
     802              :            up TYPE_MAIN_VARIANT correctly, we need to form the
     803              :            composite of the unqualified types and add the qualifiers
     804              :            back at the end.  */
     805          199 :         int quals = TYPE_QUALS (strip_array_types (elt));
     806          199 :         tree unqual_elt = c_build_qualified_type (elt, TYPE_UNQUALIFIED);
     807              : 
     808          199 :         t1 = c_build_array_type (unqual_elt, td);
     809              : 
     810              :         /* Check that a type which has a varying outermost dimension
     811              :            got marked has having a variable size.  */
     812          199 :         bool varsize = (d1_variable && d2_variable)
     813           97 :                        || (d1_variable && !t2_complete)
     814          285 :                        || (d2_variable && !t1_complete);
     815          133 :         gcc_checking_assert (!varsize || C_TYPE_VARIABLE_SIZE (t1));
     816              : 
     817              :         /* Ensure a composite type involving a zero-length array type
     818              :            is a zero-length type not an incomplete type.  */
     819          199 :         if (d1_zero && d2_zero
     820           16 :             && (t1_complete || t2_complete)
     821          200 :             && !COMPLETE_TYPE_P (t1))
     822              :           {
     823            1 :             TYPE_SIZE (t1) = bitsize_zero_node;
     824            1 :             TYPE_SIZE_UNIT (t1) = size_zero_node;
     825              :           }
     826          199 :         t1 = c_build_qualified_type (t1, quals);
     827          199 :         return c_build_type_attribute_variant (t1, attributes);
     828              :       }
     829              : 
     830          202 :     case RECORD_TYPE:
     831          202 :     case UNION_TYPE:
     832          202 :       if (flag_isoc23 && !comptypes_same_p (t1, t2))
     833              :         {
     834              :           /* Go to the original type to get the right tag.  */
     835          101 :           tree tag = c_type_tag (t1);
     836              : 
     837          101 :           gcc_checking_assert (COMPLETE_TYPE_P (t1) && COMPLETE_TYPE_P (t2));
     838          101 :           gcc_checking_assert (!tag || comptypes (t1, t2));
     839              : 
     840              :           /* If a composite type for these two types is already under
     841              :              construction, return it.  */
     842              : 
     843          246 :           for (struct composite_cache *c = cache; c != NULL; c = c->next)
     844          152 :             if ((c->t1 == t1 && c->t2 == t2) || (c->t1 == t2 && c->t2 == t1))
     845            7 :                return c->composite;
     846              : 
     847              :           /* Otherwise, create a new type node and link it into the cache.  */
     848              : 
     849           94 :           tree n = make_node (code1);
     850           94 :           SET_TYPE_STRUCTURAL_EQUALITY (n);
     851           94 :           TYPE_NAME (n) = tag;
     852              : 
     853           94 :           struct composite_cache cache2 = { t1, t2, n, cache };
     854           94 :           cache = &cache2;
     855              : 
     856           94 :           tree f1 = TYPE_FIELDS (t1);
     857           94 :           tree f2 = TYPE_FIELDS (t2);
     858           94 :           tree fields = NULL_TREE;
     859              : 
     860          214 :           for (tree a = f1, b = f2; a && b;
     861          120 :                a = DECL_CHAIN (a), b = DECL_CHAIN (b))
     862              :             {
     863          120 :               tree ta = TREE_TYPE (a);
     864          120 :               tree tb = TREE_TYPE (b);
     865              : 
     866          120 :               if (DECL_C_BIT_FIELD (a))
     867              :                 {
     868           19 :                   ta = DECL_BIT_FIELD_TYPE (a);
     869           19 :                   tb = DECL_BIT_FIELD_TYPE (b);
     870              :                 }
     871              : 
     872          120 :               gcc_assert (DECL_NAME (a) == DECL_NAME (b));
     873          120 :               gcc_checking_assert (!DECL_NAME (a) || comptypes (ta, tb));
     874              : 
     875          120 :               tree t = composite_type_internal (ta, tb, cond, cache);
     876          120 :               tree f = build_decl (input_location, FIELD_DECL, DECL_NAME (a), t);
     877              : 
     878          120 :               DECL_PACKED (f) = DECL_PACKED (a);
     879          120 :               SET_DECL_ALIGN (f, DECL_ALIGN (a));
     880          120 :               DECL_ATTRIBUTES (f) = DECL_ATTRIBUTES (a);
     881          120 :               C_DECL_VARIABLE_SIZE (f) = C_TYPE_VARIABLE_SIZE (t);
     882              : 
     883          120 :               decl_attributes (&f, DECL_ATTRIBUTES (f), 0);
     884              : 
     885          120 :               finish_decl (f, input_location, NULL, NULL, NULL);
     886              : 
     887          120 :               if (DECL_C_BIT_FIELD (a))
     888              :                 {
     889              :                   /* This will be processed by finish_struct.  */
     890           19 :                   SET_DECL_C_BIT_FIELD (f);
     891           19 :                   DECL_INITIAL (f) = build_int_cst (integer_type_node,
     892           19 :                                                     tree_to_uhwi (DECL_SIZE (a)));
     893           19 :                   DECL_NONADDRESSABLE_P (f) = true;
     894           19 :                   DECL_PADDING_P (f) = !DECL_NAME (a);
     895              :                 }
     896              : 
     897          120 :               DECL_CHAIN (f) = fields;
     898          120 :               fields = f;
     899              :             }
     900              : 
     901           94 :           fields = nreverse (fields);
     902              : 
     903              :           /* Setup the struct/union type.  Because we inherit all variably
     904              :              modified components, we can ignore the size expression.  */
     905           94 :           tree expr = NULL_TREE;
     906              : 
     907              :           /* Set TYPE_STUB_DECL for debugging symbols.  */
     908           94 :           TYPE_STUB_DECL (n) = pushdecl (build_decl (input_location, TYPE_DECL,
     909              :                                                      NULL_TREE, n));
     910              : 
     911           94 :           n = finish_struct (input_location, n, fields, attributes, NULL,
     912              :                              &expr);
     913              : 
     914           94 :           return qualify_type (n, t1);
     915              :         }
     916              :       /* FALLTHRU */
     917          101 :     case ENUMERAL_TYPE:
     918          101 :       if (attributes != NULL)
     919              :         {
     920              :           /* Try harder not to create a new aggregate type.  */
     921            4 :           if (attribute_list_equal (TYPE_ATTRIBUTES (t1), attributes))
     922              :             return t1;
     923            0 :           if (attribute_list_equal (TYPE_ATTRIBUTES (t2), attributes))
     924              :             return t2;
     925              :         }
     926           97 :       return c_build_type_attribute_variant (t1, attributes);
     927              : 
     928      2571265 :     case FUNCTION_TYPE:
     929              :       /* Function types: prefer the one that specified arg types.
     930              :          If both do, merge the arg types.  Also merge the return types.  */
     931      2571265 :       {
     932      2571265 :         tree valtype = composite_type_internal (TREE_TYPE (t1), TREE_TYPE (t2),
     933              :                                                 cond, cache);
     934      2571265 :         tree p1 = TYPE_ARG_TYPES (t1);
     935      2571265 :         tree p2 = TYPE_ARG_TYPES (t2);
     936              : 
     937              :         /* Save space: see if the result is identical to one of the args.  */
     938      2571265 :         if (valtype == TREE_TYPE (t1) && !TYPE_ARG_TYPES (t2))
     939         9845 :           return c_build_functype_attribute_variant (t1, t2, attributes);
     940      2561947 :         if (valtype == TREE_TYPE (t2) && !TYPE_ARG_TYPES (t1))
     941          517 :           return c_build_functype_attribute_variant (t2, t1, attributes);
     942              : 
     943              :         /* Simple way if one arg fails to specify argument types.  */
     944      2561430 :         if (TYPE_ARG_TYPES (t1) == NULL_TREE)
     945              :           {
     946            9 :             t1 = c_build_function_type (valtype, TYPE_ARG_TYPES (t2),
     947            9 :                                         TYPE_NO_NAMED_ARGS_STDARG_P (t2));
     948            9 :             t1 = c_build_type_attribute_variant (t1, attributes);
     949            9 :             return qualify_type (t1, t2);
     950              :          }
     951      2561421 :         if (TYPE_ARG_TYPES (t2) == NULL_TREE)
     952              :           {
     953            1 :             t1 = c_build_function_type (valtype, TYPE_ARG_TYPES (t1),
     954            1 :                                         TYPE_NO_NAMED_ARGS_STDARG_P (t1));
     955            1 :             t1 = c_build_type_attribute_variant (t1, attributes);
     956            1 :             return qualify_type (t1, t2);
     957              :           }
     958              : 
     959              :         /* If both args specify argument types, we must merge the two
     960              :            lists, argument by argument.  */
     961      2561420 :         tree newargs = NULL_TREE;
     962      2561420 :         tree *endp = &newargs;
     963              : 
     964      6661664 :         for (; p1; p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2))
     965              :           {
     966      6494483 :             if (p1 == void_list_node)
     967              :               {
     968      2394239 :                 *endp = void_list_node;
     969      2394239 :                 break;
     970              :               }
     971      4100244 :             tree mv1 = remove_qualifiers (TREE_VALUE (p1));
     972      4100244 :             tree mv2 = remove_qualifiers (TREE_VALUE (p2));
     973              : 
     974      4100244 :             gcc_assert (mv1);
     975      4100244 :             gcc_assert (mv2);
     976              : 
     977      4100244 :             mv1 = transparent_union_replacement (mv1, mv2);
     978      4100244 :             mv2 = transparent_union_replacement (mv2, mv1);
     979              : 
     980      4100244 :             *endp = tree_cons (NULL_TREE,
     981              :                                composite_type_internal (mv1, mv2, cond, cache),
     982              :                                NULL_TREE);
     983              : 
     984      4100244 :             endp = &TREE_CHAIN (*endp);
     985              :           }
     986              : 
     987      2561420 :         t1 = c_build_function_type (valtype, newargs);
     988      2561420 :         t1 = qualify_type (t1, t2);
     989              :       }
     990              :       /* FALLTHRU */
     991              : 
     992      2602270 :     default:
     993      2602270 :       return c_build_type_attribute_variant (t1, attributes);
     994              :     }
     995              : }
     996              : 
     997              : tree
     998      6316212 : composite_type_cond (tree t1, tree t2, tree cond)
     999              : {
    1000      6316212 :   gcc_checking_assert (comptypes_check_for_composite (t1, t2));
    1001              : 
    1002      6316212 :   struct composite_cache cache = { };
    1003      6316212 :   tree n = composite_type_internal (t1, t2, cond, &cache);
    1004              : 
    1005      6316212 :   gcc_checking_assert (comptypes_check_for_composite (n, t1));
    1006      6316212 :   gcc_checking_assert (comptypes_check_for_composite (n, t2));
    1007      6316212 :   return n;
    1008              : }
    1009              : 
    1010              : 
    1011              : tree
    1012      6311759 : composite_type (tree t1, tree t2)
    1013              : {
    1014      6311759 :   return composite_type_cond (t1, t2, NULL_TREE);
    1015              : }
    1016              : 
    1017              : /* Return the type of a conditional expression between pointers to
    1018              :    possibly differently qualified versions of compatible types.
    1019              : 
    1020              :    We assume that comp_target_types has already been done and returned
    1021              :    true; if that isn't so, this may crash.  */
    1022              : 
    1023              : static tree
    1024       114765 : common_pointer_type (tree t1, tree t2, tree cond)
    1025              : {
    1026       114765 :   tree attributes;
    1027       114765 :   unsigned target_quals;
    1028       114765 :   addr_space_t as1, as2, as_common;
    1029       114765 :   int quals1, quals2;
    1030              : 
    1031              :   /* Save time if the two types are the same.  */
    1032              : 
    1033       114765 :   if (t1 == t2) return t1;
    1034              : 
    1035              :   /* If one type is nonsense, use the other.  */
    1036         4453 :   if (t1 == error_mark_node)
    1037              :     return t2;
    1038         4453 :   if (t2 == error_mark_node)
    1039              :     return t1;
    1040              : 
    1041         4453 :   gcc_assert (TREE_CODE (t1) == POINTER_TYPE
    1042              :               && TREE_CODE (t2) == POINTER_TYPE);
    1043              : 
    1044              :   /* Merge the attributes.  */
    1045         4453 :   attributes = targetm.merge_type_attributes (t1, t2);
    1046              : 
    1047              :   /* Find the composite type of the target types, and combine the
    1048              :      qualifiers of the two types' targets.  */
    1049         4453 :   tree pointed_to_1 = TREE_TYPE (t1);
    1050         4453 :   tree pointed_to_2 = TREE_TYPE (t2);
    1051         4453 :   tree target = composite_type_cond (TYPE_MAIN_VARIANT (pointed_to_1),
    1052         4453 :                                      TYPE_MAIN_VARIANT (pointed_to_2), cond);
    1053              : 
    1054              :   /* Strip array types to get correct qualifier for pointers to arrays */
    1055         4453 :   quals1 = TYPE_QUALS_NO_ADDR_SPACE (strip_array_types (pointed_to_1));
    1056         4453 :   quals2 = TYPE_QUALS_NO_ADDR_SPACE (strip_array_types (pointed_to_2));
    1057              : 
    1058              :   /* For function types do not merge const qualifiers, but drop them
    1059              :      if used inconsistently.  The middle-end uses these to mark const
    1060              :      and noreturn functions.  */
    1061         4453 :   if (TREE_CODE (pointed_to_1) == FUNCTION_TYPE)
    1062         2129 :     target_quals = (quals1 & quals2);
    1063              :   else
    1064         2324 :     target_quals = (quals1 | quals2);
    1065              : 
    1066              :   /* If the two named address spaces are different, determine the common
    1067              :      superset address space.  This is guaranteed to exist due to the
    1068              :      assumption that comp_target_type returned true.  */
    1069         4453 :   as1 = TYPE_ADDR_SPACE (pointed_to_1);
    1070         4453 :   as2 = TYPE_ADDR_SPACE (pointed_to_2);
    1071         4453 :   if (!addr_space_superset (as1, as2, &as_common))
    1072            0 :     gcc_unreachable ();
    1073              : 
    1074         4453 :   target_quals |= ENCODE_QUAL_ADDR_SPACE (as_common);
    1075              : 
    1076         4453 :   t1 = c_build_pointer_type (c_build_qualified_type (target, target_quals));
    1077         4453 :   return c_build_type_attribute_variant (t1, attributes);
    1078              : }
    1079              : 
    1080              : /* Return the common type for two arithmetic types under the usual
    1081              :    arithmetic conversions.  The default conversions have already been
    1082              :    applied, and enumerated types converted to their compatible integer
    1083              :    types.  The resulting type is unqualified and has no attributes.
    1084              : 
    1085              :    This is the type for the result of most arithmetic operations
    1086              :    if the operands have the given two types.  */
    1087              : 
    1088              : static tree
    1089     13930240 : c_common_type (tree t1, tree t2)
    1090              : {
    1091     13930240 :   enum tree_code code1;
    1092     13930240 :   enum tree_code code2;
    1093              : 
    1094              :   /* If one type is nonsense, use the other.  */
    1095     13930240 :   if (t1 == error_mark_node)
    1096              :     return t2;
    1097     13930240 :   if (t2 == error_mark_node)
    1098              :     return t1;
    1099              : 
    1100     13930240 :   if (TYPE_QUALS (t1) != TYPE_UNQUALIFIED)
    1101        37959 :     t1 = TYPE_MAIN_VARIANT (t1);
    1102              : 
    1103     13930240 :   if (TYPE_QUALS (t2) != TYPE_UNQUALIFIED)
    1104        49381 :     t2 = TYPE_MAIN_VARIANT (t2);
    1105              : 
    1106     13930240 :   if (TYPE_ATTRIBUTES (t1) != NULL_TREE)
    1107              :     {
    1108       187966 :       tree attrs = affects_type_identity_attributes (TYPE_ATTRIBUTES (t1));
    1109       187966 :       t1 = c_build_type_attribute_variant (t1, attrs);
    1110              :     }
    1111              : 
    1112     13930240 :   if (TYPE_ATTRIBUTES (t2) != NULL_TREE)
    1113              :     {
    1114       187444 :       tree attrs = affects_type_identity_attributes (TYPE_ATTRIBUTES (t2));
    1115       187444 :       t2 = c_build_type_attribute_variant (t2, attrs);
    1116              :     }
    1117              : 
    1118              :   /* Save time if the two types are the same.  */
    1119              : 
    1120     13930240 :   if (t1 == t2) return t1;
    1121              : 
    1122      2320869 :   code1 = TREE_CODE (t1);
    1123      2320869 :   code2 = TREE_CODE (t2);
    1124              : 
    1125      2320869 :   gcc_assert (code1 == VECTOR_TYPE || code1 == COMPLEX_TYPE
    1126              :               || code1 == FIXED_POINT_TYPE || code1 == REAL_TYPE
    1127              :               || code1 == INTEGER_TYPE || code1 == BITINT_TYPE);
    1128      2320869 :   gcc_assert (code2 == VECTOR_TYPE || code2 == COMPLEX_TYPE
    1129              :               || code2 == FIXED_POINT_TYPE || code2 == REAL_TYPE
    1130              :               || code2 == INTEGER_TYPE || code2 == BITINT_TYPE);
    1131              : 
    1132              :   /* When one operand is a decimal float type, the other operand cannot be
    1133              :      a generic float type or a complex type.  We also disallow vector types
    1134              :      here.  */
    1135      2320869 :   if ((DECIMAL_FLOAT_TYPE_P (t1) || DECIMAL_FLOAT_TYPE_P (t2))
    1136      2323292 :       && !(DECIMAL_FLOAT_TYPE_P (t1) && DECIMAL_FLOAT_TYPE_P (t2)))
    1137              :     {
    1138         1080 :       if (code1 == VECTOR_TYPE || code2 == VECTOR_TYPE)
    1139              :         {
    1140            3 :           error ("cannot mix operands of decimal floating and vector types");
    1141            3 :           return error_mark_node;
    1142              :         }
    1143         1077 :       if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE)
    1144              :         {
    1145            5 :           error ("cannot mix operands of decimal floating and complex types");
    1146            5 :           return error_mark_node;
    1147              :         }
    1148         1072 :       if (code1 == REAL_TYPE && code2 == REAL_TYPE)
    1149              :         {
    1150           16 :           error ("cannot mix operands of decimal floating "
    1151              :                  "and other floating types");
    1152           16 :           return error_mark_node;
    1153              :         }
    1154              :     }
    1155              : 
    1156              :   /* If one type is a vector type, return that type.  (How the usual
    1157              :      arithmetic conversions apply to the vector types extension is not
    1158              :      precisely specified.)  */
    1159      2320845 :   if (code1 == VECTOR_TYPE)
    1160              :     return t1;
    1161              : 
    1162      2320565 :   if (code2 == VECTOR_TYPE)
    1163              :     return t2;
    1164              : 
    1165              :   /* If one type is complex, form the common type of the non-complex
    1166              :      components, then make that complex.  Use T1 or T2 if it is the
    1167              :      required type.  */
    1168      2320562 :   if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE)
    1169              :     {
    1170        89322 :       tree subtype1 = code1 == COMPLEX_TYPE ? TREE_TYPE (t1) : t1;
    1171        89322 :       tree subtype2 = code2 == COMPLEX_TYPE ? TREE_TYPE (t2) : t2;
    1172        89322 :       tree subtype = c_common_type (subtype1, subtype2);
    1173              : 
    1174        89322 :       if (code1 == COMPLEX_TYPE && TREE_TYPE (t1) == subtype)
    1175              :         return t1;
    1176        59207 :       else if (code2 == COMPLEX_TYPE && TREE_TYPE (t2) == subtype)
    1177              :         return t2;
    1178         3241 :       else if (TREE_CODE (subtype) == BITINT_TYPE)
    1179              :         {
    1180            8 :           sorry ("%<_Complex _BitInt(%d)%> unsupported",
    1181            4 :                  TYPE_PRECISION (subtype));
    1182            6 :           return code1 == COMPLEX_TYPE ? t1 : t2;
    1183              :         }
    1184              :       else
    1185         3237 :         return build_complex_type (subtype);
    1186              :     }
    1187              : 
    1188              :   /* If only one is real, use it as the result.  */
    1189              : 
    1190      2231240 :   if (code1 == REAL_TYPE && code2 != REAL_TYPE)
    1191              :     return t1;
    1192              : 
    1193      2104361 :   if (code2 == REAL_TYPE && code1 != REAL_TYPE)
    1194              :     return t2;
    1195              : 
    1196              :   /* If both are real and either are decimal floating point types, use
    1197              :      the decimal floating point type with the greater precision. */
    1198              : 
    1199      2073989 :   if (code1 == REAL_TYPE && code2 == REAL_TYPE)
    1200              :     {
    1201       107214 :       if (TYPE_MAIN_VARIANT (t1) == dfloat128_type_node
    1202       107214 :           || TYPE_MAIN_VARIANT (t2) == dfloat128_type_node)
    1203              :         return dfloat128_type_node;
    1204              :       /* And prefer _Decimal128 over _Decimal64x which has in GCC's
    1205              :          implementation the same mode.  */
    1206       106665 :       else if (TYPE_MAIN_VARIANT (t1) == dfloat64x_type_node
    1207       106665 :                || TYPE_MAIN_VARIANT (t2) == dfloat64x_type_node)
    1208              :         return dfloat64x_type_node;
    1209       106661 :       else if (TYPE_MAIN_VARIANT (t1) == dfloat64_type_node
    1210       106661 :                || TYPE_MAIN_VARIANT (t2) == dfloat64_type_node)
    1211              :         return dfloat64_type_node;
    1212       106216 :       else if (TYPE_MAIN_VARIANT (t1) == dfloat32_type_node
    1213       106216 :                || TYPE_MAIN_VARIANT (t2) == dfloat32_type_node)
    1214              :         return dfloat32_type_node;
    1215              :     }
    1216              : 
    1217              :   /* Deal with fixed-point types.  */
    1218      2072646 :   if (code1 == FIXED_POINT_TYPE || code2 == FIXED_POINT_TYPE)
    1219              :     {
    1220            0 :       unsigned int unsignedp = 0, satp = 0;
    1221            0 :       scalar_mode m1, m2;
    1222            0 :       unsigned int fbit1, ibit1, fbit2, ibit2, max_fbit, max_ibit;
    1223              : 
    1224            0 :       m1 = SCALAR_TYPE_MODE (t1);
    1225            0 :       m2 = SCALAR_TYPE_MODE (t2);
    1226              : 
    1227              :       /* If one input type is saturating, the result type is saturating.  */
    1228            0 :       if (TYPE_SATURATING (t1) || TYPE_SATURATING (t2))
    1229              :         satp = 1;
    1230              : 
    1231              :       /* If both fixed-point types are unsigned, the result type is unsigned.
    1232              :          When mixing fixed-point and integer types, follow the sign of the
    1233              :          fixed-point type.
    1234              :          Otherwise, the result type is signed.  */
    1235            0 :       if ((TYPE_UNSIGNED (t1) && TYPE_UNSIGNED (t2)
    1236            0 :            && code1 == FIXED_POINT_TYPE && code2 == FIXED_POINT_TYPE)
    1237            0 :           || (code1 == FIXED_POINT_TYPE && code2 != FIXED_POINT_TYPE
    1238            0 :               && TYPE_UNSIGNED (t1))
    1239            0 :           || (code1 != FIXED_POINT_TYPE && code2 == FIXED_POINT_TYPE
    1240            0 :               && TYPE_UNSIGNED (t2)))
    1241              :         unsignedp = 1;
    1242              : 
    1243              :       /* The result type is signed.  */
    1244            0 :       if (unsignedp == 0)
    1245              :         {
    1246              :           /* If the input type is unsigned, we need to convert to the
    1247              :              signed type.  */
    1248            0 :           if (code1 == FIXED_POINT_TYPE && TYPE_UNSIGNED (t1))
    1249              :             {
    1250            0 :               enum mode_class mclass = (enum mode_class) 0;
    1251            0 :               if (GET_MODE_CLASS (m1) == MODE_UFRACT)
    1252              :                 mclass = MODE_FRACT;
    1253            0 :               else if (GET_MODE_CLASS (m1) == MODE_UACCUM)
    1254              :                 mclass = MODE_ACCUM;
    1255              :               else
    1256            0 :                 gcc_unreachable ();
    1257            0 :               m1 = as_a <scalar_mode>
    1258            0 :                 (mode_for_size (GET_MODE_PRECISION (m1), mclass, 0));
    1259              :             }
    1260            0 :           if (code2 == FIXED_POINT_TYPE && TYPE_UNSIGNED (t2))
    1261              :             {
    1262            0 :               enum mode_class mclass = (enum mode_class) 0;
    1263            0 :               if (GET_MODE_CLASS (m2) == MODE_UFRACT)
    1264              :                 mclass = MODE_FRACT;
    1265            0 :               else if (GET_MODE_CLASS (m2) == MODE_UACCUM)
    1266              :                 mclass = MODE_ACCUM;
    1267              :               else
    1268            0 :                 gcc_unreachable ();
    1269            0 :               m2 = as_a <scalar_mode>
    1270            0 :                 (mode_for_size (GET_MODE_PRECISION (m2), mclass, 0));
    1271              :             }
    1272              :         }
    1273              : 
    1274            0 :       if (code1 == FIXED_POINT_TYPE)
    1275              :         {
    1276            0 :           fbit1 = GET_MODE_FBIT (m1);
    1277            0 :           ibit1 = GET_MODE_IBIT (m1);
    1278              :         }
    1279              :       else
    1280              :         {
    1281            0 :           fbit1 = 0;
    1282              :           /* Signed integers need to subtract one sign bit.  */
    1283            0 :           ibit1 = TYPE_PRECISION (t1) - (!TYPE_UNSIGNED (t1));
    1284              :         }
    1285              : 
    1286            0 :       if (code2 == FIXED_POINT_TYPE)
    1287              :         {
    1288            0 :           fbit2 = GET_MODE_FBIT (m2);
    1289            0 :           ibit2 = GET_MODE_IBIT (m2);
    1290              :         }
    1291              :       else
    1292              :         {
    1293            0 :           fbit2 = 0;
    1294              :           /* Signed integers need to subtract one sign bit.  */
    1295            0 :           ibit2 = TYPE_PRECISION (t2) - (!TYPE_UNSIGNED (t2));
    1296              :         }
    1297              : 
    1298            0 :       max_ibit = ibit1 >= ibit2 ?  ibit1 : ibit2;
    1299            0 :       max_fbit = fbit1 >= fbit2 ?  fbit1 : fbit2;
    1300            0 :       return c_common_fixed_point_type_for_size (max_ibit, max_fbit, unsignedp,
    1301              :                                                  satp);
    1302              :     }
    1303              : 
    1304              :   /* Both real or both integers; use the one with greater precision.  */
    1305              : 
    1306      2072646 :   if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2))
    1307              :     return t1;
    1308      1101680 :   else if (TYPE_PRECISION (t2) > TYPE_PRECISION (t1))
    1309              :     return t2;
    1310              : 
    1311              :   /* Same precision.  Prefer long longs to longs to ints when the
    1312              :      same precision, following the C99 rules on integer type rank
    1313              :      (which are equivalent to the C90 rules for C90 types).  */
    1314              : 
    1315       737652 :   if (TYPE_MAIN_VARIANT (t1) == long_long_unsigned_type_node
    1316       737652 :       || TYPE_MAIN_VARIANT (t2) == long_long_unsigned_type_node)
    1317              :     return long_long_unsigned_type_node;
    1318              : 
    1319       648411 :   if (TYPE_MAIN_VARIANT (t1) == long_long_integer_type_node
    1320       648411 :       || TYPE_MAIN_VARIANT (t2) == long_long_integer_type_node)
    1321              :     {
    1322        15315 :       if (TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
    1323          361 :         return long_long_unsigned_type_node;
    1324              :       else
    1325              :         return long_long_integer_type_node;
    1326              :     }
    1327              : 
    1328       633096 :   if (TYPE_MAIN_VARIANT (t1) == long_unsigned_type_node
    1329       633096 :       || TYPE_MAIN_VARIANT (t2) == long_unsigned_type_node)
    1330              :     return long_unsigned_type_node;
    1331              : 
    1332       533991 :   if (TYPE_MAIN_VARIANT (t1) == long_integer_type_node
    1333       533991 :       || TYPE_MAIN_VARIANT (t2) == long_integer_type_node)
    1334              :     {
    1335              :       /* But preserve unsignedness from the other type,
    1336              :          since long cannot hold all the values of an unsigned int.  */
    1337        26403 :       if (TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
    1338          131 :         return long_unsigned_type_node;
    1339              :       else
    1340              :         return long_integer_type_node;
    1341              :     }
    1342              : 
    1343              :   /* For floating types of the same TYPE_PRECISION (which we here
    1344              :      assume means either the same set of values, or sets of values
    1345              :      neither a subset of the other, with behavior being undefined in
    1346              :      the latter case), follow the rules from TS 18661-3: prefer
    1347              :      interchange types _FloatN, then standard types long double,
    1348              :      double, float, then extended types _FloatNx.  For extended types,
    1349              :      check them starting with _Float128x as that seems most consistent
    1350              :      in spirit with preferring long double to double; for interchange
    1351              :      types, also check in that order for consistency although it's not
    1352              :      possible for more than one of them to have the same
    1353              :      precision.  */
    1354       507588 :   tree mv1 = TYPE_MAIN_VARIANT (t1);
    1355       507588 :   tree mv2 = TYPE_MAIN_VARIANT (t2);
    1356              : 
    1357      2537374 :   for (int i = NUM_FLOATN_TYPES - 1; i >= 0; i--)
    1358      2029949 :     if (mv1 == FLOATN_TYPE_NODE (i) || mv2 == FLOATN_TYPE_NODE (i))
    1359              :       return FLOATN_TYPE_NODE (i);
    1360              : 
    1361              :   /* Likewise, prefer long double to double even if same size.  */
    1362       507425 :   if (mv1 == long_double_type_node || mv2 == long_double_type_node)
    1363              :     return long_double_type_node;
    1364              : 
    1365              :   /* Likewise, prefer double to float even if same size.
    1366              :      We got a couple of embedded targets with 32 bit doubles, and the
    1367              :      pdp11 might have 64 bit floats.  */
    1368       507183 :   if (mv1 == double_type_node || mv2 == double_type_node)
    1369              :     return double_type_node;
    1370              : 
    1371       506611 :   if (mv1 == float_type_node || mv2 == float_type_node)
    1372              :     return float_type_node;
    1373              : 
    1374      2017768 :   for (int i = NUM_FLOATNX_TYPES - 1; i >= 0; i--)
    1375      1513326 :     if (mv1 == FLOATNX_TYPE_NODE (i) || mv2 == FLOATNX_TYPE_NODE (i))
    1376              :       return FLOATNX_TYPE_NODE (i);
    1377              : 
    1378       504442 :   if ((code1 == BITINT_TYPE || code2 == BITINT_TYPE) && code1 != code2)
    1379              :     {
    1380              :       /* Prefer any other integral types over bit-precise integer types.  */
    1381           10 :       if (TYPE_UNSIGNED (t1) == TYPE_UNSIGNED (t2))
    1382            6 :         return code1 == BITINT_TYPE ? t2 : t1;
    1383              :       /* If BITINT_TYPE is unsigned and the other type is signed
    1384              :          non-BITINT_TYPE with the same precision, the latter has higher rank.
    1385              :          In that case:
    1386              :          Otherwise, both operands are converted to the unsigned integer type
    1387              :          corresponding to the type of the operand with signed integer type.  */
    1388            8 :       if (TYPE_UNSIGNED (code1 == BITINT_TYPE ? t1 : t2))
    1389            5 :         return c_common_unsigned_type (code1 == BITINT_TYPE ? t2 : t1);
    1390              :     }
    1391              : 
    1392              :   /* Otherwise prefer the unsigned one.  */
    1393              : 
    1394       504434 :   if (TYPE_UNSIGNED (t1))
    1395              :     return t1;
    1396              :   else
    1397              :     return t2;
    1398              : }
    1399              : 
    1400              : /* Wrapper around c_common_type that is used by c-common.cc and other
    1401              :    front end optimizations that remove promotions.  ENUMERAL_TYPEs
    1402              :    are allowed here and are converted to their compatible integer types.
    1403              :    BOOLEAN_TYPEs are allowed here and return either boolean_type_node or
    1404              :    preferably a non-Boolean type as the common type.  */
    1405              : tree
    1406       102837 : common_type (tree t1, tree t2)
    1407              : {
    1408       102837 :   if (TREE_CODE (t1) == ENUMERAL_TYPE)
    1409            0 :     t1 = ENUM_UNDERLYING_TYPE (t1);
    1410       102837 :   if (TREE_CODE (t2) == ENUMERAL_TYPE)
    1411            1 :     t2 = ENUM_UNDERLYING_TYPE (t2);
    1412              : 
    1413              :   /* If both types are BOOLEAN_TYPE, then return boolean_type_node.  */
    1414       102837 :   if (TREE_CODE (t1) == BOOLEAN_TYPE
    1415          584 :       && TREE_CODE (t2) == BOOLEAN_TYPE)
    1416          584 :     return boolean_type_node;
    1417              : 
    1418              :   /* If either type is BOOLEAN_TYPE, then return the other.  */
    1419       102253 :   if (TREE_CODE (t1) == BOOLEAN_TYPE)
    1420              :     return t2;
    1421       102253 :   if (TREE_CODE (t2) == BOOLEAN_TYPE)
    1422              :     return t1;
    1423              : 
    1424       102253 :   return c_common_type (t1, t2);
    1425              : }
    1426              : 
    1427              : 
    1428              : 
    1429              : /* Helper function for comptypes.  For two compatible types, return 1
    1430              :    if they pass consistency checks.  In particular we test that
    1431              :    TYPE_CANONICAL is set correctly, i.e. the two types can alias.  */
    1432              : 
    1433              : static bool
    1434     44340854 : comptypes_verify (tree type1, tree type2)
    1435              : {
    1436     44340854 :   if (type1 == type2 || !type1 || !type2
    1437      3488887 :       || TREE_CODE (type1) == ERROR_MARK || TREE_CODE (type2) == ERROR_MARK)
    1438              :     return true;
    1439              : 
    1440      3488886 :   gcc_checking_assert (c_verify_type (type1));
    1441      3488886 :   gcc_checking_assert (c_verify_type (type2));
    1442              : 
    1443      3488886 :   if (TYPE_CANONICAL (type1) != TYPE_CANONICAL (type2)
    1444       385520 :       && !TYPE_STRUCTURAL_EQUALITY_P (type1)
    1445      3872654 :       && !TYPE_STRUCTURAL_EQUALITY_P (type2))
    1446              :     {
    1447              :       /* FIXME: check other types. */
    1448       383434 :       if (RECORD_OR_UNION_TYPE_P (type1)
    1449       383434 :           || TREE_CODE (type1) == ENUMERAL_TYPE
    1450       383434 :           || TREE_CODE (type2) == ENUMERAL_TYPE)
    1451            0 :         return false;
    1452              :     }
    1453              :   return true;
    1454              : }
    1455              : 
    1456              : struct comptypes_data {
    1457              : 
    1458              :   /* output */
    1459              :   bool enum_and_int_p;
    1460              :   bool different_types_p;
    1461              :   bool warning_needed;
    1462              : 
    1463              :   /* context */
    1464              :   bool anon_field;
    1465              :   bool pointedto;
    1466              : 
    1467              :   /* configuration */
    1468              :   bool equiv;
    1469              :   bool ignore_promoting_args;
    1470              : 
    1471              :   const struct tagged_tu_seen_cache* cache;
    1472              : };
    1473              : 
    1474              : 
    1475              : /* Helper function for composite_type.  This function ignores when the
    1476              :    function type of an old-style declaration is incompatible with a type
    1477              :    of a declaration with prototype because some are arguments are not
    1478              :    self-promoting.  This is ignored only for function types but not
    1479              :    ignored in a nested context.  */
    1480              : 
    1481              : static bool
    1482     18948636 : comptypes_check_for_composite (tree t1, tree t2)
    1483              : {
    1484     18948636 :   struct comptypes_data data = { };
    1485     18948636 :   data.ignore_promoting_args = FUNCTION_TYPE == TREE_CODE (t1);
    1486     18948636 :   return comptypes_internal (t1, t2, &data);
    1487              : }
    1488              : 
    1489              : 
    1490              : /* C implementation of compatible_types_for_indirection_note_p.  */
    1491              : 
    1492              : bool
    1493          762 : compatible_types_for_indirection_note_p (tree type1, tree type2)
    1494              : {
    1495          762 :   return comptypes (type1, type2) == 1;
    1496              : }
    1497              : 
    1498              : /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
    1499              :    or various other operations.  Return 2 if they are compatible
    1500              :    but a warning may be needed if you use them together.  */
    1501              : 
    1502              : int
    1503     56286018 : comptypes (tree type1, tree type2)
    1504              : {
    1505     56286018 :   struct comptypes_data data = { };
    1506     56286018 :   bool ret = comptypes_internal (type1, type2, &data);
    1507              : 
    1508     56286018 :   gcc_checking_assert (!ret || comptypes_verify (type1, type2));
    1509              : 
    1510     37800651 :   return ret ? (data.warning_needed ? 2 : 1) : 0;
    1511              : }
    1512              : 
    1513              : 
    1514              : /* Like comptypes, but it returns non-zero only for identical
    1515              :    types.  */
    1516              : 
    1517              : bool
    1518          320 : comptypes_same_p (tree type1, tree type2)
    1519              : {
    1520          320 :   struct comptypes_data data = { };
    1521          320 :   bool ret = comptypes_internal (type1, type2, &data);
    1522              : 
    1523          320 :   gcc_checking_assert (!ret || comptypes_verify (type1, type2));
    1524              : 
    1525          320 :   if (data.different_types_p)
    1526          103 :     return false;
    1527              : 
    1528              :   return ret;
    1529              : }
    1530              : 
    1531              : 
    1532              : /* Like comptypes, but if it returns non-zero because enum and int are
    1533              :    compatible, it sets *ENUM_AND_INT_P to true.  */
    1534              : 
    1535              : int
    1536      6739587 : comptypes_check_enum_int (tree type1, tree type2, bool *enum_and_int_p)
    1537              : {
    1538      6739587 :   struct comptypes_data data = { };
    1539      6739587 :   bool ret = comptypes_internal (type1, type2, &data);
    1540      6739587 :   *enum_and_int_p = data.enum_and_int_p;
    1541              : 
    1542      6739587 :   gcc_checking_assert (!ret || comptypes_verify (type1, type2));
    1543              : 
    1544      6494155 :   return ret ? (data.warning_needed ? 2 : 1) : 0;
    1545              : }
    1546              : 
    1547              : /* Like comptypes, but if it returns nonzero for different types, it
    1548              :    sets *DIFFERENT_TYPES_P to true.  */
    1549              : 
    1550              : int
    1551        45768 : comptypes_check_different_types (tree type1, tree type2,
    1552              :                                  bool *different_types_p)
    1553              : {
    1554        45768 :   struct comptypes_data data = { };
    1555        45768 :   bool ret = comptypes_internal (type1, type2, &data);
    1556        45768 :   *different_types_p = data.different_types_p;
    1557              : 
    1558        45768 :   gcc_checking_assert (!ret || comptypes_verify (type1, type2));
    1559              : 
    1560        45768 :   return ret ? (data.warning_needed ? 2 : 1) : 0;
    1561              : }
    1562              : 
    1563              : 
    1564              : /* Like comptypes, but if it returns true for struct and union types
    1565              :    considered equivalent for aliasing purposes, i.e. for setting
    1566              :    TYPE_CANONICAL after completing a struct or union.
    1567              : 
    1568              :    This function must return false only for types which are not
    1569              :    compatible according to C language semantics (cf. comptypes),
    1570              :    otherwise the middle-end would make incorrect aliasing decisions.
    1571              :    It may return true for some similar types that are not compatible
    1572              :    according to those stricter rules.
    1573              : 
    1574              :    In particular, we ignore size expression in arrays so that the
    1575              :    following structs are in the same equivalence class:
    1576              : 
    1577              :    struct foo { char (*buf)[]; };
    1578              :    struct foo { char (*buf)[3]; };
    1579              :    struct foo { char (*buf)[4]; };
    1580              : 
    1581              :    We also treat unions / structs with members which are pointers to
    1582              :    structures or unions with the same tag as equivalent (if they are not
    1583              :    incompatible for other reasons).  Although incomplete structure
    1584              :    or union types are not compatible to any other type, they may become
    1585              :    compatible to different types when completed.  To avoid having to update
    1586              :    TYPE_CANONICAL at this point, we only consider the tag when forming
    1587              :    the equivalence classes.  For example, the following types with tag
    1588              :    'foo' are all considered equivalent:
    1589              : 
    1590              :    struct bar;
    1591              :    struct foo { struct bar *x };
    1592              :    struct foo { struct bar { int a; } *x };
    1593              :    struct foo { struct bar { char b; } *x };  */
    1594              : 
    1595              : bool
    1596     14626375 : comptypes_equiv_p (tree type1, tree type2)
    1597              : {
    1598     14626375 :   struct comptypes_data data = { };
    1599     14626375 :   data.equiv = true;
    1600     14626375 :   bool ret = comptypes_internal (type1, type2, &data);
    1601              : 
    1602              :   /* check that different equivance classes are assigned only
    1603              :      to types that are not compatible.  */
    1604     14626375 :   gcc_checking_assert (ret || !comptypes (type1, type2));
    1605              : 
    1606     14626375 :   return ret;
    1607              : }
    1608              : 
    1609              : 
    1610              : /* Return true if TYPE1 and TYPE2 are compatible types for assignment
    1611              :    or various other operations.  If they are compatible but a warning may
    1612              :    be needed if you use them together, 'warning_needed' in DATA is set.
    1613              :    If one type is an enum and the other a compatible integer type, then
    1614              :    this sets 'enum_and_int_p' in DATA to true (it is never set to
    1615              :    false).  If the types are compatible but different enough not to be
    1616              :    permitted in C11 typedef redeclarations, then this sets
    1617              :    'different_types_p' in DATA to true; it is never set to
    1618              :    false, but may or may not be set if the types are incompatible.
    1619              :    If two functions types are not compatible only because one is
    1620              :    an old-style definition that does not have self-promoting arguments,
    1621              :    then this can be ignored by setting 'ignore_promoting_args_p'.
    1622              :    For 'equiv' we can compute equivalency classes (see above).
    1623              :    This differs from comptypes, in that we don't free the seen
    1624              :    types.  */
    1625              : 
    1626              : static bool
    1627    132512585 : comptypes_internal (const_tree type1, const_tree type2,
    1628              :                     struct comptypes_data *data)
    1629              : {
    1630    132794714 :   const_tree t1 = type1;
    1631    132794714 :   const_tree t2 = type2;
    1632              : 
    1633              :   /* Suppress errors caused by previously reported errors.  */
    1634              : 
    1635    132794714 :   if (t1 == t2 || !t1 || !t2
    1636     45020504 :       || TREE_CODE (t1) == ERROR_MARK || TREE_CODE (t2) == ERROR_MARK)
    1637              :     return true;
    1638              : 
    1639              :   /* Qualifiers must match. C99 6.7.3p9 */
    1640              : 
    1641     45020501 :   if (TYPE_QUALS (t1) != TYPE_QUALS (t2))
    1642              :     return false;
    1643              : 
    1644              :   /* Enumerated types are compatible with integer types, but this is
    1645              :      not transitive: two enumerated types in the same translation unit
    1646              :      are compatible with each other only if they are the same type.  */
    1647              : 
    1648     44980441 :   if (TREE_CODE (t1) == ENUMERAL_TYPE
    1649         1014 :       && COMPLETE_TYPE_P (t1)
    1650     44981411 :       && TREE_CODE (t2) != ENUMERAL_TYPE)
    1651              :     {
    1652          858 :       t1 = ENUM_UNDERLYING_TYPE (t1);
    1653          858 :       if (TREE_CODE (t2) != VOID_TYPE)
    1654              :         {
    1655          854 :           data->enum_and_int_p = true;
    1656          854 :           data->different_types_p = true;
    1657              :         }
    1658              :     }
    1659     44979583 :   else if (TREE_CODE (t2) == ENUMERAL_TYPE
    1660         4705 :            && COMPLETE_TYPE_P (t2)
    1661     44984282 :            && TREE_CODE (t1) != ENUMERAL_TYPE)
    1662              :     {
    1663         4587 :       t2 = ENUM_UNDERLYING_TYPE (t2);
    1664         4587 :       if (TREE_CODE (t1) != VOID_TYPE)
    1665              :         {
    1666         3688 :           data->enum_and_int_p = true;
    1667         3688 :           data->different_types_p = true;
    1668              :         }
    1669              :     }
    1670              : 
    1671     44980441 :   if (t1 == t2)
    1672              :     return true;
    1673              : 
    1674              :   /* Different classes of types can't be compatible.  */
    1675              : 
    1676     44979069 :   if (TREE_CODE (t1) != TREE_CODE (t2))
    1677              :     return false;
    1678              : 
    1679              :   /* Allow for two different type nodes which have essentially the same
    1680              :      definition.  Note that we already checked for equality of the type
    1681              :      qualifiers (just above).  */
    1682              : 
    1683     36964980 :   if (TREE_CODE (t1) != ARRAY_TYPE
    1684     36964980 :       && TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
    1685              :     return true;
    1686              : 
    1687     36630274 :   int attrval;
    1688              : 
    1689              :   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
    1690     36630274 :   if (!(attrval = comp_type_attributes (t1, t2)))
    1691              :     return false;
    1692              : 
    1693     36629881 :   if (2 == attrval)
    1694          336 :     data->warning_needed = true;
    1695              : 
    1696     36629881 :   switch (TREE_CODE (t1))
    1697              :     {
    1698      3351948 :     case INTEGER_TYPE:
    1699      3351948 :     case FIXED_POINT_TYPE:
    1700      3351948 :     case REAL_TYPE:
    1701      3351948 :     case BITINT_TYPE:
    1702              :       /* With these nodes, we can't determine type equivalence by
    1703              :          looking at what is stored in the nodes themselves, because
    1704              :          two nodes might have different TYPE_MAIN_VARIANTs but still
    1705              :          represent the same type.  For example, wchar_t and int could
    1706              :          have the same properties (TYPE_PRECISION, TYPE_MIN_VALUE,
    1707              :          TYPE_MAX_VALUE, etc.), but have different TYPE_MAIN_VARIANTs
    1708              :          and are distinct types.  On the other hand, int and the
    1709              :          following typedef
    1710              : 
    1711              :            typedef int INT __attribute((may_alias));
    1712              : 
    1713              :          have identical properties, different TYPE_MAIN_VARIANTs, but
    1714              :          represent the same type.  The canonical type system keeps
    1715              :          track of equivalence in this case, so we fall back on it.  */
    1716      3351948 :       return TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2);
    1717              : 
    1718       282129 :     case POINTER_TYPE:
    1719              :       /* Do not remove mode information.  */
    1720       282129 :       if (TYPE_MODE (t1) != TYPE_MODE (t2))
    1721              :         return false;
    1722       282129 :       data->pointedto = true;
    1723       282129 :       return comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2), data);
    1724              : 
    1725      8885871 :     case FUNCTION_TYPE:
    1726      8885871 :       return function_types_compatible_p (t1, t2, data);
    1727              : 
    1728       153610 :     case ARRAY_TYPE:
    1729       153610 :       {
    1730       153610 :         tree d1 = TYPE_DOMAIN (t1);
    1731       153610 :         tree d2 = TYPE_DOMAIN (t2);
    1732       153610 :         bool d1_variable, d2_variable;
    1733       153610 :         bool d1_zero, d2_zero;
    1734              : 
    1735              :         /* Target types must match incl. qualifiers.  */
    1736       153610 :         if (!comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2), data))
    1737              :           return false;
    1738              : 
    1739       118621 :         if ((d1 == NULL_TREE) != (d2 == NULL_TREE))
    1740         6287 :           data->different_types_p = true;
    1741              :         /* Ignore size mismatches when forming equivalence classes.  */
    1742       118621 :         if (data->equiv)
    1743              :           return true;
    1744              :         /* Sizes must match unless one is missing or variable.  */
    1745        49803 :         if (d1 == NULL_TREE || d2 == NULL_TREE || d1 == d2)
    1746              :           return true;
    1747              : 
    1748        33592 :         d1_zero = !TYPE_MAX_VALUE (d1);
    1749        33592 :         d2_zero = !TYPE_MAX_VALUE (d2);
    1750              : 
    1751        67184 :         d1_variable = (!d1_zero
    1752        33592 :                        && (TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST
    1753        33586 :                            || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST));
    1754        67184 :         d2_variable = (!d2_zero
    1755        33592 :                        && (TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
    1756        33496 :                            || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST));
    1757              : 
    1758        33592 :         if (d1_variable != d2_variable)
    1759          769 :           data->different_types_p = true;
    1760        33592 :         if (d1_variable || d2_variable)
    1761              :           return true;
    1762         4047 :         if (d1_zero && d2_zero)
    1763              :           return true;
    1764         4047 :         if (d1_zero || d2_zero
    1765         3951 :             || !tree_int_cst_equal (TYPE_MIN_VALUE (d1), TYPE_MIN_VALUE (d2))
    1766         7998 :             || !tree_int_cst_equal (TYPE_MAX_VALUE (d1), TYPE_MAX_VALUE (d2)))
    1767         4047 :           return false;
    1768              : 
    1769              :         return true;
    1770              :       }
    1771              : 
    1772     23419146 :     case ENUMERAL_TYPE:
    1773     23419146 :     case RECORD_TYPE:
    1774     23419146 :     case UNION_TYPE:
    1775              : 
    1776     23419146 :       if (!flag_isoc23)
    1777              :         return false;
    1778              : 
    1779     23419099 :       return tagged_types_tu_compatible_p (t1, t2, data);
    1780              : 
    1781       536372 :     case VECTOR_TYPE:
    1782      1072744 :       return known_eq (TYPE_VECTOR_SUBPARTS (t1), TYPE_VECTOR_SUBPARTS (t2))
    1783       536372 :              && comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2), data);
    1784              : 
    1785              :     default:
    1786              :       return false;
    1787              :     }
    1788              :   gcc_unreachable ();
    1789              : }
    1790              : 
    1791              : /* Return true if TTL and TTR are pointers to types that are equivalent, ignoring
    1792              :    their qualifiers, except for named address spaces.  If the pointers point to
    1793              :    different named addresses, then we must determine if one address space is a
    1794              :    subset of the other.  */
    1795              : 
    1796              : static bool
    1797      1761862 : comp_target_types (location_t location, tree ttl, tree ttr)
    1798              : {
    1799      1761862 :   int val;
    1800      1761862 :   int val_ped;
    1801      1761862 :   tree mvl = TREE_TYPE (ttl);
    1802      1761862 :   tree mvr = TREE_TYPE (ttr);
    1803      1761862 :   addr_space_t asl = TYPE_ADDR_SPACE (mvl);
    1804      1761862 :   addr_space_t asr = TYPE_ADDR_SPACE (mvr);
    1805      1761862 :   addr_space_t as_common;
    1806      1761862 :   bool enum_and_int_p;
    1807              : 
    1808              :   /* Fail if pointers point to incompatible address spaces.  */
    1809      1761862 :   if (!addr_space_superset (asl, asr, &as_common))
    1810              :     return 0;
    1811              : 
    1812              :   /* For pedantic record result of comptypes on arrays before losing
    1813              :      qualifiers on the element type below. */
    1814      1761862 :   val_ped = 1;
    1815              : 
    1816      1761862 :   if (TREE_CODE (mvl) == ARRAY_TYPE
    1817         1991 :       && TREE_CODE (mvr) == ARRAY_TYPE)
    1818         1963 :     val_ped = comptypes (mvl, mvr);
    1819              : 
    1820              :   /* Qualifiers on element types of array types that are
    1821              :      pointer targets are also removed.  */
    1822      1761862 :   mvl = remove_qualifiers (mvl);
    1823      1761862 :   mvr = remove_qualifiers (mvr);
    1824              : 
    1825      1761862 :   enum_and_int_p = false;
    1826      1761862 :   val = comptypes_check_enum_int (mvl, mvr, &enum_and_int_p);
    1827              : 
    1828      1761862 :   if (val == 1 && val_ped != 1)
    1829          190 :     pedwarn_c11 (location, OPT_Wpedantic, "invalid use of pointers to arrays with different qualifiers "
    1830              :                                           "in ISO C before C23");
    1831              : 
    1832      1761862 :   if (val == 2)
    1833          126 :     pedwarn (location, OPT_Wpedantic, "types are not quite compatible");
    1834              : 
    1835      1761862 :   if (val == 1 && enum_and_int_p && warn_cxx_compat)
    1836            2 :     warning_at (location, OPT_Wc___compat,
    1837              :                 "pointer target types incompatible in C++");
    1838              : 
    1839      1761862 :   return val;
    1840              : }
    1841              : 
    1842              : /* Subroutines of `comptypes'.  */
    1843              : 
    1844              : /* Return true if two 'struct', 'union', or 'enum' types T1 and T2 are
    1845              :    compatible.  The two types are not the same (which has been
    1846              :    checked earlier in comptypes_internal).  */
    1847              : 
    1848              : static bool
    1849     23419099 : tagged_types_tu_compatible_p (const_tree t1, const_tree t2,
    1850              :                               struct comptypes_data *data)
    1851              : {
    1852     23419099 :   tree s1, s2;
    1853              : 
    1854     23419099 :   if (c_type_tag (t1) != c_type_tag (t2))
    1855              :     return false;
    1856              : 
    1857              :   /* When forming equivalence classes for TYPE_CANONICAL in C23, we treat
    1858              :      structs with the same tag as equivalent, but only when they are targets
    1859              :      of pointers inside other structs.  */
    1860     19376030 :   if (data->equiv && data->pointedto)
    1861              :     return true;
    1862              : 
    1863              :   /* Different types without tag are incompatible except as an anonymous
    1864              :      field or when forming equivalence classes for TYPE_CANONICAL.  */
    1865     19375996 :   if (!data->anon_field && !data->equiv && NULL_TREE == c_type_tag (t1))
    1866              :     return false;
    1867              : 
    1868     14249306 :   if (!data->anon_field && TYPE_STUB_DECL (t1) != TYPE_STUB_DECL (t2))
    1869     14248304 :     data->different_types_p = true;
    1870              : 
    1871              :   /* Incomplete types are incompatible inside a TU.  */
    1872     14249306 :   if (TYPE_SIZE (t1) == NULL || TYPE_SIZE (t2) == NULL)
    1873              :     return false;
    1874              : 
    1875     14249296 :   if (ENUMERAL_TYPE != TREE_CODE (t1)
    1876     14249296 :       && (TYPE_REVERSE_STORAGE_ORDER (t1)
    1877     14249241 :           != TYPE_REVERSE_STORAGE_ORDER (t2)))
    1878              :     return false;
    1879              : 
    1880     14249286 :   if (TYPE_USER_ALIGN (t1) != TYPE_USER_ALIGN (t2))
    1881       144499 :     data->different_types_p = true;
    1882              : 
    1883              :   /* For types already being looked at in some active
    1884              :      invocation of this function, assume compatibility.
    1885              :      The cache is built as a linked list on the stack
    1886              :      with the head of the list passed downwards.  */
    1887     14249286 :   for (const struct tagged_tu_seen_cache *t = data->cache;
    1888     14258158 :        t != NULL; t = t->next)
    1889         8983 :     if (t->t1 == t1 && t->t2 == t2)
    1890              :       return true;
    1891              : 
    1892     14249175 :   const struct tagged_tu_seen_cache entry = { data->cache, t1, t2 };
    1893              : 
    1894     14249175 :   switch (TREE_CODE (t1))
    1895              :     {
    1896           55 :     case ENUMERAL_TYPE:
    1897           55 :       {
    1898           55 :         if (!comptypes (ENUM_UNDERLYING_TYPE (t1), ENUM_UNDERLYING_TYPE (t2)))
    1899              :           return false;
    1900              : 
    1901              :         /* Speed up the case where the type values are in the same order.  */
    1902           51 :         tree tv1 = TYPE_VALUES (t1);
    1903           51 :         tree tv2 = TYPE_VALUES (t2);
    1904              : 
    1905           51 :         if (tv1 == tv2)
    1906              :           return true;
    1907              : 
    1908           97 :         for (;tv1 && tv2; tv1 = TREE_CHAIN (tv1), tv2 = TREE_CHAIN (tv2))
    1909              :           {
    1910           58 :             if (TREE_PURPOSE (tv1) != TREE_PURPOSE (tv2))
    1911              :               break;
    1912              : 
    1913           51 :             if (simple_cst_equal (DECL_INITIAL (TREE_VALUE (tv1)),
    1914           51 :                                   DECL_INITIAL (TREE_VALUE (tv2))) != 1)
    1915              :               break;
    1916              :           }
    1917              : 
    1918           51 :         if (tv1 == NULL_TREE && tv2 == NULL_TREE)
    1919              :           return true;
    1920              : 
    1921           12 :         if (tv1 == NULL_TREE || tv2 == NULL_TREE)
    1922              :           return false;
    1923              : 
    1924           12 :         if (list_length (TYPE_VALUES (t1)) != list_length (TYPE_VALUES (t2)))
    1925              :           return false;
    1926              : 
    1927           20 :         for (s1 = TYPE_VALUES (t1); s1; s1 = TREE_CHAIN (s1))
    1928              :           {
    1929           16 :             s2 = purpose_member (TREE_PURPOSE (s1), TYPE_VALUES (t2));
    1930              : 
    1931           16 :             if (s2 == NULL
    1932           29 :                 || simple_cst_equal (DECL_INITIAL (TREE_VALUE (s1)),
    1933           13 :                                      DECL_INITIAL (TREE_VALUE (s2))) != 1)
    1934            8 :               return false;
    1935              :           }
    1936              : 
    1937              :         return true;
    1938              :       }
    1939              : 
    1940     14249120 :     case UNION_TYPE:
    1941     14249120 :     case RECORD_TYPE:
    1942              : 
    1943     14249120 :         if (list_length (TYPE_FIELDS (t1)) != list_length (TYPE_FIELDS (t2)))
    1944              :           return false;
    1945              : 
    1946     12319245 :         for (s1 = TYPE_FIELDS (t1), s2 = TYPE_FIELDS (t2);
    1947     13841381 :              s1 && s2;
    1948      1522136 :              s1 = DECL_CHAIN (s1), s2 = DECL_CHAIN (s2))
    1949              :           {
    1950     13776727 :             gcc_assert (TREE_CODE (s1) == FIELD_DECL);
    1951     13776727 :             gcc_assert (TREE_CODE (s2) == FIELD_DECL);
    1952              : 
    1953     13776727 :             tree ft1 = TREE_TYPE (s1);
    1954     13776727 :             tree ft2 = TREE_TYPE (s2);
    1955              : 
    1956     13776727 :             if (DECL_NAME (s1) != DECL_NAME (s2))
    1957              :               return false;
    1958              : 
    1959     12132660 :             if (DECL_ALIGN (s1) != DECL_ALIGN (s2))
    1960              :               return false;
    1961              : 
    1962      3231667 :             if (DECL_C_BIT_FIELD (s1) != DECL_C_BIT_FIELD (s2))
    1963              :                return false;
    1964              : 
    1965      3231647 :             if (DECL_C_BIT_FIELD (s1))
    1966              :               {
    1967          496 :                 if (!tree_int_cst_equal (DECL_SIZE (s1), DECL_SIZE (s2)))
    1968              :                   return false;
    1969              : 
    1970          342 :                 ft1 = DECL_BIT_FIELD_TYPE (s1);
    1971          342 :                 ft2 = DECL_BIT_FIELD_TYPE (s2);
    1972              :               }
    1973              : 
    1974      3231493 :             if (!ft1 || !ft2)
    1975              :               return false;
    1976              : 
    1977      3231493 :             if (TREE_CODE (ft1) == ERROR_MARK || TREE_CODE (ft2) == ERROR_MARK)
    1978              :               return false;
    1979              : 
    1980      3231492 :             data->anon_field = !DECL_NAME (s1);
    1981      3231492 :             data->pointedto = false;
    1982              : 
    1983      3231492 :             const struct tagged_tu_seen_cache *cache = data->cache;
    1984      3231492 :             data->cache = &entry;
    1985      3231492 :             bool ret = comptypes_internal (ft1, ft2, data);
    1986      3231492 :             data->cache = cache;
    1987      3231492 :             if (!ret)
    1988              :               return false;
    1989              : 
    1990      1590848 :             tree st1 = TYPE_SIZE (TREE_TYPE (s1));
    1991      1590848 :             tree st2 = TYPE_SIZE (TREE_TYPE (s2));
    1992              : 
    1993      1590848 :             if (data->equiv
    1994       997665 :                 && st1 && TREE_CODE (st1) == INTEGER_CST
    1995       997183 :                 && st2 && TREE_CODE (st2) == INTEGER_CST
    1996      2588028 :                 && !tree_int_cst_equal (st1, st2))
    1997              :              return false;
    1998              : 
    1999      1522170 :             tree counted_by1 = lookup_attribute ("counted_by",
    2000      1522170 :                                                  DECL_ATTRIBUTES (s1));
    2001      1522170 :             tree counted_by2 = lookup_attribute ("counted_by",
    2002      1522170 :                                                  DECL_ATTRIBUTES (s2));
    2003              :             /* If there is no counted_by attribute for both fields.  */
    2004      1522170 :             if (!counted_by1 && !counted_by2)
    2005      1522106 :               continue;
    2006              : 
    2007              :             /* If only one field has counted_by attribute.  */
    2008           64 :             if ((counted_by1 && !counted_by2)
    2009           64 :                 || (!counted_by1 && counted_by2))
    2010              :               return false;
    2011              : 
    2012              :             /* Now both s1 and s2 have counted_by attributes, check
    2013              :                whether they are the same.  */
    2014              : 
    2015           52 :             tree counted_by_field1
    2016           52 :               = lookup_field (t1, TREE_VALUE (TREE_VALUE (counted_by1)));
    2017           52 :             tree counted_by_field2
    2018           52 :               = lookup_field (t2, TREE_VALUE (TREE_VALUE (counted_by2)));
    2019              : 
    2020           52 :             gcc_assert (counted_by_field1 && counted_by_field2);
    2021              : 
    2022           94 :             while (TREE_CHAIN (counted_by_field1))
    2023           42 :               counted_by_field1 = TREE_CHAIN (counted_by_field1);
    2024           86 :             while (TREE_CHAIN (counted_by_field2))
    2025           34 :               counted_by_field2 = TREE_CHAIN (counted_by_field2);
    2026              : 
    2027           52 :             if (DECL_NAME (TREE_VALUE (counted_by_field1))
    2028           52 :                 != DECL_NAME (TREE_VALUE (counted_by_field2)))
    2029              :               return false;
    2030              :           }
    2031              :         return true;
    2032              : 
    2033            0 :     default:
    2034            0 :       gcc_unreachable ();
    2035              :     }
    2036              : }
    2037              : 
    2038              : /* Return true if two function types F1 and F2 are compatible.
    2039              :    If either type specifies no argument types,
    2040              :    the other must specify a fixed number of self-promoting arg types.
    2041              :    Otherwise, if one type specifies only the number of arguments,
    2042              :    the other must specify that number of self-promoting arg types.
    2043              :    Otherwise, the argument types must match.  */
    2044              : 
    2045              : static bool
    2046      8885871 : function_types_compatible_p (const_tree f1, const_tree f2,
    2047              :                              struct comptypes_data *data)
    2048              : {
    2049      8885871 :   tree ret1 = TREE_TYPE (f1);
    2050      8885871 :   tree ret2 = TREE_TYPE (f2);
    2051              : 
    2052              :   /* 'volatile' qualifiers on a function's return type used to mean
    2053              :      the function is noreturn.  */
    2054      8885871 :   if (TYPE_VOLATILE (ret1) != TYPE_VOLATILE (ret2))
    2055           29 :     pedwarn (input_location, 0, "function return types not compatible due to %<volatile%>");
    2056      8885871 :   if (TYPE_VOLATILE (ret1))
    2057           15 :     ret1 = build_qualified_type (TYPE_MAIN_VARIANT (ret1),
    2058           15 :                                  TYPE_QUALS (ret1) & ~TYPE_QUAL_VOLATILE);
    2059      8885871 :   if (TYPE_VOLATILE (ret2))
    2060           18 :     ret2 = build_qualified_type (TYPE_MAIN_VARIANT (ret2),
    2061           18 :                                  TYPE_QUALS (ret2) & ~TYPE_QUAL_VOLATILE);
    2062              : 
    2063      8885871 :   bool ignore_pargs = data->ignore_promoting_args;
    2064      8885871 :   data->ignore_promoting_args = false;
    2065              : 
    2066      8885871 :   if (!comptypes_internal (ret1, ret2, data))
    2067              :     return false;
    2068              : 
    2069      8883276 :   data->ignore_promoting_args = ignore_pargs;
    2070              : 
    2071      8883276 :   tree args1 = TYPE_ARG_TYPES (f1);
    2072      8883276 :   tree args2 = TYPE_ARG_TYPES (f2);
    2073              : 
    2074      8883276 :   if ((args1 == NULL_TREE) != (args2 == NULL_TREE))
    2075        41524 :     data->different_types_p = true;
    2076              : 
    2077              :   /* An unspecified parmlist matches any specified parmlist
    2078              :      whose argument types don't need default promotions.  */
    2079              : 
    2080      8883276 :   if (args1 == NULL_TREE)
    2081              :     {
    2082        21905 :       if (TYPE_NO_NAMED_ARGS_STDARG_P (f1) != TYPE_NO_NAMED_ARGS_STDARG_P (f2))
    2083              :         return false;
    2084        21902 :       if (!(data->ignore_promoting_args || self_promoting_args_p (args2)))
    2085              :         return false;
    2086        21430 :       data->ignore_promoting_args = false;
    2087              :       /* If one of these types comes from a non-prototype fn definition,
    2088              :          compare that with the other type's arglist.
    2089              :          If they don't match, ask for a warning (but no error).  */
    2090        21430 :       if (TYPE_ACTUAL_ARG_TYPES (f1)
    2091        21430 :           && !type_lists_compatible_p (args2, TYPE_ACTUAL_ARG_TYPES (f1), data))
    2092           12 :          data->warning_needed = true;
    2093        21430 :       return true;
    2094              :     }
    2095      8861371 :   if (args2 == NULL_TREE)
    2096              :     {
    2097        19701 :       if (TYPE_NO_NAMED_ARGS_STDARG_P (f1) != TYPE_NO_NAMED_ARGS_STDARG_P (f2))
    2098              :         return false;
    2099        19699 :       if (!(data->ignore_promoting_args || self_promoting_args_p (args1)))
    2100              :         return false;
    2101        19638 :       data->ignore_promoting_args = false;
    2102        19638 :       if (TYPE_ACTUAL_ARG_TYPES (f2)
    2103        19638 :           && !type_lists_compatible_p (args1, TYPE_ACTUAL_ARG_TYPES (f2), data))
    2104            1 :         data->warning_needed = true;
    2105        19638 :       return true;
    2106              :     }
    2107              : 
    2108              :   /* Both types have argument lists: compare them and propagate results.  */
    2109      8841670 :   return type_lists_compatible_p (args1, args2, data);
    2110              : }
    2111              : 
    2112              : /* Check two lists of types for compatibility, returning false for
    2113              :    incompatible, true for compatible.  */
    2114              : 
    2115              : static bool
    2116      8841746 : type_lists_compatible_p (const_tree args1, const_tree args2,
    2117              :                          struct comptypes_data *data)
    2118              : {
    2119     55061084 :   while (1)
    2120              :     {
    2121     31951415 :       if (args1 == NULL_TREE && args2 == NULL_TREE)
    2122              :         return true;
    2123              :       /* If one list is shorter than the other,
    2124              :          they fail to match.  */
    2125     23253991 :       if (args1 == NULL_TREE || args2 == NULL_TREE)
    2126              :         return false;
    2127     23253984 :       tree a1 = TREE_VALUE (args1);
    2128     23253984 :       tree a2 = TREE_VALUE (args2);
    2129     23253984 :       tree mv1 = remove_qualifiers (a1);
    2130     23253984 :       tree mv2 = remove_qualifiers (a2);
    2131              : 
    2132     23253984 :       gcc_assert (mv2);
    2133     23253984 :       gcc_assert (mv2);
    2134              : 
    2135              :       /* If one of the lists has an error marker, ignore this arg.  */
    2136     23253984 :       if (TREE_CODE (a1) == ERROR_MARK
    2137     23253980 :                || TREE_CODE (a2) == ERROR_MARK)
    2138              :         ;
    2139     23253964 :       else if (!comptypes_internal (mv1, mv2, data))
    2140              :         {
    2141       144546 :           data->different_types_p = true;
    2142              :           /* Allow  wait (union {union wait *u; int *i} *)
    2143              :              and  wait (union wait *)  to be compatible.  */
    2144       144546 :           if (TREE_CODE (a1) == UNION_TYPE
    2145          130 :               && (TYPE_NAME (a1) == NULL_TREE
    2146           98 :                   || TYPE_TRANSPARENT_AGGR (a1))
    2147          130 :               && TREE_CODE (TYPE_SIZE (a1)) == INTEGER_CST
    2148       144676 :               && tree_int_cst_equal (TYPE_SIZE (a1),
    2149          130 :                                      TYPE_SIZE (a2)))
    2150              :             {
    2151          130 :               tree memb;
    2152          130 :               for (memb = TYPE_FIELDS (a1);
    2153          166 :                    memb; memb = DECL_CHAIN (memb))
    2154              :                 {
    2155          164 :                   tree mv3 = remove_qualifiers (TREE_TYPE (memb));
    2156          164 :                   if (comptypes_internal (mv3, mv2, data))
    2157              :                     break;
    2158              :                 }
    2159              :               if (memb == NULL_TREE)
    2160              :                 return false;
    2161              :             }
    2162       144416 :           else if (TREE_CODE (a2) == UNION_TYPE
    2163          105 :                    && (TYPE_NAME (a2) == NULL_TREE
    2164           74 :                        || TYPE_TRANSPARENT_AGGR (a2))
    2165          105 :                    && TREE_CODE (TYPE_SIZE (a2)) == INTEGER_CST
    2166       144521 :                    && tree_int_cst_equal (TYPE_SIZE (a2),
    2167          105 :                                           TYPE_SIZE (a1)))
    2168              :             {
    2169          105 :               tree memb;
    2170          105 :               for (memb = TYPE_FIELDS (a2);
    2171          133 :                    memb; memb = DECL_CHAIN (memb))
    2172              :                 {
    2173          131 :                   tree mv3 = remove_qualifiers (TREE_TYPE (memb));
    2174          131 :                   if (comptypes_internal (mv3, mv1, data))
    2175              :                     break;
    2176              :                 }
    2177              :               if (memb == NULL_TREE)
    2178              :                 return false;
    2179              :             }
    2180              :           else
    2181       144311 :             return false;
    2182              :         }
    2183              : 
    2184     23109669 :       args1 = TREE_CHAIN (args1);
    2185     23109669 :       args2 = TREE_CHAIN (args2);
    2186     23109669 :     }
    2187              : }
    2188              : 
    2189              : /* Compute the size to increment a pointer by.  When a function type or void
    2190              :    type or incomplete type is passed, size_one_node is returned.
    2191              :    This function does not emit any diagnostics; the caller is responsible
    2192              :    for that.  */
    2193              : 
    2194              : static tree
    2195       233658 : c_size_in_bytes (const_tree type)
    2196              : {
    2197       233658 :   enum tree_code code = TREE_CODE (type);
    2198              : 
    2199       233658 :   if (code == FUNCTION_TYPE || code == VOID_TYPE || code == ERROR_MARK
    2200       233658 :       || !COMPLETE_TYPE_P (type))
    2201          188 :     return size_one_node;
    2202              : 
    2203              :   /* Convert in case a char is more than one unit.  */
    2204       233470 :   return size_binop_loc (input_location, CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
    2205       233470 :                          size_int (TYPE_PRECISION (char_type_node)
    2206              :                                    / BITS_PER_UNIT));
    2207              : }
    2208              : 
    2209              : /* Return either DECL or its known constant value (if it has one).  */
    2210              : 
    2211              : tree
    2212     14313844 : decl_constant_value_1 (tree decl, bool in_init)
    2213              : {
    2214     14313844 :   if (/* Note that DECL_INITIAL isn't valid for a PARM_DECL.  */
    2215     14313844 :       TREE_CODE (decl) != PARM_DECL
    2216     14313844 :       && !TREE_THIS_VOLATILE (decl)
    2217     13969986 :       && TREE_READONLY (decl)
    2218        36928 :       && DECL_INITIAL (decl) != NULL_TREE
    2219        35932 :       && !error_operand_p (DECL_INITIAL (decl))
    2220              :       /* This is invalid if initial value is not constant.
    2221              :          If it has either a function call, a memory reference,
    2222              :          or a variable, then re-evaluating it could give different results.  */
    2223        35923 :       && TREE_CONSTANT (DECL_INITIAL (decl))
    2224              :       /* Check for cases where this is sub-optimal, even though valid.  */
    2225     14336704 :       && (in_init || TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR))
    2226        17645 :     return DECL_INITIAL (decl);
    2227              :   return decl;
    2228              : }
    2229              : 
    2230              : /* Return either DECL or its known constant value (if it has one).
    2231              :    Like the above, but always return decl outside of functions.  */
    2232              : 
    2233              : tree
    2234     14313596 : decl_constant_value (tree decl)
    2235              : {
    2236              :   /* Don't change a variable array bound or initial value to a constant
    2237              :      in a place where a variable is invalid.  */
    2238     14313596 :   return current_function_decl ? decl_constant_value_1 (decl, false) : decl;
    2239              : }
    2240              : 
    2241              : /* Convert the array expression EXP to a pointer.  */
    2242              : static tree
    2243       820352 : array_to_pointer_conversion (location_t loc, tree exp)
    2244              : {
    2245       820352 :   tree orig_exp = exp;
    2246       820352 :   tree type = TREE_TYPE (exp);
    2247       820352 :   tree adr;
    2248       820352 :   tree restype = TREE_TYPE (type);
    2249       820352 :   tree ptrtype;
    2250              : 
    2251       820352 :   gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
    2252              : 
    2253       820352 :   STRIP_TYPE_NOPS (exp);
    2254              : 
    2255       820352 :   copy_warning (exp, orig_exp);
    2256              : 
    2257       820352 :   ptrtype = c_build_pointer_type (restype);
    2258              : 
    2259       820352 :   if (INDIRECT_REF_P (exp))
    2260         2898 :     return convert (ptrtype, TREE_OPERAND (exp, 0));
    2261              : 
    2262              :   /* In C++ array compound literals are temporary objects unless they are
    2263              :      const or appear in namespace scope, so they are destroyed too soon
    2264              :      to use them for much of anything  (c++/53220).  */
    2265       817454 :   if (warn_cxx_compat && TREE_CODE (exp) == COMPOUND_LITERAL_EXPR)
    2266              :     {
    2267           48 :       tree decl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
    2268           48 :       if (!TREE_READONLY (decl) && !TREE_STATIC (decl))
    2269           46 :         warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat,
    2270              :                     "converting an array compound literal to a pointer "
    2271              :                     "leads to a dangling pointer in C++");
    2272              :     }
    2273              : 
    2274       817454 :   adr = build_unary_op (loc, ADDR_EXPR, exp, true);
    2275       817454 :   return convert (ptrtype, adr);
    2276              : }
    2277              : 
    2278              : /* Convert the function expression EXP to a pointer.  */
    2279              : static tree
    2280     50493069 : function_to_pointer_conversion (location_t loc, tree exp)
    2281              : {
    2282     50493069 :   tree orig_exp = exp;
    2283              : 
    2284     50493069 :   gcc_assert (TREE_CODE (TREE_TYPE (exp)) == FUNCTION_TYPE);
    2285              : 
    2286     50493069 :   STRIP_TYPE_NOPS (exp);
    2287              : 
    2288     50493069 :   copy_warning (exp, orig_exp);
    2289              : 
    2290     50493069 :   tree exp2 = build_unary_op (loc, ADDR_EXPR, exp, false);
    2291              : 
    2292              :   /* If the function is defined and known to not to require a non-local
    2293              :      context, make sure no trampoline is generated.  */
    2294     50493069 :   if (TREE_CODE (exp) == FUNCTION_DECL
    2295     50493069 :       && DECL_INITIAL (exp) && !C_FUNC_NONLOCAL_CONTEXT (exp))
    2296     16035409 :    TREE_NO_TRAMPOLINE (exp2) = 1;
    2297              : 
    2298     50493069 :   return exp2;
    2299              : }
    2300              : 
    2301              : /* Mark EXP as read, not just set, for set but not used -Wunused
    2302              :    warning purposes.  */
    2303              : 
    2304              : void
    2305    488886436 : mark_exp_read (tree exp)
    2306              : {
    2307    615010686 :   switch (TREE_CODE (exp))
    2308              :     {
    2309    203174122 :     case VAR_DECL:
    2310    203174122 :     case PARM_DECL:
    2311    203174122 :       DECL_READ_P (exp) = 1;
    2312    203174122 :       break;
    2313     19677133 :     CASE_CONVERT:
    2314     19677133 :       if (VOID_TYPE_P (TREE_TYPE (exp)))
    2315         3800 :         switch (TREE_CODE (TREE_OPERAND (exp, 0)))
    2316              :           {
    2317              :           case PREINCREMENT_EXPR:
    2318              :           case PREDECREMENT_EXPR:
    2319              :           case POSTINCREMENT_EXPR:
    2320              :           case POSTDECREMENT_EXPR:
    2321              :             return;
    2322              :           default:
    2323              :             break;
    2324              :           }
    2325              :       /* FALLTHRU */
    2326    123384245 :     case ARRAY_REF:
    2327    123384245 :     case COMPONENT_REF:
    2328    123384245 :     case MODIFY_EXPR:
    2329    123384245 :     case REALPART_EXPR:
    2330    123384245 :     case IMAGPART_EXPR:
    2331    123384245 :     case ADDR_EXPR:
    2332    123384245 :     case VIEW_CONVERT_EXPR:
    2333    123384245 :     case PREINCREMENT_EXPR:
    2334    123384245 :     case PREDECREMENT_EXPR:
    2335    123384245 :     case POSTINCREMENT_EXPR:
    2336    123384245 :     case POSTDECREMENT_EXPR:
    2337    123384245 :       mark_exp_read (TREE_OPERAND (exp, 0));
    2338    123384245 :       break;
    2339       236046 :     case COMPOUND_EXPR:
    2340              :       /* Pattern match what build_atomic_assign produces with modifycode
    2341              :          NOP_EXPR.  */
    2342       236046 :       if (VAR_P (TREE_OPERAND (exp, 1))
    2343        27227 :           && DECL_ARTIFICIAL (TREE_OPERAND (exp, 1))
    2344       263189 :           && TREE_CODE (TREE_OPERAND (exp, 0)) == COMPOUND_EXPR)
    2345              :         {
    2346         2210 :           tree t1 = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
    2347         2210 :           tree t2 = TREE_OPERAND (TREE_OPERAND (exp, 0), 1);
    2348         2210 :           if (TREE_CODE (t1) == TARGET_EXPR
    2349         2202 :               && TARGET_EXPR_SLOT (t1) == TREE_OPERAND (exp, 1)
    2350         4410 :               && TREE_CODE (t2) == CALL_EXPR)
    2351              :             {
    2352         2200 :               tree fndecl = get_callee_fndecl (t2);
    2353         2200 :               tree arg = NULL_TREE;
    2354         2200 :               if (fndecl
    2355         2200 :                   && TREE_CODE (fndecl) == FUNCTION_DECL
    2356         2200 :                   && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)
    2357         4400 :                   && call_expr_nargs (t2) >= 2)
    2358         2200 :                 switch (DECL_FUNCTION_CODE (fndecl))
    2359              :                   {
    2360          130 :                   case BUILT_IN_ATOMIC_STORE:
    2361          130 :                     arg = CALL_EXPR_ARG (t2, 1);
    2362          130 :                     break;
    2363         2070 :                   case BUILT_IN_ATOMIC_STORE_1:
    2364         2070 :                   case BUILT_IN_ATOMIC_STORE_2:
    2365         2070 :                   case BUILT_IN_ATOMIC_STORE_4:
    2366         2070 :                   case BUILT_IN_ATOMIC_STORE_8:
    2367         2070 :                   case BUILT_IN_ATOMIC_STORE_16:
    2368         2070 :                     arg = CALL_EXPR_ARG (t2, 0);
    2369         2070 :                     break;
    2370              :                   default:
    2371              :                     break;
    2372              :                   }
    2373         2200 :               if (arg)
    2374              :                 {
    2375         2200 :                   STRIP_NOPS (arg);
    2376         2200 :                   if (TREE_CODE (arg) == ADDR_EXPR
    2377         2200 :                       && DECL_P (TREE_OPERAND (arg, 0))
    2378         4400 :                       && TYPE_ATOMIC (TREE_TYPE (TREE_OPERAND (arg, 0))))
    2379         2200 :                     mark_exp_read (TREE_OPERAND (arg, 0));
    2380              :                 }
    2381              :             }
    2382              :         }
    2383              :       /* FALLTHRU */
    2384      2739462 :     case C_MAYBE_CONST_EXPR:
    2385      2739462 :       mark_exp_read (TREE_OPERAND (exp, 1));
    2386      2739462 :       break;
    2387          578 :     case OMP_ARRAY_SECTION:
    2388          578 :       mark_exp_read (TREE_OPERAND (exp, 0));
    2389          578 :       if (TREE_OPERAND (exp, 1))
    2390          384 :         mark_exp_read (TREE_OPERAND (exp, 1));
    2391          578 :       if (TREE_OPERAND (exp, 2))
    2392          543 :         mark_exp_read (TREE_OPERAND (exp, 2));
    2393              :       break;
    2394              :     default:
    2395              :       break;
    2396              :     }
    2397              : }
    2398              : 
    2399              : /* Perform the default conversion of arrays and functions to pointers.
    2400              :    Return the result of converting EXP.  For any other expression, just
    2401              :    return EXP.
    2402              : 
    2403              :    LOC is the location of the expression.  */
    2404              : 
    2405              : struct c_expr
    2406    361444689 : default_function_array_conversion (location_t loc, struct c_expr exp)
    2407              : {
    2408    361444689 :   tree orig_exp = exp.value;
    2409    361444689 :   tree type = TREE_TYPE (exp.value);
    2410    361444689 :   enum tree_code code = TREE_CODE (type);
    2411              : 
    2412    361444689 :   switch (code)
    2413              :     {
    2414              :     case ARRAY_TYPE:
    2415              :       {
    2416              :         bool not_lvalue = false;
    2417              :         bool lvalue_array_p;
    2418              : 
    2419       773452 :         while ((TREE_CODE (exp.value) == NON_LVALUE_EXPR
    2420       773452 :                 || CONVERT_EXPR_P (exp.value))
    2421       773452 :                && TREE_TYPE (TREE_OPERAND (exp.value, 0)) == type)
    2422              :           {
    2423            0 :             if (TREE_CODE (exp.value) == NON_LVALUE_EXPR)
    2424            0 :               not_lvalue = true;
    2425            0 :             exp.value = TREE_OPERAND (exp.value, 0);
    2426              :           }
    2427              : 
    2428       773452 :         copy_warning (exp.value, orig_exp);
    2429              : 
    2430       773452 :         lvalue_array_p = !not_lvalue && lvalue_p (exp.value);
    2431       773452 :         if (!flag_isoc99 && !lvalue_array_p)
    2432              :           {
    2433              :             /* Before C99, non-lvalue arrays do not decay to pointers.
    2434              :                Normally, using such an array would be invalid; but it can
    2435              :                be used correctly inside sizeof or as a statement expression.
    2436              :                Thus, do not give an error here; an error will result later.  */
    2437          109 :             return exp;
    2438              :           }
    2439              : 
    2440       773343 :         exp.value = array_to_pointer_conversion (loc, exp.value);
    2441              :       }
    2442       773343 :       break;
    2443       762126 :     case FUNCTION_TYPE:
    2444       762126 :       exp.value = function_to_pointer_conversion (loc, exp.value);
    2445       762126 :       break;
    2446              :     default:
    2447              :       break;
    2448              :     }
    2449              : 
    2450    361444580 :   return exp;
    2451              : }
    2452              : 
    2453              : struct c_expr
    2454       947212 : default_function_array_read_conversion (location_t loc, struct c_expr exp)
    2455              : {
    2456       947212 :   mark_exp_read (exp.value);
    2457              :   /* We only generate a call to .ACCESS_WITH_SIZE when it is a read.  */
    2458       947212 :   if (TREE_CODE (exp.value) == COMPONENT_REF
    2459       947212 :       && handle_counted_by_p (exp.value))
    2460        66607 :     exp.value = handle_counted_by_for_component_ref (loc, exp.value);
    2461       947212 :   return default_function_array_conversion (loc, exp);
    2462              : }
    2463              : 
    2464              : /* Return whether EXPR should be treated as an atomic lvalue for the
    2465              :    purposes of load and store handling.  */
    2466              : 
    2467              : static bool
    2468    362537283 : really_atomic_lvalue (tree expr)
    2469              : {
    2470    362537283 :   if (error_operand_p (expr))
    2471              :     return false;
    2472    362529762 :   if (!TYPE_ATOMIC (TREE_TYPE (expr)))
    2473              :     return false;
    2474        57389 :   if (!COMPLETE_TYPE_P (TREE_TYPE (expr)))
    2475              :     return false;
    2476        57386 :   if (!lvalue_p (expr))
    2477              :     return false;
    2478              : 
    2479              :   /* Ignore _Atomic on register variables, since their addresses can't
    2480              :      be taken so (a) atomicity is irrelevant and (b) the normal atomic
    2481              :      sequences wouldn't work.  Ignore _Atomic on structures containing
    2482              :      bit-fields, since accessing elements of atomic structures or
    2483              :      unions is undefined behavior (C11 6.5.2.3#5), but it's unclear if
    2484              :      it's undefined at translation time or execution time, and the
    2485              :      normal atomic sequences again wouldn't work.  */
    2486        57528 :   while (handled_component_p (expr))
    2487              :     {
    2488          144 :       if (TREE_CODE (expr) == COMPONENT_REF
    2489          144 :           && DECL_C_BIT_FIELD (TREE_OPERAND (expr, 1)))
    2490              :         return false;
    2491          144 :       expr = TREE_OPERAND (expr, 0);
    2492              :     }
    2493        57384 :   if (TREE_CODE (expr) == COMPOUND_LITERAL_EXPR)
    2494            1 :     expr = COMPOUND_LITERAL_EXPR_DECL (expr);
    2495       112568 :   if (DECL_P (expr) && C_DECL_REGISTER (expr))
    2496              :     return false;
    2497              :   return true;
    2498              : }
    2499              : 
    2500              : /* If EXPR is a named constant (C23) derived from a constexpr variable
    2501              :    - that is, a reference to such a variable, or a member extracted by
    2502              :    a sequence of structure and union (but not array) member accesses
    2503              :    (where union member accesses must access the same member as
    2504              :    initialized) - then return the corresponding initializer;
    2505              :    otherwise, return NULL_TREE.  */
    2506              : 
    2507              : static tree
    2508    359352571 : maybe_get_constexpr_init (tree expr)
    2509              : {
    2510    359352571 :   tree decl = NULL_TREE;
    2511    359352571 :   if (TREE_CODE (expr) == VAR_DECL)
    2512              :     decl = expr;
    2513    347661333 :   else if (TREE_CODE (expr) == COMPOUND_LITERAL_EXPR)
    2514       820282 :     decl = COMPOUND_LITERAL_EXPR_DECL (expr);
    2515       820282 :   if (decl
    2516     12511520 :       && C_DECL_DECLARED_CONSTEXPR (decl)
    2517          370 :       && DECL_INITIAL (decl) != NULL_TREE
    2518       820652 :       && !error_operand_p (DECL_INITIAL (decl)))
    2519          370 :     return DECL_INITIAL (decl);
    2520    359352201 :   if (TREE_CODE (expr) != COMPONENT_REF)
    2521              :     return NULL_TREE;
    2522       871708 :   tree inner = maybe_get_constexpr_init (TREE_OPERAND (expr, 0));
    2523       871708 :   if (inner == NULL_TREE)
    2524              :     return NULL_TREE;
    2525          126 :   while ((CONVERT_EXPR_P (inner) || TREE_CODE (inner) == NON_LVALUE_EXPR)
    2526           47 :          && !error_operand_p (inner)
    2527          220 :          && (TYPE_MAIN_VARIANT (TREE_TYPE (inner))
    2528           47 :              == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (inner, 0)))))
    2529           47 :     inner = TREE_OPERAND (inner, 0);
    2530          126 :   if (TREE_CODE (inner) != CONSTRUCTOR)
    2531              :     return NULL_TREE;
    2532          126 :   tree field = TREE_OPERAND (expr, 1);
    2533          126 :   unsigned HOST_WIDE_INT cidx;
    2534          126 :   tree cfield, cvalue;
    2535          126 :   bool have_other_init = false;
    2536          266 :   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (inner), cidx, cfield, cvalue)
    2537              :     {
    2538          250 :       if (cfield == field)
    2539              :         return cvalue;
    2540          140 :       have_other_init = true;
    2541              :     }
    2542           16 :   if (TREE_CODE (TREE_TYPE (inner)) == UNION_TYPE
    2543           16 :       && (have_other_init || field != TYPE_FIELDS (TREE_TYPE (inner))))
    2544              :     return NULL_TREE;
    2545              :   /* Return a default initializer.  */
    2546           13 :   if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (expr)))
    2547            5 :     return build_constructor (TREE_TYPE (expr), NULL);
    2548            8 :   return build_zero_cst (TREE_TYPE (expr));
    2549              : }
    2550              : 
    2551              : /* Helper function for convert_lvalue_to_rvalue called via
    2552              :    walk_tree_without_duplicates.  Find DATA inside of the expression.  */
    2553              : 
    2554              : static tree
    2555       230263 : c_find_var_r (tree *tp, int *walk_subtrees, void *data)
    2556              : {
    2557       230263 :   if (TYPE_P (*tp))
    2558            0 :     *walk_subtrees = 0;
    2559       230263 :   else if (*tp == (tree) data)
    2560              :     return *tp;
    2561              :   return NULL_TREE;
    2562              : }
    2563              : 
    2564              : /* Convert expression EXP (location LOC) from lvalue to rvalue,
    2565              :    including converting functions and arrays to pointers if CONVERT_P.
    2566              :    If READ_P, also mark the expression as having been read.  If
    2567              :    FOR_INIT, constexpr expressions of structure and union type should
    2568              :    be replaced by the corresponding CONSTRUCTOR; otherwise, only
    2569              :    constexpr scalars (including elements of structures and unions) are
    2570              :    replaced by their initializers.  */
    2571              : 
    2572              : struct c_expr
    2573    358668472 : convert_lvalue_to_rvalue (location_t loc, struct c_expr exp,
    2574              :                           bool convert_p, bool read_p, bool for_init)
    2575              : {
    2576    358668472 :   bool force_non_npc = false;
    2577    358668472 :   if (read_p)
    2578    314718095 :     mark_exp_read (exp.value);
    2579              :   /* We only generate a call to .ACCESS_WITH_SIZE when it is a read.  */
    2580    314718095 :   if (read_p && TREE_CODE (exp.value) == COMPONENT_REF
    2581       780616 :       && handle_counted_by_p (exp.value))
    2582       780587 :     exp.value = handle_counted_by_for_component_ref (loc, exp.value);
    2583              : 
    2584    358668472 :   if (convert_p)
    2585    358655262 :     exp = default_function_array_conversion (loc, exp);
    2586    358668472 :   if (!VOID_TYPE_P (TREE_TYPE (exp.value))
    2587    358668472 :       || (flag_isoc2y
    2588         1359 :           && TYPE_QUALS (TREE_TYPE (exp.value)) != TYPE_UNQUALIFIED))
    2589    356191638 :     exp.value = require_complete_type (loc, exp.value);
    2590    358668472 :   if (for_init || !RECORD_OR_UNION_TYPE_P (TREE_TYPE (exp.value)))
    2591              :     {
    2592    358480863 :       tree init = maybe_get_constexpr_init (exp.value);
    2593    358480863 :       if (init != NULL_TREE)
    2594              :         {
    2595              :           /* A named constant of pointer type or type nullptr_t is not
    2596              :              a null pointer constant even if the initializer is
    2597              :              one.  */
    2598          367 :           if (TREE_CODE (init) == INTEGER_CST
    2599          232 :               && !INTEGRAL_TYPE_P (TREE_TYPE (init))
    2600          393 :               && integer_zerop (init))
    2601              :             force_non_npc = true;
    2602              :           exp.value = init;
    2603              :         }
    2604              :     }
    2605    358668472 :   if (really_atomic_lvalue (exp.value))
    2606              :     {
    2607        26934 :       vec<tree, va_gc> *params;
    2608        26934 :       tree nonatomic_type, tmp, tmp_addr, fndecl, func_call;
    2609        26934 :       tree expr_type = TREE_TYPE (exp.value);
    2610        26934 :       tree expr_addr = build_unary_op (loc, ADDR_EXPR, exp.value, false);
    2611        26934 :       tree seq_cst = build_int_cst (integer_type_node, MEMMODEL_SEQ_CST);
    2612              : 
    2613        26934 :       gcc_assert (TYPE_ATOMIC (expr_type));
    2614              : 
    2615              :       /* Expansion of a generic atomic load may require an addition
    2616              :          element, so allocate enough to prevent a resize.  */
    2617        26934 :       vec_alloc (params, 4);
    2618              : 
    2619              :       /* Remove the qualifiers for the rest of the expressions and
    2620              :          create the VAL temp variable to hold the RHS.  */
    2621        26934 :       nonatomic_type = build_qualified_type (expr_type, TYPE_UNQUALIFIED);
    2622        26934 :       tmp = create_tmp_var_raw (nonatomic_type);
    2623        26934 :       tmp_addr = build_unary_op (loc, ADDR_EXPR, tmp, false);
    2624        26934 :       TREE_ADDRESSABLE (tmp) = 1;
    2625              :       /* Do not disable warnings for TMP even though it's artificial.
    2626              :          -Winvalid-memory-model depends on it.  */
    2627              : 
    2628              :       /* Issue __atomic_load (&expr, &tmp, SEQ_CST);  */
    2629        26934 :       fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_LOAD);
    2630        26934 :       params->quick_push (expr_addr);
    2631        26934 :       params->quick_push (tmp_addr);
    2632        26934 :       params->quick_push (seq_cst);
    2633        26934 :       func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
    2634              : 
    2635              :       /* EXPR is always read.  */
    2636        26934 :       mark_exp_read (exp.value);
    2637              : 
    2638              :       /* Optimize the common case where c_build_function_call_vec
    2639              :          immediately folds __atomic_load (&expr, &tmp, SEQ_CST); into
    2640              :          tmp = __atomic_load_<N> (&expr, SEQ_CST);
    2641              :          In that case tmp is not addressable and can be initialized
    2642              :          fully by the rhs of the MODIFY_EXPR.  */
    2643        26934 :       tree tem = func_call;
    2644        26934 :       if (CONVERT_EXPR_P (tem) && VOID_TYPE_P (TREE_TYPE (tem)))
    2645              :         {
    2646        25679 :           tem = TREE_OPERAND (tem, 0);
    2647        25679 :           if (TREE_CODE (tem) == MODIFY_EXPR
    2648        25679 :               && TREE_OPERAND (tem, 0) == tmp
    2649        51358 :               && !walk_tree_without_duplicates (&TREE_OPERAND (tem, 1),
    2650              :                                                 c_find_var_r, tmp))
    2651              :             {
    2652        25679 :               TREE_ADDRESSABLE (tmp) = 0;
    2653        25679 :               func_call = TREE_OPERAND (tem, 1);
    2654              :             }
    2655              :         }
    2656              : 
    2657              :       /* Return tmp which contains the value loaded.  */
    2658        26934 :       exp.value = build4 (TARGET_EXPR, nonatomic_type, tmp, func_call,
    2659              :                           NULL_TREE, NULL_TREE);
    2660              :     }
    2661    358655262 :   if (convert_p && !error_operand_p (exp.value)
    2662    717316257 :       && (TREE_CODE (TREE_TYPE (exp.value)) != ARRAY_TYPE))
    2663    358647676 :     exp.value = convert (build_qualified_type (TREE_TYPE (exp.value), TYPE_UNQUALIFIED), exp.value);
    2664    358668472 :   if (force_non_npc)
    2665           24 :     exp.value = build1 (NOP_EXPR, TREE_TYPE (exp.value), exp.value);
    2666              : 
    2667    358668472 :   {
    2668    358668472 :     tree false_value, true_value;
    2669    358655262 :     if (convert_p && !error_operand_p (exp.value)
    2670    717316257 :         && c_hardbool_type_attr (TREE_TYPE (exp.value),
    2671              :                                  &false_value, &true_value))
    2672              :       {
    2673         9717 :         tree t = save_expr (exp.value);
    2674              : 
    2675         9717 :         mark_exp_read (exp.value);
    2676              : 
    2677         9717 :         tree trapfn = builtin_decl_explicit (BUILT_IN_TRAP);
    2678         9717 :         tree expr = build_call_expr_loc (loc, trapfn, 0);
    2679         9717 :         expr = build_compound_expr (loc, expr, boolean_true_node);
    2680         9717 :         expr = fold_build3_loc (loc, COND_EXPR, boolean_type_node,
    2681              :                                 fold_build2_loc (loc, NE_EXPR,
    2682              :                                                  boolean_type_node,
    2683              :                                                  t, true_value),
    2684              :                                 expr, boolean_true_node);
    2685         9717 :         expr = fold_build3_loc (loc, COND_EXPR, boolean_type_node,
    2686              :                                 fold_build2_loc (loc, NE_EXPR,
    2687              :                                                  boolean_type_node,
    2688              :                                                  t, false_value),
    2689              :                                 expr, boolean_false_node);
    2690              : 
    2691         9717 :         exp.value = expr;
    2692              :       }
    2693              :   }
    2694              : 
    2695    358668472 :   return exp;
    2696              : }
    2697              : 
    2698              : /* Wrapper for the overload above, same arguments but for tree rather than
    2699              :    c_expr.  This is important for hardbools to decay to bools.  */
    2700              : 
    2701              : static inline tree
    2702       574332 : convert_lvalue_to_rvalue (location_t loc, tree val,
    2703              :                           bool convert_p, bool read_p, bool for_init = false)
    2704              : {
    2705       574332 :   struct c_expr expr;
    2706       574332 :   memset (&expr, 0, sizeof (expr));
    2707       574332 :   expr.value = val;
    2708       574332 :   expr = convert_lvalue_to_rvalue (loc, expr, convert_p, read_p, for_init);
    2709       574332 :   return expr.value;
    2710              : }
    2711              : 
    2712              : /* EXP is an expression of integer type.  Apply the integer promotions
    2713              :    to it and return the promoted value.  */
    2714              : 
    2715              : tree
    2716     76581506 : perform_integral_promotions (tree exp)
    2717              : {
    2718     76581506 :   tree type = TREE_TYPE (exp);
    2719     76581506 :   enum tree_code code = TREE_CODE (type);
    2720              : 
    2721     76581506 :   gcc_assert (INTEGRAL_TYPE_P (type));
    2722              : 
    2723              :   /* Convert enums to the result of applying the integer promotions to
    2724              :      their underlying type.  */
    2725     76581506 :   if (code == ENUMERAL_TYPE)
    2726              :     {
    2727       649130 :       type = ENUM_UNDERLYING_TYPE (type);
    2728       649130 :       if (c_promoting_integer_type_p (type))
    2729              :         {
    2730           94 :           if (TYPE_UNSIGNED (type)
    2731           94 :               && TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
    2732            0 :             type = unsigned_type_node;
    2733              :           else
    2734           94 :             type = integer_type_node;
    2735              :         }
    2736              : 
    2737       649130 :       return convert (type, exp);
    2738              :     }
    2739              : 
    2740              :   /* ??? This should no longer be needed now bit-fields have their
    2741              :      proper types.  */
    2742     75932376 :   if (TREE_CODE (exp) == COMPONENT_REF
    2743     75932376 :       && DECL_C_BIT_FIELD (TREE_OPERAND (exp, 1)))
    2744              :     {
    2745        62179 :       if (TREE_CODE (DECL_BIT_FIELD_TYPE (TREE_OPERAND (exp, 1)))
    2746              :           == BITINT_TYPE)
    2747          454 :         return convert (DECL_BIT_FIELD_TYPE (TREE_OPERAND (exp, 1)), exp);
    2748              :       /* If it's thinner than an int, promote it like a
    2749              :          c_promoting_integer_type_p, otherwise leave it alone.  */
    2750        61725 :       if (compare_tree_int (DECL_SIZE (TREE_OPERAND (exp, 1)),
    2751        61725 :                             TYPE_PRECISION (integer_type_node)) < 0)
    2752        53463 :         return convert (integer_type_node, exp);
    2753              :     }
    2754              : 
    2755     75878459 :   if (c_promoting_integer_type_p (type))
    2756              :     {
    2757              :       /* Preserve unsignedness if not really getting any wider.  */
    2758       642932 :       if (TYPE_UNSIGNED (type)
    2759       642932 :           && TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
    2760            0 :         return convert (unsigned_type_node, exp);
    2761              : 
    2762       642932 :       return convert (integer_type_node, exp);
    2763              :     }
    2764              : 
    2765              :   return exp;
    2766              : }
    2767              : 
    2768              : 
    2769              : /* Perform default promotions for C data used in expressions.
    2770              :    Enumeral types or short or char are converted to int.
    2771              :    In addition, manifest constants symbols are replaced by their values.  */
    2772              : 
    2773              : tree
    2774     86091338 : default_conversion (tree exp)
    2775              : {
    2776     86091338 :   tree orig_exp;
    2777     86091338 :   tree type = TREE_TYPE (exp);
    2778     86091338 :   enum tree_code code = TREE_CODE (type);
    2779     86091338 :   tree promoted_type;
    2780              : 
    2781     86091338 :   mark_exp_read (exp);
    2782              :   /* We only generate a call to .ACCESS_WITH_SIZE when it is a read.  */
    2783     86091338 :   if (TREE_CODE (exp) == COMPONENT_REF
    2784     86091338 :       && handle_counted_by_p (exp))
    2785       597956 :     exp = handle_counted_by_for_component_ref (EXPR_LOCATION (exp), exp);
    2786              : 
    2787              :   /* Functions and arrays have been converted during parsing.  */
    2788     86091338 :   gcc_assert (code != FUNCTION_TYPE);
    2789     86091338 :   if (code == ARRAY_TYPE)
    2790              :     return exp;
    2791              : 
    2792              :   /* Constants can be used directly unless they're not loadable.  */
    2793     86091179 :   if (TREE_CODE (exp) == CONST_DECL)
    2794            0 :     exp = DECL_INITIAL (exp);
    2795              : 
    2796              :   /* Strip no-op conversions.  */
    2797     86091179 :   orig_exp = exp;
    2798     86462372 :   STRIP_TYPE_NOPS (exp);
    2799              : 
    2800     86091179 :   copy_warning (exp, orig_exp);
    2801              : 
    2802     86091179 :   if (code == VOID_TYPE)
    2803              :     {
    2804            2 :       error_at (EXPR_LOC_OR_LOC (exp, input_location),
    2805              :                 "void value not ignored as it ought to be");
    2806            2 :       return error_mark_node;
    2807              :     }
    2808              : 
    2809     86091177 :   exp = require_complete_type (EXPR_LOC_OR_LOC (exp, input_location), exp);
    2810     86091177 :   if (exp == error_mark_node)
    2811              :     return error_mark_node;
    2812              : 
    2813     86090274 :   promoted_type = targetm.promoted_type (type);
    2814     86090274 :   if (promoted_type)
    2815            0 :     return convert (promoted_type, exp);
    2816              : 
    2817     86090274 :   if (INTEGRAL_TYPE_P (type))
    2818     75584827 :     return perform_integral_promotions (exp);
    2819              : 
    2820              :   return exp;
    2821              : }
    2822              : 
    2823              : /* Look up COMPONENT in a structure or union TYPE.
    2824              : 
    2825              :    If the component name is not found, returns NULL_TREE.  Otherwise,
    2826              :    the return value is a TREE_LIST, with each TREE_VALUE a FIELD_DECL
    2827              :    stepping down the chain to the component, which is in the last
    2828              :    TREE_VALUE of the list.  Normally the list is of length one, but if
    2829              :    the component is embedded within (nested) anonymous structures or
    2830              :    unions, the list steps down the chain to the component.  */
    2831              : 
    2832              : tree
    2833      2312901 : lookup_field (const_tree type, tree component)
    2834              : {
    2835      2312901 :   tree field;
    2836              : 
    2837              :   /* If TYPE_LANG_SPECIFIC is set, then it is a sorted array of pointers
    2838              :      to the field elements.  Use a binary search on this array to quickly
    2839              :      find the element.  Otherwise, do a linear search.  TYPE_LANG_SPECIFIC
    2840              :      will always be set for structures which have many elements.
    2841              : 
    2842              :      Duplicate field checking replaces duplicates with NULL_TREE so
    2843              :      TYPE_LANG_SPECIFIC arrays are potentially no longer sorted.  In that
    2844              :      case just iterate using DECL_CHAIN.  */
    2845              : 
    2846      2612789 :   if (TYPE_LANG_SPECIFIC (type) && TYPE_LANG_SPECIFIC (type)->s
    2847      2612789 :       && !seen_error ())
    2848              :     {
    2849       299867 :       int bot, top, half;
    2850       299867 :       tree *field_array = &TYPE_LANG_SPECIFIC (type)->s->elts[0];
    2851              : 
    2852       299867 :       field = TYPE_FIELDS (type);
    2853       299867 :       bot = 0;
    2854       299867 :       top = TYPE_LANG_SPECIFIC (type)->s->len;
    2855      1378281 :       while (top - bot > 1)
    2856              :         {
    2857      1349788 :           half = (top - bot + 1) >> 1;
    2858      1349788 :           field = field_array[bot+half];
    2859              : 
    2860      1349788 :           if (DECL_NAME (field) == NULL_TREE)
    2861              :             {
    2862              :               /* Step through all anon unions in linear fashion.  */
    2863            0 :               while (DECL_NAME (field_array[bot]) == NULL_TREE)
    2864              :                 {
    2865            0 :                   field = field_array[bot++];
    2866            0 :                   if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)))
    2867              :                     {
    2868            0 :                       tree anon = lookup_field (TREE_TYPE (field), component);
    2869              : 
    2870            0 :                       if (anon)
    2871            0 :                         return tree_cons (NULL_TREE, field, anon);
    2872              : 
    2873              :                       /* The Plan 9 compiler permits referring
    2874              :                          directly to an anonymous struct/union field
    2875              :                          using a typedef name.  */
    2876            0 :                       if (flag_plan9_extensions
    2877            0 :                           && TYPE_NAME (TREE_TYPE (field)) != NULL_TREE
    2878            0 :                           && (TREE_CODE (TYPE_NAME (TREE_TYPE (field)))
    2879              :                               == TYPE_DECL)
    2880            0 :                           && (DECL_NAME (TYPE_NAME (TREE_TYPE (field)))
    2881              :                               == component))
    2882              :                         break;
    2883              :                     }
    2884              :                 }
    2885              : 
    2886              :               /* Entire record is only anon unions.  */
    2887            0 :               if (bot > top)
    2888              :                 return NULL_TREE;
    2889              : 
    2890              :               /* Restart the binary search, with new lower bound.  */
    2891            0 :               continue;
    2892            0 :             }
    2893              : 
    2894      1349788 :           if (DECL_NAME (field) == component)
    2895              :             break;
    2896      1078414 :           if (DECL_NAME (field) < component)
    2897              :             bot += half;
    2898              :           else
    2899       892103 :             top = bot + half;
    2900              :         }
    2901              : 
    2902       299867 :       if (DECL_NAME (field_array[bot]) == component)
    2903              :         field = field_array[bot];
    2904       271374 :       else if (DECL_NAME (field) != component)
    2905              :         return NULL_TREE;
    2906              :     }
    2907              :   else
    2908              :     {
    2909      5243366 :       for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    2910              :         {
    2911      5234073 :           if (DECL_NAME (field) == NULL_TREE
    2912      5234073 :               && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)))
    2913              :             {
    2914        11876 :               tree anon = lookup_field (TREE_TYPE (field), component);
    2915              : 
    2916        11876 :               if (anon)
    2917         2678 :                 return tree_cons (NULL_TREE, field, anon);
    2918              : 
    2919              :               /* The Plan 9 compiler permits referring directly to an
    2920              :                  anonymous struct/union field using a typedef
    2921              :                  name.  */
    2922         9198 :               if (flag_plan9_extensions
    2923          174 :                   && TYPE_NAME (TREE_TYPE (field)) != NULL_TREE
    2924          172 :                   && TREE_CODE (TYPE_NAME (TREE_TYPE (field))) == TYPE_DECL
    2925         9260 :                   && (DECL_NAME (TYPE_NAME (TREE_TYPE (field)))
    2926              :                       == component))
    2927              :                 break;
    2928              :             }
    2929              : 
    2930      5231391 :           if (DECL_NAME (field) == component)
    2931              :             break;
    2932              :         }
    2933              : 
    2934      2010356 :       if (field == NULL_TREE)
    2935              :         return NULL_TREE;
    2936              :     }
    2937              : 
    2938      2300930 :   return tree_cons (NULL_TREE, field, NULL_TREE);
    2939              : }
    2940              : 
    2941              : /* Recursively append candidate IDENTIFIER_NODEs to CANDIDATES.  */
    2942              : 
    2943              : static void
    2944          101 : lookup_field_fuzzy_find_candidates (tree type, tree component,
    2945              :                                     vec<tree> *candidates)
    2946              : {
    2947          101 :   tree field;
    2948          258 :   for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    2949              :     {
    2950          157 :       if (DECL_NAME (field) == NULL_TREE
    2951          157 :           && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)))
    2952           30 :         lookup_field_fuzzy_find_candidates (TREE_TYPE (field), component,
    2953              :                                             candidates);
    2954              : 
    2955          157 :       if (DECL_NAME (field))
    2956          111 :         candidates->safe_push (DECL_NAME (field));
    2957              :     }
    2958          101 : }
    2959              : 
    2960              : /* Like "lookup_field", but find the closest matching IDENTIFIER_NODE,
    2961              :    rather than returning a TREE_LIST for an exact match.  */
    2962              : 
    2963              : static tree
    2964           71 : lookup_field_fuzzy (tree type, tree component)
    2965              : {
    2966           71 :   gcc_assert (TREE_CODE (component) == IDENTIFIER_NODE);
    2967              : 
    2968              :   /* First, gather a list of candidates.  */
    2969           71 :   auto_vec <tree> candidates;
    2970              : 
    2971           71 :   lookup_field_fuzzy_find_candidates (type, component,
    2972              :                                       &candidates);
    2973              : 
    2974           71 :   return find_closest_identifier (component, &candidates);
    2975           71 : }
    2976              : 
    2977              : /* Support function for build_component_ref's error-handling.
    2978              : 
    2979              :    Given DATUM_TYPE, and "DATUM.COMPONENT", where DATUM is *not* a
    2980              :    struct or union, should we suggest "DATUM->COMPONENT" as a hint?  */
    2981              : 
    2982              : static bool
    2983           72 : should_suggest_deref_p (tree datum_type)
    2984              : {
    2985              :   /* We don't do it for Objective-C, since Objective-C 2.0 dot-syntax
    2986              :      allows "." for ptrs; we could be handling a failed attempt
    2987              :      to access a property.  */
    2988           72 :   if (c_dialect_objc ())
    2989              :     return false;
    2990              : 
    2991              :   /* Only suggest it for pointers...  */
    2992           72 :   if (TREE_CODE (datum_type) != POINTER_TYPE)
    2993              :     return false;
    2994              : 
    2995              :   /* ...to structs/unions.  */
    2996            8 :   tree underlying_type = TREE_TYPE (datum_type);
    2997            8 :   enum tree_code code = TREE_CODE (underlying_type);
    2998            8 :   if (code == RECORD_TYPE || code == UNION_TYPE)
    2999              :     return true;
    3000              :   else
    3001            1 :     return false;
    3002              : }
    3003              : 
    3004              : /* Give a component ref REF, decide whether we should handle its counted_by
    3005              :    attribute based on its context:
    3006              :    Do not handle counted_by when in offsetof, typeof and alignof operator.  */
    3007              : 
    3008              : static bool
    3009      2269943 : handle_counted_by_p (tree ref)
    3010              : {
    3011      2269943 :   gcc_assert (TREE_CODE (ref) == COMPONENT_REF);
    3012      2269943 :   tree datum = TREE_OPERAND (ref, 0);
    3013              :   /* If the component_ref is build for a offsetof, i.e., the datum
    3014              :      of the component_ref is a indirect_ref of null_pointer_node,
    3015              :      we should not generate call to .ACCESS_WITH_SIZE.  */
    3016      2269943 :   if (TREE_CODE (datum) == INDIRECT_REF
    3017      2269943 :       && TREE_OPERAND (datum, 0) == null_pointer_node)
    3018              :     return false;
    3019      2269613 :   if (in_typeof || in_alignof)
    3020         8783 :     return false;
    3021              :   return true;
    3022              : }
    3023              : 
    3024              : /* Given a component ref REF, if there is a counted_by attribute attached,
    3025              :    issue error when the element_type is a structure or union including a
    3026              :    flexible array member.  */
    3027              : 
    3028              : static void
    3029      2269484 : check_counted_by_attribute (location_t loc, tree ref)
    3030              : {
    3031      2269484 :   tree subdatum = TREE_OPERAND (ref, 1);
    3032      2269484 :   tree sub_type = TREE_TYPE (subdatum);
    3033              : 
    3034      2269484 :   if (!c_flexible_array_member_type_p (sub_type)
    3035      2269484 :       && TREE_CODE (sub_type) != POINTER_TYPE)
    3036              :     return;
    3037              : 
    3038       386364 :   tree element_type = TREE_TYPE (sub_type);
    3039              : 
    3040       386364 :   tree attr_counted_by = lookup_attribute ("counted_by",
    3041       386364 :                                            DECL_ATTRIBUTES (subdatum));
    3042       386364 :   if (attr_counted_by)
    3043              :     {
    3044              :       /* Issue error when the element_type is a structure or
    3045              :         union including a flexible array member.  */
    3046          619 :       if (RECORD_OR_UNION_TYPE_P (element_type)
    3047          619 :           && TYPE_INCLUDES_FLEXARRAY (element_type))
    3048              :         {
    3049            2 :           error_at (loc,
    3050              :                     "%<counted_by%> attribute is not allowed for a pointer to"
    3051              :                     " structure or union with flexible array member");
    3052            2 :           return;
    3053              :         }
    3054              :     }
    3055              : }
    3056              : 
    3057              : /* For a SUBDATUM field of a structure or union DATUM, generate a REF
    3058              :    to the object that represents its counted_by per the attribute
    3059              :    counted_by attached to this field if it's a flexible array member
    3060              :    or a pointer field, otherwise return NULL_TREE.
    3061              :    Set COUNTED_BY_TYPE to the TYPE of the counted_by field.
    3062              :    For example, if:
    3063              : 
    3064              :     struct P {
    3065              :       int k;
    3066              :       int x[] __attribute__ ((counted_by (k)));
    3067              :     } *p;
    3068              : 
    3069              :     for:
    3070              :     p->x
    3071              : 
    3072              :     the ref to the object that represents its element count will be:
    3073              : 
    3074              :     &(p->k)
    3075              : */
    3076              : 
    3077              : static tree
    3078       499454 : build_counted_by_ref (tree datum, tree subdatum,
    3079              :                       tree *counted_by_type)
    3080              : {
    3081       499454 :   tree sub_type = TREE_TYPE (subdatum);
    3082       499454 :   if (!c_flexible_array_member_type_p (sub_type)
    3083       499454 :       && TREE_CODE (sub_type) != POINTER_TYPE)
    3084              :     return NULL_TREE;
    3085              : 
    3086       499454 :   tree attr_counted_by = lookup_attribute ("counted_by",
    3087       499454 :                                            DECL_ATTRIBUTES (subdatum));
    3088       499454 :   if (!attr_counted_by)
    3089              :     return NULL_TREE;
    3090              : 
    3091          472 :   tree counted_by_ref = NULL_TREE;
    3092          472 :   *counted_by_type = NULL_TREE;
    3093              : 
    3094          472 :   tree type = TREE_TYPE (datum);
    3095              : 
    3096              :   /* If the type of the containing structure is an anonymous struct/union,
    3097              :      and this anonymous struct/union is not a root type, get the first
    3098              :      outer named structure/union type.  */
    3099          472 :   while (TREE_CODE (datum) == COMPONENT_REF
    3100           35 :          && c_type_tag (type) == NULL_TREE
    3101          542 :          && DECL_NAME (TREE_OPERAND (datum, 1)) == NULL_TREE)
    3102              :     {
    3103           35 :       datum = TREE_OPERAND (datum, 0);
    3104           35 :       type = TREE_TYPE (datum);
    3105              :     }
    3106              : 
    3107          472 :   tree field_id = TREE_VALUE (TREE_VALUE (attr_counted_by));
    3108          472 :   tree counted_by_field = lookup_field (type, field_id);
    3109          472 :   gcc_assert (counted_by_field);
    3110              : 
    3111          724 :   tree counted_by_subdatum;
    3112          724 :   do
    3113              :     {
    3114          724 :       counted_by_subdatum = TREE_VALUE (counted_by_field);
    3115              :       /* Get the TYPE of the counted_by field.  */
    3116          724 :       *counted_by_type = TREE_TYPE (counted_by_subdatum);
    3117              : 
    3118          724 :       counted_by_ref
    3119          724 :         = build3 (COMPONENT_REF, TREE_TYPE (counted_by_subdatum),
    3120              :                   datum, counted_by_subdatum, NULL_TREE);
    3121              : 
    3122          724 :       datum = counted_by_ref;
    3123          724 :       counted_by_field = TREE_CHAIN (counted_by_field);
    3124              :     }
    3125          724 :   while (counted_by_field);
    3126              : 
    3127          472 :   counted_by_ref = build_fold_addr_expr (counted_by_ref);
    3128          472 :   return counted_by_ref;
    3129              : }
    3130              : 
    3131              : /* Given a COMPONENT_REF REF with the location LOC, the corresponding
    3132              :    COUNTED_BY_REF, and the COUNTED_BY_TYPE, generate the corresponding
    3133              :    call to the internal function .ACCESS_WITH_SIZE.
    3134              : 
    3135              :    A: For the Flexible Array Member, Generate an INDIRECT_REF to a call to
    3136              :    the internal function .ACCESS_WITH_SIZE.
    3137              : 
    3138              :    REF
    3139              : 
    3140              :    to:
    3141              : 
    3142              :    (*.ACCESS_WITH_SIZE (REF, COUNTED_BY_REF, (* TYPE_OF_SIZE)0,
    3143              :                         TYPE_SIZE_UNIT for element)
    3144              : 
    3145              :    NOTE: The return type of this function is the POINTER type pointing
    3146              :    to the original flexible array type.  Then the type of the INDIRECT_REF
    3147              :    is the original flexible array type.
    3148              :    The type of the first argument of this function is a POINTER type
    3149              :    to the original flexible array type.
    3150              : 
    3151              :    B: For pointers with counted_by, generate a call to the internal function
    3152              :    .ACCESS_WITH_SIZE.
    3153              : 
    3154              :     REF
    3155              : 
    3156              :     to:
    3157              : 
    3158              :     .ACCESS_WITH_SIZE (REF, COUNTED_BY_REF, (* TYPE_OF_SIZE)0,
    3159              :                        TYPE_SIZE_UNIT for element)
    3160              : 
    3161              :    NOTE: The return type of this function is the original pointer type.
    3162              :    The type of the first argument of this function is the original
    3163              :    pointer type.
    3164              : 
    3165              :    The 3rd argument of the call is a constant 0 with the pointer TYPE whose
    3166              :    pointee type is the TYPE of the object pointed by COUNTED_BY_REF.
    3167              : 
    3168              :    The 4th argument of the call is the TYPE_SIZE_UNIT of the element TYPE
    3169              :    of the array.
    3170              : 
    3171              :   */
    3172              : static tree
    3173          472 : build_access_with_size_for_counted_by (location_t loc, tree ref,
    3174              :                                        tree counted_by_ref,
    3175              :                                        tree counted_by_type)
    3176              : {
    3177          472 :   gcc_assert (c_flexible_array_member_type_p (TREE_TYPE (ref))
    3178              :               || TREE_CODE (TREE_TYPE (ref)) == POINTER_TYPE);
    3179              : 
    3180          472 :   bool is_fam = c_flexible_array_member_type_p (TREE_TYPE (ref));
    3181              : 
    3182              :   /* The result type of the call is a pointer to the flexible array type;
    3183              :      or is the original ponter type to the pointer field with counted_by.  */
    3184          472 :   tree result_type = is_fam ? c_build_pointer_type (TREE_TYPE (ref))
    3185          271 :                      : TREE_TYPE (ref);
    3186              : 
    3187          472 :   tree element_type = TREE_TYPE (TREE_TYPE (ref));
    3188          472 :   tree element_size = VOID_TYPE_P (element_type)
    3189          472 :                       ? build_one_cst (size_type_node)
    3190          464 :                       : TYPE_SIZE_UNIT (element_type);
    3191              : 
    3192          472 :   tree first_param = is_fam
    3193          472 :                      ? c_fully_fold (array_to_pointer_conversion (loc, ref),
    3194              :                                      false, NULL)
    3195          271 :                      : c_fully_fold (ref, false, NULL);
    3196          472 :   tree second_param
    3197          472 :     = c_fully_fold (counted_by_ref, false, NULL);
    3198          472 :   tree third_param = build_int_cst (c_build_pointer_type (counted_by_type), 0);
    3199              : 
    3200          472 :   tree call
    3201          472 :     = build_call_expr_internal_loc (loc, IFN_ACCESS_WITH_SIZE,
    3202              :                                     result_type, 4,
    3203              :                                     first_param,
    3204              :                                     second_param,
    3205              :                                     third_param,
    3206              :                                     element_size);
    3207              : 
    3208              :   /* Wrap the call with an INDIRECT_REF with the flexible array type.  */
    3209          472 :   if (is_fam)
    3210          201 :     call = build1 (INDIRECT_REF, TREE_TYPE (ref), call);
    3211          472 :   SET_EXPR_LOCATION (call, loc);
    3212          472 :   return call;
    3213              : }
    3214              : 
    3215              : /* For the COMPONENT_REF ref, check whether it has a counted_by attribute,
    3216              :    if so, wrap this COMPONENT_REF with the corresponding CALL to the
    3217              :    function .ACCESS_WITH_SIZE.
    3218              :    Otherwise, return the ref itself.  */
    3219              : 
    3220              : tree
    3221      2260910 : handle_counted_by_for_component_ref (location_t loc, tree ref)
    3222              : {
    3223      2260910 :   gcc_assert (TREE_CODE (ref) == COMPONENT_REF);
    3224      2260910 :   tree datum = TREE_OPERAND (ref, 0);
    3225      2260910 :   tree subdatum = TREE_OPERAND (ref, 1);
    3226      2260910 :   tree counted_by_type = NULL_TREE;
    3227              : 
    3228      2260910 :   if (!(c_flexible_array_member_type_p (TREE_TYPE (ref))
    3229      2190456 :         || TREE_CODE (TREE_TYPE (ref)) == POINTER_TYPE))
    3230              :     return ref;
    3231              : 
    3232       499454 :   tree counted_by_ref = build_counted_by_ref (datum, subdatum,
    3233              :                                               &counted_by_type);
    3234       499454 :   if (counted_by_ref)
    3235          472 :     ref = build_access_with_size_for_counted_by (loc, ref,
    3236              :                                                  counted_by_ref,
    3237              :                                                  counted_by_type);
    3238              :   return ref;
    3239              : }
    3240              : 
    3241              : /* Make an expression to refer to the COMPONENT field of structure or
    3242              :    union value DATUM.  COMPONENT is an IDENTIFIER_NODE.  LOC is the
    3243              :    location of the COMPONENT_REF.  COMPONENT_LOC is the location
    3244              :    of COMPONENT.  ARROW_LOC is the location of the first -> operand if
    3245              :    it is from -> operator.
    3246              :    If HANDLE_COUNTED_BY is true, check the counted_by attribute and generate
    3247              :    a call to .ACCESS_WITH_SIZE.  Otherwise, ignore the attribute.  */
    3248              : 
    3249              : tree
    3250      2267454 : build_component_ref (location_t loc, tree datum, tree component,
    3251              :                      location_t component_loc, location_t arrow_loc)
    3252              : {
    3253      2267454 :   tree type = TREE_TYPE (datum);
    3254      2267454 :   enum tree_code code = TREE_CODE (type);
    3255      2267454 :   tree field = NULL;
    3256      2267454 :   tree ref;
    3257      2267454 :   bool datum_lvalue = lvalue_p (datum);
    3258              : 
    3259      2267454 :   if (!objc_is_public (datum, component))
    3260            0 :     return error_mark_node;
    3261              : 
    3262              :   /* Detect Objective-C property syntax object.property.  */
    3263      2267454 :   if (c_dialect_objc ()
    3264      2267454 :       && (ref = objc_maybe_build_component_ref (datum, component)))
    3265              :     return ref;
    3266              : 
    3267              :   /* See if there is a field or component with name COMPONENT.  */
    3268              : 
    3269      2267454 :   if (code == RECORD_TYPE || code == UNION_TYPE)
    3270              :     {
    3271      2267382 :       if (!COMPLETE_TYPE_P (type))
    3272              :         {
    3273           19 :           c_incomplete_type_error (loc, NULL_TREE, type);
    3274           19 :           return error_mark_node;
    3275              :         }
    3276              : 
    3277      2267363 :       field = lookup_field (type, component);
    3278              : 
    3279      2267363 :       if (!field)
    3280              :         {
    3281           63 :           tree guessed_id = lookup_field_fuzzy (type, component);
    3282           63 :           if (guessed_id)
    3283              :             {
    3284              :               /* Attempt to provide a fixit replacement hint, if
    3285              :                  we have a valid range for the component.  */
    3286            0 :               location_t reported_loc
    3287           26 :                 = (component_loc != UNKNOWN_LOCATION) ? component_loc : loc;
    3288           26 :               gcc_rich_location rich_loc (reported_loc);
    3289           26 :               if (component_loc != UNKNOWN_LOCATION)
    3290           26 :                 rich_loc.add_fixit_misspelled_id (component_loc, guessed_id);
    3291           26 :               error_at (&rich_loc,
    3292              :                         "%qT has no member named %qE; did you mean %qE?",
    3293              :                         type, component, guessed_id);
    3294           26 :             }
    3295              :           else
    3296           37 :             error_at (loc, "%qT has no member named %qE", type, component);
    3297           63 :           return error_mark_node;
    3298              :         }
    3299              : 
    3300              :       /* Accessing elements of atomic structures or unions is undefined
    3301              :          behavior (C11 6.5.2.3#5).  */
    3302      2267300 :       if (TYPE_ATOMIC (type) && c_inhibit_evaluation_warnings == 0)
    3303              :         {
    3304           18 :           if (code == RECORD_TYPE)
    3305           12 :             warning_at (loc, 0, "accessing a member %qE of an atomic "
    3306              :                         "structure %qE", component, datum);
    3307              :           else
    3308            6 :             warning_at (loc, 0, "accessing a member %qE of an atomic "
    3309              :                         "union %qE", component, datum);
    3310              :         }
    3311              : 
    3312              :       /* Chain the COMPONENT_REFs if necessary down to the FIELD.
    3313              :          This might be better solved in future the way the C++ front
    3314              :          end does it - by giving the anonymous entities each a
    3315              :          separate name and type, and then have build_component_ref
    3316              :          recursively call itself.  We can't do that here.  */
    3317      2269484 :       do
    3318              :         {
    3319      2269484 :           tree subdatum = TREE_VALUE (field);
    3320      2269484 :           int quals;
    3321      2269484 :           tree subtype;
    3322      2269484 :           bool use_datum_quals;
    3323              : 
    3324      2269484 :           if (TREE_TYPE (subdatum) == error_mark_node)
    3325              :             return error_mark_node;
    3326              : 
    3327              :           /* If this is an rvalue, it does not have qualifiers in C
    3328              :              standard terms and we must avoid propagating such
    3329              :              qualifiers down to a non-lvalue array that is then
    3330              :              converted to a pointer.  */
    3331      4538968 :           use_datum_quals = (datum_lvalue
    3332      2269484 :                              || TREE_CODE (TREE_TYPE (subdatum)) != ARRAY_TYPE);
    3333              : 
    3334      2269484 :           quals = TYPE_QUALS (strip_array_types (TREE_TYPE (subdatum)));
    3335      2269484 :           if (use_datum_quals)
    3336      2269222 :             quals |= TYPE_QUALS (TREE_TYPE (datum));
    3337      2269484 :           subtype = c_build_qualified_type (TREE_TYPE (subdatum), quals);
    3338              : 
    3339      2269484 :           ref = build3 (COMPONENT_REF, subtype, datum, subdatum,
    3340              :                         NULL_TREE);
    3341      2269484 :           SET_EXPR_LOCATION (ref, loc);
    3342              : 
    3343      2269484 :           check_counted_by_attribute (loc, ref);
    3344              : 
    3345      2269484 :           if (TREE_READONLY (subdatum)
    3346      2269484 :               || (use_datum_quals && TREE_READONLY (datum)))
    3347        30592 :             TREE_READONLY (ref) = 1;
    3348      2269484 :           if (TREE_THIS_VOLATILE (subdatum)
    3349      2268490 :               || (use_datum_quals && TREE_THIS_VOLATILE (datum)))
    3350         2428 :             TREE_THIS_VOLATILE (ref) = 1;
    3351              : 
    3352      2269484 :           if (TREE_UNAVAILABLE (subdatum))
    3353           10 :             error_unavailable_use (subdatum, NULL_TREE);
    3354      2269474 :           else if (TREE_DEPRECATED (subdatum))
    3355           16 :             warn_deprecated_use (subdatum, NULL_TREE);
    3356              : 
    3357      2269484 :           datum = ref;
    3358              : 
    3359      2269484 :           field = TREE_CHAIN (field);
    3360              :         }
    3361      2269484 :       while (field);
    3362              : 
    3363              :       return ref;
    3364              :     }
    3365           72 :   else if (should_suggest_deref_p (type))
    3366              :     {
    3367              :       /* Special-case the error message for "ptr.field" for the case
    3368              :          where the user has confused "." vs "->".  */
    3369            7 :       rich_location richloc (line_table, loc);
    3370            7 :       if (INDIRECT_REF_P (datum) && arrow_loc != UNKNOWN_LOCATION)
    3371              :         {
    3372            2 :           richloc.add_fixit_insert_before (arrow_loc, "(*");
    3373            2 :           richloc.add_fixit_insert_after (arrow_loc, ")");
    3374            2 :           error_at (&richloc,
    3375              :                     "%qE is a pointer to pointer; did you mean to dereference "
    3376              :                     "it before applying %<->%> to it?",
    3377            2 :                     TREE_OPERAND (datum, 0));
    3378              :         }
    3379              :       else
    3380              :         {
    3381              :           /* "loc" should be the "." token.  */
    3382            5 :           richloc.add_fixit_replace ("->");
    3383            5 :           error_at (&richloc,
    3384              :                     "%qE is a pointer; did you mean to use %<->%>?",
    3385              :                     datum);
    3386              :         }
    3387            7 :       return error_mark_node;
    3388            7 :     }
    3389           65 :   else if (code != ERROR_MARK)
    3390            1 :     error_at (loc,
    3391              :               "request for member %qE in something not a structure or union",
    3392              :               component);
    3393              : 
    3394           65 :   return error_mark_node;
    3395              : }
    3396              : 
    3397              : /* Given an expression PTR for a pointer, return an expression
    3398              :    for the value pointed to.
    3399              :    ERRORSTRING is the name of the operator to appear in error messages.
    3400              : 
    3401              :    LOC is the location to use for the generated tree.  */
    3402              : 
    3403              : tree
    3404      2743360 : build_indirect_ref (location_t loc, tree ptr, ref_operator errstring)
    3405              : {
    3406      2743360 :   tree pointer = default_conversion (ptr);
    3407      2743360 :   tree type = TREE_TYPE (pointer);
    3408      2743360 :   tree ref;
    3409              : 
    3410      2743360 :   if (TREE_CODE (type) == POINTER_TYPE)
    3411              :     {
    3412      2743007 :       if (CONVERT_EXPR_P (pointer)
    3413      1963549 :           || TREE_CODE (pointer) == VIEW_CONVERT_EXPR)
    3414              :         {
    3415              :           /* If a warning is issued, mark it to avoid duplicates from
    3416              :              the backend.  This only needs to be done at
    3417              :              warn_strict_aliasing > 2.  */
    3418       779458 :           if (warn_strict_aliasing > 2)
    3419       334865 :             if (strict_aliasing_warning (EXPR_LOCATION (pointer),
    3420       334865 :                                          type, TREE_OPERAND (pointer, 0)))
    3421            7 :               suppress_warning (pointer, OPT_Wstrict_aliasing_);
    3422              :         }
    3423              : 
    3424      2743007 :       if (TREE_CODE (pointer) == ADDR_EXPR
    3425      2743007 :           && (TREE_TYPE (TREE_OPERAND (pointer, 0))
    3426        67422 :               == TREE_TYPE (type)))
    3427              :         {
    3428        67413 :           ref = TREE_OPERAND (pointer, 0);
    3429        67413 :           protected_set_expr_location (ref, loc);
    3430        67413 :           return ref;
    3431              :         }
    3432              :       else
    3433              :         {
    3434      2675594 :           tree t = TREE_TYPE (type);
    3435              : 
    3436      2675594 :           ref = build1 (INDIRECT_REF, t, pointer);
    3437              : 
    3438      2675594 :           if (VOID_TYPE_P (t) && c_inhibit_evaluation_warnings == 0)
    3439          151 :             warning_at (loc, 0, "dereferencing %<void *%> pointer");
    3440              : 
    3441              :           /* We *must* set TREE_READONLY when dereferencing a pointer to const,
    3442              :              so that we get the proper error message if the result is used
    3443              :              to assign to.  Also, &* is supposed to be a no-op.
    3444              :              And ANSI C seems to specify that the type of the result
    3445              :              should be the const type.  */
    3446              :           /* A de-reference of a pointer to const is not a const.  It is valid
    3447              :              to change it via some other pointer.  */
    3448      2675594 :           TREE_READONLY (ref) = TYPE_READONLY (t);
    3449      2675594 :           TREE_SIDE_EFFECTS (ref)
    3450      2675594 :             = TYPE_VOLATILE (t) || TREE_SIDE_EFFECTS (pointer);
    3451      2675594 :           TREE_THIS_VOLATILE (ref) = TYPE_VOLATILE (t);
    3452      2675594 :           protected_set_expr_location (ref, loc);
    3453      2675594 :           return ref;
    3454              :         }
    3455              :     }
    3456          353 :   else if (TREE_CODE (pointer) != ERROR_MARK)
    3457          278 :     invalid_indirection_error (loc, type, errstring);
    3458              : 
    3459          353 :   return error_mark_node;
    3460              : }
    3461              : 
    3462              : /* This handles expressions of the form "a[i]", which denotes
    3463              :    an array reference.
    3464              : 
    3465              :    This is logically equivalent in C to *(a+i), but we may do it differently.
    3466              :    If A is a variable or a member, we generate a primitive ARRAY_REF.
    3467              :    This avoids forcing the array out of registers, and can work on
    3468              :    arrays that are not lvalues (for example, members of structures returned
    3469              :    by functions).
    3470              : 
    3471              :    For vector types, allow vector[i] but not i[vector], and create
    3472              :    *(((type*)&vectortype) + i) for the expression.
    3473              : 
    3474              :    LOC is the location to use for the returned expression.  */
    3475              : 
    3476              : tree
    3477      3464751 : build_array_ref (location_t loc, tree array, tree index)
    3478              : {
    3479      3464751 :   tree ret;
    3480      3464751 :   bool swapped = false;
    3481      3464751 :   if (TREE_TYPE (array) == error_mark_node
    3482      3464751 :       || TREE_TYPE (index) == error_mark_node)
    3483              :     return error_mark_node;
    3484              : 
    3485      3464643 :   if (TREE_CODE (TREE_TYPE (array)) != ARRAY_TYPE
    3486      1990933 :       && TREE_CODE (TREE_TYPE (array)) != POINTER_TYPE
    3487              :       /* Allow vector[index] but not index[vector].  */
    3488      4485299 :       && !gnu_vector_type_p (TREE_TYPE (array)))
    3489              :     {
    3490          194 :       if (TREE_CODE (TREE_TYPE (index)) != ARRAY_TYPE
    3491          194 :           && TREE_CODE (TREE_TYPE (index)) != POINTER_TYPE)
    3492              :         {
    3493            2 :           error_at (loc,
    3494              :             "subscripted value is neither array nor pointer nor vector");
    3495              : 
    3496            2 :           return error_mark_node;
    3497              :         }
    3498          192 :       std::swap (array, index);
    3499          192 :       swapped = true;
    3500              :     }
    3501              : 
    3502      3464641 :   if (!INTEGRAL_TYPE_P (TREE_TYPE (index)))
    3503              :     {
    3504            2 :       error_at (loc, "array subscript is not an integer");
    3505            2 :       return error_mark_node;
    3506              :     }
    3507              : 
    3508      3464639 :   if (TREE_CODE (TREE_TYPE (TREE_TYPE (array))) == FUNCTION_TYPE)
    3509              :     {
    3510           10 :       error_at (loc, "subscripted value is pointer to function");
    3511           10 :       return error_mark_node;
    3512              :     }
    3513              : 
    3514              :   /* ??? Existing practice has been to warn only when the char
    3515              :      index is syntactically the index, not for char[array].  */
    3516      3464629 :   if (!swapped)
    3517      3464443 :      warn_array_subscript_with_type_char (loc, index);
    3518              : 
    3519              :   /* Apply default promotions *after* noticing character types.  */
    3520      3464629 :   index = default_conversion (index);
    3521      3464629 :   if (index == error_mark_node)
    3522              :     return error_mark_node;
    3523              : 
    3524      3464628 :   gcc_assert (TREE_CODE (TREE_TYPE (index)) == INTEGER_TYPE
    3525              :               || TREE_CODE (TREE_TYPE (index)) == BITINT_TYPE);
    3526              : 
    3527      3464628 :   bool was_vector = VECTOR_TYPE_P (TREE_TYPE (array));
    3528      3464628 :   bool non_lvalue = convert_vector_to_array_for_subscript (loc, &array, index);
    3529              : 
    3530              :   /* We only generate a call to .ACCESS_WITH_SIZE when it is a read.  */
    3531      3464628 :   if (TREE_CODE (array) == COMPONENT_REF
    3532      3464628 :       && handle_counted_by_p (array))
    3533       815680 :     array = handle_counted_by_for_component_ref (loc, array);
    3534              : 
    3535      3464628 :   if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE)
    3536              :     {
    3537      2494179 :       tree rval, type;
    3538              : 
    3539              :       /* An array that is indexed by a non-constant
    3540              :          cannot be stored in a register; we must be able to do
    3541              :          address arithmetic on its address.
    3542              :          Likewise an array of elements of variable size.  */
    3543      2494179 :       if (TREE_CODE (index) != INTEGER_CST
    3544      2494179 :           || (COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (array)))
    3545      2020841 :               && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array)))) != INTEGER_CST))
    3546              :         {
    3547       474078 :           if (!c_mark_addressable (array, true, true))
    3548            1 :             return error_mark_node;
    3549              :         }
    3550              :       /* An array that is indexed by a constant value which is not within
    3551              :          the array bounds cannot be stored in a register either; because we
    3552              :          would get a crash in store_bit_field/extract_bit_field when trying
    3553              :          to access a non-existent part of the register.  */
    3554      2494178 :       if (TREE_CODE (index) == INTEGER_CST
    3555      2020841 :           && TYPE_DOMAIN (TREE_TYPE (array))
    3556      4511660 :           && !int_fits_type_p (index, TYPE_DOMAIN (TREE_TYPE (array))))
    3557              :         {
    3558        60649 :           if (!c_mark_addressable (array, false, true))
    3559            0 :             return error_mark_node;
    3560              :           /* ISO C2Y disallows a negative integer constant expression index
    3561              :              when array subscripting has an operand of array type.  */
    3562        60649 :           if (flag_isoc2y
    3563           26 :               && !TREE_OVERFLOW (index)
    3564        60672 :               && tree_int_cst_sgn (index) < 0)
    3565           10 :             error_at (loc, "array subscript is negative");
    3566              :         }
    3567              : 
    3568      2494178 :       if ((pedantic || warn_c90_c99_compat || warn_c23_c2y_compat)
    3569      2470869 :           && ! was_vector)
    3570              :         {
    3571      1472996 :           tree foo = array;
    3572      2307965 :           while (TREE_CODE (foo) == COMPONENT_REF)
    3573       834969 :             foo = TREE_OPERAND (foo, 0);
    3574       973839 :           if ((VAR_P (foo) && C_DECL_REGISTER (foo))
    3575      2446769 :               || (TREE_CODE (foo) == COMPOUND_LITERAL_EXPR
    3576           72 :                   && C_DECL_REGISTER (COMPOUND_LITERAL_EXPR_DECL (foo))))
    3577           78 :             pedwarn_c23 (loc, OPT_Wpedantic,
    3578              :                          "ISO C forbids subscripting %<register%> array "
    3579              :                          "before C2Y");
    3580      1472918 :           else if (!lvalue_p (foo))
    3581          118 :             pedwarn_c90 (loc, OPT_Wpedantic,
    3582              :                          "ISO C90 forbids subscripting non-lvalue "
    3583              :                          "array");
    3584              :         }
    3585              : 
    3586      2494178 :       if (TREE_CODE (TREE_TYPE (index)) == BITINT_TYPE
    3587      2494178 :           && TYPE_PRECISION (TREE_TYPE (index)) > TYPE_PRECISION (sizetype))
    3588            3 :         index = fold_convert (sizetype, index);
    3589              : 
    3590      2494178 :       type = TREE_TYPE (TREE_TYPE (array));
    3591      2494178 :       rval = build4 (ARRAY_REF, type, array, index, NULL_TREE, NULL_TREE);
    3592              :       /* Array ref is const/volatile if the array elements are
    3593              :          or if the array is.  */
    3594      7482534 :       TREE_READONLY (rval)
    3595      2494178 :         |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array)))
    3596      2494178 :             | TREE_READONLY (array));
    3597      7482534 :       TREE_SIDE_EFFECTS (rval)
    3598      2494178 :         |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
    3599      2494178 :             | TREE_SIDE_EFFECTS (array));
    3600      4988356 :       TREE_THIS_VOLATILE (rval)
    3601      2494178 :         |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
    3602              :             /* This was added by rms on 16 Nov 91.
    3603              :                It fixes  vol struct foo *a;  a->elts[1]
    3604              :                in an inline function.
    3605              :                Hope it doesn't break something else.  */
    3606      2494178 :             | TREE_THIS_VOLATILE (array));
    3607      2494178 :       ret = require_complete_type (loc, rval);
    3608      2494178 :       protected_set_expr_location (ret, loc);
    3609      2494178 :       if (non_lvalue)
    3610       104957 :         ret = non_lvalue_loc (loc, ret);
    3611      2494178 :       return ret;
    3612              :     }
    3613              :   else
    3614              :     {
    3615       970449 :       tree ar = default_conversion (array);
    3616              : 
    3617       970449 :       if (ar == error_mark_node)
    3618              :         return ar;
    3619              : 
    3620       970449 :       gcc_assert (TREE_CODE (TREE_TYPE (ar)) == POINTER_TYPE);
    3621       970449 :       gcc_assert (TREE_CODE (TREE_TYPE (TREE_TYPE (ar))) != FUNCTION_TYPE);
    3622              : 
    3623       970449 :       ret = build_indirect_ref (loc, build_binary_op (loc, PLUS_EXPR, ar,
    3624              :                                                       index, false),
    3625              :                                 RO_ARRAY_INDEXING);
    3626       970449 :       if (non_lvalue)
    3627            0 :         ret = non_lvalue_loc (loc, ret);
    3628       970449 :       return ret;
    3629              :     }
    3630              : }
    3631              : 
    3632              : /* Build an OpenMP array section reference, creating an exact type for the
    3633              :    resulting expression based on the element type and bounds if possible.  If
    3634              :    we have variable bounds, create an incomplete array type for the result
    3635              :    instead.  */
    3636              : 
    3637              : tree
    3638         3949 : build_omp_array_section (location_t loc, tree array, tree index, tree length)
    3639              : {
    3640         3949 :   tree type = TREE_TYPE (array);
    3641         3949 :   gcc_assert (type);
    3642              : 
    3643         3949 :   tree sectype, eltype = TREE_TYPE (type);
    3644              : 
    3645              :   /* It's not an array or pointer type.  Just reuse the type of the original
    3646              :      expression as the type of the array section (an error will be raised
    3647              :      anyway, later).  */
    3648         3949 :   if (eltype == NULL_TREE || error_operand_p (eltype))
    3649           12 :     sectype = TREE_TYPE (array);
    3650              :   else
    3651              :     {
    3652         3937 :       tree idxtype = NULL_TREE;
    3653              : 
    3654         3937 :       if (index != NULL_TREE
    3655         3937 :           && length != NULL_TREE
    3656         3010 :           && INTEGRAL_TYPE_P (TREE_TYPE (index))
    3657         6942 :           && INTEGRAL_TYPE_P (TREE_TYPE (length)))
    3658              :         {
    3659         2998 :           tree low = fold_convert (sizetype, index);
    3660         2998 :           tree high = fold_convert (sizetype, length);
    3661         2998 :           high = size_binop (PLUS_EXPR, low, high);
    3662         2998 :           high = size_binop (MINUS_EXPR, high, size_one_node);
    3663         2998 :           idxtype = build_range_type (sizetype, low, high);
    3664              :         }
    3665          135 :       else if ((index == NULL_TREE || integer_zerop (index))
    3666          829 :                && length != NULL_TREE
    3667         1616 :                && INTEGRAL_TYPE_P (TREE_TYPE (length)))
    3668          660 :         idxtype = build_index_type (length);
    3669              : 
    3670         3937 :       gcc_assert (!error_operand_p (idxtype));
    3671              : 
    3672         3937 :       sectype = c_build_array_type (eltype, idxtype);
    3673              :     }
    3674              : 
    3675         3949 :   return build3_loc (loc, OMP_ARRAY_SECTION, sectype, array, index, length);
    3676              : }
    3677              : 
    3678              : 
    3679              : /* Record that REF is used.  This is relevant for undeclared static
    3680              :    function and declarations referenced from a non-local context.
    3681              :    ADDRESS indicates whether the address is taken.  */
    3682              : 
    3683              : void
    3684    472020454 : mark_decl_used (tree ref, bool address)
    3685              : {
    3686    472020454 :   if (!ref || !DECL_P (ref) || in_alignof)
    3687              :     return;
    3688              : 
    3689              :   /* Non-file-scope and non-local reference in nested function.  */
    3690    347446283 :   bool nonloc_p = current_function_decl && DECL_CONTEXT (ref)
    3691    121817203 :                   && DECL_CONTEXT (current_function_decl)
    3692    471986696 :                   && DECL_CONTEXT (ref) != current_function_decl;
    3693              : 
    3694              :   /* An undeclared static function.  */
    3695    471976645 :   bool static_p = TREE_CODE (ref) == FUNCTION_DECL
    3696    101705601 :                   && DECL_INITIAL (ref) == NULL_TREE
    3697     69571321 :                   && DECL_EXTERNAL (ref)
    3698    541545368 :                   && !TREE_PUBLIC (ref);
    3699              : 
    3700    471843223 :   if (!static_p && !nonloc_p)
    3701              :     return;
    3702              : 
    3703              :   /* If we may be in an unevaluated context, delay the decision.  */
    3704       136028 :   if (in_sizeof || in_typeof || in_countof || in_generic)
    3705          270 :     return record_maybe_used_decl (ref, address);
    3706              : 
    3707       135758 :   if (static_p)
    3708       133166 :     C_DECL_USED (ref) = 1;
    3709              : 
    3710       135758 :   if (nonloc_p && (VAR_OR_FUNCTION_DECL_P (ref)
    3711              :                    || TREE_CODE (ref) == PARM_DECL))
    3712         2048 :     DECL_NONLOCAL (ref) = 1;
    3713              : 
    3714              :   /* Nothing to do anymore.  */
    3715         2592 :   if (!nonloc_p || C_FUNC_NONLOCAL_CONTEXT (current_function_decl))
    3716       134567 :     return;
    3717              : 
    3718              :   /* Filter out the cases where referencing a non-local variable does not
    3719              :      require a non-local context passed via the static chain.  */
    3720         1191 :   if (!C_TYPE_VARIABLY_MODIFIED (TREE_TYPE (ref)))
    3721         1135 :     switch (TREE_CODE (ref))
    3722              :       {
    3723          215 :       case FUNCTION_DECL:
    3724              :         /* Use of another local function that requires no context is ok.  */
    3725          215 :         if (!C_FUNC_NONLOCAL_CONTEXT (ref) && DECL_INITIAL (ref))
    3726              :           return;
    3727              :         break;
    3728          438 :       case VAR_DECL:
    3729              :         /* Static variables and constexpr are ok, but for the later only
    3730              :            when the address is not taken.  */
    3731          438 :         if (TREE_STATIC (ref) || (C_DECL_DECLARED_CONSTEXPR (ref) && !address))
    3732              :           return;
    3733              :         break;
    3734              :       case TYPE_DECL:
    3735              :         /* A typedef is ok when not for a variably-modified type. */
    3736              :         return;
    3737              :       case CONST_DECL:
    3738              :         /* An enumeration constant is ok. */
    3739              :         return;
    3740              :       case PARM_DECL:
    3741              :         break;
    3742              :       case LABEL_DECL:
    3743              :         break;
    3744            0 :       default:
    3745            0 :         gcc_unreachable ();
    3746              :     }
    3747              : 
    3748              :   /* Mark all parent functions up to the nesting level of the variable as
    3749              :      as needing the non-local context.  */
    3750         1987 :   for (tree cont = current_function_decl; cont; cont = DECL_CONTEXT (cont))
    3751              :     {
    3752         1987 :       if (cont == DECL_CONTEXT (ref))
    3753              :         break;
    3754              : 
    3755              :       /* There should not be any other type of context used for function
    3756              :          except TRANSLATION_UNIT_DECL which we should be able to reach.  */
    3757          999 :       gcc_checking_assert (TREE_CODE (cont) == FUNCTION_DECL);
    3758              : 
    3759          999 :       if (TREE_CODE (cont) == FUNCTION_DECL)
    3760          999 :         C_FUNC_NONLOCAL_CONTEXT (cont) = 1;
    3761              :     }
    3762              : }
    3763              : 
    3764              : 
    3765              : /* Build an external reference to identifier ID.  FUN indicates
    3766              :    whether this will be used for a function call.  LOC is the source
    3767              :    location of the identifier.  This sets *TYPE to the type of the
    3768              :    identifier, which is not the same as the type of the returned value
    3769              :    for CONST_DECLs defined as enum constants.  If the type of the
    3770              :    identifier is not available, *TYPE is set to NULL.  */
    3771              : tree
    3772    174589300 : build_external_ref (location_t loc, tree id, bool fun, tree *type)
    3773              : {
    3774    174589300 :   tree ref;
    3775    174589300 :   tree decl = lookup_name (id);
    3776              : 
    3777              :   /* In Objective-C, an instance variable (ivar) may be preferred to
    3778              :      whatever lookup_name() found.  */
    3779    174589300 :   decl = objc_lookup_ivar (decl, id);
    3780              : 
    3781    174589300 :   *type = NULL;
    3782    174589300 :   if (decl && decl != error_mark_node)
    3783              :     {
    3784    174583106 :       ref = decl;
    3785    174583106 :       *type = TREE_TYPE (ref);
    3786    174583106 :       if (DECL_P (decl) && C_DECL_UNDERSPECIFIED (decl))
    3787            4 :         error_at (loc, "underspecified %qD referenced in its initializer",
    3788              :                   decl);
    3789              :     }
    3790         6194 :   else if (fun)
    3791              :     /* Implicit function declaration.  */
    3792         4729 :     ref = implicitly_declare (loc, id);
    3793         1465 :   else if (decl == error_mark_node)
    3794              :     /* Don't complain about something that's already been
    3795              :        complained about.  */
    3796              :     return error_mark_node;
    3797              :   else
    3798              :     {
    3799         1231 :       undeclared_variable (loc, id);
    3800         1231 :       return error_mark_node;
    3801              :     }
    3802              : 
    3803              :   /* For an OpenMP map clause, we can get better diagnostics for decls with
    3804              :      unmappable types if we return the decl with an error_mark_node type,
    3805              :      rather than returning error_mark_node for the decl itself.  */
    3806    174587835 :   if (TREE_TYPE (ref) == error_mark_node
    3807    174587835 :       && !c_omp_array_section_p)
    3808              :     return error_mark_node;
    3809              : 
    3810    174587818 :   if (TREE_UNAVAILABLE (ref))
    3811           14 :     error_unavailable_use (ref, NULL_TREE);
    3812    174587804 :   else if (TREE_DEPRECATED (ref))
    3813          100 :     warn_deprecated_use (ref, NULL_TREE);
    3814              : 
    3815              :   /* Recursive call does not count as usage.  */
    3816    174587818 :   if (ref != current_function_decl)
    3817              :     {
    3818    174585185 :       TREE_USED (ref) = 1;
    3819              :     }
    3820              : 
    3821    174587818 :   mark_decl_used (ref, false);
    3822              : 
    3823    174587818 :   if (TREE_CODE (ref) == CONST_DECL)
    3824              :     {
    3825       417276 :       used_types_insert (TREE_TYPE (ref));
    3826              : 
    3827       417276 :       if (warn_cxx_compat
    3828          377 :           && TREE_CODE (TREE_TYPE (ref)) == ENUMERAL_TYPE
    3829       417651 :           && C_TYPE_DEFINED_IN_STRUCT (TREE_TYPE (ref)))
    3830              :         {
    3831            1 :           warning_at (loc, OPT_Wc___compat,
    3832              :                       "enum constant defined in struct or union "
    3833              :                       "is not visible in C++");
    3834            1 :           inform (DECL_SOURCE_LOCATION (ref), "enum constant defined here");
    3835              :         }
    3836              : 
    3837       417276 :       ref = DECL_INITIAL (ref);
    3838       417276 :       TREE_CONSTANT (ref) = 1;
    3839              :     }
    3840              :   /* C99 6.7.4p3: An inline definition of a function with external
    3841              :      linkage ... shall not contain a reference to an identifier with
    3842              :      internal linkage.  */
    3843    174170542 :   else if (current_function_decl != NULL_TREE
    3844    172659526 :            && DECL_DECLARED_INLINE_P (current_function_decl)
    3845    159036218 :            && DECL_EXTERNAL (current_function_decl)
    3846    158263642 :            && VAR_OR_FUNCTION_DECL_P (ref)
    3847     56398845 :            && (!VAR_P (ref) || TREE_STATIC (ref))
    3848     47269666 :            && ! TREE_PUBLIC (ref)
    3849    174170576 :            && DECL_CONTEXT (ref) != current_function_decl)
    3850           25 :     record_inline_static (loc, current_function_decl, ref,
    3851              :                           csi_internal);
    3852              : 
    3853              :   return ref;
    3854              : }
    3855              : 
    3856              : static struct maybe_used_decl *maybe_used_decls;
    3857              : 
    3858              : /* Record that DECL, a reference seen inside sizeof or typeof or _Countof or
    3859              :    _Generic, might be used if the operand of sizeof is a VLA type or the
    3860              :    operand of typeof is a variably modified type or the operand of _Countof has
    3861              :    a variable number of elements or the operand of _Generic is the one selected
    3862              :    as the result.  */
    3863              : 
    3864              : static void
    3865          270 : record_maybe_used_decl (tree decl, bool address)
    3866              : {
    3867          270 :   struct maybe_used_decl *t = XOBNEW (&parser_obstack, struct maybe_used_decl);
    3868          270 :   t->decl = decl;
    3869          270 :   t->level = in_sizeof + in_typeof + in_countof + in_generic;
    3870          270 :   t->address = address;
    3871          270 :   t->next = maybe_used_decls;
    3872          270 :   maybe_used_decls = t;
    3873          270 : }
    3874              : 
    3875              : /* Pop the stack of decls possibly used inside sizeof or typeof or _Countof or
    3876              :    _Generic.  If USED is false, just discard them.  If it is true, mark them
    3877              :    used (if no longer inside sizeof or typeof or _Countof or _Generic) or move
    3878              :    them to the next level up (if still inside sizeof or typeof or _Countof or
    3879              :    _Generic).  */
    3880              : 
    3881              : void
    3882      1466076 : pop_maybe_used (bool used)
    3883              : {
    3884      1466076 :   struct maybe_used_decl *p = maybe_used_decls;
    3885      1466076 :   int cur_level = in_sizeof + in_typeof + in_countof + in_generic;
    3886      1466370 :   while (p && p->level > cur_level)
    3887              :     {
    3888          294 :       if (used)
    3889              :         {
    3890           74 :           if (cur_level == 0)
    3891           50 :             mark_decl_used (p->decl, p->address);
    3892              :           else
    3893           24 :             p->level = cur_level;
    3894              :         }
    3895          294 :       p = p->next;
    3896              :     }
    3897      1466076 :   if (!used || cur_level == 0)
    3898      1465997 :     maybe_used_decls = p;
    3899      1466076 : }
    3900              : 
    3901              : /* Pop the stack of decls possibly used inside sizeof or typeof or _Countof or
    3902              :    _Generic, without acting on them, and return the pointer to the previous top
    3903              :    of the stack.  This for use at the end of a default generic association when
    3904              :    it is not yet known whether the expression is used.  If it later turns out
    3905              :    the expression is used (or treated as used before C23), restore_maybe_used
    3906              :    should be called on the return value followed by pop_maybe_used (true);
    3907              :    otherwise, the return value can be discarded.  */
    3908              : 
    3909              : struct maybe_used_decl *
    3910          514 : save_maybe_used ()
    3911              : {
    3912          514 :   struct maybe_used_decl *p = maybe_used_decls, *orig = p;
    3913          514 :   int cur_level = in_sizeof + in_typeof + in_countof + in_generic;
    3914          546 :   while (p && p->level > cur_level)
    3915           32 :     p = p->next;
    3916          514 :   maybe_used_decls = p;
    3917          514 :   return orig;
    3918              : }
    3919              : 
    3920              : /* Restore the stack of decls possibly used inside sizeof or typeof or _Countof
    3921              :    or _Generic returned by save_maybe_used.  It is required that the stack is
    3922              :    at exactly the point where it was left by save_maybe_used.  */
    3923              : 
    3924              : void
    3925           72 : restore_maybe_used (struct maybe_used_decl *stack)
    3926              : {
    3927           72 :   maybe_used_decls = stack;
    3928           72 : }
    3929              : 
    3930              : /* Return the result of sizeof applied to EXPR.  */
    3931              : 
    3932              : struct c_expr
    3933       312763 : c_expr_sizeof_expr (location_t loc, struct c_expr expr)
    3934              : {
    3935       312763 :   struct c_expr ret;
    3936       312763 :   if (expr.value == error_mark_node)
    3937              :     {
    3938          113 :       ret.value = error_mark_node;
    3939          113 :       ret.original_code = ERROR_MARK;
    3940          113 :       ret.original_type = NULL;
    3941          113 :       ret.m_decimal = 0;
    3942          113 :       pop_maybe_used (false);
    3943              :     }
    3944              :   else
    3945              :     {
    3946       312650 :       bool expr_const_operands = true;
    3947              : 
    3948       312650 :       if (TREE_CODE (expr.value) == PARM_DECL
    3949       312650 :           && C_ARRAY_PARAMETER (expr.value))
    3950              :         {
    3951           55 :           auto_diagnostic_group d;
    3952           55 :           if (warning_at (loc, OPT_Wsizeof_array_argument,
    3953              :                           "%<sizeof%> on array function parameter %qE will "
    3954              :                           "return size of %qT", expr.value,
    3955           55 :                           TREE_TYPE (expr.value)))
    3956           19 :             inform (DECL_SOURCE_LOCATION (expr.value), "declared here");
    3957           55 :         }
    3958       312650 :       tree folded_expr = c_fully_fold (expr.value, require_constant_value,
    3959              :                                        &expr_const_operands);
    3960       312650 :       ret.value = c_sizeof (loc, TREE_TYPE (folded_expr));
    3961       312650 :       c_last_sizeof_arg = expr.value;
    3962       312650 :       c_last_sizeof_loc = loc;
    3963       312650 :       ret.original_code = SIZEOF_EXPR;
    3964       312650 :       ret.original_type = NULL;
    3965       312650 :       ret.m_decimal = 0;
    3966       312650 :       if (C_TYPE_VARIABLE_SIZE (TREE_TYPE (folded_expr)))
    3967              :         {
    3968              :           /* sizeof is evaluated when given a vla (C99 6.5.3.4p2).  */
    3969          288 :           ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
    3970              :                               folded_expr, ret.value);
    3971          288 :           C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !expr_const_operands;
    3972          288 :           SET_EXPR_LOCATION (ret.value, loc);
    3973              :         }
    3974       312650 :       pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (folded_expr)));
    3975              :     }
    3976       312763 :   return ret;
    3977              : }
    3978              : 
    3979              : /* Return the result of sizeof applied to T, a structure for the type
    3980              :    name passed to sizeof (rather than the type itself).  LOC is the
    3981              :    location of the original expression.  */
    3982              : 
    3983              : struct c_expr
    3984       331013 : c_expr_sizeof_type (location_t loc, struct c_type_name *t)
    3985              : {
    3986       331013 :   tree type;
    3987       331013 :   struct c_expr ret;
    3988       331013 :   tree type_expr = NULL_TREE;
    3989       331013 :   bool type_expr_const = true;
    3990       331013 :   type = groktypename (t, &type_expr, &type_expr_const);
    3991       331013 :   ret.value = c_sizeof (loc, type);
    3992       331013 :   c_last_sizeof_arg = type;
    3993       331013 :   c_last_sizeof_loc = loc;
    3994       331013 :   ret.original_code = SIZEOF_EXPR;
    3995       331013 :   ret.original_type = NULL;
    3996       331013 :   ret.m_decimal = 0;
    3997       331013 :   if (type == error_mark_node)
    3998              :     {
    3999            5 :       ret.value = error_mark_node;
    4000            5 :       ret.original_code = ERROR_MARK;
    4001              :     }
    4002              :   else
    4003       330966 :   if ((type_expr || TREE_CODE (ret.value) == INTEGER_CST)
    4004       661889 :       && C_TYPE_VARIABLE_SIZE (type))
    4005              :     {
    4006              :       /* If the type is a [*] array, it is a VLA but is represented as
    4007              :          having a size of zero.  In such a case we must ensure that
    4008              :          the result of sizeof does not get folded to a constant by
    4009              :          c_fully_fold, because if the size is evaluated the result is
    4010              :          not constant and so constraints on zero or negative size
    4011              :          arrays must not be applied when this sizeof call is inside
    4012              :          another array declarator.  */
    4013           41 :       if (!type_expr)
    4014           16 :         type_expr = integer_zero_node;
    4015           41 :       ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
    4016              :                           type_expr, ret.value);
    4017           41 :       C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !type_expr_const;
    4018              :     }
    4019       331013 :   pop_maybe_used (type != error_mark_node
    4020       331013 :                   ? C_TYPE_VARIABLE_SIZE (type) : false);
    4021       331013 :   return ret;
    4022              : }
    4023              : 
    4024              : static bool
    4025          138 : is_top_array_vla (tree type)
    4026              : {
    4027          138 :   bool zero, var;
    4028          138 :   tree d;
    4029              : 
    4030          138 :   if (TREE_CODE (type) != ARRAY_TYPE)
    4031              :     return false;
    4032          120 :   if (!COMPLETE_TYPE_P (type))
    4033              :     return false;
    4034              : 
    4035          116 :   d = TYPE_DOMAIN (type);
    4036          116 :   zero = !TYPE_MAX_VALUE (d);
    4037          116 :   if (zero)
    4038              :     return false;
    4039              : 
    4040          100 :   var = (TREE_CODE (TYPE_MIN_VALUE (d)) != INTEGER_CST
    4041          100 :          || TREE_CODE (TYPE_MAX_VALUE (d)) != INTEGER_CST);
    4042              :   return var;
    4043              : }
    4044              : 
    4045              : /* Return the result of countof applied to EXPR.  */
    4046              : 
    4047              : struct c_expr
    4048           54 : c_expr_countof_expr (location_t loc, struct c_expr expr)
    4049              : {
    4050           54 :   struct c_expr ret;
    4051           54 :   if (expr.value == error_mark_node)
    4052              :     {
    4053            1 :       ret.value = error_mark_node;
    4054            1 :       ret.original_code = ERROR_MARK;
    4055            1 :       ret.original_type = NULL;
    4056            1 :       ret.m_decimal = 0;
    4057            1 :       pop_maybe_used (false);
    4058              :     }
    4059              :   else
    4060              :     {
    4061           53 :       bool expr_const_operands = true;
    4062              : 
    4063           53 :       tree folded_expr = c_fully_fold (expr.value, require_constant_value,
    4064              :                                        &expr_const_operands);
    4065           53 :       ret.value = c_countof_type (loc, TREE_TYPE (folded_expr));
    4066           53 :       c_last_sizeof_arg = expr.value;
    4067           53 :       c_last_sizeof_loc = loc;
    4068           53 :       ret.original_code = COUNTOF_EXPR;
    4069           53 :       ret.original_type = NULL;
    4070           53 :       ret.m_decimal = 0;
    4071           53 :       if (is_top_array_vla (TREE_TYPE (folded_expr)))
    4072              :         {
    4073              :           /* countof is evaluated when given a vla.  */
    4074           11 :           ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
    4075              :                               folded_expr, ret.value);
    4076           11 :           C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !expr_const_operands;
    4077           11 :           SET_EXPR_LOCATION (ret.value, loc);
    4078              :         }
    4079           53 :       pop_maybe_used (is_top_array_vla (TREE_TYPE (folded_expr)));
    4080              :     }
    4081           54 :   return ret;
    4082              : }
    4083              : 
    4084              : /* Return the result of countof applied to T, a structure for the type
    4085              :    name passed to countof (rather than the type itself).  LOC is the
    4086              :    location of the original expression.  */
    4087              : 
    4088              : struct c_expr
    4089           18 : c_expr_countof_type (location_t loc, struct c_type_name *t)
    4090              : {
    4091           18 :   tree type;
    4092           18 :   struct c_expr ret;
    4093           18 :   tree type_expr = NULL_TREE;
    4094           18 :   bool type_expr_const = true;
    4095           18 :   type = groktypename (t, &type_expr, &type_expr_const);
    4096           18 :   ret.value = c_countof_type (loc, type);
    4097           18 :   c_last_sizeof_arg = type;
    4098           18 :   c_last_sizeof_loc = loc;
    4099           18 :   ret.original_code = COUNTOF_EXPR;
    4100           18 :   ret.original_type = NULL;
    4101           18 :   ret.m_decimal = 0;
    4102           18 :   if (type == error_mark_node)
    4103              :     {
    4104            0 :       ret.value = error_mark_node;
    4105            0 :       ret.original_code = ERROR_MARK;
    4106              :     }
    4107              :   else
    4108            8 :   if ((type_expr || TREE_CODE (ret.value) == INTEGER_CST)
    4109           22 :       && is_top_array_vla (type))
    4110              :     {
    4111              :       /* If the type is a [*] array, it is a VLA but is represented as
    4112              :          having a size of zero.  In such a case we must ensure that
    4113              :          the result of countof does not get folded to a constant by
    4114              :          c_fully_fold, because if the number of elements is evaluated
    4115              :          the result is not constant and so
    4116              :          constraints on zero or negative size arrays must not be applied
    4117              :          when this countof call is inside another array declarator.  */
    4118            6 :       if (!type_expr)
    4119            0 :         type_expr = integer_zero_node;
    4120            6 :       ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
    4121              :                           type_expr, ret.value);
    4122            6 :       C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !type_expr_const;
    4123              :     }
    4124           18 :   pop_maybe_used (type != error_mark_node ? is_top_array_vla (type) : false);
    4125           18 :   return ret;
    4126              : }
    4127              : 
    4128              : /* Return the result of maxof applied to T, a structure for the type
    4129              :    name passed to maxof (rather than the type itself).  LOC is the
    4130              :    location of the original expression.  */
    4131              : 
    4132              : struct c_expr
    4133           46 : c_expr_maxof_type (location_t loc, struct c_type_name *t)
    4134              : {
    4135           46 :   tree type;
    4136           46 :   struct c_expr ret;
    4137           46 :   tree type_expr = NULL_TREE;
    4138           46 :   bool type_expr_const = true;
    4139           46 :   type = groktypename (t, &type_expr, &type_expr_const);
    4140           46 :   ret.value = c_maxof_type (loc, type);
    4141           46 :   c_last_sizeof_arg = type;
    4142           46 :   c_last_sizeof_loc = loc;
    4143           46 :   ret.original_code = MAXOF_EXPR;
    4144           46 :   ret.original_type = NULL;
    4145           46 :   ret.m_decimal = 0;
    4146           46 :   if (type == error_mark_node)
    4147              :     {
    4148            0 :       ret.value = error_mark_node;
    4149            0 :       ret.original_code = ERROR_MARK;
    4150              :     }
    4151           46 :   pop_maybe_used (type != error_mark_node);
    4152           46 :   return ret;
    4153              : }
    4154              : 
    4155              : /* Return the result of minof applied to T, a structure for the type
    4156              :    name passed to minof (rather than the type itself).  LOC is the
    4157              :    location of the original expression.  */
    4158              : 
    4159              : struct c_expr
    4160           46 : c_expr_minof_type (location_t loc, struct c_type_name *t)
    4161              : {
    4162           46 :   tree type;
    4163           46 :   struct c_expr ret;
    4164           46 :   tree type_expr = NULL_TREE;
    4165           46 :   bool type_expr_const = true;
    4166           46 :   type = groktypename (t, &type_expr, &type_expr_const);
    4167           46 :   ret.value = c_minof_type (loc, type);
    4168           46 :   c_last_sizeof_arg = type;
    4169           46 :   c_last_sizeof_loc = loc;
    4170           46 :   ret.original_code = MINOF_EXPR;
    4171           46 :   ret.original_type = NULL;
    4172           46 :   ret.m_decimal = 0;
    4173           46 :   if (type == error_mark_node)
    4174              :     {
    4175            0 :       ret.value = error_mark_node;
    4176            0 :       ret.original_code = ERROR_MARK;
    4177              :     }
    4178           46 :   pop_maybe_used (type != error_mark_node);
    4179           46 :   return ret;
    4180              : }
    4181              : 
    4182              : /* Build a function call to function FUNCTION with parameters PARAMS.
    4183              :    The function call is at LOC.
    4184              :    PARAMS is a list--a chain of TREE_LIST nodes--in which the
    4185              :    TREE_VALUE of each node is a parameter-expression.
    4186              :    FUNCTION's data type may be a function type or a pointer-to-function.  */
    4187              : 
    4188              : tree
    4189            0 : build_function_call (location_t loc, tree function, tree params)
    4190              : {
    4191            0 :   vec<tree, va_gc> *v;
    4192            0 :   tree ret;
    4193              : 
    4194            0 :   vec_alloc (v, list_length (params));
    4195            0 :   for (; params; params = TREE_CHAIN (params))
    4196            0 :     v->quick_push (TREE_VALUE (params));
    4197            0 :   ret = c_build_function_call_vec (loc, vNULL, function, v, NULL);
    4198            0 :   vec_free (v);
    4199            0 :   return ret;
    4200              : }
    4201              : 
    4202              : /* Give a note about the location of the declaration of DECL,
    4203              :    or, failing that, a pertinent declaration for FUNCTION_EXPR.  */
    4204              : 
    4205              : static void
    4206          299 : inform_declaration (tree decl, tree function_expr)
    4207              : {
    4208          299 :   if (decl && (TREE_CODE (decl) != FUNCTION_DECL
    4209          278 :                || !DECL_IS_UNDECLARED_BUILTIN (decl)))
    4210          207 :     inform (DECL_SOURCE_LOCATION (decl), "declared here");
    4211           92 :   else if (function_expr)
    4212           92 :     switch (TREE_CODE (function_expr))
    4213              :       {
    4214              :       default:
    4215              :         break;
    4216           13 :       case COMPONENT_REF:
    4217              :         /* Show the decl of the pertinent field (e.g. for callback
    4218              :            fields in a struct.  */
    4219           13 :         {
    4220           13 :           tree field_decl = TREE_OPERAND (function_expr, 1);
    4221           13 :           if (location_t loc = DECL_SOURCE_LOCATION (field_decl))
    4222           13 :             inform (loc, "declared here");
    4223              :         }
    4224              :         break;
    4225              :       }
    4226          299 : }
    4227              : 
    4228              : /* C implementation of callback for use when checking param types.  */
    4229              : 
    4230              : static bool
    4231            2 : comp_parm_types (tree wanted_type, tree actual_type)
    4232              : {
    4233            2 :   return comptypes (wanted_type, actual_type);
    4234              : }
    4235              : 
    4236              : /* Build a function call to function FUNCTION with parameters PARAMS.
    4237              :    If FUNCTION is the result of resolving an overloaded target built-in,
    4238              :    ORIG_FUNDECL is the original function decl, otherwise it is null.
    4239              :    ORIGTYPES, if not NULL, is a vector of types; each element is
    4240              :    either NULL or the original type of the corresponding element in
    4241              :    PARAMS.  The original type may differ from TREE_TYPE of the
    4242              :    parameter for enums.  FUNCTION's data type may be a function type
    4243              :    or pointer-to-function.  This function changes the elements of
    4244              :    PARAMS.  */
    4245              : 
    4246              : tree
    4247     49793888 : build_function_call_vec (location_t loc, vec<location_t> arg_loc,
    4248              :                          tree function, vec<tree, va_gc> *params,
    4249              :                          vec<tree, va_gc> *origtypes, tree orig_fundecl)
    4250              : {
    4251     49793888 :   tree fntype, fundecl = NULL_TREE;
    4252     49793888 :   tree name = NULL_TREE, result;
    4253     49793888 :   tree tem;
    4254     49793888 :   int nargs;
    4255     49793888 :   tree *argarray;
    4256              : 
    4257              : 
    4258              :   /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
    4259     49793888 :   STRIP_TYPE_NOPS (function);
    4260              : 
    4261              :   /* Convert anything with function type to a pointer-to-function.  */
    4262     49793888 :   if (TREE_CODE (function) == FUNCTION_DECL)
    4263              :     {
    4264     49716500 :       name = DECL_NAME (function);
    4265              : 
    4266     49716500 :       if (flag_tm)
    4267          421 :         tm_malloc_replacement (function);
    4268     49716500 :       fundecl = function;
    4269     49716500 :       if (!orig_fundecl)
    4270     49716500 :         orig_fundecl = fundecl;
    4271              :       /* Atomic functions have type checking/casting already done.  They are
    4272              :          often rewritten and don't match the original parameter list.  */
    4273     99433000 :       if (name && startswith (IDENTIFIER_POINTER (name), "__atomic_"))
    4274              :         origtypes = NULL;
    4275              :     }
    4276     49793888 :   if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE)
    4277     49730943 :     function = function_to_pointer_conversion (loc, function);
    4278              : 
    4279              :   /* For Objective-C, convert any calls via a cast to OBJC_TYPE_REF
    4280              :      expressions, like those used for ObjC messenger dispatches.  */
    4281     49793888 :   if (params && !params->is_empty ())
    4282     38102257 :     function = objc_rewrite_function_call (function, (*params)[0]);
    4283              : 
    4284     49793888 :   function = c_fully_fold (function, false, NULL);
    4285              : 
    4286     49793888 :   fntype = TREE_TYPE (function);
    4287              : 
    4288     49793888 :   if (TREE_CODE (fntype) == ERROR_MARK)
    4289            5 :     return error_mark_node;
    4290              : 
    4291     49793883 :   if (!(TREE_CODE (fntype) == POINTER_TYPE
    4292     49793849 :         && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE))
    4293              :     {
    4294           37 :       if (!flag_diagnostics_show_caret && !STATEMENT_CLASS_P (function))
    4295           33 :         error_at (loc,
    4296              :                   "called object %qE is not a function or function pointer",
    4297              :                   function);
    4298            4 :       else if (DECL_P (function))
    4299              :         {
    4300            1 :           auto_diagnostic_group d;
    4301            1 :           error_at (loc,
    4302              :                     "called object %qD is not a function or function pointer",
    4303              :                     function);
    4304            1 :           inform_declaration (function, NULL_TREE);
    4305            1 :         }
    4306              :       else
    4307            3 :         error_at (loc,
    4308              :                   "called object is not a function or function pointer");
    4309           37 :       return error_mark_node;
    4310              :     }
    4311              : 
    4312     49793846 :   if (fundecl && TREE_THIS_VOLATILE (fundecl))
    4313       374300 :     current_function_returns_abnormally = 1;
    4314              : 
    4315              :   /* fntype now gets the type of function pointed to.  */
    4316     49793846 :   fntype = TREE_TYPE (fntype);
    4317     49793846 :   tree return_type = TREE_TYPE (fntype);
    4318              : 
    4319              :   /* Convert the parameters to the types declared in the
    4320              :      function prototype, or apply default promotions.  */
    4321              : 
    4322     49793846 :   nargs = convert_arguments (loc, arg_loc, fntype, params,
    4323              :                              origtypes, function, fundecl);
    4324     49793846 :   if (nargs < 0)
    4325          178 :     return error_mark_node;
    4326              : 
    4327              :   /* Check that the function is called through a compatible prototype.
    4328              :      If it is not, warn.  */
    4329     49792761 :   if (CONVERT_EXPR_P (function)
    4330          923 :       && TREE_CODE (tem = TREE_OPERAND (function, 0)) == ADDR_EXPR
    4331          215 :       && TREE_CODE (tem = TREE_OPERAND (tem, 0)) == FUNCTION_DECL
    4332     49793853 :       && !comptypes (fntype, TREE_TYPE (tem)))
    4333              :     {
    4334              :       /* This situation leads to run-time undefined behavior.  We can't,
    4335              :          therefore, simply error unless we can prove that all possible
    4336              :          executions of the program must execute the code.  */
    4337           20 :       warning_at (loc, 0, "function called through a non-compatible type");
    4338              : 
    4339           20 :       if (VOID_TYPE_P (return_type)
    4340           20 :           && TYPE_QUALS (return_type) != TYPE_UNQUALIFIED)
    4341            1 :         pedwarn (loc, 0,
    4342              :                  "function with qualified void return type called");
    4343              :      }
    4344              : 
    4345     49793668 :   argarray = vec_safe_address (params);
    4346              : 
    4347              :   /* Check that arguments to builtin functions match the expectations.  */
    4348     49793668 :   if (fundecl
    4349     49716337 :       && fndecl_built_in_p (fundecl)
    4350     82972567 :       && !check_builtin_function_arguments (loc, arg_loc, fundecl,
    4351              :                                             orig_fundecl, nargs, argarray))
    4352          298 :     return error_mark_node;
    4353              : 
    4354              :   /* Check that the arguments to the function are valid.  */
    4355     49793370 :   bool warned_p = check_function_arguments (loc, fundecl, fntype,
    4356              :                                             nargs, argarray, &arg_loc,
    4357              :                                             comp_parm_types);
    4358              : 
    4359     49793370 :   if (TYPE_QUALS (return_type) != TYPE_UNQUALIFIED
    4360     49793370 :       && !VOID_TYPE_P (return_type))
    4361           11 :     return_type = c_build_qualified_type (return_type, TYPE_UNQUALIFIED);
    4362     49793370 :   if (name != NULL_TREE
    4363     99509409 :       && startswith (IDENTIFIER_POINTER (name), "__builtin_"))
    4364              :     {
    4365     32459137 :       if (require_constant_value)
    4366         3486 :         result
    4367         3486 :           = fold_build_call_array_initializer_loc (loc, return_type,
    4368              :                                                    function, nargs, argarray);
    4369              :       else
    4370     32455651 :         result = fold_build_call_array_loc (loc, return_type,
    4371              :                                             function, nargs, argarray);
    4372     32459137 :       if (TREE_CODE (result) == NOP_EXPR
    4373     32459137 :           && TREE_CODE (TREE_OPERAND (result, 0)) == INTEGER_CST)
    4374        26434 :         STRIP_TYPE_NOPS (result);
    4375              :     }
    4376              :   else
    4377     17334233 :     result = build_call_array_loc (loc, return_type,
    4378              :                                    function, nargs, argarray);
    4379              :   /* If -Wnonnull warning has been diagnosed, avoid diagnosing it again
    4380              :      later.  */
    4381     49793370 :   if (warned_p && TREE_CODE (result) == CALL_EXPR)
    4382          215 :     suppress_warning (result, OPT_Wnonnull);
    4383              : 
    4384              :   /* In this improbable scenario, a nested function returns a VM type.
    4385              :      Create a TARGET_EXPR so that the call always has a LHS, much as
    4386              :      what the C++ FE does for functions returning non-PODs.  */
    4387     49793370 :   if (C_TYPE_VARIABLY_MODIFIED (TREE_TYPE (fntype)))
    4388              :     {
    4389           81 :       tree tmp = create_tmp_var_raw (TREE_TYPE (fntype));
    4390           81 :       result = build4 (TARGET_EXPR, TREE_TYPE (fntype), tmp, result,
    4391              :                        NULL_TREE, NULL_TREE);
    4392              :     }
    4393              : 
    4394     49793370 :   if (VOID_TYPE_P (TREE_TYPE (result)))
    4395              :     {
    4396      2387068 :       if (TYPE_QUALS (TREE_TYPE (result)) != TYPE_UNQUALIFIED)
    4397            2 :         pedwarn (loc, 0,
    4398              :                  "function with qualified void return type called");
    4399      2387068 :       return result;
    4400              :     }
    4401     47406302 :   return require_complete_type (loc, result);
    4402              : }
    4403              : 
    4404              : /* Like build_function_call_vec, but call also resolve_overloaded_builtin.  */
    4405              : 
    4406              : tree
    4407     49793445 : c_build_function_call_vec (location_t loc, const vec<location_t> &arg_loc,
    4408              :                            tree function, vec<tree, va_gc> *params,
    4409              :                            vec<tree, va_gc> *origtypes)
    4410              : {
    4411              :   /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
    4412     49793456 :   STRIP_TYPE_NOPS (function);
    4413              : 
    4414              :   /* Convert anything with function type to a pointer-to-function.  */
    4415     49793445 :   if (TREE_CODE (function) == FUNCTION_DECL)
    4416              :     {
    4417              :       /* Implement type-directed function overloading for builtins.
    4418              :          resolve_overloaded_builtin and targetm.resolve_overloaded_builtin
    4419              :          handle all the type checking.  The result is a complete expression
    4420              :          that implements this function call.  */
    4421     49716057 :       tree tem = resolve_overloaded_builtin (loc, function, params);
    4422     49716057 :       if (tem)
    4423              :         return tem;
    4424              :     }
    4425     49707543 :   return build_function_call_vec (loc, arg_loc, function, params, origtypes);
    4426              : }
    4427              : 
    4428              : /* Helper for convert_arguments called to convert the VALue of argument
    4429              :    number ARGNUM from ORIGTYPE to the corresponding parameter number
    4430              :    PARMNUM and TYPE.
    4431              :    PLOC is the location where the conversion is being performed.
    4432              :    FUNCTION and FUNDECL are the same as in convert_arguments.
    4433              :    VALTYPE is the original type of VAL before the conversion and,
    4434              :    for EXCESS_PRECISION_EXPR, the operand of the expression.
    4435              :    NPC is true if VAL represents the null pointer constant (VAL itself
    4436              :    will have been folded to an integer constant).
    4437              :    RNAME is the same as FUNCTION except in Objective C when it's
    4438              :    the function selector.
    4439              :    EXCESS_PRECISION is true when VAL was originally represented
    4440              :    as EXCESS_PRECISION_EXPR.
    4441              :    WARNOPT is the same as in convert_for_assignment.  */
    4442              : 
    4443              : static tree
    4444    125351265 : convert_argument (location_t ploc, tree function, tree fundecl,
    4445              :                   tree type, tree origtype, tree val, tree valtype,
    4446              :                   bool npc, tree rname, int parmnum, int argnum,
    4447              :                   bool excess_precision, int warnopt)
    4448              : {
    4449              :   /* Formal parm type is specified by a function prototype.  */
    4450              : 
    4451    125351265 :   if (type == error_mark_node || !COMPLETE_TYPE_P (type))
    4452              :     {
    4453            3 :       error_at (ploc, "type of formal parameter %d is incomplete",
    4454              :                 parmnum + 1);
    4455            3 :       return error_mark_node;
    4456              :     }
    4457              : 
    4458              :   /* Optionally warn about conversions that differ from the default
    4459              :      conversions.  */
    4460    125351262 :   if (warn_traditional_conversion || warn_traditional)
    4461              :     {
    4462          193 :       if (INTEGRAL_TYPE_P (type)
    4463          107 :           && SCALAR_FLOAT_TYPE_P (valtype))
    4464           19 :         warning_at (ploc, OPT_Wtraditional_conversion,
    4465              :                     "passing argument %d of %qE as integer rather "
    4466              :                     "than floating due to prototype",
    4467              :                     argnum, rname);
    4468          193 :       if (INTEGRAL_TYPE_P (type)
    4469          107 :           && TREE_CODE (valtype) == COMPLEX_TYPE)
    4470            5 :         warning_at (ploc, OPT_Wtraditional_conversion,
    4471              :                     "passing argument %d of %qE as integer rather "
    4472              :                     "than complex due to prototype",
    4473              :                     argnum, rname);
    4474          188 :       else if (TREE_CODE (type) == COMPLEX_TYPE
    4475           14 :                && SCALAR_FLOAT_TYPE_P (valtype))
    4476            7 :         warning_at (ploc, OPT_Wtraditional_conversion,
    4477              :                     "passing argument %d of %qE as complex rather "
    4478              :                     "than floating due to prototype",
    4479              :                     argnum, rname);
    4480          181 :       else if (SCALAR_FLOAT_TYPE_P (type)
    4481           71 :                && INTEGRAL_TYPE_P (valtype))
    4482           19 :         warning_at (ploc, OPT_Wtraditional_conversion,
    4483              :                     "passing argument %d of %qE as floating rather "
    4484              :                     "than integer due to prototype",
    4485              :                     argnum, rname);
    4486          162 :       else if (TREE_CODE (type) == COMPLEX_TYPE
    4487            7 :                && INTEGRAL_TYPE_P (valtype))
    4488            5 :         warning_at (ploc, OPT_Wtraditional_conversion,
    4489              :                     "passing argument %d of %qE as complex rather "
    4490              :                     "than integer due to prototype",
    4491              :                     argnum, rname);
    4492          157 :       else if (SCALAR_FLOAT_TYPE_P (type)
    4493           52 :                && TREE_CODE (valtype) == COMPLEX_TYPE)
    4494            7 :         warning_at (ploc, OPT_Wtraditional_conversion,
    4495              :                     "passing argument %d of %qE as floating rather "
    4496              :                     "than complex due to prototype",
    4497              :                     argnum, rname);
    4498              :       /* ??? At some point, messages should be written about
    4499              :          conversions between complex types, but that's too messy
    4500              :          to do now.  */
    4501          150 :       else if (SCALAR_FLOAT_TYPE_P (type)
    4502           45 :                && SCALAR_FLOAT_TYPE_P (valtype))
    4503              :         {
    4504           45 :           unsigned int formal_prec = TYPE_PRECISION (type);
    4505              : 
    4506              :           /* Warn if any argument is passed as `float',
    4507              :              since without a prototype it would be `double'.  */
    4508           45 :           if (formal_prec == TYPE_PRECISION (float_type_node)
    4509           45 :               && type != dfloat32_type_node)
    4510            7 :             warning_at (ploc, 0,
    4511              :                         "passing argument %d of %qE as %<float%> "
    4512              :                         "rather than %<double%> due to prototype",
    4513              :                         argnum, rname);
    4514              : 
    4515              :           /* Warn if mismatch between argument and prototype
    4516              :              for decimal float types.  Warn of conversions with
    4517              :              binary float types and of precision narrowing due to
    4518              :              prototype.  */
    4519           38 :           else if (type != valtype
    4520           32 :                    && (type == dfloat32_type_node
    4521           22 :                        || type == dfloat64_type_node
    4522           12 :                        || type == dfloat128_type_node
    4523            2 :                        || valtype == dfloat32_type_node
    4524            2 :                        || valtype == dfloat64_type_node
    4525            2 :                        || valtype == dfloat128_type_node)
    4526           38 :                    && (formal_prec
    4527           30 :                        <= TYPE_PRECISION (valtype)
    4528           14 :                        || (type == dfloat128_type_node
    4529           10 :                            && (valtype
    4530           10 :                                != dfloat64_type_node
    4531            8 :                                && (valtype
    4532              :                                    != dfloat32_type_node)))
    4533            8 :                        || (type == dfloat64_type_node
    4534            4 :                            && (valtype
    4535              :                                != dfloat32_type_node))))
    4536           24 :             warning_at (ploc, 0,
    4537              :                         "passing argument %d of %qE as %qT "
    4538              :                         "rather than %qT due to prototype",
    4539              :                         argnum, rname, type, valtype);
    4540              : 
    4541              :         }
    4542              :       /* Detect integer changing in width or signedness.
    4543              :          These warnings are only activated with
    4544              :          -Wtraditional-conversion, not with -Wtraditional.  */
    4545          105 :       else if (warn_traditional_conversion
    4546          105 :                && INTEGRAL_TYPE_P (type)
    4547          102 :                && INTEGRAL_TYPE_P (valtype))
    4548              :         {
    4549           83 :           unsigned int formal_prec = TYPE_PRECISION (type);
    4550           83 :           tree would_have_been = default_conversion (val);
    4551           83 :           tree type1 = TREE_TYPE (would_have_been);
    4552              : 
    4553           83 :           if (val == error_mark_node)
    4554              :             /* VAL could have been of incomplete type.  */;
    4555           83 :           else if (TREE_CODE (type) == ENUMERAL_TYPE
    4556           83 :                    && (TYPE_MAIN_VARIANT (type)
    4557            2 :                        == TYPE_MAIN_VARIANT (valtype)))
    4558              :             /* No warning if function asks for enum
    4559              :                and the actual arg is that enum type.  */
    4560              :             ;
    4561           81 :           else if (formal_prec != TYPE_PRECISION (type1))
    4562           14 :             warning_at (ploc, OPT_Wtraditional_conversion,
    4563              :                         "passing argument %d of %qE "
    4564              :                         "with different width due to prototype",
    4565              :                         argnum, rname);
    4566           67 :           else if (TYPE_UNSIGNED (type) == TYPE_UNSIGNED (type1))
    4567              :             ;
    4568              :           /* Don't complain if the formal parameter type
    4569              :              is an enum, because we can't tell now whether
    4570              :              the value was an enum--even the same enum.  */
    4571           32 :           else if (TREE_CODE (type) == ENUMERAL_TYPE)
    4572              :             ;
    4573           32 :           else if (TREE_CODE (val) == INTEGER_CST
    4574            5 :                    && int_fits_type_p (val, type))
    4575              :             /* Change in signedness doesn't matter
    4576              :                if a constant value is unaffected.  */
    4577              :             ;
    4578              :           /* If the value is extended from a narrower
    4579              :              unsigned type, it doesn't matter whether we
    4580              :              pass it as signed or unsigned; the value
    4581              :              certainly is the same either way.  */
    4582           32 :           else if (TYPE_PRECISION (valtype) < TYPE_PRECISION (type)
    4583           32 :                    && TYPE_UNSIGNED (valtype))
    4584              :             ;
    4585           32 :           else if (TYPE_UNSIGNED (type))
    4586           17 :             warning_at (ploc, OPT_Wtraditional_conversion,
    4587              :                         "passing argument %d of %qE "
    4588              :                         "as unsigned due to prototype",
    4589              :                         argnum, rname);
    4590              :           else
    4591           15 :             warning_at (ploc, OPT_Wtraditional_conversion,
    4592              :                         "passing argument %d of %qE "
    4593              :                         "as signed due to prototype",
    4594              :                         argnum, rname);
    4595              :         }
    4596              :     }
    4597              : 
    4598              :   /* Possibly restore an EXCESS_PRECISION_EXPR for the
    4599              :      sake of better warnings from convert_and_check.  */
    4600    125351262 :   if (excess_precision)
    4601          370 :     val = build1 (EXCESS_PRECISION_EXPR, valtype, val);
    4602              : 
    4603    125351262 :   tree parmval = convert_for_assignment (ploc, ploc, type,
    4604              :                                          val, origtype, ic_argpass,
    4605              :                                          npc, fundecl, function,
    4606              :                                          parmnum + 1, warnopt);
    4607    125351262 :   return parmval;
    4608              : }
    4609              : 
    4610              : /* Convert the argument expressions in the vector VALUES
    4611              :    to the types in the list TYPE_ARG_TYPES (FNTYPE).
    4612              : 
    4613              :    If the list is exhausted, or when an element has NULL as its type,
    4614              :    perform the default conversions.
    4615              : 
    4616              :    ORIGTYPES is the original types of the expressions in VALUES.  This
    4617              :    holds the type of enum values which have been converted to integral
    4618              :    types.  It may be NULL.
    4619              : 
    4620              :    FUNCTION is a tree for the called function.  It is used only for
    4621              :    error messages, where it is formatted with %qE.
    4622              : 
    4623              :    This is also where warnings about wrong number of args are generated.
    4624              : 
    4625              :    ARG_LOC are locations of function arguments (if any).
    4626              : 
    4627              :    Returns the actual number of arguments processed (which may be less
    4628              :    than the length of VALUES in some error situations), or -1 on
    4629              :    failure.  */
    4630              : 
    4631              : static int
    4632     49793846 : convert_arguments (location_t loc, vec<location_t> arg_loc, tree fntype,
    4633              :                    vec<tree, va_gc> *values, vec<tree, va_gc> *origtypes,
    4634              :                    tree function, tree fundecl)
    4635              : {
    4636     49793846 :   tree typelist = TYPE_ARG_TYPES (fntype);
    4637     49793846 :   unsigned int parmnum;
    4638     49793846 :   bool error_args = false;
    4639     49793846 :   const bool type_generic = fundecl
    4640     49793846 :     && lookup_attribute ("type generic", TYPE_ATTRIBUTES (TREE_TYPE (fundecl)));
    4641     49793846 :   bool type_generic_remove_excess_precision = false;
    4642     49793846 :   bool type_generic_overflow_p = false;
    4643     49793846 :   bool type_generic_bit_query = false;
    4644     49793846 :   tree selector;
    4645              : 
    4646              :   /* Change pointer to function to the function itself for
    4647              :      diagnostics.  */
    4648     49793846 :   if (TREE_CODE (function) == ADDR_EXPR
    4649     49793846 :       && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL)
    4650     49718598 :     function = TREE_OPERAND (function, 0);
    4651              : 
    4652              :   /* Handle an ObjC selector specially for diagnostics.  */
    4653     49793846 :   selector = objc_message_selector ();
    4654              : 
    4655              :   /* For a call to a built-in function declared without a prototype,
    4656              :      set to the built-in function's argument list.  */
    4657     49793846 :   tree builtin_typelist = NULL_TREE;
    4658              : 
    4659              :   /* For type-generic built-in functions, determine whether excess
    4660              :      precision should be removed (classification) or not
    4661              :      (comparison).  */
    4662     49793846 :   if (fundecl
    4663     49793846 :       && fndecl_built_in_p (fundecl, BUILT_IN_NORMAL))
    4664              :     {
    4665      1395721 :       built_in_function code = DECL_FUNCTION_CODE (fundecl);
    4666      1395721 :       if (C_DECL_BUILTIN_PROTOTYPE (fundecl))
    4667              :         {
    4668              :           /* For a call to a built-in function declared without a prototype
    4669              :              use the types of the parameters of the internal built-in to
    4670              :              match those of the arguments to.  */
    4671       689212 :           if (tree bdecl = builtin_decl_explicit (code))
    4672       689212 :             builtin_typelist = TYPE_ARG_TYPES (TREE_TYPE (bdecl));
    4673              :         }
    4674              : 
    4675              :       /* For type-generic built-in functions, determine whether excess
    4676              :          precision should be removed (classification) or not
    4677              :          (comparison).  */
    4678      1395721 :       if (type_generic)
    4679        60878 :         switch (code)
    4680              :           {
    4681         5380 :           case BUILT_IN_ISFINITE:
    4682         5380 :           case BUILT_IN_ISINF:
    4683         5380 :           case BUILT_IN_ISINF_SIGN:
    4684         5380 :           case BUILT_IN_ISNAN:
    4685         5380 :           case BUILT_IN_ISNORMAL:
    4686         5380 :           case BUILT_IN_ISSIGNALING:
    4687         5380 :           case BUILT_IN_FPCLASSIFY:
    4688         5380 :             type_generic_remove_excess_precision = true;
    4689         5380 :             break;
    4690              : 
    4691        21026 :           case BUILT_IN_ADD_OVERFLOW_P:
    4692        21026 :           case BUILT_IN_SUB_OVERFLOW_P:
    4693        21026 :           case BUILT_IN_MUL_OVERFLOW_P:
    4694              :             /* The last argument of these type-generic builtins
    4695              :                should not be promoted.  */
    4696        21026 :             type_generic_overflow_p = true;
    4697        21026 :             break;
    4698              : 
    4699         1294 :           case BUILT_IN_CLZG:
    4700         1294 :           case BUILT_IN_CTZG:
    4701         1294 :           case BUILT_IN_CLRSBG:
    4702         1294 :           case BUILT_IN_FFSG:
    4703         1294 :           case BUILT_IN_PARITYG:
    4704         1294 :           case BUILT_IN_POPCOUNTG:
    4705              :             /* The first argument of these type-generic builtins
    4706              :                should not be promoted.  */
    4707         1294 :             type_generic_bit_query = true;
    4708         1294 :             break;
    4709              : 
    4710              :           default:
    4711              :             break;
    4712              :           }
    4713              :     }
    4714              : 
    4715              :   /* Scan the given expressions (VALUES) and types (TYPELIST), producing
    4716              :      individual converted arguments.  */
    4717              : 
    4718     49793846 :   tree typetail, builtin_typetail, val;
    4719     49793846 :   for (typetail = typelist,
    4720     49793846 :          builtin_typetail = builtin_typelist,
    4721     49793846 :          parmnum = 0;
    4722    176079396 :        values && values->iterate (parmnum, &val);
    4723              :        ++parmnum)
    4724              :     {
    4725              :       /* The type of the function parameter (if it was declared with one).  */
    4726    251634965 :       tree type = typetail ? TREE_VALUE (typetail) : NULL_TREE;
    4727              :       /* The type of the built-in function parameter (if the function
    4728              :          is a built-in).  Used to detect type incompatibilities in
    4729              :          calls to built-ins declared without a prototype.  */
    4730    126285586 :       tree builtin_type = (builtin_typetail
    4731    127320997 :                            ? TREE_VALUE (builtin_typetail) : NULL_TREE);
    4732              :       /* The original type of the argument being passed to the function.  */
    4733    126285586 :       tree valtype = TREE_TYPE (val);
    4734              :       /* The called function (or function selector in Objective C).  */
    4735    126285586 :       tree rname = function;
    4736    126285586 :       int argnum = parmnum + 1;
    4737    126285586 :       const char *invalid_func_diag;
    4738              :       /* Set for EXCESS_PRECISION_EXPR arguments.  */
    4739    126285586 :       bool excess_precision = false;
    4740              :       /* The value of the argument after conversion to the type
    4741              :          of the function parameter it is passed to.  */
    4742    126285586 :       tree parmval;
    4743              :       /* Some __atomic_* builtins have additional hidden argument at
    4744              :          position 0.  */
    4745    126285586 :       location_t ploc
    4746    126016878 :         = !arg_loc.is_empty () && values->length () == arg_loc.length ()
    4747    126016278 :           ? expansion_point_location_if_in_system_header (arg_loc[parmnum])
    4748    126285586 :           : input_location;
    4749              : 
    4750    126285586 :       if (type == void_type_node)
    4751              :         {
    4752           33 :           auto_diagnostic_group d;
    4753           33 :           int num_expected = parmnum;
    4754           33 :           int num_actual = values->length ();
    4755           33 :           gcc_rich_location rich_loc (loc);
    4756           33 :           if (ploc != input_location)
    4757           32 :             rich_loc.add_range (ploc);
    4758           33 :           if (selector)
    4759            0 :             error_at (&rich_loc,
    4760              :                       "too many arguments to method %qE; expected %i, have %i",
    4761              :                       selector, num_expected, num_actual);
    4762              :           else
    4763           33 :             error_at (&rich_loc,
    4764              :                       "too many arguments to function %qE; expected %i, have %i",
    4765              :                       function, num_expected, num_actual);
    4766           33 :           inform_declaration (fundecl, function);
    4767           65 :           return error_args ? -1 : (int) parmnum;
    4768           33 :         }
    4769              : 
    4770    126285553 :       if (builtin_type == void_type_node)
    4771              :         {
    4772           12 :           auto_diagnostic_group d;
    4773           12 :           if (warning_at (loc, OPT_Wbuiltin_declaration_mismatch,
    4774              :                           "too many arguments to built-in function %qE "
    4775              :                           "expecting %d", function, parmnum))
    4776           12 :             inform_declaration (fundecl, function);
    4777           12 :           builtin_typetail = NULL_TREE;
    4778           12 :         }
    4779              : 
    4780        90352 :       if (!typetail && parmnum == 0 && !TYPE_NO_NAMED_ARGS_STDARG_P (fntype)
    4781    126375788 :           && !(fundecl && fndecl_built_in_p (fundecl)))
    4782              :         {
    4783         6963 :           auto_diagnostic_group d;
    4784         6963 :           bool warned;
    4785         6963 :           if (selector)
    4786            0 :             warned = warning_at (loc, OPT_Wdeprecated_non_prototype,
    4787              :                                  "ISO C23 does not allow arguments"
    4788              :                                  " for method %qE declared without parameters",
    4789              :                                  function);
    4790              :           else
    4791         6963 :             warned = warning_at (loc, OPT_Wdeprecated_non_prototype,
    4792              :                                  "ISO C23 does not allow arguments"
    4793              :                                  " for function %qE declared without parameters",
    4794              :                                  function);
    4795         6963 :           if (warned)
    4796            4 :             inform_declaration (fundecl, function);
    4797         6963 :         }
    4798              : 
    4799    126285553 :       if (selector && argnum > 2)
    4800              :         {
    4801            0 :           rname = selector;
    4802            0 :           argnum -= 2;
    4803              :         }
    4804              : 
    4805              :       /* Determine if VAL is a null pointer constant before folding it.  */
    4806    126285553 :       bool npc = null_pointer_constant_p (val);
    4807              : 
    4808              :       /* If there is excess precision and a prototype, convert once to
    4809              :          the required type rather than converting via the semantic
    4810              :          type.  Likewise without a prototype a float value represented
    4811              :          as long double should be converted once to double.  But for
    4812              :          type-generic classification functions excess precision must
    4813              :          be removed here.  */
    4814    126285553 :       if (TREE_CODE (val) == EXCESS_PRECISION_EXPR
    4815          423 :           && (type || !type_generic || !type_generic_remove_excess_precision))
    4816              :         {
    4817          403 :           val = TREE_OPERAND (val, 0);
    4818          403 :           excess_precision = true;
    4819              :         }
    4820    126285553 :       val = c_fully_fold (val, false, NULL);
    4821    252571107 :       STRIP_TYPE_NOPS (val);
    4822              : 
    4823    126285553 :       val = require_complete_type (ploc, val);
    4824              : 
    4825              :       /* Some floating-point arguments must be promoted to double when
    4826              :          no type is specified by a prototype.  This applies to
    4827              :          arguments of type float, and to architecture-specific types
    4828              :          (ARM __fp16), but not to _FloatN or _FloatNx types.  */
    4829    126285553 :       bool promote_float_arg = false;
    4830    126285553 :       if (type == NULL_TREE
    4831       936207 :           && TREE_CODE (valtype) == REAL_TYPE
    4832       269701 :           && (TYPE_PRECISION (valtype)
    4833       269701 :               <= TYPE_PRECISION (double_type_node))
    4834       262419 :           && TYPE_MAIN_VARIANT (valtype) != double_type_node
    4835       131418 :           && TYPE_MAIN_VARIANT (valtype) != long_double_type_node
    4836    126416971 :           && !DECIMAL_FLOAT_MODE_P (TYPE_MODE (valtype)))
    4837              :         {
    4838              :           /* Promote this argument, unless it has a _FloatN or
    4839              :              _FloatNx type.  */
    4840      1027846 :           promote_float_arg = true;
    4841      1027846 :           for (int i = 0; i < NUM_FLOATN_NX_TYPES; i++)
    4842       900438 :             if (TYPE_MAIN_VARIANT (valtype) == FLOATN_NX_TYPE_NODE (i))
    4843              :               {
    4844              :                 promote_float_arg = false;
    4845              :                 break;
    4846              :               }
    4847              :           /* Don't promote __bf16 either.  */
    4848       130685 :           if (TYPE_MAIN_VARIANT (valtype) == bfloat16_type_node)
    4849    126154938 :             promote_float_arg = false;
    4850              :         }
    4851              : 
    4852    126285553 :       if (type != NULL_TREE)
    4853              :         {
    4854    125349346 :           tree origtype = (!origtypes) ? NULL_TREE : (*origtypes)[parmnum];
    4855    125349346 :           parmval = convert_argument (ploc, function, fundecl, type, origtype,
    4856              :                                       val, valtype, npc, rname, parmnum, argnum,
    4857              :                                       excess_precision, 0);
    4858              :         }
    4859              :       /* A NULLPTR type is just a nullptr always.  */
    4860       936207 :       else if (TREE_CODE (TREE_TYPE (val)) == NULLPTR_TYPE)
    4861            9 :         parmval = omit_one_operand_loc (ploc, TREE_TYPE (val), nullptr_node, val);
    4862       936198 :       else if (promote_float_arg)
    4863              :         {
    4864       127338 :           if (type_generic)
    4865              :             parmval = val;
    4866              :           else
    4867              :             {
    4868              :               /* Convert `float' to `double'.  */
    4869       124446 :               if (warn_double_promotion && !c_inhibit_evaluation_warnings)
    4870            6 :                 warning_at (ploc, OPT_Wdouble_promotion,
    4871              :                             "implicit conversion from %qT to %qT when passing "
    4872              :                             "argument to function",
    4873              :                             valtype, double_type_node);
    4874       124446 :               parmval = convert (double_type_node, val);
    4875              :             }
    4876              :         }
    4877       808860 :       else if ((excess_precision && !type_generic)
    4878       808858 :                || (type_generic_overflow_p && parmnum == 2)
    4879       787836 :                || (type_generic_bit_query && parmnum == 0))
    4880              :         /* A "double" argument with excess precision being passed
    4881              :            without a prototype or in variable arguments.
    4882              :            The last argument of __builtin_*_overflow_p should not be
    4883              :            promoted, similarly the first argument of
    4884              :            __builtin_{clz,ctz,clrsb,ffs,parity,popcount}g.  */
    4885        22312 :         parmval = convert (valtype, val);
    4886      1573096 :       else if ((invalid_func_diag =
    4887       786548 :                 targetm.calls.invalid_arg_for_unprototyped_fn (typelist, fundecl, val)))
    4888              :         {
    4889            0 :           error (invalid_func_diag);
    4890            0 :           return -1;
    4891              :         }
    4892       786548 :       else if (TREE_CODE (val) == ADDR_EXPR && reject_gcc_builtin (val))
    4893              :         {
    4894              :           return -1;
    4895              :         }
    4896              :       else
    4897              :         /* Convert `short' and `char' to full-size `int'.  */
    4898       786545 :         parmval = default_conversion (val);
    4899              : 
    4900    126285550 :       (*values)[parmnum] = parmval;
    4901    126285550 :       if (parmval == error_mark_node)
    4902          105 :         error_args = true;
    4903              : 
    4904    126285550 :       if (!type && builtin_type && TREE_CODE (builtin_type) != VOID_TYPE)
    4905              :         {
    4906              :           /* For a call to a built-in function declared without a prototype,
    4907              :              perform the conversions from the argument to the expected type
    4908              :              but issue warnings rather than errors for any mismatches.
    4909              :              Ignore the converted argument and use the PARMVAL obtained
    4910              :              above by applying default conversions instead.  */
    4911         1919 :           tree origtype = (!origtypes) ? NULL_TREE : (*origtypes)[parmnum];
    4912         1919 :           convert_argument (ploc, function, fundecl, builtin_type, origtype,
    4913              :                             val, valtype, npc, rname, parmnum, argnum,
    4914              :                             excess_precision,
    4915              :                             OPT_Wbuiltin_declaration_mismatch);
    4916              :         }
    4917              : 
    4918    126285550 :       if (typetail)
    4919    125349346 :         typetail = TREE_CHAIN (typetail);
    4920              : 
    4921    126285550 :       if (builtin_typetail)
    4922      1035394 :         builtin_typetail = TREE_CHAIN (builtin_typetail);
    4923              :     }
    4924              : 
    4925     87896020 :   gcc_assert (parmnum == vec_safe_length (values));
    4926              : 
    4927     99257874 :   if (typetail != NULL_TREE && TREE_VALUE (typetail) != void_type_node)
    4928              :     {
    4929              :       /* Not enough args.
    4930              :          Determine minimum number of arguments required.  */
    4931              :       int min_expected_num = 0;
    4932          231 :       bool at_least_p = false;
    4933              :       tree iter = typelist;
    4934          386 :       while (true)
    4935              :         {
    4936          231 :           if (!iter)
    4937              :             {
    4938              :               /* Variadic arguments; stop iterating.  */
    4939              :               at_least_p = true;
    4940              :               break;
    4941              :             }
    4942          222 :           if (iter == void_list_node)
    4943              :             /* End of arguments; stop iterating.  */
    4944              :             break;
    4945          155 :           ++min_expected_num;
    4946          155 :           iter = TREE_CHAIN (iter);
    4947              :         }
    4948           76 :       auto_diagnostic_group d;
    4949           76 :       int actual_num = vec_safe_length (values);
    4950          143 :       error_at (loc,
    4951              :                 at_least_p
    4952              :                 ? G_("too few arguments to function %qE; expected at least %i, have %i")
    4953              :                 : G_("too few arguments to function %qE; expected %i, have %i"),
    4954              :                 function, min_expected_num, actual_num);
    4955           76 :       inform_declaration (fundecl, function);
    4956           76 :       return -1;
    4957           76 :     }
    4958              : 
    4959     50446779 :   if (builtin_typetail && TREE_VALUE (builtin_typetail) != void_type_node)
    4960              :     {
    4961              :       unsigned nargs = parmnum;
    4962          616 :       for (tree t = builtin_typetail; t; t = TREE_CHAIN (t))
    4963          428 :         ++nargs;
    4964              : 
    4965          188 :       auto_diagnostic_group d;
    4966          188 :       if (warning_at (loc, OPT_Wbuiltin_declaration_mismatch,
    4967              :                       "too few arguments to built-in function %qE "
    4968              :                       "expecting %u", function, nargs - 1))
    4969          173 :         inform_declaration (fundecl, function);
    4970          188 :     }
    4971              : 
    4972     49793734 :   return error_args ? -1 : (int) parmnum;
    4973              : }
    4974              : 
    4975              : /* This is the entry point used by the parser to build unary operators
    4976              :    in the input.  CODE, a tree_code, specifies the unary operator, and
    4977              :    ARG is the operand.  For unary plus, the C parser currently uses
    4978              :    CONVERT_EXPR for code.
    4979              : 
    4980              :    LOC is the location to use for the tree generated.
    4981              : */
    4982              : 
    4983              : struct c_expr
    4984      8145239 : parser_build_unary_op (location_t loc, enum tree_code code, struct c_expr arg)
    4985              : {
    4986      8145239 :   struct c_expr result;
    4987              : 
    4988      8145239 :   result.original_code = code;
    4989      8145239 :   result.original_type = NULL;
    4990      8145239 :   result.m_decimal = 0;
    4991              : 
    4992      8145239 :   if (reject_gcc_builtin (arg.value))
    4993              :     {
    4994            2 :       result.value = error_mark_node;
    4995              :     }
    4996              :   else
    4997              :     {
    4998      8145237 :       result.value = build_unary_op (loc, code, arg.value, false);
    4999              : 
    5000      8145237 :       if (TREE_OVERFLOW_P (result.value) && !TREE_OVERFLOW_P (arg.value))
    5001            5 :         overflow_warning (loc, result.value, arg.value);
    5002              :     }
    5003              : 
    5004              :   /* We are typically called when parsing a prefix token at LOC acting on
    5005              :      ARG.  Reflect this by updating the source range of the result to
    5006              :      start at LOC and end at the end of ARG.  */
    5007      8145239 :   set_c_expr_source_range (&result,
    5008              :                            loc, arg.get_finish ());
    5009              : 
    5010      8145239 :   return result;
    5011              : }
    5012              : 
    5013              : /* Returns true if TYPE is a character type, *not* including wchar_t.  */
    5014              : 
    5015              : bool
    5016      1272157 : char_type_p (tree type)
    5017              : {
    5018      1272157 :   return (type == char_type_node
    5019       982378 :           || type == unsigned_char_type_node
    5020       947302 :           || type == signed_char_type_node
    5021       946454 :           || type == char16_type_node
    5022      2000002 :           || type == char32_type_node);
    5023              : }
    5024              : 
    5025              : /* This is the entry point used by the parser to build binary operators
    5026              :    in the input.  CODE, a tree_code, specifies the binary operator, and
    5027              :    ARG1 and ARG2 are the operands.  In addition to constructing the
    5028              :    expression, we check for operands that were written with other binary
    5029              :    operators in a way that is likely to confuse the user.
    5030              : 
    5031              :    LOCATION is the location of the binary operator.  */
    5032              : 
    5033              : struct c_expr
    5034      9312968 : parser_build_binary_op (location_t location, enum tree_code code,
    5035              :                         struct c_expr arg1, struct c_expr arg2)
    5036              : {
    5037      9312968 :   struct c_expr result;
    5038      9312968 :   result.m_decimal = 0;
    5039              : 
    5040      9312968 :   enum tree_code code1 = arg1.original_code;
    5041      9312968 :   enum tree_code code2 = arg2.original_code;
    5042      9312968 :   tree type1 = (arg1.original_type
    5043      9312968 :                 ? arg1.original_type
    5044      5977828 :                 : TREE_TYPE (arg1.value));
    5045      9312968 :   tree type2 = (arg2.original_type
    5046      9312968 :                 ? arg2.original_type
    5047      6871338 :                 : TREE_TYPE (arg2.value));
    5048              : 
    5049      9312968 :   result.value = build_binary_op (location, code,
    5050              :                                   arg1.value, arg2.value, true);
    5051      9312967 :   result.original_code = code;
    5052      9312967 :   result.original_type = NULL;
    5053      9312967 :   result.m_decimal = 0;
    5054              : 
    5055      9312967 :   if (TREE_CODE (result.value) == ERROR_MARK)
    5056              :     {
    5057         1297 :       set_c_expr_source_range (&result,
    5058              :                                arg1.get_start (),
    5059              :                                arg2.get_finish ());
    5060         1297 :       return result;
    5061              :     }
    5062              : 
    5063      9311670 :   if (location != UNKNOWN_LOCATION)
    5064      9311670 :     protected_set_expr_location (result.value, location);
    5065              : 
    5066      9311670 :   set_c_expr_source_range (&result,
    5067              :                            arg1.get_start (),
    5068              :                            arg2.get_finish ());
    5069              : 
    5070              :   /* Check for cases such as x+y<<z which users are likely
    5071              :      to misinterpret.  */
    5072      9311670 :   if (warn_parentheses)
    5073      2003892 :     warn_about_parentheses (location, code, code1, arg1.value, code2,
    5074              :                             arg2.value);
    5075              : 
    5076      9311670 :   if (warn_logical_op)
    5077          340 :     warn_logical_operator (location, code, TREE_TYPE (result.value),
    5078              :                            code1, arg1.value, code2, arg2.value);
    5079              : 
    5080      9311670 :   if (warn_tautological_compare)
    5081              :     {
    5082      2002405 :       tree lhs = arg1.value;
    5083      2002405 :       tree rhs = arg2.value;
    5084      2002405 :       if (TREE_CODE (lhs) == C_MAYBE_CONST_EXPR)
    5085              :         {
    5086            2 :           if (C_MAYBE_CONST_EXPR_PRE (lhs) != NULL_TREE
    5087            2 :               && TREE_SIDE_EFFECTS (C_MAYBE_CONST_EXPR_PRE (lhs)))
    5088              :             lhs = NULL_TREE;
    5089              :           else
    5090            2 :             lhs = C_MAYBE_CONST_EXPR_EXPR (lhs);
    5091              :         }
    5092      2002405 :       if (TREE_CODE (rhs) == C_MAYBE_CONST_EXPR)
    5093              :         {
    5094           12 :           if (C_MAYBE_CONST_EXPR_PRE (rhs) != NULL_TREE
    5095           12 :               && TREE_SIDE_EFFECTS (C_MAYBE_CONST_EXPR_PRE (rhs)))
    5096              :             rhs = NULL_TREE;
    5097              :           else
    5098           12 :             rhs = C_MAYBE_CONST_EXPR_EXPR (rhs);
    5099              :         }
    5100      2002405 :       if (lhs != NULL_TREE && rhs != NULL_TREE)
    5101      2002405 :         warn_tautological_cmp (location, code, lhs, rhs);
    5102              :     }
    5103              : 
    5104      9311670 :   if (warn_logical_not_paren
    5105      2002488 :       && TREE_CODE_CLASS (code) == tcc_comparison
    5106       405796 :       && code1 == TRUTH_NOT_EXPR
    5107       405796 :       && code2 != TRUTH_NOT_EXPR
    5108              :       /* Avoid warning for !!x == y.  */
    5109      9311796 :       && (TREE_CODE (arg1.value) != NE_EXPR
    5110           19 :           || !integer_zerop (TREE_OPERAND (arg1.value, 1))))
    5111              :     {
    5112              :       /* Avoid warning for !b == y where b has _Bool type.  */
    5113          107 :       tree t = integer_zero_node;
    5114          107 :       if (TREE_CODE (arg1.value) == EQ_EXPR
    5115           98 :           && integer_zerop (TREE_OPERAND (arg1.value, 1))
    5116          205 :           && TREE_TYPE (TREE_OPERAND (arg1.value, 0)) == integer_type_node)
    5117              :         {
    5118           90 :           t = TREE_OPERAND (arg1.value, 0);
    5119          199 :           do
    5120              :             {
    5121          199 :               if (TREE_TYPE (t) != integer_type_node)
    5122              :                 break;
    5123          180 :               if (TREE_CODE (t) == C_MAYBE_CONST_EXPR)
    5124           90 :                 t = C_MAYBE_CONST_EXPR_EXPR (t);
    5125           90 :               else if (CONVERT_EXPR_P (t))
    5126           19 :                 t = TREE_OPERAND (t, 0);
    5127              :               else
    5128              :                 break;
    5129              :             }
    5130              :           while (1);
    5131              :         }
    5132          107 :       if (!C_BOOLEAN_TYPE_P (TREE_TYPE (t)))
    5133           88 :         warn_logical_not_parentheses (location, code, arg1.value, arg2.value);
    5134              :     }
    5135              : 
    5136              :   /* Warn about comparisons against string literals, with the exception
    5137              :      of testing for equality or inequality of a string literal with NULL.  */
    5138      9311670 :   if (code == EQ_EXPR || code == NE_EXPR)
    5139              :     {
    5140      1165078 :       if ((code1 == STRING_CST
    5141           16 :            && !integer_zerop (tree_strip_nop_conversions (arg2.value)))
    5142      1165089 :           || (code2 == STRING_CST
    5143           39 :               && !integer_zerop (tree_strip_nop_conversions (arg1.value))))
    5144           36 :         warning_at (location, OPT_Waddress,
    5145              :                     "comparison with string literal results in unspecified behavior");
    5146              :       /* Warn for ptr == '\0', it's likely that it should've been ptr[0].  */
    5147      1165078 :       if (POINTER_TYPE_P (type1)
    5148        90485 :           && null_pointer_constant_p (arg2.value)
    5149      1186069 :           && char_type_p (type2))
    5150              :         {
    5151           18 :           auto_diagnostic_group d;
    5152           18 :           if (warning_at (location, OPT_Wpointer_compare,
    5153              :                             "comparison between pointer and zero character "
    5154              :                             "constant"))
    5155           10 :             inform (arg1.get_start (),
    5156              :                       "did you mean to dereference the pointer?");
    5157           18 :         }
    5158      1165060 :       else if (POINTER_TYPE_P (type2)
    5159        87808 :                && null_pointer_constant_p (arg1.value)
    5160      1165326 :                && char_type_p (type1))
    5161              :         {
    5162           10 :           auto_diagnostic_group d;
    5163           10 :           if (warning_at (location, OPT_Wpointer_compare,
    5164              :                             "comparison between pointer and zero character "
    5165              :                             "constant"))
    5166           10 :             inform (arg2.get_start (),
    5167              :                       "did you mean to dereference the pointer?");
    5168           10 :         }
    5169              :     }
    5170      8146592 :   else if (TREE_CODE_CLASS (code) == tcc_comparison
    5171       995930 :            && (code1 == STRING_CST || code2 == STRING_CST))
    5172            0 :     warning_at (location, OPT_Waddress,
    5173              :                 "comparison with string literal results in unspecified "
    5174              :                 "behavior");
    5175              : 
    5176      9311670 :   if (warn_zero_as_null_pointer_constant
    5177           24 :       && c_inhibit_evaluation_warnings == 0
    5178           24 :       && TREE_CODE_CLASS (code) == tcc_comparison)
    5179              :     {
    5180           24 :       if ((TREE_CODE (type1) == POINTER_TYPE
    5181           17 :            || TREE_CODE (type1) == NULLPTR_TYPE)
    5182            9 :           && INTEGRAL_TYPE_P (type2)
    5183           33 :           && null_pointer_constant_p (arg2.value))
    5184            9 :         warning_at (arg2.get_location(), OPT_Wzero_as_null_pointer_constant,
    5185              :                     "zero as null pointer constant");
    5186              : 
    5187           24 :       if ((TREE_CODE (type2) == POINTER_TYPE
    5188           15 :            || TREE_CODE (type2) == NULLPTR_TYPE)
    5189           11 :           && INTEGRAL_TYPE_P (type1)
    5190           35 :           && null_pointer_constant_p (arg1.value))
    5191           11 :         warning_at (arg1.get_location(), OPT_Wzero_as_null_pointer_constant,
    5192              :                     "zero as null pointer constant");
    5193              :     }
    5194              : 
    5195      9311670 :   if (warn_array_compare
    5196      2002243 :       && TREE_CODE_CLASS (code) == tcc_comparison
    5197       405581 :       && TREE_CODE (type1) == ARRAY_TYPE
    5198           38 :       && TREE_CODE (type2) == ARRAY_TYPE)
    5199           15 :     do_warn_array_compare (location, code, arg1.value, arg2.value);
    5200              : 
    5201      2179481 :   if (TREE_OVERFLOW_P (result.value)
    5202          299 :       && !TREE_OVERFLOW_P (arg1.value)
    5203      9311962 :       && !TREE_OVERFLOW_P (arg2.value))
    5204          249 :     overflow_warning (location, result.value);
    5205              : 
    5206              :   /* Warn about comparisons of different enum types.  */
    5207      9311669 :   if (warn_enum_compare
    5208      2022181 :       && TREE_CODE_CLASS (code) == tcc_comparison
    5209       410006 :       && TREE_CODE (type1) == ENUMERAL_TYPE
    5210         7038 :       && TREE_CODE (type2) == ENUMERAL_TYPE
    5211      9318645 :       && TYPE_MAIN_VARIANT (type1) != TYPE_MAIN_VARIANT (type2))
    5212            2 :     warning_at (location, OPT_Wenum_compare,
    5213              :                 "comparison between %qT and %qT",
    5214              :                 type1, type2);
    5215              : 
    5216      9311669 :   if (warn_xor_used_as_pow
    5217      9311669 :       && code == BIT_XOR_EXPR
    5218        76933 :       && arg1.m_decimal
    5219          722 :       && arg2.m_decimal)
    5220          427 :     check_for_xor_used_as_pow (arg1.get_location (), arg1.value,
    5221              :                                location,
    5222              :                                arg2.get_location (), arg2.value);
    5223              : 
    5224              :   return result;
    5225              : }
    5226              : 
    5227              : /* Return a tree for the difference of pointers OP0 and OP1.
    5228              :    The resulting tree has type ptrdiff_t.  If POINTER_SUBTRACT sanitization is
    5229              :    enabled, assign to INSTRUMENT_EXPR call to libsanitizer.  */
    5230              : 
    5231              : static tree
    5232         3622 : pointer_diff (location_t loc, tree op0, tree op1, tree *instrument_expr)
    5233              : {
    5234         3622 :   tree restype = ptrdiff_type_node;
    5235         3622 :   tree result, inttype;
    5236              : 
    5237         3622 :   addr_space_t as0 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (op0)));
    5238         3622 :   addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (op1)));
    5239         3622 :   tree target_type = TREE_TYPE (TREE_TYPE (op0));
    5240         3622 :   tree orig_op0 = op0;
    5241         3622 :   tree orig_op1 = op1;
    5242              : 
    5243              :   /* If the operands point into different address spaces, we need to
    5244              :      explicitly convert them to pointers into the common address space
    5245              :      before we can subtract the numerical address values.  */
    5246         3622 :   if (as0 != as1)
    5247              :     {
    5248            0 :       addr_space_t as_common;
    5249            0 :       tree common_type;
    5250              : 
    5251              :       /* Determine the common superset address space.  This is guaranteed
    5252              :          to exist because the caller verified that comp_target_types
    5253              :          returned non-zero.  */
    5254            0 :       if (!addr_space_superset (as0, as1, &as_common))
    5255            0 :         gcc_unreachable ();
    5256              : 
    5257            0 :       common_type = common_pointer_type (TREE_TYPE (op0), TREE_TYPE (op1), NULL_TREE);
    5258            0 :       op0 = convert (common_type, op0);
    5259            0 :       op1 = convert (common_type, op1);
    5260              :     }
    5261              : 
    5262              :   /* Determine integer type result of the subtraction.  This will usually
    5263              :      be the same as the result type (ptrdiff_t), but may need to be a wider
    5264              :      type if pointers for the address space are wider than ptrdiff_t.  */
    5265         3622 :   if (TYPE_PRECISION (restype) < TYPE_PRECISION (TREE_TYPE (op0)))
    5266            0 :     inttype = c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op0)), 0);
    5267              :   else
    5268              :     inttype = restype;
    5269              : 
    5270         3622 :   if (VOID_TYPE_P (target_type))
    5271          143 :     pedwarn (loc, OPT_Wpointer_arith,
    5272              :              "pointer of type %<void *%> used in subtraction");
    5273         3622 :   if (TREE_CODE (target_type) == FUNCTION_TYPE)
    5274            4 :     pedwarn (loc, OPT_Wpointer_arith,
    5275              :              "pointer to a function used in subtraction");
    5276              : 
    5277         3622 :   if (current_function_decl != NULL_TREE
    5278         3622 :       && sanitize_flags_p (SANITIZE_POINTER_SUBTRACT))
    5279              :     {
    5280           70 :       op0 = save_expr (c_fully_fold (op0, false, NULL));
    5281           70 :       op1 = save_expr (c_fully_fold (op1, false, NULL));
    5282              : 
    5283           70 :       tree tt = builtin_decl_explicit (BUILT_IN_ASAN_POINTER_SUBTRACT);
    5284           70 :       *instrument_expr = build_call_expr_loc (loc, tt, 2, op0, op1);
    5285              :     }
    5286              : 
    5287              :   /* First do the subtraction, then build the divide operator
    5288              :      and only convert at the very end.
    5289              :      Do not do default conversions in case restype is a short type.  */
    5290              : 
    5291              :   /* POINTER_DIFF_EXPR requires a signed integer type of the same size as
    5292              :      pointers.  If some platform cannot provide that, or has a larger
    5293              :      ptrdiff_type to support differences larger than half the address
    5294              :      space, cast the pointers to some larger integer type and do the
    5295              :      computations in that type.  */
    5296         3622 :   if (TYPE_PRECISION (inttype) > TYPE_PRECISION (TREE_TYPE (op0)))
    5297            0 :     op0 = build_binary_op (loc, MINUS_EXPR, convert (inttype, op0),
    5298              :                            convert (inttype, op1), false);
    5299              :   else
    5300              :     {
    5301              :       /* Cast away qualifiers.  */
    5302         3622 :       op0 = convert (c_common_type (TREE_TYPE (op0), TREE_TYPE (op0)), op0);
    5303         3622 :       op1 = convert (c_common_type (TREE_TYPE (op1), TREE_TYPE (op1)), op1);
    5304         3622 :       op0 = build2_loc (loc, POINTER_DIFF_EXPR, inttype, op0, op1);
    5305              :     }
    5306              : 
    5307              :   /* This generates an error if op1 is pointer to incomplete type.  */
    5308         3622 :   if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (orig_op1))))
    5309            4 :     error_at (loc, "arithmetic on pointer to an incomplete type");
    5310         3618 :   else if (verify_type_context (loc, TCTX_POINTER_ARITH,
    5311         3618 :                                 TREE_TYPE (TREE_TYPE (orig_op0))))
    5312         7236 :     verify_type_context (loc, TCTX_POINTER_ARITH,
    5313         3618 :                          TREE_TYPE (TREE_TYPE (orig_op1)));
    5314              : 
    5315         3622 :   op1 = c_size_in_bytes (target_type);
    5316              : 
    5317         3622 :   if (pointer_to_zero_sized_aggr_p (TREE_TYPE (orig_op1)))
    5318            4 :     error_at (loc, "arithmetic on pointer to an empty aggregate");
    5319              : 
    5320              :   /* Divide by the size, in easiest possible way.  */
    5321         3622 :   result = fold_build2_loc (loc, EXACT_DIV_EXPR, inttype,
    5322              :                             op0, convert (inttype, op1));
    5323              : 
    5324              :   /* Convert to final result type if necessary.  */
    5325         3622 :   return convert (restype, result);
    5326              : }
    5327              : 
    5328              : /* Expand atomic compound assignments into an appropriate sequence as
    5329              :    specified by the C11 standard section 6.5.16.2.
    5330              : 
    5331              :        _Atomic T1 E1
    5332              :        T2 E2
    5333              :        E1 op= E2
    5334              : 
    5335              :   This sequence is used for all types for which these operations are
    5336              :   supported.
    5337              : 
    5338              :   In addition, built-in versions of the 'fe' prefixed routines may
    5339              :   need to be invoked for floating point (real, complex or vector) when
    5340              :   floating-point exceptions are supported.  See 6.5.16.2 footnote 113.
    5341              : 
    5342              :   T1 newval;
    5343              :   T1 old;
    5344              :   T1 *addr
    5345              :   T2 val
    5346              :   fenv_t fenv
    5347              : 
    5348              :   addr = &E1;
    5349              :   val = (E2);
    5350              :   __atomic_load (addr, &old, SEQ_CST);
    5351              :   feholdexcept (&fenv);
    5352              : loop:
    5353              :     newval = old op val;
    5354              :     if (__atomic_compare_exchange_strong (addr, &old, &newval, SEQ_CST,
    5355              :                                           SEQ_CST))
    5356              :       goto done;
    5357              :     feclearexcept (FE_ALL_EXCEPT);
    5358              :     goto loop:
    5359              : done:
    5360              :   feupdateenv (&fenv);
    5361              : 
    5362              :   The compiler will issue the __atomic_fetch_* built-in when possible,
    5363              :   otherwise it will generate the generic form of the atomic operations.
    5364              :   This requires temp(s) and has their address taken.  The atomic processing
    5365              :   is smart enough to figure out when the size of an object can utilize
    5366              :   a lock-free version, and convert the built-in call to the appropriate
    5367              :   lock-free routine.  The optimizers will then dispose of any temps that
    5368              :   are no longer required, and lock-free implementations are utilized as
    5369              :   long as there is target support for the required size.
    5370              : 
    5371              :   If the operator is NOP_EXPR, then this is a simple assignment, and
    5372              :   an __atomic_store is issued to perform the assignment rather than
    5373              :   the above loop.  */
    5374              : 
    5375              : /* Build an atomic assignment at LOC, expanding into the proper
    5376              :    sequence to store LHS MODIFYCODE= RHS.  Return a value representing
    5377              :    the result of the operation, unless RETURN_OLD_P, in which case
    5378              :    return the old value of LHS (this is only for postincrement and
    5379              :    postdecrement).  */
    5380              : 
    5381              : static tree
    5382        30433 : build_atomic_assign (location_t loc, tree lhs, enum tree_code modifycode,
    5383              :                      tree rhs, bool return_old_p)
    5384              : {
    5385        30433 :   tree fndecl, func_call;
    5386        30433 :   vec<tree, va_gc> *params;
    5387        30433 :   tree val, nonatomic_lhs_type, nonatomic_rhs_type, newval, newval_addr;
    5388        30433 :   tree old, old_addr;
    5389        30433 :   tree compound_stmt = NULL_TREE;
    5390        30433 :   tree stmt, goto_stmt;
    5391        30433 :   tree loop_label, loop_decl, done_label, done_decl;
    5392              : 
    5393        30433 :   tree lhs_type = TREE_TYPE (lhs);
    5394        30433 :   tree lhs_addr = build_unary_op (loc, ADDR_EXPR, lhs, false);
    5395        30433 :   tree seq_cst = build_int_cst (integer_type_node, MEMMODEL_SEQ_CST);
    5396        30433 :   tree rhs_semantic_type = TREE_TYPE (rhs);
    5397        30433 :   tree nonatomic_rhs_semantic_type;
    5398        30433 :   tree rhs_type;
    5399              : 
    5400        30433 :   gcc_assert (TYPE_ATOMIC (lhs_type));
    5401              : 
    5402        30433 :   if (return_old_p)
    5403         2313 :     gcc_assert (modifycode == PLUS_EXPR || modifycode == MINUS_EXPR);
    5404              : 
    5405              :   /* Allocate enough vector items for a compare_exchange.  */
    5406        30433 :   vec_alloc (params, 6);
    5407              : 
    5408              :   /* Create a compound statement to hold the sequence of statements
    5409              :      with a loop.  */
    5410        30433 :   if (modifycode != NOP_EXPR)
    5411              :     {
    5412        19954 :       compound_stmt = c_begin_compound_stmt (false);
    5413              : 
    5414              :       /* For consistency with build_modify_expr on non-_Atomic,
    5415              :          mark the lhs as read.  Also, it would be very hard to match
    5416              :          such expressions in mark_exp_read.  */
    5417        19954 :       mark_exp_read (lhs);
    5418              :     }
    5419              : 
    5420              :   /* Remove any excess precision (which is only present here in the
    5421              :      case of compound assignments).  */
    5422        30433 :   if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
    5423              :     {
    5424            0 :       gcc_assert (modifycode != NOP_EXPR);
    5425            0 :       rhs = TREE_OPERAND (rhs, 0);
    5426              :     }
    5427        30433 :   rhs_type = TREE_TYPE (rhs);
    5428              : 
    5429              :   /* Fold the RHS if it hasn't already been folded.  */
    5430        30433 :   if (modifycode != NOP_EXPR)
    5431        19954 :     rhs = c_fully_fold (rhs, false, NULL);
    5432              : 
    5433              :   /* Remove the qualifiers for the rest of the expressions and create
    5434              :      the VAL temp variable to hold the RHS.  */
    5435        30433 :   nonatomic_lhs_type = build_qualified_type (lhs_type, TYPE_UNQUALIFIED);
    5436        30433 :   nonatomic_rhs_type = build_qualified_type (rhs_type, TYPE_UNQUALIFIED);
    5437        30433 :   nonatomic_rhs_semantic_type = build_qualified_type (rhs_semantic_type,
    5438              :                                                       TYPE_UNQUALIFIED);
    5439        30433 :   val = create_tmp_var_raw (nonatomic_rhs_type);
    5440        30433 :   TREE_ADDRESSABLE (val) = 1;
    5441        30433 :   suppress_warning (val);
    5442        30433 :   rhs = build4 (TARGET_EXPR, nonatomic_rhs_type, val, rhs, NULL_TREE,
    5443              :                 NULL_TREE);
    5444        30433 :   TREE_SIDE_EFFECTS (rhs) = 1;
    5445        30433 :   SET_EXPR_LOCATION (rhs, loc);
    5446        30433 :   if (modifycode != NOP_EXPR)
    5447        19954 :     add_stmt (rhs);
    5448              : 
    5449              :   /* NOP_EXPR indicates it's a straight store of the RHS. Simply issue
    5450              :      an atomic_store.  */
    5451        30433 :   if (modifycode == NOP_EXPR)
    5452              :     {
    5453        10479 :       compound_stmt = rhs;
    5454              :       /* Build __atomic_store (&lhs, &val, SEQ_CST)  */
    5455        10479 :       rhs = build_unary_op (loc, ADDR_EXPR, val, false);
    5456        10479 :       fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_STORE);
    5457        10479 :       params->quick_push (lhs_addr);
    5458        10479 :       params->quick_push (rhs);
    5459        10479 :       params->quick_push (seq_cst);
    5460        10479 :       func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
    5461              : 
    5462        10479 :       compound_stmt = build2 (COMPOUND_EXPR, void_type_node,
    5463              :                               compound_stmt, func_call);
    5464              : 
    5465              :       /* VAL is the value which was stored, return a COMPOUND_STMT of
    5466              :          the statement and that value.  */
    5467        10479 :       return build2 (COMPOUND_EXPR, nonatomic_lhs_type, compound_stmt, val);
    5468              :     }
    5469              : 
    5470              :   /* Attempt to implement the atomic operation as an __atomic_fetch_* or
    5471              :      __atomic_*_fetch built-in rather than a CAS loop.  atomic_bool type
    5472              :      isn't applicable for such builtins.  ??? Do we want to handle enums?  */
    5473        19954 :   if ((TREE_CODE (lhs_type) == INTEGER_TYPE || POINTER_TYPE_P (lhs_type))
    5474        13941 :       && TREE_CODE (rhs_type) == INTEGER_TYPE)
    5475              :     {
    5476        11713 :       built_in_function fncode;
    5477        11713 :       switch (modifycode)
    5478              :         {
    5479         3075 :         case PLUS_EXPR:
    5480         3075 :         case POINTER_PLUS_EXPR:
    5481         2124 :           fncode = (return_old_p
    5482         3075 :                     ? BUILT_IN_ATOMIC_FETCH_ADD_N
    5483              :                     : BUILT_IN_ATOMIC_ADD_FETCH_N);
    5484              :           break;
    5485         2889 :         case MINUS_EXPR:
    5486         2094 :           fncode = (return_old_p
    5487         2889 :                     ? BUILT_IN_ATOMIC_FETCH_SUB_N
    5488              :                     : BUILT_IN_ATOMIC_SUB_FETCH_N);
    5489              :           break;
    5490          609 :         case BIT_AND_EXPR:
    5491          609 :           fncode = (return_old_p
    5492          609 :                     ? BUILT_IN_ATOMIC_FETCH_AND_N
    5493              :                     : BUILT_IN_ATOMIC_AND_FETCH_N);
    5494              :           break;
    5495          609 :         case BIT_IOR_EXPR:
    5496          609 :           fncode = (return_old_p
    5497          609 :                     ? BUILT_IN_ATOMIC_FETCH_OR_N
    5498              :                     : BUILT_IN_ATOMIC_OR_FETCH_N);
    5499              :           break;
    5500          609 :         case BIT_XOR_EXPR:
    5501          609 :           fncode = (return_old_p
    5502          609 :                     ? BUILT_IN_ATOMIC_FETCH_XOR_N
    5503              :                     : BUILT_IN_ATOMIC_XOR_FETCH_N);
    5504              :           break;
    5505         3922 :         default:
    5506         3922 :           goto cas_loop;
    5507              :         }
    5508              : 
    5509              :       /* We can only use "_1" through "_16" variants of the atomic fetch
    5510              :          built-ins.  */
    5511         7791 :       unsigned HOST_WIDE_INT size = tree_to_uhwi (TYPE_SIZE_UNIT (lhs_type));
    5512         7791 :       if (size != 1 && size != 2 && size != 4 && size != 8 && size != 16)
    5513            0 :         goto cas_loop;
    5514              : 
    5515              :       /* If this is a pointer type, we need to multiply by the size of
    5516              :          the pointer target type.  */
    5517         7791 :       if (POINTER_TYPE_P (lhs_type))
    5518              :         {
    5519         1018 :           if (!COMPLETE_TYPE_P (TREE_TYPE (lhs_type))
    5520              :               /* ??? This would introduce -Wdiscarded-qualifiers
    5521              :                  warning: __atomic_fetch_* expect volatile void *
    5522              :                  type as the first argument.  (Assignments between
    5523              :                  atomic and non-atomic objects are OK.) */
    5524         1018 :               || TYPE_RESTRICT (lhs_type))
    5525           17 :             goto cas_loop;
    5526         1001 :           tree sz = TYPE_SIZE_UNIT (TREE_TYPE (lhs_type));
    5527         1001 :           rhs = fold_build2_loc (loc, MULT_EXPR, ptrdiff_type_node,
    5528              :                                  convert (ptrdiff_type_node, rhs),
    5529              :                                  convert (ptrdiff_type_node, sz));
    5530              :         }
    5531              : 
    5532              :       /* Build __atomic_fetch_* (&lhs, &val, SEQ_CST), or
    5533              :          __atomic_*_fetch (&lhs, &val, SEQ_CST).  */
    5534         7774 :       fndecl = builtin_decl_explicit (fncode);
    5535         7774 :       params->quick_push (lhs_addr);
    5536         7774 :       params->quick_push (rhs);
    5537         7774 :       params->quick_push (seq_cst);
    5538         7774 :       func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
    5539              : 
    5540         7774 :       newval = create_tmp_var_raw (nonatomic_lhs_type);
    5541         7774 :       TREE_ADDRESSABLE (newval) = 1;
    5542         7774 :       suppress_warning (newval);
    5543         7774 :       rhs = build4 (TARGET_EXPR, nonatomic_lhs_type, newval, func_call,
    5544              :                     NULL_TREE, NULL_TREE);
    5545         7774 :       SET_EXPR_LOCATION (rhs, loc);
    5546         7774 :       add_stmt (rhs);
    5547              : 
    5548              :       /* Finish the compound statement.  */
    5549         7774 :       compound_stmt = c_end_compound_stmt (loc, compound_stmt, false);
    5550              : 
    5551              :       /* NEWVAL is the value which was stored, return a COMPOUND_STMT of
    5552              :          the statement and that value.  */
    5553         7774 :       return build2 (COMPOUND_EXPR, nonatomic_lhs_type, compound_stmt, newval);
    5554              :     }
    5555              : 
    5556         8241 : cas_loop:
    5557              :   /* Create the variables and labels required for the op= form.  */
    5558        12180 :   old = create_tmp_var_raw (nonatomic_lhs_type);
    5559        12180 :   old_addr = build_unary_op (loc, ADDR_EXPR, old, false);
    5560        12180 :   TREE_ADDRESSABLE (old) = 1;
    5561        12180 :   suppress_warning (old);
    5562              : 
    5563        12180 :   newval = create_tmp_var_raw (nonatomic_lhs_type);
    5564        12180 :   newval_addr = build_unary_op (loc, ADDR_EXPR, newval, false);
    5565        12180 :   TREE_ADDRESSABLE (newval) = 1;
    5566        12180 :   suppress_warning (newval);
    5567              : 
    5568        12180 :   loop_decl = create_artificial_label (loc);
    5569        12180 :   loop_label = build1 (LABEL_EXPR, void_type_node, loop_decl);
    5570              : 
    5571        12180 :   done_decl = create_artificial_label (loc);
    5572        12180 :   done_label = build1 (LABEL_EXPR, void_type_node, done_decl);
    5573              : 
    5574              :   /* __atomic_load (addr, &old, SEQ_CST).  */
    5575        12180 :   fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_LOAD);
    5576        12180 :   params->quick_push (lhs_addr);
    5577        12180 :   params->quick_push (old_addr);
    5578        12180 :   params->quick_push (seq_cst);
    5579        12180 :   func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
    5580        12180 :   old = build4 (TARGET_EXPR, nonatomic_lhs_type, old, func_call, NULL_TREE,
    5581              :                 NULL_TREE);
    5582        12180 :   add_stmt (old);
    5583        12180 :   params->truncate (0);
    5584              : 
    5585              :   /* Create the expressions for floating-point environment
    5586              :      manipulation, if required.  */
    5587        12180 :   bool need_fenv = (flag_trapping_math
    5588        12180 :                     && (FLOAT_TYPE_P (lhs_type) || FLOAT_TYPE_P (rhs_type)));
    5589        12180 :   tree hold_call = NULL_TREE, clear_call = NULL_TREE, update_call = NULL_TREE;
    5590        12180 :   if (need_fenv)
    5591         7054 :     targetm.atomic_assign_expand_fenv (&hold_call, &clear_call, &update_call);
    5592              : 
    5593        12180 :   if (hold_call)
    5594         7054 :     add_stmt (hold_call);
    5595              : 
    5596              :   /* loop:  */
    5597        12180 :   add_stmt (loop_label);
    5598              : 
    5599              :   /* newval = old + val;  */
    5600        12180 :   if (rhs_type != rhs_semantic_type)
    5601            0 :     val = build1 (EXCESS_PRECISION_EXPR, nonatomic_rhs_semantic_type, val);
    5602        12180 :   rhs = build_binary_op (loc, modifycode,
    5603              :                          convert_lvalue_to_rvalue (loc, old, true, true),
    5604              :                          val, true);
    5605        12180 :   if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
    5606              :     {
    5607            0 :       tree eptype = TREE_TYPE (rhs);
    5608            0 :       rhs = c_fully_fold (TREE_OPERAND (rhs, 0), false, NULL);
    5609            0 :       rhs = build1 (EXCESS_PRECISION_EXPR, eptype, rhs);
    5610              :     }
    5611              :   else
    5612        12180 :     rhs = c_fully_fold (rhs, false, NULL);
    5613        12180 :   rhs = convert_for_assignment (loc, UNKNOWN_LOCATION, nonatomic_lhs_type,
    5614              :                                 rhs, NULL_TREE, ic_assign, false, NULL_TREE,
    5615              :                                 NULL_TREE, 0);
    5616              :   /* The temporary variable for NEWVAL is only gimplified correctly (in
    5617              :      particular, given a DECL_CONTEXT) if used in a TARGET_EXPR.  To avoid
    5618              :      subsequent ICEs in nested function processing after an error, ensure such
    5619              :      a TARGET_EXPR is built even after an error.  */
    5620        12180 :   if (rhs == error_mark_node)
    5621           10 :     rhs = old;
    5622        12180 :   rhs = build4 (TARGET_EXPR, nonatomic_lhs_type, newval, rhs, NULL_TREE,
    5623              :                 NULL_TREE);
    5624        12180 :   SET_EXPR_LOCATION (rhs, loc);
    5625        12180 :   add_stmt (rhs);
    5626              : 
    5627              :   /* if (__atomic_compare_exchange (addr, &old, &new, false, SEQ_CST, SEQ_CST))
    5628              :        goto done;  */
    5629        12180 :   fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_COMPARE_EXCHANGE);
    5630        12180 :   params->quick_push (lhs_addr);
    5631        12180 :   params->quick_push (old_addr);
    5632        12180 :   params->quick_push (newval_addr);
    5633        12180 :   params->quick_push (integer_zero_node);
    5634        12180 :   params->quick_push (seq_cst);
    5635        12180 :   params->quick_push (seq_cst);
    5636        12180 :   func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
    5637              : 
    5638        12180 :   goto_stmt = build1 (GOTO_EXPR, void_type_node, done_decl);
    5639        12180 :   SET_EXPR_LOCATION (goto_stmt, loc);
    5640              : 
    5641        12180 :   stmt = build3 (COND_EXPR, void_type_node, func_call, goto_stmt, NULL_TREE);
    5642        12180 :   SET_EXPR_LOCATION (stmt, loc);
    5643        12180 :   add_stmt (stmt);
    5644              : 
    5645        12180 :   if (clear_call)
    5646         7054 :     add_stmt (clear_call);
    5647              : 
    5648              :   /* goto loop;  */
    5649        12180 :   goto_stmt  = build1 (GOTO_EXPR, void_type_node, loop_decl);
    5650        12180 :   SET_EXPR_LOCATION (goto_stmt, loc);
    5651        12180 :   add_stmt (goto_stmt);
    5652              : 
    5653              :   /* done:  */
    5654        12180 :   add_stmt (done_label);
    5655              : 
    5656        12180 :   if (update_call)
    5657         7054 :     add_stmt (update_call);
    5658              : 
    5659              :   /* Finish the compound statement.  */
    5660        12180 :   compound_stmt = c_end_compound_stmt (loc, compound_stmt, false);
    5661              : 
    5662              :   /* NEWVAL is the value that was successfully stored, return a
    5663              :      COMPOUND_EXPR of the statement and the appropriate value.  */
    5664        23787 :   return build2 (COMPOUND_EXPR, nonatomic_lhs_type, compound_stmt,
    5665        12180 :                  return_old_p ? old : newval);
    5666              : }
    5667              : 
    5668              : /* Construct and perhaps optimize a tree representation
    5669              :    for a unary operation.  CODE, a tree_code, specifies the operation
    5670              :    and XARG is the operand.
    5671              :    For any CODE other than ADDR_EXPR, NOCONVERT suppresses the default
    5672              :    promotions (such as from short to int).
    5673              :    For ADDR_EXPR, the default promotions are not applied; NOCONVERT allows
    5674              :    non-lvalues; this is only used to handle conversion of non-lvalue arrays
    5675              :    to pointers in C99.
    5676              : 
    5677              :    LOCATION is the location of the operator.  */
    5678              : 
    5679              : tree
    5680     60396868 : build_unary_op (location_t location, enum tree_code code, tree xarg,
    5681              :                 bool noconvert)
    5682              : {
    5683              :   /* No default_conversion here.  It causes trouble for ADDR_EXPR.  */
    5684     60396868 :   tree arg = xarg;
    5685     60396868 :   tree argtype = NULL_TREE;
    5686     60396868 :   enum tree_code typecode;
    5687     60396868 :   tree val;
    5688     60396868 :   tree ret = error_mark_node;
    5689     60396868 :   tree eptype = NULL_TREE;
    5690     60396868 :   const char *invalid_op_diag;
    5691     60396868 :   bool int_operands;
    5692              : 
    5693     60396868 :   int_operands = EXPR_INT_CONST_OPERANDS (xarg);
    5694      6447677 :   if (int_operands)
    5695      6447677 :     arg = remove_c_maybe_const_expr (arg);
    5696              : 
    5697     60396868 :   if (code != ADDR_EXPR)
    5698      8518613 :     arg = require_complete_type (location, arg);
    5699              : 
    5700     60396868 :   typecode = TREE_CODE (TREE_TYPE (arg));
    5701     60396868 :   if (typecode == ERROR_MARK)
    5702           74 :     return error_mark_node;
    5703     60396794 :   if (typecode == ENUMERAL_TYPE || typecode == BOOLEAN_TYPE)
    5704        32144 :     typecode = INTEGER_TYPE;
    5705              : 
    5706    120793588 :   if ((invalid_op_diag
    5707     60396794 :        = targetm.invalid_unary_op (code, TREE_TYPE (xarg))))
    5708              :     {
    5709            0 :       error_at (location, invalid_op_diag);
    5710            0 :       return error_mark_node;
    5711              :     }
    5712              : 
    5713     60396794 :   if (TREE_CODE (arg) == EXCESS_PRECISION_EXPR)
    5714              :     {
    5715          237 :       eptype = TREE_TYPE (arg);
    5716          237 :       arg = TREE_OPERAND (arg, 0);
    5717              :     }
    5718              : 
    5719     60396794 :   switch (code)
    5720              :     {
    5721        28755 :     case CONVERT_EXPR:
    5722              :       /* This is used for unary plus, because a CONVERT_EXPR
    5723              :          is enough to prevent anybody from looking inside for
    5724              :          associativity, but won't generate any code.  */
    5725        28760 :       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
    5726            8 :             || typecode == FIXED_POINT_TYPE || typecode == COMPLEX_TYPE
    5727            5 :             || typecode == BITINT_TYPE
    5728            5 :             || gnu_vector_type_p (TREE_TYPE (arg))))
    5729              :         {
    5730            1 :           error_at (location, "wrong type argument to unary plus");
    5731            1 :           return error_mark_node;
    5732              :         }
    5733        28754 :       else if (!noconvert)
    5734        28754 :         arg = default_conversion (arg);
    5735        28754 :       arg = non_lvalue_loc (location, arg);
    5736        28754 :       break;
    5737              : 
    5738      6683552 :     case NEGATE_EXPR:
    5739      7129884 :       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
    5740       482836 :             || typecode == FIXED_POINT_TYPE || typecode == COMPLEX_TYPE
    5741       451569 :             || typecode == BITINT_TYPE
    5742       446332 :             || gnu_vector_type_p (TREE_TYPE (arg))))
    5743              :         {
    5744            1 :           error_at (location, "wrong type argument to unary minus");
    5745            1 :           return error_mark_node;
    5746              :         }
    5747      6683551 :       else if (!noconvert)
    5748      6683545 :         arg = default_conversion (arg);
    5749              :       break;
    5750              : 
    5751       294690 :     case BIT_NOT_EXPR:
    5752              :       /* ~ works on integer types and non float vectors. */
    5753       294690 :       if (typecode == INTEGER_TYPE
    5754       294690 :           || typecode == BITINT_TYPE
    5755       294690 :           || (gnu_vector_type_p (TREE_TYPE (arg))
    5756         2057 :               && !VECTOR_FLOAT_TYPE_P (TREE_TYPE (arg))))
    5757              :         {
    5758              :           tree e = arg;
    5759              : 
    5760              :           /* Warn if the expression has boolean value.  */
    5761       294091 :           while (TREE_CODE (e) == COMPOUND_EXPR)
    5762           11 :             e = TREE_OPERAND (e, 1);
    5763              : 
    5764       588146 :           if ((C_BOOLEAN_TYPE_P (TREE_TYPE (arg))
    5765       588146 :                || truth_value_p (TREE_CODE (e))))
    5766              :             {
    5767          146 :               auto_diagnostic_group d;
    5768          146 :               if (warning_at (location, OPT_Wbool_operation,
    5769              :                                 "%<~%> on a boolean expression"))
    5770              :                 {
    5771           12 :                   gcc_rich_location richloc (location);
    5772           12 :                   richloc.add_fixit_insert_before (location, "!");
    5773           12 :                   inform (&richloc, "did you mean to use logical not?");
    5774           12 :                 }
    5775          146 :             }
    5776       294080 :           if (!noconvert)
    5777       294077 :             arg = default_conversion (arg);
    5778              :         }
    5779          610 :       else if (typecode == COMPLEX_TYPE)
    5780              :         {
    5781          605 :           code = CONJ_EXPR;
    5782          605 :           pedwarn (location, OPT_Wpedantic,
    5783              :                    "ISO C does not support %<~%> for complex conjugation");
    5784          605 :           if (!noconvert)
    5785          605 :             arg = default_conversion (arg);
    5786              :         }
    5787              :       else
    5788              :         {
    5789            5 :           error_at (location, "wrong type argument to bit-complement");
    5790            5 :           return error_mark_node;
    5791              :         }
    5792              :       break;
    5793              : 
    5794            3 :     case ABS_EXPR:
    5795            3 :       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE))
    5796              :         {
    5797            0 :           error_at (location, "wrong type argument to abs");
    5798            0 :           return error_mark_node;
    5799              :         }
    5800            3 :       else if (!noconvert)
    5801            0 :         arg = default_conversion (arg);
    5802              :       break;
    5803              : 
    5804            7 :     case ABSU_EXPR:
    5805            7 :       if (!(typecode == INTEGER_TYPE))
    5806              :         {
    5807            0 :           error_at (location, "wrong type argument to absu");
    5808            0 :           return error_mark_node;
    5809              :         }
    5810            7 :       else if (!noconvert)
    5811            0 :         arg = default_conversion (arg);
    5812              :       break;
    5813              : 
    5814            0 :     case CONJ_EXPR:
    5815              :       /* Conjugating a real value is a no-op, but allow it anyway.  */
    5816            0 :       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
    5817              :             || typecode == COMPLEX_TYPE))
    5818              :         {
    5819            0 :           error_at (location, "wrong type argument to conjugation");
    5820            0 :           return error_mark_node;
    5821              :         }
    5822            0 :       else if (!noconvert)
    5823            0 :         arg = default_conversion (arg);
    5824              :       break;
    5825              : 
    5826       375762 :     case TRUTH_NOT_EXPR:
    5827       375762 :       if (typecode != INTEGER_TYPE && typecode != FIXED_POINT_TYPE
    5828         7033 :           && typecode != REAL_TYPE && typecode != POINTER_TYPE
    5829           21 :           && typecode != COMPLEX_TYPE && typecode != NULLPTR_TYPE
    5830           18 :           && typecode != BITINT_TYPE)
    5831              :         {
    5832           10 :           error_at (location,
    5833              :                     "wrong type argument to unary exclamation mark");
    5834           10 :           return error_mark_node;
    5835              :         }
    5836       375752 :       if (int_operands)
    5837              :         {
    5838       139851 :           arg = c_objc_common_truthvalue_conversion (location, xarg);
    5839       139851 :           arg = remove_c_maybe_const_expr (arg);
    5840              :         }
    5841              :       else
    5842       235901 :         arg = c_objc_common_truthvalue_conversion (location, arg);
    5843       375752 :       ret = invert_truthvalue_loc (location, arg);
    5844              :       /* If the TRUTH_NOT_EXPR has been folded, reset the location.  */
    5845       375752 :       if (EXPR_P (ret) && EXPR_HAS_LOCATION (ret))
    5846       235506 :         location = EXPR_LOCATION (ret);
    5847       375752 :       goto return_build_unary_op;
    5848              : 
    5849       201216 :     case REALPART_EXPR:
    5850       201216 :     case IMAGPART_EXPR:
    5851       201216 :       ret = build_real_imag_expr (location, code, arg);
    5852       201216 :       if (ret == error_mark_node)
    5853              :         return error_mark_node;
    5854       201208 :       if (eptype && TREE_CODE (eptype) == COMPLEX_TYPE)
    5855            2 :         eptype = TREE_TYPE (eptype);
    5856       201208 :       goto return_build_unary_op;
    5857              : 
    5858       934585 :     case PREINCREMENT_EXPR:
    5859       934585 :     case POSTINCREMENT_EXPR:
    5860       934585 :     case PREDECREMENT_EXPR:
    5861       934585 :     case POSTDECREMENT_EXPR:
    5862              : 
    5863       934585 :       if (TREE_CODE (arg) == C_MAYBE_CONST_EXPR)
    5864              :         {
    5865            2 :           tree inner = build_unary_op (location, code,
    5866            2 :                                        C_MAYBE_CONST_EXPR_EXPR (arg),
    5867              :                                        noconvert);
    5868            2 :           if (inner == error_mark_node)
    5869              :             return error_mark_node;
    5870            4 :           ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner),
    5871            2 :                         C_MAYBE_CONST_EXPR_PRE (arg), inner);
    5872            2 :           gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (arg));
    5873            2 :           C_MAYBE_CONST_EXPR_NON_CONST (ret) = 1;
    5874            2 :           goto return_build_unary_op;
    5875              :         }
    5876              : 
    5877              :       /* Complain about anything that is not a true lvalue.  In
    5878              :          Objective-C, skip this check for property_refs.  */
    5879       934583 :       if (!objc_is_property_ref (arg)
    5880      1869166 :           && !lvalue_or_else (location,
    5881       934583 :                               arg, ((code == PREINCREMENT_EXPR
    5882       934583 :                                      || code == POSTINCREMENT_EXPR)
    5883              :                                     ? lv_increment
    5884              :                                     : lv_decrement)))
    5885           22 :         return error_mark_node;
    5886              : 
    5887       934561 :       if (warn_cxx_compat && TREE_CODE (TREE_TYPE (arg)) == ENUMERAL_TYPE)
    5888              :         {
    5889            4 :           if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
    5890            2 :             warning_at (location, OPT_Wc___compat,
    5891              :                         "increment of enumeration value is invalid in C++");
    5892              :           else
    5893            2 :             warning_at (location, OPT_Wc___compat,
    5894              :                         "decrement of enumeration value is invalid in C++");
    5895              :         }
    5896              : 
    5897       934561 :       if (C_BOOLEAN_TYPE_P (TREE_TYPE (arg)))
    5898              :         {
    5899          664 :           if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
    5900          328 :             warning_at (location, OPT_Wbool_operation,
    5901              :                         "increment of a boolean expression");
    5902              :           else
    5903          336 :             warning_at (location, OPT_Wbool_operation,
    5904              :                         "decrement of a boolean expression");
    5905              :         }
    5906              : 
    5907              :       /* Ensure the argument is fully folded inside any SAVE_EXPR.  */
    5908       934561 :       arg = c_fully_fold (arg, false, NULL, true);
    5909              : 
    5910       934561 :       bool atomic_op;
    5911       934561 :       atomic_op = really_atomic_lvalue (arg);
    5912              : 
    5913              :       /* Increment or decrement the real part of the value,
    5914              :          and don't change the imaginary part.  */
    5915       934561 :       if (typecode == COMPLEX_TYPE)
    5916              :         {
    5917           57 :           tree real, imag;
    5918              : 
    5919           57 :           pedwarn_c23 (location, OPT_Wpedantic,
    5920              :                        "ISO C does not support %<++%> and %<--%> on complex "
    5921              :                        "types before C2Y");
    5922              : 
    5923           57 :           if (!atomic_op)
    5924              :             {
    5925           53 :               arg = stabilize_reference (arg);
    5926           53 :               real = build_unary_op (EXPR_LOCATION (arg), REALPART_EXPR, arg,
    5927              :                                      true);
    5928           53 :               imag = build_unary_op (EXPR_LOCATION (arg), IMAGPART_EXPR, arg,
    5929              :                                      true);
    5930           53 :               real = build_unary_op (EXPR_LOCATION (arg), code, real, true);
    5931           53 :               if (real == error_mark_node || imag == error_mark_node)
    5932              :                 return error_mark_node;
    5933           53 :               ret = build2 (COMPLEX_EXPR, TREE_TYPE (arg),
    5934              :                             real, imag);
    5935           53 :               goto return_build_unary_op;
    5936              :             }
    5937              :         }
    5938              : 
    5939              :       /* Report invalid types.  */
    5940              : 
    5941       934508 :       if (typecode != POINTER_TYPE && typecode != FIXED_POINT_TYPE
    5942       704472 :           && typecode != INTEGER_TYPE && typecode != REAL_TYPE
    5943          159 :           && typecode != COMPLEX_TYPE && typecode != BITINT_TYPE
    5944       934564 :           && !gnu_vector_type_p (TREE_TYPE (arg)))
    5945              :         {
    5946            5 :           if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
    5947            3 :             error_at (location, "wrong type argument to increment");
    5948              :           else
    5949            2 :             error_at (location, "wrong type argument to decrement");
    5950              : 
    5951            5 :           return error_mark_node;
    5952              :         }
    5953              : 
    5954       934503 :       {
    5955       934503 :         tree inc;
    5956              : 
    5957       934503 :         argtype = TREE_TYPE (arg);
    5958              : 
    5959              :         /* Compute the increment.  */
    5960              : 
    5961       934503 :         if (typecode == POINTER_TYPE)
    5962              :           {
    5963              :             /* If pointer target is an incomplete type,
    5964              :                we just cannot know how to do the arithmetic.  */
    5965       230036 :             if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (argtype)))
    5966              :               {
    5967           27 :                 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
    5968           17 :                   error_at (location,
    5969              :                             "increment of pointer to an incomplete type %qT",
    5970           17 :                             TREE_TYPE (argtype));
    5971              :                 else
    5972           10 :                   error_at (location,
    5973              :                             "decrement of pointer to an incomplete type %qT",
    5974           10 :                             TREE_TYPE (argtype));
    5975              :               }
    5976       230009 :             else if (TREE_CODE (TREE_TYPE (argtype)) == FUNCTION_TYPE
    5977       230009 :                      || VOID_TYPE_P (TREE_TYPE (argtype)))
    5978              :               {
    5979           10 :                 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
    5980            6 :                   pedwarn (location, OPT_Wpointer_arith,
    5981              :                            "wrong type argument to increment");
    5982              :                 else
    5983            4 :                   pedwarn (location, OPT_Wpointer_arith,
    5984              :                            "wrong type argument to decrement");
    5985              :               }
    5986              :             else
    5987       459998 :               verify_type_context (location, TCTX_POINTER_ARITH,
    5988       229999 :                                    TREE_TYPE (argtype));
    5989              : 
    5990       230036 :             inc = c_size_in_bytes (TREE_TYPE (argtype));
    5991       230036 :             inc = convert_to_ptrofftype_loc (location, inc);
    5992              :           }
    5993       704467 :         else if (FRACT_MODE_P (TYPE_MODE (argtype)))
    5994              :           {
    5995              :             /* For signed fract types, we invert ++ to -- or
    5996              :                -- to ++, and change inc from 1 to -1, because
    5997              :                it is not possible to represent 1 in signed fract constants.
    5998              :                For unsigned fract types, the result always overflows and
    5999              :                we get an undefined (original) or the maximum value.  */
    6000            0 :             if (code == PREINCREMENT_EXPR)
    6001              :               code = PREDECREMENT_EXPR;
    6002              :             else if (code == PREDECREMENT_EXPR)
    6003              :               code = PREINCREMENT_EXPR;
    6004              :             else if (code == POSTINCREMENT_EXPR)
    6005              :               code = POSTDECREMENT_EXPR;
    6006              :             else /* code == POSTDECREMENT_EXPR  */
    6007            0 :               code = POSTINCREMENT_EXPR;
    6008              : 
    6009            0 :             inc = integer_minus_one_node;
    6010            0 :             inc = convert (argtype, inc);
    6011              :           }
    6012              :         else
    6013              :           {
    6014       704416 :             inc = VECTOR_TYPE_P (argtype)
    6015       704467 :               ? build_one_cst (argtype)
    6016              :               : integer_one_node;
    6017       704467 :             inc = convert (argtype, inc);
    6018              :           }
    6019              : 
    6020              :         /* If 'arg' is an Objective-C PROPERTY_REF expression, then we
    6021              :            need to ask Objective-C to build the increment or decrement
    6022              :            expression for it.  */
    6023       934503 :         if (objc_is_property_ref (arg))
    6024            0 :           return objc_build_incr_expr_for_property_ref (location, code,
    6025           20 :                                                         arg, inc);
    6026              : 
    6027              :         /* Report a read-only lvalue.  */
    6028       934503 :         if (TYPE_READONLY (argtype))
    6029              :           {
    6030           20 :             readonly_error (location, arg,
    6031           20 :                             ((code == PREINCREMENT_EXPR
    6032           20 :                               || code == POSTINCREMENT_EXPR)
    6033              :                              ? lv_increment : lv_decrement));
    6034           20 :             return error_mark_node;
    6035              :           }
    6036       934483 :         else if (TREE_READONLY (arg))
    6037            4 :           readonly_warning (arg,
    6038            4 :                             ((code == PREINCREMENT_EXPR
    6039            4 :                               || code == POSTINCREMENT_EXPR)
    6040              :                              ? lv_increment : lv_decrement));
    6041              : 
    6042              :         /* If the argument is atomic, use the special code sequences for
    6043              :            atomic compound assignment.  */
    6044       934483 :         if (atomic_op)
    6045              :           {
    6046         4469 :             arg = stabilize_reference (arg);
    6047         8938 :             ret = build_atomic_assign (location, arg,
    6048         4469 :                                        ((code == PREINCREMENT_EXPR
    6049         4469 :                                          || code == POSTINCREMENT_EXPR)
    6050              :                                         ? PLUS_EXPR
    6051              :                                         : MINUS_EXPR),
    6052         4469 :                                        (FRACT_MODE_P (TYPE_MODE (argtype))
    6053              :                                         ? inc
    6054              :                                         : integer_one_node),
    6055              :                                        (code == POSTINCREMENT_EXPR
    6056         4469 :                                         || code == POSTDECREMENT_EXPR));
    6057       934483 :             goto return_build_unary_op;
    6058              :           }
    6059              : 
    6060       930014 :         tree true_res;
    6061       930014 :         if (c_hardbool_type_attr (TREE_TYPE (arg), NULL, &true_res))
    6062              :           {
    6063          364 :             tree larg = stabilize_reference (arg);
    6064          364 :             tree sarg = save_expr (larg);
    6065          364 :             switch (code)
    6066              :               {
    6067           91 :               case PREINCREMENT_EXPR:
    6068           91 :                 val = build2 (MODIFY_EXPR, TREE_TYPE (larg), larg, true_res);
    6069           91 :                 val = build2 (COMPOUND_EXPR, TREE_TYPE (larg), sarg, val);
    6070           91 :                 break;
    6071           91 :               case POSTINCREMENT_EXPR:
    6072           91 :                 val = build2 (MODIFY_EXPR, TREE_TYPE (larg), larg, true_res);
    6073           91 :                 val = build2 (COMPOUND_EXPR, TREE_TYPE (larg), val, sarg);
    6074           91 :                 val = build2 (COMPOUND_EXPR, TREE_TYPE (larg), sarg, val);
    6075           91 :                 break;
    6076           91 :               case PREDECREMENT_EXPR:
    6077           91 :                 {
    6078           91 :                   tree rarg = convert_lvalue_to_rvalue (location, sarg,
    6079              :                                                         true, true);
    6080           91 :                   rarg = invert_truthvalue_loc (location, rarg);
    6081           91 :                   rarg = convert (TREE_TYPE (sarg), rarg);
    6082           91 :                   val = build2 (MODIFY_EXPR, TREE_TYPE (larg), larg, rarg);
    6083              :                 }
    6084           91 :                 break;
    6085           91 :               case POSTDECREMENT_EXPR:
    6086           91 :                 {
    6087           91 :                   tree rarg = convert_lvalue_to_rvalue (location, sarg,
    6088              :                                                         true, true);
    6089           91 :                   rarg = invert_truthvalue_loc (location, rarg);
    6090           91 :                   tree iarg = convert (TREE_TYPE (larg), rarg);
    6091           91 :                   val = build2 (MODIFY_EXPR, TREE_TYPE (larg), larg, iarg);
    6092           91 :                   val = build2 (COMPOUND_EXPR, TREE_TYPE (larg), val, sarg);
    6093           91 :                   val = build2 (COMPOUND_EXPR, TREE_TYPE (larg), sarg, val);
    6094              :                 }
    6095           91 :                 break;
    6096              :               default:
    6097              :                 gcc_unreachable ();
    6098              :               }
    6099          364 :             TREE_SIDE_EFFECTS (val) = 1;
    6100              :           }
    6101       929650 :         else if (C_BOOLEAN_TYPE_P (TREE_TYPE (arg)))
    6102           64 :           val = boolean_increment (code, arg);
    6103              :         else
    6104       929586 :           val = build2 (code, TREE_TYPE (arg), arg, inc);
    6105       930014 :         TREE_SIDE_EFFECTS (val) = 1;
    6106       930014 :         if (TYPE_QUALS (TREE_TYPE (val)) != TYPE_UNQUALIFIED)
    6107         3932 :           TREE_TYPE (val) = c_build_qualified_type (TREE_TYPE (val),
    6108              :                                                     TYPE_UNQUALIFIED);
    6109       930014 :         ret = val;
    6110       930014 :         goto return_build_unary_op;
    6111              :       }
    6112              : 
    6113     51878214 :     case ADDR_EXPR:
    6114              :       /* Note that this operation never does default_conversion.  */
    6115              : 
    6116              :       /* The operand of unary '&' must be an lvalue (which excludes
    6117              :          expressions of type void), or, in C99, the result of a [] or
    6118              :          unary '*' operator.  */
    6119     51878214 :       if (VOID_TYPE_P (TREE_TYPE (arg))
    6120           25 :           && TYPE_QUALS (TREE_TYPE (arg)) == TYPE_UNQUALIFIED
    6121     51878233 :           && (!INDIRECT_REF_P (arg) || !flag_isoc99))
    6122           18 :         pedwarn (location, 0, "taking address of expression of type %<void%>");
    6123              : 
    6124              :       /* Let &* cancel out to simplify resulting code.  */
    6125     51878214 :       if (INDIRECT_REF_P (arg))
    6126              :         {
    6127              :           /* Don't let this be an lvalue.  */
    6128        22186 :           if (lvalue_p (TREE_OPERAND (arg, 0)))
    6129        16737 :             return non_lvalue_loc (location, TREE_OPERAND (arg, 0));
    6130         5449 :           ret = TREE_OPERAND (arg, 0);
    6131         5449 :           goto return_build_unary_op;
    6132              :         }
    6133              : 
    6134              :       /* Anything not already handled and not a true memory reference
    6135              :          or a non-lvalue array is an error.  */
    6136     51856028 :       if (typecode != FUNCTION_TYPE && !noconvert
    6137     51856028 :           && !lvalue_or_else (location, arg, lv_addressof))
    6138           17 :         return error_mark_node;
    6139              : 
    6140              :       /* Move address operations inside C_MAYBE_CONST_EXPR to simplify
    6141              :          folding later.  */
    6142     51856011 :       if (TREE_CODE (arg) == C_MAYBE_CONST_EXPR)
    6143              :         {
    6144           14 :           tree inner = build_unary_op (location, code,
    6145           14 :                                        C_MAYBE_CONST_EXPR_EXPR (arg),
    6146              :                                        noconvert);
    6147           28 :           ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner),
    6148           14 :                         C_MAYBE_CONST_EXPR_PRE (arg), inner);
    6149           14 :           gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (arg));
    6150           14 :           C_MAYBE_CONST_EXPR_NON_CONST (ret)
    6151           14 :             = C_MAYBE_CONST_EXPR_NON_CONST (arg);
    6152           14 :           goto return_build_unary_op;
    6153              :         }
    6154              : 
    6155              :       /* Ordinary case; arg is a COMPONENT_REF or a decl, or a call to
    6156              :          .ACCESS_WITH_SIZE.  */
    6157     51855997 :       if (is_access_with_size_p (arg))
    6158            0 :         arg = TREE_OPERAND (TREE_OPERAND (CALL_EXPR_ARG (arg, 0), 0), 0);
    6159              : 
    6160     51855997 :       argtype = TREE_TYPE (arg);
    6161              : 
    6162              :       /* If the lvalue is const or volatile, merge that into the type
    6163              :          to which the address will point.  This is only needed
    6164              :          for function types.  */
    6165     51855997 :       if ((DECL_P (arg) || REFERENCE_CLASS_P (arg))
    6166     51369289 :           && (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg))
    6167     81885860 :           && TREE_CODE (argtype) == FUNCTION_TYPE)
    6168              :         {
    6169     29949903 :           int orig_quals = TYPE_QUALS (strip_array_types (argtype));
    6170     29949903 :           int quals = orig_quals;
    6171              : 
    6172     29949903 :           if (TREE_READONLY (arg))
    6173     29576302 :             quals |= TYPE_QUAL_CONST;
    6174     29949903 :           if (TREE_THIS_VOLATILE (arg))
    6175       374488 :             quals |= TYPE_QUAL_VOLATILE;
    6176              : 
    6177     29949903 :           argtype = c_build_qualified_type (argtype, quals);
    6178              :         }
    6179              : 
    6180     51855997 :       switch (TREE_CODE (arg))
    6181              :         {
    6182        65542 :         case COMPONENT_REF:
    6183        65542 :           if (DECL_C_BIT_FIELD (TREE_OPERAND (arg, 1)))
    6184              :             {
    6185            8 :               error_at (location, "cannot take address of bit-field %qD",
    6186            8 :                         TREE_OPERAND (arg, 1));
    6187            8 :               return error_mark_node;
    6188              :             }
    6189              : 
    6190              :           /* fall through */
    6191              : 
    6192       139670 :         case ARRAY_REF:
    6193       139670 :           if (TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (TREE_OPERAND (arg, 0))))
    6194              :             {
    6195           78 :               if (!AGGREGATE_TYPE_P (TREE_TYPE (arg))
    6196            7 :                   && !POINTER_TYPE_P (TREE_TYPE (arg))
    6197           75 :                   && !VECTOR_TYPE_P (TREE_TYPE (arg)))
    6198              :                 {
    6199            6 :                   error_at (location, "cannot take address of scalar with "
    6200              :                             "reverse storage order");
    6201            6 :                   return error_mark_node;
    6202              :                 }
    6203              : 
    6204           63 :               if (TREE_CODE (TREE_TYPE (arg)) == ARRAY_TYPE
    6205           63 :                   && TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (arg)))
    6206           58 :                 warning_at (location, OPT_Wscalar_storage_order,
    6207              :                             "address of array with reverse scalar storage "
    6208              :                             "order requested");
    6209              :             }
    6210              : 
    6211     51855983 :         default:
    6212     51855983 :           break;
    6213              :         }
    6214              : 
    6215     51855983 :       if (!c_mark_addressable (arg))
    6216           20 :         return error_mark_node;
    6217              : 
    6218     51855963 :       gcc_assert (TREE_CODE (arg) != COMPONENT_REF
    6219              :                   || !DECL_C_BIT_FIELD (TREE_OPERAND (arg, 1)));
    6220              : 
    6221     51855963 :       argtype = c_build_pointer_type (argtype);
    6222              : 
    6223              :       /* ??? Cope with user tricks that amount to offsetof.  Delete this
    6224              :          when we have proper support for integer constant expressions.  */
    6225     51855963 :       val = get_base_address (arg);
    6226     51855963 :       if (val && INDIRECT_REF_P (val)
    6227     51879946 :           && TREE_CONSTANT (TREE_OPERAND (val, 0)))
    6228              :         {
    6229          540 :           ret = fold_offsetof (arg, argtype);
    6230          540 :           goto return_build_unary_op;
    6231              :         }
    6232              : 
    6233     51855423 :       val = build1 (ADDR_EXPR, argtype, arg);
    6234              : 
    6235     51855423 :       ret = val;
    6236     51855423 :       goto return_build_unary_op;
    6237              : 
    6238           10 :     case PAREN_EXPR:
    6239           10 :       ret = build1 (code, TREE_TYPE (arg), arg);
    6240           10 :       goto return_build_unary_op;
    6241              : 
    6242            0 :     default:
    6243            0 :       gcc_unreachable ();
    6244              :     }
    6245              : 
    6246      7007000 :   if (argtype == NULL_TREE)
    6247      7007000 :     argtype = TREE_TYPE (arg);
    6248      7007000 :   if (TREE_CODE (arg) == INTEGER_CST)
    6249      6303867 :     ret = (require_constant_value
    6250      6303867 :            ? fold_build1_initializer_loc (location, code, argtype, arg)
    6251      6285286 :            : fold_build1_loc (location, code, argtype, arg));
    6252              :   else
    6253       703133 :     ret = build1 (code, argtype, arg);
    6254     60379934 :  return_build_unary_op:
    6255     60379934 :   gcc_assert (ret != error_mark_node);
    6256      6448153 :   if (TREE_CODE (ret) == INTEGER_CST && !TREE_OVERFLOW (ret)
    6257     66828078 :       && !(TREE_CODE (xarg) == INTEGER_CST && !TREE_OVERFLOW (xarg)))
    6258          562 :     ret = build1 (NOP_EXPR, TREE_TYPE (ret), ret);
    6259     60379372 :   else if (TREE_CODE (ret) != INTEGER_CST && int_operands)
    6260           74 :     ret = note_integer_operands (ret);
    6261     60379934 :   if (eptype)
    6262          237 :     ret = build1 (EXCESS_PRECISION_EXPR, eptype, ret);
    6263     60379934 :   protected_set_expr_location (ret, location);
    6264     60379934 :   return ret;
    6265              : }
    6266              : 
    6267              : /* Return nonzero if REF is an lvalue valid for this language.
    6268              :    Lvalues can be assigned, unless their type has TYPE_READONLY.
    6269              :    Lvalues can have their address taken, unless they have C_DECL_REGISTER.  */
    6270              : 
    6271              : bool
    6272    177953439 : lvalue_p (const_tree ref)
    6273              : {
    6274    179446396 :   const enum tree_code code = TREE_CODE (ref);
    6275              : 
    6276    179446396 :   switch (code)
    6277              :     {
    6278      1468204 :     case REALPART_EXPR:
    6279      1468204 :     case IMAGPART_EXPR:
    6280      1468204 :     case COMPONENT_REF:
    6281      1468204 :       return lvalue_p (TREE_OPERAND (ref, 0));
    6282              : 
    6283        24753 :     case C_MAYBE_CONST_EXPR:
    6284        24753 :       return lvalue_p (TREE_OPERAND (ref, 1));
    6285              : 
    6286              :     case COMPOUND_LITERAL_EXPR:
    6287              :     case STRING_CST:
    6288              :       return true;
    6289              : 
    6290     25454997 :     case MEM_REF:
    6291     25454997 :     case TARGET_MEM_REF:
    6292              :       /* MEM_REFs can appear from -fgimple parsing or folding, so allow them
    6293              :          here as well.  */
    6294     25454997 :     case INDIRECT_REF:
    6295     25454997 :     case ARRAY_REF:
    6296     25454997 :     case VAR_DECL:
    6297     25454997 :     case PARM_DECL:
    6298     25454997 :     case RESULT_DECL:
    6299     25454997 :     case ERROR_MARK:
    6300     25454997 :       return (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE
    6301     25454997 :               && TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE);
    6302              : 
    6303            6 :     case BIND_EXPR:
    6304            6 :       return TREE_CODE (TREE_TYPE (ref)) == ARRAY_TYPE;
    6305              : 
    6306      7069122 :     case CALL_EXPR:
    6307      7069122 :       return is_access_with_size_p (ref);
    6308              : 
    6309              :     default:
    6310              :       return false;
    6311              :     }
    6312              : }
    6313              : 
    6314              : /* Give a warning for storing in something that is read-only in GCC
    6315              :    terms but not const in ISO C terms.  */
    6316              : 
    6317              : static void
    6318            5 : readonly_warning (tree arg, enum lvalue_use use)
    6319              : {
    6320            5 :   switch (use)
    6321              :     {
    6322            1 :     case lv_assign:
    6323            1 :       warning (0, "assignment of read-only location %qE", arg);
    6324            1 :       break;
    6325            2 :     case lv_increment:
    6326            2 :       warning (0, "increment of read-only location %qE", arg);
    6327            2 :       break;
    6328            2 :     case lv_decrement:
    6329            2 :       warning (0, "decrement of read-only location %qE", arg);
    6330            2 :       break;
    6331            0 :     default:
    6332            0 :       gcc_unreachable ();
    6333              :     }
    6334            5 :   return;
    6335              : }
    6336              : 
    6337              : 
    6338              : /* Return nonzero if REF is an lvalue valid for this language;
    6339              :    otherwise, print an error message and return zero.  USE says
    6340              :    how the lvalue is being used and so selects the error message.
    6341              :    LOCATION is the location at which any error should be reported.  */
    6342              : 
    6343              : static int
    6344      4710960 : lvalue_or_else (location_t loc, const_tree ref, enum lvalue_use use)
    6345              : {
    6346      4710960 :   int win = lvalue_p (ref);
    6347              : 
    6348      4710960 :   if (!win)
    6349           75 :     lvalue_error (loc, use);
    6350              : 
    6351      4710960 :   return win;
    6352              : }
    6353              : 
    6354              : /* Mark EXP saying that we need to be able to take the
    6355              :    address of it; it should not be allocated in a register.
    6356              :    Returns true if successful.  ARRAY_REF_P is true if this
    6357              :    is for ARRAY_REF construction - in that case we don't want
    6358              :    to look through VIEW_CONVERT_EXPR from VECTOR_TYPE to ARRAY_TYPE,
    6359              :    it is fine to use ARRAY_REFs for vector subscripts on vector
    6360              :    register variables.  If OVERRIDE_REGISTER, clear DECL_REGISTER rather
    6361              :    than producing an error for taking the address of a register.  */
    6362              : 
    6363              : bool
    6364     52400448 : c_mark_addressable (tree exp, bool array_ref_p, bool override_register)
    6365              : {
    6366     52400448 :   tree x = exp;
    6367              : 
    6368     52980939 :   while (1)
    6369     52980939 :     switch (TREE_CODE (x))
    6370              :       {
    6371        10029 :       case VIEW_CONVERT_EXPR:
    6372        10029 :         if (array_ref_p
    6373         9919 :             && TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
    6374        19948 :             && VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (x, 0))))
    6375              :           return true;
    6376          110 :         x = TREE_OPERAND (x, 0);
    6377          110 :         break;
    6378              : 
    6379       396299 :       case COMPONENT_REF:
    6380       396299 :         if (DECL_C_BIT_FIELD (TREE_OPERAND (x, 1)))
    6381              :           {
    6382            6 :             error ("cannot take address of bit-field %qD",
    6383            3 :                    TREE_OPERAND (x, 1));
    6384            3 :             return false;
    6385              :           }
    6386              :         /* FALLTHRU */
    6387       580381 :       case ADDR_EXPR:
    6388       580381 :       case ARRAY_REF:
    6389       580381 :       case REALPART_EXPR:
    6390       580381 :       case IMAGPART_EXPR:
    6391       580381 :         x = TREE_OPERAND (x, 0);
    6392       580381 :         break;
    6393              : 
    6394          587 :       case COMPOUND_LITERAL_EXPR:
    6395          587 :         if (C_DECL_REGISTER (COMPOUND_LITERAL_EXPR_DECL (x)))
    6396              :           {
    6397           16 :             if (override_register)
    6398           12 :               DECL_REGISTER (COMPOUND_LITERAL_EXPR_DECL (x)) = 0;
    6399              :             else
    6400              :               {
    6401            4 :                 error ("address of register compound literal requested");
    6402            4 :                 return false;
    6403              :               }
    6404              :           }
    6405          583 :         TREE_ADDRESSABLE (x) = 1;
    6406          583 :         TREE_ADDRESSABLE (COMPOUND_LITERAL_EXPR_DECL (x)) = 1;
    6407          583 :         return true;
    6408              : 
    6409            0 :       case CONSTRUCTOR:
    6410            0 :         TREE_ADDRESSABLE (x) = 1;
    6411            0 :         return true;
    6412              : 
    6413      1320336 :       case VAR_DECL:
    6414      1320336 :       case CONST_DECL:
    6415      1320336 :       case PARM_DECL:
    6416      1320336 :       case RESULT_DECL:
    6417      1320336 :         if (C_DECL_REGISTER (x)
    6418      1320336 :             && DECL_NONLOCAL (x))
    6419              :           {
    6420            0 :             if (TREE_PUBLIC (x) || is_global_var (x))
    6421              :               {
    6422            0 :                 error
    6423            0 :                   ("global register variable %qD used in nested function", x);
    6424            0 :                 return false;
    6425              :               }
    6426            0 :             pedwarn (input_location, 0, "register variable %qD used in nested function", x);
    6427              :           }
    6428      1320336 :         else if (C_DECL_REGISTER (x))
    6429              :           {
    6430           73 :             if (TREE_PUBLIC (x) || is_global_var (x))
    6431            4 :               error ("address of global register variable %qD requested", x);
    6432          123 :             else if (override_register && !DECL_HARD_REGISTER (x))
    6433              :               {
    6434           54 :                 DECL_REGISTER (x) = 0;
    6435           54 :                 TREE_ADDRESSABLE (x) = 1;
    6436           54 :                 mark_decl_used (x, true);
    6437           54 :                 return true;
    6438              :               }
    6439              :             else
    6440           15 :               error ("address of register variable %qD requested", x);
    6441           19 :             return false;
    6442              :           }
    6443              : 
    6444              :         /* FALLTHRU */
    6445     51828036 :       case FUNCTION_DECL:
    6446     51828036 :         TREE_ADDRESSABLE (x) = 1;
    6447     51828036 :         mark_decl_used (x, true);
    6448              :         /* FALLTHRU */
    6449              :       default:
    6450              :         return true;
    6451              :     }
    6452              : }
    6453              : 
    6454              : /* Convert EXPR to TYPE, warning about conversion problems with
    6455              :    constants.  SEMANTIC_TYPE is the type this conversion would use
    6456              :    without excess precision. If SEMANTIC_TYPE is NULL, this function
    6457              :    is equivalent to convert_and_check. This function is a wrapper that
    6458              :    handles conversions that may be different than
    6459              :    the usual ones because of excess precision.  */
    6460              : 
    6461              : static tree
    6462     23570316 : ep_convert_and_check (location_t loc, tree type, tree expr,
    6463              :                       tree semantic_type)
    6464              : {
    6465     23570316 :   if (TREE_TYPE (expr) == type)
    6466              :     return expr;
    6467              : 
    6468              :   /* For C11, integer conversions may have results with excess
    6469              :      precision.  */
    6470      2056352 :   if (flag_isoc11 || !semantic_type)
    6471      2056348 :     return convert_and_check (loc, type, expr);
    6472              : 
    6473            4 :   if (TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
    6474            4 :       && TREE_TYPE (expr) != semantic_type)
    6475              :     {
    6476              :       /* For integers, we need to check the real conversion, not
    6477              :          the conversion to the excess precision type.  */
    6478            4 :       expr = convert_and_check (loc, semantic_type, expr);
    6479              :     }
    6480              :   /* Result type is the excess precision type, which should be
    6481              :      large enough, so do not check.  */
    6482            4 :   return convert (type, expr);
    6483              : }
    6484              : 
    6485              : /* If EXPR refers to a built-in declared without a prototype returns
    6486              :    the actual type of the built-in and, if non-null, set *BLTIN to
    6487              :    a pointer to the built-in.  Otherwise return the type of EXPR
    6488              :    and clear *BLTIN if non-null.  */
    6489              : 
    6490              : static tree
    6491      2831889 : type_or_builtin_type (tree expr, tree *bltin = NULL)
    6492              : {
    6493      2831889 :   tree dummy;
    6494      2831889 :   if (!bltin)
    6495            0 :     bltin = &dummy;
    6496              : 
    6497      2831889 :   *bltin = NULL_TREE;
    6498              : 
    6499      2831889 :   tree type = TREE_TYPE (expr);
    6500      2831889 :   if (TREE_CODE (expr) != ADDR_EXPR)
    6501              :     return type;
    6502              : 
    6503       208475 :   tree oper = TREE_OPERAND (expr, 0);
    6504       208475 :   if (!DECL_P (oper)
    6505       169975 :       || TREE_CODE (oper) != FUNCTION_DECL
    6506       244893 :       || !fndecl_built_in_p (oper, BUILT_IN_NORMAL))
    6507              :     return type;
    6508              : 
    6509         2086 :   built_in_function code = DECL_FUNCTION_CODE (oper);
    6510         2086 :   if (!C_DECL_BUILTIN_PROTOTYPE (oper))
    6511              :     return type;
    6512              : 
    6513         1977 :   if ((*bltin = builtin_decl_implicit (code)))
    6514          991 :     type = c_build_pointer_type (TREE_TYPE (*bltin));
    6515              : 
    6516              :   return type;
    6517              : }
    6518              : 
    6519              : /* Build and return a conditional expression IFEXP ? OP1 : OP2.  If
    6520              :    IFEXP_BCP then the condition is a call to __builtin_constant_p, and
    6521              :    if folded to an integer constant then the unselected half may
    6522              :    contain arbitrary operations not normally permitted in constant
    6523              :    expressions.  Set the location of the expression to LOC.  */
    6524              : 
    6525              : tree
    6526       408596 : build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp,
    6527              :                         tree op1, tree op1_original_type, location_t op1_loc,
    6528              :                         tree op2, tree op2_original_type, location_t op2_loc)
    6529              : {
    6530       408596 :   tree type1;
    6531       408596 :   tree type2;
    6532       408596 :   tree result_type = NULL;
    6533       408596 :   tree semantic_result_type = NULL;
    6534       408596 :   tree orig_op1 = op1, orig_op2 = op2;
    6535       408596 :   bool int_const, op1_int_operands, op2_int_operands, int_operands;
    6536       408596 :   bool ifexp_int_operands;
    6537       408596 :   tree ret;
    6538              : 
    6539       408596 :   op1_int_operands = EXPR_INT_CONST_OPERANDS (orig_op1);
    6540       116053 :   if (op1_int_operands)
    6541       116053 :     op1 = remove_c_maybe_const_expr (op1);
    6542       408596 :   op2_int_operands = EXPR_INT_CONST_OPERANDS (orig_op2);
    6543       151204 :   if (op2_int_operands)
    6544       151204 :     op2 = remove_c_maybe_const_expr (op2);
    6545       408596 :   ifexp_int_operands = EXPR_INT_CONST_OPERANDS (ifexp);
    6546       242233 :   if (ifexp_int_operands)
    6547       242233 :     ifexp = remove_c_maybe_const_expr (ifexp);
    6548              : 
    6549              :   /* Promote both alternatives.  */
    6550              : 
    6551       408596 :   if (TREE_CODE (TREE_TYPE (op1)) != VOID_TYPE)
    6552       404679 :     op1 = default_conversion (op1);
    6553       408596 :   if (TREE_CODE (TREE_TYPE (op2)) != VOID_TYPE)
    6554       378756 :     op2 = default_conversion (op2);
    6555              : 
    6556       408596 :   if (TREE_CODE (ifexp) == ERROR_MARK
    6557       408527 :       || TREE_CODE (TREE_TYPE (op1)) == ERROR_MARK
    6558       817109 :       || TREE_CODE (TREE_TYPE (op2)) == ERROR_MARK)
    6559           83 :     return error_mark_node;
    6560              : 
    6561       408513 :   tree bltin1 = NULL_TREE;
    6562       408513 :   tree bltin2 = NULL_TREE;
    6563       408513 :   type1 = type_or_builtin_type (op1, &bltin1);
    6564       408513 :   const enum tree_code code1 = TREE_CODE (type1);
    6565       408513 :   type2 = type_or_builtin_type (op2, &bltin2);
    6566       408513 :   const enum tree_code code2 = TREE_CODE (type2);
    6567              : 
    6568       408513 :   if (code1 == POINTER_TYPE && reject_gcc_builtin (op1))
    6569            1 :     return error_mark_node;
    6570              : 
    6571       408512 :   if (code2 == POINTER_TYPE && reject_gcc_builtin (op2))
    6572            1 :     return error_mark_node;
    6573              : 
    6574              :   /* C90 does not permit non-lvalue arrays in conditional expressions.
    6575              :      In C99 they will be pointers by now.  */
    6576       408511 :   if (code1 == ARRAY_TYPE || code2 == ARRAY_TYPE)
    6577              :     {
    6578            1 :       error_at (colon_loc, "non-lvalue array in conditional expression");
    6579            1 :       return error_mark_node;
    6580              :     }
    6581              : 
    6582       408510 :   if ((TREE_CODE (op1) == EXCESS_PRECISION_EXPR
    6583       408504 :        || TREE_CODE (op2) == EXCESS_PRECISION_EXPR)
    6584            7 :       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
    6585            0 :           || code1 == COMPLEX_TYPE || code1 == BITINT_TYPE)
    6586            7 :       && (code2 == INTEGER_TYPE || code2 == REAL_TYPE
    6587            0 :           || code2 == COMPLEX_TYPE || code2 == BITINT_TYPE))
    6588              :     {
    6589            7 :       semantic_result_type = c_common_type (type1, type2);
    6590            7 :       if (TREE_CODE (op1) == EXCESS_PRECISION_EXPR)
    6591              :         {
    6592            6 :           op1 = TREE_OPERAND (op1, 0);
    6593            6 :           type1 = TREE_TYPE (op1);
    6594            6 :           gcc_assert (TREE_CODE (type1) == code1);
    6595              :         }
    6596            7 :       if (TREE_CODE (op2) == EXCESS_PRECISION_EXPR)
    6597              :         {
    6598            1 :           op2 = TREE_OPERAND (op2, 0);
    6599            1 :           type2 = TREE_TYPE (op2);
    6600            1 :           gcc_assert (TREE_CODE (type2) == code2);
    6601              :         }
    6602              :     }
    6603              : 
    6604       408510 :   if (warn_cxx_compat)
    6605              :     {
    6606          418 :       tree t1 = op1_original_type ? op1_original_type : TREE_TYPE (orig_op1);
    6607          418 :       tree t2 = op2_original_type ? op2_original_type : TREE_TYPE (orig_op2);
    6608              : 
    6609          418 :       if (TREE_CODE (t1) == ENUMERAL_TYPE
    6610            6 :           && TREE_CODE (t2) == ENUMERAL_TYPE
    6611          424 :           && TYPE_MAIN_VARIANT (t1) != TYPE_MAIN_VARIANT (t2))
    6612            2 :         warning_at (colon_loc, OPT_Wc___compat,
    6613              :                     "different enum types in conditional is "
    6614              :                     "invalid in C++: %qT vs %qT", t1, t2);
    6615              :     }
    6616              : 
    6617       408510 :   if (warn_zero_as_null_pointer_constant
    6618           20 :       && c_inhibit_evaluation_warnings == 0)
    6619              :     {
    6620           20 :       if ((code1 == POINTER_TYPE || code1 == NULLPTR_TYPE)
    6621           20 :           && INTEGRAL_TYPE_P (type2) && null_pointer_constant_p (orig_op2))
    6622            5 :         warning_at (op2_loc, OPT_Wzero_as_null_pointer_constant,
    6623              :                     "zero as null pointer constant");
    6624              : 
    6625           20 :       if ((code2 == POINTER_TYPE || code2 == NULLPTR_TYPE)
    6626           20 :           && INTEGRAL_TYPE_P (type1) && null_pointer_constant_p (orig_op1))
    6627            5 :         warning_at (op1_loc, OPT_Wzero_as_null_pointer_constant,
    6628              :                     "zero as null pointer constant");
    6629              :     }
    6630              : 
    6631              :   /* Quickly detect the usual case where op1 and op2 have the same type
    6632              :      after promotion.  */
    6633       408510 :   if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2))
    6634              :     {
    6635       274040 :       if (type1 == type2)
    6636              :         result_type = type1;
    6637              :       else
    6638         6362 :         result_type = TYPE_MAIN_VARIANT (type1);
    6639              :     }
    6640       134470 :   else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE
    6641        79853 :             || code1 == COMPLEX_TYPE || code1 == BITINT_TYPE)
    6642        54665 :            && (code2 == INTEGER_TYPE || code2 == REAL_TYPE
    6643        26152 :                || code2 == COMPLEX_TYPE || code2 == BITINT_TYPE))
    6644              :     {
    6645              :       /* In C11, a conditional expression between a floating-point
    6646              :          type and an integer type should convert the integer type to
    6647              :          the evaluation format of the floating-point type, with
    6648              :          possible excess precision.  */
    6649        28613 :       tree eptype1 = type1;
    6650        28613 :       tree eptype2 = type2;
    6651        28613 :       if (flag_isoc11)
    6652              :         {
    6653        28300 :           tree eptype;
    6654        11640 :           if (ANY_INTEGRAL_TYPE_P (type1)
    6655        28300 :               && (eptype = excess_precision_type (type2)) != NULL_TREE)
    6656              :             {
    6657            2 :               eptype2 = eptype;
    6658            2 :               if (!semantic_result_type)
    6659            2 :                 semantic_result_type = c_common_type (type1, type2);
    6660              :             }
    6661          501 :           else if (ANY_INTEGRAL_TYPE_P (type2)
    6662        28298 :                    && (eptype = excess_precision_type (type1)) != NULL_TREE)
    6663              :             {
    6664         4626 :               eptype1 = eptype;
    6665         4626 :               if (!semantic_result_type)
    6666         4626 :                 semantic_result_type = c_common_type (type1, type2);
    6667              :             }
    6668              :         }
    6669        28613 :       result_type = c_common_type (eptype1, eptype2);
    6670        28613 :       if (result_type == error_mark_node)
    6671              :         return error_mark_node;
    6672        28611 :       do_warn_double_promotion (result_type, type1, type2,
    6673              :                                 "implicit conversion from %qT to %qT to "
    6674              :                                 "match other result of conditional",
    6675              :                                 colon_loc);
    6676              : 
    6677              :       /* If -Wsign-compare, warn here if type1 and type2 have
    6678              :          different signedness.  We'll promote the signed to unsigned
    6679              :          and later code won't know it used to be different.
    6680              :          Do this check on the original types, so that explicit casts
    6681              :          will be considered, but default promotions won't.  */
    6682        28611 :       if (c_inhibit_evaluation_warnings == 0)
    6683              :         {
    6684        28420 :           int unsigned_op1 = TYPE_UNSIGNED (TREE_TYPE (orig_op1));
    6685        28420 :           int unsigned_op2 = TYPE_UNSIGNED (TREE_TYPE (orig_op2));
    6686              : 
    6687        28420 :           if (unsigned_op1 ^ unsigned_op2)
    6688              :             {
    6689        13011 :               bool ovf;
    6690              : 
    6691              :               /* Do not warn if the result type is signed, since the
    6692              :                  signed type will only be chosen if it can represent
    6693              :                  all the values of the unsigned type.  */
    6694        13011 :               if (!TYPE_UNSIGNED (result_type))
    6695              :                 /* OK */;
    6696              :               else
    6697              :                 {
    6698        12907 :                   bool op1_maybe_const = true;
    6699        12907 :                   bool op2_maybe_const = true;
    6700              : 
    6701              :                   /* Do not warn if the signed quantity is an
    6702              :                      unsuffixed integer literal (or some static
    6703              :                      constant expression involving such literals) and
    6704              :                      it is non-negative.  This warning requires the
    6705              :                      operands to be folded for best results, so do
    6706              :                      that folding in this case even without
    6707              :                      warn_sign_compare to avoid warning options
    6708              :                      possibly affecting code generation.  */
    6709        12907 :                   c_inhibit_evaluation_warnings
    6710        12907 :                     += (ifexp == truthvalue_false_node);
    6711        12907 :                   op1 = c_fully_fold (op1, require_constant_value,
    6712              :                                       &op1_maybe_const);
    6713        12907 :                   c_inhibit_evaluation_warnings
    6714        12907 :                     -= (ifexp == truthvalue_false_node);
    6715              : 
    6716        12907 :                   c_inhibit_evaluation_warnings
    6717        12907 :                     += (ifexp == truthvalue_true_node);
    6718        12907 :                   op2 = c_fully_fold (op2, require_constant_value,
    6719              :                                       &op2_maybe_const);
    6720        12907 :                   c_inhibit_evaluation_warnings
    6721        12907 :                     -= (ifexp == truthvalue_true_node);
    6722              : 
    6723        12907 :                   if (warn_sign_compare)
    6724              :                     {
    6725         1245 :                       if ((unsigned_op2
    6726          685 :                            && tree_expr_nonnegative_warnv_p (op1, &ovf))
    6727         1248 :                           || (unsigned_op1
    6728          560 :                               && tree_expr_nonnegative_warnv_p (op2, &ovf)))
    6729              :                         /* OK */;
    6730           10 :                       else if (unsigned_op2)
    6731            3 :                         warning_at (op1_loc, OPT_Wsign_compare,
    6732              :                                     "operand of %<?:%> changes signedness from "
    6733              :                                     "%qT to %qT due to unsignedness of other "
    6734            3 :                                     "operand", TREE_TYPE (orig_op1),
    6735            3 :                                     TREE_TYPE (orig_op2));
    6736              :                       else
    6737            7 :                         warning_at (op2_loc, OPT_Wsign_compare,
    6738              :                                     "operand of %<?:%> changes signedness from "
    6739              :                                     "%qT to %qT due to unsignedness of other "
    6740            7 :                                     "operand", TREE_TYPE (orig_op2),
    6741            7 :                                     TREE_TYPE (orig_op1));
    6742              :                     }
    6743        12907 :                   if (!op1_maybe_const || TREE_CODE (op1) != INTEGER_CST)
    6744         7562 :                     op1 = c_wrap_maybe_const (op1, !op1_maybe_const);
    6745        12907 :                   if (!op2_maybe_const || TREE_CODE (op2) != INTEGER_CST)
    6746         4391 :                     op2 = c_wrap_maybe_const (op2, !op2_maybe_const);
    6747              :                 }
    6748              :             }
    6749              :         }
    6750              :     }
    6751       105857 :   else if (code1 == VOID_TYPE || code2 == VOID_TYPE)
    6752              :     {
    6753        25995 :       if (code1 != VOID_TYPE || code2 != VOID_TYPE)
    6754        25995 :         pedwarn (colon_loc, OPT_Wpedantic,
    6755              :                  "ISO C forbids conditional expr with only one void side");
    6756        25995 :       result_type = void_type_node;
    6757              :     }
    6758        79862 :   else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE)
    6759              :     {
    6760        79465 :       addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (type1));
    6761        79465 :       addr_space_t as2 = TYPE_ADDR_SPACE (TREE_TYPE (type2));
    6762        79465 :       addr_space_t as_common;
    6763              : 
    6764        79465 :       if (comp_target_types (colon_loc, type1, type2))
    6765              :         {
    6766         2604 :           ifexp = save_expr (ifexp);
    6767         2604 :           result_type = common_pointer_type (type1, type2, ifexp);
    6768              :         }
    6769        76861 :       else if (null_pointer_constant_p (orig_op1))
    6770              :         result_type = type2;
    6771        72699 :       else if (null_pointer_constant_p (orig_op2))
    6772              :         result_type = type1;
    6773        34803 :       else if (!addr_space_superset (as1, as2, &as_common))
    6774              :         {
    6775            0 :           error_at (colon_loc, "pointers to disjoint address spaces "
    6776              :                     "used in conditional expression");
    6777            0 :           return error_mark_node;
    6778              :         }
    6779        34803 :       else if ((VOID_TYPE_P (TREE_TYPE (type1))
    6780          330 :                 && !TYPE_ATOMIC (TREE_TYPE (type1)))
    6781        34805 :                || (VOID_TYPE_P (TREE_TYPE (type2))
    6782        34428 :                    && !TYPE_ATOMIC (TREE_TYPE (type2))))
    6783              :         {
    6784        34755 :           tree t1 = TREE_TYPE (type1);
    6785        34755 :           tree t2 = TREE_TYPE (type2);
    6786        34755 :           if (!(VOID_TYPE_P (t1)
    6787          329 :                 && !TYPE_ATOMIC (t1)))
    6788              :            {
    6789              :              /* roles are swapped */
    6790        34427 :              t1 = t2;
    6791        34427 :              t2 = TREE_TYPE (type1);
    6792              :            }
    6793        34755 :           tree t2_stripped = strip_array_types (t2);
    6794        34755 :           if ((TREE_CODE (t2) == ARRAY_TYPE)
    6795        34755 :               && (TYPE_QUALS (t2_stripped) & ~TYPE_QUALS (t1)))
    6796              :             {
    6797           18 :               if (!flag_isoc23)
    6798            6 :                 warning_at (colon_loc, OPT_Wdiscarded_array_qualifiers,
    6799              :                             "pointer to array loses qualifier "
    6800              :                             "in conditional expression");
    6801           12 :               else if (warn_c11_c23_compat > 0)
    6802            6 :                 warning_at (colon_loc, OPT_Wc11_c23_compat,
    6803              :                             "pointer to array loses qualifier "
    6804              :                             "in conditional expression in ISO C before C23");
    6805              :             }
    6806        34755 :           if (TREE_CODE (t2) == FUNCTION_TYPE)
    6807            4 :             pedwarn (colon_loc, OPT_Wpedantic,
    6808              :                      "ISO C forbids conditional expr between "
    6809              :                      "%<void *%> and function pointer");
    6810              :           /* for array, use qualifiers of element type */
    6811        34755 :           if (flag_isoc23)
    6812        11006 :             t2 = t2_stripped;
    6813        34755 :           result_type = c_build_pointer_type (qualify_type (t1, t2));
    6814              :         }
    6815              :       /* Objective-C pointer comparisons are a bit more lenient.  */
    6816           48 :       else if (objc_have_common_type (type1, type2, -3, NULL_TREE))
    6817            0 :         result_type = objc_common_type (type1, type2);
    6818              :       else
    6819              :         {
    6820           48 :           int qual = ENCODE_QUAL_ADDR_SPACE (as_common);
    6821           48 :           enum diagnostics::kind kind = diagnostics::kind::permerror;
    6822           48 :           if (!flag_isoc99)
    6823              :             /* This downgrade to a warning ensures that -std=gnu89
    6824              :                -pedantic-errors does not flag these mismatches between
    6825              :                builtins as errors (as diagnostics::kind::permerror would)
    6826              :                ISO C99 and later do not have implicit function declarations,
    6827              :                so the mismatch cannot occur naturally there.  */
    6828            5 :             kind = (bltin1 && bltin2
    6829            5 :                     ? diagnostics::kind::warning
    6830              :                     : diagnostics::kind::pedwarn);
    6831           48 :           if (emit_diagnostic (kind, colon_loc, OPT_Wincompatible_pointer_types,
    6832              :                                "pointer type mismatch "
    6833              :                                "in conditional expression"))
    6834              :             {
    6835           46 :               inform (op1_loc, "first expression has type %qT", type1);
    6836           46 :               inform (op2_loc, "second expression has type %qT", type2);
    6837              :             }
    6838           48 :           result_type = c_build_pointer_type
    6839           48 :                           (c_build_qualified_type (void_type_node, qual));
    6840              :         }
    6841              :     }
    6842          397 :   else if (code1 == POINTER_TYPE
    6843          277 :            && (code2 == INTEGER_TYPE || code2 == BITINT_TYPE))
    6844              :     {
    6845          273 :       if (!null_pointer_constant_p (orig_op2))
    6846           14 :         permerror_opt (colon_loc, OPT_Wint_conversion,
    6847              :                        "pointer/integer type mismatch "
    6848              :                        "in conditional expression");
    6849              :       else
    6850              :         {
    6851          259 :           op2 = null_pointer_node;
    6852              :         }
    6853              :       result_type = type1;
    6854              :     }
    6855          124 :   else if (code2 == POINTER_TYPE
    6856           90 :            && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
    6857              :     {
    6858           86 :       if (!null_pointer_constant_p (orig_op1))
    6859           14 :         permerror_opt (colon_loc, OPT_Wint_conversion,
    6860              :                        "pointer/integer type mismatch "
    6861              :                        "in conditional expression");
    6862              :       else
    6863              :         {
    6864           72 :           op1 = null_pointer_node;
    6865              :         }
    6866              :       result_type = type2;
    6867              :     }
    6868              :   /* 6.5.15: "if one is a null pointer constant (other than a pointer) or has
    6869              :      type nullptr_t and the other is a pointer, the result type is the pointer
    6870              :      type."  */
    6871           38 :   else if (code1 == NULLPTR_TYPE && code2 == POINTER_TYPE)
    6872              :     result_type = type2;
    6873           34 :   else if (code1 == POINTER_TYPE && code2 == NULLPTR_TYPE)
    6874              :     result_type = type1;
    6875            8 :   else if (RECORD_OR_UNION_TYPE_P (type1) && RECORD_OR_UNION_TYPE_P (type2)
    6876           38 :            && comptypes (TYPE_MAIN_VARIANT (type1),
    6877            8 :                          TYPE_MAIN_VARIANT (type2)))
    6878            8 :     result_type = composite_type (TYPE_MAIN_VARIANT (type1),
    6879            8 :                                   TYPE_MAIN_VARIANT (type2));
    6880              : 
    6881       408486 :   if (!result_type)
    6882              :     {
    6883           22 :       if (flag_cond_mismatch)
    6884            0 :         result_type = void_type_node;
    6885              :       else
    6886              :         {
    6887           22 :           error_at (colon_loc, "type mismatch in conditional expression");
    6888           22 :           return error_mark_node;
    6889              :         }
    6890              :     }
    6891              : 
    6892              :   /* Merge const and volatile flags of the incoming types.  */
    6893       408486 :   result_type
    6894       408486 :     = build_type_variant (result_type,
    6895              :                           TYPE_READONLY (type1) || TYPE_READONLY (type2),
    6896              :                           TYPE_VOLATILE (type1) || TYPE_VOLATILE (type2));
    6897              : 
    6898       408486 :   op1 = ep_convert_and_check (colon_loc, result_type, op1,
    6899              :                               semantic_result_type);
    6900       408486 :   op2 = ep_convert_and_check (colon_loc, result_type, op2,
    6901              :                               semantic_result_type);
    6902              : 
    6903       408486 :   if (ifexp_bcp && ifexp == truthvalue_true_node)
    6904              :     {
    6905           10 :       op2_int_operands = true;
    6906           10 :       op1 = c_fully_fold (op1, require_constant_value, NULL);
    6907              :     }
    6908           59 :   if (ifexp_bcp && ifexp == truthvalue_false_node)
    6909              :     {
    6910           49 :       op1_int_operands = true;
    6911           49 :       op2 = c_fully_fold (op2, require_constant_value, NULL);
    6912              :     }
    6913       914088 :   int_const = int_operands = (ifexp_int_operands
    6914       408486 :                               && op1_int_operands
    6915       408486 :                               && op2_int_operands);
    6916        97116 :   if (int_operands)
    6917              :     {
    6918        97116 :       int_const = ((ifexp == truthvalue_true_node
    6919        58772 :                     && TREE_CODE (orig_op1) == INTEGER_CST
    6920        58758 :                     && !TREE_OVERFLOW (orig_op1))
    6921        97130 :                    || (ifexp == truthvalue_false_node
    6922        38298 :                        && TREE_CODE (orig_op2) == INTEGER_CST
    6923        38282 :                        && !TREE_OVERFLOW (orig_op2)));
    6924              :     }
    6925              : 
    6926              :   /* Need to convert condition operand into a vector mask.  */
    6927       408486 :   if (VECTOR_TYPE_P (TREE_TYPE (ifexp)))
    6928              :     {
    6929            0 :       tree vectype = TREE_TYPE (ifexp);
    6930            0 :       tree elem_type = TREE_TYPE (vectype);
    6931            0 :       tree zero = build_int_cst (elem_type, 0);
    6932            0 :       tree zero_vec = build_vector_from_val (vectype, zero);
    6933            0 :       tree cmp_type = truth_type_for (vectype);
    6934            0 :       ifexp = build2 (NE_EXPR, cmp_type, ifexp, zero_vec);
    6935              :     }
    6936              : 
    6937       408486 :   if (int_const || (ifexp_bcp && TREE_CODE (ifexp) == INTEGER_CST))
    6938        97072 :     ret = fold_build3_loc (colon_loc, COND_EXPR, result_type, ifexp, op1, op2);
    6939              :   else
    6940              :     {
    6941       311414 :       if (int_operands)
    6942              :         {
    6943              :           /* Use c_fully_fold here, since C_MAYBE_CONST_EXPR might be
    6944              :              nested inside of the expression.  */
    6945           76 :           op1 = c_fully_fold (op1, false, NULL);
    6946           76 :           op2 = c_fully_fold (op2, false, NULL);
    6947              :         }
    6948       311414 :       ret = build3 (COND_EXPR, result_type, ifexp, op1, op2);
    6949       311414 :       if (int_operands)
    6950           76 :         ret = note_integer_operands (ret);
    6951              :     }
    6952       408486 :   if (semantic_result_type)
    6953         4635 :     ret = build1 (EXCESS_PRECISION_EXPR, semantic_result_type, ret);
    6954              : 
    6955       408486 :   protected_set_expr_location (ret, colon_loc);
    6956              : 
    6957              :   /* If the OP1 and OP2 are the same and don't have side-effects,
    6958              :      warn here, because the COND_EXPR will be turned into OP1.  */
    6959       408486 :   if (warn_duplicated_branches
    6960           34 :       && TREE_CODE (ret) == COND_EXPR
    6961       408520 :       && (op1 == op2 || operand_equal_p (op1, op2, OEP_ADDRESS_OF_SAME_FIELD)))
    6962           13 :     warning_at (EXPR_LOCATION (ret), OPT_Wduplicated_branches,
    6963              :                 "this condition has identical branches");
    6964              : 
    6965              :   return ret;
    6966              : }
    6967              : 
    6968              : /* EXPR is an expression, location LOC, whose result is discarded.
    6969              :    Warn if it is a call to a nodiscard function (or a COMPOUND_EXPR
    6970              :    whose right-hand operand is such a call, possibly recursively).  */
    6971              : 
    6972              : static void
    6973      6465113 : maybe_warn_nodiscard (location_t loc, tree expr)
    6974              : {
    6975      6465113 :   if (VOID_TYPE_P (TREE_TYPE (expr)))
    6976              :     return;
    6977      3953261 :   while (TREE_CODE (expr) == COMPOUND_EXPR)
    6978              :     {
    6979        49291 :       expr = TREE_OPERAND (expr, 1);
    6980        49291 :       if (EXPR_HAS_LOCATION (expr))
    6981        32190 :         loc = EXPR_LOCATION (expr);
    6982              :     }
    6983      3903970 :   if (TREE_CODE (expr) != CALL_EXPR)
    6984              :     return;
    6985       343559 :   tree fn = CALL_EXPR_FN (expr);
    6986       343559 :   if (!fn)
    6987              :     return;
    6988       343543 :   tree attr;
    6989       343543 :   if (TREE_CODE (fn) == ADDR_EXPR
    6990       342878 :       && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
    6991       686421 :       && (attr = lookup_attribute ("nodiscard",
    6992       342878 :                                    DECL_ATTRIBUTES (TREE_OPERAND (fn, 0)))))
    6993              :     {
    6994            3 :       fn = TREE_OPERAND (fn, 0);
    6995            3 :       tree args = TREE_VALUE (attr);
    6996            3 :       if (args)
    6997            1 :         args = TREE_VALUE (args);
    6998            3 :       auto_diagnostic_group d;
    6999            3 :       auto_urlify_attributes sentinel;
    7000            3 :       int warned;
    7001            3 :       if (args)
    7002            1 :         warned = warning_at (loc, OPT_Wunused_result,
    7003              :                              "ignoring return value of %qD, declared with "
    7004              :                              "attribute %<nodiscard%>: %E", fn, args);
    7005              :       else
    7006            2 :         warned = warning_at (loc, OPT_Wunused_result,
    7007              :                              "ignoring return value of %qD, declared with "
    7008              :                              "attribute %<nodiscard%>", fn);
    7009            3 :       if (warned)
    7010            3 :         inform (DECL_SOURCE_LOCATION (fn), "declared here");
    7011            3 :     }
    7012              :   else
    7013              :     {
    7014       343540 :       tree rettype = TREE_TYPE (TREE_TYPE (TREE_TYPE (fn)));
    7015       343540 :       attr = lookup_attribute ("nodiscard", TYPE_ATTRIBUTES (rettype));
    7016       343540 :       if (!attr)
    7017       343528 :         return;
    7018           12 :       tree args = TREE_VALUE (attr);
    7019           12 :       if (args)
    7020            5 :         args = TREE_VALUE (args);
    7021           12 :       auto_diagnostic_group d;
    7022           12 :       auto_urlify_attributes sentinel;
    7023           12 :       int warned;
    7024           12 :       if (args)
    7025            5 :         warned = warning_at (loc, OPT_Wunused_result,
    7026              :                              "ignoring return value of type %qT, declared "
    7027              :                              "with attribute %<nodiscard%>: %E",
    7028              :                              rettype, args);
    7029              :       else
    7030            7 :         warned = warning_at (loc, OPT_Wunused_result,
    7031              :                              "ignoring return value of type %qT, declared "
    7032              :                              "with attribute %<nodiscard%>", rettype);
    7033           12 :       if (warned)
    7034              :         {
    7035           12 :           if (TREE_CODE (fn) == ADDR_EXPR)
    7036              :             {
    7037           11 :               fn = TREE_OPERAND (fn, 0);
    7038           11 :               if (TREE_CODE (fn) == FUNCTION_DECL)
    7039           11 :                 inform (DECL_SOURCE_LOCATION (fn),
    7040              :                         "in call to %qD, declared here", fn);
    7041              :             }
    7042              :         }
    7043           12 :     }
    7044              : }
    7045              : 
    7046              : /* Return a compound expression that performs two expressions and
    7047              :    returns the value of the second of them.
    7048              : 
    7049              :    LOC is the location of the COMPOUND_EXPR.  */
    7050              : 
    7051              : tree
    7052       111492 : build_compound_expr (location_t loc, tree expr1, tree expr2)
    7053              : {
    7054       111492 :   bool expr1_int_operands, expr2_int_operands;
    7055       111492 :   tree eptype = NULL_TREE;
    7056       111492 :   tree ret;
    7057              : 
    7058       111492 :   expr1_int_operands = EXPR_INT_CONST_OPERANDS (expr1);
    7059          326 :   if (expr1_int_operands)
    7060          326 :     expr1 = remove_c_maybe_const_expr (expr1);
    7061       111492 :   expr2_int_operands = EXPR_INT_CONST_OPERANDS (expr2);
    7062        66101 :   if (expr2_int_operands)
    7063        66101 :     expr2 = remove_c_maybe_const_expr (expr2);
    7064              : 
    7065       111492 :   if (TREE_CODE (expr1) == EXCESS_PRECISION_EXPR)
    7066            0 :     expr1 = TREE_OPERAND (expr1, 0);
    7067       111492 :   if (TREE_CODE (expr2) == EXCESS_PRECISION_EXPR)
    7068              :     {
    7069            1 :       eptype = TREE_TYPE (expr2);
    7070            1 :       expr2 = TREE_OPERAND (expr2, 0);
    7071              :     }
    7072              : 
    7073       111492 :   if (!TREE_SIDE_EFFECTS (expr1))
    7074              :     {
    7075              :       /* The left-hand operand of a comma expression is like an expression
    7076              :          statement: with -Wunused, we should warn if it doesn't have
    7077              :          any side-effects, unless it was explicitly cast to (void).  */
    7078         8388 :       if (warn_unused_value)
    7079              :         {
    7080         1257 :           if (VOID_TYPE_P (TREE_TYPE (expr1))
    7081         1257 :               && CONVERT_EXPR_P (expr1))
    7082              :             ; /* (void) a, b */
    7083           14 :           else if (VOID_TYPE_P (TREE_TYPE (expr1))
    7084            4 :                    && TREE_CODE (expr1) == COMPOUND_EXPR
    7085           17 :                    && CONVERT_EXPR_P (TREE_OPERAND (expr1, 1)))
    7086              :             ; /* (void) a, (void) b, c */
    7087              :           else
    7088           11 :             warning_at (loc, OPT_Wunused_value,
    7089              :                         "left-hand operand of comma expression has no effect");
    7090              :         }
    7091              :     }
    7092       103104 :   else if (TREE_CODE (expr1) == COMPOUND_EXPR
    7093        13111 :            && warn_unused_value)
    7094              :     {
    7095              :       tree r = expr1;
    7096              :       location_t cloc = loc;
    7097         4833 :       while (TREE_CODE (r) == COMPOUND_EXPR)
    7098              :         {
    7099         2417 :           if (EXPR_HAS_LOCATION (r))
    7100         2417 :             cloc = EXPR_LOCATION (r);
    7101         2417 :           r = TREE_OPERAND (r, 1);
    7102              :         }
    7103         2416 :       if (!TREE_SIDE_EFFECTS (r)
    7104            4 :           && !VOID_TYPE_P (TREE_TYPE (r))
    7105         2420 :           && !CONVERT_EXPR_P (r))
    7106            4 :         warning_at (cloc, OPT_Wunused_value,
    7107              :                     "right-hand operand of comma expression has no effect");
    7108              :     }
    7109              : 
    7110              :   /* With -Wunused, we should also warn if the left-hand operand does have
    7111              :      side-effects, but computes a value which is not used.  For example, in
    7112              :      `foo() + bar(), baz()' the result of the `+' operator is not used,
    7113              :      so we should issue a warning.  */
    7114       100688 :   else if (warn_unused_value)
    7115        35400 :     warn_if_unused_value (expr1, loc);
    7116              : 
    7117       111492 :   maybe_warn_nodiscard (loc, expr1);
    7118              : 
    7119       111492 :   if (expr2 == error_mark_node)
    7120              :     return error_mark_node;
    7121              : 
    7122       111479 :   ret = build2 (COMPOUND_EXPR, TREE_TYPE (expr2), expr1, expr2);
    7123              : 
    7124       111479 :   if (flag_isoc99
    7125              :       && expr1_int_operands
    7126       111023 :       && expr2_int_operands)
    7127          153 :     ret = note_integer_operands (ret);
    7128              : 
    7129       111479 :   if (eptype)
    7130            1 :     ret = build1 (EXCESS_PRECISION_EXPR, eptype, ret);
    7131              : 
    7132       111479 :   protected_set_expr_location (ret, loc);
    7133       111479 :   return ret;
    7134              : }
    7135              : 
    7136              : /* Issue -Wcast-qual warnings when appropriate.  TYPE is the type to
    7137              :    which we are casting.  OTYPE is the type of the expression being
    7138              :    cast.  Both TYPE and OTYPE are pointer types.  LOC is the location
    7139              :    of the cast.  -Wcast-qual appeared on the command line.  Named
    7140              :    address space qualifiers are not handled here, because they result
    7141              :    in different warnings.  */
    7142              : 
    7143              : static void
    7144        13405 : handle_warn_cast_qual (location_t loc, tree type, tree otype)
    7145              : {
    7146        13405 :   tree in_type = type;
    7147        13405 :   tree in_otype = otype;
    7148        13405 :   int added = 0;
    7149        13405 :   int discarded = 0;
    7150        13575 :   bool is_const;
    7151              : 
    7152              :   /* Check that the qualifiers on IN_TYPE are a superset of the
    7153              :      qualifiers of IN_OTYPE.  The outermost level of POINTER_TYPE
    7154              :      nodes is uninteresting and we stop as soon as we hit a
    7155              :      non-POINTER_TYPE node on either type.  */
    7156        13575 :   do
    7157              :     {
    7158        13575 :       in_otype = TREE_TYPE (in_otype);
    7159        13575 :       in_type = TREE_TYPE (in_type);
    7160              : 
    7161              :       /* GNU C allows cv-qualified function types.  'const' means the
    7162              :          function is very pure, 'volatile' means it can't return.  We
    7163              :          need to warn when such qualifiers are added, not when they're
    7164              :          taken away.  */
    7165        13575 :       if (TREE_CODE (in_otype) == FUNCTION_TYPE
    7166           26 :           && TREE_CODE (in_type) == FUNCTION_TYPE)
    7167           18 :         added |= (TYPE_QUALS_NO_ADDR_SPACE (in_type)
    7168           18 :                   & ~TYPE_QUALS_NO_ADDR_SPACE (in_otype));
    7169              :       else
    7170        13557 :         discarded |= (TYPE_QUALS_NO_ADDR_SPACE (in_otype)
    7171        13557 :                       & ~TYPE_QUALS_NO_ADDR_SPACE (in_type));
    7172              :     }
    7173        13575 :   while (TREE_CODE (in_type) == POINTER_TYPE
    7174        13575 :          && TREE_CODE (in_otype) == POINTER_TYPE);
    7175              : 
    7176        13405 :   if (added)
    7177            2 :     warning_at (loc, OPT_Wcast_qual,
    7178              :                 "cast adds %q#v qualifier to function type", added);
    7179              : 
    7180        13405 :   if (discarded)
    7181              :     /* There are qualifiers present in IN_OTYPE that are not present
    7182              :        in IN_TYPE.  */
    7183         1117 :     warning_at (loc, OPT_Wcast_qual,
    7184              :                 "cast discards %qv qualifier from pointer target type",
    7185              :                 discarded);
    7186              : 
    7187        13405 :   if (added || discarded)
    7188              :     return;
    7189              : 
    7190              :   /* A cast from **T to const **T is unsafe, because it can cause a
    7191              :      const value to be changed with no additional warning.  We only
    7192              :      issue this warning if T is the same on both sides, and we only
    7193              :      issue the warning if there are the same number of pointers on
    7194              :      both sides, as otherwise the cast is clearly unsafe anyhow.  A
    7195              :      cast is unsafe when a qualifier is added at one level and const
    7196              :      is not present at all outer levels.
    7197              : 
    7198              :      To issue this warning, we check at each level whether the cast
    7199              :      adds new qualifiers not already seen.  We don't need to special
    7200              :      case function types, as they won't have the same
    7201              :      TYPE_MAIN_VARIANT.  */
    7202              : 
    7203        12286 :   if (TYPE_MAIN_VARIANT (in_type) != TYPE_MAIN_VARIANT (in_otype))
    7204              :     return;
    7205           51 :   if (TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE)
    7206              :     return;
    7207              : 
    7208           48 :   in_type = type;
    7209           48 :   in_otype = otype;
    7210           48 :   is_const = TYPE_READONLY (TREE_TYPE (in_type));
    7211          130 :   do
    7212              :     {
    7213          130 :       in_type = TREE_TYPE (in_type);
    7214          130 :       in_otype = TREE_TYPE (in_otype);
    7215          130 :       if ((TYPE_QUALS (in_type) &~ TYPE_QUALS (in_otype)) != 0
    7216          130 :           && !is_const)
    7217              :         {
    7218           27 :           warning_at (loc, OPT_Wcast_qual,
    7219              :                       "to be safe all intermediate pointers in cast from "
    7220              :                       "%qT to %qT must be %<const%> qualified",
    7221              :                       otype, type);
    7222           27 :           break;
    7223              :         }
    7224          103 :       if (is_const)
    7225           72 :         is_const = TYPE_READONLY (in_type);
    7226              :     }
    7227          103 :   while (TREE_CODE (in_type) == POINTER_TYPE);
    7228              : }
    7229              : 
    7230              : /* Heuristic check if two parameter types can be considered ABI-equivalent.  */
    7231              : 
    7232              : static bool
    7233         1280 : c_safe_arg_type_equiv_p (tree t1, tree t2)
    7234              : {
    7235         1280 :   if (error_operand_p (t1) || error_operand_p (t2))
    7236              :     return true;
    7237              : 
    7238         1279 :   t1 = TYPE_MAIN_VARIANT (t1);
    7239         1279 :   t2 = TYPE_MAIN_VARIANT (t2);
    7240              : 
    7241         1279 :   if (TREE_CODE (t1) == POINTER_TYPE
    7242          213 :       && TREE_CODE (t2) == POINTER_TYPE)
    7243              :     return true;
    7244              : 
    7245              :   /* Only the precision of the parameter matters.  This check should
    7246              :      make sure that the callee does not see undefined values in argument
    7247              :      registers.  */
    7248         1087 :   if (INTEGRAL_TYPE_P (t1)
    7249          905 :       && INTEGRAL_TYPE_P (t2)
    7250         1424 :       && TYPE_PRECISION (t1) == TYPE_PRECISION (t2))
    7251              :     return true;
    7252              : 
    7253          930 :   return comptypes (t1, t2);
    7254              : }
    7255              : 
    7256              : /* Check if a type cast between two function types can be considered safe.  */
    7257              : 
    7258              : static bool
    7259         7469 : c_safe_function_type_cast_p (tree t1, tree t2)
    7260              : {
    7261         7469 :   if (TREE_TYPE (t1) == void_type_node &&
    7262         5479 :       TYPE_ARG_TYPES (t1) == void_list_node)
    7263              :     return true;
    7264              : 
    7265         3714 :   if (TREE_TYPE (t2) == void_type_node &&
    7266         2889 :       TYPE_ARG_TYPES (t2) == void_list_node)
    7267              :     return true;
    7268              : 
    7269          884 :   if (!c_safe_arg_type_equiv_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    7270              :     return false;
    7271              : 
    7272          189 :   for (t1 = TYPE_ARG_TYPES (t1), t2 = TYPE_ARG_TYPES (t2);
    7273          481 :        t1 && t2;
    7274          292 :        t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
    7275          396 :     if (!c_safe_arg_type_equiv_p (TREE_VALUE (t1), TREE_VALUE (t2)))
    7276              :       return false;
    7277              : 
    7278              :   return true;
    7279              : }
    7280              : 
    7281              : /* Build an expression representing a cast to type TYPE of expression EXPR.
    7282              :    LOC is the location of the cast-- typically the open paren of the cast.  */
    7283              : 
    7284              : tree
    7285    120004659 : build_c_cast (location_t loc, tree type, tree expr)
    7286              : {
    7287    120004659 :   tree value;
    7288              : 
    7289    120004659 :   bool int_operands = EXPR_INT_CONST_OPERANDS (expr);
    7290              : 
    7291    120004659 :   if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
    7292           66 :     expr = TREE_OPERAND (expr, 0);
    7293              : 
    7294    120004659 :   value = expr;
    7295    120004659 :   if (int_operands)
    7296      6858527 :     value = remove_c_maybe_const_expr (value);
    7297              : 
    7298    120004659 :   if (type == error_mark_node || expr == error_mark_node)
    7299              :     return error_mark_node;
    7300              : 
    7301              :   /* The ObjC front-end uses TYPE_MAIN_VARIANT to tie together types differing
    7302              :      only in <protocol> qualifications.  But when constructing cast expressions,
    7303              :      the protocols do matter and must be kept around.  */
    7304    120003637 :   if (objc_is_object_ptr (type) && objc_is_object_ptr (TREE_TYPE (expr)))
    7305            0 :     return build1 (NOP_EXPR, type, expr);
    7306              : 
    7307    120003637 :   type = TYPE_MAIN_VARIANT (type);
    7308              : 
    7309    120003637 :   if (TREE_CODE (type) == ARRAY_TYPE)
    7310              :     {
    7311           13 :       error_at (loc, "cast specifies array type");
    7312           13 :       return error_mark_node;
    7313              :     }
    7314              : 
    7315    120003624 :   if (TREE_CODE (type) == FUNCTION_TYPE)
    7316              :     {
    7317            6 :       error_at (loc, "cast specifies function type");
    7318            6 :       return error_mark_node;
    7319              :     }
    7320              : 
    7321    120003618 :   if (!VOID_TYPE_P (type))
    7322              :     {
    7323    119959421 :       value = require_complete_type (loc, value);
    7324    119959421 :       if (value == error_mark_node)
    7325              :         return error_mark_node;
    7326              :     }
    7327              : 
    7328    120003617 :   if (type == TYPE_MAIN_VARIANT (TREE_TYPE (value)))
    7329              :     {
    7330     18083897 :       if (RECORD_OR_UNION_TYPE_P (type)
    7331     18083897 :           && pedwarn (loc, OPT_Wpedantic,
    7332              :                       "ISO C forbids casting nonscalar to the same type"))
    7333              :               ;
    7334     18083893 :       else if (warn_useless_cast)
    7335            7 :         warning_at (loc, OPT_Wuseless_cast,
    7336              :                     "useless cast to type %qT", type);
    7337              : 
    7338              :       /* Convert to remove any qualifiers from VALUE's type.  */
    7339     18083897 :       value = convert (type, value);
    7340              :     }
    7341    101919720 :   else if (TREE_CODE (type) == UNION_TYPE)
    7342              :     {
    7343          137 :       tree field;
    7344              : 
    7345          192 :       for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    7346          185 :         if (TREE_TYPE (field) != error_mark_node
    7347          369 :             && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field)),
    7348          184 :                           TYPE_MAIN_VARIANT (TREE_TYPE (value))))
    7349              :           break;
    7350              : 
    7351          137 :       if (field)
    7352              :         {
    7353          130 :           tree t;
    7354          130 :           bool maybe_const = true;
    7355              : 
    7356          130 :           pedwarn (loc, OPT_Wpedantic, "ISO C forbids casts to union type");
    7357          130 :           t = c_fully_fold (value, false, &maybe_const);
    7358          130 :           t = build_constructor_single (type, field, t);
    7359          130 :           if (!maybe_const)
    7360           15 :             t = c_wrap_maybe_const (t, true);
    7361          130 :           t = digest_init (loc, field, type, t,
    7362              :                            NULL_TREE, false, false, false, true, false, false);
    7363          130 :           TREE_CONSTANT (t) = TREE_CONSTANT (value);
    7364          130 :           return t;
    7365              :         }
    7366            7 :       error_at (loc, "cast to union type from type not present in union");
    7367            7 :       return error_mark_node;
    7368              :     }
    7369              :   else
    7370              :     {
    7371    101919583 :       tree otype, ovalue;
    7372              : 
    7373    101919583 :       if (type == void_type_node)
    7374              :         {
    7375        18227 :           tree t = build1 (CONVERT_EXPR, type, value);
    7376        18227 :           SET_EXPR_LOCATION (t, loc);
    7377        18227 :           return t;
    7378              :         }
    7379              : 
    7380    101901356 :       otype = TREE_TYPE (value);
    7381              : 
    7382              :       /* Optionally warn about potentially worrisome casts.  */
    7383    101901356 :       if (warn_cast_qual
    7384       179497 :           && TREE_CODE (type) == POINTER_TYPE
    7385        26463 :           && TREE_CODE (otype) == POINTER_TYPE)
    7386        13405 :         handle_warn_cast_qual (loc, type, otype);
    7387              : 
    7388              :       /* Warn about conversions between pointers to disjoint
    7389              :          address spaces.  */
    7390    101901356 :       if (TREE_CODE (type) == POINTER_TYPE
    7391      3326875 :           && TREE_CODE (otype) == POINTER_TYPE
    7392    104884038 :           && !null_pointer_constant_p (value))
    7393              :         {
    7394      2929157 :           addr_space_t as_to = TYPE_ADDR_SPACE (TREE_TYPE (type));
    7395      2929157 :           addr_space_t as_from = TYPE_ADDR_SPACE (TREE_TYPE (otype));
    7396      2929157 :           addr_space_t as_common;
    7397              : 
    7398      2929157 :           if (!addr_space_superset (as_to, as_from, &as_common))
    7399              :             {
    7400            0 :               if (ADDR_SPACE_GENERIC_P (as_from))
    7401            0 :                 warning_at (loc, 0, "cast to %qs address space pointer "
    7402              :                             "from disjoint generic address space pointer",
    7403              :                             c_addr_space_name (as_to));
    7404              : 
    7405            0 :               else if (ADDR_SPACE_GENERIC_P (as_to))
    7406            0 :                 warning_at (loc, 0, "cast to generic address space pointer "
    7407              :                             "from disjoint %qs address space pointer",
    7408              :                             c_addr_space_name (as_from));
    7409              : 
    7410              :               else
    7411            0 :                 warning_at (loc, 0, "cast to %qs address space pointer "
    7412              :                             "from disjoint %qs address space pointer",
    7413              :                             c_addr_space_name (as_to),
    7414              :                             c_addr_space_name (as_from));
    7415              :             }
    7416              : 
    7417              :           /* Warn of new allocations that are not big enough for the target
    7418              :              type.  */
    7419      2929157 :           if (warn_alloc_size && TREE_CODE (value) == CALL_EXPR)
    7420          805 :             if (tree fndecl = get_callee_fndecl (value))
    7421          801 :               if (DECL_IS_MALLOC (fndecl))
    7422              :                 {
    7423          517 :                   tree attrs = TYPE_ATTRIBUTES (TREE_TYPE (fndecl));
    7424          517 :                   tree alloc_size = lookup_attribute ("alloc_size", attrs);
    7425          517 :                   if (alloc_size)
    7426          159 :                     warn_for_alloc_size (loc, TREE_TYPE (type), value,
    7427              :                                          alloc_size);
    7428              :                 }
    7429              :         }
    7430              : 
    7431              :       /* Warn about possible alignment problems.  */
    7432    101901356 :       if ((STRICT_ALIGNMENT || warn_cast_align == 2)
    7433            7 :           && TREE_CODE (type) == POINTER_TYPE
    7434            7 :           && TREE_CODE (otype) == POINTER_TYPE
    7435            7 :           && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE
    7436            7 :           && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
    7437              :           /* Don't warn about opaque types, where the actual alignment
    7438              :              restriction is unknown.  */
    7439           12 :           && !(RECORD_OR_UNION_TYPE_P (TREE_TYPE (otype))
    7440            5 :                && TYPE_MODE (TREE_TYPE (otype)) == VOIDmode)
    7441    101901370 :           && min_align_of_type (TREE_TYPE (type))
    7442            7 :              > min_align_of_type (TREE_TYPE (otype)))
    7443            5 :         warning_at (loc, OPT_Wcast_align,
    7444              :                     "cast increases required alignment of target type");
    7445              : 
    7446    101901356 :       if ((TREE_CODE (type) == INTEGER_TYPE
    7447    101901356 :            || TREE_CODE (type) == BITINT_TYPE)
    7448      7074098 :           && TREE_CODE (otype) == POINTER_TYPE
    7449    101926562 :           && TYPE_PRECISION (type) != TYPE_PRECISION (otype))
    7450              :       /* Unlike conversion of integers to pointers, where the
    7451              :          warning is disabled for converting constants because
    7452              :          of cases such as SIG_*, warn about converting constant
    7453              :          pointers to integers. In some cases it may cause unwanted
    7454              :          sign extension, and a warning is appropriate.  */
    7455         1450 :         warning_at (loc, OPT_Wpointer_to_int_cast,
    7456              :                     "cast from pointer to integer of different size");
    7457              : 
    7458    101901356 :       if ((TREE_CODE (value) == CALL_EXPR
    7459     34595735 :            && !is_access_with_size_p (value))
    7460    136497089 :           && TREE_CODE (type) != TREE_CODE (otype))
    7461         2290 :         warning_at (loc, OPT_Wbad_function_cast,
    7462              :                     "cast from function call of type %qT "
    7463              :                     "to non-matching type %qT", otype, type);
    7464              : 
    7465    101901356 :       if (TREE_CODE (type) == POINTER_TYPE
    7466      3326875 :           && (TREE_CODE (otype) == INTEGER_TYPE
    7467      3326875 :               || TREE_CODE (otype) == BITINT_TYPE)
    7468       344107 :           && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
    7469              :           /* Don't warn about converting any constant.  */
    7470    102207928 :           && !TREE_CONSTANT (value))
    7471          407 :         warning_at (loc,
    7472          407 :                     OPT_Wint_to_pointer_cast, "cast to pointer from integer "
    7473              :                     "of different size");
    7474              : 
    7475    101901356 :       if (warn_strict_aliasing <= 2)
    7476     93369381 :         strict_aliasing_warning (EXPR_LOCATION (value), type, expr);
    7477              : 
    7478              :       /* If pedantic, warn for conversions between function and object
    7479              :          pointer types, except for converting a null pointer constant
    7480              :          to function pointer type.  */
    7481    101901356 :       if (pedantic
    7482       238921 :           && TREE_CODE (type) == POINTER_TYPE
    7483       144179 :           && TREE_CODE (otype) == POINTER_TYPE
    7484         2781 :           && TREE_CODE (TREE_TYPE (otype)) == FUNCTION_TYPE
    7485    101901377 :           && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE)
    7486           18 :         pedwarn (loc, OPT_Wpedantic, "ISO C forbids "
    7487              :                  "conversion of function pointer to object pointer type");
    7488              : 
    7489    101901356 :       if (pedantic
    7490       238921 :           && TREE_CODE (type) == POINTER_TYPE
    7491       144179 :           && TREE_CODE (otype) == POINTER_TYPE
    7492         2781 :           && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
    7493           13 :           && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
    7494    101901366 :           && !null_pointer_constant_p (value))
    7495            4 :         pedwarn (loc, OPT_Wpedantic, "ISO C forbids "
    7496              :                  "conversion of object pointer to function pointer type");
    7497              : 
    7498    101901356 :       if (TREE_CODE (type) == POINTER_TYPE
    7499      3326875 :           && TREE_CODE (otype) == POINTER_TYPE
    7500      2982682 :           && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
    7501         8581 :           && TREE_CODE (TREE_TYPE (otype)) == FUNCTION_TYPE
    7502    101908825 :           && !c_safe_function_type_cast_p (TREE_TYPE (type),
    7503         7469 :                                            TREE_TYPE (otype)))
    7504          799 :         warning_at (loc, OPT_Wcast_function_type,
    7505              :                     "cast between incompatible function types"
    7506              :                     " from %qT to %qT", otype, type);
    7507              : 
    7508    101901356 :       ovalue = value;
    7509              :       /* If converting to boolean a value with integer operands that
    7510              :          is not itself represented as an INTEGER_CST, the call below
    7511              :          to note_integer_operands may insert a C_MAYBE_CONST_EXPR, but
    7512              :          build_binary_op as called by c_common_truthvalue_conversion
    7513              :          may also insert a C_MAYBE_CONST_EXPR to indicate that a
    7514              :          subexpression has been fully folded.  To avoid nested
    7515              :          C_MAYBE_CONST_EXPR, ensure that
    7516              :          c_objc_common_truthvalue_conversion receives an argument
    7517              :          properly marked as having integer operands in that case.  */
    7518    101901356 :       if (int_operands
    7519      6668558 :           && TREE_CODE (value) != INTEGER_CST
    7520    101901398 :           && (TREE_CODE (type) == BOOLEAN_TYPE
    7521           28 :               || (TREE_CODE (type) == ENUMERAL_TYPE
    7522           14 :                   && ENUM_UNDERLYING_TYPE (type) != NULL_TREE
    7523           14 :                   && TREE_CODE (ENUM_UNDERLYING_TYPE (type)) == BOOLEAN_TYPE)))
    7524           28 :         value = note_integer_operands (value);
    7525    101901356 :       value = convert (type, value);
    7526              : 
    7527              :       /* Ignore any integer overflow caused by the cast.  */
    7528    101901356 :       if (TREE_CODE (value) == INTEGER_CST && !FLOAT_TYPE_P (otype))
    7529              :         {
    7530      6614977 :           if (TREE_OVERFLOW_P (ovalue))
    7531              :             {
    7532            9 :               if (!TREE_OVERFLOW (value))
    7533              :                 {
    7534              :                   /* Avoid clobbering a shared constant.  */
    7535            0 :                   value = copy_node (value);
    7536            0 :                   TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue);
    7537              :                 }
    7538              :             }
    7539      6614968 :           else if (TREE_OVERFLOW (value))
    7540              :             /* Reset VALUE's overflow flags, ensuring constant sharing.  */
    7541         3085 :             value = wide_int_to_tree (TREE_TYPE (value), wi::to_wide (value));
    7542              :         }
    7543              :     }
    7544              : 
    7545              :   /* Don't let a cast be an lvalue.  */
    7546    119985253 :   if (lvalue_p (value))
    7547        90442 :     value = non_lvalue_loc (loc, value);
    7548              : 
    7549              :   /* Don't allow the results of casting to floating-point or complex
    7550              :      types be confused with actual constants, or casts involving
    7551              :      integer and pointer types other than direct integer-to-integer
    7552              :      and integer-to-pointer be confused with integer constant
    7553              :      expressions and null pointer constants.  */
    7554    119985253 :   if (TREE_CODE (value) == REAL_CST
    7555    119935367 :       || TREE_CODE (value) == COMPLEX_CST
    7556    239897997 :       || (TREE_CODE (value) == INTEGER_CST
    7557      6863371 :           && !((TREE_CODE (expr) == INTEGER_CST
    7558      6790106 :                 && INTEGRAL_TYPE_P (TREE_TYPE (expr)))
    7559        65862 :                || TREE_CODE (expr) == REAL_CST
    7560              :                || TREE_CODE (expr) == COMPLEX_CST)))
    7561       134004 :       value = build1 (NOP_EXPR, type, value);
    7562              : 
    7563              :   /* If the expression has integer operands and so can occur in an
    7564              :      unevaluated part of an integer constant expression, ensure the
    7565              :      return value reflects this.  */
    7566    119985253 :   if (int_operands
    7567      6844626 :       && INTEGRAL_TYPE_P (type)
    7568      6400925 :       && value != error_mark_node
    7569    126386177 :       && !EXPR_INT_CONST_OPERANDS (value))
    7570           11 :     value = note_integer_operands (value);
    7571              : 
    7572    119985253 :   protected_set_expr_location (value, loc);
    7573    119985253 :   return value;
    7574              : }
    7575              : 
    7576              : /* Interpret a cast of expression EXPR to type TYPE.  LOC is the
    7577              :    location of the open paren of the cast, or the position of the cast
    7578              :    expr.  */
    7579              : tree
    7580    120004166 : c_cast_expr (location_t loc, struct c_type_name *type_name, tree expr)
    7581              : {
    7582    120004166 :   tree type;
    7583    120004166 :   tree type_expr = NULL_TREE;
    7584    120004166 :   bool type_expr_const = true;
    7585    120004166 :   tree ret;
    7586    120004166 :   int saved_wsp = warn_strict_prototypes;
    7587              : 
    7588              :   /* This avoids warnings about unprototyped casts on
    7589              :      integers.  E.g. "#define SIG_DFL (void(*)())0".  */
    7590    120004166 :   if (TREE_CODE (expr) == INTEGER_CST)
    7591      6912166 :     warn_strict_prototypes = 0;
    7592    120004166 :   type = groktypename (type_name, &type_expr, &type_expr_const);
    7593    120004166 :   warn_strict_prototypes = saved_wsp;
    7594              : 
    7595       764905 :   if (TREE_CODE (expr) == ADDR_EXPR && !VOID_TYPE_P (type)
    7596    120768821 :       && reject_gcc_builtin (expr))
    7597            2 :     return error_mark_node;
    7598              : 
    7599    120004164 :   ret = build_c_cast (loc, type, expr);
    7600    120004164 :   if (ret == error_mark_node)
    7601              :     return error_mark_node;
    7602              : 
    7603    120003002 :   if (type_expr)
    7604              :     {
    7605          249 :       bool inner_expr_const = true;
    7606          249 :       ret = c_fully_fold (ret, require_constant_value, &inner_expr_const);
    7607          249 :       ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret), type_expr, ret);
    7608          498 :       C_MAYBE_CONST_EXPR_NON_CONST (ret) = !(type_expr_const
    7609          145 :                                              && inner_expr_const);
    7610          249 :       SET_EXPR_LOCATION (ret, loc);
    7611              :     }
    7612              : 
    7613    120003002 :   if (!EXPR_HAS_LOCATION (ret))
    7614      6790879 :     protected_set_expr_location (ret, loc);
    7615              : 
    7616              :   /* C++ does not permits types to be defined in a cast, but it
    7617              :      allows references to incomplete types.  */
    7618    120003002 :   if (warn_cxx_compat && type_name->specs->typespec_kind == ctsk_tagdef)
    7619            1 :     warning_at (loc, OPT_Wc___compat,
    7620              :                 "defining a type in a cast is invalid in C++");
    7621              : 
    7622              :   return ret;
    7623              : }
    7624              : 
    7625              : /* Build an assignment expression of lvalue LHS from value RHS.
    7626              :    If LHS_ORIGTYPE is not NULL, it is the original type of LHS, which
    7627              :    may differ from TREE_TYPE (LHS) for an enum bitfield.
    7628              :    MODIFYCODE is the code for a binary operator that we use
    7629              :    to combine the old value of LHS with RHS to get the new value.
    7630              :    Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
    7631              :    If RHS_ORIGTYPE is not NULL_TREE, it is the original type of RHS,
    7632              :    which may differ from TREE_TYPE (RHS) for an enum value.
    7633              : 
    7634              :    LOCATION is the location of the MODIFYCODE operator.
    7635              :    RHS_LOC is the location of the RHS.  */
    7636              : 
    7637              : tree
    7638      2897290 : build_modify_expr (location_t location, tree lhs, tree lhs_origtype,
    7639              :                    enum tree_code modifycode,
    7640              :                    location_t rhs_loc, tree rhs, tree rhs_origtype)
    7641              : {
    7642      2897290 :   tree result;
    7643      2897290 :   tree newrhs;
    7644      2897290 :   tree rhseval = NULL_TREE;
    7645      2897290 :   tree lhstype = TREE_TYPE (lhs);
    7646      2897290 :   tree olhstype = lhstype;
    7647      2897290 :   bool npc;
    7648      2897290 :   bool is_atomic_op;
    7649              : 
    7650              :   /* Types that aren't fully specified cannot be used in assignments.  */
    7651      2897290 :   lhs = require_complete_type (location, lhs);
    7652      2897290 :   rhs = require_complete_type (location, rhs);
    7653              : 
    7654              :   /* Avoid duplicate error messages from operands that had errors.  */
    7655      2897290 :   if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK)
    7656          473 :     return error_mark_node;
    7657              : 
    7658              :   /* Ensure an error for assigning a non-lvalue array to an array in
    7659              :      C90.  */
    7660      2896817 :   if (TREE_CODE (lhstype) == ARRAY_TYPE)
    7661              :     {
    7662            1 :       error_at (location, "assignment to expression with array type");
    7663            1 :       return error_mark_node;
    7664              :     }
    7665              : 
    7666              :   /* For ObjC properties, defer this check.  */
    7667      2896816 :   if (!objc_is_property_ref (lhs) && !lvalue_or_else (location, lhs, lv_assign))
    7668           32 :     return error_mark_node;
    7669              : 
    7670      2896784 :   is_atomic_op = really_atomic_lvalue (lhs);
    7671              : 
    7672      2896784 :   newrhs = rhs;
    7673              : 
    7674      2896784 :   if (TREE_CODE (lhs) == C_MAYBE_CONST_EXPR)
    7675              :     {
    7676            2 :       tree inner = build_modify_expr (location, C_MAYBE_CONST_EXPR_EXPR (lhs),
    7677              :                                       lhs_origtype, modifycode, rhs_loc, rhs,
    7678              :                                       rhs_origtype);
    7679            2 :       if (inner == error_mark_node)
    7680              :         return error_mark_node;
    7681            4 :       result = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner),
    7682            2 :                        C_MAYBE_CONST_EXPR_PRE (lhs), inner);
    7683            2 :       gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (lhs));
    7684            2 :       C_MAYBE_CONST_EXPR_NON_CONST (result) = 1;
    7685            2 :       protected_set_expr_location (result, location);
    7686            2 :       return result;
    7687              :     }
    7688              : 
    7689              :   /* If a binary op has been requested, combine the old LHS value with the RHS
    7690              :      producing the value we should actually store into the LHS.  */
    7691              : 
    7692      2896782 :   if (modifycode != NOP_EXPR)
    7693              :     {
    7694       214796 :       lhs = c_fully_fold (lhs, false, NULL, true);
    7695       214796 :       lhs = stabilize_reference (lhs);
    7696              : 
    7697              :       /* Construct the RHS for any non-atomic compound assignemnt. */
    7698       214796 :       if (!is_atomic_op)
    7699              :         {
    7700              :           /* If in LHS op= RHS the RHS has side-effects, ensure they
    7701              :              are preevaluated before the rest of the assignment expression's
    7702              :              side-effects, because RHS could contain e.g. function calls
    7703              :              that modify LHS.  */
    7704       199311 :           if (TREE_SIDE_EFFECTS (rhs))
    7705              :             {
    7706         8676 :               if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
    7707           28 :                 newrhs = save_expr (TREE_OPERAND (rhs, 0));
    7708              :               else
    7709         8648 :                 newrhs = save_expr (rhs);
    7710         8676 :               rhseval = newrhs;
    7711         8676 :               if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
    7712           28 :                 newrhs = build1 (EXCESS_PRECISION_EXPR, TREE_TYPE (rhs),
    7713              :                                  newrhs);
    7714              :             }
    7715       199311 :           bool clear_decl_read = false;
    7716        88335 :           if ((VAR_P (lhs) || TREE_CODE (lhs) == PARM_DECL)
    7717       153178 :               && !DECL_READ_P (lhs)
    7718       251495 :               && (VAR_P (lhs) ? warn_unused_but_set_variable
    7719              :                               : warn_unused_but_set_parameter) > 2)
    7720              :             {
    7721        21550 :               mark_exp_read (newrhs);
    7722        21550 :               if (!DECL_READ_P (lhs))
    7723       199311 :                 clear_decl_read = true;
    7724              :             }
    7725              : 
    7726       199311 :           newrhs = build_binary_op (location, modifycode,
    7727              :                                     convert_lvalue_to_rvalue (location, lhs,
    7728              :                                                               true, true),
    7729              :                                     newrhs, true);
    7730       199311 :           if (clear_decl_read)
    7731        21550 :             DECL_READ_P (lhs) = 0;
    7732              : 
    7733              :           /* The original type of the right hand side is no longer
    7734              :              meaningful.  */
    7735              :           rhs_origtype = NULL_TREE;
    7736              :         }
    7737              :     }
    7738              : 
    7739      2896782 :   if (c_dialect_objc ())
    7740              :     {
    7741              :       /* Check if we are modifying an Objective-C property reference;
    7742              :          if so, we need to generate setter calls.  */
    7743            0 :       if (TREE_CODE (newrhs) == EXCESS_PRECISION_EXPR)
    7744            0 :         result = objc_maybe_build_modify_expr (lhs, TREE_OPERAND (newrhs, 0));
    7745              :       else
    7746            0 :         result = objc_maybe_build_modify_expr (lhs, newrhs);
    7747            0 :       if (result)
    7748            0 :         goto return_result;
    7749              : 
    7750              :       /* Else, do the check that we postponed for Objective-C.  */
    7751            0 :       if (!lvalue_or_else (location, lhs, lv_assign))
    7752            0 :         return error_mark_node;
    7753              :     }
    7754              : 
    7755              :   /* Give an error for storing in something that is 'const'.  */
    7756              : 
    7757      2896782 :   if (TYPE_READONLY (lhstype)
    7758      2896782 :       || (RECORD_OR_UNION_TYPE_P (lhstype)
    7759        25742 :           && C_TYPE_FIELDS_READONLY (lhstype)))
    7760              :     {
    7761           88 :       readonly_error (location, lhs, lv_assign);
    7762           88 :       return error_mark_node;
    7763              :     }
    7764      2896694 :   else if (TREE_READONLY (lhs))
    7765            1 :     readonly_warning (lhs, lv_assign);
    7766              : 
    7767              :   /* If storing into a structure or union member,
    7768              :      it has probably been given type `int'.
    7769              :      Compute the type that would go with
    7770              :      the actual amount of storage the member occupies.  */
    7771              : 
    7772      2896694 :   if (TREE_CODE (lhs) == COMPONENT_REF
    7773       248502 :       && (TREE_CODE (lhstype) == INTEGER_TYPE
    7774       248502 :           || TREE_CODE (lhstype) == BOOLEAN_TYPE
    7775       109646 :           || SCALAR_FLOAT_TYPE_P (lhstype)
    7776        86343 :           || TREE_CODE (lhstype) == ENUMERAL_TYPE))
    7777       169155 :     lhstype = TREE_TYPE (get_unwidened (lhs, 0));
    7778              : 
    7779              :   /* If storing in a field that is in actuality a short or narrower than one,
    7780              :      we must store in the field in its actual type.  */
    7781              : 
    7782      2896694 :   if (lhstype != TREE_TYPE (lhs))
    7783              :     {
    7784            0 :       lhs = copy_node (lhs);
    7785            0 :       TREE_TYPE (lhs) = lhstype;
    7786              :     }
    7787              : 
    7788              :   /* Issue -Wc++-compat warnings about an assignment to an enum type
    7789              :      when LHS does not have its original type.  This happens for,
    7790              :      e.g., an enum bitfield in a struct.  */
    7791      2896694 :   if (warn_cxx_compat
    7792         3196 :       && lhs_origtype != NULL_TREE
    7793         3196 :       && lhs_origtype != lhstype
    7794            7 :       && TREE_CODE (lhs_origtype) == ENUMERAL_TYPE)
    7795              :     {
    7796            4 :       tree checktype = (rhs_origtype != NULL_TREE
    7797            4 :                         ? rhs_origtype
    7798            0 :                         : TREE_TYPE (rhs));
    7799            4 :       if (checktype != error_mark_node
    7800            4 :           && (TYPE_MAIN_VARIANT (checktype) != TYPE_MAIN_VARIANT (lhs_origtype)
    7801            2 :               || (is_atomic_op && modifycode != NOP_EXPR)))
    7802            2 :         warning_at (location, OPT_Wc___compat,
    7803              :                     "enum conversion in assignment is invalid in C++");
    7804              :     }
    7805              : 
    7806              :   /* Remove qualifiers.  */
    7807      2896694 :   lhstype = c_build_qualified_type (lhstype, TYPE_UNQUALIFIED);
    7808      2896694 :   olhstype = c_build_qualified_type (olhstype, TYPE_UNQUALIFIED);
    7809              : 
    7810              :   /* Convert new value to destination type.  Fold it first, then
    7811              :      restore any excess precision information, for the sake of
    7812              :      conversion warnings.  */
    7813              : 
    7814      2896694 :   if (!(is_atomic_op && modifycode != NOP_EXPR))
    7815              :     {
    7816      2881209 :       tree rhs_semantic_type = NULL_TREE;
    7817      2881209 :       if (!c_in_omp_for)
    7818              :         {
    7819      2864888 :           if (TREE_CODE (newrhs) == EXCESS_PRECISION_EXPR)
    7820              :             {
    7821         5077 :               rhs_semantic_type = TREE_TYPE (newrhs);
    7822         5077 :               newrhs = TREE_OPERAND (newrhs, 0);
    7823              :             }
    7824      2864888 :           npc = null_pointer_constant_p (newrhs);
    7825      2864888 :           newrhs = c_fully_fold (newrhs, false, NULL);
    7826      2864888 :           if (rhs_semantic_type)
    7827         5077 :             newrhs = build1 (EXCESS_PRECISION_EXPR, rhs_semantic_type, newrhs);
    7828              :         }
    7829              :       else
    7830        16321 :         npc = null_pointer_constant_p (newrhs);
    7831      2881209 :       newrhs = convert_for_assignment (location, rhs_loc, lhstype, newrhs,
    7832              :                                        rhs_origtype, ic_assign, npc,
    7833              :                                        NULL_TREE, NULL_TREE, 0);
    7834      2881209 :       if (TREE_CODE (newrhs) == ERROR_MARK)
    7835          127 :         return error_mark_node;
    7836              :     }
    7837              : 
    7838              :   /* Emit ObjC write barrier, if necessary.  */
    7839      2896567 :   if (c_dialect_objc () && flag_objc_gc)
    7840              :     {
    7841            0 :       result = objc_generate_write_barrier (lhs, modifycode, newrhs);
    7842            0 :       if (result)
    7843              :         {
    7844            0 :           protected_set_expr_location (result, location);
    7845            0 :           goto return_result;
    7846              :         }
    7847              :     }
    7848              : 
    7849              :   /* Scan operands.  */
    7850              : 
    7851      2896567 :   if (is_atomic_op)
    7852        25964 :     result = build_atomic_assign (location, lhs, modifycode, newrhs, false);
    7853              :   else
    7854              :     {
    7855      2870603 :       result = build2 (MODIFY_EXPR, lhstype, lhs, newrhs);
    7856      2870603 :       TREE_SIDE_EFFECTS (result) = 1;
    7857      2870603 :       protected_set_expr_location (result, location);
    7858              :     }
    7859              : 
    7860              :   /* If we got the LHS in a different type for storing in,
    7861              :      convert the result back to the nominal type of LHS
    7862              :      so that the value we return always has the same type
    7863              :      as the LHS argument.  */
    7864              : 
    7865      2896567 :   if (olhstype == TREE_TYPE (result))
    7866      2896567 :     goto return_result;
    7867              : 
    7868            0 :   result = convert_for_assignment (location, rhs_loc, olhstype, result,
    7869              :                                    rhs_origtype, ic_assign, false, NULL_TREE,
    7870              :                                    NULL_TREE, 0);
    7871            0 :   protected_set_expr_location (result, location);
    7872              : 
    7873      2896567 : return_result:
    7874      2896567 :   if (rhseval)
    7875         8676 :     result = build2 (COMPOUND_EXPR, TREE_TYPE (result), rhseval, result);
    7876              :   return result;
    7877              : }
    7878              : 
    7879              : /* Return whether STRUCT_TYPE has an anonymous field with type TYPE.
    7880              :    This is used to implement -fplan9-extensions.  */
    7881              : 
    7882              : static bool
    7883           26 : find_anonymous_field_with_type (tree struct_type, tree type)
    7884              : {
    7885           26 :   tree field;
    7886           26 :   bool found;
    7887              : 
    7888           26 :   gcc_assert (RECORD_OR_UNION_TYPE_P (struct_type));
    7889           26 :   found = false;
    7890           26 :   for (field = TYPE_FIELDS (struct_type);
    7891           68 :        field != NULL_TREE;
    7892           42 :        field = TREE_CHAIN (field))
    7893              :     {
    7894           42 :       tree fieldtype = remove_qualifiers (TREE_TYPE (field));
    7895           42 :       if (DECL_NAME (field) == NULL
    7896           42 :           && comptypes (type, fieldtype))
    7897              :         {
    7898            4 :           if (found)
    7899              :             return false;
    7900              :           found = true;
    7901              :         }
    7902           38 :       else if (DECL_NAME (field) == NULL
    7903            2 :                && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field))
    7904           40 :                && find_anonymous_field_with_type (TREE_TYPE (field), type))
    7905              :         {
    7906            0 :           if (found)
    7907              :             return false;
    7908              :           found = true;
    7909              :         }
    7910              :     }
    7911              :   return found;
    7912              : }
    7913              : 
    7914              : /* RHS is an expression whose type is pointer to struct.  If there is
    7915              :    an anonymous field in RHS with type TYPE, then return a pointer to
    7916              :    that field in RHS.  This is used with -fplan9-extensions.  This
    7917              :    returns NULL if no conversion could be found.  */
    7918              : 
    7919              : static tree
    7920           28 : convert_to_anonymous_field (location_t location, tree type, tree rhs)
    7921              : {
    7922           28 :   tree rhs_struct_type, lhs_main_type;
    7923           28 :   tree field, found_field;
    7924           28 :   bool found_sub_field;
    7925           28 :   tree ret;
    7926              : 
    7927           28 :   gcc_assert (POINTER_TYPE_P (TREE_TYPE (rhs)));
    7928           28 :   rhs_struct_type = TREE_TYPE (TREE_TYPE (rhs));
    7929           28 :   gcc_assert (RECORD_OR_UNION_TYPE_P (rhs_struct_type));
    7930              : 
    7931           28 :   gcc_assert (POINTER_TYPE_P (type));
    7932           28 :   lhs_main_type = remove_qualifiers (TREE_TYPE (type));
    7933              : 
    7934           28 :   found_field = NULL_TREE;
    7935           28 :   found_sub_field = false;
    7936           28 :   for (field = TYPE_FIELDS (rhs_struct_type);
    7937          172 :        field != NULL_TREE;
    7938          144 :        field = TREE_CHAIN (field))
    7939              :     {
    7940          148 :       if (DECL_NAME (field) != NULL_TREE
    7941          148 :           || !RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)))
    7942           96 :         continue;
    7943           52 :       tree fieldtype = remove_qualifiers (TREE_TYPE (field));
    7944           52 :       if (comptypes (lhs_main_type, fieldtype))
    7945              :         {
    7946           28 :           if (found_field != NULL_TREE)
    7947              :             return NULL_TREE;
    7948              :           found_field = field;
    7949              :         }
    7950           24 :       else if (find_anonymous_field_with_type (TREE_TYPE (field),
    7951              :                                                lhs_main_type))
    7952              :         {
    7953            4 :           if (found_field != NULL_TREE)
    7954              :             return NULL_TREE;
    7955              :           found_field = field;
    7956              :           found_sub_field = true;
    7957              :         }
    7958              :     }
    7959              : 
    7960           24 :   if (found_field == NULL_TREE)
    7961              :     return NULL_TREE;
    7962              : 
    7963           24 :   ret = fold_build3_loc (location, COMPONENT_REF, TREE_TYPE (found_field),
    7964              :                          build_fold_indirect_ref (rhs), found_field,
    7965              :                          NULL_TREE);
    7966           24 :   ret = build_fold_addr_expr_loc (location, ret);
    7967              : 
    7968           24 :   if (found_sub_field)
    7969              :     {
    7970            2 :       ret = convert_to_anonymous_field (location, type, ret);
    7971            2 :       gcc_assert (ret != NULL_TREE);
    7972              :     }
    7973              : 
    7974              :   return ret;
    7975              : }
    7976              : 
    7977              : /* Issue an error message for a bad initializer component.
    7978              :    GMSGID identifies the message.
    7979              :    The component name is taken from the spelling stack.  */
    7980              : 
    7981              : static void ATTRIBUTE_GCC_DIAG (2,0)
    7982          944 : error_init (location_t loc, const char *gmsgid, ...)
    7983              : {
    7984          944 :   char *ofwhat;
    7985              : 
    7986          944 :   auto_diagnostic_group d;
    7987              : 
    7988              :   /* The gmsgid may be a format string with %< and %>. */
    7989          944 :   va_list ap;
    7990          944 :   va_start (ap, gmsgid);
    7991          944 :   bool warned = emit_diagnostic_valist (diagnostics::kind::error,
    7992          944 :                                         loc, -1, gmsgid, &ap);
    7993          944 :   va_end (ap);
    7994              : 
    7995          944 :   ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
    7996          944 :   if (*ofwhat && warned)
    7997          220 :     inform (loc, "(near initialization for %qs)", ofwhat);
    7998          944 : }
    7999              : 
    8000              : /* Used to implement pedwarn_init and permerror_init.  */
    8001              : 
    8002              : static bool ATTRIBUTE_GCC_DIAG (3,0)
    8003         2538 : pedwarn_permerror_init (location_t loc, int opt, const char *gmsgid,
    8004              :                         va_list *ap, enum diagnostics::kind kind)
    8005              : {
    8006              :   /* Use the location where a macro was expanded rather than where
    8007              :      it was defined to make sure macros defined in system headers
    8008              :      but used incorrectly elsewhere are diagnosed.  */
    8009         2538 :   location_t exploc = expansion_point_location_if_in_system_header (loc);
    8010         2538 :   auto_diagnostic_group d;
    8011         2538 :   bool warned = emit_diagnostic_valist (kind, exploc, opt, gmsgid, ap);
    8012         2538 :   if (warned)
    8013              :     {
    8014         1815 :       char *ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
    8015         1815 :       if (*ofwhat)
    8016         1494 :         inform (exploc, "(near initialization for %qs)", ofwhat);
    8017              :     }
    8018         5076 :   return warned;
    8019         2538 : }
    8020              : 
    8021              : /* Issue a pedantic warning for a bad initializer component.  OPT is
    8022              :    the option OPT_* (from options.h) controlling this warning or 0 if
    8023              :    it is unconditionally given.  GMSGID identifies the message.  The
    8024              :    component name is taken from the spelling stack.  */
    8025              : 
    8026              : static bool ATTRIBUTE_GCC_DIAG (3,0)
    8027         2187 : pedwarn_init (location_t loc, int opt, const char *gmsgid, ...)
    8028              : {
    8029         2187 :   va_list ap;
    8030         2187 :   va_start (ap, gmsgid);
    8031         2187 :   bool warned = pedwarn_permerror_init (loc, opt, gmsgid, &ap,
    8032              :                                         diagnostics::kind::pedwarn);
    8033         2187 :   va_end (ap);
    8034         2187 :   return warned;
    8035              : }
    8036              : 
    8037              : /* Like pedwarn_init, but issue a permerror.  */
    8038              : 
    8039              : static bool ATTRIBUTE_GCC_DIAG (3,0)
    8040          351 : permerror_init (location_t loc, int opt, const char *gmsgid, ...)
    8041              : {
    8042          351 :   va_list ap;
    8043          351 :   va_start (ap, gmsgid);
    8044          351 :   bool warned = pedwarn_permerror_init (loc, opt, gmsgid, &ap,
    8045              :                                         diagnostics::kind::permerror);
    8046          351 :   va_end (ap);
    8047          351 :   return warned;
    8048              : }
    8049              : 
    8050              : /* Issue a warning for a bad initializer component.
    8051              : 
    8052              :    OPT is the OPT_W* value corresponding to the warning option that
    8053              :    controls this warning.  GMSGID identifies the message.  The
    8054              :    component name is taken from the spelling stack.  */
    8055              : 
    8056              : static void
    8057          146 : warning_init (location_t loc, int opt, const char *gmsgid)
    8058              : {
    8059          146 :   char *ofwhat;
    8060          146 :   bool warned;
    8061              : 
    8062          146 :   auto_diagnostic_group d;
    8063              : 
    8064              :   /* Use the location where a macro was expanded rather than where
    8065              :      it was defined to make sure macros defined in system headers
    8066              :      but used incorrectly elsewhere are diagnosed.  */
    8067          146 :   location_t exploc = expansion_point_location_if_in_system_header (loc);
    8068              : 
    8069              :   /* The gmsgid may be a format string with %< and %>. */
    8070          146 :   warned = warning_at (exploc, opt, gmsgid);
    8071          146 :   if (warned)
    8072              :     {
    8073          133 :       ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
    8074          133 :       if (*ofwhat)
    8075          133 :         inform (exploc, "(near initialization for %qs)", ofwhat);
    8076              :     }
    8077          146 : }
    8078              : 
    8079              : /* If TYPE is an array type and EXPR is a parenthesized string
    8080              :    constant, warn if pedantic that EXPR is being used to initialize an
    8081              :    object of type TYPE.  */
    8082              : 
    8083              : void
    8084      7266589 : maybe_warn_string_init (location_t loc, tree type, struct c_expr expr)
    8085              : {
    8086      7266589 :   if (pedantic
    8087        80456 :       && TREE_CODE (type) == ARRAY_TYPE
    8088         1145 :       && TREE_CODE (expr.value) == STRING_CST
    8089          472 :       && expr.original_code != STRING_CST)
    8090           13 :     pedwarn_init (loc, OPT_Wpedantic,
    8091              :                   "array initialized from parenthesized string constant");
    8092      7266589 : }
    8093              : 
    8094              : /* Attempt to locate the parameter with the given index within FNDECL,
    8095              :    returning DECL_SOURCE_LOCATION (FNDECL) if it can't be found.  */
    8096              : 
    8097              : static location_t
    8098          937 : get_fndecl_argument_location (tree fndecl, int argnum)
    8099              : {
    8100          937 :   int i;
    8101          937 :   tree param;
    8102              : 
    8103              :   /* Locate param by index within DECL_ARGUMENTS (fndecl).  */
    8104          937 :   for (i = 0, param = DECL_ARGUMENTS (fndecl);
    8105         1016 :        i < argnum && param;
    8106           79 :        i++, param = TREE_CHAIN (param))
    8107              :     ;
    8108              : 
    8109              :   /* If something went wrong (e.g. if we have a builtin and thus no arguments),
    8110              :      return DECL_SOURCE_LOCATION (FNDECL).  */
    8111          937 :   if (param == NULL)
    8112          653 :     return DECL_SOURCE_LOCATION (fndecl);
    8113              : 
    8114          284 :   return DECL_SOURCE_LOCATION (param);
    8115              : }
    8116              : 
    8117              : /* Issue a note about a mismatching argument for parameter PARMNUM
    8118              :    to FUNDECL, for types EXPECTED_TYPE and ACTUAL_TYPE.
    8119              :    Attempt to issue the note at the pertinent parameter of the decl;
    8120              :    failing that issue it at the location of FUNDECL; failing that
    8121              :    issue it at PLOC.
    8122              :    Use highlight_colors::actual for the ACTUAL_TYPE
    8123              :    and highlight_colors::expected for EXPECTED_TYPE and the
    8124              :    parameter of FUNDECL*/
    8125              : 
    8126              : static void
    8127         1061 : inform_for_arg (tree fundecl, location_t ploc, int parmnum,
    8128              :                 tree expected_type, tree actual_type)
    8129              : {
    8130         1061 :   location_t loc;
    8131         1061 :   if (fundecl && !DECL_IS_UNDECLARED_BUILTIN (fundecl))
    8132          937 :     loc = get_fndecl_argument_location (fundecl, parmnum - 1);
    8133              :   else
    8134              :     loc = ploc;
    8135              : 
    8136         1061 :   gcc_rich_location richloc (loc, nullptr, highlight_colors::expected);
    8137              : 
    8138         1061 :   pp_markup::element_expected_type elem_expected_type (expected_type);
    8139         1061 :   pp_markup::element_actual_type elem_actual_type (actual_type);
    8140         1061 :   inform (&richloc,
    8141              :           "expected %e but argument is of type %e",
    8142              :           &elem_expected_type, &elem_actual_type);
    8143         1061 : }
    8144              : 
    8145              : /* Issue a warning when an argument of ARGTYPE is passed to a built-in
    8146              :    function FUNDECL declared without prototype to parameter PARMNUM of
    8147              :    PARMTYPE when ARGTYPE does not promote to PARMTYPE.  */
    8148              : 
    8149              : static void
    8150          418 : maybe_warn_builtin_no_proto_arg (location_t loc, tree fundecl, int parmnum,
    8151              :                                  tree parmtype, tree argtype)
    8152              : {
    8153          418 :   tree_code parmcode = TREE_CODE (parmtype);
    8154          418 :   tree_code argcode = TREE_CODE (argtype);
    8155          418 :   tree promoted = c_type_promotes_to (argtype);
    8156              : 
    8157              :   /* Avoid warning for enum arguments that promote to an integer type
    8158              :      of the same size/mode.  */
    8159          418 :   if (parmcode == INTEGER_TYPE
    8160          418 :       && argcode == ENUMERAL_TYPE
    8161          418 :       && TYPE_MODE (parmtype) == TYPE_MODE (argtype))
    8162              :     return;
    8163              : 
    8164          417 :   if ((parmcode == argcode
    8165          222 :        || (parmcode == INTEGER_TYPE
    8166              :            && argcode == ENUMERAL_TYPE))
    8167          418 :       && TYPE_MAIN_VARIANT (parmtype) == TYPE_MAIN_VARIANT (promoted))
    8168              :     return;
    8169              : 
    8170              :   /* This diagnoses even signed/unsigned mismatches.  Those might be
    8171              :      safe in many cases but GCC may emit suboptimal code for them so
    8172              :      warning on those cases drives efficiency improvements.  */
    8173          398 :   if (warning_at (loc, OPT_Wbuiltin_declaration_mismatch,
    8174          398 :                   TYPE_MAIN_VARIANT (promoted) == argtype
    8175              :                   ? G_("%qD argument %d type is %qT where %qT is expected "
    8176              :                        "in a call to built-in function declared without "
    8177              :                        "prototype")
    8178              :                   : G_("%qD argument %d promotes to %qT where %qT is expected "
    8179              :                        "in a call to built-in function declared without "
    8180              :                        "prototype"),
    8181              :                   fundecl, parmnum, promoted, parmtype))
    8182          150 :     inform (DECL_SOURCE_LOCATION (fundecl),
    8183              :             "built-in %qD declared here",
    8184              :             fundecl);
    8185              : }
    8186              : 
    8187              : /* Print a declaration in quotes, with the given highlight_color.
    8188              :    Analogous to handler for %qD, but with a specific highlight color.  */
    8189              : 
    8190          199 : class pp_element_quoted_decl : public pp_element
    8191              : {
    8192              : public:
    8193          199 :   pp_element_quoted_decl (tree decl, const char *highlight_color)
    8194          199 :   : m_decl (decl),
    8195          199 :     m_highlight_color (highlight_color)
    8196              :   {
    8197              :   }
    8198              : 
    8199          199 :   void add_to_phase_2 (pp_markup::context &ctxt) override
    8200              :   {
    8201          199 :     ctxt.begin_quote ();
    8202          199 :     ctxt.begin_highlight_color (m_highlight_color);
    8203              : 
    8204          199 :     print_decl (ctxt);
    8205              : 
    8206          199 :     ctxt.end_highlight_color ();
    8207          199 :     ctxt.end_quote ();
    8208          199 :   }
    8209              : 
    8210          199 :   void print_decl (pp_markup::context &ctxt)
    8211              :   {
    8212          199 :     pretty_printer *const pp = &ctxt.m_pp;
    8213          199 :     pp->set_padding (pp_none);
    8214          199 :     if (DECL_NAME (m_decl))
    8215          199 :       pp_identifier (pp, lang_hooks.decl_printable_name (m_decl, 2));
    8216              :     else
    8217            0 :       pp_string (pp, _("({anonymous})"));
    8218          199 :   }
    8219              : 
    8220              : private:
    8221              :   tree m_decl;
    8222              :   const char *m_highlight_color;
    8223              : };
    8224              : 
    8225              : /* If TYPE is from a typedef, issue a note showing the location
    8226              :    to the user.
    8227              :    Use HIGHLIGHT_COLOR as the highlight color.  */
    8228              : 
    8229              : static void
    8230         1178 : maybe_inform_typedef_location (tree type, const char *highlight_color)
    8231              : {
    8232         1178 :   if (!typedef_variant_p (type))
    8233         1144 :     return;
    8234              : 
    8235           34 :   tree typedef_decl = TYPE_NAME (type);
    8236           34 :   gcc_assert (TREE_CODE (typedef_decl) == TYPE_DECL);
    8237           34 :   gcc_rich_location richloc (DECL_SOURCE_LOCATION (typedef_decl),
    8238           34 :                              nullptr, highlight_color);
    8239           34 :   pp_element_quoted_decl e_typedef_decl (typedef_decl, highlight_color);
    8240           34 :   inform (&richloc, "%e declared here", &e_typedef_decl);
    8241           34 : }
    8242              : 
    8243              : /* Convert value RHS to type TYPE as preparation for an assignment to
    8244              :    an lvalue of type TYPE.  If ORIGTYPE is not NULL_TREE, it is the
    8245              :    original type of RHS; this differs from TREE_TYPE (RHS) for enum
    8246              :    types.  NULL_POINTER_CONSTANT says whether RHS was a null pointer
    8247              :    constant before any folding.
    8248              :    The real work of conversion is done by `convert'.
    8249              :    The purpose of this function is to generate error messages
    8250              :    for assignments that are not allowed in C.
    8251              :    ERRTYPE says whether it is argument passing, assignment,
    8252              :    initialization or return.
    8253              : 
    8254              :    In the following example, '~' denotes where EXPR_LOC and '^' where
    8255              :    LOCATION point to:
    8256              : 
    8257              :      f (var);      [ic_argpass]
    8258              :      ^  ~~~
    8259              :      x = var;      [ic_assign]
    8260              :        ^ ~~~;
    8261              :      int x = var;  [ic_init]
    8262              :              ^^^
    8263              :      return x;     [ic_return]
    8264              :             ^
    8265              : 
    8266              :    FUNCTION is a tree for the function being called.
    8267              :    PARMNUM is the number of the argument, for printing in error messages.
    8268              :    WARNOPT may be set to a warning option to issue the corresponding warning
    8269              :    rather than an error for invalid conversions.  Used for calls to built-in
    8270              :    functions declared without a prototype.  */
    8271              : 
    8272              : static tree
    8273    166709864 : convert_for_assignment (location_t location, location_t expr_loc, tree type,
    8274              :                         tree rhs, tree origtype, enum impl_conv errtype,
    8275              :                         bool null_pointer_constant, tree fundecl,
    8276              :                         tree function, int parmnum, int warnopt /* = 0 */)
    8277              : {
    8278    166709864 :   enum tree_code codel = TREE_CODE (type);
    8279    166709864 :   tree orig_rhs = rhs;
    8280    166709864 :   tree rhstype;
    8281    166709864 :   enum tree_code coder;
    8282    166709864 :   tree rname = NULL_TREE;
    8283    166709864 :   bool objc_ok = false;
    8284              : 
    8285              :   /* Use the expansion point location to handle cases such as user's
    8286              :      function returning a wrong-type macro defined in a system header.  */
    8287    166709864 :   location = expansion_point_location_if_in_system_header (location);
    8288              : 
    8289    166709864 :   if (errtype == ic_argpass)
    8290              :     {
    8291    125351548 :       tree selector;
    8292              :       /* Change pointer to function to the function itself for
    8293              :          diagnostics.  */
    8294    125351548 :       if (TREE_CODE (function) == ADDR_EXPR
    8295    125351548 :           && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL)
    8296            0 :         function = TREE_OPERAND (function, 0);
    8297              : 
    8298              :       /* Handle an ObjC selector specially for diagnostics.  */
    8299    125351548 :       selector = objc_message_selector ();
    8300    125351548 :       rname = function;
    8301    125351548 :       if (selector && parmnum > 2)
    8302              :         {
    8303            0 :           rname = selector;
    8304            0 :           parmnum -= 2;
    8305              :         }
    8306              :     }
    8307              : 
    8308              :   /* This macro is used to emit diagnostics to ensure that all format
    8309              :      strings are complete sentences, visible to gettext and checked at
    8310              :      compile time.  */
    8311              : #define PEDWARN_FOR_ASSIGNMENT(LOCATION, PLOC, OPT, AR, AS, IN, RE)      \
    8312              :   do {                                                                   \
    8313              :     switch (errtype)                                                     \
    8314              :       {                                                                  \
    8315              :       case ic_argpass:                                                   \
    8316              :         {                                                               \
    8317              :           auto_diagnostic_group d;                                              \
    8318              :           if (pedwarn (PLOC, OPT, AR, parmnum, rname))          \
    8319              :             inform_for_arg (fundecl, (PLOC), parmnum, type, rhstype); \
    8320              :         }                                                               \
    8321              :         break;                                                           \
    8322              :       case ic_assign:                                                    \
    8323              :         pedwarn (LOCATION, OPT, AS);                                     \
    8324              :         break;                                                           \
    8325              :       case ic_init:                                                      \
    8326              :       case ic_init_const:                                                \
    8327              :         pedwarn_init (LOCATION, OPT, IN);                                \
    8328              :         break;                                                           \
    8329              :       case ic_return:                                                    \
    8330              :         pedwarn (LOCATION, OPT, RE);                                     \
    8331              :         break;                                                           \
    8332              :       default:                                                           \
    8333              :         gcc_unreachable ();                                              \
    8334              :       }                                                                  \
    8335              :   } while (0)
    8336              : 
    8337              :   /* This macro is used to emit diagnostics to ensure that all format
    8338              :      strings are complete sentences, visible to gettext and checked at
    8339              :      compile time.  It can be called with 'pedwarn' or 'warning_at'.  */
    8340              : #define WARNING_FOR_QUALIFIERS(PEDWARN, LOCATION, PLOC, OPT, AR, AS, IN, RE, QUALS) \
    8341              :   do {                                                                   \
    8342              :     switch (errtype)                                                     \
    8343              :       {                                                                  \
    8344              :       case ic_argpass:                                                   \
    8345              :         {                                                                \
    8346              :           auto_diagnostic_group d;                                       \
    8347              :           if (PEDWARN) {                                                 \
    8348              :             if (pedwarn (PLOC, OPT, AR, parmnum, rname, QUALS))          \
    8349              :               inform_for_arg (fundecl, (PLOC), parmnum, type, rhstype);  \
    8350              :           } else {                                                       \
    8351              :             if (warning_at (PLOC, OPT, AR, parmnum, rname, QUALS))       \
    8352              :               inform_for_arg (fundecl, (PLOC), parmnum, type, rhstype);  \
    8353              :           }                                                              \
    8354              :         }                                                                \
    8355              :         break;                                                           \
    8356              :       case ic_assign:                                                    \
    8357              :         if (PEDWARN)                                                     \
    8358              :           pedwarn (LOCATION, OPT, AS, QUALS);                            \
    8359              :         else                                                             \
    8360              :           warning_at (LOCATION, OPT, AS, QUALS);                         \
    8361              :         break;                                                           \
    8362              :       case ic_init:                                                      \
    8363              :       case ic_init_const:                                                \
    8364              :         if (PEDWARN)                                                     \
    8365              :           pedwarn (LOCATION, OPT, IN, QUALS);                            \
    8366              :         else                                                             \
    8367              :           warning_at (LOCATION, OPT, IN, QUALS);                         \
    8368              :         break;                                                           \
    8369              :       case ic_return:                                                    \
    8370              :         if (PEDWARN)                                                     \
    8371              :           pedwarn (LOCATION, OPT, RE, QUALS);                            \
    8372              :         else                                                             \
    8373              :           warning_at (LOCATION, OPT, RE, QUALS);                         \
    8374              :         break;                                                           \
    8375              :       default:                                                           \
    8376              :         gcc_unreachable ();                                              \
    8377              :       }                                                                  \
    8378              :   } while (0)
    8379              : 
    8380              :   /* This macro is used to emit diagnostics to ensure that all format
    8381              :      strings are complete sentences, visible to gettext and checked at
    8382              :      compile time.  It is the same as PEDWARN_FOR_ASSIGNMENT but with an
    8383              :      extra parameter to enumerate qualifiers.  */
    8384              : #define PEDWARN_FOR_QUALIFIERS(LOCATION, PLOC, OPT, AR, AS, IN, RE, QUALS) \
    8385              :    WARNING_FOR_QUALIFIERS (true, LOCATION, PLOC, OPT, AR, AS, IN, RE, QUALS)
    8386              : 
    8387              : 
    8388    166709864 :   if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
    8389         5975 :     rhs = TREE_OPERAND (rhs, 0);
    8390              : 
    8391    166709864 :   rhstype = TREE_TYPE (rhs);
    8392    166709864 :   coder = TREE_CODE (rhstype);
    8393              : 
    8394    166709864 :   if (coder == ERROR_MARK)
    8395          346 :     return error_mark_node;
    8396              : 
    8397    166709518 :   if (c_dialect_objc ())
    8398              :     {
    8399            0 :       int parmno;
    8400              : 
    8401            0 :       switch (errtype)
    8402              :         {
    8403              :         case ic_return:
    8404              :           parmno = 0;
    8405              :           break;
    8406              : 
    8407              :         case ic_assign:
    8408              :           parmno = -1;
    8409              :           break;
    8410              : 
    8411              :         case ic_init:
    8412              :         case ic_init_const:
    8413              :           parmno = -2;
    8414              :           break;
    8415              : 
    8416              :         default:
    8417            0 :           parmno = parmnum;
    8418              :           break;
    8419              :         }
    8420              : 
    8421            0 :       objc_ok = objc_compare_types (type, rhstype, parmno, rname);
    8422              :     }
    8423              : 
    8424    166709518 :   if (warn_cxx_compat)
    8425              :     {
    8426        28859 :       tree checktype = origtype != NULL_TREE ? origtype : rhstype;
    8427        28859 :       if (checktype != error_mark_node
    8428        28859 :           && TREE_CODE (type) == ENUMERAL_TYPE
    8429        28965 :           && TYPE_MAIN_VARIANT (checktype) != TYPE_MAIN_VARIANT (type))
    8430           45 :         switch (errtype)
    8431              :           {
    8432            8 :           case ic_argpass:
    8433            8 :             if (pedwarn (expr_loc, OPT_Wc___compat, "enum conversion when "
    8434              :                          "passing argument %d of %qE is invalid in C++",
    8435              :                          parmnum, rname))
    8436           16 :               inform ((fundecl && !DECL_IS_UNDECLARED_BUILTIN (fundecl))
    8437            8 :                       ? DECL_SOURCE_LOCATION (fundecl) : expr_loc,
    8438              :                       "expected %qT but argument is of type %qT",
    8439              :                       type, rhstype);
    8440              :             break;
    8441           10 :           case ic_assign:
    8442           10 :             pedwarn (location, OPT_Wc___compat, "enum conversion from %qT to "
    8443              :                      "%qT in assignment is invalid in C++", rhstype, type);
    8444           10 :             break;
    8445           18 :           case ic_init:
    8446           18 :           case ic_init_const:
    8447           18 :             pedwarn_init (location, OPT_Wc___compat, "enum conversion from "
    8448              :                           "%qT to %qT in initialization is invalid in C++",
    8449              :                           rhstype, type);
    8450           18 :             break;
    8451            9 :           case ic_return:
    8452            9 :             pedwarn (location, OPT_Wc___compat, "enum conversion from %qT to "
    8453              :                      "%qT in return is invalid in C++", rhstype, type);
    8454            9 :             break;
    8455            0 :           default:
    8456            0 :             gcc_unreachable ();
    8457              :           }
    8458              :     }
    8459              : 
    8460    166709518 :   if (warn_enum_conversion)
    8461              :     {
    8462     14586584 :       tree checktype = origtype != NULL_TREE ? origtype : rhstype;
    8463     14586584 :       if (checktype != error_mark_node
    8464     14586584 :           && TREE_CODE (checktype) == ENUMERAL_TYPE
    8465        12705 :           && TREE_CODE (type) == ENUMERAL_TYPE
    8466     14594776 :           && !comptypes (TYPE_MAIN_VARIANT (checktype), TYPE_MAIN_VARIANT (type)))
    8467              :        {
    8468            3 :           gcc_rich_location loc (location);
    8469            3 :           warning_at (&loc, OPT_Wenum_conversion,
    8470              :                       "implicit conversion from %qT to %qT",
    8471              :                       checktype, type);
    8472            3 :        }
    8473              :     }
    8474              : 
    8475    166709518 :   if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
    8476              :     {
    8477    147650967 :       warn_for_address_of_packed_member (type, orig_rhs);
    8478    147650967 :       if (type != rhstype)
    8479              :         /* Convert RHS to TYPE in order to not lose TYPE in diagnostics.  */
    8480     36785999 :         rhs = convert (type, rhs);
    8481    147650967 :       return rhs;
    8482              :     }
    8483              : 
    8484     19058551 :   if (coder == VOID_TYPE)
    8485              :     {
    8486              :       /* Except for passing an argument to an unprototyped function,
    8487              :          this is a constraint violation.  When passing an argument to
    8488              :          an unprototyped function, it is compile-time undefined;
    8489              :          making it a constraint in that case was rejected in
    8490              :          DR#252.  */
    8491            8 :       const char msg[] = "void value not ignored as it ought to be";
    8492            8 :       if (warnopt)
    8493            0 :         warning_at (location, warnopt, msg);
    8494              :       else
    8495            8 :         error_at (location, msg);
    8496            8 :       return error_mark_node;
    8497              :     }
    8498     19058543 :   rhs = require_complete_type (location, rhs);
    8499     19058543 :   if (rhs == error_mark_node)
    8500              :     return error_mark_node;
    8501              : 
    8502     19058543 :   if (coder == POINTER_TYPE && reject_gcc_builtin (rhs))
    8503            6 :     return error_mark_node;
    8504              : 
    8505              :   /* A non-reference type can convert to a reference.  This handles
    8506              :      va_start, va_copy and possibly port built-ins.  */
    8507     19058537 :   if (codel == REFERENCE_TYPE && coder != REFERENCE_TYPE)
    8508              :     {
    8509          286 :       if (!lvalue_p (rhs))
    8510              :         {
    8511            0 :           const char msg[] = "cannot pass rvalue to reference parameter";
    8512            0 :           if (warnopt)
    8513            0 :             warning_at (location, warnopt, msg);
    8514              :           else
    8515            0 :             error_at (location, msg);
    8516            0 :           return error_mark_node;
    8517              :         }
    8518          286 :       if (!c_mark_addressable (rhs))
    8519            0 :         return error_mark_node;
    8520          286 :       rhs = build1 (ADDR_EXPR, c_build_pointer_type (TREE_TYPE (rhs)), rhs);
    8521          286 :       SET_EXPR_LOCATION (rhs, location);
    8522              : 
    8523          286 :       rhs = convert_for_assignment (location, expr_loc,
    8524          286 :                                     c_build_pointer_type (TREE_TYPE (type)),
    8525              :                                     rhs, origtype, errtype,
    8526              :                                     null_pointer_constant, fundecl, function,
    8527              :                                     parmnum, warnopt);
    8528          286 :       if (rhs == error_mark_node)
    8529              :         return error_mark_node;
    8530              : 
    8531          286 :       rhs = build1 (NOP_EXPR, type, rhs);
    8532          286 :       SET_EXPR_LOCATION (rhs, location);
    8533          286 :       return rhs;
    8534              :     }
    8535              :   /* Some types can interconvert without explicit casts.  */
    8536     19058251 :   else if (codel == VECTOR_TYPE && coder == VECTOR_TYPE
    8537     19058251 :            && vector_types_convertible_p (type, TREE_TYPE (rhs), true))
    8538      9268179 :     return convert (type, rhs);
    8539              :   /* Arithmetic types all interconvert, and enum is treated like int.  */
    8540      9790072 :   else if ((codel == INTEGER_TYPE || codel == REAL_TYPE
    8541      2271163 :             || codel == FIXED_POINT_TYPE
    8542      2271163 :             || codel == ENUMERAL_TYPE || codel == COMPLEX_TYPE
    8543      2184970 :             || codel == BOOLEAN_TYPE || codel == BITINT_TYPE)
    8544      7696711 :            && (coder == INTEGER_TYPE || coder == REAL_TYPE
    8545        82578 :                || coder == FIXED_POINT_TYPE
    8546        82578 :                || coder == ENUMERAL_TYPE || coder == COMPLEX_TYPE
    8547        39603 :                || coder == BOOLEAN_TYPE || coder == BITINT_TYPE))
    8548              :     {
    8549      7695592 :       if (warnopt && errtype == ic_argpass)
    8550          418 :         maybe_warn_builtin_no_proto_arg (expr_loc, fundecl, parmnum, type,
    8551              :                                          rhstype);
    8552              : 
    8553      7695592 :       bool save = in_late_binary_op;
    8554      7664578 :       if (C_BOOLEAN_TYPE_P (type) || codel == COMPLEX_TYPE
    8555     15303986 :           || (coder == REAL_TYPE
    8556       275795 :               && (codel == INTEGER_TYPE || codel == ENUMERAL_TYPE)
    8557        24196 :               && sanitize_flags_p (SANITIZE_FLOAT_CAST)))
    8558        93942 :         in_late_binary_op = true;
    8559     11065281 :       tree ret = convert_and_check (expr_loc != UNKNOWN_LOCATION
    8560              :                                     ? expr_loc : location, type, orig_rhs,
    8561              :                                     errtype == ic_init_const);
    8562      7695592 :       in_late_binary_op = save;
    8563      7695592 :       return ret;
    8564              :     }
    8565              : 
    8566              :   /* Aggregates in different TUs might need conversion.  */
    8567      2094480 :   if ((codel == RECORD_TYPE || codel == UNION_TYPE)
    8568          103 :       && codel == coder
    8569      2094501 :       && comptypes (TYPE_MAIN_VARIANT (type), TYPE_MAIN_VARIANT (rhstype)))
    8570            8 :     return convert_and_check (expr_loc != UNKNOWN_LOCATION
    8571            8 :                               ? expr_loc : location, type, rhs);
    8572              : 
    8573              :   /* Conversion to a transparent union or record from its member types.
    8574              :      This applies only to function arguments.  */
    8575      2094472 :   if (((codel == UNION_TYPE || codel == RECORD_TYPE)
    8576           95 :       && TYPE_TRANSPARENT_AGGR (type))
    8577      2094510 :       && errtype == ic_argpass)
    8578              :     {
    8579           38 :       tree memb, marginal_memb = NULL_TREE;
    8580              : 
    8581           48 :       for (memb = TYPE_FIELDS (type); memb ; memb = DECL_CHAIN (memb))
    8582              :         {
    8583           48 :           tree memb_type = TREE_TYPE (memb);
    8584              : 
    8585           48 :           if (comptypes (TYPE_MAIN_VARIANT (memb_type),
    8586           48 :                          TYPE_MAIN_VARIANT (rhstype)))
    8587              :             break;
    8588              : 
    8589           26 :           if (TREE_CODE (memb_type) != POINTER_TYPE)
    8590            0 :             continue;
    8591              : 
    8592           26 :           if (coder == POINTER_TYPE)
    8593              :             {
    8594           26 :               tree ttl = TREE_TYPE (memb_type);
    8595           26 :               tree ttr = TREE_TYPE (rhstype);
    8596              : 
    8597              :               /* Any non-function converts to a [const][volatile] void *
    8598              :                  and vice versa; otherwise, targets must be the same.
    8599              :                  Meanwhile, the lhs target must have all the qualifiers of
    8600              :                  the rhs.  */
    8601            0 :               if ((VOID_TYPE_P (ttl) && !TYPE_ATOMIC (ttl))
    8602           26 :                   || (VOID_TYPE_P (ttr) && !TYPE_ATOMIC (ttr))
    8603           45 :                   || comp_target_types (location, memb_type, rhstype))
    8604              :                 {
    8605           16 :                   int lquals = TYPE_QUALS (ttl) & ~TYPE_QUAL_ATOMIC;
    8606           16 :                   int rquals = TYPE_QUALS (ttr) & ~TYPE_QUAL_ATOMIC;
    8607              :                   /* If this type won't generate any warnings, use it.  */
    8608           16 :                   if (lquals == rquals
    8609           16 :                       || ((TREE_CODE (ttr) == FUNCTION_TYPE
    8610            0 :                            && TREE_CODE (ttl) == FUNCTION_TYPE)
    8611            0 :                           ? ((lquals | rquals) == rquals)
    8612           16 :                           : ((lquals | rquals) == lquals)))
    8613              :                     break;
    8614              : 
    8615              :                   /* Keep looking for a better type, but remember this one.  */
    8616            0 :                   if (!marginal_memb)
    8617           10 :                     marginal_memb = memb;
    8618              :                 }
    8619              :             }
    8620              : 
    8621              :           /* Can convert integer zero to any pointer type.  */
    8622           10 :           if (null_pointer_constant)
    8623              :             {
    8624            0 :               rhs = null_pointer_node;
    8625            0 :               break;
    8626              :             }
    8627              :         }
    8628              : 
    8629           38 :       if (memb || marginal_memb)
    8630              :         {
    8631           38 :           if (!memb)
    8632              :             {
    8633              :               /* We have only a marginally acceptable member type;
    8634              :                  it needs a warning.  */
    8635            0 :               tree ttl = TREE_TYPE (TREE_TYPE (marginal_memb));
    8636            0 :               tree ttr = TREE_TYPE (rhstype);
    8637              : 
    8638              :               /* Const and volatile mean something different for function
    8639              :                  types, so the usual warnings are not appropriate.  */
    8640            0 :               if (TREE_CODE (ttr) == FUNCTION_TYPE
    8641            0 :                   && TREE_CODE (ttl) == FUNCTION_TYPE)
    8642              :                 {
    8643              :                   /* Because const and volatile on functions are
    8644              :                      restrictions that say the function will not do
    8645              :                      certain things, it is okay to use a const or volatile
    8646              :                      function where an ordinary one is wanted, but not
    8647              :                      vice-versa.  */
    8648            0 :                   if (TYPE_QUALS_NO_ADDR_SPACE (ttl)
    8649            0 :                       & ~TYPE_QUALS_NO_ADDR_SPACE (ttr))
    8650            0 :                     PEDWARN_FOR_QUALIFIERS (location, expr_loc,
    8651              :                                             OPT_Wdiscarded_qualifiers,
    8652              :                                             G_("passing argument %d of %qE "
    8653              :                                                "makes %q#v qualified function "
    8654              :                                                "pointer from unqualified"),
    8655              :                                             G_("assignment makes %q#v qualified "
    8656              :                                                "function pointer from "
    8657              :                                                "unqualified"),
    8658              :                                             G_("initialization makes %q#v qualified "
    8659              :                                                "function pointer from "
    8660              :                                                "unqualified"),
    8661              :                                             G_("return makes %q#v qualified function "
    8662              :                                                "pointer from unqualified"),
    8663              :                                             TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr));
    8664              :                 }
    8665            0 :               else if (TYPE_QUALS_NO_ADDR_SPACE (ttr)
    8666            0 :                        & ~TYPE_QUALS_NO_ADDR_SPACE (ttl))
    8667            0 :                 PEDWARN_FOR_QUALIFIERS (location, expr_loc,
    8668              :                                         OPT_Wdiscarded_qualifiers,
    8669              :                                         G_("passing argument %d of %qE discards "
    8670              :                                            "%qv qualifier from pointer target type"),
    8671              :                                         G_("assignment discards %qv qualifier "
    8672              :                                            "from pointer target type"),
    8673              :                                         G_("initialization discards %qv qualifier "
    8674              :                                            "from pointer target type"),
    8675              :                                         G_("return discards %qv qualifier from "
    8676              :                                            "pointer target type"),
    8677              :                                         TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl));
    8678              : 
    8679              :               memb = marginal_memb;
    8680              :             }
    8681              : 
    8682           38 :           if (!fundecl || !DECL_IN_SYSTEM_HEADER (fundecl))
    8683           30 :             pedwarn (location, OPT_Wpedantic,
    8684              :                      "ISO C prohibits argument conversion to union type");
    8685              : 
    8686           38 :           rhs = fold_convert_loc (location, TREE_TYPE (memb), rhs);
    8687           38 :           return build_constructor_single (type, memb, rhs);
    8688              :         }
    8689              :     }
    8690              : 
    8691              :   /* Conversions among pointers */
    8692      2094434 :   else if ((codel == POINTER_TYPE || codel == REFERENCE_TYPE)
    8693      2093159 :            && (coder == codel))
    8694              :     {
    8695              :       /* If RHS refers to a built-in declared without a prototype
    8696              :          BLTIN is the declaration of the built-in with a prototype
    8697              :          and RHSTYPE is set to the actual type of the built-in.  */
    8698      2014863 :       tree bltin;
    8699      2014863 :       rhstype = type_or_builtin_type (rhs, &bltin);
    8700              : 
    8701      2014863 :       tree ttl = TREE_TYPE (type);
    8702      2014863 :       tree ttr = TREE_TYPE (rhstype);
    8703      2014863 :       bool is_opaque_pointer;
    8704      2014863 :       bool target_cmp = false;   /* Cache comp_target_types () result.  */
    8705      2014863 :       addr_space_t asl;
    8706      2014863 :       addr_space_t asr;
    8707              : 
    8708      2014863 :       tree mvl = remove_qualifiers (ttl);
    8709      2014863 :       tree mvr = remove_qualifiers (ttr);
    8710              : 
    8711              :       /* Opaque pointers are treated like void pointers.  */
    8712      2014863 :       is_opaque_pointer = vector_targets_convertible_p (ttl, ttr);
    8713              : 
    8714              :       /* The Plan 9 compiler permits a pointer to a struct to be
    8715              :          automatically converted into a pointer to an anonymous field
    8716              :          within the struct.  */
    8717      2014863 :       if (flag_plan9_extensions
    8718           50 :           && RECORD_OR_UNION_TYPE_P (mvl)
    8719           26 :           && RECORD_OR_UNION_TYPE_P (mvr)
    8720           26 :           && mvl != mvr)
    8721              :         {
    8722           26 :           tree new_rhs = convert_to_anonymous_field (location, type, rhs);
    8723           26 :           if (new_rhs != NULL_TREE)
    8724              :             {
    8725           22 :               rhs = new_rhs;
    8726           22 :               rhstype = TREE_TYPE (rhs);
    8727           22 :               coder = TREE_CODE (rhstype);
    8728           22 :               ttr = TREE_TYPE (rhstype);
    8729           22 :               mvr = TYPE_MAIN_VARIANT (ttr);
    8730              :             }
    8731              :         }
    8732              : 
    8733              :       /* C++ does not allow the implicit conversion void* -> T*.  However,
    8734              :          for the purpose of reducing the number of false positives, we
    8735              :          tolerate the special case of
    8736              : 
    8737              :                 int *p = NULL;
    8738              : 
    8739              :          where NULL is typically defined in C to be '(void *) 0'.  */
    8740      2014863 :       if (VOID_TYPE_P (ttr) && rhs != null_pointer_node && !VOID_TYPE_P (ttl))
    8741        26788 :         warning_at (errtype == ic_argpass ? expr_loc : location,
    8742        14204 :                     OPT_Wc___compat,
    8743              :                     "request for implicit conversion "
    8744              :                     "from %qT to %qT not permitted in C++", rhstype, type);
    8745              : 
    8746              :       /* Warn of new allocations that are not big enough for the target
    8747              :          type.  */
    8748      2014863 :       if (warn_alloc_size && TREE_CODE (rhs) == CALL_EXPR)
    8749         5455 :         if (tree fndecl = get_callee_fndecl (rhs))
    8750         5455 :           if (DECL_IS_MALLOC (fndecl))
    8751              :             {
    8752         4601 :               tree attrs = TYPE_ATTRIBUTES (TREE_TYPE (fndecl));
    8753         4601 :               tree alloc_size = lookup_attribute ("alloc_size", attrs);
    8754         4601 :               if (alloc_size)
    8755          447 :                 warn_for_alloc_size (location, ttl, rhs, alloc_size);
    8756              :             }
    8757              : 
    8758              :       /* See if the pointers point to incompatible address spaces.  */
    8759      2014863 :       asl = TYPE_ADDR_SPACE (ttl);
    8760      2014863 :       asr = TYPE_ADDR_SPACE (ttr);
    8761      2014863 :       if (!null_pointer_constant_p (rhs)
    8762      2014863 :           && asr != asl && !targetm.addr_space.subset_p (asr, asl))
    8763              :         {
    8764            3 :           auto_diagnostic_group d;
    8765            3 :           bool diagnosed = true;
    8766            3 :           switch (errtype)
    8767              :             {
    8768            1 :             case ic_argpass:
    8769            1 :               {
    8770            1 :                 const char msg[] = G_("passing argument %d of %qE from "
    8771              :                                       "pointer to non-enclosed address space");
    8772            1 :                 if (warnopt)
    8773            0 :                   diagnosed
    8774            0 :                     = warning_at (expr_loc, warnopt, msg, parmnum, rname);
    8775              :                 else
    8776            1 :                   error_at (expr_loc, msg, parmnum, rname);
    8777            0 :               break;
    8778              :               }
    8779            0 :             case ic_assign:
    8780            0 :               {
    8781            0 :                 const char msg[] = G_("assignment from pointer to "
    8782              :                                       "non-enclosed address space");
    8783            0 :                 if (warnopt)
    8784            0 :                   diagnosed = warning_at (location, warnopt, msg);
    8785              :                 else
    8786            0 :                   error_at (location, msg);
    8787            0 :                 break;
    8788              :               }
    8789            0 :             case ic_init:
    8790            0 :             case ic_init_const:
    8791            0 :               {
    8792            0 :                 const char msg[] = G_("initialization from pointer to "
    8793              :                                       "non-enclosed address space");
    8794            0 :                 if (warnopt)
    8795            0 :                   diagnosed = warning_at (location, warnopt, msg);
    8796              :                 else
    8797            0 :                   error_at (location, msg);
    8798            0 :                 break;
    8799              :               }
    8800            2 :             case ic_return:
    8801            2 :               {
    8802            2 :                 const char msg[] = G_("return from pointer to "
    8803              :                                       "non-enclosed address space");
    8804            2 :                 if (warnopt)
    8805            0 :                   diagnosed = warning_at (location, warnopt, msg);
    8806              :                 else
    8807            2 :                   error_at (location, msg);
    8808            0 :                 break;
    8809              :               }
    8810            0 :             default:
    8811            0 :               gcc_unreachable ();
    8812              :             }
    8813            3 :           if (diagnosed)
    8814              :             {
    8815            3 :               if (errtype == ic_argpass)
    8816            1 :                 inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
    8817              :               else
    8818            2 :                 inform (location, "expected %qT but pointer is of type %qT",
    8819              :                         type, rhstype);
    8820              :             }
    8821            3 :           return error_mark_node;
    8822            3 :         }
    8823              : 
    8824              :       /* Check if the right-hand side has a format attribute but the
    8825              :          left-hand side doesn't.  */
    8826      2014860 :       if (warn_suggest_attribute_format
    8827      2014860 :           && check_missing_format_attribute (type, rhstype))
    8828              :         {
    8829           16 :           switch (errtype)
    8830              :           {
    8831            4 :           case ic_argpass:
    8832            4 :             warning_at (expr_loc, OPT_Wsuggest_attribute_format,
    8833              :                         "argument %d of %qE might be "
    8834              :                         "a candidate for a format attribute",
    8835              :                         parmnum, rname);
    8836            4 :             break;
    8837            4 :           case ic_assign:
    8838            4 :             warning_at (location, OPT_Wsuggest_attribute_format,
    8839              :                         "assignment left-hand side might be "
    8840              :                         "a candidate for a format attribute");
    8841            4 :             break;
    8842            4 :           case ic_init:
    8843            4 :           case ic_init_const:
    8844            4 :             warning_at (location, OPT_Wsuggest_attribute_format,
    8845              :                         "initialization left-hand side might be "
    8846              :                         "a candidate for a format attribute");
    8847            4 :             break;
    8848            4 :           case ic_return:
    8849            4 :             warning_at (location, OPT_Wsuggest_attribute_format,
    8850              :                         "return type might be "
    8851              :                         "a candidate for a format attribute");
    8852            4 :             break;
    8853            0 :           default:
    8854            0 :             gcc_unreachable ();
    8855              :           }
    8856              :         }
    8857              : 
    8858              :       /* See if the pointers point to incompatible scalar storage orders.  */
    8859      2014860 :       if (warn_scalar_storage_order
    8860      2011944 :           && !null_pointer_constant_p (rhs)
    8861      5972466 :           && (AGGREGATE_TYPE_P (ttl) && TYPE_REVERSE_STORAGE_ORDER (ttl))
    8862      1978803 :              != (AGGREGATE_TYPE_P (ttr) && TYPE_REVERSE_STORAGE_ORDER (ttr)))
    8863              :         {
    8864           18 :           tree t;
    8865              : 
    8866           18 :           switch (errtype)
    8867              :           {
    8868           11 :           case ic_argpass:
    8869              :             /* Do not warn for built-in functions, for example memcpy, since we
    8870              :                control how they behave and they can be useful in this area.  */
    8871           11 :             if (TREE_CODE (rname) != FUNCTION_DECL
    8872           11 :                 || !fndecl_built_in_p (rname))
    8873            1 :               warning_at (location, OPT_Wscalar_storage_order,
    8874              :                           "passing argument %d of %qE from incompatible "
    8875              :                           "scalar storage order", parmnum, rname);
    8876              :             break;
    8877            3 :           case ic_assign:
    8878              :             /* Do not warn if the RHS is a call to a function that returns a
    8879              :                pointer that is not an alias.  */
    8880            3 :             if (TREE_CODE (rhs) != CALL_EXPR
    8881            2 :                 || (t = get_callee_fndecl (rhs)) == NULL_TREE
    8882            5 :                 || !DECL_IS_MALLOC (t))
    8883            1 :               warning_at (location, OPT_Wscalar_storage_order,
    8884              :                           "assignment to %qT from pointer type %qT with "
    8885              :                           "incompatible scalar storage order", type, rhstype);
    8886              :             break;
    8887            3 :           case ic_init:
    8888            3 :           case ic_init_const:
    8889              :             /* Likewise.  */
    8890            3 :             if (TREE_CODE (rhs) != CALL_EXPR
    8891            2 :                 || (t = get_callee_fndecl (rhs)) == NULL_TREE
    8892            5 :                 || !DECL_IS_MALLOC (t))
    8893            1 :               warning_at (location, OPT_Wscalar_storage_order,
    8894              :                           "initialization of %qT from pointer type %qT with "
    8895              :                           "incompatible scalar storage order", type, rhstype);
    8896              :             break;
    8897            1 :           case ic_return:
    8898            1 :             warning_at (location, OPT_Wscalar_storage_order,
    8899              :                         "returning %qT from pointer type with incompatible "
    8900              :                         "scalar storage order %qT", rhstype, type);
    8901            1 :             break;
    8902            0 :           default:
    8903            0 :             gcc_unreachable ();
    8904              :           }
    8905              :         }
    8906              : 
    8907              :       /* Any non-function converts to a [const][volatile] void *
    8908              :          and vice versa; otherwise, targets must be the same.
    8909              :          Meanwhile, the lhs target must have all the qualifiers of the rhs.  */
    8910       422478 :       if ((VOID_TYPE_P (ttl) && !TYPE_ATOMIC (ttl))
    8911      1592383 :           || (VOID_TYPE_P (ttr) && !TYPE_ATOMIC (ttr))
    8912      1545175 :           || (target_cmp = comp_target_types (location, type, rhstype))
    8913         2446 :           || is_opaque_pointer
    8914      2019752 :           || ((c_common_unsigned_type (mvl)
    8915         2446 :                == c_common_unsigned_type (mvr))
    8916         3340 :               && (c_common_signed_type (mvl)
    8917         1670 :                   == c_common_signed_type (mvr))
    8918         1655 :               && TYPE_ATOMIC (mvl) == TYPE_ATOMIC (mvr)))
    8919              :         {
    8920              :           /* Warn about loss of qualifers from pointers to arrays with
    8921              :              qualifiers on the element type. */
    8922      2014061 :           if (TREE_CODE (ttr) == ARRAY_TYPE)
    8923              :             {
    8924         2131 :               ttr = strip_array_types (ttr);
    8925         2131 :               ttl = strip_array_types (ttl);
    8926              : 
    8927         2131 :               if (TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttr)
    8928         2131 :                   & ~TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttl))
    8929          115 :                 WARNING_FOR_QUALIFIERS (flag_isoc23,
    8930              :                                         location, expr_loc,
    8931              :                                         OPT_Wdiscarded_array_qualifiers,
    8932              :                                         G_("passing argument %d of %qE discards "
    8933              :                                            "%qv qualifier from pointer target type"),
    8934              :                                         G_("assignment discards %qv qualifier "
    8935              :                                            "from pointer target type"),
    8936              :                                         G_("initialization discards %qv qualifier "
    8937              :                                            "from pointer target type"),
    8938              :                                         G_("return discards %qv qualifier from "
    8939              :                                            "pointer target type"),
    8940              :                                         TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl));
    8941              :             }
    8942      2011930 :           else if (pedantic
    8943       146050 :               && ((VOID_TYPE_P (ttl) && TREE_CODE (ttr) == FUNCTION_TYPE)
    8944       146030 :                   ||
    8945              :                   (VOID_TYPE_P (ttr)
    8946         2952 :                    && !null_pointer_constant
    8947          178 :                    && TREE_CODE (ttl) == FUNCTION_TYPE)))
    8948           34 :             PEDWARN_FOR_ASSIGNMENT (location, expr_loc, OPT_Wpedantic,
    8949              :                                     G_("ISO C forbids passing argument %d of "
    8950              :                                        "%qE between function pointer "
    8951              :                                        "and %<void *%>"),
    8952              :                                     G_("ISO C forbids assignment between "
    8953              :                                        "function pointer and %<void *%>"),
    8954              :                                     G_("ISO C forbids initialization between "
    8955              :                                        "function pointer and %<void *%>"),
    8956              :                                     G_("ISO C forbids return between function "
    8957              :                                        "pointer and %<void *%>"));
    8958              :           /* Const and volatile mean something different for function types,
    8959              :              so the usual warnings are not appropriate.  */
    8960      2011896 :           else if (TREE_CODE (ttr) != FUNCTION_TYPE
    8961      1979484 :                    && TREE_CODE (ttl) != FUNCTION_TYPE)
    8962              :             {
    8963              :                /* Assignments between atomic and non-atomic objects are OK.  */
    8964      1978787 :                bool warn_quals_ped = TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttr)
    8965      1978787 :                                      & ~TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttl);
    8966      1978787 :                bool warn_quals = TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttr)
    8967      1978787 :                                  & ~TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (strip_array_types (ttl));
    8968              : 
    8969              :               /* Don't warn about loss of qualifier for conversions from
    8970              :                  qualified void* to pointers to arrays with corresponding
    8971              :                  qualifier on the element type (except for pedantic before C23). */
    8972      1978787 :               if (warn_quals || (warn_quals_ped && pedantic && !flag_isoc23))
    8973          697 :                 PEDWARN_FOR_QUALIFIERS (location, expr_loc,
    8974              :                                         OPT_Wdiscarded_qualifiers,
    8975              :                                         G_("passing argument %d of %qE discards "
    8976              :                                            "%qv qualifier from pointer target type"),
    8977              :                                         G_("assignment discards %qv qualifier "
    8978              :                                            "from pointer target type"),
    8979              :                                         G_("initialization discards %qv qualifier "
    8980              :                                            "from pointer target type"),
    8981              :                                         G_("return discards %qv qualifier from "
    8982              :                                            "pointer target type"),
    8983              :                                         TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl));
    8984           11 :               else if (warn_quals_ped)
    8985           11 :                 pedwarn_c11 (location, OPT_Wc11_c23_compat,
    8986              :                              "array with qualifier on the element is not qualified before C23");
    8987              : 
    8988              :               /* If this is not a case of ignoring a mismatch in signedness,
    8989              :                  no warning.  */
    8990      1978079 :               else if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr)
    8991      1540254 :                        || target_cmp)
    8992              :                 ;
    8993              :               /* If there is a mismatch, do warn.  */
    8994         1647 :               else if (warn_pointer_sign)
    8995           82 :                 switch (errtype)
    8996              :                   {
    8997           33 :                   case ic_argpass:
    8998           33 :                     {
    8999           33 :                       auto_diagnostic_group d;
    9000           33 :                       range_label_for_type_mismatch rhs_label (rhstype, type);
    9001           33 :                       gcc_rich_location richloc (expr_loc, &rhs_label,
    9002           33 :                                                  highlight_colors::actual);
    9003           33 :                       if (pedwarn (&richloc, OPT_Wpointer_sign,
    9004              :                                    "pointer targets in passing argument %d of "
    9005              :                                    "%qE differ in signedness", parmnum, rname))
    9006           33 :                         inform_for_arg (fundecl, expr_loc, parmnum, type,
    9007              :                                         rhstype);
    9008           33 :                     }
    9009           33 :                     break;
    9010           21 :                   case ic_assign:
    9011           21 :                     pedwarn (location, OPT_Wpointer_sign,
    9012              :                              "pointer targets in assignment from %qT to %qT "
    9013              :                              "differ in signedness", rhstype, type);
    9014           21 :                     break;
    9015           14 :                   case ic_init:
    9016           14 :                   case ic_init_const:
    9017           14 :                     pedwarn_init (location, OPT_Wpointer_sign,
    9018              :                                   "pointer targets in initialization of %qT "
    9019              :                                   "from %qT differ in signedness", type,
    9020              :                                   rhstype);
    9021           14 :                     break;
    9022           14 :                   case ic_return:
    9023           14 :                     pedwarn (location, OPT_Wpointer_sign, "pointer targets in "
    9024              :                              "returning %qT from a function with return type "
    9025              :                              "%qT differ in signedness", rhstype, type);
    9026           14 :                     break;
    9027            0 :                   default:
    9028            0 :                     gcc_unreachable ();
    9029              :                   }
    9030              :             }
    9031        33109 :           else if (TREE_CODE (ttl) == FUNCTION_TYPE
    9032         4148 :                    && TREE_CODE (ttr) == FUNCTION_TYPE)
    9033              :             {
    9034              :               /* Because const and volatile on functions are restrictions
    9035              :                  that say the function will not do certain things,
    9036              :                  it is okay to use a const or volatile function
    9037              :                  where an ordinary one is wanted, but not vice-versa.  */
    9038         3451 :               if (TYPE_QUALS_NO_ADDR_SPACE (ttl)
    9039         3451 :                   & ~TYPE_QUALS_NO_ADDR_SPACE (ttr))
    9040           18 :                 PEDWARN_FOR_QUALIFIERS (location, expr_loc,
    9041              :                                         OPT_Wdiscarded_qualifiers,
    9042              :                                         G_("passing argument %d of %qE makes "
    9043              :                                            "%q#v qualified function pointer "
    9044              :                                            "from unqualified"),
    9045              :                                         G_("assignment makes %q#v qualified function "
    9046              :                                            "pointer from unqualified"),
    9047              :                                         G_("initialization makes %q#v qualified "
    9048              :                                            "function pointer from unqualified"),
    9049              :                                         G_("return makes %q#v qualified function "
    9050              :                                            "pointer from unqualified"),
    9051              :                                         TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr));
    9052              :             }
    9053              :         }
    9054              :       /* Avoid warning about the volatile ObjC EH puts on decls.  */
    9055          799 :       else if (!objc_ok)
    9056              :         {
    9057          799 :           auto_diagnostic_group d;
    9058          799 :           bool warned = false;
    9059          799 :           pp_markup::element_expected_type e_type (type);
    9060          799 :           pp_markup::element_actual_type e_rhstype (rhstype);
    9061          799 :           switch (errtype)
    9062              :             {
    9063          306 :             case ic_argpass:
    9064          306 :               {
    9065          306 :                 range_label_for_type_mismatch rhs_label (rhstype, type);
    9066          306 :                 gcc_rich_location richloc (expr_loc, &rhs_label,
    9067          306 :                                            highlight_colors::actual);
    9068          306 :                 warned
    9069          306 :                   = permerror_opt (&richloc, OPT_Wincompatible_pointer_types,
    9070              :                                    "passing argument %d of %qE from "
    9071              :                                    "incompatible pointer type",
    9072              :                                    parmnum, rname);
    9073          306 :                 if (warned)
    9074          174 :                   inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
    9075          306 :               }
    9076          306 :               break;
    9077          267 :             case ic_assign:
    9078          267 :               if (bltin)
    9079           11 :                 warned
    9080           11 :                   = permerror_opt (location, OPT_Wincompatible_pointer_types,
    9081              :                                    "assignment to %e from pointer to "
    9082              :                                    "%qD with incompatible type %e",
    9083              :                                    &e_type, bltin, &e_rhstype);
    9084              :               else
    9085          256 :                 warned
    9086          256 :                   = permerror_opt (location, OPT_Wincompatible_pointer_types,
    9087              :                                    "assignment to %e from incompatible "
    9088              :                                    "pointer type %e",
    9089              :                                    &e_type, &e_rhstype);
    9090              :               break;
    9091          167 :             case ic_init:
    9092          167 :             case ic_init_const:
    9093          167 :               if (bltin)
    9094           13 :                 warned
    9095           13 :                   = permerror_init (location, OPT_Wincompatible_pointer_types,
    9096              :                                     "initialization of %e from pointer to "
    9097              :                                     "%qD with incompatible type %e",
    9098              :                                     &e_type, bltin, &e_rhstype);
    9099              :               else
    9100          154 :                 warned
    9101          154 :                   = permerror_init (location, OPT_Wincompatible_pointer_types,
    9102              :                                     "initialization of %e from incompatible "
    9103              :                                     "pointer type %e",
    9104              :                                     &e_type, &e_rhstype);
    9105              :               break;
    9106           59 :             case ic_return:
    9107           59 :               if (bltin)
    9108           11 :                 warned
    9109           11 :                   = permerror_opt (location, OPT_Wincompatible_pointer_types,
    9110              :                                    "returning pointer to %qD of type %e from "
    9111              :                                    "a function with incompatible type %e",
    9112              :                                    bltin, &e_rhstype, &e_type);
    9113              :               else
    9114           48 :                 warned
    9115           48 :                   = permerror_opt (location, OPT_Wincompatible_pointer_types,
    9116              :                                    "returning %e from a function with "
    9117              :                                    "incompatible return type %e",
    9118              :                                    &e_rhstype, &e_type);
    9119              :               break;
    9120            0 :             default:
    9121            0 :               gcc_unreachable ();
    9122              :             }
    9123          799 :           if (warned)
    9124              :             {
    9125              :               /* If the mismatching function type is a pointer to a function,
    9126              :                  try to show the decl of the function.  */
    9127          589 :               if (TREE_CODE (rhs) == ADDR_EXPR
    9128          589 :                   && TREE_CODE (TREE_OPERAND (rhs, 0)) == FUNCTION_DECL)
    9129              :                 {
    9130          191 :                   tree rhs_fndecl = TREE_OPERAND (rhs, 0);
    9131          191 :                   if (!DECL_IS_UNDECLARED_BUILTIN (rhs_fndecl))
    9132              :                     {
    9133          165 :                       gcc_rich_location richloc
    9134          165 :                         (DECL_SOURCE_LOCATION (rhs_fndecl), nullptr,
    9135          165 :                          highlight_colors::actual);
    9136          165 :                       pp_element_quoted_decl e_rhs_fndecl
    9137          165 :                         (rhs_fndecl, highlight_colors::actual);
    9138          165 :                       inform (&richloc,
    9139              :                               "%e declared here", &e_rhs_fndecl);
    9140          165 :                     }
    9141              :                 }
    9142              :               /* If either/both of the types are typedefs, show the decl.  */
    9143          589 :               maybe_inform_typedef_location (type,
    9144              :                                              highlight_colors::expected);
    9145          589 :               maybe_inform_typedef_location (rhstype,
    9146              :                                              highlight_colors::actual);
    9147              :             }
    9148          799 :         }
    9149              : 
    9150              :       /* If RHS isn't an address, check pointer or array of packed
    9151              :          struct or union.  */
    9152      2014860 :       warn_for_address_of_packed_member (type, orig_rhs);
    9153              : 
    9154      2014860 :       return convert (type, rhs);
    9155              :     }
    9156        79571 :   else if (codel == POINTER_TYPE && coder == ARRAY_TYPE)
    9157              :     {
    9158              :       /* ??? This should not be an error when inlining calls to
    9159              :          unprototyped functions.  */
    9160            4 :       const char msg[] = "invalid use of non-lvalue array";
    9161            4 :       if (warnopt)
    9162            0 :         warning_at (location, warnopt, msg);
    9163              :       else
    9164            4 :         error_at (location, msg);
    9165            4 :       return error_mark_node;
    9166              :     }
    9167        79567 :   else if (codel == POINTER_TYPE
    9168        78292 :            && (coder == INTEGER_TYPE
    9169        78292 :                || coder == ENUMERAL_TYPE
    9170          611 :                || coder == BOOLEAN_TYPE
    9171          611 :                || coder == NULLPTR_TYPE
    9172           27 :                || coder == BITINT_TYPE))
    9173              :     {
    9174        78279 :       if (null_pointer_constant && c_inhibit_evaluation_warnings == 0
    9175        77281 :           && coder != NULLPTR_TYPE)
    9176        76726 :         warning_at (location, OPT_Wzero_as_null_pointer_constant,
    9177              :                     "zero as null pointer constant");
    9178              :       /* A NULLPTR type is just a nullptr always.  */
    9179        77724 :       if (coder == NULLPTR_TYPE)
    9180          570 :         return omit_one_operand_loc (expr_loc, type, nullptr_node, rhs);
    9181              :       /* An explicit constant 0 or type nullptr_t can convert to a pointer,
    9182              :          or one that results from arithmetic, even including a cast to
    9183              :          integer type.  */
    9184        77709 :       else if (!null_pointer_constant)
    9185          972 :         switch (errtype)
    9186              :           {
    9187          800 :           case ic_argpass:
    9188          800 :             {
    9189          800 :               auto_diagnostic_group d;
    9190          800 :               range_label_for_type_mismatch rhs_label (rhstype, type);
    9191          800 :               gcc_rich_location richloc (expr_loc, &rhs_label,
    9192          800 :                                          highlight_colors::actual);
    9193          800 :               if (permerror_opt (&richloc, OPT_Wint_conversion,
    9194              :                                  "passing argument %d of %qE makes pointer "
    9195              :                                  "from integer without a cast", parmnum, rname))
    9196              :                 {
    9197          439 :                   maybe_emit_indirection_note (expr_loc, rhs, type);
    9198          439 :                   inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
    9199              :                 }
    9200          800 :             }
    9201          800 :             break;
    9202           93 :           case ic_assign:
    9203           93 :             permerror_opt (location, OPT_Wint_conversion,
    9204              :                            "assignment to %qT from %qT makes pointer from "
    9205              :                            "integer without a cast", type, rhstype);
    9206           93 :             break;
    9207           56 :           case ic_init:
    9208           56 :           case ic_init_const:
    9209           56 :             permerror_init (location, OPT_Wint_conversion,
    9210              :                             "initialization of %qT from %qT makes pointer "
    9211              :                             "from integer without a cast", type, rhstype);
    9212           56 :             break;
    9213           23 :           case ic_return:
    9214           23 :             permerror_init (location, OPT_Wint_conversion,
    9215              :                             "returning %qT from a function with return type "
    9216              :                             "%qT makes pointer from integer without a cast",
    9217              :                             rhstype, type);
    9218           23 :             break;
    9219            0 :           default:
    9220            0 :             gcc_unreachable ();
    9221              :           }
    9222              : 
    9223        77709 :       return convert (type, rhs);
    9224              :     }
    9225         1288 :   else if ((codel == INTEGER_TYPE || codel == BITINT_TYPE)
    9226          540 :            && coder == POINTER_TYPE)
    9227              :     {
    9228          514 :       switch (errtype)
    9229              :         {
    9230          344 :         case ic_argpass:
    9231          344 :           {
    9232          344 :             auto_diagnostic_group d;
    9233          344 :             range_label_for_type_mismatch rhs_label (rhstype, type);
    9234          344 :             gcc_rich_location richloc (expr_loc, &rhs_label,
    9235          344 :                                        highlight_colors::actual);
    9236          344 :             if (permerror_opt (&richloc, OPT_Wint_conversion,
    9237              :                                "passing argument %d of %qE makes integer from "
    9238              :                                "pointer without a cast", parmnum, rname))
    9239              :               {
    9240          323 :                 maybe_emit_indirection_note (expr_loc, rhs, type);
    9241          323 :                 inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
    9242              :               }
    9243          344 :           }
    9244          344 :           break;
    9245           52 :         case ic_assign:
    9246           52 :           permerror_opt (location, OPT_Wint_conversion,
    9247              :                          "assignment to %qT from %qT makes integer from "
    9248              :                          "pointer without a cast", type, rhstype);
    9249           52 :           break;
    9250           83 :         case ic_init:
    9251           83 :         case ic_init_const:
    9252           83 :           permerror_init (location, OPT_Wint_conversion,
    9253              :                           "initialization of %qT from %qT makes integer "
    9254              :                           "from pointer without a cast", type, rhstype);
    9255           83 :           break;
    9256           35 :         case ic_return:
    9257           35 :           permerror_opt (location, OPT_Wint_conversion, "returning %qT from a "
    9258              :                          "function with return type %qT makes integer from "
    9259              :                          "pointer without a cast", rhstype, type);
    9260           35 :           break;
    9261            0 :         default:
    9262            0 :           gcc_unreachable ();
    9263              :         }
    9264              : 
    9265          514 :       return convert (type, rhs);
    9266              :     }
    9267          626 :   else if (C_BOOLEAN_TYPE_P (type)
    9268              :            /* The type nullptr_t may be converted to bool.  The
    9269              :               result is false.  */
    9270          776 :            && (coder == POINTER_TYPE || coder == NULLPTR_TYPE))
    9271              :     {
    9272          150 :       tree ret;
    9273          150 :       bool save = in_late_binary_op;
    9274          150 :       in_late_binary_op = true;
    9275          150 :       ret = convert (type, rhs);
    9276          150 :       in_late_binary_op = save;
    9277          150 :       return ret;
    9278              :     }
    9279          624 :   else if (codel == NULLPTR_TYPE && null_pointer_constant)
    9280            6 :     return convert (type, rhs);
    9281              : 
    9282          618 :   switch (errtype)
    9283              :     {
    9284           35 :     case ic_argpass:
    9285           35 :       {
    9286           35 :         auto_diagnostic_group d;
    9287           35 :         range_label_for_type_mismatch rhs_label (rhstype, type);
    9288           35 :         gcc_rich_location richloc (expr_loc, &rhs_label,
    9289           35 :                                    highlight_colors::actual);
    9290           35 :         const char msg[] = G_("incompatible type for argument %d of %qE");
    9291           35 :         if (warnopt)
    9292            8 :           warning_at (expr_loc, warnopt, msg, parmnum, rname);
    9293              :         else
    9294           27 :           error_at (&richloc, msg, parmnum, rname);
    9295           35 :         inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
    9296           35 :       }
    9297           35 :       break;
    9298          108 :     case ic_assign:
    9299          108 :       {
    9300          108 :         const char msg[]
    9301              :           = G_("incompatible types when assigning to type %qT from type %qT");
    9302          108 :         if (warnopt)
    9303            0 :           warning_at (expr_loc, 0, msg, type, rhstype);
    9304              :         else
    9305          108 :           error_at (expr_loc, msg, type, rhstype);
    9306          108 :         break;
    9307              :       }
    9308          460 :     case ic_init:
    9309          460 :     case ic_init_const:
    9310          460 :       {
    9311          460 :         const char msg[]
    9312              :           = G_("incompatible types when initializing type %qT using type %qT");
    9313          460 :         if (warnopt)
    9314            0 :           warning_at (location, 0, msg, type, rhstype);
    9315              :         else
    9316          460 :           error_at (location, msg, type, rhstype);
    9317          460 :         break;
    9318              :       }
    9319           15 :     case ic_return:
    9320           15 :       {
    9321           15 :         const char msg[]
    9322              :           = G_("incompatible types when returning type %qT but %qT was expected");
    9323           15 :         if (warnopt)
    9324            0 :           warning_at (location, 0, msg, rhstype, type);
    9325              :         else
    9326           15 :           error_at (location, msg, rhstype, type);
    9327           15 :         break;
    9328              :       }
    9329            0 :     default:
    9330            0 :       gcc_unreachable ();
    9331              :     }
    9332              : 
    9333          618 :   return error_mark_node;
    9334              : }
    9335              : 
    9336              : /* If VALUE is a compound expr all of whose expressions are constant, then
    9337              :    return its value.  Otherwise, return error_mark_node.
    9338              : 
    9339              :    This is for handling COMPOUND_EXPRs as initializer elements
    9340              :    which is allowed with a warning when -pedantic is specified.  */
    9341              : 
    9342              : static tree
    9343            2 : valid_compound_expr_initializer (tree value, tree endtype)
    9344              : {
    9345            2 :   if (TREE_CODE (value) == COMPOUND_EXPR)
    9346              :     {
    9347            1 :       if (valid_compound_expr_initializer (TREE_OPERAND (value, 0), endtype)
    9348            1 :           == error_mark_node)
    9349              :         return error_mark_node;
    9350            0 :       return valid_compound_expr_initializer (TREE_OPERAND (value, 1),
    9351            0 :                                               endtype);
    9352              :     }
    9353            1 :   else if (!initializer_constant_valid_p (value, endtype))
    9354            1 :     return error_mark_node;
    9355              :   else
    9356              :     return value;
    9357              : }
    9358              : 
    9359              : /* Perform appropriate conversions on the initial value of a variable,
    9360              :    store it in the declaration DECL,
    9361              :    and print any error messages that are appropriate.
    9362              :    If ORIGTYPE is not NULL_TREE, it is the original type of INIT.
    9363              :    If the init is invalid, store an ERROR_MARK.
    9364              : 
    9365              :    INIT_LOC is the location of the initial value.  */
    9366              : 
    9367              : void
    9368      7257755 : store_init_value (location_t init_loc, tree decl, tree init, tree origtype)
    9369              : {
    9370      7257755 :   tree value, type;
    9371      7257755 :   bool npc = false;
    9372      7257755 :   bool int_const_expr = false;
    9373      7257755 :   bool arith_const_expr = false;
    9374              : 
    9375              :   /* If variable's type was invalidly declared, just ignore it.  */
    9376              : 
    9377      7257755 :   type = TREE_TYPE (decl);
    9378      7257755 :   if (TREE_CODE (type) == ERROR_MARK)
    9379              :     return;
    9380              : 
    9381              :   /* Digest the specified initializer into an expression.  */
    9382              : 
    9383      7257747 :   if (init)
    9384              :     {
    9385      7257744 :       npc = null_pointer_constant_p (init);
    9386      7257744 :       int_const_expr = (TREE_CODE (init) == INTEGER_CST
    9387       419349 :                         && !TREE_OVERFLOW (init)
    9388      7677057 :                         && INTEGRAL_TYPE_P (TREE_TYPE (init)));
    9389              :       /* Not fully determined before folding.  */
    9390              :       arith_const_expr = true;
    9391              :     }
    9392      7257747 :   bool constexpr_p = (VAR_P (decl)
    9393      7257747 :                       && C_DECL_DECLARED_CONSTEXPR (decl));
    9394      7257747 :   value = digest_init (init_loc, decl, type, init, origtype, npc,
    9395              :                        int_const_expr, arith_const_expr, true,
    9396      7257747 :                        TREE_STATIC (decl) || constexpr_p, constexpr_p);
    9397              : 
    9398              :   /* Store the expression if valid; else report error.  */
    9399              : 
    9400      7257747 :   if (!in_system_header_at (input_location)
    9401      7257747 :       && AGGREGATE_TYPE_P (TREE_TYPE (decl)) && !TREE_STATIC (decl))
    9402        28092 :     warning (OPT_Wtraditional, "traditional C rejects automatic "
    9403              :              "aggregate initialization");
    9404              : 
    9405      7257747 :   if (value != error_mark_node || TREE_CODE (decl) != FUNCTION_DECL)
    9406      7257746 :     DECL_INITIAL (decl) = value;
    9407              : 
    9408              :   /* ANSI wants warnings about out-of-range constant initializers.  */
    9409      7257758 :   STRIP_TYPE_NOPS (value);
    9410      7257747 :   if (TREE_STATIC (decl))
    9411       179792 :     constant_expression_warning (value);
    9412              : 
    9413              :   /* Check if we need to set array size from compound literal size.  */
    9414      7257747 :   if (TREE_CODE (type) == ARRAY_TYPE
    9415        26307 :       && TYPE_DOMAIN (type) == NULL_TREE
    9416      7270232 :       && value != error_mark_node)
    9417              :     {
    9418              :       tree inside_init = init;
    9419              : 
    9420        11613 :       STRIP_TYPE_NOPS (inside_init);
    9421        11613 :       inside_init = fold (inside_init);
    9422              : 
    9423        11613 :       if (TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
    9424              :         {
    9425           13 :           tree cldecl = COMPOUND_LITERAL_EXPR_DECL (inside_init);
    9426              : 
    9427           13 :           if (TYPE_DOMAIN (TREE_TYPE (cldecl)))
    9428              :             {
    9429              :               /* For int foo[] = (int [3]){1}; we need to set array size
    9430              :                  now since later on array initializer will be just the
    9431              :                  brace enclosed list of the compound literal.  */
    9432           13 :               tree etype = strip_array_types (TREE_TYPE (decl));
    9433           13 :               type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
    9434           13 :               TYPE_DOMAIN (type) = TYPE_DOMAIN (TREE_TYPE (cldecl));
    9435           13 :               layout_type (type);
    9436           13 :               layout_decl (cldecl, 0);
    9437           13 :               TREE_TYPE (decl)
    9438           26 :                 = c_build_qualified_type (type, TYPE_QUALS (etype));
    9439              :             }
    9440              :         }
    9441              :     }
    9442              : }
    9443              : 
    9444              : /* Methods for storing and printing names for error messages.  */
    9445              : 
    9446              : /* Implement a spelling stack that allows components of a name to be pushed
    9447              :    and popped.  Each element on the stack is this structure.  */
    9448              : 
    9449              : struct spelling
    9450              : {
    9451              :   int kind;
    9452              :   union
    9453              :     {
    9454              :       unsigned HOST_WIDE_INT i;
    9455              :       const char *s;
    9456              :     } u;
    9457              : };
    9458              : 
    9459              : #define SPELLING_STRING 1
    9460              : #define SPELLING_MEMBER 2
    9461              : #define SPELLING_BOUNDS 3
    9462              : 
    9463              : static struct spelling *spelling;       /* Next stack element (unused).  */
    9464              : static struct spelling *spelling_base;  /* Spelling stack base.  */
    9465              : static int spelling_size;               /* Size of the spelling stack.  */
    9466              : 
    9467              : /* Macros to save and restore the spelling stack around push_... functions.
    9468              :    Alternative to SAVE_SPELLING_STACK.  */
    9469              : 
    9470              : #define SPELLING_DEPTH() (spelling - spelling_base)
    9471              : #define RESTORE_SPELLING_DEPTH(DEPTH) (spelling = spelling_base + (DEPTH))
    9472              : 
    9473              : /* Push an element on the spelling stack with type KIND and assign VALUE
    9474              :    to MEMBER.  */
    9475              : 
    9476              : #define PUSH_SPELLING(KIND, VALUE, MEMBER)                              \
    9477              : {                                                                       \
    9478              :   int depth = SPELLING_DEPTH ();                                        \
    9479              :                                                                         \
    9480              :   if (depth >= spelling_size)                                                \
    9481              :     {                                                                   \
    9482              :       spelling_size += 10;                                              \
    9483              :       spelling_base = XRESIZEVEC (struct spelling, spelling_base,       \
    9484              :                                   spelling_size);                       \
    9485              :       RESTORE_SPELLING_DEPTH (depth);                                   \
    9486              :     }                                                                   \
    9487              :                                                                         \
    9488              :   spelling->kind = (KIND);                                           \
    9489              :   spelling->MEMBER = (VALUE);                                                \
    9490              :   spelling++;                                                           \
    9491              : }
    9492              : 
    9493              : /* Push STRING on the stack.  Printed literally.  */
    9494              : 
    9495              : static void
    9496      7254989 : push_string (const char *string)
    9497              : {
    9498      7254989 :   PUSH_SPELLING (SPELLING_STRING, string, u.s);
    9499      7254989 : }
    9500              : 
    9501              : /* Push a member name on the stack.  Printed as '.' STRING.  */
    9502              : 
    9503              : static void
    9504      1227117 : push_member_name (tree decl)
    9505              : {
    9506      1227117 :   const char *const string
    9507      1227117 :     = (DECL_NAME (decl)
    9508      1227117 :        ? identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl)))
    9509          208 :        : _("<anonymous>"));
    9510      1227117 :   PUSH_SPELLING (SPELLING_MEMBER, string, u.s);
    9511      1227117 : }
    9512              : 
    9513              : /* Push an array bounds on the stack.  Printed as [BOUNDS].  */
    9514              : 
    9515              : static void
    9516      2600449 : push_array_bounds (unsigned HOST_WIDE_INT bounds)
    9517              : {
    9518      2600449 :   PUSH_SPELLING (SPELLING_BOUNDS, bounds, u.i);
    9519      2600449 : }
    9520              : 
    9521              : /* Compute the maximum size in bytes of the printed spelling.  */
    9522              : 
    9523              : static int
    9524         2892 : spelling_length (void)
    9525              : {
    9526         2892 :   int size = 0;
    9527         2892 :   struct spelling *p;
    9528              : 
    9529         6416 :   for (p = spelling_base; p < spelling; p++)
    9530              :     {
    9531         3524 :       if (p->kind == SPELLING_BOUNDS)
    9532         1479 :         size += 25;
    9533              :       else
    9534         2045 :         size += strlen (p->u.s) + 1;
    9535              :     }
    9536              : 
    9537         2892 :   return size;
    9538              : }
    9539              : 
    9540              : /* Print the spelling to BUFFER and return it.  */
    9541              : 
    9542              : static char *
    9543         2892 : print_spelling (char *buffer)
    9544              : {
    9545         2892 :   char *d = buffer;
    9546         2892 :   struct spelling *p;
    9547              : 
    9548         6416 :   for (p = spelling_base; p < spelling; p++)
    9549         3524 :     if (p->kind == SPELLING_BOUNDS)
    9550              :       {
    9551         1479 :         sprintf (d, "[" HOST_WIDE_INT_PRINT_UNSIGNED "]", p->u.i);
    9552         1479 :         d += strlen (d);
    9553              :       }
    9554              :     else
    9555              :       {
    9556         2045 :         const char *s;
    9557         2045 :         if (p->kind == SPELLING_MEMBER)
    9558          198 :           *d++ = '.';
    9559        16715 :         for (s = p->u.s; (*d = *s++); d++)
    9560              :           ;
    9561              :       }
    9562         2892 :   *d++ = '\0';
    9563         2892 :   return buffer;
    9564              : }
    9565              : 
    9566              : /* Check whether INIT, a floating or integer constant, is
    9567              :    representable in TYPE, a real floating type with the same radix or
    9568              :    a decimal floating type initialized with a binary floating
    9569              :    constant.  Return true if OK, false if not.  */
    9570              : static bool
    9571          362 : constexpr_init_fits_real_type (tree type, tree init)
    9572              : {
    9573          362 :   gcc_assert (SCALAR_FLOAT_TYPE_P (type));
    9574          362 :   gcc_assert (TREE_CODE (init) == INTEGER_CST || TREE_CODE (init) == REAL_CST);
    9575          362 :   if (TREE_CODE (init) == REAL_CST
    9576          362 :       && TYPE_MODE (TREE_TYPE (init)) == TYPE_MODE (type))
    9577              :     {
    9578              :       /* Same mode, no conversion required except for the case of
    9579              :          signaling NaNs if the types are incompatible (e.g. double and
    9580              :          long double with the same mode).  */
    9581          177 :       if (REAL_VALUE_ISSIGNALING_NAN (TREE_REAL_CST (init))
    9582          195 :           && !comptypes (TYPE_MAIN_VARIANT (type),
    9583           18 :                          TYPE_MAIN_VARIANT (TREE_TYPE (init))))
    9584              :         return false;
    9585          177 :       return true;
    9586              :     }
    9587          185 :   if (TREE_CODE (init) == INTEGER_CST)
    9588              :     {
    9589           54 :       tree converted = build_real_from_int_cst (type, init);
    9590           54 :       bool fail = false;
    9591          108 :       wide_int w = real_to_integer (&TREE_REAL_CST (converted), &fail,
    9592           54 :                                     TYPE_PRECISION (TREE_TYPE (init)));
    9593           68 :       return !fail && wi::eq_p (w, wi::to_wide (init));
    9594           54 :     }
    9595          131 :   if (REAL_VALUE_ISSIGNALING_NAN (TREE_REAL_CST (init)))
    9596              :     return false;
    9597          114 :   if ((REAL_VALUE_ISINF (TREE_REAL_CST (init))
    9598           34 :        && MODE_HAS_INFINITIES (TYPE_MODE (type)))
    9599          218 :       || (REAL_VALUE_ISNAN (TREE_REAL_CST (init))
    9600           34 :           && MODE_HAS_NANS (TYPE_MODE (type))))
    9601           20 :     return true;
    9602           94 :   if (DECIMAL_FLOAT_TYPE_P (type)
    9603          134 :       && !DECIMAL_FLOAT_TYPE_P (TREE_TYPE (init)))
    9604              :     {
    9605              :       /* This is valid if the real number represented by the
    9606              :          initializer can be exactly represented in the decimal
    9607              :          type.  Compare the values using MPFR.  */
    9608            8 :       REAL_VALUE_TYPE t;
    9609            8 :       real_convert (&t, TYPE_MODE (type), &TREE_REAL_CST (init));
    9610            8 :       mpfr_t bin_val, dec_val;
    9611            8 :       mpfr_init2 (bin_val, REAL_MODE_FORMAT (TYPE_MODE (TREE_TYPE (init)))->p);
    9612            8 :       mpfr_init2 (dec_val, REAL_MODE_FORMAT (TYPE_MODE (TREE_TYPE (init)))->p);
    9613            8 :       mpfr_from_real (bin_val, &TREE_REAL_CST (init), MPFR_RNDN);
    9614            8 :       char string[256];
    9615            8 :       real_to_decimal (string, &t, sizeof string, 0, 1);
    9616            8 :       bool res = (mpfr_strtofr (dec_val, string, NULL, 10, MPFR_RNDN) == 0
    9617            8 :                   && mpfr_equal_p (bin_val, dec_val));
    9618            8 :       mpfr_clear (bin_val);
    9619            8 :       mpfr_clear (dec_val);
    9620            8 :       return res;
    9621              :     }
    9622              :   /* exact_real_truncate is not quite right here, since it doesn't
    9623              :      allow even an exact conversion to subnormal values.  */
    9624           86 :   REAL_VALUE_TYPE t;
    9625           86 :   real_convert (&t, TYPE_MODE (type), &TREE_REAL_CST (init));
    9626           86 :   return real_identical (&t, &TREE_REAL_CST (init));
    9627              : }
    9628              : 
    9629              : /* Check whether INIT (location LOC) is valid as a 'constexpr'
    9630              :    initializer for type TYPE, and give an error if not.  INIT has
    9631              :    already been folded and verified to be constant.  INT_CONST_EXPR
    9632              :    and ARITH_CONST_EXPR say whether it is an integer constant
    9633              :    expression or arithmetic constant expression, respectively.  If
    9634              :    TYPE is not a scalar type, this function does nothing.  */
    9635              : 
    9636              : static void
    9637          912 : check_constexpr_init (location_t loc, tree type, tree init,
    9638              :                       bool int_const_expr, bool arith_const_expr)
    9639              : {
    9640          912 :   if (POINTER_TYPE_P (type))
    9641              :     {
    9642              :       /* The initializer must be null.  */
    9643           86 :       if (TREE_CODE (init) != INTEGER_CST || !integer_zerop (init))
    9644            8 :         error_at (loc, "%<constexpr%> pointer initializer is not null");
    9645           86 :       return;
    9646              :     }
    9647          826 :   if (INTEGRAL_TYPE_P (type))
    9648              :     {
    9649              :       /* The initializer must be an integer constant expression,
    9650              :          representable in the target type.  */
    9651          316 :       if (!int_const_expr)
    9652              :         {
    9653           13 :           if (TREE_CODE (init) == RAW_DATA_CST
    9654           13 :               && TYPE_PRECISION (type) == CHAR_BIT)
    9655              :             {
    9656            4 :               if (!TYPE_UNSIGNED (type))
    9657          137 :                 for (unsigned int i = 0;
    9658          140 :                      i < (unsigned) RAW_DATA_LENGTH (init); ++i)
    9659          138 :                   if (RAW_DATA_SCHAR_ELT (init, i) < 0)
    9660              :                     {
    9661            1 :                       error_at (loc, "%<constexpr%> initializer not "
    9662              :                                 "representable in type of object");
    9663            1 :                       break;
    9664              :                     }
    9665              :             }
    9666              :           else
    9667            9 :             error_at (loc, "%<constexpr%> integer initializer is not an "
    9668              :                       "integer constant expression");
    9669              :         }
    9670          303 :       else if (!int_fits_type_p (init, type))
    9671            6 :         error_at (loc, "%<constexpr%> initializer not representable in "
    9672              :                   "type of object");
    9673          316 :       return;
    9674              :     }
    9675              :   /* We don't apply any extra checks to extension types such as vector
    9676              :      or fixed-point types.  */
    9677          510 :   if (TREE_CODE (type) != REAL_TYPE && TREE_CODE (type) != COMPLEX_TYPE)
    9678              :     return;
    9679          353 :   if (!arith_const_expr)
    9680              :     {
    9681            5 :       error_at (loc, "%<constexpr%> initializer is not an arithmetic "
    9682              :                 "constant expression");
    9683            5 :       return;
    9684              :     }
    9685              :   /* We don't apply any extra checks to complex integers.  */
    9686          348 :   if (TREE_CODE (type) == COMPLEX_TYPE
    9687          348 :       && TREE_CODE (TREE_TYPE (type)) != REAL_TYPE)
    9688              :     return;
    9689              :   /* Following N3082, a real type cannot be initialized from a complex
    9690              :      type and a binary type cannot be initialized from a decimal type
    9691              :      (but initializing a decimal type from a binary type is OK).
    9692              :      Signaling NaN initializers are OK only if the types are
    9693              :      compatible (not just the same mode); all quiet NaN and infinity
    9694              :      initializations are considered to preserve the value.  */
    9695          348 :   if (TREE_CODE (TREE_TYPE (init)) == COMPLEX_TYPE
    9696          348 :       && SCALAR_FLOAT_TYPE_P (type))
    9697              :     {
    9698            6 :       error_at (loc, "%<constexpr%> initializer for a real type is of "
    9699              :                 "complex type");
    9700            6 :       return;
    9701              :     }
    9702          342 :   if (SCALAR_FLOAT_TYPE_P (type)
    9703          300 :       && SCALAR_FLOAT_TYPE_P (TREE_TYPE (init))
    9704          250 :       && DECIMAL_FLOAT_TYPE_P (TREE_TYPE (init))
    9705          481 :       && !DECIMAL_FLOAT_TYPE_P (type))
    9706              :     {
    9707            6 :       error_at (loc, "%<constexpr%> initializer for a binary "
    9708              :                 "floating-point type is of decimal type");
    9709            6 :       return;
    9710              :     }
    9711          336 :   bool fits;
    9712          336 :   if (TREE_CODE (type) == COMPLEX_TYPE)
    9713              :     {
    9714           42 :       switch (TREE_CODE (init))
    9715              :         {
    9716           10 :         case INTEGER_CST:
    9717           10 :         case REAL_CST:
    9718           10 :           fits = constexpr_init_fits_real_type (TREE_TYPE (type), init);
    9719           10 :           break;
    9720           32 :         case COMPLEX_CST:
    9721           32 :           fits = (constexpr_init_fits_real_type (TREE_TYPE (type),
    9722           32 :                                                  TREE_REALPART (init))
    9723           58 :                   && constexpr_init_fits_real_type (TREE_TYPE (type),
    9724           26 :                                                     TREE_IMAGPART (init)));
    9725              :           break;
    9726            0 :         default:
    9727            0 :           gcc_unreachable ();
    9728              :         }
    9729              :     }
    9730              :   else
    9731          294 :     fits = constexpr_init_fits_real_type (type, init);
    9732          304 :   if (!fits)
    9733           65 :     error_at (loc, "%<constexpr%> initializer not representable in "
    9734              :               "type of object");
    9735              : }
    9736              : 
    9737              : /* Digest the parser output INIT as an initializer for type TYPE
    9738              :    initializing DECL.
    9739              :    Return a C expression of type TYPE to represent the initial value.
    9740              : 
    9741              :    If ORIGTYPE is not NULL_TREE, it is the original type of INIT.
    9742              : 
    9743              :    NULL_POINTER_CONSTANT is true if INIT is a null pointer constant,
    9744              :    INT_CONST_EXPR is true if INIT is an integer constant expression,
    9745              :    and ARITH_CONST_EXPR is true if INIT is, or might be, an arithmetic
    9746              :    constant expression, false if it has already been determined in the
    9747              :    caller that it is not (but folding may have made the value passed here
    9748              :    indistinguishable from an arithmetic constant expression).
    9749              : 
    9750              :    If INIT is a string constant, STRICT_STRING is true if it is
    9751              :    unparenthesized or we should not warn here for it being parenthesized.
    9752              :    For other types of INIT, STRICT_STRING is not used.
    9753              : 
    9754              :    INIT_LOC is the location of the INIT.
    9755              : 
    9756              :    REQUIRE_CONSTANT requests an error if non-constant initializers or
    9757              :    elements are seen.  REQUIRE_CONSTEXPR means the stricter requirements
    9758              :    on initializers for 'constexpr' objects apply.  */
    9759              : 
    9760              : static tree
    9761     16865191 : digest_init (location_t init_loc, tree decl, tree type, tree init,
    9762              :              tree origtype, bool null_pointer_constant, bool int_const_expr,
    9763              :              bool arith_const_expr, bool strict_string,
    9764              :              bool require_constant, bool require_constexpr)
    9765              : {
    9766     16865191 :   enum tree_code code = TREE_CODE (type);
    9767     16865191 :   tree inside_init = init;
    9768     16865191 :   tree semantic_type = NULL_TREE;
    9769     16865191 :   bool maybe_const = true;
    9770              : 
    9771     16865191 :   if (type == error_mark_node
    9772     16865191 :       || !init
    9773     33730379 :       || error_operand_p (init))
    9774              :     return error_mark_node;
    9775              : 
    9776     16872614 :   STRIP_TYPE_NOPS (inside_init);
    9777              : 
    9778              :   /* If require_constant is TRUE,  when the initializer is a call to
    9779              :      .ACCESS_WITH_SIZE, use the first argument as the initializer.
    9780              :      For example:
    9781              :      y = (char *) .ACCESS_WITH_SIZE ((char *) &static_annotated.c,...)
    9782              :      will be converted to
    9783              :      y = &static_annotated.c.  */
    9784              : 
    9785     16864055 :   if (require_constant
    9786      2891262 :       && TREE_CODE (inside_init) == NOP_EXPR
    9787       736235 :       && TREE_CODE (TREE_OPERAND (inside_init, 0)) == CALL_EXPR
    9788     16864057 :       && is_access_with_size_p (TREE_OPERAND (inside_init, 0)))
    9789            2 :     inside_init
    9790            2 :       = get_ref_from_access_with_size (TREE_OPERAND (inside_init, 0));
    9791              : 
    9792     16864055 :   if (!c_in_omp_for)
    9793              :     {
    9794     16859303 :       if (TREE_CODE (inside_init) == EXCESS_PRECISION_EXPR)
    9795              :         {
    9796          441 :           semantic_type = TREE_TYPE (inside_init);
    9797          441 :           inside_init = TREE_OPERAND (inside_init, 0);
    9798              :         }
    9799     16859303 :       inside_init = c_fully_fold (inside_init, require_constant, &maybe_const);
    9800              :     }
    9801              :   /* TODO: this may not detect all cases of expressions folding to
    9802              :      constants that are not arithmetic constant expressions.  */
    9803     16864055 :   if (!maybe_const)
    9804              :     arith_const_expr = false;
    9805     25165594 :   else if (!INTEGRAL_TYPE_P (TREE_TYPE (inside_init))
    9806      5646792 :            && TREE_CODE (TREE_TYPE (inside_init)) != REAL_TYPE
    9807     16797837 :            && TREE_CODE (TREE_TYPE (inside_init)) != COMPLEX_TYPE)
    9808              :     arith_const_expr = false;
    9809      8396265 :   else if (TREE_CODE (inside_init) != INTEGER_CST
    9810              :            && TREE_CODE (inside_init) != REAL_CST
    9811              :            && TREE_CODE (inside_init) != COMPLEX_CST
    9812              :            && TREE_CODE (inside_init) != RAW_DATA_CST)
    9813              :     arith_const_expr = false;
    9814      5064475 :   else if (TREE_OVERFLOW (inside_init))
    9815     11799624 :     arith_const_expr = false;
    9816              : 
    9817              :   /* Initialization of an array of chars from a string constant
    9818              :      optionally enclosed in braces.  */
    9819              : 
    9820     16864055 :   if (code == ARRAY_TYPE && inside_init
    9821       188326 :       && TREE_CODE (inside_init) == STRING_CST)
    9822              :     {
    9823        11702 :       tree typ1
    9824        11702 :         = (TYPE_ATOMIC (TREE_TYPE (type))
    9825        11702 :            ? c_build_qualified_type (TYPE_MAIN_VARIANT (TREE_TYPE (type)),
    9826              :                                      TYPE_QUAL_ATOMIC)
    9827        11688 :            : TYPE_MAIN_VARIANT (TREE_TYPE (type)));
    9828              :       /* Note that an array could be both an array of character type
    9829              :          and an array of wchar_t if wchar_t is signed char or unsigned
    9830              :          char.  */
    9831        23404 :       bool char_array = (typ1 == char_type_node
    9832          516 :                          || typ1 == signed_char_type_node
    9833        12183 :                          || typ1 == unsigned_char_type_node);
    9834        11702 :       bool wchar_array = !!comptypes (typ1, wchar_type_node);
    9835        11702 :       bool char16_array = !!comptypes (typ1, char16_type_node);
    9836        11702 :       bool char32_array = !!comptypes (typ1, char32_type_node);
    9837              : 
    9838        11702 :       if (char_array || wchar_array || char16_array || char32_array)
    9839              :         {
    9840        11673 :           struct c_expr expr;
    9841        11673 :           tree typ2 = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init)));
    9842        11673 :           bool incompat_string_cst = false;
    9843        11673 :           expr.value = inside_init;
    9844        11673 :           expr.original_code = (strict_string ? STRING_CST : ERROR_MARK);
    9845        11673 :           expr.original_type = NULL;
    9846        11673 :           expr.m_decimal = 0;
    9847        11673 :           maybe_warn_string_init (init_loc, type, expr);
    9848              : 
    9849        11673 :           if (TYPE_DOMAIN (type) && !TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
    9850           91 :             pedwarn_init (init_loc, OPT_Wpedantic,
    9851              :                           "initialization of a flexible array member");
    9852              : 
    9853        11673 :           if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
    9854        11673 :                          TYPE_MAIN_VARIANT (type)))
    9855              :             return inside_init;
    9856              : 
    9857         4185 :           if (char_array)
    9858              :             {
    9859         4074 :               if (typ2 != char_type_node && typ2 != char8_type_node)
    9860              :                 incompat_string_cst = true;
    9861              :             }
    9862          111 :           else if (!comptypes (typ1, typ2))
    9863              :             incompat_string_cst = true;
    9864              : 
    9865              :           if (incompat_string_cst)
    9866              :             {
    9867           72 :               error_init (init_loc, "cannot initialize array of %qT from "
    9868              :                           "a string literal with type array of %qT",
    9869              :                           typ1, typ2);
    9870           72 :               return error_mark_node;
    9871              :             }
    9872              : 
    9873         4113 :           if (require_constexpr
    9874         4113 :               && TYPE_UNSIGNED (typ1) != TYPE_UNSIGNED (typ2))
    9875              :             {
    9876              :               /* Check if all characters of the string can be
    9877              :                  represented in the type of the constexpr object being
    9878              :                  initialized.  */
    9879           24 :               unsigned HOST_WIDE_INT len = TREE_STRING_LENGTH (inside_init);
    9880           24 :               const unsigned char *p =
    9881           24 :                 (const unsigned char *) TREE_STRING_POINTER (inside_init);
    9882           24 :               gcc_assert (CHAR_TYPE_SIZE == 8 && CHAR_BIT == 8);
    9883           70 :               for (unsigned i = 0; i < len; i++)
    9884           58 :                 if (p[i] > 127)
    9885              :                   {
    9886           12 :                     error_init (init_loc, "%<constexpr%> initializer not "
    9887              :                                 "representable in type of object");
    9888           12 :                     break;
    9889              :                   }
    9890              :             }
    9891              : 
    9892         4113 :           if (TYPE_DOMAIN (type) != NULL_TREE
    9893         4019 :               && TYPE_SIZE (type) != NULL_TREE
    9894         8073 :               && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
    9895              :             {
    9896         3960 :               unsigned HOST_WIDE_INT len = TREE_STRING_LENGTH (inside_init);
    9897              : 
    9898         3960 :               if (compare_tree_int (TYPE_SIZE_UNIT (type), len) < 0)
    9899              :                 {
    9900          396 :                   unsigned HOST_WIDE_INT avail
    9901          396 :                     = tree_to_uhwi (TYPE_SIZE_UNIT (type));
    9902          396 :                   unsigned unit = TYPE_PRECISION (typ1) / BITS_PER_UNIT;
    9903          396 :                   const char *p = TREE_STRING_POINTER (inside_init);
    9904              : 
    9905              :                   /* Construct truncated string.  */
    9906          396 :                   inside_init = build_string (avail, p);
    9907              : 
    9908              :                   /* Subtract the size of a single (possibly wide) character
    9909              :                      because it may be ok to ignore the terminating NUL char
    9910              :                      that is counted in the length of the constant.  */
    9911          396 :                   if (len - unit > avail)
    9912           63 :                     pedwarn_init (init_loc, 0,
    9913              :                                   "initializer-string for array of %qT "
    9914              :                                   "is too long (%wu chars into %wu "
    9915              :                                   "available)", typ1, len, avail);
    9916          333 :                   else if (warn_cxx_compat)
    9917            9 :                     warning_at (init_loc, OPT_Wc___compat,
    9918              :                                 "initializer-string for array of %qT "
    9919              :                                 "is too long for C++ (%wu chars into %wu "
    9920              :                                 "available)", typ1, len, avail);
    9921          324 :                   else if (warn_unterminated_string_initialization
    9922          324 :                            && get_attr_nonstring_decl (decl) == NULL_TREE)
    9923           22 :                     warning_at (init_loc,
    9924           22 :                                 OPT_Wunterminated_string_initialization,
    9925              :                                 "initializer-string for array of %qT "
    9926              :                                 "truncates NUL terminator but destination "
    9927              :                                 "lacks %qs attribute (%wu chars into %wu "
    9928              :                                 "available)", typ1, "nonstring", len, avail);
    9929              :                 }
    9930              :             }
    9931              : 
    9932         4113 :           TREE_TYPE (inside_init) = type;
    9933         4113 :           return inside_init;
    9934              :         }
    9935           29 :       else if (INTEGRAL_TYPE_P (typ1))
    9936              :         {
    9937           29 :           error_init (init_loc, "array of inappropriate type initialized "
    9938              :                       "from string constant");
    9939           29 :           return error_mark_node;
    9940              :         }
    9941              :     }
    9942              : 
    9943              :   /* Build a VECTOR_CST from a *constant* vector constructor.  If the
    9944              :      vector constructor is not constant (e.g. {1,2,3,foo()}) then punt
    9945              :      below and handle as a constructor.  */
    9946     16852353 :   if (code == VECTOR_TYPE
    9947      6297949 :       && VECTOR_TYPE_P (TREE_TYPE (inside_init))
    9948      6297947 :       && vector_types_convertible_p (TREE_TYPE (inside_init), type, true)
    9949     23150262 :       && TREE_CONSTANT (inside_init))
    9950              :     {
    9951       631829 :       if (TREE_CODE (inside_init) == VECTOR_CST
    9952       631926 :           && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
    9953           97 :                         TYPE_MAIN_VARIANT (type)))
    9954              :         return inside_init;
    9955              : 
    9956       631732 :       if (TREE_CODE (inside_init) == CONSTRUCTOR)
    9957              :         {
    9958              :           unsigned HOST_WIDE_INT ix;
    9959              :           tree value;
    9960      4163914 :           bool constant_p = true;
    9961              : 
    9962              :           /* Iterate through elements and check if all constructor
    9963              :              elements are *_CSTs.  */
    9964      4163914 :           FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (inside_init), ix, value)
    9965      3532238 :             if (!CONSTANT_CLASS_P (value))
    9966              :               {
    9967              :                 constant_p = false;
    9968              :                 break;
    9969              :               }
    9970              : 
    9971       631732 :           if (constant_p)
    9972       631676 :             return build_vector_from_ctor (type,
    9973       631676 :                                            CONSTRUCTOR_ELTS (inside_init));
    9974              :         }
    9975              :     }
    9976              : 
    9977     16220580 :   if (warn_sequence_point)
    9978      2447830 :     verify_sequence_points (inside_init);
    9979              : 
    9980              :   /* Any type can be initialized
    9981              :      from an expression of the same type, optionally with braces.  */
    9982              : 
    9983     16220580 :   if (inside_init && TREE_TYPE (inside_init) != NULL_TREE
    9984     32441160 :       && (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
    9985     16220580 :                      TYPE_MAIN_VARIANT (type))
    9986      3123622 :           || (code == ARRAY_TYPE
    9987          477 :               && comptypes (TREE_TYPE (inside_init), type))
    9988      3123622 :           || (gnu_vector_type_p (type)
    9989          189 :               && comptypes (TREE_TYPE (inside_init), type))
    9990      3123622 :           || (code == POINTER_TYPE
    9991       111895 :               && TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE
    9992         9290 :               && comptypes (TREE_TYPE (TREE_TYPE (inside_init)),
    9993         9290 :                             TREE_TYPE (type)))))
    9994              :     {
    9995     13098934 :       if (code == POINTER_TYPE)
    9996              :         {
    9997       784534 :           if (TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE)
    9998              :             {
    9999         1976 :               if (TREE_CODE (inside_init) == STRING_CST
   10000           68 :                   || TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
   10001         1973 :                 inside_init = array_to_pointer_conversion
   10002         1973 :                   (init_loc, inside_init);
   10003              :               else
   10004              :                 {
   10005            3 :                   error_init (init_loc, "invalid use of non-lvalue array");
   10006            3 :                   return error_mark_node;
   10007              :                 }
   10008              :             }
   10009              :         }
   10010              : 
   10011     13098931 :       if (code == VECTOR_TYPE || c_hardbool_type_attr (type))
   10012              :         /* Although the types are compatible, we may require a
   10013              :            conversion.  */
   10014      5666120 :         inside_init = convert (type, inside_init);
   10015              : 
   10016     13098931 :       if ((code == RECORD_TYPE || code == UNION_TYPE)
   10017     13098931 :           && !comptypes (TYPE_MAIN_VARIANT (type), TYPE_MAIN_VARIANT (TREE_TYPE (inside_init))))
   10018              :         {
   10019            0 :           error_init (init_loc, "invalid initializer");
   10020            0 :           return error_mark_node;
   10021              :         }
   10022              : 
   10023     13098931 :       if (require_constant
   10024      2298083 :           && TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
   10025              :         {
   10026              :           /* As an extension, allow initializing objects with static storage
   10027              :              duration with compound literals (which are then treated just as
   10028              :              the brace enclosed list they contain).  Also allow this for
   10029              :              vectors, as we can only assign them with compound literals.  */
   10030           31 :           if (flag_isoc99 && code != VECTOR_TYPE)
   10031            8 :             pedwarn_init (init_loc, OPT_Wpedantic, "initializer element "
   10032              :                           "is not constant");
   10033           31 :           tree decl = COMPOUND_LITERAL_EXPR_DECL (inside_init);
   10034           31 :           inside_init = DECL_INITIAL (decl);
   10035              :         }
   10036              : 
   10037     13098931 :       if (code == ARRAY_TYPE && TREE_CODE (inside_init) != STRING_CST
   10038       176147 :           && TREE_CODE (inside_init) != CONSTRUCTOR)
   10039              :         {
   10040            2 :           error_init (init_loc, "array initialized from non-constant array "
   10041              :                       "expression");
   10042            2 :           return error_mark_node;
   10043              :         }
   10044              : 
   10045              :       /* Compound expressions can only occur here if -Wpedantic or
   10046              :          -pedantic-errors is specified.  In the later case, we always want
   10047              :          an error.  In the former case, we simply want a warning.  */
   10048     13098929 :       if (require_constant && pedantic
   10049        20284 :           && TREE_CODE (inside_init) == COMPOUND_EXPR)
   10050              :         {
   10051            1 :           inside_init
   10052            1 :             = valid_compound_expr_initializer (inside_init,
   10053            1 :                                                TREE_TYPE (inside_init));
   10054            1 :           if (inside_init == error_mark_node)
   10055            1 :             error_init (init_loc, "initializer element is not constant");
   10056              :           else
   10057            0 :             pedwarn_init (init_loc, OPT_Wpedantic,
   10058              :                           "initializer element is not constant");
   10059            1 :           if (flag_pedantic_errors)
   10060            0 :             inside_init = error_mark_node;
   10061              :         }
   10062      2298082 :       else if (require_constant
   10063      2298082 :                && !initializer_constant_valid_p (inside_init,
   10064      2298082 :                                                  TREE_TYPE (inside_init)))
   10065              :         {
   10066           94 :           error_init (init_loc, "initializer element is not constant");
   10067           94 :           inside_init = error_mark_node;
   10068              :         }
   10069     13098834 :       else if (require_constant && !maybe_const)
   10070          219 :         pedwarn_init (init_loc, OPT_Wpedantic,
   10071              :                       "initializer element is not a constant expression");
   10072     13098615 :       else if (require_constexpr)
   10073          584 :         check_constexpr_init (init_loc, type, inside_init,
   10074              :                               int_const_expr, arith_const_expr);
   10075              : 
   10076              :       /* Added to enable additional -Wsuggest-attribute=format warnings.  */
   10077     13098929 :       if (TREE_CODE (TREE_TYPE (inside_init)) == POINTER_TYPE)
   10078       853355 :         inside_init = convert_for_assignment (init_loc, UNKNOWN_LOCATION,
   10079              :                                               type, inside_init, origtype,
   10080              :                                               (require_constant
   10081              :                                                ? ic_init_const
   10082              :                                                : ic_init), null_pointer_constant,
   10083              :                                               NULL_TREE, NULL_TREE, 0);
   10084     13098929 :       if (TREE_CODE (inside_init) == RAW_DATA_CST
   10085          252 :           && c_inhibit_evaluation_warnings == 0
   10086          252 :           && warn_conversion
   10087            1 :           && !TYPE_UNSIGNED (type)
   10088     13098930 :           && TYPE_PRECISION (type) == CHAR_BIT)
   10089          303 :         for (unsigned int i = 0;
   10090          304 :              i < (unsigned) RAW_DATA_LENGTH (inside_init); ++i)
   10091          303 :           if (RAW_DATA_SCHAR_ELT (inside_init, i) < 0)
   10092           10 :             warning_at (init_loc, OPT_Wconversion,
   10093              :                         "conversion from %qT to %qT changes value from "
   10094              :                         "%qd to %qd",
   10095              :                         integer_type_node, type,
   10096           10 :                         RAW_DATA_UCHAR_ELT (inside_init, i),
   10097           10 :                         RAW_DATA_SCHAR_ELT (inside_init, i));
   10098     13098929 :       return inside_init;
   10099              :     }
   10100              : 
   10101              :   /* Handle scalar types, including conversions.  */
   10102              : 
   10103      3121646 :   if (code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE
   10104       127985 :       || code == POINTER_TYPE || code == ENUMERAL_TYPE || code == BOOLEAN_TYPE
   10105        11090 :       || code == COMPLEX_TYPE || code == VECTOR_TYPE || code == NULLPTR_TYPE
   10106         9027 :       || code == BITINT_TYPE)
   10107              :     {
   10108      3121158 :       tree unconverted_init = inside_init;
   10109      3121158 :       if (TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE
   10110      3121158 :           && (TREE_CODE (init) == STRING_CST
   10111            2 :               || TREE_CODE (init) == COMPOUND_LITERAL_EXPR))
   10112         7315 :         inside_init = init = array_to_pointer_conversion (init_loc, init);
   10113      3121158 :       if (semantic_type)
   10114          436 :         inside_init = build1 (EXCESS_PRECISION_EXPR, semantic_type,
   10115              :                               inside_init);
   10116      3121158 :       inside_init
   10117      5663912 :         = convert_for_assignment (init_loc, UNKNOWN_LOCATION, type,
   10118              :                                   inside_init, origtype,
   10119              :                                   require_constant ? ic_init_const : ic_init,
   10120              :                                   null_pointer_constant, NULL_TREE, NULL_TREE,
   10121              :                                   0);
   10122              : 
   10123              :       /* Check to see if we have already given an error message.  */
   10124      3121158 :       if (inside_init == error_mark_node)
   10125              :         ;
   10126      3120698 :       else if (require_constant && !TREE_CONSTANT (inside_init))
   10127              :         {
   10128           36 :           error_init (init_loc, "initializer element is not constant");
   10129           36 :           inside_init = error_mark_node;
   10130              :         }
   10131      3120662 :       else if (require_constant
   10132      3698638 :                && !initializer_constant_valid_p (inside_init,
   10133       577976 :                                                  TREE_TYPE (inside_init)))
   10134              :         {
   10135           10 :           error_init (init_loc, "initializer element is not computable at "
   10136              :                       "load time");
   10137           10 :           inside_init = error_mark_node;
   10138              :         }
   10139      3120652 :       else if (require_constant && !maybe_const)
   10140            5 :         pedwarn_init (init_loc, OPT_Wpedantic,
   10141              :                       "initializer element is not a constant expression");
   10142      3120647 :       else if (require_constexpr)
   10143          328 :         check_constexpr_init (init_loc, type, unconverted_init,
   10144              :                               int_const_expr, arith_const_expr);
   10145              : 
   10146      3121158 :       return inside_init;
   10147              :     }
   10148              : 
   10149              :   /* Come here only for records and arrays.  */
   10150              : 
   10151          488 :   if (COMPLETE_TYPE_P (type) && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
   10152              :     {
   10153            0 :       error_init (init_loc,
   10154              :                   "variable-sized object may not be initialized except "
   10155              :                   "with an empty initializer");
   10156            0 :       return error_mark_node;
   10157              :     }
   10158              : 
   10159          488 :   error_init (init_loc, "invalid initializer");
   10160          488 :   return error_mark_node;
   10161              : }
   10162              : 
   10163              : /* Handle initializers that use braces.  */
   10164              : 
   10165              : /* Type of object we are accumulating a constructor for.
   10166              :    This type is always a RECORD_TYPE, UNION_TYPE or ARRAY_TYPE.  */
   10167              : static tree constructor_type;
   10168              : 
   10169              : /* For a RECORD_TYPE or UNION_TYPE, this is the chain of fields
   10170              :    left to fill.  */
   10171              : static tree constructor_fields;
   10172              : 
   10173              : /* For an ARRAY_TYPE, this is the specified index
   10174              :    at which to store the next element we get.  */
   10175              : static tree constructor_index;
   10176              : 
   10177              : /* For an ARRAY_TYPE, this is the maximum index.  */
   10178              : static tree constructor_max_index;
   10179              : 
   10180              : /* For a RECORD_TYPE, this is the first field not yet written out.  */
   10181              : static tree constructor_unfilled_fields;
   10182              : 
   10183              : /* For an ARRAY_TYPE, this is the index of the first element
   10184              :    not yet written out.  */
   10185              : static tree constructor_unfilled_index;
   10186              : 
   10187              : /* In a RECORD_TYPE, the byte index of the next consecutive field.
   10188              :    This is so we can generate gaps between fields, when appropriate.  */
   10189              : static tree constructor_bit_index;
   10190              : 
   10191              : /* If we are saving up the elements rather than allocating them,
   10192              :    this is the list of elements so far (in reverse order,
   10193              :    most recent first).  */
   10194              : static vec<constructor_elt, va_gc> *constructor_elements;
   10195              : 
   10196              : /* 1 if constructor should be incrementally stored into a constructor chain,
   10197              :    0 if all the elements should be kept in AVL tree.  */
   10198              : static int constructor_incremental;
   10199              : 
   10200              : /* 1 if so far this constructor's elements are all compile-time constants.  */
   10201              : static int constructor_constant;
   10202              : 
   10203              : /* 1 if so far this constructor's elements are all valid address constants.  */
   10204              : static int constructor_simple;
   10205              : 
   10206              : /* 1 if this constructor has an element that cannot be part of a
   10207              :    constant expression.  */
   10208              : static int constructor_nonconst;
   10209              : 
   10210              : /* 1 if this constructor is erroneous so far.  */
   10211              : static int constructor_erroneous;
   10212              : 
   10213              : /* 1 if this constructor is the universal zero initializer { 0 }.  */
   10214              : static int constructor_zeroinit;
   10215              : 
   10216              : /* 1 if this constructor should have padding bits zeroed (C23 {}.  */
   10217              : static bool constructor_zero_padding_bits;
   10218              : 
   10219              : /* 1 if this constructor is a braced scalar initializer (further nested levels
   10220              :    of braces are an error).  */
   10221              : static bool constructor_braced_scalar;
   10222              : 
   10223              : /* Structure for managing pending initializer elements, organized as an
   10224              :    AVL tree.  */
   10225              : 
   10226              : struct init_node
   10227              : {
   10228              :   struct init_node *left, *right;
   10229              :   struct init_node *parent;
   10230              :   int balance;
   10231              :   tree purpose;
   10232              :   tree value;
   10233              :   tree origtype;
   10234              : };
   10235              : 
   10236              : /* Tree of pending elements at this constructor level.
   10237              :    These are elements encountered out of order
   10238              :    which belong at places we haven't reached yet in actually
   10239              :    writing the output.
   10240              :    Will never hold tree nodes across GC runs.  */
   10241              : static struct init_node *constructor_pending_elts;
   10242              : 
   10243              : /* The SPELLING_DEPTH of this constructor.  */
   10244              : static int constructor_depth;
   10245              : 
   10246              : /* DECL node for which an initializer is being read.
   10247              :    0 means we are reading a constructor expression
   10248              :    such as (struct foo) {...}.  */
   10249              : static tree constructor_decl;
   10250              : 
   10251              : /* Nonzero if there were any member designators in this initializer.  */
   10252              : static int constructor_designated;
   10253              : 
   10254              : /* Nesting depth of designator list.  */
   10255              : static int designator_depth;
   10256              : 
   10257              : /* Nonzero if there were diagnosed errors in this designator list.  */
   10258              : static int designator_erroneous;
   10259              : 
   10260              : 
   10261              : /* This stack has a level for each implicit or explicit level of
   10262              :    structuring in the initializer, including the outermost one.  It
   10263              :    saves the values of most of the variables above.  */
   10264              : 
   10265              : struct constructor_range_stack;
   10266              : 
   10267              : struct constructor_stack
   10268              : {
   10269              :   struct constructor_stack *next;
   10270              :   tree type;
   10271              :   tree fields;
   10272              :   tree index;
   10273              :   tree max_index;
   10274              :   tree unfilled_index;
   10275              :   tree unfilled_fields;
   10276              :   tree bit_index;
   10277              :   vec<constructor_elt, va_gc> *elements;
   10278              :   struct init_node *pending_elts;
   10279              :   int offset;
   10280              :   int depth;
   10281              :   /* If value nonzero, this value should replace the entire
   10282              :      constructor at this level.  */
   10283              :   struct c_expr replacement_value;
   10284              :   struct constructor_range_stack *range_stack;
   10285              :   char constant;
   10286              :   char simple;
   10287              :   char nonconst;
   10288              :   char implicit;
   10289              :   char erroneous;
   10290              :   char outer;
   10291              :   char incremental;
   10292              :   char designated;
   10293              :   bool zero_padding_bits;
   10294              :   bool braced_scalar;
   10295              :   int designator_depth;
   10296              : };
   10297              : 
   10298              : static struct constructor_stack *constructor_stack;
   10299              : 
   10300              : /* This stack represents designators from some range designator up to
   10301              :    the last designator in the list.  */
   10302              : 
   10303              : struct constructor_range_stack
   10304              : {
   10305              :   struct constructor_range_stack *next, *prev;
   10306              :   struct constructor_stack *stack;
   10307              :   tree range_start;
   10308              :   tree index;
   10309              :   tree range_end;
   10310              :   tree fields;
   10311              : };
   10312              : 
   10313              : static struct constructor_range_stack *constructor_range_stack;
   10314              : 
   10315              : /* This stack records separate initializers that are nested.
   10316              :    Nested initializers can't happen in ANSI C, but GNU C allows them
   10317              :    in cases like { ... (struct foo) { ... } ... }.  */
   10318              : 
   10319              : struct initializer_stack
   10320              : {
   10321              :   struct initializer_stack *next;
   10322              :   tree decl;
   10323              :   struct constructor_stack *constructor_stack;
   10324              :   struct constructor_range_stack *constructor_range_stack;
   10325              :   vec<constructor_elt, va_gc> *elements;
   10326              :   struct spelling *spelling;
   10327              :   struct spelling *spelling_base;
   10328              :   int spelling_size;
   10329              :   char require_constant_value;
   10330              :   char require_constant_elements;
   10331              :   char require_constexpr_value;
   10332              :   char designated;
   10333              :   rich_location *missing_brace_richloc;
   10334              : };
   10335              : 
   10336              : static struct initializer_stack *initializer_stack;
   10337              : 
   10338              : /* Prepare to parse and output the initializer for variable DECL.  */
   10339              : 
   10340              : void
   10341      7254989 : start_init (tree decl, tree asmspec_tree ATTRIBUTE_UNUSED,
   10342              :             bool init_require_constant, bool init_require_constexpr,
   10343              :             rich_location *richloc)
   10344              : {
   10345      7254989 :   const char *locus;
   10346      7254989 :   struct initializer_stack *p = XNEW (struct initializer_stack);
   10347              : 
   10348      7254989 :   p->decl = constructor_decl;
   10349      7254989 :   p->require_constant_value = require_constant_value;
   10350      7254989 :   p->require_constant_elements = require_constant_elements;
   10351      7254989 :   p->require_constexpr_value = require_constexpr_value;
   10352      7254989 :   p->constructor_stack = constructor_stack;
   10353      7254989 :   p->constructor_range_stack = constructor_range_stack;
   10354      7254989 :   p->elements = constructor_elements;
   10355      7254989 :   p->spelling = spelling;
   10356      7254989 :   p->spelling_base = spelling_base;
   10357      7254989 :   p->spelling_size = spelling_size;
   10358      7254989 :   p->next = initializer_stack;
   10359      7254989 :   p->missing_brace_richloc = richloc;
   10360      7254989 :   p->designated = constructor_designated;
   10361      7254989 :   initializer_stack = p;
   10362              : 
   10363      7254989 :   constructor_decl = decl;
   10364      7254989 :   constructor_designated = 0;
   10365              : 
   10366      7254989 :   require_constant_value = init_require_constant;
   10367      7254989 :   require_constexpr_value = init_require_constexpr;
   10368      7254989 :   if (decl != NULL_TREE && decl != error_mark_node)
   10369              :     {
   10370      6335311 :       require_constant_elements
   10371      6158709 :         = ((init_require_constant || (pedantic && !flag_isoc99))
   10372              :            /* For a scalar, you can always use any value to initialize,
   10373              :               even within braces.  */
   10374      6347259 :            && AGGREGATE_TYPE_P (TREE_TYPE (decl)));
   10375      6335311 :       locus = identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl)));
   10376              :     }
   10377              :   else
   10378              :     {
   10379       919678 :       require_constant_elements = false;
   10380       919678 :       locus = _("(anonymous)");
   10381              :     }
   10382              : 
   10383      7254989 :   constructor_stack = 0;
   10384      7254989 :   constructor_range_stack = 0;
   10385              : 
   10386      7254989 :   found_missing_braces = 0;
   10387              : 
   10388      7254989 :   spelling_base = 0;
   10389      7254989 :   spelling_size = 0;
   10390      7254989 :   RESTORE_SPELLING_DEPTH (0);
   10391              : 
   10392      7254989 :   if (locus)
   10393      7254989 :     push_string (locus);
   10394      7254989 : }
   10395              : 
   10396              : void
   10397      7254987 : finish_init (void)
   10398              : {
   10399      7254987 :   struct initializer_stack *p = initializer_stack;
   10400              : 
   10401              :   /* Free the whole constructor stack of this initializer.  */
   10402      7254987 :   while (constructor_stack)
   10403              :     {
   10404            0 :       struct constructor_stack *q = constructor_stack;
   10405            0 :       constructor_stack = q->next;
   10406            0 :       XDELETE (q);
   10407              :     }
   10408              : 
   10409      7254987 :   gcc_assert (!constructor_range_stack);
   10410              : 
   10411              :   /* Pop back to the data of the outer initializer (if any).  */
   10412      7254987 :   XDELETE (spelling_base);
   10413              : 
   10414      7254987 :   constructor_decl = p->decl;
   10415      7254987 :   require_constant_value = p->require_constant_value;
   10416      7254987 :   require_constant_elements = p->require_constant_elements;
   10417      7254987 :   require_constexpr_value = p->require_constexpr_value;
   10418      7254987 :   constructor_stack = p->constructor_stack;
   10419      7254987 :   constructor_designated = p->designated;
   10420      7254987 :   constructor_range_stack = p->constructor_range_stack;
   10421      7254987 :   constructor_elements = p->elements;
   10422      7254987 :   spelling = p->spelling;
   10423      7254987 :   spelling_base = p->spelling_base;
   10424      7254987 :   spelling_size = p->spelling_size;
   10425      7254987 :   initializer_stack = p->next;
   10426      7254987 :   XDELETE (p);
   10427      7254987 : }
   10428              : 
   10429              : /* Call here when we see the initializer is surrounded by braces.
   10430              :    This is instead of a call to push_init_level;
   10431              :    it is matched by a call to pop_init_level.
   10432              : 
   10433              :    TYPE is the type to initialize, for a constructor expression.
   10434              :    For an initializer for a decl, TYPE is zero.  */
   10435              : 
   10436              : void
   10437      1023097 : really_start_incremental_init (tree type)
   10438              : {
   10439      1023097 :   struct constructor_stack *p = XNEW (struct constructor_stack);
   10440              : 
   10441      1023097 :   if (type == NULL_TREE)
   10442       105376 :     type = TREE_TYPE (constructor_decl);
   10443              : 
   10444      1023097 :   if (VECTOR_TYPE_P (type)
   10445      1023097 :       && TYPE_VECTOR_OPAQUE (type))
   10446            0 :     error ("opaque vector types cannot be initialized");
   10447              : 
   10448      1023097 :   p->type = constructor_type;
   10449      1023097 :   p->fields = constructor_fields;
   10450      1023097 :   p->index = constructor_index;
   10451      1023097 :   p->max_index = constructor_max_index;
   10452      1023097 :   p->unfilled_index = constructor_unfilled_index;
   10453      1023097 :   p->unfilled_fields = constructor_unfilled_fields;
   10454      1023097 :   p->bit_index = constructor_bit_index;
   10455      1023097 :   p->elements = constructor_elements;
   10456      1023097 :   p->constant = constructor_constant;
   10457      1023097 :   p->simple = constructor_simple;
   10458      1023097 :   p->nonconst = constructor_nonconst;
   10459      1023097 :   p->erroneous = constructor_erroneous;
   10460      1023097 :   p->pending_elts = constructor_pending_elts;
   10461      1023097 :   p->depth = constructor_depth;
   10462      1023097 :   p->replacement_value.value = 0;
   10463      1023097 :   p->replacement_value.original_code = ERROR_MARK;
   10464      1023097 :   p->replacement_value.original_type = NULL;
   10465      1023097 :   p->implicit = 0;
   10466      1023097 :   p->range_stack = 0;
   10467      1023097 :   p->outer = 0;
   10468      1023097 :   p->incremental = constructor_incremental;
   10469      1023097 :   p->designated = constructor_designated;
   10470      1023097 :   p->zero_padding_bits = constructor_zero_padding_bits;
   10471      1023097 :   p->braced_scalar = constructor_braced_scalar;
   10472      1023097 :   p->designator_depth = designator_depth;
   10473      1023097 :   p->next = 0;
   10474      1023097 :   constructor_stack = p;
   10475              : 
   10476      1023097 :   constructor_constant = 1;
   10477      1023097 :   constructor_simple = 1;
   10478      1023097 :   constructor_nonconst = 0;
   10479      1023097 :   constructor_depth = SPELLING_DEPTH ();
   10480      1023097 :   constructor_elements = NULL;
   10481      1023097 :   constructor_pending_elts = 0;
   10482      1023097 :   constructor_type = type;
   10483      1023097 :   constructor_incremental = 1;
   10484      1023097 :   constructor_designated = 0;
   10485      1023097 :   constructor_zero_padding_bits = false;
   10486      1023097 :   constructor_zeroinit = 1;
   10487      1023097 :   constructor_braced_scalar = false;
   10488      1023097 :   designator_depth = 0;
   10489      1023097 :   designator_erroneous = 0;
   10490              : 
   10491      1023097 :   if (RECORD_OR_UNION_TYPE_P (constructor_type))
   10492              :     {
   10493        81367 :       constructor_fields = TYPE_FIELDS (constructor_type);
   10494              :       /* Skip any nameless bit fields at the beginning.  */
   10495        81367 :       while (constructor_fields != NULL_TREE
   10496        81395 :              && DECL_UNNAMED_BIT_FIELD (constructor_fields))
   10497           28 :         constructor_fields = DECL_CHAIN (constructor_fields);
   10498              : 
   10499        81367 :       constructor_unfilled_fields = constructor_fields;
   10500        81367 :       constructor_bit_index = bitsize_zero_node;
   10501              :     }
   10502       941730 :   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   10503              :     {
   10504        17850 :       if (TYPE_DOMAIN (constructor_type))
   10505              :         {
   10506         9389 :           constructor_max_index
   10507         9389 :             = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
   10508              : 
   10509              :           /* Detect non-empty initializations of zero-length arrays.  */
   10510         9389 :           if (constructor_max_index == NULL_TREE
   10511         9389 :               && TYPE_SIZE (constructor_type))
   10512          205 :             constructor_max_index = integer_minus_one_node;
   10513              : 
   10514              :           /* constructor_max_index needs to be an INTEGER_CST.  Attempts
   10515              :              to initialize VLAs with a nonempty initializer will cause a
   10516              :              proper error; avoid tree checking errors as well by setting a
   10517              :              safe value.  */
   10518         9389 :           if (constructor_max_index
   10519         9389 :               && TREE_CODE (constructor_max_index) != INTEGER_CST)
   10520           73 :             constructor_max_index = integer_minus_one_node;
   10521              : 
   10522         9389 :           constructor_index
   10523         9389 :             = convert (bitsizetype,
   10524         9389 :                        TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
   10525              :         }
   10526              :       else
   10527              :         {
   10528         8461 :           constructor_index = bitsize_zero_node;
   10529         8461 :           constructor_max_index = NULL_TREE;
   10530              :         }
   10531              : 
   10532        17850 :       constructor_unfilled_index = constructor_index;
   10533              :     }
   10534       923880 :   else if (gnu_vector_type_p (constructor_type))
   10535              :     {
   10536              :       /* Vectors are like simple fixed-size arrays.  */
   10537      1846648 :       constructor_max_index =
   10538       923324 :         bitsize_int (TYPE_VECTOR_SUBPARTS (constructor_type) - 1);
   10539       923324 :       constructor_index = bitsize_zero_node;
   10540       923324 :       constructor_unfilled_index = constructor_index;
   10541              :     }
   10542              :   else
   10543              :     {
   10544              :       /* Handle the case of int x = {5}; */
   10545          556 :       constructor_fields = constructor_type;
   10546          556 :       constructor_unfilled_fields = constructor_type;
   10547          556 :       constructor_braced_scalar = true;
   10548              :     }
   10549      1023097 : }
   10550              : 
   10551              : extern location_t last_init_list_comma;
   10552              : 
   10553              : /* Called when we see an open brace for a nested initializer.  Finish
   10554              :    off any pending levels with implicit braces.  */
   10555              : void
   10556       340559 : finish_implicit_inits (location_t loc, struct obstack *braced_init_obstack)
   10557              : {
   10558       340561 :   while (constructor_stack->implicit)
   10559              :     {
   10560          304 :       if (RECORD_OR_UNION_TYPE_P (constructor_type)
   10561          140 :           && constructor_fields == NULL_TREE)
   10562            0 :         process_init_element (input_location,
   10563              :                               pop_init_level (loc, 1, braced_init_obstack,
   10564              :                                               last_init_list_comma),
   10565              :                               true, braced_init_obstack);
   10566          304 :       else if (TREE_CODE (constructor_type) == ARRAY_TYPE
   10567          164 :                && constructor_max_index
   10568          468 :                && tree_int_cst_lt (constructor_max_index,
   10569              :                                    constructor_index))
   10570            2 :         process_init_element (input_location,
   10571              :                               pop_init_level (loc, 1, braced_init_obstack,
   10572              :                                               last_init_list_comma),
   10573              :                               true, braced_init_obstack);
   10574              :       else
   10575              :         break;
   10576              :     }
   10577       340559 : }
   10578              : 
   10579              : /* Push down into a subobject, for initialization.
   10580              :    If this is for an explicit set of braces, IMPLICIT is 0.
   10581              :    If it is because the next element belongs at a lower level,
   10582              :    IMPLICIT is 1 (or 2 if the push is because of designator list).  */
   10583              : 
   10584              : void
   10585      1043225 : push_init_level (location_t loc, int implicit,
   10586              :                  struct obstack *braced_init_obstack)
   10587              : {
   10588      1043225 :   struct constructor_stack *p;
   10589      1043225 :   tree value = NULL_TREE;
   10590              : 
   10591              :   /* Unless this is an explicit brace, we need to preserve previous
   10592              :      content if any.  */
   10593      1043225 :   if (implicit)
   10594              :     {
   10595       703608 :       if (RECORD_OR_UNION_TYPE_P (constructor_type) && constructor_fields)
   10596          796 :         value = find_init_member (constructor_fields, braced_init_obstack);
   10597       702812 :       else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   10598       702812 :         value = find_init_member (constructor_index, braced_init_obstack);
   10599              :     }
   10600              : 
   10601      1043225 :   p = XNEW (struct constructor_stack);
   10602      1043225 :   p->type = constructor_type;
   10603      1043225 :   p->fields = constructor_fields;
   10604      1043225 :   p->index = constructor_index;
   10605      1043225 :   p->max_index = constructor_max_index;
   10606      1043225 :   p->unfilled_index = constructor_unfilled_index;
   10607      1043225 :   p->unfilled_fields = constructor_unfilled_fields;
   10608      1043225 :   p->bit_index = constructor_bit_index;
   10609      1043225 :   p->elements = constructor_elements;
   10610      1043225 :   p->constant = constructor_constant;
   10611      1043225 :   p->simple = constructor_simple;
   10612      1043225 :   p->nonconst = constructor_nonconst;
   10613      1043225 :   p->erroneous = constructor_erroneous;
   10614      1043225 :   p->pending_elts = constructor_pending_elts;
   10615      1043225 :   p->depth = constructor_depth;
   10616      1043225 :   p->replacement_value.value = NULL_TREE;
   10617      1043225 :   p->replacement_value.original_code = ERROR_MARK;
   10618      1043225 :   p->replacement_value.original_type = NULL;
   10619      1043225 :   p->implicit = implicit;
   10620      1043225 :   p->outer = 0;
   10621      1043225 :   p->incremental = constructor_incremental;
   10622      1043225 :   p->designated = constructor_designated;
   10623      1043225 :   p->zero_padding_bits = constructor_zero_padding_bits;
   10624      1043225 :   p->braced_scalar = constructor_braced_scalar;
   10625      1043225 :   p->designator_depth = designator_depth;
   10626      1043225 :   p->next = constructor_stack;
   10627      1043225 :   p->range_stack = 0;
   10628      1043225 :   constructor_stack = p;
   10629              : 
   10630      1043225 :   constructor_constant = 1;
   10631      1043225 :   constructor_simple = 1;
   10632      1043225 :   constructor_nonconst = 0;
   10633      1043225 :   constructor_depth = SPELLING_DEPTH ();
   10634      1043225 :   constructor_elements = NULL;
   10635      1043225 :   constructor_incremental = 1;
   10636              :   /* If the upper initializer is designated, then mark this as
   10637              :      designated too to prevent bogus warnings.  */
   10638      1043225 :   constructor_designated = p->designated;
   10639              :   /* If the upper initializer has padding bits zeroed, that includes
   10640              :      all nested initializers as well.  */
   10641      1043225 :   constructor_zero_padding_bits = p->zero_padding_bits;
   10642      1043225 :   constructor_braced_scalar = false;
   10643      1043225 :   constructor_pending_elts = 0;
   10644      1043225 :   if (!implicit)
   10645              :     {
   10646       339617 :       p->range_stack = constructor_range_stack;
   10647       339617 :       constructor_range_stack = 0;
   10648       339617 :       designator_depth = 0;
   10649       339617 :       designator_erroneous = 0;
   10650              :     }
   10651              : 
   10652              :   /* Don't die if an entire brace-pair level is superfluous
   10653              :      in the containing level.  */
   10654      1043225 :   if (constructor_type == NULL_TREE)
   10655              :     ;
   10656      1043225 :   else if (RECORD_OR_UNION_TYPE_P (constructor_type))
   10657              :     {
   10658              :       /* Don't die if there are extra init elts at the end.  */
   10659       158853 :       if (constructor_fields == NULL_TREE)
   10660           51 :         constructor_type = NULL_TREE;
   10661              :       else
   10662              :         {
   10663       158802 :           constructor_type = TREE_TYPE (constructor_fields);
   10664       158802 :           push_member_name (constructor_fields);
   10665       158802 :           constructor_depth++;
   10666              :         }
   10667              :     }
   10668       884372 :   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   10669              :     {
   10670       884321 :       constructor_type = TREE_TYPE (constructor_type);
   10671       884321 :       push_array_bounds (tree_to_uhwi (constructor_index));
   10672       884321 :       constructor_depth++;
   10673              :     }
   10674              : 
   10675      1043225 :   if (constructor_type == NULL_TREE)
   10676              :     {
   10677           51 :       error_init (loc, "extra brace group at end of initializer");
   10678           51 :       constructor_fields = NULL_TREE;
   10679           51 :       constructor_unfilled_fields = NULL_TREE;
   10680           51 :       return;
   10681              :     }
   10682              : 
   10683      1043174 :   if (value && TREE_CODE (value) == CONSTRUCTOR)
   10684              :     {
   10685          360 :       constructor_constant = TREE_CONSTANT (value);
   10686          360 :       constructor_simple = TREE_STATIC (value);
   10687          360 :       constructor_nonconst = CONSTRUCTOR_NON_CONST (value);
   10688          360 :       constructor_elements = CONSTRUCTOR_ELTS (value);
   10689          360 :       constructor_zero_padding_bits |= CONSTRUCTOR_ZERO_PADDING_BITS (value);
   10690          360 :       if (!vec_safe_is_empty (constructor_elements)
   10691          340 :           && (TREE_CODE (constructor_type) == RECORD_TYPE
   10692          340 :               || TREE_CODE (constructor_type) == ARRAY_TYPE))
   10693          294 :         set_nonincremental_init (braced_init_obstack);
   10694              :     }
   10695              : 
   10696      1043174 :   if (implicit == 1)
   10697              :     {
   10698       702666 :       found_missing_braces = 1;
   10699       702666 :       if (initializer_stack->missing_brace_richloc)
   10700       702666 :         initializer_stack->missing_brace_richloc->add_fixit_insert_before
   10701       702666 :           (loc, "{");
   10702              :     }
   10703              : 
   10704      1043174 :   if (RECORD_OR_UNION_TYPE_P (constructor_type))
   10705              :     {
   10706       879726 :       constructor_fields = TYPE_FIELDS (constructor_type);
   10707              :       /* Skip any nameless bit fields at the beginning.  */
   10708       879726 :       while (constructor_fields != NULL_TREE
   10709       879790 :              && DECL_UNNAMED_BIT_FIELD (constructor_fields))
   10710           64 :         constructor_fields = DECL_CHAIN (constructor_fields);
   10711              : 
   10712       879726 :       constructor_unfilled_fields = constructor_fields;
   10713       879726 :       constructor_bit_index = bitsize_zero_node;
   10714              :     }
   10715       163448 :   else if (gnu_vector_type_p (constructor_type))
   10716              :     {
   10717              :       /* Vectors are like simple fixed-size arrays.  */
   10718         9602 :       constructor_max_index =
   10719         4801 :         bitsize_int (TYPE_VECTOR_SUBPARTS (constructor_type) - 1);
   10720         4801 :       constructor_index = bitsize_int (0);
   10721         4801 :       constructor_unfilled_index = constructor_index;
   10722              :     }
   10723       158647 :   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   10724              :     {
   10725       158567 :       if (TYPE_DOMAIN (constructor_type))
   10726              :         {
   10727       158567 :           constructor_max_index
   10728       158567 :             = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
   10729              : 
   10730              :           /* Detect non-empty initializations of zero-length arrays.  */
   10731       158567 :           if (constructor_max_index == NULL_TREE
   10732       158567 :               && TYPE_SIZE (constructor_type))
   10733          135 :             constructor_max_index = integer_minus_one_node;
   10734              : 
   10735              :           /* constructor_max_index needs to be an INTEGER_CST.  Attempts
   10736              :              to initialize VLAs will cause a proper error; avoid tree
   10737              :              checking errors as well by setting a safe value.  */
   10738       158567 :           if (constructor_max_index
   10739       158297 :               && TREE_CODE (constructor_max_index) != INTEGER_CST)
   10740            2 :             constructor_max_index = integer_minus_one_node;
   10741              : 
   10742       158567 :           constructor_index
   10743       158567 :             = convert (bitsizetype,
   10744       158567 :                        TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
   10745              :         }
   10746              :       else
   10747            0 :         constructor_index = bitsize_zero_node;
   10748              : 
   10749       158567 :       constructor_unfilled_index = constructor_index;
   10750       158567 :       if (value && TREE_CODE (value) == STRING_CST)
   10751              :         {
   10752              :           /* We need to split the char/wchar array into individual
   10753              :              characters, so that we don't have to special case it
   10754              :              everywhere.  */
   10755            7 :           set_nonincremental_init_from_string (value, braced_init_obstack);
   10756              :         }
   10757              :     }
   10758              :   else
   10759              :     {
   10760           80 :       if (constructor_type != error_mark_node)
   10761              :         {
   10762           51 :           if (p->braced_scalar)
   10763           22 :             permerror_init (input_location, 0,
   10764              :                             "braces around scalar initializer");
   10765              :           else
   10766           29 :             warning_init (input_location, 0,
   10767              :                           "braces around scalar initializer");
   10768           51 :           constructor_braced_scalar = true;
   10769              :         }
   10770           80 :       constructor_fields = constructor_type;
   10771           80 :       constructor_unfilled_fields = constructor_type;
   10772              :     }
   10773              : }
   10774              : 
   10775              : /* At the end of an implicit or explicit brace level,
   10776              :    finish up that level of constructor.  If a single expression
   10777              :    with redundant braces initialized that level, return the
   10778              :    c_expr structure for that expression.  Otherwise, the original_code
   10779              :    element is set to ERROR_MARK.
   10780              :    If we were outputting the elements as they are read, return 0 as the value
   10781              :    from inner levels (process_init_element ignores that),
   10782              :    but return error_mark_node as the value from the outermost level
   10783              :    (that's what we want to put in DECL_INITIAL).
   10784              :    Otherwise, return a CONSTRUCTOR expression as the value.  */
   10785              : 
   10786              : struct c_expr
   10787      2066322 : pop_init_level (location_t loc, int implicit,
   10788              :                 struct obstack *braced_init_obstack,
   10789              :                 location_t insert_before)
   10790              : {
   10791      2066322 :   struct constructor_stack *p;
   10792      2066322 :   struct c_expr ret;
   10793      2066322 :   ret.value = NULL_TREE;
   10794      2066322 :   ret.original_code = ERROR_MARK;
   10795      2066322 :   ret.original_type = NULL;
   10796      2066322 :   ret.m_decimal = 0;
   10797              : 
   10798      2066322 :   if (implicit == 0)
   10799              :     {
   10800              :       /* When we come to an explicit close brace,
   10801              :          pop any inner levels that didn't have explicit braces.  */
   10802      1363633 :       while (constructor_stack->implicit)
   10803          919 :         process_init_element (input_location,
   10804              :                               pop_init_level (loc, 1, braced_init_obstack,
   10805              :                                               insert_before),
   10806              :                               true, braced_init_obstack);
   10807      1362714 :       gcc_assert (!constructor_range_stack);
   10808              :     }
   10809              :   else
   10810       703608 :     if (initializer_stack->missing_brace_richloc)
   10811       703608 :       initializer_stack->missing_brace_richloc->add_fixit_insert_before
   10812       703608 :         (insert_before, "}");
   10813              : 
   10814              :   /* Now output all pending elements.  */
   10815      2066322 :   constructor_incremental = 1;
   10816      2066322 :   output_pending_init_elements (1, braced_init_obstack);
   10817              : 
   10818      2066322 :   p = constructor_stack;
   10819              : 
   10820              :   /* Error for initializing a flexible array member, or a zero-length
   10821              :      array member in an inappropriate context.  */
   10822      2066271 :   if (constructor_type && constructor_fields
   10823       159374 :       && TREE_CODE (constructor_type) == ARRAY_TYPE
   10824       152623 :       && TYPE_DOMAIN (constructor_type)
   10825      2218937 :       && !TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type)))
   10826              :     {
   10827              :       /* Silently discard empty initializations.  The parser will
   10828              :          already have pedwarned for empty brackets for C17 and earlier.  */
   10829          300 :       if (integer_zerop (constructor_unfilled_index))
   10830           84 :         constructor_type = NULL_TREE;
   10831          300 :       if (constructor_type || flag_isoc23)
   10832              :         {
   10833          296 :           gcc_assert (!constructor_type || !TYPE_SIZE (constructor_type));
   10834              : 
   10835          296 :           if (constructor_depth <= 2)
   10836          249 :             pedwarn_init (loc, OPT_Wpedantic,
   10837              :                           "initialization of a flexible array member");
   10838           47 :           else if (constructor_type)
   10839           33 :             error_init (loc, "initialization of flexible array member "
   10840              :                              "in a nested context");
   10841              :           else
   10842           14 :             pedwarn_init (loc, OPT_Wpedantic,
   10843              :                           "initialization of flexible array member "
   10844              :                           "in a nested context");
   10845              : 
   10846              :           /* We have already issued an error message for the existence
   10847              :              of a flexible array member not at the end of the structure.
   10848              :              Discard the initializer so that we do not die later.  */
   10849          296 :           if (constructor_type
   10850          216 :               && DECL_CHAIN (constructor_fields) != NULL_TREE
   10851          302 :               && (!p->type || TREE_CODE (p->type) != UNION_TYPE))
   10852            0 :             constructor_type = NULL_TREE;
   10853              :         }
   10854              :     }
   10855              : 
   10856      2066322 :   switch (vec_safe_length (constructor_elements))
   10857              :     {
   10858         4605 :     case 0:
   10859              :       /* Initialization with { } counts as zeroinit.  */
   10860         4605 :       constructor_zeroinit = 1;
   10861         4605 :       break;
   10862       915093 :     case 1:
   10863              :       /* This might be zeroinit as well.  */
   10864       915093 :       if (integer_zerop ((*constructor_elements)[0].value))
   10865         2038 :         constructor_zeroinit = 1;
   10866              :       break;
   10867      1146624 :     default:
   10868              :       /* If the constructor has more than one element, it can't be { 0 }.  */
   10869      1146624 :       constructor_zeroinit = 0;
   10870      1146624 :       break;
   10871              :     }
   10872              : 
   10873              :   /* Warn when some structs are initialized with direct aggregation.  */
   10874      2066322 :   if (!implicit && found_missing_braces && warn_missing_braces
   10875           37 :       && !constructor_zeroinit)
   10876              :     {
   10877           18 :       gcc_assert (initializer_stack->missing_brace_richloc);
   10878           18 :       warning_at (initializer_stack->missing_brace_richloc,
   10879           18 :                   OPT_Wmissing_braces,
   10880              :                   "missing braces around initializer");
   10881              :     }
   10882              : 
   10883              :   /* Warn when some struct elements are implicitly initialized to zero.  */
   10884      2066322 :   if (warn_missing_field_initializers
   10885       425443 :       && constructor_type
   10886       425415 :       && TREE_CODE (constructor_type) == RECORD_TYPE
   10887       193395 :       && constructor_unfilled_fields)
   10888              :     {
   10889              :         /* Do not warn for flexible array members or zero-length arrays.  */
   10890           43 :         while (constructor_unfilled_fields
   10891           43 :                && (!DECL_SIZE (constructor_unfilled_fields)
   10892           43 :                    || integer_zerop (DECL_SIZE (constructor_unfilled_fields))))
   10893            0 :           constructor_unfilled_fields = DECL_CHAIN (constructor_unfilled_fields);
   10894              : 
   10895           43 :         if (constructor_unfilled_fields
   10896              :             /* Do not warn if this level of the initializer uses member
   10897              :                designators; it is likely to be deliberate.  */
   10898           43 :             && !constructor_designated
   10899              :             /* Do not warn about initializing with { 0 } or with { }.  */
   10900           24 :             && !constructor_zeroinit)
   10901              :           {
   10902           10 :             if (warning_at (input_location, OPT_Wmissing_field_initializers,
   10903              :                             "missing initializer for field %qD of %qT",
   10904              :                             constructor_unfilled_fields,
   10905              :                             constructor_type))
   10906           10 :               inform (DECL_SOURCE_LOCATION (constructor_unfilled_fields),
   10907              :                       "%qD declared here", constructor_unfilled_fields);
   10908              :           }
   10909              :     }
   10910              : 
   10911              :   /* Pad out the end of the structure.  */
   10912      2066322 :   if (p->replacement_value.value)
   10913              :     /* If this closes a superfluous brace pair,
   10914              :        just pass out the element between them.  */
   10915          138 :     ret = p->replacement_value;
   10916      2066184 :   else if (constructor_type == NULL_TREE)
   10917              :     ;
   10918      2066057 :   else if (!RECORD_OR_UNION_TYPE_P (constructor_type)
   10919      2066057 :            && TREE_CODE (constructor_type) != ARRAY_TYPE
   10920      2066057 :            && !gnu_vector_type_p (constructor_type))
   10921              :     {
   10922              :       /* A nonincremental scalar initializer--just return
   10923              :          the element, after verifying there is just one.
   10924              :          Empty scalar initializers are supported in C23.  */
   10925          636 :       if (vec_safe_is_empty (constructor_elements))
   10926              :         {
   10927          201 :           if (constructor_erroneous || constructor_type == error_mark_node)
   10928           85 :             ret.value = error_mark_node;
   10929          116 :           else if (TREE_CODE (constructor_type) == FUNCTION_TYPE)
   10930              :             {
   10931            2 :               error_init (loc, "invalid initializer");
   10932            2 :               ret.value = error_mark_node;
   10933              :             }
   10934          114 :           else if (TREE_CODE (constructor_type) == POINTER_TYPE)
   10935              :             /* Ensure this is a null pointer constant in the case of a
   10936              :                'constexpr' object initialized with {}.  */
   10937           33 :             ret.value = build_zero_cst (ptr_type_node);
   10938              :           else
   10939           81 :             ret.value = build_zero_cst (constructor_type);
   10940              :         }
   10941          435 :       else if (vec_safe_length (constructor_elements) != 1)
   10942              :         {
   10943            0 :           error_init (loc, "extra elements in scalar initializer");
   10944            0 :           ret.value = (*constructor_elements)[0].value;
   10945              :         }
   10946              :       else
   10947          435 :         ret.value = (*constructor_elements)[0].value;
   10948              :     }
   10949              :   else
   10950              :     {
   10951      2065421 :       if (constructor_erroneous)
   10952          315 :         ret.value = error_mark_node;
   10953              :       else
   10954              :         {
   10955      2065106 :           ret.value = build_constructor (constructor_type,
   10956              :                                          constructor_elements);
   10957      2065106 :           if (constructor_constant)
   10958      1736317 :             TREE_CONSTANT (ret.value) = 1;
   10959      2065106 :           if (constructor_constant && constructor_simple)
   10960      1736278 :             TREE_STATIC (ret.value) = 1;
   10961      2065106 :           if (constructor_nonconst)
   10962          672 :             CONSTRUCTOR_NON_CONST (ret.value) = 1;
   10963      2065106 :           if (constructor_zero_padding_bits)
   10964           20 :             CONSTRUCTOR_ZERO_PADDING_BITS (ret.value) = 1;
   10965              :         }
   10966              :     }
   10967              : 
   10968      2066322 :   if (ret.value && TREE_CODE (ret.value) != CONSTRUCTOR)
   10969              :     {
   10970         1089 :       if (constructor_nonconst)
   10971           15 :         ret.original_code = C_MAYBE_CONST_EXPR;
   10972         1074 :       else if (ret.original_code == C_MAYBE_CONST_EXPR)
   10973            0 :         ret.original_code = ERROR_MARK;
   10974              :     }
   10975              : 
   10976      2066322 :   constructor_type = p->type;
   10977      2066322 :   constructor_fields = p->fields;
   10978      2066322 :   constructor_index = p->index;
   10979      2066322 :   constructor_max_index = p->max_index;
   10980      2066322 :   constructor_unfilled_index = p->unfilled_index;
   10981      2066322 :   constructor_unfilled_fields = p->unfilled_fields;
   10982      2066322 :   constructor_bit_index = p->bit_index;
   10983      2066322 :   constructor_elements = p->elements;
   10984      2066322 :   constructor_constant = p->constant;
   10985      2066322 :   constructor_simple = p->simple;
   10986      2066322 :   constructor_nonconst = p->nonconst;
   10987      2066322 :   constructor_erroneous = p->erroneous;
   10988      2066322 :   constructor_incremental = p->incremental;
   10989      2066322 :   constructor_designated = p->designated;
   10990      2066322 :   constructor_zero_padding_bits = p->zero_padding_bits;
   10991      2066322 :   constructor_braced_scalar = p->braced_scalar;
   10992      2066322 :   designator_depth = p->designator_depth;
   10993      2066322 :   constructor_pending_elts = p->pending_elts;
   10994      2066322 :   constructor_depth = p->depth;
   10995      2066322 :   if (!p->implicit)
   10996      1362714 :     constructor_range_stack = p->range_stack;
   10997      2066322 :   RESTORE_SPELLING_DEPTH (constructor_depth);
   10998              : 
   10999      2066322 :   constructor_stack = p->next;
   11000      2066322 :   XDELETE (p);
   11001              : 
   11002      2066322 :   if (ret.value == NULL_TREE && constructor_stack == 0)
   11003            0 :     ret.value = error_mark_node;
   11004      2066322 :   return ret;
   11005              : }
   11006              : 
   11007              : /* Common handling for both array range and field name designators.
   11008              :    ARRAY argument is nonzero for array ranges.  Returns false for success.  */
   11009              : 
   11010              : static bool
   11011        33997 : set_designator (location_t loc, bool array,
   11012              :                 struct obstack *braced_init_obstack)
   11013              : {
   11014        33997 :   tree subtype;
   11015        33997 :   enum tree_code subcode;
   11016              : 
   11017              :   /* Don't die if an entire brace-pair level is superfluous
   11018              :      in the containing level, or for an erroneous type.  */
   11019        33997 :   if (constructor_type == NULL_TREE || constructor_type == error_mark_node)
   11020              :     return true;
   11021              : 
   11022              :   /* If there were errors in this designator list already, bail out
   11023              :      silently.  */
   11024        33988 :   if (designator_erroneous)
   11025              :     return true;
   11026              : 
   11027              :   /* Likewise for an initializer for a variable-size type.  Those are
   11028              :      diagnosed in the parser, except for empty initializer braces.  */
   11029        33988 :   if (COMPLETE_TYPE_P (constructor_type)
   11030        33988 :       && TREE_CODE (TYPE_SIZE (constructor_type)) != INTEGER_CST)
   11031              :     return true;
   11032              : 
   11033        33978 :   if (!designator_depth)
   11034              :     {
   11035        33360 :       gcc_assert (!constructor_range_stack);
   11036              : 
   11037              :       /* Designator list starts at the level of closest explicit
   11038              :          braces.  */
   11039        33743 :       while (constructor_stack->implicit)
   11040          383 :         process_init_element (input_location,
   11041              :                               pop_init_level (loc, 1, braced_init_obstack,
   11042              :                                               last_init_list_comma),
   11043              :                               true, braced_init_obstack);
   11044        33360 :       constructor_designated = 1;
   11045        33360 :       return false;
   11046              :     }
   11047              : 
   11048          618 :   switch (TREE_CODE (constructor_type))
   11049              :     {
   11050          421 :     case  RECORD_TYPE:
   11051          421 :     case  UNION_TYPE:
   11052          421 :       subtype = TREE_TYPE (constructor_fields);
   11053          421 :       if (subtype != error_mark_node)
   11054          421 :         subtype = TYPE_MAIN_VARIANT (subtype);
   11055              :       break;
   11056          197 :     case ARRAY_TYPE:
   11057          197 :       subtype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
   11058          197 :       break;
   11059            0 :     default:
   11060            0 :       gcc_unreachable ();
   11061              :     }
   11062              : 
   11063          618 :   subcode = TREE_CODE (subtype);
   11064          618 :   if (array && subcode != ARRAY_TYPE)
   11065              :     {
   11066            1 :       error_init (loc, "array index in non-array initializer");
   11067            1 :       return true;
   11068              :     }
   11069          617 :   else if (!array && subcode != RECORD_TYPE && subcode != UNION_TYPE)
   11070              :     {
   11071            0 :       error_init (loc, "field name not in record or union initializer");
   11072            0 :       return true;
   11073              :     }
   11074              : 
   11075          617 :   constructor_designated = 1;
   11076          617 :   finish_implicit_inits (loc, braced_init_obstack);
   11077          617 :   push_init_level (loc, 2, braced_init_obstack);
   11078          617 :   return false;
   11079              : }
   11080              : 
   11081              : /* If there are range designators in designator list, push a new designator
   11082              :    to constructor_range_stack.  RANGE_END is end of such stack range or
   11083              :    NULL_TREE if there is no range designator at this level.  */
   11084              : 
   11085              : static void
   11086          390 : push_range_stack (tree range_end, struct obstack * braced_init_obstack)
   11087              : {
   11088          390 :   struct constructor_range_stack *p;
   11089              : 
   11090          780 :   p = (struct constructor_range_stack *)
   11091          390 :     obstack_alloc (braced_init_obstack,
   11092              :                    sizeof (struct constructor_range_stack));
   11093          390 :   p->prev = constructor_range_stack;
   11094          390 :   p->next = 0;
   11095          390 :   p->fields = constructor_fields;
   11096          390 :   p->range_start = constructor_index;
   11097          390 :   p->index = constructor_index;
   11098          390 :   p->stack = constructor_stack;
   11099          390 :   p->range_end = range_end;
   11100          390 :   if (constructor_range_stack)
   11101           19 :     constructor_range_stack->next = p;
   11102          390 :   constructor_range_stack = p;
   11103          390 : }
   11104              : 
   11105              : /* Within an array initializer, specify the next index to be initialized.
   11106              :    FIRST is that index.  If LAST is nonzero, then initialize a range
   11107              :    of indices, running from FIRST through LAST.  */
   11108              : 
   11109              : void
   11110         1149 : set_init_index (location_t loc, tree first, tree last,
   11111              :                 struct obstack *braced_init_obstack)
   11112              : {
   11113         1149 :   if (set_designator (loc, true, braced_init_obstack))
   11114              :     return;
   11115              : 
   11116         1146 :   designator_erroneous = 1;
   11117              : 
   11118         2292 :   if (!INTEGRAL_TYPE_P (TREE_TYPE (first))
   11119         2281 :       || (last && !INTEGRAL_TYPE_P (TREE_TYPE (last))))
   11120              :     {
   11121           12 :       error_init (loc, "array index in initializer not of integer type");
   11122           12 :       return;
   11123              :     }
   11124              : 
   11125         1134 :   if (TREE_CODE (first) != INTEGER_CST)
   11126              :     {
   11127            6 :       first = c_fully_fold (first, false, NULL);
   11128            6 :       if (TREE_CODE (first) == INTEGER_CST)
   11129            5 :         pedwarn_init (loc, OPT_Wpedantic,
   11130              :                       "array index in initializer is not "
   11131              :                       "an integer constant expression");
   11132              :     }
   11133              : 
   11134         1134 :   if (last && TREE_CODE (last) != INTEGER_CST)
   11135              :     {
   11136            2 :       last = c_fully_fold (last, false, NULL);
   11137            2 :       if (TREE_CODE (last) == INTEGER_CST)
   11138            1 :         pedwarn_init (loc, OPT_Wpedantic,
   11139              :                       "array index in initializer is not "
   11140              :                       "an integer constant expression");
   11141              :     }
   11142              : 
   11143         1134 :   if (TREE_CODE (first) != INTEGER_CST)
   11144            1 :     error_init (loc, "nonconstant array index in initializer");
   11145         1133 :   else if (last != NULL_TREE && TREE_CODE (last) != INTEGER_CST)
   11146            1 :     error_init (loc, "nonconstant array index in initializer");
   11147         1132 :   else if (TREE_CODE (constructor_type) != ARRAY_TYPE)
   11148            9 :     error_init (loc, "array index in non-array initializer");
   11149         1123 :   else if (tree_int_cst_sgn (first) == -1)
   11150           15 :     error_init (loc, "array index in initializer exceeds array bounds");
   11151         1108 :   else if (constructor_max_index
   11152         1108 :            && tree_int_cst_lt (constructor_max_index, first))
   11153            7 :     error_init (loc, "array index in initializer exceeds array bounds");
   11154              :   else
   11155              :     {
   11156         1101 :       constant_expression_warning (first);
   11157         1101 :       if (last)
   11158          385 :         constant_expression_warning (last);
   11159         1101 :       constructor_index = convert (bitsizetype, first);
   11160         1101 :       if (tree_int_cst_lt (constructor_index, first))
   11161              :         {
   11162            0 :           constructor_index = copy_node (constructor_index);
   11163            0 :           TREE_OVERFLOW (constructor_index) = 1;
   11164              :         }
   11165              : 
   11166         1101 :       if (last)
   11167              :         {
   11168          385 :           if (tree_int_cst_equal (first, last))
   11169              :             last = NULL_TREE;
   11170          384 :           else if (tree_int_cst_lt (last, first))
   11171              :             {
   11172            2 :               error_init (loc, "empty index range in initializer");
   11173            2 :               last = NULL_TREE;
   11174              :             }
   11175              :           else
   11176              :             {
   11177          382 :               last = convert (bitsizetype, last);
   11178          382 :               if (constructor_max_index != NULL_TREE
   11179          382 :                   && tree_int_cst_lt (constructor_max_index, last))
   11180              :                 {
   11181            3 :                   error_init (loc, "array index range in initializer exceeds "
   11182              :                               "array bounds");
   11183            3 :                   last = NULL_TREE;
   11184              :                 }
   11185              :             }
   11186              :         }
   11187              : 
   11188         1101 :       designator_depth++;
   11189         1101 :       designator_erroneous = 0;
   11190         1101 :       if (constructor_range_stack || last)
   11191          379 :         push_range_stack (last, braced_init_obstack);
   11192              :     }
   11193              : }
   11194              : 
   11195              : /* Within a struct initializer, specify the next field to be initialized.  */
   11196              : 
   11197              : void
   11198        32803 : set_init_label (location_t loc, tree fieldname, location_t fieldname_loc,
   11199              :                 struct obstack *braced_init_obstack)
   11200              : {
   11201        32803 :   tree field;
   11202              : 
   11203        32803 :   if (set_designator (loc, false, braced_init_obstack))
   11204              :     return;
   11205              : 
   11206        32786 :   designator_erroneous = 1;
   11207              : 
   11208        32786 :   if (!RECORD_OR_UNION_TYPE_P (constructor_type))
   11209              :     {
   11210            3 :       error_init (loc, "field name not in record or union initializer");
   11211            3 :       return;
   11212              :     }
   11213              : 
   11214        32783 :   field = lookup_field (constructor_type, fieldname);
   11215              : 
   11216        32783 :   if (field == NULL_TREE)
   11217              :     {
   11218            8 :       tree guessed_id = lookup_field_fuzzy (constructor_type, fieldname);
   11219            8 :       if (guessed_id)
   11220              :         {
   11221            4 :           gcc_rich_location rich_loc (fieldname_loc);
   11222            4 :           rich_loc.add_fixit_misspelled_id (fieldname_loc, guessed_id);
   11223            4 :           error_at (&rich_loc,
   11224              :                     "%qT has no member named %qE; did you mean %qE?",
   11225              :                     constructor_type, fieldname, guessed_id);
   11226            4 :         }
   11227              :       else
   11228            4 :         error_at (fieldname_loc, "%qT has no member named %qE",
   11229              :                   constructor_type, fieldname);
   11230              :     }
   11231              :   else
   11232        32820 :     do
   11233              :       {
   11234        32820 :         constructor_fields = TREE_VALUE (field);
   11235        32820 :         designator_depth++;
   11236        32820 :         designator_erroneous = 0;
   11237        32820 :         if (constructor_range_stack)
   11238           11 :           push_range_stack (NULL_TREE, braced_init_obstack);
   11239        32820 :         field = TREE_CHAIN (field);
   11240        32820 :         if (field)
   11241              :           {
   11242           45 :             if (set_designator (loc, false, braced_init_obstack))
   11243              :               return;
   11244              :           }
   11245              :       }
   11246        32820 :     while (field != NULL_TREE);
   11247              : }
   11248              : 
   11249              : /* Helper function for add_pending_init.  Find inorder successor of P
   11250              :    in AVL tree.  */
   11251              : static struct init_node *
   11252          129 : init_node_successor (struct init_node *p)
   11253              : {
   11254          129 :   struct init_node *r;
   11255          129 :   if (p->right)
   11256              :     {
   11257              :       r = p->right;
   11258           58 :       while (r->left)
   11259              :         r = r->left;
   11260              :       return r;
   11261              :     }
   11262           75 :   r = p->parent;
   11263          114 :   while (r && p == r->right)
   11264              :     {
   11265           39 :       p = r;
   11266           39 :       r = r->parent;
   11267              :     }
   11268              :   return r;
   11269              : }
   11270              : 
   11271              : /* Add a new initializer to the tree of pending initializers.  PURPOSE
   11272              :    identifies the initializer, either array index or field in a structure.
   11273              :    VALUE is the value of that index or field.  If ORIGTYPE is not
   11274              :    NULL_TREE, it is the original type of VALUE.
   11275              : 
   11276              :    IMPLICIT is true if value comes from pop_init_level (1),
   11277              :    the new initializer has been merged with the existing one
   11278              :    and thus no warnings should be emitted about overriding an
   11279              :    existing initializer.  */
   11280              : 
   11281              : static void
   11282         3269 : add_pending_init (location_t loc, tree purpose, tree value, tree origtype,
   11283              :                   bool implicit, struct obstack *braced_init_obstack)
   11284              : {
   11285         3269 :   struct init_node *p, **q, *r;
   11286              : 
   11287         3269 :   q = &constructor_pending_elts;
   11288         3269 :   p = 0;
   11289              : 
   11290         3269 :   if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   11291              :     {
   11292         3610 :       while (*q != 0)
   11293              :         {
   11294         2412 :           p = *q;
   11295         2412 :           if (tree_int_cst_lt (purpose, p->purpose))
   11296          283 :             q = &p->left;
   11297         2129 :           else if (tree_int_cst_lt (p->purpose, purpose))
   11298              :             {
   11299         1960 :               if (TREE_CODE (p->value) != RAW_DATA_CST
   11300         1960 :                   || (p->right
   11301          112 :                       && tree_int_cst_le (p->right->purpose, purpose)))
   11302         1830 :                 q = &p->right;
   11303              :               else
   11304              :                 {
   11305          130 :                   widest_int pp = wi::to_widest (p->purpose);
   11306          130 :                   widest_int pw = wi::to_widest (purpose);
   11307          130 :                   if (pp + RAW_DATA_LENGTH (p->value) <= pw)
   11308           98 :                     q = &p->right;
   11309              :                   else
   11310              :                     {
   11311              :                       /* Override which should split the old RAW_DATA_CST
   11312              :                          into 2 or 3 pieces.  */
   11313           32 :                       if (!implicit && warn_override_init)
   11314            9 :                         warning_init (loc, OPT_Woverride_init,
   11315              :                                       "initialized field overwritten");
   11316           32 :                       unsigned HOST_WIDE_INT start = (pw - pp).to_uhwi ();
   11317           32 :                       unsigned HOST_WIDE_INT len = 1;
   11318           32 :                       if (TREE_CODE (value) == RAW_DATA_CST)
   11319            0 :                         len = RAW_DATA_LENGTH (value);
   11320           32 :                       unsigned HOST_WIDE_INT end = 0;
   11321           32 :                       unsigned plen = RAW_DATA_LENGTH (p->value);
   11322           32 :                       gcc_checking_assert (start < plen && start);
   11323           32 :                       if (plen - start > len)
   11324           30 :                         end = plen - start - len;
   11325           32 :                       tree v = p->value;
   11326           32 :                       tree origtype = p->origtype;
   11327           32 :                       if (start == 1)
   11328            2 :                         p->value = build_int_cst (TREE_TYPE (v),
   11329            2 :                                                   RAW_DATA_UCHAR_ELT (v, 0));
   11330              :                       else
   11331              :                         {
   11332           30 :                           p->value = v;
   11333           30 :                           if (end > 1)
   11334           26 :                             v = copy_node (v);
   11335           30 :                           RAW_DATA_LENGTH (p->value) = start;
   11336              :                         }
   11337           32 :                       if (end)
   11338              :                         {
   11339           30 :                           tree epurpose
   11340           30 :                             = size_binop (PLUS_EXPR, purpose,
   11341              :                                           bitsize_int (len));
   11342           30 :                           if (end > 1)
   11343              :                             {
   11344           28 :                               RAW_DATA_LENGTH (v) -= plen - end;
   11345           28 :                               RAW_DATA_POINTER (v) += plen - end;
   11346              :                             }
   11347              :                           else
   11348            2 :                             v = build_int_cst (TREE_TYPE (v),
   11349            2 :                                                RAW_DATA_UCHAR_ELT (v, plen
   11350              :                                                                       - end));
   11351           30 :                           add_pending_init (loc, epurpose, v, origtype,
   11352              :                                             implicit, braced_init_obstack);
   11353              :                         }
   11354           32 :                       q = &constructor_pending_elts;
   11355           32 :                       continue;
   11356           32 :                     }
   11357          130 :                 }
   11358              :             }
   11359              :           else
   11360              :             {
   11361          169 :               if (TREE_CODE (p->value) == RAW_DATA_CST
   11362          179 :                   && (RAW_DATA_LENGTH (p->value)
   11363           10 :                       > (TREE_CODE (value) == RAW_DATA_CST
   11364           10 :                          ? RAW_DATA_LENGTH (value) : 1)))
   11365              :                 {
   11366              :                   /* Override which should split the old RAW_DATA_CST
   11367              :                      into 2 pieces.  */
   11368            6 :                   if (!implicit && warn_override_init)
   11369            3 :                     warning_init (loc, OPT_Woverride_init,
   11370              :                                   "initialized field overwritten");
   11371            6 :                   unsigned HOST_WIDE_INT len = 1;
   11372            6 :                   if (TREE_CODE (value) == RAW_DATA_CST)
   11373            2 :                     len = RAW_DATA_LENGTH (value);
   11374            6 :                   if ((unsigned) RAW_DATA_LENGTH (p->value) > len + 1)
   11375              :                     {
   11376            6 :                       RAW_DATA_LENGTH (p->value) -= len;
   11377            6 :                       RAW_DATA_POINTER (p->value) += len;
   11378              :                     }
   11379              :                   else
   11380              :                     {
   11381            0 :                       unsigned int l = RAW_DATA_LENGTH (p->value) - 1;
   11382            0 :                       p->value
   11383            0 :                         = build_int_cst (TREE_TYPE (p->value),
   11384            0 :                                          RAW_DATA_UCHAR_ELT (p->value, l));
   11385              :                     }
   11386            6 :                   p->purpose = size_binop (PLUS_EXPR, p->purpose,
   11387              :                                            bitsize_int (len));
   11388            6 :                   continue;
   11389            6 :                 }
   11390          163 :               if (TREE_CODE (value) == RAW_DATA_CST)
   11391              :                 {
   11392            8 :                 handle_raw_data:
   11393              :                   /* RAW_DATA_CST value might overlap various further
   11394              :                      prior initval entries.  Find out how many.  */
   11395           13 :                   unsigned cnt = 0;
   11396           13 :                   widest_int w
   11397           26 :                     = wi::to_widest (purpose) + RAW_DATA_LENGTH (value);
   11398           13 :                   struct init_node *r = p, *last = NULL;
   11399           13 :                   bool override_init = warn_override_init;
   11400           13 :                   while ((r = init_node_successor (r))
   11401           53 :                          && wi::to_widest (r->purpose) < w)
   11402              :                     {
   11403           40 :                       ++cnt;
   11404           40 :                       if (TREE_SIDE_EFFECTS (r->value))
   11405            2 :                         warning_init (loc, OPT_Woverride_init_side_effects,
   11406              :                                       "initialized field with side-effects "
   11407              :                                       "overwritten");
   11408           38 :                       else if (override_init)
   11409              :                         {
   11410            6 :                           warning_init (loc, OPT_Woverride_init,
   11411              :                                         "initialized field overwritten");
   11412            6 :                           override_init = false;
   11413              :                         }
   11414              :                       last = r;
   11415              :                     }
   11416           13 :                   if (cnt)
   11417              :                     {
   11418           26 :                       if (TREE_CODE (last->value) == RAW_DATA_CST
   11419           13 :                           && (wi::to_widest (last->purpose)
   11420           13 :                               + RAW_DATA_LENGTH (last->value) > w))
   11421              :                         {
   11422              :                           /* The last overlapping prior initval overlaps
   11423              :                              only partially.  Shrink it and decrease cnt.  */
   11424            0 :                           unsigned int l = (wi::to_widest (last->purpose)
   11425            0 :                                             + RAW_DATA_LENGTH (last->value)
   11426            0 :                                             - w).to_uhwi ();
   11427            0 :                           --cnt;
   11428            0 :                           RAW_DATA_LENGTH (last->value) -= l;
   11429            0 :                           RAW_DATA_POINTER (last->value) += l;
   11430            0 :                           if (RAW_DATA_LENGTH (last->value) == 1)
   11431            0 :                             last->value
   11432            0 :                               = build_int_cst (TREE_TYPE (last->value),
   11433            0 :                                                RAW_DATA_UCHAR_ELT (last->value,
   11434              :                                                                    0));
   11435            0 :                           last->purpose
   11436            0 :                             = size_binop (PLUS_EXPR, last->purpose,
   11437              :                                           bitsize_int (l));
   11438              :                         }
   11439              :                       /* Instead of deleting cnt nodes from the AVL tree
   11440              :                          and rebalancing, peel of last cnt bytes from the
   11441              :                          RAW_DATA_CST.  Overriding thousands of previously
   11442              :                          initialized array elements with #embed needs to work,
   11443              :                          but doesn't need to be super efficient.  */
   11444           13 :                       gcc_checking_assert ((unsigned) RAW_DATA_LENGTH (value)
   11445              :                                            > cnt);
   11446           13 :                       RAW_DATA_LENGTH (value) -= cnt;
   11447           13 :                       const unsigned char *s
   11448           13 :                         = &RAW_DATA_UCHAR_ELT (value, RAW_DATA_LENGTH (value));
   11449           13 :                       unsigned int o = RAW_DATA_LENGTH (value);
   11450           53 :                       for (r = p; cnt--; ++o, ++s)
   11451              :                         {
   11452           40 :                           r = init_node_successor (r);
   11453           40 :                           r->purpose = size_binop (PLUS_EXPR, purpose,
   11454              :                                                    bitsize_int (o));
   11455           40 :                           r->value = build_int_cst (TREE_TYPE (value), *s);
   11456           40 :                           r->origtype = origtype;
   11457              :                         }
   11458           13 :                       if (RAW_DATA_LENGTH (value) == 1)
   11459            0 :                         value = build_int_cst (TREE_TYPE (value),
   11460            0 :                                                RAW_DATA_UCHAR_ELT (value, 0));
   11461              :                     }
   11462              :                 }
   11463          168 :               if (!implicit)
   11464              :                 {
   11465           54 :                   if (TREE_SIDE_EFFECTS (p->value))
   11466            6 :                     warning_init (loc, OPT_Woverride_init_side_effects,
   11467              :                                   "initialized field with side-effects "
   11468              :                                   "overwritten");
   11469           48 :                   else if (warn_override_init)
   11470           13 :                     warning_init (loc, OPT_Woverride_init,
   11471              :                                   "initialized field overwritten");
   11472              :                 }
   11473          168 :               p->value = value;
   11474          168 :               p->origtype = origtype;
   11475          168 :               return;
   11476              :             }
   11477              :         }
   11478         1198 :       if (TREE_CODE (value) == RAW_DATA_CST && p)
   11479              :         {
   11480           61 :           struct init_node *r;
   11481           61 :           if (q == &p->left)
   11482              :             r = p;
   11483              :           else
   11484           36 :             r = init_node_successor (p);
   11485          131 :           if (r && wi::to_widest (r->purpose) < (wi::to_widest (purpose)
   11486          131 :                                                  + RAW_DATA_LENGTH (value)))
   11487              :             {
   11488              :               /* Overlap with at least one prior initval in the range but
   11489              :                  not at the start.  */
   11490            5 :               p = r;
   11491            5 :               p->purpose = purpose;
   11492            5 :               goto handle_raw_data;
   11493              :             }
   11494              :         }
   11495              :     }
   11496              :   else
   11497              :     {
   11498         1908 :       tree bitpos;
   11499              : 
   11500         1908 :       bitpos = bit_position (purpose);
   11501         5430 :       while (*q != NULL)
   11502              :         {
   11503         1871 :           p = *q;
   11504         1871 :           if (tree_int_cst_lt (bitpos, bit_position (p->purpose)))
   11505           43 :             q = &p->left;
   11506         1828 :           else if (p->purpose != purpose)
   11507         1571 :             q = &p->right;
   11508              :           else
   11509              :             {
   11510          257 :               if (!implicit)
   11511              :                 {
   11512           33 :                   if (TREE_SIDE_EFFECTS (p->value))
   11513            4 :                     warning_init (loc, OPT_Woverride_init_side_effects,
   11514              :                                   "initialized field with side-effects "
   11515              :                                   "overwritten");
   11516           29 :                   else if (warn_override_init)
   11517            6 :                     warning_init (loc, OPT_Woverride_init,
   11518              :                                   "initialized field overwritten");
   11519              :                 }
   11520          257 :               p->value = value;
   11521          257 :               p->origtype = origtype;
   11522          257 :               return;
   11523              :             }
   11524              :         }
   11525              :     }
   11526              : 
   11527         2844 :   r = (struct init_node *) obstack_alloc (braced_init_obstack,
   11528              :                                           sizeof (struct init_node));
   11529         2844 :   r->purpose = purpose;
   11530         2844 :   r->value = value;
   11531         2844 :   r->origtype = origtype;
   11532              : 
   11533         2844 :   *q = r;
   11534         2844 :   r->parent = p;
   11535         2844 :   r->left = 0;
   11536         2844 :   r->right = 0;
   11537         2844 :   r->balance = 0;
   11538              : 
   11539         4878 :   while (p)
   11540              :     {
   11541         2826 :       struct init_node *s;
   11542              : 
   11543         2826 :       if (r == p->left)
   11544              :         {
   11545          237 :           if (p->balance == 0)
   11546          174 :             p->balance = -1;
   11547           63 :           else if (p->balance < 0)
   11548              :             {
   11549           45 :               if (r->balance < 0)
   11550              :                 {
   11551              :                   /* L rotation.  */
   11552           40 :                   p->left = r->right;
   11553           40 :                   if (p->left)
   11554            2 :                     p->left->parent = p;
   11555           40 :                   r->right = p;
   11556              : 
   11557           40 :                   p->balance = 0;
   11558           40 :                   r->balance = 0;
   11559              : 
   11560           40 :                   s = p->parent;
   11561           40 :                   p->parent = r;
   11562           40 :                   r->parent = s;
   11563           40 :                   if (s)
   11564              :                     {
   11565           31 :                       if (s->left == p)
   11566           10 :                         s->left = r;
   11567              :                       else
   11568           21 :                         s->right = r;
   11569              :                     }
   11570              :                   else
   11571            9 :                     constructor_pending_elts = r;
   11572              :                 }
   11573              :               else
   11574              :                 {
   11575              :                   /* LR rotation.  */
   11576            5 :                   struct init_node *t = r->right;
   11577              : 
   11578            5 :                   r->right = t->left;
   11579            5 :                   if (r->right)
   11580            0 :                     r->right->parent = r;
   11581            5 :                   t->left = r;
   11582              : 
   11583            5 :                   p->left = t->right;
   11584            5 :                   if (p->left)
   11585            0 :                     p->left->parent = p;
   11586            5 :                   t->right = p;
   11587              : 
   11588            5 :                   p->balance = t->balance < 0;
   11589            5 :                   r->balance = -(t->balance > 0);
   11590            5 :                   t->balance = 0;
   11591              : 
   11592            5 :                   s = p->parent;
   11593            5 :                   p->parent = t;
   11594            5 :                   r->parent = t;
   11595            5 :                   t->parent = s;
   11596            5 :                   if (s)
   11597              :                     {
   11598            0 :                       if (s->left == p)
   11599            0 :                         s->left = t;
   11600              :                       else
   11601            0 :                         s->right = t;
   11602              :                     }
   11603              :                   else
   11604            5 :                     constructor_pending_elts = t;
   11605              :                 }
   11606              :               break;
   11607              :             }
   11608              :           else
   11609              :             {
   11610              :               /* p->balance == +1; growth of left side balances the node.  */
   11611           18 :               p->balance = 0;
   11612           18 :               break;
   11613              :             }
   11614              :         }
   11615              :       else /* r == p->right */
   11616              :         {
   11617         2589 :           if (p->balance == 0)
   11618              :             /* Growth propagation from right side.  */
   11619         1860 :             p->balance++;
   11620          729 :           else if (p->balance > 0)
   11621              :             {
   11622          700 :               if (r->balance > 0)
   11623              :                 {
   11624              :                   /* R rotation.  */
   11625          698 :                   p->right = r->left;
   11626          698 :                   if (p->right)
   11627          173 :                     p->right->parent = p;
   11628          698 :                   r->left = p;
   11629              : 
   11630          698 :                   p->balance = 0;
   11631          698 :                   r->balance = 0;
   11632              : 
   11633          698 :                   s = p->parent;
   11634          698 :                   p->parent = r;
   11635          698 :                   r->parent = s;
   11636          698 :                   if (s)
   11637              :                     {
   11638          378 :                       if (s->left == p)
   11639            2 :                         s->left = r;
   11640              :                       else
   11641          376 :                         s->right = r;
   11642              :                     }
   11643              :                   else
   11644          320 :                     constructor_pending_elts = r;
   11645              :                 }
   11646              :               else /* r->balance == -1 */
   11647              :                 {
   11648              :                   /* RL rotation */
   11649            2 :                   struct init_node *t = r->left;
   11650              : 
   11651            2 :                   r->left = t->right;
   11652            2 :                   if (r->left)
   11653            2 :                     r->left->parent = r;
   11654            2 :                   t->right = r;
   11655              : 
   11656            2 :                   p->right = t->left;
   11657            2 :                   if (p->right)
   11658            2 :                     p->right->parent = p;
   11659            2 :                   t->left = p;
   11660              : 
   11661            2 :                   r->balance = (t->balance < 0);
   11662            2 :                   p->balance = -(t->balance > 0);
   11663            2 :                   t->balance = 0;
   11664              : 
   11665            2 :                   s = p->parent;
   11666            2 :                   p->parent = t;
   11667            2 :                   r->parent = t;
   11668            2 :                   t->parent = s;
   11669            2 :                   if (s)
   11670              :                     {
   11671            0 :                       if (s->left == p)
   11672            0 :                         s->left = t;
   11673              :                       else
   11674            0 :                         s->right = t;
   11675              :                     }
   11676              :                   else
   11677            2 :                     constructor_pending_elts = t;
   11678              :                 }
   11679              :               break;
   11680              :             }
   11681              :           else
   11682              :             {
   11683              :               /* p->balance == -1; growth of right side balances the node.  */
   11684           29 :               p->balance = 0;
   11685           29 :               break;
   11686              :             }
   11687              :         }
   11688              : 
   11689         2034 :       r = p;
   11690         2034 :       p = p->parent;
   11691              :     }
   11692              : }
   11693              : 
   11694              : /* Build AVL tree from a sorted chain.  */
   11695              : 
   11696              : static void
   11697          418 : set_nonincremental_init (struct obstack * braced_init_obstack)
   11698              : {
   11699          418 :   unsigned HOST_WIDE_INT ix;
   11700          418 :   tree index, value;
   11701              : 
   11702          418 :   if (TREE_CODE (constructor_type) != RECORD_TYPE
   11703          418 :       && TREE_CODE (constructor_type) != ARRAY_TYPE)
   11704              :     return;
   11705              : 
   11706         1601 :   FOR_EACH_CONSTRUCTOR_ELT (constructor_elements, ix, index, value)
   11707         1183 :     add_pending_init (input_location, index, value, NULL_TREE, true,
   11708              :                       braced_init_obstack);
   11709          418 :   constructor_elements = NULL;
   11710          418 :   if (TREE_CODE (constructor_type) == RECORD_TYPE)
   11711              :     {
   11712          200 :       constructor_unfilled_fields = TYPE_FIELDS (constructor_type);
   11713              :       /* Skip any nameless bit fields at the beginning.  */
   11714          200 :       while (constructor_unfilled_fields != NULL_TREE
   11715          200 :              && DECL_UNNAMED_BIT_FIELD (constructor_unfilled_fields))
   11716            0 :         constructor_unfilled_fields = TREE_CHAIN (constructor_unfilled_fields);
   11717              : 
   11718              :     }
   11719          218 :   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   11720              :     {
   11721          218 :       if (TYPE_DOMAIN (constructor_type))
   11722          160 :         constructor_unfilled_index
   11723          160 :           = convert (bitsizetype,
   11724          160 :                      TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
   11725              :       else
   11726           58 :         constructor_unfilled_index = bitsize_zero_node;
   11727              :     }
   11728          418 :   constructor_incremental = 0;
   11729              : }
   11730              : 
   11731              : /* Build AVL tree from a string constant.  */
   11732              : 
   11733              : static void
   11734            7 : set_nonincremental_init_from_string (tree str,
   11735              :                                      struct obstack * braced_init_obstack)
   11736              : {
   11737            7 :   tree value, purpose, type;
   11738            7 :   HOST_WIDE_INT val[2];
   11739            7 :   const char *p, *end;
   11740            7 :   int byte, wchar_bytes, charwidth, bitpos;
   11741              : 
   11742            7 :   gcc_assert (TREE_CODE (constructor_type) == ARRAY_TYPE);
   11743              : 
   11744            7 :   wchar_bytes = TYPE_PRECISION (TREE_TYPE (TREE_TYPE (str))) / BITS_PER_UNIT;
   11745            7 :   charwidth = TYPE_PRECISION (char_type_node);
   11746            7 :   gcc_assert ((size_t) wchar_bytes * charwidth
   11747              :               <= ARRAY_SIZE (val) * HOST_BITS_PER_WIDE_INT);
   11748            7 :   type = TREE_TYPE (constructor_type);
   11749            7 :   p = TREE_STRING_POINTER (str);
   11750            7 :   end = p + TREE_STRING_LENGTH (str);
   11751              : 
   11752            7 :   for (purpose = bitsize_zero_node;
   11753              :        p < end
   11754           52 :        && !(constructor_max_index
   11755           20 :             && tree_int_cst_lt (constructor_max_index, purpose));
   11756           25 :        purpose = size_binop (PLUS_EXPR, purpose, bitsize_one_node))
   11757              :     {
   11758           25 :       if (wchar_bytes == 1)
   11759              :         {
   11760            9 :           val[0] = (unsigned char) *p++;
   11761            9 :           val[1] = 0;
   11762              :         }
   11763              :       else
   11764              :         {
   11765           16 :           val[1] = 0;
   11766           16 :           val[0] = 0;
   11767           64 :           for (byte = 0; byte < wchar_bytes; byte++)
   11768              :             {
   11769           48 :               if (BYTES_BIG_ENDIAN)
   11770              :                 bitpos = (wchar_bytes - byte - 1) * charwidth;
   11771              :               else
   11772           48 :                 bitpos = byte * charwidth;
   11773           48 :               val[bitpos / HOST_BITS_PER_WIDE_INT]
   11774           48 :                 |= ((unsigned HOST_WIDE_INT) ((unsigned char) *p++))
   11775           48 :                    << (bitpos % HOST_BITS_PER_WIDE_INT);
   11776              :             }
   11777              :         }
   11778              : 
   11779           25 :       if (!TYPE_UNSIGNED (type))
   11780              :         {
   11781           13 :           bitpos = ((wchar_bytes - 1) * charwidth) + HOST_BITS_PER_CHAR;
   11782           13 :           if (bitpos < HOST_BITS_PER_WIDE_INT)
   11783              :             {
   11784           13 :               if (val[0] & (HOST_WIDE_INT_1 << (bitpos - 1)))
   11785              :                 {
   11786            0 :                   val[0] |= HOST_WIDE_INT_M1U << bitpos;
   11787            0 :                   val[1] = -1;
   11788              :                 }
   11789              :             }
   11790            0 :           else if (bitpos == HOST_BITS_PER_WIDE_INT)
   11791              :             {
   11792            0 :               if (val[0] < 0)
   11793            0 :                 val[1] = -1;
   11794              :             }
   11795            0 :           else if (val[1] & (HOST_WIDE_INT_1
   11796            0 :                              << (bitpos - 1 - HOST_BITS_PER_WIDE_INT)))
   11797            0 :             val[1] |= HOST_WIDE_INT_M1U << (bitpos - HOST_BITS_PER_WIDE_INT);
   11798              :         }
   11799              : 
   11800           25 :       value = wide_int_to_tree (type,
   11801           25 :                                 wide_int::from_array (val, 2,
   11802              :                                                       HOST_BITS_PER_WIDE_INT * 2));
   11803           25 :       add_pending_init (input_location, purpose, value, NULL_TREE, true,
   11804              :                         braced_init_obstack);
   11805              :     }
   11806              : 
   11807            7 :   constructor_incremental = 0;
   11808            7 : }
   11809              : 
   11810              : /* Return value of FIELD in pending initializer or NULL_TREE if the field was
   11811              :    not initialized yet.  */
   11812              : 
   11813              : static tree
   11814       703608 : find_init_member (tree field, struct obstack * braced_init_obstack)
   11815              : {
   11816       703608 :   struct init_node *p;
   11817              : 
   11818       703608 :   if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   11819              :     {
   11820       702812 :       if (constructor_incremental
   11821       702812 :           && tree_int_cst_lt (field, constructor_unfilled_index))
   11822           16 :         set_nonincremental_init (braced_init_obstack);
   11823              : 
   11824       702812 :       p = constructor_pending_elts;
   11825       702935 :       while (p)
   11826              :         {
   11827          233 :           if (tree_int_cst_lt (field, p->purpose))
   11828           25 :             p = p->left;
   11829          208 :           else if (tree_int_cst_lt (p->purpose, field))
   11830           98 :             p = p->right;
   11831              :           else
   11832          110 :             return p->value;
   11833              :         }
   11834              :     }
   11835          796 :   else if (TREE_CODE (constructor_type) == RECORD_TYPE)
   11836              :     {
   11837          673 :       tree bitpos = bit_position (field);
   11838              : 
   11839          673 :       if (constructor_incremental
   11840          673 :           && (!constructor_unfilled_fields
   11841          470 :               || tree_int_cst_lt (bitpos,
   11842          470 :                                   bit_position (constructor_unfilled_fields))))
   11843           51 :         set_nonincremental_init (braced_init_obstack);
   11844              : 
   11845          673 :       p = constructor_pending_elts;
   11846          813 :       while (p)
   11847              :         {
   11848          347 :           if (field == p->purpose)
   11849          207 :             return p->value;
   11850          140 :           else if (tree_int_cst_lt (bitpos, bit_position (p->purpose)))
   11851            7 :             p = p->left;
   11852              :           else
   11853          133 :             p = p->right;
   11854              :         }
   11855              :     }
   11856          123 :   else if (TREE_CODE (constructor_type) == UNION_TYPE)
   11857              :     {
   11858          123 :       if (!vec_safe_is_empty (constructor_elements)
   11859           50 :           && (constructor_elements->last ().index == field))
   11860           50 :         return constructor_elements->last ().value;
   11861              :     }
   11862              :   return NULL_TREE;
   11863              : }
   11864              : 
   11865              : /* "Output" the next constructor element.
   11866              :    At top level, really output it to assembler code now.
   11867              :    Otherwise, collect it in a list from which we will make a CONSTRUCTOR.
   11868              :    If ORIGTYPE is not NULL_TREE, it is the original type of VALUE.
   11869              :    TYPE is the data type that the containing data type wants here.
   11870              :    FIELD is the field (a FIELD_DECL) or the index that this element fills.
   11871              :    If VALUE is a string constant, STRICT_STRING is true if it is
   11872              :    unparenthesized or we should not warn here for it being parenthesized.
   11873              :    For other types of VALUE, STRICT_STRING is not used.
   11874              : 
   11875              :    PENDING if true means output pending elements that belong
   11876              :    right after this element.  (PENDING is normally true;
   11877              :    it is false while outputting pending elements, to avoid recursion.)
   11878              : 
   11879              :    IMPLICIT is true if value comes from pop_init_level (1),
   11880              :    the new initializer has been merged with the existing one
   11881              :    and thus no warnings should be emitted about overriding an
   11882              :    existing initializer.  */
   11883              : 
   11884              : static void
   11885      9607612 : output_init_element (location_t loc, tree value, tree origtype,
   11886              :                      bool strict_string, tree type, tree field, bool pending,
   11887              :                      bool implicit, struct obstack * braced_init_obstack)
   11888              : {
   11889      9607612 :   tree semantic_type = NULL_TREE;
   11890      9607612 :   bool maybe_const = true;
   11891      9607612 :   bool npc, int_const_expr, arith_const_expr;
   11892              : 
   11893      9607612 :   if (type == error_mark_node || value == error_mark_node)
   11894              :     {
   11895          287 :       constructor_erroneous = 1;
   11896         2412 :       return;
   11897              :     }
   11898      9607325 :   if (TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
   11899       200071 :       && (TREE_CODE (value) == STRING_CST
   11900       158661 :           || TREE_CODE (value) == COMPOUND_LITERAL_EXPR)
   11901        41418 :       && !(TREE_CODE (value) == STRING_CST
   11902        41410 :            && TREE_CODE (type) == ARRAY_TYPE
   11903         3898 :            && INTEGRAL_TYPE_P (TREE_TYPE (type)))
   11904      9644845 :       && !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (value)),
   11905        37520 :                      TYPE_MAIN_VARIANT (type)))
   11906        37520 :     value = array_to_pointer_conversion (input_location, value);
   11907              : 
   11908      9607325 :   if (TREE_CODE (value) == COMPOUND_LITERAL_EXPR
   11909          182 :       && require_constant_value && pending)
   11910              :     {
   11911              :       /* As an extension, allow initializing objects with static storage
   11912              :          duration with compound literals (which are then treated just as
   11913              :          the brace enclosed list they contain).  */
   11914          114 :       if (flag_isoc99)
   11915           24 :         pedwarn_init (loc, OPT_Wpedantic, "initializer element is not "
   11916              :                       "constant");
   11917          114 :       tree decl = COMPOUND_LITERAL_EXPR_DECL (value);
   11918          114 :       value = DECL_INITIAL (decl);
   11919              :     }
   11920              : 
   11921      9607325 :   npc = null_pointer_constant_p (value);
   11922     19214650 :   int_const_expr = (TREE_CODE (value) == INTEGER_CST
   11923      4210082 :                     && !TREE_OVERFLOW (value)
   11924     13817406 :                     && INTEGRAL_TYPE_P (TREE_TYPE (value)));
   11925              :   /* Not fully determined before folding.  */
   11926      9607325 :   arith_const_expr = true;
   11927      9607325 :   if (TREE_CODE (value) == EXCESS_PRECISION_EXPR)
   11928              :     {
   11929           16 :       semantic_type = TREE_TYPE (value);
   11930           16 :       value = TREE_OPERAND (value, 0);
   11931              :     }
   11932      9607325 :   value = c_fully_fold (value, require_constant_value, &maybe_const);
   11933              :   /* TODO: this may not detect all cases of expressions folding to
   11934              :      constants that are not arithmetic constant expressions.  */
   11935      9607325 :   if (!maybe_const)
   11936              :     arith_const_expr = false;
   11937     19212093 :   else if (!INTEGRAL_TYPE_P (TREE_TYPE (value))
   11938      3182858 :            && TREE_CODE (TREE_TYPE (value)) != REAL_TYPE
   11939     11448068 :            && TREE_CODE (TREE_TYPE (value)) != COMPLEX_TYPE)
   11940              :     arith_const_expr = false;
   11941      7779319 :   else if (TREE_CODE (value) != INTEGER_CST
   11942              :            && TREE_CODE (value) != REAL_CST
   11943              :            && TREE_CODE (value) != COMPLEX_CST
   11944              :            && TREE_CODE (value) != RAW_DATA_CST)
   11945              :     arith_const_expr = false;
   11946      4598624 :   else if (TREE_OVERFLOW (value))
   11947      5008702 :     arith_const_expr = false;
   11948              : 
   11949      9607325 :   if (value == error_mark_node)
   11950            0 :     constructor_erroneous = 1;
   11951      9607325 :   else if (!TREE_CONSTANT (value))
   11952      3200933 :     constructor_constant = 0;
   11953      6406392 :   else if (!initializer_constant_valid_p (value,
   11954      6406392 :                                           TREE_TYPE (value),
   11955      6406392 :                                           AGGREGATE_TYPE_P (constructor_type)
   11956      6406392 :                                           && TYPE_REVERSE_STORAGE_ORDER
   11957              :                                              (constructor_type))
   11958      6406392 :            || (RECORD_OR_UNION_TYPE_P (constructor_type)
   11959      1037847 :                && DECL_C_BIT_FIELD (field)
   11960         8103 :                && TREE_CODE (value) != INTEGER_CST))
   11961           77 :     constructor_simple = 0;
   11962      9607325 :   if (!maybe_const)
   11963         1172 :     constructor_nonconst = 1;
   11964              : 
   11965              :   /* Digest the initializer and issue any errors about incompatible
   11966              :      types before issuing errors about non-constant initializers.  */
   11967      9607325 :   tree new_value = value;
   11968      9607325 :   if (semantic_type)
   11969           16 :     new_value = build1 (EXCESS_PRECISION_EXPR, semantic_type, value);
   11970              :   /* In the case of braces around a scalar initializer, the result of
   11971              :      this initializer processing goes through digest_init again at the
   11972              :      outer level.  In the case of a constexpr initializer for a
   11973              :      pointer, avoid converting a null pointer constant to something
   11974              :      that is not a null pointer constant to avoid a spurious error
   11975              :      from that second processing.  */
   11976      9607325 :   if (!require_constexpr_value
   11977          398 :       || !npc
   11978           69 :       || TREE_CODE (constructor_type) != POINTER_TYPE)
   11979      9607314 :     new_value = digest_init (loc,
   11980      9607314 :                              RECORD_OR_UNION_TYPE_P (constructor_type)
   11981      8537343 :                              ? field : constructor_fields
   11982      8537343 :                              ? constructor_fields : constructor_decl,
   11983              :                              type, new_value, origtype, npc,
   11984              :                              int_const_expr, arith_const_expr, strict_string,
   11985              :                              require_constant_value, require_constexpr_value);
   11986      9607325 :   if (new_value == error_mark_node)
   11987              :     {
   11988           76 :       constructor_erroneous = 1;
   11989           76 :       return;
   11990              :     }
   11991      9607249 :   if (require_constant_value || require_constant_elements)
   11992      2712296 :     constant_expression_warning (new_value);
   11993              : 
   11994              :   /* Proceed to check the constness of the original initializer.  */
   11995      9607249 :   if (!initializer_constant_valid_p (value, TREE_TYPE (value)))
   11996              :     {
   11997      3200959 :       if (require_constant_value)
   11998              :         {
   11999            0 :           error_init (loc, "initializer element is not constant");
   12000            0 :           value = error_mark_node;
   12001              :         }
   12002      3200959 :       else if (require_constant_elements)
   12003           15 :         pedwarn (loc, OPT_Wpedantic,
   12004              :                  "initializer element is not computable at load time");
   12005              :     }
   12006      6406290 :   else if (!maybe_const
   12007           54 :            && (require_constant_value || require_constant_elements))
   12008           28 :     pedwarn_init (loc, OPT_Wpedantic,
   12009              :                   "initializer element is not a constant expression");
   12010              :   /* digest_init has already carried out the additional checks
   12011              :      required for 'constexpr' initializers (using the information
   12012              :      passed to it about whether the original initializer was certain
   12013              :      kinds of constant expression), so that check does not need to be
   12014              :      repeated here.  */
   12015              : 
   12016              :   /* Issue -Wc++-compat warnings about initializing a bitfield with
   12017              :      enum type.  */
   12018      9607249 :   if (warn_cxx_compat
   12019         6895 :       && field != NULL_TREE
   12020         6895 :       && TREE_CODE (field) == FIELD_DECL
   12021          459 :       && DECL_BIT_FIELD_TYPE (field) != NULL_TREE
   12022           21 :       && (TYPE_MAIN_VARIANT (DECL_BIT_FIELD_TYPE (field))
   12023           21 :           != TYPE_MAIN_VARIANT (type))
   12024      9607270 :       && TREE_CODE (DECL_BIT_FIELD_TYPE (field)) == ENUMERAL_TYPE)
   12025              :     {
   12026           21 :       tree checktype = origtype != NULL_TREE ? origtype : TREE_TYPE (value);
   12027           21 :       if (checktype != error_mark_node
   12028           21 :           && (TYPE_MAIN_VARIANT (checktype)
   12029           21 :               != TYPE_MAIN_VARIANT (DECL_BIT_FIELD_TYPE (field))))
   12030            9 :         warning_init (loc, OPT_Wc___compat,
   12031              :                       "enum conversion in initialization is invalid in C++");
   12032              :     }
   12033              : 
   12034              :   /* If this field is empty and does not have side effects (and is not at
   12035              :      the end of structure), don't do anything other than checking the
   12036              :      initializer.  */
   12037      9607249 :   if (field
   12038      9607249 :       && (TREE_TYPE (field) == error_mark_node
   12039      9606814 :           || (COMPLETE_TYPE_P (TREE_TYPE (field))
   12040      9606505 :               && integer_zerop (TYPE_SIZE (TREE_TYPE (field)))
   12041           62 :               && !TREE_SIDE_EFFECTS (new_value)
   12042           33 :               && (TREE_CODE (constructor_type) == ARRAY_TYPE
   12043           33 :                   || DECL_CHAIN (field)))))
   12044           18 :     return;
   12045              : 
   12046              :   /* Finally, set VALUE to the initializer value digested above.  */
   12047      9607231 :   value = new_value;
   12048              : 
   12049              :   /* If this element doesn't come next in sequence,
   12050              :      put it on constructor_pending_elts.  */
   12051      9607231 :   if (TREE_CODE (constructor_type) == ARRAY_TYPE
   12052      9607231 :       && (!constructor_incremental
   12053      1716783 :           || !tree_int_cst_equal (field, constructor_unfilled_index)
   12054      1716417 :           || (TREE_CODE (value) == RAW_DATA_CST
   12055          233 :               && constructor_pending_elts
   12056           66 :               && pending)))
   12057              :     {
   12058          627 :       if (constructor_incremental
   12059          627 :           && (tree_int_cst_lt (field, constructor_unfilled_index)
   12060          337 :               || (TREE_CODE (value) == RAW_DATA_CST
   12061           14 :                   && constructor_pending_elts
   12062           14 :                   && pending)))
   12063           48 :         set_nonincremental_init (braced_init_obstack);
   12064              : 
   12065          627 :       add_pending_init (loc, field, value, origtype, implicit,
   12066              :                         braced_init_obstack);
   12067          627 :       return;
   12068              :     }
   12069      9606604 :   else if (TREE_CODE (constructor_type) == RECORD_TYPE
   12070      1038895 :            && (!constructor_incremental
   12071      1038555 :                || field != constructor_unfilled_fields))
   12072              :     {
   12073              :       /* We do this for records but not for unions.  In a union,
   12074              :          no matter which field is specified, it can be initialized
   12075              :          right away since it starts at the beginning of the union.  */
   12076         1404 :       if (constructor_incremental)
   12077              :         {
   12078         1064 :           if (!constructor_unfilled_fields)
   12079            5 :             set_nonincremental_init (braced_init_obstack);
   12080              :           else
   12081              :             {
   12082         1059 :               tree bitpos, unfillpos;
   12083              : 
   12084         1059 :               bitpos = bit_position (field);
   12085         1059 :               unfillpos = bit_position (constructor_unfilled_fields);
   12086              : 
   12087         1059 :               if (tree_int_cst_lt (bitpos, unfillpos))
   12088            4 :                 set_nonincremental_init (braced_init_obstack);
   12089              :             }
   12090              :         }
   12091              : 
   12092         1404 :       add_pending_init (loc, field, value, origtype, implicit,
   12093              :                         braced_init_obstack);
   12094         1404 :       return;
   12095              :     }
   12096      9605200 :   else if (TREE_CODE (constructor_type) == UNION_TYPE
   12097      9605200 :            && !vec_safe_is_empty (constructor_elements))
   12098              :     {
   12099           62 :       if (!implicit)
   12100              :         {
   12101           12 :           if (TREE_SIDE_EFFECTS (constructor_elements->last ().value))
   12102            3 :             warning_init (loc, OPT_Woverride_init_side_effects,
   12103              :                           "initialized field with side-effects overwritten");
   12104            9 :           else if (warn_override_init)
   12105            6 :             warning_init (loc, OPT_Woverride_init,
   12106              :                           "initialized field overwritten");
   12107              :         }
   12108              : 
   12109              :       /* We can have just one union field set.  */
   12110           62 :       constructor_elements = NULL;
   12111              :     }
   12112              : 
   12113              :   /* Otherwise, output this element either to
   12114              :      constructor_elements or to the assembler file.  */
   12115              : 
   12116      9605200 :   constructor_elt celt = {field, value};
   12117      9605200 :   vec_safe_push (constructor_elements, celt);
   12118              : 
   12119              :   /* Advance the variable that indicates sequential elements output.  */
   12120      9605200 :   if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   12121              :     {
   12122      1716412 :       tree inc = bitsize_one_node;
   12123      1716412 :       if (value && TREE_CODE (value) == RAW_DATA_CST)
   12124          228 :         inc = bitsize_int (RAW_DATA_LENGTH (value));
   12125      1716412 :       constructor_unfilled_index
   12126      1716412 :         = size_binop_loc (input_location, PLUS_EXPR,
   12127              :                           constructor_unfilled_index, inc);
   12128              :     }
   12129      7888788 :   else if (TREE_CODE (constructor_type) == RECORD_TYPE)
   12130              :     {
   12131      1037491 :       constructor_unfilled_fields
   12132      1037491 :         = DECL_CHAIN (constructor_unfilled_fields);
   12133              : 
   12134              :       /* Skip any nameless bit fields.  */
   12135      1037491 :       while (constructor_unfilled_fields != NULL_TREE
   12136      1037592 :              && DECL_UNNAMED_BIT_FIELD (constructor_unfilled_fields))
   12137          101 :         constructor_unfilled_fields
   12138          101 :           = DECL_CHAIN (constructor_unfilled_fields);
   12139              :     }
   12140      6851297 :   else if (TREE_CODE (constructor_type) == UNION_TYPE)
   12141        31044 :     constructor_unfilled_fields = NULL_TREE;
   12142              : 
   12143              :   /* Now output any pending elements which have become next.  */
   12144      9605200 :   if (pending)
   12145      9602335 :     output_pending_init_elements (0, braced_init_obstack);
   12146              : }
   12147              : 
   12148              : /* For two FIELD_DECLs in the same chain, return -1 if field1
   12149              :    comes before field2, 1 if field1 comes after field2 and
   12150              :    0 if field1 == field2.  */
   12151              : 
   12152              : static int
   12153         4029 : init_field_decl_cmp (tree field1, tree field2)
   12154              : {
   12155         4029 :   if (field1 == field2)
   12156              :     return 0;
   12157              : 
   12158         2154 :   tree bitpos1 = bit_position (field1);
   12159         2154 :   tree bitpos2 = bit_position (field2);
   12160         2154 :   if (tree_int_cst_equal (bitpos1, bitpos2))
   12161              :     {
   12162              :       /* If one of the fields has non-zero bitsize, then that
   12163              :          field must be the last one in a sequence of zero
   12164              :          sized fields, fields after it will have bigger
   12165              :          bit_position.  */
   12166           22 :       if (TREE_TYPE (field1) != error_mark_node
   12167           22 :           && COMPLETE_TYPE_P (TREE_TYPE (field1))
   12168           44 :           && integer_nonzerop (TREE_TYPE (field1)))
   12169              :         return 1;
   12170           22 :       if (TREE_TYPE (field2) != error_mark_node
   12171           22 :           && COMPLETE_TYPE_P (TREE_TYPE (field2))
   12172           37 :           && integer_nonzerop (TREE_TYPE (field2)))
   12173              :         return -1;
   12174              :       /* Otherwise, fallback to DECL_CHAIN walk to find out
   12175              :          which field comes earlier.  Walk chains of both
   12176              :          fields, so that if field1 and field2 are close to each
   12177              :          other in either order, it is found soon even for large
   12178              :          sequences of zero sized fields.  */
   12179              :       tree f1 = field1, f2 = field2;
   12180           22 :       while (1)
   12181              :         {
   12182           22 :           f1 = DECL_CHAIN (f1);
   12183           22 :           f2 = DECL_CHAIN (f2);
   12184           22 :           if (f1 == NULL_TREE)
   12185              :             {
   12186            7 :               gcc_assert (f2);
   12187              :               return 1;
   12188              :             }
   12189           15 :           if (f2 == NULL_TREE)
   12190              :             return -1;
   12191            1 :           if (f1 == field2)
   12192              :             return -1;
   12193            0 :           if (f2 == field1)
   12194              :             return 1;
   12195            0 :           if (!tree_int_cst_equal (bit_position (f1), bitpos1))
   12196              :             return 1;
   12197            0 :           if (!tree_int_cst_equal (bit_position (f2), bitpos1))
   12198              :             return -1;
   12199              :         }
   12200              :     }
   12201         2132 :   else if (tree_int_cst_lt (bitpos1, bitpos2))
   12202              :     return -1;
   12203              :   else
   12204              :     return 1;
   12205              : }
   12206              : 
   12207              : /* Output any pending elements which have become next.
   12208              :    As we output elements, constructor_unfilled_{fields,index}
   12209              :    advances, which may cause other elements to become next;
   12210              :    if so, they too are output.
   12211              : 
   12212              :    If ALL is 0, we return when there are
   12213              :    no more pending elements to output now.
   12214              : 
   12215              :    If ALL is 1, we output space as necessary so that
   12216              :    we can output all the pending elements.  */
   12217              : static void
   12218     11668657 : output_pending_init_elements (int all, struct obstack * braced_init_obstack)
   12219              : {
   12220     11668657 :   struct init_node *elt = constructor_pending_elts;
   12221     11669657 :   tree next;
   12222              : 
   12223     11669657 :  retry:
   12224              : 
   12225              :   /* Look through the whole pending tree.
   12226              :      If we find an element that should be output now,
   12227              :      output it.  Otherwise, set NEXT to the element
   12228              :      that comes first among those still pending.  */
   12229              : 
   12230     11669657 :   next = NULL_TREE;
   12231     11675307 :   while (elt)
   12232              :     {
   12233         7598 :       if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   12234              :         {
   12235         3004 :           if (tree_int_cst_equal (elt->purpose,
   12236              :                                   constructor_unfilled_index))
   12237         1197 :             output_init_element (input_location, elt->value, elt->origtype,
   12238         1197 :                                  true, TREE_TYPE (constructor_type),
   12239              :                                  constructor_unfilled_index, false, false,
   12240              :                                  braced_init_obstack);
   12241         1807 :           else if (tree_int_cst_lt (constructor_unfilled_index,
   12242         1807 :                                     elt->purpose))
   12243              :             {
   12244              :               /* Advance to the next smaller node.  */
   12245          589 :               if (elt->left)
   12246              :                 elt = elt->left;
   12247              :               else
   12248              :                 {
   12249              :                   /* We have reached the smallest node bigger than the
   12250              :                      current unfilled index.  Fill the space first.  */
   12251          209 :                   next = elt->purpose;
   12252          209 :                   break;
   12253              :                 }
   12254              :             }
   12255              :           else
   12256              :             {
   12257              :               /* Advance to the next bigger node.  */
   12258         1218 :               if (elt->right)
   12259              :                 elt = elt->right;
   12260              :               else
   12261              :                 {
   12262              :                   /* We have reached the biggest node in a subtree.  Find
   12263              :                      the parent of it, which is the next bigger node.  */
   12264         1218 :                   while (elt->parent && elt->parent->right == elt)
   12265              :                     elt = elt->parent;
   12266          774 :                   elt = elt->parent;
   12267         1149 :                   if (elt && tree_int_cst_lt (constructor_unfilled_index,
   12268          375 :                                               elt->purpose))
   12269              :                     {
   12270           22 :                       next = elt->purpose;
   12271           22 :                       break;
   12272              :                     }
   12273              :                 }
   12274              :             }
   12275              :         }
   12276         4594 :       else if (RECORD_OR_UNION_TYPE_P (constructor_type))
   12277              :         {
   12278              :           /* If the current record is complete we are done.  */
   12279         4594 :           if (constructor_unfilled_fields == NULL_TREE)
   12280              :             break;
   12281              : 
   12282         3755 :           int cmp = init_field_decl_cmp (constructor_unfilled_fields,
   12283              :                                          elt->purpose);
   12284         3755 :           if (cmp == 0)
   12285         1668 :             output_init_element (input_location, elt->value, elt->origtype,
   12286         1668 :                                  true, TREE_TYPE (elt->purpose),
   12287              :                                  elt->purpose, false, false,
   12288              :                                  braced_init_obstack);
   12289         2087 :           else if (cmp < 0)
   12290              :             {
   12291              :               /* Advance to the next smaller node.  */
   12292         1092 :               if (elt->left)
   12293              :                 elt = elt->left;
   12294              :               else
   12295              :                 {
   12296              :                   /* We have reached the smallest node bigger than the
   12297              :                      current unfilled field.  Fill the space first.  */
   12298          811 :                   next = elt->purpose;
   12299          811 :                   break;
   12300              :                 }
   12301              :             }
   12302              :           else
   12303              :             {
   12304              :               /* Advance to the next bigger node.  */
   12305          995 :               if (elt->right)
   12306              :                 elt = elt->right;
   12307              :               else
   12308              :                 {
   12309              :                   /* We have reached the biggest node in a subtree.  Find
   12310              :                      the parent of it, which is the next bigger node.  */
   12311          735 :                   while (elt->parent && elt->parent->right == elt)
   12312              :                     elt = elt->parent;
   12313          519 :                   elt = elt->parent;
   12314          519 :                   if (elt
   12315          519 :                       && init_field_decl_cmp (constructor_unfilled_fields,
   12316              :                                               elt->purpose) < 0)
   12317              :                     {
   12318           67 :                       next = elt->purpose;
   12319           67 :                       break;
   12320              :                     }
   12321              :                 }
   12322              :             }
   12323              :         }
   12324              :     }
   12325              : 
   12326              :   /* Ordinarily return, but not if we want to output all
   12327              :      and there are elements left.  */
   12328     11669657 :   if (!(all && next != NULL_TREE))
   12329     11668657 :     return;
   12330              : 
   12331              :   /* If it's not incremental, just skip over the gap, so that after
   12332              :      jumping to retry we will output the next successive element.  */
   12333         1000 :   if (RECORD_OR_UNION_TYPE_P (constructor_type))
   12334          808 :     constructor_unfilled_fields = next;
   12335          192 :   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   12336          192 :     constructor_unfilled_index = next;
   12337              : 
   12338              :   /* ELT now points to the node in the pending tree with the next
   12339              :      initializer to output.  */
   12340         1000 :   goto retry;
   12341              : }
   12342              : 
   12343              : /* Expression VALUE coincides with the start of type TYPE in a braced
   12344              :    initializer.  Return true if we should treat VALUE as initializing
   12345              :    the first element of TYPE, false if we should treat it as initializing
   12346              :    TYPE as a whole.
   12347              : 
   12348              :    If the initializer is clearly invalid, the question becomes:
   12349              :    which choice gives the best error message?  */
   12350              : 
   12351              : static bool
   12352      3483402 : initialize_elementwise_p (tree type, tree value)
   12353              : {
   12354      3483402 :   if (type == error_mark_node || value == error_mark_node)
   12355              :     return false;
   12356              : 
   12357      3483136 :   gcc_checking_assert (TYPE_MAIN_VARIANT (type) == type);
   12358              : 
   12359      3483136 :   tree value_type = TREE_TYPE (value);
   12360      3483136 :   if (value_type == error_mark_node)
   12361              :     return false;
   12362              : 
   12363              :   /* GNU vectors can be initialized elementwise.  However, treat any
   12364              :      kind of vector value as initializing the vector type as a whole,
   12365              :      regardless of whether the value is a GNU vector.  Such initializers
   12366              :      are valid if and only if they would have been valid in a non-braced
   12367              :      initializer like:
   12368              : 
   12369              :         TYPE foo = VALUE;
   12370              : 
   12371              :      so recursing into the vector type would be at best confusing or at
   12372              :      worst wrong.  For example, when -flax-vector-conversions is in effect,
   12373              :      it's possible to initialize a V8HI from a V4SI, even though the vectors
   12374              :      have different element types and different numbers of elements.  */
   12375      3483136 :   if (gnu_vector_type_p (type))
   12376        19502 :     return !VECTOR_TYPE_P (value_type);
   12377              : 
   12378      3463634 :   if (AGGREGATE_TYPE_P (type))
   12379      1741321 :     return !comptypes (type, TYPE_MAIN_VARIANT (value_type));
   12380              : 
   12381              :   return false;
   12382              : }
   12383              : 
   12384              : /* Helper function for process_init_element.  Split first element of
   12385              :    RAW_DATA_CST and save the rest to *RAW_DATA.  */
   12386              : 
   12387              : static inline tree
   12388      9604629 : maybe_split_raw_data (tree value, tree *raw_data)
   12389              : {
   12390      9604629 :   if (value == NULL_TREE || TREE_CODE (value) != RAW_DATA_CST)
   12391              :     return value;
   12392          211 :   *raw_data = value;
   12393          211 :   value = build_int_cst (integer_type_node,
   12394          211 :                          RAW_DATA_UCHAR_ELT (*raw_data, 0));
   12395          211 :   ++RAW_DATA_POINTER (*raw_data);
   12396          211 :   --RAW_DATA_LENGTH (*raw_data);
   12397          211 :   return value;
   12398              : }
   12399              : 
   12400              : /* Return non-zero if c_parser_initval should attempt to optimize
   12401              :    large initializers into RAW_DATA_CST.  In that case return how
   12402              :    many elements to optimize at most.  */
   12403              : 
   12404              : unsigned
   12405      2983582 : c_maybe_optimize_large_byte_initializer (void)
   12406              : {
   12407      2983582 :   if (!constructor_type
   12408      2983512 :       || TREE_CODE (constructor_type) != ARRAY_TYPE
   12409       207844 :       || constructor_stack->implicit)
   12410              :     return 0;
   12411       205103 :   tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
   12412       205103 :   if (TREE_CODE (elttype) != INTEGER_TYPE
   12413       205103 :       && TREE_CODE (elttype) != BITINT_TYPE)
   12414              :     return 0;
   12415       182490 :   if (TYPE_PRECISION (elttype) != CHAR_BIT
   12416        27842 :       || constructor_stack->replacement_value.value
   12417        27842 :       || (COMPLETE_TYPE_P (constructor_type)
   12418        26205 :           && !poly_int_tree_p (TYPE_SIZE (constructor_type)))
   12419       210332 :       || constructor_range_stack)
   12420              :     return 0;
   12421        27842 :   if (constructor_max_index == NULL_TREE)
   12422              :     return INT_MAX;
   12423        26205 :   if (tree_int_cst_le (constructor_max_index, constructor_index)
   12424        26205 :       || integer_all_onesp (constructor_max_index))
   12425         4766 :     return 0;
   12426        21439 :   widest_int w = wi::to_widest (constructor_max_index);
   12427        21439 :   w -= wi::to_widest (constructor_index);
   12428        21439 :   w += 1;
   12429        21439 :   if (w < 64)
   12430              :     return 0;
   12431         6888 :   if (w > INT_MAX)
   12432              :     return INT_MAX;
   12433         6888 :   return w.to_uhwi ();
   12434        21439 : }
   12435              : 
   12436              : /* Add one non-braced element to the current constructor level.
   12437              :    This adjusts the current position within the constructor's type.
   12438              :    This may also start or terminate implicit levels
   12439              :    to handle a partly-braced initializer.
   12440              : 
   12441              :    Once this has found the correct level for the new element,
   12442              :    it calls output_init_element.
   12443              : 
   12444              :    IMPLICIT is true if value comes from pop_init_level (1),
   12445              :    the new initializer has been merged with the existing one
   12446              :    and thus no warnings should be emitted about overriding an
   12447              :    existing initializer.  */
   12448              : 
   12449              : void
   12450      9594921 : process_init_element (location_t loc, struct c_expr value, bool implicit,
   12451              :                       struct obstack * braced_init_obstack)
   12452              : {
   12453      9594921 :   tree orig_value = value.value;
   12454     19189842 :   int string_flag
   12455      9594921 :     = (orig_value != NULL_TREE && TREE_CODE (orig_value) == STRING_CST);
   12456      9594921 :   bool strict_string = value.original_code == STRING_CST;
   12457      9594921 :   bool was_designated = designator_depth != 0;
   12458      9594921 :   tree raw_data = NULL_TREE;
   12459              : 
   12460      9595133 : retry:
   12461      9595133 :   designator_depth = 0;
   12462      9595133 :   designator_erroneous = 0;
   12463              : 
   12464      9595133 :   if (!implicit && value.value && !integer_zerop (value.value))
   12465      7574953 :     constructor_zeroinit = 0;
   12466              : 
   12467              :   /* Handle superfluous braces around string cst as in
   12468              :      char x[] = {"foo"}; */
   12469      9595133 :   if (constructor_type
   12470      9595005 :       && !was_designated
   12471      9561083 :       && TREE_CODE (constructor_type) == ARRAY_TYPE
   12472      1704070 :       && INTEGRAL_TYPE_P (TREE_TYPE (constructor_type))
   12473     10330049 :       && integer_zerop (constructor_unfilled_index))
   12474              :     {
   12475       163065 :       if (constructor_stack->replacement_value.value)
   12476              :         {
   12477            8 :           error_init (loc, "excess elements in %qT initializer", constructor_type);
   12478          409 :           return;
   12479              :         }
   12480       163057 :       else if (string_flag)
   12481              :         {
   12482          138 :           constructor_stack->replacement_value = value;
   12483          138 :           return;
   12484              :         }
   12485              :     }
   12486              : 
   12487      9594987 :   if (constructor_stack->replacement_value.value != NULL_TREE)
   12488              :     {
   12489            0 :       error_init (loc, "excess elements in struct initializer");
   12490            0 :       return;
   12491              :     }
   12492              : 
   12493              :   /* Ignore elements of a brace group if it is entirely superfluous
   12494              :      and has already been diagnosed, or if the type is erroneous.  */
   12495      9594987 :   if (constructor_type == NULL_TREE || constructor_type == error_mark_node)
   12496              :     return;
   12497              : 
   12498              :   /* Ignore elements of an initializer for a variable-size type.
   12499              :      Those are diagnosed in the parser (empty initializer braces are OK).  */
   12500      9594790 :   if (COMPLETE_TYPE_P (constructor_type)
   12501      9594790 :       && !poly_int_tree_p (TYPE_SIZE (constructor_type)))
   12502              :     return;
   12503              : 
   12504      8891124 :   if (!implicit && warn_designated_init && !was_designated
   12505      8857819 :       && TREE_CODE (constructor_type) == RECORD_TYPE
   12506     10629558 :       && lookup_attribute ("designated_init",
   12507      1034826 :                            TYPE_ATTRIBUTES (constructor_type)))
   12508           50 :     warning_init (loc,
   12509              :                   OPT_Wdesignated_init,
   12510              :                   "positional initialization of field "
   12511              :                   "in %<struct%> declared with %<designated_init%> attribute");
   12512              : 
   12513              :   /* If we've exhausted any levels that didn't have braces,
   12514              :      pop them now.  */
   12515     10296711 :   while (constructor_stack->implicit)
   12516              :     {
   12517       706825 :       if (RECORD_OR_UNION_TYPE_P (constructor_type)
   12518       702792 :           && constructor_fields == NULL_TREE)
   12519       701738 :         process_init_element (loc,
   12520              :                               pop_init_level (loc, 1, braced_init_obstack,
   12521              :                                               last_init_list_comma),
   12522              :                               true, braced_init_obstack);
   12523         5087 :       else if ((TREE_CODE (constructor_type) == ARRAY_TYPE
   12524         1698 :                 || gnu_vector_type_p (constructor_type))
   12525         4033 :                && constructor_max_index
   12526         9093 :                && tree_int_cst_lt (constructor_max_index,
   12527              :                                    constructor_index))
   12528          241 :         process_init_element (loc,
   12529              :                               pop_init_level (loc, 1, braced_init_obstack,
   12530              :                                               last_init_list_comma),
   12531              :                               true, braced_init_obstack);
   12532              :       else
   12533              :         break;
   12534              :     }
   12535              : 
   12536              :   /* In the case of [LO ... HI] = VALUE, only evaluate VALUE once.  */
   12537      9594732 :   if (constructor_range_stack)
   12538              :     {
   12539              :       /* If value is a compound literal and we'll be just using its
   12540              :          content, don't put it into a SAVE_EXPR.  */
   12541          371 :       if (TREE_CODE (value.value) != COMPOUND_LITERAL_EXPR
   12542            3 :           || !require_constant_value)
   12543              :         {
   12544          368 :           tree semantic_type = NULL_TREE;
   12545          368 :           if (TREE_CODE (value.value) == EXCESS_PRECISION_EXPR)
   12546              :             {
   12547            0 :               semantic_type = TREE_TYPE (value.value);
   12548            0 :               value.value = TREE_OPERAND (value.value, 0);
   12549              :             }
   12550          368 :           value.value = save_expr (value.value);
   12551          368 :           if (semantic_type)
   12552            0 :             value.value = build1 (EXCESS_PRECISION_EXPR, semantic_type,
   12553              :                                   value.value);
   12554              :         }
   12555              :     }
   12556              : 
   12557     10308962 :   while (1)
   12558              :     {
   12559     10308962 :       if (TREE_CODE (constructor_type) == RECORD_TYPE)
   12560              :         {
   12561      1038965 :           tree fieldtype;
   12562      1038965 :           enum tree_code fieldcode;
   12563              : 
   12564      1038965 :           if (constructor_fields == NULL_TREE)
   12565              :             {
   12566         1280 :               pedwarn_init (loc, 0, "excess elements in struct initializer");
   12567         1280 :               break;
   12568              :             }
   12569              : 
   12570      1037685 :           fieldtype = TREE_TYPE (constructor_fields);
   12571      1037685 :           if (fieldtype != error_mark_node)
   12572      1037684 :             fieldtype = TYPE_MAIN_VARIANT (fieldtype);
   12573      1037685 :           fieldcode = TREE_CODE (fieldtype);
   12574              : 
   12575              :           /* Error for non-static initialization of a flexible array member.  */
   12576      1037685 :           if (fieldcode == ARRAY_TYPE
   12577       155274 :               && !require_constant_value
   12578         1124 :               && TYPE_SIZE (fieldtype) == NULL_TREE
   12579      1037695 :               && DECL_CHAIN (constructor_fields) == NULL_TREE)
   12580              :             {
   12581           10 :               error_init (loc, "non-static initialization of a flexible "
   12582              :                           "array member");
   12583           10 :               break;
   12584              :             }
   12585              : 
   12586              :           /* Error for initialization of a flexible array member with
   12587              :              a string constant if the structure is in an array.  E.g.:
   12588              :              struct S { int x; char y[]; };
   12589              :              struct S s[] = { { 1, "foo" } };
   12590              :              is invalid.  */
   12591      1037675 :           if (string_flag
   12592      1037675 :               && fieldcode == ARRAY_TYPE
   12593         3353 :               && constructor_depth > 1
   12594          489 :               && TYPE_SIZE (fieldtype) == NULL_TREE
   12595      1037722 :               && DECL_CHAIN (constructor_fields) == NULL_TREE)
   12596              :             {
   12597           47 :               bool in_array_p = false;
   12598           47 :               for (struct constructor_stack *p = constructor_stack;
   12599           73 :                    p && p->type; p = p->next)
   12600           59 :                 if (TREE_CODE (p->type) == ARRAY_TYPE)
   12601              :                   {
   12602              :                     in_array_p = true;
   12603              :                     break;
   12604              :                   }
   12605           47 :               if (in_array_p)
   12606              :                 {
   12607           33 :                   error_init (loc, "initialization of flexible array "
   12608              :                               "member in a nested context");
   12609           33 :                   break;
   12610              :                 }
   12611              :             }
   12612              : 
   12613              :           /* Accept a string constant to initialize a subarray.  */
   12614      1037642 :           if (value.value != NULL_TREE
   12615      1037569 :               && fieldcode == ARRAY_TYPE
   12616       155158 :               && INTEGRAL_TYPE_P (TREE_TYPE (fieldtype))
   12617      1192317 :               && string_flag)
   12618              :             value.value = orig_value;
   12619              :           /* Otherwise, if we have come to a subaggregate,
   12620              :              and we don't have an element of its type, push into it.  */
   12621      1034624 :           else if (value.value != NULL_TREE
   12622      1034322 :                    && initialize_elementwise_p (fieldtype, value.value))
   12623              :             {
   12624          302 :               push_init_level (loc, 1, braced_init_obstack);
   12625          302 :               continue;
   12626              :             }
   12627              : 
   12628      1037340 :           value.value = maybe_split_raw_data (value.value, &raw_data);
   12629      1037340 :           if (value.value)
   12630              :             {
   12631      1037267 :               push_member_name (constructor_fields);
   12632      1037267 :               output_init_element (loc, value.value, value.original_type,
   12633              :                                    strict_string, fieldtype,
   12634              :                                    constructor_fields, true, implicit,
   12635              :                                    braced_init_obstack);
   12636      1037267 :               RESTORE_SPELLING_DEPTH (constructor_depth);
   12637              :             }
   12638              :           else
   12639              :             /* Do the bookkeeping for an element that was
   12640              :                directly output as a constructor.  */
   12641              :             {
   12642              :               /* For a record, keep track of end position of last field.  */
   12643           73 :               if (DECL_SIZE (constructor_fields))
   12644           30 :                 constructor_bit_index
   12645           30 :                   = size_binop_loc (input_location, PLUS_EXPR,
   12646              :                                     bit_position (constructor_fields),
   12647           30 :                                     DECL_SIZE (constructor_fields));
   12648              : 
   12649              :               /* If the current field was the first one not yet written out,
   12650              :                  it isn't now, so update.  */
   12651           73 :               if (constructor_unfilled_fields == constructor_fields)
   12652              :                 {
   12653           64 :                   constructor_unfilled_fields = DECL_CHAIN (constructor_fields);
   12654              :                   /* Skip any nameless bit fields.  */
   12655           64 :                   while (constructor_unfilled_fields != 0
   12656           64 :                          && (DECL_UNNAMED_BIT_FIELD
   12657              :                              (constructor_unfilled_fields)))
   12658            0 :                     constructor_unfilled_fields =
   12659            0 :                       DECL_CHAIN (constructor_unfilled_fields);
   12660              :                 }
   12661              :             }
   12662              : 
   12663      1037340 :           constructor_fields = DECL_CHAIN (constructor_fields);
   12664              :           /* Skip any nameless bit fields at the beginning.  */
   12665      1037340 :           while (constructor_fields != NULL_TREE
   12666      1037441 :                  && DECL_UNNAMED_BIT_FIELD (constructor_fields))
   12667          101 :             constructor_fields = DECL_CHAIN (constructor_fields);
   12668              :         }
   12669      9269997 :       else if (TREE_CODE (constructor_type) == UNION_TYPE)
   12670              :         {
   12671        31107 :           tree fieldtype;
   12672        31107 :           enum tree_code fieldcode;
   12673              : 
   12674        31107 :           if (constructor_fields == NULL_TREE)
   12675              :             {
   12676            3 :               pedwarn_init (loc, 0,
   12677              :                             "excess elements in union initializer");
   12678            3 :               break;
   12679              :             }
   12680              : 
   12681        31104 :           fieldtype = TREE_TYPE (constructor_fields);
   12682        31104 :           if (fieldtype != error_mark_node)
   12683        31104 :             fieldtype = TYPE_MAIN_VARIANT (fieldtype);
   12684        31104 :           fieldcode = TREE_CODE (fieldtype);
   12685              : 
   12686              :           /* Warn that traditional C rejects initialization of unions.
   12687              :              We skip the warning if the value is zero.  This is done
   12688              :              under the assumption that the zero initializer in user
   12689              :              code appears conditioned on e.g. __STDC__ to avoid
   12690              :              "missing initializer" warnings and relies on default
   12691              :              initialization to zero in the traditional C case.
   12692              :              We also skip the warning if the initializer is designated,
   12693              :              again on the assumption that this must be conditional on
   12694              :              __STDC__ anyway (and we've already complained about the
   12695              :              member-designator already).  */
   12696        33344 :           if (!in_system_header_at (input_location) && !constructor_designated
   12697        32583 :               && !(value.value && (integer_zerop (value.value)
   12698         1372 :                                    || real_zerop (value.value))))
   12699         1365 :             warning (OPT_Wtraditional, "traditional C rejects initialization "
   12700              :                      "of unions");
   12701              : 
   12702              :           /* Error for non-static initialization of a flexible array member.  */
   12703        31104 :           if (fieldcode == ARRAY_TYPE
   12704          766 :               && !require_constant_value
   12705        31161 :               && TYPE_SIZE (fieldtype) == NULL_TREE)
   12706              :             {
   12707            3 :               error_init (loc, "non-static initialization of a flexible "
   12708              :                           "array member");
   12709            3 :               break;
   12710              :             }
   12711              : 
   12712              :           /* Error for initialization of a flexible array member with
   12713              :              a string constant if the structure is in an array.  E.g.:
   12714              :              union U { int x; char y[]; };
   12715              :              union U s[] = { { 1, "foo" } };
   12716              :              is invalid.  */
   12717        31101 :           if (string_flag
   12718        31101 :               && fieldcode == ARRAY_TYPE
   12719            7 :               && constructor_depth > 1
   12720        31105 :               && TYPE_SIZE (fieldtype) == NULL_TREE)
   12721              :             {
   12722            3 :               bool in_array_p = false;
   12723            3 :               for (struct constructor_stack *p = constructor_stack;
   12724            3 :                    p && p->type; p = p->next)
   12725            3 :                 if (TREE_CODE (p->type) == ARRAY_TYPE)
   12726              :                   {
   12727              :                     in_array_p = true;
   12728              :                     break;
   12729              :                   }
   12730            3 :               if (in_array_p)
   12731              :                 {
   12732            3 :                   error_init (loc, "initialization of flexible array "
   12733              :                               "member in a nested context");
   12734            3 :                   break;
   12735              :                 }
   12736              :             }
   12737              : 
   12738              :           /* Accept a string constant to initialize a subarray.  */
   12739        31098 :           if (value.value != NULL_TREE
   12740        31098 :               && fieldcode == ARRAY_TYPE
   12741          760 :               && INTEGRAL_TYPE_P (TREE_TYPE (fieldtype))
   12742        31853 :               && string_flag)
   12743              :             value.value = orig_value;
   12744              :           /* Otherwise, if we have come to a subaggregate,
   12745              :              and we don't have an element of its type, push into it.  */
   12746        31144 :           else if (value.value != NULL_TREE
   12747        31094 :                    && initialize_elementwise_p (fieldtype, value.value))
   12748              :             {
   12749           50 :               push_init_level (loc, 1, braced_init_obstack);
   12750           50 :               continue;
   12751              :             }
   12752              : 
   12753        31048 :           value.value = maybe_split_raw_data (value.value, &raw_data);
   12754        31048 :           if (value.value)
   12755              :             {
   12756        31048 :               push_member_name (constructor_fields);
   12757        31048 :               output_init_element (loc, value.value, value.original_type,
   12758              :                                    strict_string, fieldtype,
   12759              :                                    constructor_fields, true, implicit,
   12760              :                                    braced_init_obstack);
   12761        31048 :               RESTORE_SPELLING_DEPTH (constructor_depth);
   12762              :             }
   12763              :           else
   12764              :             /* Do the bookkeeping for an element that was
   12765              :                directly output as a constructor.  */
   12766              :             {
   12767            0 :               constructor_bit_index = DECL_SIZE (constructor_fields);
   12768            0 :               constructor_unfilled_fields = DECL_CHAIN (constructor_fields);
   12769              :             }
   12770              : 
   12771        31048 :           constructor_fields = NULL_TREE;
   12772              :         }
   12773      9238890 :       else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
   12774              :         {
   12775      2418555 :           tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
   12776      2418555 :           enum tree_code eltcode = TREE_CODE (elttype);
   12777              : 
   12778              :           /* Accept a string constant to initialize a subarray.  */
   12779      2418555 :           if (value.value != NULL_TREE
   12780      2418555 :               && eltcode == ARRAY_TYPE
   12781         7013 :               && INTEGRAL_TYPE_P (TREE_TYPE (elttype))
   12782      2424087 :               && string_flag)
   12783              :             value.value = orig_value;
   12784              :           /* Otherwise, if we have come to a subaggregate,
   12785              :              and we don't have an element of its type, push into it.  */
   12786      3120373 :           else if (value.value != NULL_TREE
   12787      2418059 :                    && initialize_elementwise_p (elttype, value.value))
   12788              :             {
   12789       702314 :               push_init_level (loc, 1, braced_init_obstack);
   12790       702314 :               continue;
   12791              :             }
   12792              : 
   12793      1716241 :           if (constructor_max_index != NULL_TREE
   12794       673320 :               && (tree_int_cst_lt (constructor_max_index, constructor_index)
   12795       673205 :                   || integer_all_onesp (constructor_max_index))
   12796              :               /* For VLA we got an error already.  */
   12797      1716356 :               && !C_TYPE_VARIABLE_SIZE (constructor_type))
   12798              :             {
   12799          113 :               pedwarn_init (loc, 0,
   12800              :                             "excess elements in array initializer");
   12801          113 :               break;
   12802              :             }
   12803              : 
   12804      1716128 :           if (value.value
   12805      1716128 :               && TREE_CODE (value.value) == RAW_DATA_CST
   12806          191 :               && RAW_DATA_LENGTH (value.value) > 1
   12807          191 :               && (TREE_CODE (elttype) == INTEGER_TYPE
   12808          191 :                   || TREE_CODE (elttype) == BITINT_TYPE)
   12809          191 :               && TYPE_PRECISION (elttype) == CHAR_BIT
   12810      1716319 :               && (constructor_max_index == NULL_TREE
   12811           53 :                   || tree_int_cst_lt (constructor_index,
   12812              :                                       constructor_max_index)))
   12813              :             {
   12814          191 :               unsigned int len = RAW_DATA_LENGTH (value.value);
   12815          191 :               if (constructor_max_index)
   12816              :                 {
   12817           53 :                   widest_int w = wi::to_widest (constructor_max_index);
   12818           53 :                   w -= wi::to_widest (constructor_index);
   12819           53 :                   w += 1;
   12820           53 :                   if (w < len)
   12821            3 :                     len = w.to_uhwi ();
   12822           53 :                 }
   12823          191 :               if (len < (unsigned) RAW_DATA_LENGTH (value.value))
   12824              :                 {
   12825            3 :                   raw_data = copy_node (value.value);
   12826            3 :                   RAW_DATA_LENGTH (raw_data) -= len;
   12827            3 :                   RAW_DATA_POINTER (raw_data) += len;
   12828            3 :                   RAW_DATA_LENGTH (value.value) = len;
   12829              :                 }
   12830          191 :               TREE_TYPE (value.value) = elttype;
   12831          191 :               push_array_bounds (tree_to_uhwi (constructor_index));
   12832          191 :               output_init_element (loc, value.value, value.original_type,
   12833              :                                    false, elttype, constructor_index, true,
   12834              :                                    implicit, braced_init_obstack);
   12835          191 :               RESTORE_SPELLING_DEPTH (constructor_depth);
   12836          191 :               constructor_index
   12837          191 :                 = size_binop_loc (input_location, PLUS_EXPR,
   12838          191 :                                   constructor_index, bitsize_int (len));
   12839              :             }
   12840              :           else
   12841              :             {
   12842      1715937 :               value.value = maybe_split_raw_data (value.value, &raw_data);
   12843              :               /* Now output the actual element.  */
   12844      1715937 :               if (value.value)
   12845              :                 {
   12846      1715937 :                   push_array_bounds (tree_to_uhwi (constructor_index));
   12847      1715937 :                   output_init_element (loc, value.value, value.original_type,
   12848              :                                        strict_string, elttype,
   12849              :                                        constructor_index, true, implicit,
   12850              :                                        braced_init_obstack);
   12851      1715937 :                   RESTORE_SPELLING_DEPTH (constructor_depth);
   12852              :                 }
   12853              : 
   12854      1715937 :               constructor_index
   12855      1715937 :                 = size_binop_loc (input_location, PLUS_EXPR,
   12856              :                                   constructor_index, bitsize_one_node);
   12857              : 
   12858      1715937 :               if (!value.value)
   12859              :                 /* If we are doing the bookkeeping for an element that was
   12860              :                    directly output as a constructor, we must update
   12861              :                    constructor_unfilled_index.  */
   12862            0 :                 constructor_unfilled_index = constructor_index;
   12863              :             }
   12864              :         }
   12865      6820335 :       else if (gnu_vector_type_p (constructor_type))
   12866              :         {
   12867      6819843 :           tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
   12868              : 
   12869              :           /* Do a basic check of initializer size.  Note that vectors
   12870              :              may not always have a fixed size derived from their type.  */
   12871      6819843 :           if (maybe_lt (tree_to_poly_uint64 (constructor_max_index),
   12872      6819843 :                         tree_to_poly_uint64 (constructor_index)))
   12873              :             {
   12874              :               /* Diagose VLA out-of-bounds as errors.  */
   12875            2 :               if (tree_to_poly_uint64 (constructor_max_index).is_constant())
   12876            2 :                 pedwarn_init (loc, 0,
   12877              :                               "excess elements in vector initializer");
   12878              :               else
   12879              :                 error_init (loc, "excess elements in vector initializer");
   12880              : 
   12881              :               break;
   12882              :             }
   12883              : 
   12884      6819841 :           value.value = maybe_split_raw_data (value.value, &raw_data);
   12885              :           /* Now output the actual element.  */
   12886      6819841 :           if (value.value)
   12887              :             {
   12888      6819841 :               if (TREE_CODE (value.value) == VECTOR_CST)
   12889            0 :                 elttype = TYPE_MAIN_VARIANT (constructor_type);
   12890      6819841 :               output_init_element (loc, value.value, value.original_type,
   12891              :                                    strict_string, elttype,
   12892              :                                    constructor_index, true, implicit,
   12893              :                                    braced_init_obstack);
   12894              :             }
   12895              : 
   12896      6819841 :           constructor_index
   12897      6819841 :             = size_binop_loc (input_location,
   12898              :                               PLUS_EXPR, constructor_index, bitsize_one_node);
   12899              : 
   12900      6819841 :           if (!value.value)
   12901              :             /* If we are doing the bookkeeping for an element that was
   12902              :                directly output as a constructor, we must update
   12903              :                constructor_unfilled_index.  */
   12904            0 :             constructor_unfilled_index = constructor_index;
   12905              :         }
   12906              : 
   12907              :       /* Handle the sole element allowed in a braced initializer
   12908              :          for a scalar variable.  */
   12909          492 :       else if (constructor_type != error_mark_node
   12910          492 :                && constructor_fields == NULL_TREE)
   12911              :         {
   12912           29 :           pedwarn_init (loc, 0,
   12913              :                         "excess elements in scalar initializer");
   12914           29 :           break;
   12915              :         }
   12916              :       else
   12917              :         {
   12918          463 :           value.value = maybe_split_raw_data (value.value, &raw_data);
   12919          463 :           if (value.value)
   12920          463 :             output_init_element (loc, value.value, value.original_type,
   12921              :                                  strict_string, constructor_type,
   12922              :                                  NULL_TREE, true, implicit,
   12923              :                                  braced_init_obstack);
   12924          463 :           constructor_fields = NULL_TREE;
   12925              :         }
   12926              : 
   12927              :       /* Handle range initializers either at this level or anywhere higher
   12928              :          in the designator stack.  */
   12929      9604820 :       if (constructor_range_stack)
   12930              :         {
   12931        11564 :           struct constructor_range_stack *p, *range_stack;
   12932        11564 :           int finish = 0;
   12933              : 
   12934        11564 :           range_stack = constructor_range_stack;
   12935        11564 :           constructor_range_stack = 0;
   12936        11564 :           while (constructor_stack != range_stack->stack)
   12937              :             {
   12938            0 :               gcc_assert (constructor_stack->implicit);
   12939            0 :               process_init_element (loc,
   12940              :                                     pop_init_level (loc, 1,
   12941              :                                                     braced_init_obstack,
   12942              :                                                     last_init_list_comma),
   12943              :                                     true, braced_init_obstack);
   12944              :             }
   12945          325 :           for (p = range_stack;
   12946        11889 :                !p->range_end || tree_int_cst_equal (p->index, p->range_end);
   12947          325 :                p = p->prev)
   12948              :             {
   12949          325 :               gcc_assert (constructor_stack->implicit);
   12950          325 :               process_init_element (loc,
   12951              :                                     pop_init_level (loc, 1,
   12952              :                                                     braced_init_obstack,
   12953              :                                                     last_init_list_comma),
   12954              :                                     true, braced_init_obstack);
   12955              :             }
   12956              : 
   12957        11564 :           p->index = size_binop_loc (input_location,
   12958              :                                      PLUS_EXPR, p->index, bitsize_one_node);
   12959        11564 :           if (tree_int_cst_equal (p->index, p->range_end) && !p->prev)
   12960          379 :             finish = 1;
   12961              : 
   12962        11889 :           while (1)
   12963              :             {
   12964        11889 :               constructor_index = p->index;
   12965        11889 :               constructor_fields = p->fields;
   12966        11889 :               if (finish && p->range_end && p->index == p->range_start)
   12967              :                 {
   12968            8 :                   finish = 0;
   12969            8 :                   p->prev = 0;
   12970              :                 }
   12971        11889 :               p = p->next;
   12972        11889 :               if (!p)
   12973              :                 break;
   12974          325 :               finish_implicit_inits (loc, braced_init_obstack);
   12975          325 :               push_init_level (loc, 2, braced_init_obstack);
   12976          325 :               p->stack = constructor_stack;
   12977          325 :               if (p->range_end && tree_int_cst_equal (p->index, p->range_end))
   12978           33 :                 p->index = p->range_start;
   12979              :             }
   12980              : 
   12981        11564 :           if (!finish)
   12982        11193 :             constructor_range_stack = range_stack;
   12983        11564 :           continue;
   12984        11564 :         }
   12985              : 
   12986              :       break;
   12987              :     }
   12988              : 
   12989      9594732 :   constructor_range_stack = 0;
   12990              : 
   12991      9594732 :   if (raw_data && RAW_DATA_LENGTH (raw_data))
   12992              :     {
   12993          212 :       gcc_assert (!string_flag && !was_designated);
   12994          212 :       value.value = raw_data;
   12995          212 :       raw_data = NULL_TREE;
   12996          212 :       goto retry;
   12997              :     }
   12998              : }
   12999              : 
   13000              : /* Build a complete asm-statement, whose components are a CV_QUALIFIER
   13001              :    (guaranteed to be 'volatile' or null) and ARGS (represented using
   13002              :    an ASM_EXPR node).  */
   13003              : tree
   13004       204782 : build_asm_stmt (bool is_volatile, tree args)
   13005              : {
   13006       204782 :   if (is_volatile)
   13007       164985 :     ASM_VOLATILE_P (args) = 1;
   13008       204782 :   return add_stmt (args);
   13009              : }
   13010              : 
   13011              : /* Build an asm-expr, whose components are a STRING, some OUTPUTS,
   13012              :    some INPUTS, and some CLOBBERS.  The latter three may be NULL.
   13013              :    SIMPLE indicates whether there was anything at all after the
   13014              :    string in the asm expression -- asm("blah") and asm("blah" : )
   13015              :    are subtly different.  We use a ASM_EXPR node to represent this.
   13016              :    LOC is the location of the asm, and IS_INLINE says whether this
   13017              :    is asm inline.  */
   13018              : tree
   13019       204834 : build_asm_expr (location_t loc, tree string, tree outputs, tree inputs,
   13020              :                 tree clobbers, tree labels, bool simple, bool is_inline)
   13021              : {
   13022       204834 :   tree tail;
   13023       204834 :   tree args;
   13024       204834 :   int i;
   13025       204834 :   const char *constraint;
   13026       204834 :   const char **oconstraints;
   13027       204834 :   bool allows_mem, allows_reg, is_inout;
   13028       204834 :   int ninputs, noutputs;
   13029              : 
   13030       204834 :   ninputs = list_length (inputs);
   13031       204834 :   noutputs = list_length (outputs);
   13032       204834 :   oconstraints = (const char **) alloca (noutputs * sizeof (const char *));
   13033              : 
   13034       204834 :   string = resolve_asm_operand_names (string, outputs, inputs, labels);
   13035              : 
   13036              :   /* Remove output conversions that change the type but not the mode.  */
   13037       553638 :   for (i = 0, tail = outputs; tail; ++i, tail = TREE_CHAIN (tail))
   13038              :     {
   13039       348804 :       tree output = TREE_VALUE (tail);
   13040              : 
   13041       348804 :       output = c_fully_fold (output, false, NULL, true);
   13042              : 
   13043              :       /* ??? Really, this should not be here.  Users should be using a
   13044              :          proper lvalue, dammit.  But there's a long history of using casts
   13045              :          in the output operands.  In cases like longlong.h, this becomes a
   13046              :          primitive form of typechecking -- if the cast can be removed, then
   13047              :          the output operand had a type of the proper width; otherwise we'll
   13048              :          get an error.  Gross, but ...  */
   13049       348804 :       STRIP_NOPS (output);
   13050              : 
   13051       348804 :       if (!lvalue_or_else (loc, output, lv_asm))
   13052            4 :         output = error_mark_node;
   13053              : 
   13054       348804 :       if (output != error_mark_node
   13055       348804 :           && (TREE_READONLY (output)
   13056       348797 :               || TYPE_READONLY (TREE_TYPE (output))
   13057       348797 :               || (RECORD_OR_UNION_TYPE_P (TREE_TYPE (output))
   13058          112 :                   && C_TYPE_FIELDS_READONLY (TREE_TYPE (output)))))
   13059            2 :         readonly_error (loc, output, lv_asm);
   13060              : 
   13061       348804 :       constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail)));
   13062       348804 :       oconstraints[i] = constraint;
   13063              : 
   13064       348804 :       if (parse_output_constraint (&constraint, i, ninputs, noutputs,
   13065              :                                    &allows_mem, &allows_reg, &is_inout,
   13066              :                                    nullptr))
   13067              :         {
   13068              :           /* If the operand is going to end up in memory,
   13069              :              mark it addressable.  */
   13070       348796 :           if (!allows_reg && !c_mark_addressable (output))
   13071            3 :             output = error_mark_node;
   13072         1419 :           if (!(!allows_reg && allows_mem)
   13073       347377 :               && output != error_mark_node
   13074       696171 :               && VOID_TYPE_P (TREE_TYPE (output)))
   13075              :             {
   13076            4 :               error_at (loc, "invalid use of void expression");
   13077            4 :               output = error_mark_node;
   13078              :             }
   13079       348796 :           if (allows_reg && current_function_decl == NULL_TREE)
   13080              :             {
   13081            1 :               error_at (loc, "constraint allows registers outside of "
   13082              :                              "a function");
   13083            1 :               output = error_mark_node;
   13084              :             }
   13085              :         }
   13086              :       else
   13087            8 :         output = error_mark_node;
   13088              : 
   13089       348804 :       if (current_function_decl == NULL_TREE && output != error_mark_node)
   13090              :         {
   13091            7 :           if (TREE_SIDE_EFFECTS (output))
   13092              :             {
   13093            0 :               error_at (loc, "side-effects in output operand outside "
   13094              :                              "of a function");
   13095            0 :               output = error_mark_node;
   13096              :             }
   13097              :           else
   13098              :             {
   13099            7 :               tree addr = build_unary_op (loc, ADDR_EXPR, output, false);
   13100            7 :               if (addr == error_mark_node)
   13101              :                 output = error_mark_node;
   13102            7 :               else if (!initializer_constant_valid_p (addr, TREE_TYPE (addr)))
   13103              :                 {
   13104            1 :                   error_at (loc, "output operand outside of a function is not "
   13105              :                                  "constant");
   13106            1 :                   output = error_mark_node;
   13107              :                 }
   13108              :             }
   13109              :         }
   13110       348797 :       else if (output != error_mark_node && strstr (constraint, "-"))
   13111              :         {
   13112            1 :           error_at (loc, "%<-%> modifier used inside of a function");
   13113            1 :           output = error_mark_node;
   13114              :         }
   13115              : 
   13116       348804 :       TREE_VALUE (tail) = output;
   13117              :     }
   13118              : 
   13119       568862 :   for (i = 0, tail = inputs; tail; ++i, tail = TREE_CHAIN (tail))
   13120              :     {
   13121       364028 :       tree input;
   13122              : 
   13123       364028 :       constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail)));
   13124       364028 :       input = TREE_VALUE (tail);
   13125              : 
   13126       364028 :       if (parse_input_constraint (&constraint, i, ninputs, noutputs, 0,
   13127              :                                   oconstraints, &allows_mem, &allows_reg,
   13128              :                                   nullptr))
   13129              :         {
   13130              :           /* If the operand is going to end up in memory,
   13131              :              mark it addressable.  */
   13132       364020 :           if (!allows_reg && allows_mem)
   13133              :             {
   13134         1363 :               input = c_fully_fold (input, false, NULL, true);
   13135              : 
   13136              :               /* Strip the nops as we allow this case.  FIXME, this really
   13137              :                  should be rejected or made deprecated.  */
   13138         1363 :               STRIP_NOPS (input);
   13139         1363 :               if (!c_mark_addressable (input))
   13140            2 :                 input = error_mark_node;
   13141              :             }
   13142              :           else
   13143              :             {
   13144       362657 :               input = c_fully_fold (convert_lvalue_to_rvalue (loc, input,
   13145              :                                                               true, false),
   13146              :                                     false, NULL);
   13147              : 
   13148       362657 :               if (input != error_mark_node && VOID_TYPE_P (TREE_TYPE (input)))
   13149              :                 {
   13150            4 :                   error_at (loc, "invalid use of void expression");
   13151            4 :                   input = error_mark_node;
   13152              :                 }
   13153              :             }
   13154       364020 :           if (allows_reg && current_function_decl == NULL_TREE)
   13155              :             {
   13156            1 :               error_at (loc, "constraint allows registers outside of "
   13157              :                              "a function");
   13158            1 :               input = error_mark_node;
   13159              :             }
   13160       364020 :           if (constraint[0] == ':' && input != error_mark_node)
   13161              :             {
   13162           35 :               tree t = input;
   13163           35 :               STRIP_NOPS (t);
   13164           35 :               if (TREE_CODE (t) != ADDR_EXPR
   13165           35 :                   || !(TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
   13166           23 :                        || (VAR_P (TREE_OPERAND (t, 0))
   13167           21 :                            && is_global_var (TREE_OPERAND (t, 0)))))
   13168              :                 {
   13169            5 :                   error_at (loc, "%<:%> constraint operand is not address "
   13170              :                                  "of a function or non-automatic variable");
   13171            5 :                   input = error_mark_node;
   13172              :                 }
   13173           30 :               else if (TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL)
   13174           10 :                 suppress_warning (TREE_OPERAND (t, 0), OPT_Wunused);
   13175              :             }
   13176              :         }
   13177              :       else
   13178            8 :         input = error_mark_node;
   13179              : 
   13180       364028 :       if (current_function_decl == NULL_TREE && input != error_mark_node)
   13181              :         {
   13182           58 :           if (TREE_SIDE_EFFECTS (input))
   13183              :             {
   13184            2 :               error_at (loc, "side-effects in input operand outside "
   13185              :                              "of a function");
   13186            2 :               input = error_mark_node;
   13187              :             }
   13188              :           else
   13189              :             {
   13190           56 :               tree tem = input;
   13191           56 :               if (allows_mem && lvalue_p (input))
   13192            7 :                 tem = build_unary_op (loc, ADDR_EXPR, input, false);
   13193           56 :               if (!initializer_constant_valid_p (tem, TREE_TYPE (tem)))
   13194              :                 {
   13195            2 :                   error_at (loc, "input operand outside of a function is not "
   13196              :                                  "constant");
   13197            2 :                   input = error_mark_node;
   13198              :                 }
   13199              :             }
   13200              :         }
   13201       363970 :       else if (input != error_mark_node && strstr (constraint, "-"))
   13202              :         {
   13203            3 :           error_at (loc, "%<-%> modifier used inside of a function");
   13204            3 :           input = error_mark_node;
   13205              :         }
   13206              : 
   13207       364028 :       TREE_VALUE (tail) = input;
   13208              :     }
   13209              : 
   13210       204834 :   args = build_stmt (loc, ASM_EXPR, string, outputs, inputs, clobbers, labels);
   13211              : 
   13212              :   /* asm statements without outputs, including simple ones, are treated
   13213              :      as volatile.  */
   13214       204834 :   ASM_BASIC_P (args) = simple;
   13215       204834 :   ASM_VOLATILE_P (args) = (noutputs == 0);
   13216       204834 :   ASM_INLINE_P (args) = is_inline;
   13217              : 
   13218       204834 :   return args;
   13219              : }
   13220              : 
   13221              : /* Generate a goto statement to LABEL.  LOC is the location of the
   13222              :    GOTO.  */
   13223              : 
   13224              : tree
   13225        82687 : c_finish_goto_label (location_t loc, tree label)
   13226              : {
   13227        82687 :   tree decl = lookup_label_for_goto (loc, label);
   13228        82687 :   if (!decl)
   13229              :     return NULL_TREE;
   13230        82687 :   TREE_USED (decl) = 1;
   13231        82687 :   mark_decl_used (decl, false);
   13232        82687 :   {
   13233        82687 :     add_stmt (build_predict_expr (PRED_GOTO, NOT_TAKEN));
   13234        82687 :     tree t = build1 (GOTO_EXPR, void_type_node, decl);
   13235        82687 :     SET_EXPR_LOCATION (t, loc);
   13236        82687 :     return add_stmt (t);
   13237              :   }
   13238              : }
   13239              : 
   13240              : /* Generate a computed goto statement to EXPR.  LOC is the location of
   13241              :    the GOTO.  */
   13242              : 
   13243              : tree
   13244          940 : c_finish_goto_ptr (location_t loc, c_expr val)
   13245              : {
   13246          940 :   tree expr = val.value;
   13247          940 :   tree t;
   13248          940 :   pedwarn (loc, OPT_Wpedantic, "ISO C forbids %<goto *expr;%>");
   13249          940 :   if (expr != error_mark_node
   13250          939 :       && !POINTER_TYPE_P (TREE_TYPE (expr))
   13251          945 :       && !null_pointer_constant_p (expr))
   13252              :     {
   13253            2 :       error_at (val.get_location (),
   13254              :                 "computed goto must be pointer type");
   13255            2 :       expr = build_zero_cst (ptr_type_node);
   13256              :     }
   13257          940 :   expr = c_fully_fold (expr, false, NULL);
   13258          940 :   expr = convert (ptr_type_node, expr);
   13259          940 :   t = build1 (GOTO_EXPR, void_type_node, expr);
   13260          940 :   SET_EXPR_LOCATION (t, loc);
   13261          940 :   return add_stmt (t);
   13262              : }
   13263              : 
   13264              : /* Generate a C `return' statement.  RETVAL is the expression for what
   13265              :    to return, or a null pointer for `return;' with no value.  LOC is
   13266              :    the location of the return statement, or the location of the expression,
   13267              :    if the statement has any.  If ORIGTYPE is not NULL_TREE, it
   13268              :    is the original type of RETVAL.  MUSTTAIL_P indicates a musttail
   13269              :    attribute.  */
   13270              : 
   13271              : tree
   13272     34580781 : c_finish_return (location_t loc, tree retval, tree origtype, bool musttail_p)
   13273              : {
   13274     34580781 :   tree valtype = TREE_TYPE (TREE_TYPE (current_function_decl)), ret_stmt;
   13275     34580781 :   bool no_warning = false;
   13276     34580781 :   bool npc = false;
   13277              : 
   13278              :   /* Use the expansion point to handle cases such as returning NULL
   13279              :      in a function returning void.  */
   13280     34580781 :   location_t xloc = expansion_point_location_if_in_system_header (loc);
   13281              : 
   13282     34580781 :   if (TREE_THIS_VOLATILE (current_function_decl))
   13283           23 :     warning_at (xloc, 0,
   13284              :                 "function declared %<noreturn%> has a %<return%> statement");
   13285              : 
   13286     34580781 :   set_musttail_on_return (retval, xloc, musttail_p);
   13287              : 
   13288     34580781 :   if (retval)
   13289              :     {
   13290     34559561 :       tree semantic_type = NULL_TREE;
   13291     34559561 :       npc = null_pointer_constant_p (retval);
   13292     34559561 :       if (TREE_CODE (retval) == EXCESS_PRECISION_EXPR)
   13293              :         {
   13294           92 :           semantic_type = TREE_TYPE (retval);
   13295           92 :           retval = TREE_OPERAND (retval, 0);
   13296              :         }
   13297     34559561 :       retval = c_fully_fold (retval, false, NULL);
   13298     34559561 :       if (semantic_type
   13299     34559561 :           && valtype != NULL_TREE
   13300           92 :           && TREE_CODE (valtype) != VOID_TYPE)
   13301           92 :         retval = build1 (EXCESS_PRECISION_EXPR, semantic_type, retval);
   13302              :     }
   13303              : 
   13304     34559561 :   if (!retval)
   13305              :     {
   13306        21220 :       current_function_returns_null = 1;
   13307        21220 :       if ((warn_return_type >= 0 || flag_isoc99)
   13308        21095 :           && valtype != NULL_TREE && TREE_CODE (valtype) != VOID_TYPE)
   13309              :         {
   13310           46 :           no_warning = true;
   13311           47 :           if (emit_diagnostic (flag_isoc99
   13312              :                                ? diagnostics::kind::permerror
   13313              :                                : diagnostics::kind::warning,
   13314           46 :                                loc, OPT_Wreturn_mismatch,
   13315              :                                "%<return%> with no value,"
   13316              :                                " in function returning non-void"))
   13317           27 :             inform (DECL_SOURCE_LOCATION (current_function_decl),
   13318              :                     "declared here");
   13319              :         }
   13320              :     }
   13321     34559561 :   else if (valtype == NULL_TREE || VOID_TYPE_P (valtype))
   13322              :     {
   13323          321 :       current_function_returns_null = 1;
   13324          321 :       bool warned_here;
   13325          321 :       if (TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
   13326           64 :         warned_here = permerror_opt
   13327           64 :           (xloc, OPT_Wreturn_mismatch,
   13328              :            "%<return%> with a value, in function returning void");
   13329              :       else
   13330          257 :         warned_here = pedwarn
   13331          257 :           (xloc, OPT_Wpedantic, "ISO C forbids "
   13332              :            "%<return%> with expression, in function returning void");
   13333          321 :       if (warned_here)
   13334           43 :         inform (DECL_SOURCE_LOCATION (current_function_decl),
   13335              :                 "declared here");
   13336              :     }
   13337              :   else
   13338              :     {
   13339     34559240 :       tree t = convert_for_assignment (loc, UNKNOWN_LOCATION, valtype,
   13340              :                                        retval, origtype, ic_return,
   13341              :                                        npc, NULL_TREE, NULL_TREE, 0);
   13342     34559240 :       tree res = DECL_RESULT (current_function_decl);
   13343     34559240 :       tree inner;
   13344     34559240 :       bool save;
   13345              : 
   13346     34559240 :       current_function_returns_value = 1;
   13347     34559240 :       if (t == error_mark_node)
   13348              :         {
   13349              :           /* Suppress -Wreturn-type for this function.  */
   13350          298 :           if (warn_return_type)
   13351          297 :             suppress_warning (current_function_decl, OPT_Wreturn_type);
   13352          298 :           return NULL_TREE;
   13353              :         }
   13354              : 
   13355     34558942 :       save = in_late_binary_op;
   13356     69109773 :       if (C_BOOLEAN_TYPE_P (TREE_TYPE (res))
   13357     34550026 :           || TREE_CODE (TREE_TYPE (res)) == COMPLEX_TYPE
   13358     69107688 :           || (SCALAR_FLOAT_TYPE_P (TREE_TYPE (t))
   13359       332987 :               && (TREE_CODE (TREE_TYPE (res)) == INTEGER_TYPE
   13360       332987 :                   || TREE_CODE (TREE_TYPE (res)) == ENUMERAL_TYPE)
   13361            0 :               && sanitize_flags_p (SANITIZE_FLOAT_CAST)))
   13362        10196 :         in_late_binary_op = true;
   13363     34558942 :       inner = t = convert (TREE_TYPE (res), t);
   13364     34558942 :       in_late_binary_op = save;
   13365              : 
   13366              :       /* Strip any conversions, additions, and subtractions, and see if
   13367              :          we are returning the address of a local variable.  Warn if so.  */
   13368     37829912 :       while (1)
   13369              :         {
   13370     37829912 :           switch (TREE_CODE (inner))
   13371              :             {
   13372      3269544 :             CASE_CONVERT:
   13373      3269544 :             case NON_LVALUE_EXPR:
   13374      3269544 :             case PLUS_EXPR:
   13375      3269544 :             case POINTER_PLUS_EXPR:
   13376      3269544 :               inner = TREE_OPERAND (inner, 0);
   13377      3269544 :               continue;
   13378              : 
   13379         1431 :             case MINUS_EXPR:
   13380              :               /* If the second operand of the MINUS_EXPR has a pointer
   13381              :                  type (or is converted from it), this may be valid, so
   13382              :                  don't give a warning.  */
   13383         1431 :               {
   13384         1431 :                 tree op1 = TREE_OPERAND (inner, 1);
   13385              : 
   13386         3111 :                 while (!POINTER_TYPE_P (TREE_TYPE (op1))
   13387         3365 :                        && (CONVERT_EXPR_P (op1)
   13388         1426 :                            || TREE_CODE (op1) == NON_LVALUE_EXPR))
   13389          254 :                   op1 = TREE_OPERAND (op1, 0);
   13390              : 
   13391         1431 :                 if (POINTER_TYPE_P (TREE_TYPE (op1)))
   13392              :                   break;
   13393              : 
   13394         1426 :                 inner = TREE_OPERAND (inner, 0);
   13395         1426 :                 continue;
   13396         1426 :               }
   13397              : 
   13398         2926 :             case ADDR_EXPR:
   13399         2926 :               inner = TREE_OPERAND (inner, 0);
   13400              : 
   13401         2926 :               while (REFERENCE_CLASS_P (inner)
   13402         3812 :                      && !INDIRECT_REF_P (inner))
   13403          886 :                 inner = TREE_OPERAND (inner, 0);
   13404              : 
   13405         2926 :               if (DECL_P (inner)
   13406         1605 :                   && !DECL_EXTERNAL (inner)
   13407          973 :                   && DECL_CONTEXT (inner) == current_function_decl
   13408         3143 :                   && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (current_function_decl))))
   13409              :                 {
   13410          177 :                   if (TREE_CODE (inner) == LABEL_DECL)
   13411            4 :                     warning_at (loc, OPT_Wreturn_local_addr,
   13412              :                                 "function returns address of label");
   13413          173 :                   else if (TREE_CODE (inner) == FUNCTION_DECL
   13414          173 :                            && (C_FUNC_NONLOCAL_CONTEXT (inner)
   13415            8 :                                || !DECL_INITIAL (inner)))
   13416           10 :                     warning_at (loc, OPT_Wreturn_local_addr,
   13417              :                                 "function returns address of nested function "
   13418              :                                 "referencing local context");
   13419          163 :                   else if (TREE_CODE (inner) != FUNCTION_DECL
   13420          156 :                            && !TREE_STATIC (inner))
   13421              :                     {
   13422            9 :                       warning_at (loc, OPT_Wreturn_local_addr,
   13423              :                                   "function returns address of local variable");
   13424            9 :                       tree zero = build_zero_cst (TREE_TYPE (res));
   13425            9 :                       t = build2 (COMPOUND_EXPR, TREE_TYPE (res), t, zero);
   13426              :                     }
   13427              :                 }
   13428              :               break;
   13429              : 
   13430              :             default:
   13431              :               break;
   13432      3269544 :             }
   13433              : 
   13434     34558942 :           break;
   13435              :         }
   13436              : 
   13437     34558942 :       retval = build2 (MODIFY_EXPR, TREE_TYPE (res), res, t);
   13438     34558942 :       SET_EXPR_LOCATION (retval, loc);
   13439              : 
   13440     34558942 :       if (warn_sequence_point)
   13441      2964475 :         verify_sequence_points (retval);
   13442              :     }
   13443              : 
   13444     34580483 :   ret_stmt = build_stmt (loc, RETURN_EXPR, retval);
   13445     34580483 :   if (no_warning)
   13446           46 :     suppress_warning (ret_stmt, OPT_Wreturn_type);
   13447     34580483 :   return add_stmt (ret_stmt);
   13448              : }
   13449              : 
   13450              : struct c_switch {
   13451              :   /* The SWITCH_STMT being built.  */
   13452              :   tree switch_stmt;
   13453              : 
   13454              :   /* The original type of the testing expression, i.e. before the
   13455              :      default conversion is applied.  */
   13456              :   tree orig_type;
   13457              : 
   13458              :   /* A splay-tree mapping the low element of a case range to the high
   13459              :      element, or NULL_TREE if there is no high element.  Used to
   13460              :      determine whether or not a new case label duplicates an old case
   13461              :      label.  We need a tree, rather than simply a hash table, because
   13462              :      of the GNU case range extension.  */
   13463              :   splay_tree cases;
   13464              : 
   13465              :   /* The bindings at the point of the switch.  This is used for
   13466              :      warnings crossing decls when branching to a case label.  */
   13467              :   struct c_spot_bindings *bindings;
   13468              : 
   13469              :   /* Whether the switch includes any break statements.  */
   13470              :   bool break_stmt_seen_p;
   13471              : 
   13472              :   /* The next node on the stack.  */
   13473              :   struct c_switch *next;
   13474              : 
   13475              :   /* Remember whether the controlling expression had boolean type
   13476              :      before integer promotions for the sake of -Wswitch-bool.  */
   13477              :   bool bool_cond_p;
   13478              : };
   13479              : 
   13480              : /* A stack of the currently active switch statements.  The innermost
   13481              :    switch statement is on the top of the stack.  There is no need to
   13482              :    mark the stack for garbage collection because it is only active
   13483              :    during the processing of the body of a function, and we never
   13484              :    collect at that point.  */
   13485              : 
   13486              : struct c_switch *c_switch_stack;
   13487              : 
   13488              : /* Start a C switch statement, testing expression EXP.  Return the new
   13489              :    SWITCH_STMT.  SWITCH_LOC is the location of the `switch'.
   13490              :    SWITCH_COND_LOC is the location of the switch's condition.
   13491              :    EXPLICIT_CAST_P is true if the expression EXP has an explicit cast.  */
   13492              : 
   13493              : tree
   13494        37243 : c_start_switch (location_t switch_loc,
   13495              :                 location_t switch_cond_loc,
   13496              :                 tree exp, bool explicit_cast_p, tree switch_name)
   13497              : {
   13498        37243 :   tree orig_type = error_mark_node;
   13499        37243 :   bool bool_cond_p = false;
   13500        37243 :   struct c_switch *cs;
   13501              : 
   13502        37243 :   if (exp != error_mark_node)
   13503              :     {
   13504        37200 :       orig_type = TREE_TYPE (exp);
   13505              : 
   13506        37200 :       if (!INTEGRAL_TYPE_P (orig_type))
   13507              :         {
   13508           12 :           if (orig_type != error_mark_node)
   13509              :             {
   13510           12 :               error_at (switch_cond_loc, "switch quantity not an integer");
   13511           12 :               orig_type = error_mark_node;
   13512              :             }
   13513           12 :           exp = integer_zero_node;
   13514              :         }
   13515              :       else
   13516              :         {
   13517        37188 :           tree type = TYPE_MAIN_VARIANT (orig_type);
   13518        37188 :           tree e = exp;
   13519              : 
   13520              :           /* Warn if the condition has boolean value.  */
   13521        37191 :           while (TREE_CODE (e) == COMPOUND_EXPR)
   13522            3 :             e = TREE_OPERAND (e, 1);
   13523              : 
   13524        37163 :           if ((C_BOOLEAN_TYPE_P (type)
   13525        37163 :                || truth_value_p (TREE_CODE (e)))
   13526              :               /* Explicit cast to int suppresses this warning.  */
   13527        37210 :               && !(TREE_CODE (type) == INTEGER_TYPE
   13528              :                    && explicit_cast_p))
   13529              :             bool_cond_p = true;
   13530              : 
   13531        37188 :           if (!in_system_header_at (input_location)
   13532        37188 :               && (type == long_integer_type_node
   13533        11932 :                   || type == long_unsigned_type_node))
   13534          280 :             warning_at (switch_cond_loc,
   13535          280 :                         OPT_Wtraditional, "%<long%> switch expression not "
   13536              :                         "converted to %<int%> in ISO C");
   13537              : 
   13538        37188 :           exp = c_fully_fold (exp, false, NULL);
   13539        37188 :           exp = default_conversion (exp);
   13540              : 
   13541        37188 :           if (warn_sequence_point)
   13542         6009 :             verify_sequence_points (exp);
   13543              :         }
   13544              :     }
   13545              : 
   13546              :   /* Add this new SWITCH_STMT to the stack.  */
   13547        37243 :   cs = XNEW (struct c_switch);
   13548        37243 :   cs->switch_stmt = build_stmt (switch_loc, SWITCH_STMT, exp,
   13549              :                                 NULL_TREE, orig_type, NULL_TREE, switch_name);
   13550        37243 :   cs->orig_type = orig_type;
   13551        37243 :   cs->cases = splay_tree_new (case_compare, NULL, NULL);
   13552        37243 :   cs->bindings = c_get_switch_bindings ();
   13553        37243 :   cs->break_stmt_seen_p = false;
   13554        37243 :   cs->bool_cond_p = bool_cond_p;
   13555        37243 :   cs->next = c_switch_stack;
   13556        37243 :   c_switch_stack = cs;
   13557              : 
   13558        37243 :   return add_stmt (cs->switch_stmt);
   13559              : }
   13560              : 
   13561              : /* Process a case label at location LOC, with attributes ATTRS.  */
   13562              : 
   13563              : tree
   13564      1029805 : do_case (location_t loc, tree low_value, tree high_value, tree attrs)
   13565              : {
   13566      1029805 :   tree label = NULL_TREE;
   13567              : 
   13568      1029805 :   if (low_value && TREE_CODE (low_value) != INTEGER_CST)
   13569              :     {
   13570           87 :       low_value = c_fully_fold (low_value, false, NULL);
   13571           87 :       if (TREE_CODE (low_value) == INTEGER_CST)
   13572            9 :         pedwarn (loc, OPT_Wpedantic,
   13573              :                  "case label is not an integer constant expression");
   13574              :     }
   13575              : 
   13576      1029805 :   if (high_value && TREE_CODE (high_value) != INTEGER_CST)
   13577              :     {
   13578            0 :       high_value = c_fully_fold (high_value, false, NULL);
   13579            0 :       if (TREE_CODE (high_value) == INTEGER_CST)
   13580            0 :         pedwarn (input_location, OPT_Wpedantic,
   13581              :                  "case label is not an integer constant expression");
   13582              :     }
   13583              : 
   13584      1029805 :   if (c_switch_stack == NULL)
   13585              :     {
   13586            3 :       if (low_value)
   13587            2 :         error_at (loc, "case label not within a switch statement");
   13588              :       else
   13589            1 :         error_at (loc, "%<default%> label not within a switch statement");
   13590            3 :       return NULL_TREE;
   13591              :     }
   13592              : 
   13593      1029802 :   if (c_check_switch_jump_warnings (c_switch_stack->bindings,
   13594      1029802 :                                     EXPR_LOCATION (c_switch_stack->switch_stmt),
   13595              :                                     loc))
   13596              :     return NULL_TREE;
   13597              : 
   13598      1029790 :   label = c_add_case_label (loc, c_switch_stack->cases,
   13599      1029790 :                             SWITCH_STMT_COND (c_switch_stack->switch_stmt),
   13600              :                             low_value, high_value, attrs);
   13601      1029790 :   if (label == error_mark_node)
   13602          144 :     label = NULL_TREE;
   13603              :   return label;
   13604              : }
   13605              : 
   13606              : /* Finish the switch statement.  TYPE is the original type of the
   13607              :    controlling expression of the switch, or NULL_TREE.  */
   13608              : 
   13609              : void
   13610        37243 : c_finish_switch (tree body, tree type)
   13611              : {
   13612        37243 :   struct c_switch *cs = c_switch_stack;
   13613        37243 :   location_t switch_location;
   13614              : 
   13615        37243 :   SWITCH_STMT_BODY (cs->switch_stmt) = body;
   13616              : 
   13617              :   /* Emit warnings as needed.  */
   13618        37243 :   switch_location = EXPR_LOCATION (cs->switch_stmt);
   13619        43427 :   c_do_switch_warnings (cs->cases, switch_location,
   13620         6184 :                         type ? type : SWITCH_STMT_TYPE (cs->switch_stmt),
   13621        37243 :                         SWITCH_STMT_COND (cs->switch_stmt), cs->bool_cond_p);
   13622        37243 :   if (c_switch_covers_all_cases_p (cs->cases,
   13623        37243 :                                    SWITCH_STMT_TYPE (cs->switch_stmt)))
   13624        33351 :     SWITCH_STMT_ALL_CASES_P (cs->switch_stmt) = 1;
   13625        37243 :   SWITCH_STMT_NO_BREAK_P (cs->switch_stmt) = !cs->break_stmt_seen_p;
   13626              : 
   13627              :   /* Pop the stack.  */
   13628        37243 :   c_switch_stack = cs->next;
   13629        37243 :   splay_tree_delete (cs->cases);
   13630        37243 :   c_release_switch_bindings (cs->bindings);
   13631        37243 :   XDELETE (cs);
   13632        37243 : }
   13633              : 
   13634              : /* Emit an if statement.  IF_LOCUS is the location of the 'if'.  COND,
   13635              :    THEN_BLOCK and ELSE_BLOCK are expressions to be used; ELSE_BLOCK
   13636              :    may be null.  */
   13637              : 
   13638              : void
   13639      1268763 : c_finish_if_stmt (location_t if_locus, tree cond, tree then_block,
   13640              :                   tree else_block)
   13641              : {
   13642      1268763 :   tree stmt;
   13643              : 
   13644      1268763 :   stmt = build3 (COND_EXPR, void_type_node, cond, then_block, else_block);
   13645      1268763 :   SET_EXPR_LOCATION (stmt, if_locus);
   13646      1268763 :   add_stmt (stmt);
   13647      1268763 : }
   13648              : 
   13649              : tree
   13650       187071 : c_finish_bc_stmt (location_t loc, tree label, bool is_break, tree name)
   13651              : {
   13652              :   /* In switch statements break is sometimes stylistically used after
   13653              :      a return statement.  This can lead to spurious warnings about
   13654              :      control reaching the end of a non-void function when it is
   13655              :      inlined.  Note that we are calling block_may_fallthru with
   13656              :      language specific tree nodes; this works because
   13657              :      block_may_fallthru returns true when given something it does not
   13658              :      understand.  */
   13659       187071 :   bool skip = !block_may_fallthru (cur_stmt_list);
   13660              : 
   13661       187071 :   if (is_break)
   13662       173911 :     switch (in_statement & ~IN_NAMED_STMT)
   13663              :       {
   13664            9 :       case 0:
   13665            9 :         error_at (loc, "break statement not within loop or switch");
   13666            9 :         return NULL_TREE;
   13667            4 :       case IN_OMP_BLOCK:
   13668            4 :         error_at (loc, "invalid exit from OpenMP structured block");
   13669            4 :         return NULL_TREE;
   13670           12 :       case IN_OMP_FOR:
   13671           12 :         error_at (loc, "break statement used with OpenMP for loop");
   13672           12 :         return NULL_TREE;
   13673              :       case IN_ITERATION_STMT:
   13674              :       case IN_OBJC_FOREACH:
   13675              :         break;
   13676       158136 :       default:
   13677       158136 :         gcc_assert (in_statement & IN_SWITCH_STMT);
   13678       158136 :         c_switch_stack->break_stmt_seen_p = true;
   13679       158136 :         break;
   13680              :       }
   13681              :   else
   13682        13160 :     switch (in_statement & ~(IN_SWITCH_STMT | IN_NAMED_STMT))
   13683              :       {
   13684            7 :       case 0:
   13685            7 :         error_at (loc, "continue statement not within a loop");
   13686            7 :         return NULL_TREE;
   13687            4 :       case IN_OMP_BLOCK:
   13688            4 :         error_at (loc, "invalid exit from OpenMP structured block");
   13689            4 :         return NULL_TREE;
   13690              :       case IN_ITERATION_STMT:
   13691              :       case IN_OMP_FOR:
   13692              :       case IN_OBJC_FOREACH:
   13693              :         break;
   13694            0 :       default:
   13695            0 :         gcc_unreachable ();
   13696              :       }
   13697              : 
   13698       187035 :   if (skip)
   13699              :     return NULL_TREE;
   13700       186607 :   else if ((in_statement & IN_OBJC_FOREACH)
   13701            0 :            && !(is_break && (in_statement & IN_SWITCH_STMT))
   13702            0 :            && name == NULL_TREE)
   13703              :     {
   13704              :       /* The foreach expander produces low-level code using gotos instead
   13705              :          of a structured loop construct.  */
   13706            0 :       gcc_assert (label);
   13707            0 :       return add_stmt (build_stmt (loc, GOTO_EXPR, label));
   13708              :     }
   13709       186704 :   else if (name && C_DECL_LOOP_NAME (name) && C_DECL_SWITCH_NAME (name))
   13710              :     {
   13711            0 :       label = DECL_CHAIN (name);
   13712            0 :       if (!is_break)
   13713            0 :         label = DECL_CHAIN (label);
   13714              :       /* Foreach expander from some outer level.  */
   13715            0 :       return add_stmt (build_stmt (loc, GOTO_EXPR, label));
   13716              :     }
   13717       199756 :   return add_stmt (build_stmt (loc, is_break ? BREAK_STMT : CONTINUE_STMT,
   13718       186607 :                                name));
   13719              : }
   13720              : 
   13721              : /* A helper routine for c_process_expr_stmt and c_finish_stmt_expr.  */
   13722              : 
   13723              : static void
   13724      6353621 : emit_side_effect_warnings (location_t loc, tree expr)
   13725              : {
   13726      6353621 :   maybe_warn_nodiscard (loc, expr);
   13727      6353621 :   if (!warn_unused_value)
   13728              :     return;
   13729      1293987 :   if (expr == error_mark_node)
   13730              :     ;
   13731      1293912 :   else if (!TREE_SIDE_EFFECTS (expr))
   13732              :     {
   13733         6446 :       if (!VOID_TYPE_P (TREE_TYPE (expr))
   13734         6446 :           && !warning_suppressed_p (expr, OPT_Wunused_value))
   13735           28 :         warning_at (loc, OPT_Wunused_value, "statement with no effect");
   13736              :     }
   13737      1287466 :   else if (TREE_CODE (expr) == COMPOUND_EXPR)
   13738              :     {
   13739              :       tree r = expr;
   13740              :       location_t cloc = loc;
   13741        11991 :       while (TREE_CODE (r) == COMPOUND_EXPR)
   13742              :         {
   13743         6011 :           if (EXPR_HAS_LOCATION (r))
   13744         5481 :             cloc = EXPR_LOCATION (r);
   13745         6011 :           r = TREE_OPERAND (r, 1);
   13746              :         }
   13747         5980 :       if (!TREE_SIDE_EFFECTS (r)
   13748           33 :           && !VOID_TYPE_P (TREE_TYPE (r))
   13749           24 :           && !CONVERT_EXPR_P (r)
   13750           24 :           && !warning_suppressed_p (r, OPT_Wunused_value)
   13751         5992 :           && !warning_suppressed_p (expr, OPT_Wunused_value))
   13752            8 :         warning_at (cloc, OPT_Wunused_value,
   13753              :                     "right-hand operand of comma expression has no effect");
   13754              :     }
   13755              :   else
   13756      1281486 :     warn_if_unused_value (expr, loc);
   13757              : }
   13758              : 
   13759              : /* Process an expression as if it were a complete statement.  Emit
   13760              :    diagnostics, but do not call ADD_STMT.  LOC is the location of the
   13761              :    statement.  */
   13762              : 
   13763              : tree
   13764      6230221 : c_process_expr_stmt (location_t loc, tree expr)
   13765              : {
   13766      6230221 :   tree exprv;
   13767              : 
   13768      6230221 :   if (!expr)
   13769              :     return NULL_TREE;
   13770              : 
   13771      6225898 :   expr = c_fully_fold (expr, false, NULL);
   13772              : 
   13773      6225898 :   if (warn_sequence_point)
   13774      1289779 :     verify_sequence_points (expr);
   13775              : 
   13776      6225898 :   if (TREE_TYPE (expr) != error_mark_node
   13777      6223321 :       && !COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (expr))
   13778      6225898 :       && TREE_CODE (TREE_TYPE (expr)) != ARRAY_TYPE)
   13779            0 :     error_at (loc, "expression statement has incomplete type");
   13780              : 
   13781              :   /* If we're not processing a statement expression, warn about unused values.
   13782              :      Warnings for statement expressions will be emitted later, once we figure
   13783              :      out which is the result.  */
   13784      6225898 :   if (!STATEMENT_LIST_STMT_EXPR (cur_stmt_list)
   13785      6225898 :       && (warn_unused_value || warn_unused_result))
   13786      6139812 :     emit_side_effect_warnings (EXPR_LOC_OR_LOC (expr, loc), expr);
   13787              : 
   13788              :   exprv = expr;
   13789      6264604 :   while (TREE_CODE (exprv) == COMPOUND_EXPR)
   13790        38707 :     exprv = TREE_OPERAND (exprv, 1);
   13791      6237036 :   while (CONVERT_EXPR_P (exprv))
   13792        11139 :     exprv = TREE_OPERAND (exprv, 0);
   13793      6225897 :   if (DECL_P (exprv)
   13794      6226471 :       || handled_component_p (exprv)
   13795     12432279 :       || TREE_CODE (exprv) == ADDR_EXPR)
   13796        20089 :     mark_exp_read (exprv);
   13797              : 
   13798              :   /* If the expression is not of a type to which we cannot assign a line
   13799              :      number, wrap the thing in a no-op NOP_EXPR.  */
   13800      6225897 :   if (DECL_P (expr) || CONSTANT_CLASS_P (expr))
   13801              :     {
   13802        14865 :       expr = build1 (NOP_EXPR, TREE_TYPE (expr), expr);
   13803        14865 :       SET_EXPR_LOCATION (expr, loc);
   13804              :     }
   13805              : 
   13806              :   return expr;
   13807              : }
   13808              : 
   13809              : /* Emit an expression as a statement.  LOC is the location of the
   13810              :    expression.  */
   13811              : 
   13812              : tree
   13813      5929861 : c_finish_expr_stmt (location_t loc, tree expr)
   13814              : {
   13815      5929861 :   if (expr)
   13816      5917377 :     return add_stmt (c_process_expr_stmt (loc, expr));
   13817              :   else
   13818              :     return NULL;
   13819              : }
   13820              : 
   13821              : /* Do the opposite and emit a statement as an expression.  To begin,
   13822              :    create a new binding level and return it.  */
   13823              : 
   13824              : tree
   13825        34851 : c_begin_stmt_expr (void)
   13826              : {
   13827        34851 :   tree ret;
   13828              : 
   13829              :   /* We must force a BLOCK for this level so that, if it is not expanded
   13830              :      later, there is a way to turn off the entire subtree of blocks that
   13831              :      are contained in it.  */
   13832        34851 :   keep_next_level ();
   13833        34851 :   ret = c_begin_compound_stmt (true);
   13834              : 
   13835        34851 :   c_bindings_start_stmt_expr (c_switch_stack == NULL
   13836              :                               ? NULL
   13837              :                               : c_switch_stack->bindings);
   13838              : 
   13839              :   /* Mark the current statement list as belonging to a statement list.  */
   13840        34851 :   STATEMENT_LIST_STMT_EXPR (ret) = 1;
   13841              : 
   13842        34851 :   return ret;
   13843              : }
   13844              : 
   13845              : /* LOC is the location of the compound statement to which this body
   13846              :    belongs.  */
   13847              : 
   13848              : tree
   13849        34851 : c_finish_stmt_expr (location_t loc, tree body)
   13850              : {
   13851        34851 :   tree last, type, tmp, val;
   13852        34851 :   tree *last_p;
   13853              : 
   13854        34851 :   body = c_end_compound_stmt (loc, body, true);
   13855              : 
   13856        34851 :   c_bindings_end_stmt_expr (c_switch_stack == NULL
   13857              :                             ? NULL
   13858              :                             : c_switch_stack->bindings);
   13859              : 
   13860              :   /* Locate the last statement in BODY.  See c_end_compound_stmt
   13861              :      about always returning a BIND_EXPR.  */
   13862        34851 :   last_p = &BIND_EXPR_BODY (body);
   13863        34851 :   last = BIND_EXPR_BODY (body);
   13864              : 
   13865        34851 :  continue_searching:
   13866        34851 :   if (TREE_CODE (last) == STATEMENT_LIST)
   13867              :     {
   13868        26047 :       tree_stmt_iterator l = tsi_last (last);
   13869              : 
   13870        26053 :       while (!tsi_end_p (l) && TREE_CODE (tsi_stmt (l)) == DEBUG_BEGIN_STMT)
   13871            6 :         tsi_prev (&l);
   13872              : 
   13873              :       /* This can happen with degenerate cases like ({ }).  No value.  */
   13874        26047 :       if (tsi_end_p (l))
   13875          389 :         return body;
   13876              : 
   13877              :       /* If we're supposed to generate side effects warnings, process
   13878              :          all of the statements except the last.  */
   13879        25658 :       if (warn_unused_value || warn_unused_result)
   13880              :         {
   13881        25658 :           for (tree_stmt_iterator i = tsi_start (last);
   13882       275672 :                tsi_stmt (i) != tsi_stmt (l); tsi_next (&i))
   13883              :             {
   13884       250014 :               location_t tloc;
   13885       250014 :               tree t = tsi_stmt (i);
   13886              : 
   13887       250014 :               tloc = EXPR_HAS_LOCATION (t) ? EXPR_LOCATION (t) : loc;
   13888       250014 :               emit_side_effect_warnings (tloc, t);
   13889              :             }
   13890              :         }
   13891        25658 :       last_p = tsi_stmt_ptr (l);
   13892        25658 :       last = *last_p;
   13893              :     }
   13894              : 
   13895              :   /* If the end of the list is exception related, then the list was split
   13896              :      by a call to push_cleanup.  Continue searching.  */
   13897        34462 :   if (TREE_CODE (last) == TRY_FINALLY_EXPR
   13898        34462 :       || TREE_CODE (last) == TRY_CATCH_EXPR)
   13899              :     {
   13900            0 :       last_p = &TREE_OPERAND (last, 0);
   13901            0 :       last = *last_p;
   13902            0 :       goto continue_searching;
   13903              :     }
   13904              : 
   13905        34462 :   if (last == error_mark_node)
   13906              :     return last;
   13907              : 
   13908              :   /* In the case that the BIND_EXPR is not necessary, return the
   13909              :      expression out from inside it.  */
   13910        34453 :   if ((last == BIND_EXPR_BODY (body)
   13911              :        /* Skip nested debug stmts.  */
   13912        25657 :        || last == expr_first (BIND_EXPR_BODY (body)))
   13913        45446 :       && BIND_EXPR_VARS (body) == NULL)
   13914              :     {
   13915              :       /* Even if this looks constant, do not allow it in a constant
   13916              :          expression.  */
   13917        10981 :       last = c_wrap_maybe_const (last, true);
   13918              :       /* Do not warn if the return value of a statement expression is
   13919              :          unused.  */
   13920        10981 :       suppress_warning (last, OPT_Wunused);
   13921        10981 :       return last;
   13922              :     }
   13923              : 
   13924              :   /* Extract the type of said expression.  */
   13925        23472 :   type = TREE_TYPE (last);
   13926              : 
   13927              :   /* If we're not returning a value at all, then the BIND_EXPR that
   13928              :      we already have is a fine expression to return.  */
   13929        23472 :   if (!type || VOID_TYPE_P (type))
   13930              :     return body;
   13931              : 
   13932              :   /* Now that we've located the expression containing the value, it seems
   13933              :      silly to make voidify_wrapper_expr repeat the process.  Create a
   13934              :      temporary of the appropriate type and stick it in a TARGET_EXPR.  */
   13935        18149 :   tmp = create_tmp_var_raw (type);
   13936              : 
   13937              :   /* Unwrap a no-op NOP_EXPR as added by c_finish_expr_stmt.  This avoids
   13938              :      tree_expr_nonnegative_p giving up immediately.  */
   13939        18149 :   val = last;
   13940        18149 :   if (TREE_CODE (val) == NOP_EXPR
   13941        18149 :       && TREE_TYPE (val) == TREE_TYPE (TREE_OPERAND (val, 0)))
   13942         3771 :     val = TREE_OPERAND (val, 0);
   13943              : 
   13944        18149 :   *last_p = build2 (MODIFY_EXPR, void_type_node, tmp, val);
   13945        18149 :   SET_EXPR_LOCATION (*last_p, EXPR_LOCATION (last));
   13946              : 
   13947        18149 :   {
   13948        18149 :     tree t = build4 (TARGET_EXPR, type, tmp, body, NULL_TREE, NULL_TREE);
   13949        18149 :     SET_EXPR_LOCATION (t, loc);
   13950        18149 :     return t;
   13951              :   }
   13952              : }
   13953              : 
   13954              : /* Begin and end compound statements.  This is as simple as pushing
   13955              :    and popping new statement lists from the tree.  */
   13956              : 
   13957              : tree
   13958     41090590 : c_begin_compound_stmt (bool do_scope)
   13959              : {
   13960     41090590 :   tree stmt = push_stmt_list ();
   13961     41090590 :   if (do_scope)
   13962     40994581 :     push_scope ();
   13963     41090590 :   return stmt;
   13964              : }
   13965              : 
   13966              : /* End a compound statement.  STMT is the statement.  LOC is the
   13967              :    location of the compound statement-- this is usually the location
   13968              :    of the opening brace.  */
   13969              : 
   13970              : tree
   13971     41090589 : c_end_compound_stmt (location_t loc, tree stmt, bool do_scope)
   13972              : {
   13973     41090589 :   tree block = NULL;
   13974              : 
   13975     41090589 :   if (do_scope)
   13976              :     {
   13977     40994580 :       if (c_dialect_objc ())
   13978            0 :         objc_clear_super_receiver ();
   13979     40994580 :       block = pop_scope ();
   13980              :     }
   13981              : 
   13982     41090589 :   stmt = pop_stmt_list (stmt);
   13983     41090589 :   stmt = c_build_bind_expr (loc, block, stmt);
   13984              : 
   13985              :   /* If this compound statement is nested immediately inside a statement
   13986              :      expression, then force a BIND_EXPR to be created.  Otherwise we'll
   13987              :      do the wrong thing for ({ { 1; } }) or ({ 1; { } }).  In particular,
   13988              :      STATEMENT_LISTs merge, and thus we can lose track of what statement
   13989              :      was really last.  */
   13990     82181178 :   if (building_stmt_list_p ()
   13991     41090504 :       && STATEMENT_LIST_STMT_EXPR (cur_stmt_list)
   13992     41213235 :       && TREE_CODE (stmt) != BIND_EXPR)
   13993              :     {
   13994       120904 :       stmt = build3 (BIND_EXPR, void_type_node, NULL, stmt, NULL);
   13995       120904 :       TREE_SIDE_EFFECTS (stmt) = 1;
   13996       120904 :       SET_EXPR_LOCATION (stmt, loc);
   13997              :     }
   13998              : 
   13999     41090589 :   return stmt;
   14000              : }
   14001              : 
   14002              : /* Queue a cleanup.  CLEANUP is an expression/statement to be executed
   14003              :    when the current scope is exited.  EH_ONLY is true when this is not
   14004              :    meant to apply to normal control flow transfer.  */
   14005              : 
   14006              : void
   14007          131 : push_cleanup (tree decl, tree cleanup, bool eh_only)
   14008              : {
   14009          131 :   enum tree_code code;
   14010          131 :   tree stmt, list;
   14011          131 :   bool stmt_expr;
   14012              : 
   14013          131 :   code = eh_only ? TRY_CATCH_EXPR : TRY_FINALLY_EXPR;
   14014          131 :   stmt = build_stmt (DECL_SOURCE_LOCATION (decl), code, NULL, cleanup);
   14015          131 :   add_stmt (stmt);
   14016          131 :   stmt_expr = STATEMENT_LIST_STMT_EXPR (cur_stmt_list);
   14017          131 :   list = push_stmt_list ();
   14018          131 :   TREE_OPERAND (stmt, 0) = list;
   14019          131 :   STATEMENT_LIST_STMT_EXPR (list) = stmt_expr;
   14020          131 : }
   14021              : 
   14022              : /* Build a vector comparison of ARG0 and ARG1 using CODE opcode
   14023              :    into a value of TYPE type.  Comparison is done via VEC_COND_EXPR.  */
   14024              : 
   14025              : static tree
   14026       100804 : build_vec_cmp (tree_code code, tree type,
   14027              :                tree arg0, tree arg1)
   14028              : {
   14029       100804 :   tree zero_vec = build_zero_cst (type);
   14030       100804 :   tree minus_one_vec = build_minus_one_cst (type);
   14031       100804 :   tree cmp_type = truth_type_for (TREE_TYPE (arg0));
   14032       100804 :   tree cmp = build2 (code, cmp_type, arg0, arg1);
   14033       100804 :   return build3 (VEC_COND_EXPR, type, cmp, minus_one_vec, zero_vec);
   14034              : }
   14035              : 
   14036              : /* Possibly warn about an address of OP never being NULL in a comparison
   14037              :    operation CODE involving null.  */
   14038              : 
   14039              : static void
   14040        51387 : maybe_warn_for_null_address (location_t loc, tree op, tree_code code)
   14041              : {
   14042              :   /* Prevent warnings issued for macro expansion.  */
   14043        51387 :   if (!warn_address
   14044        30199 :       || warning_suppressed_p (op, OPT_Waddress)
   14045        81242 :       || from_macro_expansion_at (loc))
   14046        24288 :     return;
   14047              : 
   14048        27099 :   if (TREE_CODE (op) == NOP_EXPR)
   14049              :     {
   14050              :       /* Allow casts to intptr_t to suppress the warning.  */
   14051         1133 :       tree type = TREE_TYPE (op);
   14052         1133 :       if (TREE_CODE (type) == INTEGER_TYPE)
   14053              :         return;
   14054         1133 :       op = TREE_OPERAND (op, 0);
   14055              :     }
   14056              : 
   14057        27099 :   if (TREE_CODE (op) == POINTER_PLUS_EXPR)
   14058              :     {
   14059              :       /* Allow a cast to void* to suppress the warning.  */
   14060           24 :       tree type = TREE_TYPE (TREE_TYPE (op));
   14061           24 :       if (VOID_TYPE_P (type))
   14062              :         return;
   14063              : 
   14064              :       /* Adding any value to a null pointer, including zero, is undefined
   14065              :          in C.  This includes the expression &p[0] where p is the null
   14066              :          pointer, although &p[0] will have been folded to p by this point
   14067              :          and so not diagnosed.  */
   14068           24 :       if (code == EQ_EXPR)
   14069           22 :         warning_at (loc, OPT_Waddress,
   14070              :                     "the comparison will always evaluate as %<false%> "
   14071              :                     "for the pointer operand in %qE must not be NULL",
   14072              :                     op);
   14073              :       else
   14074            2 :         warning_at (loc, OPT_Waddress,
   14075              :                     "the comparison will always evaluate as %<true%> "
   14076              :                     "for the pointer operand in %qE must not be NULL",
   14077              :                     op);
   14078              : 
   14079           24 :       return;
   14080              :     }
   14081              : 
   14082        27075 :   if (TREE_CODE (op) != ADDR_EXPR)
   14083              :     return;
   14084              : 
   14085          254 :   op = TREE_OPERAND (op, 0);
   14086              : 
   14087          254 :   if (TREE_CODE (op) == IMAGPART_EXPR
   14088          254 :       || TREE_CODE (op) == REALPART_EXPR)
   14089              :     {
   14090              :       /* The address of either complex part may not be null.  */
   14091           14 :       if (code == EQ_EXPR)
   14092            9 :         warning_at (loc, OPT_Waddress,
   14093              :                     "the comparison will always evaluate as %<false%> "
   14094              :                     "for the address of %qE will never be NULL",
   14095              :                     op);
   14096              :       else
   14097            5 :         warning_at (loc, OPT_Waddress,
   14098              :                     "the comparison will always evaluate as %<true%> "
   14099              :                     "for the address of %qE will never be NULL",
   14100              :                     op);
   14101           14 :       return;
   14102              :     }
   14103              : 
   14104              :   /* Set to true in the loop below if OP dereferences is operand.
   14105              :      In such a case the ultimate target need not be a decl for
   14106              :      the null [in]equality test to be constant.  */
   14107              :   bool deref = false;
   14108              : 
   14109              :   /* Get the outermost array or object, or member.  */
   14110          294 :   while (handled_component_p (op))
   14111              :     {
   14112           72 :       if (TREE_CODE (op) == COMPONENT_REF)
   14113              :         {
   14114              :           /* Get the member (its address is never null).  */
   14115           18 :           op = TREE_OPERAND (op, 1);
   14116           18 :           break;
   14117              :         }
   14118              : 
   14119              :       /* Get the outer array/object to refer to in the warning.  */
   14120           54 :       op = TREE_OPERAND (op, 0);
   14121           54 :       deref = true;
   14122              :     }
   14123              : 
   14124          192 :   if ((!deref && !decl_with_nonnull_addr_p (op))
   14125          371 :       || from_macro_expansion_at (loc))
   14126          109 :     return;
   14127              : 
   14128          131 :   bool w;
   14129          131 :   if (code == EQ_EXPR)
   14130           93 :     w = warning_at (loc, OPT_Waddress,
   14131              :                     "the comparison will always evaluate as %<false%> "
   14132              :                     "for the address of %qE will never be NULL",
   14133              :                     op);
   14134              :   else
   14135           38 :     w = warning_at (loc, OPT_Waddress,
   14136              :                     "the comparison will always evaluate as %<true%> "
   14137              :                     "for the address of %qE will never be NULL",
   14138              :                     op);
   14139              : 
   14140          131 :   if (w && DECL_P (op))
   14141          120 :     inform (DECL_SOURCE_LOCATION (op), "%qD declared here", op);
   14142              : }
   14143              : 
   14144              : /* Build a binary-operation expression without default conversions.
   14145              :    CODE is the kind of expression to build.
   14146              :    LOCATION is the operator's location.
   14147              :    This function differs from `build' in several ways:
   14148              :    the data type of the result is computed and recorded in it,
   14149              :    warnings are generated if arg data types are invalid,
   14150              :    special handling for addition and subtraction of pointers is known,
   14151              :    and some optimization is done (operations on narrow ints
   14152              :    are done in the narrower type when that gives the same result).
   14153              :    Constant folding is also done before the result is returned.
   14154              : 
   14155              :    Note that the operands will never have enumeral types, or function
   14156              :    or array types, because either they will have the default conversions
   14157              :    performed or they have both just been converted to some other type in which
   14158              :    the arithmetic is to be done.  */
   14159              : 
   14160              : tree
   14161     16796205 : build_binary_op (location_t location, enum tree_code code,
   14162              :                  tree orig_op0, tree orig_op1, bool convert_p)
   14163              : {
   14164     16796205 :   tree type0, type1, orig_type0, orig_type1;
   14165     16796205 :   tree eptype;
   14166     16796205 :   enum tree_code code0, code1;
   14167     16796205 :   tree op0, op1;
   14168     16796205 :   tree ret = error_mark_node;
   14169     16796205 :   const char *invalid_op_diag;
   14170     16796205 :   bool op0_int_operands, op1_int_operands;
   14171     16796205 :   bool int_const, int_const_or_overflow, int_operands;
   14172              : 
   14173              :   /* Expression code to give to the expression when it is built.
   14174              :      Normally this is CODE, which is what the caller asked for,
   14175              :      but in some special cases we change it.  */
   14176     16796205 :   enum tree_code resultcode = code;
   14177              : 
   14178              :   /* Data type in which the computation is to be performed.
   14179              :      In the simplest cases this is the common type of the arguments.  */
   14180     16796205 :   tree result_type = NULL;
   14181              : 
   14182              :   /* When the computation is in excess precision, the type of the
   14183              :      final EXCESS_PRECISION_EXPR.  */
   14184     16796205 :   tree semantic_result_type = NULL;
   14185              : 
   14186              :   /* Nonzero means operands have already been type-converted
   14187              :      in whatever way is necessary.
   14188              :      Zero means they need to be converted to RESULT_TYPE.  */
   14189     16796205 :   int converted = 0;
   14190              : 
   14191              :   /* Nonzero means create the expression with this type, rather than
   14192              :      RESULT_TYPE.  */
   14193     16796205 :   tree build_type = NULL_TREE;
   14194              : 
   14195              :   /* Nonzero means after finally constructing the expression
   14196              :      convert it to this type.  */
   14197     16796205 :   tree final_type = NULL_TREE;
   14198              : 
   14199              :   /* Nonzero if this is an operation like MIN or MAX which can
   14200              :      safely be computed in short if both args are promoted shorts.
   14201              :      Also implies COMMON.
   14202              :      -1 indicates a bitwise operation; this makes a difference
   14203              :      in the exact conditions for when it is safe to do the operation
   14204              :      in a narrower mode.  */
   14205     16796205 :   int shorten = 0;
   14206              : 
   14207              :   /* Nonzero if this is a comparison operation;
   14208              :      if both args are promoted shorts, compare the original shorts.
   14209              :      Also implies COMMON.  */
   14210     16796205 :   int short_compare = 0;
   14211              : 
   14212              :   /* Nonzero if this is a right-shift operation, which can be computed on the
   14213              :      original short and then promoted if the operand is a promoted short.  */
   14214     16796205 :   int short_shift = 0;
   14215              : 
   14216              :   /* Nonzero means set RESULT_TYPE to the common type of the args.  */
   14217     16796205 :   int common = 0;
   14218              : 
   14219              :   /* True means types are compatible as far as ObjC is concerned.  */
   14220     16796205 :   bool objc_ok;
   14221              : 
   14222              :   /* True means this is an arithmetic operation that may need excess
   14223              :      precision.  */
   14224     16796205 :   bool may_need_excess_precision;
   14225              : 
   14226              :   /* True means this is a boolean operation that converts both its
   14227              :      operands to truth-values.  */
   14228     16796205 :   bool boolean_op = false;
   14229              : 
   14230              :   /* Remember whether we're doing / or %.  */
   14231     16796205 :   bool doing_div_or_mod = false;
   14232              : 
   14233              :   /* Remember whether we're doing << or >>.  */
   14234     16796205 :   bool doing_shift = false;
   14235              : 
   14236              :   /* Tree holding instrumentation expression.  */
   14237     16796205 :   tree instrument_expr = NULL;
   14238              : 
   14239     16796205 :   if (location == UNKNOWN_LOCATION)
   14240           79 :     location = input_location;
   14241              : 
   14242     16796205 :   op0 = orig_op0;
   14243     16796205 :   op1 = orig_op1;
   14244              : 
   14245     16796205 :   op0_int_operands = EXPR_INT_CONST_OPERANDS (orig_op0);
   14246      8116231 :   if (op0_int_operands)
   14247      8116231 :     op0 = remove_c_maybe_const_expr (op0);
   14248     16796205 :   op1_int_operands = EXPR_INT_CONST_OPERANDS (orig_op1);
   14249     11375032 :   if (op1_int_operands)
   14250     11375032 :     op1 = remove_c_maybe_const_expr (op1);
   14251     28171237 :   int_operands = (op0_int_operands && op1_int_operands);
   14252     11375032 :   if (int_operands)
   14253              :     {
   14254     15879185 :       int_const_or_overflow = (TREE_CODE (orig_op0) == INTEGER_CST
   14255      7954759 :                                && TREE_CODE (orig_op1) == INTEGER_CST);
   14256      7924426 :       int_const = (int_const_or_overflow
   14257      7924426 :                    && !TREE_OVERFLOW (orig_op0)
   14258      7924357 :                    && !TREE_OVERFLOW (orig_op1));
   14259              :     }
   14260              :   else
   14261              :     int_const = int_const_or_overflow = false;
   14262              : 
   14263              :   /* Do not apply default conversion in mixed vector/scalar expression.  */
   14264     16796205 :   if (convert_p
   14265     16796205 :       && VECTOR_TYPE_P (TREE_TYPE (op0)) == VECTOR_TYPE_P (TREE_TYPE (op1)))
   14266              :     {
   14267     10109213 :       op0 = default_conversion (op0);
   14268     10109213 :       op1 = default_conversion (op1);
   14269              :     }
   14270              : 
   14271     16796205 :   orig_type0 = type0 = TREE_TYPE (op0);
   14272              : 
   14273     16796205 :   orig_type1 = type1 = TREE_TYPE (op1);
   14274              : 
   14275              :   /* The expression codes of the data types of the arguments tell us
   14276              :      whether the arguments are integers, floating, pointers, etc.  */
   14277     16796205 :   code0 = TREE_CODE (type0);
   14278     16796205 :   code1 = TREE_CODE (type1);
   14279              : 
   14280              :   /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
   14281     16796207 :   STRIP_TYPE_NOPS (op0);
   14282     16796208 :   STRIP_TYPE_NOPS (op1);
   14283              : 
   14284              :   /* If an error was already reported for one of the arguments,
   14285              :      avoid reporting another error.  */
   14286              : 
   14287     16796205 :   if (code0 == ERROR_MARK || code1 == ERROR_MARK)
   14288          710 :     return error_mark_node;
   14289              : 
   14290     16795495 :   if (code0 == POINTER_TYPE
   14291     16795495 :       && reject_gcc_builtin (op0, EXPR_LOCATION (orig_op0)))
   14292           11 :     return error_mark_node;
   14293              : 
   14294     16795484 :   if (code1 == POINTER_TYPE
   14295     16795484 :       && reject_gcc_builtin (op1, EXPR_LOCATION (orig_op1)))
   14296           11 :     return error_mark_node;
   14297              : 
   14298     33590946 :   if ((invalid_op_diag
   14299     16795473 :        = targetm.invalid_binary_op (code, type0, type1)))
   14300              :     {
   14301            0 :       error_at (location, invalid_op_diag);
   14302            0 :       return error_mark_node;
   14303              :     }
   14304              : 
   14305     16795473 :   switch (code)
   14306              :     {
   14307              :     case PLUS_EXPR:
   14308              :     case MINUS_EXPR:
   14309              :     case MULT_EXPR:
   14310              :     case TRUNC_DIV_EXPR:
   14311              :     case CEIL_DIV_EXPR:
   14312              :     case FLOOR_DIV_EXPR:
   14313              :     case ROUND_DIV_EXPR:
   14314              :     case EXACT_DIV_EXPR:
   14315              :       may_need_excess_precision = true;
   14316              :       break;
   14317              : 
   14318      2728443 :     case EQ_EXPR:
   14319      2728443 :     case NE_EXPR:
   14320      2728443 :     case LE_EXPR:
   14321      2728443 :     case GE_EXPR:
   14322      2728443 :     case LT_EXPR:
   14323      2728443 :     case GT_EXPR:
   14324              :       /* Excess precision for implicit conversions of integers to
   14325              :          floating point in C11 and later.  */
   14326      2728443 :       may_need_excess_precision = (flag_isoc11
   14327      2728443 :                                    && (ANY_INTEGRAL_TYPE_P (type0)
   14328       485297 :                                        || ANY_INTEGRAL_TYPE_P (type1)));
   14329              :       break;
   14330              : 
   14331              :     default:
   14332     16795473 :       may_need_excess_precision = false;
   14333              :       break;
   14334              :     }
   14335     16795473 :   if (TREE_CODE (op0) == EXCESS_PRECISION_EXPR)
   14336              :     {
   14337          184 :       op0 = TREE_OPERAND (op0, 0);
   14338          184 :       type0 = TREE_TYPE (op0);
   14339              :     }
   14340     16795289 :   else if (may_need_excess_precision
   14341     16795289 :            && (eptype = excess_precision_type (type0)) != NULL_TREE)
   14342              :     {
   14343          771 :       type0 = eptype;
   14344          771 :       op0 = convert (eptype, op0);
   14345              :     }
   14346     16795473 :   if (TREE_CODE (op1) == EXCESS_PRECISION_EXPR)
   14347              :     {
   14348          887 :       op1 = TREE_OPERAND (op1, 0);
   14349          887 :       type1 = TREE_TYPE (op1);
   14350              :     }
   14351     16794586 :   else if (may_need_excess_precision
   14352     16794586 :            && (eptype = excess_precision_type (type1)) != NULL_TREE)
   14353              :     {
   14354          592 :       type1 = eptype;
   14355          592 :       op1 = convert (eptype, op1);
   14356              :     }
   14357              : 
   14358     16795473 :   objc_ok = objc_compare_types (type0, type1, -3, NULL_TREE);
   14359              : 
   14360              :   /* In case when one of the operands of the binary operation is
   14361              :      a vector and another is a scalar -- convert scalar to vector.  */
   14362     18372133 :   if ((gnu_vector_type_p (type0) && code1 != VECTOR_TYPE)
   14363     18370256 :       || (gnu_vector_type_p (type1) && code0 != VECTOR_TYPE))
   14364              :     {
   14365         2482 :       enum stv_conv convert_flag = scalar_to_vector (location, code, orig_op0,
   14366              :                                                      orig_op1, true);
   14367              : 
   14368         2482 :       switch (convert_flag)
   14369              :         {
   14370           12 :           case stv_error:
   14371           12 :             return error_mark_node;
   14372          592 :           case stv_firstarg:
   14373          592 :             {
   14374          592 :               bool maybe_const = true;
   14375          592 :               tree sc;
   14376          592 :               sc = c_fully_fold (op0, false, &maybe_const);
   14377          592 :               sc = save_expr (sc);
   14378          592 :               sc = convert (TREE_TYPE (type1), sc);
   14379          592 :               op0 = build_vector_from_val (type1, sc);
   14380          592 :               if (!maybe_const)
   14381           93 :                 op0 = c_wrap_maybe_const (op0, true);
   14382          592 :               orig_type0 = type0 = TREE_TYPE (op0);
   14383          592 :               code0 = TREE_CODE (type0);
   14384          592 :               converted = 1;
   14385          592 :               break;
   14386              :             }
   14387         1044 :           case stv_secondarg:
   14388         1044 :             {
   14389         1044 :               bool maybe_const = true;
   14390         1044 :               tree sc;
   14391         1044 :               sc = c_fully_fold (op1, false, &maybe_const);
   14392         1044 :               sc = save_expr (sc);
   14393         1044 :               sc = convert (TREE_TYPE (type0), sc);
   14394         1044 :               op1 = build_vector_from_val (type0, sc);
   14395         1044 :               if (!maybe_const)
   14396           36 :                 op1 = c_wrap_maybe_const (op1, true);
   14397         1044 :               orig_type1 = type1 = TREE_TYPE (op1);
   14398         1044 :               code1 = TREE_CODE (type1);
   14399         1044 :               converted = 1;
   14400         1044 :               break;
   14401              :             }
   14402              :           default:
   14403              :             break;
   14404              :         }
   14405              :     }
   14406              : 
   14407     16795461 :   switch (code)
   14408              :     {
   14409      8608523 :     case PLUS_EXPR:
   14410              :       /* Handle the pointer + int case.  */
   14411      8608523 :       if (code0 == POINTER_TYPE
   14412      1247598 :           && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
   14413              :         {
   14414      1247592 :           ret = pointer_int_sum (location, PLUS_EXPR, op0, op1);
   14415      1247592 :           goto return_build_binary_op;
   14416              :         }
   14417      7360931 :       else if (code1 == POINTER_TYPE
   14418         1530 :                && (code0 == INTEGER_TYPE || code0 == BITINT_TYPE))
   14419              :         {
   14420         1524 :           ret = pointer_int_sum (location, PLUS_EXPR, op1, op0);
   14421         1524 :           goto return_build_binary_op;
   14422              :         }
   14423              :       else
   14424              :         common = 1;
   14425              :       break;
   14426              : 
   14427       790067 :     case MINUS_EXPR:
   14428              :       /* Subtraction of two similar pointers.
   14429              :          We must subtract them as integers, then divide by object size.  */
   14430       790067 :       if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
   14431       790067 :           && comp_target_types (location, type0, type1))
   14432              :         {
   14433         3622 :           ret = pointer_diff (location, op0, op1, &instrument_expr);
   14434         3622 :           goto return_build_binary_op;
   14435              :         }
   14436              :       /* Handle pointer minus int.  Just like pointer plus int.  */
   14437       786445 :       else if (code0 == POINTER_TYPE
   14438        16814 :                && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
   14439              :         {
   14440        16802 :           ret = pointer_int_sum (location, MINUS_EXPR, op0, op1);
   14441        16802 :           goto return_build_binary_op;
   14442              :         }
   14443              :       else
   14444              :         common = 1;
   14445              :       break;
   14446              : 
   14447              :     case MULT_EXPR:
   14448              :       common = 1;
   14449              :       break;
   14450              : 
   14451       273408 :     case TRUNC_DIV_EXPR:
   14452       273408 :     case CEIL_DIV_EXPR:
   14453       273408 :     case FLOOR_DIV_EXPR:
   14454       273408 :     case ROUND_DIV_EXPR:
   14455       273408 :     case EXACT_DIV_EXPR:
   14456       273408 :       doing_div_or_mod = true;
   14457       273408 :       warn_for_div_by_zero (location, op1);
   14458              : 
   14459       273407 :       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
   14460        49523 :            || code0 == FIXED_POINT_TYPE || code0 == BITINT_TYPE
   14461        47537 :            || code0 == COMPLEX_TYPE
   14462        45487 :            || gnu_vector_type_p (type0))
   14463       322929 :           && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
   14464        47089 :               || code1 == FIXED_POINT_TYPE || code1 == BITINT_TYPE
   14465        46950 :               || code1 == COMPLEX_TYPE
   14466        45489 :               || gnu_vector_type_p (type1)))
   14467              :         {
   14468       273403 :           enum tree_code tcode0 = code0, tcode1 = code1;
   14469              : 
   14470       273403 :           if (code0 == COMPLEX_TYPE || code0 == VECTOR_TYPE)
   14471        47536 :             tcode0 = TREE_CODE (TREE_TYPE (TREE_TYPE (op0)));
   14472       273403 :           if (code1 == COMPLEX_TYPE || code1 == VECTOR_TYPE)
   14473        46947 :             tcode1 = TREE_CODE (TREE_TYPE (TREE_TYPE (op1)));
   14474              : 
   14475       273403 :           if (!(((tcode0 == INTEGER_TYPE || tcode0 == BITINT_TYPE
   14476        69648 :                   || (tcode0 == ENUMERAL_TYPE && code0 == VECTOR_TYPE))
   14477       203756 :                  && (tcode1 == INTEGER_TYPE || tcode1 == BITINT_TYPE
   14478        12030 :                      || (tcode1 == ENUMERAL_TYPE && code1 == VECTOR_TYPE)))
   14479        81676 :                 || (tcode0 == FIXED_POINT_TYPE && tcode1 == FIXED_POINT_TYPE)))
   14480              :             resultcode = RDIV_EXPR;
   14481              :           else
   14482              :             /* Although it would be tempting to shorten always here, that
   14483              :                loses on some targets, since the modulo instruction is
   14484              :                undefined if the quotient can't be represented in the
   14485              :                computation mode.  We shorten only if unsigned or if
   14486              :                dividing by something we know != -1.  */
   14487       191727 :             shorten = may_shorten_divmod (op0, op1);
   14488              :           common = 1;
   14489              :         }
   14490              :       break;
   14491              : 
   14492      1582864 :     case BIT_AND_EXPR:
   14493      1582864 :     case BIT_IOR_EXPR:
   14494      1582864 :     case BIT_XOR_EXPR:
   14495      1582864 :       if ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE)
   14496      1048526 :           && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
   14497              :         shorten = -1;
   14498              :       /* Allow vector types which are not floating point types.   */
   14499       534374 :       else if (gnu_vector_type_p (type0)
   14500       534297 :                && gnu_vector_type_p (type1)
   14501       534297 :                && !VECTOR_FLOAT_TYPE_P (type0)
   14502      1068668 :                && !VECTOR_FLOAT_TYPE_P (type1))
   14503              :         common = 1;
   14504              :       break;
   14505              : 
   14506        58429 :     case TRUNC_MOD_EXPR:
   14507        58429 :     case FLOOR_MOD_EXPR:
   14508        58429 :       doing_div_or_mod = true;
   14509        58429 :       warn_for_div_by_zero (location, op1);
   14510              : 
   14511        58429 :       if (gnu_vector_type_p (type0)
   14512          297 :           && gnu_vector_type_p (type1)
   14513          297 :           && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
   14514        58726 :           && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE)
   14515              :         common = 1;
   14516        58132 :       else if ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE)
   14517        58131 :                && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
   14518              :         {
   14519              :           /* Although it would be tempting to shorten always here, that loses
   14520              :              on some targets, since the modulo instruction is undefined if the
   14521              :              quotient can't be represented in the computation mode.  We shorten
   14522              :              only if unsigned or if dividing by something we know != -1.  */
   14523        58131 :           shorten = may_shorten_divmod (op0, op1);
   14524        58131 :           common = 1;
   14525              :         }
   14526              :       break;
   14527              : 
   14528       508982 :     case TRUTH_ANDIF_EXPR:
   14529       508982 :     case TRUTH_ORIF_EXPR:
   14530       508982 :     case TRUTH_AND_EXPR:
   14531       508982 :     case TRUTH_OR_EXPR:
   14532       508982 :     case TRUTH_XOR_EXPR:
   14533       508982 :       if ((code0 == INTEGER_TYPE || code0 == POINTER_TYPE
   14534            0 :            || code0 == REAL_TYPE || code0 == COMPLEX_TYPE
   14535            0 :            || code0 == FIXED_POINT_TYPE || code0 == NULLPTR_TYPE
   14536            0 :            || code0 == BITINT_TYPE)
   14537       508982 :           && (code1 == INTEGER_TYPE || code1 == POINTER_TYPE
   14538          159 :               || code1 == REAL_TYPE || code1 == COMPLEX_TYPE
   14539           20 :               || code1 == FIXED_POINT_TYPE || code1 == NULLPTR_TYPE
   14540           18 :               || code1 == BITINT_TYPE))
   14541              :         {
   14542              :           /* Result of these operations is always an int,
   14543              :              but that does not mean the operands should be
   14544              :              converted to ints!  */
   14545       508982 :           result_type = integer_type_node;
   14546       508982 :           if (op0_int_operands)
   14547              :             {
   14548       110013 :               op0 = c_objc_common_truthvalue_conversion (location, orig_op0);
   14549       110013 :               op0 = remove_c_maybe_const_expr (op0);
   14550              :             }
   14551              :           else
   14552       398969 :             op0 = c_objc_common_truthvalue_conversion (location, op0);
   14553       508982 :           if (op1_int_operands)
   14554              :             {
   14555        71410 :               op1 = c_objc_common_truthvalue_conversion (location, orig_op1);
   14556        71410 :               op1 = remove_c_maybe_const_expr (op1);
   14557              :             }
   14558              :           else
   14559       437572 :             op1 = c_objc_common_truthvalue_conversion (location, op1);
   14560              :           converted = 1;
   14561              :           boolean_op = true;
   14562              :         }
   14563       508982 :       if (code == TRUTH_ANDIF_EXPR)
   14564              :         {
   14565       248011 :           int_const_or_overflow = (int_operands
   14566        63276 :                                    && TREE_CODE (orig_op0) == INTEGER_CST
   14567       248027 :                                    && (op0 == truthvalue_false_node
   14568        13202 :                                        || TREE_CODE (orig_op1) == INTEGER_CST));
   14569              :           int_const = (int_const_or_overflow
   14570        63249 :                        && !TREE_OVERFLOW (orig_op0)
   14571        63249 :                        && (op0 == truthvalue_false_node
   14572        13186 :                            || !TREE_OVERFLOW (orig_op1)));
   14573              :         }
   14574       324220 :       else if (code == TRUTH_ORIF_EXPR)
   14575              :         {
   14576       330895 :           int_const_or_overflow = (int_operands
   14577         6826 :                                    && TREE_CODE (orig_op0) == INTEGER_CST
   14578       330918 :                                    && (op0 == truthvalue_true_node
   14579         2141 :                                        || TREE_CODE (orig_op1) == INTEGER_CST));
   14580              :           int_const = (int_const_or_overflow
   14581         6796 :                        && !TREE_OVERFLOW (orig_op0)
   14582         6796 :                        && (op0 == truthvalue_true_node
   14583         2118 :                            || !TREE_OVERFLOW (orig_op1)));
   14584              :         }
   14585              :       break;
   14586              : 
   14587              :       /* Shift operations: result has same type as first operand;
   14588              :          always convert second operand to int.
   14589              :          Also set SHORT_SHIFT if shifting rightward.  */
   14590              : 
   14591       230920 :     case RSHIFT_EXPR:
   14592       230920 :       if (gnu_vector_type_p (type0)
   14593          807 :           && gnu_vector_type_p (type1)
   14594          258 :           && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
   14595          256 :           && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE
   14596       231176 :           && known_eq (TYPE_VECTOR_SUBPARTS (type0),
   14597              :                        TYPE_VECTOR_SUBPARTS (type1)))
   14598              :         {
   14599              :           result_type = type0;
   14600              :           converted = 1;
   14601              :         }
   14602       230666 :       else if ((code0 == INTEGER_TYPE || code0 == FIXED_POINT_TYPE
   14603         1089 :                 || code0 == BITINT_TYPE
   14604          557 :                 || (gnu_vector_type_p (type0)
   14605          553 :                     && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE))
   14606       231748 :                && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
   14607              :         {
   14608       230657 :           doing_shift = true;
   14609       230657 :           if (TREE_CODE (op1) == INTEGER_CST)
   14610              :             {
   14611       201298 :               if (tree_int_cst_sgn (op1) < 0)
   14612              :                 {
   14613          269 :                   int_const = false;
   14614          269 :                   if (c_inhibit_evaluation_warnings == 0)
   14615          129 :                     warning_at (location, OPT_Wshift_count_negative,
   14616              :                                 "right shift count is negative");
   14617              :                 }
   14618       201029 :               else if (code0 == VECTOR_TYPE)
   14619              :                 {
   14620          458 :                   if (compare_tree_int (op1,
   14621          458 :                                         TYPE_PRECISION (TREE_TYPE (type0)))
   14622              :                       >= 0)
   14623              :                     {
   14624           16 :                       int_const = false;
   14625           16 :                       if (c_inhibit_evaluation_warnings == 0)
   14626           16 :                         warning_at (location, OPT_Wshift_count_overflow,
   14627              :                                     "right shift count >= width of vector element");
   14628              :                     }
   14629              :                 }
   14630              :               else
   14631              :                 {
   14632       200571 :                   if (!integer_zerop (op1))
   14633       200213 :                     short_shift = 1;
   14634              : 
   14635       200571 :                   if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0)
   14636              :                     {
   14637          584 :                       int_const = false;
   14638          584 :                       if (c_inhibit_evaluation_warnings == 0)
   14639           50 :                         warning_at (location, OPT_Wshift_count_overflow,
   14640              :                                     "right shift count >= width of type");
   14641              :                     }
   14642              :                 }
   14643              :             }
   14644              : 
   14645              :           /* Use the type of the value to be shifted.  */
   14646              :           result_type = type0;
   14647              :           /* Avoid converting op1 to result_type later.  */
   14648              :           converted = 1;
   14649              :         }
   14650              :       break;
   14651              : 
   14652       802300 :     case LSHIFT_EXPR:
   14653       802300 :       if (gnu_vector_type_p (type0)
   14654          595 :           && gnu_vector_type_p (type1)
   14655          316 :           && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
   14656          314 :           && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE
   14657       802613 :           && known_eq (TYPE_VECTOR_SUBPARTS (type0),
   14658              :                        TYPE_VECTOR_SUBPARTS (type1)))
   14659              :         {
   14660              :           result_type = type0;
   14661              :           converted = 1;
   14662              :         }
   14663       801989 :       else if ((code0 == INTEGER_TYPE || code0 == FIXED_POINT_TYPE
   14664          760 :                 || code0 == BITINT_TYPE
   14665          290 :                 || (gnu_vector_type_p (type0)
   14666          284 :                     && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE))
   14667       802740 :                && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
   14668              :         {
   14669       801975 :           doing_shift = true;
   14670       801975 :           if (TREE_CODE (op0) == INTEGER_CST
   14671       438400 :               && tree_int_cst_sgn (op0) < 0
   14672       802724 :               && !TYPE_OVERFLOW_WRAPS (type0))
   14673              :             {
   14674              :               /* Don't reject a left shift of a negative value in a context
   14675              :                  where a constant expression is needed in C90.  */
   14676          712 :               if (flag_isoc99)
   14677          666 :                 int_const = false;
   14678          712 :               if (c_inhibit_evaluation_warnings == 0)
   14679          712 :                 warning_at (location, OPT_Wshift_negative_value,
   14680              :                             "left shift of negative value");
   14681              :             }
   14682       801975 :           if (TREE_CODE (op1) == INTEGER_CST)
   14683              :             {
   14684       729598 :               if (tree_int_cst_sgn (op1) < 0)
   14685              :                 {
   14686          313 :                   int_const = false;
   14687          313 :                   if (c_inhibit_evaluation_warnings == 0)
   14688          135 :                     warning_at (location, OPT_Wshift_count_negative,
   14689              :                                 "left shift count is negative");
   14690              :                 }
   14691       729285 :               else if (code0 == VECTOR_TYPE)
   14692              :                 {
   14693          215 :                   if (compare_tree_int (op1,
   14694          215 :                                         TYPE_PRECISION (TREE_TYPE (type0)))
   14695              :                       >= 0)
   14696              :                     {
   14697            6 :                       int_const = false;
   14698            6 :                       if (c_inhibit_evaluation_warnings == 0)
   14699            6 :                         warning_at (location, OPT_Wshift_count_overflow,
   14700              :                                     "left shift count >= width of vector element");
   14701              :                     }
   14702              :                 }
   14703       729070 :               else if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0)
   14704              :                 {
   14705        29733 :                   int_const = false;
   14706        29733 :                   if (c_inhibit_evaluation_warnings == 0)
   14707          113 :                     warning_at (location, OPT_Wshift_count_overflow,
   14708              :                                 "left shift count >= width of type");
   14709              :                 }
   14710       699337 :               else if (TREE_CODE (op0) == INTEGER_CST
   14711       364635 :                        && maybe_warn_shift_overflow (location, op0, op1)
   14712       699965 :                        && flag_isoc99)
   14713              :                 int_const = false;
   14714              :             }
   14715              : 
   14716              :           /* Use the type of the value to be shifted.  */
   14717              :           result_type = type0;
   14718              :           /* Avoid converting op1 to result_type later.  */
   14719              :           converted = 1;
   14720              :         }
   14721              :       break;
   14722              : 
   14723      1732457 :     case EQ_EXPR:
   14724      1732457 :     case NE_EXPR:
   14725      1732457 :       if (gnu_vector_type_p (type0) && gnu_vector_type_p (type1))
   14726              :         {
   14727        41799 :           tree intt;
   14728        41799 :           if (!vector_types_compatible_elements_p (type0, type1))
   14729              :             {
   14730            4 :               error_at (location, "comparing vectors with different "
   14731              :                                   "element types");
   14732            4 :               return error_mark_node;
   14733              :             }
   14734              : 
   14735        41795 :           if (maybe_ne (TYPE_VECTOR_SUBPARTS (type0),
   14736        83590 :                         TYPE_VECTOR_SUBPARTS (type1)))
   14737              :             {
   14738            1 :               error_at (location, "comparing vectors with different "
   14739              :                                   "number of elements");
   14740            1 :               return error_mark_node;
   14741              :             }
   14742              : 
   14743              :           /* It's not precisely specified how the usual arithmetic
   14744              :              conversions apply to the vector types.  Here, we use
   14745              :              the unsigned type if one of the operands is signed and
   14746              :              the other one is unsigned.  */
   14747        41794 :           if (TYPE_UNSIGNED (type0) != TYPE_UNSIGNED (type1))
   14748              :             {
   14749            4 :               if (!TYPE_UNSIGNED (type0))
   14750            4 :                 op0 = build1 (VIEW_CONVERT_EXPR, type1, op0);
   14751              :               else
   14752            0 :                 op1 = build1 (VIEW_CONVERT_EXPR, type0, op1);
   14753            4 :               warning_at (location, OPT_Wsign_compare, "comparison between "
   14754              :                           "types %qT and %qT", type0, type1);
   14755              :             }
   14756              : 
   14757              :           /* Always construct signed integer vector type.  */
   14758        41794 :           if (VECTOR_BOOLEAN_TYPE_P (type0) && VECTOR_BOOLEAN_TYPE_P (type1))
   14759              :             result_type = type0;
   14760              :           else
   14761              :             {
   14762        41794 :               auto nelts = TYPE_VECTOR_SUBPARTS (type0);
   14763              : 
   14764       125382 :               intt = c_common_type_for_size (GET_MODE_BITSIZE
   14765        83588 :                                              (SCALAR_TYPE_MODE
   14766              :                                                 (TREE_TYPE (type0))), 0);
   14767        41794 :               if (!intt)
   14768              :                 {
   14769            0 :                   error_at (location, "could not find an integer type "
   14770              :                                       "of the same size as %qT",
   14771            0 :                             TREE_TYPE (type0));
   14772            0 :                   return error_mark_node;
   14773              :                 }
   14774        41794 :               result_type = build_opaque_vector_type (intt, nelts);
   14775              :             }
   14776        41794 :           converted = 1;
   14777        41794 :           ret = build_vec_cmp (resultcode, result_type, op0, op1);
   14778        41794 :           goto return_build_binary_op;
   14779              :         }
   14780      1690658 :       if (FLOAT_TYPE_P (type0) || FLOAT_TYPE_P (type1))
   14781       252752 :         warning_at (location,
   14782       252752 :                     OPT_Wfloat_equal,
   14783              :                     "comparing floating-point with %<==%> or %<!=%> is unsafe");
   14784              :       /* Result of comparison is always int,
   14785              :          but don't convert the args to int!  */
   14786      1690658 :       build_type = integer_type_node;
   14787      1690658 :       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == BITINT_TYPE
   14788       156035 :            || code0 == FIXED_POINT_TYPE || code0 == COMPLEX_TYPE)
   14789      1569935 :           && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
   14790              :               || code1 == BITINT_TYPE
   14791              :               || code1 == FIXED_POINT_TYPE || code1 == COMPLEX_TYPE))
   14792              :         short_compare = 1;
   14793       120989 :       else if (code0 == POINTER_TYPE
   14794       120989 :                && (code1 == NULLPTR_TYPE
   14795       120632 :                    || null_pointer_constant_p (orig_op1)))
   14796              :         {
   14797        51099 :           maybe_warn_for_null_address (location, op0, code);
   14798        51099 :           result_type = type0;
   14799              :         }
   14800        69890 :       else if (code1 == POINTER_TYPE
   14801        69890 :                && (code0 == NULLPTR_TYPE
   14802        69788 :                    || null_pointer_constant_p (orig_op0)))
   14803              :         {
   14804          288 :           maybe_warn_for_null_address (location, op1, code);
   14805          288 :           result_type = type1;
   14806              :         }
   14807        69602 :       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
   14808              :         {
   14809        69512 :           tree tt0 = TREE_TYPE (type0);
   14810        69512 :           tree tt1 = TREE_TYPE (type1);
   14811        69512 :           addr_space_t as0 = TYPE_ADDR_SPACE (tt0);
   14812        69512 :           addr_space_t as1 = TYPE_ADDR_SPACE (tt1);
   14813        69512 :           addr_space_t as_common = ADDR_SPACE_GENERIC;
   14814              : 
   14815              :           /* Anything compares with void *.  void * compares with anything.
   14816              :              Otherwise, the targets must be compatible
   14817              :              and both must be object or both incomplete.  */
   14818        69512 :           if (comp_target_types (location, type0, type1))
   14819        48217 :             result_type = common_pointer_type (type0, type1, NULL_TREE);
   14820        21295 :           else if (!addr_space_superset (as0, as1, &as_common))
   14821              :             {
   14822            0 :               error_at (location, "comparison of pointers to "
   14823              :                         "disjoint address spaces");
   14824            0 :               return error_mark_node;
   14825              :             }
   14826        21295 :           else if (VOID_TYPE_P (tt0) && !TYPE_ATOMIC (tt0))
   14827              :             {
   14828        21086 :               if (pedantic && TREE_CODE (tt1) == FUNCTION_TYPE)
   14829            4 :                 pedwarn (location, OPT_Wpedantic, "ISO C forbids "
   14830              :                          "comparison of %<void *%> with function pointer");
   14831              :             }
   14832          209 :           else if (VOID_TYPE_P (tt1) && !TYPE_ATOMIC (tt1))
   14833              :             {
   14834          161 :               if (pedantic && TREE_CODE (tt0) == FUNCTION_TYPE)
   14835            4 :                 pedwarn (location, OPT_Wpedantic, "ISO C forbids "
   14836              :                          "comparison of %<void *%> with function pointer");
   14837              :             }
   14838              :           else
   14839              :             /* Avoid warning about the volatile ObjC EH puts on decls.  */
   14840           48 :             if (!objc_ok)
   14841           48 :               pedwarn (location, OPT_Wcompare_distinct_pointer_types,
   14842              :                        "comparison of distinct pointer types lacks a cast");
   14843              : 
   14844        48273 :           if (result_type == NULL_TREE)
   14845              :             {
   14846        21295 :               int qual = ENCODE_QUAL_ADDR_SPACE (as_common);
   14847        21295 :               result_type = c_build_pointer_type
   14848        21295 :                               (c_build_qualified_type (void_type_node, qual));
   14849              :             }
   14850              :         }
   14851           90 :       else if (code0 == POINTER_TYPE
   14852           26 :                && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
   14853              :         {
   14854           26 :           result_type = type0;
   14855           26 :           pedwarn (location, 0, "comparison between pointer and integer");
   14856              :         }
   14857           64 :       else if ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE)
   14858           21 :                && code1 == POINTER_TYPE)
   14859              :         {
   14860            8 :           result_type = type1;
   14861            8 :           pedwarn (location, 0, "comparison between pointer and integer");
   14862              :         }
   14863              :       /* 6.5.9: One of the following shall hold:
   14864              :          -- both operands have type nullptr_t;  */
   14865           56 :       else if (code0 == NULLPTR_TYPE && code1 == NULLPTR_TYPE)
   14866              :         {
   14867           22 :           result_type = nullptr_type_node;
   14868              :           /* No need to convert the operands to result_type later.  */
   14869           22 :           converted = 1;
   14870              :         }
   14871              :     /* -- one operand has type nullptr_t and the other is a null pointer
   14872              :        constant.  We will have to convert the former to the type of the
   14873              :        latter, because during gimplification we can't have mismatching
   14874              :        comparison operand type.  We convert from nullptr_t to the other
   14875              :        type, since only nullptr_t can be converted to nullptr_t.  Also,
   14876              :        even a constant 0 is a null pointer constant, so we may have to
   14877              :        create a pointer type from its type.  */
   14878           34 :       else if (code0 == NULLPTR_TYPE && null_pointer_constant_p (orig_op1))
   14879           19 :         result_type = (INTEGRAL_TYPE_P (type1)
   14880           19 :                        ? c_build_pointer_type (type1) : type1);
   14881           15 :       else if (code1 == NULLPTR_TYPE && null_pointer_constant_p (orig_op0))
   14882           11 :         result_type = (INTEGRAL_TYPE_P (type0)
   14883           11 :                        ? c_build_pointer_type (type0) : type0);
   14884      4997776 :       if ((C_BOOLEAN_TYPE_P (TREE_TYPE (orig_op0))
   14885      3307093 :            || truth_value_p (TREE_CODE (orig_op0)))
   14886      3374049 :           ^ (C_BOOLEAN_TYPE_P (TREE_TYPE (orig_op1))
   14887      3374045 :              || truth_value_p (TREE_CODE (orig_op1))))
   14888        71242 :         maybe_warn_bool_compare (location, code, orig_op0, orig_op1);
   14889              :       break;
   14890              : 
   14891       995982 :     case LE_EXPR:
   14892       995982 :     case GE_EXPR:
   14893       995982 :     case LT_EXPR:
   14894       995982 :     case GT_EXPR:
   14895       995982 :       if (gnu_vector_type_p (type0) && gnu_vector_type_p (type1))
   14896              :         {
   14897        59015 :           tree intt;
   14898        59015 :           if (!vector_types_compatible_elements_p (type0, type1))
   14899              :             {
   14900            5 :               error_at (location, "comparing vectors with different "
   14901              :                                   "element types");
   14902            5 :               return error_mark_node;
   14903              :             }
   14904              : 
   14905        59010 :           if (maybe_ne (TYPE_VECTOR_SUBPARTS (type0),
   14906       118020 :                         TYPE_VECTOR_SUBPARTS (type1)))
   14907              :             {
   14908            0 :               error_at (location, "comparing vectors with different "
   14909              :                                   "number of elements");
   14910            0 :               return error_mark_node;
   14911              :             }
   14912              : 
   14913              :           /* It's not precisely specified how the usual arithmetic
   14914              :              conversions apply to the vector types.  Here, we use
   14915              :              the unsigned type if one of the operands is signed and
   14916              :              the other one is unsigned.  */
   14917        59010 :           if (TYPE_UNSIGNED (type0) != TYPE_UNSIGNED (type1))
   14918              :             {
   14919           15 :               if (!TYPE_UNSIGNED (type0))
   14920            8 :                 op0 = build1 (VIEW_CONVERT_EXPR, type1, op0);
   14921              :               else
   14922            7 :                 op1 = build1 (VIEW_CONVERT_EXPR, type0, op1);
   14923           15 :               warning_at (location, OPT_Wsign_compare, "comparison between "
   14924              :                           "types %qT and %qT", type0, type1);
   14925              :             }
   14926              : 
   14927              :           /* Always construct signed integer vector type.  */
   14928       177030 :           intt = c_common_type_for_size (GET_MODE_BITSIZE
   14929       118020 :                                          (SCALAR_TYPE_MODE
   14930              :                                           (TREE_TYPE (type0))), 0);
   14931        59010 :           if (!intt)
   14932              :             {
   14933            0 :               error_at (location, "could not find an integer type "
   14934              :                                   "of the same size as %qT",
   14935            0 :                         TREE_TYPE (type0));
   14936            0 :               return error_mark_node;
   14937              :             }
   14938        59010 :           result_type = build_opaque_vector_type (intt,
   14939        59010 :                                                   TYPE_VECTOR_SUBPARTS (type0));
   14940        59010 :           converted = 1;
   14941        59010 :           ret = build_vec_cmp (resultcode, result_type, op0, op1);
   14942        59010 :           goto return_build_binary_op;
   14943              :         }
   14944       936967 :       build_type = integer_type_node;
   14945       936967 :       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
   14946        64638 :            || code0 == BITINT_TYPE || code0 == FIXED_POINT_TYPE)
   14947       872875 :           && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
   14948              :               || code1 == BITINT_TYPE || code1 == FIXED_POINT_TYPE))
   14949              :         short_compare = 1;
   14950        64124 :       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
   14951              :         {
   14952        64057 :           addr_space_t as0 = TYPE_ADDR_SPACE (TREE_TYPE (type0));
   14953        64057 :           addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (type1));
   14954        64057 :           addr_space_t as_common;
   14955              : 
   14956        64057 :           if (comp_target_types (location, type0, type1))
   14957              :             {
   14958        63944 :               result_type = common_pointer_type (type0, type1, NULL_TREE);
   14959        63944 :               if (!COMPLETE_TYPE_P (TREE_TYPE (type0))
   14960        63944 :                   != !COMPLETE_TYPE_P (TREE_TYPE (type1)))
   14961           32 :                 pedwarn_c99 (location, OPT_Wpedantic,
   14962              :                              "comparison of complete and incomplete pointers");
   14963        63912 :               else if (TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE)
   14964            0 :                 pedwarn (location, OPT_Wpedantic, "ISO C forbids "
   14965              :                          "ordered comparisons of pointers to functions");
   14966        63912 :               else if (null_pointer_constant_p (orig_op0)
   14967        63912 :                        || null_pointer_constant_p (orig_op1))
   14968            8 :                 warning_at (location, OPT_Wextra,
   14969              :                             "ordered comparison of pointer with null pointer");
   14970              : 
   14971              :             }
   14972          113 :           else if (!addr_space_superset (as0, as1, &as_common))
   14973              :             {
   14974            0 :               error_at (location, "comparison of pointers to "
   14975              :                         "disjoint address spaces");
   14976            0 :               return error_mark_node;
   14977              :             }
   14978              :           else
   14979              :             {
   14980          113 :               int qual = ENCODE_QUAL_ADDR_SPACE (as_common);
   14981          113 :               result_type = c_build_pointer_type
   14982          113 :                               (c_build_qualified_type (void_type_node, qual));
   14983          113 :               pedwarn (location, OPT_Wcompare_distinct_pointer_types,
   14984              :                        "comparison of distinct pointer types lacks a cast");
   14985              :             }
   14986              :         }
   14987           67 :       else if (code0 == POINTER_TYPE && null_pointer_constant_p (orig_op1))
   14988              :         {
   14989           17 :           result_type = type0;
   14990           17 :           if (pedantic)
   14991           11 :             pedwarn (location, OPT_Wpedantic,
   14992              :                      "ordered comparison of pointer with integer zero");
   14993            6 :           else if (extra_warnings)
   14994            1 :             warning_at (location, OPT_Wextra,
   14995              :                         "ordered comparison of pointer with integer zero");
   14996              :         }
   14997           50 :       else if (code1 == POINTER_TYPE && null_pointer_constant_p (orig_op0))
   14998              :         {
   14999           12 :           result_type = type1;
   15000           12 :           if (pedantic)
   15001            2 :             pedwarn (location, OPT_Wpedantic,
   15002              :                      "ordered comparison of pointer with integer zero");
   15003           10 :           else if (extra_warnings)
   15004            1 :             warning_at (location, OPT_Wextra,
   15005              :                         "ordered comparison of pointer with integer zero");
   15006              :         }
   15007           38 :       else if (code0 == POINTER_TYPE
   15008           18 :                && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE))
   15009              :         {
   15010           18 :           result_type = type0;
   15011           18 :           pedwarn (location, 0, "comparison between pointer and integer");
   15012              :         }
   15013           20 :       else if ((code0 == INTEGER_TYPE || code0 == BITINT_TYPE)
   15014           20 :                && code1 == POINTER_TYPE)
   15015              :         {
   15016           18 :           result_type = type1;
   15017           18 :           pedwarn (location, 0, "comparison between pointer and integer");
   15018              :         }
   15019              : 
   15020       936967 :       if ((code0 == POINTER_TYPE || code1 == POINTER_TYPE)
   15021        64122 :           && current_function_decl != NULL_TREE
   15022      1001078 :           && sanitize_flags_p (SANITIZE_POINTER_COMPARE))
   15023              :         {
   15024           35 :           op0 = save_expr (c_fully_fold (op0, false, NULL));
   15025           35 :           op1 = save_expr (c_fully_fold (op1, false, NULL));
   15026              : 
   15027           35 :           tree tt = builtin_decl_explicit (BUILT_IN_ASAN_POINTER_COMPARE);
   15028           35 :           instrument_expr = build_call_expr_loc (location, tt, 2, op0, op1);
   15029              :         }
   15030              : 
   15031      2810809 :       if ((C_BOOLEAN_TYPE_P (TREE_TYPE (orig_op0))
   15032      1873842 :            || truth_value_p (TREE_CODE (orig_op0)))
   15033      1873859 :           ^ (C_BOOLEAN_TYPE_P (TREE_TYPE (orig_op1))
   15034      1873859 :              || truth_value_p (TREE_CODE (orig_op1))))
   15035          511 :         maybe_warn_bool_compare (location, code, orig_op0, orig_op1);
   15036              :       break;
   15037              : 
   15038           43 :     case MIN_EXPR:
   15039           43 :     case MAX_EXPR:
   15040              :       /* Used for OpenMP atomics.  */
   15041           43 :       gcc_assert (flag_openmp);
   15042              :       common = 1;
   15043              :       break;
   15044              : 
   15045            0 :     default:
   15046            0 :       gcc_unreachable ();
   15047              :     }
   15048              : 
   15049     15425106 :   if (code0 == ERROR_MARK || code1 == ERROR_MARK)
   15050            0 :     return error_mark_node;
   15051              : 
   15052     15425106 :   if (gnu_vector_type_p (type0)
   15053      1476434 :       && gnu_vector_type_p (type1)
   15054     16900711 :       && (!tree_int_cst_equal (TYPE_SIZE (type0), TYPE_SIZE (type1))
   15055      1475585 :           || !vector_types_compatible_elements_p (type0, type1)))
   15056              :     {
   15057           26 :       gcc_rich_location richloc (location);
   15058           26 :       maybe_range_label_for_tree_type_mismatch
   15059           26 :         label_for_op0 (orig_op0, orig_op1),
   15060           26 :         label_for_op1 (orig_op1, orig_op0);
   15061           26 :       richloc.maybe_add_expr (orig_op0, &label_for_op0, highlight_colors::lhs);
   15062           26 :       richloc.maybe_add_expr (orig_op1, &label_for_op1, highlight_colors::rhs);
   15063           26 :       binary_op_error (&richloc, code, type0, type1);
   15064           26 :       return error_mark_node;
   15065           26 :     }
   15066              : 
   15067     15425080 :   if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE
   15068      1729473 :        || code0 == FIXED_POINT_TYPE || code0 == BITINT_TYPE
   15069      1661638 :        || gnu_vector_type_p (type0))
   15070     16969323 :       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE || code1 == COMPLEX_TYPE
   15071      1569068 :           || code1 == FIXED_POINT_TYPE || code1 == BITINT_TYPE
   15072      1477688 :           || gnu_vector_type_p (type1)))
   15073              :     {
   15074     15237746 :       bool first_complex = (code0 == COMPLEX_TYPE);
   15075     15237746 :       bool second_complex = (code1 == COMPLEX_TYPE);
   15076     15237746 :       int none_complex = (!first_complex && !second_complex);
   15077              : 
   15078     15237746 :       if (shorten || common || short_compare)
   15079              :         {
   15080     13697282 :           result_type = c_common_type (type0, type1);
   15081     13697282 :           do_warn_double_promotion (result_type, type0, type1,
   15082              :                                     "implicit conversion from %qT to %qT "
   15083              :                                     "to match other operand of binary "
   15084              :                                     "expression",
   15085              :                                     location);
   15086     13697282 :           if (result_type == error_mark_node)
   15087              :             return error_mark_node;
   15088              :         }
   15089              : 
   15090     15237724 :       if (first_complex != second_complex
   15091        82043 :           && (code == PLUS_EXPR
   15092              :               || code == MINUS_EXPR
   15093        82043 :               || code == MULT_EXPR
   15094        17525 :               || (code == TRUNC_DIV_EXPR && first_complex))
   15095        65932 :           && TREE_CODE (TREE_TYPE (result_type)) == REAL_TYPE
   15096     15299978 :           && flag_signed_zeros)
   15097              :         {
   15098              :           /* An operation on mixed real/complex operands must be
   15099              :              handled specially, but the language-independent code can
   15100              :              more easily optimize the plain complex arithmetic if
   15101              :              -fno-signed-zeros.  */
   15102        61942 :           tree real_type = TREE_TYPE (result_type);
   15103        61942 :           tree real, imag;
   15104        61942 :           if (type0 != orig_type0 || type1 != orig_type1)
   15105              :             {
   15106           94 :               gcc_assert (may_need_excess_precision && common);
   15107           94 :               semantic_result_type = c_common_type (orig_type0, orig_type1);
   15108              :             }
   15109        61942 :           if (first_complex)
   15110              :             {
   15111         8253 :               if (TREE_TYPE (op0) != result_type)
   15112         1787 :                 op0 = convert_and_check (location, result_type, op0);
   15113         8253 :               if (TREE_TYPE (op1) != real_type)
   15114         4601 :                 op1 = convert_and_check (location, real_type, op1);
   15115              :             }
   15116              :           else
   15117              :             {
   15118        53689 :               if (TREE_TYPE (op0) != real_type)
   15119         2698 :                 op0 = convert_and_check (location, real_type, op0);
   15120        53689 :               if (TREE_TYPE (op1) != result_type)
   15121         1866 :                 op1 = convert_and_check (location, result_type, op1);
   15122              :             }
   15123        61942 :           if (TREE_CODE (op0) == ERROR_MARK || TREE_CODE (op1) == ERROR_MARK)
   15124            0 :             return error_mark_node;
   15125        61942 :           if (first_complex)
   15126              :             {
   15127         8253 :               op0 = save_expr (op0);
   15128         8253 :               real = build_unary_op (EXPR_LOCATION (orig_op0), REALPART_EXPR,
   15129              :                                      op0, true);
   15130         8253 :               imag = build_unary_op (EXPR_LOCATION (orig_op0), IMAGPART_EXPR,
   15131              :                                      op0, true);
   15132         8253 :               switch (code)
   15133              :                 {
   15134         3488 :                 case MULT_EXPR:
   15135         3488 :                 case TRUNC_DIV_EXPR:
   15136         3488 :                   op1 = save_expr (op1);
   15137         3488 :                   imag = build2 (resultcode, real_type, imag, op1);
   15138              :                   /* Fall through.  */
   15139         8253 :                 case PLUS_EXPR:
   15140         8253 :                 case MINUS_EXPR:
   15141         8253 :                   real = build2 (resultcode, real_type, real, op1);
   15142         8253 :                   break;
   15143            0 :                 default:
   15144            0 :                   gcc_unreachable();
   15145              :                 }
   15146              :             }
   15147              :           else
   15148              :             {
   15149        53689 :               op1 = save_expr (op1);
   15150        53689 :               real = build_unary_op (EXPR_LOCATION (orig_op1), REALPART_EXPR,
   15151              :                                      op1, true);
   15152        53689 :               imag = build_unary_op (EXPR_LOCATION (orig_op1), IMAGPART_EXPR,
   15153              :                                      op1, true);
   15154        53689 :               switch (code)
   15155              :                 {
   15156         2008 :                 case MULT_EXPR:
   15157         2008 :                   op0 = save_expr (op0);
   15158         2008 :                   imag = build2 (resultcode, real_type, op0, imag);
   15159              :                   /* Fall through.  */
   15160        31957 :                 case PLUS_EXPR:
   15161        31957 :                   real = build2 (resultcode, real_type, op0, real);
   15162        31957 :                   break;
   15163        21732 :                 case MINUS_EXPR:
   15164        21732 :                   real = build2 (resultcode, real_type, op0, real);
   15165        21732 :                   imag = build1 (NEGATE_EXPR, real_type, imag);
   15166        21732 :                   break;
   15167            0 :                 default:
   15168            0 :                   gcc_unreachable();
   15169              :                 }
   15170              :             }
   15171        61942 :           ret = build2 (COMPLEX_EXPR, result_type, real, imag);
   15172        61942 :           goto return_build_binary_op;
   15173              :         }
   15174              : 
   15175              :       /* For certain operations (which identify themselves by shorten != 0)
   15176              :          if both args were extended from the same smaller type,
   15177              :          do the arithmetic in that type and then extend.
   15178              : 
   15179              :          shorten !=0 and !=1 indicates a bitwise operation.
   15180              :          For them, this optimization is safe only if
   15181              :          both args are zero-extended or both are sign-extended.
   15182              :          Otherwise, we might change the result.
   15183              :          Eg, (short)-1 | (unsigned short)-1 is (int)-1
   15184              :          but calculated in (unsigned short) it would be (unsigned short)-1.  */
   15185              : 
   15186     15175782 :       if (shorten && none_complex)
   15187              :         {
   15188      1291694 :           final_type = result_type;
   15189      1291694 :           result_type = shorten_binary_op (result_type, op0, op1,
   15190              :                                            shorten == -1);
   15191              :         }
   15192              : 
   15193              :       /* Shifts can be shortened if shifting right.  */
   15194              : 
   15195     15175782 :       if (short_shift)
   15196              :         {
   15197       200213 :           int unsigned_arg;
   15198       200213 :           tree arg0 = get_narrower (op0, &unsigned_arg);
   15199              : 
   15200       200213 :           final_type = result_type;
   15201              : 
   15202       200213 :           if (arg0 == op0 && final_type == TREE_TYPE (op0))
   15203       140846 :             unsigned_arg = TYPE_UNSIGNED (TREE_TYPE (op0));
   15204              : 
   15205       200213 :           if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type)
   15206         2982 :               && tree_int_cst_sgn (op1) > 0
   15207              :               /* We can shorten only if the shift count is less than the
   15208              :                  number of bits in the smaller type size.  */
   15209         2982 :               && compare_tree_int (op1, TYPE_PRECISION (TREE_TYPE (arg0))) < 0
   15210              :               /* We cannot drop an unsigned shift after sign-extension.  */
   15211       203055 :               && (!TYPE_UNSIGNED (final_type) || unsigned_arg))
   15212              :             {
   15213              :               /* Do an unsigned shift if the operand was zero-extended.  */
   15214         2828 :               result_type
   15215         2828 :                 = c_common_signed_or_unsigned_type (unsigned_arg,
   15216         2828 :                                                     TREE_TYPE (arg0));
   15217              :               /* Convert value-to-be-shifted to that type.  */
   15218         2828 :               if (TREE_TYPE (op0) != result_type)
   15219         2828 :                 op0 = convert (result_type, op0);
   15220              :               converted = 1;
   15221              :             }
   15222              :         }
   15223              : 
   15224              :       /* Comparison operations are shortened too but differently.
   15225              :          They identify themselves by setting short_compare = 1.  */
   15226              : 
   15227     15175782 :       if (short_compare)
   15228              :         {
   15229              :           /* Don't write &op0, etc., because that would prevent op0
   15230              :              from being kept in a register.
   15231              :              Instead, make copies of the our local variables and
   15232              :              pass the copies by reference, then copy them back afterward.  */
   15233      2442510 :           tree xop0 = op0, xop1 = op1, xresult_type = result_type;
   15234      2442510 :           enum tree_code xresultcode = resultcode;
   15235      2442510 :           tree val
   15236      2442510 :             = shorten_compare (location, &xop0, &xop1, &xresult_type,
   15237              :                                &xresultcode);
   15238              : 
   15239      2442510 :           if (val != NULL_TREE)
   15240              :             {
   15241        15787 :               ret = val;
   15242        15787 :               goto return_build_binary_op;
   15243              :             }
   15244              : 
   15245      2426723 :           op0 = xop0, op1 = xop1;
   15246      2426723 :           converted = 1;
   15247      2426723 :           resultcode = xresultcode;
   15248              : 
   15249      2426723 :           if (c_inhibit_evaluation_warnings == 0 && !c_in_omp_for)
   15250              :             {
   15251      2279081 :               bool op0_maybe_const = true;
   15252      2279081 :               bool op1_maybe_const = true;
   15253      2279081 :               tree orig_op0_folded, orig_op1_folded;
   15254              : 
   15255      2279081 :               if (in_late_binary_op)
   15256              :                 {
   15257              :                   orig_op0_folded = orig_op0;
   15258              :                   orig_op1_folded = orig_op1;
   15259              :                 }
   15260              :               else
   15261              :                 {
   15262              :                   /* Fold for the sake of possible warnings, as in
   15263              :                      build_conditional_expr.  This requires the
   15264              :                      "original" values to be folded, not just op0 and
   15265              :                      op1.  */
   15266      2270707 :                   c_inhibit_evaluation_warnings++;
   15267      2270707 :                   op0 = c_fully_fold (op0, require_constant_value,
   15268              :                                       &op0_maybe_const);
   15269      2270707 :                   op1 = c_fully_fold (op1, require_constant_value,
   15270              :                                       &op1_maybe_const);
   15271      2270707 :                   c_inhibit_evaluation_warnings--;
   15272      2270707 :                   orig_op0_folded = c_fully_fold (orig_op0,
   15273              :                                                   require_constant_value,
   15274              :                                                   NULL);
   15275      2270707 :                   orig_op1_folded = c_fully_fold (orig_op1,
   15276              :                                                   require_constant_value,
   15277              :                                                   NULL);
   15278              :                 }
   15279              : 
   15280      2279081 :               if (warn_sign_compare)
   15281       373474 :                 warn_for_sign_compare (location, orig_op0_folded,
   15282              :                                        orig_op1_folded, op0, op1,
   15283              :                                        result_type, resultcode);
   15284      2279081 :               if (!in_late_binary_op && !int_operands)
   15285              :                 {
   15286      2094639 :                   if (!op0_maybe_const || TREE_CODE (op0) != INTEGER_CST)
   15287      2091117 :                     op0 = c_wrap_maybe_const (op0, !op0_maybe_const);
   15288      2094639 :                   if (!op1_maybe_const || TREE_CODE (op1) != INTEGER_CST)
   15289       825022 :                     op1 = c_wrap_maybe_const (op1, !op1_maybe_const);
   15290              :                 }
   15291              :             }
   15292              :         }
   15293              :     }
   15294              : 
   15295              :   /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
   15296              :      If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
   15297              :      Then the expression will be built.
   15298              :      It will be given type FINAL_TYPE if that is nonzero;
   15299              :      otherwise, it will be given type RESULT_TYPE.  */
   15300              : 
   15301     15347329 :   if (!result_type)
   15302              :     {
   15303              :       /* Favor showing any expression locations that are available. */
   15304          514 :       op_location_t oploc (location, UNKNOWN_LOCATION);
   15305          514 :       binary_op_rich_location richloc (oploc, orig_op0, orig_op1, true);
   15306          514 :       binary_op_error (&richloc, code, TREE_TYPE (op0), TREE_TYPE (op1));
   15307          514 :       return error_mark_node;
   15308          514 :     }
   15309              : 
   15310     15346815 :   if (build_type == NULL_TREE)
   15311              :     {
   15312     12734985 :       build_type = result_type;
   15313     12734985 :       if ((type0 != orig_type0 || type1 != orig_type1)
   15314          797 :           && !boolean_op)
   15315              :         {
   15316          797 :           gcc_assert (may_need_excess_precision && common);
   15317          797 :           semantic_result_type = c_common_type (orig_type0, orig_type1);
   15318              :         }
   15319              :     }
   15320              : 
   15321     15346815 :   if (!converted)
   15322              :     {
   15323     11376672 :       op0 = ep_convert_and_check (location, result_type, op0,
   15324              :                                   semantic_result_type);
   15325     11376672 :       op1 = ep_convert_and_check (location, result_type, op1,
   15326              :                                   semantic_result_type);
   15327              : 
   15328              :       /* This can happen if one operand has a vector type, and the other
   15329              :          has a different type.  */
   15330     11376672 :       if (TREE_CODE (op0) == ERROR_MARK || TREE_CODE (op1) == ERROR_MARK)
   15331            3 :         return error_mark_node;
   15332              :     }
   15333              : 
   15334     15346812 :   if (sanitize_flags_p ((SANITIZE_SHIFT
   15335              :                          | SANITIZE_DIVIDE
   15336              :                          | SANITIZE_FLOAT_DIVIDE
   15337              :                          | SANITIZE_SI_OVERFLOW))
   15338        23309 :       && current_function_decl != NULL_TREE
   15339        19846 :       && (doing_div_or_mod || doing_shift)
   15340     15349737 :       && !require_constant_value)
   15341              :     {
   15342              :       /* OP0 and/or OP1 might have side-effects.  */
   15343         2869 :       op0 = save_expr (op0);
   15344         2869 :       op1 = save_expr (op1);
   15345         2869 :       op0 = c_fully_fold (op0, false, NULL);
   15346         2869 :       op1 = c_fully_fold (op1, false, NULL);
   15347         2869 :       if (doing_div_or_mod && (sanitize_flags_p ((SANITIZE_DIVIDE
   15348              :                                                   | SANITIZE_FLOAT_DIVIDE
   15349              :                                                   | SANITIZE_SI_OVERFLOW))))
   15350          912 :         instrument_expr = ubsan_instrument_division (location, op0, op1);
   15351         1957 :       else if (doing_shift && sanitize_flags_p (SANITIZE_SHIFT))
   15352         1777 :         instrument_expr = ubsan_instrument_shift (location, code, op0, op1);
   15353              :     }
   15354              : 
   15355              :   /* Treat expressions in initializers specially as they can't trap.  */
   15356     15346812 :   if (int_const_or_overflow)
   15357      7908997 :     ret = (require_constant_value
   15358      7908997 :            ? fold_build2_initializer_loc (location, resultcode, build_type,
   15359              :                                           op0, op1)
   15360      7862875 :            : fold_build2_loc (location, resultcode, build_type, op0, op1));
   15361              :   else
   15362      7437815 :     ret = build2 (resultcode, build_type, op0, op1);
   15363     15346812 :   if (final_type != NULL_TREE)
   15364      1491907 :     ret = convert (final_type, ret);
   15365              : 
   15366     13854905 :  return_build_binary_op:
   15367     16794885 :   gcc_assert (ret != error_mark_node);
   15368     16794885 :   if (TREE_CODE (ret) == INTEGER_CST && !TREE_OVERFLOW (ret) && !int_const)
   15369         1750 :     ret = (int_operands
   15370         1750 :            ? note_integer_operands (ret)
   15371          430 :            : build1 (NOP_EXPR, TREE_TYPE (ret), ret));
   15372     16793135 :   else if (TREE_CODE (ret) != INTEGER_CST && int_operands
   15373        60300 :            && !in_late_binary_op)
   15374        60300 :     ret = note_integer_operands (ret);
   15375     16794885 :   protected_set_expr_location (ret, location);
   15376              : 
   15377     16794885 :   if (instrument_expr != NULL)
   15378         1420 :     ret = fold_build2 (COMPOUND_EXPR, TREE_TYPE (ret),
   15379              :                        instrument_expr, ret);
   15380              : 
   15381     16794885 :   if (semantic_result_type)
   15382          891 :     ret = build1_loc (location, EXCESS_PRECISION_EXPR,
   15383              :                       semantic_result_type, ret);
   15384              : 
   15385              :   return ret;
   15386              : }
   15387              : 
   15388              : 
   15389              : /* Convert EXPR to be a truth-value (type TYPE), validating its type for this
   15390              :    purpose.  LOCATION is the source location for the expression.  */
   15391              : 
   15392              : tree
   15393      4114930 : c_objc_common_truthvalue_conversion (location_t location, tree expr, tree type)
   15394              : {
   15395      4114930 :   bool int_const, int_operands;
   15396              : 
   15397      4114930 :   switch (TREE_CODE (TREE_TYPE (expr)))
   15398              :     {
   15399           72 :     case ARRAY_TYPE:
   15400           72 :       error_at (location, "used array that cannot be converted to pointer where scalar is required");
   15401           72 :       return error_mark_node;
   15402              : 
   15403           86 :     case RECORD_TYPE:
   15404           86 :       error_at (location, "used struct type value where scalar is required");
   15405           86 :       return error_mark_node;
   15406              : 
   15407           83 :     case UNION_TYPE:
   15408           83 :       error_at (location, "used union type value where scalar is required");
   15409           83 :       return error_mark_node;
   15410              : 
   15411           22 :     case VOID_TYPE:
   15412           22 :       error_at (location, "void value not ignored as it ought to be");
   15413           22 :       return error_mark_node;
   15414              : 
   15415        30399 :     case POINTER_TYPE:
   15416        30399 :       if (reject_gcc_builtin (expr))
   15417            3 :         return error_mark_node;
   15418              :       break;
   15419              : 
   15420            0 :     case FUNCTION_TYPE:
   15421            0 :       gcc_unreachable ();
   15422              : 
   15423            8 :     case VECTOR_TYPE:
   15424            8 :       error_at (location, "used vector type where scalar is required");
   15425            8 :       return error_mark_node;
   15426              : 
   15427              :     default:
   15428              :       break;
   15429              :     }
   15430              : 
   15431              :   /* Conversion of a floating constant to boolean goes through here
   15432              :      and yields an integer constant expression.  Otherwise, the result
   15433              :      is only an integer constant expression if the argument is.  */
   15434       894249 :   int_const = ((TREE_CODE (expr) == INTEGER_CST && !TREE_OVERFLOW (expr))
   15435      4114732 :                || ((TREE_CODE (expr) == REAL_CST
   15436      3220109 :                     || TREE_CODE (expr) == COMPLEX_CST)
   15437          374 :                    && (TREE_CODE (type) == BOOLEAN_TYPE
   15438           15 :                        || (TREE_CODE (type) == ENUMERAL_TYPE
   15439            5 :                            && ENUM_UNDERLYING_TYPE (type) != NULL_TREE
   15440            5 :                            && (TREE_CODE (ENUM_UNDERLYING_TYPE (type))
   15441              :                                == BOOLEAN_TYPE)))));
   15442      4114656 :   int_operands = EXPR_INT_CONST_OPERANDS (expr);
   15443       894409 :   if (int_operands && TREE_CODE (expr) != INTEGER_CST)
   15444              :     {
   15445          319 :       expr = remove_c_maybe_const_expr (expr);
   15446          319 :       expr = build2 (NE_EXPR, type, expr,
   15447          319 :                      convert (TREE_TYPE (expr), integer_zero_node));
   15448          319 :       expr = note_integer_operands (expr);
   15449              :     }
   15450              :   else
   15451              :     {
   15452              :       /* ??? Should we also give an error for vectors rather than leaving
   15453              :          those to give errors later?  */
   15454      4114337 :       expr = c_common_truthvalue_conversion (location, expr);
   15455      4114337 :       expr = fold_convert_loc (location, type, expr);
   15456              :     }
   15457              : 
   15458      4114656 :   if (TREE_CODE (expr) == INTEGER_CST && int_operands && !int_const)
   15459              :     {
   15460           76 :       if (TREE_OVERFLOW (expr))
   15461              :         return expr;
   15462              :       else
   15463           76 :         return note_integer_operands (expr);
   15464              :     }
   15465      4114580 :   if (TREE_CODE (expr) == INTEGER_CST && !int_const)
   15466          754 :     return build1 (NOP_EXPR, TREE_TYPE (expr), expr);
   15467              :   return expr;
   15468              : }
   15469              : 
   15470              : 
   15471              : /* Convert EXPR to a contained DECL, updating *TC, *TI and *SE as
   15472              :    required.  */
   15473              : 
   15474              : tree
   15475    118801342 : c_expr_to_decl (tree expr, bool *tc ATTRIBUTE_UNUSED, bool *se)
   15476              : {
   15477    118801342 :   if (TREE_CODE (expr) == COMPOUND_LITERAL_EXPR)
   15478              :     {
   15479          699 :       tree decl = COMPOUND_LITERAL_EXPR_DECL (expr);
   15480              :       /* Executing a compound literal inside a function reinitializes
   15481              :          it.  */
   15482          699 :       if (!TREE_STATIC (decl))
   15483          433 :         *se = true;
   15484          699 :       return decl;
   15485              :     }
   15486              :   else
   15487              :     return expr;
   15488              : }
   15489              : 
   15490              : /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
   15491              :    statement.  LOC is the location of the construct.  */
   15492              : 
   15493              : tree
   15494         2154 : c_finish_omp_construct (location_t loc, enum tree_code code, tree body,
   15495              :                         tree clauses)
   15496              : {
   15497         2154 :   body = c_end_compound_stmt (loc, body, true);
   15498              : 
   15499         2154 :   tree stmt = make_node (code);
   15500         2154 :   TREE_TYPE (stmt) = void_type_node;
   15501         2154 :   OMP_BODY (stmt) = body;
   15502         2154 :   OMP_CLAUSES (stmt) = clauses;
   15503         2154 :   SET_EXPR_LOCATION (stmt, loc);
   15504              : 
   15505         2154 :   return add_stmt (stmt);
   15506              : }
   15507              : 
   15508              : /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
   15509              :    statement.  LOC is the location of the OACC_DATA.  */
   15510              : 
   15511              : tree
   15512          497 : c_finish_oacc_data (location_t loc, tree clauses, tree block)
   15513              : {
   15514          497 :   tree stmt;
   15515              : 
   15516          497 :   block = c_end_compound_stmt (loc, block, true);
   15517              : 
   15518          497 :   stmt = make_node (OACC_DATA);
   15519          497 :   TREE_TYPE (stmt) = void_type_node;
   15520          497 :   OACC_DATA_CLAUSES (stmt) = clauses;
   15521          497 :   OACC_DATA_BODY (stmt) = block;
   15522          497 :   SET_EXPR_LOCATION (stmt, loc);
   15523              : 
   15524          497 :   return add_stmt (stmt);
   15525              : }
   15526              : 
   15527              : /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
   15528              :    statement.  LOC is the location of the OACC_HOST_DATA.  */
   15529              : 
   15530              : tree
   15531           21 : c_finish_oacc_host_data (location_t loc, tree clauses, tree block)
   15532              : {
   15533           21 :   tree stmt;
   15534              : 
   15535           21 :   block = c_end_compound_stmt (loc, block, true);
   15536              : 
   15537           21 :   stmt = make_node (OACC_HOST_DATA);
   15538           21 :   TREE_TYPE (stmt) = void_type_node;
   15539           21 :   OACC_HOST_DATA_CLAUSES (stmt) = clauses;
   15540           21 :   OACC_HOST_DATA_BODY (stmt) = block;
   15541           21 :   SET_EXPR_LOCATION (stmt, loc);
   15542              : 
   15543           21 :   return add_stmt (stmt);
   15544              : }
   15545              : 
   15546              : /* Like c_begin_compound_stmt, except force the retention of the BLOCK.  */
   15547              : 
   15548              : tree
   15549        12003 : c_begin_omp_parallel (void)
   15550              : {
   15551        12003 :   tree block;
   15552              : 
   15553        12003 :   keep_next_level ();
   15554        12003 :   block = c_begin_compound_stmt (true);
   15555              : 
   15556        12003 :   return block;
   15557              : }
   15558              : 
   15559              : /* Generate OMP_PARALLEL, with CLAUSES and BLOCK as its compound
   15560              :    statement.  LOC is the location of the OMP_PARALLEL.  */
   15561              : 
   15562              : tree
   15563         5677 : c_finish_omp_parallel (location_t loc, tree clauses, tree block)
   15564              : {
   15565         5677 :   tree stmt;
   15566              : 
   15567         5677 :   block = c_end_compound_stmt (loc, block, true);
   15568              : 
   15569         5677 :   stmt = make_node (OMP_PARALLEL);
   15570         5677 :   TREE_TYPE (stmt) = void_type_node;
   15571         5677 :   OMP_PARALLEL_CLAUSES (stmt) = clauses;
   15572         5677 :   OMP_PARALLEL_BODY (stmt) = block;
   15573         5677 :   SET_EXPR_LOCATION (stmt, loc);
   15574              : 
   15575         5677 :   return add_stmt (stmt);
   15576              : }
   15577              : 
   15578              : /* Like c_begin_compound_stmt, except force the retention of the BLOCK.  */
   15579              : 
   15580              : tree
   15581          898 : c_begin_omp_task (void)
   15582              : {
   15583          898 :   tree block;
   15584              : 
   15585          898 :   keep_next_level ();
   15586          898 :   block = c_begin_compound_stmt (true);
   15587              : 
   15588          898 :   return block;
   15589              : }
   15590              : 
   15591              : /* Generate OMP_TASK, with CLAUSES and BLOCK as its compound
   15592              :    statement.  LOC is the location of the #pragma.  */
   15593              : 
   15594              : tree
   15595          898 : c_finish_omp_task (location_t loc, tree clauses, tree block)
   15596              : {
   15597          898 :   tree stmt;
   15598              : 
   15599          898 :   block = c_end_compound_stmt (loc, block, true);
   15600              : 
   15601          898 :   stmt = make_node (OMP_TASK);
   15602          898 :   TREE_TYPE (stmt) = void_type_node;
   15603          898 :   OMP_TASK_CLAUSES (stmt) = clauses;
   15604          898 :   OMP_TASK_BODY (stmt) = block;
   15605          898 :   SET_EXPR_LOCATION (stmt, loc);
   15606              : 
   15607          898 :   return add_stmt (stmt);
   15608              : }
   15609              : 
   15610              : /* Generate GOMP_cancel call for #pragma omp cancel.  */
   15611              : 
   15612              : void
   15613          213 : c_finish_omp_cancel (location_t loc, tree clauses)
   15614              : {
   15615          213 :   tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL);
   15616          213 :   int mask = 0;
   15617          213 :   if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
   15618              :     mask = 1;
   15619          150 :   else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
   15620              :     mask = 2;
   15621          101 :   else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
   15622              :     mask = 4;
   15623           58 :   else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
   15624              :     mask = 8;
   15625              :   else
   15626              :     {
   15627            0 :       error_at (loc, "%<#pragma omp cancel%> must specify one of "
   15628              :                      "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> "
   15629              :                      "clauses");
   15630            0 :       return;
   15631              :     }
   15632          213 :   tree ifc = omp_find_clause (clauses, OMP_CLAUSE_IF);
   15633          213 :   if (ifc != NULL_TREE)
   15634              :     {
   15635           31 :       if (OMP_CLAUSE_IF_MODIFIER (ifc) != ERROR_MARK
   15636           31 :           && OMP_CLAUSE_IF_MODIFIER (ifc) != VOID_CST)
   15637            2 :         error_at (OMP_CLAUSE_LOCATION (ifc),
   15638              :                   "expected %<cancel%> %<if%> clause modifier");
   15639              :       else
   15640              :         {
   15641           29 :           tree ifc2 = omp_find_clause (OMP_CLAUSE_CHAIN (ifc), OMP_CLAUSE_IF);
   15642           29 :           if (ifc2 != NULL_TREE)
   15643              :             {
   15644            1 :               gcc_assert (OMP_CLAUSE_IF_MODIFIER (ifc) == VOID_CST
   15645              :                           && OMP_CLAUSE_IF_MODIFIER (ifc2) != ERROR_MARK
   15646              :                           && OMP_CLAUSE_IF_MODIFIER (ifc2) != VOID_CST);
   15647            1 :               error_at (OMP_CLAUSE_LOCATION (ifc2),
   15648              :                         "expected %<cancel%> %<if%> clause modifier");
   15649              :             }
   15650              :         }
   15651              : 
   15652           31 :       tree type = TREE_TYPE (OMP_CLAUSE_IF_EXPR (ifc));
   15653           62 :       ifc = fold_build2_loc (OMP_CLAUSE_LOCATION (ifc), NE_EXPR,
   15654           31 :                              boolean_type_node, OMP_CLAUSE_IF_EXPR (ifc),
   15655              :                              build_zero_cst (type));
   15656              :     }
   15657              :   else
   15658          182 :     ifc = boolean_true_node;
   15659          213 :   tree stmt = build_call_expr_loc (loc, fn, 2,
   15660          213 :                                    build_int_cst (integer_type_node, mask),
   15661              :                                    ifc);
   15662          213 :   add_stmt (stmt);
   15663              : }
   15664              : 
   15665              : /* Generate GOMP_cancellation_point call for
   15666              :    #pragma omp cancellation point.  */
   15667              : 
   15668              : void
   15669          167 : c_finish_omp_cancellation_point (location_t loc, tree clauses)
   15670              : {
   15671          167 :   tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT);
   15672          167 :   int mask = 0;
   15673          167 :   if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
   15674              :     mask = 1;
   15675          123 :   else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
   15676              :     mask = 2;
   15677           88 :   else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
   15678              :     mask = 4;
   15679           53 :   else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
   15680              :     mask = 8;
   15681              :   else
   15682              :     {
   15683            1 :       error_at (loc, "%<#pragma omp cancellation point%> must specify one of "
   15684              :                      "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> "
   15685              :                      "clauses");
   15686            1 :       return;
   15687              :     }
   15688          166 :   tree stmt = build_call_expr_loc (loc, fn, 1,
   15689          166 :                                    build_int_cst (integer_type_node, mask));
   15690          166 :   add_stmt (stmt);
   15691              : }
   15692              : 
   15693              : /* Helper function for handle_omp_array_sections.  Called recursively
   15694              :    to handle multiple array-section-subscripts.  C is the clause,
   15695              :    T current expression (initially OMP_CLAUSE_DECL), which is either
   15696              :    a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
   15697              :    expression if specified, TREE_VALUE length expression if specified,
   15698              :    TREE_CHAIN is what it has been specified after, or some decl.
   15699              :    TYPES vector is populated with array section types, MAYBE_ZERO_LEN
   15700              :    set to true if any of the array-section-subscript could have length
   15701              :    of zero (explicit or implicit), FIRST_NON_ONE is the index of the
   15702              :    first array-section-subscript which is known not to have length
   15703              :    of one.  Given say:
   15704              :    map(a[:b][2:1][:c][:2][:d][e:f][2:5])
   15705              :    FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
   15706              :    all are or may have length of 1, array-section-subscript [:2] is the
   15707              :    first one known not to have length 1.  For array-section-subscript
   15708              :    <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
   15709              :    0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
   15710              :    can if MAYBE_ZERO_LEN is false.  MAYBE_ZERO_LEN will be true in the above
   15711              :    case though, as some lengths could be zero.  */
   15712              : 
   15713              : static tree
   15714         6394 : handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types,
   15715              :                              bool &maybe_zero_len, unsigned int &first_non_one,
   15716              :                              enum c_omp_region_type ort)
   15717              : {
   15718         6394 :   tree ret, low_bound, length, type;
   15719         6394 :   bool openacc = (ort & C_ORT_ACC) != 0;
   15720         6394 :   if (TREE_CODE (t) != OMP_ARRAY_SECTION)
   15721              :     {
   15722         2978 :       if (error_operand_p (t))
   15723            2 :         return error_mark_node;
   15724         2976 :       c_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
   15725         2976 :       ret = t;
   15726         2976 :       if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
   15727         2877 :           && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
   15728         5539 :           && TYPE_ATOMIC (strip_array_types (TREE_TYPE (t))))
   15729              :         {
   15730            6 :           error_at (OMP_CLAUSE_LOCATION (c), "%<_Atomic%> %qE in %qs clause",
   15731            6 :                     t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   15732            6 :           return error_mark_node;
   15733              :         }
   15734         2970 :       if (!ai.check_clause (c))
   15735            0 :         return error_mark_node;
   15736         2970 :       else if (ai.component_access_p ()
   15737         3271 :                && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   15738           15 :                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO
   15739           11 :                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM))
   15740          301 :         t = ai.get_root_term (true);
   15741              :       else
   15742         2669 :         t = ai.unconverted_ref_origin ();
   15743         2970 :       if (t == error_mark_node)
   15744              :         return error_mark_node;
   15745         2970 :       if (!VAR_P (t)
   15746          741 :           && (ort == C_ORT_ACC || !EXPR_P (t))
   15747          738 :           && TREE_CODE (t) != PARM_DECL)
   15748              :         {
   15749            5 :           if (DECL_P (t))
   15750            5 :             error_at (OMP_CLAUSE_LOCATION (c),
   15751              :                       "%qD is not a variable in %qs clause", t,
   15752            5 :                       omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   15753              :           else
   15754            0 :             error_at (OMP_CLAUSE_LOCATION (c),
   15755              :                       "%qE is not a variable in %qs clause", t,
   15756            0 :                       omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   15757            5 :           return error_mark_node;
   15758              :         }
   15759         2965 :       else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
   15760         2867 :                && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
   15761         5519 :                && TYPE_ATOMIC (TREE_TYPE (t)))
   15762              :         {
   15763            0 :           error_at (OMP_CLAUSE_LOCATION (c), "%<_Atomic%> %qD in %qs clause",
   15764            0 :                     t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   15765            0 :           return error_mark_node;
   15766              :         }
   15767         2965 :       else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
   15768         2867 :                && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
   15769         2554 :                && VAR_P (t)
   15770         4971 :                && DECL_THREAD_LOCAL_P (t))
   15771              :         {
   15772            3 :           error_at (OMP_CLAUSE_LOCATION (c),
   15773              :                     "%qD is threadprivate variable in %qs clause", t,
   15774            3 :                     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   15775            3 :           return error_mark_node;
   15776              :         }
   15777         2962 :       if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
   15778         2864 :            || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND)
   15779          411 :           && TYPE_ATOMIC (TREE_TYPE (t))
   15780         2964 :           && POINTER_TYPE_P (TREE_TYPE (t)))
   15781              :         {
   15782              :           /* If the array section is pointer based and the pointer
   15783              :              itself is _Atomic qualified, we need to atomically load
   15784              :              the pointer.  */
   15785            2 :           ret = convert_lvalue_to_rvalue (OMP_CLAUSE_LOCATION (c),
   15786              :                                           ret, false, false);
   15787              :         }
   15788         2962 :       return ret;
   15789         2976 :     }
   15790              : 
   15791         3416 :   ret = handle_omp_array_sections_1 (c, TREE_OPERAND (t, 0), types,
   15792              :                                      maybe_zero_len, first_non_one, ort);
   15793         3416 :   if (ret == error_mark_node || ret == NULL_TREE)
   15794              :     return ret;
   15795              : 
   15796         3351 :   type = TREE_TYPE (ret);
   15797         3351 :   low_bound = TREE_OPERAND (t, 1);
   15798         3351 :   length = TREE_OPERAND (t, 2);
   15799              : 
   15800         3351 :   if (low_bound == error_mark_node || length == error_mark_node)
   15801              :     return error_mark_node;
   15802              : 
   15803         3351 :   if (low_bound && !INTEGRAL_TYPE_P (TREE_TYPE (low_bound)))
   15804              :     {
   15805           13 :       error_at (OMP_CLAUSE_LOCATION (c),
   15806              :                 "low bound %qE of array section does not have integral type",
   15807              :                 low_bound);
   15808           13 :       return error_mark_node;
   15809              :     }
   15810         3338 :   if (length && !INTEGRAL_TYPE_P (TREE_TYPE (length)))
   15811              :     {
   15812           12 :       error_at (OMP_CLAUSE_LOCATION (c),
   15813              :                 "length %qE of array section does not have integral type",
   15814              :                 length);
   15815           12 :       return error_mark_node;
   15816              :     }
   15817         3326 :   if (low_bound
   15818         2742 :       && TREE_CODE (low_bound) == INTEGER_CST
   15819         5779 :       && TYPE_PRECISION (TREE_TYPE (low_bound))
   15820         2453 :          > TYPE_PRECISION (sizetype))
   15821            0 :     low_bound = fold_convert (sizetype, low_bound);
   15822         3326 :   if (length
   15823         3138 :       && TREE_CODE (length) == INTEGER_CST
   15824         5519 :       && TYPE_PRECISION (TREE_TYPE (length))
   15825         2193 :          > TYPE_PRECISION (sizetype))
   15826            0 :     length = fold_convert (sizetype, length);
   15827         3326 :   if (low_bound == NULL_TREE)
   15828          584 :     low_bound = integer_zero_node;
   15829         3326 :   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   15830         3326 :       && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
   15831         1936 :           || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH))
   15832              :     {
   15833           10 :       if (length != integer_one_node)
   15834              :         {
   15835            6 :           error_at (OMP_CLAUSE_LOCATION (c),
   15836              :                     "expected single pointer in %qs clause",
   15837              :                     user_omp_clause_code_name (c, openacc));
   15838            6 :           return error_mark_node;
   15839              :         }
   15840              :     }
   15841         3320 :   if (length != NULL_TREE)
   15842              :     {
   15843         3136 :       if (!integer_nonzerop (length))
   15844              :         {
   15845          974 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
   15846              :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   15847              :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   15848              :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   15849              :               || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
   15850              :             {
   15851          180 :               if (integer_zerop (length))
   15852              :                 {
   15853           12 :                   error_at (OMP_CLAUSE_LOCATION (c),
   15854              :                             "zero length array section in %qs clause",
   15855           12 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   15856           12 :                   return error_mark_node;
   15857              :                 }
   15858              :             }
   15859              :           else
   15860          794 :             maybe_zero_len = true;
   15861              :         }
   15862         3124 :       if (first_non_one == types.length ()
   15863         3124 :           && (TREE_CODE (length) != INTEGER_CST || integer_onep (length)))
   15864         1597 :         first_non_one++;
   15865              :     }
   15866         3308 :   if (TREE_CODE (type) == ARRAY_TYPE)
   15867              :     {
   15868         1496 :       if (length == NULL_TREE
   15869         1496 :           && (TYPE_DOMAIN (type) == NULL_TREE
   15870          168 :               || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE))
   15871              :         {
   15872            8 :           error_at (OMP_CLAUSE_LOCATION (c),
   15873              :                     "for unknown bound array type length expression must "
   15874              :                     "be specified");
   15875            8 :           return error_mark_node;
   15876              :         }
   15877         1488 :       if (TREE_CODE (low_bound) == INTEGER_CST
   15878         1488 :           && tree_int_cst_sgn (low_bound) == -1)
   15879              :         {
   15880           35 :           error_at (OMP_CLAUSE_LOCATION (c),
   15881              :                     "negative low bound in array section in %qs clause",
   15882           35 :                     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   15883           35 :           return error_mark_node;
   15884              :         }
   15885         1453 :       if (length != NULL_TREE
   15886         1297 :           && TREE_CODE (length) == INTEGER_CST
   15887         2310 :           && tree_int_cst_sgn (length) == -1)
   15888              :         {
   15889           35 :           error_at (OMP_CLAUSE_LOCATION (c),
   15890              :                     "negative length in array section in %qs clause",
   15891           35 :                     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   15892           35 :           return error_mark_node;
   15893              :         }
   15894         1418 :       if (TYPE_DOMAIN (type)
   15895         1407 :           && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
   15896         2825 :           && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
   15897              :                         == INTEGER_CST)
   15898              :         {
   15899         1061 :           tree size
   15900         1061 :             = fold_convert (sizetype, TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
   15901         1061 :           size = size_binop (PLUS_EXPR, size, size_one_node);
   15902         1061 :           if (TREE_CODE (low_bound) == INTEGER_CST)
   15903              :             {
   15904          874 :               if (tree_int_cst_lt (size, low_bound))
   15905              :                 {
   15906           10 :                   error_at (OMP_CLAUSE_LOCATION (c),
   15907              :                             "low bound %qE above array section size "
   15908              :                             "in %qs clause", low_bound,
   15909           10 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   15910           10 :                   return error_mark_node;
   15911              :                 }
   15912          864 :               if (tree_int_cst_equal (size, low_bound))
   15913              :                 {
   15914            5 :                   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY
   15915              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   15916              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   15917              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   15918              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
   15919              :                     {
   15920            5 :                       error_at (OMP_CLAUSE_LOCATION (c),
   15921              :                                 "zero length array section in %qs clause",
   15922            5 :                                 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   15923            5 :                       return error_mark_node;
   15924              :                     }
   15925            0 :                   maybe_zero_len = true;
   15926              :                 }
   15927          859 :               else if (length == NULL_TREE
   15928          256 :                        && first_non_one == types.length ()
   15929          914 :                        && tree_int_cst_equal
   15930           55 :                             (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
   15931              :                              low_bound))
   15932           30 :                 first_non_one++;
   15933              :             }
   15934          187 :           else if (length == NULL_TREE)
   15935              :             {
   15936            3 :               if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
   15937              :                   && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
   15938              :                   && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
   15939              :                   && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
   15940              :                   && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
   15941            0 :                 maybe_zero_len = true;
   15942            6 :               if (first_non_one == types.length ())
   15943            1 :                 first_non_one++;
   15944              :             }
   15945         1046 :           if (length && TREE_CODE (length) == INTEGER_CST)
   15946              :             {
   15947          799 :               if (tree_int_cst_lt (size, length))
   15948              :                 {
   15949           11 :                   error_at (OMP_CLAUSE_LOCATION (c),
   15950              :                             "length %qE above array section size "
   15951              :                             "in %qs clause", length,
   15952           11 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   15953           11 :                   return error_mark_node;
   15954              :                 }
   15955          788 :               if (TREE_CODE (low_bound) == INTEGER_CST)
   15956              :                 {
   15957          688 :                   tree lbpluslen
   15958          688 :                     = size_binop (PLUS_EXPR,
   15959              :                                   fold_convert (sizetype, low_bound),
   15960              :                                   fold_convert (sizetype, length));
   15961          688 :                   if (TREE_CODE (lbpluslen) == INTEGER_CST
   15962          688 :                       && tree_int_cst_lt (size, lbpluslen))
   15963              :                     {
   15964           10 :                       error_at (OMP_CLAUSE_LOCATION (c),
   15965              :                                 "high bound %qE above array section size "
   15966              :                                 "in %qs clause", lbpluslen,
   15967           10 :                                 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   15968           10 :                       return error_mark_node;
   15969              :                     }
   15970              :                 }
   15971              :             }
   15972              :         }
   15973          357 :       else if (length == NULL_TREE)
   15974              :         {
   15975           10 :           if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
   15976              :               && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
   15977              :               && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
   15978              :               && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_IN_REDUCTION
   15979              :               && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_TASK_REDUCTION)
   15980            0 :             maybe_zero_len = true;
   15981           20 :           if (first_non_one == types.length ())
   15982           10 :             first_non_one++;
   15983              :         }
   15984              : 
   15985              :       /* For [lb:] we will need to evaluate lb more than once.  */
   15986          929 :       if (length == NULL_TREE && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
   15987              :         {
   15988          127 :           tree lb = save_expr (low_bound);
   15989          127 :           if (lb != low_bound)
   15990              :             {
   15991            2 :               TREE_OPERAND (t, 1) = lb;
   15992            2 :               low_bound = lb;
   15993              :             }
   15994              :         }
   15995              :     }
   15996         1812 :   else if (TREE_CODE (type) == POINTER_TYPE)
   15997              :     {
   15998         1801 :       if (length == NULL_TREE)
   15999              :         {
   16000           10 :           if (TREE_CODE (ret) == PARM_DECL && C_ARRAY_PARAMETER (ret))
   16001            8 :             error_at (OMP_CLAUSE_LOCATION (c),
   16002              :                       "for array function parameter length expression "
   16003              :                       "must be specified");
   16004              :           else
   16005            2 :             error_at (OMP_CLAUSE_LOCATION (c),
   16006              :                       "for pointer type length expression must be specified");
   16007           10 :           return error_mark_node;
   16008              :         }
   16009         1791 :       if (length != NULL_TREE
   16010         1791 :           && TREE_CODE (length) == INTEGER_CST
   16011         1286 :           && tree_int_cst_sgn (length) == -1)
   16012              :         {
   16013           20 :           error_at (OMP_CLAUSE_LOCATION (c),
   16014              :                     "negative length in array section in %qs clause",
   16015           20 :                     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16016           20 :           return error_mark_node;
   16017              :         }
   16018              :       /* If there is a pointer type anywhere but in the very first
   16019              :          array-section-subscript, the array section could be non-contiguous.  */
   16020         1771 :       if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
   16021         1610 :           && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
   16022         3352 :           && TREE_CODE (TREE_OPERAND (t, 0)) == OMP_ARRAY_SECTION)
   16023              :         {
   16024              :           /* If any prior dimension has a non-one length, then deem this
   16025              :              array section as non-contiguous.  */
   16026           42 :           for (tree d = TREE_OPERAND (t, 0);
   16027           82 :                TREE_CODE (d) == OMP_ARRAY_SECTION;
   16028           40 :                d = TREE_OPERAND (d, 0))
   16029              :             {
   16030           44 :               tree d_length = TREE_OPERAND (d, 2);
   16031           44 :               if (d_length == NULL_TREE || !integer_onep (d_length))
   16032              :                 {
   16033            4 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16034              :                             "array section is not contiguous in %qs clause",
   16035            4 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16036            4 :                   return error_mark_node;
   16037              :                 }
   16038              :             }
   16039              :         }
   16040              :     }
   16041              :   else
   16042              :     {
   16043           11 :       error_at (OMP_CLAUSE_LOCATION (c),
   16044              :                 "%qE does not have pointer or array type", ret);
   16045           11 :       return error_mark_node;
   16046              :     }
   16047         3149 :   if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
   16048         2833 :     types.safe_push (TREE_TYPE (ret));
   16049              :   /* We will need to evaluate lb more than once.  */
   16050         3149 :   tree lb = save_expr (low_bound);
   16051         3149 :   if (lb != low_bound)
   16052              :     {
   16053          273 :       TREE_OPERAND (t, 1) = lb;
   16054          273 :       low_bound = lb;
   16055              :     }
   16056         3149 :   ret = build_array_ref (OMP_CLAUSE_LOCATION (c), ret, low_bound);
   16057         3149 :   return ret;
   16058              : }
   16059              : 
   16060              : /* Handle array sections for clause C.  */
   16061              : 
   16062              : static bool
   16063         2978 : handle_omp_array_sections (tree &c, enum c_omp_region_type ort)
   16064              : {
   16065         2978 :   bool maybe_zero_len = false;
   16066         2978 :   unsigned int first_non_one = 0;
   16067         2978 :   auto_vec<tree, 10> types;
   16068         2978 :   tree *tp = &OMP_CLAUSE_DECL (c);
   16069         2978 :   if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   16070         2664 :        || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
   16071         3077 :       && OMP_ITERATOR_DECL_P (*tp))
   16072           66 :     tp = &TREE_VALUE (*tp);
   16073         2978 :   tree first = handle_omp_array_sections_1 (c, *tp, types,
   16074              :                                             maybe_zero_len, first_non_one,
   16075              :                                             ort);
   16076         2978 :   if (first == error_mark_node)
   16077              :     return true;
   16078         2760 :   if (first == NULL_TREE)
   16079              :     return false;
   16080         2760 :   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   16081         2760 :       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY)
   16082              :     {
   16083          336 :       tree t = *tp;
   16084          336 :       tree tem = NULL_TREE;
   16085              :       /* Need to evaluate side effects in the length expressions
   16086              :          if any.  */
   16087          336 :       while (TREE_CODE (t) == TREE_LIST)
   16088              :         {
   16089            0 :           if (TREE_VALUE (t) && TREE_SIDE_EFFECTS (TREE_VALUE (t)))
   16090              :             {
   16091            0 :               if (tem == NULL_TREE)
   16092              :                 tem = TREE_VALUE (t);
   16093              :               else
   16094            0 :                 tem = build2 (COMPOUND_EXPR, TREE_TYPE (tem),
   16095            0 :                               TREE_VALUE (t), tem);
   16096              :             }
   16097            0 :           t = TREE_CHAIN (t);
   16098              :         }
   16099          336 :       if (tem)
   16100            0 :         first = build2 (COMPOUND_EXPR, TREE_TYPE (first), tem, first);
   16101          336 :       first = c_fully_fold (first, false, NULL, true);
   16102          336 :       *tp = first;
   16103              :     }
   16104              :   else
   16105              :     {
   16106         2424 :       unsigned int num = types.length (), i;
   16107         2424 :       tree t, side_effects = NULL_TREE, size = NULL_TREE;
   16108         2424 :       tree condition = NULL_TREE;
   16109              : 
   16110         2424 :       if (int_size_in_bytes (TREE_TYPE (first)) <= 0)
   16111            3 :         maybe_zero_len = true;
   16112              : 
   16113         5048 :       for (i = num, t = OMP_CLAUSE_DECL (c); i > 0;
   16114         2624 :            t = TREE_OPERAND (t, 0))
   16115              :         {
   16116         2639 :           tree low_bound = TREE_OPERAND (t, 1);
   16117         2639 :           tree length = TREE_OPERAND (t, 2);
   16118              : 
   16119         2639 :           i--;
   16120         2639 :           if (low_bound
   16121         2175 :               && TREE_CODE (low_bound) == INTEGER_CST
   16122         4628 :               && TYPE_PRECISION (TREE_TYPE (low_bound))
   16123         1989 :                  > TYPE_PRECISION (sizetype))
   16124            0 :             low_bound = fold_convert (sizetype, low_bound);
   16125         2639 :           if (length
   16126         2547 :               && TREE_CODE (length) == INTEGER_CST
   16127         4259 :               && TYPE_PRECISION (TREE_TYPE (length))
   16128         1620 :                  > TYPE_PRECISION (sizetype))
   16129            0 :             length = fold_convert (sizetype, length);
   16130         2639 :           if (low_bound == NULL_TREE)
   16131          464 :             low_bound = integer_zero_node;
   16132         2639 :           if (!maybe_zero_len && i > first_non_one)
   16133              :             {
   16134          109 :               if (integer_nonzerop (low_bound))
   16135            6 :                 goto do_warn_noncontiguous;
   16136          103 :               if (length != NULL_TREE
   16137           50 :                   && TREE_CODE (length) == INTEGER_CST
   16138           50 :                   && TYPE_DOMAIN (types[i])
   16139           50 :                   && TYPE_MAX_VALUE (TYPE_DOMAIN (types[i]))
   16140          153 :                   && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])))
   16141              :                      == INTEGER_CST)
   16142              :                 {
   16143           50 :                   tree size;
   16144           50 :                   size = size_binop (PLUS_EXPR,
   16145              :                                      TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
   16146              :                                      size_one_node);
   16147           50 :                   if (!tree_int_cst_equal (length, size))
   16148              :                     {
   16149            7 :                      do_warn_noncontiguous:
   16150           26 :                       error_at (OMP_CLAUSE_LOCATION (c),
   16151              :                                 "array section is not contiguous in %qs "
   16152              :                                 "clause",
   16153           13 :                                 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16154         2424 :                       return true;
   16155              :                     }
   16156              :                 }
   16157           96 :               if (length != NULL_TREE
   16158           96 :                   && TREE_SIDE_EFFECTS (length))
   16159              :                 {
   16160            0 :                   if (side_effects == NULL_TREE)
   16161              :                     side_effects = length;
   16162              :                   else
   16163            0 :                     side_effects = build2 (COMPOUND_EXPR,
   16164            0 :                                            TREE_TYPE (side_effects),
   16165              :                                            length, side_effects);
   16166              :                 }
   16167              :             }
   16168              :           else
   16169              :             {
   16170         2530 :               tree l;
   16171              : 
   16172         2530 :               if (i > first_non_one
   16173         2530 :                   && ((length && integer_nonzerop (length))
   16174            0 :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   16175              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   16176              :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION))
   16177            0 :                 continue;
   16178         2530 :               if (length)
   16179         2497 :                 l = fold_convert (sizetype, length);
   16180              :               else
   16181              :                 {
   16182           33 :                   l = size_binop (PLUS_EXPR,
   16183              :                                   TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
   16184              :                                   size_one_node);
   16185           33 :                   l = size_binop (MINUS_EXPR, l,
   16186              :                                   fold_convert (sizetype, low_bound));
   16187              :                 }
   16188         2530 :               if (i > first_non_one)
   16189              :                 {
   16190            0 :                   l = fold_build2 (NE_EXPR, boolean_type_node, l,
   16191              :                                    size_zero_node);
   16192            0 :                   if (condition == NULL_TREE)
   16193              :                     condition = l;
   16194              :                   else
   16195            0 :                     condition = fold_build2 (BIT_AND_EXPR, boolean_type_node,
   16196              :                                              l, condition);
   16197              :                 }
   16198         2530 :               else if (size == NULL_TREE)
   16199              :                 {
   16200         2411 :                   size = size_in_bytes (TREE_TYPE (types[i]));
   16201         2411 :                   tree eltype = TREE_TYPE (types[num - 1]);
   16202         2431 :                   while (TREE_CODE (eltype) == ARRAY_TYPE)
   16203           20 :                     eltype = TREE_TYPE (eltype);
   16204         2411 :                   if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   16205         2176 :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   16206         4327 :                       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
   16207              :                     {
   16208          539 :                       if (integer_zerop (size)
   16209         1076 :                           || integer_zerop (size_in_bytes (eltype)))
   16210              :                         {
   16211            4 :                           error_at (OMP_CLAUSE_LOCATION (c),
   16212              :                                     "zero length array section in %qs clause",
   16213            2 :                                     omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16214            2 :                           return error_mark_node;
   16215              :                         }
   16216          537 :                       size = size_binop (EXACT_DIV_EXPR, size,
   16217              :                                          size_in_bytes (eltype));
   16218              :                     }
   16219         2409 :                   size = size_binop (MULT_EXPR, size, l);
   16220         2409 :                   if (condition)
   16221            0 :                     size = fold_build3 (COND_EXPR, sizetype, condition,
   16222              :                                         size, size_zero_node);
   16223              :                 }
   16224              :               else
   16225          119 :                 size = size_binop (MULT_EXPR, size, l);
   16226              :             }
   16227              :         }
   16228         2409 :       if (side_effects)
   16229            0 :         size = build2 (COMPOUND_EXPR, sizetype, side_effects, size);
   16230         2409 :       if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   16231         2176 :           || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   16232         4325 :           || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TASK_REDUCTION)
   16233              :         {
   16234          537 :           size = size_binop (MINUS_EXPR, size, size_one_node);
   16235          537 :           size = c_fully_fold (size, false, NULL);
   16236          537 :           size = save_expr (size);
   16237          537 :           tree index_type = build_index_type (size);
   16238          537 :           tree eltype = TREE_TYPE (first);
   16239          549 :           while (TREE_CODE (eltype) == ARRAY_TYPE)
   16240           12 :             eltype = TREE_TYPE (eltype);
   16241          537 :           tree type = c_build_array_type (eltype, index_type);
   16242          537 :           tree ptype = c_build_pointer_type (eltype);
   16243          537 :           if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
   16244          296 :             t = build_fold_addr_expr (t);
   16245          537 :           tree t2 = build_fold_addr_expr (first);
   16246          537 :           t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
   16247              :                                  ptrdiff_type_node, t2);
   16248          537 :           t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
   16249              :                                 ptrdiff_type_node, t2,
   16250          537 :                                 fold_convert_loc (OMP_CLAUSE_LOCATION (c),
   16251              :                                                   ptrdiff_type_node, t));
   16252          537 :           t2 = c_fully_fold (t2, false, NULL);
   16253          537 :           if (tree_fits_shwi_p (t2))
   16254          398 :             t = build2 (MEM_REF, type, t,
   16255          398 :                         build_int_cst (ptype, tree_to_shwi (t2)));
   16256              :           else
   16257              :             {
   16258          139 :               t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c), sizetype, t2);
   16259          139 :               t = build2_loc (OMP_CLAUSE_LOCATION (c), POINTER_PLUS_EXPR,
   16260          139 :                               TREE_TYPE (t), t, t2);
   16261          139 :               t = build2 (MEM_REF, type, t, build_int_cst (ptype, 0));
   16262              :             }
   16263          537 :           OMP_CLAUSE_DECL (c) = t;
   16264          537 :           return false;
   16265              :         }
   16266         1872 :       first = c_fully_fold (first, false, NULL);
   16267         1872 :       OMP_CLAUSE_DECL (c) = first;
   16268         1872 :       if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR)
   16269              :         return false;
   16270              :       /* Don't set OMP_CLAUSE_SIZE for bare attach/detach clauses.  */
   16271         1861 :       if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
   16272         1861 :           || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
   16273         1721 :               && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH
   16274         1719 :               && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FORCE_DETACH))
   16275              :         {
   16276         1857 :           if (size)
   16277         1857 :             size = c_fully_fold (size, false, NULL);
   16278         1857 :           OMP_CLAUSE_SIZE (c) = size;
   16279              :         }
   16280              : 
   16281         1861 :       if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
   16282              :         return false;
   16283              : 
   16284         1723 :       auto_vec<omp_addr_token *, 10> addr_tokens;
   16285              : 
   16286         1723 :       if (!omp_parse_expr (addr_tokens, first))
   16287         1723 :         return true;
   16288              : 
   16289         1723 :       c_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
   16290              : 
   16291         1723 :       tree nc = ai.expand_map_clause (c, first, addr_tokens, ort);
   16292         1723 :       if (nc != error_mark_node)
   16293              :         {
   16294         1723 :           using namespace omp_addr_tokenizer;
   16295              : 
   16296         1723 :           if (ai.maybe_zero_length_array_section (c))
   16297         1719 :             OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
   16298              : 
   16299              :           /* !!! If we're accessing a base decl via chained access
   16300              :              methods (e.g. multiple indirections), duplicate clause
   16301              :              detection won't work properly.  Skip it in that case.  */
   16302         1723 :           if ((addr_tokens[0]->type == STRUCTURE_BASE
   16303         1436 :                || addr_tokens[0]->type == ARRAY_BASE)
   16304         1723 :               && addr_tokens[0]->u.structure_base_kind == BASE_DECL
   16305         1723 :               && addr_tokens[1]->type == ACCESS_METHOD
   16306         3446 :               && omp_access_chain_p (addr_tokens, 1))
   16307           34 :             c = nc;
   16308              : 
   16309         1723 :           return false;
   16310              :         }
   16311              :     }
   16312              :   return false;
   16313         2978 : }
   16314              : 
   16315              : /* Helper function of finish_omp_clauses.  Clone STMT as if we were making
   16316              :    an inline call.  But, remap
   16317              :    the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
   16318              :    and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL.  */
   16319              : 
   16320              : static tree
   16321          510 : c_clone_omp_udr (tree stmt, tree omp_decl1, tree omp_decl2,
   16322              :                  tree decl, tree placeholder)
   16323              : {
   16324          510 :   copy_body_data id;
   16325          510 :   hash_map<tree, tree> decl_map;
   16326              : 
   16327          510 :   decl_map.put (omp_decl1, placeholder);
   16328          510 :   decl_map.put (omp_decl2, decl);
   16329          510 :   memset (&id, 0, sizeof (id));
   16330          510 :   id.src_fn = DECL_CONTEXT (omp_decl1);
   16331          510 :   id.dst_fn = current_function_decl;
   16332          510 :   id.src_cfun = DECL_STRUCT_FUNCTION (id.src_fn);
   16333          510 :   id.decl_map = &decl_map;
   16334              : 
   16335          510 :   id.copy_decl = copy_decl_no_change;
   16336          510 :   id.transform_call_graph_edges = CB_CGE_DUPLICATE;
   16337          510 :   id.transform_new_cfg = true;
   16338          510 :   id.transform_return_to_modify = false;
   16339          510 :   id.eh_lp_nr = 0;
   16340          510 :   walk_tree (&stmt, copy_tree_body_r, &id, NULL);
   16341          510 :   return stmt;
   16342          510 : }
   16343              : 
   16344              : /* Helper function of c_finish_omp_clauses, called via walk_tree.
   16345              :    Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP.  */
   16346              : 
   16347              : static tree
   16348         1123 : c_find_omp_placeholder_r (tree *tp, int *, void *data)
   16349              : {
   16350         1123 :   if (*tp == (tree) data)
   16351           28 :     return *tp;
   16352              :   return NULL_TREE;
   16353              : }
   16354              : 
   16355              : /* Similarly, but also walk aggregate fields.  */
   16356              : 
   16357              : struct c_find_omp_var_s { tree var; hash_set<tree> *pset; };
   16358              : 
   16359              : static tree
   16360          288 : c_find_omp_var_r (tree *tp, int *, void *data)
   16361              : {
   16362          288 :   if (*tp == ((struct c_find_omp_var_s *) data)->var)
   16363              :     return *tp;
   16364          280 :   if (RECORD_OR_UNION_TYPE_P (*tp))
   16365              :     {
   16366            2 :       tree field;
   16367            2 :       hash_set<tree> *pset = ((struct c_find_omp_var_s *) data)->pset;
   16368              : 
   16369            2 :       for (field = TYPE_FIELDS (*tp); field;
   16370            0 :            field = DECL_CHAIN (field))
   16371            2 :         if (TREE_CODE (field) == FIELD_DECL)
   16372              :           {
   16373            2 :             tree ret = walk_tree (&DECL_FIELD_OFFSET (field),
   16374              :                                   c_find_omp_var_r, data, pset);
   16375            2 :             if (ret)
   16376              :               return ret;
   16377            2 :             ret = walk_tree (&DECL_SIZE (field), c_find_omp_var_r, data, pset);
   16378            2 :             if (ret)
   16379              :               return ret;
   16380            2 :             ret = walk_tree (&DECL_SIZE_UNIT (field), c_find_omp_var_r, data,
   16381              :                              pset);
   16382            2 :             if (ret)
   16383              :               return ret;
   16384            2 :             ret = walk_tree (&TREE_TYPE (field), c_find_omp_var_r, data, pset);
   16385            2 :             if (ret)
   16386              :               return ret;
   16387              :           }
   16388              :     }
   16389          278 :   else if (INTEGRAL_TYPE_P (*tp))
   16390           45 :     return walk_tree (&TYPE_MAX_VALUE (*tp), c_find_omp_var_r, data,
   16391              :                       ((struct c_find_omp_var_s *) data)->pset);
   16392              :   return NULL_TREE;
   16393              : }
   16394              : 
   16395              : /* Finish OpenMP iterators ITER.  Return true if they are errorneous
   16396              :    and clauses containing them should be removed.  */
   16397              : 
   16398              : static bool
   16399          142 : c_omp_finish_iterators (tree iter)
   16400              : {
   16401          142 :   bool ret = false;
   16402          323 :   for (tree it = iter; it; it = TREE_CHAIN (it))
   16403              :     {
   16404          181 :       tree var = TREE_VEC_ELT (it, 0);
   16405          181 :       tree begin = TREE_VEC_ELT (it, 1);
   16406          181 :       tree end = TREE_VEC_ELT (it, 2);
   16407          181 :       tree step = TREE_VEC_ELT (it, 3);
   16408          181 :       tree orig_step;
   16409          181 :       tree type = TREE_TYPE (var);
   16410          181 :       location_t loc = DECL_SOURCE_LOCATION (var);
   16411          181 :       if (type == error_mark_node)
   16412              :         {
   16413            0 :           ret = true;
   16414           34 :           continue;
   16415              :         }
   16416          181 :       if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type))
   16417              :         {
   16418            6 :           error_at (loc, "iterator %qD has neither integral nor pointer type",
   16419              :                     var);
   16420            6 :           ret = true;
   16421            6 :           continue;
   16422              :         }
   16423          175 :       else if (TYPE_ATOMIC (type))
   16424              :         {
   16425            2 :           error_at (loc, "iterator %qD has %<_Atomic%> qualified type", var);
   16426            2 :           ret = true;
   16427            2 :           continue;
   16428              :         }
   16429          173 :       else if (TYPE_READONLY (type))
   16430              :         {
   16431            4 :           error_at (loc, "iterator %qD has const qualified type", var);
   16432            4 :           ret = true;
   16433            4 :           continue;
   16434              :         }
   16435          169 :       else if (step == error_mark_node
   16436          169 :                || TREE_TYPE (step) == error_mark_node)
   16437              :         {
   16438            0 :           ret = true;
   16439            0 :           continue;
   16440              :         }
   16441          169 :       else if (!INTEGRAL_TYPE_P (TREE_TYPE (step)))
   16442              :         {
   16443            6 :           error_at (EXPR_LOC_OR_LOC (step, loc),
   16444              :                     "iterator step with non-integral type");
   16445            4 :           ret = true;
   16446            4 :           continue;
   16447              :         }
   16448          165 :       begin = c_fully_fold (build_c_cast (loc, type, begin), false, NULL);
   16449          165 :       end = c_fully_fold (build_c_cast (loc, type, end), false, NULL);
   16450          165 :       orig_step = save_expr (c_fully_fold (step, false, NULL));
   16451          165 :       tree stype = POINTER_TYPE_P (type) ? sizetype : type;
   16452          165 :       step = c_fully_fold (build_c_cast (loc, stype, orig_step), false, NULL);
   16453          165 :       if (POINTER_TYPE_P (type))
   16454              :         {
   16455           14 :           begin = save_expr (begin);
   16456           14 :           step = pointer_int_sum (loc, PLUS_EXPR, begin, step);
   16457           14 :           step = fold_build2_loc (loc, MINUS_EXPR, sizetype,
   16458              :                                   fold_convert (sizetype, step),
   16459              :                                   fold_convert (sizetype, begin));
   16460           14 :           step = fold_convert (ssizetype, step);
   16461              :         }
   16462          165 :       if (integer_zerop (step))
   16463              :         {
   16464            6 :           error_at (loc, "iterator %qD has zero step", var);
   16465            6 :           ret = true;
   16466            6 :           continue;
   16467              :         }
   16468              : 
   16469          159 :       if (begin == error_mark_node
   16470          157 :           || end == error_mark_node
   16471          155 :           || step == error_mark_node
   16472          155 :           || orig_step == error_mark_node)
   16473              :         {
   16474            4 :           ret = true;
   16475            4 :           continue;
   16476              :         }
   16477          155 :       hash_set<tree> pset;
   16478          155 :       tree it2;
   16479          196 :       for (it2 = TREE_CHAIN (it); it2; it2 = TREE_CHAIN (it2))
   16480              :         {
   16481           49 :           tree var2 = TREE_VEC_ELT (it2, 0);
   16482           49 :           tree begin2 = TREE_VEC_ELT (it2, 1);
   16483           49 :           tree end2 = TREE_VEC_ELT (it2, 2);
   16484           49 :           tree step2 = TREE_VEC_ELT (it2, 3);
   16485           49 :           tree type2 = TREE_TYPE (var2);
   16486           49 :           location_t loc2 = DECL_SOURCE_LOCATION (var2);
   16487           49 :           struct c_find_omp_var_s data = { var, &pset };
   16488           49 :           if (walk_tree (&type2, c_find_omp_var_r, &data, &pset))
   16489              :             {
   16490            2 :               error_at (loc2,
   16491              :                         "type of iterator %qD refers to outer iterator %qD",
   16492              :                         var2, var);
   16493           10 :               break;
   16494              :             }
   16495           47 :           else if (walk_tree (&begin2, c_find_omp_var_r, &data, &pset))
   16496              :             {
   16497            2 :               error_at (EXPR_LOC_OR_LOC (begin2, loc2),
   16498              :                         "begin expression refers to outer iterator %qD", var);
   16499            2 :               break;
   16500              :             }
   16501           45 :           else if (walk_tree (&end2, c_find_omp_var_r, &data, &pset))
   16502              :             {
   16503            2 :               error_at (EXPR_LOC_OR_LOC (end2, loc2),
   16504              :                         "end expression refers to outer iterator %qD", var);
   16505            2 :               break;
   16506              :             }
   16507           43 :           else if (walk_tree (&step2, c_find_omp_var_r, &data, &pset))
   16508              :             {
   16509            2 :               error_at (EXPR_LOC_OR_LOC (step2, loc2),
   16510              :                         "step expression refers to outer iterator %qD", var);
   16511            2 :               break;
   16512              :             }
   16513              :         }
   16514          155 :       if (it2)
   16515              :         {
   16516            8 :           ret = true;
   16517            8 :           continue;
   16518              :         }
   16519          147 :       TREE_VEC_ELT (it, 1) = begin;
   16520          147 :       TREE_VEC_ELT (it, 2) = end;
   16521          147 :       TREE_VEC_ELT (it, 3) = step;
   16522          147 :       TREE_VEC_ELT (it, 4) = orig_step;
   16523          155 :     }
   16524          142 :   return ret;
   16525              : }
   16526              : 
   16527              : /* Ensure that pointers are used in OpenACC attach and detach clauses.
   16528              :    Return true if an error has been detected.  */
   16529              : 
   16530              : static bool
   16531         9474 : c_oacc_check_attachments (tree c)
   16532              : {
   16533         9474 :   if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
   16534              :     return false;
   16535              : 
   16536              :   /* OpenACC attach / detach clauses must be pointers.  */
   16537         6479 :   if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
   16538         6479 :       || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
   16539              :     {
   16540           71 :       tree t = OMP_CLAUSE_DECL (c);
   16541              : 
   16542           77 :       while (TREE_CODE (t) == OMP_ARRAY_SECTION)
   16543            6 :         t = TREE_OPERAND (t, 0);
   16544              : 
   16545           71 :       if (TREE_CODE (TREE_TYPE (t)) != POINTER_TYPE)
   16546              :         {
   16547            6 :           error_at (OMP_CLAUSE_LOCATION (c), "expected pointer in %qs clause",
   16548              :                     user_omp_clause_code_name (c, true));
   16549            6 :           return true;
   16550              :         }
   16551              :     }
   16552              : 
   16553              :   return false;
   16554              : }
   16555              : 
   16556              : /* For all elements of CLAUSES, validate them against their constraints.
   16557              :    Remove any elements from the list that are invalid.  */
   16558              : 
   16559              : tree
   16560        29445 : c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
   16561              : {
   16562        29445 :   bitmap_head generic_head, firstprivate_head, lastprivate_head;
   16563        29445 :   bitmap_head aligned_head, map_head, map_field_head, map_firstprivate_head;
   16564        29445 :   bitmap_head oacc_reduction_head, is_on_device_head;
   16565        29445 :   tree c, t, type, *pc;
   16566        29445 :   tree simdlen = NULL_TREE, safelen = NULL_TREE;
   16567        29445 :   bool branch_seen = false;
   16568        29445 :   bool copyprivate_seen = false;
   16569        29445 :   bool mergeable_seen = false;
   16570        29445 :   tree *detach_seen = NULL;
   16571        29445 :   bool linear_variable_step_check = false;
   16572        29445 :   tree *nowait_clause = NULL;
   16573        29445 :   tree *grainsize_seen = NULL;
   16574        29445 :   bool num_tasks_seen = false;
   16575        29445 :   tree ordered_clause = NULL_TREE;
   16576        29445 :   tree schedule_clause = NULL_TREE;
   16577        29445 :   bool oacc_async = false;
   16578        29445 :   tree last_iterators = NULL_TREE;
   16579        29445 :   bool last_iterators_remove = false;
   16580        29445 :   tree *nogroup_seen = NULL;
   16581        29445 :   tree *order_clause = NULL;
   16582              :   /* 1 if normal/task reduction has been seen, -1 if inscan reduction
   16583              :      has been seen, -2 if mixed inscan/normal reduction diagnosed.  */
   16584        29445 :   int reduction_seen = 0;
   16585        29445 :   bool allocate_seen = false;
   16586        29445 :   bool implicit_moved = false;
   16587        29445 :   bool target_in_reduction_seen = false;
   16588        29445 :   tree *full_seen = NULL;
   16589        29445 :   bool partial_seen = false;
   16590        29445 :   bool openacc = (ort & C_ORT_ACC) != 0;
   16591        29445 :   bool init_seen = false;
   16592        29445 :   bool init_use_destroy_seen = false;
   16593        29445 :   tree init_no_targetsync_clause = NULL_TREE;
   16594        29445 :   tree depend_clause = NULL_TREE;
   16595              : 
   16596        29445 :   bitmap_obstack_initialize (NULL);
   16597        29445 :   bitmap_initialize (&generic_head, &bitmap_default_obstack);
   16598        29445 :   bitmap_initialize (&firstprivate_head, &bitmap_default_obstack);
   16599        29445 :   bitmap_initialize (&lastprivate_head, &bitmap_default_obstack);
   16600        29445 :   bitmap_initialize (&aligned_head, &bitmap_default_obstack);
   16601              :   /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead.  */
   16602        29445 :   bitmap_initialize (&map_head, &bitmap_default_obstack);
   16603        29445 :   bitmap_initialize (&map_field_head, &bitmap_default_obstack);
   16604        29445 :   bitmap_initialize (&map_firstprivate_head, &bitmap_default_obstack);
   16605              :   /* If ort == C_ORT_OMP used as nontemporal_head or use_device_xxx_head
   16606              :      instead and for ort == C_ORT_OMP_TARGET used as in_reduction_head.  */
   16607        29445 :   bitmap_initialize (&oacc_reduction_head, &bitmap_default_obstack);
   16608        29445 :   bitmap_initialize (&is_on_device_head, &bitmap_default_obstack);
   16609              : 
   16610        29445 :   if (openacc)
   16611        12269 :     for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
   16612         7258 :       if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ASYNC)
   16613              :         {
   16614              :           oacc_async = true;
   16615              :           break;
   16616              :         }
   16617              : 
   16618        29445 :   tree *grp_start_p = NULL, grp_sentinel = NULL_TREE;
   16619              : 
   16620        77345 :   for (pc = &clauses, c = clauses; c ; c = *pc)
   16621              :     {
   16622        47900 :       bool remove = false;
   16623        47900 :       bool need_complete = false;
   16624        47900 :       bool need_implicitly_determined = false;
   16625              : 
   16626              :       /* We've reached the end of a list of expanded nodes.  Reset the group
   16627              :          start pointer.  */
   16628        47900 :       if (c == grp_sentinel)
   16629              :         {
   16630         2470 :           if (grp_start_p
   16631         2470 :               && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
   16632           32 :             for (tree gc = *grp_start_p; gc != grp_sentinel;
   16633           22 :                  gc = OMP_CLAUSE_CHAIN (gc))
   16634           22 :               OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
   16635              :           grp_start_p = NULL;
   16636              :         }
   16637              : 
   16638        47900 :       switch (OMP_CLAUSE_CODE (c))
   16639              :         {
   16640         1139 :         case OMP_CLAUSE_SHARED:
   16641         1139 :           need_implicitly_determined = true;
   16642         1139 :           goto check_dup_generic;
   16643              : 
   16644          847 :         case OMP_CLAUSE_PRIVATE:
   16645          847 :           need_complete = true;
   16646          847 :           need_implicitly_determined = true;
   16647          847 :           goto check_dup_generic;
   16648              : 
   16649         3519 :         case OMP_CLAUSE_REDUCTION:
   16650         3519 :           if (reduction_seen == 0)
   16651         2920 :             reduction_seen = OMP_CLAUSE_REDUCTION_INSCAN (c) ? -1 : 1;
   16652          599 :           else if (reduction_seen != -2
   16653         1198 :                    && reduction_seen != (OMP_CLAUSE_REDUCTION_INSCAN (c)
   16654          599 :                                          ? -1 : 1))
   16655              :             {
   16656            2 :               error_at (OMP_CLAUSE_LOCATION (c),
   16657              :                         "%<inscan%> and non-%<inscan%> %<reduction%> clauses "
   16658              :                         "on the same construct");
   16659            2 :               reduction_seen = -2;
   16660              :             }
   16661              :           /* FALLTHRU */
   16662         4183 :         case OMP_CLAUSE_IN_REDUCTION:
   16663         4183 :         case OMP_CLAUSE_TASK_REDUCTION:
   16664         4183 :           need_implicitly_determined = true;
   16665         4183 :           t = OMP_CLAUSE_DECL (c);
   16666         4183 :           if (TREE_CODE (t) == OMP_ARRAY_SECTION)
   16667              :             {
   16668          553 :               if (handle_omp_array_sections (c, ort))
   16669              :                 {
   16670              :                   remove = true;
   16671              :                   break;
   16672              :                 }
   16673              : 
   16674          537 :               t = OMP_CLAUSE_DECL (c);
   16675          537 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   16676          537 :                   && OMP_CLAUSE_REDUCTION_INSCAN (c))
   16677              :                 {
   16678            1 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16679              :                             "%<inscan%> %<reduction%> clause with array "
   16680              :                             "section");
   16681            1 :                   remove = true;
   16682            1 :                   break;
   16683              :                 }
   16684              :             }
   16685         4166 :           t = require_complete_type (OMP_CLAUSE_LOCATION (c), t);
   16686         4166 :           if (t == error_mark_node)
   16687              :             {
   16688              :               remove = true;
   16689              :               break;
   16690              :             }
   16691         4164 :           if (oacc_async)
   16692            3 :             c_mark_addressable (t);
   16693         4164 :           type = TREE_TYPE (t);
   16694         4164 :           if (TREE_CODE (t) == MEM_REF)
   16695          536 :             type = TREE_TYPE (type);
   16696         4164 :           if (TREE_CODE (type) == ARRAY_TYPE)
   16697              :             {
   16698           74 :               tree oatype = type;
   16699           74 :               gcc_assert (TREE_CODE (t) != MEM_REF);
   16700          148 :               while (TREE_CODE (type) == ARRAY_TYPE)
   16701           74 :                 type = TREE_TYPE (type);
   16702           74 :               if (integer_zerop (TYPE_SIZE_UNIT (type)))
   16703              :                 {
   16704            1 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16705              :                             "%qD in %<reduction%> clause is a zero size array",
   16706              :                             t);
   16707            1 :                   remove = true;
   16708            1 :                   break;
   16709              :                 }
   16710           73 :               tree size = size_binop (EXACT_DIV_EXPR, TYPE_SIZE_UNIT (oatype),
   16711              :                                       TYPE_SIZE_UNIT (type));
   16712           73 :               if (integer_zerop (size))
   16713              :                 {
   16714            1 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16715              :                             "%qD in %<reduction%> clause is a zero size array",
   16716              :                             t);
   16717            1 :                   remove = true;
   16718            1 :                   break;
   16719              :                 }
   16720           72 :               size = size_binop (MINUS_EXPR, size, size_one_node);
   16721           72 :               size = save_expr (size);
   16722           72 :               tree index_type = build_index_type (size);
   16723           72 :               tree atype = c_build_array_type (TYPE_MAIN_VARIANT (type),
   16724              :                                                index_type);
   16725           72 :               atype = c_build_qualified_type (atype, TYPE_QUALS (type));
   16726           72 :               tree ptype = c_build_pointer_type (type);
   16727           72 :               if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
   16728           72 :                 t = build_fold_addr_expr (t);
   16729           72 :               t = build2 (MEM_REF, atype, t, build_int_cst (ptype, 0));
   16730           72 :               OMP_CLAUSE_DECL (c) = t;
   16731              :             }
   16732         4162 :           if (TYPE_ATOMIC (type))
   16733              :             {
   16734            3 :               error_at (OMP_CLAUSE_LOCATION (c),
   16735              :                         "%<_Atomic%> %qE in %<reduction%> clause", t);
   16736            3 :               remove = true;
   16737            3 :               break;
   16738              :             }
   16739         4159 :           if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION
   16740         4159 :               || OMP_CLAUSE_REDUCTION_TASK (c))
   16741              :             {
   16742              :               /* Disallow zero sized or potentially zero sized task
   16743              :                  reductions.  */
   16744          871 :               if (integer_zerop (TYPE_SIZE_UNIT (type)))
   16745              :                 {
   16746            6 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16747              :                             "zero sized type %qT in %qs clause", type,
   16748            3 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16749            3 :                   remove = true;
   16750            3 :                   break;
   16751              :                 }
   16752          868 :               else if (TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST)
   16753              :                 {
   16754            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16755              :                             "variable sized type %qT in %qs clause", type,
   16756            0 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   16757            0 :                   remove = true;
   16758            0 :                   break;
   16759              :                 }
   16760              :             }
   16761         4156 :           if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == NULL_TREE
   16762         4156 :               && (FLOAT_TYPE_P (type)
   16763         3604 :                   || TREE_CODE (type) == COMPLEX_TYPE))
   16764              :             {
   16765          340 :               enum tree_code r_code = OMP_CLAUSE_REDUCTION_CODE (c);
   16766          340 :               const char *r_name = NULL;
   16767              : 
   16768          340 :               switch (r_code)
   16769              :                 {
   16770              :                 case PLUS_EXPR:
   16771              :                 case MULT_EXPR:
   16772              :                 case MINUS_EXPR:
   16773              :                 case TRUTH_ANDIF_EXPR:
   16774              :                 case TRUTH_ORIF_EXPR:
   16775              :                   break;
   16776           13 :                 case MIN_EXPR:
   16777           13 :                   if (TREE_CODE (type) == COMPLEX_TYPE)
   16778              :                     r_name = "min";
   16779              :                   break;
   16780           38 :                 case MAX_EXPR:
   16781           38 :                   if (TREE_CODE (type) == COMPLEX_TYPE)
   16782              :                     r_name = "max";
   16783              :                   break;
   16784            3 :                 case BIT_AND_EXPR:
   16785            3 :                   r_name = "&";
   16786            3 :                   break;
   16787            2 :                 case BIT_XOR_EXPR:
   16788            2 :                   r_name = "^";
   16789            2 :                   break;
   16790              :                 case BIT_IOR_EXPR:
   16791              :                   r_name = "|";
   16792              :                   break;
   16793            0 :                 default:
   16794            0 :                   gcc_unreachable ();
   16795              :                 }
   16796            5 :               if (r_name)
   16797              :                 {
   16798           12 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16799              :                             "%qE has invalid type for %<reduction(%s)%>",
   16800              :                             t, r_name);
   16801           12 :                   remove = true;
   16802           12 :                   break;
   16803              :                 }
   16804              :             }
   16805         3816 :           else if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == error_mark_node)
   16806              :             {
   16807            2 :               error_at (OMP_CLAUSE_LOCATION (c),
   16808              :                         "user defined reduction not found for %qE", t);
   16809            2 :               remove = true;
   16810            2 :               break;
   16811              :             }
   16812         3814 :           else if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
   16813              :             {
   16814          277 :               tree list = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c);
   16815          277 :               type = TYPE_MAIN_VARIANT (type);
   16816          277 :               tree placeholder = build_decl (OMP_CLAUSE_LOCATION (c),
   16817              :                                              VAR_DECL, NULL_TREE, type);
   16818          277 :               tree decl_placeholder = NULL_TREE;
   16819          277 :               OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = placeholder;
   16820          277 :               DECL_ARTIFICIAL (placeholder) = 1;
   16821          277 :               DECL_IGNORED_P (placeholder) = 1;
   16822          277 :               if (TREE_CODE (t) == MEM_REF)
   16823              :                 {
   16824           56 :                   decl_placeholder = build_decl (OMP_CLAUSE_LOCATION (c),
   16825              :                                                  VAR_DECL, NULL_TREE, type);
   16826           56 :                   OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c) = decl_placeholder;
   16827           56 :                   DECL_ARTIFICIAL (decl_placeholder) = 1;
   16828           56 :                   DECL_IGNORED_P (decl_placeholder) = 1;
   16829              :                 }
   16830          277 :               if (TREE_ADDRESSABLE (TREE_VEC_ELT (list, 0)))
   16831           42 :                 c_mark_addressable (placeholder);
   16832          277 :               if (TREE_ADDRESSABLE (TREE_VEC_ELT (list, 1)))
   16833           76 :                 c_mark_addressable (decl_placeholder ? decl_placeholder
   16834           34 :                                     : OMP_CLAUSE_DECL (c));
   16835          277 :               OMP_CLAUSE_REDUCTION_MERGE (c)
   16836          775 :                 = c_clone_omp_udr (TREE_VEC_ELT (list, 2),
   16837          277 :                                    TREE_VEC_ELT (list, 0),
   16838          277 :                                    TREE_VEC_ELT (list, 1),
   16839              :                                    decl_placeholder ? decl_placeholder
   16840          221 :                                    : OMP_CLAUSE_DECL (c), placeholder);
   16841          277 :               OMP_CLAUSE_REDUCTION_MERGE (c)
   16842          277 :                 = build3_loc (OMP_CLAUSE_LOCATION (c), BIND_EXPR,
   16843              :                               void_type_node, NULL_TREE,
   16844          277 :                               OMP_CLAUSE_REDUCTION_MERGE (c), NULL_TREE);
   16845          277 :               TREE_SIDE_EFFECTS (OMP_CLAUSE_REDUCTION_MERGE (c)) = 1;
   16846          277 :               if (TREE_VEC_LENGTH (list) == 6)
   16847              :                 {
   16848          233 :                   if (TREE_ADDRESSABLE (TREE_VEC_ELT (list, 3)))
   16849           70 :                     c_mark_addressable (decl_placeholder ? decl_placeholder
   16850           33 :                                         : OMP_CLAUSE_DECL (c));
   16851          233 :                   if (TREE_ADDRESSABLE (TREE_VEC_ELT (list, 4)))
   16852           27 :                     c_mark_addressable (placeholder);
   16853          233 :                   tree init = TREE_VEC_ELT (list, 5);
   16854          233 :                   if (init == error_mark_node)
   16855          197 :                     init = DECL_INITIAL (TREE_VEC_ELT (list, 3));
   16856          233 :                   OMP_CLAUSE_REDUCTION_INIT (c)
   16857          651 :                     = c_clone_omp_udr (init, TREE_VEC_ELT (list, 4),
   16858          233 :                                        TREE_VEC_ELT (list, 3),
   16859              :                                        decl_placeholder ? decl_placeholder
   16860          185 :                                        : OMP_CLAUSE_DECL (c), placeholder);
   16861          233 :                   if (TREE_VEC_ELT (list, 5) == error_mark_node)
   16862              :                     {
   16863          197 :                       tree v = decl_placeholder ? decl_placeholder : t;
   16864          197 :                       OMP_CLAUSE_REDUCTION_INIT (c)
   16865          394 :                         = build2 (INIT_EXPR, TREE_TYPE (v), v,
   16866          197 :                                   OMP_CLAUSE_REDUCTION_INIT (c));
   16867              :                     }
   16868          233 :                   if (walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c),
   16869              :                                  c_find_omp_placeholder_r,
   16870              :                                  placeholder, NULL))
   16871           28 :                     OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c) = 1;
   16872              :                 }
   16873              :               else
   16874              :                 {
   16875           44 :                   tree init;
   16876           44 :                   tree v = decl_placeholder ? decl_placeholder : t;
   16877           44 :                   if (AGGREGATE_TYPE_P (TREE_TYPE (v)))
   16878           34 :                     init = build_constructor (TREE_TYPE (v), NULL);
   16879              :                   else
   16880           10 :                     init = fold_convert (TREE_TYPE (v), integer_zero_node);
   16881           44 :                   OMP_CLAUSE_REDUCTION_INIT (c)
   16882           88 :                     = build2 (INIT_EXPR, TREE_TYPE (v), v, init);
   16883              :                 }
   16884          277 :               OMP_CLAUSE_REDUCTION_INIT (c)
   16885          277 :                 = build3_loc (OMP_CLAUSE_LOCATION (c), BIND_EXPR,
   16886              :                               void_type_node, NULL_TREE,
   16887          277 :                                OMP_CLAUSE_REDUCTION_INIT (c), NULL_TREE);
   16888          277 :               TREE_SIDE_EFFECTS (OMP_CLAUSE_REDUCTION_INIT (c)) = 1;
   16889              :             }
   16890         4142 :           if (TREE_CODE (t) == MEM_REF)
   16891              :             {
   16892          607 :               if (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t))) == NULL_TREE
   16893          607 :                   || TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t))))
   16894              :                      != INTEGER_CST)
   16895              :                 {
   16896            0 :                   sorry ("variable length element type in array "
   16897              :                          "%<reduction%> clause");
   16898            0 :                   remove = true;
   16899            0 :                   break;
   16900              :                 }
   16901          607 :               t = TREE_OPERAND (t, 0);
   16902          607 :               if (TREE_CODE (t) == POINTER_PLUS_EXPR)
   16903          139 :                 t = TREE_OPERAND (t, 0);
   16904          607 :               if (TREE_CODE (t) == ADDR_EXPR)
   16905          367 :                 t = TREE_OPERAND (t, 0);
   16906              :             }
   16907         4142 :           goto check_dup_generic_t;
   16908              : 
   16909           24 :         case OMP_CLAUSE_COPYPRIVATE:
   16910           24 :           copyprivate_seen = true;
   16911           24 :           if (nowait_clause)
   16912              :             {
   16913            1 :               error_at (OMP_CLAUSE_LOCATION (*nowait_clause),
   16914              :                         "%<nowait%> clause must not be used together "
   16915              :                         "with %<copyprivate%> clause");
   16916            1 :               *nowait_clause = OMP_CLAUSE_CHAIN (*nowait_clause);
   16917            1 :               nowait_clause = NULL;
   16918              :             }
   16919           24 :           goto check_dup_generic;
   16920              : 
   16921           99 :         case OMP_CLAUSE_COPYIN:
   16922           99 :           t = OMP_CLAUSE_DECL (c);
   16923           99 :           if (!VAR_P (t) || !DECL_THREAD_LOCAL_P (t))
   16924              :             {
   16925            5 :               error_at (OMP_CLAUSE_LOCATION (c),
   16926              :                         "%qE must be %<threadprivate%> for %<copyin%>", t);
   16927            5 :               remove = true;
   16928            5 :               break;
   16929              :             }
   16930           94 :           goto check_dup_generic;
   16931              : 
   16932          480 :         case OMP_CLAUSE_LINEAR:
   16933          480 :           if (ort != C_ORT_OMP_DECLARE_SIMD)
   16934          327 :             need_implicitly_determined = true;
   16935          480 :           t = OMP_CLAUSE_DECL (c);
   16936          480 :           if (ort != C_ORT_OMP_DECLARE_SIMD
   16937          327 :               && OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_DEFAULT
   16938          485 :               && OMP_CLAUSE_LINEAR_OLD_LINEAR_MODIFIER (c))
   16939              :             {
   16940            5 :               error_at (OMP_CLAUSE_LOCATION (c),
   16941              :                         "modifier should not be specified in %<linear%> "
   16942              :                         "clause on %<simd%> or %<for%> constructs when not "
   16943              :                         "using OpenMP 5.2 modifiers");
   16944            5 :               OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
   16945              :             }
   16946          960 :           if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
   16947          503 :               && TREE_CODE (TREE_TYPE (t)) != POINTER_TYPE)
   16948              :             {
   16949            1 :               error_at (OMP_CLAUSE_LOCATION (c),
   16950              :                         "linear clause applied to non-integral non-pointer "
   16951            1 :                         "variable with type %qT", TREE_TYPE (t));
   16952            1 :               remove = true;
   16953            1 :               break;
   16954              :             }
   16955          479 :           if (TYPE_ATOMIC (TREE_TYPE (t)))
   16956              :             {
   16957            3 :               error_at (OMP_CLAUSE_LOCATION (c),
   16958              :                         "%<_Atomic%> %qD in %<linear%> clause", t);
   16959            3 :               remove = true;
   16960            3 :               break;
   16961              :             }
   16962          476 :           if (ort == C_ORT_OMP_DECLARE_SIMD)
   16963              :             {
   16964          152 :               tree s = OMP_CLAUSE_LINEAR_STEP (c);
   16965          152 :               if (TREE_CODE (s) == PARM_DECL)
   16966              :                 {
   16967            9 :                   OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c) = 1;
   16968              :                   /* map_head bitmap is used as uniform_head if
   16969              :                      declare_simd.  */
   16970            9 :                   if (!bitmap_bit_p (&map_head, DECL_UID (s)))
   16971            5 :                     linear_variable_step_check = true;
   16972            9 :                   goto check_dup_generic;
   16973              :                 }
   16974          143 :               if (TREE_CODE (s) != INTEGER_CST)
   16975              :                 {
   16976            7 :                   error_at (OMP_CLAUSE_LOCATION (c),
   16977              :                             "%<linear%> clause step %qE is neither constant "
   16978              :                             "nor a parameter", s);
   16979            7 :                   remove = true;
   16980            7 :                   break;
   16981              :                 }
   16982              :             }
   16983          460 :           if (TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c))) == POINTER_TYPE)
   16984              :             {
   16985           20 :               tree s = OMP_CLAUSE_LINEAR_STEP (c);
   16986           20 :               s = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
   16987           20 :                                    OMP_CLAUSE_DECL (c), s);
   16988           20 :               s = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
   16989              :                                    sizetype, fold_convert (sizetype, s),
   16990           20 :                                    fold_convert
   16991              :                                      (sizetype, OMP_CLAUSE_DECL (c)));
   16992           20 :               if (s == error_mark_node)
   16993            0 :                 s = size_one_node;
   16994           20 :               OMP_CLAUSE_LINEAR_STEP (c) = s;
   16995              :             }
   16996              :           else
   16997          440 :             OMP_CLAUSE_LINEAR_STEP (c)
   16998          880 :               = fold_convert (TREE_TYPE (t), OMP_CLAUSE_LINEAR_STEP (c));
   16999          460 :           goto check_dup_generic;
   17000              : 
   17001         2887 :         check_dup_generic:
   17002         2887 :           t = OMP_CLAUSE_DECL (c);
   17003         7118 :         check_dup_generic_t:
   17004         7118 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   17005              :             {
   17006            4 :               error_at (OMP_CLAUSE_LOCATION (c),
   17007              :                         "%qE is not a variable in clause %qs", t,
   17008            2 :                         omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17009            2 :               remove = true;
   17010              :             }
   17011         1149 :           else if ((openacc && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
   17012         6077 :                    || (ort == C_ORT_OMP
   17013         5358 :                        && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
   17014         5347 :                            || (OMP_CLAUSE_CODE (c)
   17015              :                                == OMP_CLAUSE_USE_DEVICE_ADDR)))
   17016        13146 :                    || (ort == C_ORT_OMP_TARGET
   17017          347 :                        && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION))
   17018              :             {
   17019         1196 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION
   17020         1196 :                   && (bitmap_bit_p (&generic_head, DECL_UID (t))
   17021          109 :                       || bitmap_bit_p (&firstprivate_head, DECL_UID (t))))
   17022              :                 {
   17023            2 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17024              :                             "%qD appears more than once in data-sharing "
   17025              :                             "clauses", t);
   17026            2 :                   remove = true;
   17027            2 :                   break;
   17028              :                 }
   17029         1194 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IN_REDUCTION)
   17030          108 :                 target_in_reduction_seen = true;
   17031         1194 :               if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
   17032              :                 {
   17033            4 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17034              :                             openacc
   17035              :                             ? "%qD appears more than once in reduction clauses"
   17036              :                             : "%qD appears more than once in data clauses",
   17037              :                             t);
   17038            2 :                   remove = true;
   17039              :                 }
   17040              :               else
   17041         1192 :                 bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
   17042              :             }
   17043         5920 :           else if (bitmap_bit_p (&generic_head, DECL_UID (t))
   17044         5897 :                    || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
   17045         5896 :                    || bitmap_bit_p (&lastprivate_head, DECL_UID (t))
   17046        11816 :                    || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
   17047              :             {
   17048           24 :               error_at (OMP_CLAUSE_LOCATION (c),
   17049              :                         "%qE appears more than once in data clauses", t);
   17050           24 :               remove = true;
   17051              :             }
   17052         5896 :           else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
   17053              :                     || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_HAS_DEVICE_ADDR
   17054              :                     || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
   17055         1047 :                    && bitmap_bit_p (&map_head, DECL_UID (t)))
   17056              :             {
   17057            3 :               if (openacc)
   17058            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17059              :                           "%qD appears more than once in data clauses", t);
   17060              :               else
   17061            3 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17062              :                           "%qD appears both in data and map clauses", t);
   17063              :               remove = true;
   17064              :             }
   17065              :           else
   17066         5893 :             bitmap_set_bit (&generic_head, DECL_UID (t));
   17067              :           break;
   17068              : 
   17069         1333 :         case OMP_CLAUSE_FIRSTPRIVATE:
   17070         1333 :           if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c) && !implicit_moved)
   17071              :             {
   17072          186 :             move_implicit:
   17073          186 :               implicit_moved = true;
   17074              :               /* Move firstprivate and map clauses with
   17075              :                  OMP_CLAUSE_{FIRSTPRIVATE,MAP}_IMPLICIT set to the end of
   17076              :                  clauses chain.  */
   17077          186 :               tree cl1 = NULL_TREE, cl2 = NULL_TREE;
   17078          186 :               tree *pc1 = pc, *pc2 = &cl1, *pc3 = &cl2;
   17079         1072 :               while (*pc1)
   17080          886 :                 if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_FIRSTPRIVATE
   17081          886 :                     && OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (*pc1))
   17082              :                   {
   17083          113 :                     *pc3 = *pc1;
   17084          113 :                     pc3 = &OMP_CLAUSE_CHAIN (*pc3);
   17085          113 :                     *pc1 = OMP_CLAUSE_CHAIN (*pc1);
   17086              :                   }
   17087          773 :                 else if (OMP_CLAUSE_CODE (*pc1) == OMP_CLAUSE_MAP
   17088          773 :                          && OMP_CLAUSE_MAP_IMPLICIT (*pc1))
   17089              :                   {
   17090          164 :                     *pc2 = *pc1;
   17091          164 :                     pc2 = &OMP_CLAUSE_CHAIN (*pc2);
   17092          164 :                     *pc1 = OMP_CLAUSE_CHAIN (*pc1);
   17093              :                   }
   17094              :                 else
   17095          609 :                   pc1 = &OMP_CLAUSE_CHAIN (*pc1);
   17096          186 :               *pc3 = NULL;
   17097          186 :               *pc2 = cl2;
   17098          186 :               *pc1 = cl1;
   17099          186 :               continue;
   17100          186 :             }
   17101         1238 :           t = OMP_CLAUSE_DECL (c);
   17102         1238 :           need_complete = true;
   17103         1238 :           need_implicitly_determined = true;
   17104         1238 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   17105              :             {
   17106            1 :               error_at (OMP_CLAUSE_LOCATION (c),
   17107              :                         "%qE is not a variable in clause %<firstprivate%>", t);
   17108            1 :               remove = true;
   17109              :             }
   17110         1237 :           else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
   17111          113 :                    && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c)
   17112         1343 :                    && bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
   17113              :             remove = true;
   17114         1237 :           else if (bitmap_bit_p (&generic_head, DECL_UID (t))
   17115         1235 :                    || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
   17116         2471 :                    || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
   17117              :             {
   17118            4 :               error_at (OMP_CLAUSE_LOCATION (c),
   17119              :                         "%qE appears more than once in data clauses", t);
   17120            4 :               remove = true;
   17121              :             }
   17122         1233 :           else if (bitmap_bit_p (&map_head, DECL_UID (t))
   17123         1233 :                    || bitmap_bit_p (&map_field_head, DECL_UID (t)))
   17124              :             {
   17125            7 :               if (openacc)
   17126            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17127              :                           "%qD appears more than once in data clauses", t);
   17128            7 :               else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
   17129            7 :                        && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c))
   17130              :                 /* Silently drop the clause.  */;
   17131              :               else
   17132            6 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17133              :                           "%qD appears both in data and map clauses", t);
   17134              :               remove = true;
   17135              :             }
   17136              :           else
   17137         1226 :             bitmap_set_bit (&firstprivate_head, DECL_UID (t));
   17138              :           break;
   17139              : 
   17140         1523 :         case OMP_CLAUSE_LASTPRIVATE:
   17141         1523 :           t = OMP_CLAUSE_DECL (c);
   17142         1523 :           need_complete = true;
   17143         1523 :           need_implicitly_determined = true;
   17144         1523 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   17145              :             {
   17146            0 :               error_at (OMP_CLAUSE_LOCATION (c),
   17147              :                         "%qE is not a variable in clause %<lastprivate%>", t);
   17148            0 :               remove = true;
   17149              :             }
   17150         1523 :           else if (bitmap_bit_p (&generic_head, DECL_UID (t))
   17151         1523 :                    || bitmap_bit_p (&lastprivate_head, DECL_UID (t)))
   17152              :             {
   17153            3 :               error_at (OMP_CLAUSE_LOCATION (c),
   17154              :                      "%qE appears more than once in data clauses", t);
   17155            3 :               remove = true;
   17156              :             }
   17157              :           else
   17158         1520 :             bitmap_set_bit (&lastprivate_head, DECL_UID (t));
   17159              :           break;
   17160              : 
   17161          253 :         case OMP_CLAUSE_ALIGNED:
   17162          253 :           t = OMP_CLAUSE_DECL (c);
   17163          253 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   17164              :             {
   17165            0 :               error_at (OMP_CLAUSE_LOCATION (c),
   17166              :                         "%qE is not a variable in %<aligned%> clause", t);
   17167            0 :               remove = true;
   17168              :             }
   17169          289 :           else if (!POINTER_TYPE_P (TREE_TYPE (t))
   17170          289 :                    && TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE)
   17171              :             {
   17172            7 :               error_at (OMP_CLAUSE_LOCATION (c),
   17173              :                         "%qE in %<aligned%> clause is neither a pointer nor "
   17174              :                         "an array", t);
   17175            7 :               remove = true;
   17176              :             }
   17177          246 :           else if (TYPE_ATOMIC (TREE_TYPE (t)))
   17178              :             {
   17179            1 :               error_at (OMP_CLAUSE_LOCATION (c),
   17180              :                         "%<_Atomic%> %qD in %<aligned%> clause", t);
   17181            1 :               remove = true;
   17182            1 :               break;
   17183              :             }
   17184          245 :           else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
   17185              :             {
   17186            0 :               error_at (OMP_CLAUSE_LOCATION (c),
   17187              :                         "%qE appears more than once in %<aligned%> clauses",
   17188              :                         t);
   17189            0 :               remove = true;
   17190              :             }
   17191              :           else
   17192          245 :             bitmap_set_bit (&aligned_head, DECL_UID (t));
   17193              :           break;
   17194              : 
   17195          125 :         case OMP_CLAUSE_NONTEMPORAL:
   17196          125 :           t = OMP_CLAUSE_DECL (c);
   17197          125 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   17198              :             {
   17199            0 :               error_at (OMP_CLAUSE_LOCATION (c),
   17200              :                         "%qE is not a variable in %<nontemporal%> clause", t);
   17201            0 :               remove = true;
   17202              :             }
   17203          125 :           else if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
   17204              :             {
   17205            2 :               error_at (OMP_CLAUSE_LOCATION (c),
   17206              :                         "%qE appears more than once in %<nontemporal%> "
   17207              :                         "clauses", t);
   17208            2 :               remove = true;
   17209              :             }
   17210              :           else
   17211          123 :             bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
   17212              :           break;
   17213              : 
   17214          802 :         case OMP_CLAUSE_ALLOCATE:
   17215          802 :           t = OMP_CLAUSE_DECL (c);
   17216          802 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   17217              :             {
   17218            1 :               error_at (OMP_CLAUSE_LOCATION (c),
   17219              :                         "%qE is not a variable in %<allocate%> clause", t);
   17220            1 :               remove = true;
   17221              :             }
   17222          801 :           else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
   17223              :             {
   17224            2 :               warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
   17225              :                           "%qE appears more than once in %<allocate%> clauses",
   17226              :                           t);
   17227            2 :               remove = true;
   17228              :             }
   17229              :           else
   17230              :             {
   17231          799 :               bitmap_set_bit (&aligned_head, DECL_UID (t));
   17232          799 :               if (!OMP_CLAUSE_ALLOCATE_COMBINED (c))
   17233          700 :                 allocate_seen = true;
   17234              :             }
   17235              :           break;
   17236              : 
   17237          357 :         case OMP_CLAUSE_DOACROSS:
   17238          357 :           t = OMP_CLAUSE_DECL (c);
   17239          357 :           if (t == NULL_TREE)
   17240              :             break;
   17241          169 :           if (OMP_CLAUSE_DOACROSS_KIND (c) == OMP_CLAUSE_DOACROSS_SINK)
   17242              :             {
   17243          169 :               gcc_assert (TREE_CODE (t) == TREE_LIST);
   17244         1315 :               for (; t; t = TREE_CHAIN (t))
   17245              :                 {
   17246         1146 :                   tree decl = TREE_VALUE (t);
   17247         1146 :                   if (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE)
   17248              :                     {
   17249            3 :                       tree offset = TREE_PURPOSE (t);
   17250            3 :                       bool neg = wi::neg_p (wi::to_wide (offset));
   17251            3 :                       offset = fold_unary (ABS_EXPR, TREE_TYPE (offset), offset);
   17252            6 :                       tree t2 = pointer_int_sum (OMP_CLAUSE_LOCATION (c),
   17253              :                                                  neg ? MINUS_EXPR : PLUS_EXPR,
   17254              :                                                  decl, offset);
   17255            3 :                       t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
   17256              :                                             sizetype,
   17257              :                                             fold_convert (sizetype, t2),
   17258              :                                             fold_convert (sizetype, decl));
   17259            3 :                       if (t2 == error_mark_node)
   17260              :                         {
   17261              :                           remove = true;
   17262              :                           break;
   17263              :                         }
   17264            3 :                       TREE_PURPOSE (t) = t2;
   17265              :                     }
   17266              :                 }
   17267              :               break;
   17268              :             }
   17269            0 :           gcc_unreachable ();
   17270              : 
   17271           36 :         case OMP_CLAUSE_USES_ALLOCATORS:
   17272           36 :           t = OMP_CLAUSE_USES_ALLOCATORS_ALLOCATOR (c);
   17273           36 :           if (t == error_mark_node)
   17274              :             {
   17275              :               remove = true;
   17276              :               break;
   17277              :             }
   17278            6 :           if ((VAR_P (t) || TREE_CODE (t) == PARM_DECL)
   17279           33 :               && (bitmap_bit_p (&generic_head, DECL_UID (t))
   17280           27 :                   || bitmap_bit_p (&map_head, DECL_UID (t))
   17281           27 :                   || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
   17282           26 :                   || bitmap_bit_p (&lastprivate_head, DECL_UID (t))))
   17283              :             {
   17284            1 :               error_at (OMP_CLAUSE_LOCATION (c),
   17285              :                         "%qE appears more than once in data clauses", t);
   17286            1 :               remove = true;
   17287            1 :               break;
   17288              :             }
   17289              :           else
   17290           31 :             bitmap_set_bit (&generic_head, DECL_UID (t));
   17291           31 :           if (TREE_CODE (TREE_TYPE (t)) != ENUMERAL_TYPE
   17292           59 :               || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (TREE_TYPE (t))),
   17293              :                          "omp_allocator_handle_t") != 0)
   17294              :             {
   17295            3 :               error_at (OMP_CLAUSE_LOCATION (c),
   17296              :                         "allocator %qE must be of %<omp_allocator_handle_t%> "
   17297              :                         "type", t);
   17298            3 :               remove = true;
   17299            3 :               break;
   17300              :             }
   17301           28 :           tree init;
   17302           28 :           if (!DECL_P (t)
   17303           28 :               || (TREE_CODE (t) == CONST_DECL
   17304            5 :                   && ((init = DECL_INITIAL(t)) == nullptr
   17305            5 :                       || TREE_CODE (init) != INTEGER_CST
   17306            5 :                       || ((wi::to_widest (init) < 0
   17307            5 :                            || wi::to_widest (init) > GOMP_OMP_PREDEF_ALLOC_MAX)
   17308            0 :                           && (wi::to_widest (init) < GOMP_OMPX_PREDEF_ALLOC_MIN
   17309            0 :                               || (wi::to_widest (init)
   17310            0 :                                   > GOMP_OMPX_PREDEF_ALLOC_MAX))))))
   17311              :             {
   17312            0 :               remove = true;
   17313            0 :               error_at (OMP_CLAUSE_LOCATION (c),
   17314              :                         "allocator %qE must be either a variable or a "
   17315              :                         "predefined allocator", t);
   17316            0 :               break;
   17317              :             }
   17318           28 :           else if (TREE_CODE (t) == CONST_DECL)
   17319              :             {
   17320              :               /* omp_null_allocator is ignored and for predefined allocators,
   17321              :                  not special handling is required; thus, remove them removed. */
   17322            5 :               remove = true;
   17323              : 
   17324            5 :               if (OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE (c)
   17325            5 :                   || OMP_CLAUSE_USES_ALLOCATORS_TRAITS (c))
   17326              :                 {
   17327            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17328              :                             "modifiers cannot be used with predefined "
   17329              :                             "allocator %qE", t);
   17330            0 :                   break;
   17331              :                 }
   17332              :             }
   17333           28 :           t = OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE (c);
   17334           28 :           if (t == error_mark_node)
   17335              :             {
   17336              :               remove = true;
   17337              :               break;
   17338              :             }
   17339           28 :           if (t != NULL_TREE
   17340           28 :               && ((TREE_CODE (t) != CONST_DECL && TREE_CODE (t) != INTEGER_CST)
   17341            5 :                   || TREE_CODE (TREE_TYPE (t)) != ENUMERAL_TYPE
   17342            8 :                   || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (TREE_TYPE (t))),
   17343              :                              "omp_memspace_handle_t") != 0))
   17344              :             {
   17345            1 :               error_at (OMP_CLAUSE_LOCATION (c), "memspace modifier %qE must be"
   17346              :                         " constant enum of %<omp_memspace_handle_t%> type", t);
   17347            1 :               remove = true;
   17348            1 :               break;
   17349              :             }
   17350           27 :           t = OMP_CLAUSE_USES_ALLOCATORS_TRAITS (c);
   17351           27 :           if (t == error_mark_node)
   17352              :             {
   17353              :               remove = true;
   17354              :               break;
   17355              :             }
   17356           27 :           if (t != NULL_TREE
   17357              :               && t != error_mark_node
   17358           27 :               && (DECL_EXTERNAL (t)
   17359            9 :                   || TREE_CODE (t) == PARM_DECL))
   17360              :             {
   17361            3 :               error_at (OMP_CLAUSE_LOCATION (c), "traits array %qE must be "
   17362              :                         "defined in same scope as the construct on which the "
   17363              :                         "clause appears", t);
   17364            3 :               remove = true;
   17365              :             }
   17366           27 :           if (t != NULL_TREE)
   17367              :             {
   17368           11 :               bool type_err = false;
   17369              : 
   17370           11 :               if (TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE
   17371           10 :                   || DECL_SIZE (t) == NULL_TREE
   17372           20 :                   || !COMPLETE_TYPE_P (TREE_TYPE (t)))
   17373              :                 type_err = true;
   17374              :               else
   17375              :                 {
   17376            9 :                   tree elem_t = TREE_TYPE (TREE_TYPE (t));
   17377            9 :                   if (TREE_CODE (elem_t) != RECORD_TYPE
   17378           18 :                       || strcmp (IDENTIFIER_POINTER (TYPE_IDENTIFIER (elem_t)),
   17379              :                                  "omp_alloctrait_t") != 0
   17380           18 :                       || !TYPE_READONLY (elem_t))
   17381              :                     type_err = true;
   17382              :                 }
   17383            8 :               if (type_err)
   17384              :                 {
   17385            3 :                   if (t != error_mark_node)
   17386            3 :                     error_at (OMP_CLAUSE_LOCATION (c), "traits array %qE must "
   17387              :                               "be of %<const omp_alloctrait_t []%> type", t);
   17388              :                   else
   17389            0 :                     error_at (OMP_CLAUSE_LOCATION (c), "traits array must "
   17390              :                               "be of %<const omp_alloctrait_t []%> type");
   17391              :                   remove = true;
   17392              :                 }
   17393              :               else
   17394              :                 {
   17395            8 :                   tree cst_val = decl_constant_value_1 (t, true);
   17396            8 :                   if (cst_val == t)
   17397              :                     {
   17398            1 :                       error_at (OMP_CLAUSE_LOCATION (c), "traits array must be "
   17399              :                                 "initialized with constants");
   17400              : 
   17401            1 :                       remove = true;
   17402              :                     }
   17403              :                 }
   17404              :             }
   17405           24 :           if (remove)
   17406              :             break;
   17407           18 :           pc = &OMP_CLAUSE_CHAIN (c);
   17408           18 :           continue;
   17409          713 :         case OMP_CLAUSE_DEPEND:
   17410          713 :           depend_clause = c;
   17411              :           /* FALLTHRU */
   17412          870 :         case OMP_CLAUSE_AFFINITY:
   17413          870 :           t = OMP_CLAUSE_DECL (c);
   17414          870 :           if (OMP_ITERATOR_DECL_P (t))
   17415              :             {
   17416          131 :               if (TREE_PURPOSE (t) != last_iterators)
   17417          111 :                 last_iterators_remove
   17418          111 :                   = c_omp_finish_iterators (TREE_PURPOSE (t));
   17419          131 :               last_iterators = TREE_PURPOSE (t);
   17420          131 :               t = TREE_VALUE (t);
   17421          131 :               if (last_iterators_remove)
   17422           34 :                 t = error_mark_node;
   17423              :             }
   17424              :           else
   17425              :             last_iterators = NULL_TREE;
   17426          870 :           if (TREE_CODE (t) == OMP_ARRAY_SECTION)
   17427              :             {
   17428          413 :               if (handle_omp_array_sections (c, ort))
   17429              :                 remove = true;
   17430          336 :               else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   17431          336 :                        && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ)
   17432              :                 {
   17433            1 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17434              :                             "%<depend%> clause with %<depobj%> dependence "
   17435              :                             "type on array section");
   17436            1 :                   remove = true;
   17437              :                 }
   17438              :               break;
   17439              :             }
   17440          457 :           if (t == error_mark_node)
   17441              :             remove = true;
   17442          423 :           else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   17443          423 :                    && t == ridpointers[RID_OMP_ALL_MEMORY])
   17444              :             {
   17445           15 :               if (OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_OUT
   17446           15 :                   && OMP_CLAUSE_DEPEND_KIND (c) != OMP_CLAUSE_DEPEND_INOUT)
   17447              :                 {
   17448            3 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17449              :                             "%<omp_all_memory%> used with %<depend%> kind "
   17450              :                             "other than %<out%> or %<inout%>");
   17451            3 :                   remove = true;
   17452              :                 }
   17453              :             }
   17454          408 :           else if (!lvalue_p (t))
   17455              :             {
   17456            6 :               error_at (OMP_CLAUSE_LOCATION (c),
   17457              :                         "%qE is not lvalue expression nor array section in "
   17458              :                         "%qs clause", t,
   17459            3 :                         omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17460            3 :               remove = true;
   17461              :             }
   17462          405 :           else if (TREE_CODE (t) == COMPONENT_REF
   17463          405 :                    && DECL_C_BIT_FIELD (TREE_OPERAND (t, 1)))
   17464              :             {
   17465            2 :               gcc_assert (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   17466              :                           || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_AFFINITY);
   17467            2 :               error_at (OMP_CLAUSE_LOCATION (c),
   17468              :                         "bit-field %qE in %qs clause", t,
   17469            2 :                         omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17470            2 :               remove = true;
   17471              :             }
   17472          403 :           else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   17473          403 :                    && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ)
   17474              :             {
   17475           20 :               if (!c_omp_depend_t_p (TREE_TYPE (t)))
   17476              :                 {
   17477            2 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17478              :                             "%qE does not have %<omp_depend_t%> type in "
   17479              :                             "%<depend%> clause with %<depobj%> dependence "
   17480              :                             "type", t);
   17481            2 :                   remove = true;
   17482              :                 }
   17483              :             }
   17484          383 :           else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
   17485          383 :                    && c_omp_depend_t_p (TREE_TYPE (t)))
   17486              :             {
   17487            2 :               error_at (OMP_CLAUSE_LOCATION (c),
   17488              :                         "%qE should not have %<omp_depend_t%> type in "
   17489              :                         "%<depend%> clause with dependence type other than "
   17490              :                         "%<depobj%>", t);
   17491            2 :               remove = true;
   17492              :             }
   17493           12 :           if (!remove)
   17494              :             {
   17495          411 :               if (t == ridpointers[RID_OMP_ALL_MEMORY])
   17496           12 :                 t = null_pointer_node;
   17497              :               else
   17498              :                 {
   17499          399 :                   tree addr = build_unary_op (OMP_CLAUSE_LOCATION (c),
   17500              :                                               ADDR_EXPR, t, false);
   17501          399 :                   if (addr == error_mark_node)
   17502              :                     {
   17503              :                       remove = true;
   17504              :                       break;
   17505              :                     }
   17506          399 :                   t = build_indirect_ref (OMP_CLAUSE_LOCATION (c), addr,
   17507              :                                           RO_UNARY_STAR);
   17508          399 :                   if (t == error_mark_node)
   17509              :                     {
   17510              :                       remove = true;
   17511              :                       break;
   17512              :                     }
   17513              :                 }
   17514          411 :               if (OMP_ITERATOR_DECL_P (OMP_CLAUSE_DECL (c)))
   17515           31 :                 TREE_VALUE (OMP_CLAUSE_DECL (c)) = t;
   17516              :               else
   17517          380 :                 OMP_CLAUSE_DECL (c) = t;
   17518              :             }
   17519              :           break;
   17520              : 
   17521         6606 :         case OMP_CLAUSE_MAP:
   17522         6606 :           if (OMP_CLAUSE_MAP_IMPLICIT (c) && !implicit_moved)
   17523           91 :             goto move_implicit;
   17524         6515 :           if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_PUSH_MAPPER_NAME
   17525         6515 :               || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POP_MAPPER_NAME)
   17526              :             {
   17527              :               remove = true;
   17528              :               break;
   17529              :             }
   17530              :           /* FALLTHRU */
   17531         9368 :         case OMP_CLAUSE_TO:
   17532         9368 :         case OMP_CLAUSE_FROM:
   17533         9368 :           if (OMP_CLAUSE_ITERATORS (c)
   17534         9368 :               && c_omp_finish_iterators (OMP_CLAUSE_ITERATORS (c)))
   17535              :             {
   17536        22780 :               t = error_mark_node;
   17537              :               break;
   17538              :             }
   17539              :           /* FALLTHRU */
   17540         9504 :         case OMP_CLAUSE__CACHE_:
   17541         9504 :           {
   17542         9504 :             using namespace omp_addr_tokenizer;
   17543         9504 :             auto_vec<omp_addr_token *, 10> addr_tokens;
   17544              : 
   17545         9504 :             t = OMP_CLAUSE_DECL (c);
   17546         9504 :             if (TREE_CODE (t) == OMP_ARRAY_SECTION)
   17547              :               {
   17548         2001 :                 grp_start_p = pc;
   17549         2001 :                 grp_sentinel = OMP_CLAUSE_CHAIN (c);
   17550              : 
   17551         2001 :                 if (handle_omp_array_sections (c, ort))
   17552              :                   remove = true;
   17553              :                 else
   17554              :                   {
   17555         1861 :                     t = OMP_CLAUSE_DECL (c);
   17556         1861 :                     if (!omp_mappable_type (TREE_TYPE (t)))
   17557              :                       {
   17558            2 :                         error_at (OMP_CLAUSE_LOCATION (c),
   17559              :                                   "array section does not have mappable type "
   17560              :                                   "in %qs clause",
   17561            1 :                                   omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17562            1 :                         remove = true;
   17563              :                       }
   17564         1860 :                     else if (TYPE_ATOMIC (TREE_TYPE (t)))
   17565              :                       {
   17566            2 :                         error_at (OMP_CLAUSE_LOCATION (c),
   17567              :                                   "%<_Atomic%> %qE in %qs clause", t,
   17568            1 :                                   omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17569            1 :                         remove = true;
   17570              :                       }
   17571         2510 :                     while (TREE_CODE (t) == ARRAY_REF)
   17572          649 :                       t = TREE_OPERAND (t, 0);
   17573              : 
   17574         1861 :                     c_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
   17575              : 
   17576         1861 :                     if (!omp_parse_expr (addr_tokens, t))
   17577              :                       {
   17578            0 :                         sorry_at (OMP_CLAUSE_LOCATION (c),
   17579              :                                   "unsupported map expression %qE",
   17580            0 :                                   OMP_CLAUSE_DECL (c));
   17581            0 :                         remove = true;
   17582            0 :                         break;
   17583              :                       }
   17584              : 
   17585              :                     /* This check is to determine if this will be the only map
   17586              :                        node created for this clause.  Otherwise, we'll check
   17587              :                        the following FIRSTPRIVATE_POINTER or ATTACH_DETACH
   17588              :                        node on the next iteration(s) of the loop.   */
   17589         3704 :                     if (addr_tokens.length () >= 4
   17590          304 :                         && addr_tokens[0]->type == STRUCTURE_BASE
   17591          302 :                         && addr_tokens[0]->u.structure_base_kind == BASE_DECL
   17592          302 :                         && addr_tokens[1]->type == ACCESS_METHOD
   17593          302 :                         && addr_tokens[2]->type == COMPONENT_SELECTOR
   17594          302 :                         && addr_tokens[3]->type == ACCESS_METHOD
   17595         2102 :                         && (addr_tokens[3]->u.access_kind == ACCESS_DIRECT
   17596          188 :                             || (addr_tokens[3]->u.access_kind
   17597              :                                 == ACCESS_INDEXED_ARRAY)))
   17598              :                       {
   17599           55 :                         tree rt = addr_tokens[1]->expr;
   17600              : 
   17601           55 :                         gcc_assert (DECL_P (rt));
   17602              : 
   17603           55 :                         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   17604           50 :                             && OMP_CLAUSE_MAP_IMPLICIT (c)
   17605           55 :                             && (bitmap_bit_p (&map_head, DECL_UID (rt))
   17606            0 :                                 || bitmap_bit_p (&map_field_head, DECL_UID (rt))
   17607            0 :                                 || bitmap_bit_p (&map_firstprivate_head,
   17608            0 :                                                  DECL_UID (rt))))
   17609              :                           {
   17610              :                             remove = true;
   17611              :                             break;
   17612              :                           }
   17613           55 :                         if (bitmap_bit_p (&map_field_head, DECL_UID (rt)))
   17614              :                           break;
   17615           37 :                         if (bitmap_bit_p (&map_head, DECL_UID (rt)))
   17616              :                           {
   17617            0 :                             if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
   17618            0 :                               error_at (OMP_CLAUSE_LOCATION (c),
   17619              :                                         "%qD appears more than once in motion "
   17620              :                                         "clauses", rt);
   17621            0 :                             else if (openacc)
   17622            0 :                               error_at (OMP_CLAUSE_LOCATION (c),
   17623              :                                         "%qD appears more than once in data "
   17624              :                                         "clauses", rt);
   17625              :                             else
   17626            0 :                               error_at (OMP_CLAUSE_LOCATION (c),
   17627              :                                         "%qD appears more than once in map "
   17628              :                                         "clauses", rt);
   17629              :                             remove = true;
   17630              :                           }
   17631              :                         else
   17632              :                           {
   17633           37 :                             bitmap_set_bit (&map_head, DECL_UID (rt));
   17634           37 :                             bitmap_set_bit (&map_field_head, DECL_UID (rt));
   17635              :                           }
   17636              :                       }
   17637         1861 :                   }
   17638         1983 :                 if (c_oacc_check_attachments (c))
   17639            2 :                   remove = true;
   17640         1983 :                 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   17641         1807 :                     && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
   17642         1789 :                         || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
   17643         2008 :                     && !OMP_CLAUSE_SIZE (c))
   17644              :                   /* In this case, we have a single array element which is a
   17645              :                      pointer, and we already set OMP_CLAUSE_SIZE in
   17646              :                      handle_omp_array_sections above.  For attach/detach
   17647              :                      clauses, reset the OMP_CLAUSE_SIZE (representing a bias)
   17648              :                      to zero here.  */
   17649           10 :                   OMP_CLAUSE_SIZE (c) = size_zero_node;
   17650              :                 break;
   17651              :               }
   17652         7503 :             else if (!omp_parse_expr (addr_tokens, t))
   17653              :               {
   17654            0 :                 sorry_at (OMP_CLAUSE_LOCATION (c),
   17655              :                           "unsupported map expression %qE",
   17656            0 :                           OMP_CLAUSE_DECL (c));
   17657            0 :                 remove = true;
   17658            0 :                 break;
   17659              :               }
   17660         7503 :             if (t == error_mark_node)
   17661              :               {
   17662              :                 remove = true;
   17663              :                 break;
   17664              :               }
   17665              :             /* OpenACC attach / detach clauses must be pointers.  */
   17666         7491 :             if (c_oacc_check_attachments (c))
   17667              :               {
   17668              :                 remove = true;
   17669              :                 break;
   17670              :               }
   17671         7487 :             if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   17672         4668 :                 && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ATTACH
   17673         4641 :                     || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)
   17674         7529 :                 && !OMP_CLAUSE_SIZE (c))
   17675              :               /* For attach/detach clauses, set OMP_CLAUSE_SIZE (representing a
   17676              :                  bias) to zero here, so it is not set erroneously to the pointer
   17677              :                  size later on in gimplify.cc.  */
   17678           28 :               OMP_CLAUSE_SIZE (c) = size_zero_node;
   17679              : 
   17680         7487 :             c_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t);
   17681              : 
   17682         7487 :             if (!ai.check_clause (c))
   17683              :               {
   17684              :                 remove = true;
   17685              :                 break;
   17686              :               }
   17687              : 
   17688         7479 :             if (!ai.map_supported_p ())
   17689              :               {
   17690           14 :                 sorry_at (OMP_CLAUSE_LOCATION (c),
   17691              :                           "unsupported map expression %qE",
   17692            7 :                           OMP_CLAUSE_DECL (c));
   17693            7 :                 remove = true;
   17694            7 :                 break;
   17695              :               }
   17696              : 
   17697        14944 :             gcc_assert ((addr_tokens[0]->type == ARRAY_BASE
   17698              :                          || addr_tokens[0]->type == STRUCTURE_BASE)
   17699              :                         && addr_tokens[1]->type == ACCESS_METHOD);
   17700              : 
   17701         7472 :             t = addr_tokens[1]->expr;
   17702              : 
   17703         7472 :             if (addr_tokens[0]->u.structure_base_kind != BASE_DECL)
   17704            0 :               goto skip_decl_checks;
   17705              : 
   17706              :             /* For OpenMP, we can access a struct "t" and "t.d" on the same
   17707              :                mapping.  OpenACC allows multiple fields of the same structure
   17708              :                to be written.  */
   17709         7472 :             if (addr_tokens[0]->type == STRUCTURE_BASE
   17710         7472 :                 && (bitmap_bit_p (&map_field_head, DECL_UID (t))
   17711          238 :                     || (!openacc && bitmap_bit_p (&map_head, DECL_UID (t)))))
   17712          246 :               goto skip_decl_checks;
   17713              : 
   17714         7226 :             if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   17715              :               {
   17716            3 :                 if (ort != C_ORT_ACC && EXPR_P (t))
   17717              :                   break;
   17718              : 
   17719            6 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17720              :                           "%qE is not a variable in %qs clause", t,
   17721            3 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17722            3 :                 remove = true;
   17723              :               }
   17724         7223 :             else if (VAR_P (t) && DECL_THREAD_LOCAL_P (t))
   17725              :               {
   17726            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17727              :                           "%qD is threadprivate variable in %qs clause", t,
   17728            0 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17729            0 :                 remove = true;
   17730              :               }
   17731         7223 :             else if ((OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
   17732         4411 :                       || (OMP_CLAUSE_MAP_KIND (c)
   17733              :                           != GOMP_MAP_FIRSTPRIVATE_POINTER))
   17734        10590 :                      && !c_mark_addressable (t))
   17735              :               remove = true;
   17736         7223 :             else if (!(OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   17737         4411 :                        && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
   17738         4411 :                            || (OMP_CLAUSE_MAP_KIND (c)
   17739              :                                == GOMP_MAP_FIRSTPRIVATE_POINTER)
   17740         3367 :                            || (OMP_CLAUSE_MAP_KIND (c)
   17741              :                                == GOMP_MAP_FORCE_DEVICEPTR)))
   17742         6121 :                      && t == OMP_CLAUSE_DECL (c)
   17743        13108 :                      && !omp_mappable_type (TREE_TYPE (t)))
   17744              :               {
   17745           16 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17746              :                           "%qD does not have a mappable type in %qs clause", t,
   17747            8 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17748            8 :                 remove = true;
   17749              :               }
   17750         7215 :             else if (TREE_TYPE (t) == error_mark_node)
   17751              :               remove = true;
   17752         7214 :             else if (TYPE_ATOMIC (strip_array_types (TREE_TYPE (t))))
   17753              :               {
   17754            8 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17755              :                           "%<_Atomic%> %qE in %qs clause", t,
   17756            4 :                           omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17757            4 :                 remove = true;
   17758              :               }
   17759         7210 :             else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   17760         4401 :                      && OMP_CLAUSE_MAP_IMPLICIT (c)
   17761         7374 :                      && (bitmap_bit_p (&map_head, DECL_UID (t))
   17762          128 :                          || bitmap_bit_p (&map_field_head, DECL_UID (t))
   17763          128 :                          || bitmap_bit_p (&map_firstprivate_head,
   17764          128 :                                           DECL_UID (t))))
   17765              :               remove = true;
   17766         7173 :             else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
   17767         7173 :                      && (OMP_CLAUSE_MAP_KIND (c)
   17768              :                          == GOMP_MAP_FIRSTPRIVATE_POINTER))
   17769              :               {
   17770         1042 :                 if (bitmap_bit_p (&generic_head, DECL_UID (t))
   17771         1042 :                     || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
   17772         2083 :                     || bitmap_bit_p (&map_firstprivate_head, DECL_UID (t)))
   17773              :                   {
   17774            5 :                     error_at (OMP_CLAUSE_LOCATION (c),
   17775              :                               "%qD appears more than once in data clauses", t);
   17776            5 :                     remove = true;
   17777              :                   }
   17778         1037 :                 else if (bitmap_bit_p (&map_head, DECL_UID (t))
   17779            4 :                          && !bitmap_bit_p (&map_field_head, DECL_UID (t))
   17780         1039 :                          && openacc)
   17781              :                   {
   17782            1 :                     error_at (OMP_CLAUSE_LOCATION (c),
   17783              :                               "%qD appears more than once in data clauses", t);
   17784            1 :                     remove = true;
   17785              :                   }
   17786              :                 else
   17787         1036 :                   bitmap_set_bit (&map_firstprivate_head, DECL_UID (t));
   17788              :               }
   17789         6131 :             else if (bitmap_bit_p (&map_head, DECL_UID (t))
   17790           59 :                      && !bitmap_bit_p (&map_field_head, DECL_UID (t))
   17791           13 :                      && ort != C_ORT_OMP
   17792         6144 :                      && ort != C_ORT_OMP_EXIT_DATA)
   17793              :               {
   17794           10 :                 if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
   17795            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17796              :                             "%qD appears more than once in motion clauses", t);
   17797           10 :                 else if (openacc)
   17798            7 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17799              :                             "%qD appears more than once in data clauses", t);
   17800              :                 else
   17801            3 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17802              :                             "%qD appears more than once in map clauses", t);
   17803              :                 remove = true;
   17804              :               }
   17805         6121 :             else if (openacc && bitmap_bit_p (&generic_head, DECL_UID (t)))
   17806              :               {
   17807            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17808              :                           "%qD appears more than once in data clauses", t);
   17809            0 :                 remove = true;
   17810              :               }
   17811         6121 :             else if (bitmap_bit_p (&firstprivate_head, DECL_UID (t))
   17812         6121 :                      || bitmap_bit_p (&is_on_device_head, DECL_UID (t)))
   17813              :               {
   17814            9 :                 if (openacc)
   17815            0 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17816              :                             "%qD appears more than once in data clauses", t);
   17817              :                 else
   17818            9 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17819              :                             "%qD appears both in data and map clauses", t);
   17820              :                 remove = true;
   17821              :               }
   17822         6112 :             else if (!omp_access_chain_p (addr_tokens, 1))
   17823              :               {
   17824         6112 :                 bitmap_set_bit (&map_head, DECL_UID (t));
   17825         6112 :                 if (t != OMP_CLAUSE_DECL (c)
   17826         6112 :                     && TREE_CODE (OMP_CLAUSE_DECL (c)) == COMPONENT_REF)
   17827          232 :                   bitmap_set_bit (&map_field_head, DECL_UID (t));
   17828              :               }
   17829              : 
   17830            0 :           skip_decl_checks:
   17831              :             /* If we call omp_expand_map_clause in handle_omp_array_sections,
   17832              :                the containing loop (here) iterates through the new nodes
   17833              :                created by that expansion.  Avoid expanding those again (just
   17834              :                by checking the node type).  */
   17835         7472 :             if (!remove
   17836         7472 :                 && ort != C_ORT_DECLARE_SIMD
   17837         7472 :                 && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
   17838         4579 :                     || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FIRSTPRIVATE_POINTER
   17839         3543 :                         && (OMP_CLAUSE_MAP_KIND (c)
   17840              :                             != GOMP_MAP_FIRSTPRIVATE_REFERENCE)
   17841         3543 :                         && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ALWAYS_POINTER
   17842         3543 :                         && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH_DETACH
   17843         3244 :                         && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_ATTACH
   17844         3217 :                         && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_DETACH)))
   17845              :               {
   17846         6017 :                 grp_start_p = pc;
   17847         6017 :                 grp_sentinel = OMP_CLAUSE_CHAIN (c);
   17848         6017 :                 tree nc = ai.expand_map_clause (c, OMP_CLAUSE_DECL (c),
   17849              :                                                 addr_tokens, ort);
   17850         6017 :                 if (nc != error_mark_node)
   17851         6017 :                   c = nc;
   17852              :               }
   17853         9519 :           }
   17854         7472 :           break;
   17855              : 
   17856          226 :         case OMP_CLAUSE_ENTER:
   17857          226 :         case OMP_CLAUSE_LINK:
   17858          226 :           t = OMP_CLAUSE_DECL (c);
   17859          226 :           const char *cname;
   17860          226 :           cname = omp_clause_code_name[OMP_CLAUSE_CODE (c)];
   17861          226 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER
   17862          226 :               && OMP_CLAUSE_ENTER_TO (c))
   17863              :             cname = "to";
   17864          226 :           if (TREE_CODE (t) == FUNCTION_DECL
   17865          226 :               && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
   17866              :             ;
   17867          145 :           else if (!VAR_P (t))
   17868              :             {
   17869            1 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
   17870            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17871              :                           "%qE is neither a variable nor a function name in "
   17872              :                           "clause %qs", t, cname);
   17873              :               else
   17874            1 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17875              :                           "%qE is not a variable in clause %qs", t, cname);
   17876              :               remove = true;
   17877              :             }
   17878          144 :           else if (DECL_THREAD_LOCAL_P (t))
   17879              :             {
   17880            2 :               error_at (OMP_CLAUSE_LOCATION (c),
   17881              :                         "%qD is threadprivate variable in %qs clause", t,
   17882              :                         cname);
   17883            2 :               remove = true;
   17884              :             }
   17885          142 :           else if (!omp_mappable_type (TREE_TYPE (t)))
   17886              :             {
   17887            6 :               error_at (OMP_CLAUSE_LOCATION (c),
   17888              :                         "%qD does not have a mappable type in %qs clause", t,
   17889              :                         cname);
   17890            6 :               remove = true;
   17891              :             }
   17892            8 :           if (remove)
   17893              :             break;
   17894          217 :           if (bitmap_bit_p (&generic_head, DECL_UID (t)))
   17895              :             {
   17896            8 :               error_at (OMP_CLAUSE_LOCATION (c),
   17897              :                         "%qE appears more than once on the same "
   17898              :                         "%<declare target%> directive", t);
   17899            8 :               remove = true;
   17900              :             }
   17901              :           else
   17902          209 :             bitmap_set_bit (&generic_head, DECL_UID (t));
   17903              :           break;
   17904              : 
   17905          117 :         case OMP_CLAUSE_UNIFORM:
   17906          117 :           t = OMP_CLAUSE_DECL (c);
   17907          117 :           if (TREE_CODE (t) != PARM_DECL)
   17908              :             {
   17909            0 :               if (DECL_P (t))
   17910            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17911              :                           "%qD is not an argument in %<uniform%> clause", t);
   17912              :               else
   17913            0 :                 error_at (OMP_CLAUSE_LOCATION (c),
   17914              :                           "%qE is not an argument in %<uniform%> clause", t);
   17915              :               remove = true;
   17916              :               break;
   17917              :             }
   17918              :           /* map_head bitmap is used as uniform_head if declare_simd.  */
   17919          117 :           bitmap_set_bit (&map_head, DECL_UID (t));
   17920          117 :           goto check_dup_generic;
   17921              : 
   17922          161 :         case OMP_CLAUSE_IS_DEVICE_PTR:
   17923          161 :         case OMP_CLAUSE_USE_DEVICE_PTR:
   17924          161 :           t = OMP_CLAUSE_DECL (c);
   17925          161 :           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IS_DEVICE_PTR)
   17926          123 :             bitmap_set_bit (&is_on_device_head, DECL_UID (t));
   17927          161 :           if (TREE_CODE (TREE_TYPE (t)) != POINTER_TYPE)
   17928              :             {
   17929           21 :               if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR
   17930           21 :                   && !openacc)
   17931              :                 {
   17932            1 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17933              :                             "%qs variable is not a pointer",
   17934            1 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17935            1 :                   remove = true;
   17936              :                 }
   17937           20 :               else if (TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE)
   17938              :                 {
   17939            4 :                   error_at (OMP_CLAUSE_LOCATION (c),
   17940              :                             "%qs variable is neither a pointer nor an array",
   17941            4 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   17942            4 :                   remove = true;
   17943              :                 }
   17944              :             }
   17945          161 :           goto check_dup_generic;
   17946              : 
   17947           89 :         case OMP_CLAUSE_HAS_DEVICE_ADDR:
   17948           89 :           t = OMP_CLAUSE_DECL (c);
   17949           89 :           if (TREE_CODE (t) == OMP_ARRAY_SECTION)
   17950              :             {
   17951           11 :               if (handle_omp_array_sections (c, ort))
   17952              :                 remove = true;
   17953              :               else
   17954              :                 {
   17955           11 :                   t = OMP_CLAUSE_DECL (c);
   17956           24 :                   while (TREE_CODE (t) == ARRAY_REF)
   17957           13 :                     t = TREE_OPERAND (t, 0);
   17958              :                 }
   17959              :             }
   17960           89 :           bitmap_set_bit (&is_on_device_head, DECL_UID (t));
   17961           89 :           if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
   17962           89 :             c_mark_addressable (t);
   17963           89 :           goto check_dup_generic_t;
   17964              : 
   17965           36 :         case OMP_CLAUSE_USE_DEVICE_ADDR:
   17966           36 :           t = OMP_CLAUSE_DECL (c);
   17967           36 :           if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
   17968           36 :             c_mark_addressable (t);
   17969           36 :           goto check_dup_generic;
   17970              : 
   17971         4791 :         case OMP_CLAUSE_NOWAIT:
   17972         4791 :           if (copyprivate_seen)
   17973              :             {
   17974            1 :               error_at (OMP_CLAUSE_LOCATION (c),
   17975              :                         "%<nowait%> clause must not be used together "
   17976              :                         "with %<copyprivate%> clause");
   17977            1 :               remove = true;
   17978            1 :               break;
   17979              :             }
   17980         4790 :           nowait_clause = pc;
   17981         4790 :           pc = &OMP_CLAUSE_CHAIN (c);
   17982         4790 :           continue;
   17983              : 
   17984          523 :         case OMP_CLAUSE_ORDER:
   17985          523 :           if (ordered_clause)
   17986              :             {
   17987            2 :               error_at (OMP_CLAUSE_LOCATION (c),
   17988              :                         "%<order%> clause must not be used together "
   17989              :                         "with %<ordered%> clause");
   17990            2 :               remove = true;
   17991            2 :               break;
   17992              :             }
   17993          521 :           else if (order_clause)
   17994              :             {
   17995              :               /* Silently remove duplicates.  */
   17996              :               remove = true;
   17997              :               break;
   17998              :             }
   17999          513 :           order_clause = pc;
   18000          513 :           pc = &OMP_CLAUSE_CHAIN (c);
   18001          513 :           continue;
   18002              : 
   18003           32 :         case OMP_CLAUSE_DETACH:
   18004           32 :           t = OMP_CLAUSE_DECL (c);
   18005           32 :           if (detach_seen)
   18006              :             {
   18007            1 :               error_at (OMP_CLAUSE_LOCATION (c),
   18008              :                         "too many %qs clauses on a task construct",
   18009              :                         "detach");
   18010            1 :               remove = true;
   18011            1 :               break;
   18012              :             }
   18013           31 :           detach_seen = pc;
   18014           31 :           pc = &OMP_CLAUSE_CHAIN (c);
   18015           31 :           c_mark_addressable (t);
   18016           31 :           continue;
   18017              : 
   18018        14565 :         case OMP_CLAUSE_IF:
   18019        14565 :         case OMP_CLAUSE_SELF:
   18020        14565 :         case OMP_CLAUSE_NUM_THREADS:
   18021        14565 :         case OMP_CLAUSE_NUM_TEAMS:
   18022        14565 :         case OMP_CLAUSE_THREAD_LIMIT:
   18023        14565 :         case OMP_CLAUSE_DEFAULT:
   18024        14565 :         case OMP_CLAUSE_UNTIED:
   18025        14565 :         case OMP_CLAUSE_COLLAPSE:
   18026        14565 :         case OMP_CLAUSE_FINAL:
   18027        14565 :         case OMP_CLAUSE_DEVICE:
   18028        14565 :         case OMP_CLAUSE_DIST_SCHEDULE:
   18029        14565 :         case OMP_CLAUSE_DYN_GROUPPRIVATE:
   18030        14565 :         case OMP_CLAUSE_PARALLEL:
   18031        14565 :         case OMP_CLAUSE_FOR:
   18032        14565 :         case OMP_CLAUSE_SECTIONS:
   18033        14565 :         case OMP_CLAUSE_TASKGROUP:
   18034        14565 :         case OMP_CLAUSE_PROC_BIND:
   18035        14565 :         case OMP_CLAUSE_DEVICE_TYPE:
   18036        14565 :         case OMP_CLAUSE_PRIORITY:
   18037        14565 :         case OMP_CLAUSE_THREADS:
   18038        14565 :         case OMP_CLAUSE_SIMD:
   18039        14565 :         case OMP_CLAUSE_HINT:
   18040        14565 :         case OMP_CLAUSE_FILTER:
   18041        14565 :         case OMP_CLAUSE_DEFAULTMAP:
   18042        14565 :         case OMP_CLAUSE_BIND:
   18043        14565 :         case OMP_CLAUSE_NUM_GANGS:
   18044        14565 :         case OMP_CLAUSE_NUM_WORKERS:
   18045        14565 :         case OMP_CLAUSE_VECTOR_LENGTH:
   18046        14565 :         case OMP_CLAUSE_ASYNC:
   18047        14565 :         case OMP_CLAUSE_WAIT:
   18048        14565 :         case OMP_CLAUSE_AUTO:
   18049        14565 :         case OMP_CLAUSE_INDEPENDENT:
   18050        14565 :         case OMP_CLAUSE_SEQ:
   18051        14565 :         case OMP_CLAUSE_GANG:
   18052        14565 :         case OMP_CLAUSE_WORKER:
   18053        14565 :         case OMP_CLAUSE_VECTOR:
   18054        14565 :         case OMP_CLAUSE_TILE:
   18055        14565 :         case OMP_CLAUSE_IF_PRESENT:
   18056        14565 :         case OMP_CLAUSE_FINALIZE:
   18057        14565 :         case OMP_CLAUSE_NOHOST:
   18058        14565 :         case OMP_CLAUSE_INDIRECT:
   18059        14565 :         case OMP_CLAUSE_NOVARIANTS:
   18060        14565 :         case OMP_CLAUSE_NOCONTEXT:
   18061        14565 :           pc = &OMP_CLAUSE_CHAIN (c);
   18062        14565 :           continue;
   18063              : 
   18064           62 :         case OMP_CLAUSE_GRAINSIZE:
   18065           62 :           grainsize_seen = pc;
   18066           62 :           pc = &OMP_CLAUSE_CHAIN (c);
   18067           62 :           continue;
   18068              : 
   18069           50 :         case OMP_CLAUSE_NUM_TASKS:
   18070           50 :           num_tasks_seen = true;
   18071           50 :           pc = &OMP_CLAUSE_CHAIN (c);
   18072           50 :           continue;
   18073              : 
   18074           79 :         case OMP_CLAUSE_MERGEABLE:
   18075           79 :           mergeable_seen = true;
   18076           79 :           pc = &OMP_CLAUSE_CHAIN (c);
   18077           79 :           continue;
   18078              : 
   18079           18 :         case OMP_CLAUSE_NOGROUP:
   18080           18 :           nogroup_seen = pc;
   18081           18 :           pc = &OMP_CLAUSE_CHAIN (c);
   18082           18 :           continue;
   18083              : 
   18084         3465 :         case OMP_CLAUSE_SCHEDULE:
   18085         3465 :           schedule_clause = c;
   18086         3465 :           pc = &OMP_CLAUSE_CHAIN (c);
   18087         3465 :           continue;
   18088              : 
   18089          304 :         case OMP_CLAUSE_ORDERED:
   18090          304 :           ordered_clause = c;
   18091          304 :           if (order_clause)
   18092              :             {
   18093            2 :               error_at (OMP_CLAUSE_LOCATION (*order_clause),
   18094              :                         "%<order%> clause must not be used together "
   18095              :                         "with %<ordered%> clause");
   18096            2 :               *order_clause = OMP_CLAUSE_CHAIN (*order_clause);
   18097            2 :               order_clause = NULL;
   18098              :             }
   18099          304 :           pc = &OMP_CLAUSE_CHAIN (c);
   18100          304 :           continue;
   18101              : 
   18102          223 :         case OMP_CLAUSE_SAFELEN:
   18103          223 :           safelen = c;
   18104          223 :           pc = &OMP_CLAUSE_CHAIN (c);
   18105          223 :           continue;
   18106          320 :         case OMP_CLAUSE_SIMDLEN:
   18107          320 :           simdlen = c;
   18108          320 :           pc = &OMP_CLAUSE_CHAIN (c);
   18109          320 :           continue;
   18110              : 
   18111           69 :         case OMP_CLAUSE_FULL:
   18112           69 :           full_seen = pc;
   18113           69 :           pc = &OMP_CLAUSE_CHAIN (c);
   18114           69 :           continue;
   18115              : 
   18116          223 :         case OMP_CLAUSE_PARTIAL:
   18117          223 :           partial_seen = true;
   18118          223 :           pc = &OMP_CLAUSE_CHAIN (c);
   18119          223 :           continue;
   18120              : 
   18121            0 :         case OMP_CLAUSE_SIZES:
   18122            0 :           pc = &OMP_CLAUSE_CHAIN (c);
   18123            0 :           continue;
   18124              : 
   18125          205 :         case OMP_CLAUSE_INBRANCH:
   18126          205 :         case OMP_CLAUSE_NOTINBRANCH:
   18127          205 :           if (branch_seen)
   18128              :             {
   18129            1 :               error_at (OMP_CLAUSE_LOCATION (c),
   18130              :                         "%<inbranch%> clause is incompatible with "
   18131              :                         "%<notinbranch%>");
   18132            1 :               remove = true;
   18133            1 :               break;
   18134              :             }
   18135          204 :           branch_seen = true;
   18136          204 :           pc = &OMP_CLAUSE_CHAIN (c);
   18137          204 :           continue;
   18138              : 
   18139          367 :         case OMP_CLAUSE_INCLUSIVE:
   18140          367 :         case OMP_CLAUSE_EXCLUSIVE:
   18141          367 :           need_complete = true;
   18142          367 :           need_implicitly_determined = true;
   18143          367 :           t = OMP_CLAUSE_DECL (c);
   18144          367 :           if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
   18145              :             {
   18146            0 :               error_at (OMP_CLAUSE_LOCATION (c),
   18147              :                         "%qE is not a variable in clause %qs", t,
   18148            0 :                         omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   18149            0 :               remove = true;
   18150              :             }
   18151              :           break;
   18152              : 
   18153          152 :         case OMP_CLAUSE_INIT:
   18154          152 :           init_seen = true;
   18155          152 :           if (!OMP_CLAUSE_INIT_TARGETSYNC (c))
   18156           71 :             init_no_targetsync_clause = c;
   18157              :           /* FALLTHRU */
   18158          242 :         case OMP_CLAUSE_DESTROY:
   18159          242 :         case OMP_CLAUSE_USE:
   18160          242 :           init_use_destroy_seen = true;
   18161          242 :           t = OMP_CLAUSE_DECL (c);
   18162          242 :           if (bitmap_bit_p (&generic_head, DECL_UID (t)))
   18163              :             {
   18164            3 :               error_at (OMP_CLAUSE_LOCATION (c),
   18165              :                         "%qD appears more than once in action clauses", t);
   18166            3 :               remove = true;
   18167            3 :               break;
   18168              :             }
   18169          239 :           bitmap_set_bit (&generic_head, DECL_UID (t));
   18170              :           /* FALLTHRU */
   18171          298 :         case OMP_CLAUSE_INTEROP:
   18172          298 :           if (/* ort == C_ORT_OMP_INTEROP [uncomment for depobj init]  */
   18173          298 :                    !c_omp_interop_t_p (TREE_TYPE (OMP_CLAUSE_DECL (c))))
   18174              :             {
   18175           40 :               error_at (OMP_CLAUSE_LOCATION (c),
   18176              :                         "%qD must be of %<omp_interop_t%>",
   18177           20 :                         OMP_CLAUSE_DECL (c));
   18178           20 :               remove = true;
   18179              :             }
   18180          278 :           else if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INIT
   18181          133 :                     || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DESTROY)
   18182          318 :                    && TREE_READONLY (OMP_CLAUSE_DECL (c)))
   18183              :             {
   18184           12 :               error_at (OMP_CLAUSE_LOCATION (c),
   18185            6 :                       "%qD shall not be const", OMP_CLAUSE_DECL (c));
   18186            6 :               remove = true;
   18187              :             }
   18188          298 :           pc = &OMP_CLAUSE_CHAIN (c);
   18189          298 :           break;
   18190            0 :         default:
   18191            0 :           gcc_unreachable ();
   18192        24934 :         }
   18193              : 
   18194        22780 :       if (!remove)
   18195              :         {
   18196        22195 :           t = OMP_CLAUSE_DECL (c);
   18197              : 
   18198        22195 :           if (need_complete)
   18199              :             {
   18200         3953 :               t = require_complete_type (OMP_CLAUSE_LOCATION (c), t);
   18201         3953 :               if (t == error_mark_node)
   18202            7 :                 remove = true;
   18203              :             }
   18204              : 
   18205        22195 :           if (need_implicitly_determined)
   18206              :             {
   18207         9552 :               const char *share_name = NULL;
   18208              : 
   18209         9552 :               if (VAR_P (t) && DECL_THREAD_LOCAL_P (t))
   18210              :                 share_name = "threadprivate";
   18211         9546 :               else switch (c_omp_predetermined_sharing (t))
   18212              :                 {
   18213              :                 case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
   18214              :                   break;
   18215           20 :                 case OMP_CLAUSE_DEFAULT_SHARED:
   18216           20 :                   if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
   18217           12 :                        || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE)
   18218           28 :                       && c_omp_predefined_variable (t))
   18219              :                     /* The __func__ variable and similar function-local
   18220              :                        predefined variables may be listed in a shared or
   18221              :                        firstprivate clause.  */
   18222              :                     break;
   18223              :                   share_name = "shared";
   18224              :                   break;
   18225              :                 case OMP_CLAUSE_DEFAULT_PRIVATE:
   18226              :                   share_name = "private";
   18227              :                   break;
   18228            0 :                 default:
   18229            0 :                   gcc_unreachable ();
   18230              :                 }
   18231              :               if (share_name)
   18232              :                 {
   18233           20 :                   error_at (OMP_CLAUSE_LOCATION (c),
   18234              :                             "%qE is predetermined %qs for %qs",
   18235              :                             t, share_name,
   18236           10 :                             omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
   18237           10 :                   remove = true;
   18238              :                 }
   18239         9542 :               else if (TREE_READONLY (t)
   18240           23 :                        && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED
   18241         9555 :                        && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE)
   18242              :                 {
   18243            4 :                   error_at (OMP_CLAUSE_LOCATION (c),
   18244              :                             "%<const%> qualified %qE may appear only in "
   18245              :                             "%<shared%> or %<firstprivate%> clauses", t);
   18246            4 :                   remove = true;
   18247              :                 }
   18248              :             }
   18249              :         }
   18250              : 
   18251        22195 :       if (remove)
   18252              :         {
   18253          606 :           if (grp_start_p)
   18254              :             {
   18255              :               /* If we found a clause to remove, we want to remove the whole
   18256              :                  expanded group, otherwise gimplify
   18257              :                  (omp_resolve_clause_dependencies) can get confused.  */
   18258          154 :               *grp_start_p = grp_sentinel;
   18259          154 :               pc = grp_start_p;
   18260          154 :               grp_start_p = NULL;
   18261              :             }
   18262              :           else
   18263          452 :             *pc = OMP_CLAUSE_CHAIN (c);
   18264              :         }
   18265              :       else
   18266        22174 :         pc = &OMP_CLAUSE_CHAIN (c);
   18267              :     }
   18268              : 
   18269        29445 :   if (grp_start_p
   18270        29445 :       && OMP_CLAUSE_HAS_ITERATORS (*grp_start_p))
   18271           49 :     for (tree gc = *grp_start_p; gc; gc = OMP_CLAUSE_CHAIN (gc))
   18272           30 :       OMP_CLAUSE_ITERATORS (gc) = OMP_CLAUSE_ITERATORS (*grp_start_p);
   18273              : 
   18274        29445 :   if (simdlen
   18275        29445 :       && safelen
   18276        29562 :       && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen),
   18277          117 :                           OMP_CLAUSE_SIMDLEN_EXPR (simdlen)))
   18278              :     {
   18279            0 :       error_at (OMP_CLAUSE_LOCATION (simdlen),
   18280              :                 "%<simdlen%> clause value is bigger than "
   18281              :                 "%<safelen%> clause value");
   18282            0 :       OMP_CLAUSE_SIMDLEN_EXPR (simdlen)
   18283            0 :         = OMP_CLAUSE_SAFELEN_EXPR (safelen);
   18284              :     }
   18285              : 
   18286        29445 :   if (ordered_clause
   18287        29445 :       && schedule_clause
   18288        29445 :       && (OMP_CLAUSE_SCHEDULE_KIND (schedule_clause)
   18289              :           & OMP_CLAUSE_SCHEDULE_NONMONOTONIC))
   18290              :     {
   18291            7 :       error_at (OMP_CLAUSE_LOCATION (schedule_clause),
   18292              :                 "%<nonmonotonic%> schedule modifier specified together "
   18293              :                 "with %<ordered%> clause");
   18294           14 :       OMP_CLAUSE_SCHEDULE_KIND (schedule_clause)
   18295            7 :         = (enum omp_clause_schedule_kind)
   18296            7 :           (OMP_CLAUSE_SCHEDULE_KIND (schedule_clause)
   18297              :            & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC);
   18298              :     }
   18299              : 
   18300        29445 :   if (reduction_seen < 0 && ordered_clause)
   18301              :     {
   18302            2 :       error_at (OMP_CLAUSE_LOCATION (ordered_clause),
   18303              :                 "%qs clause specified together with %<inscan%> "
   18304              :                 "%<reduction%> clause", "ordered");
   18305            2 :       reduction_seen = -2;
   18306              :     }
   18307              : 
   18308        29445 :   if (reduction_seen < 0 && schedule_clause)
   18309              :     {
   18310            3 :       error_at (OMP_CLAUSE_LOCATION (schedule_clause),
   18311              :                 "%qs clause specified together with %<inscan%> "
   18312              :                 "%<reduction%> clause", "schedule");
   18313            3 :       reduction_seen = -2;
   18314              :     }
   18315              : 
   18316        29445 :   if (linear_variable_step_check
   18317        29445 :       || reduction_seen == -2
   18318              :       || allocate_seen
   18319        29433 :       || target_in_reduction_seen)
   18320         5190 :     for (pc = &clauses, c = clauses; c ; c = *pc)
   18321              :       {
   18322         4589 :         bool remove = false;
   18323         4589 :         if (allocate_seen)
   18324         4431 :           switch (OMP_CLAUSE_CODE (c))
   18325              :             {
   18326          430 :             case OMP_CLAUSE_REDUCTION:
   18327          430 :             case OMP_CLAUSE_IN_REDUCTION:
   18328          430 :             case OMP_CLAUSE_TASK_REDUCTION:
   18329          430 :               if (TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF)
   18330              :                 {
   18331           23 :                   t = TREE_OPERAND (OMP_CLAUSE_DECL (c), 0);
   18332           23 :                   if (TREE_CODE (t) == POINTER_PLUS_EXPR)
   18333            0 :                     t = TREE_OPERAND (t, 0);
   18334           23 :                   if (TREE_CODE (t) == ADDR_EXPR
   18335           10 :                       || INDIRECT_REF_P (t))
   18336           13 :                     t = TREE_OPERAND (t, 0);
   18337           23 :                   if (DECL_P (t))
   18338           23 :                     bitmap_clear_bit (&aligned_head, DECL_UID (t));
   18339              :                   break;
   18340              :                 }
   18341              :               /* FALLTHRU */
   18342         1318 :             case OMP_CLAUSE_PRIVATE:
   18343         1318 :             case OMP_CLAUSE_FIRSTPRIVATE:
   18344         1318 :             case OMP_CLAUSE_LASTPRIVATE:
   18345         1318 :             case OMP_CLAUSE_LINEAR:
   18346         1318 :               if (DECL_P (OMP_CLAUSE_DECL (c)))
   18347         2636 :                 bitmap_clear_bit (&aligned_head,
   18348         1318 :                                   DECL_UID (OMP_CLAUSE_DECL (c)));
   18349              :               break;
   18350              :             default:
   18351              :               break;
   18352              :             }
   18353         4589 :         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
   18354           29 :             && OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c)
   18355         4596 :             && !bitmap_bit_p (&map_head,
   18356            7 :                               DECL_UID (OMP_CLAUSE_LINEAR_STEP (c))))
   18357              :           {
   18358            2 :             error_at (OMP_CLAUSE_LOCATION (c),
   18359              :                       "%<linear%> clause step is a parameter %qD not "
   18360              :                       "specified in %<uniform%> clause",
   18361            2 :                       OMP_CLAUSE_LINEAR_STEP (c));
   18362            2 :             remove = true;
   18363              :           }
   18364         4587 :         else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
   18365         4587 :                  && reduction_seen == -2)
   18366            9 :           OMP_CLAUSE_REDUCTION_INSCAN (c) = 0;
   18367         4589 :         if (target_in_reduction_seen
   18368         4589 :             && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP)
   18369              :           {
   18370          256 :             tree t = OMP_CLAUSE_DECL (c);
   18371          256 :             while (handled_component_p (t)
   18372              :                    || INDIRECT_REF_P (t)
   18373              :                    || TREE_CODE (t) == ADDR_EXPR
   18374              :                    || TREE_CODE (t) == MEM_REF
   18375          288 :                    || TREE_CODE (t) == NON_LVALUE_EXPR)
   18376           32 :               t = TREE_OPERAND (t, 0);
   18377          256 :             if (DECL_P (t)
   18378          256 :                 && bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
   18379          138 :               OMP_CLAUSE_MAP_IN_REDUCTION (c) = 1;
   18380              :           }
   18381              : 
   18382         4589 :         if (remove)
   18383            2 :           *pc = OMP_CLAUSE_CHAIN (c);
   18384              :         else
   18385         4587 :           pc = &OMP_CLAUSE_CHAIN (c);
   18386              :       }
   18387              : 
   18388          601 :   if (allocate_seen)
   18389         5006 :     for (pc = &clauses, c = clauses; c ; c = *pc)
   18390              :       {
   18391         4431 :         bool remove = false;
   18392         4431 :         if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ALLOCATE
   18393          720 :             && !OMP_CLAUSE_ALLOCATE_COMBINED (c)
   18394         5131 :             && bitmap_bit_p (&aligned_head, DECL_UID (OMP_CLAUSE_DECL (c))))
   18395              :           {
   18396            3 :             error_at (OMP_CLAUSE_LOCATION (c),
   18397              :                       "%qD specified in %<allocate%> clause but not in "
   18398            3 :                       "an explicit privatization clause", OMP_CLAUSE_DECL (c));
   18399            3 :             remove = true;
   18400              :           }
   18401         4431 :         if (remove)
   18402            3 :           *pc = OMP_CLAUSE_CHAIN (c);
   18403              :         else
   18404         4428 :           pc = &OMP_CLAUSE_CHAIN (c);
   18405              :       }
   18406              : 
   18407        29445 :   if (nogroup_seen && reduction_seen)
   18408              :     {
   18409            1 :       error_at (OMP_CLAUSE_LOCATION (*nogroup_seen),
   18410              :                 "%<nogroup%> clause must not be used together with "
   18411              :                 "%<reduction%> clause");
   18412            1 :       *nogroup_seen = OMP_CLAUSE_CHAIN (*nogroup_seen);
   18413              :     }
   18414              : 
   18415        29445 :   if (grainsize_seen && num_tasks_seen)
   18416              :     {
   18417            2 :       error_at (OMP_CLAUSE_LOCATION (*grainsize_seen),
   18418              :                 "%<grainsize%> clause must not be used together with "
   18419              :                 "%<num_tasks%> clause");
   18420            2 :       *grainsize_seen = OMP_CLAUSE_CHAIN (*grainsize_seen);
   18421              :     }
   18422              : 
   18423        29445 :   if (full_seen && partial_seen)
   18424              :     {
   18425            4 :       error_at (OMP_CLAUSE_LOCATION (*full_seen),
   18426              :                 "%<full%> clause must not be used together with "
   18427              :                 "%<partial%> clause");
   18428            4 :       *full_seen = OMP_CLAUSE_CHAIN (*full_seen);
   18429              :     }
   18430              : 
   18431        29445 :   if (detach_seen)
   18432              :     {
   18433           31 :       if (mergeable_seen)
   18434              :         {
   18435            2 :           error_at (OMP_CLAUSE_LOCATION (*detach_seen),
   18436              :                     "%<detach%> clause must not be used together with "
   18437              :                     "%<mergeable%> clause");
   18438            2 :           *detach_seen = OMP_CLAUSE_CHAIN (*detach_seen);
   18439              :         }
   18440              :       else
   18441              :         {
   18442           29 :           tree detach_decl = OMP_CLAUSE_DECL (*detach_seen);
   18443              : 
   18444           79 :           for (pc = &clauses, c = clauses; c ; c = *pc)
   18445              :             {
   18446           50 :               bool remove = false;
   18447           50 :               if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
   18448           48 :                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
   18449           48 :                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
   18450           44 :                    || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE)
   18451           54 :                   && OMP_CLAUSE_DECL (c) == detach_decl)
   18452              :                 {
   18453            2 :                   error_at (OMP_CLAUSE_LOCATION (c),
   18454              :                             "the event handle of a %<detach%> clause "
   18455              :                             "should not be in a data-sharing clause");
   18456            2 :                   remove = true;
   18457              :                 }
   18458           50 :               if (remove)
   18459            2 :                 *pc = OMP_CLAUSE_CHAIN (c);
   18460              :               else
   18461           48 :                 pc = &OMP_CLAUSE_CHAIN (c);
   18462              :             }
   18463              :         }
   18464              :     }
   18465              : 
   18466        29445 :   if (ort == C_ORT_OMP_INTEROP
   18467        29445 :       && depend_clause
   18468           21 :       && (!init_use_destroy_seen
   18469           20 :           || (init_seen && init_no_targetsync_clause)))
   18470              :     {
   18471            3 :       error_at (OMP_CLAUSE_LOCATION (depend_clause),
   18472              :                 "%<depend%> clause requires action clauses with "
   18473              :                 "%<targetsync%> interop-type");
   18474            3 :       if (init_no_targetsync_clause)
   18475            2 :         inform (OMP_CLAUSE_LOCATION (init_no_targetsync_clause),
   18476              :                 "%<init%> clause lacks the %<targetsync%> modifier");
   18477              :     }
   18478              : 
   18479        29445 :   bitmap_obstack_release (NULL);
   18480        29445 :   return clauses;
   18481              : }
   18482              : 
   18483              : /* Do processing necessary to make CLAUSES well-formed, where CLAUSES result
   18484              :    from implicit instantiation of user-defined mappers (in gimplify.cc).  */
   18485              : 
   18486              : tree
   18487           13 : c_omp_finish_mapper_clauses (tree clauses)
   18488              : {
   18489           13 :   return c_finish_omp_clauses (clauses, C_ORT_OMP);
   18490              : }
   18491              : 
   18492              : /* Return code to initialize DST with a copy constructor from SRC.
   18493              :    C doesn't have copy constructors nor assignment operators, only for
   18494              :    _Atomic vars we need to perform __atomic_load from src into a temporary
   18495              :    followed by __atomic_store of the temporary to dst.  */
   18496              : 
   18497              : tree
   18498        18735 : c_omp_clause_copy_ctor (tree clause, tree dst, tree src)
   18499              : {
   18500        18735 :   if (!really_atomic_lvalue (dst) && !really_atomic_lvalue (src))
   18501        18731 :     return build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src);
   18502              : 
   18503            4 :   location_t loc = OMP_CLAUSE_LOCATION (clause);
   18504            4 :   tree type = TREE_TYPE (dst);
   18505            4 :   tree nonatomic_type = build_qualified_type (type, TYPE_UNQUALIFIED);
   18506            4 :   tree tmp = create_tmp_var (nonatomic_type);
   18507            4 :   tree tmp_addr = build_fold_addr_expr (tmp);
   18508            4 :   TREE_ADDRESSABLE (tmp) = 1;
   18509            4 :   suppress_warning (tmp);
   18510            4 :   tree src_addr = build_fold_addr_expr (src);
   18511            4 :   tree dst_addr = build_fold_addr_expr (dst);
   18512            4 :   tree seq_cst = build_int_cst (integer_type_node, MEMMODEL_SEQ_CST);
   18513            4 :   vec<tree, va_gc> *params;
   18514              :   /* Expansion of a generic atomic load may require an addition
   18515              :      element, so allocate enough to prevent a resize.  */
   18516            4 :   vec_alloc (params, 4);
   18517              : 
   18518              :   /* Build __atomic_load (&src, &tmp, SEQ_CST);  */
   18519            4 :   tree fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_LOAD);
   18520            4 :   params->quick_push (src_addr);
   18521            4 :   params->quick_push (tmp_addr);
   18522            4 :   params->quick_push (seq_cst);
   18523            4 :   tree load = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
   18524              : 
   18525            4 :   vec_alloc (params, 4);
   18526              : 
   18527              :   /* Build __atomic_store (&dst, &tmp, SEQ_CST);  */
   18528            4 :   fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_STORE);
   18529            4 :   params->quick_push (dst_addr);
   18530            4 :   params->quick_push (tmp_addr);
   18531            4 :   params->quick_push (seq_cst);
   18532            4 :   tree store = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
   18533            4 :   return build2 (COMPOUND_EXPR, void_type_node, load, store);
   18534              : }
   18535              : 
   18536              : /* Create a transaction node.  */
   18537              : 
   18538              : tree
   18539          135 : c_finish_transaction (location_t loc, tree block, int flags)
   18540              : {
   18541          135 :   tree stmt = build_stmt (loc, TRANSACTION_EXPR, block);
   18542          135 :   if (flags & TM_STMT_ATTR_OUTER)
   18543           10 :     TRANSACTION_EXPR_OUTER (stmt) = 1;
   18544          135 :   if (flags & TM_STMT_ATTR_RELAXED)
   18545           31 :     TRANSACTION_EXPR_RELAXED (stmt) = 1;
   18546          135 :   return add_stmt (stmt);
   18547              : }
   18548              : 
   18549              : /* Make a variant type in the proper way for C/C++, propagating qualifiers
   18550              :    down to the element type of an array.  If ORIG_QUAL_TYPE is not
   18551              :    NULL, then it should be used as the qualified type
   18552              :    ORIG_QUAL_INDIRECT levels down in array type derivation (to
   18553              :    preserve information about the typedef name from which an array
   18554              :    type was derived).  */
   18555              : 
   18556              : tree
   18557     74451931 : c_build_qualified_type (tree type, int type_quals, tree orig_qual_type,
   18558              :                         size_t orig_qual_indirect)
   18559              : {
   18560     74451931 :   if (type == error_mark_node)
   18561              :     return type;
   18562              : 
   18563     74451779 :   if (TREE_CODE (type) == ARRAY_TYPE)
   18564              :     {
   18565      3161301 :       tree t;
   18566      3161301 :       tree element_type = c_build_qualified_type (TREE_TYPE (type),
   18567              :                                                   type_quals, orig_qual_type,
   18568              :                                                   orig_qual_indirect - 1);
   18569              : 
   18570              :       /* See if we already have an identically qualified type.  */
   18571      3161301 :       if (orig_qual_type && orig_qual_indirect == 0)
   18572              :         t = orig_qual_type;
   18573              :       else
   18574      4603795 :         for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
   18575              :           {
   18576      4464131 :             if (TYPE_QUALS (strip_array_types (t)) == type_quals
   18577      3042499 :                 && TYPE_NAME (t) == TYPE_NAME (type)
   18578      3021596 :                 && TYPE_CONTEXT (t) == TYPE_CONTEXT (type)
   18579      7485727 :                 && attribute_list_equal (TYPE_ATTRIBUTES (t),
   18580      3021596 :                                          TYPE_ATTRIBUTES (type)))
   18581              :               break;
   18582              :           }
   18583      3161260 :       if (!t)
   18584              :         {
   18585       139664 :           tree domain = TYPE_DOMAIN (type);
   18586              : 
   18587       139664 :           t = build_variant_type_copy (type);
   18588       139664 :           TREE_TYPE (t) = element_type;
   18589       139664 :           TYPE_ADDR_SPACE (t) = TYPE_ADDR_SPACE (element_type);
   18590              : 
   18591       139664 :           if (TYPE_STRUCTURAL_EQUALITY_P (element_type)
   18592       139664 :               || (domain && TYPE_STRUCTURAL_EQUALITY_P (domain)))
   18593          196 :             SET_TYPE_STRUCTURAL_EQUALITY (t);
   18594       139468 :           else if (TYPE_CANONICAL (element_type) != element_type
   18595       139468 :                    || (domain && TYPE_CANONICAL (domain) != domain))
   18596              :             {
   18597         2718 :               tree unqualified_canon
   18598         5218 :                 = c_build_array_type (TYPE_CANONICAL (element_type),
   18599         2500 :                                       domain ? TYPE_CANONICAL (domain)
   18600              :                                              : NULL_TREE);
   18601         2718 :               if (TYPE_REVERSE_STORAGE_ORDER (type))
   18602              :                 {
   18603            0 :                   unqualified_canon
   18604            0 :                     = build_distinct_type_copy (unqualified_canon);
   18605            0 :                   TYPE_REVERSE_STORAGE_ORDER (unqualified_canon) = 1;
   18606              :                 }
   18607         2718 :               TYPE_CANONICAL (t)
   18608         5436 :                 = c_build_qualified_type (unqualified_canon, type_quals);
   18609              :             }
   18610              :           else
   18611       136750 :             TYPE_CANONICAL (t) = t;
   18612              :         }
   18613      3161301 :       return t;
   18614              :     }
   18615              : 
   18616              :   /* A restrict-qualified pointer type must be a pointer to object or
   18617              :      incomplete type.  Note that the use of POINTER_TYPE_P also allows
   18618              :      REFERENCE_TYPEs, which is appropriate for C++.  */
   18619     71290478 :   if ((type_quals & TYPE_QUAL_RESTRICT)
   18620     71290478 :       && (!POINTER_TYPE_P (type)
   18621      3376208 :           || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type))))
   18622              :     {
   18623            3 :       error ("invalid use of %<restrict%>");
   18624            3 :       type_quals &= ~TYPE_QUAL_RESTRICT;
   18625              :     }
   18626              : 
   18627     71290478 :   tree var_type = (orig_qual_type && orig_qual_indirect == 0
   18628     71290478 :                    ? orig_qual_type
   18629     71290447 :                    : build_qualified_type (type, type_quals));
   18630              : 
   18631     71290478 :   gcc_checking_assert (C_TYPE_VARIABLE_SIZE (var_type)
   18632              :                        == C_TYPE_VARIABLE_SIZE (type));
   18633     71290478 :   gcc_checking_assert (C_TYPE_VARIABLY_MODIFIED (var_type)
   18634              :                        == C_TYPE_VARIABLY_MODIFIED (type));
   18635              : 
   18636              :   /* A variant type does not inherit the list of incomplete vars from the
   18637              :      type main variant.  */
   18638     71290478 :   if ((RECORD_OR_UNION_TYPE_P (var_type)
   18639     69369900 :        || TREE_CODE (var_type) == ENUMERAL_TYPE)
   18640     71395782 :       && TYPE_MAIN_VARIANT (var_type) != var_type)
   18641      1412385 :     C_TYPE_INCOMPLETE_VARS (var_type) = 0;
   18642              :   return var_type;
   18643              : }
   18644              : 
   18645              : /* Build a VA_ARG_EXPR for the C parser.  */
   18646              : 
   18647              : tree
   18648        19884 : c_build_va_arg (location_t loc1, tree expr, location_t loc2, tree type,
   18649              :                 tree type_expr)
   18650              : {
   18651        19884 :   if (error_operand_p (type))
   18652            2 :     return error_mark_node;
   18653              :   /* VA_ARG_EXPR cannot be used for a scalar va_list with reverse storage
   18654              :      order because it takes the address of the expression.  */
   18655        19882 :   else if (handled_component_p (expr)
   18656           31 :            && reverse_storage_order_for_component_p (expr))
   18657              :     {
   18658            0 :       error_at (loc1, "cannot use %<va_arg%> with reverse storage order");
   18659            0 :       return error_mark_node;
   18660              :     }
   18661        19882 :   else if (!COMPLETE_TYPE_P (type))
   18662              :     {
   18663           11 :       error_at (loc2, "second argument to %<va_arg%> is of incomplete "
   18664              :                 "type %qT", type);
   18665           11 :       return error_mark_node;
   18666              :     }
   18667        19871 :   else if (TREE_CODE (type) == FUNCTION_TYPE)
   18668              :     {
   18669            1 :       error_at (loc2, "second argument to %<va_arg%> is a function type %qT",
   18670              :                 type);
   18671            1 :       return error_mark_node;
   18672              :     }
   18673            6 :   else if (TREE_CODE (type) == ARRAY_TYPE && C_TYPE_VARIABLE_SIZE (type)
   18674        19873 :            && !flag_isoc99)
   18675              :     {
   18676            1 :       error_at (loc2, "second argument to %<va_arg%> is an array type %qT",
   18677              :                 type);
   18678            1 :       return error_mark_node;
   18679              :     }
   18680        19869 :   else if (warn_cxx_compat && TREE_CODE (type) == ENUMERAL_TYPE)
   18681            1 :     warning_at (loc2, OPT_Wc___compat,
   18682              :                 "C++ requires promoted type, not enum type, in %<va_arg%>");
   18683              : 
   18684        19869 :   if (flag_isoc99 && TREE_CODE (type) == ARRAY_TYPE)
   18685              :     {
   18686            3 :       warning_at (loc2, 0, "second argument to %<va_arg%> is an array type %qT",
   18687              :                   type);
   18688              :       /* We create a trap but evaluate side effects first.  */
   18689            3 :       tree trapfn = builtin_decl_explicit (BUILT_IN_TRAP);
   18690            3 :       trapfn = build_call_expr_loc (loc2, trapfn, 0);
   18691            3 :       tree e2 = build2 (COMPOUND_EXPR, void_type_node, expr, trapfn);
   18692              :       /* Return a compound literal of the right type.  */
   18693            3 :       tree e1 = build_compound_literal (loc2, type, NULL, true, 0, NULL);
   18694            3 :       expr = build2 (COMPOUND_EXPR, type, e2, e1);
   18695            3 :     }
   18696              :   else
   18697        19866 :     expr = build_va_arg (loc2, expr, type);
   18698              : 
   18699        19869 :   if (type_expr)
   18700           26 :     expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr), type_expr, expr);
   18701              : 
   18702              :   return expr;
   18703              : }
   18704              : 
   18705              : /* Return truthvalue of whether T1 is the same tree structure as T2.
   18706              :    Return 1 if they are the same. Return false if they are different.  */
   18707              : 
   18708              : bool
   18709         1854 : c_tree_equal (tree t1, tree t2)
   18710              : {
   18711         1883 :   enum tree_code code1, code2;
   18712              : 
   18713         1883 :   if (t1 == t2)
   18714              :     return true;
   18715          661 :   if (!t1 || !t2)
   18716              :     return false;
   18717              : 
   18718          681 :   for (code1 = TREE_CODE (t1); code1 == NON_LVALUE_EXPR;
   18719           20 :        code1 = TREE_CODE (t1))
   18720           20 :     t1 = TREE_OPERAND (t1, 0);
   18721          682 :   for (code2 = TREE_CODE (t2); code2 == NON_LVALUE_EXPR;
   18722           21 :        code2 = TREE_CODE (t2))
   18723           21 :     t2 = TREE_OPERAND (t2, 0);
   18724              : 
   18725              :   /* They might have become equal now.  */
   18726          661 :   if (t1 == t2)
   18727              :     return true;
   18728              : 
   18729          640 :   if (code1 != code2)
   18730              :     return false;
   18731              : 
   18732          379 :   if (CONSTANT_CLASS_P (t1) && !comptypes (TREE_TYPE (t1), TREE_TYPE (t2)))
   18733              :     return false;
   18734              : 
   18735          379 :   switch (code1)
   18736              :     {
   18737            2 :     case INTEGER_CST:
   18738            2 :       return wi::to_wide (t1) == wi::to_wide (t2);
   18739              : 
   18740           10 :     case REAL_CST:
   18741           10 :       return real_equal (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
   18742              : 
   18743            0 :     case STRING_CST:
   18744            0 :       return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
   18745            0 :         && !memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
   18746            0 :                     TREE_STRING_LENGTH (t1));
   18747              : 
   18748            0 :     case FIXED_CST:
   18749            0 :       return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1),
   18750              :                                      TREE_FIXED_CST (t2));
   18751              : 
   18752            0 :     case COMPLEX_CST:
   18753            0 :       return c_tree_equal (TREE_REALPART (t1), TREE_REALPART (t2))
   18754            0 :              && c_tree_equal (TREE_IMAGPART (t1), TREE_IMAGPART (t2));
   18755              : 
   18756            0 :     case VECTOR_CST:
   18757            0 :       return operand_equal_p (t1, t2, OEP_ONLY_CONST);
   18758              : 
   18759            0 :     case CONSTRUCTOR:
   18760              :       /* We need to do this when determining whether or not two
   18761              :          non-type pointer to member function template arguments
   18762              :          are the same.  */
   18763            0 :       if (!comptypes (TREE_TYPE (t1), TREE_TYPE (t2))
   18764            0 :           || CONSTRUCTOR_NELTS (t1) != CONSTRUCTOR_NELTS (t2))
   18765              :         return false;
   18766              :       {
   18767              :         tree field, value;
   18768              :         unsigned int i;
   18769            0 :         FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t1), i, field, value)
   18770              :           {
   18771            0 :             constructor_elt *elt2 = CONSTRUCTOR_ELT (t2, i);
   18772            0 :             if (!c_tree_equal (field, elt2->index)
   18773            0 :                 || !c_tree_equal (value, elt2->value))
   18774            0 :               return false;
   18775              :           }
   18776              :       }
   18777              :       return true;
   18778              : 
   18779            0 :     case TREE_LIST:
   18780            0 :       if (!c_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)))
   18781              :         return false;
   18782            0 :       if (!c_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2)))
   18783              :         return false;
   18784            0 :       return c_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2));
   18785              : 
   18786            0 :     case SAVE_EXPR:
   18787            0 :       return c_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
   18788              : 
   18789           25 :     case CALL_EXPR:
   18790           25 :       {
   18791           25 :         tree arg1, arg2;
   18792           25 :         call_expr_arg_iterator iter1, iter2;
   18793           25 :         if (!c_tree_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2)))
   18794              :           return false;
   18795           50 :         for (arg1 = first_call_expr_arg (t1, &iter1),
   18796           25 :                arg2 = first_call_expr_arg (t2, &iter2);
   18797           25 :              arg1 && arg2;
   18798            0 :              arg1 = next_call_expr_arg (&iter1),
   18799            0 :                arg2 = next_call_expr_arg (&iter2))
   18800            0 :           if (!c_tree_equal (arg1, arg2))
   18801              :             return false;
   18802           25 :         if (arg1 || arg2)
   18803              :           return false;
   18804              :         return true;
   18805              :       }
   18806              : 
   18807            0 :     case TARGET_EXPR:
   18808            0 :       {
   18809            0 :         tree o1 = TREE_OPERAND (t1, 0);
   18810            0 :         tree o2 = TREE_OPERAND (t2, 0);
   18811              : 
   18812              :         /* Special case: if either target is an unallocated VAR_DECL,
   18813              :            it means that it's going to be unified with whatever the
   18814              :            TARGET_EXPR is really supposed to initialize, so treat it
   18815              :            as being equivalent to anything.  */
   18816            0 :         if (VAR_P (o1) && DECL_NAME (o1) == NULL_TREE
   18817            0 :             && !DECL_RTL_SET_P (o1))
   18818              :           /*Nop*/;
   18819            0 :         else if (VAR_P (o2) && DECL_NAME (o2) == NULL_TREE
   18820            0 :                  && !DECL_RTL_SET_P (o2))
   18821              :           /*Nop*/;
   18822            0 :         else if (!c_tree_equal (o1, o2))
   18823              :           return false;
   18824              : 
   18825            0 :         return c_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
   18826              :       }
   18827              : 
   18828           29 :     case COMPONENT_REF:
   18829           29 :       if (TREE_OPERAND (t1, 1) != TREE_OPERAND (t2, 1))
   18830              :         return false;
   18831           29 :       return c_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
   18832              : 
   18833              :     case PARM_DECL:
   18834              :     case VAR_DECL:
   18835              :     case CONST_DECL:
   18836              :     case FIELD_DECL:
   18837              :     case FUNCTION_DECL:
   18838              :     case IDENTIFIER_NODE:
   18839              :     case SSA_NAME:
   18840              :       return false;
   18841              : 
   18842            0 :     case TREE_VEC:
   18843            0 :       {
   18844            0 :         unsigned ix;
   18845            0 :         if (TREE_VEC_LENGTH (t1) != TREE_VEC_LENGTH (t2))
   18846              :           return false;
   18847            0 :         for (ix = TREE_VEC_LENGTH (t1); ix--;)
   18848            0 :           if (!c_tree_equal (TREE_VEC_ELT (t1, ix),
   18849            0 :                              TREE_VEC_ELT (t2, ix)))
   18850              :             return false;
   18851              :         return true;
   18852              :       }
   18853              : 
   18854           22 :     CASE_CONVERT:
   18855           22 :       if (!comptypes (TREE_TYPE (t1), TREE_TYPE (t2)))
   18856              :         return false;
   18857              :       break;
   18858              : 
   18859              :     default:
   18860              :       break;
   18861              :     }
   18862              : 
   18863          131 :   switch (TREE_CODE_CLASS (code1))
   18864              :     {
   18865          131 :     case tcc_unary:
   18866          131 :     case tcc_binary:
   18867          131 :     case tcc_comparison:
   18868          131 :     case tcc_expression:
   18869          131 :     case tcc_vl_exp:
   18870          131 :     case tcc_reference:
   18871          131 :     case tcc_statement:
   18872          131 :       {
   18873          131 :         int i, n = TREE_OPERAND_LENGTH (t1);
   18874              : 
   18875          131 :         switch (code1)
   18876              :           {
   18877            0 :           case PREINCREMENT_EXPR:
   18878            0 :           case PREDECREMENT_EXPR:
   18879            0 :           case POSTINCREMENT_EXPR:
   18880            0 :           case POSTDECREMENT_EXPR:
   18881            0 :             n = 1;
   18882            0 :             break;
   18883           16 :           case ARRAY_REF:
   18884           16 :             n = 2;
   18885           16 :             break;
   18886              :           default:
   18887              :             break;
   18888              :           }
   18889              : 
   18890          131 :         if (TREE_CODE_CLASS (code1) == tcc_vl_exp
   18891          131 :             && n != TREE_OPERAND_LENGTH (t2))
   18892              :           return false;
   18893              : 
   18894          305 :         for (i = 0; i < n; ++i)
   18895          186 :           if (!c_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i)))
   18896              :             return false;
   18897              : 
   18898              :         return true;
   18899              :       }
   18900              : 
   18901            0 :     case tcc_type:
   18902            0 :       return comptypes (t1, t2);
   18903            0 :     default:
   18904            0 :       gcc_unreachable ();
   18905              :     }
   18906              : }
   18907              : 
   18908              : /* Returns true when the function declaration FNDECL is implicit,
   18909              :    introduced as a result of a call to an otherwise undeclared
   18910              :    function, and false otherwise.  */
   18911              : 
   18912              : bool
   18913         2013 : c_decl_implicit (const_tree fndecl)
   18914              : {
   18915         2013 :   return C_DECL_IMPLICIT (fndecl);
   18916              : }
        

Generated by: LCOV version 2.4-beta

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