OSDN Git Service

* c-common.c (decl_attributes): Set DECL_SIZE_UNIT.
[pf3gnuchains/gcc-fork.git] / gcc / c-typeck.c
1 /* Build expressions with type checking for C compiler.
2    Copyright (C) 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3    1998, 1999, 2000 Free Software Foundation, Inc.
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22
23 /* This file is part of the C front end.
24    It contains routines to build C expressions given their operands,
25    including computing the types of the result, C-specific error checks,
26    and some optimization.
27
28    There are also routines to build RETURN_STMT nodes and CASE_STMT nodes,
29    and to process initializations in declarations (since they work
30    like a strange sort of assignment).  */
31
32 #include "config.h"
33 #include "system.h"
34 #include "tree.h"
35 #include "c-tree.h"
36 #include "tm_p.h"
37 #include "flags.h"
38 #include "output.h"
39 #include "rtl.h"
40 #include "expr.h"
41 #include "toplev.h"
42 #include "intl.h"
43 #include "defaults.h"
44 #include "ggc.h"
45
46 /* Nonzero if we've already printed a "missing braces around initializer"
47    message within this initializer.  */
48 static int missing_braces_mentioned;
49
50 static tree qualify_type                PARAMS ((tree, tree));
51 static int comp_target_types            PARAMS ((tree, tree));
52 static int function_types_compatible_p  PARAMS ((tree, tree));
53 static int type_lists_compatible_p      PARAMS ((tree, tree));
54 static tree decl_constant_value         PARAMS ((tree));
55 static tree lookup_field                PARAMS ((tree, tree, tree *));
56 static tree convert_arguments           PARAMS ((tree, tree, tree, tree));
57 static tree pointer_int_sum             PARAMS ((enum tree_code, tree, tree));
58 static tree pointer_diff                PARAMS ((tree, tree));
59 static tree unary_complex_lvalue        PARAMS ((enum tree_code, tree));
60 static void pedantic_lvalue_warning     PARAMS ((enum tree_code));
61 static tree internal_build_compound_expr PARAMS ((tree, int));
62 static tree convert_for_assignment      PARAMS ((tree, tree, const char *,
63                                                  tree, tree, int));
64 static void warn_for_assignment         PARAMS ((const char *, const char *,
65                                                  tree, int));
66 static tree valid_compound_expr_initializer PARAMS ((tree, tree));
67 static void push_string                 PARAMS ((const char *));
68 static void push_member_name            PARAMS ((tree));
69 static void push_array_bounds           PARAMS ((int));
70 static int spelling_length              PARAMS ((void));
71 static char *print_spelling             PARAMS ((char *));
72 static void warning_init                PARAMS ((const char *));
73 static tree digest_init                 PARAMS ((tree, tree, int, int));
74 static void check_init_type_bitfields   PARAMS ((tree));
75 static void output_init_element         PARAMS ((tree, tree, tree, int));
76 static void output_pending_init_elements PARAMS ((int));
77 static void add_pending_init            PARAMS ((tree, tree));
78 static int pending_init_member          PARAMS ((tree));
79 \f
80 /* Do `exp = require_complete_type (exp);' to make sure exp
81    does not have an incomplete type.  (That includes void types.)  */
82
83 tree
84 require_complete_type (value)
85      tree value;
86 {
87   tree type = TREE_TYPE (value);
88
89   if (TREE_CODE (value) == ERROR_MARK)
90     return error_mark_node;
91
92   /* First, detect a valid value with a complete type.  */
93   if (TYPE_SIZE (type) != 0
94       && type != void_type_node)
95     return value;
96
97   incomplete_type_error (value, type);
98   return error_mark_node;
99 }
100
101 /* Print an error message for invalid use of an incomplete type.
102    VALUE is the expression that was used (or 0 if that isn't known)
103    and TYPE is the type that was invalid.  */
104
105 void
106 incomplete_type_error (value, type)
107      tree value;
108      tree type;
109 {
110   const char *type_code_string;
111
112   /* Avoid duplicate error message.  */
113   if (TREE_CODE (type) == ERROR_MARK)
114     return;
115
116   if (value != 0 && (TREE_CODE (value) == VAR_DECL
117                      || TREE_CODE (value) == PARM_DECL))
118     error ("`%s' has an incomplete type",
119            IDENTIFIER_POINTER (DECL_NAME (value)));
120   else
121     {
122     retry:
123       /* We must print an error message.  Be clever about what it says.  */
124
125       switch (TREE_CODE (type))
126         {
127         case RECORD_TYPE:
128           type_code_string = "struct";
129           break;
130
131         case UNION_TYPE:
132           type_code_string = "union";
133           break;
134
135         case ENUMERAL_TYPE:
136           type_code_string = "enum";
137           break;
138
139         case VOID_TYPE:
140           error ("invalid use of void expression");
141           return;
142
143         case ARRAY_TYPE:
144           if (TYPE_DOMAIN (type))
145             {
146               type = TREE_TYPE (type);
147               goto retry;
148             }
149           error ("invalid use of array with unspecified bounds");
150           return;
151
152         default:
153           abort ();
154         }
155
156       if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
157         error ("invalid use of undefined type `%s %s'",
158                type_code_string, IDENTIFIER_POINTER (TYPE_NAME (type)));
159       else
160         /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL.  */
161         error ("invalid use of incomplete typedef `%s'",
162                IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
163     }
164 }
165
166 /* Return a variant of TYPE which has all the type qualifiers of LIKE
167    as well as those of TYPE.  */
168
169 static tree
170 qualify_type (type, like)
171      tree type, like;
172 {
173   return c_build_qualified_type (type, 
174                                  TYPE_QUALS (type) | TYPE_QUALS (like));
175 }
176 \f
177 /* Return the common type of two types.
178    We assume that comptypes has already been done and returned 1;
179    if that isn't so, this may crash.  In particular, we assume that qualifiers
180    match.
181
182    This is the type for the result of most arithmetic operations
183    if the operands have the given two types.  */
184
185 tree
186 common_type (t1, t2)
187      tree t1, t2;
188 {
189   register enum tree_code code1;
190   register enum tree_code code2;
191   tree attributes;
192
193   /* Save time if the two types are the same.  */
194
195   if (t1 == t2) return t1;
196
197   /* If one type is nonsense, use the other.  */
198   if (t1 == error_mark_node)
199     return t2;
200   if (t2 == error_mark_node)
201     return t1;
202
203   /* Merge the attributes.  */
204   attributes = merge_machine_type_attributes (t1, t2);
205
206   /* Treat an enum type as the unsigned integer type of the same width.  */
207
208   if (TREE_CODE (t1) == ENUMERAL_TYPE)
209     t1 = type_for_size (TYPE_PRECISION (t1), 1);
210   if (TREE_CODE (t2) == ENUMERAL_TYPE)
211     t2 = type_for_size (TYPE_PRECISION (t2), 1);
212
213   code1 = TREE_CODE (t1);
214   code2 = TREE_CODE (t2);
215
216   /* If one type is complex, form the common type of the non-complex
217      components, then make that complex.  Use T1 or T2 if it is the
218      required type.  */
219   if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE)
220     {
221       tree subtype1 = code1 == COMPLEX_TYPE ? TREE_TYPE (t1) : t1;
222       tree subtype2 = code2 == COMPLEX_TYPE ? TREE_TYPE (t2) : t2;
223       tree subtype = common_type (subtype1, subtype2);
224
225       if (code1 == COMPLEX_TYPE && TREE_TYPE (t1) == subtype)
226         return build_type_attribute_variant (t1, attributes);
227       else if (code2 == COMPLEX_TYPE && TREE_TYPE (t2) == subtype)
228         return build_type_attribute_variant (t2, attributes);
229       else
230         return build_type_attribute_variant (build_complex_type (subtype),
231                                              attributes);
232     }
233
234   switch (code1)
235     {
236     case INTEGER_TYPE:
237     case REAL_TYPE:
238       /* If only one is real, use it as the result.  */
239
240       if (code1 == REAL_TYPE && code2 != REAL_TYPE)
241         return build_type_attribute_variant (t1, attributes);
242
243       if (code2 == REAL_TYPE && code1 != REAL_TYPE)
244         return build_type_attribute_variant (t2, attributes);
245
246       /* Both real or both integers; use the one with greater precision.  */
247
248       if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2))
249         return build_type_attribute_variant (t1, attributes);
250       else if (TYPE_PRECISION (t2) > TYPE_PRECISION (t1))
251         return build_type_attribute_variant (t2, attributes);
252
253       /* Same precision.  Prefer longs to ints even when same size.  */
254
255       if (TYPE_MAIN_VARIANT (t1) == long_unsigned_type_node
256           || TYPE_MAIN_VARIANT (t2) == long_unsigned_type_node)
257         return build_type_attribute_variant (long_unsigned_type_node,
258                                              attributes);
259
260       if (TYPE_MAIN_VARIANT (t1) == long_integer_type_node
261           || TYPE_MAIN_VARIANT (t2) == long_integer_type_node)
262         {
263           /* But preserve unsignedness from the other type,
264              since long cannot hold all the values of an unsigned int.  */
265           if (TREE_UNSIGNED (t1) || TREE_UNSIGNED (t2))
266              t1 = long_unsigned_type_node;
267           else
268              t1 = long_integer_type_node;
269           return build_type_attribute_variant (t1, attributes);
270         }
271
272       /* Likewise, prefer long double to double even if same size.  */
273       if (TYPE_MAIN_VARIANT (t1) == long_double_type_node
274           || TYPE_MAIN_VARIANT (t2) == long_double_type_node)
275         return build_type_attribute_variant (long_double_type_node,
276                                              attributes);
277
278       /* Otherwise prefer the unsigned one.  */
279
280       if (TREE_UNSIGNED (t1))
281         return build_type_attribute_variant (t1, attributes);
282       else
283         return build_type_attribute_variant (t2, attributes);
284
285     case POINTER_TYPE:
286       /* For two pointers, do this recursively on the target type,
287          and combine the qualifiers of the two types' targets.  */
288       /* This code was turned off; I don't know why.
289          But ANSI C specifies doing this with the qualifiers.
290          So I turned it on again.  */
291       {
292         tree pointed_to_1 = TREE_TYPE (t1);
293         tree pointed_to_2 = TREE_TYPE (t2);
294         tree target = common_type (TYPE_MAIN_VARIANT (pointed_to_1),
295                                    TYPE_MAIN_VARIANT (pointed_to_2));
296         t1 = build_pointer_type (c_build_qualified_type 
297                                  (target, 
298                                   TYPE_QUALS (pointed_to_1) | 
299                                   TYPE_QUALS (pointed_to_2)));
300         return build_type_attribute_variant (t1, attributes);
301       }
302 #if 0
303       t1 = build_pointer_type (common_type (TREE_TYPE (t1), TREE_TYPE (t2)));
304       return build_type_attribute_variant (t1, attributes);
305 #endif
306
307     case ARRAY_TYPE:
308       {
309         tree elt = common_type (TREE_TYPE (t1), TREE_TYPE (t2));
310         /* Save space: see if the result is identical to one of the args.  */
311         if (elt == TREE_TYPE (t1) && TYPE_DOMAIN (t1))
312           return build_type_attribute_variant (t1, attributes);
313         if (elt == TREE_TYPE (t2) && TYPE_DOMAIN (t2))
314           return build_type_attribute_variant (t2, attributes);
315         /* Merge the element types, and have a size if either arg has one.  */
316         t1 = build_array_type (elt, TYPE_DOMAIN (TYPE_DOMAIN (t1) ? t1 : t2));
317         return build_type_attribute_variant (t1, attributes);
318       }
319
320     case FUNCTION_TYPE:
321       /* Function types: prefer the one that specified arg types.
322          If both do, merge the arg types.  Also merge the return types.  */
323       {
324         tree valtype = common_type (TREE_TYPE (t1), TREE_TYPE (t2));
325         tree p1 = TYPE_ARG_TYPES (t1);
326         tree p2 = TYPE_ARG_TYPES (t2);
327         int len;
328         tree newargs, n;
329         int i;
330
331         /* Save space: see if the result is identical to one of the args.  */
332         if (valtype == TREE_TYPE (t1) && ! TYPE_ARG_TYPES (t2))
333           return build_type_attribute_variant (t1, attributes);
334         if (valtype == TREE_TYPE (t2) && ! TYPE_ARG_TYPES (t1))
335           return build_type_attribute_variant (t2, attributes);
336
337         /* Simple way if one arg fails to specify argument types.  */
338         if (TYPE_ARG_TYPES (t1) == 0)
339          {
340            t1 = build_function_type (valtype, TYPE_ARG_TYPES (t2));
341            return build_type_attribute_variant (t1, attributes);
342          }
343         if (TYPE_ARG_TYPES (t2) == 0)
344          {
345            t1 = build_function_type (valtype, TYPE_ARG_TYPES (t1));
346            return build_type_attribute_variant (t1, attributes);
347          }
348
349         /* If both args specify argument types, we must merge the two
350            lists, argument by argument.  */
351
352         len = list_length (p1);
353         newargs = 0;
354
355         for (i = 0; i < len; i++)
356           newargs = tree_cons (NULL_TREE, NULL_TREE, newargs);
357
358         n = newargs;
359
360         for (; p1;
361              p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2), n = TREE_CHAIN (n))
362           {
363             /* A null type means arg type is not specified.
364                Take whatever the other function type has.  */
365             if (TREE_VALUE (p1) == 0)
366               {
367                 TREE_VALUE (n) = TREE_VALUE (p2);
368                 goto parm_done;
369               }
370             if (TREE_VALUE (p2) == 0)
371               {
372                 TREE_VALUE (n) = TREE_VALUE (p1);
373                 goto parm_done;
374               }
375               
376             /* Given  wait (union {union wait *u; int *i} *)
377                and  wait (union wait *),
378                prefer  union wait *  as type of parm.  */
379             if (TREE_CODE (TREE_VALUE (p1)) == UNION_TYPE
380                 && TREE_VALUE (p1) != TREE_VALUE (p2))
381               {
382                 tree memb;
383                 for (memb = TYPE_FIELDS (TREE_VALUE (p1));
384                      memb; memb = TREE_CHAIN (memb))
385                   if (comptypes (TREE_TYPE (memb), TREE_VALUE (p2)))
386                     {
387                       TREE_VALUE (n) = TREE_VALUE (p2);
388                       if (pedantic)
389                         pedwarn ("function types not truly compatible in ANSI C");
390                       goto parm_done;
391                     }
392               }
393             if (TREE_CODE (TREE_VALUE (p2)) == UNION_TYPE
394                 && TREE_VALUE (p2) != TREE_VALUE (p1))
395               {
396                 tree memb;
397                 for (memb = TYPE_FIELDS (TREE_VALUE (p2));
398                      memb; memb = TREE_CHAIN (memb))
399                   if (comptypes (TREE_TYPE (memb), TREE_VALUE (p1)))
400                     {
401                       TREE_VALUE (n) = TREE_VALUE (p1);
402                       if (pedantic)
403                         pedwarn ("function types not truly compatible in ANSI C");
404                       goto parm_done;
405                     }
406               }
407             TREE_VALUE (n) = common_type (TREE_VALUE (p1), TREE_VALUE (p2));
408           parm_done: ;
409           }
410
411         t1 = build_function_type (valtype, newargs);
412         /* ... falls through ...  */
413       }
414
415     default:
416       return build_type_attribute_variant (t1, attributes);
417     }
418
419 }
420 \f
421 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
422    or various other operations.  Return 2 if they are compatible
423    but a warning may be needed if you use them together.  */
424
425 int
426 comptypes (type1, type2)
427      tree type1, type2;
428 {
429   register tree t1 = type1;
430   register tree t2 = type2;
431   int attrval, val;
432
433   /* Suppress errors caused by previously reported errors.  */
434
435   if (t1 == t2 || !t1 || !t2
436       || TREE_CODE (t1) == ERROR_MARK || TREE_CODE (t2) == ERROR_MARK)
437     return 1;
438
439   /* Treat an enum type as the integer type of the same width and 
440      signedness.  */
441
442   if (TREE_CODE (t1) == ENUMERAL_TYPE)
443     t1 = type_for_size (TYPE_PRECISION (t1), TREE_UNSIGNED (t1));
444   if (TREE_CODE (t2) == ENUMERAL_TYPE)
445     t2 = type_for_size (TYPE_PRECISION (t2), TREE_UNSIGNED (t2));
446
447   if (t1 == t2)
448     return 1;
449
450   /* Different classes of types can't be compatible.  */
451
452   if (TREE_CODE (t1) != TREE_CODE (t2)) return 0;
453
454   /* Qualifiers must match.  */
455
456   if (TYPE_QUALS (t1) != TYPE_QUALS (t2))
457     return 0;
458
459   /* Allow for two different type nodes which have essentially the same
460      definition.  Note that we already checked for equality of the type
461      qualifiers (just above).  */
462
463   if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
464     return 1;
465
466 #ifndef COMP_TYPE_ATTRIBUTES
467 #define COMP_TYPE_ATTRIBUTES(t1,t2)     1
468 #endif
469
470   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
471   if (! (attrval = COMP_TYPE_ATTRIBUTES (t1, t2)))
472      return 0;
473
474   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
475   val = 0;
476
477   switch (TREE_CODE (t1))
478     {
479     case POINTER_TYPE:
480       val = (TREE_TYPE (t1) == TREE_TYPE (t2)
481               ? 1 : comptypes (TREE_TYPE (t1), TREE_TYPE (t2)));
482       break;
483
484     case FUNCTION_TYPE:
485       val = function_types_compatible_p (t1, t2);
486       break;
487
488     case ARRAY_TYPE:
489       {
490         tree d1 = TYPE_DOMAIN (t1);
491         tree d2 = TYPE_DOMAIN (t2);
492         val = 1;
493
494         /* Target types must match incl. qualifiers.  */
495         if (TREE_TYPE (t1) != TREE_TYPE (t2)
496             && 0 == (val = comptypes (TREE_TYPE (t1), TREE_TYPE (t2))))
497           return 0;
498
499         /* Sizes must match unless one is missing or variable.  */
500         if (d1 == 0 || d2 == 0 || d1 == d2
501             || TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST
502             || TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
503             || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST
504             || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST)
505           break;
506
507         if (! ((TREE_INT_CST_LOW (TYPE_MIN_VALUE (d1))
508                   == TREE_INT_CST_LOW (TYPE_MIN_VALUE (d2)))
509                  && (TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d1))
510                      == TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d2)))
511                  && (TREE_INT_CST_LOW (TYPE_MAX_VALUE (d1))
512                      == TREE_INT_CST_LOW (TYPE_MAX_VALUE (d2)))
513                  && (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d1))
514                      == TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d2)))))
515            val = 0;
516         break;
517       }
518
519     case RECORD_TYPE:
520       if (maybe_objc_comptypes (t1, t2, 0) == 1)
521         val = 1;
522       break;
523
524     default:
525       break;
526     }
527   return attrval == 2 && val == 1 ? 2 : val;
528 }
529
530 /* Return 1 if TTL and TTR are pointers to types that are equivalent,
531    ignoring their qualifiers.  */
532
533 static int
534 comp_target_types (ttl, ttr)
535      tree ttl, ttr;
536 {
537   int val;
538
539   /* Give maybe_objc_comptypes a crack at letting these types through.  */
540   if ((val = maybe_objc_comptypes (ttl, ttr, 1)) >= 0)
541     return val;
542
543   val = comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (ttl)),
544                    TYPE_MAIN_VARIANT (TREE_TYPE (ttr)));
545
546   if (val == 2 && pedantic)
547     pedwarn ("types are not quite compatible");
548   return val;
549 }
550 \f
551 /* Subroutines of `comptypes'.  */
552
553 /* Return 1 if two function types F1 and F2 are compatible.
554    If either type specifies no argument types,
555    the other must specify a fixed number of self-promoting arg types.
556    Otherwise, if one type specifies only the number of arguments, 
557    the other must specify that number of self-promoting arg types.
558    Otherwise, the argument types must match.  */
559
560 static int
561 function_types_compatible_p (f1, f2)
562      tree f1, f2;
563 {
564   tree args1, args2;
565   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
566   int val = 1;
567   int val1;
568
569   if (!(TREE_TYPE (f1) == TREE_TYPE (f2)
570         || (val = comptypes (TREE_TYPE (f1), TREE_TYPE (f2)))))
571     return 0;
572
573   args1 = TYPE_ARG_TYPES (f1);
574   args2 = TYPE_ARG_TYPES (f2);
575
576   /* An unspecified parmlist matches any specified parmlist
577      whose argument types don't need default promotions.  */
578
579   if (args1 == 0)
580     {
581       if (!self_promoting_args_p (args2))
582         return 0;
583       /* If one of these types comes from a non-prototype fn definition,
584          compare that with the other type's arglist.
585          If they don't match, ask for a warning (but no error).  */
586       if (TYPE_ACTUAL_ARG_TYPES (f1)
587           && 1 != type_lists_compatible_p (args2, TYPE_ACTUAL_ARG_TYPES (f1)))
588         val = 2;
589       return val;
590     }
591   if (args2 == 0)
592     {
593       if (!self_promoting_args_p (args1))
594         return 0;
595       if (TYPE_ACTUAL_ARG_TYPES (f2)
596           && 1 != type_lists_compatible_p (args1, TYPE_ACTUAL_ARG_TYPES (f2)))
597         val = 2;
598       return val;
599     }
600
601   /* Both types have argument lists: compare them and propagate results.  */
602   val1 = type_lists_compatible_p (args1, args2);
603   return val1 != 1 ? val1 : val;
604 }
605
606 /* Check two lists of types for compatibility,
607    returning 0 for incompatible, 1 for compatible,
608    or 2 for compatible with warning.  */
609
610 static int
611 type_lists_compatible_p (args1, args2)
612      tree args1, args2;
613 {
614   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
615   int val = 1;
616   int newval = 0;
617
618   while (1)
619     {
620       if (args1 == 0 && args2 == 0)
621         return val;
622       /* If one list is shorter than the other,
623          they fail to match.  */
624       if (args1 == 0 || args2 == 0)
625         return 0;
626       /* A null pointer instead of a type
627          means there is supposed to be an argument
628          but nothing is specified about what type it has.
629          So match anything that self-promotes.  */
630       if (TREE_VALUE (args1) == 0)
631         {
632           if (simple_type_promotes_to (TREE_VALUE (args2)) != NULL_TREE)
633             return 0;
634         }
635       else if (TREE_VALUE (args2) == 0)
636         {
637           if (simple_type_promotes_to (TREE_VALUE (args1)) != NULL_TREE)
638             return 0;
639         }
640       else if (! (newval = comptypes (TREE_VALUE (args1), TREE_VALUE (args2))))
641         {
642           /* Allow  wait (union {union wait *u; int *i} *)
643              and  wait (union wait *)  to be compatible.  */
644           if (TREE_CODE (TREE_VALUE (args1)) == UNION_TYPE
645               && (TYPE_NAME (TREE_VALUE (args1)) == 0
646                   || TYPE_TRANSPARENT_UNION (TREE_VALUE (args1)))
647               && TREE_CODE (TYPE_SIZE (TREE_VALUE (args1))) == INTEGER_CST
648               && tree_int_cst_equal (TYPE_SIZE (TREE_VALUE (args1)),
649                                      TYPE_SIZE (TREE_VALUE (args2))))
650             {
651               tree memb;
652               for (memb = TYPE_FIELDS (TREE_VALUE (args1));
653                    memb; memb = TREE_CHAIN (memb))
654                 if (comptypes (TREE_TYPE (memb), TREE_VALUE (args2)))
655                   break;
656               if (memb == 0)
657                 return 0;
658             }
659           else if (TREE_CODE (TREE_VALUE (args2)) == UNION_TYPE
660                    && (TYPE_NAME (TREE_VALUE (args2)) == 0
661                        || TYPE_TRANSPARENT_UNION (TREE_VALUE (args2)))
662                    && TREE_CODE (TYPE_SIZE (TREE_VALUE (args2))) == INTEGER_CST
663                    && tree_int_cst_equal (TYPE_SIZE (TREE_VALUE (args2)),
664                                           TYPE_SIZE (TREE_VALUE (args1))))
665             {
666               tree memb;
667               for (memb = TYPE_FIELDS (TREE_VALUE (args2));
668                    memb; memb = TREE_CHAIN (memb))
669                 if (comptypes (TREE_TYPE (memb), TREE_VALUE (args1)))
670                   break;
671               if (memb == 0)
672                 return 0;
673             }
674           else
675             return 0;
676         }
677
678       /* comptypes said ok, but record if it said to warn.  */
679       if (newval > val)
680         val = newval;
681
682       args1 = TREE_CHAIN (args1);
683       args2 = TREE_CHAIN (args2);
684     }
685 }
686 \f
687 /* Compute the value of the `sizeof' operator.  */
688
689 tree
690 c_sizeof (type)
691      tree type;
692 {
693   enum tree_code code = TREE_CODE (type);
694   tree t;
695
696   if (code == FUNCTION_TYPE)
697     {
698       if (pedantic || warn_pointer_arith)
699         pedwarn ("sizeof applied to a function type");
700       return size_int (1);
701     }
702   if (code == VOID_TYPE)
703     {
704       if (pedantic || warn_pointer_arith)
705         pedwarn ("sizeof applied to a void type");
706       return size_int (1);
707     }
708   if (code == ERROR_MARK)
709     return size_int (1);
710   if (TYPE_SIZE (type) == 0)
711     {
712       error ("sizeof applied to an incomplete type");
713       return size_int (0);
714     }
715
716   /* Convert in case a char is more than one unit.  */
717   t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type), 
718                   size_int (TYPE_PRECISION (char_type_node)));
719   t = convert (sizetype, t);
720   /* size_binop does not put the constant in range, so do it now.  */
721   if (TREE_CODE (t) == INTEGER_CST && force_fit_type (t, 0))
722     TREE_CONSTANT_OVERFLOW (t) = TREE_OVERFLOW (t) = 1;
723   return t;
724 }
725
726 tree
727 c_sizeof_nowarn (type)
728      tree type;
729 {
730   enum tree_code code = TREE_CODE (type);
731   tree t;
732
733   if (code == FUNCTION_TYPE
734       || code == VOID_TYPE
735       || code == ERROR_MARK)
736     return size_int (1);
737   if (TYPE_SIZE (type) == 0)
738     return size_int (0);
739
740   /* Convert in case a char is more than one unit.  */
741   t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type), 
742                   size_int (TYPE_PRECISION (char_type_node)));
743   t = convert (sizetype, t);
744   force_fit_type (t, 0);
745   return t;
746 }
747
748 /* Compute the size to increment a pointer by.  */
749
750 tree
751 c_size_in_bytes (type)
752      tree type;
753 {
754   enum tree_code code = TREE_CODE (type);
755   tree t;
756
757   if (code == FUNCTION_TYPE)
758     return size_int (1);
759   if (code == VOID_TYPE)
760     return size_int (1);
761   if (code == ERROR_MARK)
762     return size_int (1);
763   if (TYPE_SIZE (type) == 0)
764     {
765       error ("arithmetic on pointer to an incomplete type");
766       return size_int (1);
767     }
768
769   /* Convert in case a char is more than one unit.  */
770   t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type), 
771                      size_int (BITS_PER_UNIT));
772   t = convert (sizetype, t);
773   force_fit_type (t, 0);
774   return t;
775 }
776
777 /* Implement the __alignof keyword: Return the minimum required
778    alignment of TYPE, measured in bytes.  */
779
780 tree
781 c_alignof (type)
782      tree type;
783 {
784   enum tree_code code = TREE_CODE (type);
785
786   if (code == FUNCTION_TYPE)
787     return size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
788
789   if (code == VOID_TYPE || code == ERROR_MARK)
790     return size_int (1);
791
792   return size_int (TYPE_ALIGN (type) / BITS_PER_UNIT);
793 }
794 \f
795 /* Implement the __alignof keyword: Return the minimum required
796    alignment of EXPR, measured in bytes.  For VAR_DECL's and
797    FIELD_DECL's return DECL_ALIGN (which can be set from an
798    "aligned" __attribute__ specification).  */
799
800 tree
801 c_alignof_expr (expr)
802      tree expr;
803 {
804   if (TREE_CODE (expr) == VAR_DECL)
805     return size_int (DECL_ALIGN (expr) / BITS_PER_UNIT);
806  
807   if (TREE_CODE (expr) == COMPONENT_REF
808       && DECL_C_BIT_FIELD (TREE_OPERAND (expr, 1)))
809     {
810       error ("`__alignof' applied to a bit-field");
811       return size_int (1);
812     }
813   else if (TREE_CODE (expr) == COMPONENT_REF
814       && TREE_CODE (TREE_OPERAND (expr, 1)) == FIELD_DECL)
815     return size_int (DECL_ALIGN (TREE_OPERAND (expr, 1)) / BITS_PER_UNIT);
816  
817   if (TREE_CODE (expr) == INDIRECT_REF)
818     {
819       tree t = TREE_OPERAND (expr, 0);
820       tree best = t;
821       int bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
822  
823       while (TREE_CODE (t) == NOP_EXPR
824               && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE)
825         {
826           int thisalign;
827
828           t = TREE_OPERAND (t, 0);
829           thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
830           if (thisalign > bestalign)
831             best = t, bestalign = thisalign;
832         }
833       return c_alignof (TREE_TYPE (TREE_TYPE (best)));
834     }
835   else
836     return c_alignof (TREE_TYPE (expr));
837 }
838
839 /* Return either DECL or its known constant value (if it has one).  */
840
841 static tree
842 decl_constant_value (decl)
843      tree decl;
844 {
845   if (/* Don't change a variable array bound or initial value to a constant
846          in a place where a variable is invalid.  */
847       current_function_decl != 0
848       && ! pedantic
849       && ! TREE_THIS_VOLATILE (decl)
850       && TREE_READONLY (decl) && ! ITERATOR_P (decl)
851       && DECL_INITIAL (decl) != 0
852       && TREE_CODE (DECL_INITIAL (decl)) != ERROR_MARK
853       /* This is invalid if initial value is not constant.
854          If it has either a function call, a memory reference,
855          or a variable, then re-evaluating it could give different results.  */
856       && TREE_CONSTANT (DECL_INITIAL (decl))
857       /* Check for cases where this is sub-optimal, even though valid.  */
858       && TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR
859       && DECL_MODE (decl) != BLKmode)
860     return DECL_INITIAL (decl);
861   return decl;
862 }
863
864 /* Perform default promotions for C data used in expressions.
865    Arrays and functions are converted to pointers;
866    enumeral types or short or char, to int.
867    In addition, manifest constants symbols are replaced by their values.  */
868
869 tree
870 default_conversion (exp)
871      tree exp;
872 {
873   register tree type = TREE_TYPE (exp);
874   register enum tree_code code = TREE_CODE (type);
875
876   /* Constants can be used directly unless they're not loadable.  */
877   if (TREE_CODE (exp) == CONST_DECL)
878     exp = DECL_INITIAL (exp);
879
880   /* Replace a nonvolatile const static variable with its value unless
881      it is an array, in which case we must be sure that taking the
882      address of the array produces consistent results.  */
883   else if (optimize && TREE_CODE (exp) == VAR_DECL && code != ARRAY_TYPE)
884     {
885       exp = decl_constant_value (exp);
886       type = TREE_TYPE (exp);
887     }
888
889   /* Strip NON_LVALUE_EXPRs and no-op conversions, since we aren't using as
890      an lvalue.  */
891   /* Do not use STRIP_NOPS here!  It will remove conversions from pointer
892      to integer and cause infinite recursion.  */
893   while (TREE_CODE (exp) == NON_LVALUE_EXPR
894          || (TREE_CODE (exp) == NOP_EXPR
895              && TREE_TYPE (TREE_OPERAND (exp, 0)) == TREE_TYPE (exp)))
896     exp = TREE_OPERAND (exp, 0);
897
898   /* Normally convert enums to int,
899      but convert wide enums to something wider.  */
900   if (code == ENUMERAL_TYPE)
901     {
902       type = type_for_size (MAX (TYPE_PRECISION (type),
903                                  TYPE_PRECISION (integer_type_node)),
904                             ((flag_traditional
905                               || (TYPE_PRECISION (type)
906                                   >= TYPE_PRECISION (integer_type_node)))
907                              && TREE_UNSIGNED (type)));
908       return convert (type, exp);
909     }
910
911   if (TREE_CODE (exp) == COMPONENT_REF
912       && DECL_C_BIT_FIELD (TREE_OPERAND (exp, 1)))
913     {
914       tree width = DECL_SIZE (TREE_OPERAND (exp, 1));
915       HOST_WIDE_INT low = TREE_INT_CST_LOW (width);
916
917       /* If it's thinner than an int, promote it like a
918          C_PROMOTING_INTEGER_TYPE_P, otherwise leave it alone.  */
919
920       if (low < TYPE_PRECISION (integer_type_node))
921         {
922           if (flag_traditional && TREE_UNSIGNED (type))
923             return convert (unsigned_type_node, exp);
924           else
925             return convert (integer_type_node, exp);
926         }
927     }
928
929   if (C_PROMOTING_INTEGER_TYPE_P (type))
930     {
931       /* Traditionally, unsignedness is preserved in default promotions.
932          Also preserve unsignedness if not really getting any wider.  */
933       if (TREE_UNSIGNED (type)
934           && (flag_traditional
935               || TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)))
936         return convert (unsigned_type_node, exp);
937       return convert (integer_type_node, exp);
938     }
939   if (flag_traditional && !flag_allow_single_precision
940       && TYPE_MAIN_VARIANT (type) == float_type_node)
941     return convert (double_type_node, exp);
942   if (code == VOID_TYPE)
943     {
944       error ("void value not ignored as it ought to be");
945       return error_mark_node;
946     }
947   if (code == FUNCTION_TYPE)
948     {
949       return build_unary_op (ADDR_EXPR, exp, 0);
950     }
951   if (code == ARRAY_TYPE)
952     {
953       register tree adr;
954       tree restype = TREE_TYPE (type);
955       tree ptrtype;
956       int constp = 0;
957       int volatilep = 0;
958
959       if (TREE_CODE_CLASS (TREE_CODE (exp)) == 'r'
960           || TREE_CODE_CLASS (TREE_CODE (exp)) == 'd')
961         {
962           constp = TREE_READONLY (exp);
963           volatilep = TREE_THIS_VOLATILE (exp);
964         }
965
966       if (TYPE_QUALS (type) || constp || volatilep)
967         restype 
968           = c_build_qualified_type (restype,
969                                     TYPE_QUALS (type) 
970                                     | (constp * TYPE_QUAL_CONST)
971                                     | (volatilep * TYPE_QUAL_VOLATILE));
972
973       if (TREE_CODE (exp) == INDIRECT_REF)
974         return convert (TYPE_POINTER_TO (restype),
975                         TREE_OPERAND (exp, 0));
976
977       if (TREE_CODE (exp) == COMPOUND_EXPR)
978         {
979           tree op1 = default_conversion (TREE_OPERAND (exp, 1));
980           return build (COMPOUND_EXPR, TREE_TYPE (op1),
981                         TREE_OPERAND (exp, 0), op1);
982         }
983
984       if (! lvalue_p (exp)
985           && ! (TREE_CODE (exp) == CONSTRUCTOR && TREE_STATIC (exp)))
986         {
987           error ("invalid use of non-lvalue array");
988           return error_mark_node;
989         }
990
991       ptrtype = build_pointer_type (restype);
992
993       if (TREE_CODE (exp) == VAR_DECL)
994         {
995           /* ??? This is not really quite correct
996              in that the type of the operand of ADDR_EXPR
997              is not the target type of the type of the ADDR_EXPR itself.
998              Question is, can this lossage be avoided?  */
999           adr = build1 (ADDR_EXPR, ptrtype, exp);
1000           if (mark_addressable (exp) == 0)
1001             return error_mark_node;
1002           TREE_CONSTANT (adr) = staticp (exp);
1003           TREE_SIDE_EFFECTS (adr) = 0;   /* Default would be, same as EXP.  */
1004           return adr;
1005         }
1006       /* This way is better for a COMPONENT_REF since it can
1007          simplify the offset for a component.  */
1008       adr = build_unary_op (ADDR_EXPR, exp, 1);
1009       return convert (ptrtype, adr);
1010     }
1011   return exp;
1012 }
1013 \f
1014 /* Look up component name in the structure type definition.
1015
1016    If this component name is found indirectly within an anonymous union,
1017    store in *INDIRECT the component which directly contains
1018    that anonymous union.  Otherwise, set *INDIRECT to 0.  */
1019      
1020 static tree
1021 lookup_field (type, component, indirect)
1022      tree type, component;
1023      tree *indirect;
1024 {
1025   tree field;
1026
1027   /* If TYPE_LANG_SPECIFIC is set, then it is a sorted array of pointers
1028      to the field elements.  Use a binary search on this array to quickly
1029      find the element.  Otherwise, do a linear search.  TYPE_LANG_SPECIFIC
1030      will always be set for structures which have many elements.  */
1031
1032   if (TYPE_LANG_SPECIFIC (type))
1033     {
1034       int bot, top, half;
1035       tree *field_array = &TYPE_LANG_SPECIFIC (type)->elts[0];
1036
1037       field = TYPE_FIELDS (type);
1038       bot = 0;
1039       top = TYPE_LANG_SPECIFIC (type)->len;
1040       while (top - bot > 1)
1041         {
1042           half = (top - bot + 1) >> 1;
1043           field = field_array[bot+half];
1044
1045           if (DECL_NAME (field) == NULL_TREE)
1046             {
1047               /* Step through all anon unions in linear fashion.  */
1048               while (DECL_NAME (field_array[bot]) == NULL_TREE)
1049                 {
1050                   tree anon = 0, junk;
1051
1052                   field = field_array[bot++];
1053                   if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE
1054                       || TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)
1055                     anon = lookup_field (TREE_TYPE (field), component, &junk);
1056
1057                   if (anon != NULL_TREE)
1058                     {
1059                       *indirect = field;
1060                       return anon;
1061                     }
1062                 }
1063
1064               /* Entire record is only anon unions.  */
1065               if (bot > top)
1066                 return NULL_TREE;
1067
1068               /* Restart the binary search, with new lower bound.  */
1069               continue;
1070             }
1071
1072           if (DECL_NAME (field) == component)
1073             break;
1074           if (DECL_NAME (field) < component)
1075             bot += half;
1076           else
1077             top = bot + half;
1078         }
1079
1080       if (DECL_NAME (field_array[bot]) == component)
1081         field = field_array[bot];
1082       else if (DECL_NAME (field) != component)
1083         field = 0;
1084     }
1085   else
1086     {
1087       for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
1088         {
1089           if (DECL_NAME (field) == NULL_TREE)
1090             {
1091               tree junk;
1092               tree anon = 0;
1093
1094               if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE
1095                   || TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)
1096                 anon = lookup_field (TREE_TYPE (field), component, &junk);
1097
1098               if (anon != NULL_TREE)
1099                 {
1100                   *indirect = field;
1101                   return anon;
1102                 }
1103             }
1104
1105           if (DECL_NAME (field) == component)
1106             break;
1107         }
1108     }
1109
1110   *indirect = NULL_TREE;
1111   return field;
1112 }
1113
1114 /* Make an expression to refer to the COMPONENT field of
1115    structure or union value DATUM.  COMPONENT is an IDENTIFIER_NODE.  */
1116
1117 tree
1118 build_component_ref (datum, component)
1119      tree datum, component;
1120 {
1121   register tree type = TREE_TYPE (datum);
1122   register enum tree_code code = TREE_CODE (type);
1123   register tree field = NULL;
1124   register tree ref;
1125
1126   /* If DATUM is a COMPOUND_EXPR or COND_EXPR, move our reference inside it
1127      unless we are not to support things not strictly ANSI.  */
1128   switch (TREE_CODE (datum))
1129     {
1130     case COMPOUND_EXPR:
1131       {
1132         tree value = build_component_ref (TREE_OPERAND (datum, 1), component);
1133         return build (COMPOUND_EXPR, TREE_TYPE (value),
1134                       TREE_OPERAND (datum, 0), value);
1135       }
1136     case COND_EXPR:
1137       return build_conditional_expr
1138         (TREE_OPERAND (datum, 0),
1139          build_component_ref (TREE_OPERAND (datum, 1), component),
1140          build_component_ref (TREE_OPERAND (datum, 2), component));
1141
1142     default:
1143       break;
1144     }
1145
1146   /* See if there is a field or component with name COMPONENT.  */
1147
1148   if (code == RECORD_TYPE || code == UNION_TYPE)
1149     {
1150       tree indirect = 0;
1151
1152       if (TYPE_SIZE (type) == 0)
1153         {
1154           incomplete_type_error (NULL_TREE, type);
1155           return error_mark_node;
1156         }
1157
1158       field = lookup_field (type, component, &indirect);
1159
1160       if (!field)
1161         {
1162           error ("%s has no member named `%s'",
1163                  code == RECORD_TYPE ? "structure" : "union",
1164                  IDENTIFIER_POINTER (component));
1165           return error_mark_node;
1166         }
1167       if (TREE_TYPE (field) == error_mark_node)
1168         return error_mark_node;
1169
1170       /* If FIELD was found buried within an anonymous union,
1171          make one COMPONENT_REF to get that anonymous union,
1172          then fall thru to make a second COMPONENT_REF to get FIELD.  */
1173       if (indirect != 0)
1174         {
1175           ref = build (COMPONENT_REF, TREE_TYPE (indirect), datum, indirect);
1176           if (TREE_READONLY (datum) || TREE_READONLY (indirect))
1177             TREE_READONLY (ref) = 1;
1178           if (TREE_THIS_VOLATILE (datum) || TREE_THIS_VOLATILE (indirect))
1179             TREE_THIS_VOLATILE (ref) = 1;
1180           datum = ref;
1181         }
1182
1183       ref = build (COMPONENT_REF, TREE_TYPE (field), datum, field);
1184
1185       if (TREE_READONLY (datum) || TREE_READONLY (field))
1186         TREE_READONLY (ref) = 1;
1187       if (TREE_THIS_VOLATILE (datum) || TREE_THIS_VOLATILE (field))
1188         TREE_THIS_VOLATILE (ref) = 1;
1189
1190       return ref;
1191     }
1192   else if (code != ERROR_MARK)
1193     error ("request for member `%s' in something not a structure or union",
1194             IDENTIFIER_POINTER (component));
1195
1196   return error_mark_node;
1197 }
1198 \f
1199 /* Given an expression PTR for a pointer, return an expression
1200    for the value pointed to.
1201    ERRORSTRING is the name of the operator to appear in error messages.  */
1202
1203 tree
1204 build_indirect_ref (ptr, errorstring)
1205      tree ptr;
1206      const char *errorstring;
1207 {
1208   register tree pointer = default_conversion (ptr);
1209   register tree type = TREE_TYPE (pointer);
1210
1211   if (TREE_CODE (type) == POINTER_TYPE)
1212     {
1213       if (TREE_CODE (pointer) == ADDR_EXPR
1214           && !flag_volatile
1215           && (TREE_TYPE (TREE_OPERAND (pointer, 0))
1216               == TREE_TYPE (type)))
1217         return TREE_OPERAND (pointer, 0);
1218       else
1219         {
1220           tree t = TREE_TYPE (type);
1221           register tree ref = build1 (INDIRECT_REF,
1222                                       TYPE_MAIN_VARIANT (t), pointer);
1223
1224           if (TYPE_SIZE (t) == 0 && TREE_CODE (t) != ARRAY_TYPE)
1225             {
1226               error ("dereferencing pointer to incomplete type");
1227               return error_mark_node;
1228             }
1229           if (TREE_CODE (t) == VOID_TYPE && skip_evaluation == 0)
1230             warning ("dereferencing `void *' pointer");
1231
1232           /* We *must* set TREE_READONLY when dereferencing a pointer to const,
1233              so that we get the proper error message if the result is used
1234              to assign to.  Also, &* is supposed to be a no-op.
1235              And ANSI C seems to specify that the type of the result
1236              should be the const type.  */
1237           /* A de-reference of a pointer to const is not a const.  It is valid
1238              to change it via some other pointer.  */
1239           TREE_READONLY (ref) = TYPE_READONLY (t);
1240           TREE_SIDE_EFFECTS (ref)
1241             = TYPE_VOLATILE (t) || TREE_SIDE_EFFECTS (pointer) || flag_volatile;
1242           TREE_THIS_VOLATILE (ref) = TYPE_VOLATILE (t);
1243           return ref;
1244         }
1245     }
1246   else if (TREE_CODE (pointer) != ERROR_MARK)
1247     error ("invalid type argument of `%s'", errorstring);
1248   return error_mark_node;
1249 }
1250
1251 /* This handles expressions of the form "a[i]", which denotes
1252    an array reference.
1253
1254    This is logically equivalent in C to *(a+i), but we may do it differently.
1255    If A is a variable or a member, we generate a primitive ARRAY_REF.
1256    This avoids forcing the array out of registers, and can work on
1257    arrays that are not lvalues (for example, members of structures returned
1258    by functions).  */
1259
1260 tree
1261 build_array_ref (array, index)
1262      tree array, index;
1263 {
1264   if (index == 0)
1265     {
1266       error ("subscript missing in array reference");
1267       return error_mark_node;
1268     }
1269
1270   if (TREE_TYPE (array) == error_mark_node
1271       || TREE_TYPE (index) == error_mark_node)
1272     return error_mark_node;
1273
1274   if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE
1275       && TREE_CODE (array) != INDIRECT_REF)
1276     {
1277       tree rval, type;
1278
1279       /* Subscripting with type char is likely to lose
1280          on a machine where chars are signed.
1281          So warn on any machine, but optionally.
1282          Don't warn for unsigned char since that type is safe.
1283          Don't warn for signed char because anyone who uses that
1284          must have done so deliberately.  */
1285       if (warn_char_subscripts
1286           && TYPE_MAIN_VARIANT (TREE_TYPE (index)) == char_type_node)
1287         warning ("array subscript has type `char'");
1288
1289       /* Apply default promotions *after* noticing character types.  */
1290       index = default_conversion (index);
1291
1292       /* Require integer *after* promotion, for sake of enums.  */
1293       if (TREE_CODE (TREE_TYPE (index)) != INTEGER_TYPE)
1294         {
1295           error ("array subscript is not an integer");
1296           return error_mark_node;
1297         }
1298
1299       /* An array that is indexed by a non-constant
1300          cannot be stored in a register; we must be able to do
1301          address arithmetic on its address.
1302          Likewise an array of elements of variable size.  */
1303       if (TREE_CODE (index) != INTEGER_CST
1304           || (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array))) != 0
1305               && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array)))) != INTEGER_CST))
1306         {
1307           if (mark_addressable (array) == 0)
1308             return error_mark_node;
1309         }
1310       /* An array that is indexed by a constant value which is not within
1311          the array bounds cannot be stored in a register either; because we
1312          would get a crash in store_bit_field/extract_bit_field when trying
1313          to access a non-existent part of the register.  */
1314       if (TREE_CODE (index) == INTEGER_CST
1315           && TYPE_VALUES (TREE_TYPE (array))
1316           && ! int_fits_type_p (index, TYPE_VALUES (TREE_TYPE (array))))
1317         {
1318           if (mark_addressable (array) == 0)
1319             return error_mark_node;
1320         }
1321
1322       if (pedantic && !lvalue_p (array))
1323         {
1324           if (DECL_REGISTER (array))
1325             pedwarn ("ANSI C forbids subscripting `register' array");
1326           else
1327             pedwarn ("ANSI C forbids subscripting non-lvalue array");
1328         }
1329
1330       if (pedantic)
1331         {
1332           tree foo = array;
1333           while (TREE_CODE (foo) == COMPONENT_REF)
1334             foo = TREE_OPERAND (foo, 0);
1335           if (TREE_CODE (foo) == VAR_DECL && DECL_REGISTER (foo))
1336             pedwarn ("ANSI C forbids subscripting non-lvalue array");
1337         }
1338
1339       type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (array)));
1340       rval = build (ARRAY_REF, type, array, index);
1341       /* Array ref is const/volatile if the array elements are
1342          or if the array is.  */
1343       TREE_READONLY (rval)
1344         |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array)))
1345             | TREE_READONLY (array));
1346       TREE_SIDE_EFFECTS (rval)
1347         |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
1348             | TREE_SIDE_EFFECTS (array));
1349       TREE_THIS_VOLATILE (rval)
1350         |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
1351             /* This was added by rms on 16 Nov 91.
1352                It fixes  vol struct foo *a;  a->elts[1] 
1353                in an inline function.
1354                Hope it doesn't break something else.  */
1355             | TREE_THIS_VOLATILE (array));
1356       return require_complete_type (fold (rval));
1357     }
1358
1359   {
1360     tree ar = default_conversion (array);
1361     tree ind = default_conversion (index);
1362
1363     /* Do the same warning check as above, but only on the part that's
1364        syntactically the index and only if it is also semantically
1365        the index.  */
1366     if (warn_char_subscripts
1367         && TREE_CODE (TREE_TYPE (index)) == INTEGER_TYPE
1368         && TYPE_MAIN_VARIANT (TREE_TYPE (index)) == char_type_node)
1369       warning ("subscript has type `char'");
1370
1371     /* Put the integer in IND to simplify error checking.  */
1372     if (TREE_CODE (TREE_TYPE (ar)) == INTEGER_TYPE)
1373       {
1374         tree temp = ar;
1375         ar = ind;
1376         ind = temp;
1377       }
1378
1379     if (ar == error_mark_node)
1380       return ar;
1381
1382     if (TREE_CODE (TREE_TYPE (ar)) != POINTER_TYPE
1383         || TREE_CODE (TREE_TYPE (TREE_TYPE (ar))) == FUNCTION_TYPE)
1384       {
1385         error ("subscripted value is neither array nor pointer");
1386         return error_mark_node;
1387       }
1388     if (TREE_CODE (TREE_TYPE (ind)) != INTEGER_TYPE)
1389       {
1390         error ("array subscript is not an integer");
1391         return error_mark_node;
1392       }
1393
1394     return build_indirect_ref (build_binary_op (PLUS_EXPR, ar, ind, 0),
1395                                "array indexing");
1396   }
1397 }
1398 \f
1399 /* Build a function call to function FUNCTION with parameters PARAMS.
1400    PARAMS is a list--a chain of TREE_LIST nodes--in which the
1401    TREE_VALUE of each node is a parameter-expression.
1402    FUNCTION's data type may be a function type or a pointer-to-function.  */
1403
1404 tree
1405 build_function_call (function, params)
1406      tree function, params;
1407 {
1408   register tree fntype, fundecl = 0;
1409   register tree coerced_params;
1410   tree name = NULL_TREE, assembler_name = NULL_TREE, result;
1411
1412   /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
1413   STRIP_TYPE_NOPS (function);
1414
1415   /* Convert anything with function type to a pointer-to-function.  */
1416   if (TREE_CODE (function) == FUNCTION_DECL)
1417     {
1418       name = DECL_NAME (function);
1419       assembler_name = DECL_ASSEMBLER_NAME (function);
1420
1421       /* Differs from default_conversion by not setting TREE_ADDRESSABLE
1422          (because calling an inline function does not mean the function
1423          needs to be separately compiled).  */
1424       fntype = build_type_variant (TREE_TYPE (function),
1425                                    TREE_READONLY (function),
1426                                    TREE_THIS_VOLATILE (function));
1427       fundecl = function;
1428       function = build1 (ADDR_EXPR, build_pointer_type (fntype), function);
1429     }
1430   else
1431     function = default_conversion (function);
1432
1433   fntype = TREE_TYPE (function);
1434
1435   if (TREE_CODE (fntype) == ERROR_MARK)
1436     return error_mark_node;
1437
1438   if (!(TREE_CODE (fntype) == POINTER_TYPE
1439         && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE))
1440     {
1441       error ("called object is not a function");
1442       return error_mark_node;
1443     }
1444
1445   /* fntype now gets the type of function pointed to.  */
1446   fntype = TREE_TYPE (fntype);
1447
1448   /* Convert the parameters to the types declared in the
1449      function prototype, or apply default promotions.  */
1450
1451   coerced_params
1452     = convert_arguments (TYPE_ARG_TYPES (fntype), params, name, fundecl);
1453
1454   /* Check for errors in format strings.  */
1455
1456   if (warn_format && (name || assembler_name))
1457     check_function_format (name, assembler_name, coerced_params);
1458
1459   /* Recognize certain built-in functions so we can make tree-codes
1460      other than CALL_EXPR.  We do this when it enables fold-const.c
1461      to do something useful.  */
1462
1463   if (TREE_CODE (function) == ADDR_EXPR
1464       && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL
1465       && DECL_BUILT_IN (TREE_OPERAND (function, 0)))
1466     {
1467       result = expand_tree_builtin (TREE_OPERAND (function, 0),
1468                                     params, coerced_params);
1469       if (result)
1470         return result;
1471     }
1472
1473   result = build (CALL_EXPR, TREE_TYPE (fntype),
1474                   function, coerced_params, NULL_TREE);
1475
1476   TREE_SIDE_EFFECTS (result) = 1;
1477   if (TREE_TYPE (result) == void_type_node)
1478     return result;
1479   return require_complete_type (result);
1480 }
1481 \f
1482 /* Convert the argument expressions in the list VALUES
1483    to the types in the list TYPELIST.  The result is a list of converted
1484    argument expressions.
1485
1486    If TYPELIST is exhausted, or when an element has NULL as its type,
1487    perform the default conversions.
1488
1489    PARMLIST is the chain of parm decls for the function being called.
1490    It may be 0, if that info is not available.
1491    It is used only for generating error messages.
1492
1493    NAME is an IDENTIFIER_NODE or 0.  It is used only for error messages.
1494
1495    This is also where warnings about wrong number of args are generated.
1496
1497    Both VALUES and the returned value are chains of TREE_LIST nodes
1498    with the elements of the list in the TREE_VALUE slots of those nodes.  */
1499
1500 static tree
1501 convert_arguments (typelist, values, name, fundecl)
1502      tree typelist, values, name, fundecl;
1503 {
1504   register tree typetail, valtail;
1505   register tree result = NULL;
1506   int parmnum;
1507
1508   /* Scan the given expressions and types, producing individual
1509      converted arguments and pushing them on RESULT in reverse order.  */
1510
1511   for (valtail = values, typetail = typelist, parmnum = 0;
1512        valtail;
1513        valtail = TREE_CHAIN (valtail), parmnum++)
1514     {
1515       register tree type = typetail ? TREE_VALUE (typetail) : 0;
1516       register tree val = TREE_VALUE (valtail);
1517
1518       if (type == void_type_node)
1519         {
1520           if (name)
1521             error ("too many arguments to function `%s'",
1522                    IDENTIFIER_POINTER (name));
1523           else
1524             error ("too many arguments to function");
1525           break;
1526         }
1527
1528       /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
1529       /* Do not use STRIP_NOPS here!  We do not want an enumerator with value 0
1530          to convert automatically to a pointer.  */
1531       if (TREE_CODE (val) == NON_LVALUE_EXPR)
1532         val = TREE_OPERAND (val, 0);
1533
1534       if (TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE
1535           || TREE_CODE (TREE_TYPE (val)) == FUNCTION_TYPE)
1536         val = default_conversion (val);
1537
1538       val = require_complete_type (val);
1539
1540       if (type != 0)
1541         {
1542           /* Formal parm type is specified by a function prototype.  */
1543           tree parmval;
1544
1545           if (TYPE_SIZE (type) == 0)
1546             {
1547               error ("type of formal parameter %d is incomplete", parmnum + 1);
1548               parmval = val;
1549             }
1550           else
1551             {
1552               /* Optionally warn about conversions that
1553                  differ from the default conversions.  */
1554               if (warn_conversion)
1555                 {
1556                   int formal_prec = TYPE_PRECISION (type);
1557
1558                   if (INTEGRAL_TYPE_P (type)
1559                       && TREE_CODE (TREE_TYPE (val)) == REAL_TYPE)
1560                     warn_for_assignment ("%s as integer rather than floating due to prototype", (char *) 0, name, parmnum + 1);
1561                   else if (TREE_CODE (type) == COMPLEX_TYPE
1562                            && TREE_CODE (TREE_TYPE (val)) == REAL_TYPE)
1563                     warn_for_assignment ("%s as complex rather than floating due to prototype", (char *) 0, name, parmnum + 1);
1564                   else if (TREE_CODE (type) == REAL_TYPE
1565                            && INTEGRAL_TYPE_P (TREE_TYPE (val)))
1566                     warn_for_assignment ("%s as floating rather than integer due to prototype", (char *) 0, name, parmnum + 1);
1567                   else if (TREE_CODE (type) == REAL_TYPE
1568                            && TREE_CODE (TREE_TYPE (val)) == COMPLEX_TYPE)
1569                     warn_for_assignment ("%s as floating rather than complex due to prototype", (char *) 0, name, parmnum + 1);
1570                   /* ??? At some point, messages should be written about
1571                      conversions between complex types, but that's too messy
1572                      to do now.  */
1573                   else if (TREE_CODE (type) == REAL_TYPE
1574                            && TREE_CODE (TREE_TYPE (val)) == REAL_TYPE)
1575                     {
1576                       /* Warn if any argument is passed as `float',
1577                          since without a prototype it would be `double'.  */
1578                       if (formal_prec == TYPE_PRECISION (float_type_node))
1579                         warn_for_assignment ("%s as `float' rather than `double' due to prototype", (char *) 0, name, parmnum + 1);
1580                     }
1581                   /* Detect integer changing in width or signedness.  */
1582                   else if (INTEGRAL_TYPE_P (type)
1583                            && INTEGRAL_TYPE_P (TREE_TYPE (val)))
1584                     {
1585                       tree would_have_been = default_conversion (val);
1586                       tree type1 = TREE_TYPE (would_have_been);
1587
1588                       if (TREE_CODE (type) == ENUMERAL_TYPE
1589                           && type == TREE_TYPE (val))
1590                         /* No warning if function asks for enum
1591                            and the actual arg is that enum type.  */
1592                         ;
1593                       else if (formal_prec != TYPE_PRECISION (type1))
1594                         warn_for_assignment ("%s with different width due to prototype", (char *) 0, name, parmnum + 1);
1595                       else if (TREE_UNSIGNED (type) == TREE_UNSIGNED (type1))
1596                         ;
1597                       /* Don't complain if the formal parameter type
1598                          is an enum, because we can't tell now whether
1599                          the value was an enum--even the same enum.  */
1600                       else if (TREE_CODE (type) == ENUMERAL_TYPE)
1601                         ;
1602                       else if (TREE_CODE (val) == INTEGER_CST
1603                                && int_fits_type_p (val, type))
1604                         /* Change in signedness doesn't matter
1605                            if a constant value is unaffected.  */
1606                         ;
1607                       /* Likewise for a constant in a NOP_EXPR.  */
1608                       else if (TREE_CODE (val) == NOP_EXPR
1609                                && TREE_CODE (TREE_OPERAND (val, 0)) == INTEGER_CST
1610                                && int_fits_type_p (TREE_OPERAND (val, 0), type))
1611                         ;
1612 #if 0 /* We never get such tree structure here.  */
1613                       else if (TREE_CODE (TREE_TYPE (val)) == ENUMERAL_TYPE
1614                                && int_fits_type_p (TYPE_MIN_VALUE (TREE_TYPE (val)), type)
1615                                && int_fits_type_p (TYPE_MAX_VALUE (TREE_TYPE (val)), type))
1616                         /* Change in signedness doesn't matter
1617                            if an enum value is unaffected.  */
1618                         ;
1619 #endif
1620                       /* If the value is extended from a narrower
1621                          unsigned type, it doesn't matter whether we
1622                          pass it as signed or unsigned; the value
1623                          certainly is the same either way.  */
1624                       else if (TYPE_PRECISION (TREE_TYPE (val)) < TYPE_PRECISION (type)
1625                                && TREE_UNSIGNED (TREE_TYPE (val)))
1626                         ;
1627                       else if (TREE_UNSIGNED (type))
1628                         warn_for_assignment ("%s as unsigned due to prototype", (char *) 0, name, parmnum + 1);
1629                       else
1630                         warn_for_assignment ("%s as signed due to prototype", (char *) 0, name, parmnum + 1);
1631                     }
1632                 }
1633
1634               parmval = convert_for_assignment (type, val, 
1635                                                 (char *) 0, /* arg passing  */
1636                                                 fundecl, name, parmnum + 1);
1637               
1638               if (PROMOTE_PROTOTYPES
1639                   && (TREE_CODE (type) == INTEGER_TYPE
1640                       || TREE_CODE (type) == ENUMERAL_TYPE)
1641                   && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
1642                 parmval = default_conversion (parmval);
1643             }
1644           result = tree_cons (NULL_TREE, parmval, result);
1645         }
1646       else if (TREE_CODE (TREE_TYPE (val)) == REAL_TYPE
1647                && (TYPE_PRECISION (TREE_TYPE (val))
1648                    < TYPE_PRECISION (double_type_node)))
1649         /* Convert `float' to `double'.  */
1650         result = tree_cons (NULL_TREE, convert (double_type_node, val), result);
1651       else
1652         /* Convert `short' and `char' to full-size `int'.  */
1653         result = tree_cons (NULL_TREE, default_conversion (val), result);
1654
1655       if (typetail)
1656         typetail = TREE_CHAIN (typetail);
1657     }
1658
1659   if (typetail != 0 && TREE_VALUE (typetail) != void_type_node)
1660     {
1661       if (name)
1662         error ("too few arguments to function `%s'",
1663                IDENTIFIER_POINTER (name));
1664       else
1665         error ("too few arguments to function");
1666     }
1667
1668   return nreverse (result);
1669 }
1670 \f
1671 /* This is the entry point used by the parser
1672    for binary operators in the input.
1673    In addition to constructing the expression,
1674    we check for operands that were written with other binary operators
1675    in a way that is likely to confuse the user.  */
1676
1677 tree
1678 parser_build_binary_op (code, arg1, arg2)
1679      enum tree_code code;
1680      tree arg1, arg2;
1681 {
1682   tree result = build_binary_op (code, arg1, arg2, 1);
1683
1684   char class;
1685   char class1 = TREE_CODE_CLASS (TREE_CODE (arg1));
1686   char class2 = TREE_CODE_CLASS (TREE_CODE (arg2));
1687   enum tree_code code1 = ERROR_MARK;
1688   enum tree_code code2 = ERROR_MARK;
1689
1690   if (class1 == 'e' || class1 == '1'
1691       || class1 == '2' || class1 == '<')
1692     code1 = C_EXP_ORIGINAL_CODE (arg1);
1693   if (class2 == 'e' || class2 == '1'
1694       || class2 == '2' || class2 == '<')
1695     code2 = C_EXP_ORIGINAL_CODE (arg2);
1696
1697   /* Check for cases such as x+y<<z which users are likely
1698      to misinterpret.  If parens are used, C_EXP_ORIGINAL_CODE
1699      is cleared to prevent these warnings.  */
1700   if (warn_parentheses)
1701     {
1702       if (code == LSHIFT_EXPR || code == RSHIFT_EXPR)
1703         {
1704           if (code1 == PLUS_EXPR || code1 == MINUS_EXPR
1705               || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
1706             warning ("suggest parentheses around + or - inside shift");
1707         }
1708
1709       if (code == TRUTH_ORIF_EXPR)
1710         {
1711           if (code1 == TRUTH_ANDIF_EXPR
1712               || code2 == TRUTH_ANDIF_EXPR)
1713             warning ("suggest parentheses around && within ||");
1714         }
1715
1716       if (code == BIT_IOR_EXPR)
1717         {
1718           if (code1 == BIT_AND_EXPR || code1 == BIT_XOR_EXPR
1719               || code1 == PLUS_EXPR || code1 == MINUS_EXPR
1720               || code2 == BIT_AND_EXPR || code2 == BIT_XOR_EXPR
1721               || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
1722             warning ("suggest parentheses around arithmetic in operand of |");
1723           /* Check cases like x|y==z */
1724           if (TREE_CODE_CLASS (code1) == '<' || TREE_CODE_CLASS (code2) == '<')
1725             warning ("suggest parentheses around comparison in operand of |");
1726         }
1727
1728       if (code == BIT_XOR_EXPR)
1729         {
1730           if (code1 == BIT_AND_EXPR
1731               || code1 == PLUS_EXPR || code1 == MINUS_EXPR
1732               || code2 == BIT_AND_EXPR
1733               || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
1734             warning ("suggest parentheses around arithmetic in operand of ^");
1735           /* Check cases like x^y==z */
1736           if (TREE_CODE_CLASS (code1) == '<' || TREE_CODE_CLASS (code2) == '<')
1737             warning ("suggest parentheses around comparison in operand of ^");
1738         }
1739
1740       if (code == BIT_AND_EXPR)
1741         {
1742           if (code1 == PLUS_EXPR || code1 == MINUS_EXPR
1743               || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
1744             warning ("suggest parentheses around + or - in operand of &");
1745           /* Check cases like x&y==z */
1746           if (TREE_CODE_CLASS (code1) == '<' || TREE_CODE_CLASS (code2) == '<')
1747             warning ("suggest parentheses around comparison in operand of &");
1748         }
1749     }
1750
1751   /* Similarly, check for cases like 1<=i<=10 that are probably errors.  */
1752   if (TREE_CODE_CLASS (code) == '<' && extra_warnings
1753       && (TREE_CODE_CLASS (code1) == '<' || TREE_CODE_CLASS (code2) == '<'))
1754     warning ("comparisons like X<=Y<=Z do not have their mathematical meaning");
1755
1756   unsigned_conversion_warning (result, arg1);
1757   unsigned_conversion_warning (result, arg2);
1758   overflow_warning (result);
1759
1760   class = TREE_CODE_CLASS (TREE_CODE (result));
1761
1762   /* Record the code that was specified in the source,
1763      for the sake of warnings about confusing nesting.  */
1764   if (class == 'e' || class == '1'
1765       || class == '2' || class == '<')
1766     C_SET_EXP_ORIGINAL_CODE (result, code);
1767   else
1768     {
1769       int flag = TREE_CONSTANT (result);
1770       /* We used to use NOP_EXPR rather than NON_LVALUE_EXPR
1771          so that convert_for_assignment wouldn't strip it.
1772          That way, we got warnings for things like p = (1 - 1).
1773          But it turns out we should not get those warnings.  */
1774       result = build1 (NON_LVALUE_EXPR, TREE_TYPE (result), result);
1775       C_SET_EXP_ORIGINAL_CODE (result, code);
1776       TREE_CONSTANT (result) = flag;
1777     }
1778
1779   return result;
1780 }
1781
1782 /* Build a binary-operation expression without default conversions.
1783    CODE is the kind of expression to build.
1784    This function differs from `build' in several ways:
1785    the data type of the result is computed and recorded in it,
1786    warnings are generated if arg data types are invalid,
1787    special handling for addition and subtraction of pointers is known,
1788    and some optimization is done (operations on narrow ints
1789    are done in the narrower type when that gives the same result).
1790    Constant folding is also done before the result is returned.
1791
1792    Note that the operands will never have enumeral types, or function
1793    or array types, because either they will have the default conversions
1794    performed or they have both just been converted to some other type in which
1795    the arithmetic is to be done.  */
1796
1797 tree
1798 build_binary_op (code, orig_op0, orig_op1, convert_p)
1799      enum tree_code code;
1800      tree orig_op0, orig_op1;
1801      int convert_p;
1802 {
1803   tree type0, type1;
1804   register enum tree_code code0, code1;
1805   tree op0, op1;
1806
1807   /* Expression code to give to the expression when it is built.
1808      Normally this is CODE, which is what the caller asked for,
1809      but in some special cases we change it.  */
1810   register enum tree_code resultcode = code;
1811
1812   /* Data type in which the computation is to be performed.
1813      In the simplest cases this is the common type of the arguments.  */
1814   register tree result_type = NULL;
1815
1816   /* Nonzero means operands have already been type-converted
1817      in whatever way is necessary.
1818      Zero means they need to be converted to RESULT_TYPE.  */
1819   int converted = 0;
1820
1821   /* Nonzero means create the expression with this type, rather than
1822      RESULT_TYPE.  */
1823   tree build_type = 0;
1824
1825   /* Nonzero means after finally constructing the expression
1826      convert it to this type.  */
1827   tree final_type = 0;
1828
1829   /* Nonzero if this is an operation like MIN or MAX which can
1830      safely be computed in short if both args are promoted shorts.
1831      Also implies COMMON.
1832      -1 indicates a bitwise operation; this makes a difference
1833      in the exact conditions for when it is safe to do the operation
1834      in a narrower mode.  */
1835   int shorten = 0;
1836
1837   /* Nonzero if this is a comparison operation;
1838      if both args are promoted shorts, compare the original shorts.
1839      Also implies COMMON.  */
1840   int short_compare = 0;
1841
1842   /* Nonzero if this is a right-shift operation, which can be computed on the
1843      original short and then promoted if the operand is a promoted short.  */
1844   int short_shift = 0;
1845
1846   /* Nonzero means set RESULT_TYPE to the common type of the args.  */
1847   int common = 0;
1848
1849   if (convert_p)
1850     {
1851       op0 = default_conversion (orig_op0);
1852       op1 = default_conversion (orig_op1);
1853     }
1854   else
1855     {
1856       op0 = orig_op0;
1857       op1 = orig_op1;
1858     }
1859
1860   type0 = TREE_TYPE (op0);
1861   type1 = TREE_TYPE (op1);
1862
1863   /* The expression codes of the data types of the arguments tell us
1864      whether the arguments are integers, floating, pointers, etc.  */
1865   code0 = TREE_CODE (type0);
1866   code1 = TREE_CODE (type1);
1867
1868   /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
1869   STRIP_TYPE_NOPS (op0);
1870   STRIP_TYPE_NOPS (op1);
1871
1872   /* If an error was already reported for one of the arguments,
1873      avoid reporting another error.  */
1874
1875   if (code0 == ERROR_MARK || code1 == ERROR_MARK)
1876     return error_mark_node;
1877
1878   switch (code)
1879     {
1880     case PLUS_EXPR:
1881       /* Handle the pointer + int case.  */
1882       if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
1883         return pointer_int_sum (PLUS_EXPR, op0, op1);
1884       else if (code1 == POINTER_TYPE && code0 == INTEGER_TYPE)
1885         return pointer_int_sum (PLUS_EXPR, op1, op0);
1886       else
1887         common = 1;
1888       break;
1889
1890     case MINUS_EXPR:
1891       /* Subtraction of two similar pointers.
1892          We must subtract them as integers, then divide by object size.  */
1893       if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
1894           && comp_target_types (type0, type1))
1895         return pointer_diff (op0, op1);
1896       /* Handle pointer minus int.  Just like pointer plus int.  */
1897       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
1898         return pointer_int_sum (MINUS_EXPR, op0, op1);
1899       else
1900         common = 1;
1901       break;
1902
1903     case MULT_EXPR:
1904       common = 1;
1905       break;
1906
1907     case TRUNC_DIV_EXPR:
1908     case CEIL_DIV_EXPR:
1909     case FLOOR_DIV_EXPR:
1910     case ROUND_DIV_EXPR:
1911     case EXACT_DIV_EXPR:
1912       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
1913            || code0 == COMPLEX_TYPE)
1914           && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
1915               || code1 == COMPLEX_TYPE))
1916         {
1917           if (!(code0 == INTEGER_TYPE && code1 == INTEGER_TYPE))
1918             resultcode = RDIV_EXPR;
1919           else
1920             {
1921               /* Although it would be tempting to shorten always here, that
1922                  loses on some targets, since the modulo instruction is
1923                  undefined if the quotient can't be represented in the
1924                  computation mode.  We shorten only if unsigned or if
1925                  dividing by something we know != -1.  */
1926               shorten = (TREE_UNSIGNED (TREE_TYPE (orig_op0))
1927                          || (TREE_CODE (op1) == INTEGER_CST
1928                              && (TREE_INT_CST_LOW (op1) != -1
1929                                  || TREE_INT_CST_HIGH (op1) != -1)));
1930             }
1931           common = 1;
1932         }
1933       break;
1934
1935     case BIT_AND_EXPR:
1936     case BIT_ANDTC_EXPR:
1937     case BIT_IOR_EXPR:
1938     case BIT_XOR_EXPR:
1939       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
1940         shorten = -1;
1941       /* If one operand is a constant, and the other is a short type
1942          that has been converted to an int,
1943          really do the work in the short type and then convert the
1944          result to int.  If we are lucky, the constant will be 0 or 1
1945          in the short type, making the entire operation go away.  */
1946       if (TREE_CODE (op0) == INTEGER_CST
1947           && TREE_CODE (op1) == NOP_EXPR
1948           && TYPE_PRECISION (type1) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1, 0)))
1949           && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op1, 0))))
1950         {
1951           final_type = result_type;
1952           op1 = TREE_OPERAND (op1, 0);
1953           result_type = TREE_TYPE (op1);
1954         }
1955       if (TREE_CODE (op1) == INTEGER_CST
1956           && TREE_CODE (op0) == NOP_EXPR
1957           && TYPE_PRECISION (type0) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0, 0)))
1958           && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0, 0))))
1959         {
1960           final_type = result_type;
1961           op0 = TREE_OPERAND (op0, 0);
1962           result_type = TREE_TYPE (op0);
1963         }
1964       break;
1965
1966     case TRUNC_MOD_EXPR:
1967     case FLOOR_MOD_EXPR:
1968       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
1969         {
1970           /* Although it would be tempting to shorten always here, that loses
1971              on some targets, since the modulo instruction is undefined if the
1972              quotient can't be represented in the computation mode.  We shorten
1973              only if unsigned or if dividing by something we know != -1.  */
1974           shorten = (TREE_UNSIGNED (TREE_TYPE (orig_op0))
1975                      || (TREE_CODE (op1) == INTEGER_CST
1976                          && (TREE_INT_CST_LOW (op1) != -1
1977                              || TREE_INT_CST_HIGH (op1) != -1)));
1978           common = 1;
1979         }
1980       break;
1981
1982     case TRUTH_ANDIF_EXPR:
1983     case TRUTH_ORIF_EXPR:
1984     case TRUTH_AND_EXPR:
1985     case TRUTH_OR_EXPR:
1986     case TRUTH_XOR_EXPR:
1987       if ((code0 == INTEGER_TYPE || code0 == POINTER_TYPE
1988            || code0 == REAL_TYPE || code0 == COMPLEX_TYPE)
1989           && (code1 == INTEGER_TYPE || code1 == POINTER_TYPE
1990               || code1 == REAL_TYPE || code1 == COMPLEX_TYPE))
1991         {
1992           /* Result of these operations is always an int,
1993              but that does not mean the operands should be
1994              converted to ints!  */
1995           result_type = integer_type_node;
1996           op0 = truthvalue_conversion (op0);
1997           op1 = truthvalue_conversion (op1);
1998           converted = 1;
1999         }
2000       break;
2001
2002       /* Shift operations: result has same type as first operand;
2003          always convert second operand to int.
2004          Also set SHORT_SHIFT if shifting rightward.  */
2005
2006     case RSHIFT_EXPR:
2007       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
2008         {
2009           if (TREE_CODE (op1) == INTEGER_CST && skip_evaluation == 0)
2010             {
2011               if (tree_int_cst_sgn (op1) < 0)
2012                 warning ("right shift count is negative");
2013               else
2014                 {
2015                   if (TREE_INT_CST_LOW (op1) | TREE_INT_CST_HIGH (op1))
2016                     short_shift = 1;
2017                   if (TREE_INT_CST_HIGH (op1) != 0
2018                       || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1)
2019                           >= TYPE_PRECISION (type0)))
2020                     warning ("right shift count >= width of type");
2021                 }
2022             }
2023           /* Use the type of the value to be shifted.
2024              This is what most traditional C compilers do.  */
2025           result_type = type0;
2026           /* Unless traditional, convert the shift-count to an integer,
2027              regardless of size of value being shifted.  */
2028           if (! flag_traditional)
2029             {
2030               if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
2031                 op1 = convert (integer_type_node, op1);
2032               /* Avoid converting op1 to result_type later.  */
2033               converted = 1;
2034             }
2035         }
2036       break;
2037
2038     case LSHIFT_EXPR:
2039       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
2040         {
2041           if (TREE_CODE (op1) == INTEGER_CST && skip_evaluation == 0)
2042             {
2043               if (tree_int_cst_sgn (op1) < 0)
2044                 warning ("left shift count is negative");
2045               else if (TREE_INT_CST_HIGH (op1) != 0
2046                        || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1)
2047                            >= TYPE_PRECISION (type0)))
2048                 warning ("left shift count >= width of type");
2049             }
2050           /* Use the type of the value to be shifted.
2051              This is what most traditional C compilers do.  */
2052           result_type = type0;
2053           /* Unless traditional, convert the shift-count to an integer,
2054              regardless of size of value being shifted.  */
2055           if (! flag_traditional)
2056             {
2057               if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
2058                 op1 = convert (integer_type_node, op1);
2059               /* Avoid converting op1 to result_type later.  */
2060               converted = 1;
2061             }
2062         }
2063       break;
2064
2065     case RROTATE_EXPR:
2066     case LROTATE_EXPR:
2067       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
2068         {
2069           if (TREE_CODE (op1) == INTEGER_CST && skip_evaluation == 0)
2070             {
2071               if (tree_int_cst_sgn (op1) < 0)
2072                 warning ("shift count is negative");
2073               else if (TREE_INT_CST_HIGH (op1) != 0
2074                        || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1)
2075                            >= TYPE_PRECISION (type0)))
2076                 warning ("shift count >= width of type");
2077             }
2078           /* Use the type of the value to be shifted.
2079              This is what most traditional C compilers do.  */
2080           result_type = type0;
2081           /* Unless traditional, convert the shift-count to an integer,
2082              regardless of size of value being shifted.  */
2083           if (! flag_traditional)
2084             {
2085               if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
2086                 op1 = convert (integer_type_node, op1);
2087               /* Avoid converting op1 to result_type later.  */
2088               converted = 1;
2089             }
2090         }
2091       break;
2092
2093     case EQ_EXPR:
2094     case NE_EXPR:
2095       if (warn_float_equal && (code0 == REAL_TYPE || code1 == REAL_TYPE))
2096         warning ("comparing floating point with == or != is unsafe");
2097       /* Result of comparison is always int,
2098          but don't convert the args to int!  */
2099       build_type = integer_type_node;
2100       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
2101            || code0 == COMPLEX_TYPE)
2102           && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
2103               || code1 == COMPLEX_TYPE))
2104         short_compare = 1;
2105       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
2106         {
2107           register tree tt0 = TREE_TYPE (type0);
2108           register tree tt1 = TREE_TYPE (type1);
2109           /* Anything compares with void *.  void * compares with anything.
2110              Otherwise, the targets must be compatible
2111              and both must be object or both incomplete.  */
2112           if (comp_target_types (type0, type1))
2113             result_type = common_type (type0, type1);
2114           else if (TYPE_MAIN_VARIANT (tt0) == void_type_node)
2115             {
2116               /* op0 != orig_op0 detects the case of something
2117                  whose value is 0 but which isn't a valid null ptr const.  */
2118               if (pedantic && (!integer_zerop (op0) || op0 != orig_op0)
2119                   && TREE_CODE (tt1) == FUNCTION_TYPE)
2120                 pedwarn ("ANSI C forbids comparison of `void *' with function pointer");
2121             }
2122           else if (TYPE_MAIN_VARIANT (tt1) == void_type_node)
2123             {
2124               if (pedantic && (!integer_zerop (op1) || op1 != orig_op1)
2125                   && TREE_CODE (tt0) == FUNCTION_TYPE)
2126                 pedwarn ("ANSI C forbids comparison of `void *' with function pointer");
2127             }
2128           else
2129             pedwarn ("comparison of distinct pointer types lacks a cast");
2130
2131           if (result_type == NULL_TREE)
2132             result_type = ptr_type_node;
2133         }
2134       else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
2135                && integer_zerop (op1))
2136         result_type = type0;
2137       else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
2138                && integer_zerop (op0))
2139         result_type = type1;
2140       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
2141         {
2142           result_type = type0;
2143           if (! flag_traditional)
2144             pedwarn ("comparison between pointer and integer");
2145         }
2146       else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
2147         {
2148           result_type = type1;
2149           if (! flag_traditional)
2150             pedwarn ("comparison between pointer and integer");
2151         }
2152       break;
2153
2154     case MAX_EXPR:
2155     case MIN_EXPR:
2156       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
2157           && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
2158         shorten = 1;
2159       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
2160         {
2161           if (comp_target_types (type0, type1))
2162             {
2163               result_type = common_type (type0, type1);
2164               if (pedantic 
2165                   && TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE)
2166                 pedwarn ("ANSI C forbids ordered comparisons of pointers to functions");
2167             }
2168           else
2169             {
2170               result_type = ptr_type_node;
2171               pedwarn ("comparison of distinct pointer types lacks a cast");
2172             }
2173         }
2174       break;
2175
2176     case LE_EXPR:
2177     case GE_EXPR:
2178     case LT_EXPR:
2179     case GT_EXPR:
2180       build_type = integer_type_node;
2181       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
2182           && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
2183         short_compare = 1;
2184       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
2185         {
2186           if (comp_target_types (type0, type1))
2187             {
2188               result_type = common_type (type0, type1);
2189               if ((TYPE_SIZE (TREE_TYPE (type0)) != 0)
2190                   != (TYPE_SIZE (TREE_TYPE (type1)) != 0))
2191                 pedwarn ("comparison of complete and incomplete pointers");
2192               else if (pedantic 
2193                        && TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE)
2194                 pedwarn ("ANSI C forbids ordered comparisons of pointers to functions");
2195             }
2196           else
2197             {
2198               result_type = ptr_type_node;
2199               pedwarn ("comparison of distinct pointer types lacks a cast");
2200             }
2201         }
2202       else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
2203                && integer_zerop (op1))
2204         {
2205           result_type = type0;
2206           if (pedantic || extra_warnings)
2207             pedwarn ("ordered comparison of pointer with integer zero");
2208         }
2209       else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
2210                && integer_zerop (op0))
2211         {
2212           result_type = type1;
2213           if (pedantic)
2214             pedwarn ("ordered comparison of pointer with integer zero");
2215         }
2216       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
2217         {
2218           result_type = type0;
2219           if (! flag_traditional)
2220             pedwarn ("comparison between pointer and integer");
2221         }
2222       else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
2223         {
2224           result_type = type1;
2225           if (! flag_traditional)
2226             pedwarn ("comparison between pointer and integer");
2227         }
2228       break;
2229
2230     case UNORDERED_EXPR:
2231     case ORDERED_EXPR:
2232     case UNLT_EXPR:
2233     case UNLE_EXPR:
2234     case UNGT_EXPR:
2235     case UNGE_EXPR:
2236     case UNEQ_EXPR:
2237       build_type = integer_type_node;
2238       if (code0 != REAL_TYPE || code1 != REAL_TYPE)
2239         {
2240           error ("unordered comparison on non-floating point argument");
2241           return error_mark_node;
2242         }
2243       common = 1;
2244       break;
2245
2246     default:
2247       break;
2248     }
2249
2250   if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE)
2251       &&
2252       (code1 == INTEGER_TYPE || code1 == REAL_TYPE || code1 == COMPLEX_TYPE))
2253     {
2254       int none_complex = (code0 != COMPLEX_TYPE && code1 != COMPLEX_TYPE);
2255
2256       if (shorten || common || short_compare)
2257         result_type = common_type (type0, type1);
2258
2259       /* For certain operations (which identify themselves by shorten != 0)
2260          if both args were extended from the same smaller type,
2261          do the arithmetic in that type and then extend.
2262
2263          shorten !=0 and !=1 indicates a bitwise operation.
2264          For them, this optimization is safe only if
2265          both args are zero-extended or both are sign-extended.
2266          Otherwise, we might change the result.
2267          Eg, (short)-1 | (unsigned short)-1 is (int)-1
2268          but calculated in (unsigned short) it would be (unsigned short)-1.  */
2269
2270       if (shorten && none_complex)
2271         {
2272           int unsigned0, unsigned1;
2273           tree arg0 = get_narrower (op0, &unsigned0);
2274           tree arg1 = get_narrower (op1, &unsigned1);
2275           /* UNS is 1 if the operation to be done is an unsigned one.  */
2276           int uns = TREE_UNSIGNED (result_type);
2277           tree type;
2278
2279           final_type = result_type;
2280
2281           /* Handle the case that OP0 (or OP1) does not *contain* a conversion
2282              but it *requires* conversion to FINAL_TYPE.  */
2283
2284           if ((TYPE_PRECISION (TREE_TYPE (op0))
2285                == TYPE_PRECISION (TREE_TYPE (arg0)))
2286               && TREE_TYPE (op0) != final_type)
2287             unsigned0 = TREE_UNSIGNED (TREE_TYPE (op0));
2288           if ((TYPE_PRECISION (TREE_TYPE (op1))
2289                == TYPE_PRECISION (TREE_TYPE (arg1)))
2290               && TREE_TYPE (op1) != final_type)
2291             unsigned1 = TREE_UNSIGNED (TREE_TYPE (op1));
2292
2293           /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE.  */
2294
2295           /* For bitwise operations, signedness of nominal type
2296              does not matter.  Consider only how operands were extended.  */
2297           if (shorten == -1)
2298             uns = unsigned0;
2299
2300           /* Note that in all three cases below we refrain from optimizing
2301              an unsigned operation on sign-extended args.
2302              That would not be valid.  */
2303
2304           /* Both args variable: if both extended in same way
2305              from same width, do it in that width.
2306              Do it unsigned if args were zero-extended.  */
2307           if ((TYPE_PRECISION (TREE_TYPE (arg0))
2308                < TYPE_PRECISION (result_type))
2309               && (TYPE_PRECISION (TREE_TYPE (arg1))
2310                   == TYPE_PRECISION (TREE_TYPE (arg0)))
2311               && unsigned0 == unsigned1
2312               && (unsigned0 || !uns))
2313             result_type
2314               = signed_or_unsigned_type (unsigned0,
2315                                          common_type (TREE_TYPE (arg0), TREE_TYPE (arg1)));
2316           else if (TREE_CODE (arg0) == INTEGER_CST
2317                    && (unsigned1 || !uns)
2318                    && (TYPE_PRECISION (TREE_TYPE (arg1))
2319                        < TYPE_PRECISION (result_type))
2320                    && (type = signed_or_unsigned_type (unsigned1,
2321                                                        TREE_TYPE (arg1)),
2322                        int_fits_type_p (arg0, type)))
2323             result_type = type;
2324           else if (TREE_CODE (arg1) == INTEGER_CST
2325                    && (unsigned0 || !uns)
2326                    && (TYPE_PRECISION (TREE_TYPE (arg0))
2327                        < TYPE_PRECISION (result_type))
2328                    && (type = signed_or_unsigned_type (unsigned0,
2329                                                        TREE_TYPE (arg0)),
2330                        int_fits_type_p (arg1, type)))
2331             result_type = type;
2332         }
2333
2334       /* Shifts can be shortened if shifting right.  */
2335
2336       if (short_shift)
2337         {
2338           int unsigned_arg;
2339           tree arg0 = get_narrower (op0, &unsigned_arg);
2340
2341           final_type = result_type;
2342
2343           if (arg0 == op0 && final_type == TREE_TYPE (op0))
2344             unsigned_arg = TREE_UNSIGNED (TREE_TYPE (op0));
2345
2346           if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type)
2347               /* We can shorten only if the shift count is less than the
2348                  number of bits in the smaller type size.  */
2349               && TREE_INT_CST_HIGH (op1) == 0
2350               && TYPE_PRECISION (TREE_TYPE (arg0)) > TREE_INT_CST_LOW (op1)
2351               /* If arg is sign-extended and then unsigned-shifted,
2352                  we can simulate this with a signed shift in arg's type
2353                  only if the extended result is at least twice as wide
2354                  as the arg.  Otherwise, the shift could use up all the
2355                  ones made by sign-extension and bring in zeros.
2356                  We can't optimize that case at all, but in most machines
2357                  it never happens because available widths are 2**N.  */
2358               && (!TREE_UNSIGNED (final_type)
2359                   || unsigned_arg
2360                   || 2 * TYPE_PRECISION (TREE_TYPE (arg0)) <= TYPE_PRECISION (result_type)))
2361             {
2362               /* Do an unsigned shift if the operand was zero-extended.  */
2363               result_type
2364                 = signed_or_unsigned_type (unsigned_arg,
2365                                            TREE_TYPE (arg0));
2366               /* Convert value-to-be-shifted to that type.  */
2367               if (TREE_TYPE (op0) != result_type)
2368                 op0 = convert (result_type, op0);
2369               converted = 1;
2370             }
2371         }
2372
2373       /* Comparison operations are shortened too but differently.
2374          They identify themselves by setting short_compare = 1.  */
2375
2376       if (short_compare)
2377         {
2378           /* Don't write &op0, etc., because that would prevent op0
2379              from being kept in a register.
2380              Instead, make copies of the our local variables and
2381              pass the copies by reference, then copy them back afterward.  */
2382           tree xop0 = op0, xop1 = op1, xresult_type = result_type;
2383           enum tree_code xresultcode = resultcode;
2384           tree val 
2385             = shorten_compare (&xop0, &xop1, &xresult_type, &xresultcode);
2386           if (val != 0)
2387             return val;
2388           op0 = xop0, op1 = xop1;
2389           converted = 1;
2390           resultcode = xresultcode;
2391
2392           if ((warn_sign_compare < 0 ? extra_warnings : warn_sign_compare != 0)
2393               && skip_evaluation == 0)
2394             {
2395               int op0_signed = ! TREE_UNSIGNED (TREE_TYPE (orig_op0));
2396               int op1_signed = ! TREE_UNSIGNED (TREE_TYPE (orig_op1));
2397
2398               int unsignedp0, unsignedp1;
2399               tree primop0 = get_narrower (op0, &unsignedp0);
2400               tree primop1 = get_narrower (op1, &unsignedp1);
2401
2402               xop0 = orig_op0;
2403               xop1 = orig_op1;
2404               STRIP_TYPE_NOPS (xop0);
2405               STRIP_TYPE_NOPS (xop1);
2406
2407               /* Give warnings for comparisons between signed and unsigned
2408                  quantities that may fail.  */
2409               /* Do the checking based on the original operand trees, so that
2410                  casts will be considered, but default promotions won't be.  */
2411
2412               /* Do not warn if the comparison is being done in a signed type,
2413                  since the signed type will only be chosen if it can represent
2414                  all the values of the unsigned type.  */
2415               if (! TREE_UNSIGNED (result_type))
2416                 /* OK */;
2417               /* Do not warn if both operands are the same signedness.  */
2418               else if (op0_signed == op1_signed)
2419                 /* OK */;
2420               else
2421                 {
2422                   tree sop, uop;
2423                   if (op0_signed)
2424                     sop = xop0, uop = xop1;
2425                   else
2426                     sop = xop1, uop = xop0;
2427
2428                   /* Do not warn if the signed quantity is an unsuffixed
2429                      integer literal (or some static constant expression
2430                      involving such literals) and it is non-negative.  */
2431                   if (TREE_CODE (sop) == INTEGER_CST
2432                       && tree_int_cst_sgn (sop) >= 0)
2433                     /* OK */;
2434                   /* Do not warn if the comparison is an equality operation,
2435                      the unsigned quantity is an integral constant, and it
2436                      would fit in the result if the result were signed.  */
2437                   else if (TREE_CODE (uop) == INTEGER_CST
2438                            && (resultcode == EQ_EXPR || resultcode == NE_EXPR)
2439                            && int_fits_type_p (uop, signed_type (result_type)))
2440                     /* OK */;
2441                   /* Do not warn if the unsigned quantity is an enumeration
2442                      constant and its maximum value would fit in the result
2443                      if the result were signed.  */
2444                   else if (TREE_CODE (uop) == INTEGER_CST
2445                            && TREE_CODE (TREE_TYPE (uop)) == ENUMERAL_TYPE
2446                            && int_fits_type_p (TYPE_MAX_VALUE (TREE_TYPE(uop)),
2447                                                signed_type (result_type)))
2448                     /* OK */;
2449                   else
2450                     warning ("comparison between signed and unsigned");
2451                 }
2452
2453               /* Warn if two unsigned values are being compared in a size
2454                  larger than their original size, and one (and only one) is the
2455                  result of a `~' operator.  This comparison will always fail.
2456
2457                  Also warn if one operand is a constant, and the constant
2458                  does not have all bits set that are set in the ~ operand
2459                  when it is extended.  */
2460
2461               if ((TREE_CODE (primop0) == BIT_NOT_EXPR)
2462                   != (TREE_CODE (primop1) == BIT_NOT_EXPR))
2463                 {
2464                   if (TREE_CODE (primop0) == BIT_NOT_EXPR)
2465                     primop0 = get_narrower (TREE_OPERAND (primop0, 0),
2466                                             &unsignedp0);
2467                   else
2468                     primop1 = get_narrower (TREE_OPERAND (primop1, 0),
2469                                             &unsignedp1);
2470               
2471                   if (TREE_CODE (primop0) == INTEGER_CST
2472                       || TREE_CODE (primop1) == INTEGER_CST)
2473                     {
2474                       tree primop;
2475                       long constant, mask;
2476                       int unsignedp, bits;
2477
2478                       if (TREE_CODE (primop0) == INTEGER_CST)
2479                         {
2480                           primop = primop1;
2481                           unsignedp = unsignedp1;
2482                           constant = TREE_INT_CST_LOW (primop0);
2483                         }
2484                       else
2485                         {
2486                           primop = primop0;
2487                           unsignedp = unsignedp0;
2488                           constant = TREE_INT_CST_LOW (primop1);
2489                         }
2490
2491                       bits = TYPE_PRECISION (TREE_TYPE (primop));
2492                       if (bits < TYPE_PRECISION (result_type)
2493                           && bits < HOST_BITS_PER_LONG && unsignedp)
2494                         {
2495                           mask = (~0L) << bits;
2496                           if ((mask & constant) != mask)
2497                             warning ("comparison of promoted ~unsigned with constant");
2498                         }
2499                     }
2500                   else if (unsignedp0 && unsignedp1
2501                            && (TYPE_PRECISION (TREE_TYPE (primop0))
2502                                < TYPE_PRECISION (result_type))
2503                            && (TYPE_PRECISION (TREE_TYPE (primop1))
2504                                < TYPE_PRECISION (result_type)))
2505                     warning ("comparison of promoted ~unsigned with unsigned");
2506                 }
2507             }
2508         }
2509     }
2510
2511   /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
2512      If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
2513      Then the expression will be built.
2514      It will be given type FINAL_TYPE if that is nonzero;
2515      otherwise, it will be given type RESULT_TYPE.  */
2516
2517   if (!result_type)
2518     {
2519       binary_op_error (code);
2520       return error_mark_node;
2521     }
2522
2523   if (! converted)
2524     {
2525       if (TREE_TYPE (op0) != result_type)
2526         op0 = convert (result_type, op0); 
2527       if (TREE_TYPE (op1) != result_type)
2528         op1 = convert (result_type, op1); 
2529     }
2530
2531   if (build_type == NULL_TREE)
2532     build_type = result_type;
2533
2534   {
2535     register tree result = build (resultcode, build_type, op0, op1);
2536     register tree folded;
2537
2538     folded = fold (result);
2539     if (folded == result)
2540       TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1);
2541     if (final_type != 0)
2542       return convert (final_type, folded);
2543     return folded;
2544   }
2545 }
2546 \f
2547 /* Return a tree for the sum or difference (RESULTCODE says which)
2548    of pointer PTROP and integer INTOP.  */
2549
2550 static tree
2551 pointer_int_sum (resultcode, ptrop, intop)
2552      enum tree_code resultcode;
2553      register tree ptrop, intop;
2554 {
2555   tree size_exp;
2556
2557   register tree result;
2558   register tree folded;
2559
2560   /* The result is a pointer of the same type that is being added.  */
2561
2562   register tree result_type = TREE_TYPE (ptrop);
2563
2564   if (TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE)
2565     {
2566       if (pedantic || warn_pointer_arith)
2567         pedwarn ("pointer of type `void *' used in arithmetic");
2568       size_exp = integer_one_node;
2569     }
2570   else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE)
2571     {
2572       if (pedantic || warn_pointer_arith)
2573         pedwarn ("pointer to a function used in arithmetic");
2574       size_exp = integer_one_node;
2575     }
2576   else
2577     size_exp = c_size_in_bytes (TREE_TYPE (result_type));
2578
2579   /* If what we are about to multiply by the size of the elements
2580      contains a constant term, apply distributive law
2581      and multiply that constant term separately.
2582      This helps produce common subexpressions.  */
2583
2584   if ((TREE_CODE (intop) == PLUS_EXPR || TREE_CODE (intop) == MINUS_EXPR)
2585       && ! TREE_CONSTANT (intop)
2586       && TREE_CONSTANT (TREE_OPERAND (intop, 1))
2587       && TREE_CONSTANT (size_exp)
2588       /* If the constant comes from pointer subtraction,
2589          skip this optimization--it would cause an error.  */
2590       && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop, 0))) == INTEGER_TYPE
2591       /* If the constant is unsigned, and smaller than the pointer size,
2592          then we must skip this optimization.  This is because it could cause
2593          an overflow error if the constant is negative but INTOP is not.  */
2594       && (! TREE_UNSIGNED (TREE_TYPE (intop))
2595           || (TYPE_PRECISION (TREE_TYPE (intop))
2596               == TYPE_PRECISION (TREE_TYPE (ptrop)))))
2597     {
2598       enum tree_code subcode = resultcode;
2599       tree int_type = TREE_TYPE (intop);
2600       if (TREE_CODE (intop) == MINUS_EXPR)
2601         subcode = (subcode == PLUS_EXPR ? MINUS_EXPR : PLUS_EXPR);
2602       /* Convert both subexpression types to the type of intop,
2603          because weird cases involving pointer arithmetic
2604          can result in a sum or difference with different type args.  */
2605       ptrop = build_binary_op (subcode, ptrop,
2606                                convert (int_type, TREE_OPERAND (intop, 1)), 1);
2607       intop = convert (int_type, TREE_OPERAND (intop, 0));
2608     }
2609
2610   /* Convert the integer argument to a type the same size as sizetype
2611      so the multiply won't overflow spuriously.  */
2612
2613   if (TYPE_PRECISION (TREE_TYPE (intop)) != TYPE_PRECISION (sizetype)
2614       || TREE_UNSIGNED (TREE_TYPE (intop)) != TREE_UNSIGNED (sizetype))
2615     intop = convert (type_for_size (TYPE_PRECISION (sizetype), 
2616                                     TREE_UNSIGNED (sizetype)), intop);
2617
2618   /* Replace the integer argument with a suitable product by the object size.
2619      Do this multiplication as signed, then convert to the appropriate
2620      pointer type (actually unsigned integral).  */
2621
2622   intop = convert (result_type,
2623                    build_binary_op (MULT_EXPR, intop,
2624                                     convert (TREE_TYPE (intop), size_exp), 1));
2625
2626   /* Create the sum or difference.  */
2627
2628   result = build (resultcode, result_type, ptrop, intop);
2629
2630   folded = fold (result);
2631   if (folded == result)
2632     TREE_CONSTANT (folded) = TREE_CONSTANT (ptrop) & TREE_CONSTANT (intop);
2633   return folded;
2634 }
2635
2636 /* Return a tree for the difference of pointers OP0 and OP1.
2637    The resulting tree has type int.  */
2638
2639 static tree
2640 pointer_diff (op0, op1)
2641      register tree op0, op1;
2642 {
2643   register tree result, folded;
2644   tree restype = ptrdiff_type_node;
2645
2646   tree target_type = TREE_TYPE (TREE_TYPE (op0));
2647
2648   if (pedantic || warn_pointer_arith)
2649     {
2650       if (TREE_CODE (target_type) == VOID_TYPE)
2651         pedwarn ("pointer of type `void *' used in subtraction");
2652       if (TREE_CODE (target_type) == FUNCTION_TYPE)
2653         pedwarn ("pointer to a function used in subtraction");
2654     }
2655
2656   /* First do the subtraction as integers;
2657      then drop through to build the divide operator.
2658      Do not do default conversions on the minus operator
2659      in case restype is a short type.  */
2660
2661   op0 = build_binary_op (MINUS_EXPR, convert (restype, op0),
2662                          convert (restype, op1), 0);
2663   /* This generates an error if op1 is pointer to incomplete type.  */
2664   if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (op1))) == 0)
2665     error ("arithmetic on pointer to an incomplete type");
2666
2667   /* This generates an error if op0 is pointer to incomplete type.  */
2668   op1 = c_size_in_bytes (target_type);
2669
2670   /* Divide by the size, in easiest possible way.  */
2671
2672   result = build (EXACT_DIV_EXPR, restype, op0, convert (restype, op1));
2673
2674   folded = fold (result);
2675   if (folded == result)
2676     TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1);
2677   return folded;
2678 }
2679 \f
2680 /* Construct and perhaps optimize a tree representation
2681    for a unary operation.  CODE, a tree_code, specifies the operation
2682    and XARG is the operand.  NOCONVERT nonzero suppresses
2683    the default promotions (such as from short to int).  */
2684
2685 tree
2686 build_unary_op (code, xarg, noconvert)
2687      enum tree_code code;
2688      tree xarg;
2689      int noconvert;
2690 {
2691   /* No default_conversion here.  It causes trouble for ADDR_EXPR.  */
2692   register tree arg = xarg;
2693   register tree argtype = 0;
2694   register enum tree_code typecode = TREE_CODE (TREE_TYPE (arg));
2695   tree val;
2696
2697   if (typecode == ERROR_MARK)
2698     return error_mark_node;
2699   if (typecode == ENUMERAL_TYPE)
2700     typecode = INTEGER_TYPE;
2701
2702   switch (code)
2703     {
2704     case CONVERT_EXPR:
2705       /* This is used for unary plus, because a CONVERT_EXPR
2706          is enough to prevent anybody from looking inside for
2707          associativity, but won't generate any code.  */
2708       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
2709             || typecode == COMPLEX_TYPE))
2710         {
2711           error ("wrong type argument to unary plus");
2712           return error_mark_node;
2713         }
2714       else if (!noconvert)
2715         arg = default_conversion (arg);
2716       break;
2717
2718     case NEGATE_EXPR:
2719       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
2720             || typecode == COMPLEX_TYPE))
2721         {
2722           error ("wrong type argument to unary minus");
2723           return error_mark_node;
2724         }
2725       else if (!noconvert)
2726         arg = default_conversion (arg);
2727       break;
2728
2729     case BIT_NOT_EXPR:
2730       if (typecode == COMPLEX_TYPE)
2731         {
2732           code = CONJ_EXPR;
2733           if (!noconvert)
2734             arg = default_conversion (arg);
2735         }
2736       else if (typecode != INTEGER_TYPE)
2737         {
2738           error ("wrong type argument to bit-complement");
2739           return error_mark_node;
2740         }
2741       else if (!noconvert)
2742         arg = default_conversion (arg);
2743       break;
2744
2745     case ABS_EXPR:
2746       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
2747             || typecode == COMPLEX_TYPE))
2748         {
2749           error ("wrong type argument to abs");
2750           return error_mark_node;
2751         }
2752       else if (!noconvert)
2753         arg = default_conversion (arg);
2754       break;
2755
2756     case CONJ_EXPR:
2757       /* Conjugating a real value is a no-op, but allow it anyway.  */
2758       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
2759             || typecode == COMPLEX_TYPE))
2760         {
2761           error ("wrong type argument to conjugation");
2762           return error_mark_node;
2763         }
2764       else if (!noconvert)
2765         arg = default_conversion (arg);
2766       break;
2767
2768     case TRUTH_NOT_EXPR:
2769       if (typecode != INTEGER_TYPE
2770           && typecode != REAL_TYPE && typecode != POINTER_TYPE
2771           && typecode != COMPLEX_TYPE
2772           /* These will convert to a pointer.  */
2773           && typecode != ARRAY_TYPE && typecode != FUNCTION_TYPE)
2774         {
2775           error ("wrong type argument to unary exclamation mark");
2776           return error_mark_node;
2777         }
2778       arg = truthvalue_conversion (arg);
2779       return invert_truthvalue (arg);
2780
2781     case NOP_EXPR:
2782       break;
2783
2784     case REALPART_EXPR:
2785       if (TREE_CODE (arg) == COMPLEX_CST)
2786         return TREE_REALPART (arg);
2787       else if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
2788         return fold (build1 (REALPART_EXPR, TREE_TYPE (TREE_TYPE (arg)), arg));
2789       else
2790         return arg;
2791
2792     case IMAGPART_EXPR:
2793       if (TREE_CODE (arg) == COMPLEX_CST)
2794         return TREE_IMAGPART (arg);
2795       else if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
2796         return fold (build1 (IMAGPART_EXPR, TREE_TYPE (TREE_TYPE (arg)), arg));
2797       else
2798         return convert (TREE_TYPE (arg), integer_zero_node);
2799       
2800     case PREINCREMENT_EXPR:
2801     case POSTINCREMENT_EXPR:
2802     case PREDECREMENT_EXPR:
2803     case POSTDECREMENT_EXPR:
2804       /* Handle complex lvalues (when permitted)
2805          by reduction to simpler cases.  */
2806
2807       val = unary_complex_lvalue (code, arg);
2808       if (val != 0)
2809         return val;
2810
2811       /* Increment or decrement the real part of the value,
2812          and don't change the imaginary part.  */
2813       if (typecode == COMPLEX_TYPE)
2814         {
2815           tree real, imag;
2816
2817           arg = stabilize_reference (arg);
2818           real = build_unary_op (REALPART_EXPR, arg, 1);
2819           imag = build_unary_op (IMAGPART_EXPR, arg, 1);
2820           return build (COMPLEX_EXPR, TREE_TYPE (arg),
2821                         build_unary_op (code, real, 1), imag);
2822         }
2823
2824       /* Report invalid types.  */
2825
2826       if (typecode != POINTER_TYPE
2827           && typecode != INTEGER_TYPE && typecode != REAL_TYPE)
2828         {
2829           error ("wrong type argument to %s",
2830                  code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR
2831                  ? "increment" : "decrement");
2832           return error_mark_node;
2833         }
2834
2835       {
2836         register tree inc;
2837         tree result_type = TREE_TYPE (arg);
2838
2839         arg = get_unwidened (arg, 0);
2840         argtype = TREE_TYPE (arg);
2841
2842         /* Compute the increment.  */
2843
2844         if (typecode == POINTER_TYPE)
2845           {
2846             /* If pointer target is an undefined struct,
2847                we just cannot know how to do the arithmetic.  */
2848             if (TYPE_SIZE (TREE_TYPE (result_type)) == 0)
2849               error ("%s of pointer to unknown structure",
2850                      code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR
2851                      ? "increment" : "decrement");
2852             else if ((pedantic || warn_pointer_arith)
2853                      && (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE
2854                          || TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE))
2855               pedwarn ("wrong type argument to %s",
2856                        code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR
2857                        ? "increment" : "decrement");
2858             inc = c_size_in_bytes (TREE_TYPE (result_type));
2859           }
2860         else
2861           inc = integer_one_node;
2862
2863         inc = convert (argtype, inc);
2864
2865         /* Handle incrementing a cast-expression.  */
2866
2867         while (1)
2868           switch (TREE_CODE (arg))
2869             {
2870             case NOP_EXPR:
2871             case CONVERT_EXPR:
2872             case FLOAT_EXPR:
2873             case FIX_TRUNC_EXPR:
2874             case FIX_FLOOR_EXPR:
2875             case FIX_ROUND_EXPR:
2876             case FIX_CEIL_EXPR:
2877               pedantic_lvalue_warning (CONVERT_EXPR);
2878               /* If the real type has the same machine representation
2879                  as the type it is cast to, we can make better output
2880                  by adding directly to the inside of the cast.  */
2881               if ((TREE_CODE (TREE_TYPE (arg))
2882                    == TREE_CODE (TREE_TYPE (TREE_OPERAND (arg, 0))))
2883                   && (TYPE_MODE (TREE_TYPE (arg))
2884                       == TYPE_MODE (TREE_TYPE (TREE_OPERAND (arg, 0)))))
2885                 arg = TREE_OPERAND (arg, 0);
2886               else
2887                 {
2888                   tree incremented, modify, value;
2889                   arg = stabilize_reference (arg);
2890                   if (code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR)
2891                     value = arg;
2892                   else
2893                     value = save_expr (arg);
2894                   incremented = build (((code == PREINCREMENT_EXPR
2895                                          || code == POSTINCREMENT_EXPR)
2896                                         ? PLUS_EXPR : MINUS_EXPR),
2897                                        argtype, value, inc);
2898                   TREE_SIDE_EFFECTS (incremented) = 1;
2899                   modify = build_modify_expr (arg, NOP_EXPR, incremented);
2900                   value = build (COMPOUND_EXPR, TREE_TYPE (arg), modify, value);
2901                   TREE_USED (value) = 1;
2902                   return value;
2903                 }
2904               break;
2905
2906             default:
2907               goto give_up;
2908             }
2909       give_up:
2910
2911         /* Complain about anything else that is not a true lvalue.  */
2912         if (!lvalue_or_else (arg, ((code == PREINCREMENT_EXPR
2913                                     || code == POSTINCREMENT_EXPR)
2914                                    ? "invalid lvalue in increment"
2915                                    : "invalid lvalue in decrement")))
2916           return error_mark_node;
2917
2918         /* Report a read-only lvalue.  */
2919         if (TREE_READONLY (arg))
2920           readonly_warning (arg, 
2921                             ((code == PREINCREMENT_EXPR
2922                               || code == POSTINCREMENT_EXPR)
2923                              ? "increment" : "decrement"));
2924
2925         val = build (code, TREE_TYPE (arg), arg, inc);
2926         TREE_SIDE_EFFECTS (val) = 1;
2927         val = convert (result_type, val);
2928         if (TREE_CODE (val) != code)
2929           TREE_NO_UNUSED_WARNING (val) = 1;
2930         return val;
2931       }
2932
2933     case ADDR_EXPR:
2934       /* Note that this operation never does default_conversion
2935          regardless of NOCONVERT.  */
2936
2937       /* Let &* cancel out to simplify resulting code.  */
2938       if (TREE_CODE (arg) == INDIRECT_REF)
2939         {
2940           /* Don't let this be an lvalue.  */
2941           if (lvalue_p (TREE_OPERAND (arg, 0)))
2942             return non_lvalue (TREE_OPERAND (arg, 0));
2943           return TREE_OPERAND (arg, 0);
2944         }
2945
2946       /* For &x[y], return x+y */
2947       if (TREE_CODE (arg) == ARRAY_REF)
2948         {
2949           if (mark_addressable (TREE_OPERAND (arg, 0)) == 0)
2950             return error_mark_node;
2951           return build_binary_op (PLUS_EXPR, TREE_OPERAND (arg, 0),
2952                                   TREE_OPERAND (arg, 1), 1);
2953         }
2954
2955       /* Handle complex lvalues (when permitted)
2956          by reduction to simpler cases.  */
2957       val = unary_complex_lvalue (code, arg);
2958       if (val != 0)
2959         return val;
2960
2961 #if 0 /* Turned off because inconsistent;
2962          float f; *&(int)f = 3.4 stores in int format
2963          whereas (int)f = 3.4 stores in float format.  */
2964       /* Address of a cast is just a cast of the address
2965          of the operand of the cast.  */
2966       switch (TREE_CODE (arg))
2967         {
2968         case NOP_EXPR:
2969         case CONVERT_EXPR:
2970         case FLOAT_EXPR:
2971         case FIX_TRUNC_EXPR:
2972         case FIX_FLOOR_EXPR:
2973         case FIX_ROUND_EXPR:
2974         case FIX_CEIL_EXPR:
2975           if (pedantic)
2976             pedwarn ("ANSI C forbids the address of a cast expression");
2977           return convert (build_pointer_type (TREE_TYPE (arg)),
2978                           build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0),
2979                                           0));
2980         }
2981 #endif
2982
2983       /* Allow the address of a constructor if all the elements
2984          are constant.  */
2985       if (TREE_CODE (arg) == CONSTRUCTOR && TREE_CONSTANT (arg))
2986         ;
2987       /* Anything not already handled and not a true memory reference
2988          is an error.  */
2989       else if (typecode != FUNCTION_TYPE
2990                && !lvalue_or_else (arg, "invalid lvalue in unary `&'"))
2991         return error_mark_node;
2992
2993       /* Ordinary case; arg is a COMPONENT_REF or a decl.  */
2994       argtype = TREE_TYPE (arg);
2995       /* If the lvalue is const or volatile, merge that into the type
2996          to which the address will point.  Note that you can't get a
2997          restricted pointer by taking the address of something, so we
2998          only have to deal with `const' and `volatile' here.  */
2999       if (TREE_CODE_CLASS (TREE_CODE (arg)) == 'd'
3000           || TREE_CODE_CLASS (TREE_CODE (arg)) == 'r')
3001         {
3002           if (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg))
3003             argtype = c_build_type_variant (argtype,
3004                                             TREE_READONLY (arg),
3005                                             TREE_THIS_VOLATILE (arg));
3006         }
3007
3008       argtype = build_pointer_type (argtype);
3009
3010       if (mark_addressable (arg) == 0)
3011         return error_mark_node;
3012
3013       {
3014         tree addr;
3015
3016         if (TREE_CODE (arg) == COMPONENT_REF)
3017           {
3018             tree field = TREE_OPERAND (arg, 1);
3019
3020             addr = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0), 0);
3021
3022             if (DECL_C_BIT_FIELD (field))
3023               {
3024                 error ("attempt to take address of bit-field structure member `%s'",
3025                        IDENTIFIER_POINTER (DECL_NAME (field)));
3026                 return error_mark_node;
3027               }
3028
3029             addr = convert (argtype, addr);
3030
3031             if (! integer_zerop (DECL_FIELD_BITPOS (field)))
3032               {
3033                 tree offset
3034                   = size_binop (EASY_DIV_EXPR, DECL_FIELD_BITPOS (field),
3035                                 size_int (BITS_PER_UNIT));
3036                 int flag = TREE_CONSTANT (addr);
3037                 addr = fold (build (PLUS_EXPR, argtype,
3038                                     addr, convert (argtype, offset)));
3039                 TREE_CONSTANT (addr) = flag;
3040               }
3041           }
3042         else
3043           addr = build1 (code, argtype, arg);
3044
3045         /* Address of a static or external variable or
3046            file-scope function counts as a constant.  */
3047         if (staticp (arg)
3048             && ! (TREE_CODE (arg) == FUNCTION_DECL
3049                   && DECL_CONTEXT (arg) != 0))
3050           TREE_CONSTANT (addr) = 1;
3051         return addr;
3052       }
3053
3054     default:
3055       break;
3056     }
3057
3058   if (argtype == 0)
3059     argtype = TREE_TYPE (arg);
3060   return fold (build1 (code, argtype, arg));
3061 }
3062
3063 #if 0
3064 /* If CONVERSIONS is a conversion expression or a nested sequence of such,
3065    convert ARG with the same conversions in the same order
3066    and return the result.  */
3067
3068 static tree
3069 convert_sequence (conversions, arg)
3070      tree conversions;
3071      tree arg;
3072 {
3073   switch (TREE_CODE (conversions))
3074     {
3075     case NOP_EXPR:
3076     case CONVERT_EXPR:
3077     case FLOAT_EXPR:
3078     case FIX_TRUNC_EXPR:
3079     case FIX_FLOOR_EXPR:
3080     case FIX_ROUND_EXPR:
3081     case FIX_CEIL_EXPR:
3082       return convert (TREE_TYPE (conversions),
3083                       convert_sequence (TREE_OPERAND (conversions, 0),
3084                                         arg));
3085
3086     default:
3087       return arg;
3088     }
3089 }
3090 #endif /* 0 */
3091
3092 /* Return nonzero if REF is an lvalue valid for this language.
3093    Lvalues can be assigned, unless their type has TYPE_READONLY.
3094    Lvalues can have their address taken, unless they have DECL_REGISTER.  */
3095
3096 int
3097 lvalue_p (ref)
3098      tree ref;
3099 {
3100   register enum tree_code code = TREE_CODE (ref);
3101
3102   switch (code)
3103     {
3104     case REALPART_EXPR:
3105     case IMAGPART_EXPR:
3106     case COMPONENT_REF:
3107       return lvalue_p (TREE_OPERAND (ref, 0));
3108
3109     case STRING_CST:
3110       return 1;
3111
3112     case INDIRECT_REF:
3113     case ARRAY_REF:
3114     case VAR_DECL:
3115     case PARM_DECL:
3116     case RESULT_DECL:
3117     case ERROR_MARK:
3118       return (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE
3119               && TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE);
3120
3121     case BIND_EXPR:
3122     case RTL_EXPR:
3123       return TREE_CODE (TREE_TYPE (ref)) == ARRAY_TYPE;
3124
3125     default:
3126       return 0;
3127     }
3128 }
3129
3130 /* Return nonzero if REF is an lvalue valid for this language;
3131    otherwise, print an error message and return zero.  */
3132
3133 int
3134 lvalue_or_else (ref, msgid)
3135      tree ref;
3136      const char *msgid;
3137 {
3138   int win = lvalue_p (ref);
3139
3140   if (! win)
3141     error ("%s", msgid);
3142
3143   return win;
3144 }
3145
3146 /* Apply unary lvalue-demanding operator CODE to the expression ARG
3147    for certain kinds of expressions which are not really lvalues
3148    but which we can accept as lvalues.
3149
3150    If ARG is not a kind of expression we can handle, return zero.  */
3151    
3152 static tree
3153 unary_complex_lvalue (code, arg)
3154      enum tree_code code;
3155      tree arg;
3156 {
3157   /* Handle (a, b) used as an "lvalue".  */
3158   if (TREE_CODE (arg) == COMPOUND_EXPR)
3159     {
3160       tree real_result = build_unary_op (code, TREE_OPERAND (arg, 1), 0);
3161
3162       /* If this returns a function type, it isn't really being used as
3163          an lvalue, so don't issue a warning about it.  */
3164       if (TREE_CODE (TREE_TYPE (arg)) != FUNCTION_TYPE)
3165         pedantic_lvalue_warning (COMPOUND_EXPR);
3166
3167       return build (COMPOUND_EXPR, TREE_TYPE (real_result),
3168                     TREE_OPERAND (arg, 0), real_result);
3169     }
3170
3171   /* Handle (a ? b : c) used as an "lvalue".  */
3172   if (TREE_CODE (arg) == COND_EXPR)
3173     {
3174       pedantic_lvalue_warning (COND_EXPR);
3175       if (TREE_CODE (TREE_TYPE (arg)) != FUNCTION_TYPE)
3176         pedantic_lvalue_warning (COMPOUND_EXPR);
3177
3178       return (build_conditional_expr
3179               (TREE_OPERAND (arg, 0),
3180                build_unary_op (code, TREE_OPERAND (arg, 1), 0),
3181                build_unary_op (code, TREE_OPERAND (arg, 2), 0)));
3182     }
3183
3184   return 0;
3185 }
3186
3187 /* If pedantic, warn about improper lvalue.   CODE is either COND_EXPR
3188    COMPOUND_EXPR, or CONVERT_EXPR (for casts).  */
3189
3190 static void
3191 pedantic_lvalue_warning (code)
3192      enum tree_code code;
3193 {
3194   if (pedantic)
3195     switch (code)
3196       {
3197       case COND_EXPR:
3198         pedwarn ("ANSI C forbids use of conditional expressions as lvalues");
3199         break;
3200       case COMPOUND_EXPR:
3201         pedwarn ("ANSI C forbids use of compound expressions as lvalues");
3202         break;
3203       default:
3204         pedwarn ("ANSI C forbids use of cast expressions as lvalues");
3205         break;
3206       }
3207 }
3208 \f
3209 /* Warn about storing in something that is `const'.  */
3210
3211 void
3212 readonly_warning (arg, msgid)
3213      tree arg;
3214      const char *msgid;
3215 {
3216   /* Forbid assignments to iterators.  */
3217   if (TREE_CODE (arg) == VAR_DECL && ITERATOR_P (arg))
3218     pedwarn ("%s of iterator `%s'",  _(msgid), 
3219              IDENTIFIER_POINTER (DECL_NAME (arg)));
3220
3221   if (TREE_CODE (arg) == COMPONENT_REF)
3222     {
3223       if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg, 0))))
3224         readonly_warning (TREE_OPERAND (arg, 0), msgid);
3225       else
3226         pedwarn ("%s of read-only member `%s'", _(msgid),
3227                  IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (arg, 1))));
3228     }
3229   else if (TREE_CODE (arg) == VAR_DECL)
3230     pedwarn ("%s of read-only variable `%s'", _(msgid),
3231              IDENTIFIER_POINTER (DECL_NAME (arg)));
3232   else
3233     pedwarn ("%s of read-only location", _(msgid));
3234 }
3235 \f
3236 /* Mark EXP saying that we need to be able to take the
3237    address of it; it should not be allocated in a register.
3238    Value is 1 if successful.  */
3239
3240 int
3241 mark_addressable (exp)
3242      tree exp;
3243 {
3244   register tree x = exp;
3245   while (1)
3246     switch (TREE_CODE (x))
3247       {
3248       case COMPONENT_REF:
3249         if (DECL_C_BIT_FIELD (TREE_OPERAND (x, 1)))
3250           {
3251             error ("cannot take address of bitfield `%s'",
3252                    IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (x, 1))));
3253             return 0;
3254           }
3255
3256         /* ... fall through ...  */
3257
3258       case ADDR_EXPR:
3259       case ARRAY_REF:
3260       case REALPART_EXPR:
3261       case IMAGPART_EXPR:
3262         x = TREE_OPERAND (x, 0);
3263         break;
3264
3265       case CONSTRUCTOR:
3266         TREE_ADDRESSABLE (x) = 1;
3267         return 1;
3268
3269       case VAR_DECL:
3270       case CONST_DECL:
3271       case PARM_DECL:
3272       case RESULT_DECL:
3273         if (DECL_REGISTER (x) && !TREE_ADDRESSABLE (x)
3274             && DECL_NONLOCAL (x))
3275           {
3276             if (TREE_PUBLIC (x))
3277               {
3278                 error ("global register variable `%s' used in nested function",
3279                        IDENTIFIER_POINTER (DECL_NAME (x)));
3280                 return 0;
3281               }
3282             pedwarn ("register variable `%s' used in nested function",
3283                      IDENTIFIER_POINTER (DECL_NAME (x)));
3284           }
3285         else if (DECL_REGISTER (x) && !TREE_ADDRESSABLE (x))
3286           {
3287             if (TREE_PUBLIC (x))
3288               {
3289                 error ("address of global register variable `%s' requested",
3290                        IDENTIFIER_POINTER (DECL_NAME (x)));
3291                 return 0;
3292               }
3293
3294             /* If we are making this addressable due to its having
3295                volatile components, give a different error message.  Also
3296                handle the case of an unnamed parameter by not trying
3297                to give the name.  */
3298
3299             else if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (x)))
3300               {
3301                 error ("cannot put object with volatile field into register");
3302                 return 0;
3303               }
3304
3305             pedwarn ("address of register variable `%s' requested",
3306                      IDENTIFIER_POINTER (DECL_NAME (x)));
3307           }
3308         put_var_into_stack (x);
3309
3310         /* drops in */
3311       case FUNCTION_DECL:
3312         TREE_ADDRESSABLE (x) = 1;
3313 #if 0  /* poplevel deals with this now.  */
3314         if (DECL_CONTEXT (x) == 0)
3315           TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (x)) = 1;
3316 #endif
3317
3318       default:
3319         return 1;
3320     }
3321 }
3322 \f
3323 /* Build and return a conditional expression IFEXP ? OP1 : OP2.  */
3324
3325 tree
3326 build_conditional_expr (ifexp, op1, op2)
3327      tree ifexp, op1, op2;
3328 {
3329   register tree type1;
3330   register tree type2;
3331   register enum tree_code code1;
3332   register enum tree_code code2;
3333   register tree result_type = NULL;
3334   tree orig_op1 = op1, orig_op2 = op2;
3335
3336   ifexp = truthvalue_conversion (default_conversion (ifexp));
3337
3338 #if 0 /* Produces wrong result if within sizeof.  */
3339   /* Don't promote the operands separately if they promote
3340      the same way.  Return the unpromoted type and let the combined
3341      value get promoted if necessary.  */
3342
3343   if (TREE_TYPE (op1) == TREE_TYPE (op2)
3344       && TREE_CODE (TREE_TYPE (op1)) != ARRAY_TYPE
3345       && TREE_CODE (TREE_TYPE (op1)) != ENUMERAL_TYPE
3346       && TREE_CODE (TREE_TYPE (op1)) != FUNCTION_TYPE)
3347     {
3348       if (TREE_CODE (ifexp) == INTEGER_CST)
3349         return pedantic_non_lvalue (integer_zerop (ifexp) ? op2 : op1);
3350
3351       return fold (build (COND_EXPR, TREE_TYPE (op1), ifexp, op1, op2));
3352     }
3353 #endif
3354
3355   /* Promote both alternatives.  */
3356
3357   if (TREE_CODE (TREE_TYPE (op1)) != VOID_TYPE)
3358     op1 = default_conversion (op1);
3359   if (TREE_CODE (TREE_TYPE (op2)) != VOID_TYPE)
3360     op2 = default_conversion (op2);
3361
3362   if (TREE_CODE (ifexp) == ERROR_MARK
3363       || TREE_CODE (TREE_TYPE (op1)) == ERROR_MARK
3364       || TREE_CODE (TREE_TYPE (op2)) == ERROR_MARK)
3365     return error_mark_node;
3366
3367   type1 = TREE_TYPE (op1);
3368   code1 = TREE_CODE (type1);
3369   type2 = TREE_TYPE (op2);
3370   code2 = TREE_CODE (type2);
3371       
3372   /* Quickly detect the usual case where op1 and op2 have the same type
3373      after promotion.  */
3374   if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2))
3375     {
3376       if (type1 == type2)
3377         result_type = type1;
3378       else
3379         result_type = TYPE_MAIN_VARIANT (type1);
3380     }
3381   else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE)
3382            && (code2 == INTEGER_TYPE || code2 == REAL_TYPE))
3383     {
3384       result_type = common_type (type1, type2);
3385
3386       /* If -Wsign-compare, warn here if type1 and type2 have
3387          different signedness.  We'll promote the signed to unsigned
3388          and later code won't know it used to be different.
3389          Do this check on the original types, so that explicit casts
3390          will be considered, but default promotions won't.  */
3391       if ((warn_sign_compare < 0 ? extra_warnings : warn_sign_compare)
3392           && !skip_evaluation)
3393         {
3394           int unsigned_op1 = TREE_UNSIGNED (TREE_TYPE (orig_op1));
3395           int unsigned_op2 = TREE_UNSIGNED (TREE_TYPE (orig_op2));
3396
3397           if (unsigned_op1 ^ unsigned_op2)
3398             {
3399               /* Do not warn if the result type is signed, since the
3400                  signed type will only be chosen if it can represent
3401                  all the values of the unsigned type.  */
3402               if (! TREE_UNSIGNED (result_type))
3403                 /* OK */;
3404               /* Do not warn if the signed quantity is an unsuffixed
3405                  integer literal (or some static constant expression
3406                  involving such literals) and it is non-negative.  */
3407               else if ((unsigned_op2 && TREE_CODE (op1) == INTEGER_CST
3408                         && tree_int_cst_sgn (op1) >= 0)
3409                        || (unsigned_op1 && TREE_CODE (op2) == INTEGER_CST
3410                            && tree_int_cst_sgn (op2) >= 0))
3411                 /* OK */;
3412               else
3413                 warning ("signed and unsigned type in conditional expression");
3414             }
3415         }
3416     }
3417   else if (code1 == VOID_TYPE || code2 == VOID_TYPE)
3418     {
3419       if (pedantic && (code1 != VOID_TYPE || code2 != VOID_TYPE))
3420         pedwarn ("ANSI C forbids conditional expr with only one void side");
3421       result_type = void_type_node;
3422     }
3423   else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE)
3424     {
3425       if (comp_target_types (type1, type2))
3426         result_type = common_type (type1, type2);
3427       else if (integer_zerop (op1) && TREE_TYPE (type1) == void_type_node
3428                && TREE_CODE (orig_op1) != NOP_EXPR)
3429         result_type = qualify_type (type2, type1);
3430       else if (integer_zerop (op2) && TREE_TYPE (type2) == void_type_node
3431                && TREE_CODE (orig_op2) != NOP_EXPR)
3432         result_type = qualify_type (type1, type2);
3433       else if (TYPE_MAIN_VARIANT (TREE_TYPE (type1)) == void_type_node)
3434         {
3435           if (pedantic && TREE_CODE (TREE_TYPE (type2)) == FUNCTION_TYPE)
3436             pedwarn ("ANSI C forbids conditional expr between `void *' and function pointer");
3437           result_type = qualify_type (type1, type2);
3438         }
3439       else if (TYPE_MAIN_VARIANT (TREE_TYPE (type2)) == void_type_node)
3440         {
3441           if (pedantic && TREE_CODE (TREE_TYPE (type1)) == FUNCTION_TYPE)
3442             pedwarn ("ANSI C forbids conditional expr between `void *' and function pointer");
3443           result_type = qualify_type (type2, type1);
3444         }
3445       else
3446         {
3447           pedwarn ("pointer type mismatch in conditional expression");
3448           result_type = build_pointer_type (void_type_node);
3449         }
3450     }
3451   else if (code1 == POINTER_TYPE && code2 == INTEGER_TYPE)
3452     {
3453       if (! integer_zerop (op2))
3454         pedwarn ("pointer/integer type mismatch in conditional expression");
3455       else
3456         {
3457           op2 = null_pointer_node;
3458 #if 0  /* The spec seems to say this is permitted.  */
3459           if (pedantic && TREE_CODE (type1) == FUNCTION_TYPE)
3460             pedwarn ("ANSI C forbids conditional expr between 0 and function pointer");
3461 #endif
3462         }
3463       result_type = type1;
3464     }
3465   else if (code2 == POINTER_TYPE && code1 == INTEGER_TYPE)
3466     {
3467       if (!integer_zerop (op1))
3468         pedwarn ("pointer/integer type mismatch in conditional expression");
3469       else
3470         {
3471           op1 = null_pointer_node;
3472 #if 0  /* The spec seems to say this is permitted.  */
3473           if (pedantic && TREE_CODE (type2) == FUNCTION_TYPE)
3474             pedwarn ("ANSI C forbids conditional expr between 0 and function pointer");
3475 #endif
3476         }
3477       result_type = type2;
3478     }
3479
3480   if (!result_type)
3481     {
3482       if (flag_cond_mismatch)
3483         result_type = void_type_node;
3484       else
3485         {
3486           error ("type mismatch in conditional expression");
3487           return error_mark_node;
3488         }
3489     }
3490
3491   /* Merge const and volatile flags of the incoming types.  */
3492   result_type
3493     = build_type_variant (result_type,
3494                           TREE_READONLY (op1) || TREE_READONLY (op2),
3495                           TREE_THIS_VOLATILE (op1) || TREE_THIS_VOLATILE (op2));
3496
3497   if (result_type != TREE_TYPE (op1))
3498     op1 = convert_and_check (result_type, op1);
3499   if (result_type != TREE_TYPE (op2))
3500     op2 = convert_and_check (result_type, op2);
3501     
3502   if (TREE_CODE (ifexp) == INTEGER_CST)
3503     return pedantic_non_lvalue (integer_zerop (ifexp) ? op2 : op1);
3504
3505   return fold (build (COND_EXPR, result_type, ifexp, op1, op2));
3506 }
3507 \f
3508 /* Given a list of expressions, return a compound expression
3509    that performs them all and returns the value of the last of them.  */
3510
3511 tree
3512 build_compound_expr (list)
3513      tree list;
3514 {
3515   return internal_build_compound_expr (list, TRUE);
3516 }
3517
3518 static tree
3519 internal_build_compound_expr (list, first_p)
3520      tree list;
3521      int first_p;
3522 {
3523   register tree rest;
3524
3525   if (TREE_CHAIN (list) == 0)
3526     {
3527 #if 0 /* If something inside inhibited lvalueness, we should not override.  */
3528       /* Consider (x, y+0), which is not an lvalue since y+0 is not.  */
3529
3530       /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
3531       if (TREE_CODE (list) == NON_LVALUE_EXPR)
3532         list = TREE_OPERAND (list, 0);
3533 #endif
3534
3535       /* Don't let (0, 0) be null pointer constant.  */
3536       if (!first_p && integer_zerop (TREE_VALUE (list)))
3537         return non_lvalue (TREE_VALUE (list));
3538       return TREE_VALUE (list);
3539     }
3540
3541   if (TREE_CHAIN (list) != 0 && TREE_CHAIN (TREE_CHAIN (list)) == 0)
3542     {
3543       /* Convert arrays to pointers when there really is a comma operator.  */
3544       if (TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (list)))) == ARRAY_TYPE)
3545         TREE_VALUE (TREE_CHAIN (list))
3546           = default_conversion (TREE_VALUE (TREE_CHAIN (list)));
3547     }
3548
3549   rest = internal_build_compound_expr (TREE_CHAIN (list), FALSE);
3550
3551   if (! TREE_SIDE_EFFECTS (TREE_VALUE (list)))
3552     {
3553       /* The left-hand operand of a comma expression is like an expression
3554          statement: with -W or -Wunused, we should warn if it doesn't have
3555          any side-effects, unless it was explicitly cast to (void).  */
3556       if ((extra_warnings || warn_unused)
3557            && ! (TREE_CODE (TREE_VALUE (list)) == CONVERT_EXPR
3558                 && TREE_TYPE (TREE_VALUE (list)) == void_type_node))
3559         warning ("left-hand operand of comma expression has no effect");
3560
3561       /* When pedantic, a compound expression can be neither an lvalue
3562          nor an integer constant expression.  */
3563       if (! pedantic)
3564         return rest;
3565     }
3566
3567   /* With -Wunused, we should also warn if the left-hand operand does have
3568      side-effects, but computes a value which is not used.  For example, in
3569      `foo() + bar(), baz()' the result of the `+' operator is not used,
3570      so we should issue a warning.  */
3571   else if (warn_unused)
3572     warn_if_unused_value (TREE_VALUE (list));
3573
3574   return build (COMPOUND_EXPR, TREE_TYPE (rest), TREE_VALUE (list), rest);
3575 }
3576
3577 /* Build an expression representing a cast to type TYPE of expression EXPR.  */
3578
3579 tree
3580 build_c_cast (type, expr)
3581      register tree type;
3582      tree expr;
3583 {
3584   register tree value = expr;
3585   
3586   if (type == error_mark_node || expr == error_mark_node)
3587     return error_mark_node;
3588   type = TYPE_MAIN_VARIANT (type);
3589
3590 #if 0
3591   /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
3592   if (TREE_CODE (value) == NON_LVALUE_EXPR)
3593     value = TREE_OPERAND (value, 0);
3594 #endif
3595
3596   if (TREE_CODE (type) == ARRAY_TYPE)
3597     {
3598       error ("cast specifies array type");
3599       return error_mark_node;
3600     }
3601
3602   if (TREE_CODE (type) == FUNCTION_TYPE)
3603     {
3604       error ("cast specifies function type");
3605       return error_mark_node;
3606     }
3607
3608   if (type == TREE_TYPE (value))
3609     {
3610       if (pedantic)
3611         {
3612           if (TREE_CODE (type) == RECORD_TYPE
3613               || TREE_CODE (type) == UNION_TYPE)
3614             pedwarn ("ANSI C forbids casting nonscalar to the same type");
3615         }
3616     }
3617   else if (TREE_CODE (type) == UNION_TYPE)
3618     {
3619       tree field;
3620       if (TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
3621           || TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE)
3622         value = default_conversion (value);
3623
3624       for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
3625         if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field)),
3626                        TYPE_MAIN_VARIANT (TREE_TYPE (value))))
3627           break;
3628
3629       if (field)
3630         {
3631           const char *name;
3632           tree t;
3633
3634           if (pedantic)
3635             pedwarn ("ANSI C forbids casts to union type");
3636           if (TYPE_NAME (type) != 0)
3637             {
3638               if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
3639                 name = IDENTIFIER_POINTER (TYPE_NAME (type));
3640               else
3641                 name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
3642             }
3643           else
3644             name = "";
3645           t = digest_init (type, build (CONSTRUCTOR, type, NULL_TREE,
3646                                         build_tree_list (field, value)),
3647                            0, 0);
3648           TREE_CONSTANT (t) = TREE_CONSTANT (value);
3649           return t;
3650         }
3651       error ("cast to union type from type not present in union");
3652       return error_mark_node;
3653     }
3654   else
3655     {
3656       tree otype, ovalue;
3657
3658       /* If casting to void, avoid the error that would come
3659          from default_conversion in the case of a non-lvalue array.  */
3660       if (type == void_type_node)
3661         return build1 (CONVERT_EXPR, type, value);
3662
3663       /* Convert functions and arrays to pointers,
3664          but don't convert any other types.  */
3665       if (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE
3666           || TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE)
3667         value = default_conversion (value);
3668       otype = TREE_TYPE (value);
3669
3670       /* Optionally warn about potentially worrisome casts.  */
3671
3672       if (warn_cast_qual
3673           && TREE_CODE (type) == POINTER_TYPE
3674           && TREE_CODE (otype) == POINTER_TYPE)
3675         {
3676           tree in_type = type;
3677           tree in_otype = otype;
3678           int warn = 0;
3679
3680           /* Check that the qualifiers on IN_TYPE are a superset of
3681              the qualifiers of IN_OTYPE.  The outermost level of
3682              POINTER_TYPE nodes is uninteresting and we stop as soon
3683              as we hit a non-POINTER_TYPE node on either type.  */
3684           do
3685             {
3686               in_otype = TREE_TYPE (in_otype);
3687               in_type = TREE_TYPE (in_type);
3688               warn |= (TYPE_QUALS (in_otype) & ~TYPE_QUALS (in_type));
3689             }
3690           while (TREE_CODE (in_type) == POINTER_TYPE
3691                  && TREE_CODE (in_otype) == POINTER_TYPE);
3692
3693           if (warn)
3694             /* There are qualifiers present in IN_OTYPE that are not
3695                present in IN_TYPE.  */
3696             pedwarn ("cast discards qualifiers from pointer target type");
3697         }
3698
3699       /* Warn about possible alignment problems.  */
3700       if (STRICT_ALIGNMENT && warn_cast_align
3701           && TREE_CODE (type) == POINTER_TYPE
3702           && TREE_CODE (otype) == POINTER_TYPE
3703           && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE
3704           && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
3705           /* Don't warn about opaque types, where the actual alignment
3706              restriction is unknown.  */
3707           && !((TREE_CODE (TREE_TYPE (otype)) == UNION_TYPE
3708                 || TREE_CODE (TREE_TYPE (otype)) == RECORD_TYPE)
3709                && TYPE_MODE (TREE_TYPE (otype)) == VOIDmode)
3710           && TYPE_ALIGN (TREE_TYPE (type)) > TYPE_ALIGN (TREE_TYPE (otype)))
3711         warning ("cast increases required alignment of target type");
3712
3713       if (TREE_CODE (type) == INTEGER_TYPE
3714           && TREE_CODE (otype) == POINTER_TYPE
3715           && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
3716           && !TREE_CONSTANT (value))
3717         warning ("cast from pointer to integer of different size");
3718
3719       if (warn_bad_function_cast
3720           && TREE_CODE (value) == CALL_EXPR
3721           && TREE_CODE (type) != TREE_CODE (otype))
3722         warning ("cast does not match function type");
3723
3724       if (TREE_CODE (type) == POINTER_TYPE
3725           && TREE_CODE (otype) == INTEGER_TYPE
3726           && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
3727 #if 0
3728           /* Don't warn about converting 0 to pointer,
3729              provided the 0 was explicit--not cast or made by folding.  */
3730           && !(TREE_CODE (value) == INTEGER_CST && integer_zerop (value))
3731 #endif
3732           /* Don't warn about converting any constant.  */
3733           && !TREE_CONSTANT (value))
3734         warning ("cast to pointer from integer of different size");
3735
3736       ovalue = value;
3737       value = convert (type, value);
3738
3739       /* Ignore any integer overflow caused by the cast.  */
3740       if (TREE_CODE (value) == INTEGER_CST)
3741         {
3742           TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue);
3743           TREE_CONSTANT_OVERFLOW (value) = TREE_CONSTANT_OVERFLOW (ovalue);
3744         }
3745     }
3746
3747   /* Pedantically, don't ley (void *) (FOO *) 0 be a null pointer constant.  */
3748   if (pedantic && TREE_CODE (value) == INTEGER_CST
3749       && TREE_CODE (expr) == INTEGER_CST
3750       && TREE_CODE (TREE_TYPE (expr)) != INTEGER_TYPE)
3751     value = non_lvalue (value);
3752
3753   /* If pedantic, don't let a cast be an lvalue.  */
3754   if (value == expr && pedantic)
3755     value = non_lvalue (value);
3756
3757   return value;
3758 }
3759 \f
3760 /* Build an assignment expression of lvalue LHS from value RHS.
3761    MODIFYCODE is the code for a binary operator that we use
3762    to combine the old value of LHS with RHS to get the new value.
3763    Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.  */
3764
3765 tree
3766 build_modify_expr (lhs, modifycode, rhs)
3767      tree lhs, rhs;
3768      enum tree_code modifycode;
3769 {
3770   register tree result;
3771   tree newrhs;
3772   tree lhstype = TREE_TYPE (lhs);
3773   tree olhstype = lhstype;
3774
3775   /* Types that aren't fully specified cannot be used in assignments.  */
3776   lhs = require_complete_type (lhs);
3777
3778   /* Avoid duplicate error messages from operands that had errors.  */
3779   if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK)
3780     return error_mark_node;
3781
3782   /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
3783   /* Do not use STRIP_NOPS here.  We do not want an enumerator
3784      whose value is 0 to count as a null pointer constant.  */
3785   if (TREE_CODE (rhs) == NON_LVALUE_EXPR)
3786     rhs = TREE_OPERAND (rhs, 0);
3787
3788   newrhs = rhs;
3789
3790   /* Handle control structure constructs used as "lvalues".  */
3791
3792   switch (TREE_CODE (lhs))
3793     {
3794       /* Handle (a, b) used as an "lvalue".  */
3795     case COMPOUND_EXPR:
3796       pedantic_lvalue_warning (COMPOUND_EXPR);
3797       newrhs = build_modify_expr (TREE_OPERAND (lhs, 1), modifycode, rhs);
3798       if (TREE_CODE (newrhs) == ERROR_MARK)
3799         return error_mark_node;
3800       return build (COMPOUND_EXPR, lhstype,
3801                     TREE_OPERAND (lhs, 0), newrhs);
3802  
3803       /* Handle (a ? b : c) used as an "lvalue".  */
3804     case COND_EXPR:
3805       pedantic_lvalue_warning (COND_EXPR);
3806       rhs = save_expr (rhs);
3807       {
3808         /* Produce (a ? (b = rhs) : (c = rhs))
3809            except that the RHS goes through a save-expr
3810            so the code to compute it is only emitted once.  */
3811         tree cond
3812           = build_conditional_expr (TREE_OPERAND (lhs, 0),
3813                                     build_modify_expr (TREE_OPERAND (lhs, 1),
3814                                                        modifycode, rhs),
3815                                     build_modify_expr (TREE_OPERAND (lhs, 2),
3816                                                        modifycode, rhs));
3817         if (TREE_CODE (cond) == ERROR_MARK)
3818           return cond;
3819         /* Make sure the code to compute the rhs comes out
3820            before the split.  */
3821         return build (COMPOUND_EXPR, TREE_TYPE (lhs),
3822                       /* But cast it to void to avoid an "unused" error.  */
3823                       convert (void_type_node, rhs), cond);
3824       }
3825     default:
3826       break;
3827     }
3828
3829   /* If a binary op has been requested, combine the old LHS value with the RHS
3830      producing the value we should actually store into the LHS.  */
3831
3832   if (modifycode != NOP_EXPR)
3833     {
3834       lhs = stabilize_reference (lhs);
3835       newrhs = build_binary_op (modifycode, lhs, rhs, 1);
3836     }
3837
3838   /* Handle a cast used as an "lvalue".
3839      We have already performed any binary operator using the value as cast.
3840      Now convert the result to the cast type of the lhs,
3841      and then true type of the lhs and store it there;
3842      then convert result back to the cast type to be the value
3843      of the assignment.  */
3844
3845   switch (TREE_CODE (lhs))
3846     {
3847     case NOP_EXPR:
3848     case CONVERT_EXPR:
3849     case FLOAT_EXPR:
3850     case FIX_TRUNC_EXPR:
3851     case FIX_FLOOR_EXPR:
3852     case FIX_ROUND_EXPR:
3853     case FIX_CEIL_EXPR:
3854       if (TREE_CODE (TREE_TYPE (newrhs)) == ARRAY_TYPE
3855           || TREE_CODE (TREE_TYPE (newrhs)) == FUNCTION_TYPE)
3856         newrhs = default_conversion (newrhs);
3857       {
3858         tree inner_lhs = TREE_OPERAND (lhs, 0);
3859         tree result;
3860         result = build_modify_expr (inner_lhs, NOP_EXPR,
3861                                     convert (TREE_TYPE (inner_lhs),
3862                                              convert (lhstype, newrhs)));
3863         if (TREE_CODE (result) == ERROR_MARK)
3864           return result;
3865         pedantic_lvalue_warning (CONVERT_EXPR);
3866         return convert (TREE_TYPE (lhs), result);
3867       }
3868       
3869     default:
3870       break;
3871     }
3872
3873   /* Now we have handled acceptable kinds of LHS that are not truly lvalues.
3874      Reject anything strange now.  */
3875
3876   if (!lvalue_or_else (lhs, "invalid lvalue in assignment"))
3877     return error_mark_node;
3878
3879   /* Warn about storing in something that is `const'.  */
3880
3881   if (TREE_READONLY (lhs) || TYPE_READONLY (lhstype)
3882       || ((TREE_CODE (lhstype) == RECORD_TYPE
3883            || TREE_CODE (lhstype) == UNION_TYPE)
3884           && C_TYPE_FIELDS_READONLY (lhstype)))
3885     readonly_warning (lhs, "assignment");
3886
3887   /* If storing into a structure or union member,
3888      it has probably been given type `int'.
3889      Compute the type that would go with
3890      the actual amount of storage the member occupies.  */
3891
3892   if (TREE_CODE (lhs) == COMPONENT_REF
3893       && (TREE_CODE (lhstype) == INTEGER_TYPE
3894           || TREE_CODE (lhstype) == REAL_TYPE
3895           || TREE_CODE (lhstype) == ENUMERAL_TYPE))
3896     lhstype = TREE_TYPE (get_unwidened (lhs, 0));
3897
3898   /* If storing in a field that is in actuality a short or narrower than one,
3899      we must store in the field in its actual type.  */
3900
3901   if (lhstype != TREE_TYPE (lhs))
3902     {
3903       lhs = copy_node (lhs);
3904       TREE_TYPE (lhs) = lhstype;
3905     }
3906
3907   /* Convert new value to destination type.  */
3908
3909   newrhs = convert_for_assignment (lhstype, newrhs, _("assignment"),
3910                                    NULL_TREE, NULL_TREE, 0);
3911   if (TREE_CODE (newrhs) == ERROR_MARK)
3912     return error_mark_node;
3913
3914   result = build (MODIFY_EXPR, lhstype, lhs, newrhs);
3915   TREE_SIDE_EFFECTS (result) = 1;
3916
3917   /* If we got the LHS in a different type for storing in,
3918      convert the result back to the nominal type of LHS
3919      so that the value we return always has the same type
3920      as the LHS argument.  */
3921
3922   if (olhstype == TREE_TYPE (result))
3923     return result;
3924   return convert_for_assignment (olhstype, result, _("assignment"),
3925                                  NULL_TREE, NULL_TREE, 0);
3926 }
3927 \f
3928 /* Convert value RHS to type TYPE as preparation for an assignment
3929    to an lvalue of type TYPE.
3930    The real work of conversion is done by `convert'.
3931    The purpose of this function is to generate error messages
3932    for assignments that are not allowed in C.
3933    ERRTYPE is a string to use in error messages:
3934    "assignment", "return", etc.  If it is null, this is parameter passing
3935    for a function call (and different error messages are output).
3936
3937    FUNNAME is the name of the function being called,
3938    as an IDENTIFIER_NODE, or null.
3939    PARMNUM is the number of the argument, for printing in error messages.  */
3940
3941 static tree
3942 convert_for_assignment (type, rhs, errtype, fundecl, funname, parmnum)
3943      tree type, rhs;
3944      const char *errtype;
3945      tree fundecl, funname;
3946      int parmnum;
3947 {
3948   register enum tree_code codel = TREE_CODE (type);
3949   register tree rhstype;
3950   register enum tree_code coder;
3951
3952   /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
3953   /* Do not use STRIP_NOPS here.  We do not want an enumerator
3954      whose value is 0 to count as a null pointer constant.  */
3955   if (TREE_CODE (rhs) == NON_LVALUE_EXPR)
3956     rhs = TREE_OPERAND (rhs, 0);
3957
3958   if (TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
3959       || TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE)
3960     rhs = default_conversion (rhs);
3961   else if (optimize && TREE_CODE (rhs) == VAR_DECL)
3962     rhs = decl_constant_value (rhs);
3963
3964   rhstype = TREE_TYPE (rhs);
3965   coder = TREE_CODE (rhstype);
3966
3967   if (coder == ERROR_MARK)
3968     return error_mark_node;
3969
3970   if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
3971     {
3972       overflow_warning (rhs);
3973       /* Check for Objective-C protocols.  This will issue a warning if
3974          there are protocol violations.  No need to use the return value.  */
3975       maybe_objc_comptypes (type, rhstype, 0);
3976       return rhs;
3977     }
3978
3979   if (coder == VOID_TYPE)
3980     {
3981       error ("void value not ignored as it ought to be");
3982       return error_mark_node;
3983     }
3984   /* Arithmetic types all interconvert, and enum is treated like int.  */
3985   if ((codel == INTEGER_TYPE || codel == REAL_TYPE || codel == ENUMERAL_TYPE
3986        || codel == COMPLEX_TYPE)
3987       && (coder == INTEGER_TYPE || coder == REAL_TYPE || coder == ENUMERAL_TYPE
3988           || coder == COMPLEX_TYPE))
3989     return convert_and_check (type, rhs);
3990
3991   /* Conversion to a transparent union from its member types.
3992      This applies only to function arguments.  */
3993   else if (codel == UNION_TYPE && TYPE_TRANSPARENT_UNION (type) && ! errtype)
3994     {
3995       tree memb_types;
3996       tree marginal_memb_type = 0;
3997
3998       for (memb_types = TYPE_FIELDS (type); memb_types;
3999            memb_types = TREE_CHAIN (memb_types))
4000         {
4001           tree memb_type = TREE_TYPE (memb_types);
4002
4003           if (comptypes (TYPE_MAIN_VARIANT (memb_type),
4004                          TYPE_MAIN_VARIANT (rhstype)))
4005             break;
4006
4007           if (TREE_CODE (memb_type) != POINTER_TYPE)
4008             continue;
4009
4010           if (coder == POINTER_TYPE)
4011             {
4012               register tree ttl = TREE_TYPE (memb_type);
4013               register tree ttr = TREE_TYPE (rhstype);
4014
4015               /* Any non-function converts to a [const][volatile] void *
4016                  and vice versa; otherwise, targets must be the same.
4017                  Meanwhile, the lhs target must have all the qualifiers of
4018                  the rhs.  */
4019               if (TYPE_MAIN_VARIANT (ttl) == void_type_node
4020                   || TYPE_MAIN_VARIANT (ttr) == void_type_node
4021                   || comp_target_types (memb_type, rhstype))
4022                 {
4023                   /* If this type won't generate any warnings, use it.  */
4024                   if (TYPE_QUALS (ttl) == TYPE_QUALS (ttr)
4025                       || ((TREE_CODE (ttr) == FUNCTION_TYPE
4026                            && TREE_CODE (ttl) == FUNCTION_TYPE)
4027                           ? ((TYPE_QUALS (ttl) | TYPE_QUALS (ttr))
4028                              == TYPE_QUALS (ttr))
4029                           : ((TYPE_QUALS (ttl) | TYPE_QUALS (ttr))
4030                              == TYPE_QUALS (ttl))))
4031                     break;
4032
4033                   /* Keep looking for a better type, but remember this one.  */
4034                   if (! marginal_memb_type)
4035                     marginal_memb_type = memb_type;
4036                 }
4037             }
4038
4039           /* Can convert integer zero to any pointer type.  */
4040           if (integer_zerop (rhs)
4041               || (TREE_CODE (rhs) == NOP_EXPR
4042                   && integer_zerop (TREE_OPERAND (rhs, 0))))
4043             {
4044               rhs = null_pointer_node;
4045               break;
4046             }
4047         }
4048
4049       if (memb_types || marginal_memb_type)
4050         {
4051           if (! memb_types)
4052             {
4053               /* We have only a marginally acceptable member type;
4054                  it needs a warning.  */
4055               register tree ttl = TREE_TYPE (marginal_memb_type);
4056               register tree ttr = TREE_TYPE (rhstype);
4057
4058               /* Const and volatile mean something different for function
4059                  types, so the usual warnings are not appropriate.  */
4060               if (TREE_CODE (ttr) == FUNCTION_TYPE
4061                   && TREE_CODE (ttl) == FUNCTION_TYPE)
4062                 {
4063                   /* Because const and volatile on functions are
4064                      restrictions that say the function will not do
4065                      certain things, it is okay to use a const or volatile
4066                      function where an ordinary one is wanted, but not
4067                      vice-versa.  */
4068                   if (TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr))
4069                     warn_for_assignment ("%s makes qualified function pointer from unqualified",
4070                                          errtype, funname, parmnum);
4071                 }
4072               else if (TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl))
4073                 warn_for_assignment ("%s discards qualifiers from pointer target type",
4074                                      errtype, funname,
4075                                      parmnum);
4076             }
4077           
4078           if (pedantic && ! DECL_IN_SYSTEM_HEADER (fundecl))
4079             pedwarn ("ANSI C prohibits argument conversion to union type");
4080
4081           return build1 (NOP_EXPR, type, rhs);
4082         }
4083     }
4084
4085   /* Conversions among pointers */
4086   else if (codel == POINTER_TYPE && coder == POINTER_TYPE)
4087     {
4088       register tree ttl = TREE_TYPE (type);
4089       register tree ttr = TREE_TYPE (rhstype);
4090
4091       /* Any non-function converts to a [const][volatile] void *
4092          and vice versa; otherwise, targets must be the same.
4093          Meanwhile, the lhs target must have all the qualifiers of the rhs.  */
4094       if (TYPE_MAIN_VARIANT (ttl) == void_type_node
4095           || TYPE_MAIN_VARIANT (ttr) == void_type_node
4096           || comp_target_types (type, rhstype)
4097           || (unsigned_type (TYPE_MAIN_VARIANT (ttl))
4098               == unsigned_type (TYPE_MAIN_VARIANT (ttr))))
4099         {
4100           if (pedantic
4101               && ((TYPE_MAIN_VARIANT (ttl) == void_type_node
4102                    && TREE_CODE (ttr) == FUNCTION_TYPE)
4103                   ||
4104                   (TYPE_MAIN_VARIANT (ttr) == void_type_node
4105                    /* Check TREE_CODE to catch cases like (void *) (char *) 0
4106                       which are not ANSI null ptr constants.  */
4107                    && (!integer_zerop (rhs) || TREE_CODE (rhs) == NOP_EXPR)
4108                    && TREE_CODE (ttl) == FUNCTION_TYPE)))
4109             warn_for_assignment ("ANSI forbids %s between function pointer and `void *'",
4110                                  errtype, funname, parmnum);
4111           /* Const and volatile mean something different for function types,
4112              so the usual warnings are not appropriate.  */
4113           else if (TREE_CODE (ttr) != FUNCTION_TYPE
4114                    && TREE_CODE (ttl) != FUNCTION_TYPE)
4115             {
4116               if (TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl))
4117                 warn_for_assignment ("%s discards qualifiers from pointer target type",
4118                                      errtype, funname, parmnum);
4119               /* If this is not a case of ignoring a mismatch in signedness,
4120                  no warning.  */
4121               else if (TYPE_MAIN_VARIANT (ttl) == void_type_node
4122                        || TYPE_MAIN_VARIANT (ttr) == void_type_node
4123                        || comp_target_types (type, rhstype))
4124                 ;
4125               /* If there is a mismatch, do warn.  */
4126               else if (pedantic)
4127                 warn_for_assignment ("pointer targets in %s differ in signedness",
4128                                      errtype, funname, parmnum);
4129             }
4130           else if (TREE_CODE (ttl) == FUNCTION_TYPE
4131                    && TREE_CODE (ttr) == FUNCTION_TYPE)
4132             {
4133               /* Because const and volatile on functions are restrictions
4134                  that say the function will not do certain things,
4135                  it is okay to use a const or volatile function
4136                  where an ordinary one is wanted, but not vice-versa.  */
4137               if (TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr))
4138                 warn_for_assignment ("%s makes qualified function pointer from unqualified",
4139                                      errtype, funname, parmnum);
4140             }
4141         }
4142       else
4143         warn_for_assignment ("%s from incompatible pointer type",
4144                              errtype, funname, parmnum);
4145       return convert (type, rhs);
4146     }
4147   else if (codel == POINTER_TYPE && coder == INTEGER_TYPE)
4148     {
4149       /* An explicit constant 0 can convert to a pointer,
4150          or one that results from arithmetic, even including
4151          a cast to integer type.  */
4152       if (! (TREE_CODE (rhs) == INTEGER_CST && integer_zerop (rhs))
4153           &&
4154           ! (TREE_CODE (rhs) == NOP_EXPR
4155              && TREE_CODE (TREE_TYPE (rhs)) == INTEGER_TYPE
4156              && TREE_CODE (TREE_OPERAND (rhs, 0)) == INTEGER_CST
4157              && integer_zerop (TREE_OPERAND (rhs, 0))))
4158         {
4159           warn_for_assignment ("%s makes pointer from integer without a cast",
4160                                errtype, funname, parmnum);
4161           return convert (type, rhs);
4162         }
4163       return null_pointer_node;
4164     }
4165   else if (codel == INTEGER_TYPE && coder == POINTER_TYPE)
4166     {
4167       warn_for_assignment ("%s makes integer from pointer without a cast",
4168                            errtype, funname, parmnum);
4169       return convert (type, rhs);
4170     }
4171
4172   if (!errtype)
4173     {
4174       if (funname)
4175         {
4176           tree selector = maybe_building_objc_message_expr ();
4177  
4178           if (selector && parmnum > 2)
4179             error ("incompatible type for argument %d of `%s'",
4180                    parmnum - 2, IDENTIFIER_POINTER (selector));
4181           else
4182             error ("incompatible type for argument %d of `%s'",
4183                    parmnum, IDENTIFIER_POINTER (funname));
4184         }
4185       else
4186         error ("incompatible type for argument %d of indirect function call",
4187                parmnum);
4188     }
4189   else
4190     error ("incompatible types in %s", errtype);
4191
4192   return error_mark_node;
4193 }
4194
4195 /* Print a warning using MSGID.
4196    It gets OPNAME as its one parameter.
4197    If OPNAME is null, it is replaced by "passing arg ARGNUM of `FUNCTION'".
4198    FUNCTION and ARGNUM are handled specially if we are building an
4199    Objective-C selector.  */
4200
4201 static void
4202 warn_for_assignment (msgid, opname, function, argnum)
4203      const char *msgid;
4204      const char *opname;
4205      tree function;
4206      int argnum;
4207 {
4208   if (opname == 0)
4209     {
4210       tree selector = maybe_building_objc_message_expr ();
4211       char * new_opname;
4212       
4213       if (selector && argnum > 2)
4214         {
4215           function = selector;
4216           argnum -= 2;
4217         }
4218       if (function)
4219         {
4220           /* Function name is known; supply it.  */
4221           const char *argstring = _("passing arg %d of `%s'");
4222           new_opname = (char *) alloca (IDENTIFIER_LENGTH (function)
4223                                         + strlen (argstring) + 1 + 25
4224                                         /*%d*/ + 1);
4225           sprintf (new_opname, argstring, argnum,
4226                    IDENTIFIER_POINTER (function));
4227         }
4228       else
4229         {
4230           /* Function name unknown (call through ptr); just give arg number.*/
4231           const char *argnofun = _("passing arg %d of pointer to function");
4232           new_opname = (char *) alloca (strlen (argnofun) + 1 + 25 /*%d*/ + 1);
4233           sprintf (new_opname, argnofun, argnum);
4234         }
4235       opname = new_opname;
4236     }
4237   pedwarn (msgid, opname);
4238 }
4239 \f
4240 /* If VALUE is a compound expr all of whose expressions are constant, then
4241    return its value.  Otherwise, return error_mark_node.
4242
4243    This is for handling COMPOUND_EXPRs as initializer elements
4244    which is allowed with a warning when -pedantic is specified.  */
4245
4246 static tree
4247 valid_compound_expr_initializer (value, endtype)
4248      tree value;
4249      tree endtype;
4250 {
4251   if (TREE_CODE (value) == COMPOUND_EXPR)
4252     {
4253       if (valid_compound_expr_initializer (TREE_OPERAND (value, 0), endtype)
4254           == error_mark_node)
4255         return error_mark_node;
4256       return valid_compound_expr_initializer (TREE_OPERAND (value, 1),
4257                                               endtype);
4258     }
4259   else if (! TREE_CONSTANT (value)
4260            && ! initializer_constant_valid_p (value, endtype))
4261     return error_mark_node;
4262   else
4263     return value;
4264 }
4265 \f
4266 /* Perform appropriate conversions on the initial value of a variable,
4267    store it in the declaration DECL,
4268    and print any error messages that are appropriate.
4269    If the init is invalid, store an ERROR_MARK.  */
4270
4271 void
4272 store_init_value (decl, init)
4273      tree decl, init;
4274 {
4275   register tree value, type;
4276
4277   /* If variable's type was invalidly declared, just ignore it.  */
4278
4279   type = TREE_TYPE (decl);
4280   if (TREE_CODE (type) == ERROR_MARK)
4281     return;
4282
4283   /* Digest the specified initializer into an expression.  */
4284
4285   value = digest_init (type, init, TREE_STATIC (decl),
4286                        TREE_STATIC (decl) || pedantic);
4287
4288   /* Store the expression if valid; else report error.  */
4289
4290 #if 0
4291   /* Note that this is the only place we can detect the error
4292      in a case such as   struct foo bar = (struct foo) { x, y };
4293      where there is one initial value which is a constructor expression.  */
4294   if (value == error_mark_node)
4295     ;
4296   else if (TREE_STATIC (decl) && ! TREE_CONSTANT (value))
4297     {
4298       error ("initializer for static variable is not constant");
4299       value = error_mark_node;
4300     }
4301   else if (TREE_STATIC (decl)
4302            && initializer_constant_valid_p (value, TREE_TYPE (value)) == 0)
4303     {
4304       error ("initializer for static variable uses complicated arithmetic");
4305       value = error_mark_node;
4306     }
4307   else
4308     {
4309       if (pedantic && TREE_CODE (value) == CONSTRUCTOR)
4310         {
4311           if (! TREE_CONSTANT (value))
4312             pedwarn ("aggregate initializer is not constant");
4313           else if (! TREE_STATIC (value))
4314             pedwarn ("aggregate initializer uses complicated arithmetic");
4315         }
4316     }
4317 #endif
4318
4319   DECL_INITIAL (decl) = value;
4320
4321   /* ANSI wants warnings about out-of-range constant initializers.  */
4322   STRIP_TYPE_NOPS (value);
4323   constant_expression_warning (value);
4324 }
4325 \f
4326 /* Methods for storing and printing names for error messages.  */
4327
4328 /* Implement a spelling stack that allows components of a name to be pushed
4329    and popped.  Each element on the stack is this structure.  */
4330
4331 struct spelling
4332 {
4333   int kind;
4334   union
4335     {
4336       int i;
4337       const char *s;
4338     } u;
4339 };
4340
4341 #define SPELLING_STRING 1
4342 #define SPELLING_MEMBER 2
4343 #define SPELLING_BOUNDS 3
4344
4345 static struct spelling *spelling;       /* Next stack element (unused).  */
4346 static struct spelling *spelling_base;  /* Spelling stack base.  */
4347 static int spelling_size;               /* Size of the spelling stack.  */
4348
4349 /* Macros to save and restore the spelling stack around push_... functions.
4350    Alternative to SAVE_SPELLING_STACK.  */
4351
4352 #define SPELLING_DEPTH() (spelling - spelling_base)
4353 #define RESTORE_SPELLING_DEPTH(depth) (spelling = spelling_base + depth)
4354
4355 /* Save and restore the spelling stack around arbitrary C code.  */
4356
4357 #define SAVE_SPELLING_DEPTH(code)               \
4358 {                                               \
4359   int __depth = SPELLING_DEPTH ();              \
4360   code;                                         \
4361   RESTORE_SPELLING_DEPTH (__depth);             \
4362 }
4363
4364 /* Push an element on the spelling stack with type KIND and assign VALUE
4365    to MEMBER.  */
4366
4367 #define PUSH_SPELLING(KIND, VALUE, MEMBER)                              \
4368 {                                                                       \
4369   int depth = SPELLING_DEPTH ();                                        \
4370                                                                         \
4371   if (depth >= spelling_size)                                           \
4372     {                                                                   \
4373       spelling_size += 10;                                              \
4374       if (spelling_base == 0)                                           \
4375         spelling_base                                                   \
4376           = (struct spelling *) xmalloc (spelling_size * sizeof (struct spelling));     \
4377       else                                                              \
4378         spelling_base                                                   \
4379           = (struct spelling *) xrealloc (spelling_base,                \
4380                                           spelling_size * sizeof (struct spelling));    \
4381       RESTORE_SPELLING_DEPTH (depth);                                   \
4382     }                                                                   \
4383                                                                         \
4384   spelling->kind = (KIND);                                              \
4385   spelling->MEMBER = (VALUE);                                           \
4386   spelling++;                                                           \
4387 }
4388
4389 /* Push STRING on the stack.  Printed literally.  */
4390
4391 static void
4392 push_string (string)
4393      const char *string;
4394 {
4395   PUSH_SPELLING (SPELLING_STRING, string, u.s);
4396 }
4397
4398 /* Push a member name on the stack.  Printed as '.' STRING.  */
4399
4400 static void
4401 push_member_name (decl)
4402      tree decl;
4403      
4404 {
4405   const char *string
4406     = DECL_NAME (decl) ? IDENTIFIER_POINTER (DECL_NAME (decl)) : "<anonymous>";
4407   PUSH_SPELLING (SPELLING_MEMBER, string, u.s);
4408 }
4409
4410 /* Push an array bounds on the stack.  Printed as [BOUNDS].  */
4411
4412 static void
4413 push_array_bounds (bounds)
4414      int bounds;
4415 {
4416   PUSH_SPELLING (SPELLING_BOUNDS, bounds, u.i);
4417 }
4418
4419 /* Compute the maximum size in bytes of the printed spelling.  */
4420
4421 static int
4422 spelling_length ()
4423 {
4424   register int size = 0;
4425   register struct spelling *p;
4426
4427   for (p = spelling_base; p < spelling; p++)
4428     {
4429       if (p->kind == SPELLING_BOUNDS)
4430         size += 25;
4431       else
4432         size += strlen (p->u.s) + 1;
4433     }
4434
4435   return size;
4436 }
4437
4438 /* Print the spelling to BUFFER and return it.  */
4439
4440 static char *
4441 print_spelling (buffer)
4442      register char *buffer;
4443 {
4444   register char *d = buffer;
4445   register struct spelling *p;
4446
4447   for (p = spelling_base; p < spelling; p++)
4448     if (p->kind == SPELLING_BOUNDS)
4449       {
4450         sprintf (d, "[%d]", p->u.i);
4451         d += strlen (d);
4452       }
4453     else
4454       {
4455         register const char *s;
4456         if (p->kind == SPELLING_MEMBER)
4457           *d++ = '.';
4458         for (s = p->u.s; (*d = *s++); d++)
4459           ;
4460       }
4461   *d++ = '\0';
4462   return buffer;
4463 }
4464
4465 /* Issue an error message for a bad initializer component.
4466    MSGID identifies the message.
4467    The component name is taken from the spelling stack.  */
4468
4469 void
4470 error_init (msgid)
4471      const char *msgid;
4472 {
4473   char *ofwhat;
4474
4475   error ("%s", msgid);
4476   ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
4477   if (*ofwhat)
4478     error ("(near initialization for `%s')", ofwhat);
4479 }
4480
4481 /* Issue a pedantic warning for a bad initializer component.
4482    MSGID identifies the message.
4483    The component name is taken from the spelling stack.  */
4484
4485 void
4486 pedwarn_init (msgid)
4487      const char *msgid;
4488 {
4489   char *ofwhat;
4490
4491   pedwarn ("%s", msgid);
4492   ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
4493   if (*ofwhat)
4494     pedwarn ("(near initialization for `%s')", ofwhat);
4495 }
4496
4497 /* Issue a warning for a bad initializer component.
4498    MSGID identifies the message.
4499    The component name is taken from the spelling stack.  */
4500
4501 static void
4502 warning_init (msgid)
4503      const char *msgid;
4504 {
4505   char *ofwhat;
4506
4507   warning ("%s", msgid);
4508   ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
4509   if (*ofwhat)
4510     warning ("(near initialization for `%s')", ofwhat);
4511 }
4512 \f
4513 /* Digest the parser output INIT as an initializer for type TYPE.
4514    Return a C expression of type TYPE to represent the initial value.
4515
4516    The arguments REQUIRE_CONSTANT and CONSTRUCTOR_CONSTANT request errors
4517    if non-constant initializers or elements are seen.  CONSTRUCTOR_CONSTANT
4518    applies only to elements of constructors.  */
4519
4520 static tree
4521 digest_init (type, init, require_constant, constructor_constant)
4522      tree type, init;
4523      int require_constant, constructor_constant;
4524 {
4525   enum tree_code code = TREE_CODE (type);
4526   tree inside_init = init;
4527
4528   if (type == error_mark_node || init == error_mark_node)
4529     return error_mark_node;
4530
4531   /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
4532   /* Do not use STRIP_NOPS here.  We do not want an enumerator
4533      whose value is 0 to count as a null pointer constant.  */
4534   if (TREE_CODE (init) == NON_LVALUE_EXPR)
4535     inside_init = TREE_OPERAND (init, 0);
4536
4537   /* Initialization of an array of chars from a string constant
4538      optionally enclosed in braces.  */
4539
4540   if (code == ARRAY_TYPE)
4541     {
4542       tree typ1 = TYPE_MAIN_VARIANT (TREE_TYPE (type));
4543       if ((typ1 == char_type_node
4544            || typ1 == signed_char_type_node
4545            || typ1 == unsigned_char_type_node
4546            || typ1 == unsigned_wchar_type_node
4547            || typ1 == signed_wchar_type_node)
4548           && ((inside_init && TREE_CODE (inside_init) == STRING_CST)))
4549         {
4550           if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
4551                          TYPE_MAIN_VARIANT (type)))
4552             return inside_init;
4553
4554           if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init)))
4555                != char_type_node)
4556               && TYPE_PRECISION (typ1) == TYPE_PRECISION (char_type_node))
4557             {
4558               error_init ("char-array initialized from wide string");
4559               return error_mark_node;
4560             }
4561           if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init)))
4562                == char_type_node)
4563               && TYPE_PRECISION (typ1) != TYPE_PRECISION (char_type_node))
4564             {
4565               error_init ("int-array initialized from non-wide string");
4566               return error_mark_node;
4567             }
4568
4569           TREE_TYPE (inside_init) = type;
4570           if (TYPE_DOMAIN (type) != 0
4571               && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
4572             {
4573               register int size = TREE_INT_CST_LOW (TYPE_SIZE (type));
4574               size = (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
4575               /* Subtract 1 (or sizeof (wchar_t))
4576                  because it's ok to ignore the terminating null char
4577                  that is counted in the length of the constant.  */
4578               if (size < TREE_STRING_LENGTH (inside_init)
4579                   - (TYPE_PRECISION (typ1) != TYPE_PRECISION (char_type_node)
4580                      ? TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT
4581                      : 1))
4582                 pedwarn_init ("initializer-string for array of chars is too long");
4583             }
4584           return inside_init;
4585         }
4586     }
4587
4588   /* Any type can be initialized
4589      from an expression of the same type, optionally with braces.  */
4590
4591   if (inside_init && TREE_TYPE (inside_init) != 0
4592       && (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
4593                      TYPE_MAIN_VARIANT (type))
4594           || (code == ARRAY_TYPE
4595               && comptypes (TREE_TYPE (inside_init), type))
4596           || (code == POINTER_TYPE
4597               && (TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE
4598                   || TREE_CODE (TREE_TYPE (inside_init)) == FUNCTION_TYPE)
4599               && comptypes (TREE_TYPE (TREE_TYPE (inside_init)),
4600                             TREE_TYPE (type)))))
4601     {
4602       if (code == POINTER_TYPE
4603           && (TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE
4604               || TREE_CODE (TREE_TYPE (inside_init)) == FUNCTION_TYPE))
4605         inside_init = default_conversion (inside_init);
4606       else if (code == ARRAY_TYPE && TREE_CODE (inside_init) != STRING_CST
4607                && TREE_CODE (inside_init) != CONSTRUCTOR)
4608         {
4609           error_init ("array initialized from non-constant array expression");
4610           return error_mark_node;
4611         }
4612
4613       if (optimize && TREE_CODE (inside_init) == VAR_DECL)
4614         inside_init = decl_constant_value (inside_init);
4615
4616       /* Compound expressions can only occur here if -pedantic or
4617          -pedantic-errors is specified.  In the later case, we always want
4618          an error.  In the former case, we simply want a warning.  */
4619       if (require_constant && pedantic
4620           && TREE_CODE (inside_init) == COMPOUND_EXPR)
4621         {
4622           inside_init
4623             = valid_compound_expr_initializer (inside_init,
4624                                                TREE_TYPE (inside_init));
4625           if (inside_init == error_mark_node)
4626             error_init ("initializer element is not constant");
4627           else
4628             pedwarn_init ("initializer element is not constant");
4629           if (flag_pedantic_errors)
4630             inside_init = error_mark_node;
4631         }
4632       else if (require_constant && ! TREE_CONSTANT (inside_init))
4633         {
4634           error_init ("initializer element is not constant");
4635           inside_init = error_mark_node;
4636         }
4637       else if (require_constant
4638                && initializer_constant_valid_p (inside_init, TREE_TYPE (inside_init)) == 0)
4639         {
4640           error_init ("initializer element is not computable at load time");
4641           inside_init = error_mark_node;
4642         }
4643
4644       return inside_init;
4645     }
4646
4647   /* Handle scalar types, including conversions.  */
4648
4649   if (code == INTEGER_TYPE || code == REAL_TYPE || code == POINTER_TYPE
4650       || code == ENUMERAL_TYPE || code == COMPLEX_TYPE)
4651     {
4652       /* Note that convert_for_assignment calls default_conversion
4653          for arrays and functions.  We must not call it in the
4654          case where inside_init is a null pointer constant.  */
4655       inside_init
4656         = convert_for_assignment (type, init, _("initialization"),
4657                                   NULL_TREE, NULL_TREE, 0);
4658
4659       if (require_constant && ! TREE_CONSTANT (inside_init))
4660         {
4661           error_init ("initializer element is not constant");
4662           inside_init = error_mark_node;
4663         }
4664       else if (require_constant
4665                && initializer_constant_valid_p (inside_init, TREE_TYPE (inside_init)) == 0)
4666         {
4667           error_init ("initializer element is not computable at load time");
4668           inside_init = error_mark_node;
4669         }
4670
4671       return inside_init;
4672     }
4673
4674   /* Come here only for records and arrays.  */
4675
4676   if (TYPE_SIZE (type) && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
4677     {
4678       error_init ("variable-sized object may not be initialized");
4679       return error_mark_node;
4680     }
4681
4682   /* Traditionally, you can write  struct foo x = 0;
4683      and it initializes the first element of x to 0.  */
4684   if (flag_traditional)
4685     {
4686       tree top = 0, prev = 0, otype = type;
4687       while (TREE_CODE (type) == RECORD_TYPE
4688              || TREE_CODE (type) == ARRAY_TYPE
4689              || TREE_CODE (type) == QUAL_UNION_TYPE
4690              || TREE_CODE (type) == UNION_TYPE)
4691         {
4692           tree temp = build (CONSTRUCTOR, type, NULL_TREE, NULL_TREE);
4693           if (prev == 0)
4694             top = temp;
4695           else
4696             TREE_OPERAND (prev, 1) = build_tree_list (NULL_TREE, temp);
4697           prev = temp;
4698           if (TREE_CODE (type) == ARRAY_TYPE)
4699             type = TREE_TYPE (type);
4700           else if (TYPE_FIELDS (type))
4701             type = TREE_TYPE (TYPE_FIELDS (type));
4702           else
4703             {
4704               error_init ("invalid initializer");
4705               return error_mark_node;
4706             }
4707         }
4708
4709       if (otype != type)
4710         {
4711           TREE_OPERAND (prev, 1)
4712             = build_tree_list (NULL_TREE,
4713                                digest_init (type, init, require_constant,
4714                                             constructor_constant));
4715           return top;
4716         }
4717       else
4718         return error_mark_node;
4719     }
4720   error_init ("invalid initializer");
4721   return error_mark_node;
4722 }
4723 \f
4724 /* Handle initializers that use braces.  */
4725
4726 /* Type of object we are accumulating a constructor for.
4727    This type is always a RECORD_TYPE, UNION_TYPE or ARRAY_TYPE.  */
4728 static tree constructor_type;
4729
4730 /* For a RECORD_TYPE or UNION_TYPE, this is the chain of fields
4731    left to fill.  */
4732 static tree constructor_fields;
4733
4734 /* For an ARRAY_TYPE, this is the specified index
4735    at which to store the next element we get.
4736    This is a special INTEGER_CST node that we modify in place.  */
4737 static tree constructor_index;
4738
4739 /* For an ARRAY_TYPE, this is the end index of the range
4740    to initialize with the next element, or NULL in the ordinary case
4741    where the element is used just once.  */
4742 static tree constructor_range_end;
4743
4744 /* For an ARRAY_TYPE, this is the maximum index.  */
4745 static tree constructor_max_index;
4746
4747 /* For a RECORD_TYPE, this is the first field not yet written out.  */
4748 static tree constructor_unfilled_fields;
4749
4750 /* For an ARRAY_TYPE, this is the index of the first element
4751    not yet written out.
4752    This is a special INTEGER_CST node that we modify in place.  */
4753 static tree constructor_unfilled_index;
4754
4755 /* In a RECORD_TYPE, the byte index of the next consecutive field.
4756    This is so we can generate gaps between fields, when appropriate.
4757    This is a special INTEGER_CST node that we modify in place.  */
4758 static tree constructor_bit_index;
4759
4760 /* If we are saving up the elements rather than allocating them,
4761    this is the list of elements so far (in reverse order,
4762    most recent first).  */
4763 static tree constructor_elements;
4764
4765 /* 1 if so far this constructor's elements are all compile-time constants.  */
4766 static int constructor_constant;
4767
4768 /* 1 if so far this constructor's elements are all valid address constants.  */
4769 static int constructor_simple;
4770
4771 /* 1 if this constructor is erroneous so far.  */
4772 static int constructor_erroneous;
4773
4774 /* 1 if have called defer_addressed_constants.  */
4775 static int constructor_subconstants_deferred;
4776
4777 /* Structure for managing pending initializer elements, organized as an
4778    AVL tree.  */
4779
4780 struct init_node
4781 {
4782   struct init_node *left, *right;
4783   struct init_node *parent;
4784   int balance;
4785   tree purpose;
4786   tree value;
4787 };
4788
4789 /* Tree of pending elements at this constructor level.
4790    These are elements encountered out of order
4791    which belong at places we haven't reached yet in actually
4792    writing the output.
4793    Will never hold tree nodes across GC runs.  */
4794 static struct init_node *constructor_pending_elts;
4795
4796 /* The SPELLING_DEPTH of this constructor.  */
4797 static int constructor_depth;
4798
4799 /* 0 if implicitly pushing constructor levels is allowed.  */
4800 int constructor_no_implicit = 0; /* 0 for C; 1 for some other languages.  */
4801
4802 static int require_constant_value;
4803 static int require_constant_elements;
4804
4805 /* 1 if it is ok to output this constructor as we read it.
4806    0 means must accumulate a CONSTRUCTOR expression.  */
4807 static int constructor_incremental;
4808
4809 /* DECL node for which an initializer is being read.
4810    0 means we are reading a constructor expression
4811    such as (struct foo) {...}.  */
4812 static tree constructor_decl;
4813
4814 /* start_init saves the ASMSPEC arg here for really_start_incremental_init.  */
4815 static char *constructor_asmspec;
4816
4817 /* Nonzero if this is an initializer for a top-level decl.  */
4818 static int constructor_top_level;
4819
4820 \f
4821 /* This stack has a level for each implicit or explicit level of
4822    structuring in the initializer, including the outermost one.  It
4823    saves the values of most of the variables above.  */
4824
4825 struct constructor_stack
4826 {
4827   struct constructor_stack *next;
4828   tree type;
4829   tree fields;
4830   tree index;
4831   tree range_end;
4832   tree max_index;
4833   tree unfilled_index;
4834   tree unfilled_fields;
4835   tree bit_index;
4836   tree elements;
4837   int offset;
4838   struct init_node *pending_elts;
4839   int depth;
4840   /* If nonzero, this value should replace the entire
4841      constructor at this level.  */
4842   tree replacement_value;
4843   char constant;
4844   char simple;
4845   char implicit;
4846   char incremental;
4847   char erroneous;
4848   char outer;
4849 };
4850
4851 struct constructor_stack *constructor_stack;
4852
4853 /* This stack records separate initializers that are nested.
4854    Nested initializers can't happen in ANSI C, but GNU C allows them
4855    in cases like { ... (struct foo) { ... } ... }.  */
4856
4857 struct initializer_stack
4858 {
4859   struct initializer_stack *next;
4860   tree decl;
4861   char *asmspec;
4862   struct constructor_stack *constructor_stack;
4863   tree elements;
4864   struct spelling *spelling;
4865   struct spelling *spelling_base;
4866   int spelling_size;
4867   char top_level;
4868   char incremental;
4869   char require_constant_value;
4870   char require_constant_elements;
4871   char deferred;
4872 };
4873
4874 struct initializer_stack *initializer_stack;
4875 \f
4876 /* Prepare to parse and output the initializer for variable DECL.  */
4877
4878 void
4879 start_init (decl, asmspec_tree, top_level)
4880      tree decl;
4881      tree asmspec_tree;
4882      int top_level;
4883 {
4884   const char *locus;
4885   struct initializer_stack *p
4886     = (struct initializer_stack *) xmalloc (sizeof (struct initializer_stack));
4887   char *asmspec = 0;
4888
4889   if (asmspec_tree)
4890     asmspec = TREE_STRING_POINTER (asmspec_tree);
4891
4892   p->decl = constructor_decl;
4893   p->asmspec = constructor_asmspec;
4894   p->incremental = constructor_incremental;
4895   p->require_constant_value = require_constant_value;
4896   p->require_constant_elements = require_constant_elements;
4897   p->constructor_stack = constructor_stack;
4898   p->elements = constructor_elements;
4899   p->spelling = spelling;
4900   p->spelling_base = spelling_base;
4901   p->spelling_size = spelling_size;
4902   p->deferred = constructor_subconstants_deferred;
4903   p->top_level = constructor_top_level;
4904   p->next = initializer_stack;
4905   initializer_stack = p;
4906
4907   constructor_decl = decl;
4908   constructor_incremental = top_level;
4909   constructor_asmspec = asmspec;
4910   constructor_subconstants_deferred = 0;
4911   constructor_top_level = top_level;
4912
4913   if (decl != 0)
4914     {
4915       require_constant_value = TREE_STATIC (decl);
4916       require_constant_elements
4917         = ((TREE_STATIC (decl) || pedantic)
4918            /* For a scalar, you can always use any value to initialize,
4919               even within braces.  */
4920            && (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
4921                || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
4922                || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
4923                || TREE_CODE (TREE_TYPE (decl)) == QUAL_UNION_TYPE));
4924       locus = IDENTIFIER_POINTER (DECL_NAME (decl));
4925       constructor_incremental |= TREE_STATIC (decl);
4926     }
4927   else
4928     {
4929       require_constant_value = 0;
4930       require_constant_elements = 0;
4931       locus = "(anonymous)";
4932     }
4933
4934   constructor_stack = 0;
4935
4936   missing_braces_mentioned = 0;
4937
4938   spelling_base = 0;
4939   spelling_size = 0;
4940   RESTORE_SPELLING_DEPTH (0);
4941
4942   if (locus)
4943     push_string (locus);
4944 }
4945
4946 void
4947 finish_init ()
4948 {
4949   struct initializer_stack *p = initializer_stack;
4950
4951   /* Output subconstants (string constants, usually)
4952      that were referenced within this initializer and saved up.
4953      Must do this if and only if we called defer_addressed_constants.  */
4954   if (constructor_subconstants_deferred)
4955     output_deferred_addressed_constants ();
4956
4957   /* Free the whole constructor stack of this initializer.  */
4958   while (constructor_stack)
4959     {
4960       struct constructor_stack *q = constructor_stack;
4961       constructor_stack = q->next;
4962       free (q);
4963     }
4964
4965   /* Pop back to the data of the outer initializer (if any).  */
4966   constructor_decl = p->decl;
4967   constructor_asmspec = p->asmspec;
4968   constructor_incremental = p->incremental;
4969   require_constant_value = p->require_constant_value;
4970   require_constant_elements = p->require_constant_elements;
4971   constructor_stack = p->constructor_stack;
4972   constructor_elements = p->elements;
4973   spelling = p->spelling;
4974   spelling_base = p->spelling_base;
4975   spelling_size = p->spelling_size;
4976   constructor_subconstants_deferred = p->deferred;
4977   constructor_top_level = p->top_level;
4978   initializer_stack = p->next;
4979   free (p);
4980 }
4981 \f
4982 /* Call here when we see the initializer is surrounded by braces.
4983    This is instead of a call to push_init_level;
4984    it is matched by a call to pop_init_level.
4985
4986    TYPE is the type to initialize, for a constructor expression.
4987    For an initializer for a decl, TYPE is zero.  */
4988
4989 void
4990 really_start_incremental_init (type)
4991      tree type;
4992 {
4993   struct constructor_stack *p
4994     = (struct constructor_stack *) xmalloc (sizeof (struct constructor_stack));
4995
4996   if (type == 0)
4997     type = TREE_TYPE (constructor_decl);
4998
4999   /* Turn off constructor_incremental if type is a struct with bitfields.
5000      Do this before the first push, so that the corrected value
5001      is available in finish_init.  */
5002   check_init_type_bitfields (type);
5003
5004   p->type = constructor_type;
5005   p->fields = constructor_fields;
5006   p->index = constructor_index;
5007   p->range_end = constructor_range_end;
5008   p->max_index = constructor_max_index;
5009   p->unfilled_index = constructor_unfilled_index;
5010   p->unfilled_fields = constructor_unfilled_fields;
5011   p->bit_index = constructor_bit_index;
5012   p->elements = constructor_elements;
5013   p->constant = constructor_constant;
5014   p->simple = constructor_simple;
5015   p->erroneous = constructor_erroneous;
5016   p->pending_elts = constructor_pending_elts;
5017   p->depth = constructor_depth;
5018   p->replacement_value = 0;
5019   p->implicit = 0;
5020   p->incremental = constructor_incremental;
5021   p->outer = 0;
5022   p->next = 0;
5023   constructor_stack = p;
5024
5025   constructor_constant = 1;
5026   constructor_simple = 1;
5027   constructor_depth = SPELLING_DEPTH ();
5028   constructor_elements = 0;
5029   constructor_pending_elts = 0;
5030   constructor_type = type;
5031
5032   if (TREE_CODE (constructor_type) == RECORD_TYPE
5033       || TREE_CODE (constructor_type) == UNION_TYPE)
5034     {
5035       constructor_fields = TYPE_FIELDS (constructor_type);
5036       /* Skip any nameless bit fields at the beginning.  */
5037       while (constructor_fields != 0 && DECL_C_BIT_FIELD (constructor_fields)
5038              && DECL_NAME (constructor_fields) == 0)
5039         constructor_fields = TREE_CHAIN (constructor_fields);
5040       constructor_unfilled_fields = constructor_fields;
5041       constructor_bit_index = copy_node (integer_zero_node);
5042       TREE_TYPE (constructor_bit_index) = sbitsizetype;
5043     }
5044   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5045     {
5046       constructor_range_end = 0;
5047       if (TYPE_DOMAIN (constructor_type))
5048         {
5049           constructor_max_index
5050             = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
5051           constructor_index
5052             = copy_node (TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
5053         }
5054       else
5055         constructor_index = copy_node (integer_zero_node);
5056       constructor_unfilled_index = copy_node (constructor_index);
5057     }
5058   else
5059     {
5060       /* Handle the case of int x = {5}; */
5061       constructor_fields = constructor_type;
5062       constructor_unfilled_fields = constructor_type;
5063     }
5064
5065   if (constructor_incremental)
5066     {
5067       make_decl_rtl (constructor_decl, constructor_asmspec,
5068                      constructor_top_level);
5069       assemble_variable (constructor_decl, constructor_top_level, 0, 1);
5070
5071       defer_addressed_constants ();
5072       constructor_subconstants_deferred = 1;
5073     }
5074 }
5075 \f
5076 /* Push down into a subobject, for initialization.
5077    If this is for an explicit set of braces, IMPLICIT is 0.
5078    If it is because the next element belongs at a lower level,
5079    IMPLICIT is 1.  */
5080
5081 void
5082 push_init_level (implicit)
5083      int implicit;
5084 {
5085   struct constructor_stack *p;
5086
5087   /* If we've exhausted any levels that didn't have braces,
5088      pop them now.  */
5089   while (constructor_stack->implicit)
5090     {
5091       if ((TREE_CODE (constructor_type) == RECORD_TYPE
5092            || TREE_CODE (constructor_type) == UNION_TYPE)
5093           && constructor_fields == 0)
5094         process_init_element (pop_init_level (1));
5095       else if (TREE_CODE (constructor_type) == ARRAY_TYPE
5096                && tree_int_cst_lt (constructor_max_index, constructor_index))
5097         process_init_element (pop_init_level (1));
5098       else
5099         break;
5100     }
5101
5102   /* Structure elements may require alignment.  Do this now if necessary
5103      for the subaggregate, and if it comes next in sequence.  Don't do
5104      this for subaggregates that will go on the pending list.  */
5105   if (constructor_incremental && constructor_type != 0
5106       && TREE_CODE (constructor_type) == RECORD_TYPE && constructor_fields
5107       && constructor_fields == constructor_unfilled_fields)
5108     {
5109       /* Advance to offset of this element.  */
5110       if (! tree_int_cst_equal (constructor_bit_index,
5111                                 DECL_FIELD_BITPOS (constructor_fields)))
5112         {
5113           /* By using unsigned arithmetic, the result will be correct even
5114              in case of overflows, if BITS_PER_UNIT is a power of two.  */
5115           unsigned next = (TREE_INT_CST_LOW
5116                            (DECL_FIELD_BITPOS (constructor_fields))
5117                            / (unsigned)BITS_PER_UNIT);
5118           unsigned here = (TREE_INT_CST_LOW (constructor_bit_index)
5119                            / (unsigned)BITS_PER_UNIT);
5120
5121           assemble_zeros ((next - here)
5122                           * (unsigned)BITS_PER_UNIT
5123                           / (unsigned)BITS_PER_UNIT);
5124         }
5125       /* Indicate that we have now filled the structure up to the current
5126          field.  */
5127       constructor_unfilled_fields = constructor_fields;
5128     }
5129
5130   p = (struct constructor_stack *) xmalloc (sizeof (struct constructor_stack));
5131   p->type = constructor_type;
5132   p->fields = constructor_fields;
5133   p->index = constructor_index;
5134   p->range_end = constructor_range_end;
5135   p->max_index = constructor_max_index;
5136   p->unfilled_index = constructor_unfilled_index;
5137   p->unfilled_fields = constructor_unfilled_fields;
5138   p->bit_index = constructor_bit_index;
5139   p->elements = constructor_elements;
5140   p->constant = constructor_constant;
5141   p->simple = constructor_simple;
5142   p->erroneous = constructor_erroneous;
5143   p->pending_elts = constructor_pending_elts;
5144   p->depth = constructor_depth;
5145   p->replacement_value = 0;
5146   p->implicit = implicit;
5147   p->incremental = constructor_incremental;
5148   p->outer = 0;
5149   p->next = constructor_stack;
5150   constructor_stack = p;
5151
5152   constructor_constant = 1;
5153   constructor_simple = 1;
5154   constructor_depth = SPELLING_DEPTH ();
5155   constructor_elements = 0;
5156   constructor_pending_elts = 0;
5157
5158   /* Don't die if an entire brace-pair level is superfluous
5159      in the containing level.  */
5160   if (constructor_type == 0)
5161     ;
5162   else if (TREE_CODE (constructor_type) == RECORD_TYPE
5163            || TREE_CODE (constructor_type) == UNION_TYPE)
5164     {
5165       /* Don't die if there are extra init elts at the end.  */
5166       if (constructor_fields == 0)
5167         constructor_type = 0;
5168       else
5169         {
5170           constructor_type = TREE_TYPE (constructor_fields);
5171           push_member_name (constructor_fields);
5172           constructor_depth++;
5173           if (constructor_fields != constructor_unfilled_fields)
5174             constructor_incremental = 0;
5175         }
5176     }
5177   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5178     {
5179       constructor_type = TREE_TYPE (constructor_type);
5180       push_array_bounds (TREE_INT_CST_LOW (constructor_index));
5181       constructor_depth++;
5182       if (! tree_int_cst_equal (constructor_index, constructor_unfilled_index)
5183           || constructor_range_end != 0)
5184         constructor_incremental = 0;
5185     }
5186
5187   if (constructor_type == 0)
5188     {
5189       error_init ("extra brace group at end of initializer");
5190       constructor_fields = 0;
5191       constructor_unfilled_fields = 0;
5192       return;
5193     }
5194
5195   /* Turn off constructor_incremental if type is a struct with bitfields.  */
5196   check_init_type_bitfields (constructor_type);
5197
5198   if (implicit && warn_missing_braces && !missing_braces_mentioned)
5199     {
5200       missing_braces_mentioned = 1;
5201       warning_init ("missing braces around initializer");
5202     }
5203
5204   if (TREE_CODE (constructor_type) == RECORD_TYPE
5205            || TREE_CODE (constructor_type) == UNION_TYPE)
5206     {
5207       constructor_fields = TYPE_FIELDS (constructor_type);
5208       /* Skip any nameless bit fields at the beginning.  */
5209       while (constructor_fields != 0 && DECL_C_BIT_FIELD (constructor_fields)
5210              && DECL_NAME (constructor_fields) == 0)
5211         constructor_fields = TREE_CHAIN (constructor_fields);
5212       constructor_unfilled_fields = constructor_fields;
5213       constructor_bit_index = copy_node (integer_zero_node);
5214       TREE_TYPE (constructor_bit_index) = sbitsizetype;
5215     }
5216   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5217     {
5218       constructor_range_end = 0;
5219       if (TYPE_DOMAIN (constructor_type))
5220         {
5221           constructor_max_index
5222             = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
5223           constructor_index
5224             = copy_node (TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
5225         }
5226       else
5227         constructor_index = copy_node (integer_zero_node);
5228       constructor_unfilled_index = copy_node (constructor_index);
5229     }
5230   else
5231     {
5232       warning_init ("braces around scalar initializer");
5233       constructor_fields = constructor_type;
5234       constructor_unfilled_fields = constructor_type;
5235     }
5236 }
5237
5238 /* Don't read a struct incrementally if it has any bitfields,
5239    because the incremental reading code doesn't know how to
5240    handle bitfields yet.  */
5241
5242 static void
5243 check_init_type_bitfields (type)
5244      tree type;
5245 {
5246   if (TREE_CODE (type) == RECORD_TYPE)
5247     {
5248       tree tail;
5249       for (tail = TYPE_FIELDS (type); tail;
5250            tail = TREE_CHAIN (tail))
5251         {
5252           if (DECL_C_BIT_FIELD (tail))
5253             {
5254               constructor_incremental = 0;
5255               break;
5256             }
5257
5258           check_init_type_bitfields (TREE_TYPE (tail));
5259         }
5260     }
5261
5262   else if (TREE_CODE (type) == UNION_TYPE)
5263     {
5264       tree tail = TYPE_FIELDS (type);
5265       if (tail && DECL_C_BIT_FIELD (tail))
5266         /* We also use the nonincremental algorithm for initiliazation
5267            of unions whose first member is a bitfield, becuase the
5268            incremental algorithm has no code for dealing with
5269            bitfields. */
5270         constructor_incremental = 0;
5271     }
5272
5273   else if (TREE_CODE (type) == ARRAY_TYPE)
5274     check_init_type_bitfields (TREE_TYPE (type));
5275 }
5276
5277 /* At the end of an implicit or explicit brace level, 
5278    finish up that level of constructor.
5279    If we were outputting the elements as they are read, return 0
5280    from inner levels (process_init_element ignores that),
5281    but return error_mark_node from the outermost level
5282    (that's what we want to put in DECL_INITIAL).
5283    Otherwise, return a CONSTRUCTOR expression.  */
5284
5285 tree
5286 pop_init_level (implicit)
5287      int implicit;
5288 {
5289   struct constructor_stack *p;
5290   int size = 0;
5291   tree constructor = 0;
5292
5293   if (implicit == 0)
5294     {
5295       /* When we come to an explicit close brace,
5296          pop any inner levels that didn't have explicit braces.  */
5297       while (constructor_stack->implicit)
5298         process_init_element (pop_init_level (1));
5299     }
5300
5301   p = constructor_stack;
5302
5303   if (constructor_type != 0)
5304     size = int_size_in_bytes (constructor_type);
5305
5306   /* Warn when some struct elements are implicitly initialized to zero.  */
5307   if (extra_warnings
5308       && constructor_type
5309       && TREE_CODE (constructor_type) == RECORD_TYPE
5310       && constructor_unfilled_fields)
5311     {
5312       push_member_name (constructor_unfilled_fields);
5313       warning_init ("missing initializer");
5314       RESTORE_SPELLING_DEPTH (constructor_depth);
5315     }
5316
5317   /* Now output all pending elements.  */
5318   output_pending_init_elements (1);
5319
5320 #if 0 /* c-parse.in warns about {}.  */
5321   /* In ANSI, each brace level must have at least one element.  */
5322   if (! implicit && pedantic
5323       && (TREE_CODE (constructor_type) == ARRAY_TYPE
5324           ? integer_zerop (constructor_unfilled_index)
5325           : constructor_unfilled_fields == TYPE_FIELDS (constructor_type)))
5326     pedwarn_init ("empty braces in initializer");
5327 #endif
5328
5329   /* Pad out the end of the structure.  */
5330   
5331   if (p->replacement_value)
5332     {
5333       /* If this closes a superfluous brace pair,
5334          just pass out the element between them.  */
5335       constructor = p->replacement_value;
5336       /* If this is the top level thing within the initializer,
5337          and it's for a variable, then since we already called
5338          assemble_variable, we must output the value now.  */
5339       if (p->next == 0 && constructor_decl != 0
5340           && constructor_incremental)
5341         {
5342           constructor = digest_init (constructor_type, constructor,
5343                                      require_constant_value,
5344                                      require_constant_elements);
5345
5346           /* If initializing an array of unknown size,
5347              determine the size now.  */
5348           if (TREE_CODE (constructor_type) == ARRAY_TYPE
5349               && TYPE_DOMAIN (constructor_type) == 0)
5350             {
5351               /* We shouldn't have an incomplete array type within
5352                  some other type.  */
5353               if (constructor_stack->next)
5354                 abort ();
5355
5356               if (complete_array_type (constructor_type, constructor, 0))
5357                 abort ();
5358
5359               size = int_size_in_bytes (constructor_type);
5360             }
5361
5362           output_constant (constructor, size);
5363         }
5364     }
5365   else if (constructor_type == 0)
5366     ;
5367   else if (TREE_CODE (constructor_type) != RECORD_TYPE
5368            && TREE_CODE (constructor_type) != UNION_TYPE
5369            && TREE_CODE (constructor_type) != ARRAY_TYPE
5370            && ! constructor_incremental)
5371     {
5372       /* A nonincremental scalar initializer--just return
5373          the element, after verifying there is just one.  */
5374       if (constructor_elements == 0)
5375         {
5376           error_init ("empty scalar initializer");
5377           constructor = error_mark_node;
5378         }
5379       else if (TREE_CHAIN (constructor_elements) != 0)
5380         {
5381           error_init ("extra elements in scalar initializer");
5382           constructor = TREE_VALUE (constructor_elements);
5383         }
5384       else
5385         constructor = TREE_VALUE (constructor_elements);
5386     }
5387   else if (! constructor_incremental)
5388     {
5389       if (constructor_erroneous)
5390         constructor = error_mark_node;
5391       else
5392         {
5393           constructor = build (CONSTRUCTOR, constructor_type, NULL_TREE,
5394                                nreverse (constructor_elements));
5395           if (constructor_constant)
5396             TREE_CONSTANT (constructor) = 1;
5397           if (constructor_constant && constructor_simple)
5398             TREE_STATIC (constructor) = 1;
5399         }
5400     }
5401   else
5402     {
5403       tree filled;
5404       if (TREE_CODE (constructor_type) == RECORD_TYPE
5405           || TREE_CODE (constructor_type) == UNION_TYPE)
5406         {
5407           /* Find the offset of the end of that field.  */
5408           filled = size_binop (CEIL_DIV_EXPR,
5409                                constructor_bit_index,
5410                                size_int (BITS_PER_UNIT));
5411         }
5412       else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5413         {
5414           /* If initializing an array of unknown size,
5415              determine the size now.  */
5416           if (TREE_CODE (constructor_type) == ARRAY_TYPE
5417               && TYPE_DOMAIN (constructor_type) == 0)
5418             {
5419               tree maxindex
5420                 = size_binop (MINUS_EXPR,
5421                               constructor_unfilled_index,
5422                               integer_one_node);
5423
5424               maxindex = copy_node (maxindex);
5425               TYPE_DOMAIN (constructor_type) = build_index_type (maxindex);
5426               TREE_TYPE (maxindex) = TYPE_DOMAIN (constructor_type);
5427
5428               /* TYPE_MAX_VALUE is always one less than the number of elements
5429                  in the array, because we start counting at zero.  Therefore,
5430                  warn only if the value is less than zero.  */
5431               if (pedantic
5432                   && (tree_int_cst_sgn (TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type)))
5433                       < 0))
5434                 error_with_decl (constructor_decl,
5435                                  "zero or negative array size `%s'");
5436               layout_type (constructor_type);
5437               size = int_size_in_bytes (constructor_type);
5438             }
5439
5440           filled = size_binop (MULT_EXPR, constructor_unfilled_index,
5441                                size_in_bytes (TREE_TYPE (constructor_type)));
5442         }
5443       else
5444         filled = 0;
5445
5446       if (filled != 0)
5447         assemble_zeros (size - TREE_INT_CST_LOW (filled));
5448     }
5449
5450           
5451   constructor_type = p->type;
5452   constructor_fields = p->fields;
5453   constructor_index = p->index;
5454   constructor_range_end = p->range_end;
5455   constructor_max_index = p->max_index;
5456   constructor_unfilled_index = p->unfilled_index;
5457   constructor_unfilled_fields = p->unfilled_fields;
5458   constructor_bit_index = p->bit_index;
5459   constructor_elements = p->elements;
5460   constructor_constant = p->constant;
5461   constructor_simple = p->simple;
5462   constructor_erroneous = p->erroneous;
5463   constructor_pending_elts = p->pending_elts;
5464   constructor_depth = p->depth;
5465   constructor_incremental = p->incremental;
5466   RESTORE_SPELLING_DEPTH (constructor_depth);
5467
5468   constructor_stack = p->next;
5469   free (p);
5470
5471   if (constructor == 0)
5472     {
5473       if (constructor_stack == 0)
5474         return error_mark_node;
5475       return NULL_TREE;
5476     }
5477   return constructor;
5478 }
5479
5480 /* Within an array initializer, specify the next index to be initialized.
5481    FIRST is that index.  If LAST is nonzero, then initialize a range
5482    of indices, running from FIRST through LAST.  */
5483
5484 void
5485 set_init_index (first, last)
5486      tree first, last;
5487 {
5488   while ((TREE_CODE (first) == NOP_EXPR
5489           || TREE_CODE (first) == CONVERT_EXPR
5490           || TREE_CODE (first) == NON_LVALUE_EXPR)
5491          && (TYPE_MODE (TREE_TYPE (first))
5492              == TYPE_MODE (TREE_TYPE (TREE_OPERAND (first, 0)))))
5493     (first) = TREE_OPERAND (first, 0);
5494   if (last)
5495     while ((TREE_CODE (last) == NOP_EXPR
5496             || TREE_CODE (last) == CONVERT_EXPR
5497             || TREE_CODE (last) == NON_LVALUE_EXPR)
5498            && (TYPE_MODE (TREE_TYPE (last))
5499                == TYPE_MODE (TREE_TYPE (TREE_OPERAND (last, 0)))))
5500       (last) = TREE_OPERAND (last, 0);
5501
5502   if (TREE_CODE (first) != INTEGER_CST)
5503     error_init ("nonconstant array index in initializer");
5504   else if (last != 0 && TREE_CODE (last) != INTEGER_CST)
5505     error_init ("nonconstant array index in initializer");
5506   else if (! constructor_unfilled_index)
5507     error_init ("array index in non-array initializer");
5508   else if (tree_int_cst_lt (first, constructor_unfilled_index))
5509     error_init ("duplicate array index in initializer");
5510   else
5511     {
5512       TREE_INT_CST_LOW (constructor_index) = TREE_INT_CST_LOW (first);
5513       TREE_INT_CST_HIGH (constructor_index) = TREE_INT_CST_HIGH (first);
5514
5515       if (last != 0 && tree_int_cst_lt (last, first))
5516         error_init ("empty index range in initializer");
5517       else
5518         {
5519           if (pedantic)
5520             pedwarn ("ANSI C forbids specifying element to initialize");
5521           constructor_range_end = last;
5522         }
5523     }
5524 }
5525
5526 /* Within a struct initializer, specify the next field to be initialized.  */
5527
5528 void
5529 set_init_label (fieldname)
5530      tree fieldname;
5531 {
5532   tree tail;
5533   int passed = 0;
5534
5535   /* Don't die if an entire brace-pair level is superfluous
5536      in the containing level.  */
5537   if (constructor_type == 0)
5538     return;
5539
5540   for (tail = TYPE_FIELDS (constructor_type); tail;
5541        tail = TREE_CHAIN (tail))
5542     {
5543       if (tail == constructor_unfilled_fields)
5544         passed = 1;
5545       if (DECL_NAME (tail) == fieldname)
5546         break;
5547     }
5548
5549   if (tail == 0)
5550     error ("unknown field `%s' specified in initializer",
5551            IDENTIFIER_POINTER (fieldname));
5552   else if (!passed)
5553     error ("field `%s' already initialized",
5554            IDENTIFIER_POINTER (fieldname));
5555   else
5556     {
5557       constructor_fields = tail;
5558       if (pedantic)
5559         pedwarn ("ANSI C forbids specifying structure member to initialize");
5560     }
5561 }
5562 \f
5563 /* Add a new initializer to the tree of pending initializers.  PURPOSE
5564    indentifies the initializer, either array index or field in a structure. 
5565    VALUE is the value of that index or field.  */
5566
5567 static void
5568 add_pending_init (purpose, value)
5569      tree purpose, value;
5570 {
5571   struct init_node *p, **q, *r;
5572
5573   q = &constructor_pending_elts;
5574   p = 0;
5575
5576   if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5577     {
5578       while (*q != 0)
5579         {
5580           p = *q;
5581           if (tree_int_cst_lt (purpose, p->purpose))
5582             q = &p->left;
5583           else if (tree_int_cst_lt (p->purpose, purpose))
5584             q = &p->right;
5585           else
5586             abort ();
5587         }
5588     }
5589   else
5590     {
5591       while (*q != NULL)
5592         {
5593           p = *q;
5594           if (tree_int_cst_lt (DECL_FIELD_BITPOS (purpose),
5595                                DECL_FIELD_BITPOS (p->purpose)))
5596             q = &p->left;
5597           else if (tree_int_cst_lt (DECL_FIELD_BITPOS (p->purpose),
5598                                     DECL_FIELD_BITPOS (purpose)))
5599             q = &p->right;
5600           else
5601             abort ();
5602         }
5603     }
5604
5605   r = (struct init_node *) ggc_alloc_obj (sizeof (struct init_node), 0);
5606   r->purpose = purpose;
5607   r->value = value;
5608
5609   *q = r;
5610   r->parent = p;
5611   r->left = 0;
5612   r->right = 0;
5613   r->balance = 0;
5614
5615   while (p)
5616     {
5617       struct init_node *s;
5618
5619       if (r == p->left)
5620         {
5621           if (p->balance == 0)
5622             p->balance = -1;
5623           else if (p->balance < 0)
5624             {
5625               if (r->balance < 0)
5626                 {
5627                   /* L rotation. */
5628                   p->left = r->right;
5629                   if (p->left)
5630                     p->left->parent = p;
5631                   r->right = p;
5632
5633                   p->balance = 0;
5634                   r->balance = 0;
5635
5636                   s = p->parent;
5637                   p->parent = r;
5638                   r->parent = s;
5639                   if (s)
5640                     {
5641                       if (s->left == p)
5642                         s->left = r;
5643                       else
5644                         s->right = r;
5645                     }
5646                   else
5647                     constructor_pending_elts = r;
5648                 }
5649               else
5650                 {
5651                   /* LR rotation. */
5652                   struct init_node *t = r->right;
5653
5654                   r->right = t->left;
5655                   if (r->right)
5656                     r->right->parent = r;
5657                   t->left = r;
5658
5659                   p->left = t->right;
5660                   if (p->left)
5661                     p->left->parent = p;
5662                   t->right = p;
5663
5664                   p->balance = t->balance < 0;
5665                   r->balance = -(t->balance > 0);
5666                   t->balance = 0;
5667
5668                   s = p->parent;
5669                   p->parent = t;
5670                   r->parent = t;
5671                   t->parent = s;
5672                   if (s)
5673                     {
5674                       if (s->left == p)
5675                         s->left = t;
5676                       else
5677                         s->right = t;
5678                     }
5679                   else
5680                     constructor_pending_elts = t;
5681                 }
5682               break;
5683             }
5684           else
5685             {
5686               /* p->balance == +1; growth of left side balances the node.  */
5687               p->balance = 0;
5688               break;
5689             }
5690         }
5691       else /* r == p->right */
5692         {
5693           if (p->balance == 0)
5694             /* Growth propagation from right side.  */
5695             p->balance++;
5696           else if (p->balance > 0)
5697             {
5698               if (r->balance > 0)
5699                 {
5700                   /* R rotation. */
5701                   p->right = r->left;
5702                   if (p->right)
5703                     p->right->parent = p;
5704                   r->left = p;
5705
5706                   p->balance = 0;
5707                   r->balance = 0;
5708
5709                   s = p->parent;
5710                   p->parent = r;
5711                   r->parent = s;
5712                   if (s)
5713                     {
5714                       if (s->left == p)
5715                         s->left = r;
5716                       else
5717                         s->right = r;
5718                     }
5719                   else
5720                     constructor_pending_elts = r;
5721                 }
5722               else /* r->balance == -1 */
5723                 {
5724                   /* RL rotation */
5725                   struct init_node *t = r->left;
5726
5727                   r->left = t->right;
5728                   if (r->left)
5729                     r->left->parent = r;
5730                   t->right = r;
5731
5732                   p->right = t->left;
5733                   if (p->right)
5734                     p->right->parent = p;
5735                   t->left = p;
5736
5737                   r->balance = (t->balance < 0);
5738                   p->balance = -(t->balance > 0);
5739                   t->balance = 0;
5740
5741                   s = p->parent;
5742                   p->parent = t;
5743                   r->parent = t;
5744                   t->parent = s;
5745                   if (s)
5746                     {
5747                       if (s->left == p)
5748                         s->left = t;
5749                       else
5750                         s->right = t;
5751                     }
5752                   else
5753                     constructor_pending_elts = t;
5754                 }
5755               break;
5756             }
5757           else
5758             {
5759               /* p->balance == -1; growth of right side balances the node. */
5760               p->balance = 0;
5761               break;
5762             }
5763         }
5764
5765       r = p;
5766       p = p->parent;
5767     }
5768 }
5769
5770 /* Return nonzero if FIELD is equal to the index of a pending initializer.  */
5771
5772 static int
5773 pending_init_member (field)
5774      tree field;
5775 {
5776   struct init_node *p;
5777
5778   p = constructor_pending_elts;
5779   if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5780     {
5781       while (p)
5782         {
5783           if (tree_int_cst_equal (field, p->purpose))
5784             return 1;
5785           else if (tree_int_cst_lt (field, p->purpose))
5786             p = p->left;
5787           else
5788             p = p->right;
5789         }
5790     }
5791   else
5792     {
5793       while (p)
5794         {
5795           if (field == p->purpose)
5796             return 1;
5797           else if (tree_int_cst_lt (DECL_FIELD_BITPOS (field),
5798                                     DECL_FIELD_BITPOS (p->purpose)))
5799             p = p->left;
5800           else
5801             p = p->right;
5802         }
5803     }
5804
5805   return 0;
5806 }
5807
5808 /* "Output" the next constructor element.
5809    At top level, really output it to assembler code now.
5810    Otherwise, collect it in a list from which we will make a CONSTRUCTOR.
5811    TYPE is the data type that the containing data type wants here.
5812    FIELD is the field (a FIELD_DECL) or the index that this element fills.
5813
5814    PENDING if non-nil means output pending elements that belong
5815    right after this element.  (PENDING is normally 1;
5816    it is 0 while outputting pending elements, to avoid recursion.)  */
5817
5818 static void
5819 output_init_element (value, type, field, pending)
5820      tree value, type, field;
5821      int pending;
5822 {
5823   int duplicate = 0;
5824
5825   if (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE
5826       || (TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
5827           && !(TREE_CODE (value) == STRING_CST
5828                && TREE_CODE (type) == ARRAY_TYPE
5829                && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE)
5830           && !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (value)),
5831                          TYPE_MAIN_VARIANT (type))))
5832     value = default_conversion (value);
5833
5834   if (value == error_mark_node)
5835     constructor_erroneous = 1;
5836   else if (!TREE_CONSTANT (value))
5837     constructor_constant = 0;
5838   else if (initializer_constant_valid_p (value, TREE_TYPE (value)) == 0
5839            || ((TREE_CODE (constructor_type) == RECORD_TYPE
5840                 || TREE_CODE (constructor_type) == UNION_TYPE)
5841                && DECL_C_BIT_FIELD (field)
5842                && TREE_CODE (value) != INTEGER_CST))
5843     constructor_simple = 0;
5844
5845   if (require_constant_value && ! TREE_CONSTANT (value))
5846     {
5847       error_init ("initializer element is not constant");
5848       value = error_mark_node;
5849     }
5850   else if (require_constant_elements
5851            && initializer_constant_valid_p (value, TREE_TYPE (value)) == 0)
5852     {
5853       error_init ("initializer element is not computable at load time");
5854       value = error_mark_node;
5855     }
5856
5857   /* If this element duplicates one on constructor_pending_elts,
5858      print a message and ignore it.  Don't do this when we're
5859      processing elements taken off constructor_pending_elts,
5860      because we'd always get spurious errors.  */
5861   if (pending)
5862     {
5863       if (TREE_CODE (constructor_type) == RECORD_TYPE
5864           || TREE_CODE (constructor_type) == UNION_TYPE
5865           || TREE_CODE (constructor_type) == ARRAY_TYPE)
5866         {
5867           if (pending_init_member (field))
5868             {
5869               error_init ("duplicate initializer");
5870               duplicate = 1;
5871             }
5872         }
5873     }
5874
5875   /* If this element doesn't come next in sequence,
5876      put it on constructor_pending_elts.  */
5877   if (TREE_CODE (constructor_type) == ARRAY_TYPE
5878       && !tree_int_cst_equal (field, constructor_unfilled_index))
5879     {
5880       if (! duplicate)
5881         /* The copy_node is needed in case field is actually
5882            constructor_index, which is modified in place.  */
5883         add_pending_init (copy_node (field),
5884                           digest_init (type, value, require_constant_value, 
5885                                        require_constant_elements));
5886     }
5887   else if (TREE_CODE (constructor_type) == RECORD_TYPE
5888            && field != constructor_unfilled_fields)
5889     {
5890       /* We do this for records but not for unions.  In a union,
5891          no matter which field is specified, it can be initialized
5892          right away since it starts at the beginning of the union.  */
5893       if (!duplicate)
5894         add_pending_init (field,
5895                           digest_init (type, value, require_constant_value, 
5896                                        require_constant_elements));
5897     }
5898   else
5899     {
5900       /* Otherwise, output this element either to
5901          constructor_elements or to the assembler file.  */
5902
5903       if (!duplicate)
5904         {
5905           if (! constructor_incremental)
5906             {
5907               if (field && TREE_CODE (field) == INTEGER_CST)
5908                 field = copy_node (field);
5909               constructor_elements
5910                 = tree_cons (field, digest_init (type, value,
5911                                                  require_constant_value, 
5912                                                  require_constant_elements),
5913                              constructor_elements);
5914             }
5915           else
5916             {
5917               /* Structure elements may require alignment.
5918                  Do this, if necessary.  */
5919               if (TREE_CODE (constructor_type) == RECORD_TYPE)
5920                 {
5921                   /* Advance to offset of this element.  */
5922                   if (! tree_int_cst_equal (constructor_bit_index,
5923                                             DECL_FIELD_BITPOS (field)))
5924                     {
5925                       /* By using unsigned arithmetic, the result will be
5926                          correct even in case of overflows, if BITS_PER_UNIT
5927                          is a power of two.  */
5928                       unsigned next = (TREE_INT_CST_LOW
5929                                        (DECL_FIELD_BITPOS (field))
5930                                        / (unsigned)BITS_PER_UNIT);
5931                       unsigned here = (TREE_INT_CST_LOW
5932                                        (constructor_bit_index)
5933                                        / (unsigned)BITS_PER_UNIT);
5934
5935                       assemble_zeros ((next - here)
5936                                       * (unsigned)BITS_PER_UNIT
5937                                       / (unsigned)BITS_PER_UNIT);
5938                     }
5939                 }
5940               output_constant (digest_init (type, value,
5941                                             require_constant_value,
5942                                             require_constant_elements),
5943                                int_size_in_bytes (type));
5944
5945               /* For a record or union,
5946                  keep track of end position of last field.  */
5947               if (TREE_CODE (constructor_type) == RECORD_TYPE
5948                   || TREE_CODE (constructor_type) == UNION_TYPE)
5949                 {
5950                   tree temp = size_binop (PLUS_EXPR, DECL_FIELD_BITPOS (field),
5951                                           DECL_SIZE (field));
5952
5953                   TREE_INT_CST_LOW (constructor_bit_index)
5954                     = TREE_INT_CST_LOW (temp);
5955                   TREE_INT_CST_HIGH (constructor_bit_index)
5956                     = TREE_INT_CST_HIGH (temp);
5957                 }
5958             }
5959         }
5960
5961       /* Advance the variable that indicates sequential elements output.  */
5962       if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5963         {
5964           tree tem = size_binop (PLUS_EXPR, constructor_unfilled_index,
5965                                  integer_one_node);
5966           TREE_INT_CST_LOW (constructor_unfilled_index)
5967             = TREE_INT_CST_LOW (tem);
5968           TREE_INT_CST_HIGH (constructor_unfilled_index)
5969             = TREE_INT_CST_HIGH (tem);
5970         }
5971       else if (TREE_CODE (constructor_type) == RECORD_TYPE)
5972         {
5973           constructor_unfilled_fields =
5974             TREE_CHAIN (constructor_unfilled_fields);
5975           /* Skip any nameless bit fields.  */
5976           while (constructor_unfilled_fields != 0
5977                  && DECL_C_BIT_FIELD (constructor_unfilled_fields)
5978                  && DECL_NAME (constructor_unfilled_fields) == 0)
5979             constructor_unfilled_fields =
5980               TREE_CHAIN (constructor_unfilled_fields);
5981         }
5982       else if (TREE_CODE (constructor_type) == UNION_TYPE)
5983         constructor_unfilled_fields = 0;
5984
5985       /* Now output any pending elements which have become next.  */
5986       if (pending)
5987         output_pending_init_elements (0);
5988     }
5989 }
5990
5991 /* Output any pending elements which have become next.
5992    As we output elements, constructor_unfilled_{fields,index}
5993    advances, which may cause other elements to become next;
5994    if so, they too are output.
5995
5996    If ALL is 0, we return when there are
5997    no more pending elements to output now.
5998
5999    If ALL is 1, we output space as necessary so that
6000    we can output all the pending elements.  */
6001
6002 static void
6003 output_pending_init_elements (all)
6004      int all;
6005 {
6006   struct init_node *elt = constructor_pending_elts;
6007   tree next;
6008
6009  retry:
6010
6011   /* Look thru the whole pending tree.
6012      If we find an element that should be output now,
6013      output it.  Otherwise, set NEXT to the element
6014      that comes first among those still pending.  */
6015      
6016   next = 0;
6017   while (elt)
6018     {
6019       if (TREE_CODE (constructor_type) == ARRAY_TYPE)
6020         {
6021           if (tree_int_cst_equal (elt->purpose,
6022                                   constructor_unfilled_index))
6023             output_init_element (elt->value,
6024                                  TREE_TYPE (constructor_type),
6025                                  constructor_unfilled_index, 0);
6026           else if (tree_int_cst_lt (constructor_unfilled_index,
6027                                     elt->purpose))
6028             {
6029               /* Advance to the next smaller node.  */
6030               if (elt->left)
6031                 elt = elt->left;
6032               else
6033                 {
6034                   /* We have reached the smallest node bigger than the
6035                      current unfilled index.  Fill the space first.  */
6036                   next = elt->purpose;
6037                   break;
6038                 }
6039             }
6040           else
6041             {
6042               /* Advance to the next bigger node.  */
6043               if (elt->right)
6044                 elt = elt->right;
6045               else
6046                 {
6047                   /* We have reached the biggest node in a subtree.  Find
6048                      the parent of it, which is the next bigger node.  */
6049                   while (elt->parent && elt->parent->right == elt)
6050                     elt = elt->parent;
6051                   elt = elt->parent;
6052                   if (elt && tree_int_cst_lt (constructor_unfilled_index,
6053                                               elt->purpose))
6054                     {
6055                       next = elt->purpose;
6056                       break;
6057                     }
6058                 }
6059             }
6060         }
6061       else if (TREE_CODE (constructor_type) == RECORD_TYPE
6062                || TREE_CODE (constructor_type) == UNION_TYPE)
6063         {
6064           /* If the current record is complete we are done.  */
6065           if (constructor_unfilled_fields == 0)
6066             break;
6067           if (elt->purpose == constructor_unfilled_fields)
6068             {
6069               output_init_element (elt->value,
6070                                    TREE_TYPE (constructor_unfilled_fields),
6071                                    constructor_unfilled_fields,
6072                                    0);
6073             }
6074           else if (tree_int_cst_lt (DECL_FIELD_BITPOS (constructor_unfilled_fields),
6075                                     DECL_FIELD_BITPOS (elt->purpose)))
6076             {
6077               /* Advance to the next smaller node.  */
6078               if (elt->left)
6079                 elt = elt->left;
6080               else
6081                 {
6082                   /* We have reached the smallest node bigger than the
6083                      current unfilled field.  Fill the space first.  */
6084                   next = elt->purpose;
6085                   break;
6086                 }
6087             }
6088           else
6089             {
6090               /* Advance to the next bigger node.  */
6091               if (elt->right)
6092                 elt = elt->right;
6093               else
6094                 {
6095                   /* We have reached the biggest node in a subtree.  Find
6096                      the parent of it, which is the next bigger node.  */
6097                   while (elt->parent && elt->parent->right == elt)
6098                     elt = elt->parent;
6099                   elt = elt->parent;
6100                   if (elt
6101                       && tree_int_cst_lt (DECL_FIELD_BITPOS (constructor_unfilled_fields),
6102                                           DECL_FIELD_BITPOS (elt->purpose)))
6103                     {
6104                       next = elt->purpose;
6105                       break;
6106                     }
6107                 }
6108             }
6109         }
6110     }
6111
6112   /* Ordinarily return, but not if we want to output all
6113      and there are elements left.  */
6114   if (! (all && next != 0))
6115     return;
6116
6117   /* Generate space up to the position of NEXT.  */
6118   if (constructor_incremental)
6119     {
6120       tree filled;
6121       tree nextpos_tree = size_int (0);
6122
6123       if (TREE_CODE (constructor_type) == RECORD_TYPE
6124           || TREE_CODE (constructor_type) == UNION_TYPE)
6125         {
6126           tree tail;
6127           /* Find the last field written out, if any.  */
6128           for (tail = TYPE_FIELDS (constructor_type); tail;
6129                tail = TREE_CHAIN (tail))
6130             if (TREE_CHAIN (tail) == constructor_unfilled_fields)
6131               break;
6132
6133           if (tail)
6134             /* Find the offset of the end of that field.  */
6135             filled = size_binop (CEIL_DIV_EXPR,
6136                                  size_binop (PLUS_EXPR,
6137                                              DECL_FIELD_BITPOS (tail),
6138                                              DECL_SIZE (tail)),
6139                                  size_int (BITS_PER_UNIT));
6140           else
6141             filled = size_int (0);
6142
6143           nextpos_tree = size_binop (CEIL_DIV_EXPR,
6144                                      DECL_FIELD_BITPOS (next),
6145                                      size_int (BITS_PER_UNIT));
6146
6147           TREE_INT_CST_HIGH (constructor_bit_index)
6148             = TREE_INT_CST_HIGH (DECL_FIELD_BITPOS (next));
6149           TREE_INT_CST_LOW (constructor_bit_index)
6150             = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (next));
6151           constructor_unfilled_fields = next;
6152         }
6153       else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
6154         {
6155           filled = size_binop (MULT_EXPR, constructor_unfilled_index,
6156                                size_in_bytes (TREE_TYPE (constructor_type)));
6157           nextpos_tree
6158             = size_binop (MULT_EXPR, next,
6159                           size_in_bytes (TREE_TYPE (constructor_type)));
6160           TREE_INT_CST_LOW (constructor_unfilled_index)
6161             = TREE_INT_CST_LOW (next);
6162           TREE_INT_CST_HIGH (constructor_unfilled_index)
6163             = TREE_INT_CST_HIGH (next);
6164         }
6165       else
6166         filled = 0;
6167
6168       if (filled)
6169         {
6170           int nextpos = TREE_INT_CST_LOW (nextpos_tree);
6171
6172           assemble_zeros (nextpos - TREE_INT_CST_LOW (filled));
6173         }
6174     }
6175   else
6176     {
6177       /* If it's not incremental, just skip over the gap,
6178          so that after jumping to retry we will output the next
6179          successive element.  */
6180       if (TREE_CODE (constructor_type) == RECORD_TYPE
6181           || TREE_CODE (constructor_type) == UNION_TYPE)
6182         constructor_unfilled_fields = next;
6183       else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
6184         {
6185           TREE_INT_CST_LOW (constructor_unfilled_index)
6186             = TREE_INT_CST_LOW (next);
6187           TREE_INT_CST_HIGH (constructor_unfilled_index)
6188             = TREE_INT_CST_HIGH (next);
6189         }
6190     }
6191
6192   /* ELT now points to the node in the pending tree with the next
6193      initializer to output.  */
6194   goto retry;
6195 }
6196 \f
6197 /* Add one non-braced element to the current constructor level.
6198    This adjusts the current position within the constructor's type.
6199    This may also start or terminate implicit levels
6200    to handle a partly-braced initializer.
6201
6202    Once this has found the correct level for the new element,
6203    it calls output_init_element.
6204
6205    Note: if we are incrementally outputting this constructor,
6206    this function may be called with a null argument
6207    representing a sub-constructor that was already incrementally output.
6208    When that happens, we output nothing, but we do the bookkeeping
6209    to skip past that element of the current constructor.  */
6210
6211 void
6212 process_init_element (value)
6213      tree value;
6214 {
6215   tree orig_value = value;
6216   int string_flag = value != 0 && TREE_CODE (value) == STRING_CST;
6217
6218   /* Handle superfluous braces around string cst as in
6219      char x[] = {"foo"}; */
6220   if (string_flag
6221       && constructor_type
6222       && TREE_CODE (constructor_type) == ARRAY_TYPE
6223       && TREE_CODE (TREE_TYPE (constructor_type)) == INTEGER_TYPE
6224       && integer_zerop (constructor_unfilled_index))
6225     {
6226       if (constructor_stack->replacement_value)
6227         error_init ("excess elements in char array initializer");
6228       constructor_stack->replacement_value = value;
6229       return;
6230     }
6231
6232   if (constructor_stack->replacement_value != 0)
6233     {
6234       error_init ("excess elements in struct initializer");
6235       return;
6236     }
6237
6238   /* Ignore elements of a brace group if it is entirely superfluous
6239      and has already been diagnosed.  */
6240   if (constructor_type == 0)
6241     return;
6242
6243   /* If we've exhausted any levels that didn't have braces,
6244      pop them now.  */
6245   while (constructor_stack->implicit)
6246     {
6247       if ((TREE_CODE (constructor_type) == RECORD_TYPE
6248            || TREE_CODE (constructor_type) == UNION_TYPE)
6249           && constructor_fields == 0)
6250         process_init_element (pop_init_level (1));
6251       else if (TREE_CODE (constructor_type) == ARRAY_TYPE
6252                && (constructor_max_index == 0
6253                    || tree_int_cst_lt (constructor_max_index,
6254                                        constructor_index)))
6255         process_init_element (pop_init_level (1));
6256       else
6257         break;
6258     }
6259
6260   while (1)
6261     {
6262       if (TREE_CODE (constructor_type) == RECORD_TYPE)
6263         {
6264           tree fieldtype;
6265           enum tree_code fieldcode;
6266
6267           if (constructor_fields == 0)
6268             {
6269               pedwarn_init ("excess elements in struct initializer");
6270               break;
6271             }
6272
6273           fieldtype = TREE_TYPE (constructor_fields);
6274           if (fieldtype != error_mark_node)
6275             fieldtype = TYPE_MAIN_VARIANT (fieldtype);
6276           fieldcode = TREE_CODE (fieldtype);
6277
6278           /* Accept a string constant to initialize a subarray.  */
6279           if (value != 0
6280               && fieldcode == ARRAY_TYPE
6281               && TREE_CODE (TREE_TYPE (fieldtype)) == INTEGER_TYPE
6282               && string_flag)
6283             value = orig_value;
6284           /* Otherwise, if we have come to a subaggregate,
6285              and we don't have an element of its type, push into it.  */
6286           else if (value != 0 && !constructor_no_implicit
6287                    && value != error_mark_node
6288                    && TYPE_MAIN_VARIANT (TREE_TYPE (value)) != fieldtype
6289                    && (fieldcode == RECORD_TYPE || fieldcode == ARRAY_TYPE
6290                        || fieldcode == UNION_TYPE))
6291             {
6292               push_init_level (1);
6293               continue;
6294             }
6295
6296           if (value)
6297             {
6298               push_member_name (constructor_fields);
6299               output_init_element (value, fieldtype, constructor_fields, 1);
6300               RESTORE_SPELLING_DEPTH (constructor_depth);
6301             }
6302           else
6303             /* Do the bookkeeping for an element that was
6304                directly output as a constructor.  */
6305             {
6306               /* For a record, keep track of end position of last field.  */
6307               tree temp = size_binop (PLUS_EXPR,
6308                                       DECL_FIELD_BITPOS (constructor_fields),
6309                                       DECL_SIZE (constructor_fields));
6310               TREE_INT_CST_LOW (constructor_bit_index)
6311                 = TREE_INT_CST_LOW (temp);
6312               TREE_INT_CST_HIGH (constructor_bit_index)
6313                 = TREE_INT_CST_HIGH (temp);
6314
6315               constructor_unfilled_fields = TREE_CHAIN (constructor_fields);
6316               /* Skip any nameless bit fields.  */
6317               while (constructor_unfilled_fields != 0
6318                      && DECL_C_BIT_FIELD (constructor_unfilled_fields)
6319                      && DECL_NAME (constructor_unfilled_fields) == 0)
6320                 constructor_unfilled_fields =
6321                   TREE_CHAIN (constructor_unfilled_fields);
6322             }
6323
6324           constructor_fields = TREE_CHAIN (constructor_fields);
6325           /* Skip any nameless bit fields at the beginning.  */
6326           while (constructor_fields != 0
6327                  && DECL_C_BIT_FIELD (constructor_fields)
6328                  && DECL_NAME (constructor_fields) == 0)
6329             constructor_fields = TREE_CHAIN (constructor_fields);
6330           break;
6331         }
6332       if (TREE_CODE (constructor_type) == UNION_TYPE)
6333         {
6334           tree fieldtype;
6335           enum tree_code fieldcode;
6336
6337           if (constructor_fields == 0)
6338             {
6339               pedwarn_init ("excess elements in union initializer");
6340               break;
6341             }
6342
6343           fieldtype = TREE_TYPE (constructor_fields);
6344           if (fieldtype != error_mark_node)
6345             fieldtype = TYPE_MAIN_VARIANT (fieldtype);
6346           fieldcode = TREE_CODE (fieldtype);
6347
6348           /* Accept a string constant to initialize a subarray.  */
6349           if (value != 0
6350               && fieldcode == ARRAY_TYPE
6351               && TREE_CODE (TREE_TYPE (fieldtype)) == INTEGER_TYPE
6352               && string_flag)
6353             value = orig_value;
6354           /* Otherwise, if we have come to a subaggregate,
6355              and we don't have an element of its type, push into it.  */
6356           else if (value != 0 && !constructor_no_implicit
6357                    && value != error_mark_node
6358                    && TYPE_MAIN_VARIANT (TREE_TYPE (value)) != fieldtype
6359                    && (fieldcode == RECORD_TYPE || fieldcode == ARRAY_TYPE
6360                        || fieldcode == UNION_TYPE))
6361             {
6362               push_init_level (1);
6363               continue;
6364             }
6365
6366           if (value)
6367             {
6368               push_member_name (constructor_fields);
6369               output_init_element (value, fieldtype, constructor_fields, 1);
6370               RESTORE_SPELLING_DEPTH (constructor_depth);
6371             }
6372           else
6373             /* Do the bookkeeping for an element that was
6374                directly output as a constructor.  */
6375             {
6376               TREE_INT_CST_LOW (constructor_bit_index)
6377                 = TREE_INT_CST_LOW (DECL_SIZE (constructor_fields));
6378               TREE_INT_CST_HIGH (constructor_bit_index)
6379                 = TREE_INT_CST_HIGH (DECL_SIZE (constructor_fields));
6380
6381               constructor_unfilled_fields = TREE_CHAIN (constructor_fields);
6382             }
6383
6384           constructor_fields = 0;
6385           break;
6386         }
6387       if (TREE_CODE (constructor_type) == ARRAY_TYPE)
6388         {
6389           tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
6390           enum tree_code eltcode = TREE_CODE (elttype);
6391
6392           /* Accept a string constant to initialize a subarray.  */
6393           if (value != 0
6394               && eltcode == ARRAY_TYPE
6395               && TREE_CODE (TREE_TYPE (elttype)) == INTEGER_TYPE
6396               && string_flag)
6397             value = orig_value;
6398           /* Otherwise, if we have come to a subaggregate,
6399              and we don't have an element of its type, push into it.  */
6400           else if (value != 0 && !constructor_no_implicit
6401                    && value != error_mark_node
6402                    && TYPE_MAIN_VARIANT (TREE_TYPE (value)) != elttype
6403                    && (eltcode == RECORD_TYPE || eltcode == ARRAY_TYPE
6404                        || eltcode == UNION_TYPE))
6405             {
6406               push_init_level (1);
6407               continue;
6408             }
6409
6410           if (constructor_max_index != 0
6411               && tree_int_cst_lt (constructor_max_index, constructor_index))
6412             {
6413               pedwarn_init ("excess elements in array initializer");
6414               break;
6415             }
6416
6417           /* In the case of [LO .. HI] = VALUE, only evaluate VALUE once.  */
6418           if (constructor_range_end)
6419             {
6420               if (constructor_max_index != 0
6421                   && tree_int_cst_lt (constructor_max_index, 
6422                                       constructor_range_end))
6423                 {
6424                   pedwarn_init ("excess elements in array initializer");
6425                   TREE_INT_CST_HIGH (constructor_range_end)
6426                     = TREE_INT_CST_HIGH (constructor_max_index);
6427                   TREE_INT_CST_LOW (constructor_range_end)
6428                     = TREE_INT_CST_LOW (constructor_max_index);
6429                 }
6430
6431               value = save_expr (value);
6432             }
6433
6434           /* Now output the actual element.
6435              Ordinarily, output once.
6436              If there is a range, repeat it till we advance past the range.  */
6437           do
6438             {
6439               tree tem;
6440
6441               if (value)
6442                 {
6443                   push_array_bounds (TREE_INT_CST_LOW (constructor_index));
6444                   output_init_element (value, elttype, constructor_index, 1);
6445                   RESTORE_SPELLING_DEPTH (constructor_depth);
6446                 }
6447
6448               tem = size_binop (PLUS_EXPR, constructor_index,
6449                                 integer_one_node);
6450               TREE_INT_CST_LOW (constructor_index) = TREE_INT_CST_LOW (tem);
6451               TREE_INT_CST_HIGH (constructor_index) = TREE_INT_CST_HIGH (tem);
6452
6453               if (!value)
6454                 /* If we are doing the bookkeeping for an element that was
6455                    directly output as a constructor,
6456                    we must update constructor_unfilled_index.  */
6457                 {
6458                   TREE_INT_CST_LOW (constructor_unfilled_index)
6459                     = TREE_INT_CST_LOW (constructor_index);
6460                   TREE_INT_CST_HIGH (constructor_unfilled_index)
6461                     = TREE_INT_CST_HIGH (constructor_index);
6462                 }
6463             }
6464           while (! (constructor_range_end == 0
6465                     || tree_int_cst_lt (constructor_range_end,
6466                                         constructor_index)));
6467
6468           break;
6469         }
6470
6471       /* Handle the sole element allowed in a braced initializer
6472          for a scalar variable.  */
6473       if (constructor_fields == 0)
6474         {
6475           pedwarn_init ("excess elements in scalar initializer");
6476           break;
6477         }
6478
6479       if (value)
6480         output_init_element (value, constructor_type, NULL_TREE, 1);
6481       constructor_fields = 0;
6482       break;
6483     }
6484 }
6485 \f
6486 /* Expand an ASM statement with operands, handling output operands
6487    that are not variables or INDIRECT_REFS by transforming such
6488    cases into cases that expand_asm_operands can handle.
6489
6490    Arguments are same as for expand_asm_operands.  */
6491
6492 void
6493 c_expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line)
6494      tree string, outputs, inputs, clobbers;
6495      int vol;
6496      char *filename;
6497      int line;
6498 {
6499   int noutputs = list_length (outputs);
6500   register int i;
6501   /* o[I] is the place that output number I should be written.  */
6502   register tree *o = (tree *) alloca (noutputs * sizeof (tree));
6503   register tree tail;
6504
6505   if (TREE_CODE (string) == ADDR_EXPR)
6506     string = TREE_OPERAND (string, 0);
6507   if (TREE_CODE (string) != STRING_CST)
6508     {
6509       error ("asm template is not a string constant");
6510       return;
6511     }
6512
6513   /* Record the contents of OUTPUTS before it is modified.  */
6514   for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
6515     {
6516       tree output = TREE_VALUE (tail);
6517
6518       /* We can remove conversions that just change the type, not the mode.  */
6519       STRIP_NOPS (output);
6520       o[i] = output;
6521
6522       /* Allow conversions as LHS here.  build_modify_expr as called below
6523          will do the right thing with them.  */
6524       while (TREE_CODE (output) == NOP_EXPR
6525              || TREE_CODE (output) == CONVERT_EXPR
6526              || TREE_CODE (output) == FLOAT_EXPR
6527              || TREE_CODE (output) == FIX_TRUNC_EXPR
6528              || TREE_CODE (output) == FIX_FLOOR_EXPR
6529              || TREE_CODE (output) == FIX_ROUND_EXPR
6530              || TREE_CODE (output) == FIX_CEIL_EXPR)
6531         output = TREE_OPERAND (output, 0);
6532
6533       lvalue_or_else (o[i], "invalid lvalue in asm statement");
6534     }
6535
6536   /* Perform default conversions on array and function inputs.  */
6537   /* Don't do this for other types--
6538      it would screw up operands expected to be in memory.  */
6539   for (i = 0, tail = inputs; tail; tail = TREE_CHAIN (tail), i++)
6540     if (TREE_CODE (TREE_TYPE (TREE_VALUE (tail))) == ARRAY_TYPE
6541         || TREE_CODE (TREE_TYPE (TREE_VALUE (tail))) == FUNCTION_TYPE)
6542       TREE_VALUE (tail) = default_conversion (TREE_VALUE (tail));
6543
6544   /* Generate the ASM_OPERANDS insn;
6545      store into the TREE_VALUEs of OUTPUTS some trees for
6546      where the values were actually stored.  */
6547   expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line);
6548
6549   /* Copy all the intermediate outputs into the specified outputs.  */
6550   for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
6551     {
6552       if (o[i] != TREE_VALUE (tail))
6553         {
6554           expand_expr (build_modify_expr (o[i], NOP_EXPR, TREE_VALUE (tail)),
6555                        NULL_RTX, VOIDmode, EXPAND_NORMAL);
6556           free_temp_slots ();
6557         }
6558       /* Detect modification of read-only values.
6559          (Otherwise done by build_modify_expr.)  */
6560       else
6561         {
6562           tree type = TREE_TYPE (o[i]);
6563           if (TREE_READONLY (o[i])
6564               || TYPE_READONLY (type)
6565               || ((TREE_CODE (type) == RECORD_TYPE
6566                    || TREE_CODE (type) == UNION_TYPE)
6567                   && C_TYPE_FIELDS_READONLY (type)))
6568             readonly_warning (o[i], "modification by `asm'");
6569         }
6570     }
6571
6572   /* Those MODIFY_EXPRs could do autoincrements.  */
6573   emit_queue ();
6574 }
6575 \f
6576 /* Expand a C `return' statement.
6577    RETVAL is the expression for what to return,
6578    or a null pointer for `return;' with no value.  */
6579
6580 void
6581 c_expand_return (retval)
6582      tree retval;
6583 {
6584   tree valtype = TREE_TYPE (TREE_TYPE (current_function_decl));
6585
6586   if (TREE_THIS_VOLATILE (current_function_decl))
6587     warning ("function declared `noreturn' has a `return' statement");
6588
6589   if (!retval)
6590     {
6591       current_function_returns_null = 1;
6592       if (warn_return_type && valtype != 0 && TREE_CODE (valtype) != VOID_TYPE)
6593         warning ("`return' with no value, in function returning non-void");
6594       expand_null_return ();
6595     }
6596   else if (valtype == 0 || TREE_CODE (valtype) == VOID_TYPE)
6597     {
6598       current_function_returns_null = 1;
6599       if (pedantic || TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
6600         pedwarn ("`return' with a value, in function returning void");
6601       expand_return (retval);
6602     }
6603   else
6604     {
6605       tree t = convert_for_assignment (valtype, retval, _("return"),
6606                                        NULL_TREE, NULL_TREE, 0);
6607       tree res = DECL_RESULT (current_function_decl);
6608       tree inner;
6609
6610       if (t == error_mark_node)
6611         return;
6612
6613       inner = t = convert (TREE_TYPE (res), t);
6614
6615       /* Strip any conversions, additions, and subtractions, and see if
6616          we are returning the address of a local variable.  Warn if so.  */
6617       while (1)
6618         {
6619           switch (TREE_CODE (inner))
6620             {
6621             case NOP_EXPR:   case NON_LVALUE_EXPR:  case CONVERT_EXPR:
6622             case PLUS_EXPR:
6623               inner = TREE_OPERAND (inner, 0);
6624               continue;
6625
6626             case MINUS_EXPR:
6627               /* If the second operand of the MINUS_EXPR has a pointer
6628                  type (or is converted from it), this may be valid, so
6629                  don't give a warning.  */
6630               {
6631                 tree op1 = TREE_OPERAND (inner, 1);
6632
6633                 while (! POINTER_TYPE_P (TREE_TYPE (op1))
6634                        && (TREE_CODE (op1) == NOP_EXPR
6635                            || TREE_CODE (op1) == NON_LVALUE_EXPR
6636                            || TREE_CODE (op1) == CONVERT_EXPR))
6637                   op1 = TREE_OPERAND (op1, 0);
6638
6639                 if (POINTER_TYPE_P (TREE_TYPE (op1)))
6640                   break;
6641
6642                 inner = TREE_OPERAND (inner, 0);
6643                 continue;
6644               }
6645               
6646             case ADDR_EXPR:
6647               inner = TREE_OPERAND (inner, 0);
6648
6649               while (TREE_CODE_CLASS (TREE_CODE (inner)) == 'r')
6650                 inner = TREE_OPERAND (inner, 0);
6651
6652               if (TREE_CODE (inner) == VAR_DECL
6653                   && ! DECL_EXTERNAL (inner)
6654                   && ! TREE_STATIC (inner)
6655                   && DECL_CONTEXT (inner) == current_function_decl)
6656                 warning ("function returns address of local variable");
6657               break;
6658
6659             default:
6660               break;
6661             }
6662
6663           break;
6664         }
6665
6666       t = build (MODIFY_EXPR, TREE_TYPE (res), res, t);
6667       TREE_SIDE_EFFECTS (t) = 1;
6668       expand_return (t);
6669       current_function_returns_value = 1;
6670     }
6671 }
6672 \f
6673 /* Start a C switch statement, testing expression EXP.
6674    Return EXP if it is valid, an error node otherwise.  */
6675
6676 tree
6677 c_expand_start_case (exp)
6678      tree exp;
6679 {
6680   register enum tree_code code;
6681   tree type;
6682
6683   if (TREE_CODE (exp) == ERROR_MARK)
6684     return exp;
6685
6686   code = TREE_CODE (TREE_TYPE (exp));
6687   type = TREE_TYPE (exp);
6688
6689   if (code != INTEGER_TYPE && code != ENUMERAL_TYPE && code != ERROR_MARK)
6690     {
6691       error ("switch quantity not an integer");
6692       exp = error_mark_node;
6693     }
6694   else
6695     {
6696       tree index;
6697       type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
6698
6699       if (warn_traditional
6700           && ! in_system_header
6701           && (type == long_integer_type_node
6702               || type == long_unsigned_type_node))
6703         pedwarn ("`long' switch expression not converted to `int' in ANSI C");
6704
6705       exp = default_conversion (exp);
6706       type = TREE_TYPE (exp);
6707       index = get_unwidened (exp, NULL_TREE);
6708       /* We can't strip a conversion from a signed type to an unsigned,
6709          because if we did, int_fits_type_p would do the wrong thing
6710          when checking case values for being in range,
6711          and it's too hard to do the right thing.  */
6712       if (TREE_UNSIGNED (TREE_TYPE (exp))
6713           == TREE_UNSIGNED (TREE_TYPE (index)))
6714         exp = index;
6715     }
6716
6717   expand_start_case (1, exp, type, "switch statement");
6718
6719   return exp;
6720 }