• Main Page
  • Modules
  • Data Types
  • Files

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