LCOV - code coverage report
Current view: top level - gcc/c - c-typeck.c (source / functions) Hit Total Coverage
Test: gcc.info Lines: 6717 7469 89.9 %
Date: 2020-03-28 11:57:23 Functions: 151 157 96.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* Build expressions with type checking for C compiler.
       2                 :            :    Copyright (C) 1987-2020 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 "gcc-rich-location.h"
      52                 :            : #include "stringpool.h"
      53                 :            : #include "attribs.h"
      54                 :            : #include "asan.h"
      55                 :            : 
      56                 :            : /* Possible cases of implicit bad conversions.  Used to select
      57                 :            :    diagnostic messages in convert_for_assignment.  */
      58                 :            : enum impl_conv {
      59                 :            :   ic_argpass,
      60                 :            :   ic_assign,
      61                 :            :   ic_init,
      62                 :            :   ic_return
      63                 :            : };
      64                 :            : 
      65                 :            : /* The level of nesting inside "__alignof__".  */
      66                 :            : int in_alignof;
      67                 :            : 
      68                 :            : /* The level of nesting inside "sizeof".  */
      69                 :            : int in_sizeof;
      70                 :            : 
      71                 :            : /* The level of nesting inside "typeof".  */
      72                 :            : int in_typeof;
      73                 :            : 
      74                 :            : /* The argument of last parsed sizeof expression, only to be tested
      75                 :            :    if expr.original_code == SIZEOF_EXPR.  */
      76                 :            : tree c_last_sizeof_arg;
      77                 :            : location_t c_last_sizeof_loc;
      78                 :            : 
      79                 :            : /* Nonzero if we might need to print a "missing braces around
      80                 :            :    initializer" message within this initializer.  */
      81                 :            : static int found_missing_braces;
      82                 :            : 
      83                 :            : static int require_constant_value;
      84                 :            : static int require_constant_elements;
      85                 :            : 
      86                 :            : static bool null_pointer_constant_p (const_tree);
      87                 :            : static tree qualify_type (tree, tree);
      88                 :            : static int tagged_types_tu_compatible_p (const_tree, const_tree, bool *,
      89                 :            :                                          bool *);
      90                 :            : static int comp_target_types (location_t, tree, tree);
      91                 :            : static int function_types_compatible_p (const_tree, const_tree, bool *,
      92                 :            :                                         bool *);
      93                 :            : static int type_lists_compatible_p (const_tree, const_tree, bool *, bool *);
      94                 :            : static tree lookup_field (tree, tree);
      95                 :            : static int convert_arguments (location_t, vec<location_t>, tree,
      96                 :            :                               vec<tree, va_gc> *, vec<tree, va_gc> *, tree,
      97                 :            :                               tree);
      98                 :            : static tree pointer_diff (location_t, tree, tree, tree *);
      99                 :            : static tree convert_for_assignment (location_t, location_t, tree, tree, tree,
     100                 :            :                                     enum impl_conv, bool, tree, tree, int,
     101                 :            :                                     int = 0);
     102                 :            : static tree valid_compound_expr_initializer (tree, tree);
     103                 :            : static void push_string (const char *);
     104                 :            : static void push_member_name (tree);
     105                 :            : static int spelling_length (void);
     106                 :            : static char *print_spelling (char *);
     107                 :            : static void warning_init (location_t, int, const char *);
     108                 :            : static tree digest_init (location_t, tree, tree, tree, bool, bool, int);
     109                 :            : static void output_init_element (location_t, tree, tree, bool, tree, tree, bool,
     110                 :            :                                  bool, struct obstack *);
     111                 :            : static void output_pending_init_elements (int, struct obstack *);
     112                 :            : static bool set_designator (location_t, bool, struct obstack *);
     113                 :            : static void push_range_stack (tree, struct obstack *);
     114                 :            : static void add_pending_init (location_t, tree, tree, tree, bool,
     115                 :            :                               struct obstack *);
     116                 :            : static void set_nonincremental_init (struct obstack *);
     117                 :            : static void set_nonincremental_init_from_string (tree, struct obstack *);
     118                 :            : static tree find_init_member (tree, struct obstack *);
     119                 :            : static void readonly_warning (tree, enum lvalue_use);
     120                 :            : static int lvalue_or_else (location_t, const_tree, enum lvalue_use);
     121                 :            : static void record_maybe_used_decl (tree);
     122                 :            : static int comptypes_internal (const_tree, const_tree, bool *, bool *);
     123                 :            : 
     124                 :            : /* Return true if EXP is a null pointer constant, false otherwise.  */
     125                 :            : 
     126                 :            : static bool
     127                 :  102425000 : null_pointer_constant_p (const_tree expr)
     128                 :            : {
     129                 :            :   /* This should really operate on c_expr structures, but they aren't
     130                 :            :      yet available everywhere required.  */
     131                 :  102425000 :   tree type = TREE_TYPE (expr);
     132                 :  102425000 :   return (TREE_CODE (expr) == INTEGER_CST
     133                 :   10445000 :           && !TREE_OVERFLOW (expr)
     134                 :   10445000 :           && integer_zerop (expr)
     135                 :  104644000 :           && (INTEGRAL_TYPE_P (type)
     136                 :     201261 :               || (TREE_CODE (type) == POINTER_TYPE
     137                 :     201261 :                   && VOID_TYPE_P (TREE_TYPE (type))
     138                 :     159642 :                   && TYPE_QUALS (TREE_TYPE (type)) == TYPE_UNQUALIFIED)));
     139                 :            : }
     140                 :            : 
     141                 :            : /* EXPR may appear in an unevaluated part of an integer constant
     142                 :            :    expression, but not in an evaluated part.  Wrap it in a
     143                 :            :    C_MAYBE_CONST_EXPR, or mark it with TREE_OVERFLOW if it is just an
     144                 :            :    INTEGER_CST and we cannot create a C_MAYBE_CONST_EXPR.  */
     145                 :            : 
     146                 :            : static tree
     147                 :      60359 : note_integer_operands (tree expr)
     148                 :            : {
     149                 :      60359 :   tree ret;
     150                 :      60359 :   if (TREE_CODE (expr) == INTEGER_CST && in_late_binary_op)
     151                 :            :     {
     152                 :          8 :       ret = copy_node (expr);
     153                 :          8 :       TREE_OVERFLOW (ret) = 1;
     154                 :            :     }
     155                 :            :   else
     156                 :            :     {
     157                 :      60351 :       ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (expr), NULL_TREE, expr);
     158                 :      60351 :       C_MAYBE_CONST_EXPR_INT_OPERANDS (ret) = 1;
     159                 :            :     }
     160                 :      60359 :   return ret;
     161                 :            : }
     162                 :            : 
     163                 :            : /* Having checked whether EXPR may appear in an unevaluated part of an
     164                 :            :    integer constant expression and found that it may, remove any
     165                 :            :    C_MAYBE_CONST_EXPR noting this fact and return the resulting
     166                 :            :    expression.  */
     167                 :            : 
     168                 :            : static inline tree
     169                 :   21667400 : remove_c_maybe_const_expr (tree expr)
     170                 :            : {
     171                 :   21667400 :   if (TREE_CODE (expr) == C_MAYBE_CONST_EXPR)
     172                 :      59658 :     return C_MAYBE_CONST_EXPR_EXPR (expr);
     173                 :            :   else
     174                 :            :     return expr;
     175                 :            : }
     176                 :            : 
     177                 :            : /* This is a cache to hold if two types are compatible or not.  */
     178                 :            : 
     179                 :            : struct tagged_tu_seen_cache {
     180                 :            :   const struct tagged_tu_seen_cache * next;
     181                 :            :   const_tree t1;
     182                 :            :   const_tree t2;
     183                 :            :   /* The return value of tagged_types_tu_compatible_p if we had seen
     184                 :            :      these two types already.  */
     185                 :            :   int val;
     186                 :            : };
     187                 :            : 
     188                 :            : static const struct tagged_tu_seen_cache * tagged_tu_seen_base;
     189                 :            : static void free_all_tagged_tu_seen_up_to (const struct tagged_tu_seen_cache *);
     190                 :            : 
     191                 :            : /* Do `exp = require_complete_type (loc, exp);' to make sure exp
     192                 :            :    does not have an incomplete type.  (That includes void types.)
     193                 :            :    LOC is the location of the use.  */
     194                 :            : 
     195                 :            : tree
     196                 :  427286000 : require_complete_type (location_t loc, tree value)
     197                 :            : {
     198                 :  427286000 :   tree type = TREE_TYPE (value);
     199                 :            : 
     200                 :  427286000 :   if (error_operand_p (value))
     201                 :            :     return error_mark_node;
     202                 :            : 
     203                 :            :   /* First, detect a valid value with a complete type.  */
     204                 :  427282000 :   if (COMPLETE_TYPE_P (type))
     205                 :            :     return value;
     206                 :            : 
     207                 :        108 :   c_incomplete_type_error (loc, value, type);
     208                 :        108 :   return error_mark_node;
     209                 :            : }
     210                 :            : 
     211                 :            : /* Print an error message for invalid use of an incomplete type.
     212                 :            :    VALUE is the expression that was used (or 0 if that isn't known)
     213                 :            :    and TYPE is the type that was invalid.  LOC is the location for
     214                 :            :    the error.  */
     215                 :            : 
     216                 :            : void
     217                 :        161 : c_incomplete_type_error (location_t loc, const_tree value, const_tree type)
     218                 :            : {
     219                 :            :   /* Avoid duplicate error message.  */
     220                 :        161 :   if (TREE_CODE (type) == ERROR_MARK)
     221                 :            :     return;
     222                 :            : 
     223                 :        161 :   if (value != NULL_TREE && (VAR_P (value) || TREE_CODE (value) == PARM_DECL))
     224                 :         88 :     error_at (loc, "%qD has an incomplete type %qT", value, type);
     225                 :            :   else
     226                 :            :     {
     227                 :         73 :     retry:
     228                 :            :       /* We must print an error message.  Be clever about what it says.  */
     229                 :            : 
     230                 :         73 :       switch (TREE_CODE (type))
     231                 :            :         {
     232                 :         67 :         case RECORD_TYPE:
     233                 :         67 :         case UNION_TYPE:
     234                 :         67 :         case ENUMERAL_TYPE:
     235                 :         67 :           break;
     236                 :            : 
     237                 :          0 :         case VOID_TYPE:
     238                 :          0 :           error_at (loc, "invalid use of void expression");
     239                 :          0 :           return;
     240                 :            : 
     241                 :          6 :         case ARRAY_TYPE:
     242                 :          6 :           if (TYPE_DOMAIN (type))
     243                 :            :             {
     244                 :          3 :               if (TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL)
     245                 :            :                 {
     246                 :          3 :                   error_at (loc, "invalid use of flexible array member");
     247                 :          3 :                   return;
     248                 :            :                 }
     249                 :          0 :               type = TREE_TYPE (type);
     250                 :          0 :               goto retry;
     251                 :            :             }
     252                 :          3 :           error_at (loc, "invalid use of array with unspecified bounds");
     253                 :          3 :           return;
     254                 :            : 
     255                 :          0 :         default:
     256                 :          0 :           gcc_unreachable ();
     257                 :            :         }
     258                 :            : 
     259                 :         67 :       if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
     260                 :         65 :         error_at (loc, "invalid use of undefined type %qT", type);
     261                 :            :       else
     262                 :            :         /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL.  */
     263                 :          2 :         error_at (loc, "invalid use of incomplete typedef %qT", type);
     264                 :            :     }
     265                 :            : }
     266                 :            : 
     267                 :            : /* Given a type, apply default promotions wrt unnamed function
     268                 :            :    arguments and return the new type.  */
     269                 :            : 
     270                 :            : tree
     271                 :   83116500 : c_type_promotes_to (tree type)
     272                 :            : {
     273                 :   83116500 :   tree ret = NULL_TREE;
     274                 :            : 
     275                 :   83116500 :   if (TYPE_MAIN_VARIANT (type) == float_type_node)
     276                 :     836908 :     ret = double_type_node;
     277                 :   82279600 :   else if (c_promoting_integer_type_p (type))
     278                 :            :     {
     279                 :            :       /* Preserve unsignedness if not really getting any wider.  */
     280                 :   21468000 :       if (TYPE_UNSIGNED (type)
     281                 :   21468000 :           && (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)))
     282                 :          0 :         ret = unsigned_type_node;
     283                 :            :       else
     284                 :   21468000 :         ret = integer_type_node;
     285                 :            :     }
     286                 :            : 
     287                 :   22304900 :   if (ret != NULL_TREE)
     288                 :   22304900 :     return (TYPE_ATOMIC (type)
     289                 :          8 :             ? c_build_qualified_type (ret, TYPE_QUAL_ATOMIC)
     290                 :   22304900 :             : ret);
     291                 :            : 
     292                 :            :   return type;
     293                 :            : }
     294                 :            : 
     295                 :            : /* Return true if between two named address spaces, whether there is a superset
     296                 :            :    named address space that encompasses both address spaces.  If there is a
     297                 :            :    superset, return which address space is the superset.  */
     298                 :            : 
     299                 :            : static bool
     300                 :    4105900 : addr_space_superset (addr_space_t as1, addr_space_t as2, addr_space_t *common)
     301                 :            : {
     302                 :    4105900 :   if (as1 == as2)
     303                 :            :     {
     304                 :    4105900 :       *common = as1;
     305                 :    4105900 :       return true;
     306                 :            :     }
     307                 :          0 :   else if (targetm.addr_space.subset_p (as1, as2))
     308                 :            :     {
     309                 :          0 :       *common = as2;
     310                 :          0 :       return true;
     311                 :            :     }
     312                 :          0 :   else if (targetm.addr_space.subset_p (as2, as1))
     313                 :            :     {
     314                 :          0 :       *common = as1;
     315                 :          0 :       return true;
     316                 :            :     }
     317                 :            :   else
     318                 :            :     return false;
     319                 :            : }
     320                 :            : 
     321                 :            : /* Return a variant of TYPE which has all the type qualifiers of LIKE
     322                 :            :    as well as those of TYPE.  */
     323                 :            : 
     324                 :            : static tree
     325                 :    1105540 : qualify_type (tree type, tree like)
     326                 :            : {
     327                 :    1105540 :   addr_space_t as_type = TYPE_ADDR_SPACE (type);
     328                 :    1105540 :   addr_space_t as_like = TYPE_ADDR_SPACE (like);
     329                 :    1105540 :   addr_space_t as_common;
     330                 :            : 
     331                 :            :   /* If the two named address spaces are different, determine the common
     332                 :            :      superset address space.  If there isn't one, raise an error.  */
     333                 :    1105540 :   if (!addr_space_superset (as_type, as_like, &as_common))
     334                 :            :     {
     335                 :          0 :       as_common = as_type;
     336                 :          0 :       error ("%qT and %qT are in disjoint named address spaces",
     337                 :            :              type, like);
     338                 :            :     }
     339                 :            : 
     340                 :    1105540 :   return c_build_qualified_type (type,
     341                 :    1105540 :                                  TYPE_QUALS_NO_ADDR_SPACE (type)
     342                 :    1105540 :                                  | TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (like)
     343                 :    1105540 :                                  | ENCODE_QUAL_ADDR_SPACE (as_common));
     344                 :            : }
     345                 :            : 
     346                 :            : /* Return true iff the given tree T is a variable length array.  */
     347                 :            : 
     348                 :            : bool
     349                 :  902183000 : c_vla_type_p (const_tree t)
     350                 :            : {
     351                 :  902183000 :   if (TREE_CODE (t) == ARRAY_TYPE
     352                 :  902958000 :       && C_TYPE_VARIABLE_SIZE (t))
     353                 :        419 :     return true;
     354                 :            :   return false;
     355                 :            : }
     356                 :            : 
     357                 :            : /* If NTYPE is a type of a non-variadic function with a prototype
     358                 :            :    and OTYPE is a type of a function without a prototype and ATTRS
     359                 :            :    contains attribute format, diagnosess and removes it from ATTRS.
     360                 :            :    Returns the result of build_type_attribute_variant of NTYPE and
     361                 :            :    the (possibly) modified ATTRS.  */
     362                 :            : 
     363                 :            : static tree
     364                 :       8378 : build_functype_attribute_variant (tree ntype, tree otype, tree attrs)
     365                 :            : {
     366                 :       8378 :   if (!prototype_p (otype)
     367                 :       8378 :       && prototype_p (ntype)
     368                 :      16675 :       && lookup_attribute ("format", attrs))
     369                 :            :     {
     370                 :         14 :       warning_at (input_location, OPT_Wattributes,
     371                 :            :                   "%qs attribute cannot be applied to a function that "
     372                 :            :                   "does not take variable arguments", "format");
     373                 :         14 :       attrs = remove_attribute ("format", attrs);
     374                 :            :     }
     375                 :       8378 :   return build_type_attribute_variant (ntype, attrs);
     376                 :            : 
     377                 :            : }
     378                 :            : /* Return the composite type of two compatible types.
     379                 :            : 
     380                 :            :    We assume that comptypes has already been done and returned
     381                 :            :    nonzero; if that isn't so, this may crash.  In particular, we
     382                 :            :    assume that qualifiers match.  */
     383                 :            : 
     384                 :            : tree
     385                 :    5912720 : composite_type (tree t1, tree t2)
     386                 :            : {
     387                 :    5912720 :   enum tree_code code1;
     388                 :    5912720 :   enum tree_code code2;
     389                 :    5912720 :   tree attributes;
     390                 :            : 
     391                 :            :   /* Save time if the two types are the same.  */
     392                 :            : 
     393                 :    5912720 :   if (t1 == t2) return t1;
     394                 :            : 
     395                 :            :   /* If one type is nonsense, use the other.  */
     396                 :    1340010 :   if (t1 == error_mark_node)
     397                 :            :     return t2;
     398                 :    1340010 :   if (t2 == error_mark_node)
     399                 :            :     return t1;
     400                 :            : 
     401                 :    1340010 :   code1 = TREE_CODE (t1);
     402                 :    1340010 :   code2 = TREE_CODE (t2);
     403                 :            : 
     404                 :            :   /* Merge the attributes.  */
     405                 :    1340010 :   attributes = targetm.merge_type_attributes (t1, t2);
     406                 :            : 
     407                 :            :   /* If one is an enumerated type and the other is the compatible
     408                 :            :      integer type, the composite type might be either of the two
     409                 :            :      (DR#013 question 3).  For consistency, use the enumerated type as
     410                 :            :      the composite type.  */
     411                 :            : 
     412                 :    1340010 :   if (code1 == ENUMERAL_TYPE && code2 == INTEGER_TYPE)
     413                 :            :     return t1;
     414                 :    1339910 :   if (code2 == ENUMERAL_TYPE && code1 == INTEGER_TYPE)
     415                 :            :     return t2;
     416                 :            : 
     417                 :    1339910 :   gcc_assert (code1 == code2);
     418                 :            : 
     419                 :    1339910 :   switch (code1)
     420                 :            :     {
     421                 :     320109 :     case POINTER_TYPE:
     422                 :            :       /* For two pointers, do this recursively on the target type.  */
     423                 :     320109 :       {
     424                 :     320109 :         tree pointed_to_1 = TREE_TYPE (t1);
     425                 :     320109 :         tree pointed_to_2 = TREE_TYPE (t2);
     426                 :     320109 :         tree target = composite_type (pointed_to_1, pointed_to_2);
     427                 :     320109 :         t1 = build_pointer_type_for_mode (target, TYPE_MODE (t1), false);
     428                 :     320109 :         t1 = build_type_attribute_variant (t1, attributes);
     429                 :     320109 :         return qualify_type (t1, t2);
     430                 :            :       }
     431                 :            : 
     432                 :       1411 :     case ARRAY_TYPE:
     433                 :       1411 :       {
     434                 :       1411 :         tree elt = composite_type (TREE_TYPE (t1), TREE_TYPE (t2));
     435                 :       1411 :         int quals;
     436                 :       1411 :         tree unqual_elt;
     437                 :       1411 :         tree d1 = TYPE_DOMAIN (t1);
     438                 :       1411 :         tree d2 = TYPE_DOMAIN (t2);
     439                 :       1411 :         bool d1_variable, d2_variable;
     440                 :       1411 :         bool d1_zero, d2_zero;
     441                 :       1411 :         bool t1_complete, t2_complete;
     442                 :            : 
     443                 :            :         /* We should not have any type quals on arrays at all.  */
     444                 :       2822 :         gcc_assert (!TYPE_QUALS_NO_ADDR_SPACE (t1)
     445                 :            :                     && !TYPE_QUALS_NO_ADDR_SPACE (t2));
     446                 :            : 
     447                 :       1411 :         t1_complete = COMPLETE_TYPE_P (t1);
     448                 :       1411 :         t2_complete = COMPLETE_TYPE_P (t2);
     449                 :            : 
     450                 :       1411 :         d1_zero = d1 == NULL_TREE || !TYPE_MAX_VALUE (d1);
     451                 :       1411 :         d2_zero = d2 == NULL_TREE || !TYPE_MAX_VALUE (d2);
     452                 :            : 
     453                 :       2822 :         d1_variable = (!d1_zero
     454                 :       1411 :                        && (TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST
     455                 :        676 :                            || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST));
     456                 :       2822 :         d2_variable = (!d2_zero
     457                 :       1411 :                        && (TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
     458                 :        970 :                            || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST));
     459                 :       1411 :         d1_variable = d1_variable || (d1_zero && c_vla_type_p (t1));
     460                 :       1411 :         d2_variable = d2_variable || (d2_zero && c_vla_type_p (t2));
     461                 :            : 
     462                 :            :         /* Save space: see if the result is identical to one of the args.  */
     463                 :       2763 :         if (elt == TREE_TYPE (t1) && TYPE_DOMAIN (t1)
     464                 :       2062 :             && (d2_variable || d2_zero || !d1_variable))
     465                 :        596 :           return build_type_attribute_variant (t1, attributes);
     466                 :       1549 :         if (elt == TREE_TYPE (t2) && TYPE_DOMAIN (t2)
     467                 :       1546 :             && (d1_variable || d1_zero || !d2_variable))
     468                 :        731 :           return build_type_attribute_variant (t2, attributes);
     469                 :            : 
     470                 :        119 :         if (elt == TREE_TYPE (t1) && !TYPE_DOMAIN (t2) && !TYPE_DOMAIN (t1))
     471                 :         10 :           return build_type_attribute_variant (t1, attributes);
     472                 :         80 :         if (elt == TREE_TYPE (t2) && !TYPE_DOMAIN (t2) && !TYPE_DOMAIN (t1))
     473                 :          2 :           return build_type_attribute_variant (t2, attributes);
     474                 :            : 
     475                 :            :         /* Merge the element types, and have a size if either arg has
     476                 :            :            one.  We may have qualifiers on the element types.  To set
     477                 :            :            up TYPE_MAIN_VARIANT correctly, we need to form the
     478                 :            :            composite of the unqualified types and add the qualifiers
     479                 :            :            back at the end.  */
     480                 :         72 :         quals = TYPE_QUALS (strip_array_types (elt));
     481                 :         72 :         unqual_elt = c_build_qualified_type (elt, TYPE_UNQUALIFIED);
     482                 :         72 :         t1 = build_array_type (unqual_elt,
     483                 :        144 :                                TYPE_DOMAIN ((TYPE_DOMAIN (t1)
     484                 :            :                                              && (d2_variable
     485                 :            :                                                  || d2_zero
     486                 :            :                                                  || !d1_variable))
     487                 :            :                                             ? t1
     488                 :            :                                             : t2));
     489                 :            :         /* Ensure a composite type involving a zero-length array type
     490                 :            :            is a zero-length type not an incomplete type.  */
     491                 :         72 :         if (d1_zero && d2_zero
     492                 :         16 :             && (t1_complete || t2_complete)
     493                 :         73 :             && !COMPLETE_TYPE_P (t1))
     494                 :            :           {
     495                 :          1 :             TYPE_SIZE (t1) = bitsize_zero_node;
     496                 :          1 :             TYPE_SIZE_UNIT (t1) = size_zero_node;
     497                 :            :           }
     498                 :         72 :         t1 = c_build_qualified_type (t1, quals);
     499                 :         72 :         return build_type_attribute_variant (t1, attributes);
     500                 :            :       }
     501                 :            : 
     502                 :         16 :     case ENUMERAL_TYPE:
     503                 :         16 :     case RECORD_TYPE:
     504                 :         16 :     case UNION_TYPE:
     505                 :         16 :       if (attributes != NULL)
     506                 :            :         {
     507                 :            :           /* Try harder not to create a new aggregate type.  */
     508                 :          0 :           if (attribute_list_equal (TYPE_ATTRIBUTES (t1), attributes))
     509                 :            :             return t1;
     510                 :          0 :           if (attribute_list_equal (TYPE_ATTRIBUTES (t2), attributes))
     511                 :            :             return t2;
     512                 :            :         }
     513                 :         16 :       return build_type_attribute_variant (t1, attributes);
     514                 :            : 
     515                 :     775128 :     case FUNCTION_TYPE:
     516                 :            :       /* Function types: prefer the one that specified arg types.
     517                 :            :          If both do, merge the arg types.  Also merge the return types.  */
     518                 :     775128 :       {
     519                 :     775128 :         tree valtype = composite_type (TREE_TYPE (t1), TREE_TYPE (t2));
     520                 :     775128 :         tree p1 = TYPE_ARG_TYPES (t1);
     521                 :     775128 :         tree p2 = TYPE_ARG_TYPES (t2);
     522                 :     775128 :         int len;
     523                 :     775128 :         tree newargs, n;
     524                 :     775128 :         int i;
     525                 :            : 
     526                 :            :         /* Save space: see if the result is identical to one of the args.  */
     527                 :    1550140 :         if (valtype == TREE_TYPE (t1) && !TYPE_ARG_TYPES (t2))
     528                 :       7198 :           return build_functype_attribute_variant (t1, t2, attributes);
     529                 :    1508940 :         if (valtype == TREE_TYPE (t2) && !TYPE_ARG_TYPES (t1))
     530                 :       1180 :           return build_functype_attribute_variant (t2, t1, attributes);
     531                 :            : 
     532                 :            :         /* Simple way if one arg fails to specify argument types.  */
     533                 :     766750 :         if (TYPE_ARG_TYPES (t1) == NULL_TREE)
     534                 :            :          {
     535                 :          7 :             t1 = build_function_type (valtype, TYPE_ARG_TYPES (t2));
     536                 :          7 :             t1 = build_type_attribute_variant (t1, attributes);
     537                 :          7 :             return qualify_type (t1, t2);
     538                 :            :          }
     539                 :     766743 :         if (TYPE_ARG_TYPES (t2) == NULL_TREE)
     540                 :            :          {
     541                 :          1 :            t1 = build_function_type (valtype, TYPE_ARG_TYPES (t1));
     542                 :          1 :            t1 = build_type_attribute_variant (t1, attributes);
     543                 :          1 :            return qualify_type (t1, t2);
     544                 :            :          }
     545                 :            : 
     546                 :            :         /* If both args specify argument types, we must merge the two
     547                 :            :            lists, argument by argument.  */
     548                 :            : 
     549                 :    1612010 :         for (len = 0, newargs = p1;
     550                 :    2378750 :              newargs && newargs != void_list_node;
     551                 :    1612010 :              len++, newargs = TREE_CHAIN (newargs))
     552                 :            :           ;
     553                 :            : 
     554                 :    2378750 :         for (i = 0; i < len; i++)
     555                 :    1612010 :           newargs = tree_cons (NULL_TREE, NULL_TREE, newargs);
     556                 :            : 
     557                 :            :         n = newargs;
     558                 :            : 
     559                 :    2378750 :         for (; p1 && p1 != void_list_node;
     560                 :    1612010 :              p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2), n = TREE_CHAIN (n))
     561                 :            :           {
     562                 :            :             /* A null type means arg type is not specified.
     563                 :            :                Take whatever the other function type has.  */
     564                 :    1612010 :             if (TREE_VALUE (p1) == NULL_TREE)
     565                 :            :               {
     566                 :          0 :                 TREE_VALUE (n) = TREE_VALUE (p2);
     567                 :          0 :                 goto parm_done;
     568                 :            :               }
     569                 :    1612010 :             if (TREE_VALUE (p2) == NULL_TREE)
     570                 :            :               {
     571                 :          0 :                 TREE_VALUE (n) = TREE_VALUE (p1);
     572                 :          0 :                 goto parm_done;
     573                 :            :               }
     574                 :            : 
     575                 :            :             /* Given  wait (union {union wait *u; int *i} *)
     576                 :            :                and  wait (union wait *),
     577                 :            :                prefer  union wait *  as type of parm.  */
     578                 :    1612010 :             if (TREE_CODE (TREE_VALUE (p1)) == UNION_TYPE
     579                 :    1612010 :                 && TREE_VALUE (p1) != TREE_VALUE (p2))
     580                 :            :               {
     581                 :         22 :                 tree memb;
     582                 :         22 :                 tree mv2 = TREE_VALUE (p2);
     583                 :         22 :                 if (mv2 && mv2 != error_mark_node
     584                 :         22 :                     && TREE_CODE (mv2) != ARRAY_TYPE)
     585                 :         22 :                   mv2 = TYPE_MAIN_VARIANT (mv2);
     586                 :         26 :                 for (memb = TYPE_FIELDS (TREE_VALUE (p1));
     587                 :         26 :                      memb; memb = DECL_CHAIN (memb))
     588                 :            :                   {
     589                 :         26 :                     tree mv3 = TREE_TYPE (memb);
     590                 :         26 :                     if (mv3 && mv3 != error_mark_node
     591                 :         26 :                         && TREE_CODE (mv3) != ARRAY_TYPE)
     592                 :         26 :                       mv3 = TYPE_MAIN_VARIANT (mv3);
     593                 :         26 :                     if (comptypes (mv3, mv2))
     594                 :            :                       {
     595                 :         44 :                         TREE_VALUE (n) = composite_type (TREE_TYPE (memb),
     596                 :         22 :                                                          TREE_VALUE (p2));
     597                 :         22 :                         pedwarn (input_location, OPT_Wpedantic,
     598                 :            :                                  "function types not truly compatible in ISO C");
     599                 :         22 :                         goto parm_done;
     600                 :            :                       }
     601                 :            :                   }
     602                 :            :               }
     603                 :    1611990 :             if (TREE_CODE (TREE_VALUE (p2)) == UNION_TYPE
     604                 :    1611990 :                 && TREE_VALUE (p2) != TREE_VALUE (p1))
     605                 :            :               {
     606                 :         22 :                 tree memb;
     607                 :         22 :                 tree mv1 = TREE_VALUE (p1);
     608                 :         22 :                 if (mv1 && mv1 != error_mark_node
     609                 :         22 :                     && TREE_CODE (mv1) != ARRAY_TYPE)
     610                 :         22 :                   mv1 = TYPE_MAIN_VARIANT (mv1);
     611                 :         26 :                 for (memb = TYPE_FIELDS (TREE_VALUE (p2));
     612                 :         26 :                      memb; memb = DECL_CHAIN (memb))
     613                 :            :                   {
     614                 :         26 :                     tree mv3 = TREE_TYPE (memb);
     615                 :         26 :                     if (mv3 && mv3 != error_mark_node
     616                 :         26 :                         && TREE_CODE (mv3) != ARRAY_TYPE)
     617                 :         26 :                       mv3 = TYPE_MAIN_VARIANT (mv3);
     618                 :         26 :                     if (comptypes (mv3, mv1))
     619                 :            :                       {
     620                 :         44 :                         TREE_VALUE (n) = composite_type (TREE_TYPE (memb),
     621                 :         22 :                                                          TREE_VALUE (p1));
     622                 :         22 :                         pedwarn (input_location, OPT_Wpedantic,
     623                 :            :                                  "function types not truly compatible in ISO C");
     624                 :         22 :                         goto parm_done;
     625                 :            :                       }
     626                 :            :                   }
     627                 :            :               }
     628                 :    1611960 :             TREE_VALUE (n) = composite_type (TREE_VALUE (p1), TREE_VALUE (p2));
     629                 :    1612010 :           parm_done: ;
     630                 :            :           }
     631                 :            : 
     632                 :     766742 :         t1 = build_function_type (valtype, newargs);
     633                 :     766742 :         t1 = qualify_type (t1, t2);
     634                 :            :       }
     635                 :            :       /* FALLTHRU */
     636                 :            : 
     637                 :    1009990 :     default:
     638                 :    1009990 :       return build_type_attribute_variant (t1, attributes);
     639                 :            :     }
     640                 :            : 
     641                 :            : }
     642                 :            : 
     643                 :            : /* Return the type of a conditional expression between pointers to
     644                 :            :    possibly differently qualified versions of compatible types.
     645                 :            : 
     646                 :            :    We assume that comp_target_types has already been done and returned
     647                 :            :    nonzero; if that isn't so, this may crash.  */
     648                 :            : 
     649                 :            : static tree
     650                 :      72020 : common_pointer_type (tree t1, tree t2)
     651                 :            : {
     652                 :      72020 :   tree attributes;
     653                 :      72020 :   tree pointed_to_1, mv1;
     654                 :      72020 :   tree pointed_to_2, mv2;
     655                 :      72020 :   tree target;
     656                 :      72020 :   unsigned target_quals;
     657                 :      72020 :   addr_space_t as1, as2, as_common;
     658                 :      72020 :   int quals1, quals2;
     659                 :            : 
     660                 :            :   /* Save time if the two types are the same.  */
     661                 :            : 
     662                 :      72020 :   if (t1 == t2) return t1;
     663                 :            : 
     664                 :            :   /* If one type is nonsense, use the other.  */
     665                 :       6085 :   if (t1 == error_mark_node)
     666                 :            :     return t2;
     667                 :       6085 :   if (t2 == error_mark_node)
     668                 :            :     return t1;
     669                 :            : 
     670                 :       6085 :   gcc_assert (TREE_CODE (t1) == POINTER_TYPE
     671                 :            :               && TREE_CODE (t2) == POINTER_TYPE);
     672                 :            : 
     673                 :            :   /* Merge the attributes.  */
     674                 :       6085 :   attributes = targetm.merge_type_attributes (t1, t2);
     675                 :            : 
     676                 :            :   /* Find the composite type of the target types, and combine the
     677                 :            :      qualifiers of the two types' targets.  Do not lose qualifiers on
     678                 :            :      array element types by taking the TYPE_MAIN_VARIANT.  */
     679                 :       6085 :   mv1 = pointed_to_1 = TREE_TYPE (t1);
     680                 :       6085 :   mv2 = pointed_to_2 = TREE_TYPE (t2);
     681                 :       6085 :   if (TREE_CODE (mv1) != ARRAY_TYPE)
     682                 :       5784 :     mv1 = TYPE_MAIN_VARIANT (pointed_to_1);
     683                 :       6085 :   if (TREE_CODE (mv2) != ARRAY_TYPE)
     684                 :       5784 :     mv2 = TYPE_MAIN_VARIANT (pointed_to_2);
     685                 :       6085 :   target = composite_type (mv1, mv2);
     686                 :            : 
     687                 :            :   /* Strip array types to get correct qualifier for pointers to arrays */
     688                 :       6085 :   quals1 = TYPE_QUALS_NO_ADDR_SPACE (strip_array_types (pointed_to_1));
     689                 :       6085 :   quals2 = TYPE_QUALS_NO_ADDR_SPACE (strip_array_types (pointed_to_2));
     690                 :            : 
     691                 :            :   /* For function types do not merge const qualifiers, but drop them
     692                 :            :      if used inconsistently.  The middle-end uses these to mark const
     693                 :            :      and noreturn functions.  */
     694                 :       6085 :   if (TREE_CODE (pointed_to_1) == FUNCTION_TYPE)
     695                 :       2178 :     target_quals = (quals1 & quals2);
     696                 :            :   else
     697                 :       3907 :     target_quals = (quals1 | quals2);
     698                 :            : 
     699                 :            :   /* If the two named address spaces are different, determine the common
     700                 :            :      superset address space.  This is guaranteed to exist due to the
     701                 :            :      assumption that comp_target_type returned non-zero.  */
     702                 :       6085 :   as1 = TYPE_ADDR_SPACE (pointed_to_1);
     703                 :       6085 :   as2 = TYPE_ADDR_SPACE (pointed_to_2);
     704                 :       6085 :   if (!addr_space_superset (as1, as2, &as_common))
     705                 :          0 :     gcc_unreachable ();
     706                 :            : 
     707                 :       6085 :   target_quals |= ENCODE_QUAL_ADDR_SPACE (as_common);
     708                 :            : 
     709                 :       6085 :   t1 = build_pointer_type (c_build_qualified_type (target, target_quals));
     710                 :       6085 :   return build_type_attribute_variant (t1, attributes);
     711                 :            : }
     712                 :            : 
     713                 :            : /* Return the common type for two arithmetic types under the usual
     714                 :            :    arithmetic conversions.  The default conversions have already been
     715                 :            :    applied, and enumerated types converted to their compatible integer
     716                 :            :    types.  The resulting type is unqualified and has no attributes.
     717                 :            : 
     718                 :            :    This is the type for the result of most arithmetic operations
     719                 :            :    if the operands have the given two types.  */
     720                 :            : 
     721                 :            : static tree
     722                 :    9351680 : c_common_type (tree t1, tree t2)
     723                 :            : {
     724                 :    9351680 :   enum tree_code code1;
     725                 :    9351680 :   enum tree_code code2;
     726                 :            : 
     727                 :            :   /* If one type is nonsense, use the other.  */
     728                 :    9351680 :   if (t1 == error_mark_node)
     729                 :            :     return t2;
     730                 :    9351680 :   if (t2 == error_mark_node)
     731                 :            :     return t1;
     732                 :            : 
     733                 :    9351680 :   if (TYPE_QUALS (t1) != TYPE_UNQUALIFIED)
     734                 :     304603 :     t1 = TYPE_MAIN_VARIANT (t1);
     735                 :            : 
     736                 :    9351680 :   if (TYPE_QUALS (t2) != TYPE_UNQUALIFIED)
     737                 :     147528 :     t2 = TYPE_MAIN_VARIANT (t2);
     738                 :            : 
     739                 :    9351680 :   if (TYPE_ATTRIBUTES (t1) != NULL_TREE)
     740                 :      72491 :     t1 = build_type_attribute_variant (t1, NULL_TREE);
     741                 :            : 
     742                 :    9351680 :   if (TYPE_ATTRIBUTES (t2) != NULL_TREE)
     743                 :      72493 :     t2 = build_type_attribute_variant (t2, NULL_TREE);
     744                 :            : 
     745                 :            :   /* Save time if the two types are the same.  */
     746                 :            : 
     747                 :    9351680 :   if (t1 == t2) return t1;
     748                 :            : 
     749                 :    1721030 :   code1 = TREE_CODE (t1);
     750                 :    1721030 :   code2 = TREE_CODE (t2);
     751                 :            : 
     752                 :    1721030 :   gcc_assert (code1 == VECTOR_TYPE || code1 == COMPLEX_TYPE
     753                 :            :               || code1 == FIXED_POINT_TYPE || code1 == REAL_TYPE
     754                 :            :               || code1 == INTEGER_TYPE);
     755                 :    1721030 :   gcc_assert (code2 == VECTOR_TYPE || code2 == COMPLEX_TYPE
     756                 :            :               || code2 == FIXED_POINT_TYPE || code2 == REAL_TYPE
     757                 :            :               || code2 == INTEGER_TYPE);
     758                 :            : 
     759                 :            :   /* When one operand is a decimal float type, the other operand cannot be
     760                 :            :      a generic float type or a complex type.  We also disallow vector types
     761                 :            :      here.  */
     762                 :    1841290 :   if ((DECIMAL_FLOAT_TYPE_P (t1) || DECIMAL_FLOAT_TYPE_P (t2))
     763                 :    1728020 :       && !(DECIMAL_FLOAT_TYPE_P (t1) && DECIMAL_FLOAT_TYPE_P (t2)))
     764                 :            :     {
     765                 :       1056 :       if (code1 == VECTOR_TYPE || code2 == VECTOR_TYPE)
     766                 :            :         {
     767                 :          3 :           error ("cannot mix operands of decimal floating and vector types");
     768                 :          3 :           return error_mark_node;
     769                 :            :         }
     770                 :       1053 :       if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE)
     771                 :            :         {
     772                 :          5 :           error ("cannot mix operands of decimal floating and complex types");
     773                 :          5 :           return error_mark_node;
     774                 :            :         }
     775                 :       1048 :       if (code1 == REAL_TYPE && code2 == REAL_TYPE)
     776                 :            :         {
     777                 :         16 :           error ("cannot mix operands of decimal floating "
     778                 :            :                  "and other floating types");
     779                 :         16 :           return error_mark_node;
     780                 :            :         }
     781                 :            :     }
     782                 :            : 
     783                 :            :   /* If one type is a vector type, return that type.  (How the usual
     784                 :            :      arithmetic conversions apply to the vector types extension is not
     785                 :            :      precisely specified.)  */
     786                 :    1721000 :   if (code1 == VECTOR_TYPE)
     787                 :            :     return t1;
     788                 :            : 
     789                 :    1720900 :   if (code2 == VECTOR_TYPE)
     790                 :            :     return t2;
     791                 :            : 
     792                 :            :   /* If one type is complex, form the common type of the non-complex
     793                 :            :      components, then make that complex.  Use T1 or T2 if it is the
     794                 :            :      required type.  */
     795                 :    1720900 :   if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE)
     796                 :            :     {
     797                 :     120300 :       tree subtype1 = code1 == COMPLEX_TYPE ? TREE_TYPE (t1) : t1;
     798                 :     153121 :       tree subtype2 = code2 == COMPLEX_TYPE ? TREE_TYPE (t2) : t2;
     799                 :      88803 :       tree subtype = c_common_type (subtype1, subtype2);
     800                 :            : 
     801                 :     120300 :       if (code1 == COMPLEX_TYPE && TREE_TYPE (t1) == subtype)
     802                 :            :         return t1;
     803                 :     117136 :       else if (code2 == COMPLEX_TYPE && TREE_TYPE (t2) == subtype)
     804                 :            :         return t2;
     805                 :            :       else
     806                 :       3345 :         return build_complex_type (subtype);
     807                 :            :     }
     808                 :            : 
     809                 :            :   /* If only one is real, use it as the result.  */
     810                 :            : 
     811                 :    1632100 :   if (code1 == REAL_TYPE && code2 != REAL_TYPE)
     812                 :            :     return t1;
     813                 :            : 
     814                 :    1566210 :   if (code2 == REAL_TYPE && code1 != REAL_TYPE)
     815                 :            :     return t2;
     816                 :            : 
     817                 :            :   /* If both are real and either are decimal floating point types, use
     818                 :            :      the decimal floating point type with the greater precision. */
     819                 :            : 
     820                 :    1541780 :   if (code1 == REAL_TYPE && code2 == REAL_TYPE)
     821                 :            :     {
     822                 :      93258 :       if (TYPE_MAIN_VARIANT (t1) == dfloat128_type_node
     823                 :     185947 :           || TYPE_MAIN_VARIANT (t2) == dfloat128_type_node)
     824                 :            :         return dfloat128_type_node;
     825                 :      92646 :       else if (TYPE_MAIN_VARIANT (t1) == dfloat64_type_node
     826                 :      92646 :                || TYPE_MAIN_VARIANT (t2) == dfloat64_type_node)
     827                 :            :         return dfloat64_type_node;
     828                 :      92091 :       else if (TYPE_MAIN_VARIANT (t1) == dfloat32_type_node
     829                 :      92091 :                || TYPE_MAIN_VARIANT (t2) == dfloat32_type_node)
     830                 :            :         return dfloat32_type_node;
     831                 :            :     }
     832                 :            : 
     833                 :            :   /* Deal with fixed-point types.  */
     834                 :    1540140 :   if (code1 == FIXED_POINT_TYPE || code2 == FIXED_POINT_TYPE)
     835                 :            :     {
     836                 :          0 :       unsigned int unsignedp = 0, satp = 0;
     837                 :          0 :       scalar_mode m1, m2;
     838                 :          0 :       unsigned int fbit1, ibit1, fbit2, ibit2, max_fbit, max_ibit;
     839                 :            : 
     840                 :          0 :       m1 = SCALAR_TYPE_MODE (t1);
     841                 :          0 :       m2 = SCALAR_TYPE_MODE (t2);
     842                 :            : 
     843                 :            :       /* If one input type is saturating, the result type is saturating.  */
     844                 :          0 :       if (TYPE_SATURATING (t1) || TYPE_SATURATING (t2))
     845                 :            :         satp = 1;
     846                 :            : 
     847                 :            :       /* If both fixed-point types are unsigned, the result type is unsigned.
     848                 :            :          When mixing fixed-point and integer types, follow the sign of the
     849                 :            :          fixed-point type.
     850                 :            :          Otherwise, the result type is signed.  */
     851                 :          0 :       if ((TYPE_UNSIGNED (t1) && TYPE_UNSIGNED (t2)
     852                 :          0 :            && code1 == FIXED_POINT_TYPE && code2 == FIXED_POINT_TYPE)
     853                 :          0 :           || (code1 == FIXED_POINT_TYPE && code2 != FIXED_POINT_TYPE
     854                 :          0 :               && TYPE_UNSIGNED (t1))
     855                 :          0 :           || (code1 != FIXED_POINT_TYPE && code2 == FIXED_POINT_TYPE
     856                 :          0 :               && TYPE_UNSIGNED (t2)))
     857                 :            :         unsignedp = 1;
     858                 :            : 
     859                 :            :       /* The result type is signed.  */
     860                 :          0 :       if (unsignedp == 0)
     861                 :            :         {
     862                 :            :           /* If the input type is unsigned, we need to convert to the
     863                 :            :              signed type.  */
     864                 :          0 :           if (code1 == FIXED_POINT_TYPE && TYPE_UNSIGNED (t1))
     865                 :            :             {
     866                 :          0 :               enum mode_class mclass = (enum mode_class) 0;
     867                 :          0 :               if (GET_MODE_CLASS (m1) == MODE_UFRACT)
     868                 :            :                 mclass = MODE_FRACT;
     869                 :          0 :               else if (GET_MODE_CLASS (m1) == MODE_UACCUM)
     870                 :            :                 mclass = MODE_ACCUM;
     871                 :            :               else
     872                 :          0 :                 gcc_unreachable ();
     873                 :          0 :               m1 = as_a <scalar_mode>
     874                 :          0 :                 (mode_for_size (GET_MODE_PRECISION (m1), mclass, 0));
     875                 :            :             }
     876                 :          0 :           if (code2 == FIXED_POINT_TYPE && TYPE_UNSIGNED (t2))
     877                 :            :             {
     878                 :          0 :               enum mode_class mclass = (enum mode_class) 0;
     879                 :          0 :               if (GET_MODE_CLASS (m2) == MODE_UFRACT)
     880                 :            :                 mclass = MODE_FRACT;
     881                 :          0 :               else if (GET_MODE_CLASS (m2) == MODE_UACCUM)
     882                 :            :                 mclass = MODE_ACCUM;
     883                 :            :               else
     884                 :          0 :                 gcc_unreachable ();
     885                 :          0 :               m2 = as_a <scalar_mode>
     886                 :          0 :                 (mode_for_size (GET_MODE_PRECISION (m2), mclass, 0));
     887                 :            :             }
     888                 :            :         }
     889                 :            : 
     890                 :          0 :       if (code1 == FIXED_POINT_TYPE)
     891                 :            :         {
     892                 :          0 :           fbit1 = GET_MODE_FBIT (m1);
     893                 :          0 :           ibit1 = GET_MODE_IBIT (m1);
     894                 :            :         }
     895                 :            :       else
     896                 :            :         {
     897                 :          0 :           fbit1 = 0;
     898                 :            :           /* Signed integers need to subtract one sign bit.  */
     899                 :          0 :           ibit1 = TYPE_PRECISION (t1) - (!TYPE_UNSIGNED (t1));
     900                 :            :         }
     901                 :            : 
     902                 :          0 :       if (code2 == FIXED_POINT_TYPE)
     903                 :            :         {
     904                 :          0 :           fbit2 = GET_MODE_FBIT (m2);
     905                 :          0 :           ibit2 = GET_MODE_IBIT (m2);
     906                 :            :         }
     907                 :            :       else
     908                 :            :         {
     909                 :          0 :           fbit2 = 0;
     910                 :            :           /* Signed integers need to subtract one sign bit.  */
     911                 :          0 :           ibit2 = TYPE_PRECISION (t2) - (!TYPE_UNSIGNED (t2));
     912                 :            :         }
     913                 :            : 
     914                 :          0 :       max_ibit = ibit1 >= ibit2 ?  ibit1 : ibit2;
     915                 :          0 :       max_fbit = fbit1 >= fbit2 ?  fbit1 : fbit2;
     916                 :          0 :       return c_common_fixed_point_type_for_size (max_ibit, max_fbit, unsignedp,
     917                 :            :                                                  satp);
     918                 :            :     }
     919                 :            : 
     920                 :            :   /* Both real or both integers; use the one with greater precision.  */
     921                 :            : 
     922                 :    1540140 :   if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2))
     923                 :            :     return t1;
     924                 :     774196 :   else if (TYPE_PRECISION (t2) > TYPE_PRECISION (t1))
     925                 :            :     return t2;
     926                 :            : 
     927                 :            :   /* Same precision.  Prefer long longs to longs to ints when the
     928                 :            :      same precision, following the C99 rules on integer type rank
     929                 :            :      (which are equivalent to the C90 rules for C90 types).  */
     930                 :            : 
     931                 :     491144 :   if (TYPE_MAIN_VARIANT (t1) == long_long_unsigned_type_node
     932                 :     491144 :       || TYPE_MAIN_VARIANT (t2) == long_long_unsigned_type_node)
     933                 :            :     return long_long_unsigned_type_node;
     934                 :            : 
     935                 :     431907 :   if (TYPE_MAIN_VARIANT (t1) == long_long_integer_type_node
     936                 :     431907 :       || TYPE_MAIN_VARIANT (t2) == long_long_integer_type_node)
     937                 :            :     {
     938                 :       5757 :       if (TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
     939                 :        200 :         return long_long_unsigned_type_node;
     940                 :            :       else
     941                 :            :         return long_long_integer_type_node;
     942                 :            :     }
     943                 :            : 
     944                 :     426150 :   if (TYPE_MAIN_VARIANT (t1) == long_unsigned_type_node
     945                 :     426150 :       || TYPE_MAIN_VARIANT (t2) == long_unsigned_type_node)
     946                 :            :     return long_unsigned_type_node;
     947                 :            : 
     948                 :     352184 :   if (TYPE_MAIN_VARIANT (t1) == long_integer_type_node
     949                 :     352184 :       || TYPE_MAIN_VARIANT (t2) == long_integer_type_node)
     950                 :            :     {
     951                 :            :       /* But preserve unsignedness from the other type,
     952                 :            :          since long cannot hold all the values of an unsigned int.  */
     953                 :      21939 :       if (TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
     954                 :        107 :         return long_unsigned_type_node;
     955                 :            :       else
     956                 :            :         return long_integer_type_node;
     957                 :            :     }
     958                 :            : 
     959                 :            :   /* For floating types of the same TYPE_PRECISION (which we here
     960                 :            :      assume means either the same set of values, or sets of values
     961                 :            :      neither a subset of the other, with behavior being undefined in
     962                 :            :      the latter case), follow the rules from TS 18661-3: prefer
     963                 :            :      interchange types _FloatN, then standard types long double,
     964                 :            :      double, float, then extended types _FloatNx.  For extended types,
     965                 :            :      check them starting with _Float128x as that seems most consistent
     966                 :            :      in spirit with preferring long double to double; for interchange
     967                 :            :      types, also check in that order for consistency although it's not
     968                 :            :      possible for more than one of them to have the same
     969                 :            :      precision.  */
     970                 :    1643770 :   tree mv1 = TYPE_MAIN_VARIANT (t1);
     971                 :    1643770 :   tree mv2 = TYPE_MAIN_VARIANT (t2);
     972                 :            : 
     973                 :    1643770 :   for (int i = NUM_FLOATN_TYPES - 1; i >= 0; i--)
     974                 :    1315390 :     if (mv1 == FLOATN_TYPE_NODE (i) || mv2 == FLOATN_TYPE_NODE (i))
     975                 :       1866 :       return FLOATN_TYPE_NODE (i);
     976                 :            : 
     977                 :            :   /* Likewise, prefer long double to double even if same size.  */
     978                 :     328379 :   if (mv1 == long_double_type_node || mv2 == long_double_type_node)
     979                 :            :     return long_double_type_node;
     980                 :            : 
     981                 :            :   /* Likewise, prefer double to float even if same size.
     982                 :            :      We got a couple of embedded targets with 32 bit doubles, and the
     983                 :            :      pdp11 might have 64 bit floats.  */
     984                 :     326249 :   if (mv1 == double_type_node || mv2 == double_type_node)
     985                 :            :     return double_type_node;
     986                 :            : 
     987                 :     323985 :   if (mv1 == float_type_node || mv2 == float_type_node)
     988                 :            :     return float_type_node;
     989                 :            : 
     990                 :    1287730 :   for (int i = NUM_FLOATNX_TYPES - 1; i >= 0; i--)
     991                 :     965796 :     if (mv1 == FLOATNX_TYPE_NODE (i) || mv2 == FLOATNX_TYPE_NODE (i))
     992                 :          0 :       return FLOATNX_TYPE_NODE (i);
     993                 :            : 
     994                 :            :   /* Otherwise prefer the unsigned one.  */
     995                 :            : 
     996                 :     321932 :   if (TYPE_UNSIGNED (t1))
     997                 :            :     return t1;
     998                 :            :   else
     999                 :     135288 :     return t2;
    1000                 :            : }
    1001                 :            : 
    1002                 :            : /* Wrapper around c_common_type that is used by c-common.c and other
    1003                 :            :    front end optimizations that remove promotions.  ENUMERAL_TYPEs
    1004                 :            :    are allowed here and are converted to their compatible integer types.
    1005                 :            :    BOOLEAN_TYPEs are allowed here and return either boolean_type_node or
    1006                 :            :    preferably a non-Boolean type as the common type.  */
    1007                 :            : tree
    1008                 :      86322 : common_type (tree t1, tree t2)
    1009                 :            : {
    1010                 :      86322 :   if (TREE_CODE (t1) == ENUMERAL_TYPE)
    1011                 :          0 :     t1 = c_common_type_for_size (TYPE_PRECISION (t1), 1);
    1012                 :      86322 :   if (TREE_CODE (t2) == ENUMERAL_TYPE)
    1013                 :          1 :     t2 = c_common_type_for_size (TYPE_PRECISION (t2), 1);
    1014                 :            : 
    1015                 :            :   /* If both types are BOOLEAN_TYPE, then return boolean_type_node.  */
    1016                 :      86322 :   if (TREE_CODE (t1) == BOOLEAN_TYPE
    1017                 :          0 :       && TREE_CODE (t2) == BOOLEAN_TYPE)
    1018                 :          0 :     return boolean_type_node;
    1019                 :            : 
    1020                 :            :   /* If either type is BOOLEAN_TYPE, then return the other.  */
    1021                 :      86322 :   if (TREE_CODE (t1) == BOOLEAN_TYPE)
    1022                 :            :     return t2;
    1023                 :      86322 :   if (TREE_CODE (t2) == BOOLEAN_TYPE)
    1024                 :            :     return t1;
    1025                 :            : 
    1026                 :      86322 :   return c_common_type (t1, t2);
    1027                 :            : }
    1028                 :            : 
    1029                 :            : /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
    1030                 :            :    or various other operations.  Return 2 if they are compatible
    1031                 :            :    but a warning may be needed if you use them together.  */
    1032                 :            : 
    1033                 :            : int
    1034                 :   17043800 : comptypes (tree type1, tree type2)
    1035                 :            : {
    1036                 :   17043800 :   const struct tagged_tu_seen_cache * tagged_tu_seen_base1 = tagged_tu_seen_base;
    1037                 :   17043800 :   int val;
    1038                 :            : 
    1039                 :   17043800 :   val = comptypes_internal (type1, type2, NULL, NULL);
    1040                 :   34087500 :   free_all_tagged_tu_seen_up_to (tagged_tu_seen_base1);
    1041                 :            : 
    1042                 :   17043800 :   return val;
    1043                 :            : }
    1044                 :            : 
    1045                 :            : /* Like comptypes, but if it returns non-zero because enum and int are
    1046                 :            :    compatible, it sets *ENUM_AND_INT_P to true.  */
    1047                 :            : 
    1048                 :            : static int
    1049                 :    1069430 : comptypes_check_enum_int (tree type1, tree type2, bool *enum_and_int_p)
    1050                 :            : {
    1051                 :    1069430 :   const struct tagged_tu_seen_cache * tagged_tu_seen_base1 = tagged_tu_seen_base;
    1052                 :    1069430 :   int val;
    1053                 :            : 
    1054                 :    1069430 :   val = comptypes_internal (type1, type2, enum_and_int_p, NULL);
    1055                 :    2138870 :   free_all_tagged_tu_seen_up_to (tagged_tu_seen_base1);
    1056                 :            : 
    1057                 :    1069430 :   return val;
    1058                 :            : }
    1059                 :            : 
    1060                 :            : /* Like comptypes, but if it returns nonzero for different types, it
    1061                 :            :    sets *DIFFERENT_TYPES_P to true.  */
    1062                 :            : 
    1063                 :            : int
    1064                 :      70773 : comptypes_check_different_types (tree type1, tree type2,
    1065                 :            :                                  bool *different_types_p)
    1066                 :            : {
    1067                 :      70773 :   const struct tagged_tu_seen_cache * tagged_tu_seen_base1 = tagged_tu_seen_base;
    1068                 :      70773 :   int val;
    1069                 :            : 
    1070                 :      70773 :   val = comptypes_internal (type1, type2, NULL, different_types_p);
    1071                 :     141546 :   free_all_tagged_tu_seen_up_to (tagged_tu_seen_base1);
    1072                 :            : 
    1073                 :      70773 :   return val;
    1074                 :            : }
    1075                 :            : 
    1076                 :            : /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
    1077                 :            :    or various other operations.  Return 2 if they are compatible
    1078                 :            :    but a warning may be needed if you use them together.  If
    1079                 :            :    ENUM_AND_INT_P is not NULL, and one type is an enum and the other a
    1080                 :            :    compatible integer type, then this sets *ENUM_AND_INT_P to true;
    1081                 :            :    *ENUM_AND_INT_P is never set to false.  If DIFFERENT_TYPES_P is not
    1082                 :            :    NULL, and the types are compatible but different enough not to be
    1083                 :            :    permitted in C11 typedef redeclarations, then this sets
    1084                 :            :    *DIFFERENT_TYPES_P to true; *DIFFERENT_TYPES_P is never set to
    1085                 :            :    false, but may or may not be set if the types are incompatible.
    1086                 :            :    This differs from comptypes, in that we don't free the seen
    1087                 :            :    types.  */
    1088                 :            : 
    1089                 :            : static int
    1090                 :   22925300 : comptypes_internal (const_tree type1, const_tree type2, bool *enum_and_int_p,
    1091                 :            :                     bool *different_types_p)
    1092                 :            : {
    1093                 :   22925300 :   const_tree t1 = type1;
    1094                 :   22925300 :   const_tree t2 = type2;
    1095                 :   22925300 :   int attrval, val;
    1096                 :            : 
    1097                 :            :   /* Suppress errors caused by previously reported errors.  */
    1098                 :            : 
    1099                 :   22925300 :   if (t1 == t2 || !t1 || !t2
    1100                 :    3348480 :       || TREE_CODE (t1) == ERROR_MARK || TREE_CODE (t2) == ERROR_MARK)
    1101                 :            :     return 1;
    1102                 :            : 
    1103                 :            :   /* Enumerated types are compatible with integer types, but this is
    1104                 :            :      not transitive: two enumerated types in the same translation unit
    1105                 :            :      are compatible with each other only if they are the same type.  */
    1106                 :            : 
    1107                 :    3348480 :   if (TREE_CODE (t1) == ENUMERAL_TYPE && TREE_CODE (t2) != ENUMERAL_TYPE)
    1108                 :            :     {
    1109                 :        152 :       t1 = c_common_type_for_size (TYPE_PRECISION (t1), TYPE_UNSIGNED (t1));
    1110                 :        152 :       if (TREE_CODE (t2) != VOID_TYPE)
    1111                 :            :         {
    1112                 :        152 :           if (enum_and_int_p != NULL)
    1113                 :         59 :             *enum_and_int_p = true;
    1114                 :        152 :           if (different_types_p != NULL)
    1115                 :          1 :             *different_types_p = true;
    1116                 :            :         }
    1117                 :            :     }
    1118                 :    3348330 :   else if (TREE_CODE (t2) == ENUMERAL_TYPE && TREE_CODE (t1) != ENUMERAL_TYPE)
    1119                 :            :     {
    1120                 :       1902 :       t2 = c_common_type_for_size (TYPE_PRECISION (t2), TYPE_UNSIGNED (t2));
    1121                 :       1902 :       if (TREE_CODE (t1) != VOID_TYPE)
    1122                 :            :         {
    1123                 :       1010 :           if (enum_and_int_p != NULL)
    1124                 :          2 :             *enum_and_int_p = true;
    1125                 :       1010 :           if (different_types_p != NULL)
    1126                 :          3 :             *different_types_p = true;
    1127                 :            :         }
    1128                 :            :     }
    1129                 :            : 
    1130                 :    3348480 :   if (t1 == t2)
    1131                 :            :     return 1;
    1132                 :            : 
    1133                 :            :   /* Different classes of types can't be compatible.  */
    1134                 :            : 
    1135                 :    3348160 :   if (TREE_CODE (t1) != TREE_CODE (t2))
    1136                 :            :     return 0;
    1137                 :            : 
    1138                 :            :   /* Qualifiers must match. C99 6.7.3p9 */
    1139                 :            : 
    1140                 :    3045440 :   if (TYPE_QUALS (t1) != TYPE_QUALS (t2))
    1141                 :            :     return 0;
    1142                 :            : 
    1143                 :            :   /* Allow for two different type nodes which have essentially the same
    1144                 :            :      definition.  Note that we already checked for equality of the type
    1145                 :            :      qualifiers (just above).  */
    1146                 :            : 
    1147                 :    3022640 :   if (TREE_CODE (t1) != ARRAY_TYPE
    1148                 :    3022640 :       && TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
    1149                 :            :     return 1;
    1150                 :            : 
    1151                 :            :   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
    1152                 :    2777400 :   if (!(attrval = comp_type_attributes (t1, t2)))
    1153                 :            :      return 0;
    1154                 :            : 
    1155                 :            :   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
    1156                 :    2777380 :   val = 0;
    1157                 :            : 
    1158                 :    2777380 :   switch (TREE_CODE (t1))
    1159                 :            :     {
    1160                 :    1304840 :     case INTEGER_TYPE:
    1161                 :    1304840 :     case FIXED_POINT_TYPE:
    1162                 :    1304840 :     case REAL_TYPE:
    1163                 :            :       /* With these nodes, we can't determine type equivalence by
    1164                 :            :          looking at what is stored in the nodes themselves, because
    1165                 :            :          two nodes might have different TYPE_MAIN_VARIANTs but still
    1166                 :            :          represent the same type.  For example, wchar_t and int could
    1167                 :            :          have the same properties (TYPE_PRECISION, TYPE_MIN_VALUE,
    1168                 :            :          TYPE_MAX_VALUE, etc.), but have different TYPE_MAIN_VARIANTs
    1169                 :            :          and are distinct types.  On the other hand, int and the
    1170                 :            :          following typedef
    1171                 :            : 
    1172                 :            :            typedef int INT __attribute((may_alias));
    1173                 :            : 
    1174                 :            :          have identical properties, different TYPE_MAIN_VARIANTs, but
    1175                 :            :          represent the same type.  The canonical type system keeps
    1176                 :            :          track of equivalence in this case, so we fall back on it.  */
    1177                 :    1304840 :       return TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2);
    1178                 :            : 
    1179                 :     165625 :     case POINTER_TYPE:
    1180                 :            :       /* Do not remove mode information.  */
    1181                 :     331250 :       if (TYPE_MODE (t1) != TYPE_MODE (t2))
    1182                 :            :         break;
    1183                 :     165625 :       val = (TREE_TYPE (t1) == TREE_TYPE (t2)
    1184                 :     165625 :              ? 1 : comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2),
    1185                 :            :                                        enum_and_int_p, different_types_p));
    1186                 :            :       break;
    1187                 :            : 
    1188                 :    1161340 :     case FUNCTION_TYPE:
    1189                 :    1161340 :       val = function_types_compatible_p (t1, t2, enum_and_int_p,
    1190                 :            :                                          different_types_p);
    1191                 :    1161340 :       break;
    1192                 :            : 
    1193                 :       8932 :     case ARRAY_TYPE:
    1194                 :       8932 :       {
    1195                 :       8932 :         tree d1 = TYPE_DOMAIN (t1);
    1196                 :       8932 :         tree d2 = TYPE_DOMAIN (t2);
    1197                 :       8932 :         bool d1_variable, d2_variable;
    1198                 :       8932 :         bool d1_zero, d2_zero;
    1199                 :       8932 :         val = 1;
    1200                 :            : 
    1201                 :            :         /* Target types must match incl. qualifiers.  */
    1202                 :       8932 :         if (TREE_TYPE (t1) != TREE_TYPE (t2)
    1203                 :       8932 :             && (val = comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2),
    1204                 :            :                                           enum_and_int_p,
    1205                 :            :                                           different_types_p)) == 0)
    1206                 :            :           return 0;
    1207                 :            : 
    1208                 :       8607 :         if (different_types_p != NULL
    1209                 :        694 :             && (d1 == NULL_TREE) != (d2 == NULL_TREE))
    1210                 :          3 :           *different_types_p = true;
    1211                 :            :         /* Sizes must match unless one is missing or variable.  */
    1212                 :       8607 :         if (d1 == NULL_TREE || d2 == NULL_TREE || d1 == d2)
    1213                 :            :           break;
    1214                 :            : 
    1215                 :       3168 :         d1_zero = !TYPE_MAX_VALUE (d1);
    1216                 :       3168 :         d2_zero = !TYPE_MAX_VALUE (d2);
    1217                 :            : 
    1218                 :       6336 :         d1_variable = (!d1_zero
    1219                 :       3168 :                        && (TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST
    1220                 :       3161 :                            || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST));
    1221                 :       6336 :         d2_variable = (!d2_zero
    1222                 :       3168 :                        && (TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
    1223                 :       3054 :                            || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST));
    1224                 :       3168 :         d1_variable = d1_variable || (d1_zero && c_vla_type_p (t1));
    1225                 :       3168 :         d2_variable = d2_variable || (d2_zero && c_vla_type_p (t2));
    1226                 :            : 
    1227                 :       3168 :         if (different_types_p != NULL
    1228                 :       3168 :             && d1_variable != d2_variable)
    1229                 :          1 :           *different_types_p = true;
    1230                 :       3168 :         if (d1_variable || d2_variable)
    1231                 :            :           break;
    1232                 :       1889 :         if (d1_zero && d2_zero)
    1233                 :            :           break;
    1234                 :       1889 :         if (d1_zero || d2_zero
    1235                 :       1778 :             || !tree_int_cst_equal (TYPE_MIN_VALUE (d1), TYPE_MIN_VALUE (d2))
    1236                 :       3667 :             || !tree_int_cst_equal (TYPE_MAX_VALUE (d1), TYPE_MAX_VALUE (d2)))
    1237                 :            :           val = 0;
    1238                 :            : 
    1239                 :            :         break;
    1240                 :            :       }
    1241                 :            : 
    1242                 :         93 :     case ENUMERAL_TYPE:
    1243                 :         93 :     case RECORD_TYPE:
    1244                 :         93 :     case UNION_TYPE:
    1245                 :         93 :       if (val != 1 && !same_translation_unit_p (t1, t2))
    1246                 :            :         {
    1247                 :          0 :           tree a1 = TYPE_ATTRIBUTES (t1);
    1248                 :          0 :           tree a2 = TYPE_ATTRIBUTES (t2);
    1249                 :            : 
    1250                 :          0 :           if (! attribute_list_contained (a1, a2)
    1251                 :          0 :               && ! attribute_list_contained (a2, a1))
    1252                 :            :             break;
    1253                 :            : 
    1254                 :          0 :           if (attrval != 2)
    1255                 :          0 :             return tagged_types_tu_compatible_p (t1, t2, enum_and_int_p,
    1256                 :          0 :                                                  different_types_p);
    1257                 :          0 :           val = tagged_types_tu_compatible_p (t1, t2, enum_and_int_p,
    1258                 :            :                                               different_types_p);
    1259                 :            :         }
    1260                 :            :       break;
    1261                 :            : 
    1262                 :     136084 :     case VECTOR_TYPE:
    1263                 :     136084 :       val = (known_eq (TYPE_VECTOR_SUBPARTS (t1), TYPE_VECTOR_SUBPARTS (t2))
    1264                 :     272164 :              && comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2),
    1265                 :            :                                     enum_and_int_p, different_types_p));
    1266                 :     136084 :       break;
    1267                 :            : 
    1268                 :            :     default:
    1269                 :            :       break;
    1270                 :            :     }
    1271                 :    1472210 :   return attrval == 2 && val == 1 ? 2 : val;
    1272                 :            : }
    1273                 :            : 
    1274                 :            : /* Return 1 if TTL and TTR are pointers to types that are equivalent, ignoring
    1275                 :            :    their qualifiers, except for named address spaces.  If the pointers point to
    1276                 :            :    different named addresses, then we must determine if one address space is a
    1277                 :            :    subset of the other.  */
    1278                 :            : 
    1279                 :            : static int
    1280                 :    1069430 : comp_target_types (location_t location, tree ttl, tree ttr)
    1281                 :            : {
    1282                 :    1069430 :   int val;
    1283                 :    1069430 :   int val_ped;
    1284                 :    1069430 :   tree mvl = TREE_TYPE (ttl);
    1285                 :    1069430 :   tree mvr = TREE_TYPE (ttr);
    1286                 :    1069430 :   addr_space_t asl = TYPE_ADDR_SPACE (mvl);
    1287                 :    1069430 :   addr_space_t asr = TYPE_ADDR_SPACE (mvr);
    1288                 :    1069430 :   addr_space_t as_common;
    1289                 :    1069430 :   bool enum_and_int_p;
    1290                 :            : 
    1291                 :            :   /* Fail if pointers point to incompatible address spaces.  */
    1292                 :    1069430 :   if (!addr_space_superset (asl, asr, &as_common))
    1293                 :            :     return 0;
    1294                 :            : 
    1295                 :            :   /* For pedantic record result of comptypes on arrays before losing
    1296                 :            :      qualifiers on the element type below. */
    1297                 :    1069430 :   val_ped = 1;
    1298                 :            : 
    1299                 :    1069430 :   if (TREE_CODE (mvl) == ARRAY_TYPE
    1300                 :       1720 :       && TREE_CODE (mvr) == ARRAY_TYPE)
    1301                 :       1704 :     val_ped = comptypes (mvl, mvr);
    1302                 :            : 
    1303                 :            :   /* Qualifiers on element types of array types that are
    1304                 :            :      pointer targets are lost by taking their TYPE_MAIN_VARIANT.  */
    1305                 :            : 
    1306                 :    1069430 :   mvl = (TYPE_ATOMIC (strip_array_types (mvl))
    1307                 :        123 :          ? c_build_qualified_type (TYPE_MAIN_VARIANT (mvl), TYPE_QUAL_ATOMIC)
    1308                 :    2138740 :          : TYPE_MAIN_VARIANT (mvl));
    1309                 :            : 
    1310                 :    1069430 :   mvr = (TYPE_ATOMIC (strip_array_types (mvr))
    1311                 :        117 :          ? c_build_qualified_type (TYPE_MAIN_VARIANT (mvr), TYPE_QUAL_ATOMIC)
    1312                 :    2138750 :          : TYPE_MAIN_VARIANT (mvr));
    1313                 :            : 
    1314                 :    1069430 :   enum_and_int_p = false;
    1315                 :    1069430 :   val = comptypes_check_enum_int (mvl, mvr, &enum_and_int_p);
    1316                 :            : 
    1317                 :    1069430 :   if (val == 1 && val_ped != 1)
    1318                 :         93 :     pedwarn (location, OPT_Wpedantic, "pointers to arrays with different qualifiers "
    1319                 :            :                                       "are incompatible in ISO C");
    1320                 :            : 
    1321                 :    1069430 :   if (val == 2)
    1322                 :          0 :     pedwarn (location, OPT_Wpedantic, "types are not quite compatible");
    1323                 :            : 
    1324                 :    1069430 :   if (val == 1 && enum_and_int_p && warn_cxx_compat)
    1325                 :          2 :     warning_at (location, OPT_Wc___compat,
    1326                 :            :                 "pointer target types incompatible in C++");
    1327                 :            : 
    1328                 :            :   return val;
    1329                 :            : }
    1330                 :            : 
    1331                 :            : /* Subroutines of `comptypes'.  */
    1332                 :            : 
    1333                 :            : /* Determine whether two trees derive from the same translation unit.
    1334                 :            :    If the CONTEXT chain ends in a null, that tree's context is still
    1335                 :            :    being parsed, so if two trees have context chains ending in null,
    1336                 :            :    they're in the same translation unit.  */
    1337                 :            : 
    1338                 :            : bool
    1339                 :        318 : same_translation_unit_p (const_tree t1, const_tree t2)
    1340                 :            : {
    1341                 :        654 :   while (t1 && TREE_CODE (t1) != TRANSLATION_UNIT_DECL)
    1342                 :        336 :     switch (TREE_CODE_CLASS (TREE_CODE (t1)))
    1343                 :            :       {
    1344                 :        236 :       case tcc_declaration:
    1345                 :        236 :         t1 = DECL_CONTEXT (t1); break;
    1346                 :        100 :       case tcc_type:
    1347                 :        100 :         t1 = TYPE_CONTEXT (t1); break;
    1348                 :          0 :       case tcc_exceptional:
    1349                 :          0 :         t1 = BLOCK_SUPERCONTEXT (t1); break;  /* assume block */
    1350                 :          0 :       default: gcc_unreachable ();
    1351                 :            :       }
    1352                 :            : 
    1353                 :        656 :   while (t2 && TREE_CODE (t2) != TRANSLATION_UNIT_DECL)
    1354                 :        338 :     switch (TREE_CODE_CLASS (TREE_CODE (t2)))
    1355                 :            :       {
    1356                 :        245 :       case tcc_declaration:
    1357                 :        245 :         t2 = DECL_CONTEXT (t2); break;
    1358                 :         93 :       case tcc_type:
    1359                 :         93 :         t2 = TYPE_CONTEXT (t2); break;
    1360                 :          0 :       case tcc_exceptional:
    1361                 :          0 :         t2 = BLOCK_SUPERCONTEXT (t2); break;  /* assume block */
    1362                 :          0 :       default: gcc_unreachable ();
    1363                 :            :       }
    1364                 :            : 
    1365                 :        318 :   return t1 == t2;
    1366                 :            : }
    1367                 :            : 
    1368                 :            : /* Allocate the seen two types, assuming that they are compatible. */
    1369                 :            : 
    1370                 :            : static struct tagged_tu_seen_cache *
    1371                 :          0 : alloc_tagged_tu_seen_cache (const_tree t1, const_tree t2)
    1372                 :            : {
    1373                 :          0 :   struct tagged_tu_seen_cache *tu = XNEW (struct tagged_tu_seen_cache);
    1374                 :          0 :   tu->next = tagged_tu_seen_base;
    1375                 :          0 :   tu->t1 = t1;
    1376                 :          0 :   tu->t2 = t2;
    1377                 :            : 
    1378                 :          0 :   tagged_tu_seen_base = tu;
    1379                 :            : 
    1380                 :            :   /* The C standard says that two structures in different translation
    1381                 :            :      units are compatible with each other only if the types of their
    1382                 :            :      fields are compatible (among other things).  We assume that they
    1383                 :            :      are compatible until proven otherwise when building the cache.
    1384                 :            :      An example where this can occur is:
    1385                 :            :      struct a
    1386                 :            :      {
    1387                 :            :        struct a *next;
    1388                 :            :      };
    1389                 :            :      If we are comparing this against a similar struct in another TU,
    1390                 :            :      and did not assume they were compatible, we end up with an infinite
    1391                 :            :      loop.  */
    1392                 :          0 :   tu->val = 1;
    1393                 :          0 :   return tu;
    1394                 :            : }
    1395                 :            : 
    1396                 :            : /* Free the seen types until we get to TU_TIL. */
    1397                 :            : 
    1398                 :            : static void
    1399                 :   18184000 : free_all_tagged_tu_seen_up_to (const struct tagged_tu_seen_cache *tu_til)
    1400                 :            : {
    1401                 :   18184000 :   const struct tagged_tu_seen_cache *tu = tagged_tu_seen_base;
    1402                 :   18184000 :   while (tu != tu_til)
    1403                 :            :     {
    1404                 :          0 :       const struct tagged_tu_seen_cache *const tu1
    1405                 :            :         = (const struct tagged_tu_seen_cache *) tu;
    1406                 :          0 :       tu = tu1->next;
    1407                 :          0 :       free (CONST_CAST (struct tagged_tu_seen_cache *, tu1));
    1408                 :            :     }
    1409                 :   18184000 :   tagged_tu_seen_base = tu_til;
    1410                 :          0 : }
    1411                 :            : 
    1412                 :            : /* Return 1 if two 'struct', 'union', or 'enum' types T1 and T2 are
    1413                 :            :    compatible.  If the two types are not the same (which has been
    1414                 :            :    checked earlier), this can only happen when multiple translation
    1415                 :            :    units are being compiled.  See C99 6.2.7 paragraph 1 for the exact
    1416                 :            :    rules.  ENUM_AND_INT_P and DIFFERENT_TYPES_P are as in
    1417                 :            :    comptypes_internal.  */
    1418                 :            : 
    1419                 :            : static int
    1420                 :          0 : tagged_types_tu_compatible_p (const_tree t1, const_tree t2,
    1421                 :            :                               bool *enum_and_int_p, bool *different_types_p)
    1422                 :            : {
    1423                 :          0 :   tree s1, s2;
    1424                 :          0 :   bool needs_warning = false;
    1425                 :            : 
    1426                 :            :   /* We have to verify that the tags of the types are the same.  This
    1427                 :            :      is harder than it looks because this may be a typedef, so we have
    1428                 :            :      to go look at the original type.  It may even be a typedef of a
    1429                 :            :      typedef...
    1430                 :            :      In the case of compiler-created builtin structs the TYPE_DECL
    1431                 :            :      may be a dummy, with no DECL_ORIGINAL_TYPE.  Don't fault.  */
    1432                 :          0 :   while (TYPE_NAME (t1)
    1433                 :          0 :          && TREE_CODE (TYPE_NAME (t1)) == TYPE_DECL
    1434                 :          0 :          && DECL_ORIGINAL_TYPE (TYPE_NAME (t1)))
    1435                 :          0 :     t1 = DECL_ORIGINAL_TYPE (TYPE_NAME (t1));
    1436                 :            : 
    1437                 :          0 :   while (TYPE_NAME (t2)
    1438                 :          0 :          && TREE_CODE (TYPE_NAME (t2)) == TYPE_DECL
    1439                 :          0 :          && DECL_ORIGINAL_TYPE (TYPE_NAME (t2)))
    1440                 :          0 :     t2 = DECL_ORIGINAL_TYPE (TYPE_NAME (t2));
    1441                 :            : 
    1442                 :            :   /* C90 didn't have the requirement that the two tags be the same.  */
    1443                 :          0 :   if (flag_isoc99 && TYPE_NAME (t1) != TYPE_NAME (t2))
    1444                 :            :     return 0;
    1445                 :            : 
    1446                 :            :   /* C90 didn't say what happened if one or both of the types were
    1447                 :            :      incomplete; we choose to follow C99 rules here, which is that they
    1448                 :            :      are compatible.  */
    1449                 :          0 :   if (TYPE_SIZE (t1) == NULL
    1450                 :          0 :       || TYPE_SIZE (t2) == NULL)
    1451                 :            :     return 1;
    1452                 :            : 
    1453                 :          0 :   {
    1454                 :          0 :     const struct tagged_tu_seen_cache * tts_i;
    1455                 :          0 :     for (tts_i = tagged_tu_seen_base; tts_i != NULL; tts_i = tts_i->next)
    1456                 :          0 :       if (tts_i->t1 == t1 && tts_i->t2 == t2)
    1457                 :          0 :         return tts_i->val;
    1458                 :            :   }
    1459                 :            : 
    1460                 :          0 :   switch (TREE_CODE (t1))
    1461                 :            :     {
    1462                 :          0 :     case ENUMERAL_TYPE:
    1463                 :          0 :       {
    1464                 :          0 :         struct tagged_tu_seen_cache *tu = alloc_tagged_tu_seen_cache (t1, t2);
    1465                 :            :         /* Speed up the case where the type values are in the same order.  */
    1466                 :          0 :         tree tv1 = TYPE_VALUES (t1);
    1467                 :          0 :         tree tv2 = TYPE_VALUES (t2);
    1468                 :            : 
    1469                 :          0 :         if (tv1 == tv2)
    1470                 :            :           {
    1471                 :            :             return 1;
    1472                 :            :           }
    1473                 :            : 
    1474                 :          0 :         for (;tv1 && tv2; tv1 = TREE_CHAIN (tv1), tv2 = TREE_CHAIN (tv2))
    1475                 :            :           {
    1476                 :          0 :             if (TREE_PURPOSE (tv1) != TREE_PURPOSE (tv2))
    1477                 :            :               break;
    1478                 :          0 :             if (simple_cst_equal (TREE_VALUE (tv1), TREE_VALUE (tv2)) != 1)
    1479                 :            :               {
    1480                 :          0 :                 tu->val = 0;
    1481                 :          0 :                 return 0;
    1482                 :            :               }
    1483                 :            :           }
    1484                 :            : 
    1485                 :          0 :         if (tv1 == NULL_TREE && tv2 == NULL_TREE)
    1486                 :            :           {
    1487                 :            :             return 1;
    1488                 :            :           }
    1489                 :          0 :         if (tv1 == NULL_TREE || tv2 == NULL_TREE)
    1490                 :            :           {
    1491                 :          0 :             tu->val = 0;
    1492                 :          0 :             return 0;
    1493                 :            :           }
    1494                 :            : 
    1495                 :          0 :         if (list_length (TYPE_VALUES (t1)) != list_length (TYPE_VALUES (t2)))
    1496                 :            :           {
    1497                 :          0 :             tu->val = 0;
    1498                 :          0 :             return 0;
    1499                 :            :           }
    1500                 :            : 
    1501                 :          0 :         for (s1 = TYPE_VALUES (t1); s1; s1 = TREE_CHAIN (s1))
    1502                 :            :           {
    1503                 :          0 :             s2 = purpose_member (TREE_PURPOSE (s1), TYPE_VALUES (t2));
    1504                 :          0 :             if (s2 == NULL
    1505                 :          0 :                 || simple_cst_equal (TREE_VALUE (s1), TREE_VALUE (s2)) != 1)
    1506                 :            :               {
    1507                 :          0 :                 tu->val = 0;
    1508                 :          0 :                 return 0;
    1509                 :            :               }
    1510                 :            :           }
    1511                 :            :         return 1;
    1512                 :            :       }
    1513                 :            : 
    1514                 :          0 :     case UNION_TYPE:
    1515                 :          0 :       {
    1516                 :          0 :         struct tagged_tu_seen_cache *tu = alloc_tagged_tu_seen_cache (t1, t2);
    1517                 :          0 :         if (list_length (TYPE_FIELDS (t1)) != list_length (TYPE_FIELDS (t2)))
    1518                 :            :           {
    1519                 :          0 :             tu->val = 0;
    1520                 :          0 :             return 0;
    1521                 :            :           }
    1522                 :            : 
    1523                 :            :         /*  Speed up the common case where the fields are in the same order. */
    1524                 :          0 :         for (s1 = TYPE_FIELDS (t1), s2 = TYPE_FIELDS (t2); s1 && s2;
    1525                 :          0 :              s1 = DECL_CHAIN (s1), s2 = DECL_CHAIN (s2))
    1526                 :            :           {
    1527                 :          0 :             int result;
    1528                 :            : 
    1529                 :          0 :             if (DECL_NAME (s1) != DECL_NAME (s2))
    1530                 :            :               break;
    1531                 :          0 :             result = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2),
    1532                 :            :                                          enum_and_int_p, different_types_p);
    1533                 :            : 
    1534                 :          0 :             if (result != 1 && !DECL_NAME (s1))
    1535                 :            :               break;
    1536                 :          0 :             if (result == 0)
    1537                 :            :               {
    1538                 :          0 :                 tu->val = 0;
    1539                 :          0 :                 return 0;
    1540                 :            :               }
    1541                 :          0 :             if (result == 2)
    1542                 :          0 :               needs_warning = true;
    1543                 :            : 
    1544                 :          0 :             if (TREE_CODE (s1) == FIELD_DECL
    1545                 :          0 :                 && simple_cst_equal (DECL_FIELD_BIT_OFFSET (s1),
    1546                 :          0 :                                      DECL_FIELD_BIT_OFFSET (s2)) != 1)
    1547                 :            :               {
    1548                 :          0 :                 tu->val = 0;
    1549                 :          0 :                 return 0;
    1550                 :            :               }
    1551                 :            :           }
    1552                 :          0 :         if (!s1 && !s2)
    1553                 :            :           {
    1554                 :          0 :             tu->val = needs_warning ? 2 : 1;
    1555                 :          0 :             return tu->val;
    1556                 :            :           }
    1557                 :            : 
    1558                 :          0 :         for (s1 = TYPE_FIELDS (t1); s1; s1 = DECL_CHAIN (s1))
    1559                 :            :           {
    1560                 :          0 :             bool ok = false;
    1561                 :            : 
    1562                 :          0 :             for (s2 = TYPE_FIELDS (t2); s2; s2 = DECL_CHAIN (s2))
    1563                 :          0 :               if (DECL_NAME (s1) == DECL_NAME (s2))
    1564                 :            :                 {
    1565                 :          0 :                   int result;
    1566                 :            : 
    1567                 :          0 :                   result = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2),
    1568                 :            :                                                enum_and_int_p,
    1569                 :            :                                                different_types_p);
    1570                 :            : 
    1571                 :          0 :                   if (result != 1 && !DECL_NAME (s1))
    1572                 :          0 :                     continue;
    1573                 :          0 :                   if (result == 0)
    1574                 :            :                     {
    1575                 :          0 :                       tu->val = 0;
    1576                 :          0 :                       return 0;
    1577                 :            :                     }
    1578                 :          0 :                   if (result == 2)
    1579                 :          0 :                     needs_warning = true;
    1580                 :            : 
    1581                 :          0 :                   if (TREE_CODE (s1) == FIELD_DECL
    1582                 :          0 :                       && simple_cst_equal (DECL_FIELD_BIT_OFFSET (s1),
    1583                 :          0 :                                            DECL_FIELD_BIT_OFFSET (s2)) != 1)
    1584                 :            :                     break;
    1585                 :            : 
    1586                 :            :                   ok = true;
    1587                 :            :                   break;
    1588                 :            :                 }
    1589                 :          0 :             if (!ok)
    1590                 :            :               {
    1591                 :          0 :                 tu->val = 0;
    1592                 :          0 :                 return 0;
    1593                 :            :               }
    1594                 :            :           }
    1595                 :          0 :         tu->val = needs_warning ? 2 : 10;
    1596                 :          0 :         return tu->val;
    1597                 :            :       }
    1598                 :            : 
    1599                 :          0 :     case RECORD_TYPE:
    1600                 :          0 :       {
    1601                 :          0 :         struct tagged_tu_seen_cache *tu = alloc_tagged_tu_seen_cache (t1, t2);
    1602                 :            : 
    1603                 :          0 :         for (s1 = TYPE_FIELDS (t1), s2 = TYPE_FIELDS (t2);
    1604                 :          0 :              s1 && s2;
    1605                 :          0 :              s1 = DECL_CHAIN (s1), s2 = DECL_CHAIN (s2))
    1606                 :            :           {
    1607                 :          0 :             int result;
    1608                 :          0 :             if (TREE_CODE (s1) != TREE_CODE (s2)
    1609                 :          0 :                 || DECL_NAME (s1) != DECL_NAME (s2))
    1610                 :            :               break;
    1611                 :          0 :             result = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2),
    1612                 :            :                                          enum_and_int_p, different_types_p);
    1613                 :          0 :             if (result == 0)
    1614                 :            :               break;
    1615                 :          0 :             if (result == 2)
    1616                 :          0 :               needs_warning = true;
    1617                 :            : 
    1618                 :          0 :             if (TREE_CODE (s1) == FIELD_DECL
    1619                 :          0 :                 && simple_cst_equal (DECL_FIELD_BIT_OFFSET (s1),
    1620                 :          0 :                                      DECL_FIELD_BIT_OFFSET (s2)) != 1)
    1621                 :            :               break;
    1622                 :            :           }
    1623                 :          0 :         if (s1 && s2)
    1624                 :          0 :           tu->val = 0;
    1625                 :            :         else
    1626                 :          0 :           tu->val = needs_warning ? 2 : 1;
    1627                 :          0 :         return tu->val;
    1628                 :            :       }
    1629                 :            : 
    1630                 :          0 :     default:
    1631                 :          0 :       gcc_unreachable ();
    1632                 :            :     }
    1633                 :            : }
    1634                 :            : 
    1635                 :            : /* Return 1 if two function types F1 and F2 are compatible.
    1636                 :            :    If either type specifies no argument types,
    1637                 :            :    the other must specify a fixed number of self-promoting arg types.
    1638                 :            :    Otherwise, if one type specifies only the number of arguments,
    1639                 :            :    the other must specify that number of self-promoting arg types.
    1640                 :            :    Otherwise, the argument types must match.
    1641                 :            :    ENUM_AND_INT_P and DIFFERENT_TYPES_P are as in comptypes_internal.  */
    1642                 :            : 
    1643                 :            : static int
    1644                 :    1161340 : function_types_compatible_p (const_tree f1, const_tree f2,
    1645                 :            :                              bool *enum_and_int_p, bool *different_types_p)
    1646                 :            : {
    1647                 :    1161340 :   tree args1, args2;
    1648                 :            :   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
    1649                 :    1161340 :   int val = 1;
    1650                 :    1161340 :   int val1;
    1651                 :    1161340 :   tree ret1, ret2;
    1652                 :            : 
    1653                 :    1161340 :   ret1 = TREE_TYPE (f1);
    1654                 :    1161340 :   ret2 = TREE_TYPE (f2);
    1655                 :            : 
    1656                 :            :   /* 'volatile' qualifiers on a function's return type used to mean
    1657                 :            :      the function is noreturn.  */
    1658                 :    1161340 :   if (TYPE_VOLATILE (ret1) != TYPE_VOLATILE (ret2))
    1659                 :          9 :     pedwarn (input_location, 0, "function return types not compatible due to %<volatile%>");
    1660                 :    1161340 :   if (TYPE_VOLATILE (ret1))
    1661                 :          3 :     ret1 = build_qualified_type (TYPE_MAIN_VARIANT (ret1),
    1662                 :          3 :                                  TYPE_QUALS (ret1) & ~TYPE_QUAL_VOLATILE);
    1663                 :    1161340 :   if (TYPE_VOLATILE (ret2))
    1664                 :          6 :     ret2 = build_qualified_type (TYPE_MAIN_VARIANT (ret2),
    1665                 :          6 :                                  TYPE_QUALS (ret2) & ~TYPE_QUAL_VOLATILE);
    1666                 :    1161340 :   val = comptypes_internal (ret1, ret2, enum_and_int_p, different_types_p);
    1667                 :    1161340 :   if (val == 0)
    1668                 :            :     return 0;
    1669                 :            : 
    1670                 :    1143940 :   args1 = TYPE_ARG_TYPES (f1);
    1671                 :    1143940 :   args2 = TYPE_ARG_TYPES (f2);
    1672                 :            : 
    1673                 :    1143940 :   if (different_types_p != NULL
    1674                 :         12 :       && (args1 == NULL_TREE) != (args2 == NULL_TREE))
    1675                 :          1 :     *different_types_p = true;
    1676                 :            : 
    1677                 :            :   /* An unspecified parmlist matches any specified parmlist
    1678                 :            :      whose argument types don't need default promotions.  */
    1679                 :            : 
    1680                 :    1143940 :   if (args1 == NULL_TREE)
    1681                 :            :     {
    1682                 :      16252 :       if (!self_promoting_args_p (args2))
    1683                 :            :         return 0;
    1684                 :            :       /* If one of these types comes from a non-prototype fn definition,
    1685                 :            :          compare that with the other type's arglist.
    1686                 :            :          If they don't match, ask for a warning (but no error).  */
    1687                 :      15588 :       if (TYPE_ACTUAL_ARG_TYPES (f1)
    1688                 :      15588 :           && type_lists_compatible_p (args2, TYPE_ACTUAL_ARG_TYPES (f1),
    1689                 :            :                                       enum_and_int_p, different_types_p) != 1)
    1690                 :            :         val = 2;
    1691                 :      15588 :       return val;
    1692                 :            :     }
    1693                 :    1127690 :   if (args2 == NULL_TREE)
    1694                 :            :     {
    1695                 :       2412 :       if (!self_promoting_args_p (args1))
    1696                 :            :         return 0;
    1697                 :       2343 :       if (TYPE_ACTUAL_ARG_TYPES (f2)
    1698                 :       2343 :           && type_lists_compatible_p (args1, TYPE_ACTUAL_ARG_TYPES (f2),
    1699                 :            :                                       enum_and_int_p, different_types_p) != 1)
    1700                 :            :         val = 2;
    1701                 :       2343 :       return val;
    1702                 :            :     }
    1703                 :            : 
    1704                 :            :   /* Both types have argument lists: compare them and propagate results.  */
    1705                 :    1125270 :   val1 = type_lists_compatible_p (args1, args2, enum_and_int_p,
    1706                 :            :                                   different_types_p);
    1707                 :    1125270 :   return val1 != 1 ? val1 : val;
    1708                 :            : }
    1709                 :            : 
    1710                 :            : /* Check two lists of types for compatibility, returning 0 for
    1711                 :            :    incompatible, 1 for compatible, or 2 for compatible with
    1712                 :            :    warning.  ENUM_AND_INT_P and DIFFERENT_TYPES_P are as in
    1713                 :            :    comptypes_internal.  */
    1714                 :            : 
    1715                 :            : static int
    1716                 :    1125320 : type_lists_compatible_p (const_tree args1, const_tree args2,
    1717                 :            :                          bool *enum_and_int_p, bool *different_types_p)
    1718                 :            : {
    1719                 :            :   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
    1720                 :    1125320 :   int val = 1;
    1721                 :    1125320 :   int newval = 0;
    1722                 :            : 
    1723                 :    7466740 :   while (1)
    1724                 :            :     {
    1725                 :    4296030 :       tree a1, mv1, a2, mv2;
    1726                 :    4296030 :       if (args1 == NULL_TREE && args2 == NULL_TREE)
    1727                 :    1018660 :         return val;
    1728                 :            :       /* If one list is shorter than the other,
    1729                 :            :          they fail to match.  */
    1730                 :    3277360 :       if (args1 == NULL_TREE || args2 == NULL_TREE)
    1731                 :            :         return 0;
    1732                 :    3277360 :       mv1 = a1 = TREE_VALUE (args1);
    1733                 :    3277360 :       mv2 = a2 = TREE_VALUE (args2);
    1734                 :    3277360 :       if (mv1 && mv1 != error_mark_node && TREE_CODE (mv1) != ARRAY_TYPE)
    1735                 :    3277360 :         mv1 = (TYPE_ATOMIC (mv1)
    1736                 :          7 :                ? c_build_qualified_type (TYPE_MAIN_VARIANT (mv1),
    1737                 :            :                                          TYPE_QUAL_ATOMIC)
    1738                 :    3277360 :                : TYPE_MAIN_VARIANT (mv1));
    1739                 :    3277360 :       if (mv2 && mv2 != error_mark_node && TREE_CODE (mv2) != ARRAY_TYPE)
    1740                 :    3277360 :         mv2 = (TYPE_ATOMIC (mv2)
    1741                 :          8 :                ? c_build_qualified_type (TYPE_MAIN_VARIANT (mv2),
    1742                 :            :                                          TYPE_QUAL_ATOMIC)
    1743                 :    3277360 :                : TYPE_MAIN_VARIANT (mv2));
    1744                 :            :       /* A null pointer instead of a type
    1745                 :            :          means there is supposed to be an argument
    1746                 :            :          but nothing is specified about what type it has.
    1747                 :            :          So match anything that self-promotes.  */
    1748                 :    3277360 :       if (different_types_p != NULL
    1749                 :         19 :           && (a1 == NULL_TREE) != (a2 == NULL_TREE))
    1750                 :          0 :         *different_types_p = true;
    1751                 :    3277360 :       if (a1 == NULL_TREE)
    1752                 :            :         {
    1753                 :          0 :           if (c_type_promotes_to (a2) != a2)
    1754                 :            :             return 0;
    1755                 :            :         }
    1756                 :    3277360 :       else if (a2 == NULL_TREE)
    1757                 :            :         {
    1758                 :          0 :           if (c_type_promotes_to (a1) != a1)
    1759                 :            :             return 0;
    1760                 :            :         }
    1761                 :            :       /* If one of the lists has an error marker, ignore this arg.  */
    1762                 :    3277360 :       else if (TREE_CODE (a1) == ERROR_MARK
    1763                 :    3277360 :                || TREE_CODE (a2) == ERROR_MARK)
    1764                 :            :         ;
    1765                 :    3277360 :       else if (!(newval = comptypes_internal (mv1, mv2, enum_and_int_p,
    1766                 :            :                                               different_types_p)))
    1767                 :            :         {
    1768                 :     106722 :           if (different_types_p != NULL)
    1769                 :          0 :             *different_types_p = true;
    1770                 :            :           /* Allow  wait (union {union wait *u; int *i} *)
    1771                 :            :              and  wait (union wait *)  to be compatible.  */
    1772                 :     106722 :           if (TREE_CODE (a1) == UNION_TYPE
    1773                 :         68 :               && (TYPE_NAME (a1) == NULL_TREE
    1774                 :         47 :                   || TYPE_TRANSPARENT_AGGR (a1))
    1775                 :         68 :               && TREE_CODE (TYPE_SIZE (a1)) == INTEGER_CST
    1776                 :     106790 :               && tree_int_cst_equal (TYPE_SIZE (a1),
    1777                 :         68 :                                      TYPE_SIZE (a2)))
    1778                 :            :             {
    1779                 :         68 :               tree memb;
    1780                 :        152 :               for (memb = TYPE_FIELDS (a1);
    1781                 :         84 :                    memb; memb = DECL_CHAIN (memb))
    1782                 :            :                 {
    1783                 :         82 :                   tree mv3 = TREE_TYPE (memb);
    1784                 :         82 :                   if (mv3 && mv3 != error_mark_node
    1785                 :         82 :                       && TREE_CODE (mv3) != ARRAY_TYPE)
    1786                 :         82 :                     mv3 = (TYPE_ATOMIC (mv3)
    1787                 :          0 :                            ? c_build_qualified_type (TYPE_MAIN_VARIANT (mv3),
    1788                 :            :                                                      TYPE_QUAL_ATOMIC)
    1789                 :         82 :                            : TYPE_MAIN_VARIANT (mv3));
    1790                 :         82 :                   if (comptypes_internal (mv3, mv2, enum_and_int_p,
    1791                 :            :                                           different_types_p))
    1792                 :            :                     break;
    1793                 :            :                 }
    1794                 :         68 :               if (memb == NULL_TREE)
    1795                 :            :                 return 0;
    1796                 :            :             }
    1797                 :     106654 :           else if (TREE_CODE (a2) == UNION_TYPE
    1798                 :          9 :                    && (TYPE_NAME (a2) == NULL_TREE
    1799                 :          2 :                        || TYPE_TRANSPARENT_AGGR (a2))
    1800                 :          9 :                    && TREE_CODE (TYPE_SIZE (a2)) == INTEGER_CST
    1801                 :     106663 :                    && tree_int_cst_equal (TYPE_SIZE (a2),
    1802                 :          9 :                                           TYPE_SIZE (a1)))
    1803                 :            :             {
    1804                 :          9 :               tree memb;
    1805                 :         22 :               for (memb = TYPE_FIELDS (a2);
    1806                 :         13 :                    memb; memb = DECL_CHAIN (memb))
    1807                 :            :                 {
    1808                 :         11 :                   tree mv3 = TREE_TYPE (memb);
    1809                 :         11 :                   if (mv3 && mv3 != error_mark_node
    1810                 :         11 :                       && TREE_CODE (mv3) != ARRAY_TYPE)
    1811                 :         11 :                     mv3 = (TYPE_ATOMIC (mv3)
    1812                 :          0 :                            ? c_build_qualified_type (TYPE_MAIN_VARIANT (mv3),
    1813                 :            :                                                      TYPE_QUAL_ATOMIC)
    1814                 :         11 :                            : TYPE_MAIN_VARIANT (mv3));
    1815                 :         11 :                   if (comptypes_internal (mv3, mv1, enum_and_int_p,
    1816                 :            :                                           different_types_p))
    1817                 :            :                     break;
    1818                 :            :                 }
    1819                 :          9 :               if (memb == NULL_TREE)
    1820                 :            :                 return 0;
    1821                 :            :             }
    1822                 :            :           else
    1823                 :     106645 :             return 0;
    1824                 :            :         }
    1825                 :            : 
    1826                 :            :       /* comptypes said ok, but record if it said to warn.  */
    1827                 :    3170710 :       if (newval > val)
    1828                 :            :         val = newval;
    1829                 :            : 
    1830                 :    3170710 :       args1 = TREE_CHAIN (args1);
    1831                 :    3170710 :       args2 = TREE_CHAIN (args2);
    1832                 :    3170710 :     }
    1833                 :            : }
    1834                 :            : 
    1835                 :            : /* Compute the size to increment a pointer by.  When a function type or void
    1836                 :            :    type or incomplete type is passed, size_one_node is returned.
    1837                 :            :    This function does not emit any diagnostics; the caller is responsible
    1838                 :            :    for that.  */
    1839                 :            : 
    1840                 :            : static tree
    1841                 :      74014 : c_size_in_bytes (const_tree type)
    1842                 :            : {
    1843                 :      74014 :   enum tree_code code = TREE_CODE (type);
    1844                 :            : 
    1845                 :      74014 :   if (code == FUNCTION_TYPE || code == VOID_TYPE || code == ERROR_MARK
    1846                 :     147886 :       || !COMPLETE_TYPE_P (type))
    1847                 :        173 :     return size_one_node;
    1848                 :            : 
    1849                 :            :   /* Convert in case a char is more than one unit.  */
    1850                 :      73841 :   return size_binop_loc (input_location, CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
    1851                 :      73841 :                          size_int (TYPE_PRECISION (char_type_node)
    1852                 :            :                                    / BITS_PER_UNIT));
    1853                 :            : }
    1854                 :            : 
    1855                 :            : /* Return either DECL or its known constant value (if it has one).  */
    1856                 :            : 
    1857                 :            : tree
    1858                 :    6763660 : decl_constant_value_1 (tree decl, bool in_init)
    1859                 :            : {
    1860                 :    6763660 :   if (/* Note that DECL_INITIAL isn't valid for a PARM_DECL.  */
    1861                 :    6763660 :       TREE_CODE (decl) != PARM_DECL
    1862                 :    6763660 :       && !TREE_THIS_VOLATILE (decl)
    1863                 :    6459400 :       && TREE_READONLY (decl)
    1864                 :      31058 :       && DECL_INITIAL (decl) != NULL_TREE
    1865                 :      30246 :       && !error_operand_p (DECL_INITIAL (decl))
    1866                 :            :       /* This is invalid if initial value is not constant.
    1867                 :            :          If it has either a function call, a memory reference,
    1868                 :            :          or a variable, then re-evaluating it could give different results.  */
    1869                 :      30238 :       && TREE_CONSTANT (DECL_INITIAL (decl))
    1870                 :            :       /* Check for cases where this is sub-optimal, even though valid.  */
    1871                 :    6781430 :       && (in_init || TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR))
    1872                 :    6763660 :     return DECL_INITIAL (decl);
    1873                 :            :   return decl;
    1874                 :            : }
    1875                 :            : 
    1876                 :            : /* Return either DECL or its known constant value (if it has one).
    1877                 :            :    Like the above, but always return decl outside of functions.  */
    1878                 :            : 
    1879                 :            : tree
    1880                 :    6763540 : decl_constant_value (tree decl)
    1881                 :            : {
    1882                 :            :   /* Don't change a variable array bound or initial value to a constant
    1883                 :            :      in a place where a variable is invalid.  */
    1884                 :    6763540 :   return current_function_decl ? decl_constant_value_1 (decl, false) : decl;
    1885                 :            : }
    1886                 :            : 
    1887                 :            : /* Convert the array expression EXP to a pointer.  */
    1888                 :            : static tree
    1889                 :     332041 : array_to_pointer_conversion (location_t loc, tree exp)
    1890                 :            : {
    1891                 :     332041 :   tree orig_exp = exp;
    1892                 :     332041 :   tree type = TREE_TYPE (exp);
    1893                 :     332041 :   tree adr;
    1894                 :     332041 :   tree restype = TREE_TYPE (type);
    1895                 :     332041 :   tree ptrtype;
    1896                 :            : 
    1897                 :     332041 :   gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
    1898                 :            : 
    1899                 :     332041 :   STRIP_TYPE_NOPS (exp);
    1900                 :            : 
    1901                 :     332041 :   if (TREE_NO_WARNING (orig_exp))
    1902                 :          0 :     TREE_NO_WARNING (exp) = 1;
    1903                 :            : 
    1904                 :     332041 :   ptrtype = build_pointer_type (restype);
    1905                 :            : 
    1906                 :     332041 :   if (INDIRECT_REF_P (exp))
    1907                 :       2308 :     return convert (ptrtype, TREE_OPERAND (exp, 0));
    1908                 :            : 
    1909                 :            :   /* In C++ array compound literals are temporary objects unless they are
    1910                 :            :      const or appear in namespace scope, so they are destroyed too soon
    1911                 :            :      to use them for much of anything  (c++/53220).  */
    1912                 :     329733 :   if (warn_cxx_compat && TREE_CODE (exp) == COMPOUND_LITERAL_EXPR)
    1913                 :            :     {
    1914                 :         48 :       tree decl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
    1915                 :         48 :       if (!TREE_READONLY (decl) && !TREE_STATIC (decl))
    1916                 :         46 :         warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat,
    1917                 :            :                     "converting an array compound literal to a pointer "
    1918                 :            :                     "is ill-formed in C++");
    1919                 :            :     }
    1920                 :            : 
    1921                 :     329733 :   adr = build_unary_op (loc, ADDR_EXPR, exp, true);
    1922                 :     329733 :   return convert (ptrtype, adr);
    1923                 :            : }
    1924                 :            : 
    1925                 :            : /* Convert the function expression EXP to a pointer.  */
    1926                 :            : static tree
    1927                 :   27945600 : function_to_pointer_conversion (location_t loc, tree exp)
    1928                 :            : {
    1929                 :   27945600 :   tree orig_exp = exp;
    1930                 :            : 
    1931                 :   27945600 :   gcc_assert (TREE_CODE (TREE_TYPE (exp)) == FUNCTION_TYPE);
    1932                 :            : 
    1933                 :   27945600 :   STRIP_TYPE_NOPS (exp);
    1934                 :            : 
    1935                 :   27945600 :   if (TREE_NO_WARNING (orig_exp))
    1936                 :          1 :     TREE_NO_WARNING (exp) = 1;
    1937                 :            : 
    1938                 :   27945600 :   return build_unary_op (loc, ADDR_EXPR, exp, false);
    1939                 :            : }
    1940                 :            : 
    1941                 :            : /* Mark EXP as read, not just set, for set but not used -Wunused
    1942                 :            :    warning purposes.  */
    1943                 :            : 
    1944                 :            : void
    1945                 :  272423000 : mark_exp_read (tree exp)
    1946                 :            : {
    1947                 :  353672000 :   switch (TREE_CODE (exp))
    1948                 :            :     {
    1949                 :  125426000 :     case VAR_DECL:
    1950                 :  125426000 :     case PARM_DECL:
    1951                 :  125426000 :       DECL_READ_P (exp) = 1;
    1952                 :  125426000 :       break;
    1953                 :   80684000 :     case ARRAY_REF:
    1954                 :   80684000 :     case COMPONENT_REF:
    1955                 :   80684000 :     case MODIFY_EXPR:
    1956                 :   80684000 :     case REALPART_EXPR:
    1957                 :   80684000 :     case IMAGPART_EXPR:
    1958                 :   80684000 :     CASE_CONVERT:
    1959                 :   80684000 :     case ADDR_EXPR:
    1960                 :   80684000 :     case VIEW_CONVERT_EXPR:
    1961                 :   80684000 :       mark_exp_read (TREE_OPERAND (exp, 0));
    1962                 :   80684000 :       break;
    1963                 :     564990 :     case COMPOUND_EXPR:
    1964                 :     564990 :     case C_MAYBE_CONST_EXPR:
    1965                 :     564990 :       mark_exp_read (TREE_OPERAND (exp, 1));
    1966                 :     564990 :       break;
    1967                 :            :     default:
    1968                 :            :       break;
    1969                 :            :     }
    1970                 :  272423000 : }
    1971                 :            : 
    1972                 :            : /* Perform the default conversion of arrays and functions to pointers.
    1973                 :            :    Return the result of converting EXP.  For any other expression, just
    1974                 :            :    return EXP.
    1975                 :            : 
    1976                 :            :    LOC is the location of the expression.  */
    1977                 :            : 
    1978                 :            : struct c_expr
    1979                 :  194744000 : default_function_array_conversion (location_t loc, struct c_expr exp)
    1980                 :            : {
    1981                 :  194744000 :   tree orig_exp = exp.value;
    1982                 :  194744000 :   tree type = TREE_TYPE (exp.value);
    1983                 :  194744000 :   enum tree_code code = TREE_CODE (type);
    1984                 :            : 
    1985                 :  194744000 :   switch (code)
    1986                 :            :     {
    1987                 :            :     case ARRAY_TYPE:
    1988                 :            :       {
    1989                 :            :         bool not_lvalue = false;
    1990                 :     306092 :         bool lvalue_array_p;
    1991                 :            : 
    1992                 :     306092 :         while ((TREE_CODE (exp.value) == NON_LVALUE_EXPR
    1993                 :     306092 :                 || CONVERT_EXPR_P (exp.value))
    1994                 :     306092 :                && TREE_TYPE (TREE_OPERAND (exp.value, 0)) == type)
    1995                 :            :           {
    1996                 :          0 :             if (TREE_CODE (exp.value) == NON_LVALUE_EXPR)
    1997                 :          0 :               not_lvalue = true;
    1998                 :          0 :             exp.value = TREE_OPERAND (exp.value, 0);
    1999                 :            :           }
    2000                 :            : 
    2001                 :     306092 :         if (TREE_NO_WARNING (orig_exp))
    2002                 :          0 :           TREE_NO_WARNING (exp.value) = 1;
    2003                 :            : 
    2004                 :     306092 :         lvalue_array_p = !not_lvalue && lvalue_p (exp.value);
    2005                 :     306092 :         if (!flag_isoc99 && !lvalue_array_p)
    2006                 :            :           {
    2007                 :            :             /* Before C99, non-lvalue arrays do not decay to pointers.
    2008                 :            :                Normally, using such an array would be invalid; but it can
    2009                 :            :                be used correctly inside sizeof or as a statement expression.
    2010                 :            :                Thus, do not give an error here; an error will result later.  */
    2011                 :        108 :             return exp;
    2012                 :            :           }
    2013                 :            : 
    2014                 :     305984 :         exp.value = array_to_pointer_conversion (loc, exp.value);
    2015                 :            :       }
    2016                 :     305984 :       break;
    2017                 :     751646 :     case FUNCTION_TYPE:
    2018                 :     751646 :       exp.value = function_to_pointer_conversion (loc, exp.value);
    2019                 :     751646 :       break;
    2020                 :            :     default:
    2021                 :            :       break;
    2022                 :            :     }
    2023                 :            : 
    2024                 :  194744000 :   return exp;
    2025                 :            : }
    2026                 :            : 
    2027                 :            : struct c_expr
    2028                 :     659665 : default_function_array_read_conversion (location_t loc, struct c_expr exp)
    2029                 :            : {
    2030                 :     659665 :   mark_exp_read (exp.value);
    2031                 :     659665 :   return default_function_array_conversion (loc, exp);
    2032                 :            : }
    2033                 :            : 
    2034                 :            : /* Return whether EXPR should be treated as an atomic lvalue for the
    2035                 :            :    purposes of load and store handling.  */
    2036                 :            : 
    2037                 :            : static bool
    2038                 :  195424000 : really_atomic_lvalue (tree expr)
    2039                 :            : {
    2040                 :  390845000 :   if (error_operand_p (expr))
    2041                 :            :     return false;
    2042                 :  195421000 :   if (!TYPE_ATOMIC (TREE_TYPE (expr)))
    2043                 :            :     return false;
    2044                 :      54068 :   if (!lvalue_p (expr))
    2045                 :            :     return false;
    2046                 :            : 
    2047                 :            :   /* Ignore _Atomic on register variables, since their addresses can't
    2048                 :            :      be taken so (a) atomicity is irrelevant and (b) the normal atomic
    2049                 :            :      sequences wouldn't work.  Ignore _Atomic on structures containing
    2050                 :            :      bit-fields, since accessing elements of atomic structures or
    2051                 :            :      unions is undefined behavior (C11 6.5.2.3#5), but it's unclear if
    2052                 :            :      it's undefined at translation time or execution time, and the
    2053                 :            :      normal atomic sequences again wouldn't work.  */
    2054                 :      54099 :   while (handled_component_p (expr))
    2055                 :            :     {
    2056                 :         36 :       if (TREE_CODE (expr) == COMPONENT_REF
    2057                 :         36 :           && DECL_C_BIT_FIELD (TREE_OPERAND (expr, 1)))
    2058                 :            :         return false;
    2059                 :         36 :       expr = TREE_OPERAND (expr, 0);
    2060                 :            :     }
    2061                 :     108014 :   if (DECL_P (expr) && C_DECL_REGISTER (expr))
    2062                 :          6 :     return false;
    2063                 :            :   return true;
    2064                 :            : }
    2065                 :            : 
    2066                 :            : /* Convert expression EXP (location LOC) from lvalue to rvalue,
    2067                 :            :    including converting functions and arrays to pointers if CONVERT_P.
    2068                 :            :    If READ_P, also mark the expression as having been read.  */
    2069                 :            : 
    2070                 :            : struct c_expr
    2071                 :  192700000 : convert_lvalue_to_rvalue (location_t loc, struct c_expr exp,
    2072                 :            :                           bool convert_p, bool read_p)
    2073                 :            : {
    2074                 :  192700000 :   if (read_p)
    2075                 :  167005000 :     mark_exp_read (exp.value);
    2076                 :  192700000 :   if (convert_p)
    2077                 :  192690000 :     exp = default_function_array_conversion (loc, exp);
    2078                 :  192700000 :   if (!VOID_TYPE_P (TREE_TYPE (exp.value)))
    2079                 :  191022000 :     exp.value = require_complete_type (loc, exp.value);
    2080                 :  192700000 :   if (really_atomic_lvalue (exp.value))
    2081                 :            :     {
    2082                 :      24001 :       vec<tree, va_gc> *params;
    2083                 :      24001 :       tree nonatomic_type, tmp, tmp_addr, fndecl, func_call;
    2084                 :      24001 :       tree expr_type = TREE_TYPE (exp.value);
    2085                 :      24001 :       tree expr_addr = build_unary_op (loc, ADDR_EXPR, exp.value, false);
    2086                 :      24001 :       tree seq_cst = build_int_cst (integer_type_node, MEMMODEL_SEQ_CST);
    2087                 :            : 
    2088                 :      24001 :       gcc_assert (TYPE_ATOMIC (expr_type));
    2089                 :            : 
    2090                 :            :       /* Expansion of a generic atomic load may require an addition
    2091                 :            :          element, so allocate enough to prevent a resize.  */
    2092                 :      24001 :       vec_alloc (params, 4);
    2093                 :            : 
    2094                 :            :       /* Remove the qualifiers for the rest of the expressions and
    2095                 :            :          create the VAL temp variable to hold the RHS.  */
    2096                 :      24001 :       nonatomic_type = build_qualified_type (expr_type, TYPE_UNQUALIFIED);
    2097                 :      24001 :       tmp = create_tmp_var_raw (nonatomic_type);
    2098                 :      24001 :       tmp_addr = build_unary_op (loc, ADDR_EXPR, tmp, false);
    2099                 :      24001 :       TREE_ADDRESSABLE (tmp) = 1;
    2100                 :      24001 :       TREE_NO_WARNING (tmp) = 1;
    2101                 :            : 
    2102                 :            :       /* Issue __atomic_load (&expr, &tmp, SEQ_CST);  */
    2103                 :      24001 :       fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_LOAD);
    2104                 :      24001 :       params->quick_push (expr_addr);
    2105                 :      24001 :       params->quick_push (tmp_addr);
    2106                 :      24001 :       params->quick_push (seq_cst);
    2107                 :      24001 :       func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
    2108                 :            : 
    2109                 :            :       /* EXPR is always read.  */
    2110                 :      24001 :       mark_exp_read (exp.value);
    2111                 :            : 
    2112                 :            :       /* Return tmp which contains the value loaded.  */
    2113                 :      24001 :       exp.value = build4 (TARGET_EXPR, nonatomic_type, tmp, func_call,
    2114                 :            :                           NULL_TREE, NULL_TREE);
    2115                 :            :     }
    2116                 :  192700000 :   return exp;
    2117                 :            : }
    2118                 :            : 
    2119                 :            : /* EXP is an expression of integer type.  Apply the integer promotions
    2120                 :            :    to it and return the promoted value.  */
    2121                 :            : 
    2122                 :            : tree
    2123                 :   51162400 : perform_integral_promotions (tree exp)
    2124                 :            : {
    2125                 :   51162400 :   tree type = TREE_TYPE (exp);
    2126                 :   51162400 :   enum tree_code code = TREE_CODE (type);
    2127                 :            : 
    2128                 :   51162400 :   gcc_assert (INTEGRAL_TYPE_P (type));
    2129                 :            : 
    2130                 :            :   /* Normally convert enums to int,
    2131                 :            :      but convert wide enums to something wider.  */
    2132                 :   51162400 :   if (code == ENUMERAL_TYPE)
    2133                 :            :     {
    2134                 :     604688 :       type = c_common_type_for_size (MAX (TYPE_PRECISION (type),
    2135                 :            :                                           TYPE_PRECISION (integer_type_node)),
    2136                 :     302344 :                                      ((TYPE_PRECISION (type)
    2137                 :     302344 :                                        >= TYPE_PRECISION (integer_type_node))
    2138                 :     302344 :                                       && TYPE_UNSIGNED (type)));
    2139                 :            : 
    2140                 :     302344 :       return convert (type, exp);
    2141                 :            :     }
    2142                 :            : 
    2143                 :            :   /* ??? This should no longer be needed now bit-fields have their
    2144                 :            :      proper types.  */
    2145                 :   50860100 :   if (TREE_CODE (exp) == COMPONENT_REF
    2146                 :     244262 :       && DECL_C_BIT_FIELD (TREE_OPERAND (exp, 1))
    2147                 :            :       /* If it's thinner than an int, promote it like a
    2148                 :            :          c_promoting_integer_type_p, otherwise leave it alone.  */
    2149                 :   50920600 :       && compare_tree_int (DECL_SIZE (TREE_OPERAND (exp, 1)),
    2150                 :      60592 :                            TYPE_PRECISION (integer_type_node)) < 0)
    2151                 :      52373 :     return convert (integer_type_node, exp);
    2152                 :            : 
    2153                 :   50807700 :   if (c_promoting_integer_type_p (type))
    2154                 :            :     {
    2155                 :            :       /* Preserve unsignedness if not really getting any wider.  */
    2156                 :   13536700 :       if (TYPE_UNSIGNED (type)
    2157                 :   13536700 :           && TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
    2158                 :          0 :         return convert (unsigned_type_node, exp);
    2159                 :            : 
    2160                 :   13536700 :       return convert (integer_type_node, exp);
    2161                 :            :     }
    2162                 :            : 
    2163                 :            :   return exp;
    2164                 :            : }
    2165                 :            : 
    2166                 :            : 
    2167                 :            : /* Perform default promotions for C data used in expressions.
    2168                 :            :    Enumeral types or short or char are converted to int.
    2169                 :            :    In addition, manifest constants symbols are replaced by their values.  */
    2170                 :            : 
    2171                 :            : tree
    2172                 :   56200900 : default_conversion (tree exp)
    2173                 :            : {
    2174                 :   56200900 :   tree orig_exp;
    2175                 :   56200900 :   tree type = TREE_TYPE (exp);
    2176                 :   56200900 :   enum tree_code code = TREE_CODE (type);
    2177                 :   56200900 :   tree promoted_type;
    2178                 :            : 
    2179                 :   56200900 :   mark_exp_read (exp);
    2180                 :            : 
    2181                 :            :   /* Functions and arrays have been converted during parsing.  */
    2182                 :   56200900 :   gcc_assert (code != FUNCTION_TYPE);
    2183                 :   56200900 :   if (code == ARRAY_TYPE)
    2184                 :            :     return exp;
    2185                 :            : 
    2186                 :            :   /* Constants can be used directly unless they're not loadable.  */
    2187                 :   56200800 :   if (TREE_CODE (exp) == CONST_DECL)
    2188                 :          0 :     exp = DECL_INITIAL (exp);
    2189                 :            : 
    2190                 :            :   /* Strip no-op conversions.  */
    2191                 :   56200800 :   orig_exp = exp;
    2192                 :   64599300 :   STRIP_TYPE_NOPS (exp);
    2193                 :            : 
    2194                 :   56200800 :   if (TREE_NO_WARNING (orig_exp))
    2195                 :      27135 :     TREE_NO_WARNING (exp) = 1;
    2196                 :            : 
    2197                 :   56200800 :   if (code == VOID_TYPE)
    2198                 :            :     {
    2199                 :          2 :       error_at (EXPR_LOC_OR_LOC (exp, input_location),
    2200                 :            :                 "void value not ignored as it ought to be");
    2201                 :          2 :       return error_mark_node;
    2202                 :            :     }
    2203                 :            : 
    2204                 :   56200800 :   exp = require_complete_type (EXPR_LOC_OR_LOC (exp, input_location), exp);
    2205                 :   56200800 :   if (exp == error_mark_node)
    2206                 :            :     return error_mark_node;
    2207                 :            : 
    2208                 :   56200300 :   promoted_type = targetm.promoted_type (type);
    2209                 :   56200300 :   if (promoted_type)
    2210                 :          0 :     return convert (promoted_type, exp);
    2211                 :            : 
    2212                 :   56200300 :   if (INTEGRAL_TYPE_P (type))
    2213                 :   50241700 :     return perform_integral_promotions (exp);
    2214                 :            : 
    2215                 :            :   return exp;
    2216                 :            : }
    2217                 :            : 
    2218                 :            : /* Look up COMPONENT in a structure or union TYPE.
    2219                 :            : 
    2220                 :            :    If the component name is not found, returns NULL_TREE.  Otherwise,
    2221                 :            :    the return value is a TREE_LIST, with each TREE_VALUE a FIELD_DECL
    2222                 :            :    stepping down the chain to the component, which is in the last
    2223                 :            :    TREE_VALUE of the list.  Normally the list is of length one, but if
    2224                 :            :    the component is embedded within (nested) anonymous structures or
    2225                 :            :    unions, the list steps down the chain to the component.  */
    2226                 :            : 
    2227                 :            : static tree
    2228                 :    1717050 : lookup_field (tree type, tree component)
    2229                 :            : {
    2230                 :    1717050 :   tree field;
    2231                 :            : 
    2232                 :            :   /* If TYPE_LANG_SPECIFIC is set, then it is a sorted array of pointers
    2233                 :            :      to the field elements.  Use a binary search on this array to quickly
    2234                 :            :      find the element.  Otherwise, do a linear search.  TYPE_LANG_SPECIFIC
    2235                 :            :      will always be set for structures which have many elements.
    2236                 :            : 
    2237                 :            :      Duplicate field checking replaces duplicates with NULL_TREE so
    2238                 :            :      TYPE_LANG_SPECIFIC arrays are potentially no longer sorted.  In that
    2239                 :            :      case just iterate using DECL_CHAIN.  */
    2240                 :            : 
    2241                 :    1940500 :   if (TYPE_LANG_SPECIFIC (type) && TYPE_LANG_SPECIFIC (type)->s
    2242                 :    1940500 :       && !seen_error ())
    2243                 :            :     {
    2244                 :     223452 :       int bot, top, half;
    2245                 :     223452 :       tree *field_array = &TYPE_LANG_SPECIFIC (type)->s->elts[0];
    2246                 :            : 
    2247                 :     223452 :       field = TYPE_FIELDS (type);
    2248                 :     223452 :       bot = 0;
    2249                 :     223452 :       top = TYPE_LANG_SPECIFIC (type)->s->len;
    2250                 :    1017030 :       while (top - bot > 1)
    2251                 :            :         {
    2252                 :     998138 :           half = (top - bot + 1) >> 1;
    2253                 :     998138 :           field = field_array[bot+half];
    2254                 :            : 
    2255                 :     998138 :           if (DECL_NAME (field) == NULL_TREE)
    2256                 :            :             {
    2257                 :            :               /* Step through all anon unions in linear fashion.  */
    2258                 :          0 :               while (DECL_NAME (field_array[bot]) == NULL_TREE)
    2259                 :            :                 {
    2260                 :          0 :                   field = field_array[bot++];
    2261                 :          0 :                   if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)))
    2262                 :            :                     {
    2263                 :          0 :                       tree anon = lookup_field (TREE_TYPE (field), component);
    2264                 :            : 
    2265                 :          0 :                       if (anon)
    2266                 :          0 :                         return tree_cons (NULL_TREE, field, anon);
    2267                 :            : 
    2268                 :            :                       /* The Plan 9 compiler permits referring
    2269                 :            :                          directly to an anonymous struct/union field
    2270                 :            :                          using a typedef name.  */
    2271                 :          0 :                       if (flag_plan9_extensions
    2272                 :          0 :                           && TYPE_NAME (TREE_TYPE (field)) != NULL_TREE
    2273                 :          0 :                           && (TREE_CODE (TYPE_NAME (TREE_TYPE (field)))
    2274                 :            :                               == TYPE_DECL)
    2275                 :          0 :                           && (DECL_NAME (TYPE_NAME (TREE_TYPE (field)))
    2276                 :            :                               == component))
    2277                 :            :                         break;
    2278                 :            :                     }
    2279                 :            :                 }
    2280                 :            : 
    2281                 :            :               /* Entire record is only anon unions.  */
    2282                 :          0 :               if (bot > top)
    2283                 :            :                 return NULL_TREE;
    2284                 :            : 
    2285                 :            :               /* Restart the binary search, with new lower bound.  */
    2286                 :          0 :               continue;
    2287                 :            :             }
    2288                 :            : 
    2289                 :     998138 :           if (DECL_NAME (field) == component)
    2290                 :            :             break;
    2291                 :     793575 :           if (DECL_NAME (field) < component)
    2292                 :            :             bot += half;
    2293                 :            :           else
    2294                 :     647285 :             top = bot + half;
    2295                 :            :         }
    2296                 :            : 
    2297                 :     223452 :       if (DECL_NAME (field_array[bot]) == component)
    2298                 :            :         field = field_array[bot];
    2299                 :     204563 :       else if (DECL_NAME (field) != component)
    2300                 :            :         return NULL_TREE;
    2301                 :            :     }
    2302                 :            :   else
    2303                 :            :     {
    2304                 :    4746830 :       for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    2305                 :            :         {
    2306                 :    4196650 :           if (DECL_NAME (field) == NULL_TREE
    2307                 :    4208280 :               && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)))
    2308                 :            :             {
    2309                 :       6338 :               tree anon = lookup_field (TREE_TYPE (field), component);
    2310                 :            : 
    2311                 :       6338 :               if (anon)
    2312                 :       1601 :                 return tree_cons (NULL_TREE, field, anon);
    2313                 :            : 
    2314                 :            :               /* The Plan 9 compiler permits referring directly to an
    2315                 :            :                  anonymous struct/union field using a typedef
    2316                 :            :                  name.  */
    2317                 :       4737 :               if (flag_plan9_extensions
    2318                 :         28 :                   && TYPE_NAME (TREE_TYPE (field)) != NULL_TREE
    2319                 :         26 :                   && TREE_CODE (TYPE_NAME (TREE_TYPE (field))) == TYPE_DECL
    2320                 :       4743 :                   && (DECL_NAME (TYPE_NAME (TREE_TYPE (field)))
    2321                 :            :                       == component))
    2322                 :            :                 break;
    2323                 :            :             }
    2324                 :            : 
    2325                 :    4195040 :           if (DECL_NAME (field) == component)
    2326                 :            :             break;
    2327                 :            :         }
    2328                 :            : 
    2329                 :    1492000 :       if (field == NULL_TREE)
    2330                 :            :         return NULL_TREE;
    2331                 :            :     }
    2332                 :            : 
    2333                 :    1710650 :   return tree_cons (NULL_TREE, field, NULL_TREE);
    2334                 :            : }
    2335                 :            : 
    2336                 :            : /* Recursively append candidate IDENTIFIER_NODEs to CANDIDATES.  */
    2337                 :            : 
    2338                 :            : static void
    2339                 :         75 : lookup_field_fuzzy_find_candidates (tree type, tree component,
    2340                 :            :                                     vec<tree> *candidates)
    2341                 :            : {
    2342                 :         75 :   tree field;
    2343                 :        205 :   for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    2344                 :            :     {
    2345                 :        117 :       if (DECL_NAME (field) == NULL_TREE
    2346                 :        140 :           && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)))
    2347                 :         15 :         lookup_field_fuzzy_find_candidates (TREE_TYPE (field), component,
    2348                 :            :                                             candidates);
    2349                 :            : 
    2350                 :        117 :       if (DECL_NAME (field))
    2351                 :         94 :         candidates->safe_push (DECL_NAME (field));
    2352                 :            :     }
    2353                 :         75 : }
    2354                 :            : 
    2355                 :            : /* Like "lookup_field", but find the closest matching IDENTIFIER_NODE,
    2356                 :            :    rather than returning a TREE_LIST for an exact match.  */
    2357                 :            : 
    2358                 :            : static tree
    2359                 :         60 : lookup_field_fuzzy (tree type, tree component)
    2360                 :            : {
    2361                 :         60 :   gcc_assert (TREE_CODE (component) == IDENTIFIER_NODE);
    2362                 :            : 
    2363                 :            :   /* First, gather a list of candidates.  */
    2364                 :         60 :   auto_vec <tree> candidates;
    2365                 :            : 
    2366                 :         60 :   lookup_field_fuzzy_find_candidates (type, component,
    2367                 :            :                                       &candidates);
    2368                 :            : 
    2369                 :         60 :   return find_closest_identifier (component, &candidates);
    2370                 :            : }
    2371                 :            : 
    2372                 :            : /* Support function for build_component_ref's error-handling.
    2373                 :            : 
    2374                 :            :    Given DATUM_TYPE, and "DATUM.COMPONENT", where DATUM is *not* a
    2375                 :            :    struct or union, should we suggest "DATUM->COMPONENT" as a hint?  */
    2376                 :            : 
    2377                 :            : static bool
    2378                 :         64 : should_suggest_deref_p (tree datum_type)
    2379                 :            : {
    2380                 :            :   /* We don't do it for Objective-C, since Objective-C 2.0 dot-syntax
    2381                 :            :      allows "." for ptrs; we could be handling a failed attempt
    2382                 :            :      to access a property.  */
    2383                 :         64 :   if (c_dialect_objc ())
    2384                 :            :     return false;
    2385                 :            : 
    2386                 :            :   /* Only suggest it for pointers...  */
    2387                 :         64 :   if (TREE_CODE (datum_type) != POINTER_TYPE)
    2388                 :            :     return false;
    2389                 :            : 
    2390                 :            :   /* ...to structs/unions.  */
    2391                 :          3 :   tree underlying_type = TREE_TYPE (datum_type);
    2392                 :          3 :   enum tree_code code = TREE_CODE (underlying_type);
    2393                 :          3 :   if (code == RECORD_TYPE || code == UNION_TYPE)
    2394                 :            :     return true;
    2395                 :            :   else
    2396                 :          1 :     return false;
    2397                 :            : }
    2398                 :            : 
    2399                 :            : /* Make an expression to refer to the COMPONENT field of structure or
    2400                 :            :    union value DATUM.  COMPONENT is an IDENTIFIER_NODE.  LOC is the
    2401                 :            :    location of the COMPONENT_REF.  COMPONENT_LOC is the location
    2402                 :            :    of COMPONENT.  */
    2403                 :            : 
    2404                 :            : tree
    2405                 :    1708750 : build_component_ref (location_t loc, tree datum, tree component,
    2406                 :            :                      location_t component_loc)
    2407                 :            : {
    2408                 :    1708750 :   tree type = TREE_TYPE (datum);
    2409                 :    1708750 :   enum tree_code code = TREE_CODE (type);
    2410                 :    1708750 :   tree field = NULL;
    2411                 :    1708750 :   tree ref;
    2412                 :    1708750 :   bool datum_lvalue = lvalue_p (datum);
    2413                 :            : 
    2414                 :    1708750 :   if (!objc_is_public (datum, component))
    2415                 :          0 :     return error_mark_node;
    2416                 :            : 
    2417                 :            :   /* Detect Objective-C property syntax object.property.  */
    2418                 :    1708750 :   if (c_dialect_objc ()
    2419                 :    1708750 :       && (ref = objc_maybe_build_component_ref (datum, component)))
    2420                 :            :     return ref;
    2421                 :            : 
    2422                 :            :   /* See if there is a field or component with name COMPONENT.  */
    2423                 :            : 
    2424                 :    1708750 :   if (code == RECORD_TYPE || code == UNION_TYPE)
    2425                 :            :     {
    2426                 :    1708690 :       if (!COMPLETE_TYPE_P (type))
    2427                 :            :         {
    2428                 :         15 :           c_incomplete_type_error (loc, NULL_TREE, type);
    2429                 :         15 :           return error_mark_node;
    2430                 :            :         }
    2431                 :            : 
    2432                 :    1708670 :       field = lookup_field (type, component);
    2433                 :            : 
    2434                 :    1708670 :       if (!field)
    2435                 :            :         {
    2436                 :         52 :           tree guessed_id = lookup_field_fuzzy (type, component);
    2437                 :         52 :           if (guessed_id)
    2438                 :            :             {
    2439                 :            :               /* Attempt to provide a fixit replacement hint, if
    2440                 :            :                  we have a valid range for the component.  */
    2441                 :         52 :               location_t reported_loc
    2442                 :         26 :                 = (component_loc != UNKNOWN_LOCATION) ? component_loc : loc;
    2443                 :         52 :               gcc_rich_location rich_loc (reported_loc);
    2444                 :         26 :               if (component_loc != UNKNOWN_LOCATION)
    2445                 :         26 :                 rich_loc.add_fixit_misspelled_id (component_loc, guessed_id);
    2446                 :         26 :               error_at (&rich_loc,
    2447                 :            :                         "%qT has no member named %qE; did you mean %qE?",
    2448                 :            :                         type, component, guessed_id);
    2449                 :            :             }
    2450                 :            :           else
    2451                 :         26 :             error_at (loc, "%qT has no member named %qE", type, component);
    2452                 :         52 :           return error_mark_node;
    2453                 :            :         }
    2454                 :            : 
    2455                 :            :       /* Accessing elements of atomic structures or unions is undefined
    2456                 :            :          behavior (C11 6.5.2.3#5).  */
    2457                 :    1708620 :       if (TYPE_ATOMIC (type) && c_inhibit_evaluation_warnings == 0)
    2458                 :            :         {
    2459                 :         18 :           if (code == RECORD_TYPE)
    2460                 :         12 :             warning_at (loc, 0, "accessing a member %qE of an atomic "
    2461                 :            :                         "structure %qE", component, datum);
    2462                 :            :           else
    2463                 :          6 :             warning_at (loc, 0, "accessing a member %qE of an atomic "
    2464                 :            :                         "union %qE", component, datum);
    2465                 :            :         }
    2466                 :            : 
    2467                 :            :       /* Chain the COMPONENT_REFs if necessary down to the FIELD.
    2468                 :            :          This might be better solved in future the way the C++ front
    2469                 :            :          end does it - by giving the anonymous entities each a
    2470                 :            :          separate name and type, and then have build_component_ref
    2471                 :            :          recursively call itself.  We can't do that here.  */
    2472                 :    1710210 :       do
    2473                 :            :         {
    2474                 :    1710210 :           tree subdatum = TREE_VALUE (field);
    2475                 :    1710210 :           int quals;
    2476                 :    1710210 :           tree subtype;
    2477                 :    1710210 :           bool use_datum_quals;
    2478                 :            : 
    2479                 :    1710210 :           if (TREE_TYPE (subdatum) == error_mark_node)
    2480                 :          0 :             return error_mark_node;
    2481                 :            : 
    2482                 :            :           /* If this is an rvalue, it does not have qualifiers in C
    2483                 :            :              standard terms and we must avoid propagating such
    2484                 :            :              qualifiers down to a non-lvalue array that is then
    2485                 :            :              converted to a pointer.  */
    2486                 :    3420410 :           use_datum_quals = (datum_lvalue
    2487                 :    1710210 :                              || TREE_CODE (TREE_TYPE (subdatum)) != ARRAY_TYPE);
    2488                 :            : 
    2489                 :    1710210 :           quals = TYPE_QUALS (strip_array_types (TREE_TYPE (subdatum)));
    2490                 :    1710210 :           if (use_datum_quals)
    2491                 :    1709970 :             quals |= TYPE_QUALS (TREE_TYPE (datum));
    2492                 :    1710210 :           subtype = c_build_qualified_type (TREE_TYPE (subdatum), quals);
    2493                 :            : 
    2494                 :    1710210 :           ref = build3 (COMPONENT_REF, subtype, datum, subdatum,
    2495                 :            :                         NULL_TREE);
    2496                 :    1710210 :           SET_EXPR_LOCATION (ref, loc);
    2497                 :    1710210 :           if (TREE_READONLY (subdatum)
    2498                 :    3419390 :               || (use_datum_quals && TREE_READONLY (datum)))
    2499                 :      25422 :             TREE_READONLY (ref) = 1;
    2500                 :    1710210 :           if (TREE_THIS_VOLATILE (subdatum)
    2501                 :    1710210 :               || (use_datum_quals && TREE_THIS_VOLATILE (datum)))
    2502                 :       2099 :             TREE_THIS_VOLATILE (ref) = 1;
    2503                 :            : 
    2504                 :    1710210 :           if (TREE_DEPRECATED (subdatum))
    2505                 :         16 :             warn_deprecated_use (subdatum, NULL_TREE);
    2506                 :            : 
    2507                 :    1710210 :           datum = ref;
    2508                 :            : 
    2509                 :    1710210 :           field = TREE_CHAIN (field);
    2510                 :            :         }
    2511                 :    1710210 :       while (field);
    2512                 :            : 
    2513                 :    1708620 :       return ref;
    2514                 :            :     }
    2515                 :         64 :   else if (should_suggest_deref_p (type))
    2516                 :            :     {
    2517                 :            :       /* Special-case the error message for "ptr.field" for the case
    2518                 :            :          where the user has confused "." vs "->".  */
    2519                 :          2 :       rich_location richloc (line_table, loc);
    2520                 :            :       /* "loc" should be the "." token.  */
    2521                 :          2 :       richloc.add_fixit_replace ("->");
    2522                 :          2 :       error_at (&richloc,
    2523                 :            :                 "%qE is a pointer; did you mean to use %<->%>?",
    2524                 :            :                 datum);
    2525                 :          2 :       return error_mark_node;
    2526                 :            :     }
    2527                 :         62 :   else if (code != ERROR_MARK)
    2528                 :          1 :     error_at (loc,
    2529                 :            :               "request for member %qE in something not a structure or union",
    2530                 :            :               component);
    2531                 :            : 
    2532                 :         62 :   return error_mark_node;
    2533                 :            : }
    2534                 :            : 
    2535                 :            : /* Given an expression PTR for a pointer, return an expression
    2536                 :            :    for the value pointed to.
    2537                 :            :    ERRORSTRING is the name of the operator to appear in error messages.
    2538                 :            : 
    2539                 :            :    LOC is the location to use for the generated tree.  */
    2540                 :            : 
    2541                 :            : tree
    2542                 :    1699320 : build_indirect_ref (location_t loc, tree ptr, ref_operator errstring)
    2543                 :            : {
    2544                 :    1699320 :   tree pointer = default_conversion (ptr);
    2545                 :    1699320 :   tree type = TREE_TYPE (pointer);
    2546                 :    1699320 :   tree ref;
    2547                 :            : 
    2548                 :    1699320 :   if (TREE_CODE (type) == POINTER_TYPE)
    2549                 :            :     {
    2550                 :    1699000 :       if (CONVERT_EXPR_P (pointer)
    2551                 :    1488190 :           || TREE_CODE (pointer) == VIEW_CONVERT_EXPR)
    2552                 :            :         {
    2553                 :            :           /* If a warning is issued, mark it to avoid duplicates from
    2554                 :            :              the backend.  This only needs to be done at
    2555                 :            :              warn_strict_aliasing > 2.  */
    2556                 :     210809 :           if (warn_strict_aliasing > 2)
    2557                 :      26488 :             if (strict_aliasing_warning (EXPR_LOCATION (pointer),
    2558                 :      26488 :                                          type, TREE_OPERAND (pointer, 0)))
    2559                 :          7 :               TREE_NO_WARNING (pointer) = 1;
    2560                 :            :         }
    2561                 :            : 
    2562                 :    1699000 :       if (TREE_CODE (pointer) == ADDR_EXPR
    2563                 :    1699000 :           && (TREE_TYPE (TREE_OPERAND (pointer, 0))
    2564                 :      62915 :               == TREE_TYPE (type)))
    2565                 :            :         {
    2566                 :      62912 :           ref = TREE_OPERAND (pointer, 0);
    2567                 :      62912 :           protected_set_expr_location (ref, loc);
    2568                 :      62912 :           return ref;
    2569                 :            :         }
    2570                 :            :       else
    2571                 :            :         {
    2572                 :    1636080 :           tree t = TREE_TYPE (type);
    2573                 :            : 
    2574                 :    1636080 :           ref = build1 (INDIRECT_REF, t, pointer);
    2575                 :            : 
    2576                 :    1636080 :           if (VOID_TYPE_P (t) && c_inhibit_evaluation_warnings == 0)
    2577                 :        133 :             warning_at (loc, 0, "dereferencing %<void *%> pointer");
    2578                 :            : 
    2579                 :            :           /* We *must* set TREE_READONLY when dereferencing a pointer to const,
    2580                 :            :              so that we get the proper error message if the result is used
    2581                 :            :              to assign to.  Also, &* is supposed to be a no-op.
    2582                 :            :              And ANSI C seems to specify that the type of the result
    2583                 :            :              should be the const type.  */
    2584                 :            :           /* A de-reference of a pointer to const is not a const.  It is valid
    2585                 :            :              to change it via some other pointer.  */
    2586                 :    1636080 :           TREE_READONLY (ref) = TYPE_READONLY (t);
    2587                 :    1636080 :           TREE_SIDE_EFFECTS (ref)
    2588                 :    3263750 :             = TYPE_VOLATILE (t) || TREE_SIDE_EFFECTS (pointer);
    2589                 :    1636080 :           TREE_THIS_VOLATILE (ref) = TYPE_VOLATILE (t);
    2590                 :    1636080 :           protected_set_expr_location (ref, loc);
    2591                 :    1636080 :           return ref;
    2592                 :            :         }
    2593                 :            :     }
    2594                 :        330 :   else if (TREE_CODE (pointer) != ERROR_MARK)
    2595                 :        260 :     invalid_indirection_error (loc, type, errstring);
    2596                 :            : 
    2597                 :        330 :   return error_mark_node;
    2598                 :            : }
    2599                 :            : 
    2600                 :            : /* This handles expressions of the form "a[i]", which denotes
    2601                 :            :    an array reference.
    2602                 :            : 
    2603                 :            :    This is logically equivalent in C to *(a+i), but we may do it differently.
    2604                 :            :    If A is a variable or a member, we generate a primitive ARRAY_REF.
    2605                 :            :    This avoids forcing the array out of registers, and can work on
    2606                 :            :    arrays that are not lvalues (for example, members of structures returned
    2607                 :            :    by functions).
    2608                 :            : 
    2609                 :            :    For vector types, allow vector[i] but not i[vector], and create
    2610                 :            :    *(((type*)&vectortype) + i) for the expression.
    2611                 :            : 
    2612                 :            :    LOC is the location to use for the returned expression.  */
    2613                 :            : 
    2614                 :            : tree
    2615                 :    2178900 : build_array_ref (location_t loc, tree array, tree index)
    2616                 :            : {
    2617                 :    2178900 :   tree ret;
    2618                 :    2178900 :   bool swapped = false;
    2619                 :    2178900 :   if (TREE_TYPE (array) == error_mark_node
    2620                 :    2178900 :       || TREE_TYPE (index) == error_mark_node)
    2621                 :            :     return error_mark_node;
    2622                 :            : 
    2623                 :    2178800 :   if (TREE_CODE (TREE_TYPE (array)) != ARRAY_TYPE
    2624                 :    1072440 :       && TREE_CODE (TREE_TYPE (array)) != POINTER_TYPE
    2625                 :            :       /* Allow vector[index] but not index[vector].  */
    2626                 :    2517370 :       && !gnu_vector_type_p (TREE_TYPE (array)))
    2627                 :            :     {
    2628                 :        188 :       if (TREE_CODE (TREE_TYPE (index)) != ARRAY_TYPE
    2629                 :        188 :           && TREE_CODE (TREE_TYPE (index)) != POINTER_TYPE)
    2630                 :            :         {
    2631                 :          2 :           error_at (loc,
    2632                 :            :             "subscripted value is neither array nor pointer nor vector");
    2633                 :            : 
    2634                 :          2 :           return error_mark_node;
    2635                 :            :         }
    2636                 :        186 :       std::swap (array, index);
    2637                 :        186 :       swapped = true;
    2638                 :            :     }
    2639                 :            : 
    2640                 :    2178800 :   if (!INTEGRAL_TYPE_P (TREE_TYPE (index)))
    2641                 :            :     {
    2642                 :          2 :       error_at (loc, "array subscript is not an integer");
    2643                 :          2 :       return error_mark_node;
    2644                 :            :     }
    2645                 :            : 
    2646                 :    2178790 :   if (TREE_CODE (TREE_TYPE (TREE_TYPE (array))) == FUNCTION_TYPE)
    2647                 :            :     {
    2648                 :         10 :       error_at (loc, "subscripted value is pointer to function");
    2649                 :         10 :       return error_mark_node;
    2650                 :            :     }
    2651                 :            : 
    2652                 :            :   /* ??? Existing practice has been to warn only when the char
    2653                 :            :      index is syntactically the index, not for char[array].  */
    2654                 :    2178780 :   if (!swapped)
    2655                 :    2178600 :      warn_array_subscript_with_type_char (loc, index);
    2656                 :            : 
    2657                 :            :   /* Apply default promotions *after* noticing character types.  */
    2658                 :    2178780 :   index = default_conversion (index);
    2659                 :    2178780 :   if (index == error_mark_node)
    2660                 :            :     return error_mark_node;
    2661                 :            : 
    2662                 :    2178780 :   gcc_assert (TREE_CODE (TREE_TYPE (index)) == INTEGER_TYPE);
    2663                 :            : 
    2664                 :    2178780 :   bool was_vector = VECTOR_TYPE_P (TREE_TYPE (array));
    2665                 :    2178780 :   bool non_lvalue = convert_vector_to_array_for_subscript (loc, &array, index);
    2666                 :            : 
    2667                 :    2178780 :   if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE)
    2668                 :            :     {
    2669                 :    1444750 :       tree rval, type;
    2670                 :            : 
    2671                 :            :       /* An array that is indexed by a non-constant
    2672                 :            :          cannot be stored in a register; we must be able to do
    2673                 :            :          address arithmetic on its address.
    2674                 :            :          Likewise an array of elements of variable size.  */
    2675                 :    1444750 :       if (TREE_CODE (index) != INTEGER_CST
    2676                 :    1444750 :           || (COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (array)))
    2677                 :    1050380 :               && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array)))) != INTEGER_CST))
    2678                 :            :         {
    2679                 :     395025 :           if (!c_mark_addressable (array, true))
    2680                 :          1 :             return error_mark_node;
    2681                 :            :         }
    2682                 :            :       /* An array that is indexed by a constant value which is not within
    2683                 :            :          the array bounds cannot be stored in a register either; because we
    2684                 :            :          would get a crash in store_bit_field/extract_bit_field when trying
    2685                 :            :          to access a non-existent part of the register.  */
    2686                 :    1444740 :       if (TREE_CODE (index) == INTEGER_CST
    2687                 :    1050380 :           && TYPE_DOMAIN (TREE_TYPE (array))
    2688                 :    2493720 :           && !int_fits_type_p (index, TYPE_DOMAIN (TREE_TYPE (array))))
    2689                 :            :         {
    2690                 :      35303 :           if (!c_mark_addressable (array))
    2691                 :          0 :             return error_mark_node;
    2692                 :            :         }
    2693                 :            : 
    2694                 :    1444740 :       if ((pedantic || warn_c90_c99_compat)
    2695                 :    1435470 :           && ! was_vector)
    2696                 :            :         {
    2697                 :    1105840 :           tree foo = array;
    2698                 :    1736700 :           while (TREE_CODE (foo) == COMPONENT_REF)
    2699                 :     630867 :             foo = TREE_OPERAND (foo, 0);
    2700                 :    1823350 :           if (VAR_P (foo) && C_DECL_REGISTER (foo))
    2701                 :          0 :             pedwarn (loc, OPT_Wpedantic,
    2702                 :            :                      "ISO C forbids subscripting %<register%> array");
    2703                 :    1105840 :           else if (!lvalue_p (foo))
    2704                 :         87 :             pedwarn_c90 (loc, OPT_Wpedantic,
    2705                 :            :                          "ISO C90 forbids subscripting non-lvalue "
    2706                 :            :                          "array");
    2707                 :            :         }
    2708                 :            : 
    2709                 :    1444740 :       type = TREE_TYPE (TREE_TYPE (array));
    2710                 :    1444740 :       rval = build4 (ARRAY_REF, type, array, index, NULL_TREE, NULL_TREE);
    2711                 :            :       /* Array ref is const/volatile if the array elements are
    2712                 :            :          or if the array is.  */
    2713                 :    2889490 :       TREE_READONLY (rval)
    2714                 :    1444740 :         |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array)))
    2715                 :    1444740 :             | TREE_READONLY (array));
    2716                 :    2889490 :       TREE_SIDE_EFFECTS (rval)
    2717                 :    1444740 :         |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
    2718                 :    1444740 :             | TREE_SIDE_EFFECTS (array));
    2719                 :    1444740 :       TREE_THIS_VOLATILE (rval)
    2720                 :    1444740 :         |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
    2721                 :            :             /* This was added by rms on 16 Nov 91.
    2722                 :            :                It fixes  vol struct foo *a;  a->elts[1]
    2723                 :            :                in an inline function.
    2724                 :            :                Hope it doesn't break something else.  */
    2725                 :    1444740 :             | TREE_THIS_VOLATILE (array));
    2726                 :    1444740 :       ret = require_complete_type (loc, rval);
    2727                 :    1444740 :       protected_set_expr_location (ret, loc);
    2728                 :    1444740 :       if (non_lvalue)
    2729                 :      48335 :         ret = non_lvalue_loc (loc, ret);
    2730                 :    1444740 :       return ret;
    2731                 :            :     }
    2732                 :            :   else
    2733                 :            :     {
    2734                 :     734037 :       tree ar = default_conversion (array);
    2735                 :            : 
    2736                 :     734037 :       if (ar == error_mark_node)
    2737                 :            :         return ar;
    2738                 :            : 
    2739                 :     734037 :       gcc_assert (TREE_CODE (TREE_TYPE (ar)) == POINTER_TYPE);
    2740                 :     734037 :       gcc_assert (TREE_CODE (TREE_TYPE (TREE_TYPE (ar))) != FUNCTION_TYPE);
    2741                 :            : 
    2742                 :     734037 :       ret = build_indirect_ref (loc, build_binary_op (loc, PLUS_EXPR, ar,
    2743                 :            :                                                       index, false),
    2744                 :            :                                 RO_ARRAY_INDEXING);
    2745                 :     734037 :       if (non_lvalue)
    2746                 :          0 :         ret = non_lvalue_loc (loc, ret);
    2747                 :     734037 :       return ret;
    2748                 :            :     }
    2749                 :            : }
    2750                 :            : 
    2751                 :            : /* Build an external reference to identifier ID.  FUN indicates
    2752                 :            :    whether this will be used for a function call.  LOC is the source
    2753                 :            :    location of the identifier.  This sets *TYPE to the type of the
    2754                 :            :    identifier, which is not the same as the type of the returned value
    2755                 :            :    for CONST_DECLs defined as enum constants.  If the type of the
    2756                 :            :    identifier is not available, *TYPE is set to NULL.  */
    2757                 :            : tree
    2758                 :   96585000 : build_external_ref (location_t loc, tree id, bool fun, tree *type)
    2759                 :            : {
    2760                 :   96585000 :   tree ref;
    2761                 :   96585000 :   tree decl = lookup_name (id);
    2762                 :            : 
    2763                 :            :   /* In Objective-C, an instance variable (ivar) may be preferred to
    2764                 :            :      whatever lookup_name() found.  */
    2765                 :   96585000 :   decl = objc_lookup_ivar (decl, id);
    2766                 :            : 
    2767                 :   96585000 :   *type = NULL;
    2768                 :   96585000 :   if (decl && decl != error_mark_node)
    2769                 :            :     {
    2770                 :   96562700 :       ref = decl;
    2771                 :   96562700 :       *type = TREE_TYPE (ref);
    2772                 :            :     }
    2773                 :      22295 :   else if (fun)
    2774                 :            :     /* Implicit function declaration.  */
    2775                 :      20963 :     ref = implicitly_declare (loc, id);
    2776                 :       1332 :   else if (decl == error_mark_node)
    2777                 :            :     /* Don't complain about something that's already been
    2778                 :            :        complained about.  */
    2779                 :            :     return error_mark_node;
    2780                 :            :   else
    2781                 :            :     {
    2782                 :       1105 :       undeclared_variable (loc, id);
    2783                 :       1105 :       return error_mark_node;
    2784                 :            :     }
    2785                 :            : 
    2786                 :   96583600 :   if (TREE_TYPE (ref) == error_mark_node)
    2787                 :            :     return error_mark_node;
    2788                 :            : 
    2789                 :   96583600 :   if (TREE_DEPRECATED (ref))
    2790                 :         45 :     warn_deprecated_use (ref, NULL_TREE);
    2791                 :            : 
    2792                 :            :   /* Recursive call does not count as usage.  */
    2793                 :   96583600 :   if (ref != current_function_decl)
    2794                 :            :     {
    2795                 :   96581700 :       TREE_USED (ref) = 1;
    2796                 :            :     }
    2797                 :            : 
    2798                 :   96583600 :   if (TREE_CODE (ref) == FUNCTION_DECL && !in_alignof)
    2799                 :            :     {
    2800                 :   28573500 :       if (!in_sizeof && !in_typeof)
    2801                 :   27870500 :         C_DECL_USED (ref) = 1;
    2802                 :     702906 :       else if (DECL_INITIAL (ref) == NULL_TREE
    2803                 :     692008 :                && DECL_EXTERNAL (ref)
    2804                 :    1394910 :                && !TREE_PUBLIC (ref))
    2805                 :        183 :         record_maybe_used_decl (ref);
    2806                 :            :     }
    2807                 :            : 
    2808                 :   96583600 :   if (TREE_CODE (ref) == CONST_DECL)
    2809                 :            :     {
    2810                 :     346425 :       used_types_insert (TREE_TYPE (ref));
    2811                 :            : 
    2812                 :     346425 :       if (warn_cxx_compat
    2813                 :        262 :           && TREE_CODE (TREE_TYPE (ref)) == ENUMERAL_TYPE
    2814                 :     346685 :           && C_TYPE_DEFINED_IN_STRUCT (TREE_TYPE (ref)))
    2815                 :            :         {
    2816                 :          1 :           warning_at (loc, OPT_Wc___compat,
    2817                 :            :                       ("enum constant defined in struct or union "
    2818                 :            :                        "is not visible in C++"));
    2819                 :          1 :           inform (DECL_SOURCE_LOCATION (ref), "enum constant defined here");
    2820                 :            :         }
    2821                 :            : 
    2822                 :     346425 :       ref = DECL_INITIAL (ref);
    2823                 :     346425 :       TREE_CONSTANT (ref) = 1;
    2824                 :            :     }
    2825                 :   96237200 :   else if (current_function_decl != NULL_TREE
    2826                 :   94817800 :            && !DECL_FILE_SCOPE_P (current_function_decl)
    2827                 :   96243500 :            && (VAR_OR_FUNCTION_DECL_P (ref)
    2828                 :       2288 :                || TREE_CODE (ref) == PARM_DECL))
    2829                 :            :     {
    2830                 :       6300 :       tree context = decl_function_context (ref);
    2831                 :            : 
    2832                 :       6300 :       if (context != NULL_TREE && context != current_function_decl)
    2833                 :       1517 :         DECL_NONLOCAL (ref) = 1;
    2834                 :            :     }
    2835                 :            :   /* C99 6.7.4p3: An inline definition of a function with external
    2836                 :            :      linkage ... shall not contain a reference to an identifier with
    2837                 :            :      internal linkage.  */
    2838                 :   96230900 :   else if (current_function_decl != NULL_TREE
    2839                 :   94811500 :            && DECL_DECLARED_INLINE_P (current_function_decl)
    2840                 :   85932600 :            && DECL_EXTERNAL (current_function_decl)
    2841                 :   85355000 :            && VAR_OR_FUNCTION_DECL_P (ref)
    2842                 :   28597400 :            && (!VAR_P (ref) || TREE_STATIC (ref))
    2843                 :   25694400 :            && ! TREE_PUBLIC (ref)
    2844                 :   96230900 :            && DECL_CONTEXT (ref) != current_function_decl)
    2845                 :         25 :     record_inline_static (loc, current_function_decl, ref,
    2846                 :            :                           csi_internal);
    2847                 :            : 
    2848                 :            :   return ref;
    2849                 :            : }
    2850                 :            : 
    2851                 :            : /* Record details of decls possibly used inside sizeof or typeof.  */
    2852                 :            : struct maybe_used_decl
    2853                 :            : {
    2854                 :            :   /* The decl.  */
    2855                 :            :   tree decl;
    2856                 :            :   /* The level seen at (in_sizeof + in_typeof).  */
    2857                 :            :   int level;
    2858                 :            :   /* The next one at this level or above, or NULL.  */
    2859                 :            :   struct maybe_used_decl *next;
    2860                 :            : };
    2861                 :            : 
    2862                 :            : static struct maybe_used_decl *maybe_used_decls;
    2863                 :            : 
    2864                 :            : /* Record that DECL, an undefined static function reference seen
    2865                 :            :    inside sizeof or typeof, might be used if the operand of sizeof is
    2866                 :            :    a VLA type or the operand of typeof is a variably modified
    2867                 :            :    type.  */
    2868                 :            : 
    2869                 :            : static void
    2870                 :        183 : record_maybe_used_decl (tree decl)
    2871                 :            : {
    2872                 :        183 :   struct maybe_used_decl *t = XOBNEW (&parser_obstack, struct maybe_used_decl);
    2873                 :        183 :   t->decl = decl;
    2874                 :        183 :   t->level = in_sizeof + in_typeof;
    2875                 :        183 :   t->next = maybe_used_decls;
    2876                 :        183 :   maybe_used_decls = t;
    2877                 :        183 : }
    2878                 :            : 
    2879                 :            : /* Pop the stack of decls possibly used inside sizeof or typeof.  If
    2880                 :            :    USED is false, just discard them.  If it is true, mark them used
    2881                 :            :    (if no longer inside sizeof or typeof) or move them to the next
    2882                 :            :    level up (if still inside sizeof or typeof).  */
    2883                 :            : 
    2884                 :            : void
    2885                 :    1324100 : pop_maybe_used (bool used)
    2886                 :            : {
    2887                 :    1324100 :   struct maybe_used_decl *p = maybe_used_decls;
    2888                 :    1324100 :   int cur_level = in_sizeof + in_typeof;
    2889                 :    1324280 :   while (p && p->level > cur_level)
    2890                 :            :     {
    2891                 :        185 :       if (used)
    2892                 :            :         {
    2893                 :          5 :           if (cur_level == 0)
    2894                 :          3 :             C_DECL_USED (p->decl) = 1;
    2895                 :            :           else
    2896                 :          2 :             p->level = cur_level;
    2897                 :            :         }
    2898                 :        185 :       p = p->next;
    2899                 :            :     }
    2900                 :    1324100 :   if (!used || cur_level == 0)
    2901                 :    1324090 :     maybe_used_decls = p;
    2902                 :    1324100 : }
    2903                 :            : 
    2904                 :            : /* Return the result of sizeof applied to EXPR.  */
    2905                 :            : 
    2906                 :            : struct c_expr
    2907                 :     245109 : c_expr_sizeof_expr (location_t loc, struct c_expr expr)
    2908                 :            : {
    2909                 :     245109 :   struct c_expr ret;
    2910                 :     245109 :   if (expr.value == error_mark_node)
    2911                 :            :     {
    2912                 :         94 :       ret.value = error_mark_node;
    2913                 :         94 :       ret.original_code = ERROR_MARK;
    2914                 :         94 :       ret.original_type = NULL;
    2915                 :         94 :       pop_maybe_used (false);
    2916                 :            :     }
    2917                 :            :   else
    2918                 :            :     {
    2919                 :     245015 :       bool expr_const_operands = true;
    2920                 :            : 
    2921                 :     245015 :       if (TREE_CODE (expr.value) == PARM_DECL
    2922                 :     245015 :           && C_ARRAY_PARAMETER (expr.value))
    2923                 :            :         {
    2924                 :        108 :           auto_diagnostic_group d;
    2925                 :         54 :           if (warning_at (loc, OPT_Wsizeof_array_argument,
    2926                 :            :                           "%<sizeof%> on array function parameter %qE will "
    2927                 :            :                           "return size of %qT", expr.value,
    2928                 :         54 :                           TREE_TYPE (expr.value)))
    2929                 :         18 :             inform (DECL_SOURCE_LOCATION (expr.value), "declared here");
    2930                 :            :         }
    2931                 :     245015 :       tree folded_expr = c_fully_fold (expr.value, require_constant_value,
    2932                 :            :                                        &expr_const_operands);
    2933                 :     245015 :       ret.value = c_sizeof (loc, TREE_TYPE (folded_expr));
    2934                 :     245015 :       c_last_sizeof_arg = expr.value;
    2935                 :     245015 :       c_last_sizeof_loc = loc;
    2936                 :     245015 :       ret.original_code = SIZEOF_EXPR;
    2937                 :     245015 :       ret.original_type = NULL;
    2938                 :     245015 :       if (c_vla_type_p (TREE_TYPE (folded_expr)))
    2939                 :            :         {
    2940                 :            :           /* sizeof is evaluated when given a vla (C99 6.5.3.4p2).  */
    2941                 :        100 :           ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
    2942                 :            :                               folded_expr, ret.value);
    2943                 :        100 :           C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !expr_const_operands;
    2944                 :        100 :           SET_EXPR_LOCATION (ret.value, loc);
    2945                 :            :         }
    2946                 :     245015 :       pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (folded_expr)));
    2947                 :            :     }
    2948                 :     245109 :   return ret;
    2949                 :            : }
    2950                 :            : 
    2951                 :            : /* Return the result of sizeof applied to T, a structure for the type
    2952                 :            :    name passed to sizeof (rather than the type itself).  LOC is the
    2953                 :            :    location of the original expression.  */
    2954                 :            : 
    2955                 :            : struct c_expr
    2956                 :     268101 : c_expr_sizeof_type (location_t loc, struct c_type_name *t)
    2957                 :            : {
    2958                 :     268101 :   tree type;
    2959                 :     268101 :   struct c_expr ret;
    2960                 :     268101 :   tree type_expr = NULL_TREE;
    2961                 :     268101 :   bool type_expr_const = true;
    2962                 :     268101 :   type = groktypename (t, &type_expr, &type_expr_const);
    2963                 :     268101 :   ret.value = c_sizeof (loc, type);
    2964                 :     268101 :   c_last_sizeof_arg = type;
    2965                 :     268101 :   c_last_sizeof_loc = loc;
    2966                 :     268101 :   ret.original_code = SIZEOF_EXPR;
    2967                 :     268101 :   ret.original_type = NULL;
    2968                 :     268087 :   if ((type_expr || TREE_CODE (ret.value) == INTEGER_CST)
    2969                 :     536141 :       && c_vla_type_p (type))
    2970                 :            :     {
    2971                 :            :       /* If the type is a [*] array, it is a VLA but is represented as
    2972                 :            :          having a size of zero.  In such a case we must ensure that
    2973                 :            :          the result of sizeof does not get folded to a constant by
    2974                 :            :          c_fully_fold, because if the size is evaluated the result is
    2975                 :            :          not constant and so constraints on zero or negative size
    2976                 :            :          arrays must not be applied when this sizeof call is inside
    2977                 :            :          another array declarator.  */
    2978                 :          8 :       if (!type_expr)
    2979                 :          2 :         type_expr = integer_zero_node;
    2980                 :          8 :       ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
    2981                 :            :                           type_expr, ret.value);
    2982                 :          8 :       C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !type_expr_const;
    2983                 :            :     }
    2984                 :     268101 :   pop_maybe_used (type != error_mark_node
    2985                 :     536198 :                   ? C_TYPE_VARIABLE_SIZE (type) : false);
    2986                 :     268101 :   return ret;
    2987                 :            : }
    2988                 :            : 
    2989                 :            : /* Build a function call to function FUNCTION with parameters PARAMS.
    2990                 :            :    The function call is at LOC.
    2991                 :            :    PARAMS is a list--a chain of TREE_LIST nodes--in which the
    2992                 :            :    TREE_VALUE of each node is a parameter-expression.
    2993                 :            :    FUNCTION's data type may be a function type or a pointer-to-function.  */
    2994                 :            : 
    2995                 :            : tree
    2996                 :          0 : build_function_call (location_t loc, tree function, tree params)
    2997                 :            : {
    2998                 :          0 :   vec<tree, va_gc> *v;
    2999                 :          0 :   tree ret;
    3000                 :            : 
    3001                 :          0 :   vec_alloc (v, list_length (params));
    3002                 :          0 :   for (; params; params = TREE_CHAIN (params))
    3003                 :          0 :     v->quick_push (TREE_VALUE (params));
    3004                 :          0 :   ret = c_build_function_call_vec (loc, vNULL, function, v, NULL);
    3005                 :          0 :   vec_free (v);
    3006                 :          0 :   return ret;
    3007                 :            : }
    3008                 :            : 
    3009                 :            : /* Give a note about the location of the declaration of DECL.  */
    3010                 :            : 
    3011                 :            : static void
    3012                 :        292 : inform_declaration (tree decl)
    3013                 :            : {
    3014                 :        574 :   if (decl && (TREE_CODE (decl) != FUNCTION_DECL || !DECL_IS_BUILTIN (decl)))
    3015                 :        211 :     inform (DECL_SOURCE_LOCATION (decl), "declared here");
    3016                 :        292 : }
    3017                 :            : 
    3018                 :            : /* Build a function call to function FUNCTION with parameters PARAMS.
    3019                 :            :    If FUNCTION is the result of resolving an overloaded target built-in,
    3020                 :            :    ORIG_FUNDECL is the original function decl, otherwise it is null.
    3021                 :            :    ORIGTYPES, if not NULL, is a vector of types; each element is
    3022                 :            :    either NULL or the original type of the corresponding element in
    3023                 :            :    PARAMS.  The original type may differ from TREE_TYPE of the
    3024                 :            :    parameter for enums.  FUNCTION's data type may be a function type
    3025                 :            :    or pointer-to-function.  This function changes the elements of
    3026                 :            :    PARAMS.  */
    3027                 :            : 
    3028                 :            : tree
    3029                 :   27253300 : build_function_call_vec (location_t loc, vec<location_t> arg_loc,
    3030                 :            :                          tree function, vec<tree, va_gc> *params,
    3031                 :            :                          vec<tree, va_gc> *origtypes, tree orig_fundecl)
    3032                 :            : {
    3033                 :   27253300 :   tree fntype, fundecl = NULL_TREE;
    3034                 :   27253300 :   tree name = NULL_TREE, result;
    3035                 :   27253300 :   tree tem;
    3036                 :   27253300 :   int nargs;
    3037                 :   27253300 :   tree *argarray;
    3038                 :            : 
    3039                 :            : 
    3040                 :            :   /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
    3041                 :   27253700 :   STRIP_TYPE_NOPS (function);
    3042                 :            : 
    3043                 :            :   /* Convert anything with function type to a pointer-to-function.  */
    3044                 :   27253300 :   if (TREE_CODE (function) == FUNCTION_DECL)
    3045                 :            :     {
    3046                 :   27183200 :       name = DECL_NAME (function);
    3047                 :            : 
    3048                 :   27183200 :       if (flag_tm)
    3049                 :        420 :         tm_malloc_replacement (function);
    3050                 :   27183200 :       fundecl = function;
    3051                 :   27183200 :       if (!orig_fundecl)
    3052                 :   27183200 :         orig_fundecl = fundecl;
    3053                 :            :       /* Atomic functions have type checking/casting already done.  They are 
    3054                 :            :          often rewritten and don't match the original parameter list.  */
    3055                 :   54366300 :       if (name && !strncmp (IDENTIFIER_POINTER (name), "__atomic_", 9))
    3056                 :            :         origtypes = NULL;
    3057                 :            :     }
    3058                 :   27253300 :   if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE)
    3059                 :   27194000 :     function = function_to_pointer_conversion (loc, function);
    3060                 :            : 
    3061                 :            :   /* For Objective-C, convert any calls via a cast to OBJC_TYPE_REF
    3062                 :            :      expressions, like those used for ObjC messenger dispatches.  */
    3063                 :   27253300 :   if (params && !params->is_empty ())
    3064                 :   21136600 :     function = objc_rewrite_function_call (function, (*params)[0]);
    3065                 :            : 
    3066                 :   27253300 :   function = c_fully_fold (function, false, NULL);
    3067                 :            : 
    3068                 :   27253300 :   fntype = TREE_TYPE (function);
    3069                 :            : 
    3070                 :   27253300 :   if (TREE_CODE (fntype) == ERROR_MARK)
    3071                 :          2 :     return error_mark_node;
    3072                 :            : 
    3073                 :   27253300 :   if (!(TREE_CODE (fntype) == POINTER_TYPE
    3074                 :   27253200 :         && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE))
    3075                 :            :     {
    3076                 :         37 :       if (!flag_diagnostics_show_caret)
    3077                 :         35 :         error_at (loc,
    3078                 :            :                   "called object %qE is not a function or function pointer",
    3079                 :            :                   function);
    3080                 :          2 :       else if (DECL_P (function))
    3081                 :            :         {
    3082                 :          1 :           error_at (loc,
    3083                 :            :                     "called object %qD is not a function or function pointer",
    3084                 :            :                     function);
    3085                 :          1 :           inform_declaration (function);
    3086                 :            :         }
    3087                 :            :       else
    3088                 :          1 :         error_at (loc,
    3089                 :            :                   "called object is not a function or function pointer");
    3090                 :         37 :       return error_mark_node;
    3091                 :            :     }
    3092                 :            : 
    3093                 :   27253200 :   if (fundecl && TREE_THIS_VOLATILE (fundecl))
    3094                 :     244107 :     current_function_returns_abnormally = 1;
    3095                 :            : 
    3096                 :            :   /* fntype now gets the type of function pointed to.  */
    3097                 :   27253200 :   fntype = TREE_TYPE (fntype);
    3098                 :            : 
    3099                 :            :   /* Convert the parameters to the types declared in the
    3100                 :            :      function prototype, or apply default promotions.  */
    3101                 :            : 
    3102                 :   27253200 :   nargs = convert_arguments (loc, arg_loc, TYPE_ARG_TYPES (fntype), params,
    3103                 :            :                              origtypes, function, fundecl);
    3104                 :   27253200 :   if (nargs < 0)
    3105                 :        150 :     return error_mark_node;
    3106                 :            : 
    3107                 :            :   /* Check that the function is called through a compatible prototype.
    3108                 :            :      If it is not, warn.  */
    3109                 :   27252400 :   if (CONVERT_EXPR_P (function)
    3110                 :        696 :       && TREE_CODE (tem = TREE_OPERAND (function, 0)) == ADDR_EXPR
    3111                 :         88 :       && TREE_CODE (tem = TREE_OPERAND (tem, 0)) == FUNCTION_DECL
    3112                 :   27253200 :       && !comptypes (fntype, TREE_TYPE (tem)))
    3113                 :            :     {
    3114                 :         19 :       tree return_type = TREE_TYPE (fntype);
    3115                 :            : 
    3116                 :            :       /* This situation leads to run-time undefined behavior.  We can't,
    3117                 :            :          therefore, simply error unless we can prove that all possible
    3118                 :            :          executions of the program must execute the code.  */
    3119                 :         19 :       warning_at (loc, 0, "function called through a non-compatible type");
    3120                 :            : 
    3121                 :         19 :       if (VOID_TYPE_P (return_type)
    3122                 :         24 :           && TYPE_QUALS (return_type) != TYPE_UNQUALIFIED)
    3123                 :          1 :         pedwarn (loc, 0,
    3124                 :            :                  "function with qualified void return type called");
    3125                 :            :      }
    3126                 :            : 
    3127                 :   27253100 :   argarray = vec_safe_address (params);
    3128                 :            : 
    3129                 :            :   /* Check that arguments to builtin functions match the expectations.  */
    3130                 :   27253100 :   if (fundecl
    3131                 :   27183000 :       && fndecl_built_in_p (fundecl)
    3132                 :   46174200 :       && !check_builtin_function_arguments (loc, arg_loc, fundecl,
    3133                 :            :                                             orig_fundecl, nargs, argarray))
    3134                 :        180 :     return error_mark_node;
    3135                 :            : 
    3136                 :            :   /* Check that the arguments to the function are valid.  */
    3137                 :   27252900 :   bool warned_p = check_function_arguments (loc, fundecl, fntype,
    3138                 :            :                                             nargs, argarray, &arg_loc);
    3139                 :            : 
    3140                 :   27252900 :   if (name != NULL_TREE
    3141                 :   54435800 :       && !strncmp (IDENTIFIER_POINTER (name), "__builtin_", 10))
    3142                 :            :     {
    3143                 :   18502000 :       if (require_constant_value)
    3144                 :       1424 :         result
    3145                 :       1424 :           = fold_build_call_array_initializer_loc (loc, TREE_TYPE (fntype),
    3146                 :            :                                                    function, nargs, argarray);
    3147                 :            :       else
    3148                 :   18500600 :         result = fold_build_call_array_loc (loc, TREE_TYPE (fntype),
    3149                 :            :                                             function, nargs, argarray);
    3150                 :   18502000 :       if (TREE_CODE (result) == NOP_EXPR
    3151                 :   18502000 :           && TREE_CODE (TREE_OPERAND (result, 0)) == INTEGER_CST)
    3152                 :      20856 :         STRIP_TYPE_NOPS (result);
    3153                 :            :     }
    3154                 :            :   else
    3155                 :    8750900 :     result = build_call_array_loc (loc, TREE_TYPE (fntype),
    3156                 :            :                                    function, nargs, argarray);
    3157                 :            :   /* If -Wnonnull warning has been diagnosed, avoid diagnosing it again
    3158                 :            :      later.  */
    3159                 :   27252900 :   if (warned_p && TREE_CODE (result) == CALL_EXPR)
    3160                 :        157 :     TREE_NO_WARNING (result) = 1;
    3161                 :            : 
    3162                 :            :   /* In this improbable scenario, a nested function returns a VM type.
    3163                 :            :      Create a TARGET_EXPR so that the call always has a LHS, much as
    3164                 :            :      what the C++ FE does for functions returning non-PODs.  */
    3165                 :   27252900 :   if (variably_modified_type_p (TREE_TYPE (fntype), NULL_TREE))
    3166                 :            :     {
    3167                 :         43 :       tree tmp = create_tmp_var_raw (TREE_TYPE (fntype));
    3168                 :         43 :       result = build4 (TARGET_EXPR, TREE_TYPE (fntype), tmp, result,
    3169                 :            :                        NULL_TREE, NULL_TREE);
    3170                 :            :     }
    3171                 :            : 
    3172                 :   27252900 :   if (VOID_TYPE_P (TREE_TYPE (result)))
    3173                 :            :     {
    3174                 :    1650330 :       if (TYPE_QUALS (TREE_TYPE (result)) != TYPE_UNQUALIFIED)
    3175                 :          2 :         pedwarn (loc, 0,
    3176                 :            :                  "function with qualified void return type called");
    3177                 :    1650330 :       return result;
    3178                 :            :     }
    3179                 :   25602600 :   return require_complete_type (loc, result);
    3180                 :            : }
    3181                 :            : 
    3182                 :            : /* Like build_function_call_vec, but call also resolve_overloaded_builtin.  */
    3183                 :            : 
    3184                 :            : tree
    3185                 :   27253400 : c_build_function_call_vec (location_t loc, vec<location_t> arg_loc,
    3186                 :            :                            tree function, vec<tree, va_gc> *params,
    3187                 :            :                            vec<tree, va_gc> *origtypes)
    3188                 :            : {
    3189                 :            :   /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
    3190                 :   27253800 :   STRIP_TYPE_NOPS (function);
    3191                 :            : 
    3192                 :            :   /* Convert anything with function type to a pointer-to-function.  */
    3193                 :   27253400 :   if (TREE_CODE (function) == FUNCTION_DECL)
    3194                 :            :     {
    3195                 :            :       /* Implement type-directed function overloading for builtins.
    3196                 :            :          resolve_overloaded_builtin and targetm.resolve_overloaded_builtin
    3197                 :            :          handle all the type checking.  The result is a complete expression
    3198                 :            :          that implements this function call.  */
    3199                 :   27183200 :       tree tem = resolve_overloaded_builtin (loc, function, params);
    3200                 :   27183200 :       if (tem)
    3201                 :            :         return tem;
    3202                 :            :     }
    3203                 :   27175300 :   return build_function_call_vec (loc, arg_loc, function, params, origtypes);
    3204                 :            : }
    3205                 :            : 
    3206                 :            : /* Helper for convert_arguments called to convert the VALue of argument
    3207                 :            :    number ARGNUM from ORIGTYPE to the corresponding parameter number
    3208                 :            :    PARMNUM and TYPE.
    3209                 :            :    PLOC is the location where the conversion is being performed.
    3210                 :            :    FUNCTION and FUNDECL are the same as in convert_arguments.
    3211                 :            :    VALTYPE is the original type of VAL before the conversion and,
    3212                 :            :    for EXCESS_PRECISION_EXPR, the operand of the expression.
    3213                 :            :    NPC is true if VAL represents the null pointer constant (VAL itself
    3214                 :            :    will have been folded to an integer constant).
    3215                 :            :    RNAME is the same as FUNCTION except in Objective C when it's
    3216                 :            :    the function selector.
    3217                 :            :    EXCESS_PRECISION is true when VAL was originally represented
    3218                 :            :    as EXCESS_PRECISION_EXPR.
    3219                 :            :    WARNOPT is the same as in convert_for_assignment.  */
    3220                 :            : 
    3221                 :            : static tree
    3222                 :   68807000 : convert_argument (location_t ploc, tree function, tree fundecl,
    3223                 :            :                   tree type, tree origtype, tree val, tree valtype,
    3224                 :            :                   bool npc, tree rname, int parmnum, int argnum,
    3225                 :            :                   bool excess_precision, int warnopt)
    3226                 :            : {
    3227                 :            :   /* Formal parm type is specified by a function prototype.  */
    3228                 :            : 
    3229                 :  137614000 :   if (type == error_mark_node || !COMPLETE_TYPE_P (type))
    3230                 :            :     {
    3231                 :          2 :       error_at (ploc, "type of formal parameter %d is incomplete",
    3232                 :            :                 parmnum + 1);
    3233                 :          2 :       return val;
    3234                 :            :     }
    3235                 :            : 
    3236                 :            :   /* Optionally warn about conversions that differ from the default
    3237                 :            :      conversions.  */
    3238                 :   68807000 :   if (warn_traditional_conversion || warn_traditional)
    3239                 :            :     {
    3240                 :        192 :       unsigned int formal_prec = TYPE_PRECISION (type);
    3241                 :            : 
    3242                 :        192 :       if (INTEGRAL_TYPE_P (type)
    3243                 :        107 :           && TREE_CODE (valtype) == REAL_TYPE)
    3244                 :         19 :         warning_at (ploc, OPT_Wtraditional_conversion,
    3245                 :            :                     "passing argument %d of %qE as integer rather "
    3246                 :            :                     "than floating due to prototype",
    3247                 :            :                     argnum, rname);
    3248                 :        192 :       if (INTEGRAL_TYPE_P (type)
    3249                 :        107 :           && TREE_CODE (valtype) == COMPLEX_TYPE)
    3250                 :          5 :         warning_at (ploc, OPT_Wtraditional_conversion,
    3251                 :            :                     "passing argument %d of %qE as integer rather "
    3252                 :            :                     "than complex due to prototype",
    3253                 :            :                     argnum, rname);
    3254                 :        187 :       else if (TREE_CODE (type) == COMPLEX_TYPE
    3255                 :         14 :                && TREE_CODE (valtype) == REAL_TYPE)
    3256                 :          7 :         warning_at (ploc, OPT_Wtraditional_conversion,
    3257                 :            :                     "passing argument %d of %qE as complex rather "
    3258                 :            :                     "than floating due to prototype",
    3259                 :            :                     argnum, rname);
    3260                 :        180 :       else if (TREE_CODE (type) == REAL_TYPE
    3261                 :         71 :                && INTEGRAL_TYPE_P (valtype))
    3262                 :         19 :         warning_at (ploc, OPT_Wtraditional_conversion,
    3263                 :            :                     "passing argument %d of %qE as floating rather "
    3264                 :            :                     "than integer due to prototype",
    3265                 :            :                     argnum, rname);
    3266                 :        161 :       else if (TREE_CODE (type) == COMPLEX_TYPE
    3267                 :          7 :                && INTEGRAL_TYPE_P (valtype))
    3268                 :          5 :         warning_at (ploc, OPT_Wtraditional_conversion,
    3269                 :            :                     "passing argument %d of %qE as complex rather "
    3270                 :            :                     "than integer due to prototype",
    3271                 :            :                     argnum, rname);
    3272                 :        156 :       else if (TREE_CODE (type) == REAL_TYPE
    3273                 :         52 :                && TREE_CODE (valtype) == COMPLEX_TYPE)
    3274                 :          7 :         warning_at (ploc, OPT_Wtraditional_conversion,
    3275                 :            :                     "passing argument %d of %qE as floating rather "
    3276                 :            :                     "than complex due to prototype",
    3277                 :            :                     argnum, rname);
    3278                 :            :       /* ??? At some point, messages should be written about
    3279                 :            :          conversions between complex types, but that's too messy
    3280                 :            :          to do now.  */
    3281                 :        149 :       else if (TREE_CODE (type) == REAL_TYPE
    3282                 :         45 :                && TREE_CODE (valtype) == REAL_TYPE)
    3283                 :            :         {
    3284                 :            :           /* Warn if any argument is passed as `float',
    3285                 :            :              since without a prototype it would be `double'.  */
    3286                 :         45 :           if (formal_prec == TYPE_PRECISION (float_type_node)
    3287                 :         45 :               && type != dfloat32_type_node)
    3288                 :          7 :             warning_at (ploc, 0,
    3289                 :            :                         "passing argument %d of %qE as %<float%> "
    3290                 :            :                         "rather than %<double%> due to prototype",
    3291                 :            :                         argnum, rname);
    3292                 :            : 
    3293                 :            :           /* Warn if mismatch between argument and prototype
    3294                 :            :              for decimal float types.  Warn of conversions with
    3295                 :            :              binary float types and of precision narrowing due to
    3296                 :            :              prototype.  */
    3297                 :         38 :           else if (type != valtype
    3298                 :         32 :                    && (type == dfloat32_type_node
    3299                 :         22 :                        || type == dfloat64_type_node
    3300                 :         12 :                        || type == dfloat128_type_node
    3301                 :          2 :                        || valtype == dfloat32_type_node
    3302                 :          2 :                        || valtype == dfloat64_type_node
    3303                 :          2 :                        || valtype == dfloat128_type_node)
    3304                 :         38 :                    && (formal_prec
    3305                 :         30 :                        <= TYPE_PRECISION (valtype)
    3306                 :         14 :                        || (type == dfloat128_type_node
    3307                 :         10 :                            && (valtype
    3308                 :         10 :                                != dfloat64_type_node
    3309                 :          8 :                                && (valtype
    3310                 :            :                                    != dfloat32_type_node)))
    3311                 :          8 :                        || (type == dfloat64_type_node
    3312                 :          4 :                            && (valtype
    3313                 :            :                                != dfloat32_type_node))))
    3314                 :         24 :             warning_at (ploc, 0,
    3315                 :            :                         "passing argument %d of %qE as %qT "
    3316                 :            :                         "rather than %qT due to prototype",
    3317                 :            :                         argnum, rname, type, valtype);
    3318                 :            : 
    3319                 :            :         }
    3320                 :            :       /* Detect integer changing in width or signedness.
    3321                 :            :          These warnings are only activated with
    3322                 :            :          -Wtraditional-conversion, not with -Wtraditional.  */
    3323                 :        104 :       else if (warn_traditional_conversion
    3324                 :        104 :                && INTEGRAL_TYPE_P (type)
    3325                 :        102 :                && INTEGRAL_TYPE_P (valtype))
    3326                 :            :         {
    3327                 :         83 :           tree would_have_been = default_conversion (val);
    3328                 :         83 :           tree type1 = TREE_TYPE (would_have_been);
    3329                 :            : 
    3330                 :         83 :           if (val == error_mark_node)
    3331                 :            :             /* VAL could have been of incomplete type.  */;
    3332                 :         83 :           else if (TREE_CODE (type) == ENUMERAL_TYPE
    3333                 :         85 :                    && (TYPE_MAIN_VARIANT (type)
    3334                 :          2 :                        == TYPE_MAIN_VARIANT (valtype)))
    3335                 :            :             /* No warning if function asks for enum
    3336                 :            :                and the actual arg is that enum type.  */
    3337                 :            :             ;
    3338                 :         81 :           else if (formal_prec != TYPE_PRECISION (type1))
    3339                 :         14 :             warning_at (ploc, OPT_Wtraditional_conversion,
    3340                 :            :                         "passing argument %d of %qE "
    3341                 :            :                         "with different width due to prototype",
    3342                 :            :                         argnum, rname);
    3343                 :         67 :           else if (TYPE_UNSIGNED (type) == TYPE_UNSIGNED (type1))
    3344                 :            :             ;
    3345                 :            :           /* Don't complain if the formal parameter type
    3346                 :            :              is an enum, because we can't tell now whether
    3347                 :            :              the value was an enum--even the same enum.  */
    3348                 :         32 :           else if (TREE_CODE (type) == ENUMERAL_TYPE)
    3349                 :            :             ;
    3350                 :         32 :           else if (TREE_CODE (val) == INTEGER_CST
    3351                 :          5 :                    && int_fits_type_p (val, type))
    3352                 :            :             /* Change in signedness doesn't matter
    3353                 :            :                if a constant value is unaffected.  */
    3354                 :            :             ;
    3355                 :            :           /* If the value is extended from a narrower
    3356                 :            :              unsigned type, it doesn't matter whether we
    3357                 :            :              pass it as signed or unsigned; the value
    3358                 :            :              certainly is the same either way.  */
    3359                 :         32 :           else if (TYPE_PRECISION (valtype) < TYPE_PRECISION (type)
    3360                 :         32 :                    && TYPE_UNSIGNED (valtype))
    3361                 :            :             ;
    3362                 :         32 :           else if (TYPE_UNSIGNED (type))
    3363                 :         17 :             warning_at (ploc, OPT_Wtraditional_conversion,
    3364                 :            :                         "passing argument %d of %qE "
    3365                 :            :                         "as unsigned due to prototype",
    3366                 :            :                         argnum, rname);
    3367                 :            :           else
    3368                 :         15 :             warning_at (ploc, OPT_Wtraditional_conversion,
    3369                 :            :                         "passing argument %d of %qE "
    3370                 :            :                         "as signed due to prototype",
    3371                 :            :                         argnum, rname);
    3372                 :            :         }
    3373                 :            :     }
    3374                 :            : 
    3375                 :            :   /* Possibly restore an EXCESS_PRECISION_EXPR for the
    3376                 :            :      sake of better warnings from convert_and_check.  */
    3377                 :   68807000 :   if (excess_precision)
    3378                 :          3 :     val = build1 (EXCESS_PRECISION_EXPR, valtype, val);
    3379                 :            : 
    3380                 :   68807000 :   tree parmval = convert_for_assignment (ploc, ploc, type,
    3381                 :            :                                          val, origtype, ic_argpass,
    3382                 :            :                                          npc, fundecl, function,
    3383                 :            :                                          parmnum + 1, warnopt);
    3384                 :            : 
    3385                 :  137444000 :   if (targetm.calls.promote_prototypes (fundecl ? TREE_TYPE (fundecl) : 0)
    3386                 :   68807000 :       && INTEGRAL_TYPE_P (type)
    3387                 :   93371600 :       && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
    3388                 :   13029200 :     parmval = default_conversion (parmval);
    3389                 :            : 
    3390                 :            :   return parmval;
    3391                 :            : }
    3392                 :            : 
    3393                 :            : /* Convert the argument expressions in the vector VALUES
    3394                 :            :    to the types in the list TYPELIST.
    3395                 :            : 
    3396                 :            :    If TYPELIST is exhausted, or when an element has NULL as its type,
    3397                 :            :    perform the default conversions.
    3398                 :            : 
    3399                 :            :    ORIGTYPES is the original types of the expressions in VALUES.  This
    3400                 :            :    holds the type of enum values which have been converted to integral
    3401                 :            :    types.  It may be NULL.
    3402                 :            : 
    3403                 :            :    FUNCTION is a tree for the called function.  It is used only for
    3404                 :            :    error messages, where it is formatted with %qE.
    3405                 :            : 
    3406                 :            :    This is also where warnings about wrong number of args are generated.
    3407                 :            : 
    3408                 :            :    ARG_LOC are locations of function arguments (if any).
    3409                 :            : 
    3410                 :            :    Returns the actual number of arguments processed (which may be less
    3411                 :            :    than the length of VALUES in some error situations), or -1 on
    3412                 :            :    failure.  */
    3413                 :            : 
    3414                 :            : static int
    3415                 :   27253200 : convert_arguments (location_t loc, vec<location_t> arg_loc, tree typelist,
    3416                 :            :                    vec<tree, va_gc> *values, vec<tree, va_gc> *origtypes,
    3417                 :            :                    tree function, tree fundecl)
    3418                 :            : {
    3419                 :   27253200 :   unsigned int parmnum;
    3420                 :   27253200 :   bool error_args = false;
    3421                 :   27253200 :   const bool type_generic = fundecl
    3422                 :   54436400 :     && lookup_attribute ("type generic", TYPE_ATTRIBUTES (TREE_TYPE (fundecl)));
    3423                 :   27253200 :   bool type_generic_remove_excess_precision = false;
    3424                 :   27253200 :   bool type_generic_overflow_p = false;
    3425                 :   27253200 :   tree selector;
    3426                 :            : 
    3427                 :            :   /* Change pointer to function to the function itself for
    3428                 :            :      diagnostics.  */
    3429                 :   27253200 :   if (TREE_CODE (function) == ADDR_EXPR
    3430                 :   27253200 :       && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL)
    3431                 :   27185400 :     function = TREE_OPERAND (function, 0);
    3432                 :            : 
    3433                 :            :   /* Handle an ObjC selector specially for diagnostics.  */
    3434                 :   27253200 :   selector = objc_message_selector ();
    3435                 :            : 
    3436                 :            :   /* For a call to a built-in function declared without a prototype,
    3437                 :            :      set to the built-in function's argument list.  */
    3438                 :   27253200 :   tree builtin_typelist = NULL_TREE;
    3439                 :            : 
    3440                 :            :   /* For type-generic built-in functions, determine whether excess
    3441                 :            :      precision should be removed (classification) or not
    3442                 :            :      (comparison).  */
    3443                 :   27253200 :   if (fundecl
    3444                 :   27253200 :       && fndecl_built_in_p (fundecl, BUILT_IN_NORMAL))
    3445                 :            :     {
    3446                 :     944286 :       built_in_function code = DECL_FUNCTION_CODE (fundecl);
    3447                 :     944286 :       if (C_DECL_BUILTIN_PROTOTYPE (fundecl))
    3448                 :            :         {
    3449                 :            :           /* For a call to a built-in function declared without a prototype
    3450                 :            :              use the types of the parameters of the internal built-in to
    3451                 :            :              match those of the arguments to.  */
    3452                 :     566395 :           if (tree bdecl = builtin_decl_explicit (code))
    3453                 :     566395 :             builtin_typelist = TYPE_ARG_TYPES (TREE_TYPE (bdecl));
    3454                 :            :         }
    3455                 :            : 
    3456                 :            :       /* For type-generic built-in functions, determine whether excess
    3457                 :            :          precision should be removed (classification) or not
    3458                 :            :          (comparison).  */
    3459                 :     944286 :       if (type_generic)
    3460                 :      47906 :         switch (code)
    3461                 :            :           {
    3462                 :       3889 :           case BUILT_IN_ISFINITE:
    3463                 :       3889 :           case BUILT_IN_ISINF:
    3464                 :       3889 :           case BUILT_IN_ISINF_SIGN:
    3465                 :       3889 :           case BUILT_IN_ISNAN:
    3466                 :       3889 :           case BUILT_IN_ISNORMAL:
    3467                 :       3889 :           case BUILT_IN_FPCLASSIFY:
    3468                 :       3889 :             type_generic_remove_excess_precision = true;
    3469                 :       3889 :             break;
    3470                 :            : 
    3471                 :      20459 :           case BUILT_IN_ADD_OVERFLOW_P:
    3472                 :      20459 :           case BUILT_IN_SUB_OVERFLOW_P:
    3473                 :      20459 :           case BUILT_IN_MUL_OVERFLOW_P:
    3474                 :            :             /* The last argument of these type-generic builtins
    3475                 :            :                should not be promoted.  */
    3476                 :      20459 :             type_generic_overflow_p = true;
    3477                 :      20459 :             break;
    3478                 :            : 
    3479                 :            :           default:
    3480                 :            :             break;
    3481                 :            :           }
    3482                 :            :     }
    3483                 :            : 
    3484                 :            :   /* Scan the given expressions (VALUES) and types (TYPELIST), producing
    3485                 :            :      individual converted arguments.  */
    3486                 :            : 
    3487                 :   27253200 :   tree typetail, builtin_typetail, val;
    3488                 :   27253200 :   for (typetail = typelist,
    3489                 :   27253200 :          builtin_typetail = builtin_typelist,
    3490                 :   27253200 :          parmnum = 0;
    3491                 :   96449700 :        values && values->iterate (parmnum, &val);
    3492                 :            :        ++parmnum)
    3493                 :            :     {
    3494                 :            :       /* The type of the function parameter (if it was declared with one).  */
    3495                 :  138001000 :       tree type = typetail ? TREE_VALUE (typetail) : NULL_TREE;
    3496                 :            :       /* The type of the built-in function parameter (if the function
    3497                 :            :          is a built-in).  Used to detect type incompatibilities in
    3498                 :            :          calls to built-ins declared without a prototype.  */
    3499                 :   69196500 :       tree builtin_type = (builtin_typetail
    3500                 :   70076300 :                            ? TREE_VALUE (builtin_typetail) : NULL_TREE);
    3501                 :            :       /* The original type of the argument being passed to the function.  */
    3502                 :   69196500 :       tree valtype = TREE_TYPE (val);
    3503                 :            :       /* The called function (or function selector in Objective C).  */
    3504                 :   69196500 :       tree rname = function;
    3505                 :   69196500 :       int argnum = parmnum + 1;
    3506                 :   69196500 :       const char *invalid_func_diag;
    3507                 :            :       /* Set for EXCESS_PRECISION_EXPR arguments.  */
    3508                 :   69196500 :       bool excess_precision = false;
    3509                 :            :       /* The value of the argument after conversion to the type
    3510                 :            :          of the function parameter it is passed to.  */
    3511                 :   69196500 :       tree parmval;
    3512                 :            :       /* Some __atomic_* builtins have additional hidden argument at
    3513                 :            :          position 0.  */
    3514                 :   69196500 :       location_t ploc
    3515                 :  138151000 :         = !arg_loc.is_empty () && values->length () == arg_loc.length ()
    3516                 :   69196500 :           ? expansion_point_location_if_in_system_header (arg_loc[parmnum])
    3517                 :   69196500 :           : input_location;
    3518                 :            : 
    3519                 :   69196500 :       if (type == void_type_node)
    3520                 :            :         {
    3521                 :         24 :           if (selector)
    3522                 :          0 :             error_at (loc, "too many arguments to method %qE", selector);
    3523                 :            :           else
    3524                 :         24 :             error_at (loc, "too many arguments to function %qE", function);
    3525                 :         24 :           inform_declaration (fundecl);
    3526                 :         24 :           return error_args ? -1 : (int) parmnum;
    3527                 :            :         }
    3528                 :            : 
    3529                 :   69196500 :       if (builtin_type == void_type_node)
    3530                 :            :         {
    3531                 :         12 :           if (warning_at (loc, OPT_Wbuiltin_declaration_mismatch,
    3532                 :            :                           "too many arguments to built-in function %qE "
    3533                 :            :                           "expecting %d", function, parmnum))
    3534                 :         12 :             inform_declaration (fundecl);
    3535                 :            :           builtin_typetail = NULL_TREE;
    3536                 :            :         }
    3537                 :            : 
    3538                 :   69196500 :       if (selector && argnum > 2)
    3539                 :            :         {
    3540                 :          0 :           rname = selector;
    3541                 :          0 :           argnum -= 2;
    3542                 :            :         }
    3543                 :            : 
    3544                 :            :       /* Determine if VAL is a null pointer constant before folding it.  */
    3545                 :   69196500 :       bool npc = null_pointer_constant_p (val);
    3546                 :            : 
    3547                 :            :       /* If there is excess precision and a prototype, convert once to
    3548                 :            :          the required type rather than converting via the semantic
    3549                 :            :          type.  Likewise without a prototype a float value represented
    3550                 :            :          as long double should be converted once to double.  But for
    3551                 :            :          type-generic classification functions excess precision must
    3552                 :            :          be removed here.  */
    3553                 :   69196500 :       if (TREE_CODE (val) == EXCESS_PRECISION_EXPR
    3554                 :         42 :           && (type || !type_generic || !type_generic_remove_excess_precision))
    3555                 :            :         {
    3556                 :         36 :           val = TREE_OPERAND (val, 0);
    3557                 :         36 :           excess_precision = true;
    3558                 :            :         }
    3559                 :   69196500 :       val = c_fully_fold (val, false, NULL);
    3560                 :   69196500 :       STRIP_TYPE_NOPS (val);
    3561                 :            : 
    3562                 :   69196500 :       val = require_complete_type (ploc, val);
    3563                 :            : 
    3564                 :            :       /* Some floating-point arguments must be promoted to double when
    3565                 :            :          no type is specified by a prototype.  This applies to
    3566                 :            :          arguments of type float, and to architecture-specific types
    3567                 :            :          (ARM __fp16), but not to _FloatN or _FloatNx types.  */
    3568                 :   69196500 :       bool promote_float_arg = false;
    3569                 :   69196500 :       if (type == NULL_TREE
    3570                 :     391842 :           && TREE_CODE (valtype) == REAL_TYPE
    3571                 :      55816 :           && (TYPE_PRECISION (valtype)
    3572                 :      27908 :               <= TYPE_PRECISION (double_type_node))
    3573                 :      20549 :           && TYPE_MAIN_VARIANT (valtype) != double_type_node
    3574                 :       5935 :           && TYPE_MAIN_VARIANT (valtype) != long_double_type_node
    3575                 :   69202400 :           && !DECIMAL_FLOAT_MODE_P (TYPE_MODE (valtype)))
    3576                 :            :         {
    3577                 :            :           /* Promote this argument, unless it has a _FloatN or
    3578                 :            :              _FloatNx type.  */
    3579                 :      32214 :           promote_float_arg = true;
    3580                 :      32214 :           for (int i = 0; i < NUM_FLOATN_NX_TYPES; i++)
    3581                 :      29106 :             if (TYPE_MAIN_VARIANT (valtype) == FLOATN_NX_TYPE_NODE (i))
    3582                 :            :               {
    3583                 :            :                 promote_float_arg = false;
    3584                 :            :                 break;
    3585                 :            :               }
    3586                 :            :         }
    3587                 :            : 
    3588                 :   69196500 :       if (type != NULL_TREE)
    3589                 :            :         {
    3590                 :  137365000 :           tree origtype = (!origtypes) ? NULL_TREE : (*origtypes)[parmnum];
    3591                 :   68804600 :           parmval = convert_argument (ploc, function, fundecl, type, origtype,
    3592                 :            :                                       val, valtype, npc, rname, parmnum, argnum,
    3593                 :            :                                       excess_precision, 0);
    3594                 :            :         }
    3595                 :     391842 :       else if (promote_float_arg)
    3596                 :            :         {
    3597                 :       3108 :           if (type_generic)
    3598                 :            :             parmval = val;
    3599                 :            :           else
    3600                 :            :             {
    3601                 :            :               /* Convert `float' to `double'.  */
    3602                 :        766 :               if (warn_double_promotion && !c_inhibit_evaluation_warnings)
    3603                 :          6 :                 warning_at (ploc, OPT_Wdouble_promotion,
    3604                 :            :                             "implicit conversion from %qT to %qT when passing "
    3605                 :            :                             "argument to function",
    3606                 :            :                             valtype, double_type_node);
    3607                 :        766 :               parmval = convert (double_type_node, val);
    3608                 :            :             }
    3609                 :            :         }
    3610                 :     388734 :       else if ((excess_precision && !type_generic)
    3611                 :     388732 :                || (type_generic_overflow_p && parmnum == 2))
    3612                 :            :         /* A "double" argument with excess precision being passed
    3613                 :            :            without a prototype or in variable arguments.
    3614                 :            :            The last argument of __builtin_*_overflow_p should not be
    3615                 :            :            promoted.  */
    3616                 :      20457 :         parmval = convert (valtype, val);
    3617                 :     736554 :       else if ((invalid_func_diag =
    3618                 :     368277 :                 targetm.calls.invalid_arg_for_unprototyped_fn (typelist, fundecl, val)))
    3619                 :            :         {
    3620                 :          0 :           error (invalid_func_diag);
    3621                 :          0 :           return -1;
    3622                 :            :         }
    3623                 :     368277 :       else if (TREE_CODE (val) == ADDR_EXPR && reject_gcc_builtin (val))
    3624                 :            :         {
    3625                 :            :           return -1;
    3626                 :            :         }
    3627                 :            :       else
    3628                 :            :         /* Convert `short' and `char' to full-size `int'.  */
    3629                 :     368274 :         parmval = default_conversion (val);
    3630                 :            : 
    3631                 :   69196500 :       (*values)[parmnum] = parmval;
    3632                 :   69196500 :       if (parmval == error_mark_node)
    3633                 :         82 :         error_args = true;
    3634                 :            : 
    3635                 :   69196500 :       if (!type && builtin_type && TREE_CODE (builtin_type) != VOID_TYPE)
    3636                 :            :         {
    3637                 :            :           /* For a call to a built-in function declared without a prototype,
    3638                 :            :              perform the conversions from the argument to the expected type
    3639                 :            :              but issue warnings rather than errors for any mismatches.
    3640                 :            :              Ignore the converted argument and use the PARMVAL obtained
    3641                 :            :              above by applying default conversions instead.  */
    3642                 :       4652 :           tree origtype = (!origtypes) ? NULL_TREE : (*origtypes)[parmnum];
    3643                 :       2326 :           convert_argument (ploc, function, fundecl, builtin_type, origtype,
    3644                 :            :                             val, valtype, npc, rname, parmnum, argnum,
    3645                 :            :                             excess_precision,
    3646                 :            :                             OPT_Wbuiltin_declaration_mismatch);
    3647                 :            :         }
    3648                 :            : 
    3649                 :   69196500 :       if (typetail)
    3650                 :   68804600 :         typetail = TREE_CHAIN (typetail);
    3651                 :            : 
    3652                 :   69196500 :       if (builtin_typetail)
    3653                 :     879827 :         builtin_typetail = TREE_CHAIN (builtin_typetail);
    3654                 :            :     }
    3655                 :            : 
    3656                 :   48389700 :   gcc_assert (parmnum == vec_safe_length (values));
    3657                 :            : 
    3658                 :   54309300 :   if (typetail != NULL_TREE && TREE_VALUE (typetail) != void_type_node)
    3659                 :            :     {
    3660                 :         67 :       error_at (loc, "too few arguments to function %qE", function);
    3661                 :         67 :       inform_declaration (fundecl);
    3662                 :         67 :       return -1;
    3663                 :            :     }
    3664                 :            : 
    3665                 :   27786300 :   if (builtin_typetail && TREE_VALUE (builtin_typetail) != void_type_node)
    3666                 :            :     {
    3667                 :            :       unsigned nargs = parmnum;
    3668                 :       1130 :       for (tree t = builtin_typetail; t; t = TREE_CHAIN (t))
    3669                 :        780 :         ++nargs;
    3670                 :            : 
    3671                 :        350 :       if (warning_at (loc, OPT_Wbuiltin_declaration_mismatch,
    3672                 :            :                       "too few arguments to built-in function %qE "
    3673                 :            :                       "expecting %u", function, nargs - 1))
    3674                 :        188 :         inform_declaration (fundecl);
    3675                 :            :     }
    3676                 :            : 
    3677                 :   27253100 :   return error_args ? -1 : (int) parmnum;
    3678                 :            : }
    3679                 :            : 
    3680                 :            : /* This is the entry point used by the parser to build unary operators
    3681                 :            :    in the input.  CODE, a tree_code, specifies the unary operator, and
    3682                 :            :    ARG is the operand.  For unary plus, the C parser currently uses
    3683                 :            :    CONVERT_EXPR for code.
    3684                 :            : 
    3685                 :            :    LOC is the location to use for the tree generated.
    3686                 :            : */
    3687                 :            : 
    3688                 :            : struct c_expr
    3689                 :    4466870 : parser_build_unary_op (location_t loc, enum tree_code code, struct c_expr arg)
    3690                 :            : {
    3691                 :    4466870 :   struct c_expr result;
    3692                 :            : 
    3693                 :    4466870 :   result.original_code = code;
    3694                 :    4466870 :   result.original_type = NULL;
    3695                 :            : 
    3696                 :    4466870 :   if (reject_gcc_builtin (arg.value))
    3697                 :            :     {
    3698                 :          2 :       result.value = error_mark_node;
    3699                 :            :     }
    3700                 :            :   else
    3701                 :            :     {
    3702                 :    4466870 :       result.value = build_unary_op (loc, code, arg.value, false);
    3703                 :            : 
    3704                 :    4466870 :       if (TREE_OVERFLOW_P (result.value) && !TREE_OVERFLOW_P (arg.value))
    3705                 :          5 :         overflow_warning (loc, result.value, arg.value);
    3706                 :            :     }
    3707                 :            : 
    3708                 :            :   /* We are typically called when parsing a prefix token at LOC acting on
    3709                 :            :      ARG.  Reflect this by updating the source range of the result to
    3710                 :            :      start at LOC and end at the end of ARG.  */
    3711                 :    4466870 :   set_c_expr_source_range (&result,
    3712                 :            :                            loc, arg.get_finish ());
    3713                 :            : 
    3714                 :    4466870 :   return result;
    3715                 :            : }
    3716                 :            : 
    3717                 :            : /* Returns true if TYPE is a character type, *not* including wchar_t.  */
    3718                 :            : 
    3719                 :            : static bool
    3720                 :      16327 : char_type_p (tree type)
    3721                 :            : {
    3722                 :      16327 :   return (type == char_type_node
    3723                 :      16307 :           || type == unsigned_char_type_node
    3724                 :      16307 :           || type == signed_char_type_node
    3725                 :      16307 :           || type == char16_type_node
    3726                 :      32634 :           || type == char32_type_node);
    3727                 :            : }
    3728                 :            : 
    3729                 :            : /* This is the entry point used by the parser to build binary operators
    3730                 :            :    in the input.  CODE, a tree_code, specifies the binary operator, and
    3731                 :            :    ARG1 and ARG2 are the operands.  In addition to constructing the
    3732                 :            :    expression, we check for operands that were written with other binary
    3733                 :            :    operators in a way that is likely to confuse the user.
    3734                 :            : 
    3735                 :            :    LOCATION is the location of the binary operator.  */
    3736                 :            : 
    3737                 :            : struct c_expr
    3738                 :    5861670 : parser_build_binary_op (location_t location, enum tree_code code,
    3739                 :            :                         struct c_expr arg1, struct c_expr arg2)
    3740                 :            : {
    3741                 :    5861670 :   struct c_expr result;
    3742                 :            : 
    3743                 :    5861670 :   enum tree_code code1 = arg1.original_code;
    3744                 :    5861670 :   enum tree_code code2 = arg2.original_code;
    3745                 :    5861670 :   tree type1 = (arg1.original_type
    3746                 :    5861670 :                 ? arg1.original_type
    3747                 :    4059990 :                 : TREE_TYPE (arg1.value));
    3748                 :    5861670 :   tree type2 = (arg2.original_type
    3749                 :    5861670 :                 ? arg2.original_type
    3750                 :    4856430 :                 : TREE_TYPE (arg2.value));
    3751                 :            : 
    3752                 :    5861670 :   result.value = build_binary_op (location, code,
    3753                 :            :                                   arg1.value, arg2.value, true);
    3754                 :    5861670 :   result.original_code = code;
    3755                 :    5861670 :   result.original_type = NULL;
    3756                 :            : 
    3757                 :    5861670 :   if (TREE_CODE (result.value) == ERROR_MARK)
    3758                 :            :     {
    3759                 :       1274 :       set_c_expr_source_range (&result,
    3760                 :            :                                arg1.get_start (),
    3761                 :            :                                arg2.get_finish ());
    3762                 :       1274 :       return result;
    3763                 :            :     }
    3764                 :            : 
    3765                 :    5860400 :   if (location != UNKNOWN_LOCATION)
    3766                 :    5860400 :     protected_set_expr_location (result.value, location);
    3767                 :            : 
    3768                 :    5860400 :   set_c_expr_source_range (&result,
    3769                 :            :                            arg1.get_start (),
    3770                 :            :                            arg2.get_finish ());
    3771                 :            : 
    3772                 :            :   /* Check for cases such as x+y<<z which users are likely
    3773                 :            :      to misinterpret.  */
    3774                 :    5860400 :   if (warn_parentheses)
    3775                 :     976405 :     warn_about_parentheses (location, code, code1, arg1.value, code2,
    3776                 :            :                             arg2.value);
    3777                 :            : 
    3778                 :    5860400 :   if (warn_logical_op)
    3779                 :        338 :     warn_logical_operator (location, code, TREE_TYPE (result.value),
    3780                 :            :                            code1, arg1.value, code2, arg2.value);
    3781                 :            : 
    3782                 :    5860400 :   if (warn_tautological_compare)
    3783                 :            :     {
    3784                 :     974920 :       tree lhs = arg1.value;
    3785                 :     974920 :       tree rhs = arg2.value;
    3786                 :     974920 :       if (TREE_CODE (lhs) == C_MAYBE_CONST_EXPR)
    3787                 :            :         {
    3788                 :          2 :           if (C_MAYBE_CONST_EXPR_PRE (lhs) != NULL_TREE
    3789                 :          2 :               && TREE_SIDE_EFFECTS (C_MAYBE_CONST_EXPR_PRE (lhs)))
    3790                 :            :             lhs = NULL_TREE;
    3791                 :            :           else
    3792                 :          2 :             lhs = C_MAYBE_CONST_EXPR_EXPR (lhs);
    3793                 :            :         }
    3794                 :     974920 :       if (TREE_CODE (rhs) == C_MAYBE_CONST_EXPR)
    3795                 :            :         {
    3796                 :          8 :           if (C_MAYBE_CONST_EXPR_PRE (rhs) != NULL_TREE
    3797                 :          8 :               && TREE_SIDE_EFFECTS (C_MAYBE_CONST_EXPR_PRE (rhs)))
    3798                 :            :             rhs = NULL_TREE;
    3799                 :            :           else
    3800                 :          8 :             rhs = C_MAYBE_CONST_EXPR_EXPR (rhs);
    3801                 :            :         }
    3802                 :     974920 :       if (lhs != NULL_TREE && rhs != NULL_TREE)
    3803                 :     974920 :         warn_tautological_cmp (location, code, lhs, rhs);
    3804                 :            :     }
    3805                 :            : 
    3806                 :    5860400 :   if (warn_logical_not_paren
    3807                 :     975003 :       && TREE_CODE_CLASS (code) == tcc_comparison
    3808                 :     250071 :       && code1 == TRUTH_NOT_EXPR
    3809                 :     250071 :       && code2 != TRUTH_NOT_EXPR
    3810                 :            :       /* Avoid warning for !!x == y.  */
    3811                 :    5860520 :       && (TREE_CODE (arg1.value) != NE_EXPR
    3812                 :         19 :           || !integer_zerop (TREE_OPERAND (arg1.value, 1))))
    3813                 :            :     {
    3814                 :            :       /* Avoid warning for !b == y where b has _Bool type.  */
    3815                 :        107 :       tree t = integer_zero_node;
    3816                 :        107 :       if (TREE_CODE (arg1.value) == EQ_EXPR
    3817                 :         98 :           && integer_zerop (TREE_OPERAND (arg1.value, 1))
    3818                 :        205 :           && TREE_TYPE (TREE_OPERAND (arg1.value, 0)) == integer_type_node)
    3819                 :            :         {
    3820                 :         90 :           t = TREE_OPERAND (arg1.value, 0);
    3821                 :        199 :           do
    3822                 :            :             {
    3823                 :        199 :               if (TREE_TYPE (t) != integer_type_node)
    3824                 :            :                 break;
    3825                 :        180 :               if (TREE_CODE (t) == C_MAYBE_CONST_EXPR)
    3826                 :         90 :                 t = C_MAYBE_CONST_EXPR_EXPR (t);
    3827                 :         90 :               else if (CONVERT_EXPR_P (t))
    3828                 :         19 :                 t = TREE_OPERAND (t, 0);
    3829                 :            :               else
    3830                 :            :                 break;
    3831                 :            :             }
    3832                 :            :           while (1);
    3833                 :            :         }
    3834                 :        107 :       if (TREE_CODE (TREE_TYPE (t)) != BOOLEAN_TYPE)
    3835                 :         88 :         warn_logical_not_parentheses (location, code, arg1.value, arg2.value);
    3836                 :            :     }
    3837                 :            : 
    3838                 :            :   /* Warn about comparisons against string literals, with the exception
    3839                 :            :      of testing for equality or inequality of a string literal with NULL.  */
    3840                 :    5860400 :   if (code == EQ_EXPR || code == NE_EXPR)
    3841                 :            :     {
    3842                 :     932645 :       if ((code1 == STRING_CST
    3843                 :         16 :            && !integer_zerop (tree_strip_nop_conversions (arg2.value)))
    3844                 :     932656 :           || (code2 == STRING_CST
    3845                 :         24 :               && !integer_zerop (tree_strip_nop_conversions (arg1.value))))
    3846                 :         21 :         warning_at (location, OPT_Waddress,
    3847                 :            :                     "comparison with string literal results in unspecified behavior");
    3848                 :            :       /* Warn for ptr == '\0', it's likely that it should've been ptr[0].  */
    3849                 :     932645 :       if (POINTER_TYPE_P (type1)
    3850                 :      58594 :           && null_pointer_constant_p (arg2.value)
    3851                 :     932645 :           && char_type_p (type2))
    3852                 :            :         {
    3853                 :         20 :           auto_diagnostic_group d;
    3854                 :         10 :           if (warning_at (location, OPT_Wpointer_compare,
    3855                 :            :                             "comparison between pointer and zero character "
    3856                 :            :                             "constant"))
    3857                 :         10 :             inform (arg1.get_start (),
    3858                 :            :                       "did you mean to dereference the pointer?");
    3859                 :            :         }
    3860                 :     932635 :       else if (POINTER_TYPE_P (type2)
    3861                 :      55978 :                && null_pointer_constant_p (arg1.value)
    3862                 :     932635 :                && char_type_p (type1))
    3863                 :            :         {
    3864                 :         20 :           auto_diagnostic_group d;
    3865                 :         10 :           if (warning_at (location, OPT_Wpointer_compare,
    3866                 :            :                             "comparison between pointer and zero character "
    3867                 :            :                             "constant"))
    3868                 :         10 :             inform (arg2.get_start (),
    3869                 :            :                       "did you mean to dereference the pointer?");
    3870                 :            :         }
    3871                 :            :     }
    3872                 :    4927750 :   else if (TREE_CODE_CLASS (code) == tcc_comparison
    3873                 :     736784 :            && (code1 == STRING_CST || code2 == STRING_CST))
    3874                 :          0 :     warning_at (location, OPT_Waddress,
    3875                 :            :                 "comparison with string literal results in unspecified behavior");
    3876                 :            : 
    3877                 :    1496080 :   if (TREE_OVERFLOW_P (result.value)
    3878                 :        208 :       && !TREE_OVERFLOW_P (arg1.value)
    3879                 :    5860600 :       && !TREE_OVERFLOW_P (arg2.value))
    3880                 :        159 :     overflow_warning (location, result.value);
    3881                 :            : 
    3882                 :            :   /* Warn about comparisons of different enum types.  */
    3883                 :    5860400 :   if (warn_enum_compare
    3884                 :     991120 :       && TREE_CODE_CLASS (code) == tcc_comparison
    3885                 :     253178 :       && TREE_CODE (type1) == ENUMERAL_TYPE
    3886                 :       5832 :       && TREE_CODE (type2) == ENUMERAL_TYPE
    3887                 :    5866040 :       && TYPE_MAIN_VARIANT (type1) != TYPE_MAIN_VARIANT (type2))
    3888                 :          2 :     warning_at (location, OPT_Wenum_compare,
    3889                 :            :                 "comparison between %qT and %qT",
    3890                 :            :                 type1, type2);
    3891                 :            : 
    3892                 :            :   return result;
    3893                 :            : }
    3894                 :            : 
    3895                 :            : /* Return a tree for the difference of pointers OP0 and OP1.
    3896                 :            :    The resulting tree has type ptrdiff_t.  If POINTER_SUBTRACT sanitization is
    3897                 :            :    enabled, assign to INSTRUMENT_EXPR call to libsanitizer.  */
    3898                 :            : 
    3899                 :            : static tree
    3900                 :       2895 : pointer_diff (location_t loc, tree op0, tree op1, tree *instrument_expr)
    3901                 :            : {
    3902                 :       2895 :   tree restype = ptrdiff_type_node;
    3903                 :       2895 :   tree result, inttype;
    3904                 :            : 
    3905                 :       2895 :   addr_space_t as0 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (op0)));
    3906                 :       2895 :   addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (op1)));
    3907                 :       2895 :   tree target_type = TREE_TYPE (TREE_TYPE (op0));
    3908                 :       2895 :   tree orig_op0 = op0;
    3909                 :       2895 :   tree orig_op1 = op1;
    3910                 :            : 
    3911                 :            :   /* If the operands point into different address spaces, we need to
    3912                 :            :      explicitly convert them to pointers into the common address space
    3913                 :            :      before we can subtract the numerical address values.  */
    3914                 :       2895 :   if (as0 != as1)
    3915                 :            :     {
    3916                 :          0 :       addr_space_t as_common;
    3917                 :          0 :       tree common_type;
    3918                 :            : 
    3919                 :            :       /* Determine the common superset address space.  This is guaranteed
    3920                 :            :          to exist because the caller verified that comp_target_types
    3921                 :            :          returned non-zero.  */
    3922                 :          0 :       if (!addr_space_superset (as0, as1, &as_common))
    3923                 :          0 :         gcc_unreachable ();
    3924                 :            : 
    3925                 :          0 :       common_type = common_pointer_type (TREE_TYPE (op0), TREE_TYPE (op1));
    3926                 :          0 :       op0 = convert (common_type, op0);
    3927                 :          0 :       op1 = convert (common_type, op1);
    3928                 :            :     }
    3929                 :            : 
    3930                 :            :   /* Determine integer type result of the subtraction.  This will usually
    3931                 :            :      be the same as the result type (ptrdiff_t), but may need to be a wider
    3932                 :            :      type if pointers for the address space are wider than ptrdiff_t.  */
    3933                 :       2895 :   if (TYPE_PRECISION (restype) < TYPE_PRECISION (TREE_TYPE (op0)))
    3934                 :          0 :     inttype = c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op0)), 0);
    3935                 :            :   else
    3936                 :            :     inttype = restype;
    3937                 :            : 
    3938                 :       2895 :   if (TREE_CODE (target_type) == VOID_TYPE)
    3939                 :        129 :     pedwarn (loc, OPT_Wpointer_arith,
    3940                 :            :              "pointer of type %<void *%> used in subtraction");
    3941                 :       2895 :   if (TREE_CODE (target_type) == FUNCTION_TYPE)
    3942                 :          4 :     pedwarn (loc, OPT_Wpointer_arith,
    3943                 :            :              "pointer to a function used in subtraction");
    3944                 :            : 
    3945                 :       2895 :   if (sanitize_flags_p (SANITIZE_POINTER_SUBTRACT))
    3946                 :            :     {
    3947                 :         35 :       gcc_assert (current_function_decl != NULL_TREE);
    3948                 :            : 
    3949                 :         35 :       op0 = save_expr (op0);
    3950                 :         35 :       op1 = save_expr (op1);
    3951                 :            : 
    3952                 :         35 :       tree tt = builtin_decl_explicit (BUILT_IN_ASAN_POINTER_SUBTRACT);
    3953                 :         35 :       *instrument_expr = build_call_expr_loc (loc, tt, 2, op0, op1);
    3954                 :            :     }
    3955                 :            : 
    3956                 :            :   /* First do the subtraction, then build the divide operator
    3957                 :            :      and only convert at the very end.
    3958                 :            :      Do not do default conversions in case restype is a short type.  */
    3959                 :            : 
    3960                 :            :   /* POINTER_DIFF_EXPR requires a signed integer type of the same size as
    3961                 :            :      pointers.  If some platform cannot provide that, or has a larger
    3962                 :            :      ptrdiff_type to support differences larger than half the address
    3963                 :            :      space, cast the pointers to some larger integer type and do the
    3964                 :            :      computations in that type.  */
    3965                 :       2895 :   if (TYPE_PRECISION (inttype) > TYPE_PRECISION (TREE_TYPE (op0)))
    3966                 :          0 :     op0 = build_binary_op (loc, MINUS_EXPR, convert (inttype, op0),
    3967                 :            :                            convert (inttype, op1), false);
    3968                 :            :   else
    3969                 :            :     {
    3970                 :            :       /* Cast away qualifiers.  */
    3971                 :       2895 :       op0 = convert (c_common_type (TREE_TYPE (op0), TREE_TYPE (op0)), op0);
    3972                 :       2895 :       op1 = convert (c_common_type (TREE_TYPE (op1), TREE_TYPE (op1)), op1);
    3973                 :       2895 :       op0 = build2_loc (loc, POINTER_DIFF_EXPR, inttype, op0, op1);
    3974                 :            :     }
    3975                 :            : 
    3976                 :            :   /* This generates an error if op1 is pointer to incomplete type.  */
    3977                 :       2895 :   if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (orig_op1))))
    3978                 :          4 :     error_at (loc, "arithmetic on pointer to an incomplete type");
    3979                 :       5782 :   else if (verify_type_context (loc, TCTX_POINTER_ARITH,
    3980                 :       2891 :                                 TREE_TYPE (TREE_TYPE (orig_op0))))
    3981                 :       2891 :     verify_type_context (loc, TCTX_POINTER_ARITH,
    3982                 :       2891 :                          TREE_TYPE (TREE_TYPE (orig_op1)));
    3983                 :            : 
    3984                 :       2895 :   op1 = c_size_in_bytes (target_type);
    3985                 :            : 
    3986                 :       2895 :   if (pointer_to_zero_sized_aggr_p (TREE_TYPE (orig_op1)))
    3987                 :          4 :     error_at (loc, "arithmetic on pointer to an empty aggregate");
    3988                 :            : 
    3989                 :            :   /* Divide by the size, in easiest possible way.  */
    3990                 :       2895 :   result = fold_build2_loc (loc, EXACT_DIV_EXPR, inttype,
    3991                 :            :                             op0, convert (inttype, op1));
    3992                 :            : 
    3993                 :            :   /* Convert to final result type if necessary.  */
    3994                 :       2895 :   return convert (restype, result);
    3995                 :            : }
    3996                 :            : 
    3997                 :            : /* Expand atomic compound assignments into an appropriate sequence as
    3998                 :            :    specified by the C11 standard section 6.5.16.2.
    3999                 :            : 
    4000                 :            :        _Atomic T1 E1
    4001                 :            :        T2 E2
    4002                 :            :        E1 op= E2
    4003                 :            : 
    4004                 :            :   This sequence is used for all types for which these operations are
    4005                 :            :   supported.
    4006                 :            : 
    4007                 :            :   In addition, built-in versions of the 'fe' prefixed routines may
    4008                 :            :   need to be invoked for floating point (real, complex or vector) when
    4009                 :            :   floating-point exceptions are supported.  See 6.5.16.2 footnote 113.
    4010                 :            : 
    4011                 :            :   T1 newval;
    4012                 :            :   T1 old;
    4013                 :            :   T1 *addr
    4014                 :            :   T2 val
    4015                 :            :   fenv_t fenv
    4016                 :            : 
    4017                 :            :   addr = &E1;
    4018                 :            :   val = (E2);
    4019                 :            :   __atomic_load (addr, &old, SEQ_CST);
    4020                 :            :   feholdexcept (&fenv);
    4021                 :            : loop:
    4022                 :            :     newval = old op val;
    4023                 :            :     if (__atomic_compare_exchange_strong (addr, &old, &newval, SEQ_CST,
    4024                 :            :                                           SEQ_CST))
    4025                 :            :       goto done;
    4026                 :            :     feclearexcept (FE_ALL_EXCEPT);
    4027                 :            :     goto loop:
    4028                 :            : done:
    4029                 :            :   feupdateenv (&fenv);
    4030                 :            : 
    4031                 :            :   The compiler will issue the __atomic_fetch_* built-in when possible,
    4032                 :            :   otherwise it will generate the generic form of the atomic operations.
    4033                 :            :   This requires temp(s) and has their address taken.  The atomic processing
    4034                 :            :   is smart enough to figure out when the size of an object can utilize
    4035                 :            :   a lock-free version, and convert the built-in call to the appropriate
    4036                 :            :   lock-free routine.  The optimizers will then dispose of any temps that
    4037                 :            :   are no longer required, and lock-free implementations are utilized as
    4038                 :            :   long as there is target support for the required size.
    4039                 :            : 
    4040                 :            :   If the operator is NOP_EXPR, then this is a simple assignment, and
    4041                 :            :   an __atomic_store is issued to perform the assignment rather than
    4042                 :            :   the above loop.  */
    4043                 :            : 
    4044                 :            : /* Build an atomic assignment at LOC, expanding into the proper
    4045                 :            :    sequence to store LHS MODIFYCODE= RHS.  Return a value representing
    4046                 :            :    the result of the operation, unless RETURN_OLD_P, in which case
    4047                 :            :    return the old value of LHS (this is only for postincrement and
    4048                 :            :    postdecrement).  */
    4049                 :            : 
    4050                 :            : static tree
    4051                 :      30046 : build_atomic_assign (location_t loc, tree lhs, enum tree_code modifycode,
    4052                 :            :                      tree rhs, bool return_old_p)
    4053                 :            : {
    4054                 :      30046 :   tree fndecl, func_call;
    4055                 :      30046 :   vec<tree, va_gc> *params;
    4056                 :      30046 :   tree val, nonatomic_lhs_type, nonatomic_rhs_type, newval, newval_addr;
    4057                 :      30046 :   tree old, old_addr;
    4058                 :      30046 :   tree compound_stmt;
    4059                 :      30046 :   tree stmt, goto_stmt;
    4060                 :      30046 :   tree loop_label, loop_decl, done_label, done_decl;
    4061                 :            : 
    4062                 :      30046 :   tree lhs_type = TREE_TYPE (lhs);
    4063                 :      30046 :   tree lhs_addr = build_unary_op (loc, ADDR_EXPR, lhs, false);
    4064                 :      30046 :   tree seq_cst = build_int_cst (integer_type_node, MEMMODEL_SEQ_CST);
    4065                 :      30046 :   tree rhs_semantic_type = TREE_TYPE (rhs);
    4066                 :      30046 :   tree nonatomic_rhs_semantic_type;
    4067                 :      30046 :   tree rhs_type;
    4068                 :            : 
    4069                 :      30046 :   gcc_assert (TYPE_ATOMIC (lhs_type));
    4070                 :            : 
    4071                 :      30046 :   if (return_old_p)
    4072                 :       2286 :     gcc_assert (modifycode == PLUS_EXPR || modifycode == MINUS_EXPR);
    4073                 :            : 
    4074                 :            :   /* Allocate enough vector items for a compare_exchange.  */
    4075                 :      30046 :   vec_alloc (params, 6);
    4076                 :            : 
    4077                 :            :   /* Create a compound statement to hold the sequence of statements
    4078                 :            :      with a loop.  */
    4079                 :      30046 :   compound_stmt = c_begin_compound_stmt (false);
    4080                 :            : 
    4081                 :            :   /* Remove any excess precision (which is only present here in the
    4082                 :            :      case of compound assignments).  */
    4083                 :      30046 :   if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
    4084                 :            :     {
    4085                 :          0 :       gcc_assert (modifycode != NOP_EXPR);
    4086                 :          0 :       rhs = TREE_OPERAND (rhs, 0);
    4087                 :            :     }
    4088                 :      30046 :   rhs_type = TREE_TYPE (rhs);
    4089                 :            : 
    4090                 :            :   /* Fold the RHS if it hasn't already been folded.  */
    4091                 :      30046 :   if (modifycode != NOP_EXPR)
    4092                 :      19862 :     rhs = c_fully_fold (rhs, false, NULL);
    4093                 :            : 
    4094                 :            :   /* Remove the qualifiers for the rest of the expressions and create
    4095                 :            :      the VAL temp variable to hold the RHS.  */
    4096                 :      30046 :   nonatomic_lhs_type = build_qualified_type (lhs_type, TYPE_UNQUALIFIED);
    4097                 :      30046 :   nonatomic_rhs_type = build_qualified_type (rhs_type, TYPE_UNQUALIFIED);
    4098                 :      30046 :   nonatomic_rhs_semantic_type = build_qualified_type (rhs_semantic_type,
    4099                 :            :                                                       TYPE_UNQUALIFIED);
    4100                 :      30046 :   val = create_tmp_var_raw (nonatomic_rhs_type);
    4101                 :      30046 :   TREE_ADDRESSABLE (val) = 1;
    4102                 :      30046 :   TREE_NO_WARNING (val) = 1;
    4103                 :      30046 :   rhs = build4 (TARGET_EXPR, nonatomic_rhs_type, val, rhs, NULL_TREE,
    4104                 :            :                 NULL_TREE);
    4105                 :      30046 :   SET_EXPR_LOCATION (rhs, loc);
    4106                 :      30046 :   add_stmt (rhs);
    4107                 :            : 
    4108                 :            :   /* NOP_EXPR indicates it's a straight store of the RHS. Simply issue
    4109                 :            :      an atomic_store.  */
    4110                 :      30046 :   if (modifycode == NOP_EXPR)
    4111                 :            :     {
    4112                 :            :       /* Build __atomic_store (&lhs, &val, SEQ_CST)  */
    4113                 :      10184 :       rhs = build_unary_op (loc, ADDR_EXPR, val, false);
    4114                 :      10184 :       fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_STORE);
    4115                 :      10184 :       params->quick_push (lhs_addr);
    4116                 :      10184 :       params->quick_push (rhs);
    4117                 :      10184 :       params->quick_push (seq_cst);
    4118                 :      10184 :       func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
    4119                 :      10184 :       add_stmt (func_call);
    4120                 :            : 
    4121                 :            :       /* Finish the compound statement.  */
    4122                 :      10184 :       compound_stmt = c_end_compound_stmt (loc, compound_stmt, false);
    4123                 :            : 
    4124                 :            :       /* VAL is the value which was stored, return a COMPOUND_STMT of
    4125                 :            :          the statement and that value.  */
    4126                 :      10184 :       return build2 (COMPOUND_EXPR, nonatomic_lhs_type, compound_stmt, val);
    4127                 :            :     }
    4128                 :            : 
    4129                 :            :   /* Attempt to implement the atomic operation as an __atomic_fetch_* or
    4130                 :            :      __atomic_*_fetch built-in rather than a CAS loop.  atomic_bool type
    4131                 :            :      isn't applicable for such builtins.  ??? Do we want to handle enums?  */
    4132                 :      19862 :   if ((TREE_CODE (lhs_type) == INTEGER_TYPE || POINTER_TYPE_P (lhs_type))
    4133                 :      13917 :       && TREE_CODE (rhs_type) == INTEGER_TYPE)
    4134                 :            :     {
    4135                 :      11689 :       built_in_function fncode;
    4136                 :      11689 :       switch (modifycode)
    4137                 :            :         {
    4138                 :       3060 :         case PLUS_EXPR:
    4139                 :       3060 :         case POINTER_PLUS_EXPR:
    4140                 :       3060 :           fncode = (return_old_p
    4141                 :       3060 :                     ? BUILT_IN_ATOMIC_FETCH_ADD_N
    4142                 :            :                     : BUILT_IN_ATOMIC_ADD_FETCH_N);
    4143                 :            :           break;
    4144                 :       2883 :         case MINUS_EXPR:
    4145                 :       2883 :           fncode = (return_old_p
    4146                 :       2883 :                     ? BUILT_IN_ATOMIC_FETCH_SUB_N
    4147                 :            :                     : BUILT_IN_ATOMIC_SUB_FETCH_N);
    4148                 :            :           break;
    4149                 :        609 :         case BIT_AND_EXPR:
    4150                 :        609 :           fncode = (return_old_p
    4151                 :        609 :                     ? BUILT_IN_ATOMIC_FETCH_AND_N
    4152                 :            :                     : BUILT_IN_ATOMIC_AND_FETCH_N);
    4153                 :            :           break;
    4154                 :        609 :         case BIT_IOR_EXPR:
    4155                 :        609 :           fncode = (return_old_p
    4156                 :        609 :                     ? BUILT_IN_ATOMIC_FETCH_OR_N
    4157                 :            :                     : BUILT_IN_ATOMIC_OR_FETCH_N);
    4158                 :            :           break;
    4159                 :        609 :         case BIT_XOR_EXPR:
    4160                 :        609 :           fncode = (return_old_p
    4161                 :        609 :                     ? BUILT_IN_ATOMIC_FETCH_XOR_N
    4162                 :            :                     : BUILT_IN_ATOMIC_XOR_FETCH_N);
    4163                 :            :           break;
    4164                 :       3919 :         default:
    4165                 :       3919 :           goto cas_loop;
    4166                 :            :         }
    4167                 :            : 
    4168                 :            :       /* We can only use "_1" through "_16" variants of the atomic fetch
    4169                 :            :          built-ins.  */
    4170                 :       7770 :       unsigned HOST_WIDE_INT size = tree_to_uhwi (TYPE_SIZE_UNIT (lhs_type));
    4171                 :       7770 :       if (size != 1 && size != 2 && size != 4 && size != 8 && size != 16)
    4172                 :          0 :         goto cas_loop;
    4173                 :            : 
    4174                 :            :       /* If this is a pointer type, we need to multiply by the size of
    4175                 :            :          the pointer target type.  */
    4176                 :       7770 :       if (POINTER_TYPE_P (lhs_type))
    4177                 :            :         {
    4178                 :       1018 :           if (!COMPLETE_TYPE_P (TREE_TYPE (lhs_type))
    4179                 :            :               /* ??? This would introduce -Wdiscarded-qualifiers
    4180                 :            :                  warning: __atomic_fetch_* expect volatile void *
    4181                 :            :                  type as the first argument.  (Assignments between
    4182                 :            :                  atomic and non-atomic objects are OK.) */
    4183                 :       1018 :               || TYPE_RESTRICT (lhs_type))
    4184                 :         17 :             goto cas_loop;
    4185                 :       1001 :           tree sz = TYPE_SIZE_UNIT (TREE_TYPE (lhs_type));
    4186                 :       1001 :           rhs = fold_build2_loc (loc, MULT_EXPR, ptrdiff_type_node,
    4187                 :            :                                  convert (ptrdiff_type_node, rhs),
    4188                 :            :                                  convert (ptrdiff_type_node, sz));
    4189                 :            :         }
    4190                 :            : 
    4191                 :            :       /* Build __atomic_fetch_* (&lhs, &val, SEQ_CST), or
    4192                 :            :          __atomic_*_fetch (&lhs, &val, SEQ_CST).  */
    4193                 :       7753 :       fndecl = builtin_decl_explicit (fncode);
    4194                 :       7753 :       params->quick_push (lhs_addr);
    4195                 :       7753 :       params->quick_push (rhs);
    4196                 :       7753 :       params->quick_push (seq_cst);
    4197                 :       7753 :       func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
    4198                 :            : 
    4199                 :       7753 :       newval = create_tmp_var_raw (nonatomic_lhs_type);
    4200                 :       7753 :       TREE_ADDRESSABLE (newval) = 1;
    4201                 :       7753 :       TREE_NO_WARNING (newval) = 1;
    4202                 :       7753 :       rhs = build4 (TARGET_EXPR, nonatomic_lhs_type, newval, func_call,
    4203                 :            :                     NULL_TREE, NULL_TREE);
    4204                 :       7753 :       SET_EXPR_LOCATION (rhs, loc);
    4205                 :       7753 :       add_stmt (rhs);
    4206                 :            : 
    4207                 :            :       /* Finish the compound statement.  */
    4208                 :       7753 :       compound_stmt = c_end_compound_stmt (loc, compound_stmt, false);
    4209                 :            : 
    4210                 :            :       /* NEWVAL is the value which was stored, return a COMPOUND_STMT of
    4211                 :            :          the statement and that value.  */
    4212                 :       7753 :       return build2 (COMPOUND_EXPR, nonatomic_lhs_type, compound_stmt, newval);
    4213                 :            :     }
    4214                 :            : 
    4215                 :       8173 : cas_loop:
    4216                 :            :   /* Create the variables and labels required for the op= form.  */
    4217                 :      12109 :   old = create_tmp_var_raw (nonatomic_lhs_type);
    4218                 :      12109 :   old_addr = build_unary_op (loc, ADDR_EXPR, old, false);
    4219                 :      12109 :   TREE_ADDRESSABLE (old) = 1;
    4220                 :      12109 :   TREE_NO_WARNING (old) = 1;
    4221                 :            : 
    4222                 :      12109 :   newval = create_tmp_var_raw (nonatomic_lhs_type);
    4223                 :      12109 :   newval_addr = build_unary_op (loc, ADDR_EXPR, newval, false);
    4224                 :      12109 :   TREE_ADDRESSABLE (newval) = 1;
    4225                 :      12109 :   TREE_NO_WARNING (newval) = 1;
    4226                 :            : 
    4227                 :      12109 :   loop_decl = create_artificial_label (loc);
    4228                 :      12109 :   loop_label = build1 (LABEL_EXPR, void_type_node, loop_decl);
    4229                 :            : 
    4230                 :      12109 :   done_decl = create_artificial_label (loc);
    4231                 :      12109 :   done_label = build1 (LABEL_EXPR, void_type_node, done_decl);
    4232                 :            : 
    4233                 :            :   /* __atomic_load (addr, &old, SEQ_CST).  */
    4234                 :      12109 :   fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_LOAD);
    4235                 :      12109 :   params->quick_push (lhs_addr);
    4236                 :      12109 :   params->quick_push (old_addr);
    4237                 :      12109 :   params->quick_push (seq_cst);
    4238                 :      12109 :   func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
    4239                 :      12109 :   old = build4 (TARGET_EXPR, nonatomic_lhs_type, old, func_call, NULL_TREE,
    4240                 :            :                 NULL_TREE);
    4241                 :      12109 :   add_stmt (old);
    4242                 :      12109 :   params->truncate (0);
    4243                 :            : 
    4244                 :            :   /* Create the expressions for floating-point environment
    4245                 :            :      manipulation, if required.  */
    4246                 :      12109 :   bool need_fenv = (flag_trapping_math
    4247                 :      14947 :                     && (FLOAT_TYPE_P (lhs_type) || FLOAT_TYPE_P (rhs_type)));
    4248                 :      12109 :   tree hold_call = NULL_TREE, clear_call = NULL_TREE, update_call = NULL_TREE;
    4249                 :      12109 :   if (need_fenv)
    4250                 :       7052 :     targetm.atomic_assign_expand_fenv (&hold_call, &clear_call, &update_call);
    4251                 :            : 
    4252                 :      12109 :   if (hold_call)
    4253                 :       7052 :     add_stmt (hold_call);
    4254                 :            : 
    4255                 :            :   /* loop:  */
    4256                 :      12109 :   add_stmt (loop_label);
    4257                 :            : 
    4258                 :            :   /* newval = old + val;  */
    4259                 :      12109 :   if (rhs_type != rhs_semantic_type)
    4260                 :          0 :     val = build1 (EXCESS_PRECISION_EXPR, nonatomic_rhs_semantic_type, val);
    4261                 :      12109 :   rhs = build_binary_op (loc, modifycode, old, val, true);
    4262                 :      12109 :   if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
    4263                 :            :     {
    4264                 :          0 :       tree eptype = TREE_TYPE (rhs);
    4265                 :          0 :       rhs = c_fully_fold (TREE_OPERAND (rhs, 0), false, NULL);
    4266                 :          0 :       rhs = build1 (EXCESS_PRECISION_EXPR, eptype, rhs);
    4267                 :            :     }
    4268                 :            :   else
    4269                 :      12109 :     rhs = c_fully_fold (rhs, false, NULL);
    4270                 :      12109 :   rhs = convert_for_assignment (loc, UNKNOWN_LOCATION, nonatomic_lhs_type,
    4271                 :            :                                 rhs, NULL_TREE, ic_assign, false, NULL_TREE,
    4272                 :            :                                 NULL_TREE, 0);
    4273                 :      12109 :   if (rhs != error_mark_node)
    4274                 :            :     {
    4275                 :      12100 :       rhs = build4 (TARGET_EXPR, nonatomic_lhs_type, newval, rhs, NULL_TREE,
    4276                 :            :                     NULL_TREE);
    4277                 :      12100 :       SET_EXPR_LOCATION (rhs, loc);
    4278                 :      12100 :       add_stmt (rhs);
    4279                 :            :     }
    4280                 :            : 
    4281                 :            :   /* if (__atomic_compare_exchange (addr, &old, &new, false, SEQ_CST, SEQ_CST))
    4282                 :            :        goto done;  */
    4283                 :      12109 :   fndecl = builtin_decl_explicit (BUILT_IN_ATOMIC_COMPARE_EXCHANGE);
    4284                 :      12109 :   params->quick_push (lhs_addr);
    4285                 :      12109 :   params->quick_push (old_addr);
    4286                 :      12109 :   params->quick_push (newval_addr);
    4287                 :      12109 :   params->quick_push (integer_zero_node);
    4288                 :      12109 :   params->quick_push (seq_cst);
    4289                 :      12109 :   params->quick_push (seq_cst);
    4290                 :      12109 :   func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
    4291                 :            : 
    4292                 :      12109 :   goto_stmt = build1 (GOTO_EXPR, void_type_node, done_decl);
    4293                 :      12109 :   SET_EXPR_LOCATION (goto_stmt, loc);
    4294                 :            : 
    4295                 :      12109 :   stmt = build3 (COND_EXPR, void_type_node, func_call, goto_stmt, NULL_TREE);
    4296                 :      12109 :   SET_EXPR_LOCATION (stmt, loc);
    4297                 :      12109 :   add_stmt (stmt);
    4298                 :            : 
    4299                 :      12109 :   if (clear_call)
    4300                 :       7052 :     add_stmt (clear_call);
    4301                 :            : 
    4302                 :            :   /* goto loop;  */
    4303                 :      12109 :   goto_stmt  = build1 (GOTO_EXPR, void_type_node, loop_decl);
    4304                 :      12109 :   SET_EXPR_LOCATION (goto_stmt, loc);
    4305                 :      12109 :   add_stmt (goto_stmt);
    4306                 :            : 
    4307                 :            :   /* done:  */
    4308                 :      12109 :   add_stmt (done_label);
    4309                 :            : 
    4310                 :      12109 :   if (update_call)
    4311                 :       7052 :     add_stmt (update_call);
    4312                 :            : 
    4313                 :            :   /* Finish the compound statement.  */
    4314                 :      12109 :   compound_stmt = c_end_compound_stmt (loc, compound_stmt, false);
    4315                 :            : 
    4316                 :            :   /* NEWVAL is the value that was successfully stored, return a
    4317                 :            :      COMPOUND_EXPR of the statement and the appropriate value.  */
    4318                 :      23665 :   return build2 (COMPOUND_EXPR, nonatomic_lhs_type, compound_stmt,
    4319                 :      12109 :                  return_old_p ? old : newval);
    4320                 :            : }
    4321                 :            : 
    4322                 :            : /* Construct and perhaps optimize a tree representation
    4323                 :            :    for a unary operation.  CODE, a tree_code, specifies the operation
    4324                 :            :    and XARG is the operand.
    4325                 :            :    For any CODE other than ADDR_EXPR, NOCONVERT suppresses the default
    4326                 :            :    promotions (such as from short to int).
    4327                 :            :    For ADDR_EXPR, the default promotions are not applied; NOCONVERT allows
    4328                 :            :    non-lvalues; this is only used to handle conversion of non-lvalue arrays
    4329                 :            :    to pointers in C99.
    4330                 :            : 
    4331                 :            :    LOCATION is the location of the operator.  */
    4332                 :            : 
    4333                 :            : tree
    4334                 :   33411600 : build_unary_op (location_t location, enum tree_code code, tree xarg,
    4335                 :            :                 bool noconvert)
    4336                 :            : {
    4337                 :            :   /* No default_conversion here.  It causes trouble for ADDR_EXPR.  */
    4338                 :   33411600 :   tree arg = xarg;
    4339                 :   33411600 :   tree argtype = NULL_TREE;
    4340                 :   33411600 :   enum tree_code typecode;
    4341                 :   33411600 :   tree val;
    4342                 :   33411600 :   tree ret = error_mark_node;
    4343                 :   33411600 :   tree eptype = NULL_TREE;
    4344                 :   33411600 :   const char *invalid_op_diag;
    4345                 :   33411600 :   bool int_operands;
    4346                 :            : 
    4347                 :   33411600 :   int_operands = EXPR_INT_CONST_OPERANDS (xarg);
    4348                 :    3347580 :   if (int_operands)
    4349                 :    3347580 :     arg = remove_c_maybe_const_expr (arg);
    4350                 :            : 
    4351                 :   33411600 :   if (code != ADDR_EXPR)
    4352                 :    4706830 :     arg = require_complete_type (location, arg);
    4353                 :            : 
    4354                 :   33411600 :   typecode = TREE_CODE (TREE_TYPE (arg));
    4355                 :   33411600 :   if (typecode == ERROR_MARK)
    4356                 :         66 :     return error_mark_node;
    4357                 :   33411500 :   if (typecode == ENUMERAL_TYPE || typecode == BOOLEAN_TYPE)
    4358                 :      25650 :     typecode = INTEGER_TYPE;
    4359                 :            : 
    4360                 :   66823000 :   if ((invalid_op_diag
    4361                 :   33411500 :        = targetm.invalid_unary_op (code, TREE_TYPE (xarg))))
    4362                 :            :     {
    4363                 :          0 :       error_at (location, invalid_op_diag);
    4364                 :          0 :       return error_mark_node;
    4365                 :            :     }
    4366                 :            : 
    4367                 :   33411500 :   if (TREE_CODE (arg) == EXCESS_PRECISION_EXPR)
    4368                 :            :     {
    4369                 :          6 :       eptype = TREE_TYPE (arg);
    4370                 :          6 :       arg = TREE_OPERAND (arg, 0);
    4371                 :            :     }
    4372                 :            : 
    4373                 :   33411500 :   switch (code)
    4374                 :            :     {
    4375                 :      28453 :     case CONVERT_EXPR:
    4376                 :            :       /* This is used for unary plus, because a CONVERT_EXPR
    4377                 :            :          is enough to prevent anybody from looking inside for
    4378                 :            :          associativity, but won't generate any code.  */
    4379                 :          2 :       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
    4380                 :      28453 :             || typecode == FIXED_POINT_TYPE || typecode == COMPLEX_TYPE
    4381                 :          2 :             || gnu_vector_type_p (TREE_TYPE (arg))))
    4382                 :            :         {
    4383                 :          0 :           error_at (location, "wrong type argument to unary plus");
    4384                 :          0 :           return error_mark_node;
    4385                 :            :         }
    4386                 :      28453 :       else if (!noconvert)
    4387                 :      28453 :         arg = default_conversion (arg);
    4388                 :      28453 :       arg = non_lvalue_loc (location, arg);
    4389                 :      28453 :       break;
    4390                 :            : 
    4391                 :    3481900 :     case NEGATE_EXPR:
    4392                 :     266611 :       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
    4393                 :    3481900 :             || typecode == FIXED_POINT_TYPE || typecode == COMPLEX_TYPE
    4394                 :     266611 :             || gnu_vector_type_p (TREE_TYPE (arg))))
    4395                 :            :         {
    4396                 :          1 :           error_at (location, "wrong type argument to unary minus");
    4397                 :          1 :           return error_mark_node;
    4398                 :            :         }
    4399                 :    3481900 :       else if (!noconvert)
    4400                 :    3481900 :         arg = default_conversion (arg);
    4401                 :            :       break;
    4402                 :            : 
    4403                 :     195778 :     case BIT_NOT_EXPR:
    4404                 :            :       /* ~ works on integer types and non float vectors. */
    4405                 :     195778 :       if (typecode == INTEGER_TYPE
    4406                 :     198692 :           || (gnu_vector_type_p (TREE_TYPE (arg))
    4407                 :        104 :               && !VECTOR_FLOAT_TYPE_P (TREE_TYPE (arg))))
    4408                 :            :         {
    4409                 :            :           tree e = arg;
    4410                 :            : 
    4411                 :            :           /* Warn if the expression has boolean value.  */
    4412                 :     192977 :           while (TREE_CODE (e) == COMPOUND_EXPR)
    4413                 :         10 :             e = TREE_OPERAND (e, 1);
    4414                 :            : 
    4415                 :     192967 :           if ((TREE_CODE (TREE_TYPE (arg)) == BOOLEAN_TYPE
    4416                 :     192967 :                || truth_value_p (TREE_CODE (e))))
    4417                 :            :             {
    4418                 :        218 :               auto_diagnostic_group d;
    4419                 :        109 :               if (warning_at (location, OPT_Wbool_operation,
    4420                 :            :                                 "%<~%> on a boolean expression"))
    4421                 :            :                 {
    4422                 :         24 :                   gcc_rich_location richloc (location);
    4423                 :         12 :                   richloc.add_fixit_insert_before (location, "!");
    4424                 :         12 :                   inform (&richloc, "did you mean to use logical not?");
    4425                 :            :                 }
    4426                 :            :             }
    4427                 :     192967 :           if (!noconvert)
    4428                 :     192967 :             arg = default_conversion (arg);
    4429                 :            :         }
    4430                 :       2811 :       else if (typecode == COMPLEX_TYPE)
    4431                 :            :         {
    4432                 :       2809 :           code = CONJ_EXPR;
    4433                 :       2809 :           pedwarn (location, OPT_Wpedantic,
    4434                 :            :                    "ISO C does not support %<~%> for complex conjugation");
    4435                 :       2809 :           if (!noconvert)
    4436                 :       2809 :             arg = default_conversion (arg);
    4437                 :            :         }
    4438                 :            :       else
    4439                 :            :         {
    4440                 :          2 :           error_at (location, "wrong type argument to bit-complement");
    4441                 :          2 :           return error_mark_node;
    4442                 :            :         }
    4443                 :            :       break;
    4444                 :            : 
    4445                 :          3 :     case ABS_EXPR:
    4446                 :          3 :       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE))
    4447                 :            :         {
    4448                 :          0 :           error_at (location, "wrong type argument to abs");
    4449                 :          0 :           return error_mark_node;
    4450                 :            :         }
    4451                 :          3 :       else if (!noconvert)
    4452                 :          3 :         arg = default_conversion (arg);
    4453                 :            :       break;
    4454                 :            : 
    4455                 :          7 :     case ABSU_EXPR:
    4456                 :          7 :       if (!(typecode == INTEGER_TYPE))
    4457                 :            :         {
    4458                 :          0 :           error_at (location, "wrong type argument to absu");
    4459                 :          0 :           return error_mark_node;
    4460                 :            :         }
    4461                 :          7 :       else if (!noconvert)
    4462                 :          7 :         arg = default_conversion (arg);
    4463                 :            :       break;
    4464                 :            : 
    4465                 :          0 :     case CONJ_EXPR:
    4466                 :            :       /* Conjugating a real value is a no-op, but allow it anyway.  */
    4467                 :          0 :       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
    4468                 :          0 :             || typecode == COMPLEX_TYPE))
    4469                 :            :         {
    4470                 :          0 :           error_at (location, "wrong type argument to conjugation");
    4471                 :          0 :           return error_mark_node;
    4472                 :            :         }
    4473                 :          0 :       else if (!noconvert)
    4474                 :          0 :         arg = default_conversion (arg);
    4475                 :            :       break;
    4476                 :            : 
    4477                 :     146637 :     case TRUTH_NOT_EXPR:
    4478                 :     146637 :       if (typecode != INTEGER_TYPE && typecode != FIXED_POINT_TYPE
    4479                 :       4099 :           && typecode != REAL_TYPE && typecode != POINTER_TYPE
    4480                 :          8 :           && typecode != COMPLEX_TYPE)
    4481                 :            :         {
    4482                 :          8 :           error_at (location,
    4483                 :            :                     "wrong type argument to unary exclamation mark");
    4484                 :          8 :           return error_mark_node;
    4485                 :            :         }
    4486                 :     146629 :       if (int_operands)
    4487                 :            :         {
    4488                 :      73373 :           arg = c_objc_common_truthvalue_conversion (location, xarg);
    4489                 :      73373 :           arg = remove_c_maybe_const_expr (arg);
    4490                 :            :         }
    4491                 :            :       else
    4492                 :      73256 :         arg = c_objc_common_truthvalue_conversion (location, arg);
    4493                 :     146629 :       ret = invert_truthvalue_loc (location, arg);
    4494                 :            :       /* If the TRUTH_NOT_EXPR has been folded, reset the location.  */
    4495                 :     146629 :       if (EXPR_P (ret) && EXPR_HAS_LOCATION (ret))
    4496                 :      72902 :         location = EXPR_LOCATION (ret);
    4497                 :     146629 :       goto return_build_unary_op;
    4498                 :            : 
    4499                 :     204732 :     case REALPART_EXPR:
    4500                 :     204732 :     case IMAGPART_EXPR:
    4501                 :     204732 :       ret = build_real_imag_expr (location, code, arg);
    4502                 :     204732 :       if (ret == error_mark_node)
    4503                 :            :         return error_mark_node;
    4504                 :     204728 :       if (eptype && TREE_CODE (eptype) == COMPLEX_TYPE)
    4505                 :          2 :         eptype = TREE_TYPE (eptype);
    4506                 :     204728 :       goto return_build_unary_op;
    4507                 :            : 
    4508                 :     649282 :     case PREINCREMENT_EXPR:
    4509                 :     649282 :     case POSTINCREMENT_EXPR:
    4510                 :     649282 :     case PREDECREMENT_EXPR:
    4511                 :     649282 :     case POSTDECREMENT_EXPR:
    4512                 :            : 
    4513                 :     649282 :       if (TREE_CODE (arg) == C_MAYBE_CONST_EXPR)
    4514                 :            :         {
    4515                 :          2 :           tree inner = build_unary_op (location, code,
    4516                 :          2 :                                        C_MAYBE_CONST_EXPR_EXPR (arg),
    4517                 :            :                                        noconvert);
    4518                 :          2 :           if (inner == error_mark_node)
    4519                 :            :             return error_mark_node;
    4520                 :          4 :           ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner),
    4521                 :          2 :                         C_MAYBE_CONST_EXPR_PRE (arg), inner);
    4522                 :          2 :           gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (arg));
    4523                 :          2 :           C_MAYBE_CONST_EXPR_NON_CONST (ret) = 1;
    4524                 :          2 :           goto return_build_unary_op;
    4525                 :            :         }
    4526                 :            : 
    4527                 :            :       /* Complain about anything that is not a true lvalue.  In
    4528                 :            :          Objective-C, skip this check for property_refs.  */
    4529                 :     649280 :       if (!objc_is_property_ref (arg)
    4530                 :     649280 :           && !lvalue_or_else (location,
    4531                 :     649280 :                               arg, ((code == PREINCREMENT_EXPR
    4532                 :     649280 :                                      || code == POSTINCREMENT_EXPR)
    4533                 :            :                                     ? lv_increment
    4534                 :            :                                     : lv_decrement)))
    4535                 :         20 :         return error_mark_node;
    4536                 :            : 
    4537                 :     649659 :       if (warn_cxx_compat && TREE_CODE (TREE_TYPE (arg)) == ENUMERAL_TYPE)
    4538                 :            :         {
    4539                 :          4 :           if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
    4540                 :          2 :             warning_at (location, OPT_Wc___compat,
    4541                 :            :                         "increment of enumeration value is invalid in C++");
    4542                 :            :           else
    4543                 :          2 :             warning_at (location, OPT_Wc___compat,
    4544                 :            :                         "decrement of enumeration value is invalid in C++");
    4545                 :            :         }
    4546                 :            : 
    4547                 :     649260 :       if (TREE_CODE (TREE_TYPE (arg)) == BOOLEAN_TYPE)
    4548                 :            :         {
    4549                 :        232 :           if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
    4550                 :        116 :             warning_at (location, OPT_Wbool_operation,
    4551                 :            :                         "increment of a boolean expression");
    4552                 :            :           else
    4553                 :        116 :             warning_at (location, OPT_Wbool_operation,
    4554                 :            :                         "decrement of a boolean expression");
    4555                 :            :         }
    4556                 :            : 
    4557                 :            :       /* Ensure the argument is fully folded inside any SAVE_EXPR.  */
    4558                 :     649260 :       arg = c_fully_fold (arg, false, NULL, true);
    4559                 :            : 
    4560                 :     649260 :       bool atomic_op;
    4561                 :     649260 :       atomic_op = really_atomic_lvalue (arg);
    4562                 :            : 
    4563                 :            :       /* Increment or decrement the real part of the value,
    4564                 :            :          and don't change the imaginary part.  */
    4565                 :     649260 :       if (typecode == COMPLEX_TYPE)
    4566                 :            :         {
    4567                 :          8 :           tree real, imag;
    4568                 :            : 
    4569                 :          8 :           pedwarn (location, OPT_Wpedantic,
    4570                 :            :                    "ISO C does not support %<++%> and %<--%> on complex types");
    4571                 :            : 
    4572                 :          8 :           if (!atomic_op)
    4573                 :            :             {
    4574                 :          4 :               arg = stabilize_reference (arg);
    4575                 :          4 :               real = build_unary_op (EXPR_LOCATION (arg), REALPART_EXPR, arg,
    4576                 :            :                                      true);
    4577                 :          4 :               imag = build_unary_op (EXPR_LOCATION (arg), IMAGPART_EXPR, arg,
    4578                 :            :                                      true);
    4579                 :          4 :               real = build_unary_op (EXPR_LOCATION (arg), code, real, true);
    4580                 :          4 :               if (real == error_mark_node || imag == error_mark_node)
    4581                 :            :                 return error_mark_node;
    4582                 :          4 :               ret = build2 (COMPLEX_EXPR, TREE_TYPE (arg),
    4583                 :            :                             real, imag);
    4584                 :          4 :               goto return_build_unary_op;
    4585                 :            :             }
    4586                 :            :         }
    4587                 :            : 
    4588                 :            :       /* Report invalid types.  */
    4589                 :            : 
    4590                 :     649256 :       if (typecode != POINTER_TYPE && typecode != FIXED_POINT_TYPE
    4591                 :     578137 :           && typecode != INTEGER_TYPE && typecode != REAL_TYPE
    4592                 :         45 :           && typecode != COMPLEX_TYPE
    4593                 :     649297 :           && !gnu_vector_type_p (TREE_TYPE (arg)))
    4594                 :            :         {
    4595                 :          5 :           if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
    4596                 :          3 :             error_at (location, "wrong type argument to increment");
    4597                 :            :           else
    4598                 :          2 :             error_at (location, "wrong type argument to decrement");
    4599                 :            : 
    4600                 :          5 :           return error_mark_node;
    4601                 :            :         }
    4602                 :            : 
    4603                 :     649251 :       {
    4604                 :     649251 :         tree inc;
    4605                 :            : 
    4606                 :     649251 :         argtype = TREE_TYPE (arg);
    4607                 :            : 
    4608                 :            :         /* Compute the increment.  */
    4609                 :            : 
    4610                 :     649251 :         if (typecode == POINTER_TYPE)
    4611                 :            :           {
    4612                 :            :             /* If pointer target is an incomplete type,
    4613                 :            :                we just cannot know how to do the arithmetic.  */
    4614                 :      71119 :             if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (argtype)))
    4615                 :            :               {
    4616                 :         27 :                 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
    4617                 :         17 :                   error_at (location,
    4618                 :            :                             "increment of pointer to an incomplete type %qT",
    4619                 :         17 :                             TREE_TYPE (argtype));
    4620                 :            :                 else
    4621                 :         10 :                   error_at (location,
    4622                 :            :                             "decrement of pointer to an incomplete type %qT",
    4623                 :         10 :                             TREE_TYPE (argtype));
    4624                 :            :               }
    4625                 :      71092 :             else if (TREE_CODE (TREE_TYPE (argtype)) == FUNCTION_TYPE
    4626                 :      71092 :                      || TREE_CODE (TREE_TYPE (argtype)) == VOID_TYPE)
    4627                 :            :               {
    4628                 :          9 :                 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
    4629                 :          5 :                   pedwarn (location, OPT_Wpointer_arith,
    4630                 :            :                            "wrong type argument to increment");
    4631                 :            :                 else
    4632                 :          4 :                   pedwarn (location, OPT_Wpointer_arith,
    4633                 :            :                            "wrong type argument to decrement");
    4634                 :            :               }
    4635                 :            :             else
    4636                 :      71083 :               verify_type_context (location, TCTX_POINTER_ARITH,
    4637                 :      71083 :                                    TREE_TYPE (argtype));
    4638                 :            : 
    4639                 :      71119 :             inc = c_size_in_bytes (TREE_TYPE (argtype));
    4640                 :      71119 :             inc = convert_to_ptrofftype_loc (location, inc);
    4641                 :            :           }
    4642                 :    1156260 :         else if (FRACT_MODE_P (TYPE_MODE (argtype)))
    4643                 :            :           {
    4644                 :            :             /* For signed fract types, we invert ++ to -- or
    4645                 :            :                -- to ++, and change inc from 1 to -1, because
    4646                 :            :                it is not possible to represent 1 in signed fract constants.
    4647                 :            :                For unsigned fract types, the result always overflows and
    4648                 :            :                we get an undefined (original) or the maximum value.  */
    4649                 :          0 :             if (code == PREINCREMENT_EXPR)
    4650                 :            :               code = PREDECREMENT_EXPR;
    4651                 :          0 :             else if (code == PREDECREMENT_EXPR)
    4652                 :            :               code = PREINCREMENT_EXPR;
    4653                 :          0 :             else if (code == POSTINCREMENT_EXPR)
    4654                 :            :               code = POSTDECREMENT_EXPR;
    4655                 :            :             else /* code == POSTDECREMENT_EXPR  */
    4656                 :          0 :               code = POSTINCREMENT_EXPR;
    4657                 :            : 
    4658                 :          0 :             inc = integer_minus_one_node;
    4659                 :          0 :             inc = convert (argtype, inc);
    4660                 :            :           }
    4661                 :            :         else
    4662                 :            :           {
    4663                 :    1156260 :             inc = VECTOR_TYPE_P (argtype)
    4664                 :     578132 :               ? build_one_cst (argtype)
    4665                 :            :               : integer_one_node;
    4666                 :     578132 :             inc = convert (argtype, inc);
    4667                 :            :           }
    4668                 :            : 
    4669                 :            :         /* If 'arg' is an Objective-C PROPERTY_REF expression, then we
    4670                 :            :            need to ask Objective-C to build the increment or decrement
    4671                 :            :            expression for it.  */
    4672                 :     649251 :         if (objc_is_property_ref (arg))
    4673                 :          0 :           return objc_build_incr_expr_for_property_ref (location, code,
    4674                 :          0 :                                                         arg, inc);
    4675                 :            : 
    4676                 :            :         /* Report a read-only lvalue.  */
    4677                 :     649251 :         if (TYPE_READONLY (argtype))
    4678                 :            :           {
    4679                 :         19 :             readonly_error (location, arg,
    4680                 :         19 :                             ((code == PREINCREMENT_EXPR
    4681                 :         19 :                               || code == POSTINCREMENT_EXPR)
    4682                 :            :                              ? lv_increment : lv_decrement));
    4683                 :         19 :             return error_mark_node;
    4684                 :            :           }
    4685                 :     649232 :         else if (TREE_READONLY (arg))
    4686                 :          4 :           readonly_warning (arg,
    4687                 :          4 :                             ((code == PREINCREMENT_EXPR
    4688                 :          4 :                               || code == POSTINCREMENT_EXPR)
    4689                 :            :                              ? lv_increment : lv_decrement));
    4690                 :            : 
    4691                 :            :         /* If the argument is atomic, use the special code sequences for
    4692                 :            :            atomic compound assignment.  */
    4693                 :     649232 :         if (atomic_op)
    4694                 :            :           {
    4695                 :       4416 :             arg = stabilize_reference (arg);
    4696                 :       8832 :             ret = build_atomic_assign (location, arg,
    4697                 :       4416 :                                        ((code == PREINCREMENT_EXPR
    4698                 :       4416 :                                          || code == POSTINCREMENT_EXPR)
    4699                 :            :                                         ? PLUS_EXPR
    4700                 :            :                                         : MINUS_EXPR),
    4701                 :       8832 :                                        (FRACT_MODE_P (TYPE_MODE (argtype))
    4702                 :            :                                         ? inc
    4703                 :            :                                         : integer_one_node),
    4704                 :            :                                        (code == POSTINCREMENT_EXPR
    4705                 :       4416 :                                         || code == POSTDECREMENT_EXPR));
    4706                 :       4416 :             goto return_build_unary_op;
    4707                 :            :           }
    4708                 :            : 
    4709                 :     644816 :         if (TREE_CODE (TREE_TYPE (arg)) == BOOLEAN_TYPE)
    4710                 :         36 :           val = boolean_increment (code, arg);
    4711                 :            :         else
    4712                 :     644780 :           val = build2 (code, TREE_TYPE (arg), arg, inc);
    4713                 :     644816 :         TREE_SIDE_EFFECTS (val) = 1;
    4714                 :     644816 :         if (TREE_CODE (val) != code)
    4715                 :         36 :           TREE_NO_WARNING (val) = 1;
    4716                 :     644816 :         ret = val;
    4717                 :     644816 :         goto return_build_unary_op;
    4718                 :            :       }
    4719                 :            : 
    4720                 :   28704700 :     case ADDR_EXPR:
    4721                 :            :       /* Note that this operation never does default_conversion.  */
    4722                 :            : 
    4723                 :            :       /* The operand of unary '&' must be an lvalue (which excludes
    4724                 :            :          expressions of type void), or, in C99, the result of a [] or
    4725                 :            :          unary '*' operator.  */
    4726                 :   28704700 :       if (VOID_TYPE_P (TREE_TYPE (arg))
    4727                 :         24 :           && TYPE_QUALS (TREE_TYPE (arg)) == TYPE_UNQUALIFIED
    4728                 :   28704700 :           && (!INDIRECT_REF_P (arg) || !flag_isoc99))
    4729                 :         18 :         pedwarn (location, 0, "taking address of expression of type %<void%>");
    4730                 :            : 
    4731                 :            :       /* Let &* cancel out to simplify resulting code.  */
    4732                 :   28704700 :       if (INDIRECT_REF_P (arg))
    4733                 :            :         {
    4734                 :            :           /* Don't let this be an lvalue.  */
    4735                 :      15475 :           if (lvalue_p (TREE_OPERAND (arg, 0)))
    4736                 :      10932 :             return non_lvalue_loc (location, TREE_OPERAND (arg, 0));
    4737                 :       4543 :           ret = TREE_OPERAND (arg, 0);
    4738                 :       4543 :           goto return_build_unary_op;
    4739                 :            :         }
    4740                 :            : 
    4741                 :            :       /* Anything not already handled and not a true memory reference
    4742                 :            :          or a non-lvalue array is an error.  */
    4743                 :   28689200 :       if (typecode != FUNCTION_TYPE && !noconvert
    4744                 :   28689200 :           && !lvalue_or_else (location, arg, lv_addressof))
    4745                 :         16 :         return error_mark_node;
    4746                 :            : 
    4747                 :            :       /* Move address operations inside C_MAYBE_CONST_EXPR to simplify
    4748                 :            :          folding later.  */
    4749                 :   28689200 :       if (TREE_CODE (arg) == C_MAYBE_CONST_EXPR)
    4750                 :            :         {
    4751                 :          1 :           tree inner = build_unary_op (location, code,
    4752                 :          1 :                                        C_MAYBE_CONST_EXPR_EXPR (arg),
    4753                 :            :                                        noconvert);
    4754                 :          2 :           ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner),
    4755                 :          1 :                         C_MAYBE_CONST_EXPR_PRE (arg), inner);
    4756                 :          1 :           gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (arg));
    4757                 :          1 :           C_MAYBE_CONST_EXPR_NON_CONST (ret)
    4758                 :          1 :             = C_MAYBE_CONST_EXPR_NON_CONST (arg);
    4759                 :          1 :           goto return_build_unary_op;
    4760                 :            :         }
    4761                 :            : 
    4762                 :            :       /* Ordinary case; arg is a COMPONENT_REF or a decl.  */
    4763                 :   28689200 :       argtype = TREE_TYPE (arg);
    4764                 :            : 
    4765                 :            :       /* If the lvalue is const or volatile, merge that into the type
    4766                 :            :          to which the address will point.  This is only needed
    4767                 :            :          for function types.  */
    4768                 :   28689200 :       if ((DECL_P (arg) || REFERENCE_CLASS_P (arg))
    4769                 :   28511900 :           && (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg))
    4770                 :   45648300 :           && TREE_CODE (argtype) == FUNCTION_TYPE)
    4771                 :            :         {
    4772                 :   16889200 :           int orig_quals = TYPE_QUALS (strip_array_types (argtype));
    4773                 :   16889200 :           int quals = orig_quals;
    4774                 :            : 
    4775                 :   16889200 :           if (TREE_READONLY (arg))
    4776                 :   16645400 :             quals |= TYPE_QUAL_CONST;
    4777                 :   16889200 :           if (TREE_THIS_VOLATILE (arg))
    4778                 :     244268 :             quals |= TYPE_QUAL_VOLATILE;
    4779                 :            : 
    4780                 :   16889200 :           argtype = c_build_qualified_type (argtype, quals);
    4781                 :            :         }
    4782                 :            : 
    4783                 :   28689200 :       switch (TREE_CODE (arg))
    4784                 :            :         {
    4785                 :      49976 :         case COMPONENT_REF:
    4786                 :      49976 :           if (DECL_C_BIT_FIELD (TREE_OPERAND (arg, 1)))
    4787                 :            :             {
    4788                 :          5 :               error_at (location, "cannot take address of bit-field %qD",
    4789                 :          5 :                         TREE_OPERAND (arg, 1));
    4790                 :          5 :               return error_mark_node;
    4791                 :            :             }
    4792                 :            : 
    4793                 :            :           /* fall through */
    4794                 :            : 
    4795                 :     109911 :         case ARRAY_REF:
    4796                 :     109911 :           if (TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (TREE_OPERAND (arg, 0))))
    4797                 :            :             {
    4798                 :         78 :               if (!AGGREGATE_TYPE_P (TREE_TYPE (arg))
    4799                 :         76 :                   && !VECTOR_TYPE_P (TREE_TYPE (arg)))
    4800                 :            :                 {
    4801                 :          6 :                   error_at (location, "cannot take address of scalar with "
    4802                 :            :                             "reverse storage order");
    4803                 :          6 :                   return error_mark_node;
    4804                 :            :                 }
    4805                 :            : 
    4806                 :         64 :               if (TREE_CODE (TREE_TYPE (arg)) == ARRAY_TYPE
    4807                 :         64 :                   && TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (arg)))
    4808                 :         58 :                 warning_at (location, OPT_Wscalar_storage_order,
    4809                 :            :                             "address of array with reverse scalar storage "
    4810                 :            :                             "order requested");
    4811                 :            :             }
    4812                 :            : 
    4813                 :   28689200 :         default:
    4814                 :   28689200 :           break;
    4815                 :            :         }
    4816                 :            : 
    4817                 :   28689200 :       if (!c_mark_addressable (arg))
    4818                 :          8 :         return error_mark_node;
    4819                 :            : 
    4820                 :   28689200 :       gcc_assert (TREE_CODE (arg) != COMPONENT_REF
    4821                 :            :                   || !DECL_C_BIT_FIELD (TREE_OPERAND (arg, 1)));
    4822                 :            : 
    4823                 :   28689200 :       argtype = build_pointer_type (argtype);
    4824                 :            : 
    4825                 :            :       /* ??? Cope with user tricks that amount to offsetof.  Delete this
    4826                 :            :          when we have proper support for integer constant expressions.  */
    4827                 :   28689200 :       val = get_base_address (arg);
    4828                 :   28689200 :       if (val && INDIRECT_REF_P (val)
    4829                 :   28707400 :           && TREE_CONSTANT (TREE_OPERAND (val, 0)))
    4830                 :            :         {
    4831                 :        520 :           ret = fold_offsetof (arg, argtype);
    4832                 :        520 :           goto return_build_unary_op;
    4833                 :            :         }
    4834                 :            : 
    4835                 :   28688700 :       val = build1 (ADDR_EXPR, argtype, arg);
    4836                 :            : 
    4837                 :   28688700 :       ret = val;
    4838                 :   28688700 :       goto return_build_unary_op;
    4839                 :            : 
    4840                 :          0 :     default:
    4841                 :          0 :       gcc_unreachable ();
    4842                 :            :     }
    4843                 :            : 
    4844                 :    3706140 :   if (argtype == NULL_TREE)
    4845                 :    3706140 :     argtype = TREE_TYPE (arg);
    4846                 :    3706140 :   if (TREE_CODE (arg) == INTEGER_CST)
    4847                 :    3270250 :     ret = (require_constant_value
    4848                 :      15044 :            ? fold_build1_initializer_loc (location, code, argtype, arg)
    4849                 :    3270250 :            : fold_build1_loc (location, code, argtype, arg));
    4850                 :            :   else
    4851                 :     435892 :     ret = build1 (code, argtype, arg);
    4852                 :   33400500 :  return_build_unary_op:
    4853                 :   33400500 :   gcc_assert (ret != error_mark_node);
    4854                 :    3348060 :   if (TREE_CODE (ret) == INTEGER_CST && !TREE_OVERFLOW (ret)
    4855                 :   40096000 :       && !(TREE_CODE (xarg) == INTEGER_CST && !TREE_OVERFLOW (xarg)))
    4856                 :        533 :     ret = build1 (NOP_EXPR, TREE_TYPE (ret), ret);
    4857                 :   33400000 :   else if (TREE_CODE (ret) != INTEGER_CST && int_operands)
    4858                 :         46 :     ret = note_integer_operands (ret);
    4859                 :   33400500 :   if (eptype)
    4860                 :          6 :     ret = build1 (EXCESS_PRECISION_EXPR, eptype, ret);
    4861                 :   33400500 :   protected_set_expr_location (ret, location);
    4862                 :   33400500 :   return ret;
    4863                 :            : }
    4864                 :            : 
    4865                 :            : /* Return nonzero if REF is an lvalue valid for this language.
    4866                 :            :    Lvalues can be assigned, unless their type has TYPE_READONLY.
    4867                 :            :    Lvalues can have their address taken, unless they have C_DECL_REGISTER.  */
    4868                 :            : 
    4869                 :            : bool
    4870                 :   92311400 : lvalue_p (const_tree ref)
    4871                 :            : {
    4872                 :   93432400 :   const enum tree_code code = TREE_CODE (ref);
    4873                 :            : 
    4874                 :   93432400 :   switch (code)
    4875                 :            :     {
    4876                 :    1120900 :     case REALPART_EXPR:
    4877                 :    1120900 :     case IMAGPART_EXPR:
    4878                 :    1120900 :     case COMPONENT_REF:
    4879                 :    1120900 :       return lvalue_p (TREE_OPERAND (ref, 0));
    4880                 :            : 
    4881                 :         24 :     case C_MAYBE_CONST_EXPR:
    4882                 :         24 :       return lvalue_p (TREE_OPERAND (ref, 1));
    4883                 :            : 
    4884                 :            :     case COMPOUND_LITERAL_EXPR:
    4885                 :            :     case STRING_CST:
    4886                 :            :       return true;
    4887                 :            : 
    4888                 :   11981700 :     case INDIRECT_REF:
    4889                 :   11981700 :     case ARRAY_REF:
    4890                 :   11981700 :     case VAR_DECL:
    4891                 :   11981700 :     case PARM_DECL:
    4892                 :   11981700 :     case RESULT_DECL:
    4893                 :   11981700 :     case ERROR_MARK:
    4894                 :   11981700 :       return (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE
    4895                 :   11981700 :               && TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE);
    4896                 :            : 
    4897                 :          1 :     case BIND_EXPR:
    4898                 :          1 :       return TREE_CODE (TREE_TYPE (ref)) == ARRAY_TYPE;
    4899                 :            : 
    4900                 :   80088600 :     default:
    4901                 :   80088600 :       return false;
    4902                 :            :     }
    4903                 :            : }
    4904                 :            : 
    4905                 :            : /* Give a warning for storing in something that is read-only in GCC
    4906                 :            :    terms but not const in ISO C terms.  */
    4907                 :            : 
    4908                 :            : static void
    4909                 :          6 : readonly_warning (tree arg, enum lvalue_use use)
    4910                 :            : {
    4911                 :          6 :   switch (use)
    4912                 :            :     {
    4913                 :          2 :     case lv_assign:
    4914                 :          2 :       warning (0, "assignment of read-only location %qE", arg);
    4915                 :          2 :       break;
    4916                 :          2 :     case lv_increment:
    4917                 :          2 :       warning (0, "increment of read-only location %qE", arg);
    4918                 :          2 :       break;
    4919                 :          2 :     case lv_decrement:
    4920                 :          2 :       warning (0, "decrement of read-only location %qE", arg);
    4921                 :          2 :       break;
    4922                 :          0 :     default:
    4923                 :          0 :       gcc_unreachable ();
    4924                 :            :     }
    4925                 :          6 :   return;
    4926                 :            : }
    4927                 :            : 
    4928                 :            : 
    4929                 :            : /* Return nonzero if REF is an lvalue valid for this language;
    4930                 :            :    otherwise, print an error message and return zero.  USE says
    4931                 :            :    how the lvalue is being used and so selects the error message.
    4932                 :            :    LOCATION is the location at which any error should be reported.  */
    4933                 :            : 
    4934                 :            : static int
    4935                 :    3364440 : lvalue_or_else (location_t loc, const_tree ref, enum lvalue_use use)
    4936                 :            : {
    4937                 :    3117410 :   int win = lvalue_p (ref);
    4938                 :            : 
    4939                 :    3364440 :   if (!win)
    4940                 :         68 :     lvalue_error (loc, use);
    4941                 :            : 
    4942                 :    1072510 :   return win;
    4943                 :            : }
    4944                 :            : 
    4945                 :            : /* Mark EXP saying that we need to be able to take the
    4946                 :            :    address of it; it should not be allocated in a register.
    4947                 :            :    Returns true if successful.  ARRAY_REF_P is true if this
    4948                 :            :    is for ARRAY_REF construction - in that case we don't want
    4949                 :            :    to look through VIEW_CONVERT_EXPR from VECTOR_TYPE to ARRAY_TYPE,
    4950                 :            :    it is fine to use ARRAY_REFs for vector subscripts on vector
    4951                 :            :    register variables.  */
    4952                 :            : 
    4953                 :            : bool
    4954                 :   29125500 : c_mark_addressable (tree exp, bool array_ref_p)
    4955                 :            : {
    4956                 :   29125500 :   tree x = exp;
    4957                 :            : 
    4958                 :   30033900 :   while (1)
    4959                 :   29579700 :     switch (TREE_CODE (x))
    4960                 :            :       {
    4961                 :       8381 :       case VIEW_CONVERT_EXPR:
    4962                 :       8381 :         if (array_ref_p
    4963                 :       8307 :             && TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
    4964                 :      16688 :             && VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (x, 0))))
    4965                 :            :           return true;
    4966                 :            :         /* FALLTHRU */
    4967                 :     454200 :       case COMPONENT_REF:
    4968                 :     454200 :       case ADDR_EXPR:
    4969                 :     454200 :       case ARRAY_REF:
    4970                 :     454200 :       case REALPART_EXPR:
    4971                 :     454200 :       case IMAGPART_EXPR:
    4972                 :     454200 :         x = TREE_OPERAND (x, 0);
    4973                 :     454200 :         break;
    4974                 :            : 
    4975                 :        390 :       case COMPOUND_LITERAL_EXPR:
    4976                 :        390 :         TREE_ADDRESSABLE (x) = 1;
    4977                 :        390 :         TREE_ADDRESSABLE (COMPOUND_LITERAL_EXPR_DECL (x)) = 1;
    4978                 :        390 :         return true;
    4979                 :            : 
    4980                 :          0 :       case CONSTRUCTOR:
    4981                 :          0 :         TREE_ADDRESSABLE (x) = 1;
    4982                 :          0 :         return true;
    4983                 :            : 
    4984                 :     942280 :       case VAR_DECL:
    4985                 :     942280 :       case CONST_DECL:
    4986                 :     942280 :       case PARM_DECL:
    4987                 :     942280 :       case RESULT_DECL:
    4988                 :     942280 :         if (C_DECL_REGISTER (x)
    4989                 :     942280 :             && DECL_NONLOCAL (x))
    4990                 :            :           {
    4991                 :          0 :             if (TREE_PUBLIC (x) || is_global_var (x))
    4992                 :            :               {
    4993                 :          0 :                 error
    4994                 :          0 :                   ("global register variable %qD used in nested function", x);
    4995                 :          0 :                 return false;
    4996                 :            :               }
    4997                 :          0 :             pedwarn (input_location, 0, "register variable %qD used in nested function", x);
    4998                 :            :           }
    4999                 :     942280 :         else if (C_DECL_REGISTER (x))
    5000                 :            :           {
    5001                 :         11 :             if (TREE_PUBLIC (x) || is_global_var (x))
    5002                 :          4 :               error ("address of global register variable %qD requested", x);
    5003                 :            :             else
    5004                 :          7 :               error ("address of register variable %qD requested", x);
    5005                 :         11 :             return false;
    5006                 :            :           }
    5007                 :            : 
    5008                 :            :         /* FALLTHRU */
    5009                 :   28878500 :       case FUNCTION_DECL:
    5010                 :   28878500 :         TREE_ADDRESSABLE (x) = 1;
    5011                 :            :         /* FALLTHRU */
    5012                 :            :       default:
    5013                 :            :         return true;
    5014                 :            :     }
    5015                 :            : }
    5016                 :            : 
    5017                 :            : /* Convert EXPR to TYPE, warning about conversion problems with
    5018                 :            :    constants.  SEMANTIC_TYPE is the type this conversion would use
    5019                 :            :    without excess precision. If SEMANTIC_TYPE is NULL, this function
    5020                 :            :    is equivalent to convert_and_check. This function is a wrapper that
    5021                 :            :    handles conversions that may be different than
    5022                 :            :    the usual ones because of excess precision.  */
    5023                 :            : 
    5024                 :            : static tree
    5025                 :   15385500 : ep_convert_and_check (location_t loc, tree type, tree expr,
    5026                 :            :                       tree semantic_type)
    5027                 :            : {
    5028                 :   15385500 :   if (TREE_TYPE (expr) == type)
    5029                 :            :     return expr;
    5030                 :            : 
    5031                 :            :   /* For C11, integer conversions may have results with excess
    5032                 :            :      precision.  */
    5033                 :    1493120 :   if (flag_isoc11 || !semantic_type)
    5034                 :    1493120 :     return convert_and_check (loc, type, expr);
    5035                 :            : 
    5036                 :          4 :   if (TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
    5037                 :          4 :       && TREE_TYPE (expr) != semantic_type)
    5038                 :            :     {
    5039                 :            :       /* For integers, we need to check the real conversion, not
    5040                 :            :          the conversion to the excess precision type.  */
    5041                 :          4 :       expr = convert_and_check (loc, semantic_type, expr);
    5042                 :            :     }
    5043                 :            :   /* Result type is the excess precision type, which should be
    5044                 :            :      large enough, so do not check.  */
    5045                 :          4 :   return convert (type, expr);
    5046                 :            : }
    5047                 :            : 
    5048                 :            : /* If EXPR refers to a built-in declared without a prototype returns
    5049                 :            :    the actual type of the built-in and, if non-null, set *BLTIN to
    5050                 :            :    a pointer to the built-in.  Otherwise return the type of EXPR
    5051                 :            :    and clear *BLTIN if non-null.  */
    5052                 :            : 
    5053                 :            : static tree
    5054                 :    1795290 : type_or_builtin_type (tree expr, tree *bltin = NULL)
    5055                 :            : {
    5056                 :    1795290 :   tree dummy;
    5057                 :    1795290 :   if (!bltin)
    5058                 :          0 :     bltin = &dummy;
    5059                 :            : 
    5060                 :    1795290 :   *bltin = NULL_TREE;
    5061                 :            : 
    5062                 :    1795290 :   tree type = TREE_TYPE (expr);
    5063                 :    1795290 :   if (TREE_CODE (expr) != ADDR_EXPR)
    5064                 :            :     return type;
    5065                 :            : 
    5066                 :     153144 :   tree oper = TREE_OPERAND (expr, 0);
    5067                 :     153144 :   if (!DECL_P (oper)
    5068                 :     124822 :       || TREE_CODE (oper) != FUNCTION_DECL
    5069                 :     188980 :       || !fndecl_built_in_p (oper, BUILT_IN_NORMAL))
    5070                 :            :     return type;
    5071                 :            : 
    5072                 :       2020 :   built_in_function code = DECL_FUNCTION_CODE (oper);
    5073                 :       2020 :   if (!C_DECL_BUILTIN_PROTOTYPE (oper))
    5074                 :            :     return type;
    5075                 :            : 
    5076                 :       1923 :   if ((*bltin = builtin_decl_implicit (code)))
    5077                 :        937 :     type = build_pointer_type (TREE_TYPE (*bltin));
    5078                 :            : 
    5079                 :            :   return type;
    5080                 :            : }
    5081                 :            : 
    5082                 :            : /* Build and return a conditional expression IFEXP ? OP1 : OP2.  If
    5083                 :            :    IFEXP_BCP then the condition is a call to __builtin_constant_p, and
    5084                 :            :    if folded to an integer constant then the unselected half may
    5085                 :            :    contain arbitrary operations not normally permitted in constant
    5086                 :            :    expressions.  Set the location of the expression to LOC.  */
    5087                 :            : 
    5088                 :            : tree
    5089                 :     244540 : build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp,
    5090                 :            :                         tree op1, tree op1_original_type, location_t op1_loc,
    5091                 :            :                         tree op2, tree op2_original_type, location_t op2_loc)
    5092                 :            : {
    5093                 :     244540 :   tree type1;
    5094                 :     244540 :   tree type2;
    5095                 :     244540 :   enum tree_code code1;
    5096                 :     244540 :   enum tree_code code2;
    5097                 :     244540 :   tree result_type = NULL;
    5098                 :     244540 :   tree semantic_result_type = NULL;
    5099                 :     244540 :   tree orig_op1 = op1, orig_op2 = op2;
    5100                 :     244540 :   bool int_const, op1_int_operands, op2_int_operands, int_operands;
    5101                 :     244540 :   bool ifexp_int_operands;
    5102                 :     244540 :   tree ret;
    5103                 :            : 
    5104                 :     244540 :   op1_int_operands = EXPR_INT_CONST_OPERANDS (orig_op1);
    5105                 :      70037 :   if (op1_int_operands)
    5106                 :      70037 :     op1 = remove_c_maybe_const_expr (op1);
    5107                 :     244540 :   op2_int_operands = EXPR_INT_CONST_OPERANDS (orig_op2);
    5108                 :      92617 :   if (op2_int_operands)
    5109                 :      92617 :     op2 = remove_c_maybe_const_expr (op2);
    5110                 :     244540 :   ifexp_int_operands = EXPR_INT_CONST_OPERANDS (ifexp);
    5111                 :     133166 :   if (ifexp_int_operands)
    5112                 :     133166 :     ifexp = remove_c_maybe_const_expr (ifexp);
    5113                 :            : 
    5114                 :            :   /* Promote both alternatives.  */
    5115                 :            : 
    5116                 :     244540 :   if (TREE_CODE (TREE_TYPE (op1)) != VOID_TYPE)
    5117                 :     241062 :     op1 = default_conversion (op1);
    5118                 :     244540 :   if (TREE_CODE (TREE_TYPE (op2)) != VOID_TYPE)
    5119                 :     241061 :     op2 = default_conversion (op2);
    5120                 :            : 
    5121                 :     244540 :   if (TREE_CODE (ifexp) == ERROR_MARK
    5122                 :     244479 :       || TREE_CODE (TREE_TYPE (op1)) == ERROR_MARK
    5123                 :     489005 :       || TREE_CODE (TREE_TYPE (op2)) == ERROR_MARK)
    5124                 :         76 :     return error_mark_node;
    5125                 :            : 
    5126                 :     244464 :   tree bltin1 = NULL_TREE;
    5127                 :     244464 :   tree bltin2 = NULL_TREE;
    5128                 :     244464 :   type1 = type_or_builtin_type (op1, &bltin1);
    5129                 :     244464 :   code1 = TREE_CODE (type1);
    5130                 :     244464 :   type2 = type_or_builtin_type (op2, &bltin2);
    5131                 :     244464 :   code2 = TREE_CODE (type2);
    5132                 :            : 
    5133                 :     244464 :   if (code1 == POINTER_TYPE && reject_gcc_builtin (op1))
    5134                 :          1 :     return error_mark_node;
    5135                 :            : 
    5136                 :     244463 :   if (code2 == POINTER_TYPE && reject_gcc_builtin (op2))
    5137                 :          1 :     return error_mark_node;
    5138                 :            : 
    5139                 :            :   /* C90 does not permit non-lvalue arrays in conditional expressions.
    5140                 :            :      In C99 they will be pointers by now.  */
    5141                 :     244462 :   if (code1 == ARRAY_TYPE || code2 == ARRAY_TYPE)
    5142                 :            :     {
    5143                 :          1 :       error_at (colon_loc, "non-lvalue array in conditional expression");
    5144                 :          1 :       return error_mark_node;
    5145                 :            :     }
    5146                 :            : 
    5147                 :     244461 :   if ((TREE_CODE (op1) == EXCESS_PRECISION_EXPR
    5148                 :     244455 :        || TREE_CODE (op2) == EXCESS_PRECISION_EXPR)
    5149                 :          7 :       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
    5150                 :          7 :           || code1 == COMPLEX_TYPE)
    5151                 :          7 :       && (code2 == INTEGER_TYPE || code2 == REAL_TYPE
    5152                 :          7 :           || code2 == COMPLEX_TYPE))
    5153                 :            :     {
    5154                 :          7 :       semantic_result_type = c_common_type (type1, type2);
    5155                 :          7 :       if (TREE_CODE (op1) == EXCESS_PRECISION_EXPR)
    5156                 :            :         {
    5157                 :          6 :           op1 = TREE_OPERAND (op1, 0);
    5158                 :          6 :           type1 = TREE_TYPE (op1);
    5159                 :          6 :           gcc_assert (TREE_CODE (type1) == code1);
    5160                 :            :         }
    5161                 :          7 :       if (TREE_CODE (op2) == EXCESS_PRECISION_EXPR)
    5162                 :            :         {
    5163                 :          1 :           op2 = TREE_OPERAND (op2, 0);
    5164                 :          1 :           type2 = TREE_TYPE (op2);
    5165                 :          1 :           gcc_assert (TREE_CODE (type2) == code2);
    5166                 :            :         }
    5167                 :            :     }
    5168                 :            : 
    5169                 :     244461 :   if (warn_cxx_compat)
    5170                 :            :     {
    5171                 :        589 :       tree t1 = op1_original_type ? op1_original_type : TREE_TYPE (orig_op1);
    5172                 :        579 :       tree t2 = op2_original_type ? op2_original_type : TREE_TYPE (orig_op2);
    5173                 :            : 
    5174                 :        328 :       if (TREE_CODE (t1) == ENUMERAL_TYPE
    5175                 :          6 :           && TREE_CODE (t2) == ENUMERAL_TYPE
    5176                 :        334 :           && TYPE_MAIN_VARIANT (t1) != TYPE_MAIN_VARIANT (t2))
    5177                 :          2 :         warning_at (colon_loc, OPT_Wc___compat,
    5178                 :            :                     ("different enum types in conditional is "
    5179                 :            :                      "invalid in C++: %qT vs %qT"),
    5180                 :            :                     t1, t2);
    5181                 :            :     }
    5182                 :            : 
    5183                 :            :   /* Quickly detect the usual case where op1 and op2 have the same type
    5184                 :            :      after promotion.  */
    5185                 :     244461 :   if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2))
    5186                 :            :     {
    5187                 :     180913 :       if (type1 == type2)
    5188                 :            :         result_type = type1;
    5189                 :            :       else
    5190                 :        719 :         result_type = TYPE_MAIN_VARIANT (type1);
    5191                 :            :     }
    5192                 :      63548 :   else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE
    5193                 :      63548 :             || code1 == COMPLEX_TYPE)
    5194                 :      18635 :            && (code2 == INTEGER_TYPE || code2 == REAL_TYPE
    5195                 :      18635 :                || code2 == COMPLEX_TYPE))
    5196                 :            :     {
    5197                 :            :       /* In C11, a conditional expression between a floating-point
    5198                 :            :          type and an integer type should convert the integer type to
    5199                 :            :          the evaluation format of the floating-point type, with
    5200                 :            :          possible excess precision.  */
    5201                 :      18550 :       tree eptype1 = type1;
    5202                 :      18550 :       tree eptype2 = type2;
    5203                 :      18550 :       if (flag_isoc11)
    5204                 :            :         {
    5205                 :      18361 :           tree eptype;
    5206                 :       4708 :           if (ANY_INTEGRAL_TYPE_P (type1)
    5207                 :      18361 :               && (eptype = excess_precision_type (type2)) != NULL_TREE)
    5208                 :            :             {
    5209                 :          1 :               eptype2 = eptype;
    5210                 :          1 :               if (!semantic_result_type)
    5211                 :          1 :                 semantic_result_type = c_common_type (type1, type2);
    5212                 :            :             }
    5213                 :        388 :           else if (ANY_INTEGRAL_TYPE_P (type2)
    5214                 :      18360 :                    && (eptype = excess_precision_type (type1)) != NULL_TREE)
    5215                 :            :             {
    5216                 :          1 :               eptype1 = eptype;
    5217                 :          1 :               if (!semantic_result_type)
    5218                 :          1 :                 semantic_result_type = c_common_type (type1, type2);
    5219                 :            :             }
    5220                 :            :         }
    5221                 :      18550 :       result_type = c_common_type (eptype1, eptype2);
    5222                 :      18550 :       if (result_type == error_mark_node)
    5223                 :            :         return error_mark_node;
    5224                 :      18548 :       do_warn_double_promotion (result_type, type1, type2,
    5225                 :            :                                 "implicit conversion from %qT to %qT to "
    5226                 :            :                                 "match other result of conditional",
    5227                 :            :                                 colon_loc);
    5228                 :            : 
    5229                 :            :       /* If -Wsign-compare, warn here if type1 and type2 have
    5230                 :            :          different signedness.  We'll promote the signed to unsigned
    5231                 :            :          and later code won't know it used to be different.
    5232                 :            :          Do this check on the original types, so that explicit casts
    5233                 :            :          will be considered, but default promotions won't.  */
    5234                 :      18548 :       if (c_inhibit_evaluation_warnings == 0)
    5235                 :            :         {
    5236                 :      18435 :           int unsigned_op1 = TYPE_UNSIGNED (TREE_TYPE (orig_op1));
    5237                 :      18435 :           int unsigned_op2 = TYPE_UNSIGNED (TREE_TYPE (orig_op2));
    5238                 :            : 
    5239                 :      18435 :           if (unsigned_op1 ^ unsigned_op2)
    5240                 :            :             {
    5241                 :      10778 :               bool ovf;
    5242                 :            : 
    5243                 :            :               /* Do not warn if the result type is signed, since the
    5244                 :            :                  signed type will only be chosen if it can represent
    5245                 :            :                  all the values of the unsigned type.  */
    5246                 :      10778 :               if (!TYPE_UNSIGNED (result_type))
    5247                 :            :                 /* OK */;
    5248                 :            :               else
    5249                 :            :                 {
    5250                 :      10675 :                   bool op1_maybe_const = true;
    5251                 :      10675 :                   bool op2_maybe_const = true;
    5252                 :            : 
    5253                 :            :                   /* Do not warn if the signed quantity is an
    5254                 :            :                      unsuffixed integer literal (or some static
    5255                 :            :                      constant expression involving such literals) and
    5256                 :            :                      it is non-negative.  This warning requires the
    5257                 :            :                      operands to be folded for best results, so do
    5258                 :            :                      that folding in this case even without
    5259                 :            :                      warn_sign_compare to avoid warning options
    5260                 :            :                      possibly affecting code generation.  */
    5261                 :      10675 :                   c_inhibit_evaluation_warnings
    5262                 :      10675 :                     += (ifexp == truthvalue_false_node);
    5263                 :      10675 :                   op1 = c_fully_fold (op1, require_constant_value,
    5264                 :            :                                       &op1_maybe_const);
    5265                 :      10675 :                   c_inhibit_evaluation_warnings
    5266                 :      10675 :                     -= (ifexp == truthvalue_false_node);
    5267                 :            : 
    5268                 :      10675 :                   c_inhibit_evaluation_warnings
    5269                 :      10675 :                     += (ifexp == truthvalue_true_node);
    5270                 :      10675 :                   op2 = c_fully_fold (op2, require_constant_value,
    5271                 :            :                                       &op2_maybe_const);
    5272                 :      10675 :                   c_inhibit_evaluation_warnings
    5273                 :      10675 :                     -= (ifexp == truthvalue_true_node);
    5274                 :            : 
    5275                 :      10675 :                   if (warn_sign_compare)
    5276                 :            :                     {
    5277                 :        749 :                       if ((unsigned_op2
    5278                 :        405 :                            && tree_expr_nonnegative_warnv_p (op1, &ovf))
    5279                 :        752 :                           || (unsigned_op1
    5280                 :        344 :                               && tree_expr_nonnegative_warnv_p (op2, &ovf)))
    5281                 :            :                         /* OK */;
    5282                 :         10 :                       else if (unsigned_op2)
    5283                 :          3 :                         warning_at (op1_loc, OPT_Wsign_compare,
    5284                 :            :                                     "operand of %<?:%> changes signedness from "
    5285                 :            :                                     "%qT to %qT due to unsignedness of other "
    5286                 :          3 :                                     "operand", TREE_TYPE (orig_op1),
    5287                 :          3 :                                     TREE_TYPE (orig_op2));
    5288                 :            :                       else
    5289                 :          7 :                         warning_at (op2_loc, OPT_Wsign_compare,
    5290                 :            :                                     "operand of %<?:%> changes signedness from "
    5291                 :            :                                     "%qT to %qT due to unsignedness of other "
    5292                 :          7 :                                     "operand", TREE_TYPE (orig_op2),
    5293                 :          7 :                                     TREE_TYPE (orig_op1));
    5294                 :            :                     }
    5295                 :      10675 :                   if (!op1_maybe_const || TREE_CODE (op1) != INTEGER_CST)
    5296                 :       5558 :                     op1 = c_wrap_maybe_const (op1, !op1_maybe_const);
    5297                 :      10675 :                   if (!op2_maybe_const || TREE_CODE (op2) != INTEGER_CST)
    5298                 :       3733 :                     op2 = c_wrap_maybe_const (op2, !op2_maybe_const);
    5299                 :            :                 }
    5300                 :            :             }
    5301                 :            :         }
    5302                 :            :     }
    5303                 :      44998 :   else if (code1 == VOID_TYPE || code2 == VOID_TYPE)
    5304                 :            :     {
    5305                 :         55 :       if (code1 != VOID_TYPE || code2 != VOID_TYPE)
    5306                 :         55 :         pedwarn (colon_loc, OPT_Wpedantic,
    5307                 :            :                  "ISO C forbids conditional expr with only one void side");
    5308                 :         55 :       result_type = void_type_node;
    5309                 :            :     }
    5310                 :      44943 :   else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE)
    5311                 :            :     {
    5312                 :      44718 :       addr_space_t as1 = TYPE_ADDR_SPACE (TREE_TYPE (type1));
    5313                 :      44718 :       addr_space_t as2 = TYPE_ADDR_SPACE (TREE_TYPE (type2));
    5314                 :      44718 :       addr_space_t as_common;
    5315                 :            : 
    5316                 :      44718 :       if (comp_target_types (colon_loc, type1, type2))
    5317                 :       2527 :         result_type = common_pointer_type (type1, type2);
    5318                 :      42191 :       else if (null_pointer_constant_p (orig_op1))
    5319                 :            :         result_type = type2;
    5320                 :      39653 :       else if (null_pointer_constant_p (orig_op2))
    5321                 :            :         result_type = type1;
    5322                 :      18697 :       else if (!addr_space_superset (as1, as2, &as_common))
    5323                 :            :         {
    5324                 :          0 :           error_at (colon_loc, "pointers to disjoint address spaces "
    5325                 :            :                     "used in conditional expression");
    5326                 :          0 :           return error_mark_node;
    5327                 :            :         }
    5328                 :      18697 :       else if (VOID_TYPE_P (TREE_TYPE (type1))
    5329                 :      18697 :                && !TYPE_ATOMIC (TREE_TYPE (type1)))
    5330                 :            :         {
    5331                 :        291 :           if ((TREE_CODE (TREE_TYPE (type2)) == ARRAY_TYPE)
    5332                 :        299 :               && (TYPE_QUALS (strip_array_types (TREE_TYPE (type2)))
    5333                 :          8 :                   & ~TYPE_QUALS (TREE_TYPE (type1))))
    5334                 :          4 :             warning_at (colon_loc, OPT_Wdiscarded_array_qualifiers,
    5335                 :            :                         "pointer to array loses qualifier "
    5336                 :            :                         "in conditional expression");
    5337                 :            : 
    5338                 :        291 :           if (TREE_CODE (TREE_TYPE (type2)) == FUNCTION_TYPE)
    5339                 :          1 :             pedwarn (colon_loc, OPT_Wpedantic,
    5340                 :            :                      "ISO C forbids conditional expr between "
    5341                 :            :                      "%<void *%> and function pointer");
    5342                 :        582 :           result_type = build_pointer_type (qualify_type (TREE_TYPE (type1),
    5343                 :        291 :                                                           TREE_TYPE (type2)));
    5344                 :            :         }
    5345                 :      18406 :       else if (VOID_TYPE_P (TREE_TYPE (type2))
    5346                 :      18406 :                && !TYPE_ATOMIC (TREE_TYPE (type2)))
    5347                 :            :         {
    5348                 :      18391 :           if ((TREE_CODE (TREE_TYPE (type1)) == ARRAY_TYPE)
    5349                 :      18391 :               && (TYPE_QUALS (strip_array_types (TREE_TYPE (type1)))
    5350                 :          0 :                   & ~TYPE_QUALS (TREE_TYPE (type2))))
    5351                 :          0 :             warning_at (colon_loc, OPT_Wdiscarded_array_qualifiers,
    5352                 :            :                         "pointer to array loses qualifier "
    5353                 :            :                         "in conditional expression");
    5354                 :            : 
    5355                 :      18391 :           if (TREE_CODE (TREE_TYPE (type1)) == FUNCTION_TYPE)
    5356                 :          1 :             pedwarn (colon_loc, OPT_Wpedantic,
    5357                 :            :                      "ISO C forbids conditional expr between "
    5358                 :            :                      "%<void *%> and function pointer");
    5359                 :      36782 :           result_type = build_pointer_type (qualify_type (TREE_TYPE (type2),
    5360                 :      18391 :                                                           TREE_TYPE (type1)));
    5361                 :            :         }
    5362                 :            :       /* Objective-C pointer comparisons are a bit more lenient.  */
    5363                 :         15 :       else if (objc_have_common_type (type1, type2, -3, NULL_TREE))
    5364                 :          0 :         result_type = objc_common_type (type1, type2);
    5365                 :            :       else
    5366                 :            :         {
    5367                 :         15 :           int qual = ENCODE_QUAL_ADDR_SPACE (as_common);
    5368                 :         15 :           if (bltin1 && bltin2)
    5369                 :          1 :             warning_at (colon_loc, OPT_Wincompatible_pointer_types,
    5370                 :            :                         "pointer type mismatch between %qT and %qT "
    5371                 :            :                         "of %qD and %qD in conditional expression",
    5372                 :            :                         type1, type2, bltin1, bltin2);
    5373                 :            :           else
    5374                 :         14 :             pedwarn (colon_loc, 0,
    5375                 :            :                      "pointer type mismatch in conditional expression");
    5376                 :         15 :           result_type = build_pointer_type
    5377                 :         15 :                           (build_qualified_type (void_type_node, qual));
    5378                 :            :         }
    5379                 :            :     }
    5380                 :        225 :   else if (code1 == POINTER_TYPE && code2 == INTEGER_TYPE)
    5381                 :            :     {
    5382                 :        168 :       if (!null_pointer_constant_p (orig_op2))
    5383                 :          2 :         pedwarn (colon_loc, 0,
    5384                 :            :                  "pointer/integer type mismatch in conditional expression");
    5385                 :            :       else
    5386                 :            :         {
    5387                 :        166 :           op2 = null_pointer_node;
    5388                 :            :         }
    5389                 :            :       result_type = type1;
    5390                 :            :     }
    5391                 :         57 :   else if (code2 == POINTER_TYPE && code1 == INTEGER_TYPE)
    5392                 :            :     {
    5393                 :         57 :       if (!null_pointer_constant_p (orig_op1))
    5394                 :          0 :         pedwarn (colon_loc, 0,
    5395                 :            :                  "pointer/integer type mismatch in conditional expression");
    5396                 :            :       else
    5397                 :            :         {
    5398                 :         57 :           op1 = null_pointer_node;
    5399                 :            :         }
    5400                 :            :       result_type = type2;
    5401                 :            :     }
    5402                 :            : 
    5403                 :     244459 :   if (!result_type)
    5404                 :            :     {
    5405                 :          0 :       if (flag_cond_mismatch)
    5406                 :          0 :         result_type = void_type_node;
    5407                 :            :       else
    5408                 :            :         {
    5409                 :          0 :           error_at (colon_loc, "type mismatch in conditional expression");
    5410                 :          0 :           return error_mark_node;
    5411                 :            :         }
    5412                 :            :     }
    5413                 :            : 
    5414                 :            :   /* Merge const and volatile flags of the incoming types.  */
    5415                 :     244459 :   result_type
    5416                 :     733242 :     = build_type_variant (result_type,
    5417                 :            :                           TYPE_READONLY (type1) || TYPE_READONLY (type2),
    5418                 :            :                           TYPE_VOLATILE (type1) || TYPE_VOLATILE (type2));
    5419                 :            : 
    5420                 :     244459 :   op1 = ep_convert_and_check (colon_loc, result_type, op1,
    5421                 :            :                               semantic_result_type);
    5422                 :     244459 :   op2 = ep_convert_and_check (colon_loc, result_type, op2,
    5423                 :            :                               semantic_result_type);
    5424                 :            : 
    5425                 :     244459 :   if (ifexp_bcp && ifexp == truthvalue_true_node)
    5426                 :            :     {
    5427                 :         10 :       op2_int_operands = true;
    5428                 :         10 :       op1 = c_fully_fold (op1, require_constant_value, NULL);
    5429                 :            :     }
    5430                 :     244459 :   if (ifexp_bcp && ifexp == truthvalue_false_node)
    5431                 :            :     {
    5432                 :         46 :       op1_int_operands = true;
    5433                 :         46 :       op2 = c_fully_fold (op2, require_constant_value, NULL);
    5434                 :            :     }
    5435                 :     544713 :   int_const = int_operands = (ifexp_int_operands
    5436                 :     244459 :                               && op1_int_operands
    5437                 :     244459 :                               && op2_int_operands);
    5438                 :      55795 :   if (int_operands)
    5439                 :            :     {
    5440                 :      55795 :       int_const = ((ifexp == truthvalue_true_node
    5441                 :      33997 :                     && TREE_CODE (orig_op1) == INTEGER_CST
    5442                 :      33983 :                     && !TREE_OVERFLOW (orig_op1))
    5443                 :      55809 :                    || (ifexp == truthvalue_false_node
    5444                 :      21752 :                        && TREE_CODE (orig_op2) == INTEGER_CST
    5445                 :      21736 :                        && !TREE_OVERFLOW (orig_op2)));
    5446                 :            :     }
    5447                 :            : 
    5448                 :            :   /* Need to convert condition operand into a vector mask.  */
    5449                 :     244459 :   if (VECTOR_TYPE_P (TREE_TYPE (ifexp)))
    5450                 :            :     {
    5451                 :          0 :       tree vectype = TREE_TYPE (ifexp);
    5452                 :          0 :       tree elem_type = TREE_TYPE (vectype);
    5453                 :          0 :       tree zero = build_int_cst (elem_type, 0);
    5454                 :          0 :       tree zero_vec = build_vector_from_val (vectype, zero);
    5455                 :          0 :       tree cmp_type = truth_type_for (vectype);
    5456                 :          0 :       ifexp = build2 (NE_EXPR, cmp_type, ifexp, zero_vec);
    5457                 :            :     }
    5458                 :            : 
    5459                 :     244459 :   if (int_const || (ifexp_bcp && TREE_CODE (ifexp) == INTEGER_CST))
    5460                 :      55748 :     ret = fold_build3_loc (colon_loc, COND_EXPR, result_type, ifexp, op1, op2);
    5461                 :            :   else
    5462                 :            :     {
    5463                 :     188711 :       if (int_operands)
    5464                 :            :         {
    5465                 :            :           /* Use c_fully_fold here, since C_MAYBE_CONST_EXPR might be
    5466                 :            :              nested inside of the expression.  */
    5467                 :         76 :           op1 = c_fully_fold (op1, false, NULL);
    5468                 :         76 :           op2 = c_fully_fold (op2, false, NULL);
    5469                 :            :         }
    5470                 :     188711 :       ret = build3 (COND_EXPR, result_type, ifexp, op1, op2);
    5471                 :     188711 :       if (int_operands)
    5472                 :         76 :         ret = note_integer_operands (ret);
    5473                 :            :     }
    5474                 :     244459 :   if (semantic_result_type)
    5475                 :          9 :     ret = build1 (EXCESS_PRECISION_EXPR, semantic_result_type, ret);
    5476                 :            : 
    5477                 :     244459 :   protected_set_expr_location (ret, colon_loc);
    5478                 :            : 
    5479                 :            :   /* If the OP1 and OP2 are the same and don't have side-effects,
    5480                 :            :      warn here, because the COND_EXPR will be turned into OP1.  */
    5481                 :     244459 :   if (warn_duplicated_branches
    5482                 :         34 :       && TREE_CODE (ret) == COND_EXPR
    5483                 :     244493 :       && (op1 == op2 || operand_equal_p (op1, op2, 0)))
    5484                 :         13 :     warning_at (EXPR_LOCATION (ret), OPT_Wduplicated_branches,
    5485                 :            :                 "this condition has identical branches");
    5486                 :            : 
    5487                 :            :   return ret;
    5488                 :            : }
    5489                 :            : 
    5490                 :            : /* Return a compound expression that performs two expressions and
    5491                 :            :    returns the value of the second of them.
    5492                 :            : 
    5493                 :            :    LOC is the location of the COMPOUND_EXPR.  */
    5494                 :            : 
    5495                 :            : tree
    5496                 :      53549 : build_compound_expr (location_t loc, tree expr1, tree expr2)
    5497                 :            : {
    5498                 :      53549 :   bool expr1_int_operands, expr2_int_operands;
    5499                 :      53549 :   tree eptype = NULL_TREE;
    5500                 :      53549 :   tree ret;
    5501                 :            : 
    5502                 :      53549 :   expr1_int_operands = EXPR_INT_CONST_OPERANDS (expr1);
    5503                 :        274 :   if (expr1_int_operands)
    5504                 :        274 :     expr1 = remove_c_maybe_const_expr (expr1);
    5505                 :      53549 :   expr2_int_operands = EXPR_INT_CONST_OPERANDS (expr2);
    5506                 :      20248 :   if (expr2_int_operands)
    5507                 :      20248 :     expr2 = remove_c_maybe_const_expr (expr2);
    5508                 :            : 
    5509                 :      53549 :   if (TREE_CODE (expr1) == EXCESS_PRECISION_EXPR)
    5510                 :          0 :     expr1 = TREE_OPERAND (expr1, 0);
    5511                 :      53549 :   if (TREE_CODE (expr2) == EXCESS_PRECISION_EXPR)
    5512                 :            :     {
    5513                 :          1 :       eptype = TREE_TYPE (expr2);
    5514                 :          1 :       expr2 = TREE_OPERAND (expr2, 0);
    5515                 :            :     }
    5516                 :            : 
    5517                 :      53549 :   if (!TREE_SIDE_EFFECTS (expr1))
    5518                 :            :     {
    5519                 :            :       /* The left-hand operand of a comma expression is like an expression
    5520                 :            :          statement: with -Wunused, we should warn if it doesn't have
    5521                 :            :          any side-effects, unless it was explicitly cast to (void).  */
    5522                 :       3026 :       if (warn_unused_value)
    5523                 :            :         {
    5524                 :       1100 :           if (VOID_TYPE_P (TREE_TYPE (expr1))
    5525                 :       1100 :               && CONVERT_EXPR_P (expr1))
    5526                 :            :             ; /* (void) a, b */
    5527                 :         14 :           else if (VOID_TYPE_P (TREE_TYPE (expr1))
    5528                 :          4 :                    && TREE_CODE (expr1) == COMPOUND_EXPR
    5529                 :         17 :                    && CONVERT_EXPR_P (TREE_OPERAND (expr1, 1)))
    5530                 :            :             ; /* (void) a, (void) b, c */
    5531                 :            :           else
    5532                 :         11 :             warning_at (loc, OPT_Wunused_value,
    5533                 :            :                         "left-hand operand of comma expression has no effect");
    5534                 :            :         }
    5535                 :            :     }
    5536                 :      50523 :   else if (TREE_CODE (expr1) == COMPOUND_EXPR
    5537                 :      11986 :            && warn_unused_value)
    5538                 :            :     {
    5539                 :            :       tree r = expr1;
    5540                 :            :       location_t cloc = loc;
    5541                 :       3829 :       while (TREE_CODE (r) == COMPOUND_EXPR)
    5542                 :            :         {
    5543                 :       1915 :           if (EXPR_HAS_LOCATION (r))
    5544                 :       1915 :             cloc = EXPR_LOCATION (r);
    5545                 :       1915 :           r = TREE_OPERAND (r, 1);
    5546                 :            :         }
    5547                 :       1914 :       if (!TREE_SIDE_EFFECTS (r)
    5548                 :          3 :           && !VOID_TYPE_P (TREE_TYPE (r))
    5549                 :       1917 :           && !CONVERT_EXPR_P (r))
    5550                 :          3 :         warning_at (cloc, OPT_Wunused_value,
    5551                 :            :                     "right-hand operand of comma expression has no effect");
    5552                 :            :     }
    5553                 :            : 
    5554                 :            :   /* With -Wunused, we should also warn if the left-hand operand does have
    5555                 :            :      side-effects, but computes a value which is not used.  For example, in
    5556                 :            :      `foo() + bar(), baz()' the result of the `+' operator is not used,
    5557                 :            :      so we should issue a warning.  */
    5558                 :      48609 :   else if (warn_unused_value)
    5559                 :       8383 :     warn_if_unused_value (expr1, loc);
    5560                 :            : 
    5561                 :      53549 :   if (expr2 == error_mark_node)
    5562                 :            :     return error_mark_node;
    5563                 :            : 
    5564                 :      53528 :   ret = build2 (COMPOUND_EXPR, TREE_TYPE (expr2), expr1, expr2);
    5565                 :            : 
    5566                 :      53528 :   if (flag_isoc99
    5567                 :      53528 :       && expr1_int_operands
    5568                 :      53471 :       && expr2_int_operands)
    5569                 :        120 :     ret = note_integer_operands (ret);
    5570                 :            : 
    5571                 :      53528 :   if (eptype)
    5572                 :          1 :     ret = build1 (EXCESS_PRECISION_EXPR, eptype, ret);
    5573                 :            : 
    5574                 :      53528 :   protected_set_expr_location (ret, loc);
    5575                 :      53528 :   return ret;
    5576                 :            : }
    5577                 :            : 
    5578                 :            : /* Issue -Wcast-qual warnings when appropriate.  TYPE is the type to
    5579                 :            :    which we are casting.  OTYPE is the type of the expression being
    5580                 :            :    cast.  Both TYPE and OTYPE are pointer types.  LOC is the location
    5581                 :            :    of the cast.  -Wcast-qual appeared on the command line.  Named
    5582                 :            :    address space qualifiers are not handled here, because they result
    5583                 :            :    in different warnings.  */
    5584                 :            : 
    5585                 :            : static void
    5586                 :      10458 : handle_warn_cast_qual (location_t loc, tree type, tree otype)
    5587                 :            : {
    5588                 :      10458 :   tree in_type = type;
    5589                 :      10458 :   tree in_otype = otype;
    5590                 :      10458 :   int added = 0;
    5591                 :      10458 :   int discarded = 0;
    5592                 :      10628 :   bool is_const;
    5593                 :            : 
    5594                 :            :   /* Check that the qualifiers on IN_TYPE are a superset of the
    5595                 :            :      qualifiers of IN_OTYPE.  The outermost level of POINTER_TYPE
    5596                 :            :      nodes is uninteresting and we stop as soon as we hit a
    5597                 :            :      non-POINTER_TYPE node on either type.  */
    5598                 :      10628 :   do
    5599                 :            :     {
    5600                 :      10628 :       in_otype = TREE_TYPE (in_otype);
    5601                 :      10628 :       in_type = TREE_TYPE (in_type);
    5602                 :            : 
    5603                 :            :       /* GNU C allows cv-qualified function types.  'const' means the
    5604                 :            :          function is very pure, 'volatile' means it can't return.  We
    5605                 :            :          need to warn when such qualifiers are added, not when they're
    5606                 :            :          taken away.  */
    5607                 :      10628 :       if (TREE_CODE (in_otype) == FUNCTION_TYPE
    5608                 :         62 :           && TREE_CODE (in_type) == FUNCTION_TYPE)
    5609                 :         18 :         added |= (TYPE_QUALS_NO_ADDR_SPACE (in_type)
    5610                 :         18 :                   & ~TYPE_QUALS_NO_ADDR_SPACE (in_otype));
    5611                 :            :       else
    5612                 :      10610 :         discarded |= (TYPE_QUALS_NO_ADDR_SPACE (in_otype)
    5613                 :      10610 :                       & ~TYPE_QUALS_NO_ADDR_SPACE (in_type));
    5614                 :            :     }
    5615                 :      10628 :   while (TREE_CODE (in_type) == POINTER_TYPE
    5616                 :      10628 :          && TREE_CODE (in_otype) == POINTER_TYPE);
    5617                 :            : 
    5618                 :      10458 :   if (added)
    5619                 :          2 :     warning_at (loc, OPT_Wcast_qual,
    5620                 :            :                 "cast adds %q#v qualifier to function type", added);
    5621                 :            : 
    5622                 :      10458 :   if (discarded)
    5623                 :            :     /* There are qualifiers present in IN_OTYPE that are not present
    5624                 :            :        in IN_TYPE.  */
    5625                 :       1533 :     warning_at (loc, OPT_Wcast_qual,
    5626                 :            :                 "cast discards %qv qualifier from pointer target type",
    5627                 :            :                 discarded);
    5628                 :            : 
    5629                 :      10458 :   if (added || discarded)
    5630                 :            :     return;
    5631                 :            : 
    5632                 :            :   /* A cast from **T to const **T is unsafe, because it can cause a
    5633                 :            :      const value to be changed with no additional warning.  We only
    5634                 :            :      issue this warning if T is the same on both sides, and we only
    5635                 :            :      issue the warning if there are the same number of pointers on
    5636                 :            :      both sides, as otherwise the cast is clearly unsafe anyhow.  A
    5637                 :            :      cast is unsafe when a qualifier is added at one level and const
    5638                 :            :      is not present at all outer levels.
    5639                 :            : 
    5640                 :            :      To issue this warning, we check at each level whether the cast
    5641                 :            :      adds new qualifiers not already seen.  We don't need to special
    5642                 :            :      case function types, as they won't have the same
    5643                 :            :      TYPE_MAIN_VARIANT.  */
    5644                 :            : 
    5645                 :       8923 :   if (TYPE_MAIN_VARIANT (in_type) != TYPE_MAIN_VARIANT (in_otype))
    5646                 :            :     return;
    5647                 :         51 :   if (TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE)
    5648                 :            :     return;
    5649                 :            : 
    5650                 :         48 :   in_type = type;
    5651                 :         48 :   in_otype = otype;
    5652                 :         48 :   is_const = TYPE_READONLY (TREE_TYPE (in_type));
    5653                 :        130 :   do
    5654                 :            :     {
    5655                 :        130 :       in_type = TREE_TYPE (in_type);
    5656                 :        130 :       in_otype = TREE_TYPE (in_otype);
    5657                 :        130 :       if ((TYPE_QUALS (in_type) &~ TYPE_QUALS (in_otype)) != 0
    5658                 :        130 :           && !is_const)
    5659                 :            :         {
    5660                 :         27 :           warning_at (loc, OPT_Wcast_qual,
    5661                 :            :                       "to be safe all intermediate pointers in cast from "
    5662                 :            :                       "%qT to %qT must be %<const%> qualified",
    5663                 :            :                       otype, type);
    5664                 :         27 :           break;
    5665                 :            :         }
    5666                 :        103 :       if (is_const)
    5667                 :         72 :         is_const = TYPE_READONLY (in_type);
    5668                 :            :     }
    5669                 :        103 :   while (TREE_CODE (in_type) == POINTER_TYPE);
    5670                 :            : }
    5671                 :            : 
    5672                 :            : /* Heuristic check if two parameter types can be considered ABI-equivalent.  */
    5673                 :            : 
    5674                 :            : static bool
    5675                 :       1882 : c_safe_arg_type_equiv_p (tree t1, tree t2)
    5676                 :            : {
    5677                 :       1882 :   t1 = TYPE_MAIN_VARIANT (t1);
    5678                 :       1882 :   t2 = TYPE_MAIN_VARIANT (t2);
    5679                 :            : 
    5680                 :       1882 :   if (TREE_CODE (t1) == POINTER_TYPE
    5681                 :         83 :       && TREE_CODE (t2) == POINTER_TYPE)
    5682                 :            :     return true;
    5683                 :            : 
    5684                 :            :   /* The signedness of the parameter matters only when an integral
    5685                 :            :      type smaller than int is promoted to int, otherwise only the
    5686                 :            :      precision of the parameter matters.
    5687                 :            :      This check should make sure that the callee does not see
    5688                 :            :      undefined values in argument registers.  */
    5689                 :       1821 :   if (INTEGRAL_TYPE_P (t1)
    5690                 :        727 :       && INTEGRAL_TYPE_P (t2)
    5691                 :        286 :       && TYPE_PRECISION (t1) == TYPE_PRECISION (t2)
    5692                 :       1930 :       && (TYPE_UNSIGNED (t1) == TYPE_UNSIGNED (t2)
    5693                 :          0 :           || !targetm.calls.promote_prototypes (NULL_TREE)
    5694                 :          0 :           || TYPE_PRECISION (t1) >= TYPE_PRECISION (integer_type_node)))
    5695                 :        109 :     return true;
    5696                 :            : 
    5697                 :       1712 :   return comptypes (t1, t2);
    5698                 :            : }
    5699                 :            : 
    5700                 :            : /* Check if a type cast between two function types can be considered safe.  */
    5701                 :            : 
    5702                 :            : static bool
    5703                 :       3485 : c_safe_function_type_cast_p (tree t1, tree t2)
    5704                 :            : {
    5705                 :       3485 :   if (TREE_TYPE (t1) == void_type_node &&
    5706                 :       2372 :       TYPE_ARG_TYPES (t1) == void_list_node)
    5707                 :            :     return true;
    5708                 :            : 
    5709                 :       2678 :   if (TREE_TYPE (t2) == void_type_node &&
    5710                 :       1556 :       TYPE_ARG_TYPES (t2) == void_list_node)
    5711                 :            :     return true;
    5712                 :            : 
    5713                 :       1695 :   if (!c_safe_arg_type_equiv_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    5714                 :            :     return false;
    5715                 :            : 
    5716                 :        759 :   for (t1 = TYPE_ARG_TYPES (t1), t2 = TYPE_ARG_TYPES (t2);
    5717                 :        759 :        t1 && t2;
    5718                 :         84 :        t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
    5719                 :        187 :     if (!c_safe_arg_type_equiv_p (TREE_VALUE (t1), TREE_VALUE (t2)))
    5720                 :            :       return false;
    5721                 :            : 
    5722                 :            :   return true;
    5723                 :            : }
    5724                 :            : 
    5725                 :            : /* Build an expression representing a cast to type TYPE of expression EXPR.
    5726                 :            :    LOC is the location of the cast-- typically the open paren of the cast.  */
    5727                 :            : 
    5728                 :            : tree
    5729                 :   71031400 : build_c_cast (location_t loc, tree type, tree expr)
    5730                 :            : {
    5731                 :   71031400 :   tree value;
    5732                 :            : 
    5733                 :   71031400 :   bool int_operands = EXPR_INT_CONST_OPERANDS (expr);
    5734                 :            : 
    5735                 :   71031400 :   if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
    5736                 :          8 :     expr = TREE_OPERAND (expr, 0);
    5737                 :            : 
    5738                 :   71031400 :   value = expr;
    5739                 :   71031400 :   if (int_operands)
    5740                 :    3734600 :     value = remove_c_maybe_const_expr (value);
    5741                 :            : 
    5742                 :   71031400 :   if (type == error_mark_node || expr == error_mark_node)
    5743                 :            :     return error_mark_node;
    5744                 :            : 
    5745                 :            :   /* The ObjC front-end uses TYPE_MAIN_VARIANT to tie together types differing
    5746                 :            :      only in <protocol> qualifications.  But when constructing cast expressions,
    5747                 :            :      the protocols do matter and must be kept around.  */
    5748                 :   71031200 :   if (objc_is_object_ptr (type) && objc_is_object_ptr (TREE_TYPE (expr)))
    5749                 :          0 :     return build1 (NOP_EXPR, type, expr);
    5750                 :            : 
    5751                 :   71031200 :   type = TYPE_MAIN_VARIANT (type);
    5752                 :            : 
    5753                 :   71031200 :   if (TREE_CODE (type) == ARRAY_TYPE)
    5754                 :            :     {
    5755                 :         24 :       error_at (loc, "cast specifies array type");
    5756                 :         24 :       return error_mark_node;
    5757                 :            :     }
    5758                 :            : 
    5759                 :   71031100 :   if (TREE_CODE (type) == FUNCTION_TYPE)
    5760                 :            :     {
    5761                 :          6 :       error_at (loc, "cast specifies function type");
    5762                 :          6 :       return error_mark_node;
    5763                 :            :     }
    5764                 :            : 
    5765                 :   71031100 :   if (!VOID_TYPE_P (type))
    5766                 :            :     {
    5767                 :   71016300 :       value = require_complete_type (loc, value);
    5768                 :   71016300 :       if (value == error_mark_node)
    5769                 :            :         return error_mark_node;
    5770                 :            :     }
    5771                 :            : 
    5772                 :   71031100 :   if (type == TYPE_MAIN_VARIANT (TREE_TYPE (value)))
    5773                 :            :     {
    5774                 :   10919200 :       if (RECORD_OR_UNION_TYPE_P (type))
    5775                 :         35 :         pedwarn (loc, OPT_Wpedantic,
    5776                 :            :                  "ISO C forbids casting nonscalar to the same type");
    5777                 :            : 
    5778                 :            :       /* Convert to remove any qualifiers from VALUE's type.  */
    5779                 :   10919200 :       value = convert (type, value);
    5780                 :            :     }
    5781                 :   60111900 :   else if (TREE_CODE (type) == UNION_TYPE)
    5782                 :            :     {
    5783                 :         95 :       tree field;
    5784                 :            : 
    5785                 :        151 :       for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    5786                 :        136 :         if (TREE_TYPE (field) != error_mark_node
    5787                 :        271 :             && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field)),
    5788                 :        135 :                           TYPE_MAIN_VARIANT (TREE_TYPE (value))))
    5789                 :            :           break;
    5790                 :            : 
    5791                 :         95 :       if (field)
    5792                 :            :         {
    5793                 :         80 :           tree t;
    5794                 :         80 :           bool maybe_const = true;
    5795                 :            : 
    5796                 :         80 :           pedwarn (loc, OPT_Wpedantic, "ISO C forbids casts to union type");
    5797                 :         80 :           t = c_fully_fold (value, false, &maybe_const);
    5798                 :         80 :           t = build_constructor_single (type, field, t);
    5799                 :         80 :           if (!maybe_const)
    5800                 :          8 :             t = c_wrap_maybe_const (t, true);
    5801                 :         80 :           t = digest_init (loc, type, t,
    5802                 :            :                            NULL_TREE, false, true, 0);
    5803                 :         80 :           TREE_CONSTANT (t) = TREE_CONSTANT (value);
    5804                 :         80 :           return t;
    5805                 :            :         }
    5806                 :         15 :       error_at (loc, "cast to union type from type not present in union");
    5807                 :         15 :       return error_mark_node;
    5808                 :            :     }
    5809                 :            :   else
    5810                 :            :     {
    5811                 :   60111800 :       tree otype, ovalue;
    5812                 :            : 
    5813                 :   60111800 :       if (type == void_type_node)
    5814                 :            :         {
    5815                 :      14800 :           tree t = build1 (CONVERT_EXPR, type, value);
    5816                 :      14800 :           SET_EXPR_LOCATION (t, loc);
    5817                 :      14800 :           return t;
    5818                 :            :         }
    5819                 :            : 
    5820                 :   60097000 :       otype = TREE_TYPE (value);
    5821                 :            : 
    5822                 :            :       /* Optionally warn about potentially worrisome casts.  */
    5823                 :   60097000 :       if (warn_cast_qual
    5824                 :     126175 :           && TREE_CODE (type) == POINTER_TYPE
    5825                 :      18804 :           && TREE_CODE (otype) == POINTER_TYPE)
    5826                 :      10458 :         handle_warn_cast_qual (loc, type, otype);
    5827                 :            : 
    5828                 :            :       /* Warn about conversions between pointers to disjoint
    5829                 :            :          address spaces.  */
    5830                 :   60097000 :       if (TREE_CODE (type) == POINTER_TYPE
    5831                 :    2143960 :           && TREE_CODE (otype) == POINTER_TYPE
    5832                 :   62022200 :           && !null_pointer_constant_p (value))
    5833                 :            :         {
    5834                 :    1885080 :           addr_space_t as_to = TYPE_ADDR_SPACE (TREE_TYPE (type));
    5835                 :    1885080 :           addr_space_t as_from = TYPE_ADDR_SPACE (TREE_TYPE (otype));
    5836                 :    1885080 :           addr_space_t as_common;
    5837                 :            : 
    5838                 :    1885080 :           if (!addr_space_superset (as_to, as_from, &as_common))
    5839                 :            :             {
    5840                 :          0 :               if (ADDR_SPACE_GENERIC_P (as_from))
    5841                 :          0 :                 warning_at (loc, 0, "cast to %s address space pointer "
    5842                 :            :                             "from disjoint generic address space pointer",
    5843                 :            :                             c_addr_space_name (as_to));
    5844                 :            : 
    5845                 :          0 :               else if (ADDR_SPACE_GENERIC_P (as_to))
    5846                 :          0 :                 warning_at (loc, 0, "cast to generic address space pointer "
    5847                 :            :                             "from disjoint %s address space pointer",
    5848                 :            :                             c_addr_space_name (as_from));
    5849                 :            : 
    5850                 :            :               else
    5851                 :          0 :                 warning_at (loc, 0, "cast to %s address space pointer "
    5852                 :            :                             "from disjoint %s address space pointer",
    5853                 :            :                             c_addr_space_name (as_to),
    5854                 :            :                             c_addr_space_name (as_from));
    5855                 :            :             }
    5856                 :            :         }
    5857                 :            : 
    5858                 :            :       /* Warn about possible alignment problems.  */
    5859                 :   60097000 :       if ((STRICT_ALIGNMENT || warn_cast_align == 2)
    5860                 :          4 :           && TREE_CODE (type) == POINTER_TYPE
    5861                 :          4 :           && TREE_CODE (otype) == POINTER_TYPE
    5862                 :          4 :           && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE
    5863                 :          4 :           && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
    5864                 :            :           /* Don't warn about opaque types, where the actual alignment
    5865                 :            :              restriction is unknown.  */
    5866                 :          6 :           && !(RECORD_OR_UNION_TYPE_P (TREE_TYPE (otype))
    5867                 :          2 :                && TYPE_MODE (TREE_TYPE (otype)) == VOIDmode)
    5868                 :   60097000 :           && min_align_of_type (TREE_TYPE (type))
    5869                 :          4 :              > min_align_of_type (TREE_TYPE (otype)))
    5870                 :          2 :         warning_at (loc, OPT_Wcast_align,
    5871                 :            :                     "cast increases required alignment of target type");
    5872                 :            : 
    5873                 :   60097000 :       if (TREE_CODE (type) == INTEGER_TYPE
    5874                 :    3723930 :           && TREE_CODE (otype) == POINTER_TYPE
    5875                 :   60118000 :           && TYPE_PRECISION (type) != TYPE_PRECISION (otype))
    5876                 :            :       /* Unlike conversion of integers to pointers, where the
    5877                 :            :          warning is disabled for converting constants because
    5878                 :            :          of cases such as SIG_*, warn about converting constant
    5879                 :            :          pointers to integers. In some cases it may cause unwanted
    5880                 :            :          sign extension, and a warning is appropriate.  */
    5881                 :       1510 :         warning_at (loc, OPT_Wpointer_to_int_cast,
    5882                 :            :                     "cast from pointer to integer of different size");
    5883                 :            : 
    5884                 :   60097000 :       if (TREE_CODE (value) == CALL_EXPR
    5885                 :   20156800 :           && TREE_CODE (type) != TREE_CODE (otype))
    5886                 :       2251 :         warning_at (loc, OPT_Wbad_function_cast,
    5887                 :            :                     "cast from function call of type %qT "
    5888                 :            :                     "to non-matching type %qT", otype, type);
    5889                 :            : 
    5890                 :   60097000 :       if (TREE_CODE (type) == POINTER_TYPE
    5891                 :    2143960 :           && TREE_CODE (otype) == INTEGER_TYPE
    5892                 :     218701 :           && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
    5893                 :            :           /* Don't warn about converting any constant.  */
    5894                 :   60286000 :           && !TREE_CONSTANT (value))
    5895                 :        350 :         warning_at (loc,
    5896                 :            :                     OPT_Wint_to_pointer_cast, "cast to pointer from integer "
    5897                 :            :                     "of different size");
    5898                 :            : 
    5899                 :   60097000 :       if (warn_strict_aliasing <= 2)
    5900                 :   58662300 :         strict_aliasing_warning (EXPR_LOCATION (value), type, expr);
    5901                 :            : 
    5902                 :            :       /* If pedantic, warn for conversions between function and object
    5903                 :            :          pointer types, except for converting a null pointer constant
    5904                 :            :          to function pointer type.  */
    5905                 :   60097000 :       if (pedantic
    5906                 :     155211 :           && TREE_CODE (type) == POINTER_TYPE
    5907                 :      83085 :           && TREE_CODE (otype) == POINTER_TYPE
    5908                 :       1449 :           && TREE_CODE (TREE_TYPE (otype)) == FUNCTION_TYPE
    5909                 :   60097000 :           && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE)
    5910                 :         10 :         pedwarn (loc, OPT_Wpedantic, "ISO C forbids "
    5911                 :            :                  "conversion of function pointer to object pointer type");
    5912                 :            : 
    5913                 :   60097000 :       if (pedantic
    5914                 :     155211 :           && TREE_CODE (type) == POINTER_TYPE
    5915                 :      83085 :           && TREE_CODE (otype) == POINTER_TYPE
    5916                 :       1449 :           && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
    5917                 :         10 :           && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
    5918                 :   60097000 :           && !null_pointer_constant_p (value))
    5919                 :          2 :         pedwarn (loc, OPT_Wpedantic, "ISO C forbids "
    5920                 :            :                  "conversion of object pointer to function pointer type");
    5921                 :            : 
    5922                 :   60097000 :       if (TREE_CODE (type) == POINTER_TYPE
    5923                 :    2143960 :           && TREE_CODE (otype) == POINTER_TYPE
    5924                 :    1925250 :           && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
    5925                 :       4438 :           && TREE_CODE (TREE_TYPE (otype)) == FUNCTION_TYPE
    5926                 :   60100500 :           && !c_safe_function_type_cast_p (TREE_TYPE (type),
    5927                 :       3485 :                                            TREE_TYPE (otype)))
    5928                 :       1123 :         warning_at (loc, OPT_Wcast_function_type,
    5929                 :            :                     "cast between incompatible function types"
    5930                 :            :                     " from %qT to %qT", otype, type);
    5931                 :            : 
    5932                 :   60097000 :       ovalue = value;
    5933                 :   60097000 :       value = convert (type, value);
    5934                 :            : 
    5935                 :            :       /* Ignore any integer overflow caused by the cast.  */
    5936                 :   60102700 :       if (TREE_CODE (value) == INTEGER_CST && !FLOAT_TYPE_P (otype))
    5937                 :            :         {
    5938                 :    3555450 :           if (CONSTANT_CLASS_P (ovalue) && TREE_OVERFLOW (ovalue))
    5939                 :            :             {
    5940                 :          9 :               if (!TREE_OVERFLOW (value))
    5941                 :            :                 {
    5942                 :            :                   /* Avoid clobbering a shared constant.  */
    5943                 :          0 :                   value = copy_node (value);
    5944                 :          0 :                   TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue);
    5945                 :            :                 }
    5946                 :            :             }
    5947                 :    3555440 :           else if (TREE_OVERFLOW (value))
    5948                 :            :             /* Reset VALUE's overflow flags, ensuring constant sharing.  */
    5949                 :       8287 :             value = wide_int_to_tree (TREE_TYPE (value), wi::to_wide (value));
    5950                 :            :         }
    5951                 :            :     }
    5952                 :            : 
    5953                 :            :   /* Don't let a cast be an lvalue.  */
    5954                 :   71016200 :   if (lvalue_p (value))
    5955                 :      36981 :     value = non_lvalue_loc (loc, value);
    5956                 :            : 
    5957                 :            :   /* Don't allow the results of casting to floating-point or complex
    5958                 :            :      types be confused with actual constants, or casts involving
    5959                 :            :      integer and pointer types other than direct integer-to-integer
    5960                 :            :      and integer-to-pointer be confused with integer constant
    5961                 :            :      expressions and null pointer constants.  */
    5962                 :   71016200 :   if (TREE_CODE (value) == REAL_CST
    5963                 :   71016200 :       || TREE_CODE (value) == COMPLEX_CST
    5964                 :   71016200 :       || (TREE_CODE (value) == INTEGER_CST
    5965                 :    3733770 :           && !((TREE_CODE (expr) == INTEGER_CST
    5966                 :    3672840 :                 && INTEGRAL_TYPE_P (TREE_TYPE (expr)))
    5967                 :      52998 :                || TREE_CODE (expr) == REAL_CST
    5968                 :            :                || TREE_CODE (expr) == COMPLEX_CST)))
    5969                 :     118054 :       value = build1 (NOP_EXPR, type, value);
    5970                 :            : 
    5971                 :            :   /* If the expression has integer operands and so can occur in an
    5972                 :            :      unevaluated part of an integer constant expression, ensure the
    5973                 :            :      return value reflects this.  */
    5974                 :   71016200 :   if (int_operands
    5975                 :    3726740 :       && INTEGRAL_TYPE_P (type)
    5976                 :   74436700 :       && !EXPR_INT_CONST_OPERANDS (value))
    5977                 :         13 :     value = note_integer_operands (value);
    5978                 :            : 
    5979                 :   71016200 :   protected_set_expr_location (value, loc);
    5980                 :   71016200 :   return value;
    5981                 :            : }
    5982                 :            : 
    5983                 :            : /* Interpret a cast of expression EXPR to type TYPE.  LOC is the
    5984                 :            :    location of the open paren of the cast, or the position of the cast
    5985                 :            :    expr.  */
    5986                 :            : tree
    5987                 :   71031200 : c_cast_expr (location_t loc, struct c_type_name *type_name, tree expr)
    5988                 :            : {
    5989                 :   71031200 :   tree type;
    5990                 :   71031200 :   tree type_expr = NULL_TREE;
    5991                 :   71031200 :   bool type_expr_const = true;
    5992                 :   71031200 :   tree ret;
    5993                 :   71031200 :   int saved_wsp = warn_strict_prototypes;
    5994                 :            : 
    5995                 :            :   /* This avoids warnings about unprototyped casts on
    5996                 :            :      integers.  E.g. "#define SIG_DFL (void(*)())0".  */
    5997                 :   71031200 :   if (TREE_CODE (expr) == INTEGER_CST)
    5998                 :    3775190 :     warn_strict_prototypes = 0;
    5999                 :   71031200 :   type = groktypename (type_name, &type_expr, &type_expr_const);
    6000                 :   71031200 :   warn_strict_prototypes = saved_wsp;
    6001                 :            : 
    6002                 :     728676 :   if (TREE_CODE (expr) == ADDR_EXPR && !VOID_TYPE_P (type)
    6003                 :   71758300 :       && reject_gcc_builtin (expr))
    6004                 :          2 :     return error_mark_node;
    6005                 :            : 
    6006                 :   71031200 :   ret = build_c_cast (loc, type, expr);
    6007                 :   71031200 :   if (type_expr)
    6008                 :            :     {
    6009                 :        156 :       bool inner_expr_const = true;
    6010                 :        156 :       ret = c_fully_fold (ret, require_constant_value, &inner_expr_const);
    6011                 :        156 :       ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret), type_expr, ret);
    6012                 :        312 :       C_MAYBE_CONST_EXPR_NON_CONST (ret) = !(type_expr_const
    6013                 :        103 :                                              && inner_expr_const);
    6014                 :        156 :       SET_EXPR_LOCATION (ret, loc);
    6015                 :            :     }
    6016                 :            : 
    6017                 :   71031200 :   if (!EXPR_HAS_LOCATION (ret))
    6018                 :    3676310 :     protected_set_expr_location (ret, loc);
    6019                 :            : 
    6020                 :            :   /* C++ does not permits types to be defined in a cast, but it
    6021                 :            :      allows references to incomplete types.  */
    6022                 :   71031200 :   if (warn_cxx_compat && type_name->specs->typespec_kind == ctsk_tagdef)
    6023                 :          1 :     warning_at (loc, OPT_Wc___compat,
    6024                 :            :                 "defining a type in a cast is invalid in C++");
    6025                 :            : 
    6026                 :            :   return ret;
    6027                 :            : }
    6028                 :            : 
    6029                 :            : /* Build an assignment expression of lvalue LHS from value RHS.
    6030                 :            :    If LHS_ORIGTYPE is not NULL, it is the original type of LHS, which
    6031                 :            :    may differ from TREE_TYPE (LHS) for an enum bitfield.
    6032                 :            :    MODIFYCODE is the code for a binary operator that we use
    6033                 :            :    to combine the old value of LHS with RHS to get the new value.
    6034                 :            :    Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
    6035                 :            :    If RHS_ORIGTYPE is not NULL_TREE, it is the original type of RHS,
    6036                 :            :    which may differ from TREE_TYPE (RHS) for an enum value.
    6037                 :            : 
    6038                 :            :    LOCATION is the location of the MODIFYCODE operator.
    6039                 :            :    RHS_LOC is the location of the RHS.  */
    6040                 :            : 
    6041                 :            : tree
    6042                 :    2045300 : build_modify_expr (location_t location, tree lhs, tree lhs_origtype,
    6043                 :            :                    enum tree_code modifycode,
    6044                 :            :                    location_t rhs_loc, tree rhs, tree rhs_origtype)
    6045                 :            : {
    6046                 :    2045300 :   tree result;
    6047                 :    2045300 :   tree newrhs;
    6048                 :    2045300 :   tree rhseval = NULL_TREE;
    6049                 :    2045300 :   tree lhstype = TREE_TYPE (lhs);
    6050                 :    2045300 :   tree olhstype = lhstype;
    6051                 :    2045300 :   bool npc;
    6052                 :    2045300 :   bool is_atomic_op;
    6053                 :            : 
    6054                 :            :   /* Types that aren't fully specified cannot be used in assignments.  */
    6055                 :    2045300 :   lhs = require_complete_type (location, lhs);
    6056                 :            : 
    6057                 :            :   /* Avoid duplicate error messages from operands that had errors.  */
    6058                 :    2045300 :   if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK)
    6059                 :        396 :     return error_mark_node;
    6060                 :            : 
    6061                 :            :   /* Ensure an error for assigning a non-lvalue array to an array in
    6062                 :            :      C90.  */
    6063                 :    2044910 :   if (TREE_CODE (lhstype) == ARRAY_TYPE)
    6064                 :            :     {
    6065                 :          2 :       error_at (location, "assignment to expression with array type");
    6066                 :          2 :       return error_mark_node;
    6067                 :            :     }
    6068                 :            : 
    6069                 :            :   /* For ObjC properties, defer this check.  */
    6070                 :    4089810 :   if (!objc_is_property_ref (lhs) && !lvalue_or_else (location, lhs, lv_assign))
    6071                 :         31 :     return error_mark_node;
    6072                 :            : 
    6073                 :    2044870 :   is_atomic_op = really_atomic_lvalue (lhs);
    6074                 :            : 
    6075                 :    2044870 :   newrhs = rhs;
    6076                 :            : 
    6077                 :    2044870 :   if (TREE_CODE (lhs) == C_MAYBE_CONST_EXPR)
    6078                 :            :     {
    6079                 :          2 :       tree inner = build_modify_expr (location, C_MAYBE_CONST_EXPR_EXPR (lhs),
    6080                 :            :                                       lhs_origtype, modifycode, rhs_loc, rhs,
    6081                 :            :                                       rhs_origtype);
    6082                 :          2 :       if (inner == error_mark_node)
    6083                 :            :         return error_mark_node;
    6084                 :          4 :       result = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (inner),
    6085                 :          2 :                        C_MAYBE_CONST_EXPR_PRE (lhs), inner);
    6086                 :          2 :       gcc_assert (!C_MAYBE_CONST_EXPR_INT_OPERANDS (lhs));
    6087                 :          2 :       C_MAYBE_CONST_EXPR_NON_CONST (result) = 1;
    6088                 :          2 :       protected_set_expr_location (result, location);
    6089                 :          2 :       return result;
    6090                 :            :     }
    6091                 :            : 
    6092                 :            :   /* If a binary op has been requested, combine the old LHS value with the RHS
    6093                 :            :      producing the value we should actually store into the LHS.  */
    6094                 :            : 
    6095                 :    2044870 :   if (modifycode != NOP_EXPR)
    6096                 :            :     {
    6097                 :     131966 :       lhs = c_fully_fold (lhs, false, NULL, true);
    6098                 :     131966 :       lhs = stabilize_reference (lhs);
    6099                 :            : 
    6100                 :            :       /* Construct the RHS for any non-atomic compound assignemnt. */
    6101                 :     131966 :       if (!is_atomic_op)
    6102                 :            :         {
    6103                 :            :           /* If in LHS op= RHS the RHS has side-effects, ensure they
    6104                 :            :              are preevaluated before the rest of the assignment expression's
    6105                 :            :              side-effects, because RHS could contain e.g. function calls
    6106                 :            :              that modify LHS.  */
    6107                 :     116520 :           if (TREE_SIDE_EFFECTS (rhs))
    6108                 :            :             {
    6109                 :       4996 :               if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
    6110                 :          0 :                 newrhs = save_expr (TREE_OPERAND (rhs, 0));
    6111                 :            :               else
    6112                 :       4996 :                 newrhs = save_expr (rhs);
    6113                 :       4996 :               rhseval = newrhs;
    6114                 :       4996 :               if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
    6115                 :          0 :                 newrhs = build1 (EXCESS_PRECISION_EXPR, TREE_TYPE (rhs),
    6116                 :            :                                  newrhs);
    6117                 :            :             }
    6118                 :     116520 :           newrhs = build_binary_op (location,
    6119                 :            :                                     modifycode, lhs, newrhs, true);
    6120                 :            : 
    6121                 :            :           /* The original type of the right hand side is no longer
    6122                 :            :              meaningful.  */
    6123                 :     116520 :           rhs_origtype = NULL_TREE;
    6124                 :            :         }
    6125                 :            :     }
    6126                 :            : 
    6127                 :    2044870 :   if (c_dialect_objc ())
    6128                 :            :     {
    6129                 :            :       /* Check if we are modifying an Objective-C property reference;
    6130                 :            :          if so, we need to generate setter calls.  */
    6131                 :          0 :       if (TREE_CODE (newrhs) == EXCESS_PRECISION_EXPR)
    6132                 :          0 :         result = objc_maybe_build_modify_expr (lhs, TREE_OPERAND (newrhs, 0));
    6133                 :            :       else
    6134                 :          0 :         result = objc_maybe_build_modify_expr (lhs, newrhs);
    6135                 :          0 :       if (result)
    6136                 :          0 :         goto return_result;
    6137                 :            : 
    6138                 :            :       /* Else, do the check that we postponed for Objective-C.  */
    6139                 :          0 :       if (!lvalue_or_else (location, lhs, lv_assign))
    6140                 :          0 :         return error_mark_node;
    6141                 :            :     }
    6142                 :            : 
    6143                 :            :   /* Give an error for storing in something that is 'const'.  */
    6144                 :            : 
    6145                 :    2044870 :   if (TYPE_READONLY (lhstype)
    6146                 :    2044790 :       || (RECORD_OR_UNION_TYPE_P (lhstype)
    6147                 :    2062100 :           && C_TYPE_FIELDS_READONLY (lhstype)))
    6148                 :            :     {
    6149                 :         79 :       readonly_error (location, lhs, lv_assign);
    6150                 :         79 :       return error_mark_node;
    6151                 :            :     }
    6152                 :    2044790 :   else if (TREE_READONLY (lhs))
    6153                 :          2 :     readonly_warning (lhs, lv_assign);
    6154                 :            : 
    6155                 :            :   /* If storing into a structure or union member,
    6156                 :            :      it has probably been given type `int'.
    6157                 :            :      Compute the type that would go with
    6158                 :            :      the actual amount of storage the member occupies.  */
    6159                 :            : 
    6160                 :    2044790 :   if (TREE_CODE (lhs) == COMPONENT_REF
    6161                 :     201778 :       && (TREE_CODE (lhstype) == INTEGER_TYPE
    6162                 :            :           || TREE_CODE (lhstype) == BOOLEAN_TYPE
    6163                 :            :           || TREE_CODE (lhstype) == REAL_TYPE
    6164                 :     201778 :           || TREE_CODE (lhstype) == ENUMERAL_TYPE))
    6165                 :     143037 :     lhstype = TREE_TYPE (get_unwidened (lhs, 0));
    6166                 :            : 
    6167                 :            :   /* If storing in a field that is in actuality a short or narrower than one,
    6168                 :            :      we must store in the field in its actual type.  */
    6169                 :            : 
    6170                 :    2044790 :   if (lhstype != TREE_TYPE (lhs))
    6171                 :            :     {
    6172                 :          0 :       lhs = copy_node (lhs);
    6173                 :          0 :       TREE_TYPE (lhs) = lhstype;
    6174                 :            :     }
    6175                 :            : 
    6176                 :            :   /* Issue -Wc++-compat warnings about an assignment to an enum type
    6177                 :            :      when LHS does not have its original type.  This happens for,
    6178                 :            :      e.g., an enum bitfield in a struct.  */
    6179                 :    2044790 :   if (warn_cxx_compat
    6180                 :       1840 :       && lhs_origtype != NULL_TREE
    6181                 :       1840 :       && lhs_origtype != lhstype
    6182                 :          7 :       && TREE_CODE (lhs_origtype) == ENUMERAL_TYPE)
    6183                 :            :     {
    6184                 :          4 :       tree checktype = (rhs_origtype != NULL_TREE
    6185                 :          4 :                         ? rhs_origtype
    6186                 :          0 :                         : TREE_TYPE (rhs));
    6187                 :          4 :       if (checktype != error_mark_node
    6188                 :          8 :           && (TYPE_MAIN_VARIANT (checktype) != TYPE_MAIN_VARIANT (lhs_origtype)
    6189                 :          2 :               || (is_atomic_op && modifycode != NOP_EXPR)))
    6190                 :          2 :         warning_at (location, OPT_Wc___compat,
    6191                 :            :                     "enum conversion in assignment is invalid in C++");
    6192                 :            :     }
    6193                 :            : 
    6194                 :            :   /* If the lhs is atomic, remove that qualifier.  */
    6195                 :    2044790 :   if (is_atomic_op)
    6196                 :            :     {
    6197                 :      25632 :       lhstype = build_qualified_type (lhstype, 
    6198                 :      25632 :                                       (TYPE_QUALS (lhstype)
    6199                 :            :                                        & ~TYPE_QUAL_ATOMIC));
    6200                 :      25632 :       olhstype = build_qualified_type (olhstype, 
    6201                 :      25632 :                                        (TYPE_QUALS (lhstype)
    6202                 :            :                                         & ~TYPE_QUAL_ATOMIC));
    6203                 :            :     }
    6204                 :            : 
    6205                 :            :   /* Convert new value to destination type.  Fold it first, then
    6206                 :            :      restore any excess precision information, for the sake of
    6207                 :            :      conversion warnings.  */
    6208                 :            : 
    6209                 :    2044790 :   if (!(is_atomic_op && modifycode != NOP_EXPR))
    6210                 :            :     {
    6211                 :    2029350 :       tree rhs_semantic_type = NULL_TREE;
    6212                 :    2029350 :       if (TREE_CODE (newrhs) == EXCESS_PRECISION_EXPR)
    6213                 :            :         {
    6214                 :         17 :           rhs_semantic_type = TREE_TYPE (newrhs);
    6215                 :         17 :           newrhs = TREE_OPERAND (newrhs, 0);
    6216                 :            :         }
    6217                 :    2029350 :       npc = null_pointer_constant_p (newrhs);
    6218                 :    2029350 :       newrhs = c_fully_fold (newrhs, false, NULL);
    6219                 :    2029350 :       if (rhs_semantic_type)
    6220                 :         17 :         newrhs = build1 (EXCESS_PRECISION_EXPR, rhs_semantic_type, newrhs);
    6221                 :    2029350 :       newrhs = convert_for_assignment (location, rhs_loc, lhstype, newrhs,
    6222                 :            :                                        rhs_origtype, ic_assign, npc,
    6223                 :            :                                        NULL_TREE, NULL_TREE, 0);
    6224                 :    2029350 :       if (TREE_CODE (newrhs) == ERROR_MARK)
    6225                 :        113 :         return error_mark_node;
    6226                 :            :     }
    6227                 :            : 
    6228                 :            :   /* Emit ObjC write barrier, if necessary.  */
    6229                 :    2044680 :   if (c_dialect_objc () && flag_objc_gc)
    6230                 :            :     {
    6231                 :          0 :       result = objc_generate_write_barrier (lhs, modifycode, newrhs);
    6232                 :          0 :       if (result)
    6233                 :            :         {
    6234                 :          0 :           protected_set_expr_location (result, location);
    6235                 :          0 :           goto return_result;
    6236                 :            :         }
    6237                 :            :     }
    6238                 :            : 
    6239                 :            :   /* Scan operands.  */
    6240                 :            : 
    6241                 :    2044680 :   if (is_atomic_op)
    6242                 :      25630 :     result = build_atomic_assign (location, lhs, modifycode, newrhs, false);
    6243                 :            :   else
    6244                 :            :     {
    6245                 :    2019050 :       result = build2 (MODIFY_EXPR, lhstype, lhs, newrhs);
    6246                 :    2019050 :       TREE_SIDE_EFFECTS (result) = 1;
    6247                 :    2019050 :       protected_set_expr_location (result, location);
    6248                 :            :     }
    6249                 :            : 
    6250                 :            :   /* If we got the LHS in a different type for storing in,
    6251                 :            :      convert the result back to the nominal type of LHS
    6252                 :            :      so that the value we return always has the same type
    6253                 :            :      as the LHS argument.  */
    6254                 :            : 
    6255                 :    2044680 :   if (olhstype == TREE_TYPE (result))
    6256                 :    2025070 :     goto return_result;
    6257                 :            : 
    6258                 :      19607 :   result = convert_for_assignment (location, rhs_loc, olhstype, result,
    6259                 :            :                                    rhs_origtype, ic_assign, false, NULL_TREE,
    6260                 :            :                                    NULL_TREE, 0);
    6261                 :      19607 :   protected_set_expr_location (result, location);
    6262                 :            : 
    6263                 :    2044680 : return_result:
    6264                 :    2044680 :   if (rhseval)
    6265                 :       4996 :     result = build2 (COMPOUND_EXPR, TREE_TYPE (result), rhseval, result);
    6266                 :            :   return result;
    6267                 :            : }
    6268                 :            : 
    6269                 :            : /* Return whether STRUCT_TYPE has an anonymous field with type TYPE.
    6270                 :            :    This is used to implement -fplan9-extensions.  */
    6271                 :            : 
    6272                 :            : static bool
    6273                 :          9 : find_anonymous_field_with_type (tree struct_type, tree type)
    6274                 :            : {
    6275                 :          9 :   tree field;
    6276                 :          9 :   bool found;
    6277                 :            : 
    6278                 :          9 :   gcc_assert (RECORD_OR_UNION_TYPE_P (struct_type));
    6279                 :          9 :   found = false;
    6280                 :         18 :   for (field = TYPE_FIELDS (struct_type);
    6281                 :         18 :        field != NULL_TREE;
    6282                 :          9 :        field = TREE_CHAIN (field))
    6283                 :            :     {
    6284                 :          9 :       tree fieldtype = (TYPE_ATOMIC (TREE_TYPE (field))
    6285                 :          9 :                         ? c_build_qualified_type (TREE_TYPE (field),
    6286                 :            :                                                   TYPE_QUAL_ATOMIC)
    6287                 :          9 :                         : TYPE_MAIN_VARIANT (TREE_TYPE (field)));
    6288                 :          9 :       if (DECL_NAME (field) == NULL
    6289                 :          9 :           && comptypes (type, fieldtype))
    6290                 :            :         {
    6291                 :          3 :           if (found)
    6292                 :            :             return false;
    6293                 :            :           found = true;
    6294                 :            :         }
    6295                 :          6 :       else if (DECL_NAME (field) == NULL
    6296                 :          2 :                && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field))
    6297                 :          8 :                && find_anonymous_field_with_type (TREE_TYPE (field), type))
    6298                 :            :         {
    6299                 :          0 :           if (found)
    6300                 :            :             return false;
    6301                 :            :           found = true;
    6302                 :            :         }
    6303                 :            :     }
    6304                 :            :   return found;
    6305                 :            : }
    6306                 :            : 
    6307                 :            : /* RHS is an expression whose type is pointer to struct.  If there is
    6308                 :            :    an anonymous field in RHS with type TYPE, then return a pointer to
    6309                 :            :    that field in RHS.  This is used with -fplan9-extensions.  This
    6310                 :            :    returns NULL if no conversion could be found.  */
    6311                 :            : 
    6312                 :            : static tree
    6313                 :         10 : convert_to_anonymous_field (location_t location, tree type, tree rhs)
    6314                 :            : {
    6315                 :         10 :   tree rhs_struct_type, lhs_main_type;
    6316                 :         10 :   tree field, found_field;
    6317                 :         10 :   bool found_sub_field;
    6318                 :         10 :   tree ret;
    6319                 :            : 
    6320                 :         10 :   gcc_assert (POINTER_TYPE_P (TREE_TYPE (rhs)));
    6321                 :         10 :   rhs_struct_type = TREE_TYPE (TREE_TYPE (rhs));
    6322                 :         10 :   gcc_assert (RECORD_OR_UNION_TYPE_P (rhs_struct_type));
    6323                 :            : 
    6324                 :         10 :   gcc_assert (POINTER_TYPE_P (type));
    6325                 :         10 :   lhs_main_type = (TYPE_ATOMIC (TREE_TYPE (type))
    6326                 :         10 :                    ? c_build_qualified_type (TREE_TYPE (type),
    6327                 :            :                                              TYPE_QUAL_ATOMIC)
    6328                 :         10 :                    : TYPE_MAIN_VARIANT (TREE_TYPE (type)));
    6329                 :            : 
    6330                 :         10 :   found_field = NULL_TREE;
    6331                 :         10 :   found_sub_field = false;
    6332                 :         42 :   for (field = TYPE_FIELDS (rhs_struct_type);
    6333                 :         40 :        field != NULL_TREE;
    6334                 :         30 :        field = TREE_CHAIN (field))
    6335                 :            :     {
    6336                 :         32 :       if (DECL_NAME (field) != NULL_TREE
    6337                 :         48 :           || !RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)))
    6338                 :         16 :         continue;
    6339                 :         16 :       tree fieldtype = (TYPE_ATOMIC (TREE_TYPE (field))
    6340                 :         16 :                         ? c_build_qualified_type (TREE_TYPE (field),
    6341                 :            :                                                   TYPE_QUAL_ATOMIC)
    6342                 :         16 :                         : TYPE_MAIN_VARIANT (TREE_TYPE (field)));
    6343                 :         16 :       if (comptypes (lhs_main_type, fieldtype))
    6344                 :            :         {
    6345                 :          9 :           if (found_field != NULL_TREE)
    6346                 :            :             return NULL_TREE;
    6347                 :            :           found_field = field;
    6348                 :            :         }
    6349                 :          7 :       else if (find_anonymous_field_with_type (TREE_TYPE (field),
    6350                 :            :                                                lhs_main_type))
    6351                 :            :         {
    6352                 :          3 :           if (found_field != NULL_TREE)
    6353                 :            :             return NULL_TREE;
    6354                 :            :           found_field = field;
    6355                 :            :           found_sub_field = true;
    6356                 :            :         }
    6357                 :            :     }
    6358                 :            : 
    6359                 :          8 :   if (found_field == NULL_TREE)
    6360                 :            :     return NULL_TREE;
    6361                 :            : 
    6362                 :          8 :   ret = fold_build3_loc (location, COMPONENT_REF, TREE_TYPE (found_field),
    6363                 :            :                          build_fold_indirect_ref (rhs), found_field,
    6364                 :            :                          NULL_TREE);
    6365                 :          8 :   ret = build_fold_addr_expr_loc (location, ret);
    6366                 :            : 
    6367                 :          8 :   if (found_sub_field)
    6368                 :            :     {
    6369                 :          2 :       ret = convert_to_anonymous_field (location, type, ret);
    6370                 :          2 :       gcc_assert (ret != NULL_TREE);
    6371                 :            :     }
    6372                 :            : 
    6373                 :            :   return ret;
    6374                 :            : }
    6375                 :            : 
    6376                 :            : /* Issue an error message for a bad initializer component.
    6377                 :            :    GMSGID identifies the message.
    6378                 :            :    The component name is taken from the spelling stack.  */
    6379                 :            : 
    6380                 :            : static void ATTRIBUTE_GCC_DIAG (2,0)
    6381                 :       1278 : error_init (location_t loc, const char *gmsgid, ...)
    6382                 :            : {
    6383                 :       1278 :   char *ofwhat;
    6384                 :            : 
    6385                 :       2556 :   auto_diagnostic_group d;
    6386                 :            : 
    6387                 :            :   /* The gmsgid may be a format string with %< and %>. */
    6388                 :       1278 :   va_list ap;
    6389                 :       1278 :   va_start (ap, gmsgid);
    6390                 :       1278 :   bool warned = emit_diagnostic_valist (DK_ERROR, loc, -1, gmsgid, &ap);
    6391                 :       1278 :   va_end (ap);
    6392                 :            : 
    6393                 :       1278 :   ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
    6394                 :       1278 :   if (*ofwhat && warned)
    6395                 :        197 :     inform (loc, "(near initialization for %qs)", ofwhat);
    6396                 :       1278 : }
    6397                 :            : 
    6398                 :            : /* Issue a pedantic warning for a bad initializer component.  OPT is
    6399                 :            :    the option OPT_* (from options.h) controlling this warning or 0 if
    6400                 :            :    it is unconditionally given.  GMSGID identifies the message.  The
    6401                 :            :    component name is taken from the spelling stack.  */
    6402                 :            : 
    6403                 :            : static void ATTRIBUTE_GCC_DIAG (3,0)
    6404                 :       1139 : pedwarn_init (location_t loc, int opt, const char *gmsgid, ...)
    6405                 :            : {
    6406                 :            :   /* Use the location where a macro was expanded rather than where
    6407                 :            :      it was defined to make sure macros defined in system headers
    6408                 :            :      but used incorrectly elsewhere are diagnosed.  */
    6409                 :       1139 :   location_t exploc = expansion_point_location_if_in_system_header (loc);
    6410                 :       2278 :   auto_diagnostic_group d;
    6411                 :       1139 :   va_list ap;
    6412                 :       1139 :   va_start (ap, gmsgid);
    6413                 :       1139 :   bool warned = emit_diagnostic_valist (DK_PEDWARN, exploc, opt, gmsgid, &ap);
    6414                 :       1139 :   va_end (ap);
    6415                 :       1139 :   char *ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
    6416                 :       1139 :   if (*ofwhat && warned)
    6417                 :        251 :     inform (exploc, "(near initialization for %qs)", ofwhat);
    6418                 :       1139 : }
    6419                 :            : 
    6420                 :            : /* Issue a warning for a bad initializer component.
    6421                 :            : 
    6422                 :            :    OPT is the OPT_W* value corresponding to the warning option that
    6423                 :            :    controls this warning.  GMSGID identifies the message.  The
    6424                 :            :    component name is taken from the spelling stack.  */
    6425                 :            : 
    6426                 :            : static void
    6427                 :        102 : warning_init (location_t loc, int opt, const char *gmsgid)
    6428                 :            : {
    6429                 :        102 :   char *ofwhat;
    6430                 :        102 :   bool warned;
    6431                 :            : 
    6432                 :        204 :   auto_diagnostic_group d;
    6433                 :            : 
    6434                 :            :   /* Use the location where a macro was expanded rather than where
    6435                 :            :      it was defined to make sure macros defined in system headers
    6436                 :            :      but used incorrectly elsewhere are diagnosed.  */
    6437                 :        102 :   location_t exploc = expansion_point_location_if_in_system_header (loc);
    6438                 :            : 
    6439                 :            :   /* The gmsgid may be a format string with %< and %>. */
    6440                 :        102 :   warned = warning_at (exploc, opt, gmsgid);
    6441                 :        102 :   ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
    6442                 :        102 :   if (*ofwhat && warned)
    6443                 :         80 :     inform (exploc, "(near initialization for %qs)", ofwhat);
    6444                 :        102 : }
    6445                 :            : 
    6446                 :            : /* If TYPE is an array type and EXPR is a parenthesized string
    6447                 :            :    constant, warn if pedantic that EXPR is being used to initialize an
    6448                 :            :    object of type TYPE.  */
    6449                 :            : 
    6450                 :            : void
    6451                 :    2580080 : maybe_warn_string_init (location_t loc, tree type, struct c_expr expr)
    6452                 :            : {
    6453                 :    2580080 :   if (pedantic
    6454                 :      59015 :       && TREE_CODE (type) == ARRAY_TYPE
    6455                 :        458 :       && TREE_CODE (expr.value) == STRING_CST
    6456                 :        256 :       && expr.original_code != STRING_CST)
    6457                 :         13 :     pedwarn_init (loc, OPT_Wpedantic,
    6458                 :            :                   "array initialized from parenthesized string constant");
    6459                 :    2580080 : }
    6460                 :            : 
    6461                 :            : /* Attempt to locate the parameter with the given index within FNDECL,
    6462                 :            :    returning DECL_SOURCE_LOCATION (FNDECL) if it can't be found.  */
    6463                 :            : 
    6464                 :            : static location_t
    6465                 :        828 : get_fndecl_argument_location (tree fndecl, int argnum)
    6466                 :            : {
    6467                 :        828 :   int i;
    6468                 :        828 :   tree param;
    6469                 :            : 
    6470                 :            :   /* Locate param by index within DECL_ARGUMENTS (fndecl).  */
    6471                 :        880 :   for (i = 0, param = DECL_ARGUMENTS (fndecl);
    6472                 :        880 :        i < argnum && param;
    6473                 :         52 :        i++, param = TREE_CHAIN (param))
    6474                 :            :     ;
    6475                 :            : 
    6476                 :            :   /* If something went wrong (e.g. if we have a builtin and thus no arguments),
    6477                 :            :      return DECL_SOURCE_LOCATION (FNDECL).  */
    6478                 :        828 :   if (param == NULL)
    6479                 :        653 :     return DECL_SOURCE_LOCATION (fndecl);
    6480                 :            : 
    6481                 :        175 :   return DECL_SOURCE_LOCATION (param);
    6482                 :            : }
    6483                 :            : 
    6484                 :            : /* Issue a note about a mismatching argument for parameter PARMNUM
    6485                 :            :    to FUNDECL, for types EXPECTED_TYPE and ACTUAL_TYPE.
    6486                 :            :    Attempt to issue the note at the pertinent parameter of the decl;
    6487                 :            :    failing that issue it at the location of FUNDECL; failing that
    6488                 :            :    issue it at PLOC.  */
    6489                 :            : 
    6490                 :            : static void
    6491                 :        941 : inform_for_arg (tree fundecl, location_t ploc, int parmnum,
    6492                 :            :                 tree expected_type, tree actual_type)
    6493                 :            : {
    6494                 :        941 :   location_t loc;
    6495                 :       1850 :   if (fundecl && !DECL_IS_BUILTIN (fundecl))
    6496                 :        828 :     loc = get_fndecl_argument_location (fundecl, parmnum - 1);
    6497                 :            :   else
    6498                 :            :     loc = ploc;
    6499                 :            : 
    6500                 :        941 :   inform (loc,
    6501                 :            :           "expected %qT but argument is of type %qT",
    6502                 :            :           expected_type, actual_type);
    6503                 :        941 : }
    6504                 :            : 
    6505                 :            : /* Issue a warning when an argument of ARGTYPE is passed to a built-in
    6506                 :            :    function FUNDECL declared without prototype to parameter PARMNUM of
    6507                 :            :    PARMTYPE when ARGTYPE does not promote to PARMTYPE.  */
    6508                 :            : 
    6509                 :            : static void
    6510                 :        431 : maybe_warn_builtin_no_proto_arg (location_t loc, tree fundecl, int parmnum,
    6511                 :            :                                  tree parmtype, tree argtype)
    6512                 :            : {
    6513                 :        431 :   tree_code parmcode = TREE_CODE (parmtype);
    6514                 :        431 :   tree_code argcode = TREE_CODE (argtype);
    6515                 :        431 :   tree promoted = c_type_promotes_to (argtype);
    6516                 :            : 
    6517                 :            :   /* Avoid warning for enum arguments that promote to an integer type
    6518                 :            :      of the same size/mode.  */
    6519                 :        431 :   if (parmcode == INTEGER_TYPE
    6520                 :        431 :       && argcode == ENUMERAL_TYPE
    6521                 :        435 :       && TYPE_MODE (parmtype) == TYPE_MODE (argtype))
    6522                 :            :     return;
    6523                 :            : 
    6524                 :        430 :   if ((parmcode == argcode
    6525                 :        220 :        || (parmcode == INTEGER_TYPE
    6526                 :            :            && argcode == ENUMERAL_TYPE))
    6527                 :        641 :       && TYPE_MAIN_VARIANT (parmtype) == TYPE_MAIN_VARIANT (promoted))
    6528                 :            :     return;
    6529                 :            : 
    6530                 :            :   /* This diagnoses even signed/unsigned mismatches.  Those might be
    6531                 :            :      safe in many cases but GCC may emit suboptimal code for them so
    6532                 :            :      warning on those cases drives efficiency improvements.  */
    6533                 :        830 :   if (warning_at (loc, OPT_Wbuiltin_declaration_mismatch,
    6534                 :        415 :                   TYPE_MAIN_VARIANT (promoted) == argtype
    6535                 :            :                   ? G_("%qD argument %d type is %qT where %qT is expected "
    6536                 :            :                        "in a call to built-in function declared without "
    6537                 :            :                        "prototype")
    6538                 :            :                   : G_("%qD argument %d promotes to %qT where %qT is expected "
    6539                 :            :                        "in a call to built-in function declared without "
    6540                 :            :                        "prototype"),
    6541                 :            :                   fundecl, parmnum, promoted, parmtype))
    6542                 :        150 :     inform (DECL_SOURCE_LOCATION (fundecl),
    6543                 :            :             "built-in %qD declared here",
    6544                 :            :             fundecl);
    6545                 :            : }
    6546                 :            : 
    6547                 :            : /* Convert value RHS to type TYPE as preparation for an assignment to
    6548                 :            :    an lvalue of type TYPE.  If ORIGTYPE is not NULL_TREE, it is the
    6549                 :            :    original type of RHS; this differs from TREE_TYPE (RHS) for enum
    6550                 :            :    types.  NULL_POINTER_CONSTANT says whether RHS was a null pointer
    6551                 :            :    constant before any folding.
    6552                 :            :    The real work of conversion is done by `convert'.
    6553                 :            :    The purpose of this function is to generate error messages
    6554                 :            :    for assignments that are not allowed in C.
    6555                 :            :    ERRTYPE says whether it is argument passing, assignment,
    6556                 :            :    initialization or return.
    6557                 :            : 
    6558                 :            :    In the following example, '~' denotes where EXPR_LOC and '^' where
    6559                 :            :    LOCATION point to:
    6560                 :            : 
    6561                 :            :      f (var);      [ic_argpass]
    6562                 :            :      ^  ~~~
    6563                 :            :      x = var;      [ic_assign]
    6564                 :            :        ^ ~~~;
    6565                 :            :      int x = var;  [ic_init]
    6566                 :            :              ^^^
    6567                 :            :      return x;     [ic_return]
    6568                 :            :             ^
    6569                 :            : 
    6570                 :            :    FUNCTION is a tree for the function being called.
    6571                 :            :    PARMNUM is the number of the argument, for printing in error messages.
    6572                 :            :    WARNOPT may be set to a warning option to issue the corresponding warning
    6573                 :            :    rather than an error for invalid conversions.  Used for calls to built-in
    6574                 :            :    functions declared without a prototype.  */
    6575                 :            : 
    6576                 :            : static tree
    6577                 :   92144000 : convert_for_assignment (location_t location, location_t expr_loc, tree type,
    6578                 :            :                         tree rhs, tree origtype, enum impl_conv errtype,
    6579                 :            :                         bool null_pointer_constant, tree fundecl,
    6580                 :            :                         tree function, int parmnum, int warnopt /* = 0 */)
    6581                 :            : {
    6582                 :   92144000 :   enum tree_code codel = TREE_CODE (type);
    6583                 :   92144000 :   tree orig_rhs = rhs;
    6584                 :   92144000 :   tree rhstype;
    6585                 :   92144000 :   enum tree_code coder;
    6586                 :   92144000 :   tree rname = NULL_TREE;
    6587                 :   92144000 :   bool objc_ok = false;
    6588                 :            : 
    6589                 :            :   /* Use the expansion point location to handle cases such as user's
    6590                 :            :      function returning a wrong-type macro defined in a system header.  */
    6591                 :   92144000 :   location = expansion_point_location_if_in_system_header (location);
    6592                 :            : 
    6593                 :   92144000 :   if (errtype == ic_argpass)
    6594                 :            :     {
    6595                 :   68807200 :       tree selector;
    6596                 :            :       /* Change pointer to function to the function itself for
    6597                 :            :          diagnostics.  */
    6598                 :   68807200 :       if (TREE_CODE (function) == ADDR_EXPR
    6599                 :   68807200 :           && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL)
    6600                 :          0 :         function = TREE_OPERAND (function, 0);
    6601                 :            : 
    6602                 :            :       /* Handle an ObjC selector specially for diagnostics.  */
    6603                 :   68807200 :       selector = objc_message_selector ();
    6604                 :   68807200 :       rname = function;
    6605                 :   68807200 :       if (selector && parmnum > 2)
    6606                 :            :         {
    6607                 :          0 :           rname = selector;
    6608                 :          0 :           parmnum -= 2;
    6609                 :            :         }
    6610                 :            :     }
    6611                 :            : 
    6612                 :            :   /* This macro is used to emit diagnostics to ensure that all format
    6613                 :            :      strings are complete sentences, visible to gettext and checked at
    6614                 :            :      compile time.  */
    6615                 :            : #define PEDWARN_FOR_ASSIGNMENT(LOCATION, PLOC, OPT, AR, AS, IN, RE)      \
    6616                 :            :   do {                                                                   \
    6617                 :            :     switch (errtype)                                                     \
    6618                 :            :       {                                                                  \
    6619                 :            :       case ic_argpass:                                                   \
    6620                 :            :         {                                                               \
    6621                 :            :           auto_diagnostic_group d;                                              \
    6622                 :            :           if (pedwarn (PLOC, OPT, AR, parmnum, rname))          \
    6623                 :            :             inform_for_arg (fundecl, (PLOC), parmnum, type, rhstype); \
    6624                 :            :         }                                                               \
    6625                 :            :         break;                                                           \
    6626                 :            :       case ic_assign:                                                    \
    6627                 :            :         pedwarn (LOCATION, OPT, AS);                                     \
    6628                 :            :         break;                                                           \
    6629                 :            :       case ic_init:                                                      \
    6630                 :            :         pedwarn_init (LOCATION, OPT, IN);                                \
    6631                 :            :         break;                                                           \
    6632                 :            :       case ic_return:                                                    \
    6633                 :            :         pedwarn (LOCATION, OPT, RE);                                     \
    6634                 :            :         break;                                                           \
    6635                 :            :       default:                                                           \
    6636                 :            :         gcc_unreachable ();                                              \
    6637                 :            :       }                                                                  \
    6638                 :            :   } while (0)
    6639                 :            : 
    6640                 :            :   /* This macro is used to emit diagnostics to ensure that all format
    6641                 :            :      strings are complete sentences, visible to gettext and checked at
    6642                 :            :      compile time.  It is the same as PEDWARN_FOR_ASSIGNMENT but with an
    6643                 :            :      extra parameter to enumerate qualifiers.  */
    6644                 :            : #define PEDWARN_FOR_QUALIFIERS(LOCATION, PLOC, OPT, AR, AS, IN, RE, QUALS) \
    6645                 :            :   do {                                                                   \
    6646                 :            :     switch (errtype)                                                     \
    6647                 :            :       {                                                                  \
    6648                 :            :       case ic_argpass:                                                   \
    6649                 :            :         {                                                               \
    6650                 :            :         auto_diagnostic_group d;                                                \
    6651                 :            :         if (pedwarn (PLOC, OPT, AR, parmnum, rname, QUALS))             \
    6652                 :            :           inform_for_arg (fundecl, (PLOC), parmnum, type, rhstype);     \
    6653                 :            :         }                                                               \
    6654                 :            :         break;                                                           \
    6655                 :            :       case ic_assign:                                                    \
    6656                 :            :         pedwarn (LOCATION, OPT, AS, QUALS);                              \
    6657                 :            :         break;                                                           \
    6658                 :            :       case ic_init:                                                      \
    6659                 :            :         pedwarn (LOCATION, OPT, IN, QUALS);                              \
    6660                 :            :         break;                                                           \
    6661                 :            :       case ic_return:                                                    \
    6662                 :            :         pedwarn (LOCATION, OPT, RE, QUALS);                              \
    6663                 :            :         break;                                                           \
    6664                 :            :       default:                                                           \
    6665                 :            :         gcc_unreachable ();                                              \
    6666                 :            :       }                                                                  \
    6667                 :            :   } while (0)
    6668                 :            : 
    6669                 :            :   /* This macro is used to emit diagnostics to ensure that all format
    6670                 :            :      strings are complete sentences, visible to gettext and checked at
    6671                 :            :      compile time.  It is the same as PEDWARN_FOR_QUALIFIERS but uses
    6672                 :            :      warning_at instead of pedwarn.  */
    6673                 :            : #define WARNING_FOR_QUALIFIERS(LOCATION, PLOC, OPT, AR, AS, IN, RE, QUALS) \
    6674                 :            :   do {                                                                   \
    6675                 :            :     switch (errtype)                                                     \
    6676                 :            :       {                                                                  \
    6677                 :            :       case ic_argpass:                                                   \
    6678                 :            :         {                                                               \
    6679                 :            :           auto_diagnostic_group d;                                              \
    6680                 :            :           if (warning_at (PLOC, OPT, AR, parmnum, rname, QUALS))        \
    6681                 :            :             inform_for_arg (fundecl, (PLOC), parmnum, type, rhstype); \
    6682                 :            :         }                                                               \
    6683                 :            :         break;                                                           \
    6684                 :            :       case ic_assign:                                                    \
    6685                 :            :         warning_at (LOCATION, OPT, AS, QUALS);                           \
    6686                 :            :         break;                                                           \
    6687                 :            :       case ic_init:                                                      \
    6688                 :            :         warning_at (LOCATION, OPT, IN, QUALS);                           \
    6689                 :            :         break;                                                           \
    6690                 :            :       case ic_return:                                                    \
    6691                 :            :         warning_at (LOCATION, OPT, RE, QUALS);                           \
    6692                 :            :         break;                                                           \
    6693                 :            :       default:                                                           \
    6694                 :            :         gcc_unreachable ();                                              \
    6695                 :            :       }                                                                  \
    6696                 :            :   } while (0)
    6697                 :            : 
    6698                 :   92144000 :   if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
    6699                 :         65 :     rhs = TREE_OPERAND (rhs, 0);
    6700                 :            : 
    6701                 :   92144000 :   rhstype = TREE_TYPE (rhs);
    6702                 :   92144000 :   coder = TREE_CODE (rhstype);
    6703                 :            : 
    6704                 :   92144000 :   if (coder == ERROR_MARK)
    6705                 :        316 :     return error_mark_node;
    6706                 :            : 
    6707                 :   92143600 :   if (c_dialect_objc ())
    6708                 :            :     {
    6709                 :          0 :       int parmno;
    6710                 :            : 
    6711                 :          0 :       switch (errtype)
    6712                 :            :         {
    6713                 :            :         case ic_return:
    6714                 :            :           parmno = 0;
    6715                 :            :           break;
    6716                 :            : 
    6717                 :            :         case ic_assign:
    6718                 :            :           parmno = -1;
    6719                 :            :           break;
    6720                 :            : 
    6721                 :            :         case ic_init:
    6722                 :            :           parmno = -2;
    6723                 :            :           break;
    6724                 :            : 
    6725                 :            :         default:
    6726                 :          0 :           parmno = parmnum;
    6727                 :            :           break;
    6728                 :            :         }
    6729                 :            : 
    6730                 :          0 :       objc_ok = objc_compare_types (type, rhstype, parmno, rname);
    6731                 :            :     }
    6732                 :            : 
    6733                 :   92143600 :   if (warn_cxx_compat)
    6734                 :            :     {
    6735                 :      18485 :       tree checktype = origtype != NULL_TREE ? origtype : rhstype;
    6736                 :      18485 :       if (checktype != error_mark_node
    6737                 :      18485 :           && TREE_CODE (type) == ENUMERAL_TYPE
    6738                 :      18582 :           && TYPE_MAIN_VARIANT (checktype) != TYPE_MAIN_VARIANT (type))
    6739                 :         45 :         switch (errtype)
    6740                 :            :           {
    6741                 :          8 :           case ic_argpass:
    6742                 :          8 :             if (pedwarn (expr_loc, OPT_Wc___compat, "enum conversion when "
    6743                 :            :                          "passing argument %d of %qE is invalid in C++",
    6744                 :            :                          parmnum, rname))
    6745                 :         24 :               inform ((fundecl && !DECL_IS_BUILTIN (fundecl))
    6746                 :          8 :                       ? DECL_SOURCE_LOCATION (fundecl) : expr_loc,
    6747                 :            :                       "expected %qT but argument is of type %qT",
    6748                 :            :                       type, rhstype);
    6749                 :            :             break;
    6750                 :         10 :           case ic_assign:
    6751                 :         10 :             pedwarn (location, OPT_Wc___compat, "enum conversion from %qT to "
    6752                 :            :                      "%qT in assignment is invalid in C++", rhstype, type);
    6753                 :         10 :             break;
    6754                 :         18 :           case ic_init:
    6755                 :         18 :             pedwarn_init (location, OPT_Wc___compat, "enum conversion from "
    6756                 :            :                           "%qT to %qT in initialization is invalid in C++",
    6757                 :            :                           rhstype, type);
    6758                 :         18 :             break;
    6759                 :          9 :           case ic_return:
    6760                 :          9 :             pedwarn (location, OPT_Wc___compat, "enum conversion from %qT to "
    6761                 :            :                      "%qT in return is invalid in C++", rhstype, type);
    6762                 :          9 :             break;
    6763                 :          0 :           default:
    6764                 :          0 :             gcc_unreachable ();
    6765                 :            :           }
    6766                 :            :     }
    6767                 :            : 
    6768                 :   92143600 :   if (warn_enum_conversion)
    6769                 :            :     {
    6770                 :    3034730 :       tree checktype = origtype != NULL_TREE ? origtype : rhstype;
    6771                 :    3034730 :       if (checktype != error_mark_node
    6772                 :    3034730 :           && TREE_CODE (checktype) == ENUMERAL_TYPE
    6773                 :       6670 :           && TREE_CODE (type) == ENUMERAL_TYPE
    6774                 :    3039710 :           && TYPE_MAIN_VARIANT (checktype) != TYPE_MAIN_VARIANT (type))
    6775                 :            :        {
    6776                 :          6 :           gcc_rich_location loc (location);
    6777                 :          3 :           warning_at (&loc, OPT_Wenum_conversion,
    6778                 :            :                       "implicit conversion from %qT to %qT",
    6779                 :            :                       checktype, type);
    6780                 :            :        }
    6781                 :            :     }
    6782                 :            : 
    6783                 :   92143600 :   if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
    6784                 :            :     {
    6785                 :   86096700 :       warn_for_address_or_pointer_of_packed_member (type, orig_rhs);
    6786                 :   86096700 :       return rhs;
    6787                 :            :     }
    6788                 :            : 
    6789                 :    6046900 :   if (coder == VOID_TYPE)
    6790                 :            :     {
    6791                 :            :       /* Except for passing an argument to an unprototyped function,
    6792                 :            :          this is a constraint violation.  When passing an argument to
    6793                 :            :          an unprototyped function, it is compile-time undefined;
    6794                 :            :          making it a constraint in that case was rejected in
    6795                 :            :          DR#252.  */
    6796                 :         34 :       const char msg[] = "void value not ignored as it ought to be";
    6797                 :         34 :       if (warnopt)
    6798                 :          0 :         warning_at (location, warnopt, msg);
    6799                 :            :       else
    6800                 :         34 :         error_at (location, msg);
    6801                 :         34 :       return error_mark_node;
    6802                 :            :     }
    6803                 :    6046870 :   rhs = require_complete_type (location, rhs);
    6804                 :    6046870 :   if (rhs == error_mark_node)
    6805                 :            :     return error_mark_node;
    6806                 :            : 
    6807                 :    6046870 :   if (coder == POINTER_TYPE && reject_gcc_builtin (rhs))
    6808                 :          6 :     return error_mark_node;
    6809                 :            : 
    6810                 :            :   /* A non-reference type can convert to a reference.  This handles
    6811                 :            :      va_start, va_copy and possibly port built-ins.  */
    6812                 :    6046860 :   if (codel == REFERENCE_TYPE && coder != REFERENCE_TYPE)
    6813                 :            :     {
    6814                 :        206 :       if (!lvalue_p (rhs))
    6815                 :            :         {
    6816                 :          0 :           const char msg[] = "cannot pass rvalue to reference parameter";
    6817                 :          0 :           if (warnopt)
    6818                 :          0 :             warning_at (location, warnopt, msg);
    6819                 :            :           else
    6820                 :          0 :             error_at (location, msg);
    6821                 :          0 :           return error_mark_node;
    6822                 :            :         }
    6823                 :        206 :       if (!c_mark_addressable (rhs))
    6824                 :          0 :         return error_mark_node;
    6825                 :        206 :       rhs = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (rhs)), rhs);
    6826                 :        206 :       SET_EXPR_LOCATION (rhs, location);
    6827                 :            : 
    6828                 :        412 :       rhs = convert_for_assignment (location, expr_loc,
    6829                 :        206 :                                     build_pointer_type (TREE_TYPE (type)),
    6830                 :            :                                     rhs, origtype, errtype,
    6831                 :            :                                     null_pointer_constant, fundecl, function,
    6832                 :            :                                     parmnum, warnopt);
    6833                 :        206 :       if (rhs == error_mark_node)
    6834                 :            :         return error_mark_node;
    6835                 :            : 
    6836                 :        206 :       rhs = build1 (NOP_EXPR, type, rhs);
    6837                 :        206 :       SET_EXPR_LOCATION (rhs, location);
    6838                 :        206 :       return rhs;
    6839                 :            :     }
    6840                 :            :   /* Some types can interconvert without explicit casts.  */
    6841                 :    6046660 :   else if (codel == VECTOR_TYPE && coder == VECTOR_TYPE
    6842                 :    6573130 :            && vector_types_convertible_p (type, TREE_TYPE (rhs), true))
    6843                 :     526468 :     return convert (type, rhs);
    6844                 :            :   /* Arithmetic types all interconvert, and enum is treated like int.  */
    6845                 :    5520190 :   else if ((codel == INTEGER_TYPE || codel == REAL_TYPE
    6846                 :    5520190 :             || codel == FIXED_POINT_TYPE
    6847                 :    1506510 :             || codel == ENUMERAL_TYPE || codel == COMPLEX_TYPE
    6848                 :    1385740 :             || codel == BOOLEAN_TYPE)
    6849                 :    4163340 :            && (coder == INTEGER_TYPE || coder == REAL_TYPE
    6850                 :    4163340 :                || coder == FIXED_POINT_TYPE
    6851                 :      53858 :                || coder == ENUMERAL_TYPE || coder == COMPLEX_TYPE
    6852                 :       3291 :                || coder == BOOLEAN_TYPE))
    6853                 :            :     {
    6854                 :    4162220 :       if (warnopt && errtype == ic_argpass)
    6855                 :        431 :         maybe_warn_builtin_no_proto_arg (expr_loc, fundecl, parmnum, type,
    6856                 :            :                                          rhstype);
    6857                 :            : 
    6858                 :    4162220 :       bool save = in_late_binary_op;
    6859                 :    4162220 :       if (codel == BOOLEAN_TYPE || codel == COMPLEX_TYPE
    6860                 :    4162220 :           || (coder == REAL_TYPE
    6861                 :     166521 :               && (codel == INTEGER_TYPE || codel == ENUMERAL_TYPE)
    6862                 :      22515 :               && sanitize_flags_p (SANITIZE_FLOAT_CAST)))
    6863                 :      84454 :         in_late_binary_op = true;
    6864                 :    5577400 :       tree ret = convert_and_check (expr_loc != UNKNOWN_LOCATION
    6865                 :            :                                     ? expr_loc : location, type, orig_rhs);
    6866                 :    4162220 :       in_late_binary_op = save;
    6867                 :    4162220 :       return ret;
    6868                 :            :     }
    6869                 :            : 
    6870                 :            :   /* Aggregates in different TUs might need conversion.  */
    6871                 :    1357970 :   if ((codel == RECORD_TYPE || codel == UNION_TYPE)
    6872                 :         68 :       && codel == coder
    6873                 :    1357980 :       && comptypes (type, rhstype))
    6874                 :          0 :     return convert_and_check (expr_loc != UNKNOWN_LOCATION
    6875                 :          0 :                               ? expr_loc : location, type, rhs);
    6876                 :            : 
    6877                 :            :   /* Conversion to a transparent union or record from its member types.
    6878                 :            :      This applies only to function arguments.  */
    6879                 :    1357970 :   if (((codel == UNION_TYPE || codel == RECORD_TYPE)
    6880                 :         68 :       && TYPE_TRANSPARENT_AGGR (type))
    6881                 :    1357990 :       && errtype == ic_argpass)
    6882                 :            :     {
    6883                 :         19 :       tree memb, marginal_memb = NULL_TREE;
    6884                 :            : 
    6885                 :         44 :       for (memb = TYPE_FIELDS (type); memb ; memb = DECL_CHAIN (memb))
    6886                 :            :         {
    6887                 :         25 :           tree memb_type = TREE_TYPE (memb);
    6888                 :            : 
    6889                 :         50 :           if (comptypes (TYPE_MAIN_VARIANT (memb_type),
    6890                 :         25 :                          TYPE_MAIN_VARIANT (rhstype)))
    6891                 :            :             break;
    6892                 :            : 
    6893                 :         13 :           if (TREE_CODE (memb_type) != POINTER_TYPE)
    6894                 :          0 :             continue;
    6895                 :            : 
    6896                 :         13 :           if (coder == POINTER_TYPE)
    6897                 :            :             {
    6898                 :         13 :               tree ttl = TREE_TYPE (memb_type);
    6899                 :         13 :               tree ttr = TREE_TYPE (rhstype);
    6900                 :            : 
    6901                 :            :               /* Any non-function converts to a [const][volatile] void *
    6902                 :            :                  and vice versa; otherwise, targets must be the same.
    6903                 :            :                  Meanwhile, the lhs target must have all the qualifiers of
    6904                 :            :                  the rhs.  */
    6905                 :          0 :               if ((VOID_TYPE_P (ttl) && !TYPE_ATOMIC (ttl))
    6906                 :         20 :                   || (VOID_TYPE_P (ttr) && !TYPE_ATOMIC (ttr))
    6907                 :         19 :                   || comp_target_types (location, memb_type, rhstype))
    6908                 :            :                 {
    6909                 :          7 :                   int lquals = TYPE_QUALS (ttl) & ~TYPE_QUAL_ATOMIC;
    6910                 :          7 :                   int rquals = TYPE_QUALS (ttr) & ~TYPE_QUAL_ATOMIC;
    6911                 :            :                   /* If this type won't generate any warnings, use it.  */
    6912                 :          7 :                   if (lquals == rquals
    6913                 :          0 :                       || ((TREE_CODE (ttr) == FUNCTION_TYPE
    6914                 :          0 :                            && TREE_CODE (ttl) == FUNCTION_TYPE)
    6915                 :          0 :                           ? ((lquals | rquals) == rquals)
    6916                 :          7 :                           : ((lquals | rquals) == lquals)))
    6917                 :            :                     break;
    6918                 :            : 
    6919                 :            :                   /* Keep looking for a better type, but remember this one.  */
    6920                 :          0 :                   if (!marginal_memb)
    6921                 :          0 :                     marginal_memb = memb;
    6922                 :            :                 }
    6923                 :            :             }
    6924                 :            : 
    6925                 :            :           /* Can convert integer zero to any pointer type.  */
    6926                 :          6 :           if (null_pointer_constant)
    6927                 :            :             {
    6928                 :          0 :               rhs = null_pointer_node;
    6929                 :          0 :               break;
    6930                 :            :             }
    6931                 :            :         }
    6932                 :            : 
    6933                 :         19 :       if (memb || marginal_memb)
    6934                 :            :         {
    6935                 :         19 :           if (!memb)
    6936                 :            :             {
    6937                 :            :               /* We have only a marginally acceptable member type;
    6938                 :            :                  it needs a warning.  */
    6939                 :          0 :               tree ttl = TREE_TYPE (TREE_TYPE (marginal_memb));
    6940                 :          0 :               tree ttr = TREE_TYPE (rhstype);
    6941                 :            : 
    6942                 :            :               /* Const and volatile mean something different for function
    6943                 :            :                  types, so the usual warnings are not appropriate.  */
    6944                 :          0 :               if (TREE_CODE (ttr) == FUNCTION_TYPE
    6945                 :          0 :                   && TREE_CODE (ttl) == FUNCTION_TYPE)
    6946                 :            :                 {
    6947                 :            :                   /* Because const and volatile on functions are
    6948                 :            :                      restrictions that say the function will not do
    6949                 :            :                      certain things, it is okay to use a const or volatile
    6950                 :            :                      function where an ordinary one is wanted, but not
    6951                 :            :                      vice-versa.  */
    6952                 :          0 :                   if (TYPE_QUALS_NO_ADDR_SPACE (ttl)
    6953                 :          0 :                       & ~TYPE_QUALS_NO_ADDR_SPACE (ttr))
    6954                 :          0 :                     PEDWARN_FOR_QUALIFIERS (location, expr_loc,
    6955                 :            :                                             OPT_Wdiscarded_qualifiers,
    6956                 :            :                                             G_("passing argument %d of %qE "
    6957                 :            :                                                "makes %q#v qualified function "
    6958                 :            :                                                "pointer from unqualified"),
    6959                 :            :                                             G_("assignment makes %q#v qualified "
    6960                 :            :                                                "function pointer from "
    6961                 :            :                                                "unqualified"),
    6962                 :            :                                             G_("initialization makes %q#v qualified "
    6963                 :            :                                                "function pointer from "
    6964                 :            :                                                "unqualified"),
    6965                 :            :                                             G_("return makes %q#v qualified function "
    6966                 :            :                                                "pointer from unqualified"),
    6967                 :            :                                             TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr));
    6968                 :            :                 }
    6969                 :          0 :               else if (TYPE_QUALS_NO_ADDR_SPACE (ttr)
    6970                 :          0 :                        & ~TYPE_QUALS_NO_ADDR_SPACE (ttl))
    6971                 :          0 :                 PEDWARN_FOR_QUALIFIERS (location, expr_loc,
    6972                 :            :                                         OPT_Wdiscarded_qualifiers,
    6973                 :            :                                         G_("passing argument %d of %qE discards "
    6974                 :            :                                            "%qv qualifier from pointer target type"),
    6975                 :            :                                         G_("assignment discards %qv qualifier "
    6976                 :            :                                            "from pointer target type"),
    6977                 :            :                                         G_("initialization discards %qv qualifier "
    6978                 :            :                                            "from pointer target type"),
    6979                 :            :                                         G_("return discards %qv qualifier from "
    6980                 :            :                                            "pointer target type"),
    6981                 :            :                                         TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl));
    6982                 :            : 
    6983                 :            :               memb = marginal_memb;
    6984                 :            :             }
    6985                 :            : 
    6986                 :         37 :           if (!fundecl || !DECL_IN_SYSTEM_HEADER (fundecl))
    6987                 :         19 :             pedwarn (location, OPT_Wpedantic,
    6988                 :            :                      "ISO C prohibits argument conversion to union type");
    6989                 :            : 
    6990                 :         19 :           rhs = fold_convert_loc (location, TREE_TYPE (memb), rhs);
    6991                 :         19 :           return build_constructor_single (type, memb, rhs);
    6992                 :            :         }
    6993                 :            :     }
    6994                 :            : 
    6995                 :            :   /* Conversions among pointers */
    6996                 :    1357950 :   else if ((codel == POINTER_TYPE || codel == REFERENCE_TYPE)
    6997                 :    1356760 :            && (coder == codel))
    6998                 :            :     {
    6999                 :            :       /* If RHS refers to a built-in declared without a prototype
    7000                 :            :          BLTIN is the declaration of the built-in with a prototype
    7001                 :            :          and RHSTYPE is set to the actual type of the built-in.  */
    7002                 :    1306360 :       tree bltin;
    7003                 :    1306360 :       rhstype = type_or_builtin_type (rhs, &bltin);
    7004                 :            : 
    7005                 :    1306360 :       tree ttl = TREE_TYPE (type);
    7006                 :    1306360 :       tree ttr = TREE_TYPE (rhstype);
    7007                 :    1306360 :       tree mvl = ttl;
    7008                 :    1306360 :       tree mvr = ttr;
    7009                 :    1306360 :       bool is_opaque_pointer;
    7010                 :    1306360 :       int target_cmp = 0;   /* Cache comp_target_types () result.  */
    7011                 :    1306360 :       addr_space_t asl;
    7012                 :    1306360 :       addr_space_t asr;
    7013                 :            : 
    7014                 :    1306360 :       if (TREE_CODE (mvl) != ARRAY_TYPE)
    7015                 :    1305810 :         mvl = (TYPE_ATOMIC (mvl)
    7016                 :         92 :                ? c_build_qualified_type (TYPE_MAIN_VARIANT (mvl),
    7017                 :            :                                          TYPE_QUAL_ATOMIC)
    7018                 :    1305810 :                : TYPE_MAIN_VARIANT (mvl));
    7019                 :    1306360 :       if (TREE_CODE (mvr) != ARRAY_TYPE)
    7020                 :    1305010 :         mvr = (TYPE_ATOMIC (mvr)
    7021                 :      12208 :                ? c_build_qualified_type (TYPE_MAIN_VARIANT (mvr),
    7022                 :            :                                          TYPE_QUAL_ATOMIC)
    7023                 :    1305010 :                : TYPE_MAIN_VARIANT (mvr));
    7024                 :            :       /* Opaque pointers are treated like void pointers.  */
    7025                 :    1306360 :       is_opaque_pointer = vector_targets_convertible_p (ttl, ttr);
    7026                 :            : 
    7027                 :            :       /* The Plan 9 compiler permits a pointer to a struct to be
    7028                 :            :          automatically converted into a pointer to an anonymous field
    7029                 :            :          within the struct.  */
    7030                 :    1306360 :       if (flag_plan9_extensions
    7031                 :          8 :           && RECORD_OR_UNION_TYPE_P (mvl)
    7032                 :          8 :           && RECORD_OR_UNION_TYPE_P (mvr)
    7033                 :          8 :           && mvl != mvr)
    7034                 :            :         {
    7035                 :          8 :           tree new_rhs = convert_to_anonymous_field (location, type, rhs);
    7036                 :          8 :           if (new_rhs != NULL_TREE)
    7037                 :            :             {
    7038                 :          6 :               rhs = new_rhs;
    7039                 :          6 :               rhstype = TREE_TYPE (rhs);
    7040                 :          6 :               coder = TREE_CODE (rhstype);
    7041                 :          6 :               ttr = TREE_TYPE (rhstype);
    7042                 :          6 :               mvr = TYPE_MAIN_VARIANT (ttr);
    7043                 :            :             }
    7044                 :            :         }
    7045                 :            : 
    7046                 :            :       /* C++ does not allow the implicit conversion void* -> T*.  However,
    7047                 :            :          for the purpose of reducing the number of false positives, we
    7048                 :            :          tolerate the special case of
    7049                 :            : 
    7050                 :            :                 int *p = NULL;
    7051                 :            : 
    7052                 :            :          where NULL is typically defined in C to be '(void *) 0'.  */
    7053                 :    1306360 :       if (VOID_TYPE_P (ttr) && rhs != null_pointer_node && !VOID_TYPE_P (ttl))
    7054                 :      22009 :         warning_at (errtype == ic_argpass ? expr_loc : location,
    7055                 :            :                     OPT_Wc___compat,
    7056                 :            :                     "request for implicit conversion "
    7057                 :            :                     "from %qT to %qT not permitted in C++", rhstype, type);
    7058                 :            : 
    7059                 :            :       /* See if the pointers point to incompatible address spaces.  */
    7060                 :    1306360 :       asl = TYPE_ADDR_SPACE (ttl);
    7061                 :    1306360 :       asr = TYPE_ADDR_SPACE (ttr);
    7062                 :    1306360 :       if (!null_pointer_constant_p (rhs)
    7063                 :    1306360 :           && asr != asl && !targetm.addr_space.subset_p (asr, asl))
    7064                 :            :         {
    7065                 :          0 :           switch (errtype)
    7066                 :            :             {
    7067                 :          0 :             case ic_argpass:
    7068                 :          0 :               {
    7069                 :          0 :                 const char msg[] = G_("passing argument %d of %qE from "
    7070                 :            :                                       "pointer to non-enclosed address space");
    7071                 :          0 :                 if (warnopt)
    7072                 :          0 :                   warning_at (expr_loc, warnopt, msg, parmnum, rname);
    7073                 :            :                 else
    7074                 :          0 :                   error_at (expr_loc, msg, parmnum, rname);
    7075                 :          0 :               break;
    7076                 :            :               }
    7077                 :          0 :             case ic_assign:
    7078                 :          0 :               {
    7079                 :          0 :                 const char msg[] = G_("assignment from pointer to "
    7080                 :            :                                       "non-enclosed address space");
    7081                 :          0 :                 if (warnopt)
    7082                 :          0 :                   warning_at (location, warnopt, msg);
    7083                 :            :                 else
    7084                 :          0 :                   error_at (location, msg);
    7085                 :          0 :                 break;
    7086                 :            :               }
    7087                 :          0 :             case ic_init:
    7088                 :          0 :               {
    7089                 :          0 :                 const char msg[] = G_("initialization from pointer to "
    7090                 :            :                                       "non-enclosed address space");
    7091                 :          0 :                 if (warnopt)
    7092                 :          0 :                   warning_at (location, warnopt, msg);
    7093                 :            :                 else
    7094                 :          0 :                   error_at (location, msg);
    7095                 :          0 :                 break;
    7096                 :            :               }
    7097                 :          0 :             case ic_return:
    7098                 :          0 :               {
    7099                 :          0 :                 const char msg[] = G_("return from pointer to "
    7100                 :            :                                       "non-enclosed address space");
    7101                 :          0 :                 if (warnopt)
    7102                 :          0 :                   warning_at (location, warnopt, msg);
    7103                 :            :                 else
    7104                 :          0 :                   error_at (location, msg);
    7105                 :          0 :                 break;
    7106                 :            :               }
    7107                 :          0 :             default:
    7108                 :          0 :               gcc_unreachable ();
    7109                 :            :             }
    7110                 :          0 :           return error_mark_node;
    7111                 :            :         }
    7112                 :            : 
    7113                 :            :       /* Check if the right-hand side has a format attribute but the
    7114                 :            :          left-hand side doesn't.  */
    7115                 :    1306360 :       if (warn_suggest_attribute_format
    7116                 :    1306360 :           && check_missing_format_attribute (type, rhstype))
    7117                 :            :         {
    7118                 :         16 :           switch (errtype)
    7119                 :            :           {
    7120                 :          4 :           case ic_argpass:
    7121                 :          4 :             warning_at (expr_loc, OPT_Wsuggest_attribute_format,
    7122                 :            :                         "argument %d of %qE might be "
    7123                 :            :                         "a candidate for a format attribute",
    7124                 :            :                         parmnum, rname);
    7125                 :          4 :             break;
    7126                 :          4 :           case ic_assign:
    7127                 :          4 :             warning_at (location, OPT_Wsuggest_attribute_format,
    7128                 :            :                         "assignment left-hand side might be "
    7129                 :            :                         "a candidate for a format attribute");
    7130                 :          4 :             break;
    7131                 :          4 :           case ic_init:
    7132                 :          4 :             warning_at (location, OPT_Wsuggest_attribute_format,
    7133                 :            :                         "initialization left-hand side might be "
    7134                 :            :                         "a candidate for a format attribute");
    7135                 :          4 :             break;
    7136                 :          4 :           case ic_return:
    7137                 :          4 :             warning_at (location, OPT_Wsuggest_attribute_format,
    7138                 :            :                         "return type might be "
    7139                 :            :                         "a candidate for a format attribute");
    7140                 :          4 :             break;
    7141                 :          0 :           default:
    7142                 :          0 :             gcc_unreachable ();
    7143                 :            :           }
    7144                 :            :         }
    7145                 :            : 
    7146                 :            :       /* Any non-function converts to a [const][volatile] void *
    7147                 :            :          and vice versa; otherwise, targets must be the same.
    7148                 :            :          Meanwhile, the lhs target must have all the qualifiers of the rhs.  */
    7149                 :     339635 :       if ((VOID_TYPE_P (ttl) && !TYPE_ATOMIC (ttl))
    7150                 :    1002210 :           || (VOID_TYPE_P (ttr) && !TYPE_ATOMIC (ttr))
    7151                 :     931253 :           || (target_cmp = comp_target_types (location, type, rhstype))
    7152                 :       1587 :           || is_opaque_pointer
    7153                 :    1309540 :           || ((c_common_unsigned_type (mvl)
    7154                 :       1587 :                == c_common_unsigned_type (mvr))
    7155                 :       2144 :               && (c_common_signed_type (mvl)
    7156                 :       1072 :                   == c_common_signed_type (mvr))
    7157                 :       1072 :               && TYPE_ATOMIC (mvl) == TYPE_ATOMIC (mvr)))
    7158                 :            :         {
    7159                 :            :           /* Warn about loss of qualifers from pointers to arrays with
    7160                 :            :              qualifiers on the element type. */
    7161                 :    1305850 :           if (TREE_CODE (ttr) == ARRAY_TYPE)
    7162                 :            :             {
    7163                 :       1331 :               ttr = strip_array_types (ttr);
    7164                 :       1331 :               ttl = strip_array_types (ttl);
    7165                 :            : 
    7166                 :       1331 :               if (TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttr)
    7167                 :       1331 :                   & ~TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttl))
    7168                 :         80 :                 WARNING_FOR_QUALIFIERS (location, expr_loc,
    7169                 :            :                                         OPT_Wdiscarded_array_qualifiers,
    7170                 :            :                                         G_("passing argument %d of %qE discards "
    7171                 :            :                                            "%qv qualifier from pointer target type"),
    7172                 :            :                                         G_("assignment discards %qv qualifier "
    7173                 :            :                                            "from pointer target type"),
    7174                 :            :                                         G_("initialization discards %qv qualifier "
    7175                 :            :                                            "from pointer target type"),
    7176                 :            :                                         G_("return discards %qv qualifier from "
    7177                 :            :                                            "pointer target type"),
    7178                 :            :                                         TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl));
    7179                 :            :             }
    7180                 :    1304520 :           else if (pedantic
    7181                 :     121234 :               && ((VOID_TYPE_P (ttl) && TREE_CODE (ttr) == FUNCTION_TYPE)
    7182                 :     121218 :                   ||
    7183                 :            :                   (VOID_TYPE_P (ttr)
    7184                 :       2885 :                    && !null_pointer_constant
    7185                 :        186 :                    && TREE_CODE (ttl) == FUNCTION_TYPE)))
    7186                 :         29 :             PEDWARN_FOR_ASSIGNMENT (location, expr_loc, OPT_Wpedantic,
    7187                 :            :                                     G_("ISO C forbids passing argument %d of "
    7188                 :            :                                        "%qE between function pointer "
    7189                 :            :                                        "and %<void *%>"),
    7190                 :            :                                     G_("ISO C forbids assignment between "
    7191                 :            :                                        "function pointer and %<void *%>"),
    7192                 :            :                                     G_("ISO C forbids initialization between "
    7193                 :            :                                        "function pointer and %<void *%>"),
    7194                 :            :                                     G_("ISO C forbids return between function "
    7195                 :            :                                        "pointer and %<void *%>"));
    7196                 :            :           /* Const and volatile mean something different for function types,
    7197                 :            :              so the usual warnings are not appropriate.  */
    7198                 :    1304490 :           else if (TREE_CODE (ttr) != FUNCTION_TYPE
    7199                 :    1271610 :                    && TREE_CODE (ttl) != FUNCTION_TYPE)
    7200                 :            :             {
    7201                 :            :               /* Don't warn about loss of qualifier for conversions from
    7202                 :            :                  qualified void* to pointers to arrays with corresponding
    7203                 :            :                  qualifier on the element type. */
    7204                 :    1271080 :               if (!pedantic)
    7205                 :    1149930 :                 ttl = strip_array_types (ttl);
    7206                 :            : 
    7207                 :            :               /* Assignments between atomic and non-atomic objects are OK.  */
    7208                 :    1271080 :               if (TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttr)
    7209                 :    1271080 :                   & ~TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttl))
    7210                 :            :                 {
    7211                 :        644 :                   PEDWARN_FOR_QUALIFIERS (location, expr_loc,
    7212                 :            :                                           OPT_Wdiscarded_qualifiers,
    7213                 :            :                                           G_("passing argument %d of %qE discards "
    7214                 :            :                                              "%qv qualifier from pointer target type"),
    7215                 :            :                                           G_("assignment discards %qv qualifier "
    7216                 :            :                                              "from pointer target type"),
    7217                 :            :                                           G_("initialization discards %qv qualifier "
    7218                 :            :                                              "from pointer target type"),
    7219                 :            :                                           G_("return discards %qv qualifier from "
    7220                 :            :                                              "pointer target type"),
    7221                 :            :                                           TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl));
    7222                 :            :                 }
    7223                 :            :               /* If this is not a case of ignoring a mismatch in signedness,
    7224                 :            :                  no warning.  */
    7225                 :    1270430 :               else if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr)
    7226                 :     926261 :                        || target_cmp)
    7227                 :            :                 ;
    7228                 :            :               /* If there is a mismatch, do warn.  */
    7229                 :       1070 :               else if (warn_pointer_sign)
    7230                 :         81 :                 switch (errtype)
    7231                 :            :                   {
    7232                 :         32 :                   case ic_argpass:
    7233                 :         32 :                     {
    7234                 :         32 :                       auto_diagnostic_group d;
    7235                 :         64 :                       range_label_for_type_mismatch rhs_label (rhstype, type);
    7236                 :         64 :                       gcc_rich_location richloc (expr_loc, &rhs_label);
    7237                 :         32 :                       if (pedwarn (&richloc, OPT_Wpointer_sign,
    7238                 :            :                                    "pointer targets in passing argument %d of "
    7239                 :            :                                    "%qE differ in signedness", parmnum, rname))
    7240                 :         32 :                         inform_for_arg (fundecl, expr_loc, parmnum, type,
    7241                 :            :                                         rhstype);
    7242                 :            :                     }
    7243                 :         32 :                     break;
    7244                 :         21 :                   case ic_assign:
    7245                 :         21 :                     pedwarn (location, OPT_Wpointer_sign,
    7246                 :            :                              "pointer targets in assignment from %qT to %qT "
    7247                 :            :                              "differ in signedness", rhstype, type);
    7248                 :         21 :                     break;
    7249                 :         14 :                   case ic_init:
    7250                 :         14 :                     pedwarn_init (location, OPT_Wpointer_sign,
    7251                 :            :                                   "pointer targets in initialization of %qT "
    7252                 :            :                                   "from %qT differ in signedness", type,
    7253                 :            :                                   rhstype);
    7254                 :         14 :                     break;
    7255                 :         14 :                   case ic_return:
    7256                 :         14 :                     pedwarn (location, OPT_Wpointer_sign, "pointer targets in "
    7257                 :            :                              "returning %qT from a function with return type "
    7258                 :            :                              "%qT differ in signedness", rhstype, type);
    7259                 :         14 :                     break;
    7260                 :          0 :                   default:
    7261                 :          0 :                     gcc_unreachable ();
    7262                 :            :                   }
    7263                 :            :             }
    7264                 :      33411 :           else if (TREE_CODE (ttl) == FUNCTION_TYPE
    7265                 :       4468 :                    && TREE_CODE (ttr) == FUNCTION_TYPE)
    7266                 :            :             {
    7267                 :            :               /* Because const and volatile on functions are restrictions
    7268                 :            :                  that say the function will not do certain things,
    7269                 :            :                  it is okay to use a const or volatile function
    7270                 :            :                  where an ordinary one is wanted, but not vice-versa.  */
    7271                 :       3934 :               if (TYPE_QUALS_NO_ADDR_SPACE (ttl)
    7272                 :       3934 :                   & ~TYPE_QUALS_NO_ADDR_SPACE (ttr))
    7273                 :         14 :                 PEDWARN_FOR_QUALIFIERS (location, expr_loc,
    7274                 :            :                                         OPT_Wdiscarded_qualifiers,
    7275                 :            :                                         G_("passing argument %d of %qE makes "
    7276                 :            :                                            "%q#v qualified function pointer "
    7277                 :            :                                            "from unqualified"),
    7278                 :            :                                         G_("assignment makes %q#v qualified function "
    7279                 :            :                                            "pointer from unqualified"),
    7280                 :            :                                         G_("initialization makes %q#v qualified "
    7281                 :            :                                            "function pointer from unqualified"),
    7282                 :            :                                         G_("return makes %q#v qualified function "
    7283                 :            :                                            "pointer from unqualified"),
    7284                 :            :                                         TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr));
    7285                 :            :             }
    7286                 :            :         }
    7287                 :            :       /* Avoid warning about the volatile ObjC EH puts on decls.  */
    7288                 :        517 :       else if (!objc_ok)
    7289                 :            :         {
    7290                 :        517 :           switch (errtype)
    7291                 :            :             {
    7292                 :        238 :             case ic_argpass:
    7293                 :        238 :               {
    7294                 :        238 :                 auto_diagnostic_group d;
    7295                 :        476 :                 range_label_for_type_mismatch rhs_label (rhstype, type);
    7296                 :        476 :                 gcc_rich_location richloc (expr_loc, &rhs_label);
    7297                 :        238 :                 if (pedwarn (&richloc, OPT_Wincompatible_pointer_types,
    7298                 :            :                              "passing argument %d of %qE from incompatible "
    7299                 :            :                              "pointer type", parmnum, rname))
    7300                 :        118 :                   inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
    7301                 :            :               }
    7302                 :        238 :               break;
    7303                 :        141 :             case ic_assign:
    7304                 :        141 :               if (bltin)
    7305                 :          1 :                 pedwarn (location, OPT_Wincompatible_pointer_types,
    7306                 :            :                          "assignment to %qT from pointer to "
    7307                 :            :                          "%qD with incompatible type %qT",
    7308                 :            :                          type, bltin, rhstype);
    7309                 :            :               else
    7310                 :        140 :                 pedwarn (location, OPT_Wincompatible_pointer_types,
    7311                 :            :                          "assignment to %qT from incompatible pointer type %qT",
    7312                 :            :                          type, rhstype);
    7313                 :            :               break;
    7314                 :        121 :             case ic_init:
    7315                 :        121 :               if (bltin)
    7316                 :          3 :                 pedwarn_init (location, OPT_Wincompatible_pointer_types,
    7317                 :            :                               "initialization of %qT from pointer to "
    7318                 :            :                               "%qD with incompatible type %qT",
    7319                 :            :                               type, bltin, rhstype);
    7320                 :            :               else
    7321                 :        118 :                 pedwarn_init (location, OPT_Wincompatible_pointer_types,
    7322                 :            :                               "initialization of %qT from incompatible "
    7323                 :            :                               "pointer type %qT",
    7324                 :            :                               type, rhstype);
    7325                 :            :               break;
    7326                 :         17 :             case ic_return:
    7327                 :         17 :               if (bltin)
    7328                 :          1 :                 pedwarn (location, OPT_Wincompatible_pointer_types,
    7329                 :            :                          "returning pointer to %qD of type %qT from "
    7330                 :            :                          "a function with incompatible type %qT",
    7331                 :            :                          bltin, rhstype, type);
    7332                 :            :               else
    7333                 :         16 :                 pedwarn (location, OPT_Wincompatible_pointer_types,
    7334                 :            :                          "returning %qT from a function with incompatible "
    7335                 :            :                          "return type %qT", rhstype, type);
    7336                 :            :               break;
    7337                 :          0 :             default:
    7338                 :          0 :               gcc_unreachable ();
    7339                 :            :             }
    7340                 :            :         }
    7341                 :            : 
    7342                 :            :       /* If RHS isn't an address, check pointer or array of packed
    7343                 :            :          struct or union.  */
    7344                 :    1306360 :       warn_for_address_or_pointer_of_packed_member (type, orig_rhs);
    7345                 :            : 
    7346                 :    1306360 :       return convert (type, rhs);
    7347                 :            :     }
    7348                 :      51583 :   else if (codel == POINTER_TYPE && coder == ARRAY_TYPE)
    7349                 :            :     {
    7350                 :            :       /* ??? This should not be an error when inlining calls to
    7351                 :            :          unprototyped functions.  */
    7352                 :          4 :       const char msg[] = "invalid use of non-lvalue array";
    7353                 :          4 :       if (warnopt)
    7354                 :          0 :         warning_at (location, warnopt, msg);
    7355                 :            :       else
    7356                 :          4 :         error_at (location, msg);
    7357                 :          4 :       return error_mark_node;
    7358                 :            :     }
    7359                 :      51579 :   else if (codel == POINTER_TYPE && coder == INTEGER_TYPE)
    7360                 :            :     {
    7361                 :            :       /* An explicit constant 0 can convert to a pointer,
    7362                 :            :          or one that results from arithmetic, even including
    7363                 :            :          a cast to integer type.  */
    7364                 :      50378 :       if (!null_pointer_constant)
    7365                 :        942 :         switch (errtype)
    7366                 :            :           {
    7367                 :        782 :           case ic_argpass:
    7368                 :        782 :             {
    7369                 :        782 :               auto_diagnostic_group d;
    7370                 :       1564 :               range_label_for_type_mismatch rhs_label (rhstype, type);
    7371                 :       1564 :               gcc_rich_location richloc (expr_loc, &rhs_label);
    7372                 :        782 :               if (pedwarn (&richloc, OPT_Wint_conversion,
    7373                 :            :                            "passing argument %d of %qE makes pointer from "
    7374                 :            :                            "integer without a cast", parmnum, rname))
    7375                 :        414 :                 inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
    7376                 :            :             }
    7377                 :        782 :             break;
    7378                 :        119 :           case ic_assign:
    7379                 :        119 :             pedwarn (location, OPT_Wint_conversion,
    7380                 :            :                      "assignment to %qT from %qT makes pointer from integer "
    7381                 :            :                      "without a cast", type, rhstype);
    7382                 :        119 :             break;
    7383                 :         31 :           case ic_init:
    7384                 :         31 :             pedwarn_init (location, OPT_Wint_conversion,
    7385                 :            :                           "initialization of %qT from %qT makes pointer from "
    7386                 :            :                           "integer without a cast", type, rhstype);
    7387                 :         31 :             break;
    7388                 :         10 :           case ic_return:
    7389                 :         10 :             pedwarn (location, OPT_Wint_conversion, "returning %qT from a "
    7390                 :            :                      "function with return type %qT makes pointer from "
    7391                 :            :                      "integer without a cast", rhstype, type);
    7392                 :         10 :             break;
    7393                 :          0 :           default:
    7394                 :          0 :             gcc_unreachable ();
    7395                 :            :           }
    7396                 :            : 
    7397                 :      50378 :       return convert (type, rhs);
    7398                 :            :     }
    7399                 :       1201 :   else if (codel == INTEGER_TYPE && coder == POINTER_TYPE)
    7400                 :            :     {
    7401                 :        538 :       switch (errtype)
    7402                 :            :         {
    7403                 :        326 :         case ic_argpass:
    7404                 :        326 :           {
    7405                 :        326 :             auto_diagnostic_group d;
    7406                 :        652 :             range_label_for_type_mismatch rhs_label (rhstype, type);
    7407                 :        652 :             gcc_rich_location richloc (expr_loc, &rhs_label);
    7408                 :        326 :             if (pedwarn (&richloc, OPT_Wint_conversion,
    7409                 :            :                          "passing argument %d of %qE makes integer from "
    7410                 :            :                          "pointer without a cast", parmnum, rname))
    7411                 :        309 :               inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
    7412                 :            :           }
    7413                 :        326 :           break;
    7414                 :         39 :         case ic_assign:
    7415                 :         39 :           pedwarn (location, OPT_Wint_conversion,
    7416                 :            :                    "assignment to %qT from %qT makes integer from pointer "
    7417                 :            :                    "without a cast", type, rhstype);
    7418                 :         39 :           break;
    7419                 :        152 :         case ic_init:
    7420                 :        152 :           pedwarn_init (location, OPT_Wint_conversion,
    7421                 :            :                         "initialization of %qT from %qT makes integer from "
    7422                 :            :                         "pointer without a cast", type, rhstype);
    7423                 :        152 :           break;
    7424                 :         21 :         case ic_return:
    7425                 :         21 :           pedwarn (location, OPT_Wint_conversion, "returning %qT from a "
    7426                 :            :                    "function with return type %qT makes integer from "
    7427                 :            :                    "pointer without a cast", rhstype, type);
    7428                 :         21 :           break;
    7429                 :          0 :         default:
    7430                 :          0 :           gcc_unreachable ();
    7431                 :            :         }
    7432                 :            : 
    7433                 :        538 :       return convert (type, rhs);
    7434                 :            :     }
    7435                 :        663 :   else if (codel == BOOLEAN_TYPE && coder == POINTER_TYPE)
    7436                 :            :     {
    7437                 :          3 :       tree ret;
    7438                 :          3 :       bool save = in_late_binary_op;
    7439                 :          3 :       in_late_binary_op = true;
    7440                 :          3 :       ret = convert (type, rhs);
    7441                 :          3 :       in_late_binary_op = save;
    7442                 :          3 :       return ret;
    7443                 :            :     }
    7444                 :            : 
    7445                 :        660 :   switch (errtype)
    7446                 :            :     {
    7447                 :         30 :     case ic_argpass:
    7448                 :         30 :       {
    7449                 :         30 :         auto_diagnostic_group d;
    7450                 :         60 :         range_label_for_type_mismatch rhs_label (rhstype, type);
    7451                 :         60 :         gcc_rich_location richloc (expr_loc, &rhs_label);
    7452                 :         30 :         const char msg[] = G_("incompatible type for argument %d of %qE");
    7453                 :         30 :         if (warnopt)
    7454                 :          8 :           warning_at (expr_loc, warnopt, msg, parmnum, rname);
    7455                 :            :         else
    7456                 :         22 :           error_at (&richloc, msg, parmnum, rname);
    7457                 :         30 :         inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
    7458                 :            :       }
    7459                 :         30 :       break;
    7460                 :         61 :     case ic_assign:
    7461                 :         61 :       {
    7462                 :         61 :         const char msg[]
    7463                 :            :           = G_("incompatible types when assigning to type %qT from type %qT");
    7464                 :         61 :         if (warnopt)
    7465                 :          0 :           warning_at (expr_loc, 0, msg, type, rhstype);
    7466                 :            :         else
    7467                 :         61 :           error_at (expr_loc, msg, type, rhstype);
    7468                 :         61 :         break;
    7469                 :            :       }
    7470                 :        555 :     case ic_init:
    7471                 :        555 :       {
    7472                 :        555 :         const char msg[]
    7473                 :            :           = G_("incompatible types when initializing type %qT using type %qT");
    7474                 :        555 :         if (warnopt)
    7475                 :          0 :           warning_at (location, 0, msg, type, rhstype);
    7476                 :            :         else
    7477                 :        555 :           error_at (location, msg, type, rhstype);
    7478                 :        555 :         break;
    7479                 :            :       }
    7480                 :         14 :     case ic_return:
    7481                 :         14 :       {
    7482                 :         14 :         const char msg[]
    7483                 :            :           = G_("incompatible types when returning type %qT but %qT was expected");
    7484                 :         14 :         if (warnopt)
    7485                 :          0 :           warning_at (location, 0, msg, rhstype, type);
    7486                 :            :         else
    7487                 :         14 :           error_at (location, msg, rhstype, type);
    7488                 :         14 :         break;
    7489                 :            :       }
    7490                 :          0 :     default:
    7491                 :          0 :       gcc_unreachable ();
    7492                 :            :     }
    7493                 :            : 
    7494                 :        660 :   return error_mark_node;
    7495                 :            : }
    7496                 :            : 
    7497                 :            : /* If VALUE is a compound expr all of whose expressions are constant, then
    7498                 :            :    return its value.  Otherwise, return error_mark_node.
    7499                 :            : 
    7500                 :            :    This is for handling COMPOUND_EXPRs as initializer elements
    7501                 :            :    which is allowed with a warning when -pedantic is specified.  */
    7502                 :            : 
    7503                 :            : static tree
    7504                 :          2 : valid_compound_expr_initializer (tree value, tree endtype)
    7505                 :            : {
    7506                 :          2 :   if (TREE_CODE (value) == COMPOUND_EXPR)
    7507                 :            :     {
    7508                 :          1 :       if (valid_compound_expr_initializer (TREE_OPERAND (value, 0), endtype)
    7509                 :          1 :           == error_mark_node)
    7510                 :            :         return error_mark_node;
    7511                 :          0 :       return valid_compound_expr_initializer (TREE_OPERAND (value, 1),
    7512                 :          0 :                                               endtype);
    7513                 :            :     }
    7514                 :          1 :   else if (!initializer_constant_valid_p (value, endtype))
    7515                 :          1 :     return error_mark_node;
    7516                 :            :   else
    7517                 :            :     return value;
    7518                 :            : }
    7519                 :            : 
    7520                 :            : /* Perform appropriate conversions on the initial value of a variable,
    7521                 :            :    store it in the declaration DECL,
    7522                 :            :    and print any error messages that are appropriate.