• Main Page
  • Modules
  • Data Types
  • Files

osprey-gcc-4.2.0/gcc/c-typeck.c

Go to the documentation of this file.
00001 /* Build expressions with type checking for C compiler.
00002    Copyright (C) 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
00003    1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
00004    Free Software Foundation, Inc.
00005 
00006 This file is part of GCC.
00007 
00008 GCC is free software; you can redistribute it and/or modify it under
00009 the terms of the GNU General Public License as published by the Free
00010 Software Foundation; either version 2, or (at your option) any later
00011 version.
00012 
00013 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
00014 WARRANTY; without even the implied warranty of MERCHANTABILITY or
00015 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00016 for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with GCC; see the file COPYING.  If not, write to the Free
00020 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
00021 02110-1301, USA.  */
00022 
00023 
00024 /* This file is part of the C front end.
00025    It contains routines to build C expressions given their operands,
00026    including computing the types of the result, C-specific error checks,
00027    and some optimization.  */
00028 
00029 #include "config.h"
00030 #include "system.h"
00031 #include "coretypes.h"
00032 #include "tm.h"
00033 #include "rtl.h"
00034 #include "tree.h"
00035 #include "langhooks.h"
00036 #include "c-tree.h"
00037 #include "tm_p.h"
00038 #include "flags.h"
00039 #include "output.h"
00040 #include "expr.h"
00041 #include "toplev.h"
00042 #include "intl.h"
00043 #include "ggc.h"
00044 #include "target.h"
00045 #include "tree-iterator.h"
00046 #include "tree-gimple.h"
00047 #include "tree-flow.h"
00048 
00049 /* Possible cases of implicit bad conversions.  Used to select
00050    diagnostic messages in convert_for_assignment.  */
00051 enum impl_conv {
00052   ic_argpass,
00053   ic_argpass_nonproto,
00054   ic_assign,
00055   ic_init,
00056   ic_return
00057 };
00058 
00059 /* The level of nesting inside "__alignof__".  */
00060 int in_alignof;
00061 
00062 /* The level of nesting inside "sizeof".  */
00063 int in_sizeof;
00064 
00065 /* The level of nesting inside "typeof".  */
00066 int in_typeof;
00067 
00068 struct c_label_context_se *label_context_stack_se;
00069 struct c_label_context_vm *label_context_stack_vm;
00070 
00071 /* Nonzero if we've already printed a "missing braces around initializer"
00072    message within this initializer.  */
00073 static int missing_braces_mentioned;
00074 
00075 static int require_constant_value;
00076 static int require_constant_elements;
00077 
00078 static bool null_pointer_constant_p (tree);
00079 static tree qualify_type (tree, tree);
00080 static int tagged_types_tu_compatible_p (tree, tree);
00081 static int comp_target_types (tree, tree);
00082 static int function_types_compatible_p (tree, tree);
00083 static int type_lists_compatible_p (tree, tree);
00084 static tree decl_constant_value_for_broken_optimization (tree);
00085 static tree lookup_field (tree, tree);
00086 static tree convert_arguments (tree, tree, tree, tree);
00087 static tree pointer_diff (tree, tree);
00088 static tree convert_for_assignment (tree, tree, enum impl_conv, tree, tree,
00089             int);
00090 static tree valid_compound_expr_initializer (tree, tree);
00091 static void push_string (const char *);
00092 static void push_member_name (tree);
00093 static int spelling_length (void);
00094 static char *print_spelling (char *);
00095 static void warning_init (const char *);
00096 static tree digest_init (tree, tree, bool, int);
00097 static void output_init_element (tree, bool, tree, tree, int);
00098 static void output_pending_init_elements (int);
00099 static int set_designator (int);
00100 static void push_range_stack (tree);
00101 static void add_pending_init (tree, tree);
00102 static void set_nonincremental_init (void);
00103 static void set_nonincremental_init_from_string (tree);
00104 static tree find_init_member (tree);
00105 static void readonly_error (tree, enum lvalue_use);
00106 static int lvalue_or_else (tree, enum lvalue_use);
00107 static int lvalue_p (tree);
00108 static void record_maybe_used_decl (tree);
00109 static int comptypes_internal (tree, tree);
00110 
00111 /* Return true if EXP is a null pointer constant, false otherwise.  */
00112 
00113 static bool
00114 null_pointer_constant_p (tree expr)
00115 {
00116   /* This should really operate on c_expr structures, but they aren't
00117      yet available everywhere required.  */
00118   tree type = TREE_TYPE (expr);
00119   return (TREE_CODE (expr) == INTEGER_CST
00120     && !TREE_CONSTANT_OVERFLOW (expr)
00121     && integer_zerop (expr)
00122     && (INTEGRAL_TYPE_P (type)
00123         || (TREE_CODE (type) == POINTER_TYPE
00124       && VOID_TYPE_P (TREE_TYPE (type))
00125       && TYPE_QUALS (TREE_TYPE (type)) == TYPE_UNQUALIFIED)));
00126 }
00127 /* This is a cache to hold if two types are compatible or not.  */
00128 
00129 struct tagged_tu_seen_cache {
00130   const struct tagged_tu_seen_cache * next;
00131   tree t1;
00132   tree t2;
00133   /* The return value of tagged_types_tu_compatible_p if we had seen
00134      these two types already.  */
00135   int val;
00136 };
00137 
00138 static const struct tagged_tu_seen_cache * tagged_tu_seen_base;
00139 static void free_all_tagged_tu_seen_up_to (const struct tagged_tu_seen_cache *);
00140 
00141 /* Do `exp = require_complete_type (exp);' to make sure exp
00142    does not have an incomplete type.  (That includes void types.)  */
00143 
00144 tree
00145 require_complete_type (tree value)
00146 {
00147   tree type = TREE_TYPE (value);
00148 
00149   if (value == error_mark_node || type == error_mark_node)
00150     return error_mark_node;
00151 
00152   /* First, detect a valid value with a complete type.  */
00153   if (COMPLETE_TYPE_P (type))
00154     return value;
00155 
00156   c_incomplete_type_error (value, type);
00157   return error_mark_node;
00158 }
00159 
00160 /* Print an error message for invalid use of an incomplete type.
00161    VALUE is the expression that was used (or 0 if that isn't known)
00162    and TYPE is the type that was invalid.  */
00163 
00164 void
00165 c_incomplete_type_error (tree value, tree type)
00166 {
00167   const char *type_code_string;
00168 
00169   /* Avoid duplicate error message.  */
00170   if (TREE_CODE (type) == ERROR_MARK)
00171     return;
00172 
00173   if (value != 0 && (TREE_CODE (value) == VAR_DECL
00174          || TREE_CODE (value) == PARM_DECL))
00175     error ("%qD has an incomplete type", value);
00176   else
00177     {
00178     retry:
00179       /* We must print an error message.  Be clever about what it says.  */
00180 
00181       switch (TREE_CODE (type))
00182   {
00183   case RECORD_TYPE:
00184     type_code_string = "struct";
00185     break;
00186 
00187   case UNION_TYPE:
00188     type_code_string = "union";
00189     break;
00190 
00191   case ENUMERAL_TYPE:
00192     type_code_string = "enum";
00193     break;
00194 
00195   case VOID_TYPE:
00196     error ("invalid use of void expression");
00197     return;
00198 
00199   case ARRAY_TYPE:
00200     if (TYPE_DOMAIN (type))
00201       {
00202         if (TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL)
00203     {
00204       error ("invalid use of flexible array member");
00205       return;
00206     }
00207         type = TREE_TYPE (type);
00208         goto retry;
00209       }
00210     error ("invalid use of array with unspecified bounds");
00211     return;
00212 
00213   default:
00214     gcc_unreachable ();
00215   }
00216 
00217       if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
00218   error ("invalid use of undefined type %<%s %E%>",
00219          type_code_string, TYPE_NAME (type));
00220       else
00221   /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL.  */
00222   error ("invalid use of incomplete typedef %qD", TYPE_NAME (type));
00223     }
00224 }
00225 
00226 /* Given a type, apply default promotions wrt unnamed function
00227    arguments and return the new type.  */
00228 
00229 tree
00230 c_type_promotes_to (tree type)
00231 {
00232   if (TYPE_MAIN_VARIANT (type) == float_type_node)
00233     return double_type_node;
00234 
00235   if (c_promoting_integer_type_p (type))
00236     {
00237       /* Preserve unsignedness if not really getting any wider.  */
00238       if (TYPE_UNSIGNED (type)
00239     && (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)))
00240   return unsigned_type_node;
00241       return integer_type_node;
00242     }
00243 
00244   return type;
00245 }
00246 
00247 /* Return a variant of TYPE which has all the type qualifiers of LIKE
00248    as well as those of TYPE.  */
00249 
00250 static tree
00251 qualify_type (tree type, tree like)
00252 {
00253   return c_build_qualified_type (type,
00254          TYPE_QUALS (type) | TYPE_QUALS (like));
00255 }
00256 
00257 /* Return true iff the given tree T is a variable length array.  */
00258 
00259 bool
00260 c_vla_type_p (tree t)
00261 {
00262   if (TREE_CODE (t) == ARRAY_TYPE
00263       && C_TYPE_VARIABLE_SIZE (t))
00264     return true;
00265   return false;
00266 }
00267 
00268 /* Return the composite type of two compatible types.
00269 
00270    We assume that comptypes has already been done and returned
00271    nonzero; if that isn't so, this may crash.  In particular, we
00272    assume that qualifiers match.  */
00273 
00274 tree
00275 composite_type (tree t1, tree t2)
00276 {
00277   enum tree_code code1;
00278   enum tree_code code2;
00279   tree attributes;
00280 
00281   /* Save time if the two types are the same.  */
00282 
00283   if (t1 == t2) return t1;
00284 
00285   /* If one type is nonsense, use the other.  */
00286   if (t1 == error_mark_node)
00287     return t2;
00288   if (t2 == error_mark_node)
00289     return t1;
00290 
00291   code1 = TREE_CODE (t1);
00292   code2 = TREE_CODE (t2);
00293 
00294   /* Merge the attributes.  */
00295   attributes = targetm.merge_type_attributes (t1, t2);
00296 
00297   /* If one is an enumerated type and the other is the compatible
00298      integer type, the composite type might be either of the two
00299      (DR#013 question 3).  For consistency, use the enumerated type as
00300      the composite type.  */
00301 
00302   if (code1 == ENUMERAL_TYPE && code2 == INTEGER_TYPE)
00303     return t1;
00304   if (code2 == ENUMERAL_TYPE && code1 == INTEGER_TYPE)
00305     return t2;
00306 
00307   gcc_assert (code1 == code2);
00308 
00309   switch (code1)
00310     {
00311     case POINTER_TYPE:
00312       /* For two pointers, do this recursively on the target type.  */
00313       {
00314   tree pointed_to_1 = TREE_TYPE (t1);
00315   tree pointed_to_2 = TREE_TYPE (t2);
00316   tree target = composite_type (pointed_to_1, pointed_to_2);
00317   t1 = build_pointer_type (target);
00318   t1 = build_type_attribute_variant (t1, attributes);
00319   return qualify_type (t1, t2);
00320       }
00321 
00322     case ARRAY_TYPE:
00323       {
00324   tree elt = composite_type (TREE_TYPE (t1), TREE_TYPE (t2));
00325   int quals;
00326   tree unqual_elt;
00327   tree d1 = TYPE_DOMAIN (t1);
00328   tree d2 = TYPE_DOMAIN (t2);
00329   bool d1_variable, d2_variable;
00330   bool d1_zero, d2_zero;
00331 
00332   /* We should not have any type quals on arrays at all.  */
00333   gcc_assert (!TYPE_QUALS (t1) && !TYPE_QUALS (t2));
00334 
00335   d1_zero = d1 == 0 || !TYPE_MAX_VALUE (d1);
00336   d2_zero = d2 == 0 || !TYPE_MAX_VALUE (d2);
00337 
00338   d1_variable = (!d1_zero
00339            && (TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST
00340          || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST));
00341   d2_variable = (!d2_zero
00342            && (TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
00343          || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST));
00344   d1_variable = d1_variable || (d1_zero && c_vla_type_p (t1));
00345   d2_variable = d2_variable || (d2_zero && c_vla_type_p (t2));
00346 
00347   /* Save space: see if the result is identical to one of the args.  */
00348   if (elt == TREE_TYPE (t1) && TYPE_DOMAIN (t1)
00349       && (d2_variable || d2_zero || !d1_variable))
00350     return build_type_attribute_variant (t1, attributes);
00351   if (elt == TREE_TYPE (t2) && TYPE_DOMAIN (t2)
00352       && (d1_variable || d1_zero || !d2_variable))
00353     return build_type_attribute_variant (t2, attributes);
00354 
00355   if (elt == TREE_TYPE (t1) && !TYPE_DOMAIN (t2) && !TYPE_DOMAIN (t1))
00356     return build_type_attribute_variant (t1, attributes);
00357   if (elt == TREE_TYPE (t2) && !TYPE_DOMAIN (t2) && !TYPE_DOMAIN (t1))
00358     return build_type_attribute_variant (t2, attributes);
00359 
00360   /* Merge the element types, and have a size if either arg has
00361      one.  We may have qualifiers on the element types.  To set
00362      up TYPE_MAIN_VARIANT correctly, we need to form the
00363      composite of the unqualified types and add the qualifiers
00364      back at the end.  */
00365   quals = TYPE_QUALS (strip_array_types (elt));
00366   unqual_elt = c_build_qualified_type (elt, TYPE_UNQUALIFIED);
00367   t1 = build_array_type (unqual_elt,
00368              TYPE_DOMAIN ((TYPE_DOMAIN (t1)
00369                && (d2_variable
00370              || d2_zero
00371              || !d1_variable))
00372               ? t1
00373               : t2));
00374   t1 = c_build_qualified_type (t1, quals);
00375   return build_type_attribute_variant (t1, attributes);
00376       }
00377 
00378     case ENUMERAL_TYPE:
00379     case RECORD_TYPE:
00380     case UNION_TYPE:
00381       if (attributes != NULL)
00382   {
00383     /* Try harder not to create a new aggregate type.  */
00384     if (attribute_list_equal (TYPE_ATTRIBUTES (t1), attributes))
00385       return t1;
00386     if (attribute_list_equal (TYPE_ATTRIBUTES (t2), attributes))
00387       return t2;
00388   }
00389       return build_type_attribute_variant (t1, attributes);
00390 
00391     case FUNCTION_TYPE:
00392       /* Function types: prefer the one that specified arg types.
00393    If both do, merge the arg types.  Also merge the return types.  */
00394       {
00395   tree valtype = composite_type (TREE_TYPE (t1), TREE_TYPE (t2));
00396   tree p1 = TYPE_ARG_TYPES (t1);
00397   tree p2 = TYPE_ARG_TYPES (t2);
00398   int len;
00399   tree newargs, n;
00400   int i;
00401 
00402   /* Save space: see if the result is identical to one of the args.  */
00403   if (valtype == TREE_TYPE (t1) && !TYPE_ARG_TYPES (t2))
00404     return build_type_attribute_variant (t1, attributes);
00405   if (valtype == TREE_TYPE (t2) && !TYPE_ARG_TYPES (t1))
00406     return build_type_attribute_variant (t2, attributes);
00407 
00408   /* Simple way if one arg fails to specify argument types.  */
00409   if (TYPE_ARG_TYPES (t1) == 0)
00410    {
00411       t1 = build_function_type (valtype, TYPE_ARG_TYPES (t2));
00412       t1 = build_type_attribute_variant (t1, attributes);
00413       return qualify_type (t1, t2);
00414    }
00415   if (TYPE_ARG_TYPES (t2) == 0)
00416    {
00417      t1 = build_function_type (valtype, TYPE_ARG_TYPES (t1));
00418      t1 = build_type_attribute_variant (t1, attributes);
00419      return qualify_type (t1, t2);
00420    }
00421 
00422   /* If both args specify argument types, we must merge the two
00423      lists, argument by argument.  */
00424   /* Tell global_bindings_p to return false so that variable_size
00425      doesn't die on VLAs in parameter types.  */
00426   c_override_global_bindings_to_false = true;
00427 
00428   len = list_length (p1);
00429   newargs = 0;
00430 
00431   for (i = 0; i < len; i++)
00432     newargs = tree_cons (NULL_TREE, NULL_TREE, newargs);
00433 
00434   n = newargs;
00435 
00436   for (; p1;
00437        p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2), n = TREE_CHAIN (n))
00438     {
00439       /* A null type means arg type is not specified.
00440          Take whatever the other function type has.  */
00441       if (TREE_VALUE (p1) == 0)
00442         {
00443     TREE_VALUE (n) = TREE_VALUE (p2);
00444     goto parm_done;
00445         }
00446       if (TREE_VALUE (p2) == 0)
00447         {
00448     TREE_VALUE (n) = TREE_VALUE (p1);
00449     goto parm_done;
00450         }
00451 
00452       /* Given  wait (union {union wait *u; int *i} *)
00453          and  wait (union wait *),
00454          prefer  union wait *  as type of parm.  */
00455       if (TREE_CODE (TREE_VALUE (p1)) == UNION_TYPE
00456     && TREE_VALUE (p1) != TREE_VALUE (p2))
00457         {
00458     tree memb;
00459     tree mv2 = TREE_VALUE (p2);
00460     if (mv2 && mv2 != error_mark_node
00461         && TREE_CODE (mv2) != ARRAY_TYPE)
00462       mv2 = TYPE_MAIN_VARIANT (mv2);
00463     for (memb = TYPE_FIELDS (TREE_VALUE (p1));
00464          memb; memb = TREE_CHAIN (memb))
00465       {
00466         tree mv3 = TREE_TYPE (memb);
00467         if (mv3 && mv3 != error_mark_node
00468       && TREE_CODE (mv3) != ARRAY_TYPE)
00469           mv3 = TYPE_MAIN_VARIANT (mv3);
00470         if (comptypes (mv3, mv2))
00471           {
00472       TREE_VALUE (n) = composite_type (TREE_TYPE (memb),
00473                TREE_VALUE (p2));
00474       if (pedantic)
00475         pedwarn ("function types not truly compatible in ISO C");
00476       goto parm_done;
00477           }
00478       }
00479         }
00480       if (TREE_CODE (TREE_VALUE (p2)) == UNION_TYPE
00481     && TREE_VALUE (p2) != TREE_VALUE (p1))
00482         {
00483     tree memb;
00484     tree mv1 = TREE_VALUE (p1);
00485     if (mv1 && mv1 != error_mark_node
00486         && TREE_CODE (mv1) != ARRAY_TYPE)
00487       mv1 = TYPE_MAIN_VARIANT (mv1);
00488     for (memb = TYPE_FIELDS (TREE_VALUE (p2));
00489          memb; memb = TREE_CHAIN (memb))
00490       {
00491         tree mv3 = TREE_TYPE (memb);
00492         if (mv3 && mv3 != error_mark_node
00493       && TREE_CODE (mv3) != ARRAY_TYPE)
00494           mv3 = TYPE_MAIN_VARIANT (mv3);
00495         if (comptypes (mv3, mv1))
00496           {
00497       TREE_VALUE (n) = composite_type (TREE_TYPE (memb),
00498                TREE_VALUE (p1));
00499       if (pedantic)
00500         pedwarn ("function types not truly compatible in ISO C");
00501       goto parm_done;
00502           }
00503       }
00504         }
00505       TREE_VALUE (n) = composite_type (TREE_VALUE (p1), TREE_VALUE (p2));
00506     parm_done: ;
00507     }
00508 
00509   c_override_global_bindings_to_false = false;
00510   t1 = build_function_type (valtype, newargs);
00511   t1 = qualify_type (t1, t2);
00512   /* ... falls through ...  */
00513       }
00514 
00515     default:
00516       return build_type_attribute_variant (t1, attributes);
00517     }
00518 
00519 }
00520 
00521 /* Return the type of a conditional expression between pointers to
00522    possibly differently qualified versions of compatible types.
00523 
00524    We assume that comp_target_types has already been done and returned
00525    nonzero; if that isn't so, this may crash.  */
00526 
00527 static tree
00528 common_pointer_type (tree t1, tree t2)
00529 {
00530   tree attributes;
00531   tree pointed_to_1, mv1;
00532   tree pointed_to_2, mv2;
00533   tree target;
00534 
00535   /* Save time if the two types are the same.  */
00536 
00537   if (t1 == t2) return t1;
00538 
00539   /* If one type is nonsense, use the other.  */
00540   if (t1 == error_mark_node)
00541     return t2;
00542   if (t2 == error_mark_node)
00543     return t1;
00544 
00545   gcc_assert (TREE_CODE (t1) == POINTER_TYPE
00546         && TREE_CODE (t2) == POINTER_TYPE);
00547 
00548   /* Merge the attributes.  */
00549   attributes = targetm.merge_type_attributes (t1, t2);
00550 
00551   /* Find the composite type of the target types, and combine the
00552      qualifiers of the two types' targets.  Do not lose qualifiers on
00553      array element types by taking the TYPE_MAIN_VARIANT.  */
00554   mv1 = pointed_to_1 = TREE_TYPE (t1);
00555   mv2 = pointed_to_2 = TREE_TYPE (t2);
00556   if (TREE_CODE (mv1) != ARRAY_TYPE)
00557     mv1 = TYPE_MAIN_VARIANT (pointed_to_1);
00558   if (TREE_CODE (mv2) != ARRAY_TYPE)
00559     mv2 = TYPE_MAIN_VARIANT (pointed_to_2);
00560   target = composite_type (mv1, mv2);
00561   t1 = build_pointer_type (c_build_qualified_type
00562          (target,
00563           TYPE_QUALS (pointed_to_1) |
00564           TYPE_QUALS (pointed_to_2)));
00565   return build_type_attribute_variant (t1, attributes);
00566 }
00567 
00568 /* Return the common type for two arithmetic types under the usual
00569    arithmetic conversions.  The default conversions have already been
00570    applied, and enumerated types converted to their compatible integer
00571    types.  The resulting type is unqualified and has no attributes.
00572 
00573    This is the type for the result of most arithmetic operations
00574    if the operands have the given two types.  */
00575 
00576 static tree
00577 c_common_type (tree t1, tree t2)
00578 {
00579   enum tree_code code1;
00580   enum tree_code code2;
00581 
00582   /* If one type is nonsense, use the other.  */
00583   if (t1 == error_mark_node)
00584     return t2;
00585   if (t2 == error_mark_node)
00586     return t1;
00587 
00588   if (TYPE_QUALS (t1) != TYPE_UNQUALIFIED)
00589     t1 = TYPE_MAIN_VARIANT (t1);
00590 
00591   if (TYPE_QUALS (t2) != TYPE_UNQUALIFIED)
00592     t2 = TYPE_MAIN_VARIANT (t2);
00593 
00594   if (TYPE_ATTRIBUTES (t1) != NULL_TREE)
00595     t1 = build_type_attribute_variant (t1, NULL_TREE);
00596 
00597   if (TYPE_ATTRIBUTES (t2) != NULL_TREE)
00598     t2 = build_type_attribute_variant (t2, NULL_TREE);
00599 
00600   /* Save time if the two types are the same.  */
00601 
00602   if (t1 == t2) return t1;
00603 
00604   code1 = TREE_CODE (t1);
00605   code2 = TREE_CODE (t2);
00606 
00607   gcc_assert (code1 == VECTOR_TYPE || code1 == COMPLEX_TYPE
00608         || code1 == REAL_TYPE || code1 == INTEGER_TYPE);
00609   gcc_assert (code2 == VECTOR_TYPE || code2 == COMPLEX_TYPE
00610         || code2 == REAL_TYPE || code2 == INTEGER_TYPE);
00611 
00612   /* When one operand is a decimal float type, the other operand cannot be
00613      a generic float type or a complex type.  We also disallow vector types
00614      here.  */
00615   if ((DECIMAL_FLOAT_TYPE_P (t1) || DECIMAL_FLOAT_TYPE_P (t2))
00616       && !(DECIMAL_FLOAT_TYPE_P (t1) && DECIMAL_FLOAT_TYPE_P (t2)))
00617     {
00618       if (code1 == VECTOR_TYPE || code2 == VECTOR_TYPE)
00619   {
00620     error ("can%'t mix operands of decimal float and vector types");
00621     return error_mark_node;
00622   }
00623       if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE)
00624   {
00625     error ("can%'t mix operands of decimal float and complex types");
00626     return error_mark_node;
00627   }
00628       if (code1 == REAL_TYPE && code2 == REAL_TYPE)
00629   {
00630     error ("can%'t mix operands of decimal float and other float types");
00631     return error_mark_node;
00632   }
00633     }
00634 
00635   /* If one type is a vector type, return that type.  (How the usual
00636      arithmetic conversions apply to the vector types extension is not
00637      precisely specified.)  */
00638   if (code1 == VECTOR_TYPE)
00639     return t1;
00640 
00641   if (code2 == VECTOR_TYPE)
00642     return t2;
00643 
00644   /* If one type is complex, form the common type of the non-complex
00645      components, then make that complex.  Use T1 or T2 if it is the
00646      required type.  */
00647   if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE)
00648     {
00649       tree subtype1 = code1 == COMPLEX_TYPE ? TREE_TYPE (t1) : t1;
00650       tree subtype2 = code2 == COMPLEX_TYPE ? TREE_TYPE (t2) : t2;
00651       tree subtype = c_common_type (subtype1, subtype2);
00652 
00653       if (code1 == COMPLEX_TYPE && TREE_TYPE (t1) == subtype)
00654   return t1;
00655       else if (code2 == COMPLEX_TYPE && TREE_TYPE (t2) == subtype)
00656   return t2;
00657       else
00658   return build_complex_type (subtype);
00659     }
00660 
00661   /* If only one is real, use it as the result.  */
00662 
00663   if (code1 == REAL_TYPE && code2 != REAL_TYPE)
00664     return t1;
00665 
00666   if (code2 == REAL_TYPE && code1 != REAL_TYPE)
00667     return t2;
00668 
00669   /* If both are real and either are decimal floating point types, use
00670      the decimal floating point type with the greater precision. */
00671 
00672   if (code1 == REAL_TYPE && code2 == REAL_TYPE)
00673     {
00674       if (TYPE_MAIN_VARIANT (t1) == dfloat128_type_node
00675     || TYPE_MAIN_VARIANT (t2) == dfloat128_type_node)
00676   return dfloat128_type_node;
00677       else if (TYPE_MAIN_VARIANT (t1) == dfloat64_type_node
00678          || TYPE_MAIN_VARIANT (t2) == dfloat64_type_node)
00679   return dfloat64_type_node;
00680       else if (TYPE_MAIN_VARIANT (t1) == dfloat32_type_node
00681          || TYPE_MAIN_VARIANT (t2) == dfloat32_type_node)
00682   return dfloat32_type_node;
00683     }
00684 
00685   /* Both real or both integers; use the one with greater precision.  */
00686 
00687   if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2))
00688     return t1;
00689   else if (TYPE_PRECISION (t2) > TYPE_PRECISION (t1))
00690     return t2;
00691 
00692   /* Same precision.  Prefer long longs to longs to ints when the
00693      same precision, following the C99 rules on integer type rank
00694      (which are equivalent to the C90 rules for C90 types).  */
00695 
00696   if (TYPE_MAIN_VARIANT (t1) == long_long_unsigned_type_node
00697       || TYPE_MAIN_VARIANT (t2) == long_long_unsigned_type_node)
00698     return long_long_unsigned_type_node;
00699 
00700   if (TYPE_MAIN_VARIANT (t1) == long_long_integer_type_node
00701       || TYPE_MAIN_VARIANT (t2) == long_long_integer_type_node)
00702     {
00703       if (TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
00704   return long_long_unsigned_type_node;
00705       else
00706   return long_long_integer_type_node;
00707     }
00708 
00709   if (TYPE_MAIN_VARIANT (t1) == long_unsigned_type_node
00710       || TYPE_MAIN_VARIANT (t2) == long_unsigned_type_node)
00711     return long_unsigned_type_node;
00712 
00713   if (TYPE_MAIN_VARIANT (t1) == long_integer_type_node
00714       || TYPE_MAIN_VARIANT (t2) == long_integer_type_node)
00715     {
00716       /* But preserve unsignedness from the other type,
00717    since long cannot hold all the values of an unsigned int.  */
00718       if (TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
00719   return long_unsigned_type_node;
00720       else
00721   return long_integer_type_node;
00722     }
00723 
00724   /* Likewise, prefer long double to double even if same size.  */
00725   if (TYPE_MAIN_VARIANT (t1) == long_double_type_node
00726       || TYPE_MAIN_VARIANT (t2) == long_double_type_node)
00727     return long_double_type_node;
00728 
00729   /* Otherwise prefer the unsigned one.  */
00730 
00731   if (TYPE_UNSIGNED (t1))
00732     return t1;
00733   else
00734     return t2;
00735 }
00736 
00737 /* Wrapper around c_common_type that is used by c-common.c and other
00738    front end optimizations that remove promotions.  ENUMERAL_TYPEs
00739    are allowed here and are converted to their compatible integer types.
00740    BOOLEAN_TYPEs are allowed here and return either boolean_type_node or
00741    preferably a non-Boolean type as the common type.  */
00742 tree
00743 common_type (tree t1, tree t2)
00744 {
00745   if (TREE_CODE (t1) == ENUMERAL_TYPE)
00746     t1 = c_common_type_for_size (TYPE_PRECISION (t1), 1);
00747   if (TREE_CODE (t2) == ENUMERAL_TYPE)
00748     t2 = c_common_type_for_size (TYPE_PRECISION (t2), 1);
00749 
00750   /* If both types are BOOLEAN_TYPE, then return boolean_type_node.  */
00751   if (TREE_CODE (t1) == BOOLEAN_TYPE
00752       && TREE_CODE (t2) == BOOLEAN_TYPE)
00753     return boolean_type_node;
00754 
00755   /* If either type is BOOLEAN_TYPE, then return the other.  */
00756   if (TREE_CODE (t1) == BOOLEAN_TYPE)
00757     return t2;
00758   if (TREE_CODE (t2) == BOOLEAN_TYPE)
00759     return t1;
00760 
00761   return c_common_type (t1, t2);
00762 }
00763 
00764 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
00765    or various other operations.  Return 2 if they are compatible
00766    but a warning may be needed if you use them together.  */
00767 
00768 int
00769 comptypes (tree type1, tree type2)
00770 {
00771   const struct tagged_tu_seen_cache * tagged_tu_seen_base1 = tagged_tu_seen_base;
00772   int val;
00773 
00774   val = comptypes_internal (type1, type2);
00775   free_all_tagged_tu_seen_up_to (tagged_tu_seen_base1);
00776 
00777   return val;
00778 }
00779 
00780 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
00781    or various other operations.  Return 2 if they are compatible
00782    but a warning may be needed if you use them together.  This
00783    differs from comptypes, in that we don't free the seen types.  */
00784 
00785 static int
00786 comptypes_internal (tree type1, tree type2)
00787 {
00788   tree t1 = type1;
00789   tree t2 = type2;
00790   int attrval, val;
00791 
00792   /* Suppress errors caused by previously reported errors.  */
00793 
00794   if (t1 == t2 || !t1 || !t2
00795       || TREE_CODE (t1) == ERROR_MARK || TREE_CODE (t2) == ERROR_MARK)
00796     return 1;
00797 
00798   /* If either type is the internal version of sizetype, return the
00799      language version.  */
00800   if (TREE_CODE (t1) == INTEGER_TYPE && TYPE_IS_SIZETYPE (t1)
00801       && TYPE_ORIG_SIZE_TYPE (t1))
00802     t1 = TYPE_ORIG_SIZE_TYPE (t1);
00803 
00804   if (TREE_CODE (t2) == INTEGER_TYPE && TYPE_IS_SIZETYPE (t2)
00805       && TYPE_ORIG_SIZE_TYPE (t2))
00806     t2 = TYPE_ORIG_SIZE_TYPE (t2);
00807 
00808 
00809   /* Enumerated types are compatible with integer types, but this is
00810      not transitive: two enumerated types in the same translation unit
00811      are compatible with each other only if they are the same type.  */
00812 
00813   if (TREE_CODE (t1) == ENUMERAL_TYPE && TREE_CODE (t2) != ENUMERAL_TYPE)
00814     t1 = c_common_type_for_size (TYPE_PRECISION (t1), TYPE_UNSIGNED (t1));
00815   else if (TREE_CODE (t2) == ENUMERAL_TYPE && TREE_CODE (t1) != ENUMERAL_TYPE)
00816     t2 = c_common_type_for_size (TYPE_PRECISION (t2), TYPE_UNSIGNED (t2));
00817 
00818   if (t1 == t2)
00819     return 1;
00820 
00821   /* Different classes of types can't be compatible.  */
00822 
00823   if (TREE_CODE (t1) != TREE_CODE (t2))
00824     return 0;
00825 
00826   /* Qualifiers must match. C99 6.7.3p9 */
00827 
00828   if (TYPE_QUALS (t1) != TYPE_QUALS (t2))
00829     return 0;
00830 
00831   /* Allow for two different type nodes which have essentially the same
00832      definition.  Note that we already checked for equality of the type
00833      qualifiers (just above).  */
00834 
00835   if (TREE_CODE (t1) != ARRAY_TYPE
00836       && TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
00837     return 1;
00838 
00839   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
00840   if (!(attrval = targetm.comp_type_attributes (t1, t2)))
00841      return 0;
00842 
00843   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
00844   val = 0;
00845 
00846   switch (TREE_CODE (t1))
00847     {
00848     case POINTER_TYPE:
00849       /* Do not remove mode or aliasing information.  */
00850       if (TYPE_MODE (t1) != TYPE_MODE (t2)
00851     || TYPE_REF_CAN_ALIAS_ALL (t1) != TYPE_REF_CAN_ALIAS_ALL (t2))
00852   break;
00853       val = (TREE_TYPE (t1) == TREE_TYPE (t2)
00854        ? 1 : comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2)));
00855       break;
00856 
00857     case FUNCTION_TYPE:
00858       val = function_types_compatible_p (t1, t2);
00859       break;
00860 
00861     case ARRAY_TYPE:
00862       {
00863   tree d1 = TYPE_DOMAIN (t1);
00864   tree d2 = TYPE_DOMAIN (t2);
00865   bool d1_variable, d2_variable;
00866   bool d1_zero, d2_zero;
00867   val = 1;
00868 
00869   /* Target types must match incl. qualifiers.  */
00870   if (TREE_TYPE (t1) != TREE_TYPE (t2)
00871       && 0 == (val = comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2))))
00872     return 0;
00873 
00874   /* Sizes must match unless one is missing or variable.  */
00875   if (d1 == 0 || d2 == 0 || d1 == d2)
00876     break;
00877 
00878   d1_zero = !TYPE_MAX_VALUE (d1);
00879   d2_zero = !TYPE_MAX_VALUE (d2);
00880 
00881   d1_variable = (!d1_zero
00882            && (TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST
00883          || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST));
00884   d2_variable = (!d2_zero
00885            && (TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
00886          || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST));
00887   d1_variable = d1_variable || (d1_zero && c_vla_type_p (t1));
00888   d2_variable = d2_variable || (d2_zero && c_vla_type_p (t2));
00889 
00890   if (d1_variable || d2_variable)
00891     break;
00892   if (d1_zero && d2_zero)
00893     break;
00894   if (d1_zero || d2_zero
00895       || !tree_int_cst_equal (TYPE_MIN_VALUE (d1), TYPE_MIN_VALUE (d2))
00896       || !tree_int_cst_equal (TYPE_MAX_VALUE (d1), TYPE_MAX_VALUE (d2)))
00897     val = 0;
00898 
00899   break;
00900       }
00901 
00902     case ENUMERAL_TYPE:
00903     case RECORD_TYPE:
00904     case UNION_TYPE:
00905       if (val != 1 && !same_translation_unit_p (t1, t2))
00906   {
00907     tree a1 = TYPE_ATTRIBUTES (t1);
00908     tree a2 = TYPE_ATTRIBUTES (t2);
00909 
00910     if (! attribute_list_contained (a1, a2)
00911         && ! attribute_list_contained (a2, a1))
00912       break;
00913 
00914     if (attrval != 2)
00915       return tagged_types_tu_compatible_p (t1, t2);
00916     val = tagged_types_tu_compatible_p (t1, t2);
00917   }
00918       break;
00919 
00920     case VECTOR_TYPE:
00921       val = TYPE_VECTOR_SUBPARTS (t1) == TYPE_VECTOR_SUBPARTS (t2)
00922       && comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2));
00923       break;
00924 
00925     default:
00926       break;
00927     }
00928   return attrval == 2 && val == 1 ? 2 : val;
00929 }
00930 
00931 /* Return 1 if TTL and TTR are pointers to types that are equivalent,
00932    ignoring their qualifiers.  */
00933 
00934 static int
00935 comp_target_types (tree ttl, tree ttr)
00936 {
00937   int val;
00938   tree mvl, mvr;
00939 
00940   /* Do not lose qualifiers on element types of array types that are
00941      pointer targets by taking their TYPE_MAIN_VARIANT.  */
00942   mvl = TREE_TYPE (ttl);
00943   mvr = TREE_TYPE (ttr);
00944   if (TREE_CODE (mvl) != ARRAY_TYPE)
00945     mvl = TYPE_MAIN_VARIANT (mvl);
00946   if (TREE_CODE (mvr) != ARRAY_TYPE)
00947     mvr = TYPE_MAIN_VARIANT (mvr);
00948   val = comptypes (mvl, mvr);
00949 
00950   if (val == 2 && pedantic)
00951     pedwarn ("types are not quite compatible");
00952   return val;
00953 }
00954 
00955 /* Subroutines of `comptypes'.  */
00956 
00957 /* Determine whether two trees derive from the same translation unit.
00958    If the CONTEXT chain ends in a null, that tree's context is still
00959    being parsed, so if two trees have context chains ending in null,
00960    they're in the same translation unit.  */
00961 int
00962 same_translation_unit_p (tree t1, tree t2)
00963 {
00964   while (t1 && TREE_CODE (t1) != TRANSLATION_UNIT_DECL)
00965     switch (TREE_CODE_CLASS (TREE_CODE (t1)))
00966       {
00967       case tcc_declaration:
00968   t1 = DECL_CONTEXT (t1); break;
00969       case tcc_type:
00970   t1 = TYPE_CONTEXT (t1); break;
00971       case tcc_exceptional:
00972   t1 = BLOCK_SUPERCONTEXT (t1); break;  /* assume block */
00973       default: gcc_unreachable ();
00974       }
00975 
00976   while (t2 && TREE_CODE (t2) != TRANSLATION_UNIT_DECL)
00977     switch (TREE_CODE_CLASS (TREE_CODE (t2)))
00978       {
00979       case tcc_declaration:
00980   t2 = DECL_CONTEXT (t2); break;
00981       case tcc_type:
00982   t2 = TYPE_CONTEXT (t2); break;
00983       case tcc_exceptional:
00984   t2 = BLOCK_SUPERCONTEXT (t2); break;  /* assume block */
00985       default: gcc_unreachable ();
00986       }
00987 
00988   return t1 == t2;
00989 }
00990 
00991 /* Allocate the seen two types, assuming that they are compatible. */
00992 
00993 static struct tagged_tu_seen_cache *
00994 alloc_tagged_tu_seen_cache (tree t1, tree t2)
00995 {
00996   struct tagged_tu_seen_cache *tu = XNEW (struct tagged_tu_seen_cache);
00997   tu->next = tagged_tu_seen_base;
00998   tu->t1 = t1;
00999   tu->t2 = t2;
01000 
01001   tagged_tu_seen_base = tu;
01002 
01003   /* The C standard says that two structures in different translation
01004      units are compatible with each other only if the types of their
01005      fields are compatible (among other things).  We assume that they
01006      are compatible until proven otherwise when building the cache.
01007      An example where this can occur is:
01008      struct a
01009      {
01010        struct a *next;
01011      };
01012      If we are comparing this against a similar struct in another TU,
01013      and did not assume they were compatible, we end up with an infinite
01014      loop.  */
01015   tu->val = 1;
01016   return tu;
01017 }
01018 
01019 /* Free the seen types until we get to TU_TIL. */
01020 
01021 static void
01022 free_all_tagged_tu_seen_up_to (const struct tagged_tu_seen_cache *tu_til)
01023 {
01024   const struct tagged_tu_seen_cache *tu = tagged_tu_seen_base;
01025   while (tu != tu_til)
01026     {
01027       struct tagged_tu_seen_cache *tu1 = (struct tagged_tu_seen_cache*)tu;
01028       tu = tu1->next;
01029       free (tu1);
01030     }
01031   tagged_tu_seen_base = tu_til;
01032 }
01033 
01034 /* Return 1 if two 'struct', 'union', or 'enum' types T1 and T2 are
01035    compatible.  If the two types are not the same (which has been
01036    checked earlier), this can only happen when multiple translation
01037    units are being compiled.  See C99 6.2.7 paragraph 1 for the exact
01038    rules.  */
01039 
01040 static int
01041 tagged_types_tu_compatible_p (tree t1, tree t2)
01042 {
01043   tree s1, s2;
01044   bool needs_warning = false;
01045 
01046   /* We have to verify that the tags of the types are the same.  This
01047      is harder than it looks because this may be a typedef, so we have
01048      to go look at the original type.  It may even be a typedef of a
01049      typedef...
01050      In the case of compiler-created builtin structs the TYPE_DECL
01051      may be a dummy, with no DECL_ORIGINAL_TYPE.  Don't fault.  */
01052   while (TYPE_NAME (t1)
01053    && TREE_CODE (TYPE_NAME (t1)) == TYPE_DECL
01054    && DECL_ORIGINAL_TYPE (TYPE_NAME (t1)))
01055     t1 = DECL_ORIGINAL_TYPE (TYPE_NAME (t1));
01056 
01057   while (TYPE_NAME (t2)
01058    && TREE_CODE (TYPE_NAME (t2)) == TYPE_DECL
01059    && DECL_ORIGINAL_TYPE (TYPE_NAME (t2)))
01060     t2 = DECL_ORIGINAL_TYPE (TYPE_NAME (t2));
01061 
01062   /* C90 didn't have the requirement that the two tags be the same.  */
01063   if (flag_isoc99 && TYPE_NAME (t1) != TYPE_NAME (t2))
01064     return 0;
01065 
01066   /* C90 didn't say what happened if one or both of the types were
01067      incomplete; we choose to follow C99 rules here, which is that they
01068      are compatible.  */
01069   if (TYPE_SIZE (t1) == NULL
01070       || TYPE_SIZE (t2) == NULL)
01071     return 1;
01072 
01073   {
01074     const struct tagged_tu_seen_cache * tts_i;
01075     for (tts_i = tagged_tu_seen_base; tts_i != NULL; tts_i = tts_i->next)
01076       if (tts_i->t1 == t1 && tts_i->t2 == t2)
01077   return tts_i->val;
01078   }
01079 
01080   switch (TREE_CODE (t1))
01081     {
01082     case ENUMERAL_TYPE:
01083       {
01084   struct tagged_tu_seen_cache *tu = alloc_tagged_tu_seen_cache (t1, t2);
01085   /* Speed up the case where the type values are in the same order.  */
01086   tree tv1 = TYPE_VALUES (t1);
01087   tree tv2 = TYPE_VALUES (t2);
01088 
01089   if (tv1 == tv2)
01090     {
01091       return 1;
01092     }
01093 
01094   for (;tv1 && tv2; tv1 = TREE_CHAIN (tv1), tv2 = TREE_CHAIN (tv2))
01095     {
01096       if (TREE_PURPOSE (tv1) != TREE_PURPOSE (tv2))
01097         break;
01098       if (simple_cst_equal (TREE_VALUE (tv1), TREE_VALUE (tv2)) != 1)
01099         {
01100     tu->val = 0;
01101     return 0;
01102         }
01103     }
01104 
01105   if (tv1 == NULL_TREE && tv2 == NULL_TREE)
01106     {
01107       return 1;
01108     }
01109   if (tv1 == NULL_TREE || tv2 == NULL_TREE)
01110     {
01111       tu->val = 0;
01112       return 0;
01113     }
01114 
01115   if (list_length (TYPE_VALUES (t1)) != list_length (TYPE_VALUES (t2)))
01116     {
01117       tu->val = 0;
01118       return 0;
01119     }
01120 
01121   for (s1 = TYPE_VALUES (t1); s1; s1 = TREE_CHAIN (s1))
01122     {
01123       s2 = purpose_member (TREE_PURPOSE (s1), TYPE_VALUES (t2));
01124       if (s2 == NULL
01125     || simple_cst_equal (TREE_VALUE (s1), TREE_VALUE (s2)) != 1)
01126         {
01127     tu->val = 0;
01128     return 0;
01129         }
01130     }
01131   return 1;
01132       }
01133 
01134     case UNION_TYPE:
01135       {
01136   struct tagged_tu_seen_cache *tu = alloc_tagged_tu_seen_cache (t1, t2);
01137   if (list_length (TYPE_FIELDS (t1)) != list_length (TYPE_FIELDS (t2)))
01138     {
01139       tu->val = 0;
01140       return 0;
01141     }
01142 
01143   /*  Speed up the common case where the fields are in the same order. */
01144   for (s1 = TYPE_FIELDS (t1), s2 = TYPE_FIELDS (t2); s1 && s2;
01145        s1 = TREE_CHAIN (s1), s2 = TREE_CHAIN (s2))
01146     {
01147       int result;
01148 
01149 
01150       if (DECL_NAME (s1) == NULL
01151     || DECL_NAME (s1) != DECL_NAME (s2))
01152         break;
01153       result = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2));
01154       if (result == 0)
01155         {
01156     tu->val = 0;
01157     return 0;
01158         }
01159       if (result == 2)
01160         needs_warning = true;
01161 
01162       if (TREE_CODE (s1) == FIELD_DECL
01163     && simple_cst_equal (DECL_FIELD_BIT_OFFSET (s1),
01164              DECL_FIELD_BIT_OFFSET (s2)) != 1)
01165         {
01166     tu->val = 0;
01167     return 0;
01168         }
01169     }
01170   if (!s1 && !s2)
01171     {
01172       tu->val = needs_warning ? 2 : 1;
01173       return tu->val;
01174     }
01175 
01176   for (s1 = TYPE_FIELDS (t1); s1; s1 = TREE_CHAIN (s1))
01177     {
01178       bool ok = false;
01179 
01180       if (DECL_NAME (s1) != NULL)
01181         for (s2 = TYPE_FIELDS (t2); s2; s2 = TREE_CHAIN (s2))
01182     if (DECL_NAME (s1) == DECL_NAME (s2))
01183       {
01184         int result;
01185         result = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2));
01186         if (result == 0)
01187           {
01188       tu->val = 0;
01189       return 0;
01190           }
01191         if (result == 2)
01192           needs_warning = true;
01193 
01194         if (TREE_CODE (s1) == FIELD_DECL
01195       && simple_cst_equal (DECL_FIELD_BIT_OFFSET (s1),
01196                DECL_FIELD_BIT_OFFSET (s2)) != 1)
01197           break;
01198 
01199         ok = true;
01200         break;
01201       }
01202       if (!ok)
01203         {
01204     tu->val = 0;
01205     return 0;
01206         }
01207     }
01208   tu->val = needs_warning ? 2 : 10;
01209   return tu->val;
01210       }
01211 
01212     case RECORD_TYPE:
01213       {
01214   struct tagged_tu_seen_cache *tu = alloc_tagged_tu_seen_cache (t1, t2);
01215 
01216   for (s1 = TYPE_FIELDS (t1), s2 = TYPE_FIELDS (t2);
01217        s1 && s2;
01218        s1 = TREE_CHAIN (s1), s2 = TREE_CHAIN (s2))
01219     {
01220       int result;
01221       if (TREE_CODE (s1) != TREE_CODE (s2)
01222     || DECL_NAME (s1) != DECL_NAME (s2))
01223         break;
01224       result = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2));
01225       if (result == 0)
01226         break;
01227       if (result == 2)
01228         needs_warning = true;
01229 
01230       if (TREE_CODE (s1) == FIELD_DECL
01231     && simple_cst_equal (DECL_FIELD_BIT_OFFSET (s1),
01232              DECL_FIELD_BIT_OFFSET (s2)) != 1)
01233         break;
01234     }
01235   if (s1 && s2)
01236     tu->val = 0;
01237   else
01238     tu->val = needs_warning ? 2 : 1;
01239   return tu->val;
01240       }
01241 
01242     default:
01243       gcc_unreachable ();
01244     }
01245 }
01246 
01247 /* Return 1 if two function types F1 and F2 are compatible.
01248    If either type specifies no argument types,
01249    the other must specify a fixed number of self-promoting arg types.
01250    Otherwise, if one type specifies only the number of arguments,
01251    the other must specify that number of self-promoting arg types.
01252    Otherwise, the argument types must match.  */
01253 
01254 static int
01255 function_types_compatible_p (tree f1, tree f2)
01256 {
01257   tree args1, args2;
01258   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
01259   int val = 1;
01260   int val1;
01261   tree ret1, ret2;
01262 
01263   ret1 = TREE_TYPE (f1);
01264   ret2 = TREE_TYPE (f2);
01265 
01266   /* 'volatile' qualifiers on a function's return type used to mean
01267      the function is noreturn.  */
01268   if (TYPE_VOLATILE (ret1) != TYPE_VOLATILE (ret2))
01269     pedwarn ("function return types not compatible due to %<volatile%>");
01270   if (TYPE_VOLATILE (ret1))
01271     ret1 = build_qualified_type (TYPE_MAIN_VARIANT (ret1),
01272          TYPE_QUALS (ret1) & ~TYPE_QUAL_VOLATILE);
01273   if (TYPE_VOLATILE (ret2))
01274     ret2 = build_qualified_type (TYPE_MAIN_VARIANT (ret2),
01275          TYPE_QUALS (ret2) & ~TYPE_QUAL_VOLATILE);
01276   val = comptypes_internal (ret1, ret2);
01277   if (val == 0)
01278     return 0;
01279 
01280   args1 = TYPE_ARG_TYPES (f1);
01281   args2 = TYPE_ARG_TYPES (f2);
01282 
01283   /* An unspecified parmlist matches any specified parmlist
01284      whose argument types don't need default promotions.  */
01285 
01286   if (args1 == 0)
01287     {
01288       if (!self_promoting_args_p (args2))
01289   return 0;
01290       /* If one of these types comes from a non-prototype fn definition,
01291    compare that with the other type's arglist.
01292    If they don't match, ask for a warning (but no error).  */
01293       if (TYPE_ACTUAL_ARG_TYPES (f1)
01294     && 1 != type_lists_compatible_p (args2, TYPE_ACTUAL_ARG_TYPES (f1)))
01295   val = 2;
01296       return val;
01297     }
01298   if (args2 == 0)
01299     {
01300       if (!self_promoting_args_p (args1))
01301   return 0;
01302       if (TYPE_ACTUAL_ARG_TYPES (f2)
01303     && 1 != type_lists_compatible_p (args1, TYPE_ACTUAL_ARG_TYPES (f2)))
01304   val = 2;
01305       return val;
01306     }
01307 
01308   /* Both types have argument lists: compare them and propagate results.  */
01309   val1 = type_lists_compatible_p (args1, args2);
01310   return val1 != 1 ? val1 : val;
01311 }
01312 
01313 /* Check two lists of types for compatibility,
01314    returning 0 for incompatible, 1 for compatible,
01315    or 2 for compatible with warning.  */
01316 
01317 static int
01318 type_lists_compatible_p (tree args1, tree args2)
01319 {
01320   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
01321   int val = 1;
01322   int newval = 0;
01323 
01324   while (1)
01325     {
01326       tree a1, mv1, a2, mv2;
01327       if (args1 == 0 && args2 == 0)
01328   return val;
01329       /* If one list is shorter than the other,
01330    they fail to match.  */
01331       if (args1 == 0 || args2 == 0)
01332   return 0;
01333       mv1 = a1 = TREE_VALUE (args1);
01334       mv2 = a2 = TREE_VALUE (args2);
01335       if (mv1 && mv1 != error_mark_node && TREE_CODE (mv1) != ARRAY_TYPE)
01336   mv1 = TYPE_MAIN_VARIANT (mv1);
01337       if (mv2 && mv2 != error_mark_node && TREE_CODE (mv2) != ARRAY_TYPE)
01338   mv2 = TYPE_MAIN_VARIANT (mv2);
01339       /* A null pointer instead of a type
01340    means there is supposed to be an argument
01341    but nothing is specified about what type it has.
01342    So match anything that self-promotes.  */
01343       if (a1 == 0)
01344   {
01345     if (c_type_promotes_to (a2) != a2)
01346       return 0;
01347   }
01348       else if (a2 == 0)
01349   {
01350     if (c_type_promotes_to (a1) != a1)
01351       return 0;
01352   }
01353       /* If one of the lists has an error marker, ignore this arg.  */
01354       else if (TREE_CODE (a1) == ERROR_MARK
01355          || TREE_CODE (a2) == ERROR_MARK)
01356   ;
01357       else if (!(newval = comptypes_internal (mv1, mv2)))
01358   {
01359     /* Allow  wait (union {union wait *u; int *i} *)
01360        and  wait (union wait *)  to be compatible.  */
01361     if (TREE_CODE (a1) == UNION_TYPE
01362         && (TYPE_NAME (a1) == 0
01363       || TYPE_TRANSPARENT_UNION (a1))
01364         && TREE_CODE (TYPE_SIZE (a1)) == INTEGER_CST
01365         && tree_int_cst_equal (TYPE_SIZE (a1),
01366              TYPE_SIZE (a2)))
01367       {
01368         tree memb;
01369         for (memb = TYPE_FIELDS (a1);
01370        memb; memb = TREE_CHAIN (memb))
01371     {
01372       tree mv3 = TREE_TYPE (memb);
01373       if (mv3 && mv3 != error_mark_node
01374           && TREE_CODE (mv3) != ARRAY_TYPE)
01375         mv3 = TYPE_MAIN_VARIANT (mv3);
01376       if (comptypes_internal (mv3, mv2))
01377         break;
01378     }
01379         if (memb == 0)
01380     return 0;
01381       }
01382     else if (TREE_CODE (a2) == UNION_TYPE
01383        && (TYPE_NAME (a2) == 0
01384            || TYPE_TRANSPARENT_UNION (a2))
01385        && TREE_CODE (TYPE_SIZE (a2)) == INTEGER_CST
01386        && tree_int_cst_equal (TYPE_SIZE (a2),
01387             TYPE_SIZE (a1)))
01388       {
01389         tree memb;
01390         for (memb = TYPE_FIELDS (a2);
01391        memb; memb = TREE_CHAIN (memb))
01392     {
01393       tree mv3 = TREE_TYPE (memb);
01394       if (mv3 && mv3 != error_mark_node
01395           && TREE_CODE (mv3) != ARRAY_TYPE)
01396         mv3 = TYPE_MAIN_VARIANT (mv3);
01397       if (comptypes_internal (mv3, mv1))
01398         break;
01399     }
01400         if (memb == 0)
01401     return 0;
01402       }
01403     else
01404       return 0;
01405   }
01406 
01407       /* comptypes said ok, but record if it said to warn.  */
01408       if (newval > val)
01409   val = newval;
01410 
01411       args1 = TREE_CHAIN (args1);
01412       args2 = TREE_CHAIN (args2);
01413     }
01414 }
01415 
01416 /* Compute the size to increment a pointer by.  */
01417 
01418 static tree
01419 c_size_in_bytes (tree type)
01420 {
01421   enum tree_code code = TREE_CODE (type);
01422 
01423   if (code == FUNCTION_TYPE || code == VOID_TYPE || code == ERROR_MARK)
01424     return size_one_node;
01425 
01426   if (!COMPLETE_OR_VOID_TYPE_P (type))
01427     {
01428       error ("arithmetic on pointer to an incomplete type");
01429       return size_one_node;
01430     }
01431 
01432   /* Convert in case a char is more than one unit.  */
01433   return size_binop (CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
01434          size_int (TYPE_PRECISION (char_type_node)
01435              / BITS_PER_UNIT));
01436 }
01437 
01438 /* Return either DECL or its known constant value (if it has one).  */
01439 
01440 tree
01441 decl_constant_value (tree decl)
01442 {
01443   if (/* Don't change a variable array bound or initial value to a constant
01444    in a place where a variable is invalid.  Note that DECL_INITIAL
01445    isn't valid for a PARM_DECL.  */
01446       current_function_decl != 0
01447       && TREE_CODE (decl) != PARM_DECL
01448       && !TREE_THIS_VOLATILE (decl)
01449       && TREE_READONLY (decl)
01450       && DECL_INITIAL (decl) != 0
01451       && TREE_CODE (DECL_INITIAL (decl)) != ERROR_MARK
01452       /* This is invalid if initial value is not constant.
01453    If it has either a function call, a memory reference,
01454    or a variable, then re-evaluating it could give different results.  */
01455       && TREE_CONSTANT (DECL_INITIAL (decl))
01456       /* Check for cases where this is sub-optimal, even though valid.  */
01457       && TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR)
01458     return DECL_INITIAL (decl);
01459   return decl;
01460 }
01461 
01462 /* Return either DECL or its known constant value (if it has one), but
01463    return DECL if pedantic or DECL has mode BLKmode.  This is for
01464    bug-compatibility with the old behavior of decl_constant_value
01465    (before GCC 3.0); every use of this function is a bug and it should
01466    be removed before GCC 3.1.  It is not appropriate to use pedantic
01467    in a way that affects optimization, and BLKmode is probably not the
01468    right test for avoiding misoptimizations either.  */
01469 
01470 static tree
01471 decl_constant_value_for_broken_optimization (tree decl)
01472 {
01473   tree ret;
01474 
01475   if (pedantic || DECL_MODE (decl) == BLKmode)
01476     return decl;
01477 
01478   ret = decl_constant_value (decl);
01479   /* Avoid unwanted tree sharing between the initializer and current
01480      function's body where the tree can be modified e.g. by the
01481      gimplifier.  */
01482   if (ret != decl && TREE_STATIC (decl))
01483     ret = unshare_expr (ret);
01484   return ret;
01485 }
01486 
01487 /* Convert the array expression EXP to a pointer.  */
01488 static tree
01489 array_to_pointer_conversion (tree exp)
01490 {
01491   tree orig_exp = exp;
01492   tree type = TREE_TYPE (exp);
01493   tree adr;
01494   tree restype = TREE_TYPE (type);
01495   tree ptrtype;
01496 
01497   gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
01498 
01499   STRIP_TYPE_NOPS (exp);
01500 
01501   if (TREE_NO_WARNING (orig_exp))
01502     TREE_NO_WARNING (exp) = 1;
01503 
01504   ptrtype = build_pointer_type (restype);
01505 
01506   if (TREE_CODE (exp) == INDIRECT_REF)
01507     return convert (ptrtype, TREE_OPERAND (exp, 0));
01508 
01509   if (TREE_CODE (exp) == VAR_DECL)
01510     {
01511       /* We are making an ADDR_EXPR of ptrtype.  This is a valid
01512    ADDR_EXPR because it's the best way of representing what
01513    happens in C when we take the address of an array and place
01514    it in a pointer to the element type.  */
01515       adr = build1 (ADDR_EXPR, ptrtype, exp);
01516       if (!c_mark_addressable (exp))
01517   return error_mark_node;
01518       TREE_SIDE_EFFECTS (adr) = 0;   /* Default would be, same as EXP.  */
01519       return adr;
01520     }
01521 
01522   /* This way is better for a COMPONENT_REF since it can
01523      simplify the offset for a component.  */
01524   adr = build_unary_op (ADDR_EXPR, exp, 1);
01525   return convert (ptrtype, adr);
01526 }
01527 
01528 /* Convert the function expression EXP to a pointer.  */
01529 static tree
01530 function_to_pointer_conversion (tree exp)
01531 {
01532   tree orig_exp = exp;
01533 
01534   gcc_assert (TREE_CODE (TREE_TYPE (exp)) == FUNCTION_TYPE);
01535 
01536   STRIP_TYPE_NOPS (exp);
01537 
01538   if (TREE_NO_WARNING (orig_exp))
01539     TREE_NO_WARNING (exp) = 1;
01540 
01541   return build_unary_op (ADDR_EXPR, exp, 0);
01542 }
01543 
01544 /* Perform the default conversion of arrays and functions to pointers.
01545    Return the result of converting EXP.  For any other expression, just
01546    return EXP after removing NOPs.  */
01547 
01548 struct c_expr
01549 default_function_array_conversion (struct c_expr exp)
01550 {
01551   tree orig_exp = exp.value;
01552   tree type = TREE_TYPE (exp.value);
01553   enum tree_code code = TREE_CODE (type);
01554 
01555   switch (code)
01556     {
01557     case ARRAY_TYPE:
01558       {
01559   bool not_lvalue = false;
01560   bool lvalue_array_p;
01561 
01562   while ((TREE_CODE (exp.value) == NON_LVALUE_EXPR
01563     || TREE_CODE (exp.value) == NOP_EXPR
01564     || TREE_CODE (exp.value) == CONVERT_EXPR)
01565          && TREE_TYPE (TREE_OPERAND (exp.value, 0)) == type)
01566     {
01567       if (TREE_CODE (exp.value) == NON_LVALUE_EXPR)
01568         not_lvalue = true;
01569       exp.value = TREE_OPERAND (exp.value, 0);
01570     }
01571 
01572   if (TREE_NO_WARNING (orig_exp))
01573     TREE_NO_WARNING (exp.value) = 1;
01574 
01575   lvalue_array_p = !not_lvalue && lvalue_p (exp.value);
01576   if (!flag_isoc99 && !lvalue_array_p)
01577     {
01578       /* Before C99, non-lvalue arrays do not decay to pointers.
01579          Normally, using such an array would be invalid; but it can
01580          be used correctly inside sizeof or as a statement expression.
01581          Thus, do not give an error here; an error will result later.  */
01582       return exp;
01583     }
01584 
01585   exp.value = array_to_pointer_conversion (exp.value);
01586       }
01587       break;
01588     case FUNCTION_TYPE:
01589       exp.value = function_to_pointer_conversion (exp.value);
01590       break;
01591     default:
01592       STRIP_TYPE_NOPS (exp.value);
01593       if (TREE_NO_WARNING (orig_exp))
01594   TREE_NO_WARNING (exp.value) = 1;
01595       break;
01596     }
01597 
01598   return exp;
01599 }
01600 
01601 
01602 /* EXP is an expression of integer type.  Apply the integer promotions
01603    to it and return the promoted value.  */
01604 
01605 tree
01606 perform_integral_promotions (tree exp)
01607 {
01608   tree type = TREE_TYPE (exp);
01609   enum tree_code code = TREE_CODE (type);
01610 
01611   gcc_assert (INTEGRAL_TYPE_P (type));
01612 
01613   /* Normally convert enums to int,
01614      but convert wide enums to something wider.  */
01615   if (code == ENUMERAL_TYPE)
01616     {
01617       type = c_common_type_for_size (MAX (TYPE_PRECISION (type),
01618             TYPE_PRECISION (integer_type_node)),
01619              ((TYPE_PRECISION (type)
01620                >= TYPE_PRECISION (integer_type_node))
01621               && TYPE_UNSIGNED (type)));
01622 
01623       return convert (type, exp);
01624     }
01625 
01626   /* ??? This should no longer be needed now bit-fields have their
01627      proper types.  */
01628   if (TREE_CODE (exp) == COMPONENT_REF
01629       && DECL_C_BIT_FIELD (TREE_OPERAND (exp, 1))
01630       /* If it's thinner than an int, promote it like a
01631    c_promoting_integer_type_p, otherwise leave it alone.  */
01632       && 0 > compare_tree_int (DECL_SIZE (TREE_OPERAND (exp, 1)),
01633              TYPE_PRECISION (integer_type_node)))
01634     return convert (integer_type_node, exp);
01635 
01636   if (c_promoting_integer_type_p (type))
01637     {
01638       /* Preserve unsignedness if not really getting any wider.  */
01639       if (TYPE_UNSIGNED (type)
01640     && TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
01641   return convert (unsigned_type_node, exp);
01642 
01643       return convert (integer_type_node, exp);
01644     }
01645 
01646   return exp;
01647 }
01648 
01649 
01650 /* Perform default promotions for C data used in expressions.
01651    Enumeral types or short or char are converted to int.
01652    In addition, manifest constants symbols are replaced by their values.  */
01653 
01654 tree
01655 default_conversion (tree exp)
01656 {
01657   tree orig_exp;
01658   tree type = TREE_TYPE (exp);
01659   enum tree_code code = TREE_CODE (type);
01660 
01661   /* Functions and arrays have been converted during parsing.  */
01662   gcc_assert (code != FUNCTION_TYPE);
01663   if (code == ARRAY_TYPE)
01664     return exp;
01665 
01666   /* Constants can be used directly unless they're not loadable.  */
01667   if (TREE_CODE (exp) == CONST_DECL)
01668     exp = DECL_INITIAL (exp);
01669 
01670   /* Replace a nonvolatile const static variable with its value unless
01671      it is an array, in which case we must be sure that taking the
01672      address of the array produces consistent results.  */
01673   else if (optimize && TREE_CODE (exp) == VAR_DECL && code != ARRAY_TYPE)
01674     {
01675       exp = decl_constant_value_for_broken_optimization (exp);
01676       type = TREE_TYPE (exp);
01677     }
01678 
01679   /* Strip no-op conversions.  */
01680   orig_exp = exp;
01681   STRIP_TYPE_NOPS (exp);
01682 
01683   if (TREE_NO_WARNING (orig_exp))
01684     TREE_NO_WARNING (exp) = 1;
01685 
01686   if (INTEGRAL_TYPE_P (type))
01687     return perform_integral_promotions (exp);
01688 
01689   if (code == VOID_TYPE)
01690     {
01691       error ("void value not ignored as it ought to be");
01692       return error_mark_node;
01693     }
01694   return exp;
01695 }
01696 
01697 /* Look up COMPONENT in a structure or union DECL.
01698 
01699    If the component name is not found, returns NULL_TREE.  Otherwise,
01700    the return value is a TREE_LIST, with each TREE_VALUE a FIELD_DECL
01701    stepping down the chain to the component, which is in the last
01702    TREE_VALUE of the list.  Normally the list is of length one, but if
01703    the component is embedded within (nested) anonymous structures or
01704    unions, the list steps down the chain to the component.  */
01705 
01706 static tree
01707 lookup_field (tree decl, tree component)
01708 {
01709   tree type = TREE_TYPE (decl);
01710   tree field;
01711 
01712   /* If TYPE_LANG_SPECIFIC is set, then it is a sorted array of pointers
01713      to the field elements.  Use a binary search on this array to quickly
01714      find the element.  Otherwise, do a linear search.  TYPE_LANG_SPECIFIC
01715      will always be set for structures which have many elements.  */
01716 
01717   if (TYPE_LANG_SPECIFIC (type) && TYPE_LANG_SPECIFIC (type)->s)
01718     {
01719       int bot, top, half;
01720       tree *field_array = &TYPE_LANG_SPECIFIC (type)->s->elts[0];
01721 
01722       field = TYPE_FIELDS (type);
01723       bot = 0;
01724       top = TYPE_LANG_SPECIFIC (type)->s->len;
01725       while (top - bot > 1)
01726   {
01727     half = (top - bot + 1) >> 1;
01728     field = field_array[bot+half];
01729 
01730     if (DECL_NAME (field) == NULL_TREE)
01731       {
01732         /* Step through all anon unions in linear fashion.  */
01733         while (DECL_NAME (field_array[bot]) == NULL_TREE)
01734     {
01735       field = field_array[bot++];
01736       if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE
01737           || TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)
01738         {
01739           tree anon = lookup_field (field, component);
01740 
01741           if (anon)
01742       return tree_cons (NULL_TREE, field, anon);
01743         }
01744     }
01745 
01746         /* Entire record is only anon unions.  */
01747         if (bot > top)
01748     return NULL_TREE;
01749 
01750         /* Restart the binary search, with new lower bound.  */
01751         continue;
01752       }
01753 
01754     if (DECL_NAME (field) == component)
01755       break;
01756     if (DECL_NAME (field) < component)
01757       bot += half;
01758     else
01759       top = bot + half;
01760   }
01761 
01762       if (DECL_NAME (field_array[bot]) == component)
01763   field = field_array[bot];
01764       else if (DECL_NAME (field) != component)
01765   return NULL_TREE;
01766     }
01767   else
01768     {
01769       for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
01770   {
01771     if (DECL_NAME (field) == NULL_TREE
01772         && (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE
01773       || TREE_CODE (TREE_TYPE (field)) == UNION_TYPE))
01774       {
01775         tree anon = lookup_field (field, component);
01776 
01777         if (anon)
01778     return tree_cons (NULL_TREE, field, anon);
01779       }
01780 
01781     if (DECL_NAME (field) == component)
01782       break;
01783   }
01784 
01785       if (field == NULL_TREE)
01786   return NULL_TREE;
01787     }
01788 
01789   return tree_cons (NULL_TREE, field, NULL_TREE);
01790 }
01791 
01792 /* Make an expression to refer to the COMPONENT field of
01793    structure or union value DATUM.  COMPONENT is an IDENTIFIER_NODE.  */
01794 
01795 tree
01796 build_component_ref (tree datum, tree component)
01797 {
01798   tree type = TREE_TYPE (datum);
01799   enum tree_code code = TREE_CODE (type);
01800   tree field = NULL;
01801   tree ref;
01802 
01803   if (!objc_is_public (datum, component))
01804     return error_mark_node;
01805 
01806   /* See if there is a field or component with name COMPONENT.  */
01807 
01808   if (code == RECORD_TYPE || code == UNION_TYPE)
01809     {
01810       if (!COMPLETE_TYPE_P (type))
01811   {
01812     c_incomplete_type_error (NULL_TREE, type);
01813     return error_mark_node;
01814   }
01815 
01816       field = lookup_field (datum, component);
01817 
01818       if (!field)
01819   {
01820     error ("%qT has no member named %qE", type, component);
01821     return error_mark_node;
01822   }
01823 
01824       /* Chain the COMPONENT_REFs if necessary down to the FIELD.
01825    This might be better solved in future the way the C++ front
01826    end does it - by giving the anonymous entities each a
01827    separate name and type, and then have build_component_ref
01828    recursively call itself.  We can't do that here.  */
01829       do
01830   {
01831     tree subdatum = TREE_VALUE (field);
01832     int quals;
01833     tree subtype;
01834 
01835     if (TREE_TYPE (subdatum) == error_mark_node)
01836       return error_mark_node;
01837 
01838     quals = TYPE_QUALS (strip_array_types (TREE_TYPE (subdatum)));
01839     quals |= TYPE_QUALS (TREE_TYPE (datum));
01840     subtype = c_build_qualified_type (TREE_TYPE (subdatum), quals);
01841 
01842     ref = build3 (COMPONENT_REF, subtype, datum, subdatum,
01843       NULL_TREE);
01844     if (TREE_READONLY (datum) || TREE_READONLY (subdatum))
01845       TREE_READONLY (ref) = 1;
01846     if (TREE_THIS_VOLATILE (datum) || TREE_THIS_VOLATILE (subdatum))
01847       TREE_THIS_VOLATILE (ref) = 1;
01848 
01849     if (TREE_DEPRECATED (subdatum))
01850       warn_deprecated_use (subdatum);
01851 
01852     datum = ref;
01853 
01854     field = TREE_CHAIN (field);
01855   }
01856       while (field);
01857 
01858       return ref;
01859     }
01860   else if (code != ERROR_MARK)
01861     error ("request for member %qE in something not a structure or union",
01862      component);
01863 
01864   return error_mark_node;
01865 }
01866 
01867 /* Given an expression PTR for a pointer, return an expression
01868    for the value pointed to.
01869    ERRORSTRING is the name of the operator to appear in error messages.  */
01870 
01871 tree
01872 build_indirect_ref (tree ptr, const char *errorstring)
01873 {
01874   tree pointer = default_conversion (ptr);
01875   tree type = TREE_TYPE (pointer);
01876 
01877   if (TREE_CODE (type) == POINTER_TYPE)
01878     {
01879       if (TREE_CODE (pointer) == ADDR_EXPR
01880     && (TREE_TYPE (TREE_OPERAND (pointer, 0))
01881         == TREE_TYPE (type)))
01882   return TREE_OPERAND (pointer, 0);
01883       else
01884   {
01885     tree t = TREE_TYPE (type);
01886     tree ref;
01887 
01888     ref = build1 (INDIRECT_REF, t, pointer);
01889 
01890     if (!COMPLETE_OR_VOID_TYPE_P (t) && TREE_CODE (t) != ARRAY_TYPE)
01891       {
01892         error ("dereferencing pointer to incomplete type");
01893         return error_mark_node;
01894       }
01895     if (VOID_TYPE_P (t) && skip_evaluation == 0)
01896       warning (0, "dereferencing %<void *%> pointer");
01897 
01898     /* We *must* set TREE_READONLY when dereferencing a pointer to const,
01899        so that we get the proper error message if the result is used
01900        to assign to.  Also, &* is supposed to be a no-op.
01901        And ANSI C seems to specify that the type of the result
01902        should be the const type.  */
01903     /* A de-reference of a pointer to const is not a const.  It is valid
01904        to change it via some other pointer.  */
01905     TREE_READONLY (ref) = TYPE_READONLY (t);
01906     TREE_SIDE_EFFECTS (ref)
01907       = TYPE_VOLATILE (t) || TREE_SIDE_EFFECTS (pointer);
01908     TREE_THIS_VOLATILE (ref) = TYPE_VOLATILE (t);
01909     return ref;
01910   }
01911     }
01912   else if (TREE_CODE (pointer) != ERROR_MARK)
01913     error ("invalid type argument of %qs", errorstring);
01914   return error_mark_node;
01915 }
01916 
01917 /* This handles expressions of the form "a[i]", which denotes
01918    an array reference.
01919 
01920    This is logically equivalent in C to *(a+i), but we may do it differently.
01921    If A is a variable or a member, we generate a primitive ARRAY_REF.
01922    This avoids forcing the array out of registers, and can work on
01923    arrays that are not lvalues (for example, members of structures returned
01924    by functions).  */
01925 
01926 tree
01927 build_array_ref (tree array, tree index)
01928 {
01929   bool swapped = false;
01930   if (TREE_TYPE (array) == error_mark_node
01931       || TREE_TYPE (index) == error_mark_node)
01932     return error_mark_node;
01933 
01934   if (TREE_CODE (TREE_TYPE (array)) != ARRAY_TYPE
01935       && TREE_CODE (TREE_TYPE (array)) != POINTER_TYPE)
01936     {
01937       tree temp;
01938       if (TREE_CODE (TREE_TYPE (index)) != ARRAY_TYPE
01939     && TREE_CODE (TREE_TYPE (index)) != POINTER_TYPE)
01940   {
01941     error ("subscripted value is neither array nor pointer");
01942     return error_mark_node;
01943   }
01944       temp = array;
01945       array = index;
01946       index = temp;
01947       swapped = true;
01948     }
01949 
01950   if (!INTEGRAL_TYPE_P (TREE_TYPE (index)))
01951     {
01952       error ("array subscript is not an integer");
01953       return error_mark_node;
01954     }
01955 
01956   if (TREE_CODE (TREE_TYPE (TREE_TYPE (array))) == FUNCTION_TYPE)
01957     {
01958       error ("subscripted value is pointer to function");
01959       return error_mark_node;
01960     }
01961 
01962   /* ??? Existing practice has been to warn only when the char
01963      index is syntactically the index, not for char[array].  */
01964   if (!swapped)
01965      warn_array_subscript_with_type_char (index);
01966 
01967   /* Apply default promotions *after* noticing character types.  */
01968   index = default_conversion (index);
01969 
01970   gcc_assert (TREE_CODE (TREE_TYPE (index)) == INTEGER_TYPE);
01971 
01972   if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE)
01973     {
01974       tree rval, type;
01975 
01976       /* An array that is indexed by a non-constant
01977    cannot be stored in a register; we must be able to do
01978    address arithmetic on its address.
01979    Likewise an array of elements of variable size.  */
01980       if (TREE_CODE (index) != INTEGER_CST
01981     || (COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (array)))
01982         && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array)))) != INTEGER_CST))
01983   {
01984     if (!c_mark_addressable (array))
01985       return error_mark_node;
01986   }
01987       /* An array that is indexed by a constant value which is not within
01988    the array bounds cannot be stored in a register either; because we
01989    would get a crash in store_bit_field/extract_bit_field when trying
01990    to access a non-existent part of the register.  */
01991       if (TREE_CODE (index) == INTEGER_CST
01992     && TYPE_DOMAIN (TREE_TYPE (array))
01993     && !int_fits_type_p (index, TYPE_DOMAIN (TREE_TYPE (array))))
01994   {
01995     if (!c_mark_addressable (array))
01996       return error_mark_node;
01997   }
01998 
01999       if (pedantic)
02000   {
02001     tree foo = array;
02002     while (TREE_CODE (foo) == COMPONENT_REF)
02003       foo = TREE_OPERAND (foo, 0);
02004     if (TREE_CODE (foo) == VAR_DECL && C_DECL_REGISTER (foo))
02005       pedwarn ("ISO C forbids subscripting %<register%> array");
02006     else if (!flag_isoc99 && !lvalue_p (foo))
02007       pedwarn ("ISO C90 forbids subscripting non-lvalue array");
02008   }
02009 
02010       type = TREE_TYPE (TREE_TYPE (array));
02011       if (TREE_CODE (type) != ARRAY_TYPE)
02012   type = TYPE_MAIN_VARIANT (type);
02013       rval = build4 (ARRAY_REF, type, array, index, NULL_TREE, NULL_TREE);
02014       /* Array ref is const/volatile if the array elements are
02015    or if the array is.  */
02016       TREE_READONLY (rval)
02017   |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array)))
02018       | TREE_READONLY (array));
02019       TREE_SIDE_EFFECTS (rval)
02020   |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
02021       | TREE_SIDE_EFFECTS (array));
02022       TREE_THIS_VOLATILE (rval)
02023   |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
02024       /* This was added by rms on 16 Nov 91.
02025          It fixes  vol struct foo *a;  a->elts[1]
02026          in an inline function.
02027          Hope it doesn't break something else.  */
02028       | TREE_THIS_VOLATILE (array));
02029       return require_complete_type (fold (rval));
02030     }
02031   else
02032     {
02033       tree ar = default_conversion (array);
02034 
02035       if (ar == error_mark_node)
02036   return ar;
02037 
02038       gcc_assert (TREE_CODE (TREE_TYPE (ar)) == POINTER_TYPE);
02039       gcc_assert (TREE_CODE (TREE_TYPE (TREE_TYPE (ar))) != FUNCTION_TYPE);
02040 
02041       return build_indirect_ref (build_binary_op (PLUS_EXPR, ar, index, 0),
02042          "array indexing");
02043     }
02044 }
02045 
02046 /* Build an external reference to identifier ID.  FUN indicates
02047    whether this will be used for a function call.  LOC is the source
02048    location of the identifier.  */
02049 tree
02050 build_external_ref (tree id, int fun, location_t loc)
02051 {
02052   tree ref;
02053   tree decl = lookup_name (id);
02054 
02055   /* In Objective-C, an instance variable (ivar) may be preferred to
02056      whatever lookup_name() found.  */
02057   decl = objc_lookup_ivar (decl, id);
02058 
02059   if (decl && decl != error_mark_node)
02060     ref = decl;
02061   else if (fun)
02062     /* Implicit function declaration.  */
02063     ref = implicitly_declare (id);
02064   else if (decl == error_mark_node)
02065     /* Don't complain about something that's already been
02066        complained about.  */
02067     return error_mark_node;
02068   else
02069     {
02070       undeclared_variable (id, loc);
02071       return error_mark_node;
02072     }
02073 
02074   if (TREE_TYPE (ref) == error_mark_node)
02075     return error_mark_node;
02076 
02077   if (TREE_DEPRECATED (ref))
02078     warn_deprecated_use (ref);
02079 
02080   if (!skip_evaluation)
02081     assemble_external (ref);
02082   TREE_USED (ref) = 1;
02083 
02084   if (TREE_CODE (ref) == FUNCTION_DECL && !in_alignof)
02085     {
02086       if (!in_sizeof && !in_typeof)
02087   C_DECL_USED (ref) = 1;
02088       else if (DECL_INITIAL (ref) == 0
02089          && DECL_EXTERNAL (ref)
02090          && !TREE_PUBLIC (ref))
02091   record_maybe_used_decl (ref);
02092     }
02093 
02094   if (TREE_CODE (ref) == CONST_DECL)
02095     {
02096       used_types_insert (TREE_TYPE (ref));
02097       ref = DECL_INITIAL (ref);
02098       TREE_CONSTANT (ref) = 1;
02099       TREE_INVARIANT (ref) = 1;
02100     }
02101   else if (current_function_decl != 0
02102      && !DECL_FILE_SCOPE_P (current_function_decl)
02103      && (TREE_CODE (ref) == VAR_DECL
02104          || TREE_CODE (ref) == PARM_DECL
02105          || TREE_CODE (ref) == FUNCTION_DECL))
02106     {
02107       tree context = decl_function_context (ref);
02108 
02109       if (context != 0 && context != current_function_decl)
02110   DECL_NONLOCAL (ref) = 1;
02111     }
02112 
02113   return ref;
02114 }
02115 
02116 /* Record details of decls possibly used inside sizeof or typeof.  */
02117 struct maybe_used_decl
02118 {
02119   /* The decl.  */
02120   tree decl;
02121   /* The level seen at (in_sizeof + in_typeof).  */
02122   int level;
02123   /* The next one at this level or above, or NULL.  */
02124   struct maybe_used_decl *next;
02125 };
02126 
02127 static struct maybe_used_decl *maybe_used_decls;
02128 
02129 /* Record that DECL, an undefined static function reference seen
02130    inside sizeof or typeof, might be used if the operand of sizeof is
02131    a VLA type or the operand of typeof is a variably modified
02132    type.  */
02133 
02134 static void
02135 record_maybe_used_decl (tree decl)
02136 {
02137   struct maybe_used_decl *t = XOBNEW (&parser_obstack, struct maybe_used_decl);
02138   t->decl = decl;
02139   t->level = in_sizeof + in_typeof;
02140   t->next = maybe_used_decls;
02141   maybe_used_decls = t;
02142 }
02143 
02144 /* Pop the stack of decls possibly used inside sizeof or typeof.  If
02145    USED is false, just discard them.  If it is true, mark them used
02146    (if no longer inside sizeof or typeof) or move them to the next
02147    level up (if still inside sizeof or typeof).  */
02148 
02149 void
02150 pop_maybe_used (bool used)
02151 {
02152   struct maybe_used_decl *p = maybe_used_decls;
02153   int cur_level = in_sizeof + in_typeof;
02154   while (p && p->level > cur_level)
02155     {
02156       if (used)
02157   {
02158     if (cur_level == 0)
02159       C_DECL_USED (p->decl) = 1;
02160     else
02161       p->level = cur_level;
02162   }
02163       p = p->next;
02164     }
02165   if (!used || cur_level == 0)
02166     maybe_used_decls = p;
02167 }
02168 
02169 /* Return the result of sizeof applied to EXPR.  */
02170 
02171 struct c_expr
02172 c_expr_sizeof_expr (struct c_expr expr)
02173 {
02174   struct c_expr ret;
02175   if (expr.value == error_mark_node)
02176     {
02177       ret.value = error_mark_node;
02178       ret.original_code = ERROR_MARK;
02179       pop_maybe_used (false);
02180     }
02181   else
02182     {
02183       ret.value = c_sizeof (TREE_TYPE (expr.value));
02184       ret.original_code = ERROR_MARK;
02185       if (c_vla_type_p (TREE_TYPE (expr.value)))
02186   {
02187     /* sizeof is evaluated when given a vla (C99 6.5.3.4p2).  */
02188     ret.value = build2 (COMPOUND_EXPR, TREE_TYPE (ret.value), expr.value, ret.value);
02189   }
02190       pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (expr.value)));
02191     }
02192   return ret;
02193 }
02194 
02195 /* Return the result of sizeof applied to T, a structure for the type
02196    name passed to sizeof (rather than the type itself).  */
02197 
02198 struct c_expr
02199 c_expr_sizeof_type (struct c_type_name *t)
02200 {
02201   tree type;
02202   struct c_expr ret;
02203   type = groktypename (t);
02204   ret.value = c_sizeof (type);
02205   ret.original_code = ERROR_MARK;
02206   pop_maybe_used (type != error_mark_node
02207       ? C_TYPE_VARIABLE_SIZE (type) : false);
02208   return ret;
02209 }
02210 
02211 /* Build a function call to function FUNCTION with parameters PARAMS.
02212    PARAMS is a list--a chain of TREE_LIST nodes--in which the
02213    TREE_VALUE of each node is a parameter-expression.
02214    FUNCTION's data type may be a function type or a pointer-to-function.  */
02215 
02216 tree
02217 build_function_call (tree function, tree params)
02218 {
02219   tree fntype, fundecl = 0;
02220   tree coerced_params;
02221   tree name = NULL_TREE, result;
02222   tree tem;
02223 
02224   /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
02225   STRIP_TYPE_NOPS (function);
02226 
02227   /* Convert anything with function type to a pointer-to-function.  */
02228   if (TREE_CODE (function) == FUNCTION_DECL)
02229     {
02230       /* Implement type-directed function overloading for builtins.
02231    resolve_overloaded_builtin and targetm.resolve_overloaded_builtin
02232    handle all the type checking.  The result is a complete expression
02233    that implements this function call.  */
02234       tem = resolve_overloaded_builtin (function, params);
02235       if (tem)
02236   return tem;
02237 
02238       name = DECL_NAME (function);
02239       fundecl = function;
02240     }
02241   if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE)
02242     function = function_to_pointer_conversion (function);
02243 
02244   /* For Objective-C, convert any calls via a cast to OBJC_TYPE_REF
02245      expressions, like those used for ObjC messenger dispatches.  */
02246   function = objc_rewrite_function_call (function, params);
02247 
02248   fntype = TREE_TYPE (function);
02249 
02250   if (TREE_CODE (fntype) == ERROR_MARK)
02251     return error_mark_node;
02252 
02253   if (!(TREE_CODE (fntype) == POINTER_TYPE
02254   && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE))
02255     {
02256       error ("called object %qE is not a function", function);
02257       return error_mark_node;
02258     }
02259 
02260   if (fundecl && TREE_THIS_VOLATILE (fundecl))
02261     current_function_returns_abnormally = 1;
02262 
02263   /* fntype now gets the type of function pointed to.  */
02264   fntype = TREE_TYPE (fntype);
02265 
02266   /* Check that the function is called through a compatible prototype.
02267      If it is not, replace the call by a trap, wrapped up in a compound
02268      expression if necessary.  This has the nice side-effect to prevent
02269      the tree-inliner from generating invalid assignment trees which may
02270      blow up in the RTL expander later.  */
02271   if ((TREE_CODE (function) == NOP_EXPR
02272        || TREE_CODE (function) == CONVERT_EXPR)
02273       && TREE_CODE (tem = TREE_OPERAND (function, 0)) == ADDR_EXPR
02274       && TREE_CODE (tem = TREE_OPERAND (tem, 0)) == FUNCTION_DECL
02275       && !comptypes (fntype, TREE_TYPE (tem)))
02276     {
02277       tree return_type = TREE_TYPE (fntype);
02278       tree trap = build_function_call (built_in_decls[BUILT_IN_TRAP],
02279                NULL_TREE);
02280 
02281       /* This situation leads to run-time undefined behavior.  We can't,
02282    therefore, simply error unless we can prove that all possible
02283    executions of the program must execute the code.  */
02284       warning (0, "function called through a non-compatible type");
02285 
02286       /* We can, however, treat "undefined" any way we please.
02287    Call abort to encourage the user to fix the program.  */
02288       inform ("if this code is reached, the program will abort");
02289 
02290       if (VOID_TYPE_P (return_type))
02291   return trap;
02292       else
02293   {
02294     tree rhs;
02295 
02296     if (AGGREGATE_TYPE_P (return_type))
02297       rhs = build_compound_literal (return_type,
02298             build_constructor (return_type, 0));
02299     else
02300       rhs = fold_convert (return_type, integer_zero_node);
02301 
02302     return build2 (COMPOUND_EXPR, return_type, trap, rhs);
02303   }
02304     }
02305 
02306   /* Convert the parameters to the types declared in the
02307      function prototype, or apply default promotions.  */
02308 
02309   coerced_params
02310     = convert_arguments (TYPE_ARG_TYPES (fntype), params, function, fundecl);
02311 
02312   if (coerced_params == error_mark_node)
02313     return error_mark_node;
02314 
02315   /* Check that the arguments to the function are valid.  */
02316 
02317   check_function_arguments (TYPE_ATTRIBUTES (fntype), coerced_params,
02318           TYPE_ARG_TYPES (fntype));
02319 
02320   if (require_constant_value)
02321     {
02322       result = fold_build3_initializer (CALL_EXPR, TREE_TYPE (fntype),
02323           function, coerced_params, NULL_TREE);
02324 
02325       if (TREE_CONSTANT (result)
02326     && (name == NULL_TREE
02327         || strncmp (IDENTIFIER_POINTER (name), "__builtin_", 10) != 0))
02328   pedwarn_init ("initializer element is not constant");
02329     }
02330   else
02331     result = fold_build3 (CALL_EXPR, TREE_TYPE (fntype),
02332         function, coerced_params, NULL_TREE);
02333 
02334   if (VOID_TYPE_P (TREE_TYPE (result)))
02335     return result;
02336   return require_complete_type (result);
02337 }
02338 
02339 /* Convert the argument expressions in the list VALUES
02340    to the types in the list TYPELIST.  The result is a list of converted
02341    argument expressions, unless there are too few arguments in which
02342    case it is error_mark_node.
02343 
02344    If TYPELIST is exhausted, or when an element has NULL as its type,
02345    perform the default conversions.
02346 
02347    PARMLIST is the chain of parm decls for the function being called.
02348    It may be 0, if that info is not available.
02349    It is used only for generating error messages.
02350 
02351    FUNCTION is a tree for the called function.  It is used only for
02352    error messages, where it is formatted with %qE.
02353 
02354    This is also where warnings about wrong number of args are generated.
02355 
02356    Both VALUES and the returned value are chains of TREE_LIST nodes
02357    with the elements of the list in the TREE_VALUE slots of those nodes.  */
02358 
02359 static tree
02360 convert_arguments (tree typelist, tree values, tree function, tree fundecl)
02361 {
02362   tree typetail, valtail;
02363   tree result = NULL;
02364   int parmnum;
02365   tree selector;
02366 
02367   /* Change pointer to function to the function itself for
02368      diagnostics.  */
02369   if (TREE_CODE (function) == ADDR_EXPR
02370       && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL)
02371     function = TREE_OPERAND (function, 0);
02372 
02373   /* Handle an ObjC selector specially for diagnostics.  */
02374   selector = objc_message_selector ();
02375 
02376   /* Scan the given expressions and types, producing individual
02377      converted arguments and pushing them on RESULT in reverse order.  */
02378 
02379   for (valtail = values, typetail = typelist, parmnum = 0;
02380        valtail;
02381        valtail = TREE_CHAIN (valtail), parmnum++)
02382     {
02383       tree type = typetail ? TREE_VALUE (typetail) : 0;
02384       tree val = TREE_VALUE (valtail);
02385       tree rname = function;
02386       int argnum = parmnum + 1;
02387       const char *invalid_func_diag;
02388 
02389       if (type == void_type_node)
02390   {
02391     error ("too many arguments to function %qE", function);
02392     break;
02393   }
02394 
02395       if (selector && argnum > 2)
02396   {
02397     rname = selector;
02398     argnum -= 2;
02399   }
02400 
02401       STRIP_TYPE_NOPS (val);
02402 
02403       val = require_complete_type (val);
02404 
02405       if (type != 0)
02406   {
02407     /* Formal parm type is specified by a function prototype.  */
02408     tree parmval;
02409 
02410     if (type == error_mark_node || !COMPLETE_TYPE_P (type))
02411       {
02412         error ("type of formal parameter %d is incomplete", parmnum + 1);
02413         parmval = val;
02414       }
02415     else
02416       {
02417         /* Optionally warn about conversions that
02418      differ from the default conversions.  */
02419         if (warn_conversion || warn_traditional)
02420     {
02421       unsigned int formal_prec = TYPE_PRECISION (type);
02422 
02423       if (INTEGRAL_TYPE_P (type)
02424           && TREE_CODE (TREE_TYPE (val)) == REAL_TYPE)
02425         warning (0, "passing argument %d of %qE as integer "
02426            "rather than floating due to prototype",
02427            argnum, rname);
02428       if (INTEGRAL_TYPE_P (type)
02429           && TREE_CODE (TREE_TYPE (val)) == COMPLEX_TYPE)
02430         warning (0, "passing argument %d of %qE as integer "
02431            "rather than complex due to prototype",
02432            argnum, rname);
02433       else if (TREE_CODE (type) == COMPLEX_TYPE
02434          && TREE_CODE (TREE_TYPE (val)) == REAL_TYPE)
02435         warning (0, "passing argument %d of %qE as complex "
02436            "rather than floating due to prototype",
02437            argnum, rname);
02438       else if (TREE_CODE (type) == REAL_TYPE
02439          && INTEGRAL_TYPE_P (TREE_TYPE (val)))
02440         warning (0, "passing argument %d of %qE as floating "
02441            "rather than integer due to prototype",
02442            argnum, rname);
02443       else if (TREE_CODE (type) == COMPLEX_TYPE
02444          && INTEGRAL_TYPE_P (TREE_TYPE (val)))
02445         warning (0, "passing argument %d of %qE as complex "
02446            "rather than integer due to prototype",
02447            argnum, rname);
02448       else if (TREE_CODE (type) == REAL_TYPE
02449          && TREE_CODE (TREE_TYPE (val)) == COMPLEX_TYPE)
02450         warning (0, "passing argument %d of %qE as floating "
02451            "rather than complex due to prototype",
02452            argnum, rname);
02453       /* ??? At some point, messages should be written about
02454          conversions between complex types, but that's too messy
02455          to do now.  */
02456       else if (TREE_CODE (type) == REAL_TYPE
02457          && TREE_CODE (TREE_TYPE (val)) == REAL_TYPE)
02458         {
02459           /* Warn if any argument is passed as `float',
02460        since without a prototype it would be `double'.  */
02461           if (formal_prec == TYPE_PRECISION (float_type_node)
02462         && type != dfloat32_type_node)
02463       warning (0, "passing argument %d of %qE as %<float%> "
02464          "rather than %<double%> due to prototype",
02465          argnum, rname);
02466 
02467           /* Warn if mismatch between argument and prototype
02468        for decimal float types.  Warn of conversions with
02469        binary float types and of precision narrowing due to
02470        prototype. */
02471           else if (type != TREE_TYPE (val)
02472              && (type == dfloat32_type_node
02473            || type == dfloat64_type_node
02474            || type == dfloat128_type_node
02475            || TREE_TYPE (val) == dfloat32_type_node
02476            || TREE_TYPE (val) == dfloat64_type_node
02477            || TREE_TYPE (val) == dfloat128_type_node)
02478              && (formal_prec
02479            <= TYPE_PRECISION (TREE_TYPE (val))
02480            || (type == dfloat128_type_node
02481                && (TREE_TYPE (val)
02482              != dfloat64_type_node
02483              && (TREE_TYPE (val)
02484                  != dfloat32_type_node)))
02485            || (type == dfloat64_type_node
02486                && (TREE_TYPE (val)
02487              != dfloat32_type_node))))
02488       warning (0, "passing argument %d of %qE as %qT "
02489          "rather than %qT due to prototype",
02490          argnum, rname, type, TREE_TYPE (val));
02491 
02492         }
02493       /* Detect integer changing in width or signedness.
02494          These warnings are only activated with
02495          -Wconversion, not with -Wtraditional.  */
02496       else if (warn_conversion && INTEGRAL_TYPE_P (type)
02497          && INTEGRAL_TYPE_P (TREE_TYPE (val)))
02498         {
02499           tree would_have_been = default_conversion (val);
02500           tree type1 = TREE_TYPE (would_have_been);
02501 
02502           if (TREE_CODE (type) == ENUMERAL_TYPE
02503         && (TYPE_MAIN_VARIANT (type)
02504             == TYPE_MAIN_VARIANT (TREE_TYPE (val))))
02505       /* No warning if function asks for enum
02506          and the actual arg is that enum type.  */
02507       ;
02508           else if (formal_prec != TYPE_PRECISION (type1))
02509       warning (OPT_Wconversion, "passing argument %d of %qE "
02510          "with different width due to prototype",
02511          argnum, rname);
02512           else if (TYPE_UNSIGNED (type) == TYPE_UNSIGNED (type1))
02513       ;
02514           /* Don't complain if the formal parameter type
02515        is an enum, because we can't tell now whether
02516        the value was an enum--even the same enum.  */
02517           else if (TREE_CODE (type) == ENUMERAL_TYPE)
02518       ;
02519           else if (TREE_CODE (val) == INTEGER_CST
02520              && int_fits_type_p (val, type))
02521       /* Change in signedness doesn't matter
02522          if a constant value is unaffected.  */
02523       ;
02524           /* If the value is extended from a narrower
02525        unsigned type, it doesn't matter whether we
02526        pass it as signed or unsigned; the value
02527        certainly is the same either way.  */
02528           else if (TYPE_PRECISION (TREE_TYPE (val)) < TYPE_PRECISION (type)
02529              && TYPE_UNSIGNED (TREE_TYPE (val)))
02530       ;
02531           else if (TYPE_UNSIGNED (type))
02532       warning (OPT_Wconversion, "passing argument %d of %qE "
02533          "as unsigned due to prototype",
02534          argnum, rname);
02535           else
02536       warning (OPT_Wconversion, "passing argument %d of %qE "
02537          "as signed due to prototype", argnum, rname);
02538         }
02539     }
02540 
02541         parmval = convert_for_assignment (type, val, ic_argpass,
02542             fundecl, function,
02543             parmnum + 1);
02544 
02545         if (targetm.calls.promote_prototypes (fundecl ? TREE_TYPE (fundecl) : 0)
02546       && INTEGRAL_TYPE_P (type)
02547       && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
02548     parmval = default_conversion (parmval);
02549       }
02550     result = tree_cons (NULL_TREE, parmval, result);
02551   }
02552       else if (TREE_CODE (TREE_TYPE (val)) == REAL_TYPE
02553          && (TYPE_PRECISION (TREE_TYPE (val))
02554        < TYPE_PRECISION (double_type_node))
02555          && !DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (val))))
02556   /* Convert `float' to `double'.  */
02557   result = tree_cons (NULL_TREE, convert (double_type_node, val), result);
02558       else if ((invalid_func_diag =
02559     targetm.calls.invalid_arg_for_unprototyped_fn (typelist, fundecl, val)))
02560   {
02561     error (invalid_func_diag);
02562     return error_mark_node;
02563   }
02564       else
02565   /* Convert `short' and `char' to full-size `int'.  */
02566   result = tree_cons (NULL_TREE, default_conversion (val), result);
02567 
02568       if (typetail)
02569   typetail = TREE_CHAIN (typetail);
02570     }
02571 
02572   if (typetail != 0 && TREE_VALUE (typetail) != void_type_node)
02573     {
02574       error ("too few arguments to function %qE", function);
02575       return error_mark_node;
02576     }
02577 
02578   return nreverse (result);
02579 }
02580 
02581 /* This is the entry point used by the parser to build unary operators
02582    in the input.  CODE, a tree_code, specifies the unary operator, and
02583    ARG is the operand.  For unary plus, the C parser currently uses
02584    CONVERT_EXPR for code.  */
02585 
02586 struct c_expr
02587 parser_build_unary_op (enum tree_code code, struct c_expr arg)
02588 {
02589   struct c_expr result;
02590 
02591   result.original_code = ERROR_MARK;
02592   result.value = build_unary_op (code, arg.value, 0);
02593   overflow_warning (result.value);
02594   return result;
02595 }
02596 
02597 /* This is the entry point used by the parser to build binary operators
02598    in the input.  CODE, a tree_code, specifies the binary operator, and
02599    ARG1 and ARG2 are the operands.  In addition to constructing the
02600    expression, we check for operands that were written with other binary
02601    operators in a way that is likely to confuse the user.  */
02602 
02603 struct c_expr
02604 parser_build_binary_op (enum tree_code code, struct c_expr arg1,
02605       struct c_expr arg2)
02606 {
02607   struct c_expr result;
02608 
02609   enum tree_code code1 = arg1.original_code;
02610   enum tree_code code2 = arg2.original_code;
02611 
02612   result.value = build_binary_op (code, arg1.value, arg2.value, 1);
02613   result.original_code = code;
02614 
02615   if (TREE_CODE (result.value) == ERROR_MARK)
02616     return result;
02617 
02618   /* Check for cases such as x+y<<z which users are likely
02619      to misinterpret.  */
02620   if (warn_parentheses)
02621     {
02622       if (code == LSHIFT_EXPR || code == RSHIFT_EXPR)
02623   {
02624     if (code1 == PLUS_EXPR || code1 == MINUS_EXPR
02625         || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
02626       warning (OPT_Wparentheses,
02627          "suggest parentheses around + or - inside shift");
02628   }
02629 
02630       if (code == TRUTH_ORIF_EXPR)
02631   {
02632     if (code1 == TRUTH_ANDIF_EXPR
02633         || code2 == TRUTH_ANDIF_EXPR)
02634       warning (OPT_Wparentheses,
02635          "suggest parentheses around && within ||");
02636   }
02637 
02638       if (code == BIT_IOR_EXPR)
02639   {
02640     if (code1 == BIT_AND_EXPR || code1 == BIT_XOR_EXPR
02641         || code1 == PLUS_EXPR || code1 == MINUS_EXPR
02642         || code2 == BIT_AND_EXPR || code2 == BIT_XOR_EXPR
02643         || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
02644       warning (OPT_Wparentheses,
02645          "suggest parentheses around arithmetic in operand of |");
02646     /* Check cases like x|y==z */
02647     if (TREE_CODE_CLASS (code1) == tcc_comparison
02648         || TREE_CODE_CLASS (code2) == tcc_comparison)
02649       warning (OPT_Wparentheses,
02650          "suggest parentheses around comparison in operand of |");
02651   }
02652 
02653       if (code == BIT_XOR_EXPR)
02654   {
02655     if (code1 == BIT_AND_EXPR
02656         || code1 == PLUS_EXPR || code1 == MINUS_EXPR
02657         || code2 == BIT_AND_EXPR
02658         || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
02659       warning (OPT_Wparentheses,
02660          "suggest parentheses around arithmetic in operand of ^");
02661     /* Check cases like x^y==z */
02662     if (TREE_CODE_CLASS (code1) == tcc_comparison
02663         || TREE_CODE_CLASS (code2) == tcc_comparison)
02664       warning (OPT_Wparentheses,
02665          "suggest parentheses around comparison in operand of ^");
02666   }
02667 
02668       if (code == BIT_AND_EXPR)
02669   {
02670     if (code1 == PLUS_EXPR || code1 == MINUS_EXPR
02671         || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
02672       warning (OPT_Wparentheses,
02673          "suggest parentheses around + or - in operand of &");
02674     /* Check cases like x&y==z */
02675     if (TREE_CODE_CLASS (code1) == tcc_comparison
02676         || TREE_CODE_CLASS (code2) == tcc_comparison)
02677       warning (OPT_Wparentheses,
02678          "suggest parentheses around comparison in operand of &");
02679   }
02680       /* Similarly, check for cases like 1<=i<=10 that are probably errors.  */
02681       if (TREE_CODE_CLASS (code) == tcc_comparison
02682     && (TREE_CODE_CLASS (code1) == tcc_comparison
02683         || TREE_CODE_CLASS (code2) == tcc_comparison))
02684   warning (OPT_Wparentheses, "comparisons like X<=Y<=Z do not "
02685      "have their mathematical meaning");
02686 
02687     }
02688 
02689   /* Warn about comparisons against string literals, with the exception
02690      of testing for equality or inequality of a string literal with NULL.  */
02691   if (code == EQ_EXPR || code == NE_EXPR)
02692     {
02693       if ((code1 == STRING_CST && !integer_zerop (arg2.value))
02694     || (code2 == STRING_CST && !integer_zerop (arg1.value)))
02695   warning (OPT_Waddress, 
02696                  "comparison with string literal results in unspecified behaviour");
02697     }
02698   else if (TREE_CODE_CLASS (code) == tcc_comparison
02699      && (code1 == STRING_CST || code2 == STRING_CST))
02700     warning (OPT_Waddress, 
02701              "comparison with string literal results in unspecified behaviour");
02702 
02703   overflow_warning (result.value);
02704 
02705   return result;
02706 }
02707 
02708 /* Return a tree for the difference of pointers OP0 and OP1.
02709    The resulting tree has type int.  */
02710 
02711 static tree
02712 pointer_diff (tree op0, tree op1)
02713 {
02714   tree restype = ptrdiff_type_node;
02715 
02716   tree target_type = TREE_TYPE (TREE_TYPE (op0));
02717   tree con0, con1, lit0, lit1;
02718   tree orig_op1 = op1;
02719 
02720   if (pedantic || warn_pointer_arith)
02721     {
02722       if (TREE_CODE (target_type) == VOID_TYPE)
02723   pedwarn ("pointer of type %<void *%> used in subtraction");
02724       if (TREE_CODE (target_type) == FUNCTION_TYPE)
02725   pedwarn ("pointer to a function used in subtraction");
02726     }
02727 
02728   /* If the conversion to ptrdiff_type does anything like widening or
02729      converting a partial to an integral mode, we get a convert_expression
02730      that is in the way to do any simplifications.
02731      (fold-const.c doesn't know that the extra bits won't be needed.
02732      split_tree uses STRIP_SIGN_NOPS, which leaves conversions to a
02733      different mode in place.)
02734      So first try to find a common term here 'by hand'; we want to cover
02735      at least the cases that occur in legal static initializers.  */
02736   if ((TREE_CODE (op0) == NOP_EXPR || TREE_CODE (op0) == CONVERT_EXPR)
02737       && (TYPE_PRECISION (TREE_TYPE (op0))
02738     == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0, 0)))))
02739     con0 = TREE_OPERAND (op0, 0);
02740   else
02741     con0 = op0;
02742   if ((TREE_CODE (op1) == NOP_EXPR || TREE_CODE (op1) == CONVERT_EXPR)
02743       && (TYPE_PRECISION (TREE_TYPE (op1))
02744     == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1, 0)))))
02745     con1 = TREE_OPERAND (op1, 0);
02746   else
02747     con1 = op1;
02748 
02749   if (TREE_CODE (con0) == PLUS_EXPR)
02750     {
02751       lit0 = TREE_OPERAND (con0, 1);
02752       con0 = TREE_OPERAND (con0, 0);
02753     }
02754   else
02755     lit0 = integer_zero_node;
02756 
02757   if (TREE_CODE (con1) == PLUS_EXPR)
02758     {
02759       lit1 = TREE_OPERAND (con1, 1);
02760       con1 = TREE_OPERAND (con1, 0);
02761     }
02762   else
02763     lit1 = integer_zero_node;
02764 
02765   if (operand_equal_p (con0, con1, 0))
02766     {
02767       op0 = lit0;
02768       op1 = lit1;
02769     }
02770 
02771 
02772   /* First do the subtraction as integers;
02773      then drop through to build the divide operator.
02774      Do not do default conversions on the minus operator
02775      in case restype is a short type.  */
02776 
02777   op0 = build_binary_op (MINUS_EXPR, convert (restype, op0),
02778        convert (restype, op1), 0);
02779   /* This generates an error if op1 is pointer to incomplete type.  */
02780   if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (orig_op1))))
02781     error ("arithmetic on pointer to an incomplete type");
02782 
02783   /* This generates an error if op0 is pointer to incomplete type.  */
02784   op1 = c_size_in_bytes (target_type);
02785 
02786   /* Divide by the size, in easiest possible way.  */
02787   return fold_build2 (EXACT_DIV_EXPR, restype, op0, convert (restype, op1));
02788 }
02789 
02790 /* Construct and perhaps optimize a tree representation
02791    for a unary operation.  CODE, a tree_code, specifies the operation
02792    and XARG is the operand.
02793    For any CODE other than ADDR_EXPR, FLAG nonzero suppresses
02794    the default promotions (such as from short to int).
02795    For ADDR_EXPR, the default promotions are not applied; FLAG nonzero
02796    allows non-lvalues; this is only used to handle conversion of non-lvalue
02797    arrays to pointers in C99.  */
02798 
02799 tree
02800 build_unary_op (enum tree_code code, tree xarg, int flag)
02801 {
02802   /* No default_conversion here.  It causes trouble for ADDR_EXPR.  */
02803   tree arg = xarg;
02804   tree argtype = 0;
02805   enum tree_code typecode = TREE_CODE (TREE_TYPE (arg));
02806   tree val;
02807   int noconvert = flag;
02808   const char *invalid_op_diag;
02809 
02810   if (typecode == ERROR_MARK)
02811     return error_mark_node;
02812   if (typecode == ENUMERAL_TYPE || typecode == BOOLEAN_TYPE)
02813     typecode = INTEGER_TYPE;
02814 
02815   if ((invalid_op_diag
02816        = targetm.invalid_unary_op (code, TREE_TYPE (xarg))))
02817     {
02818       error (invalid_op_diag);
02819       return error_mark_node;
02820     }
02821 
02822   switch (code)
02823     {
02824     case CONVERT_EXPR:
02825       /* This is used for unary plus, because a CONVERT_EXPR
02826    is enough to prevent anybody from looking inside for
02827    associativity, but won't generate any code.  */
02828       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
02829       || typecode == COMPLEX_TYPE
02830       || typecode == VECTOR_TYPE))
02831   {
02832     error ("wrong type argument to unary plus");
02833     return error_mark_node;
02834   }
02835       else if (!noconvert)
02836   arg = default_conversion (arg);
02837       arg = non_lvalue (arg);
02838       break;
02839 
02840     case NEGATE_EXPR:
02841       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
02842       || typecode == COMPLEX_TYPE
02843       || typecode == VECTOR_TYPE))
02844   {
02845     error ("wrong type argument to unary minus");
02846     return error_mark_node;
02847   }
02848       else if (!noconvert)
02849   arg = default_conversion (arg);
02850       break;
02851 
02852     case BIT_NOT_EXPR:
02853       if (typecode == INTEGER_TYPE || typecode == VECTOR_TYPE)
02854   {
02855     if (!noconvert)
02856       arg = default_conversion (arg);
02857   }
02858       else if (typecode == COMPLEX_TYPE)
02859   {
02860     code = CONJ_EXPR;
02861     if (pedantic)
02862       pedwarn ("ISO C does not support %<~%> for complex conjugation");
02863     if (!noconvert)
02864       arg = default_conversion (arg);
02865   }
02866       else
02867   {
02868     error ("wrong type argument to bit-complement");
02869     return error_mark_node;
02870   }
02871       break;
02872 
02873     case ABS_EXPR:
02874       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE))
02875   {
02876     error ("wrong type argument to abs");
02877     return error_mark_node;
02878   }
02879       else if (!noconvert)
02880   arg = default_conversion (arg);
02881       break;
02882 
02883     case CONJ_EXPR:
02884       /* Conjugating a real value is a no-op, but allow it anyway.  */
02885       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
02886       || typecode == COMPLEX_TYPE))
02887   {
02888     error ("wrong type argument to conjugation");
02889     return error_mark_node;
02890   }
02891       else if (!noconvert)
02892   arg = default_conversion (arg);
02893       break;
02894 
02895     case TRUTH_NOT_EXPR:
02896       if (typecode != INTEGER_TYPE
02897     && typecode != REAL_TYPE && typecode != POINTER_TYPE
02898     && typecode != COMPLEX_TYPE)
02899   {
02900     error ("wrong type argument to unary exclamation mark");
02901     return error_mark_node;
02902   }
02903       arg = c_objc_common_truthvalue_conversion (arg);
02904       return invert_truthvalue (arg);
02905 
02906     case REALPART_EXPR:
02907       if (TREE_CODE (arg) == COMPLEX_CST)
02908   return TREE_REALPART (arg);
02909       else if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
02910   return fold_build1 (REALPART_EXPR, TREE_TYPE (TREE_TYPE (arg)), arg);
02911       else
02912   return arg;
02913 
02914     case IMAGPART_EXPR:
02915       if (TREE_CODE (arg) == COMPLEX_CST)
02916   return TREE_IMAGPART (arg);
02917       else if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
02918   return fold_build1 (IMAGPART_EXPR, TREE_TYPE (TREE_TYPE (arg)), arg);
02919       else
02920   return convert (TREE_TYPE (arg), integer_zero_node);
02921 
02922     case PREINCREMENT_EXPR:
02923     case POSTINCREMENT_EXPR:
02924     case PREDECREMENT_EXPR:
02925     case POSTDECREMENT_EXPR:
02926 
02927       /* Increment or decrement the real part of the value,
02928    and don't change the imaginary part.  */
02929       if (typecode == COMPLEX_TYPE)
02930   {
02931     tree real, imag;
02932 
02933     if (pedantic)
02934       pedwarn ("ISO C does not support %<++%> and %<--%>"
02935          " on complex types");
02936 
02937     arg = stabilize_reference (arg);
02938     real = build_unary_op (REALPART_EXPR, arg, 1);
02939     imag = build_unary_op (IMAGPART_EXPR, arg, 1);
02940     return build2 (COMPLEX_EXPR, TREE_TYPE (arg),
02941        build_unary_op (code, real, 1), imag);
02942   }
02943 
02944       /* Report invalid types.  */
02945 
02946       if (typecode != POINTER_TYPE
02947     && typecode != INTEGER_TYPE && typecode != REAL_TYPE)
02948   {
02949     if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
02950       error ("wrong type argument to increment");
02951     else
02952       error ("wrong type argument to decrement");
02953 
02954     return error_mark_node;
02955   }
02956 
02957       {
02958   tree inc;
02959   tree result_type = TREE_TYPE (arg);
02960 
02961   arg = get_unwidened (arg, 0);
02962   argtype = TREE_TYPE (arg);
02963 
02964   /* Compute the increment.  */
02965 
02966   if (typecode == POINTER_TYPE)
02967     {
02968       /* If pointer target is an undefined struct,
02969          we just cannot know how to do the arithmetic.  */
02970       if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (result_type)))
02971         {
02972     if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
02973       error ("increment of pointer to unknown structure");
02974     else
02975       error ("decrement of pointer to unknown structure");
02976         }
02977       else if ((pedantic || warn_pointer_arith)
02978          && (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE
02979        || TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE))
02980         {
02981     if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
02982       pedwarn ("wrong type argument to increment");
02983     else
02984       pedwarn ("wrong type argument to decrement");
02985         }
02986 
02987       inc = c_size_in_bytes (TREE_TYPE (result_type));
02988     }
02989   else
02990     inc = integer_one_node;
02991 
02992   inc = convert (argtype, inc);
02993 
02994   /* Complain about anything else that is not a true lvalue.  */
02995   if (!lvalue_or_else (arg, ((code == PREINCREMENT_EXPR
02996             || code == POSTINCREMENT_EXPR)
02997            ? lv_increment
02998            : lv_decrement)))
02999     return error_mark_node;
03000 
03001   /* Report a read-only lvalue.  */
03002   if (TREE_READONLY (arg))
03003     {
03004       readonly_error (arg,
03005           ((code == PREINCREMENT_EXPR
03006             || code == POSTINCREMENT_EXPR)
03007            ? lv_increment : lv_decrement));
03008       return error_mark_node;
03009     }
03010 
03011   if (TREE_CODE (TREE_TYPE (arg)) == BOOLEAN_TYPE)
03012     val = boolean_increment (code, arg);
03013   else
03014     val = build2 (code, TREE_TYPE (arg), arg, inc);
03015   TREE_SIDE_EFFECTS (val) = 1;
03016   val = convert (result_type, val);
03017   if (TREE_CODE (val) != code)
03018     TREE_NO_WARNING (val) = 1;
03019   return val;
03020       }
03021 
03022     case ADDR_EXPR:
03023       /* Note that this operation never does default_conversion.  */
03024 
03025       /* Let &* cancel out to simplify resulting code.  */
03026       if (TREE_CODE (arg) == INDIRECT_REF)
03027   {
03028     /* Don't let this be an lvalue.  */
03029     if (lvalue_p (TREE_OPERAND (arg, 0)))
03030       return non_lvalue (TREE_OPERAND (arg, 0));
03031     return TREE_OPERAND (arg, 0);
03032   }
03033 
03034       /* For &x[y], return x+y */
03035       if (TREE_CODE (arg) == ARRAY_REF)
03036   {
03037     tree op0 = TREE_OPERAND (arg, 0);
03038     if (!c_mark_addressable (op0))
03039       return error_mark_node;
03040     return build_binary_op (PLUS_EXPR,
03041           (TREE_CODE (TREE_TYPE (op0)) == ARRAY_TYPE
03042            ? array_to_pointer_conversion (op0)
03043            : op0),
03044           TREE_OPERAND (arg, 1), 1);
03045   }
03046 
03047       /* Anything not already handled and not a true memory reference
03048    or a non-lvalue array is an error.  */
03049       else if (typecode != FUNCTION_TYPE && !flag
03050          && !lvalue_or_else (arg, lv_addressof))
03051   return error_mark_node;
03052 
03053       /* Ordinary case; arg is a COMPONENT_REF or a decl.  */
03054       argtype = TREE_TYPE (arg);
03055 
03056       /* If the lvalue is const or volatile, merge that into the type
03057    to which the address will point.  Note that you can't get a
03058    restricted pointer by taking the address of something, so we
03059    only have to deal with `const' and `volatile' here.  */
03060       if ((DECL_P (arg) || REFERENCE_CLASS_P (arg))
03061     && (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg)))
03062     argtype = c_build_type_variant (argtype,
03063             TREE_READONLY (arg),
03064             TREE_THIS_VOLATILE (arg));
03065 
03066       if (!c_mark_addressable (arg))
03067   return error_mark_node;
03068 
03069       gcc_assert (TREE_CODE (arg) != COMPONENT_REF
03070       || !DECL_C_BIT_FIELD (TREE_OPERAND (arg, 1)));
03071 
03072       argtype = build_pointer_type (argtype);
03073 
03074       /* ??? Cope with user tricks that amount to offsetof.  Delete this
03075    when we have proper support for integer constant expressions.  */
03076       val = get_base_address (arg);
03077       if (val && TREE_CODE (val) == INDIRECT_REF
03078           && TREE_CONSTANT (TREE_OPERAND (val, 0)))
03079   {
03080     tree op0 = fold_convert (argtype, fold_offsetof (arg, val)), op1;
03081 
03082     op1 = fold_convert (argtype, TREE_OPERAND (val, 0));
03083     return fold_build2 (PLUS_EXPR, argtype, op0, op1);
03084   }
03085 
03086       val = build1 (ADDR_EXPR, argtype, arg);
03087 
03088       return val;
03089 
03090     default:
03091       gcc_unreachable ();
03092     }
03093 
03094   if (argtype == 0)
03095     argtype = TREE_TYPE (arg);
03096   return require_constant_value ? fold_build1_initializer (code, argtype, arg)
03097         : fold_build1 (code, argtype, arg);
03098 }
03099 
03100 /* Return nonzero if REF is an lvalue valid for this language.
03101    Lvalues can be assigned, unless their type has TYPE_READONLY.
03102    Lvalues can have their address taken, unless they have C_DECL_REGISTER.  */
03103 
03104 static int
03105 lvalue_p (tree ref)
03106 {
03107   enum tree_code code = TREE_CODE (ref);
03108 
03109   switch (code)
03110     {
03111     case REALPART_EXPR:
03112     case IMAGPART_EXPR:
03113     case COMPONENT_REF:
03114       return lvalue_p (TREE_OPERAND (ref, 0));
03115 
03116     case COMPOUND_LITERAL_EXPR:
03117     case STRING_CST:
03118       return 1;
03119 
03120     case INDIRECT_REF:
03121     case ARRAY_REF:
03122     case VAR_DECL:
03123     case PARM_DECL:
03124     case RESULT_DECL:
03125     case ERROR_MARK:
03126       return (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE
03127         && TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE);
03128 
03129     case BIND_EXPR:
03130       return TREE_CODE (TREE_TYPE (ref)) == ARRAY_TYPE;
03131 
03132     default:
03133       return 0;
03134     }
03135 }
03136 
03137 /* Give an error for storing in something that is 'const'.  */
03138 
03139 static void
03140 readonly_error (tree arg, enum lvalue_use use)
03141 {
03142   gcc_assert (use == lv_assign || use == lv_increment || use == lv_decrement
03143         || use == lv_asm);
03144   /* Using this macro rather than (for example) arrays of messages
03145      ensures that all the format strings are checked at compile
03146      time.  */
03147 #define READONLY_MSG(A, I, D, AS) (use == lv_assign ? (A)   \
03148            : (use == lv_increment ? (I)   \
03149            : (use == lv_decrement ? (D) : (AS))))
03150   if (TREE_CODE (arg) == COMPONENT_REF)
03151     {
03152       if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg, 0))))
03153   readonly_error (TREE_OPERAND (arg, 0), use);
03154       else
03155   error (READONLY_MSG (G_("assignment of read-only member %qD"),
03156            G_("increment of read-only member %qD"),
03157            G_("decrement of read-only member %qD"),
03158            G_("read-only member %qD used as %<asm%> output")),
03159          TREE_OPERAND (arg, 1));
03160     }
03161   else if (TREE_CODE (arg) == VAR_DECL)
03162     error (READONLY_MSG (G_("assignment of read-only variable %qD"),
03163        G_("increment of read-only variable %qD"),
03164        G_("decrement of read-only variable %qD"),
03165        G_("read-only variable %qD used as %<asm%> output")),
03166      arg);
03167   else
03168     error (READONLY_MSG (G_("assignment of read-only location"),
03169        G_("increment of read-only location"),
03170        G_("decrement of read-only location"),
03171        G_("read-only location used as %<asm%> output")));
03172 }
03173 
03174 
03175 /* Return nonzero if REF is an lvalue valid for this language;
03176    otherwise, print an error message and return zero.  USE says
03177    how the lvalue is being used and so selects the error message.  */
03178 
03179 static int
03180 lvalue_or_else (tree ref, enum lvalue_use use)
03181 {
03182   int win = lvalue_p (ref);
03183 
03184   if (!win)
03185     lvalue_error (use);
03186 
03187   return win;
03188 }
03189 
03190 /* Mark EXP saying that we need to be able to take the
03191    address of it; it should not be allocated in a register.
03192    Returns true if successful.  */
03193 
03194 bool
03195 c_mark_addressable (tree exp)
03196 {
03197   tree x = exp;
03198 
03199   while (1)
03200     switch (TREE_CODE (x))
03201       {
03202       case COMPONENT_REF:
03203   if (DECL_C_BIT_FIELD (TREE_OPERAND (x, 1)))
03204     {
03205       error
03206         ("cannot take address of bit-field %qD", TREE_OPERAND (x, 1));
03207       return false;
03208     }
03209 
03210   /* ... fall through ...  */
03211 
03212       case ADDR_EXPR:
03213       case ARRAY_REF:
03214       case REALPART_EXPR:
03215       case IMAGPART_EXPR:
03216   x = TREE_OPERAND (x, 0);
03217   break;
03218 
03219       case COMPOUND_LITERAL_EXPR:
03220       case CONSTRUCTOR:
03221   TREE_ADDRESSABLE (x) = 1;
03222   return true;
03223 
03224       case VAR_DECL:
03225       case CONST_DECL:
03226       case PARM_DECL:
03227       case RESULT_DECL:
03228   if (C_DECL_REGISTER (x)
03229       && DECL_NONLOCAL (x))
03230     {
03231       if (TREE_PUBLIC (x) || TREE_STATIC (x) || DECL_EXTERNAL (x))
03232         {
03233     error
03234       ("global register variable %qD used in nested function", x);
03235     return false;
03236         }
03237       pedwarn ("register variable %qD used in nested function", x);
03238     }
03239   else if (C_DECL_REGISTER (x))
03240     {
03241       if (TREE_PUBLIC (x) || TREE_STATIC (x) || DECL_EXTERNAL (x))
03242         error ("address of global register variable %qD requested", x);
03243       else
03244         error ("address of register variable %qD requested", x);
03245       return false;
03246     }
03247 
03248   /* drops in */
03249       case FUNCTION_DECL:
03250   TREE_ADDRESSABLE (x) = 1;
03251   /* drops out */
03252       default:
03253   return true;
03254     }
03255 }
03256 
03257 /* Build and return a conditional expression IFEXP ? OP1 : OP2.  */
03258 
03259 tree
03260 build_conditional_expr (tree ifexp, tree op1, tree op2)
03261 {
03262   tree type1;
03263   tree type2;
03264   enum tree_code code1;
03265   enum tree_code code2;
03266   tree result_type = NULL;
03267   tree orig_op1 = op1, orig_op2 = op2;
03268 
03269   /* Promote both alternatives.  */
03270 
03271   if (TREE_CODE (TREE_TYPE (op1)) != VOID_TYPE)
03272     op1 = default_conversion (op1);
03273   if (TREE_CODE (TREE_TYPE (op2)) != VOID_TYPE)
03274     op2 = default_conversion (op2);
03275 
03276   if (TREE_CODE (ifexp) == ERROR_MARK
03277       || TREE_CODE (TREE_TYPE (op1)) == ERROR_MARK
03278       || TREE_CODE (TREE_TYPE (op2)) == ERROR_MARK)
03279     return error_mark_node;
03280 
03281   type1 = TREE_TYPE (op1);
03282   code1 = TREE_CODE (type1);
03283   type2 = TREE_TYPE (op2);
03284   code2 = TREE_CODE (type2);
03285 
03286   /* C90 does not permit non-lvalue arrays in conditional expressions.
03287      In C99 they will be pointers by now.  */
03288   if (code1 == ARRAY_TYPE || code2 == ARRAY_TYPE)
03289     {
03290       error ("non-lvalue array in conditional expression");
03291       return error_mark_node;
03292     }
03293 
03294   /* Quickly detect the usual case where op1 and op2 have the same type
03295      after promotion.  */
03296   if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2))
03297     {
03298       if (type1 == type2)
03299   result_type = type1;
03300       else
03301   result_type = TYPE_MAIN_VARIANT (type1);
03302     }
03303   else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE
03304       || code1 == COMPLEX_TYPE)
03305      && (code2 == INTEGER_TYPE || code2 == REAL_TYPE
03306          || code2 == COMPLEX_TYPE))
03307     {
03308       result_type = c_common_type (type1, type2);
03309 
03310       /* If -Wsign-compare, warn here if type1 and type2 have
03311    different signedness.  We'll promote the signed to unsigned
03312    and later code won't know it used to be different.
03313    Do this check on the original types, so that explicit casts
03314    will be considered, but default promotions won't.  */
03315       if (warn_sign_compare && !skip_evaluation)
03316   {
03317     int unsigned_op1 = TYPE_UNSIGNED (TREE_TYPE (orig_op1));
03318     int unsigned_op2 = TYPE_UNSIGNED (TREE_TYPE (orig_op2));
03319 
03320     if (unsigned_op1 ^ unsigned_op2)
03321       {
03322         bool ovf;
03323 
03324         /* Do not warn if the result type is signed, since the
03325      signed type will only be chosen if it can represent
03326      all the values of the unsigned type.  */
03327         if (!TYPE_UNSIGNED (result_type))
03328     /* OK */;
03329         /* Do not warn if the signed quantity is an unsuffixed
03330      integer literal (or some static constant expression
03331      involving such literals) and it is non-negative.  */
03332         else if ((unsigned_op2
03333       && tree_expr_nonnegative_warnv_p (op1, &ovf))
03334            || (unsigned_op1
03335          && tree_expr_nonnegative_warnv_p (op2, &ovf)))
03336     /* OK */;
03337         else
03338     warning (0, "signed and unsigned type in conditional expression");
03339       }
03340   }
03341     }
03342   else if (code1 == VOID_TYPE || code2 == VOID_TYPE)
03343     {
03344       if (pedantic && (code1 != VOID_TYPE || code2 != VOID_TYPE))
03345   pedwarn ("ISO C forbids conditional expr with only one void side");
03346       result_type = void_type_node;
03347     }
03348   else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE)
03349     {
03350       if (comp_target_types (type1, type2))
03351   result_type = common_pointer_type (type1, type2);
03352       else if (null_pointer_constant_p (orig_op1))
03353   result_type = qualify_type (type2, type1);
03354       else if (null_pointer_constant_p (orig_op2))
03355   result_type = qualify_type (type1, type2);
03356       else if (VOID_TYPE_P (TREE_TYPE (type1)))
03357   {
03358     if (pedantic && TREE_CODE (TREE_TYPE (type2)) == FUNCTION_TYPE)
03359       pedwarn ("ISO C forbids conditional expr between "
03360          "%<void *%> and function pointer");
03361     result_type = build_pointer_type (qualify_type (TREE_TYPE (type1),
03362                 TREE_TYPE (type2)));
03363   }
03364       else if (VOID_TYPE_P (TREE_TYPE (type2)))
03365   {
03366     if (pedantic && TREE_CODE (TREE_TYPE (type1)) == FUNCTION_TYPE)
03367       pedwarn ("ISO C forbids conditional expr between "
03368          "%<void *%> and function pointer");
03369     result_type = build_pointer_type (qualify_type (TREE_TYPE (type2),
03370                 TREE_TYPE (type1)));
03371   }
03372       else
03373   {
03374     pedwarn ("pointer type mismatch in conditional expression");
03375     result_type = build_pointer_type (void_type_node);
03376   }
03377     }
03378   else if (code1 == POINTER_TYPE && code2 == INTEGER_TYPE)
03379     {
03380       if (!null_pointer_constant_p (orig_op2))
03381   pedwarn ("pointer/integer type mismatch in conditional expression");
03382       else
03383   {
03384     op2 = null_pointer_node;
03385   }
03386       result_type = type1;
03387     }
03388   else if (code2 == POINTER_TYPE && code1 == INTEGER_TYPE)
03389     {
03390       if (!null_pointer_constant_p (orig_op1))
03391   pedwarn ("pointer/integer type mismatch in conditional expression");
03392       else
03393   {
03394     op1 = null_pointer_node;
03395   }
03396       result_type = type2;
03397     }
03398 
03399   if (!result_type)
03400     {
03401       if (flag_cond_mismatch)
03402   result_type = void_type_node;
03403       else
03404   {
03405     error ("type mismatch in conditional expression");
03406     return error_mark_node;
03407   }
03408     }
03409 
03410   /* Merge const and volatile flags of the incoming types.  */
03411   result_type
03412     = build_type_variant (result_type,
03413         TREE_READONLY (op1) || TREE_READONLY (op2),
03414         TREE_THIS_VOLATILE (op1) || TREE_THIS_VOLATILE (op2));
03415 
03416   if (result_type != TREE_TYPE (op1))
03417     op1 = convert_and_check (result_type, op1);
03418   if (result_type != TREE_TYPE (op2))
03419     op2 = convert_and_check (result_type, op2);
03420 
03421   return fold_build3 (COND_EXPR, result_type, ifexp, op1, op2);
03422 }
03423 
03424 /* Return a compound expression that performs two expressions and
03425    returns the value of the second of them.  */
03426 
03427 tree
03428 build_compound_expr (tree expr1, tree expr2)
03429 {
03430   if (!TREE_SIDE_EFFECTS (expr1))
03431     {
03432       /* The left-hand operand of a comma expression is like an expression
03433    statement: with -Wextra or -Wunused, we should warn if it doesn't have
03434    any side-effects, unless it was explicitly cast to (void).  */
03435       if (warn_unused_value)
03436   {
03437     if (VOID_TYPE_P (TREE_TYPE (expr1))
03438         && (TREE_CODE (expr1) == NOP_EXPR
03439       || TREE_CODE (expr1) == CONVERT_EXPR))
03440       ; /* (void) a, b */
03441     else if (VOID_TYPE_P (TREE_TYPE (expr1))
03442        && TREE_CODE (expr1) == COMPOUND_EXPR
03443        && (TREE_CODE (TREE_OPERAND (expr1, 1)) == CONVERT_EXPR
03444            || TREE_CODE (TREE_OPERAND (expr1, 1)) == NOP_EXPR))
03445       ; /* (void) a, (void) b, c */
03446     else
03447       warning (0, "left-hand operand of comma expression has no effect");
03448   }
03449     }
03450 
03451   /* With -Wunused, we should also warn if the left-hand operand does have
03452      side-effects, but computes a value which is not used.  For example, in
03453      `foo() + bar(), baz()' the result of the `+' operator is not used,
03454      so we should issue a warning.  */
03455   else if (warn_unused_value)
03456     warn_if_unused_value (expr1, input_location);
03457 
03458   if (expr2 == error_mark_node)
03459     return error_mark_node;
03460 
03461   return build2 (COMPOUND_EXPR, TREE_TYPE (expr2), expr1, expr2);
03462 }
03463 
03464 /* Build an expression representing a cast to type TYPE of expression EXPR.  */
03465 
03466 tree
03467 build_c_cast (tree type, tree expr)
03468 {
03469   tree value = expr;
03470 
03471   if (type == error_mark_node || expr == error_mark_node)
03472     return error_mark_node;
03473 
03474   /* The ObjC front-end uses TYPE_MAIN_VARIANT to tie together types differing
03475      only in <protocol> qualifications.  But when constructing cast expressions,
03476      the protocols do matter and must be kept around.  */
03477   if (objc_is_object_ptr (type) && objc_is_object_ptr (TREE_TYPE (expr)))
03478     return build1 (NOP_EXPR, type, expr);
03479 
03480   type = TYPE_MAIN_VARIANT (type);
03481 
03482   if (TREE_CODE (type) == ARRAY_TYPE)
03483     {
03484       error ("cast specifies array type");
03485       return error_mark_node;
03486     }
03487 
03488   if (TREE_CODE (type) == FUNCTION_TYPE)
03489     {
03490       error ("cast specifies function type");
03491       return error_mark_node;
03492     }
03493 
03494   if (type == TYPE_MAIN_VARIANT (TREE_TYPE (value)))
03495     {
03496       if (pedantic)
03497   {
03498     if (TREE_CODE (type) == RECORD_TYPE
03499         || TREE_CODE (type) == UNION_TYPE)
03500       pedwarn ("ISO C forbids casting nonscalar to the same type");
03501   }
03502     }
03503   else if (TREE_CODE (type) == UNION_TYPE)
03504     {
03505       tree field;
03506 
03507       for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
03508   if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field)),
03509            TYPE_MAIN_VARIANT (TREE_TYPE (value))))
03510     break;
03511 
03512       if (field)
03513   {
03514     tree t;
03515 
03516     if (pedantic)
03517       pedwarn ("ISO C forbids casts to union type");
03518     t = digest_init (type,
03519          build_constructor_single (type, field, value),
03520          true, 0);
03521     TREE_CONSTANT (t) = TREE_CONSTANT (value);
03522     TREE_INVARIANT (t) = TREE_INVARIANT (value);
03523     return t;
03524   }
03525       error ("cast to union type from type not present in union");
03526       return error_mark_node;
03527     }
03528   else
03529     {
03530       tree otype, ovalue;
03531 
03532       if (type == void_type_node)
03533   return build1 (CONVERT_EXPR, type, value);
03534 
03535       otype = TREE_TYPE (value);
03536 
03537       /* Optionally warn about potentially worrisome casts.  */
03538 
03539       if (warn_cast_qual
03540     && TREE_CODE (type) == POINTER_TYPE
03541     && TREE_CODE (otype) == POINTER_TYPE)
03542   {
03543     tree in_type = type;
03544     tree in_otype = otype;
03545     int added = 0;
03546     int discarded = 0;
03547 
03548     /* Check that the qualifiers on IN_TYPE are a superset of
03549        the qualifiers of IN_OTYPE.  The outermost level of
03550        POINTER_TYPE nodes is uninteresting and we stop as soon
03551        as we hit a non-POINTER_TYPE node on either type.  */
03552     do
03553       {
03554         in_otype = TREE_TYPE (in_otype);
03555         in_type = TREE_TYPE (in_type);
03556 
03557         /* GNU C allows cv-qualified function types.  'const'
03558      means the function is very pure, 'volatile' means it
03559      can't return.  We need to warn when such qualifiers
03560      are added, not when they're taken away.  */
03561         if (TREE_CODE (in_otype) == FUNCTION_TYPE
03562       && TREE_CODE (in_type) == FUNCTION_TYPE)
03563     added |= (TYPE_QUALS (in_type) & ~TYPE_QUALS (in_otype));
03564         else
03565     discarded |= (TYPE_QUALS (in_otype) & ~TYPE_QUALS (in_type));
03566       }
03567     while (TREE_CODE (in_type) == POINTER_TYPE
03568      && TREE_CODE (in_otype) == POINTER_TYPE);
03569 
03570     if (added)
03571       warning (0, "cast adds new qualifiers to function type");
03572 
03573     if (discarded)
03574       /* There are qualifiers present in IN_OTYPE that are not
03575          present in IN_TYPE.  */
03576       warning (0, "cast discards qualifiers from pointer target type");
03577   }
03578 
03579       /* Warn about possible alignment problems.  */
03580       if (STRICT_ALIGNMENT
03581     && TREE_CODE (type) == POINTER_TYPE
03582     && TREE_CODE (otype) == POINTER_TYPE
03583     && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE
03584     && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
03585     /* Don't warn about opaque types, where the actual alignment
03586        restriction is unknown.  */
03587     && !((TREE_CODE (TREE_TYPE (otype)) == UNION_TYPE
03588     || TREE_CODE (TREE_TYPE (otype)) == RECORD_TYPE)
03589          && TYPE_MODE (TREE_TYPE (otype)) == VOIDmode)
03590     && TYPE_ALIGN (TREE_TYPE (type)) > TYPE_ALIGN (TREE_TYPE (otype)))
03591   warning (OPT_Wcast_align,
03592      "cast increases required alignment of target type");
03593 
03594       if (TREE_CODE (type) == INTEGER_TYPE
03595     && TREE_CODE (otype) == POINTER_TYPE
03596     && TYPE_PRECISION (type) != TYPE_PRECISION (otype))
03597       /* Unlike conversion of integers to pointers, where the
03598          warning is disabled for converting constants because
03599          of cases such as SIG_*, warn about converting constant
03600          pointers to integers. In some cases it may cause unwanted
03601          sign extension, and a warning is appropriate.  */
03602   warning (OPT_Wpointer_to_int_cast,
03603      "cast from pointer to integer of different size");
03604 
03605       if (TREE_CODE (value) == CALL_EXPR
03606     && TREE_CODE (type) != TREE_CODE (otype))
03607   warning (OPT_Wbad_function_cast, "cast from function call of type %qT "
03608      "to non-matching type %qT", otype, type);
03609 
03610       if (TREE_CODE (type) == POINTER_TYPE
03611     && TREE_CODE (otype) == INTEGER_TYPE
03612     && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
03613     /* Don't warn about converting any constant.  */
03614     && !TREE_CONSTANT (value))
03615   warning (OPT_Wint_to_pointer_cast, "cast to pointer from integer "
03616      "of different size");
03617 
03618       strict_aliasing_warning (otype, type, expr);
03619 
03620       /* If pedantic, warn for conversions between function and object
03621    pointer types, except for converting a null pointer constant
03622    to function pointer type.  */
03623       if (pedantic
03624     && TREE_CODE (type) == POINTER_TYPE
03625     && TREE_CODE (otype) == POINTER_TYPE
03626     && TREE_CODE (TREE_TYPE (otype)) == FUNCTION_TYPE
03627     && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE)
03628   pedwarn ("ISO C forbids conversion of function pointer to object pointer type");
03629 
03630       if (pedantic
03631     && TREE_CODE (type) == POINTER_TYPE
03632     && TREE_CODE (otype) == POINTER_TYPE
03633     && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
03634     && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
03635     && !null_pointer_constant_p (value))
03636   pedwarn ("ISO C forbids conversion of object pointer to function pointer type");
03637 
03638       ovalue = value;
03639       value = convert (type, value);
03640 
03641       /* Ignore any integer overflow caused by the cast.  */
03642       if (TREE_CODE (value) == INTEGER_CST)
03643   {
03644     if (CONSTANT_CLASS_P (ovalue)
03645         && (TREE_OVERFLOW (ovalue) || TREE_CONSTANT_OVERFLOW (ovalue)))
03646       {
03647         /* Avoid clobbering a shared constant.  */
03648         value = copy_node (value);
03649         TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue);
03650         TREE_CONSTANT_OVERFLOW (value) = TREE_CONSTANT_OVERFLOW (ovalue);
03651       }
03652     else if (TREE_OVERFLOW (value) || TREE_CONSTANT_OVERFLOW (value))
03653       /* Reset VALUE's overflow flags, ensuring constant sharing.  */
03654       value = build_int_cst_wide (TREE_TYPE (value),
03655           TREE_INT_CST_LOW (value),
03656           TREE_INT_CST_HIGH (value));
03657   }
03658     }
03659 
03660   /* Don't let a cast be an lvalue.  */
03661   if (value == expr)
03662     value = non_lvalue (value);
03663 
03664   return value;
03665 }
03666 
03667 /* Interpret a cast of expression EXPR to type TYPE.  */
03668 tree
03669 c_cast_expr (struct c_type_name *type_name, tree expr)
03670 {
03671   tree type;
03672   int saved_wsp = warn_strict_prototypes;
03673 
03674   /* This avoids warnings about unprototyped casts on
03675      integers.  E.g. "#define SIG_DFL (void(*)())0".  */
03676   if (TREE_CODE (expr) == INTEGER_CST)
03677     warn_strict_prototypes = 0;
03678   type = groktypename (type_name);
03679   warn_strict_prototypes = saved_wsp;
03680 
03681   return build_c_cast (type, expr);
03682 }
03683 
03684 /* Build an assignment expression of lvalue LHS from value RHS.
03685    MODIFYCODE is the code for a binary operator that we use
03686    to combine the old value of LHS with RHS to get the new value.
03687    Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.  */
03688 
03689 tree
03690 build_modify_expr (tree lhs, enum tree_code modifycode, tree rhs)
03691 {
03692   tree result;
03693   tree newrhs;
03694   tree lhstype = TREE_TYPE (lhs);
03695   tree olhstype = lhstype;
03696 
03697   /* Types that aren't fully specified cannot be used in assignments.  */
03698   lhs = require_complete_type (lhs);
03699 
03700   /* Avoid duplicate error messages from operands that had errors.  */
03701   if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK)
03702     return error_mark_node;
03703 
03704   if (!lvalue_or_else (lhs, lv_assign))
03705     return error_mark_node;
03706 
03707   STRIP_TYPE_NOPS (rhs);
03708 
03709   newrhs = rhs;
03710 
03711   /* If a binary op has been requested, combine the old LHS value with the RHS
03712      producing the value we should actually store into the LHS.  */
03713 
03714   if (modifycode != NOP_EXPR)
03715     {
03716       lhs = stabilize_reference (lhs);
03717       newrhs = build_binary_op (modifycode, lhs, rhs, 1);
03718     }
03719 
03720   /* Give an error for storing in something that is 'const'.  */
03721 
03722   if (TREE_READONLY (lhs) || TYPE_READONLY (lhstype)
03723       || ((TREE_CODE (lhstype) == RECORD_TYPE
03724      || TREE_CODE (lhstype) == UNION_TYPE)
03725     && C_TYPE_FIELDS_READONLY (lhstype)))
03726     {
03727       readonly_error (lhs, lv_assign);
03728       return error_mark_node;
03729     }
03730 
03731   /* If storing into a structure or union member,
03732      it has probably been given type `int'.
03733      Compute the type that would go with
03734      the actual amount of storage the member occupies.  */
03735 
03736   if (TREE_CODE (lhs) == COMPONENT_REF
03737       && (TREE_CODE (lhstype) == INTEGER_TYPE
03738     || TREE_CODE (lhstype) == BOOLEAN_TYPE
03739     || TREE_CODE (lhstype) == REAL_TYPE
03740     || TREE_CODE (lhstype) == ENUMERAL_TYPE))
03741     lhstype = TREE_TYPE (get_unwidened (lhs, 0));
03742 
03743   /* If storing in a field that is in actuality a short or narrower than one,
03744      we must store in the field in its actual type.  */
03745 
03746   if (lhstype != TREE_TYPE (lhs))
03747     {
03748       lhs = copy_node (lhs);
03749       TREE_TYPE (lhs) = lhstype;
03750     }
03751 
03752   /* Convert new value to destination type.  */
03753 
03754   newrhs = convert_for_assignment (lhstype, newrhs, ic_assign,
03755            NULL_TREE, NULL_TREE, 0);
03756   if (TREE_CODE (newrhs) == ERROR_MARK)
03757     return error_mark_node;
03758 
03759   /* Emit ObjC write barrier, if necessary.  */
03760   if (c_dialect_objc () && flag_objc_gc)
03761     {
03762       result = objc_generate_write_barrier (lhs, modifycode, newrhs);
03763       if (result)
03764   return result;
03765     }
03766 
03767   /* Scan operands.  */
03768 
03769   result = build2 (MODIFY_EXPR, lhstype, lhs, newrhs);
03770   TREE_SIDE_EFFECTS (result) = 1;
03771 
03772   /* If we got the LHS in a different type for storing in,
03773      convert the result back to the nominal type of LHS
03774      so that the value we return always has the same type
03775      as the LHS argument.  */
03776 
03777   if (olhstype == TREE_TYPE (result))
03778     return result;
03779   return convert_for_assignment (olhstype, result, ic_assign,
03780          NULL_TREE, NULL_TREE, 0);
03781 }
03782 
03783 /* Convert value RHS to type TYPE as preparation for an assignment
03784    to an lvalue of type TYPE.
03785    The real work of conversion is done by `convert'.
03786    The purpose of this function is to generate error messages
03787    for assignments that are not allowed in C.
03788    ERRTYPE says whether it is argument passing, assignment,
03789    initialization or return.
03790 
03791    FUNCTION is a tree for the function being called.
03792    PARMNUM is the number of the argument, for printing in error messages.  */
03793 
03794 static tree
03795 convert_for_assignment (tree type, tree rhs, enum impl_conv errtype,
03796       tree fundecl, tree function, int parmnum)
03797 {
03798   enum tree_code codel = TREE_CODE (type);
03799   tree rhstype;
03800   enum tree_code coder;
03801   tree rname = NULL_TREE;
03802   bool objc_ok = false;
03803 
03804   if (errtype == ic_argpass || errtype == ic_argpass_nonproto)
03805     {
03806       tree selector;
03807       /* Change pointer to function to the function itself for
03808    diagnostics.  */
03809       if (TREE_CODE (function) == ADDR_EXPR
03810     && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL)
03811   function = TREE_OPERAND (function, 0);
03812 
03813       /* Handle an ObjC selector specially for diagnostics.  */
03814       selector = objc_message_selector ();
03815       rname = function;
03816       if (selector && parmnum > 2)
03817   {
03818     rname = selector;
03819     parmnum -= 2;
03820   }
03821     }
03822 
03823   /* This macro is used to emit diagnostics to ensure that all format
03824      strings are complete sentences, visible to gettext and checked at
03825      compile time.  */
03826 #define WARN_FOR_ASSIGNMENT(AR, AS, IN, RE) \
03827   do {            \
03828     switch (errtype)        \
03829       {           \
03830       case ic_argpass:        \
03831   pedwarn (AR, parmnum, rname);   \
03832   break;          \
03833       case ic_argpass_nonproto:     \
03834   warning (0, AR, parmnum, rname);    \
03835   break;          \
03836       case ic_assign:       \
03837   pedwarn (AS);       \
03838   break;          \
03839       case ic_init:       \
03840   pedwarn (IN);       \
03841   break;          \
03842       case ic_return:       \
03843   pedwarn (RE);       \
03844   break;          \
03845       default:          \
03846   gcc_unreachable ();     \
03847       }           \
03848   } while (0)
03849 
03850   STRIP_TYPE_NOPS (rhs);
03851 
03852   if (optimize && TREE_CODE (rhs) == VAR_DECL
03853      && TREE_CODE (TREE_TYPE (rhs)) != ARRAY_TYPE)
03854     rhs = decl_constant_value_for_broken_optimization (rhs);
03855 
03856   rhstype = TREE_TYPE (rhs);
03857   coder = TREE_CODE (rhstype);
03858 
03859   if (coder == ERROR_MARK)
03860     return error_mark_node;
03861 
03862   if (c_dialect_objc ())
03863     {
03864       int parmno;
03865 
03866       switch (errtype)
03867   {
03868   case ic_return:
03869     parmno = 0;
03870     break;
03871 
03872   case ic_assign:
03873     parmno = -1;
03874     break;
03875 
03876   case ic_init:
03877     parmno = -2;
03878     break;
03879 
03880   default:
03881     parmno = parmnum;
03882     break;
03883   }
03884 
03885       objc_ok = objc_compare_types (type, rhstype, parmno, rname);
03886     }
03887 
03888   if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
03889     {
03890       overflow_warning (rhs);
03891       return rhs;
03892     }
03893 
03894   if (coder == VOID_TYPE)
03895     {
03896       /* Except for passing an argument to an unprototyped function,
03897    this is a constraint violation.  When passing an argument to
03898    an unprototyped function, it is compile-time undefined;
03899    making it a constraint in that case was rejected in
03900    DR#252.  */
03901       error ("void value not ignored as it ought to be");
03902       return error_mark_node;
03903     }
03904   /* A type converts to a reference to it.
03905      This code doesn't fully support references, it's just for the
03906      special case of va_start and va_copy.  */
03907   if (codel == REFERENCE_TYPE
03908       && comptypes (TREE_TYPE (type), TREE_TYPE (rhs)) == 1)
03909     {
03910       if (!lvalue_p (rhs))
03911   {
03912     error ("cannot pass rvalue to reference parameter");
03913     return error_mark_node;
03914   }
03915       if (!c_mark_addressable (rhs))
03916   return error_mark_node;
03917       rhs = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (rhs)), rhs);
03918 
03919       /* We already know that these two types are compatible, but they
03920    may not be exactly identical.  In fact, `TREE_TYPE (type)' is
03921    likely to be __builtin_va_list and `TREE_TYPE (rhs)' is
03922    likely to be va_list, a typedef to __builtin_va_list, which
03923    is different enough that it will cause problems later.  */
03924       if (TREE_TYPE (TREE_TYPE (rhs)) != TREE_TYPE (type))
03925   rhs = build1 (NOP_EXPR, build_pointer_type (TREE_TYPE (type)), rhs);
03926 
03927       rhs = build1 (NOP_EXPR, type, rhs);
03928       return rhs;
03929     }
03930   /* Some types can interconvert without explicit casts.  */
03931   else if (codel == VECTOR_TYPE && coder == VECTOR_TYPE
03932      && vector_types_convertible_p (type, TREE_TYPE (rhs)))
03933     return convert (type, rhs);
03934   /* Arithmetic types all interconvert, and enum is treated like int.  */
03935   else if ((codel == INTEGER_TYPE || codel == REAL_TYPE
03936       || codel == ENUMERAL_TYPE || codel == COMPLEX_TYPE
03937       || codel == BOOLEAN_TYPE)
03938      && (coder == INTEGER_TYPE || coder == REAL_TYPE
03939          || coder == ENUMERAL_TYPE || coder == COMPLEX_TYPE
03940          || coder == BOOLEAN_TYPE))
03941     return convert_and_check (type, rhs);
03942 
03943   /* Aggregates in different TUs might need conversion.  */
03944   if ((codel == RECORD_TYPE || codel == UNION_TYPE)
03945       && codel == coder
03946       && comptypes (type, rhstype))
03947     return convert_and_check (type, rhs);
03948 
03949   /* Conversion to a transparent union from its member types.
03950      This applies only to function arguments.  */
03951   if (codel == UNION_TYPE && TYPE_TRANSPARENT_UNION (type)
03952       && (errtype == ic_argpass || errtype == ic_argpass_nonproto))
03953     {
03954       tree memb, marginal_memb = NULL_TREE;
03955 
03956       for (memb = TYPE_FIELDS (type); memb ; memb = TREE_CHAIN (memb))
03957   {
03958     tree memb_type = TREE_TYPE (memb);
03959 
03960     if (comptypes (TYPE_MAIN_VARIANT (memb_type),
03961        TYPE_MAIN_VARIANT (rhstype)))
03962       break;
03963 
03964     if (TREE_CODE (memb_type) != POINTER_TYPE)
03965       continue;
03966 
03967     if (coder == POINTER_TYPE)
03968       {
03969         tree ttl = TREE_TYPE (memb_type);
03970         tree ttr = TREE_TYPE (rhstype);
03971 
03972         /* Any non-function converts to a [const][volatile] void *
03973      and vice versa; otherwise, targets must be the same.
03974      Meanwhile, the lhs target must have all the qualifiers of
03975      the rhs.  */
03976         if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr)
03977       || comp_target_types (memb_type, rhstype))
03978     {
03979       /* If this type won't generate any warnings, use it.  */
03980       if (TYPE_QUALS (ttl) == TYPE_QUALS (ttr)
03981           || ((TREE_CODE (ttr) == FUNCTION_TYPE
03982          && TREE_CODE (ttl) == FUNCTION_TYPE)
03983         ? ((TYPE_QUALS (ttl) | TYPE_QUALS (ttr))
03984            == TYPE_QUALS (ttr))
03985         : ((TYPE_QUALS (ttl) | TYPE_QUALS (ttr))
03986            == TYPE_QUALS (ttl))))
03987         break;
03988 
03989       /* Keep looking for a better type, but remember this one.  */
03990       if (!marginal_memb)
03991         marginal_memb = memb;
03992     }
03993       }
03994 
03995     /* Can convert integer zero to any pointer type.  */
03996     if (null_pointer_constant_p (rhs))
03997       {
03998         rhs = null_pointer_node;
03999         break;
04000       }
04001   }
04002 
04003       if (memb || marginal_memb)
04004   {
04005     if (!memb)
04006       {
04007         /* We have only a marginally acceptable member type;
04008      it needs a warning.  */
04009         tree ttl = TREE_TYPE (TREE_TYPE (marginal_memb));
04010         tree ttr = TREE_TYPE (rhstype);
04011 
04012         /* Const and volatile mean something different for function
04013      types, so the usual warnings are not appropriate.  */
04014         if (TREE_CODE (ttr) == FUNCTION_TYPE
04015       && TREE_CODE (ttl) == FUNCTION_TYPE)
04016     {
04017       /* Because const and volatile on functions are
04018          restrictions that say the function will not do
04019          certain things, it is okay to use a const or volatile
04020          function where an ordinary one is wanted, but not
04021          vice-versa.  */
04022       if (TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr))
04023         WARN_FOR_ASSIGNMENT (G_("passing argument %d of %qE "
04024               "makes qualified function "
04025               "pointer from unqualified"),
04026            G_("assignment makes qualified "
04027               "function pointer from "
04028               "unqualified"),
04029            G_("initialization makes qualified "
04030               "function pointer from "
04031               "unqualified"),
04032            G_("return makes qualified function "
04033               "pointer from unqualified"));
04034     }
04035         else if (TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl))
04036     WARN_FOR_ASSIGNMENT (G_("passing argument %d of %qE discards "
04037           "qualifiers from pointer target type"),
04038              G_("assignment discards qualifiers "
04039           "from pointer target type"),
04040              G_("initialization discards qualifiers "
04041           "from pointer target type"),
04042              G_("return discards qualifiers from "
04043           "pointer target type"));
04044 
04045         memb = marginal_memb;
04046       }
04047 
04048     if (pedantic && (!fundecl || !DECL_IN_SYSTEM_HEADER (fundecl)))
04049       pedwarn ("ISO C prohibits argument conversion to union type");
04050 
04051     return build_constructor_single (type, memb, rhs);
04052   }
04053     }
04054 
04055   /* Conversions among pointers */
04056   else if ((codel == POINTER_TYPE || codel == REFERENCE_TYPE)
04057      && (coder == codel))
04058     {
04059       tree ttl = TREE_TYPE (type);
04060       tree ttr = TREE_TYPE (rhstype);
04061       tree mvl = ttl;
04062       tree mvr = ttr;
04063       bool is_opaque_pointer;
04064       int target_cmp = 0;   /* Cache comp_target_types () result.  */
04065 
04066       if (TREE_CODE (mvl) != ARRAY_TYPE)
04067   mvl = TYPE_MAIN_VARIANT (mvl);
04068       if (TREE_CODE (mvr) != ARRAY_TYPE)
04069   mvr = TYPE_MAIN_VARIANT (mvr);
04070       /* Opaque pointers are treated like void pointers.  */
04071       is_opaque_pointer = (targetm.vector_opaque_p (type)
04072          || targetm.vector_opaque_p (rhstype))
04073   && TREE_CODE (ttl) == VECTOR_TYPE
04074   && TREE_CODE (ttr) == VECTOR_TYPE;
04075 
04076       /* C++ does not allow the implicit conversion void* -> T*.  However,
04077    for the purpose of reducing the number of false positives, we
04078    tolerate the special case of
04079 
04080     int *p = NULL;
04081 
04082    where NULL is typically defined in C to be '(void *) 0'.  */
04083       if (VOID_TYPE_P (ttr) && rhs != null_pointer_node && !VOID_TYPE_P (ttl))
04084   warning (OPT_Wc___compat, "request for implicit conversion from "
04085      "%qT to %qT not permitted in C++", rhstype, type);
04086 
04087       /* Check if the right-hand side has a format attribute but the
04088    left-hand side doesn't.  */
04089       if (warn_missing_format_attribute
04090     && check_missing_format_attribute (type, rhstype))
04091   {
04092     switch (errtype)
04093     {
04094     case ic_argpass:
04095     case ic_argpass_nonproto:
04096       warning (OPT_Wmissing_format_attribute,
04097          "argument %d of %qE might be "
04098          "a candidate for a format attribute",
04099          parmnum, rname);
04100       break;
04101     case ic_assign:
04102       warning (OPT_Wmissing_format_attribute,
04103          "assignment left-hand side might be "
04104          "a candidate for a format attribute");
04105       break;
04106     case ic_init:
04107       warning (OPT_Wmissing_format_attribute,
04108          "initialization left-hand side might be "
04109          "a candidate for a format attribute");
04110       break;
04111     case ic_return:
04112       warning (OPT_Wmissing_format_attribute,
04113          "return type might be "
04114          "a candidate for a format attribute");
04115       break;
04116     default:
04117       gcc_unreachable ();
04118     }
04119   }
04120 
04121       /* Any non-function converts to a [const][volatile] void *
04122    and vice versa; otherwise, targets must be the same.
04123    Meanwhile, the lhs target must have all the qualifiers of the rhs.  */
04124       if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr)
04125     || (target_cmp = comp_target_types (type, rhstype))
04126     || is_opaque_pointer
04127     || (c_common_unsigned_type (mvl)
04128         == c_common_unsigned_type (mvr)))
04129   {
04130     if (pedantic
04131         && ((VOID_TYPE_P (ttl) && TREE_CODE (ttr) == FUNCTION_TYPE)
04132       ||
04133       (VOID_TYPE_P (ttr)
04134        && !null_pointer_constant_p (rhs)
04135        && TREE_CODE (ttl) == FUNCTION_TYPE)))
04136       WARN_FOR_ASSIGNMENT (G_("ISO C forbids passing argument %d of "
04137             "%qE between function pointer "
04138             "and %<void *%>"),
04139          G_("ISO C forbids assignment between "
04140             "function pointer and %<void *%>"),
04141          G_("ISO C forbids initialization between "
04142             "function pointer and %<void *%>"),
04143          G_("ISO C forbids return between function "
04144             "pointer and %<void *%>"));
04145     /* Const and volatile mean something different for function types,
04146        so the usual warnings are not appropriate.  */
04147     else if (TREE_CODE (ttr) != FUNCTION_TYPE
04148        && TREE_CODE (ttl) != FUNCTION_TYPE)
04149       {
04150         if (TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl))
04151     {
04152       /* Types differing only by the presence of the 'volatile'
04153          qualifier are acceptable if the 'volatile' has been added
04154          in by the Objective-C EH machinery.  */
04155       if (!objc_type_quals_match (ttl, ttr))
04156         WARN_FOR_ASSIGNMENT (G_("passing argument %d of %qE discards "
04157               "qualifiers from pointer target type"),
04158            G_("assignment discards qualifiers "
04159               "from pointer target type"),
04160            G_("initialization discards qualifiers "
04161               "from pointer target type"),
04162            G_("return discards qualifiers from "
04163               "pointer target type"));
04164     }
04165         /* If this is not a case of ignoring a mismatch in signedness,
04166      no warning.  */
04167         else if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr)
04168            || target_cmp)
04169     ;
04170         /* If there is a mismatch, do warn.  */
04171         else if (warn_pointer_sign)
04172     WARN_FOR_ASSIGNMENT (G_("pointer targets in passing argument "
04173           "%d of %qE differ in signedness"),
04174              G_("pointer targets in assignment "
04175           "differ in signedness"),
04176              G_("pointer targets in initialization "
04177           "differ in signedness"),
04178              G_("pointer targets in return differ "
04179           "in signedness"));
04180       }
04181     else if (TREE_CODE (ttl) == FUNCTION_TYPE
04182        && TREE_CODE (ttr) == FUNCTION_TYPE)
04183       {
04184         /* Because const and volatile on functions are restrictions
04185      that say the function will not do certain things,
04186      it is okay to use a const or volatile function
04187      where an ordinary one is wanted, but not vice-versa.  */
04188         if (TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr))
04189     WARN_FOR_ASSIGNMENT (G_("passing argument %d of %qE makes "
04190           "qualified function pointer "
04191           "from unqualified"),
04192              G_("assignment makes qualified function "
04193           "pointer from unqualified"),
04194              G_("initialization makes qualified "
04195           "function pointer from unqualified"),
04196              G_("return makes qualified function "
04197           "pointer from unqualified"));
04198       }
04199   }
04200       else
04201   /* Avoid warning about the volatile ObjC EH puts on decls.  */
04202   if (!objc_ok)
04203     WARN_FOR_ASSIGNMENT (G_("passing argument %d of %qE from "
04204           "incompatible pointer type"),
04205              G_("assignment from incompatible pointer type"),
04206              G_("initialization from incompatible "
04207           "pointer type"),
04208              G_("return from incompatible pointer type"));
04209 
04210       return convert (type, rhs);
04211     }
04212   else if (codel == POINTER_TYPE && coder == ARRAY_TYPE)
04213     {
04214       /* ??? This should not be an error when inlining calls to
04215    unprototyped functions.  */
04216       error ("invalid use of non-lvalue array");
04217       return error_mark_node;
04218     }
04219   else if (codel == POINTER_TYPE && coder == INTEGER_TYPE)
04220     {
04221       /* An explicit constant 0 can convert to a pointer,
04222    or one that results from arithmetic, even including
04223    a cast to integer type.  */
04224       if (!null_pointer_constant_p (rhs))
04225   WARN_FOR_ASSIGNMENT (G_("passing argument %d of %qE makes "
04226         "pointer from integer without a cast"),
04227            G_("assignment makes pointer from integer "
04228         "without a cast"),
04229            G_("initialization makes pointer from "
04230         "integer without a cast"),
04231            G_("return makes pointer from integer "
04232         "without a cast"));
04233 
04234       return convert (type, rhs);
04235     }
04236   else if (codel == INTEGER_TYPE && coder == POINTER_TYPE)
04237     {
04238       WARN_FOR_ASSIGNMENT (G_("passing argument %d of %qE makes integer "
04239             "from pointer without a cast"),
04240          G_("assignment makes integer from pointer "
04241             "without a cast"),
04242          G_("initialization makes integer from pointer "
04243             "without a cast"),
04244          G_("return makes integer from pointer "
04245             "without a cast"));
04246       return convert (type, rhs);
04247     }
04248   else if (codel == BOOLEAN_TYPE && coder == POINTER_TYPE)
04249     return convert (type, rhs);
04250 
04251   switch (errtype)
04252     {
04253     case ic_argpass:
04254     case ic_argpass_nonproto:
04255       /* ??? This should not be an error when inlining calls to
04256    unprototyped functions.  */
04257       error ("incompatible type for argument %d of %qE", parmnum, rname);
04258       break;
04259     case ic_assign:
04260       error ("incompatible types in assignment");
04261       break;
04262     case ic_init:
04263       error ("incompatible types in initialization");
04264       break;
04265     case ic_return:
04266       error ("incompatible types in return");
04267       break;
04268     default:
04269       gcc_unreachable ();
04270     }
04271 
04272   return error_mark_node;
04273 }
04274 
04275 /* Convert VALUE for assignment into inlined parameter PARM.  ARGNUM
04276    is used for error and warning reporting and indicates which argument
04277    is being processed.  */
04278 
04279 tree
04280 c_convert_parm_for_inlining (tree parm, tree value, tree fn, int argnum)
04281 {
04282   tree ret, type;
04283 
04284   /* If FN was prototyped at the call site, the value has been converted
04285      already in convert_arguments.
04286      However, we might see a prototype now that was not in place when
04287      the function call was seen, so check that the VALUE actually matches
04288      PARM before taking an early exit.  */
04289   if (!value
04290       || (TYPE_ARG_TYPES (TREE_TYPE (fn))
04291     && (TYPE_MAIN_VARIANT (TREE_TYPE (parm))
04292         == TYPE_MAIN_VARIANT (TREE_TYPE (value)))))
04293     return value;
04294 
04295   type = TREE_TYPE (parm);
04296   ret = convert_for_assignment (type, value,
04297         ic_argpass_nonproto, fn,
04298         fn, argnum);
04299   if (targetm.calls.promote_prototypes (TREE_TYPE (fn))
04300       && INTEGRAL_TYPE_P (type)
04301       && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
04302     ret = default_conversion (ret);
04303   return ret;
04304 }
04305 
04306 /* If VALUE is a compound expr all of whose expressions are constant, then
04307    return its value.  Otherwise, return error_mark_node.
04308 
04309    This is for handling COMPOUND_EXPRs as initializer elements
04310    which is allowed with a warning when -pedantic is specified.  */
04311 
04312 static tree
04313 valid_compound_expr_initializer (tree value, tree endtype)
04314 {
04315   if (TREE_CODE (value) == COMPOUND_EXPR)
04316     {
04317       if (valid_compound_expr_initializer (TREE_OPERAND (value, 0), endtype)
04318     == error_mark_node)
04319   return error_mark_node;
04320       return valid_compound_expr_initializer (TREE_OPERAND (value, 1),
04321                 endtype);
04322     }
04323   else if (!initializer_constant_valid_p (value, endtype))
04324     return error_mark_node;
04325   else
04326     return value;
04327 }
04328 
04329 /* Perform appropriate conversions on the initial value of a variable,
04330    store it in the declaration DECL,
04331    and print any error messages that are appropriate.
04332    If the init is invalid, store an ERROR_MARK.  */
04333 
04334 void
04335 store_init_value (tree decl, tree init)
04336 {
04337   tree value, type;
04338 
04339   /* If variable's type was invalidly declared, just ignore it.  */
04340 
04341   type = TREE_TYPE (decl);
04342   if (TREE_CODE (type) == ERROR_MARK)
04343     return;
04344 
04345   /* Digest the specified initializer into an expression.  */
04346 
04347   value = digest_init (type, init, true, TREE_STATIC (decl));
04348 
04349   /* Store the expression if valid; else report error.  */
04350 
04351   if (!in_system_header
04352       && AGGREGATE_TYPE_P (TREE_TYPE (decl)) && !TREE_STATIC (decl))
04353     warning (OPT_Wtraditional, "traditional C rejects automatic "
04354        "aggregate initialization");
04355 
04356   DECL_INITIAL (decl) = value;
04357 
04358   /* ANSI wants warnings about out-of-range constant initializers.  */
04359   STRIP_TYPE_NOPS (value);
04360   constant_expression_warning (value);
04361 
04362   /* Check if we need to set array size from compound literal size.  */
04363   if (TREE_CODE (type) == ARRAY_TYPE
04364       && TYPE_DOMAIN (type) == 0
04365       && value != error_mark_node)
04366     {
04367       tree inside_init = init;
04368 
04369       STRIP_TYPE_NOPS (inside_init);
04370       inside_init = fold (inside_init);
04371 
04372       if (TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
04373   {
04374     tree cldecl = COMPOUND_LITERAL_EXPR_DECL (inside_init);
04375 
04376     if (TYPE_DOMAIN (TREE_TYPE (cldecl)))
04377       {
04378         /* For int foo[] = (int [3]){1}; we need to set array size
04379      now since later on array initializer will be just the
04380      brace enclosed list of the compound literal.  */
04381         type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
04382         TREE_TYPE (decl) = type;
04383         TYPE_DOMAIN (type) = TYPE_DOMAIN (TREE_TYPE (cldecl));
04384         layout_type (type);
04385         layout_decl (cldecl, 0);
04386       }
04387   }
04388     }
04389 }
04390 
04391 /* Methods for storing and printing names for error messages.  */
04392 
04393 /* Implement a spelling stack that allows components of a name to be pushed
04394    and popped.  Each element on the stack is this structure.  */
04395 
04396 struct spelling
04397 {
04398   int kind;
04399   union
04400     {
04401       unsigned HOST_WIDE_INT i;
04402       const char *s;
04403     } u;
04404 };
04405 
04406 #define SPELLING_STRING 1
04407 #define SPELLING_MEMBER 2
04408 #define SPELLING_BOUNDS 3
04409 
04410 static struct spelling *spelling; /* Next stack element (unused).  */
04411 static struct spelling *spelling_base;  /* Spelling stack base.  */
04412 static int spelling_size;   /* Size of the spelling stack.  */
04413 
04414 /* Macros to save and restore the spelling stack around push_... functions.
04415    Alternative to SAVE_SPELLING_STACK.  */
04416 
04417 #define SPELLING_DEPTH() (spelling - spelling_base)
04418 #define RESTORE_SPELLING_DEPTH(DEPTH) (spelling = spelling_base + (DEPTH))
04419 
04420 /* Push an element on the spelling stack with type KIND and assign VALUE
04421    to MEMBER.  */
04422 
04423 #define PUSH_SPELLING(KIND, VALUE, MEMBER)        \
04424 {                 \
04425   int depth = SPELLING_DEPTH ();          \
04426                   \
04427   if (depth >= spelling_size)           \
04428     {                 \
04429       spelling_size += 10;            \
04430       spelling_base = XRESIZEVEC (struct spelling, spelling_base, \
04431           spelling_size);     \
04432       RESTORE_SPELLING_DEPTH (depth);         \
04433     }                 \
04434                   \
04435   spelling->kind = (KIND);            \
04436   spelling->MEMBER = (VALUE);           \
04437   spelling++;               \
04438 }
04439 
04440 /* Push STRING on the stack.  Printed literally.  */
04441 
04442 static void
04443 push_string (const char *string)
04444 {
04445   PUSH_SPELLING (SPELLING_STRING, string, u.s);
04446 }
04447 
04448 /* Push a member name on the stack.  Printed as '.' STRING.  */
04449 
04450 static void
04451 push_member_name (tree decl)
04452 {
04453   const char *const string
04454     = DECL_NAME (decl) ? IDENTIFIER_POINTER (DECL_NAME (decl)) : "<anonymous>";
04455   PUSH_SPELLING (SPELLING_MEMBER, string, u.s);
04456 }
04457 
04458 /* Push an array bounds on the stack.  Printed as [BOUNDS].  */
04459 
04460 static void
04461 push_array_bounds (unsigned HOST_WIDE_INT bounds)
04462 {
04463   PUSH_SPELLING (SPELLING_BOUNDS, bounds, u.i);
04464 }
04465 
04466 /* Compute the maximum size in bytes of the printed spelling.  */
04467 
04468 static int
04469 spelling_length (void)
04470 {
04471   int size = 0;
04472   struct spelling *p;
04473 
04474   for (p = spelling_base; p < spelling; p++)
04475     {
04476       if (p->kind == SPELLING_BOUNDS)
04477   size += 25;
04478       else
04479   size += strlen (p->u.s) + 1;
04480     }
04481 
04482   return size;
04483 }
04484 
04485 /* Print the spelling to BUFFER and return it.  */
04486 
04487 static char *
04488 print_spelling (char *buffer)
04489 {
04490   char *d = buffer;
04491   struct spelling *p;
04492 
04493   for (p = spelling_base; p < spelling; p++)
04494     if (p->kind == SPELLING_BOUNDS)
04495       {
04496   sprintf (d, "[" HOST_WIDE_INT_PRINT_UNSIGNED "]", p->u.i);
04497   d += strlen (d);
04498       }
04499     else
04500       {
04501   const char *s;
04502   if (p->kind == SPELLING_MEMBER)
04503     *d++ = '.';
04504   for (s = p->u.s; (*d = *s++); d++)
04505     ;
04506       }
04507   *d++ = '\0';
04508   return buffer;
04509 }
04510 
04511 /* Issue an error message for a bad initializer component.
04512    MSGID identifies the message.
04513    The component name is taken from the spelling stack.  */
04514 
04515 void
04516 error_init (const char *msgid)
04517 {
04518   char *ofwhat;
04519 
04520   error ("%s", _(msgid));
04521   ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
04522   if (*ofwhat)
04523     error ("(near initialization for %qs)", ofwhat);
04524 }
04525 
04526 /* Issue a pedantic warning for a bad initializer component.
04527    MSGID identifies the message.
04528    The component name is taken from the spelling stack.  */
04529 
04530 void
04531 pedwarn_init (const char *msgid)
04532 {
04533   char *ofwhat;
04534 
04535   pedwarn ("%s", _(msgid));
04536   ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
04537   if (*ofwhat)
04538     pedwarn ("(near initialization for %qs)", ofwhat);
04539 }
04540 
04541 /* Issue a warning for a bad initializer component.
04542    MSGID identifies the message.
04543    The component name is taken from the spelling stack.  */
04544 
04545 static void
04546 warning_init (const char *msgid)
04547 {
04548   char *ofwhat;
04549 
04550   warning (0, "%s", _(msgid));
04551   ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
04552   if (*ofwhat)
04553     warning (0, "(near initialization for %qs)", ofwhat);
04554 }
04555 
04556 /* If TYPE is an array type and EXPR is a parenthesized string
04557    constant, warn if pedantic that EXPR is being used to initialize an
04558    object of type TYPE.  */
04559 
04560 void
04561 maybe_warn_string_init (tree type, struct c_expr expr)
04562 {
04563   if (pedantic
04564       && TREE_CODE (type) == ARRAY_TYPE
04565       && TREE_CODE (expr.value) == STRING_CST
04566       && expr.original_code != STRING_CST)
04567     pedwarn_init ("array initialized from parenthesized string constant");
04568 }
04569 
04570 /* Digest the parser output INIT as an initializer for type TYPE.
04571    Return a C expression of type TYPE to represent the initial value.
04572 
04573    If INIT is a string constant, STRICT_STRING is true if it is
04574    unparenthesized or we should not warn here for it being parenthesized.
04575    For other types of INIT, STRICT_STRING is not used.
04576 
04577    REQUIRE_CONSTANT requests an error if non-constant initializers or
04578    elements are seen.  */
04579 
04580 static tree
04581 digest_init (tree type, tree init, bool strict_string, int require_constant)
04582 {
04583   enum tree_code code = TREE_CODE (type);
04584   tree inside_init = init;
04585 
04586   if (type == error_mark_node
04587       || !init
04588       || init == error_mark_node
04589       || TREE_TYPE (init) == error_mark_node)
04590     return error_mark_node;
04591 
04592   STRIP_TYPE_NOPS (inside_init);
04593 
04594   inside_init = fold (inside_init);
04595 
04596   /* Initialization of an array of chars from a string constant
04597      optionally enclosed in braces.  */
04598 
04599   if (code == ARRAY_TYPE && inside_init
04600       && TREE_CODE (inside_init) == STRING_CST)
04601     {
04602       tree typ1 = TYPE_MAIN_VARIANT (TREE_TYPE (type));
04603       /* Note that an array could be both an array of character type
04604    and an array of wchar_t if wchar_t is signed char or unsigned
04605    char.  */
04606       bool char_array = (typ1 == char_type_node
04607        || typ1 == signed_char_type_node
04608        || typ1 == unsigned_char_type_node);
04609       bool wchar_array = !!comptypes (typ1, wchar_type_node);
04610       if (char_array || wchar_array)
04611   {
04612     struct c_expr expr;
04613     bool char_string;
04614     expr.value = inside_init;
04615     expr.original_code = (strict_string ? STRING_CST : ERROR_MARK);
04616     maybe_warn_string_init (type, expr);
04617 
04618     char_string
04619       = (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init)))
04620          == char_type_node);
04621 
04622     if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
04623        TYPE_MAIN_VARIANT (type)))
04624       return inside_init;
04625 
04626     if (!wchar_array && !char_string)
04627       {
04628         error_init ("char-array initialized from wide string");
04629         return error_mark_node;
04630       }
04631     if (char_string && !char_array)
04632       {
04633         error_init ("wchar_t-array initialized from non-wide string");
04634         return error_mark_node;
04635       }
04636 
04637     TREE_TYPE (inside_init) = type;
04638     if (TYPE_DOMAIN (type) != 0
04639         && TYPE_SIZE (type) != 0
04640         && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
04641         /* Subtract 1 (or sizeof (wchar_t))
04642      because it's ok to ignore the terminating null char
04643      that is counted in the length of the constant.  */
04644         && 0 > compare_tree_int (TYPE_SIZE_UNIT (type),
04645                TREE_STRING_LENGTH (inside_init)
04646                - ((TYPE_PRECISION (typ1)
04647              != TYPE_PRECISION (char_type_node))
04648             ? (TYPE_PRECISION (wchar_type_node)
04649                / BITS_PER_UNIT)
04650             : 1)))
04651       pedwarn_init ("initializer-string for array of chars is too long");
04652 
04653     return inside_init;
04654   }
04655       else if (INTEGRAL_TYPE_P (typ1))
04656   {
04657     error_init ("array of inappropriate type initialized "
04658           "from string constant");
04659     return error_mark_node;
04660   }
04661     }
04662 
04663   /* Build a VECTOR_CST from a *constant* vector constructor.  If the
04664      vector constructor is not constant (e.g. {1,2,3,foo()}) then punt
04665      below and handle as a constructor.  */
04666   if (code == VECTOR_TYPE
04667       && TREE_CODE (TREE_TYPE (inside_init)) == VECTOR_TYPE
04668       && vector_types_convertible_p (TREE_TYPE (inside_init), type)
04669       && TREE_CONSTANT (inside_init))
04670     {
04671       if (TREE_CODE (inside_init) == VECTOR_CST
04672     && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
04673       TYPE_MAIN_VARIANT (type)))
04674   return inside_init;
04675 
04676       if (TREE_CODE (inside_init) == CONSTRUCTOR)
04677   {
04678     unsigned HOST_WIDE_INT ix;
04679     tree value;
04680     bool constant_p = true;
04681 
04682     /* Iterate through elements and check if all constructor
04683        elements are *_CSTs.  */
04684     FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (inside_init), ix, value)
04685       if (!CONSTANT_CLASS_P (value))
04686         {
04687     constant_p = false;
04688     break;
04689         }
04690 
04691     if (constant_p)
04692       return build_vector_from_ctor (type,
04693              CONSTRUCTOR_ELTS (inside_init));
04694   }
04695     }
04696 
04697   /* Any type can be initialized
04698      from an expression of the same type, optionally with braces.  */
04699 
04700   if (inside_init && TREE_TYPE (inside_init) != 0
04701       && (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
04702          TYPE_MAIN_VARIANT (type))
04703     || (code == ARRAY_TYPE
04704         && comptypes (TREE_TYPE (inside_init), type))
04705     || (code == VECTOR_TYPE
04706         && comptypes (TREE_TYPE (inside_init), type))
04707     || (code == POINTER_TYPE
04708         && TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE
04709         && comptypes (TREE_TYPE (TREE_TYPE (inside_init)),
04710           TREE_TYPE (type)))))
04711     {
04712       if (code == POINTER_TYPE)
04713   {
04714     if (TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE)
04715       {
04716         if (TREE_CODE (inside_init) == STRING_CST
04717       || TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
04718     inside_init = array_to_pointer_conversion (inside_init);
04719         else
04720     {
04721       error_init ("invalid use of non-lvalue array");
04722       return error_mark_node;
04723     }
04724       }
04725   }
04726 
04727       if (code == VECTOR_TYPE)
04728   /* Although the types are compatible, we may require a
04729      conversion.  */
04730   inside_init = convert (type, inside_init);
04731 
04732       if (require_constant
04733     && (code == VECTOR_TYPE || !flag_isoc99)
04734     && TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
04735   {
04736     /* As an extension, allow initializing objects with static storage
04737        duration with compound literals (which are then treated just as
04738        the brace enclosed list they contain).  Also allow this for
04739        vectors, as we can only assign them with compound literals.  */
04740     tree decl = COMPOUND_LITERAL_EXPR_DECL (inside_init);
04741     inside_init = DECL_INITIAL (decl);
04742   }
04743 
04744       if (code == ARRAY_TYPE && TREE_CODE (inside_init) != STRING_CST
04745     && TREE_CODE (inside_init) != CONSTRUCTOR)
04746   {
04747     error_init ("array initialized from non-constant array expression");
04748     return error_mark_node;
04749   }
04750 
04751       if (optimize && TREE_CODE (inside_init) == VAR_DECL)
04752   inside_init = decl_constant_value_for_broken_optimization (inside_init);
04753 
04754       /* Compound expressions can only occur here if -pedantic or
04755    -pedantic-errors is specified.  In the later case, we always want
04756    an error.  In the former case, we simply want a warning.  */
04757       if (require_constant && pedantic
04758     && TREE_CODE (inside_init) == COMPOUND_EXPR)
04759   {
04760     inside_init
04761       = valid_compound_expr_initializer (inside_init,
04762                  TREE_TYPE (inside_init));
04763     if (inside_init == error_mark_node)
04764       error_init ("initializer element is not constant");
04765     else
04766       pedwarn_init ("initializer element is not constant");
04767     if (flag_pedantic_errors)
04768       inside_init = error_mark_node;
04769   }
04770       else if (require_constant
04771          && !initializer_constant_valid_p (inside_init,
04772              TREE_TYPE (inside_init)))
04773   {
04774     error_init ("initializer element is not constant");
04775     inside_init = error_mark_node;
04776   }
04777 
04778       /* Added to enable additional -Wmissing-format-attribute warnings.  */
04779       if (TREE_CODE (TREE_TYPE (inside_init)) == POINTER_TYPE)
04780   inside_init = convert_for_assignment (type, inside_init, ic_init, NULL_TREE,
04781                 NULL_TREE, 0);
04782       return inside_init;
04783     }
04784 
04785   /* Handle scalar types, including conversions.  */
04786 
04787   if (code == INTEGER_TYPE || code == REAL_TYPE || code == POINTER_TYPE
04788       || code == ENUMERAL_TYPE || code == BOOLEAN_TYPE || code == COMPLEX_TYPE
04789       || code == VECTOR_TYPE)
04790     {
04791       if (TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE
04792     && (TREE_CODE (init) == STRING_CST
04793         || TREE_CODE (init) == COMPOUND_LITERAL_EXPR))
04794   init = array_to_pointer_conversion (init);
04795       inside_init
04796   = convert_for_assignment (type, init, ic_init,
04797           NULL_TREE, NULL_TREE, 0);
04798 
04799       /* Check to see if we have already given an error message.  */
04800       if (inside_init == error_mark_node)
04801   ;
04802       else if (require_constant && !TREE_CONSTANT (inside_init))
04803   {
04804     error_init ("initializer element is not constant");
04805     inside_init = error_mark_node;
04806   }
04807       else if (require_constant
04808          && !initializer_constant_valid_p (inside_init,
04809              TREE_TYPE (inside_init)))
04810   {
04811     error_init ("initializer element is not computable at load time");
04812     inside_init = error_mark_node;
04813   }
04814 
04815       return inside_init;
04816     }
04817 
04818   /* Come here only for records and arrays.  */
04819 
04820   if (COMPLETE_TYPE_P (type) && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
04821     {
04822       error_init ("variable-sized object may not be initialized");
04823       return error_mark_node;
04824     }
04825 
04826   error_init ("invalid initializer");
04827   return error_mark_node;
04828 }
04829 
04830 /* Handle initializers that use braces.  */
04831 
04832 /* Type of object we are accumulating a constructor for.
04833    This type is always a RECORD_TYPE, UNION_TYPE or ARRAY_TYPE.  */
04834 static tree constructor_type;
04835 
04836 /* For a RECORD_TYPE or UNION_TYPE, this is the chain of fields
04837    left to fill.  */
04838 static tree constructor_fields;
04839 
04840 /* For an ARRAY_TYPE, this is the specified index
04841    at which to store the next element we get.  */
04842 static tree constructor_index;
04843 
04844 /* For an ARRAY_TYPE, this is the maximum index.  */
04845 static tree constructor_max_index;
04846 
04847 /* For a RECORD_TYPE, this is the first field not yet written out.  */
04848 static tree constructor_unfilled_fields;
04849 
04850 /* For an ARRAY_TYPE, this is the index of the first element
04851    not yet written out.  */
04852 static tree constructor_unfilled_index;
04853 
04854 /* In a RECORD_TYPE, the byte index of the next consecutive field.
04855    This is so we can generate gaps between fields, when appropriate.  */
04856 static tree constructor_bit_index;
04857 
04858 /* If we are saving up the elements rather than allocating them,
04859    this is the list of elements so far (in reverse order,
04860    most recent first).  */
04861 static VEC(constructor_elt,gc) *constructor_elements;
04862 
04863 /* 1 if constructor should be incrementally stored into a constructor chain,
04864    0 if all the elements should be kept in AVL tree.  */
04865 static int constructor_incremental;
04866 
04867 /* 1 if so far this constructor's elements are all compile-time constants.  */
04868 static int constructor_constant;
04869 
04870 /* 1 if so far this constructor's elements are all valid address constants.  */
04871 static int constructor_simple;
04872 
04873 /* 1 if this constructor is erroneous so far.  */
04874 static int constructor_erroneous;
04875 
04876 /* Structure for managing pending initializer elements, organized as an
04877    AVL tree.  */
04878 
04879 struct init_node
04880 {
04881   struct init_node *left, *right;
04882   struct init_node *parent;
04883   int balance;
04884   tree purpose;
04885   tree value;
04886 };
04887 
04888 /* Tree of pending elements at this constructor level.
04889    These are elements encountered out of order
04890    which belong at places we haven't reached yet in actually
04891    writing the output.
04892    Will never hold tree nodes across GC runs.  */
04893 static struct init_node *constructor_pending_elts;
04894 
04895 /* The SPELLING_DEPTH of this constructor.  */
04896 static int constructor_depth;
04897 
04898 /* DECL node for which an initializer is being read.
04899    0 means we are reading a constructor expression
04900    such as (struct foo) {...}.  */
04901 static tree constructor_decl;
04902 
04903 /* Nonzero if this is an initializer for a top-level decl.  */
04904 static int constructor_top_level;
04905 
04906 /* Nonzero if there were any member designators in this initializer.  */
04907 static int constructor_designated;
04908 
04909 /* Nesting depth of designator list.  */
04910 static int designator_depth;
04911 
04912 /* Nonzero if there were diagnosed errors in this designator list.  */
04913 static int designator_erroneous;
04914 
04915 
04916 /* This stack has a level for each implicit or explicit level of
04917    structuring in the initializer, including the outermost one.  It
04918    saves the values of most of the variables above.  */
04919 
04920 struct constructor_range_stack;
04921 
04922 struct constructor_stack
04923 {
04924   struct constructor_stack *next;
04925   tree type;
04926   tree fields;
04927   tree index;
04928   tree max_index;
04929   tree unfilled_index;
04930   tree unfilled_fields;
04931   tree bit_index;
04932   VEC(constructor_elt,gc) *elements;
04933   struct init_node *pending_elts;
04934   int offset;
04935   int depth;
04936   /* If value nonzero, this value should replace the entire
04937      constructor at this level.  */
04938   struct c_expr replacement_value;
04939   struct constructor_range_stack *range_stack;
04940   char constant;
04941   char simple;
04942   char implicit;
04943   char erroneous;
04944   char outer;
04945   char incremental;
04946   char designated;
04947 };
04948 
04949 static struct constructor_stack *constructor_stack;
04950 
04951 /* This stack represents designators from some range designator up to
04952    the last designator in the list.  */
04953 
04954 struct constructor_range_stack
04955 {
04956   struct constructor_range_stack *next, *prev;
04957   struct constructor_stack *stack;
04958   tree range_start;
04959   tree index;
04960   tree range_end;
04961   tree fields;
04962 };
04963 
04964 static struct constructor_range_stack *constructor_range_stack;
04965 
04966 /* This stack records separate initializers that are nested.
04967    Nested initializers can't happen in ANSI C, but GNU C allows them
04968    in cases like { ... (struct foo) { ... } ... }.  */
04969 
04970 struct initializer_stack
04971 {
04972   struct initializer_stack *next;
04973   tree decl;
04974   struct constructor_stack *constructor_stack;
04975   struct constructor_range_stack *constructor_range_stack;
04976   VEC(constructor_elt,gc) *elements;
04977   struct spelling *spelling;
04978   struct spelling *spelling_base;
04979   int spelling_size;
04980   char top_level;
04981   char require_constant_value;
04982   char require_constant_elements;
04983 };
04984 
04985 static struct initializer_stack *initializer_stack;
04986 
04987 /* Prepare to parse and output the initializer for variable DECL.  */
04988 
04989 void
04990 start_init (tree decl, tree asmspec_tree ATTRIBUTE_UNUSED, int top_level)
04991 {
04992   const char *locus;
04993   struct initializer_stack *p = XNEW (struct initializer_stack);
04994 
04995   p->decl = constructor_decl;
04996   p->require_constant_value = require_constant_value;
04997   p->require_constant_elements = require_constant_elements;
04998   p->constructor_stack = constructor_stack;
04999   p->constructor_range_stack = constructor_range_stack;
05000   p->elements = constructor_elements;
05001   p->spelling = spelling;
05002   p->spelling_base = spelling_base;
05003   p->spelling_size = spelling_size;
05004   p->top_level = constructor_top_level;
05005   p->next = initializer_stack;
05006   initializer_stack = p;
05007 
05008   constructor_decl = decl;
05009   constructor_designated = 0;
05010   constructor_top_level = top_level;
05011 
05012   if (decl != 0 && decl != error_mark_node)
05013     {
05014       require_constant_value = TREE_STATIC (decl);
05015       require_constant_elements
05016   = ((TREE_STATIC (decl) || (pedantic && !flag_isoc99))
05017      /* For a scalar, you can always use any value to initialize,
05018         even within braces.  */
05019      && (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
05020          || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
05021          || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
05022          || TREE_CODE (TREE_TYPE (decl)) == QUAL_UNION_TYPE));
05023       locus = IDENTIFIER_POINTER (DECL_NAME (decl));
05024     }
05025   else
05026     {
05027       require_constant_value = 0;
05028       require_constant_elements = 0;
05029       locus = "(anonymous)";
05030     }
05031 
05032   constructor_stack = 0;
05033   constructor_range_stack = 0;
05034 
05035   missing_braces_mentioned = 0;
05036 
05037   spelling_base = 0;
05038   spelling_size = 0;
05039   RESTORE_SPELLING_DEPTH (0);
05040 
05041   if (locus)
05042     push_string (locus);
05043 }
05044 
05045 void
05046 finish_init (void)
05047 {
05048   struct initializer_stack *p = initializer_stack;
05049 
05050   /* Free the whole constructor stack of this initializer.  */
05051   while (constructor_stack)
05052     {
05053       struct constructor_stack *q = constructor_stack;
05054       constructor_stack = q->next;
05055       free (q);
05056     }
05057 
05058   gcc_assert (!constructor_range_stack);
05059 
05060   /* Pop back to the data of the outer initializer (if any).  */
05061   free (spelling_base);
05062 
05063   constructor_decl = p->decl;
05064   require_constant_value = p->require_constant_value;
05065   require_constant_elements = p->require_constant_elements;
05066   constructor_stack = p->constructor_stack;
05067   constructor_range_stack = p->constructor_range_stack;
05068   constructor_elements = p->elements;
05069   spelling = p->spelling;
05070   spelling_base = p->spelling_base;
05071   spelling_size = p->spelling_size;
05072   constructor_top_level = p->top_level;
05073   initializer_stack = p->next;
05074   free (p);
05075 }
05076 
05077 /* Call here when we see the initializer is surrounded by braces.
05078    This is instead of a call to push_init_level;
05079    it is matched by a call to pop_init_level.
05080 
05081    TYPE is the type to initialize, for a constructor expression.
05082    For an initializer for a decl, TYPE is zero.  */
05083 
05084 void
05085 really_start_incremental_init (tree type)
05086 {
05087   struct constructor_stack *p = XNEW (struct constructor_stack);
05088 
05089   if (type == 0)
05090     type = TREE_TYPE (constructor_decl);
05091 
05092   if (targetm.vector_opaque_p (type))
05093     error ("opaque vector types cannot be initialized");
05094 
05095   p->type = constructor_type;
05096   p->fields = constructor_fields;
05097   p->index = constructor_index;
05098   p->max_index = constructor_max_index;
05099   p->unfilled_index = constructor_unfilled_index;
05100   p->unfilled_fields = constructor_unfilled_fields;
05101   p->bit_index = constructor_bit_index;
05102   p->elements = constructor_elements;
05103   p->constant = constructor_constant;
05104   p->simple = constructor_simple;
05105   p->erroneous = constructor_erroneous;
05106   p->pending_elts = constructor_pending_elts;
05107   p->depth = constructor_depth;
05108   p->replacement_value.value = 0;
05109   p->replacement_value.original_code = ERROR_MARK;
05110   p->implicit = 0;
05111   p->range_stack = 0;
05112   p->outer = 0;
05113   p->incremental = constructor_incremental;
05114   p->designated = constructor_designated;
05115   p->next = 0;
05116   constructor_stack = p;
05117 
05118   constructor_constant = 1;
05119   constructor_simple = 1;
05120   constructor_depth = SPELLING_DEPTH ();
05121   constructor_elements = 0;
05122   constructor_pending_elts = 0;
05123   constructor_type = type;
05124   constructor_incremental = 1;
05125   constructor_designated = 0;
05126   designator_depth = 0;
05127   designator_erroneous = 0;
05128 
05129   if (TREE_CODE (constructor_type) == RECORD_TYPE
05130       || TREE_CODE (constructor_type) == UNION_TYPE)
05131     {
05132       constructor_fields = TYPE_FIELDS (constructor_type);
05133       /* Skip any nameless bit fields at the beginning.  */
05134       while (constructor_fields != 0 && DECL_C_BIT_FIELD (constructor_fields)
05135        && DECL_NAME (constructor_fields) == 0)
05136   constructor_fields = TREE_CHAIN (constructor_fields);
05137 
05138       constructor_unfilled_fields = constructor_fields;
05139       constructor_bit_index = bitsize_zero_node;
05140     }
05141   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
05142     {
05143       if (TYPE_DOMAIN (constructor_type))
05144   {
05145     constructor_max_index
05146       = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
05147 
05148     /* Detect non-empty initializations of zero-length arrays.  */
05149     if (constructor_max_index == NULL_TREE
05150         && TYPE_SIZE (constructor_type))
05151       constructor_max_index = build_int_cst (NULL_TREE, -1);
05152 
05153     /* constructor_max_index needs to be an INTEGER_CST.  Attempts
05154        to initialize VLAs will cause a proper error; avoid tree
05155        checking errors as well by setting a safe value.  */
05156     if (constructor_max_index
05157         && TREE_CODE (constructor_max_index) != INTEGER_CST)
05158       constructor_max_index = build_int_cst (NULL_TREE, -1);
05159 
05160     constructor_index
05161       = convert (bitsizetype,
05162            TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
05163   }
05164       else
05165   {
05166     constructor_index = bitsize_zero_node;
05167     constructor_max_index = NULL_TREE;
05168   }
05169 
05170       constructor_unfilled_index = constructor_index;
05171     }
05172   else if (TREE_CODE (constructor_type) == VECTOR_TYPE)
05173     {
05174       /* Vectors are like simple fixed-size arrays.  */
05175       constructor_max_index =
05176   build_int_cst (NULL_TREE, TYPE_VECTOR_SUBPARTS (constructor_type) - 1);
05177       constructor_index = bitsize_zero_node;
05178       constructor_unfilled_index = constructor_index;
05179     }
05180   else
05181     {
05182       /* Handle the case of int x = {5}; */
05183       constructor_fields = constructor_type;
05184       constructor_unfilled_fields = constructor_type;
05185     }
05186 }
05187 
05188 /* Push down into a subobject, for initialization.
05189    If this is for an explicit set of braces, IMPLICIT is 0.
05190    If it is because the next element belongs at a lower level,
05191    IMPLICIT is 1 (or 2 if the push is because of designator list).  */
05192 
05193 void
05194 push_init_level (int implicit)
05195 {
05196   struct constructor_stack *p;
05197   tree value = NULL_TREE;
05198 
05199   /* If we've exhausted any levels that didn't have braces,
05200      pop them now.  If implicit == 1, this will have been done in
05201      process_init_element; do not repeat it here because in the case
05202      of excess initializers for an empty aggregate this leads to an
05203      infinite cycle of popping a level and immediately recreating
05204      it.  */
05205   if (implicit != 1)
05206     {
05207       while (constructor_stack->implicit)
05208   {
05209     if ((TREE_CODE (constructor_type) == RECORD_TYPE
05210          || TREE_CODE (constructor_type) == UNION_TYPE)
05211         && constructor_fields == 0)
05212       process_init_element (pop_init_level (1));
05213     else if (TREE_CODE (constructor_type) == ARRAY_TYPE
05214        && constructor_max_index
05215        && tree_int_cst_lt (constructor_max_index,
05216                constructor_index))
05217       process_init_element (pop_init_level (1));
05218     else
05219       break;
05220   }
05221     }
05222 
05223   /* Unless this is an explicit brace, we need to preserve previous
05224      content if any.  */
05225   if (implicit)
05226     {
05227       if ((TREE_CODE (constructor_type) == RECORD_TYPE
05228      || TREE_CODE (constructor_type) == UNION_TYPE)
05229     && constructor_fields)
05230   value = find_init_member (constructor_fields);
05231       else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
05232   value = find_init_member (constructor_index);
05233     }
05234 
05235   p = XNEW (struct constructor_stack);
05236   p->type = constructor_type;
05237   p->fields = constructor_fields;
05238   p->index = constructor_index;
05239   p->max_index = constructor_max_index;
05240   p->unfilled_index = constructor_unfilled_index;
05241   p->unfilled_fields = constructor_unfilled_fields;
05242   p->bit_index = constructor_bit_index;
05243   p->elements = constructor_elements;
05244   p->constant = constructor_constant;
05245   p->simple = constructor_simple;
05246   p->erroneous = constructor_erroneous;
05247   p->pending_elts = constructor_pending_elts;
05248   p->depth = constructor_depth;
05249   p->replacement_value.value = 0;
05250   p->replacement_value.original_code = ERROR_MARK;
05251   p->implicit = implicit;
05252   p->outer = 0;
05253   p->incremental = constructor_incremental;
05254   p->designated = constructor_designated;
05255   p->next = constructor_stack;
05256   p->range_stack = 0;
05257   constructor_stack = p;
05258 
05259   constructor_constant = 1;
05260   constructor_simple = 1;
05261   constructor_depth = SPELLING_DEPTH ();
05262   constructor_elements = 0;
05263   constructor_incremental = 1;
05264   constructor_designated = 0;
05265   constructor_pending_elts = 0;
05266   if (!implicit)
05267     {
05268       p->range_stack = constructor_range_stack;
05269       constructor_range_stack = 0;
05270       designator_depth = 0;
05271       designator_erroneous = 0;
05272     }
05273 
05274   /* Don't die if an entire brace-pair level is superfluous
05275      in the containing level.  */
05276   if (constructor_type == 0)
05277     ;
05278   else if (TREE_CODE (constructor_type) == RECORD_TYPE
05279      || TREE_CODE (constructor_type) == UNION_TYPE)
05280     {
05281       /* Don't die if there are extra init elts at the end.  */
05282       if (constructor_fields == 0)
05283   constructor_type = 0;
05284       else
05285   {
05286     constructor_type = TREE_TYPE (constructor_fields);
05287     push_member_name (constructor_fields);
05288     constructor_depth++;
05289   }
05290     }
05291   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
05292     {
05293       constructor_type = TREE_TYPE (constructor_type);
05294       push_array_bounds (tree_low_cst (constructor_index, 1));
05295       constructor_depth++;
05296     }
05297 
05298   if (constructor_type == 0)
05299     {
05300       error_init ("extra brace group at end of initializer");
05301       constructor_fields = 0;
05302       constructor_unfilled_fields = 0;
05303       return;
05304     }
05305 
05306   if (value && TREE_CODE (value) == CONSTRUCTOR)
05307     {
05308       constructor_constant = TREE_CONSTANT (value);
05309       constructor_simple = TREE_STATIC (value);
05310       constructor_elements = CONSTRUCTOR_ELTS (value);
05311       if (!VEC_empty (constructor_elt, constructor_elements)
05312     && (TREE_CODE (constructor_type) == RECORD_TYPE
05313         || TREE_CODE (constructor_type) == ARRAY_TYPE))
05314   set_nonincremental_init ();
05315     }
05316 
05317   if (implicit == 1 && warn_missing_braces && !missing_braces_mentioned)
05318     {
05319       missing_braces_mentioned = 1;
05320       warning_init ("missing braces around initializer");
05321     }
05322 
05323   if (TREE_CODE (constructor_type) == RECORD_TYPE
05324      || TREE_CODE (constructor_type) == UNION_TYPE)
05325     {
05326       constructor_fields = TYPE_FIELDS (constructor_type);
05327       /* Skip any nameless bit fields at the beginning.  */
05328       while (constructor_fields != 0 && DECL_C_BIT_FIELD (constructor_fields)
05329        && DECL_NAME (constructor_fields) == 0)
05330   constructor_fields = TREE_CHAIN (constructor_fields);
05331 
05332       constructor_unfilled_fields = constructor_fields;
05333       constructor_bit_index = bitsize_zero_node;
05334     }
05335   else if (TREE_CODE (constructor_type) == VECTOR_TYPE)
05336     {
05337       /* Vectors are like simple fixed-size arrays.  */
05338       constructor_max_index =
05339   build_int_cst (NULL_TREE, TYPE_VECTOR_SUBPARTS (constructor_type) - 1);
05340       constructor_index = convert (bitsizetype, integer_zero_node);
05341       constructor_unfilled_index = constructor_index;
05342     }
05343   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
05344     {
05345       if (TYPE_DOMAIN (constructor_type))
05346   {
05347     constructor_max_index
05348       = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
05349 
05350     /* Detect non-empty initializations of zero-length arrays.  */
05351     if (constructor_max_index == NULL_TREE
05352         && TYPE_SIZE (constructor_type))
05353       constructor_max_index = build_int_cst (NULL_TREE, -1);
05354 
05355     /* constructor_max_index needs to be an INTEGER_CST.  Attempts
05356        to initialize VLAs will cause a proper error; avoid tree
05357        checking errors as well by setting a safe value.  */
05358     if (constructor_max_index
05359         && TREE_CODE (constructor_max_index) != INTEGER_CST)
05360       constructor_max_index = build_int_cst (NULL_TREE, -1);
05361 
05362     constructor_index
05363       = convert (bitsizetype,
05364            TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
05365   }
05366       else
05367   constructor_index = bitsize_zero_node;
05368 
05369       constructor_unfilled_index = constructor_index;
05370       if (value && TREE_CODE (value) == STRING_CST)
05371   {
05372     /* We need to split the char/wchar array into individual
05373        characters, so that we don't have to special case it
05374        everywhere.  */
05375     set_nonincremental_init_from_string (value);
05376   }
05377     }
05378   else
05379     {
05380       if (constructor_type != error_mark_node)
05381   warning_init ("braces around scalar initializer");
05382       constructor_fields = constructor_type;
05383       constructor_unfilled_fields = constructor_type;
05384     }
05385 }
05386 
05387 /* At the end of an implicit or explicit brace level,
05388    finish up that level of constructor.  If a single expression
05389    with redundant braces initialized that level, return the
05390    c_expr structure for that expression.  Otherwise, the original_code
05391    element is set to ERROR_MARK.
05392    If we were outputting the elements as they are read, return 0 as the value
05393    from inner levels (process_init_element ignores that),
05394    but return error_mark_node as the value from the outermost level
05395    (that's what we want to put in DECL_INITIAL).
05396    Otherwise, return a CONSTRUCTOR expression as the value.  */
05397 
05398 struct c_expr
05399 pop_init_level (int implicit)
05400 {
05401   struct constructor_stack *p;
05402   struct c_expr ret;
05403   ret.value = 0;
05404   ret.original_code = ERROR_MARK;
05405 
05406   if (implicit == 0)
05407     {
05408       /* When we come to an explicit close brace,
05409    pop any inner levels that didn't have explicit braces.  */
05410       while (constructor_stack->implicit)
05411   process_init_element (pop_init_level (1));
05412 
05413       gcc_assert (!constructor_range_stack);
05414     }
05415 
05416   /* Now output all pending elements.  */
05417   constructor_incremental = 1;
05418   output_pending_init_elements (1);
05419 
05420   p = constructor_stack;
05421 
05422   /* Error for initializing a flexible array member, or a zero-length
05423      array member in an inappropriate context.  */
05424   if (constructor_type && constructor_fields
05425       && TREE_CODE (constructor_type) == ARRAY_TYPE
05426       && TYPE_DOMAIN (constructor_type)
05427       && !TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type)))
05428     {
05429       /* Silently discard empty initializations.  The parser will
05430    already have pedwarned for empty brackets.  */
05431       if (integer_zerop (constructor_unfilled_index))
05432   constructor_type = NULL_TREE;
05433       else
05434   {
05435     gcc_assert (!TYPE_SIZE (constructor_type));
05436 
05437     if (constructor_depth > 2)
05438       error_init ("initialization of flexible array member in a nested context");
05439     else if (pedantic)
05440       pedwarn_init ("initialization of a flexible array member");
05441 
05442     /* We have already issued an error message for the existence
05443        of a flexible array member not at the end of the structure.
05444        Discard the initializer so that we do not die later.  */
05445     if (TREE_CHAIN (constructor_fields) != NULL_TREE)
05446       constructor_type = NULL_TREE;
05447   }
05448     }
05449 
05450   /* Warn when some struct elements are implicitly initialized to zero.  */
05451   if (warn_missing_field_initializers
05452       && constructor_type
05453       && TREE_CODE (constructor_type) == RECORD_TYPE
05454       && constructor_unfilled_fields)
05455     {
05456   /* Do not warn for flexible array members or zero-length arrays.  */
05457   while (constructor_unfilled_fields
05458          && (!DECL_SIZE (constructor_unfilled_fields)
05459        || integer_zerop (DECL_SIZE (constructor_unfilled_fields))))
05460     constructor_unfilled_fields = TREE_CHAIN (constructor_unfilled_fields);
05461 
05462   /* Do not warn if this level of the initializer uses member
05463      designators; it is likely to be deliberate.  */
05464   if (constructor_unfilled_fields && !constructor_designated)
05465     {
05466       push_member_name (constructor_unfilled_fields);
05467       warning_init ("missing initializer");
05468       RESTORE_SPELLING_DEPTH (constructor_depth);
05469     }
05470     }
05471 
05472   /* Pad out the end of the structure.  */
05473   if (p->replacement_value.value)
05474     /* If this closes a superfluous brace pair,
05475        just pass out the element between them.  */
05476     ret = p->replacement_value;
05477   else if (constructor_type == 0)
05478     ;
05479   else if (TREE_CODE (constructor_type) != RECORD_TYPE
05480      && TREE_CODE (constructor_type) != UNION_TYPE
05481      && TREE_CODE (constructor_type) != ARRAY_TYPE
05482      && TREE_CODE (constructor_type) != VECTOR_TYPE)
05483     {
05484       /* A nonincremental scalar initializer--just return
05485    the element, after verifying there is just one.  */
05486       if (VEC_empty (constructor_elt,constructor_elements))
05487   {
05488     if (!constructor_erroneous)
05489       error_init ("empty scalar initializer");
05490     ret.value = error_mark_node;
05491   }
05492       else if (VEC_length (constructor_elt,constructor_elements) != 1)
05493   {
05494     error_init ("extra elements in scalar initializer");
05495     ret.value = VEC_index (constructor_elt,constructor_elements,0)->value;
05496   }
05497       else
05498   ret.value = VEC_index (constructor_elt,constructor_elements,0)->value;
05499     }
05500   else
05501     {
05502       if (constructor_erroneous)
05503   ret.value = error_mark_node;
05504       else
05505   {
05506     ret.value = build_constructor (constructor_type,
05507            constructor_elements);
05508     if (constructor_constant)
05509       TREE_CONSTANT (ret.value) = TREE_INVARIANT (ret.value) = 1;
05510     if (constructor_constant && constructor_simple)
05511       TREE_STATIC (ret.value) = 1;
05512   }
05513     }
05514 
05515   constructor_type = p->type;
05516   constructor_fields = p->fields;
05517   constructor_index = p->index;
05518   constructor_max_index = p->max_index;
05519   constructor_unfilled_index = p->unfilled_index;
05520   constructor_unfilled_fields = p->unfilled_fields;
05521   constructor_bit_index = p->bit_index;
05522   constructor_elements = p->elements;
05523   constructor_constant = p->constant;
05524   constructor_simple = p->simple;
05525   constructor_erroneous = p->erroneous;
05526   constructor_incremental = p->incremental;
05527   constructor_designated = p->designated;
05528   constructor_pending_elts = p->pending_elts;
05529   constructor_depth = p->depth;
05530   if (!p->implicit)
05531     constructor_range_stack = p->range_stack;
05532   RESTORE_SPELLING_DEPTH (constructor_depth);
05533 
05534   constructor_stack = p->next;
05535   free (p);
05536 
05537   if (ret.value == 0 && constructor_stack == 0)
05538     ret.value = error_mark_node;
05539   return ret;
05540 }
05541 
05542 /* Common handling for both array range and field name designators.
05543    ARRAY argument is nonzero for array ranges.  Returns zero for success.  */
05544 
05545 static int
05546 set_designator (int array)
05547 {
05548   tree subtype;
05549   enum tree_code subcode;
05550 
05551   /* Don't die if an entire brace-pair level is superfluous
05552      in the containing level.  */
05553   if (constructor_type == 0)
05554     return 1;
05555 
05556   /* If there were errors in this designator list already, bail out
05557      silently.  */
05558   if (designator_erroneous)
05559     return 1;
05560 
05561   if (!designator_depth)
05562     {
05563       gcc_assert (!constructor_range_stack);
05564 
05565       /* Designator list starts at the level of closest explicit
05566    braces.  */
05567       while (constructor_stack->implicit)
05568   process_init_element (pop_init_level (1));
05569       constructor_designated = 1;
05570       return 0;
05571     }
05572 
05573   switch (TREE_CODE (constructor_type))
05574     {
05575     case  RECORD_TYPE:
05576     case  UNION_TYPE:
05577       subtype = TREE_TYPE (constructor_fields);
05578       if (subtype != error_mark_node)
05579   subtype = TYPE_MAIN_VARIANT (subtype);
05580       break;
05581     case ARRAY_TYPE:
05582       subtype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
05583       break;
05584     default:
05585       gcc_unreachable ();
05586     }
05587 
05588   subcode = TREE_CODE (subtype);
05589   if (array && subcode != ARRAY_TYPE)
05590     {
05591       error_init ("array index in non-array initializer");
05592       return 1;
05593     }
05594   else if (!array && subcode != RECORD_TYPE && subcode != UNION_TYPE)
05595     {
05596       error_init ("field name not in record or union initializer");
05597       return 1;
05598     }
05599 
05600   constructor_designated = 1;
05601   push_init_level (2);
05602   return 0;
05603 }
05604 
05605 /* If there are range designators in designator list, push a new designator
05606    to constructor_range_stack.  RANGE_END is end of such stack range or
05607    NULL_TREE if there is no range designator at this level.  */
05608 
05609 static void
05610 push_range_stack (tree range_end)
05611 {
05612   struct constructor_range_stack *p;
05613 
05614   p = GGC_NEW (struct constructor_range_stack);
05615   p->prev = constructor_range_stack;
05616   p->next = 0;
05617   p->fields = constructor_fields;
05618   p->range_start = constructor_index;
05619   p->index = constructor_index;
05620   p->stack = constructor_stack;
05621   p->range_end = range_end;
05622   if (constructor_range_stack)
05623     constructor_range_stack->next = p;
05624   constructor_range_stack = p;
05625 }
05626 
05627 /* Within an array initializer, specify the next index to be initialized.
05628    FIRST is that index.  If LAST is nonzero, then initialize a range
05629    of indices, running from FIRST through LAST.  */
05630 
05631 void
05632 set_init_index (tree first, tree last)
05633 {
05634   if (set_designator (1))
05635     return;
05636 
05637   designator_erroneous = 1;
05638 
05639   if (!INTEGRAL_TYPE_P (TREE_TYPE (first))
05640       || (last && !INTEGRAL_TYPE_P (TREE_TYPE (last))))
05641     {
05642       error_init ("array index in initializer not of integer type");
05643       return;
05644     }
05645 
05646   if (TREE_CODE (first) != INTEGER_CST)
05647     error_init ("nonconstant array index in initializer");
05648   else if (last != 0 && TREE_CODE (last) != INTEGER_CST)
05649     error_init ("nonconstant array index in initializer");
05650   else if (TREE_CODE (constructor_type) != ARRAY_TYPE)
05651     error_init ("array index in non-array initializer");
05652   else if (tree_int_cst_sgn (first) == -1)
05653     error_init ("array index in initializer exceeds array bounds");
05654   else if (constructor_max_index
05655      && tree_int_cst_lt (constructor_max_index, first))
05656     error_init ("array index in initializer exceeds array bounds");
05657   else
05658     {
05659       constructor_index = convert (bitsizetype, first);
05660 
05661       if (last)
05662   {
05663     if (tree_int_cst_equal (first, last))
05664       last = 0;
05665     else if (tree_int_cst_lt (last, first))
05666       {
05667         error_init ("empty index range in initializer");
05668         last = 0;
05669       }
05670     else
05671       {
05672         last = convert (bitsizetype, last);
05673         if (constructor_max_index != 0
05674       && tree_int_cst_lt (constructor_max_index, last))
05675     {
05676       error_init ("array index range in initializer exceeds array bounds");
05677       last = 0;
05678     }
05679       }
05680   }
05681 
05682       designator_depth++;
05683       designator_erroneous = 0;
05684       if (constructor_range_stack || last)
05685   push_range_stack (last);
05686     }
05687 }
05688 
05689 /* Within a struct initializer, specify the next field to be initialized.  */
05690 
05691 void
05692 set_init_label (tree fieldname)
05693 {
05694   tree tail;
05695 
05696   if (set_designator (0))
05697     return;
05698 
05699   designator_erroneous = 1;
05700 
05701   if (TREE_CODE (constructor_type) != RECORD_TYPE
05702       && TREE_CODE (constructor_type) != UNION_TYPE)
05703     {
05704       error_init ("field name not in record or union initializer");
05705       return;
05706     }
05707 
05708   for (tail = TYPE_FIELDS (constructor_type); tail;
05709        tail = TREE_CHAIN (tail))
05710     {
05711       if (DECL_NAME (tail) == fieldname)
05712   break;
05713     }
05714 
05715   if (tail == 0)
05716     error ("unknown field %qE specified in initializer", fieldname);
05717   else
05718     {
05719       constructor_fields = tail;
05720       designator_depth++;
05721       designator_erroneous = 0;
05722       if (constructor_range_stack)
05723   push_range_stack (NULL_TREE);
05724     }
05725 }
05726 
05727 /* Add a new initializer to the tree of pending initializers.  PURPOSE
05728    identifies the initializer, either array index or field in a structure.
05729    VALUE is the value of that index or field.  */
05730 
05731 static void
05732 add_pending_init (tree purpose, tree value)
05733 {
05734   struct init_node *p, **q, *r;
05735 
05736   q = &constructor_pending_elts;
05737   p = 0;
05738 
05739   if (TREE_CODE (constructor_type) == ARRAY_TYPE)
05740     {
05741       while (*q != 0)
05742   {
05743     p = *q;
05744     if (tree_int_cst_lt (purpose, p->purpose))
05745       q = &p->left;
05746     else if (tree_int_cst_lt (p->purpose, purpose))
05747       q = &p->right;
05748     else
05749       {
05750         if (TREE_SIDE_EFFECTS (p->value))
05751     warning_init ("initialized field with side-effects overwritten");
05752         else if (warn_override_init)
05753     warning_init ("initialized field overwritten");
05754         p->value = value;
05755         return;
05756       }
05757   }
05758     }
05759   else
05760     {
05761       tree bitpos;
05762 
05763       bitpos = bit_position (purpose);
05764       while (*q != NULL)
05765   {
05766     p = *q;
05767     if (tree_int_cst_lt (bitpos, bit_position (p->purpose)))
05768       q = &p->left;
05769     else if (p->purpose != purpose)
05770       q = &p->right;
05771     else
05772       {
05773         if (TREE_SIDE_EFFECTS (p->value))
05774     warning_init ("initialized field with side-effects overwritten");
05775         else if (warn_override_init)
05776     warning_init ("initialized field overwritten");
05777         p->value = value;
05778         return;
05779       }
05780   }
05781     }
05782 
05783   r = GGC_NEW (struct init_node);
05784   r->purpose = purpose;
05785   r->value = value;
05786 
05787   *q = r;
05788   r->parent = p;
05789   r->left = 0;
05790   r->right = 0;
05791   r->balance = 0;
05792 
05793   while (p)
05794     {
05795       struct init_node *s;
05796 
05797       if (r == p->left)
05798   {
05799     if (p->balance == 0)
05800       p->balance = -1;
05801     else if (p->balance < 0)
05802       {
05803         if (r->balance < 0)
05804     {
05805       /* L rotation.  */
05806       p->left = r->right;
05807       if (p->left)
05808         p->left->parent = p;
05809       r->right = p;
05810 
05811       p->balance = 0;
05812       r->balance = 0;
05813 
05814       s = p->parent;
05815       p->parent = r;
05816       r->parent = s;
05817       if (s)
05818         {
05819           if (s->left == p)
05820       s->left = r;
05821           else
05822       s->right = r;
05823         }
05824       else
05825         constructor_pending_elts = r;
05826     }
05827         else
05828     {
05829       /* LR rotation.  */
05830       struct init_node *t = r->right;
05831 
05832       r->right = t->left;
05833       if (r->right)
05834         r->right->parent = r;
05835       t->left = r;
05836 
05837       p->left = t->right;
05838       if (p->left)
05839         p->left->parent = p;
05840       t->right = p;
05841 
05842       p->balance = t->balance < 0;
05843       r->balance = -(t->balance > 0);
05844       t->balance = 0;
05845 
05846       s = p->parent;
05847       p->parent = t;
05848       r->parent = t;
05849       t->parent = s;
05850       if (s)
05851         {
05852           if (s->left == p)
05853       s->left = t;
05854           else
05855       s->right = t;
05856         }
05857       else
05858         constructor_pending_elts = t;
05859     }
05860         break;
05861       }
05862     else
05863       {
05864         /* p->balance == +1; growth of left side balances the node.  */
05865         p->balance = 0;
05866         break;
05867       }
05868   }
05869       else /* r == p->right */
05870   {
05871     if (p->balance == 0)
05872       /* Growth propagation from right side.  */
05873       p->balance++;
05874     else if (p->balance > 0)
05875       {
05876         if (r->balance > 0)
05877     {
05878       /* R rotation.  */
05879       p->right = r->left;
05880       if (p->right)
05881         p->right->parent = p;
05882       r->left = p;
05883 
05884       p->balance = 0;
05885       r->balance = 0;
05886 
05887       s = p->parent;
05888       p->parent = r;
05889       r->parent = s;
05890       if (s)
05891         {
05892           if (s->left == p)
05893       s->left = r;
05894           else
05895       s->right = r;
05896         }
05897       else
05898         constructor_pending_elts = r;
05899     }
05900         else /* r->balance == -1 */
05901     {
05902       /* RL rotation */
05903       struct init_node *t = r->left;
05904 
05905       r->left = t->right;
05906       if (r->left)
05907         r->left->parent = r;
05908       t->right = r;
05909 
05910       p->right = t->left;
05911       if (p->right)
05912         p->right->parent = p;
05913       t->left = p;
05914 
05915       r->balance = (t->balance < 0);
05916       p->balance = -(t->balance > 0);
05917       t->balance = 0;
05918 
05919       s = p->parent;
05920       p->parent = t;
05921       r->parent = t;
05922       t->parent = s;
05923       if (s)
05924         {
05925           if (s->left == p)
05926       s->left = t;
05927           else
05928       s->right = t;
05929         }
05930       else
05931         constructor_pending_elts = t;
05932     }
05933         break;
05934       }
05935     else
05936       {
05937         /* p->balance == -1; growth of right side balances the node.  */
05938         p->balance = 0;
05939         break;
05940       }
05941   }
05942 
05943       r = p;
05944       p = p->parent;
05945     }
05946 }
05947 
05948 /* Build AVL tree from a sorted chain.  */
05949 
05950 static void
05951 set_nonincremental_init (void)
05952 {
05953   unsigned HOST_WIDE_INT ix;
05954   tree index, value;
05955 
05956   if (TREE_CODE (constructor_type) != RECORD_TYPE
05957       && TREE_CODE (constructor_type) != ARRAY_TYPE)
05958     return;
05959 
05960   FOR_EACH_CONSTRUCTOR_ELT (constructor_elements, ix, index, value)
05961     add_pending_init (index, value);
05962   constructor_elements = 0;
05963   if (TREE_CODE (constructor_type) == RECORD_TYPE)
05964     {
05965       constructor_unfilled_fields = TYPE_FIELDS (constructor_type);
05966       /* Skip any nameless bit fields at the beginning.  */
05967       while (constructor_unfilled_fields != 0
05968        && DECL_C_BIT_FIELD (constructor_unfilled_fields)
05969        && DECL_NAME (constructor_unfilled_fields) == 0)
05970   constructor_unfilled_fields = TREE_CHAIN (constructor_unfilled_fields);
05971 
05972     }
05973   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
05974     {
05975       if (TYPE_DOMAIN (constructor_type))
05976   constructor_unfilled_index
05977       = convert (bitsizetype,
05978            TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
05979       else
05980   constructor_unfilled_index = bitsize_zero_node;
05981     }
05982   constructor_incremental = 0;
05983 }
05984 
05985 /* Build AVL tree from a string constant.  */
05986 
05987 static void
05988 set_nonincremental_init_from_string (tree str)
05989 {
05990   tree value, purpose, type;
05991   HOST_WIDE_INT val[2];
05992   const char *p, *end;
05993   int byte, wchar_bytes, charwidth, bitpos;
05994 
05995   gcc_assert (TREE_CODE (constructor_type) == ARRAY_TYPE);
05996 
05997   if (TYPE_PRECISION (TREE_TYPE (TREE_TYPE (str)))
05998       == TYPE_PRECISION (char_type_node))
05999     wchar_bytes = 1;
06000   else
06001     {
06002       gcc_assert (TYPE_PRECISION (TREE_TYPE (TREE_TYPE (str)))
06003       == TYPE_PRECISION (wchar_type_node));
06004       wchar_bytes = TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT;
06005     }
06006   charwidth = TYPE_PRECISION (char_type_node);
06007   type = TREE_TYPE (constructor_type);
06008   p = TREE_STRING_POINTER (str);
06009   end = p + TREE_STRING_LENGTH (str);
06010 
06011   for (purpose = bitsize_zero_node;
06012        p < end && !tree_int_cst_lt (constructor_max_index, purpose);
06013        purpose = size_binop (PLUS_EXPR, purpose, bitsize_one_node))
06014     {
06015       if (wchar_bytes == 1)
06016   {
06017     val[1] = (unsigned char) *p++;
06018     val[0] = 0;
06019   }
06020       else
06021   {
06022     val[0] = 0;
06023     val[1] = 0;
06024     for (byte = 0; byte < wchar_bytes; byte++)
06025       {
06026         if (BYTES_BIG_ENDIAN)
06027     bitpos = (wchar_bytes - byte - 1) * charwidth;
06028         else
06029     bitpos = byte * charwidth;
06030         val[bitpos < HOST_BITS_PER_WIDE_INT]
06031     |= ((unsigned HOST_WIDE_INT) ((unsigned char) *p++))
06032        << (bitpos % HOST_BITS_PER_WIDE_INT);
06033       }
06034   }
06035 
06036       if (!TYPE_UNSIGNED (type))
06037   {
06038     bitpos = ((wchar_bytes - 1) * charwidth) + HOST_BITS_PER_CHAR;
06039     if (bitpos < HOST_BITS_PER_WIDE_INT)
06040       {
06041         if (val[1] & (((HOST_WIDE_INT) 1) << (bitpos - 1)))
06042     {
06043       val[1] |= ((HOST_WIDE_INT) -1) << bitpos;
06044       val[0] = -1;
06045     }
06046       }
06047     else if (bitpos == HOST_BITS_PER_WIDE_INT)
06048       {
06049         if (val[1] < 0)
06050     val[0] = -1;
06051       }
06052     else if (val[0] & (((HOST_WIDE_INT) 1)
06053            << (bitpos - 1 - HOST_BITS_PER_WIDE_INT)))
06054       val[0] |= ((HOST_WIDE_INT) -1)
06055           << (bitpos - HOST_BITS_PER_WIDE_INT);
06056   }
06057 
06058       value = build_int_cst_wide (type, val[1], val[0]);
06059       add_pending_init (purpose, value);
06060     }
06061 
06062   constructor_incremental = 0;
06063 }
06064 
06065 /* Return value of FIELD in pending initializer or zero if the field was
06066    not initialized yet.  */
06067 
06068 static tree
06069 find_init_member (tree field)
06070 {
06071   struct init_node *p;
06072 
06073   if (TREE_CODE (constructor_type) == ARRAY_TYPE)
06074     {
06075       if (constructor_incremental
06076     && tree_int_cst_lt (field, constructor_unfilled_index))
06077   set_nonincremental_init ();
06078 
06079       p = constructor_pending_elts;
06080       while (p)
06081   {
06082     if (tree_int_cst_lt (field, p->purpose))
06083       p = p->left;
06084     else if (tree_int_cst_lt (p->purpose, field))
06085       p = p->right;
06086     else
06087       return p->value;
06088   }
06089     }
06090   else if (TREE_CODE (constructor_type) == RECORD_TYPE)
06091     {
06092       tree bitpos = bit_position (field);
06093 
06094       if (constructor_incremental
06095     && (!constructor_unfilled_fields
06096         || tree_int_cst_lt (bitpos,
06097           bit_position (constructor_unfilled_fields))))
06098   set_nonincremental_init ();
06099 
06100       p = constructor_pending_elts;
06101       while (p)
06102   {
06103     if (field == p->purpose)
06104       return p->value;
06105     else if (tree_int_cst_lt (bitpos, bit_position (p->purpose)))
06106       p = p->left;
06107     else
06108       p = p->right;
06109   }
06110     }
06111   else if (TREE_CODE (constructor_type) == UNION_TYPE)
06112     {
06113       if (!VEC_empty (constructor_elt, constructor_elements)
06114     && (VEC_last (constructor_elt, constructor_elements)->index
06115         == field))
06116   return VEC_last (constructor_elt, constructor_elements)->value;
06117     }
06118   return 0;
06119 }
06120 
06121 /* "Output" the next constructor element.
06122    At top level, really output it to assembler code now.
06123    Otherwise, collect it in a list from which we will make a CONSTRUCTOR.
06124    TYPE is the data type that the containing data type wants here.
06125    FIELD is the field (a FIELD_DECL) or the index that this element fills.
06126    If VALUE is a string constant, STRICT_STRING is true if it is
06127    unparenthesized or we should not warn here for it being parenthesized.
06128    For other types of VALUE, STRICT_STRING is not used.
06129 
06130    PENDING if non-nil means output pending elements that belong
06131    right after this element.  (PENDING is normally 1;
06132    it is 0 while outputting pending elements, to avoid recursion.)  */
06133 
06134 static void
06135 output_init_element (tree value, bool strict_string, tree type, tree field,
06136          int pending)
06137 {
06138   constructor_elt *celt;
06139 
06140   if (type == error_mark_node || value == error_mark_node)
06141     {
06142       constructor_erroneous = 1;
06143       return;
06144     }
06145   if (TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
06146       && (TREE_CODE (value) == STRING_CST
06147     || TREE_CODE (value) == COMPOUND_LITERAL_EXPR)
06148       && !(TREE_CODE (value) == STRING_CST
06149      && TREE_CODE (type) == ARRAY_TYPE
06150      && INTEGRAL_TYPE_P (TREE_TYPE (type)))
06151       && !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (value)),
06152          TYPE_MAIN_VARIANT (type)))
06153     value = array_to_pointer_conversion (value);
06154 
06155   if (TREE_CODE (value) == COMPOUND_LITERAL_EXPR
06156       && require_constant_value && !flag_isoc99 && pending)
06157     {
06158       /* As an extension, allow initializing objects with static storage
06159    duration with compound literals (which are then treated just as
06160    the brace enclosed list they contain).  */
06161       tree decl = COMPOUND_LITERAL_EXPR_DECL (value);
06162       value = DECL_INITIAL (decl);
06163     }
06164 
06165   if (value == error_mark_node)
06166     constructor_erroneous = 1;
06167   else if (!TREE_CONSTANT (value))
06168     constructor_constant = 0;
06169   else if (!initializer_constant_valid_p (value, TREE_TYPE (value))
06170      || ((TREE_CODE (constructor_type) == RECORD_TYPE
06171     || TREE_CODE (constructor_type) == UNION_TYPE)
06172          && DECL_C_BIT_FIELD (field)
06173          && TREE_CODE (value) != INTEGER_CST))
06174     constructor_simple = 0;
06175 
06176   if (!initializer_constant_valid_p (value, TREE_TYPE (value)))
06177     {
06178       if (require_constant_value)
06179   {
06180     error_init ("initializer element is not constant");
06181     value = error_mark_node;
06182   }
06183       else if (require_constant_elements)
06184   pedwarn ("initializer element is not computable at load time");
06185     }
06186 
06187   /* If this field is empty (and not at the end of structure),
06188      don't do anything other than checking the initializer.  */
06189   if (field
06190       && (TREE_TYPE (field) == error_mark_node
06191     || (COMPLETE_TYPE_P (TREE_TYPE (field))
06192         && integer_zerop (TYPE_SIZE (TREE_TYPE (field)))
06193         && (TREE_CODE (constructor_type) == ARRAY_TYPE
06194       || TREE_CHAIN (field)))))
06195     return;
06196 
06197   value = digest_init (type, value, strict_string, require_constant_value);
06198   if (value == error_mark_node)
06199     {
06200       constructor_erroneous = 1;
06201       return;
06202     }
06203 
06204   /* If this element doesn't come next in sequence,
06205      put it on constructor_pending_elts.  */
06206   if (TREE_CODE (constructor_type) == ARRAY_TYPE
06207       && (!constructor_incremental
06208     || !tree_int_cst_equal (field, constructor_unfilled_index)))
06209     {
06210       if (constructor_incremental
06211     && tree_int_cst_lt (field, constructor_unfilled_index))
06212   set_nonincremental_init ();
06213 
06214       add_pending_init (field, value);
06215       return;
06216     }
06217   else if (TREE_CODE (constructor_type) == RECORD_TYPE
06218      && (!constructor_incremental
06219          || field != constructor_unfilled_fields))
06220     {
06221       /* We do this for records but not for unions.  In a union,
06222    no matter which field is specified, it can be initialized
06223    right away since it starts at the beginning of the union.  */
06224       if (constructor_incremental)
06225   {
06226     if (!constructor_unfilled_fields)
06227       set_nonincremental_init ();
06228     else
06229       {
06230         tree bitpos, unfillpos;
06231 
06232         bitpos = bit_position (field);
06233         unfillpos = bit_position (constructor_unfilled_fields);
06234 
06235         if (tree_int_cst_lt (bitpos, unfillpos))
06236     set_nonincremental_init ();
06237       }
06238   }
06239 
06240       add_pending_init (field, value);
06241       return;
06242     }
06243   else if (TREE_CODE (constructor_type) == UNION_TYPE
06244      && !VEC_empty (constructor_elt, constructor_elements))
06245     {
06246       if (TREE_SIDE_EFFECTS (VEC_last (constructor_elt,
06247                constructor_elements)->value))
06248   warning_init ("initialized field with side-effects overwritten");
06249       else if (warn_override_init)
06250   warning_init ("initialized field overwritten");
06251 
06252       /* We can have just one union field set.  */
06253       constructor_elements = 0;
06254     }
06255 
06256   /* Otherwise, output this element either to
06257      constructor_elements or to the assembler file.  */
06258 
06259   celt = VEC_safe_push (constructor_elt, gc, constructor_elements, NULL);
06260   celt->index = field;
06261   celt->value = value;
06262 
06263   /* Advance the variable that indicates sequential elements output.  */
06264   if (TREE_CODE (constructor_type) == ARRAY_TYPE)
06265     constructor_unfilled_index
06266       = size_binop (PLUS_EXPR, constructor_unfilled_index,
06267         bitsize_one_node);
06268   else if (TREE_CODE (constructor_type) == RECORD_TYPE)
06269     {
06270       constructor_unfilled_fields
06271   = TREE_CHAIN (constructor_unfilled_fields);
06272 
06273       /* Skip any nameless bit fields.  */
06274       while (constructor_unfilled_fields != 0
06275        && DECL_C_BIT_FIELD (constructor_unfilled_fields)
06276        && DECL_NAME (constructor_unfilled_fields) == 0)
06277   constructor_unfilled_fields =
06278     TREE_CHAIN (constructor_unfilled_fields);
06279     }
06280   else if (TREE_CODE (constructor_type) == UNION_TYPE)
06281     constructor_unfilled_fields = 0;
06282 
06283   /* Now output any pending elements which have become next.  */
06284   if (pending)
06285     output_pending_init_elements (0);
06286 }
06287 
06288 /* Output any pending elements which have become next.
06289    As we output elements, constructor_unfilled_{fields,index}
06290    advances, which may cause other elements to become next;
06291    if so, they too are output.
06292 
06293    If ALL is 0, we return when there are
06294    no more pending elements to output now.
06295 
06296    If ALL is 1, we output space as necessary so that
06297    we can output all the pending elements.  */
06298 
06299 static void
06300 output_pending_init_elements (int all)
06301 {
06302   struct init_node *elt = constructor_pending_elts;
06303   tree next;
06304 
06305  retry:
06306 
06307   /* Look through the whole pending tree.
06308      If we find an element that should be output now,
06309      output it.  Otherwise, set NEXT to the element
06310      that comes first among those still pending.  */
06311 
06312   next = 0;
06313   while (elt)
06314     {
06315       if (TREE_CODE (constructor_type) == ARRAY_TYPE)
06316   {
06317     if (tree_int_cst_equal (elt->purpose,
06318           constructor_unfilled_index))
06319       output_init_element (elt->value, true,
06320          TREE_TYPE (constructor_type),
06321          constructor_unfilled_index, 0);
06322     else if (tree_int_cst_lt (constructor_unfilled_index,
06323             elt->purpose))
06324       {
06325         /* Advance to the next smaller node.  */
06326         if (elt->left)
06327     elt = elt->left;
06328         else
06329     {
06330       /* We have reached the smallest node bigger than the
06331          current unfilled index.  Fill the space first.  */
06332       next = elt->purpose;
06333       break;
06334     }
06335       }
06336     else
06337       {
06338         /* Advance to the next bigger node.  */
06339         if (elt->right)
06340     elt = elt->right;
06341         else
06342     {
06343       /* We have reached the biggest node in a subtree.  Find
06344          the parent of it, which is the next bigger node.  */
06345       while (elt->parent && elt->parent->right == elt)
06346         elt = elt->parent;
06347       elt = elt->parent;
06348       if (elt && tree_int_cst_lt (constructor_unfilled_index,
06349                 elt->purpose))
06350         {
06351           next = elt->purpose;
06352           break;
06353         }
06354     }
06355       }
06356   }
06357       else if (TREE_CODE (constructor_type) == RECORD_TYPE
06358          || TREE_CODE (constructor_type) == UNION_TYPE)
06359   {
06360     tree ctor_unfilled_bitpos, elt_bitpos;
06361 
06362     /* If the current record is complete we are done.  */
06363     if (constructor_unfilled_fields == 0)
06364       break;
06365 
06366     ctor_unfilled_bitpos = bit_position (constructor_unfilled_fields);
06367     elt_bitpos = bit_position (elt->purpose);
06368     /* We can't compare fields here because there might be empty
06369        fields in between.  */
06370     if (tree_int_cst_equal (elt_bitpos, ctor_unfilled_bitpos))
06371       {
06372         constructor_unfilled_fields = elt->purpose;
06373         output_init_element (elt->value, true, TREE_TYPE (elt->purpose),
06374            elt->purpose, 0);
06375       }
06376     else if (tree_int_cst_lt (ctor_unfilled_bitpos, elt_bitpos))
06377       {
06378         /* Advance to the next smaller node.  */
06379         if (elt->left)
06380     elt = elt->left;
06381         else
06382     {
06383       /* We have reached the smallest node bigger than the
06384          current unfilled field.  Fill the space first.  */
06385       next = elt->purpose;
06386       break;
06387     }
06388       }
06389     else
06390       {
06391         /* Advance to the next bigger node.  */
06392         if (elt->right)
06393     elt = elt->right;
06394         else
06395     {
06396       /* We have reached the biggest node in a subtree.  Find
06397          the parent of it, which is the next bigger node.  */
06398       while (elt->parent && elt->parent->right == elt)
06399         elt = elt->parent;
06400       elt = elt->parent;
06401       if (elt
06402           && (tree_int_cst_lt (ctor_unfilled_bitpos,
06403              bit_position (elt->purpose))))
06404         {
06405           next = elt->purpose;
06406           break;
06407         }
06408     }
06409       }
06410   }
06411     }
06412 
06413   /* Ordinarily return, but not if we want to output all
06414      and there are elements left.  */
06415   if (!(all && next != 0))
06416     return;
06417 
06418   /* If it's not incremental, just skip over the gap, so that after
06419      jumping to retry we will output the next successive element.  */
06420   if (TREE_CODE (constructor_type) == RECORD_TYPE
06421       || TREE_CODE (constructor_type) == UNION_TYPE)
06422     constructor_unfilled_fields = next;
06423   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
06424     constructor_unfilled_index = next;
06425 
06426   /* ELT now points to the node in the pending tree with the next
06427      initializer to output.  */
06428   goto retry;
06429 }
06430 
06431 /* Add one non-braced element to the current constructor level.
06432    This adjusts the current position within the constructor's type.
06433    This may also start or terminate implicit levels
06434    to handle a partly-braced initializer.
06435 
06436    Once this has found the correct level for the new element,
06437    it calls output_init_element.  */
06438 
06439 void
06440 process_init_element (struct c_expr value)
06441 {
06442   tree orig_value = value.value;
06443   int string_flag = orig_value != 0 && TREE_CODE (orig_value) == STRING_CST;
06444   bool strict_string = value.original_code == STRING_CST;
06445 
06446   designator_depth = 0;
06447   designator_erroneous = 0;
06448 
06449   /* Handle superfluous braces around string cst as in
06450      char x[] = {"foo"}; */
06451   if (string_flag
06452       && constructor_type
06453       && TREE_CODE (constructor_type) == ARRAY_TYPE
06454       && INTEGRAL_TYPE_P (TREE_TYPE (constructor_type))
06455       && integer_zerop (constructor_unfilled_index))
06456     {
06457       if (constructor_stack->replacement_value.value)
06458   error_init ("excess elements in char array initializer");
06459       constructor_stack->replacement_value = value;
06460       return;
06461     }
06462 
06463   if (constructor_stack->replacement_value.value != 0)
06464     {
06465       error_init ("excess elements in struct initializer");
06466       return;
06467     }
06468 
06469   /* Ignore elements of a brace group if it is entirely superfluous
06470      and has already been diagnosed.  */
06471   if (constructor_type == 0)
06472     return;
06473 
06474   /* If we've exhausted any levels that didn't have braces,
06475      pop them now.  */
06476   while (constructor_stack->implicit)
06477     {
06478       if ((TREE_CODE (constructor_type) == RECORD_TYPE
06479      || TREE_CODE (constructor_type) == UNION_TYPE)
06480     && constructor_fields == 0)
06481   process_init_element (pop_init_level (1));
06482       else if (TREE_CODE (constructor_type) == ARRAY_TYPE
06483          && (constructor_max_index == 0
06484        || tree_int_cst_lt (constructor_max_index,
06485                constructor_index)))
06486   process_init_element (pop_init_level (1));
06487       else
06488   break;
06489     }
06490 
06491   /* In the case of [LO ... HI] = VALUE, only evaluate VALUE once.  */
06492   if (constructor_range_stack)
06493     {
06494       /* If value is a compound literal and we'll be just using its
06495    content, don't put it into a SAVE_EXPR.  */
06496       if (TREE_CODE (value.value) != COMPOUND_LITERAL_EXPR
06497     || !require_constant_value
06498     || flag_isoc99)
06499   value.value = save_expr (value.value);
06500     }
06501 
06502   while (1)
06503     {
06504       if (TREE_CODE (constructor_type) == RECORD_TYPE)
06505   {
06506     tree fieldtype;
06507     enum tree_code fieldcode;
06508 
06509     if (constructor_fields == 0)
06510       {
06511         pedwarn_init ("excess elements in struct initializer");
06512         break;
06513       }
06514 
06515     fieldtype = TREE_TYPE (constructor_fields);
06516     if (fieldtype != error_mark_node)
06517       fieldtype = TYPE_MAIN_VARIANT (fieldtype);
06518     fieldcode = TREE_CODE (fieldtype);
06519 
06520     /* Error for non-static initialization of a flexible array member.  */
06521     if (fieldcode == ARRAY_TYPE
06522         && !require_constant_value
06523         && TYPE_SIZE (fieldtype) == NULL_TREE
06524         && TREE_CHAIN (constructor_fields) == NULL_TREE)
06525       {
06526         error_init ("non-static initialization of a flexible array member");
06527         break;
06528       }
06529 
06530     /* Accept a string constant to initialize a subarray.  */
06531     if (value.value != 0
06532         && fieldcode == ARRAY_TYPE
06533         && INTEGRAL_TYPE_P (TREE_TYPE (fieldtype))
06534         && string_flag)
06535       value.value = orig_value;
06536     /* Otherwise, if we have come to a subaggregate,
06537        and we don't have an element of its type, push into it.  */
06538     else if (value.value != 0
06539        && value.value != error_mark_node
06540        && TYPE_MAIN_VARIANT (TREE_TYPE (value.value)) != fieldtype
06541        && (fieldcode == RECORD_TYPE || fieldcode == ARRAY_TYPE
06542            || fieldcode == UNION_TYPE))
06543       {
06544         push_init_level (1);
06545         continue;
06546       }
06547 
06548     if (value.value)
06549       {
06550         push_member_name (constructor_fields);
06551         output_init_element (value.value, strict_string,
06552            fieldtype, constructor_fields, 1);
06553         RESTORE_SPELLING_DEPTH (constructor_depth);
06554       }
06555     else
06556       /* Do the bookkeeping for an element that was
06557          directly output as a constructor.  */
06558       {
06559         /* For a record, keep track of end position of last field.  */
06560         if (DECL_SIZE (constructor_fields))
06561     constructor_bit_index
06562       = size_binop (PLUS_EXPR,
06563         bit_position (constructor_fields),
06564         DECL_SIZE (constructor_fields));
06565 
06566         /* If the current field was the first one not yet written out,
06567      it isn't now, so update.  */
06568         if (constructor_unfilled_fields == constructor_fields)
06569     {
06570       constructor_unfilled_fields = TREE_CHAIN (constructor_fields);
06571       /* Skip any nameless bit fields.  */
06572       while (constructor_unfilled_fields != 0
06573        && DECL_C_BIT_FIELD (constructor_unfilled_fields)
06574        && DECL_NAME (constructor_unfilled_fields) == 0)
06575         constructor_unfilled_fields =
06576           TREE_CHAIN (constructor_unfilled_fields);
06577     }
06578       }
06579 
06580     constructor_fields = TREE_CHAIN (constructor_fields);
06581     /* Skip any nameless bit fields at the beginning.  */
06582     while (constructor_fields != 0
06583      && DECL_C_BIT_FIELD (constructor_fields)
06584      && DECL_NAME (constructor_fields) == 0)
06585       constructor_fields = TREE_CHAIN (constructor_fields);
06586   }
06587       else if (TREE_CODE (constructor_type) == UNION_TYPE)
06588   {
06589     tree fieldtype;
06590     enum tree_code fieldcode;
06591 
06592     if (constructor_fields == 0)
06593       {
06594         pedwarn_init ("excess elements in union initializer");
06595         break;
06596       }
06597 
06598     fieldtype = TREE_TYPE (constructor_fields);
06599     if (fieldtype != error_mark_node)
06600       fieldtype = TYPE_MAIN_VARIANT (fieldtype);
06601     fieldcode = TREE_CODE (fieldtype);
06602 
06603     /* Warn that traditional C rejects initialization of unions.
06604        We skip the warning if the value is zero.  This is done
06605        under the assumption that the zero initializer in user
06606        code appears conditioned on e.g. __STDC__ to avoid
06607        "missing initializer" warnings and relies on default
06608        initialization to zero in the traditional C case.
06609        We also skip the warning if the initializer is designated,
06610        again on the assumption that this must be conditional on
06611        __STDC__ anyway (and we've already complained about the
06612        member-designator already).  */
06613     if (!in_system_header && !constructor_designated
06614         && !(value.value && (integer_zerop (value.value)
06615            || real_zerop (value.value))))
06616       warning (OPT_Wtraditional, "traditional C rejects initialization "
06617          "of unions");
06618 
06619     /* Accept a string constant to initialize a subarray.  */
06620     if (value.value != 0
06621         && fieldcode == ARRAY_TYPE
06622         && INTEGRAL_TYPE_P (TREE_TYPE (fieldtype))
06623         && string_flag)
06624       value.value = orig_value;
06625     /* Otherwise, if we have come to a subaggregate,
06626        and we don't have an element of its type, push into it.  */
06627     else if (value.value != 0
06628        && value.value != error_mark_node
06629        && TYPE_MAIN_VARIANT (TREE_TYPE (value.value)) != fieldtype
06630        && (fieldcode == RECORD_TYPE || fieldcode == ARRAY_TYPE
06631            || fieldcode == UNION_TYPE))
06632       {
06633         push_init_level (1);
06634         continue;
06635       }
06636 
06637     if (value.value)
06638       {
06639         push_member_name (constructor_fields);
06640         output_init_element (value.value, strict_string,
06641            fieldtype, constructor_fields, 1);
06642         RESTORE_SPELLING_DEPTH (constructor_depth);
06643       }
06644     else
06645       /* Do the bookkeeping for an element that was
06646          directly output as a constructor.  */
06647       {
06648         constructor_bit_index = DECL_SIZE (constructor_fields);
06649         constructor_unfilled_fields = TREE_CHAIN (constructor_fields);
06650       }
06651 
06652     constructor_fields = 0;
06653   }
06654       else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
06655   {
06656     tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
06657     enum tree_code eltcode = TREE_CODE (elttype);
06658 
06659     /* Accept a string constant to initialize a subarray.  */
06660     if (value.value != 0
06661         && eltcode == ARRAY_TYPE
06662         && INTEGRAL_TYPE_P (TREE_TYPE (elttype))
06663         && string_flag)
06664       value.value = orig_value;
06665     /* Otherwise, if we have come to a subaggregate,
06666        and we don't have an element of its type, push into it.  */
06667     else if (value.value != 0
06668        && value.value != error_mark_node
06669        && TYPE_MAIN_VARIANT (TREE_TYPE (value.value)) != elttype
06670        && (eltcode == RECORD_TYPE || eltcode == ARRAY_TYPE
06671            || eltcode == UNION_TYPE))
06672       {
06673         push_init_level (1);
06674         continue;
06675       }
06676 
06677     if (constructor_max_index != 0
06678         && (tree_int_cst_lt (constructor_max_index, constructor_index)
06679       || integer_all_onesp (constructor_max_index)))
06680       {
06681         pedwarn_init ("excess elements in array initializer");
06682         break;
06683       }
06684 
06685     /* Now output the actual element.  */
06686     if (value.value)
06687       {
06688         push_array_bounds (tree_low_cst (constructor_index, 1));
06689         output_init_element (value.value, strict_string,
06690            elttype, constructor_index, 1);
06691         RESTORE_SPELLING_DEPTH (constructor_depth);
06692       }
06693 
06694     constructor_index
06695       = size_binop (PLUS_EXPR, constructor_index, bitsize_one_node);
06696 
06697     if (!value.value)
06698       /* If we are doing the bookkeeping for an element that was
06699          directly output as a constructor, we must update
06700          constructor_unfilled_index.  */
06701       constructor_unfilled_index = constructor_index;
06702   }
06703       else if (TREE_CODE (constructor_type) == VECTOR_TYPE)
06704   {
06705     tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
06706 
06707    /* Do a basic check of initializer size.  Note that vectors
06708       always have a fixed size derived from their type.  */
06709     if (tree_int_cst_lt (constructor_max_index, constructor_index))
06710       {
06711         pedwarn_init ("excess elements in vector initializer");
06712         break;
06713       }
06714 
06715     /* Now output the actual element.  */
06716     if (value.value)
06717       output_init_element (value.value, strict_string,
06718          elttype, constructor_index, 1);
06719 
06720     constructor_index
06721       = size_binop (PLUS_EXPR, constructor_index, bitsize_one_node);
06722 
06723     if (!value.value)
06724       /* If we are doing the bookkeeping for an element that was
06725          directly output as a constructor, we must update
06726          constructor_unfilled_index.  */
06727       constructor_unfilled_index = constructor_index;
06728   }
06729 
06730       /* Handle the sole element allowed in a braced initializer
06731    for a scalar variable.  */
06732       else if (constructor_type != error_mark_node
06733          && constructor_fields == 0)
06734   {
06735     pedwarn_init ("excess elements in scalar initializer");
06736     break;
06737   }
06738       else
06739   {
06740     if (value.value)
06741       output_init_element (value.value, strict_string,
06742          constructor_type, NULL_TREE, 1);
06743     constructor_fields = 0;
06744   }
06745 
06746       /* Handle range initializers either at this level or anywhere higher
06747    in the designator stack.  */
06748       if (constructor_range_stack)
06749   {
06750     struct constructor_range_stack *p, *range_stack;
06751     int finish = 0;
06752 
06753     range_stack = constructor_range_stack;
06754     constructor_range_stack = 0;
06755     while (constructor_stack != range_stack->stack)
06756       {
06757         gcc_assert (constructor_stack->implicit);
06758         process_init_element (pop_init_level (1));
06759       }
06760     for (p = range_stack;
06761          !p->range_end || tree_int_cst_equal (p->index, p->range_end);
06762          p = p->prev)
06763       {
06764         gcc_assert (constructor_stack->implicit);
06765         process_init_element (pop_init_level (1));
06766       }
06767 
06768     p->index = size_binop (PLUS_EXPR, p->index, bitsize_one_node);
06769     if (tree_int_cst_equal (p->index, p->range_end) && !p->prev)
06770       finish = 1;
06771 
06772     while (1)
06773       {
06774         constructor_index = p->index;
06775         constructor_fields = p->fields;
06776         if (finish && p->range_end && p->index == p->range_start)
06777     {
06778       finish = 0;
06779       p->prev = 0;
06780     }
06781         p = p->next;
06782         if (!p)
06783     break;
06784         push_init_level (2);
06785         p->stack = constructor_stack;
06786         if (p->range_end && tree_int_cst_equal (p->index, p->range_end))
06787     p->index = p->range_start;
06788       }
06789 
06790     if (!finish)
06791       constructor_range_stack = range_stack;
06792     continue;
06793   }
06794 
06795       break;
06796     }
06797 
06798   constructor_range_stack = 0;
06799 }
06800 
06801 /* Build a complete asm-statement, whose components are a CV_QUALIFIER
06802    (guaranteed to be 'volatile' or null) and ARGS (represented using
06803    an ASM_EXPR node).  */
06804 tree
06805 build_asm_stmt (tree cv_qualifier, tree args)
06806 {
06807   if (!ASM_VOLATILE_P (args) && cv_qualifier)
06808     ASM_VOLATILE_P (args) = 1;
06809   return add_stmt (args);
06810 }
06811 
06812 /* Build an asm-expr, whose components are a STRING, some OUTPUTS,
06813    some INPUTS, and some CLOBBERS.  The latter three may be NULL.
06814    SIMPLE indicates whether there was anything at all after the
06815    string in the asm expression -- asm("blah") and asm("blah" : )
06816    are subtly different.  We use a ASM_EXPR node to represent this.  */
06817 tree
06818 build_asm_expr (tree string, tree outputs, tree inputs, tree clobbers,
06819     bool simple)
06820 {
06821   tree tail;
06822   tree args;
06823   int i;
06824   const char *constraint;
06825   const char **oconstraints;
06826   bool allows_mem, allows_reg, is_inout;
06827   int ninputs, noutputs;
06828 
06829   ninputs = list_length (inputs);
06830   noutputs = list_length (outputs);
06831   oconstraints = (const char **) alloca (noutputs * sizeof (const char *));
06832 
06833   string = resolve_asm_operand_names (string, outputs, inputs);
06834 
06835   /* Remove output conversions that change the type but not the mode.  */
06836   for (i = 0, tail = outputs; tail; ++i, tail = TREE_CHAIN (tail))
06837     {
06838       tree output = TREE_VALUE (tail);
06839 
06840       /* ??? Really, this should not be here.  Users should be using a
06841    proper lvalue, dammit.  But there's a long history of using casts
06842    in the output operands.  In cases like longlong.h, this becomes a
06843    primitive form of typechecking -- if the cast can be removed, then
06844    the output operand had a type of the proper width; otherwise we'll
06845    get an error.  Gross, but ...  */
06846       STRIP_NOPS (output);
06847 
06848       if (!lvalue_or_else (output, lv_asm))
06849   output = error_mark_node;
06850 
06851       if (output != error_mark_node
06852     && (TREE_READONLY (output)
06853         || TYPE_READONLY (TREE_TYPE (output))
06854         || ((TREE_CODE (TREE_TYPE (output)) == RECORD_TYPE
06855        || TREE_CODE (TREE_TYPE (output)) == UNION_TYPE)
06856       && C_TYPE_FIELDS_READONLY (TREE_TYPE (output)))))
06857   readonly_error (output, lv_asm);
06858 
06859       constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail)));
06860       oconstraints[i] = constraint;
06861 
06862       if (parse_output_constraint (&constraint, i, ninputs, noutputs,
06863            &allows_mem, &allows_reg, &is_inout))
06864   {
06865     /* If the operand is going to end up in memory,
06866        mark it addressable.  */
06867     if (!allows_reg && !c_mark_addressable (output))
06868       output = error_mark_node;
06869   }
06870       else
06871   output = error_mark_node;
06872 
06873       TREE_VALUE (tail) = output;
06874     }
06875 
06876   for (i = 0, tail = inputs; tail; ++i, tail = TREE_CHAIN (tail))
06877     {
06878       tree input;
06879 
06880       constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail)));
06881       input = TREE_VALUE (tail);
06882 
06883       if (parse_input_constraint (&constraint, i, ninputs, noutputs, 0,
06884           oconstraints, &allows_mem, &allows_reg))
06885   {
06886     /* If the operand is going to end up in memory,
06887        mark it addressable.  */
06888     if (!allows_reg && allows_mem)
06889       {
06890         /* Strip the nops as we allow this case.  FIXME, this really
06891      should be rejected or made deprecated.  */
06892         STRIP_NOPS (input);
06893         if (!c_mark_addressable (input))
06894     input = error_mark_node;
06895     }
06896   }
06897       else
06898   input = error_mark_node;
06899 
06900       TREE_VALUE (tail) = input;
06901     }
06902 
06903   args = build_stmt (ASM_EXPR, string, outputs, inputs, clobbers);
06904 
06905   /* asm statements without outputs, including simple ones, are treated
06906      as volatile.  */
06907   ASM_INPUT_P (args) = simple;
06908   ASM_VOLATILE_P (args) = (noutputs == 0);
06909 
06910   return args;
06911 }
06912 
06913 /* Generate a goto statement to LABEL.  */
06914 
06915 tree
06916 c_finish_goto_label (tree label)
06917 {
06918   tree decl = lookup_label (label);
06919   if (!decl)
06920     return NULL_TREE;
06921 
06922   if (C_DECL_UNJUMPABLE_STMT_EXPR (decl))
06923     {
06924       error ("jump into statement expression");
06925       return NULL_TREE;
06926     }
06927 
06928   if (C_DECL_UNJUMPABLE_VM (decl))
06929     {
06930       error ("jump into scope of identifier with variably modified type");
06931       return NULL_TREE;
06932     }
06933 
06934   if (!C_DECL_UNDEFINABLE_STMT_EXPR (decl))
06935     {
06936       /* No jump from outside this statement expression context, so
06937    record that there is a jump from within this context.  */
06938       struct c_label_list *nlist;
06939       nlist = XOBNEW (&parser_obstack, struct c_label_list);
06940       nlist->next = label_context_stack_se->labels_used;
06941       nlist->label = decl;
06942       label_context_stack_se->labels_used = nlist;
06943     }
06944 
06945   if (!C_DECL_UNDEFINABLE_VM (decl))
06946     {
06947       /* No jump from outside this context context of identifiers with
06948    variably modified type, so record that there is a jump from
06949    within this context.  */
06950       struct c_label_list *nlist;
06951       nlist = XOBNEW (&parser_obstack, struct c_label_list);
06952       nlist->next = label_context_stack_vm->labels_used;
06953       nlist->label = decl;
06954       label_context_stack_vm->labels_used = nlist;
06955     }
06956 
06957   TREE_USED (decl) = 1;
06958   return add_stmt (build1 (GOTO_EXPR, void_type_node, decl));
06959 }
06960 
06961 /* Generate a computed goto statement to EXPR.  */
06962 
06963 tree
06964 c_finish_goto_ptr (tree expr)
06965 {
06966   if (pedantic)
06967     pedwarn ("ISO C forbids %<goto *expr;%>");
06968   expr = convert (ptr_type_node, expr);
06969   return add_stmt (build1 (GOTO_EXPR, void_type_node, expr));
06970 }
06971 
06972 /* Generate a C `return' statement.  RETVAL is the expression for what
06973    to return, or a null pointer for `return;' with no value.  */
06974 
06975 tree
06976 c_finish_return (tree retval)
06977 {
06978   tree valtype = TREE_TYPE (TREE_TYPE (current_function_decl)), ret_stmt;
06979   bool no_warning = false;
06980 
06981   if (TREE_THIS_VOLATILE (current_function_decl))
06982     warning (0, "function declared %<noreturn%> has a %<return%> statement");
06983 
06984   if (!retval)
06985     {
06986       current_function_returns_null = 1;
06987       if ((warn_return_type || flag_isoc99)
06988     && valtype != 0 && TREE_CODE (valtype) != VOID_TYPE)
06989   {
06990     pedwarn_c99 ("%<return%> with no value, in "
06991            "function returning non-void");
06992     no_warning = true;
06993   }
06994     }
06995   else if (valtype == 0 || TREE_CODE (valtype) == VOID_TYPE)
06996     {
06997       current_function_returns_null = 1;
06998       if (pedantic || TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
06999   pedwarn ("%<return%> with a value, in function returning void");
07000     }
07001   else
07002     {
07003       tree t = convert_for_assignment (valtype, retval, ic_return,
07004                NULL_TREE, NULL_TREE, 0);
07005       tree res = DECL_RESULT (current_function_decl);
07006       tree inner;
07007 
07008       current_function_returns_value = 1;
07009       if (t == error_mark_node)
07010   return NULL_TREE;
07011 
07012       inner = t = convert (TREE_TYPE (res), t);
07013 
07014       /* Strip any conversions, additions, and subtractions, and see if
07015    we are returning the address of a local variable.  Warn if so.  */
07016       while (1)
07017   {
07018     switch (TREE_CODE (inner))
07019       {
07020       case NOP_EXPR:   case NON_LVALUE_EXPR:  case CONVERT_EXPR:
07021       case PLUS_EXPR:
07022         inner = TREE_OPERAND (inner, 0);
07023         continue;
07024 
07025       case MINUS_EXPR:
07026         /* If the second operand of the MINUS_EXPR has a pointer
07027      type (or is converted from it), this may be valid, so
07028      don't give a warning.  */
07029         {
07030     tree op1 = TREE_OPERAND (inner, 1);
07031 
07032     while (!POINTER_TYPE_P (TREE_TYPE (op1))
07033            && (TREE_CODE (op1) == NOP_EXPR
07034          || TREE_CODE (op1) == NON_LVALUE_EXPR
07035          || TREE_CODE (op1) == CONVERT_EXPR))
07036       op1 = TREE_OPERAND (op1, 0);
07037 
07038     if (POINTER_TYPE_P (TREE_TYPE (op1)))
07039       break;
07040 
07041     inner = TREE_OPERAND (inner, 0);
07042     continue;
07043         }
07044 
07045       case ADDR_EXPR:
07046         inner = TREE_OPERAND (inner, 0);
07047 
07048         while (REFERENCE_CLASS_P (inner)
07049          && TREE_CODE (inner) != INDIRECT_REF)
07050     inner = TREE_OPERAND (inner, 0);
07051 
07052         if (DECL_P (inner)
07053       && !DECL_EXTERNAL (inner)
07054       && !TREE_STATIC (inner)
07055       && DECL_CONTEXT (inner) == current_function_decl)
07056     warning (0, "function returns address of local variable");
07057         break;
07058 
07059       default:
07060         break;
07061       }
07062 
07063     break;
07064   }
07065 
07066       retval = build2 (MODIFY_EXPR, TREE_TYPE (res), res, t);
07067     }
07068 
07069   ret_stmt = build_stmt (RETURN_EXPR, retval);
07070   TREE_NO_WARNING (ret_stmt) |= no_warning;
07071   return add_stmt (ret_stmt);
07072 }
07073 
07074 struct c_switch {
07075   /* The SWITCH_EXPR being built.  */
07076   tree switch_expr;
07077 
07078   /* The original type of the testing expression, i.e. before the
07079      default conversion is applied.  */
07080   tree orig_type;
07081 
07082   /* A splay-tree mapping the low element of a case range to the high
07083      element, or NULL_TREE if there is no high element.  Used to
07084      determine whether or not a new case label duplicates an old case
07085      label.  We need a tree, rather than simply a hash table, because
07086      of the GNU case range extension.  */
07087   splay_tree cases;
07088 
07089   /* Number of nested statement expressions within this switch
07090      statement; if nonzero, case and default labels may not
07091      appear.  */
07092   unsigned int blocked_stmt_expr;
07093 
07094   /* Scope of outermost declarations of identifiers with variably
07095      modified type within this switch statement; if nonzero, case and
07096      default labels may not appear.  */
07097   unsigned int blocked_vm;
07098 
07099   /* The next node on the stack.  */
07100   struct c_switch *next;
07101 };
07102 
07103 /* A stack of the currently active switch statements.  The innermost
07104    switch statement is on the top of the stack.  There is no need to
07105    mark the stack for garbage collection because it is only active
07106    during the processing of the body of a function, and we never
07107    collect at that point.  */
07108 
07109 struct c_switch *c_switch_stack;
07110 
07111 /* Start a C switch statement, testing expression EXP.  Return the new
07112    SWITCH_EXPR.  */
07113 
07114 tree
07115 c_start_case (tree exp)
07116 {
07117   tree orig_type = error_mark_node;
07118   struct c_switch *cs;
07119 
07120   if (exp != error_mark_node)
07121     {
07122       orig_type = TREE_TYPE (exp);
07123 
07124       if (!INTEGRAL_TYPE_P (orig_type))
07125   {
07126     if (orig_type != error_mark_node)
07127       {
07128         error ("switch quantity not an integer");
07129         orig_type = error_mark_node;
07130       }
07131     exp = integer_zero_node;
07132   }
07133       else
07134   {
07135     tree type = TYPE_MAIN_VARIANT (orig_type);
07136 
07137     if (!in_system_header
07138         && (type == long_integer_type_node
07139       || type == long_unsigned_type_node))
07140       warning (OPT_Wtraditional, "%<long%> switch expression not "
07141          "converted to %<int%> in ISO C");
07142 
07143     exp = default_conversion (exp);
07144   }
07145     }
07146 
07147   /* Add this new SWITCH_EXPR to the stack.  */
07148   cs = XNEW (struct c_switch);
07149   cs->switch_expr = build3 (SWITCH_EXPR, orig_type, exp, NULL_TREE, NULL_TREE);
07150   cs->orig_type = orig_type;
07151   cs->cases = splay_tree_new (case_compare, NULL, NULL);
07152   cs->blocked_stmt_expr = 0;
07153   cs->blocked_vm = 0;
07154   cs->next = c_switch_stack;
07155   c_switch_stack = cs;
07156 
07157   return add_stmt (cs->switch_expr);
07158 }
07159 
07160 /* Process a case label.  */
07161 
07162 tree
07163 do_case (tree low_value, tree high_value)
07164 {
07165   tree label = NULL_TREE;
07166 
07167   if (c_switch_stack && !c_switch_stack->blocked_stmt_expr
07168       && !c_switch_stack->blocked_vm)
07169     {
07170       label = c_add_case_label (c_switch_stack->cases,
07171         SWITCH_COND (c_switch_stack->switch_expr),
07172         c_switch_stack->orig_type,
07173         low_value, high_value);
07174       if (label == error_mark_node)
07175   label = NULL_TREE;
07176     }
07177   else if (c_switch_stack && c_switch_stack->blocked_stmt_expr)
07178     {
07179       if (low_value)
07180   error ("case label in statement expression not containing "
07181          "enclosing switch statement");
07182       else
07183   error ("%<default%> label in statement expression not containing "
07184          "enclosing switch statement");
07185     }
07186   else if (c_switch_stack && c_switch_stack->blocked_vm)
07187     {
07188       if (low_value)
07189   error ("case label in scope of identifier with variably modified "
07190          "type not containing enclosing switch statement");
07191       else
07192   error ("%<default%> label in scope of identifier with variably "
07193          "modified type not containing enclosing switch statement");
07194     }
07195   else if (low_value)
07196     error ("case label not within a switch statement");
07197   else
07198     error ("%<default%> label not within a switch statement");
07199 
07200   return label;
07201 }
07202 
07203 /* Finish the switch statement.  */
07204 
07205 void
07206 c_finish_case (tree body)
07207 {
07208   struct c_switch *cs = c_switch_stack;
07209   location_t switch_location;
07210 
07211   SWITCH_BODY (cs->switch_expr) = body;
07212 
07213   /* We must not be within a statement expression nested in the switch
07214      at this point; we might, however, be within the scope of an
07215      identifier with variably modified type nested in the switch.  */
07216   gcc_assert (!cs->blocked_stmt_expr);
07217 
07218   /* Emit warnings as needed.  */
07219   if (EXPR_HAS_LOCATION (cs->switch_expr))
07220     switch_location = EXPR_LOCATION (cs->switch_expr);
07221   else
07222     switch_location = input_location;
07223   c_do_switch_warnings (cs->cases, switch_location,
07224       TREE_TYPE (cs->switch_expr),
07225       SWITCH_COND (cs->switch_expr));
07226 
07227   /* Pop the stack.  */
07228   c_switch_stack = cs->next;
07229   splay_tree_delete (cs->cases);
07230   XDELETE (cs);
07231 }
07232 
07233 /* Emit an if statement.  IF_LOCUS is the location of the 'if'.  COND,
07234    THEN_BLOCK and ELSE_BLOCK are expressions to be used; ELSE_BLOCK
07235    may be null.  NESTED_IF is true if THEN_BLOCK contains another IF
07236    statement, and was not surrounded with parenthesis.  */
07237 
07238 void
07239 c_finish_if_stmt (location_t if_locus, tree cond, tree then_block,
07240       tree else_block, bool nested_if)
07241 {
07242   tree stmt;
07243 
07244   /* Diagnose an ambiguous else if if-then-else is nested inside if-then.  */
07245   if (warn_parentheses && nested_if && else_block == NULL)
07246     {
07247       tree inner_if = then_block;
07248 
07249       /* We know from the grammar productions that there is an IF nested
07250    within THEN_BLOCK.  Due to labels and c99 conditional declarations,
07251    it might not be exactly THEN_BLOCK, but should be the last
07252    non-container statement within.  */
07253       while (1)
07254   switch (TREE_CODE (inner_if))
07255     {
07256     case COND_EXPR:
07257       goto found;
07258     case BIND_EXPR:
07259       inner_if = BIND_EXPR_BODY (inner_if);
07260       break;
07261     case STATEMENT_LIST:
07262       inner_if = expr_last (then_block);
07263       break;
07264     case TRY_FINALLY_EXPR:
07265     case TRY_CATCH_EXPR:
07266       inner_if = TREE_OPERAND (inner_if, 0);
07267       break;
07268     default:
07269       gcc_unreachable ();
07270     }
07271     found:
07272 
07273       if (COND_EXPR_ELSE (inner_if))
07274    warning (OPT_Wparentheses,
07275       "%Hsuggest explicit braces to avoid ambiguous %<else%>",
07276       &if_locus);
07277     }
07278 
07279   empty_body_warning (then_block, else_block);
07280 
07281   stmt = build3 (COND_EXPR, void_type_node, cond, then_block, else_block);
07282   SET_EXPR_LOCATION (stmt, if_locus);
07283   add_stmt (stmt);
07284 }
07285 
07286 /* Emit a general-purpose loop construct.  START_LOCUS is the location of
07287    the beginning of the loop.  COND is the loop condition.  COND_IS_FIRST
07288    is false for DO loops.  INCR is the FOR increment expression.  BODY is
07289    the statement controlled by the loop.  BLAB is the break label.  CLAB is
07290    the continue label.  Everything is allowed to be NULL.  */
07291 
07292 void
07293 c_finish_loop (location_t start_locus, tree cond, tree incr, tree body,
07294          tree blab, tree clab, bool cond_is_first)
07295 {
07296   tree entry = NULL, exit = NULL, t;
07297 
07298   /* If the condition is zero don't generate a loop construct.  */
07299   if (cond && integer_zerop (cond))
07300     {
07301       if (cond_is_first)
07302   {
07303     t = build_and_jump (&blab);
07304     SET_EXPR_LOCATION (t, start_locus);
07305     add_stmt (t);
07306   }
07307     }
07308   else
07309     {
07310       tree top = build1 (LABEL_EXPR, void_type_node, NULL_TREE);
07311 
07312       /* If we have an exit condition, then we build an IF with gotos either
07313    out of the loop, or to the top of it.  If there's no exit condition,
07314    then we just build a jump back to the top.  */
07315       exit = build_and_jump (&LABEL_EXPR_LABEL (top));
07316 
07317       if (cond && !integer_nonzerop (cond))
07318   {
07319     /* Canonicalize the loop condition to the end.  This means
07320        generating a branch to the loop condition.  Reuse the
07321        continue label, if possible.  */
07322     if (cond_is_first)
07323       {
07324         if (incr || !clab)
07325     {
07326       entry = build1 (LABEL_EXPR, void_type_node, NULL_TREE);
07327       t = build_and_jump (&LABEL_EXPR_LABEL (entry));
07328     }
07329         else
07330     t = build1 (GOTO_EXPR, void_type_node, clab);
07331         SET_EXPR_LOCATION (t, start_locus);
07332         add_stmt (t);
07333       }
07334 
07335     t = build_and_jump (&blab);
07336     exit = fold_build3 (COND_EXPR, void_type_node, cond, exit, t);
07337     if (cond_is_first)
07338       SET_EXPR_LOCATION (exit, start_locus);
07339     else
07340       SET_EXPR_LOCATION (exit, input_location);
07341   }
07342 
07343       add_stmt (top);
07344     }
07345 
07346   if (body)
07347     add_stmt (body);
07348   if (clab)
07349     add_stmt (build1 (LABEL_EXPR, void_type_node, clab));
07350   if (incr)
07351     add_stmt (incr);
07352   if (entry)
07353     add_stmt (entry);
07354   if (exit)
07355     add_stmt (exit);
07356   if (blab)
07357     add_stmt (build1 (LABEL_EXPR, void_type_node, blab));
07358 }
07359 
07360 tree
07361 c_finish_bc_stmt (tree *label_p, bool is_break)
07362 {
07363   bool skip;
07364   tree label = *label_p;
07365 
07366   /* In switch statements break is sometimes stylistically used after
07367      a return statement.  This can lead to spurious warnings about
07368      control reaching the end of a non-void function when it is
07369      inlined.  Note that we are calling block_may_fallthru with
07370      language specific tree nodes; this works because
07371      block_may_fallthru returns true when given something it does not
07372      understand.  */
07373   skip = !block_may_fallthru (cur_stmt_list);
07374 
07375   if (!label)
07376     {
07377       if (!skip)
07378   *label_p = label = create_artificial_label ();
07379     }
07380   else if (TREE_CODE (label) == LABEL_DECL)
07381     ;
07382   else switch (TREE_INT_CST_LOW (label))
07383     {
07384     case 0:
07385       if (is_break)
07386   error ("break statement not within loop or switch");
07387       else
07388   error ("continue statement not within a loop");
07389       return NULL_TREE;
07390 
07391     case 1:
07392       gcc_assert (is_break);
07393       error ("break statement used with OpenMP for loop");
07394       return NULL_TREE;
07395 
07396     default:
07397       gcc_unreachable ();
07398     }
07399 
07400   if (skip)
07401     return NULL_TREE;
07402 
07403   return add_stmt (build1 (GOTO_EXPR, void_type_node, label));
07404 }
07405 
07406 /* A helper routine for c_process_expr_stmt and c_finish_stmt_expr.  */
07407 
07408 static void
07409 emit_side_effect_warnings (tree expr)
07410 {
07411   if (expr == error_mark_node)
07412     ;
07413   else if (!TREE_SIDE_EFFECTS (expr))
07414     {
07415       if (!VOID_TYPE_P (TREE_TYPE (expr)) && !TREE_NO_WARNING (expr))
07416   warning (0, "%Hstatement with no effect",
07417      EXPR_HAS_LOCATION (expr) ? EXPR_LOCUS (expr) : &input_location);
07418     }
07419   else if (warn_unused_value)
07420     warn_if_unused_value (expr, input_location);
07421 }
07422 
07423 /* Process an expression as if it were a complete statement.  Emit
07424    diagnostics, but do not call ADD_STMT.  */
07425 
07426 tree
07427 c_process_expr_stmt (tree expr)
07428 {
07429   if (!expr)
07430     return NULL_TREE;
07431 
07432   if (warn_sequence_point)
07433     verify_sequence_points (expr);
07434 
07435   if (TREE_TYPE (expr) != error_mark_node
07436       && !COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (expr))
07437       && TREE_CODE (TREE_TYPE (expr)) != ARRAY_TYPE)
07438     error ("expression statement has incomplete type");
07439 
07440   /* If we're not processing a statement expression, warn about unused values.
07441      Warnings for statement expressions will be emitted later, once we figure
07442      out which is the result.  */
07443   if (!STATEMENT_LIST_STMT_EXPR (cur_stmt_list)
07444       && (extra_warnings || warn_unused_value))
07445     emit_side_effect_warnings (expr);
07446 
07447   /* If the expression is not of a type to which we cannot assign a line
07448      number, wrap the thing in a no-op NOP_EXPR.  */
07449   if (DECL_P (expr) || CONSTANT_CLASS_P (expr))
07450     expr = build1 (NOP_EXPR, TREE_TYPE (expr), expr);
07451 
07452   if (EXPR_P (expr))
07453     SET_EXPR_LOCATION (expr, input_location);
07454 
07455   return expr;
07456 }
07457 
07458 /* Emit an expression as a statement.  */
07459 
07460 tree
07461 c_finish_expr_stmt (tree expr)
07462 {
07463   if (expr)
07464     return add_stmt (c_process_expr_stmt (expr));
07465   else
07466     return NULL;
07467 }
07468 
07469 /* Do the opposite and emit a statement as an expression.  To begin,
07470    create a new binding level and return it.  */
07471 
07472 tree
07473 c_begin_stmt_expr (void)
07474 {
07475   tree ret;
07476   struct c_label_context_se *nstack;
07477   struct c_label_list *glist;
07478 
07479   /* We must force a BLOCK for this level so that, if it is not expanded
07480      later, there is a way to turn off the entire subtree of blocks that
07481      are contained in it.  */
07482   keep_next_level ();
07483   ret = c_begin_compound_stmt (true);
07484   if (c_switch_stack)
07485     {
07486       c_switch_stack->blocked_stmt_expr++;
07487       gcc_assert (c_switch_stack->blocked_stmt_expr != 0);
07488     }
07489   for (glist = label_context_stack_se->labels_used;
07490        glist != NULL;
07491        glist = glist->next)
07492     {
07493       C_DECL_UNDEFINABLE_STMT_EXPR (glist->label) = 1;
07494     }
07495   nstack = XOBNEW (&parser_obstack, struct c_label_context_se);
07496   nstack->labels_def = NULL;
07497   nstack->labels_used = NULL;
07498   nstack->next = label_context_stack_se;
07499   label_context_stack_se = nstack;
07500 
07501   /* Mark the current statement list as belonging to a statement list.  */
07502   STATEMENT_LIST_STMT_EXPR (ret) = 1;
07503 
07504   return ret;
07505 }
07506 
07507 tree
07508 c_finish_stmt_expr (tree body)
07509 {
07510   tree last, type, tmp, val;
07511   tree *last_p;
07512   struct c_label_list *dlist, *glist, *glist_prev = NULL;
07513 
07514   body = c_end_compound_stmt (body, true);
07515   if (c_switch_stack)
07516     {
07517       gcc_assert (c_switch_stack->blocked_stmt_expr != 0);
07518       c_switch_stack->blocked_stmt_expr--;
07519     }
07520   /* It is no longer possible to jump to labels defined within this
07521      statement expression.  */
07522   for (dlist = label_context_stack_se->labels_def;
07523        dlist != NULL;
07524        dlist = dlist->next)
07525     {
07526       C_DECL_UNJUMPABLE_STMT_EXPR (dlist->label) = 1;
07527     }
07528   /* It is again possible to define labels with a goto just outside
07529      this statement expression.  */
07530   for (glist = label_context_stack_se->next->labels_used;
07531        glist != NULL;
07532        glist = glist->next)
07533     {
07534       C_DECL_UNDEFINABLE_STMT_EXPR (glist->label) = 0;
07535       glist_prev = glist;
07536     }
07537   if (glist_prev != NULL)
07538     glist_prev->next = label_context_stack_se->labels_used;
07539   else
07540     label_context_stack_se->next->labels_used
07541       = label_context_stack_se->labels_used;
07542   label_context_stack_se = label_context_stack_se->next;
07543 
07544   /* Locate the last statement in BODY.  See c_end_compound_stmt
07545      about always returning a BIND_EXPR.  */
07546   last_p = &BIND_EXPR_BODY (body);
07547   last = BIND_EXPR_BODY (body);
07548 
07549  continue_searching:
07550   if (TREE_CODE (last) == STATEMENT_LIST)
07551     {
07552       tree_stmt_iterator i;
07553 
07554       /* This can happen with degenerate cases like ({ }).  No value.  */
07555       if (!TREE_SIDE_EFFECTS (last))
07556   return body;
07557 
07558       /* If we're supposed to generate side effects warnings, process
07559    all of the statements except the last.  */
07560       if (extra_warnings || warn_unused_value)
07561   {
07562     for (i = tsi_start (last); !tsi_one_before_end_p (i); tsi_next (&i))
07563       emit_side_effect_warnings (tsi_stmt (i));
07564   }
07565       else
07566   i = tsi_last (last);
07567       last_p = tsi_stmt_ptr (i);
07568       last = *last_p;
07569     }
07570 
07571   /* If the end of the list is exception related, then the list was split
07572      by a call to push_cleanup.  Continue searching.  */
07573   if (TREE_CODE (last) == TRY_FINALLY_EXPR
07574       || TREE_CODE (last) == TRY_CATCH_EXPR)
07575     {
07576       last_p = &TREE_OPERAND (last, 0);
07577       last = *last_p;
07578       goto continue_searching;
07579     }
07580 
07581   /* In the case that the BIND_EXPR is not necessary, return the
07582      expression out from inside it.  */
07583   if (last == error_mark_node
07584       || (last == BIND_EXPR_BODY (body)
07585     && BIND_EXPR_VARS (body) == NULL))
07586     {
07587       /* Do not warn if the return value of a statement expression is
07588    unused.  */
07589       if (EXPR_P (last))
07590   TREE_NO_WARNING (last) = 1;
07591       return last;
07592     }
07593 
07594   /* Extract the type of said expression.  */
07595   type = TREE_TYPE (last);
07596 
07597   /* If we're not returning a value at all, then the BIND_EXPR that
07598      we already have is a fine expression to return.  */
07599   if (!type || VOID_TYPE_P (type))
07600     return body;
07601 
07602   /* Now that we've located the expression containing the value, it seems
07603      silly to make voidify_wrapper_expr repeat the process.  Create a
07604      temporary of the appropriate type and stick it in a TARGET_EXPR.  */
07605   tmp = create_tmp_var_raw (type, NULL);
07606 
07607   /* Unwrap a no-op NOP_EXPR as added by c_finish_expr_stmt.  This avoids
07608      tree_expr_nonnegative_p giving up immediately.  */
07609   val = last;
07610   if (TREE_CODE (val) == NOP_EXPR
07611       && TREE_TYPE (val) == TREE_TYPE (TREE_OPERAND (val, 0)))
07612     val = TREE_OPERAND (val, 0);
07613 
07614   *last_p = build2 (MODIFY_EXPR, void_type_node, tmp, val);
07615   SET_EXPR_LOCUS (*last_p, EXPR_LOCUS (last));
07616 
07617   return build4 (TARGET_EXPR, type, tmp, body, NULL_TREE, NULL_TREE);
07618 }
07619 
07620 /* Begin the scope of an identifier of variably modified type, scope
07621    number SCOPE.  Jumping from outside this scope to inside it is not
07622    permitted.  */
07623 
07624 void
07625 c_begin_vm_scope (unsigned int scope)
07626 {
07627   struct c_label_context_vm *nstack;
07628   struct c_label_list *glist;
07629 
07630   gcc_assert (scope > 0);
07631 
07632   /* At file_scope, we don't have to do any processing.  */
07633   if (label_context_stack_vm == NULL)
07634     return;
07635 
07636   if (c_switch_stack && !c_switch_stack->blocked_vm)
07637     c_switch_stack->