OSDN Git Service

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