Merge from vendor branch LESS:
[dragonfly.git] / contrib / gcc-4.1 / gcc / c-typeck.c
1 /* Build expressions with type checking for C compiler.
2    Copyright (C) 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3    1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING.  If not, write to the Free
19 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301, USA.  */
21
22
23 /* This file is part of the C front end.
24    It contains routines to build C expressions given their operands,
25    including computing the types of the result, C-specific error checks,
26    and some optimization.  */
27
28 #include "config.h"
29 #include "system.h"
30 #include "coretypes.h"
31 #include "tm.h"
32 #include "rtl.h"
33 #include "tree.h"
34 #include "langhooks.h"
35 #include "c-tree.h"
36 #include "tm_p.h"
37 #include "flags.h"
38 #include "output.h"
39 #include "expr.h"
40 #include "toplev.h"
41 #include "intl.h"
42 #include "ggc.h"
43 #include "target.h"
44 #include "tree-iterator.h"
45 #include "tree-gimple.h"
46 #include "tree-flow.h"
47
48 /* Possible cases of implicit bad conversions.  Used to select
49    diagnostic messages in convert_for_assignment.  */
50 enum impl_conv {
51   ic_argpass,
52   ic_argpass_nonproto,
53   ic_assign,
54   ic_init,
55   ic_return
56 };
57
58 /* The level of nesting inside "__alignof__".  */
59 int in_alignof;
60
61 /* The level of nesting inside "sizeof".  */
62 int in_sizeof;
63
64 /* The level of nesting inside "typeof".  */
65 int in_typeof;
66
67 struct c_label_context_se *label_context_stack_se;
68 struct c_label_context_vm *label_context_stack_vm;
69
70 /* Nonzero if we've already printed a "missing braces around initializer"
71    message within this initializer.  */
72 static int missing_braces_mentioned;
73
74 static int require_constant_value;
75 static int require_constant_elements;
76
77 static tree qualify_type (tree, tree);
78 static int tagged_types_tu_compatible_p (tree, tree);
79 static int comp_target_types (tree, tree);
80 static int function_types_compatible_p (tree, tree);
81 static int type_lists_compatible_p (tree, tree);
82 static tree decl_constant_value_for_broken_optimization (tree);
83 static tree lookup_field (tree, tree);
84 static tree convert_arguments (tree, tree, tree, tree);
85 static tree pointer_diff (tree, tree);
86 static tree convert_for_assignment (tree, tree, enum impl_conv, tree, tree,
87                                     int);
88 static tree valid_compound_expr_initializer (tree, tree);
89 static void push_string (const char *);
90 static void push_member_name (tree);
91 static int spelling_length (void);
92 static char *print_spelling (char *);
93 static void warning_init (const char *);
94 static tree digest_init (tree, tree, bool, int);
95 static void output_init_element (tree, bool, tree, tree, int);
96 static void output_pending_init_elements (int);
97 static int set_designator (int);
98 static void push_range_stack (tree);
99 static void add_pending_init (tree, tree);
100 static void set_nonincremental_init (void);
101 static void set_nonincremental_init_from_string (tree);
102 static tree find_init_member (tree);
103 static void readonly_error (tree, enum lvalue_use);
104 static int lvalue_or_else (tree, enum lvalue_use);
105 static int lvalue_p (tree);
106 static void record_maybe_used_decl (tree);
107 static int comptypes_internal (tree, tree);
108 \f/* This is a cache to hold if two types are compatible or not.  */
109
110 struct tagged_tu_seen_cache {
111   const struct tagged_tu_seen_cache * next;
112   tree t1;
113   tree t2;
114   /* The return value of tagged_types_tu_compatible_p if we had seen
115      these two types already.  */
116   int val;
117 };
118
119 static const struct tagged_tu_seen_cache * tagged_tu_seen_base;
120 static void free_all_tagged_tu_seen_up_to (const struct tagged_tu_seen_cache *);
121
122 /* Do `exp = require_complete_type (exp);' to make sure exp
123    does not have an incomplete type.  (That includes void types.)  */
124
125 tree
126 require_complete_type (tree value)
127 {
128   tree type = TREE_TYPE (value);
129
130   if (value == error_mark_node || type == error_mark_node)
131     return error_mark_node;
132
133   /* First, detect a valid value with a complete type.  */
134   if (COMPLETE_TYPE_P (type))
135     return value;
136
137   c_incomplete_type_error (value, type);
138   return error_mark_node;
139 }
140
141 /* Print an error message for invalid use of an incomplete type.
142    VALUE is the expression that was used (or 0 if that isn't known)
143    and TYPE is the type that was invalid.  */
144
145 void
146 c_incomplete_type_error (tree value, tree type)
147 {
148   const char *type_code_string;
149
150   /* Avoid duplicate error message.  */
151   if (TREE_CODE (type) == ERROR_MARK)
152     return;
153
154   if (value != 0 && (TREE_CODE (value) == VAR_DECL
155                      || TREE_CODE (value) == PARM_DECL))
156     error ("%qD has an incomplete type", value);
157   else
158     {
159     retry:
160       /* We must print an error message.  Be clever about what it says.  */
161
162       switch (TREE_CODE (type))
163         {
164         case RECORD_TYPE:
165           type_code_string = "struct";
166           break;
167
168         case UNION_TYPE:
169           type_code_string = "union";
170           break;
171
172         case ENUMERAL_TYPE:
173           type_code_string = "enum";
174           break;
175
176         case VOID_TYPE:
177           error ("invalid use of void expression");
178           return;
179
180         case ARRAY_TYPE:
181           if (TYPE_DOMAIN (type))
182             {
183               if (TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL)
184                 {
185                   error ("invalid use of flexible array member");
186                   return;
187                 }
188               type = TREE_TYPE (type);
189               goto retry;
190             }
191           error ("invalid use of array with unspecified bounds");
192           return;
193
194         default:
195           gcc_unreachable ();
196         }
197
198       if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
199         error ("invalid use of undefined type %<%s %E%>",
200                type_code_string, TYPE_NAME (type));
201       else
202         /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL.  */
203         error ("invalid use of incomplete typedef %qD", TYPE_NAME (type));
204     }
205 }
206
207 /* Given a type, apply default promotions wrt unnamed function
208    arguments and return the new type.  */
209
210 tree
211 c_type_promotes_to (tree type)
212 {
213   if (TYPE_MAIN_VARIANT (type) == float_type_node)
214     return double_type_node;
215
216   if (c_promoting_integer_type_p (type))
217     {
218       /* Preserve unsignedness if not really getting any wider.  */
219       if (TYPE_UNSIGNED (type)
220           && (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)))
221         return unsigned_type_node;
222       return integer_type_node;
223     }
224
225   return type;
226 }
227
228 /* Return a variant of TYPE which has all the type qualifiers of LIKE
229    as well as those of TYPE.  */
230
231 static tree
232 qualify_type (tree type, tree like)
233 {
234   return c_build_qualified_type (type,
235                                  TYPE_QUALS (type) | TYPE_QUALS (like));
236 }
237 \f
238 /* Return the composite type of two compatible types.
239
240    We assume that comptypes has already been done and returned
241    nonzero; if that isn't so, this may crash.  In particular, we
242    assume that qualifiers match.  */
243
244 tree
245 composite_type (tree t1, tree t2)
246 {
247   enum tree_code code1;
248   enum tree_code code2;
249   tree attributes;
250
251   /* Save time if the two types are the same.  */
252
253   if (t1 == t2) return t1;
254
255   /* If one type is nonsense, use the other.  */
256   if (t1 == error_mark_node)
257     return t2;
258   if (t2 == error_mark_node)
259     return t1;
260
261   code1 = TREE_CODE (t1);
262   code2 = TREE_CODE (t2);
263
264   /* Merge the attributes.  */
265   attributes = targetm.merge_type_attributes (t1, t2);
266
267   /* If one is an enumerated type and the other is the compatible
268      integer type, the composite type might be either of the two
269      (DR#013 question 3).  For consistency, use the enumerated type as
270      the composite type.  */
271
272   if (code1 == ENUMERAL_TYPE && code2 == INTEGER_TYPE)
273     return t1;
274   if (code2 == ENUMERAL_TYPE && code1 == INTEGER_TYPE)
275     return t2;
276
277   gcc_assert (code1 == code2);
278
279   switch (code1)
280     {
281     case POINTER_TYPE:
282       /* For two pointers, do this recursively on the target type.  */
283       {
284         tree pointed_to_1 = TREE_TYPE (t1);
285         tree pointed_to_2 = TREE_TYPE (t2);
286         tree target = composite_type (pointed_to_1, pointed_to_2);
287         t1 = build_pointer_type (target);
288         t1 = build_type_attribute_variant (t1, attributes);
289         return qualify_type (t1, t2);
290       }
291
292     case ARRAY_TYPE:
293       {
294         tree elt = composite_type (TREE_TYPE (t1), TREE_TYPE (t2));
295         int quals;
296         tree unqual_elt;
297         tree d1 = TYPE_DOMAIN (t1);
298         tree d2 = TYPE_DOMAIN (t2);
299         bool d1_variable, d2_variable;
300         bool d1_zero, d2_zero;
301
302         /* We should not have any type quals on arrays at all.  */
303         gcc_assert (!TYPE_QUALS (t1) && !TYPE_QUALS (t2));
304         
305         d1_zero = d1 == 0 || !TYPE_MAX_VALUE (d1);
306         d2_zero = d2 == 0 || !TYPE_MAX_VALUE (d2);
307
308         d1_variable = (!d1_zero
309                        && (TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST
310                            || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST));
311         d2_variable = (!d2_zero
312                        && (TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
313                            || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST));
314
315         /* Save space: see if the result is identical to one of the args.  */
316         if (elt == TREE_TYPE (t1) && TYPE_DOMAIN (t1)
317             && (d2_variable || d2_zero || !d1_variable))
318           return build_type_attribute_variant (t1, attributes);
319         if (elt == TREE_TYPE (t2) && TYPE_DOMAIN (t2)
320             && (d1_variable || d1_zero || !d2_variable))
321           return build_type_attribute_variant (t2, attributes);
322         
323         if (elt == TREE_TYPE (t1) && !TYPE_DOMAIN (t2) && !TYPE_DOMAIN (t1))
324           return build_type_attribute_variant (t1, attributes);
325         if (elt == TREE_TYPE (t2) && !TYPE_DOMAIN (t2) && !TYPE_DOMAIN (t1))
326           return build_type_attribute_variant (t2, attributes);
327         
328         /* Merge the element types, and have a size if either arg has
329            one.  We may have qualifiers on the element types.  To set
330            up TYPE_MAIN_VARIANT correctly, we need to form the
331            composite of the unqualified types and add the qualifiers
332            back at the end.  */
333         quals = TYPE_QUALS (strip_array_types (elt));
334         unqual_elt = c_build_qualified_type (elt, TYPE_UNQUALIFIED);
335         t1 = build_array_type (unqual_elt,
336                                TYPE_DOMAIN ((TYPE_DOMAIN (t1)
337                                              && (d2_variable
338                                                  || d2_zero
339                                                  || !d1_variable))
340                                             ? t1
341                                             : t2));
342         t1 = c_build_qualified_type (t1, quals);
343         return build_type_attribute_variant (t1, attributes);
344       }
345
346     case FUNCTION_TYPE:
347       /* Function types: prefer the one that specified arg types.
348          If both do, merge the arg types.  Also merge the return types.  */
349       {
350         tree valtype = composite_type (TREE_TYPE (t1), TREE_TYPE (t2));
351         tree p1 = TYPE_ARG_TYPES (t1);
352         tree p2 = TYPE_ARG_TYPES (t2);
353         int len;
354         tree newargs, n;
355         int i;
356
357         /* Save space: see if the result is identical to one of the args.  */
358         if (valtype == TREE_TYPE (t1) && !TYPE_ARG_TYPES (t2))
359           return build_type_attribute_variant (t1, attributes);
360         if (valtype == TREE_TYPE (t2) && !TYPE_ARG_TYPES (t1))
361           return build_type_attribute_variant (t2, attributes);
362
363         /* Simple way if one arg fails to specify argument types.  */
364         if (TYPE_ARG_TYPES (t1) == 0)
365          {
366             t1 = build_function_type (valtype, TYPE_ARG_TYPES (t2));
367             t1 = build_type_attribute_variant (t1, attributes);
368             return qualify_type (t1, t2);
369          }
370         if (TYPE_ARG_TYPES (t2) == 0)
371          {
372            t1 = build_function_type (valtype, TYPE_ARG_TYPES (t1));
373            t1 = build_type_attribute_variant (t1, attributes);
374            return qualify_type (t1, t2);
375          }
376
377         /* If both args specify argument types, we must merge the two
378            lists, argument by argument.  */
379         /* Tell global_bindings_p to return false so that variable_size
380            doesn't die on VLAs in parameter types.  */
381         c_override_global_bindings_to_false = true;
382
383         len = list_length (p1);
384         newargs = 0;
385
386         for (i = 0; i < len; i++)
387           newargs = tree_cons (NULL_TREE, NULL_TREE, newargs);
388
389         n = newargs;
390
391         for (; p1;
392              p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2), n = TREE_CHAIN (n))
393           {
394             /* A null type means arg type is not specified.
395                Take whatever the other function type has.  */
396             if (TREE_VALUE (p1) == 0)
397               {
398                 TREE_VALUE (n) = TREE_VALUE (p2);
399                 goto parm_done;
400               }
401             if (TREE_VALUE (p2) == 0)
402               {
403                 TREE_VALUE (n) = TREE_VALUE (p1);
404                 goto parm_done;
405               }
406
407             /* Given  wait (union {union wait *u; int *i} *)
408                and  wait (union wait *),
409                prefer  union wait *  as type of parm.  */
410             if (TREE_CODE (TREE_VALUE (p1)) == UNION_TYPE
411                 && TREE_VALUE (p1) != TREE_VALUE (p2))
412               {
413                 tree memb;
414                 tree mv2 = TREE_VALUE (p2);
415                 if (mv2 && mv2 != error_mark_node
416                     && TREE_CODE (mv2) != ARRAY_TYPE)
417                   mv2 = TYPE_MAIN_VARIANT (mv2);
418                 for (memb = TYPE_FIELDS (TREE_VALUE (p1));
419                      memb; memb = TREE_CHAIN (memb))
420                   {
421                     tree mv3 = TREE_TYPE (memb);
422                     if (mv3 && mv3 != error_mark_node
423                         && TREE_CODE (mv3) != ARRAY_TYPE)
424                       mv3 = TYPE_MAIN_VARIANT (mv3);
425                     if (comptypes (mv3, mv2))
426                       {
427                         TREE_VALUE (n) = composite_type (TREE_TYPE (memb),
428                                                          TREE_VALUE (p2));
429                         if (pedantic)
430                           pedwarn ("function types not truly compatible in ISO C");
431                         goto parm_done;
432                       }
433                   }
434               }
435             if (TREE_CODE (TREE_VALUE (p2)) == UNION_TYPE
436                 && TREE_VALUE (p2) != TREE_VALUE (p1))
437               {
438                 tree memb;
439                 tree mv1 = TREE_VALUE (p1);
440                 if (mv1 && mv1 != error_mark_node
441                     && TREE_CODE (mv1) != ARRAY_TYPE)
442                   mv1 = TYPE_MAIN_VARIANT (mv1);
443                 for (memb = TYPE_FIELDS (TREE_VALUE (p2));
444                      memb; memb = TREE_CHAIN (memb))
445                   {
446                     tree mv3 = TREE_TYPE (memb);
447                     if (mv3 && mv3 != error_mark_node
448                         && TREE_CODE (mv3) != ARRAY_TYPE)
449                       mv3 = TYPE_MAIN_VARIANT (mv3);
450                     if (comptypes (mv3, mv1))
451                       {
452                         TREE_VALUE (n) = composite_type (TREE_TYPE (memb),
453                                                          TREE_VALUE (p1));
454                         if (pedantic)
455                           pedwarn ("function types not truly compatible in ISO C");
456                         goto parm_done;
457                       }
458                   }
459               }
460             TREE_VALUE (n) = composite_type (TREE_VALUE (p1), TREE_VALUE (p2));
461           parm_done: ;
462           }
463
464         c_override_global_bindings_to_false = false;
465         t1 = build_function_type (valtype, newargs);
466         t1 = qualify_type (t1, t2);
467         /* ... falls through ...  */
468       }
469
470     default:
471       return build_type_attribute_variant (t1, attributes);
472     }
473
474 }
475
476 /* Return the type of a conditional expression between pointers to
477    possibly differently qualified versions of compatible types.
478
479    We assume that comp_target_types has already been done and returned
480    nonzero; if that isn't so, this may crash.  */
481
482 static tree
483 common_pointer_type (tree t1, tree t2)
484 {
485   tree attributes;
486   tree pointed_to_1, mv1;
487   tree pointed_to_2, mv2;
488   tree target;
489
490   /* Save time if the two types are the same.  */
491
492   if (t1 == t2) return t1;
493
494   /* If one type is nonsense, use the other.  */
495   if (t1 == error_mark_node)
496     return t2;
497   if (t2 == error_mark_node)
498     return t1;
499
500   gcc_assert (TREE_CODE (t1) == POINTER_TYPE
501               && TREE_CODE (t2) == POINTER_TYPE);
502
503   /* Merge the attributes.  */
504   attributes = targetm.merge_type_attributes (t1, t2);
505
506   /* Find the composite type of the target types, and combine the
507      qualifiers of the two types' targets.  Do not lose qualifiers on
508      array element types by taking the TYPE_MAIN_VARIANT.  */
509   mv1 = pointed_to_1 = TREE_TYPE (t1);
510   mv2 = pointed_to_2 = TREE_TYPE (t2);
511   if (TREE_CODE (mv1) != ARRAY_TYPE)
512     mv1 = TYPE_MAIN_VARIANT (pointed_to_1);
513   if (TREE_CODE (mv2) != ARRAY_TYPE)
514     mv2 = TYPE_MAIN_VARIANT (pointed_to_2);
515   target = composite_type (mv1, mv2);
516   t1 = build_pointer_type (c_build_qualified_type
517                            (target,
518                             TYPE_QUALS (pointed_to_1) |
519                             TYPE_QUALS (pointed_to_2)));
520   return build_type_attribute_variant (t1, attributes);
521 }
522
523 /* Return the common type for two arithmetic types under the usual
524    arithmetic conversions.  The default conversions have already been
525    applied, and enumerated types converted to their compatible integer
526    types.  The resulting type is unqualified and has no attributes.
527
528    This is the type for the result of most arithmetic operations
529    if the operands have the given two types.  */
530
531 static tree
532 c_common_type (tree t1, tree t2)
533 {
534   enum tree_code code1;
535   enum tree_code code2;
536
537   /* If one type is nonsense, use the other.  */
538   if (t1 == error_mark_node)
539     return t2;
540   if (t2 == error_mark_node)
541     return t1;
542
543   if (TYPE_QUALS (t1) != TYPE_UNQUALIFIED)
544     t1 = TYPE_MAIN_VARIANT (t1);
545
546   if (TYPE_QUALS (t2) != TYPE_UNQUALIFIED)
547     t2 = TYPE_MAIN_VARIANT (t2);
548
549   if (TYPE_ATTRIBUTES (t1) != NULL_TREE)
550     t1 = build_type_attribute_variant (t1, NULL_TREE);
551
552   if (TYPE_ATTRIBUTES (t2) != NULL_TREE)
553     t2 = build_type_attribute_variant (t2, NULL_TREE);
554
555   /* Save time if the two types are the same.  */
556
557   if (t1 == t2) return t1;
558
559   code1 = TREE_CODE (t1);
560   code2 = TREE_CODE (t2);
561
562   gcc_assert (code1 == VECTOR_TYPE || code1 == COMPLEX_TYPE
563               || code1 == REAL_TYPE || code1 == INTEGER_TYPE);
564   gcc_assert (code2 == VECTOR_TYPE || code2 == COMPLEX_TYPE
565               || code2 == REAL_TYPE || code2 == INTEGER_TYPE);
566
567   /* If one type is a vector type, return that type.  (How the usual
568      arithmetic conversions apply to the vector types extension is not
569      precisely specified.)  */
570   if (code1 == VECTOR_TYPE)
571     return t1;
572
573   if (code2 == VECTOR_TYPE)
574     return t2;
575
576   /* If one type is complex, form the common type of the non-complex
577      components, then make that complex.  Use T1 or T2 if it is the
578      required type.  */
579   if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE)
580     {
581       tree subtype1 = code1 == COMPLEX_TYPE ? TREE_TYPE (t1) : t1;
582       tree subtype2 = code2 == COMPLEX_TYPE ? TREE_TYPE (t2) : t2;
583       tree subtype = c_common_type (subtype1, subtype2);
584
585       if (code1 == COMPLEX_TYPE && TREE_TYPE (t1) == subtype)
586         return t1;
587       else if (code2 == COMPLEX_TYPE && TREE_TYPE (t2) == subtype)
588         return t2;
589       else
590         return build_complex_type (subtype);
591     }
592
593   /* If only one is real, use it as the result.  */
594
595   if (code1 == REAL_TYPE && code2 != REAL_TYPE)
596     return t1;
597
598   if (code2 == REAL_TYPE && code1 != REAL_TYPE)
599     return t2;
600
601   /* Both real or both integers; use the one with greater precision.  */
602
603   if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2))
604     return t1;
605   else if (TYPE_PRECISION (t2) > TYPE_PRECISION (t1))
606     return t2;
607
608   /* Same precision.  Prefer long longs to longs to ints when the
609      same precision, following the C99 rules on integer type rank
610      (which are equivalent to the C90 rules for C90 types).  */
611
612   if (TYPE_MAIN_VARIANT (t1) == long_long_unsigned_type_node
613       || TYPE_MAIN_VARIANT (t2) == long_long_unsigned_type_node)
614     return long_long_unsigned_type_node;
615
616   if (TYPE_MAIN_VARIANT (t1) == long_long_integer_type_node
617       || TYPE_MAIN_VARIANT (t2) == long_long_integer_type_node)
618     {
619       if (TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
620         return long_long_unsigned_type_node;
621       else
622         return long_long_integer_type_node;
623     }
624
625   if (TYPE_MAIN_VARIANT (t1) == long_unsigned_type_node
626       || TYPE_MAIN_VARIANT (t2) == long_unsigned_type_node)
627     return long_unsigned_type_node;
628
629   if (TYPE_MAIN_VARIANT (t1) == long_integer_type_node
630       || TYPE_MAIN_VARIANT (t2) == long_integer_type_node)
631     {
632       /* But preserve unsignedness from the other type,
633          since long cannot hold all the values of an unsigned int.  */
634       if (TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
635         return long_unsigned_type_node;
636       else
637         return long_integer_type_node;
638     }
639
640   /* Likewise, prefer long double to double even if same size.  */
641   if (TYPE_MAIN_VARIANT (t1) == long_double_type_node
642       || TYPE_MAIN_VARIANT (t2) == long_double_type_node)
643     return long_double_type_node;
644
645   /* Otherwise prefer the unsigned one.  */
646
647   if (TYPE_UNSIGNED (t1))
648     return t1;
649   else
650     return t2;
651 }
652 \f
653 /* Wrapper around c_common_type that is used by c-common.c and other
654    front end optimizations that remove promotions.  ENUMERAL_TYPEs
655    are allowed here and are converted to their compatible integer types.
656    BOOLEAN_TYPEs are allowed here and return either boolean_type_node or
657    preferably a non-Boolean type as the common type.  */
658 tree
659 common_type (tree t1, tree t2)
660 {
661   if (TREE_CODE (t1) == ENUMERAL_TYPE)
662     t1 = c_common_type_for_size (TYPE_PRECISION (t1), 1);
663   if (TREE_CODE (t2) == ENUMERAL_TYPE)
664     t2 = c_common_type_for_size (TYPE_PRECISION (t2), 1);
665
666   /* If both types are BOOLEAN_TYPE, then return boolean_type_node.  */
667   if (TREE_CODE (t1) == BOOLEAN_TYPE
668       && TREE_CODE (t2) == BOOLEAN_TYPE)
669     return boolean_type_node;
670
671   /* If either type is BOOLEAN_TYPE, then return the other.  */
672   if (TREE_CODE (t1) == BOOLEAN_TYPE)
673     return t2;
674   if (TREE_CODE (t2) == BOOLEAN_TYPE)
675     return t1;
676
677   return c_common_type (t1, t2);
678 }
679
680 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
681    or various other operations.  Return 2 if they are compatible
682    but a warning may be needed if you use them together.  */
683
684 int
685 comptypes (tree type1, tree type2)
686 {
687   const struct tagged_tu_seen_cache * tagged_tu_seen_base1 = tagged_tu_seen_base;
688   int val;
689
690   val = comptypes_internal (type1, type2);
691   free_all_tagged_tu_seen_up_to (tagged_tu_seen_base1);
692   
693   return val;
694 }\f
695 /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
696    or various other operations.  Return 2 if they are compatible
697    but a warning may be needed if you use them together.  This
698    differs from comptypes, in that we don't free the seen types.  */
699
700 static int
701 comptypes_internal (tree type1, tree type2)
702 {
703   tree t1 = type1;
704   tree t2 = type2;
705   int attrval, val;
706
707   /* Suppress errors caused by previously reported errors.  */
708
709   if (t1 == t2 || !t1 || !t2
710       || TREE_CODE (t1) == ERROR_MARK || TREE_CODE (t2) == ERROR_MARK)
711     return 1;
712
713   /* If either type is the internal version of sizetype, return the
714      language version.  */
715   if (TREE_CODE (t1) == INTEGER_TYPE && TYPE_IS_SIZETYPE (t1)
716       && TYPE_ORIG_SIZE_TYPE (t1))
717     t1 = TYPE_ORIG_SIZE_TYPE (t1);
718
719   if (TREE_CODE (t2) == INTEGER_TYPE && TYPE_IS_SIZETYPE (t2)
720       && TYPE_ORIG_SIZE_TYPE (t2))
721     t2 = TYPE_ORIG_SIZE_TYPE (t2);
722
723
724   /* Enumerated types are compatible with integer types, but this is
725      not transitive: two enumerated types in the same translation unit
726      are compatible with each other only if they are the same type.  */
727
728   if (TREE_CODE (t1) == ENUMERAL_TYPE && TREE_CODE (t2) != ENUMERAL_TYPE)
729     t1 = c_common_type_for_size (TYPE_PRECISION (t1), TYPE_UNSIGNED (t1));
730   else if (TREE_CODE (t2) == ENUMERAL_TYPE && TREE_CODE (t1) != ENUMERAL_TYPE)
731     t2 = c_common_type_for_size (TYPE_PRECISION (t2), TYPE_UNSIGNED (t2));
732
733   if (t1 == t2)
734     return 1;
735
736   /* Different classes of types can't be compatible.  */
737
738   if (TREE_CODE (t1) != TREE_CODE (t2))
739     return 0;
740
741   /* Qualifiers must match. C99 6.7.3p9 */
742
743   if (TYPE_QUALS (t1) != TYPE_QUALS (t2))
744     return 0;
745
746   /* Allow for two different type nodes which have essentially the same
747      definition.  Note that we already checked for equality of the type
748      qualifiers (just above).  */
749
750   if (TREE_CODE (t1) != ARRAY_TYPE
751       && TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
752     return 1;
753
754   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
755   if (!(attrval = targetm.comp_type_attributes (t1, t2)))
756      return 0;
757
758   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
759   val = 0;
760
761   switch (TREE_CODE (t1))
762     {
763     case POINTER_TYPE:
764       /* Do not remove mode or aliasing information.  */
765       if (TYPE_MODE (t1) != TYPE_MODE (t2)
766           || TYPE_REF_CAN_ALIAS_ALL (t1) != TYPE_REF_CAN_ALIAS_ALL (t2))
767         break;
768       val = (TREE_TYPE (t1) == TREE_TYPE (t2)
769              ? 1 : comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2)));
770       break;
771
772     case FUNCTION_TYPE:
773       val = function_types_compatible_p (t1, t2);
774       break;
775
776     case ARRAY_TYPE:
777       {
778         tree d1 = TYPE_DOMAIN (t1);
779         tree d2 = TYPE_DOMAIN (t2);
780         bool d1_variable, d2_variable;
781         bool d1_zero, d2_zero;
782         val = 1;
783
784         /* Target types must match incl. qualifiers.  */
785         if (TREE_TYPE (t1) != TREE_TYPE (t2)
786             && 0 == (val = comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2))))
787           return 0;
788
789         /* Sizes must match unless one is missing or variable.  */
790         if (d1 == 0 || d2 == 0 || d1 == d2)
791           break;
792
793         d1_zero = !TYPE_MAX_VALUE (d1);
794         d2_zero = !TYPE_MAX_VALUE (d2);
795
796         d1_variable = (!d1_zero
797                        && (TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST
798                            || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST));
799         d2_variable = (!d2_zero
800                        && (TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
801                            || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST));
802
803         if (d1_variable || d2_variable)
804           break;
805         if (d1_zero && d2_zero)
806           break;
807         if (d1_zero || d2_zero
808             || !tree_int_cst_equal (TYPE_MIN_VALUE (d1), TYPE_MIN_VALUE (d2))
809             || !tree_int_cst_equal (TYPE_MAX_VALUE (d1), TYPE_MAX_VALUE (d2)))
810           val = 0;
811
812         break;
813       }
814
815     case ENUMERAL_TYPE:
816     case RECORD_TYPE:
817     case UNION_TYPE:
818       if (val != 1 && !same_translation_unit_p (t1, t2))
819         {
820           if (attrval != 2)
821             return tagged_types_tu_compatible_p (t1, t2);
822           val = tagged_types_tu_compatible_p (t1, t2);
823         }
824       break;
825
826     case VECTOR_TYPE:
827       val = TYPE_VECTOR_SUBPARTS (t1) == TYPE_VECTOR_SUBPARTS (t2)
828             && comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2));
829       break;
830
831     default:
832       break;
833     }
834   return attrval == 2 && val == 1 ? 2 : val;
835 }
836
837 /* Return 1 if TTL and TTR are pointers to types that are equivalent,
838    ignoring their qualifiers.  */
839
840 static int
841 comp_target_types (tree ttl, tree ttr)
842 {
843   int val;
844   tree mvl, mvr;
845
846   /* Do not lose qualifiers on element types of array types that are
847      pointer targets by taking their TYPE_MAIN_VARIANT.  */
848   mvl = TREE_TYPE (ttl);
849   mvr = TREE_TYPE (ttr);
850   if (TREE_CODE (mvl) != ARRAY_TYPE)
851     mvl = TYPE_MAIN_VARIANT (mvl);
852   if (TREE_CODE (mvr) != ARRAY_TYPE)
853     mvr = TYPE_MAIN_VARIANT (mvr);
854   val = comptypes (mvl, mvr);
855
856   if (val == 2 && pedantic)
857     pedwarn ("types are not quite compatible");
858   return val;
859 }
860 \f
861 /* Subroutines of `comptypes'.  */
862
863 /* Determine whether two trees derive from the same translation unit.
864    If the CONTEXT chain ends in a null, that tree's context is still
865    being parsed, so if two trees have context chains ending in null,
866    they're in the same translation unit.  */
867 int
868 same_translation_unit_p (tree t1, tree t2)
869 {
870   while (t1 && TREE_CODE (t1) != TRANSLATION_UNIT_DECL)
871     switch (TREE_CODE_CLASS (TREE_CODE (t1)))
872       {
873       case tcc_declaration:
874         t1 = DECL_CONTEXT (t1); break;
875       case tcc_type:
876         t1 = TYPE_CONTEXT (t1); break;
877       case tcc_exceptional:
878         t1 = BLOCK_SUPERCONTEXT (t1); break;  /* assume block */
879       default: gcc_unreachable ();
880       }
881
882   while (t2 && TREE_CODE (t2) != TRANSLATION_UNIT_DECL)
883     switch (TREE_CODE_CLASS (TREE_CODE (t2)))
884       {
885       case tcc_declaration:
886         t2 = DECL_CONTEXT (t2); break;
887       case tcc_type:
888         t2 = TYPE_CONTEXT (t2); break;
889       case tcc_exceptional:
890         t2 = BLOCK_SUPERCONTEXT (t2); break;  /* assume block */
891       default: gcc_unreachable ();
892       }
893
894   return t1 == t2;
895 }
896
897 /* Allocate the seen two types, assuming that they are compatible. */
898
899 static struct tagged_tu_seen_cache *
900 alloc_tagged_tu_seen_cache (tree t1, tree t2)
901 {
902   struct tagged_tu_seen_cache *tu = xmalloc (sizeof (struct tagged_tu_seen_cache));
903   tu->next = tagged_tu_seen_base;
904   tu->t1 = t1;
905   tu->t2 = t2;
906   
907   tagged_tu_seen_base = tu;
908   
909   /* The C standard says that two structures in different translation
910      units are compatible with each other only if the types of their
911      fields are compatible (among other things).  We assume that they
912      are compatible until proven otherwise when building the cache.
913      An example where this can occur is:
914      struct a
915      {
916        struct a *next;
917      };
918      If we are comparing this against a similar struct in another TU,
919      and did not assume they were compatible, we end up with an infinite
920      loop.  */
921   tu->val = 1;
922   return tu;
923 }
924
925 /* Free the seen types until we get to TU_TIL. */
926
927 static void
928 free_all_tagged_tu_seen_up_to (const struct tagged_tu_seen_cache *tu_til)
929 {
930   const struct tagged_tu_seen_cache *tu = tagged_tu_seen_base;
931   while (tu != tu_til)
932     {
933       struct tagged_tu_seen_cache *tu1 = (struct tagged_tu_seen_cache*)tu;
934       tu = tu1->next;
935       free (tu1);
936     }
937   tagged_tu_seen_base = tu_til;
938 }
939
940 /* Return 1 if two 'struct', 'union', or 'enum' types T1 and T2 are
941    compatible.  If the two types are not the same (which has been
942    checked earlier), this can only happen when multiple translation
943    units are being compiled.  See C99 6.2.7 paragraph 1 for the exact
944    rules.  */
945
946 static int
947 tagged_types_tu_compatible_p (tree t1, tree t2)
948 {
949   tree s1, s2;
950   bool needs_warning = false;
951
952   /* We have to verify that the tags of the types are the same.  This
953      is harder than it looks because this may be a typedef, so we have
954      to go look at the original type.  It may even be a typedef of a
955      typedef...
956      In the case of compiler-created builtin structs the TYPE_DECL
957      may be a dummy, with no DECL_ORIGINAL_TYPE.  Don't fault.  */
958   while (TYPE_NAME (t1)
959          && TREE_CODE (TYPE_NAME (t1)) == TYPE_DECL
960          && DECL_ORIGINAL_TYPE (TYPE_NAME (t1)))
961     t1 = DECL_ORIGINAL_TYPE (TYPE_NAME (t1));
962
963   while (TYPE_NAME (t2)
964          && TREE_CODE (TYPE_NAME (t2)) == TYPE_DECL
965          && DECL_ORIGINAL_TYPE (TYPE_NAME (t2)))
966     t2 = DECL_ORIGINAL_TYPE (TYPE_NAME (t2));
967
968   /* C90 didn't have the requirement that the two tags be the same.  */
969   if (flag_isoc99 && TYPE_NAME (t1) != TYPE_NAME (t2))
970     return 0;
971
972   /* C90 didn't say what happened if one or both of the types were
973      incomplete; we choose to follow C99 rules here, which is that they
974      are compatible.  */
975   if (TYPE_SIZE (t1) == NULL
976       || TYPE_SIZE (t2) == NULL)
977     return 1;
978
979   {
980     const struct tagged_tu_seen_cache * tts_i;
981     for (tts_i = tagged_tu_seen_base; tts_i != NULL; tts_i = tts_i->next)
982       if (tts_i->t1 == t1 && tts_i->t2 == t2)
983         return tts_i->val;
984   }
985
986   switch (TREE_CODE (t1))
987     {
988     case ENUMERAL_TYPE:
989       {
990         struct tagged_tu_seen_cache *tu = alloc_tagged_tu_seen_cache (t1, t2);
991         /* Speed up the case where the type values are in the same order.  */
992         tree tv1 = TYPE_VALUES (t1);
993         tree tv2 = TYPE_VALUES (t2);
994
995         if (tv1 == tv2)
996           {
997             return 1;
998           }
999
1000         for (;tv1 && tv2; tv1 = TREE_CHAIN (tv1), tv2 = TREE_CHAIN (tv2))
1001           {
1002             if (TREE_PURPOSE (tv1) != TREE_PURPOSE (tv2))
1003               break;
1004             if (simple_cst_equal (TREE_VALUE (tv1), TREE_VALUE (tv2)) != 1)
1005               {
1006                 tu->val = 0;
1007                 return 0;
1008               }
1009           }
1010
1011         if (tv1 == NULL_TREE && tv2 == NULL_TREE)
1012           {
1013             return 1;
1014           }
1015         if (tv1 == NULL_TREE || tv2 == NULL_TREE)
1016           {
1017             tu->val = 0;
1018             return 0;
1019           }
1020
1021         if (list_length (TYPE_VALUES (t1)) != list_length (TYPE_VALUES (t2)))
1022           {
1023             tu->val = 0;
1024             return 0;
1025           }
1026
1027         for (s1 = TYPE_VALUES (t1); s1; s1 = TREE_CHAIN (s1))
1028           {
1029             s2 = purpose_member (TREE_PURPOSE (s1), TYPE_VALUES (t2));
1030             if (s2 == NULL
1031                 || simple_cst_equal (TREE_VALUE (s1), TREE_VALUE (s2)) != 1)
1032               {
1033                 tu->val = 0;
1034                 return 0;
1035               }
1036           }
1037         return 1;
1038       }
1039
1040     case UNION_TYPE:
1041       {
1042         struct tagged_tu_seen_cache *tu = alloc_tagged_tu_seen_cache (t1, t2);
1043         if (list_length (TYPE_FIELDS (t1)) != list_length (TYPE_FIELDS (t2)))
1044           {
1045             tu->val = 0;
1046             return 0;
1047           }
1048         
1049         /*  Speed up the common case where the fields are in the same order. */
1050         for (s1 = TYPE_FIELDS (t1), s2 = TYPE_FIELDS (t2); s1 && s2;
1051              s1 = TREE_CHAIN (s1), s2 = TREE_CHAIN (s2))
1052           {
1053             int result;
1054             
1055             
1056             if (DECL_NAME (s1) == NULL
1057                 || DECL_NAME (s1) != DECL_NAME (s2))
1058               break;
1059             result = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2));
1060             if (result == 0)
1061               {
1062                 tu->val = 0;
1063                 return 0;
1064               }
1065             if (result == 2)
1066               needs_warning = true;
1067
1068             if (TREE_CODE (s1) == FIELD_DECL
1069                 && simple_cst_equal (DECL_FIELD_BIT_OFFSET (s1),
1070                                      DECL_FIELD_BIT_OFFSET (s2)) != 1)
1071               {
1072                 tu->val = 0;
1073                 return 0;
1074               }
1075           }
1076         if (!s1 && !s2)
1077           {
1078             tu->val = needs_warning ? 2 : 1;
1079             return tu->val;
1080           }
1081
1082         for (s1 = TYPE_FIELDS (t1); s1; s1 = TREE_CHAIN (s1))
1083           {
1084             bool ok = false;
1085
1086             if (DECL_NAME (s1) != NULL)
1087               for (s2 = TYPE_FIELDS (t2); s2; s2 = TREE_CHAIN (s2))
1088                 if (DECL_NAME (s1) == DECL_NAME (s2))
1089                   {
1090                     int result;
1091                     result = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2));
1092                     if (result == 0)
1093                       {
1094                         tu->val = 0;
1095                         return 0;
1096                       }
1097                     if (result == 2)
1098                       needs_warning = true;
1099
1100                     if (TREE_CODE (s1) == FIELD_DECL
1101                         && simple_cst_equal (DECL_FIELD_BIT_OFFSET (s1),
1102                                              DECL_FIELD_BIT_OFFSET (s2)) != 1)
1103                       break;
1104
1105                     ok = true;
1106                     break;
1107                   }
1108             if (!ok)
1109               {
1110                 tu->val = 0;
1111                 return 0;
1112               }
1113           }
1114         tu->val = needs_warning ? 2 : 10;
1115         return tu->val;
1116       }
1117
1118     case RECORD_TYPE:
1119       {
1120         struct tagged_tu_seen_cache *tu = alloc_tagged_tu_seen_cache (t1, t2);
1121
1122         for (s1 = TYPE_FIELDS (t1), s2 = TYPE_FIELDS (t2);
1123              s1 && s2;
1124              s1 = TREE_CHAIN (s1), s2 = TREE_CHAIN (s2))
1125           {
1126             int result;
1127             if (TREE_CODE (s1) != TREE_CODE (s2)
1128                 || DECL_NAME (s1) != DECL_NAME (s2))
1129               break;
1130             result = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2));
1131             if (result == 0)
1132               break;
1133             if (result == 2)
1134               needs_warning = true;
1135
1136             if (TREE_CODE (s1) == FIELD_DECL
1137                 && simple_cst_equal (DECL_FIELD_BIT_OFFSET (s1),
1138                                      DECL_FIELD_BIT_OFFSET (s2)) != 1)
1139               break;
1140           }
1141         if (s1 && s2)
1142           tu->val = 0;
1143         else
1144           tu->val = needs_warning ? 2 : 1;
1145         return tu->val;
1146       }
1147
1148     default:
1149       gcc_unreachable ();
1150     }
1151 }
1152
1153 /* Return 1 if two function types F1 and F2 are compatible.
1154    If either type specifies no argument types,
1155    the other must specify a fixed number of self-promoting arg types.
1156    Otherwise, if one type specifies only the number of arguments,
1157    the other must specify that number of self-promoting arg types.
1158    Otherwise, the argument types must match.  */
1159
1160 static int
1161 function_types_compatible_p (tree f1, tree f2)
1162 {
1163   tree args1, args2;
1164   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
1165   int val = 1;
1166   int val1;
1167   tree ret1, ret2;
1168
1169   ret1 = TREE_TYPE (f1);
1170   ret2 = TREE_TYPE (f2);
1171
1172   /* 'volatile' qualifiers on a function's return type used to mean
1173      the function is noreturn.  */
1174   if (TYPE_VOLATILE (ret1) != TYPE_VOLATILE (ret2))
1175     pedwarn ("function return types not compatible due to %<volatile%>");
1176   if (TYPE_VOLATILE (ret1))
1177     ret1 = build_qualified_type (TYPE_MAIN_VARIANT (ret1),
1178                                  TYPE_QUALS (ret1) & ~TYPE_QUAL_VOLATILE);
1179   if (TYPE_VOLATILE (ret2))
1180     ret2 = build_qualified_type (TYPE_MAIN_VARIANT (ret2),
1181                                  TYPE_QUALS (ret2) & ~TYPE_QUAL_VOLATILE);
1182   val = comptypes_internal (ret1, ret2);
1183   if (val == 0)
1184     return 0;
1185
1186   args1 = TYPE_ARG_TYPES (f1);
1187   args2 = TYPE_ARG_TYPES (f2);
1188
1189   /* An unspecified parmlist matches any specified parmlist
1190      whose argument types don't need default promotions.  */
1191
1192   if (args1 == 0)
1193     {
1194       if (!self_promoting_args_p (args2))
1195         return 0;
1196       /* If one of these types comes from a non-prototype fn definition,
1197          compare that with the other type's arglist.
1198          If they don't match, ask for a warning (but no error).  */
1199       if (TYPE_ACTUAL_ARG_TYPES (f1)
1200           && 1 != type_lists_compatible_p (args2, TYPE_ACTUAL_ARG_TYPES (f1)))
1201         val = 2;
1202       return val;
1203     }
1204   if (args2 == 0)
1205     {
1206       if (!self_promoting_args_p (args1))
1207         return 0;
1208       if (TYPE_ACTUAL_ARG_TYPES (f2)
1209           && 1 != type_lists_compatible_p (args1, TYPE_ACTUAL_ARG_TYPES (f2)))
1210         val = 2;
1211       return val;
1212     }
1213
1214   /* Both types have argument lists: compare them and propagate results.  */
1215   val1 = type_lists_compatible_p (args1, args2);
1216   return val1 != 1 ? val1 : val;
1217 }
1218
1219 /* Check two lists of types for compatibility,
1220    returning 0 for incompatible, 1 for compatible,
1221    or 2 for compatible with warning.  */
1222
1223 static int
1224 type_lists_compatible_p (tree args1, tree args2)
1225 {
1226   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
1227   int val = 1;
1228   int newval = 0;
1229
1230   while (1)
1231     {
1232       tree a1, mv1, a2, mv2;
1233       if (args1 == 0 && args2 == 0)
1234         return val;
1235       /* If one list is shorter than the other,
1236          they fail to match.  */
1237       if (args1 == 0 || args2 == 0)
1238         return 0;
1239       mv1 = a1 = TREE_VALUE (args1);
1240       mv2 = a2 = TREE_VALUE (args2);
1241       if (mv1 && mv1 != error_mark_node && TREE_CODE (mv1) != ARRAY_TYPE)
1242         mv1 = TYPE_MAIN_VARIANT (mv1);
1243       if (mv2 && mv2 != error_mark_node && TREE_CODE (mv2) != ARRAY_TYPE)
1244         mv2 = TYPE_MAIN_VARIANT (mv2);
1245       /* A null pointer instead of a type
1246          means there is supposed to be an argument
1247          but nothing is specified about what type it has.
1248          So match anything that self-promotes.  */
1249       if (a1 == 0)
1250         {
1251           if (c_type_promotes_to (a2) != a2)
1252             return 0;
1253         }
1254       else if (a2 == 0)
1255         {
1256           if (c_type_promotes_to (a1) != a1)
1257             return 0;
1258         }
1259       /* If one of the lists has an error marker, ignore this arg.  */
1260       else if (TREE_CODE (a1) == ERROR_MARK
1261                || TREE_CODE (a2) == ERROR_MARK)
1262         ;
1263       else if (!(newval = comptypes_internal (mv1, mv2)))
1264         {
1265           /* Allow  wait (union {union wait *u; int *i} *)
1266              and  wait (union wait *)  to be compatible.  */
1267           if (TREE_CODE (a1) == UNION_TYPE
1268               && (TYPE_NAME (a1) == 0
1269                   || TYPE_TRANSPARENT_UNION (a1))
1270               && TREE_CODE (TYPE_SIZE (a1)) == INTEGER_CST
1271               && tree_int_cst_equal (TYPE_SIZE (a1),
1272                                      TYPE_SIZE (a2)))
1273             {
1274               tree memb;
1275               for (memb = TYPE_FIELDS (a1);
1276                    memb; memb = TREE_CHAIN (memb))
1277                 {
1278                   tree mv3 = TREE_TYPE (memb);
1279                   if (mv3 && mv3 != error_mark_node
1280                       && TREE_CODE (mv3) != ARRAY_TYPE)
1281                     mv3 = TYPE_MAIN_VARIANT (mv3);
1282                   if (comptypes_internal (mv3, mv2))
1283                     break;
1284                 }
1285               if (memb == 0)
1286                 return 0;
1287             }
1288           else if (TREE_CODE (a2) == UNION_TYPE
1289                    && (TYPE_NAME (a2) == 0
1290                        || TYPE_TRANSPARENT_UNION (a2))
1291                    && TREE_CODE (TYPE_SIZE (a2)) == INTEGER_CST
1292                    && tree_int_cst_equal (TYPE_SIZE (a2),
1293                                           TYPE_SIZE (a1)))
1294             {
1295               tree memb;
1296               for (memb = TYPE_FIELDS (a2);
1297                    memb; memb = TREE_CHAIN (memb))
1298                 {
1299                   tree mv3 = TREE_TYPE (memb);
1300                   if (mv3 && mv3 != error_mark_node
1301                       && TREE_CODE (mv3) != ARRAY_TYPE)
1302                     mv3 = TYPE_MAIN_VARIANT (mv3);
1303                   if (comptypes_internal (mv3, mv1))
1304                     break;
1305                 }
1306               if (memb == 0)
1307                 return 0;
1308             }
1309           else
1310             return 0;
1311         }
1312
1313       /* comptypes said ok, but record if it said to warn.  */
1314       if (newval > val)
1315         val = newval;
1316
1317       args1 = TREE_CHAIN (args1);
1318       args2 = TREE_CHAIN (args2);
1319     }
1320 }
1321 \f
1322 /* Compute the size to increment a pointer by.  */
1323
1324 static tree
1325 c_size_in_bytes (tree type)
1326 {
1327   enum tree_code code = TREE_CODE (type);
1328
1329   if (code == FUNCTION_TYPE || code == VOID_TYPE || code == ERROR_MARK)
1330     return size_one_node;
1331
1332   if (!COMPLETE_OR_VOID_TYPE_P (type))
1333     {
1334       error ("arithmetic on pointer to an incomplete type");
1335       return size_one_node;
1336     }
1337
1338   /* Convert in case a char is more than one unit.  */
1339   return size_binop (CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
1340                      size_int (TYPE_PRECISION (char_type_node)
1341                                / BITS_PER_UNIT));
1342 }
1343 \f
1344 /* Return either DECL or its known constant value (if it has one).  */
1345
1346 tree
1347 decl_constant_value (tree decl)
1348 {
1349   if (/* Don't change a variable array bound or initial value to a constant
1350          in a place where a variable is invalid.  Note that DECL_INITIAL
1351          isn't valid for a PARM_DECL.  */
1352       current_function_decl != 0
1353       && TREE_CODE (decl) != PARM_DECL
1354       && !TREE_THIS_VOLATILE (decl)
1355       && TREE_READONLY (decl)
1356       && DECL_INITIAL (decl) != 0
1357       && TREE_CODE (DECL_INITIAL (decl)) != ERROR_MARK
1358       /* This is invalid if initial value is not constant.
1359          If it has either a function call, a memory reference,
1360          or a variable, then re-evaluating it could give different results.  */
1361       && TREE_CONSTANT (DECL_INITIAL (decl))
1362       /* Check for cases where this is sub-optimal, even though valid.  */
1363       && TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR)
1364     return DECL_INITIAL (decl);
1365   return decl;
1366 }
1367
1368 /* Return either DECL or its known constant value (if it has one), but
1369    return DECL if pedantic or DECL has mode BLKmode.  This is for
1370    bug-compatibility with the old behavior of decl_constant_value
1371    (before GCC 3.0); every use of this function is a bug and it should
1372    be removed before GCC 3.1.  It is not appropriate to use pedantic
1373    in a way that affects optimization, and BLKmode is probably not the
1374    right test for avoiding misoptimizations either.  */
1375
1376 static tree
1377 decl_constant_value_for_broken_optimization (tree decl)
1378 {
1379   tree ret;
1380
1381   if (pedantic || DECL_MODE (decl) == BLKmode)
1382     return decl;
1383
1384   ret = decl_constant_value (decl);
1385   /* Avoid unwanted tree sharing between the initializer and current
1386      function's body where the tree can be modified e.g. by the
1387      gimplifier.  */
1388   if (ret != decl && TREE_STATIC (decl))
1389     ret = unshare_expr (ret);
1390   return ret;
1391 }
1392
1393 /* Convert the array expression EXP to a pointer.  */
1394 static tree
1395 array_to_pointer_conversion (tree exp)
1396 {
1397   tree orig_exp = exp;
1398   tree type = TREE_TYPE (exp);
1399   tree adr;
1400   tree restype = TREE_TYPE (type);
1401   tree ptrtype;
1402
1403   gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
1404
1405   STRIP_TYPE_NOPS (exp);
1406
1407   if (TREE_NO_WARNING (orig_exp))
1408     TREE_NO_WARNING (exp) = 1;
1409
1410   ptrtype = build_pointer_type (restype);
1411
1412   if (TREE_CODE (exp) == INDIRECT_REF)
1413     return convert (ptrtype, TREE_OPERAND (exp, 0));
1414
1415   if (TREE_CODE (exp) == VAR_DECL)
1416     {
1417       /* We are making an ADDR_EXPR of ptrtype.  This is a valid
1418          ADDR_EXPR because it's the best way of representing what
1419          happens in C when we take the address of an array and place
1420          it in a pointer to the element type.  */
1421       adr = build1 (ADDR_EXPR, ptrtype, exp);
1422       if (!c_mark_addressable (exp))
1423         return error_mark_node;
1424       TREE_SIDE_EFFECTS (adr) = 0;   /* Default would be, same as EXP.  */
1425       return adr;
1426     }
1427
1428   /* This way is better for a COMPONENT_REF since it can
1429      simplify the offset for a component.  */
1430   adr = build_unary_op (ADDR_EXPR, exp, 1);
1431   return convert (ptrtype, adr);
1432 }
1433
1434 /* Convert the function expression EXP to a pointer.  */
1435 static tree
1436 function_to_pointer_conversion (tree exp)
1437 {
1438   tree orig_exp = exp;
1439
1440   gcc_assert (TREE_CODE (TREE_TYPE (exp)) == FUNCTION_TYPE);
1441
1442   STRIP_TYPE_NOPS (exp);
1443
1444   if (TREE_NO_WARNING (orig_exp))
1445     TREE_NO_WARNING (exp) = 1;
1446
1447   return build_unary_op (ADDR_EXPR, exp, 0);
1448 }
1449
1450 /* Perform the default conversion of arrays and functions to pointers.
1451    Return the result of converting EXP.  For any other expression, just
1452    return EXP after removing NOPs.  */
1453
1454 struct c_expr
1455 default_function_array_conversion (struct c_expr exp)
1456 {
1457   tree orig_exp = exp.value;
1458   tree type = TREE_TYPE (exp.value);
1459   enum tree_code code = TREE_CODE (type);
1460
1461   switch (code)
1462     {
1463     case ARRAY_TYPE:
1464       {
1465         bool not_lvalue = false;
1466         bool lvalue_array_p;
1467
1468         while ((TREE_CODE (exp.value) == NON_LVALUE_EXPR
1469                 || TREE_CODE (exp.value) == NOP_EXPR)
1470                && TREE_TYPE (TREE_OPERAND (exp.value, 0)) == type)
1471           {
1472             if (TREE_CODE (exp.value) == NON_LVALUE_EXPR)
1473               not_lvalue = true;
1474             exp.value = TREE_OPERAND (exp.value, 0);
1475           }
1476
1477         if (TREE_NO_WARNING (orig_exp))
1478           TREE_NO_WARNING (exp.value) = 1;
1479
1480         lvalue_array_p = !not_lvalue && lvalue_p (exp.value);
1481         if (!flag_isoc99 && !lvalue_array_p)
1482           {
1483             /* Before C99, non-lvalue arrays do not decay to pointers.
1484                Normally, using such an array would be invalid; but it can
1485                be used correctly inside sizeof or as a statement expression.
1486                Thus, do not give an error here; an error will result later.  */
1487             return exp;
1488           }
1489
1490         exp.value = array_to_pointer_conversion (exp.value);
1491       }
1492       break;
1493     case FUNCTION_TYPE:
1494       exp.value = function_to_pointer_conversion (exp.value);
1495       break;
1496     default:
1497       STRIP_TYPE_NOPS (exp.value);
1498       if (TREE_NO_WARNING (orig_exp))
1499         TREE_NO_WARNING (exp.value) = 1;
1500       break;
1501     }
1502
1503   return exp;
1504 }
1505
1506
1507 /* EXP is an expression of integer type.  Apply the integer promotions
1508    to it and return the promoted value.  */
1509
1510 tree
1511 perform_integral_promotions (tree exp)
1512 {
1513   tree type = TREE_TYPE (exp);
1514   enum tree_code code = TREE_CODE (type);
1515
1516   gcc_assert (INTEGRAL_TYPE_P (type));
1517
1518   /* Normally convert enums to int,
1519      but convert wide enums to something wider.  */
1520   if (code == ENUMERAL_TYPE)
1521     {
1522       type = c_common_type_for_size (MAX (TYPE_PRECISION (type),
1523                                           TYPE_PRECISION (integer_type_node)),
1524                                      ((TYPE_PRECISION (type)
1525                                        >= TYPE_PRECISION (integer_type_node))
1526                                       && TYPE_UNSIGNED (type)));
1527
1528       return convert (type, exp);
1529     }
1530
1531   /* ??? This should no longer be needed now bit-fields have their
1532      proper types.  */
1533   if (TREE_CODE (exp) == COMPONENT_REF
1534       && DECL_C_BIT_FIELD (TREE_OPERAND (exp, 1))
1535       /* If it's thinner than an int, promote it like a
1536          c_promoting_integer_type_p, otherwise leave it alone.  */
1537       && 0 > compare_tree_int (DECL_SIZE (TREE_OPERAND (exp, 1)),
1538                                TYPE_PRECISION (integer_type_node)))
1539     return convert (integer_type_node, exp);
1540
1541   if (c_promoting_integer_type_p (type))
1542     {
1543       /* Preserve unsignedness if not really getting any wider.  */
1544       if (TYPE_UNSIGNED (type)
1545           && TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
1546         return convert (unsigned_type_node, exp);
1547
1548       return convert (integer_type_node, exp);
1549     }
1550
1551   return exp;
1552 }
1553
1554
1555 /* Perform default promotions for C data used in expressions.
1556    Enumeral types or short or char are converted to int.
1557    In addition, manifest constants symbols are replaced by their values.  */
1558
1559 tree
1560 default_conversion (tree exp)
1561 {
1562   tree orig_exp;
1563   tree type = TREE_TYPE (exp);
1564   enum tree_code code = TREE_CODE (type);
1565
1566   /* Functions and arrays have been converted during parsing.  */
1567   gcc_assert (code != FUNCTION_TYPE);
1568   if (code == ARRAY_TYPE)
1569     return exp;
1570
1571   /* Constants can be used directly unless they're not loadable.  */
1572   if (TREE_CODE (exp) == CONST_DECL)
1573     exp = DECL_INITIAL (exp);
1574
1575   /* Replace a nonvolatile const static variable with its value unless
1576      it is an array, in which case we must be sure that taking the
1577      address of the array produces consistent results.  */
1578   else if (optimize && TREE_CODE (exp) == VAR_DECL && code != ARRAY_TYPE)
1579     {
1580       exp = decl_constant_value_for_broken_optimization (exp);
1581       type = TREE_TYPE (exp);
1582     }
1583
1584   /* Strip no-op conversions.  */
1585   orig_exp = exp;
1586   STRIP_TYPE_NOPS (exp);
1587
1588   if (TREE_NO_WARNING (orig_exp))
1589     TREE_NO_WARNING (exp) = 1;
1590
1591   if (INTEGRAL_TYPE_P (type))
1592     return perform_integral_promotions (exp);
1593
1594   if (code == VOID_TYPE)
1595     {
1596       error ("void value not ignored as it ought to be");
1597       return error_mark_node;
1598     }
1599   return exp;
1600 }
1601 \f
1602 /* Look up COMPONENT in a structure or union DECL.
1603
1604    If the component name is not found, returns NULL_TREE.  Otherwise,
1605    the return value is a TREE_LIST, with each TREE_VALUE a FIELD_DECL
1606    stepping down the chain to the component, which is in the last
1607    TREE_VALUE of the list.  Normally the list is of length one, but if
1608    the component is embedded within (nested) anonymous structures or
1609    unions, the list steps down the chain to the component.  */
1610
1611 static tree
1612 lookup_field (tree decl, tree component)
1613 {
1614   tree type = TREE_TYPE (decl);
1615   tree field;
1616
1617   /* If TYPE_LANG_SPECIFIC is set, then it is a sorted array of pointers
1618      to the field elements.  Use a binary search on this array to quickly
1619      find the element.  Otherwise, do a linear search.  TYPE_LANG_SPECIFIC
1620      will always be set for structures which have many elements.  */
1621
1622   if (TYPE_LANG_SPECIFIC (type) && TYPE_LANG_SPECIFIC (type)->s)
1623     {
1624       int bot, top, half;
1625       tree *field_array = &TYPE_LANG_SPECIFIC (type)->s->elts[0];
1626
1627       field = TYPE_FIELDS (type);
1628       bot = 0;
1629       top = TYPE_LANG_SPECIFIC (type)->s->len;
1630       while (top - bot > 1)
1631         {
1632           half = (top - bot + 1) >> 1;
1633           field = field_array[bot+half];
1634
1635           if (DECL_NAME (field) == NULL_TREE)
1636             {
1637               /* Step through all anon unions in linear fashion.  */
1638               while (DECL_NAME (field_array[bot]) == NULL_TREE)
1639                 {
1640                   field = field_array[bot++];
1641                   if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE
1642                       || TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)
1643                     {
1644                       tree anon = lookup_field (field, component);
1645
1646                       if (anon)
1647                         return tree_cons (NULL_TREE, field, anon);
1648                     }
1649                 }
1650
1651               /* Entire record is only anon unions.  */
1652               if (bot > top)
1653                 return NULL_TREE;
1654
1655               /* Restart the binary search, with new lower bound.  */
1656               continue;
1657             }
1658
1659           if (DECL_NAME (field) == component)
1660             break;
1661           if (DECL_NAME (field) < component)
1662             bot += half;
1663           else
1664             top = bot + half;
1665         }
1666
1667       if (DECL_NAME (field_array[bot]) == component)
1668         field = field_array[bot];
1669       else if (DECL_NAME (field) != component)
1670         return NULL_TREE;
1671     }
1672   else
1673     {
1674       for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
1675         {
1676           if (DECL_NAME (field) == NULL_TREE
1677               && (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE
1678                   || TREE_CODE (TREE_TYPE (field)) == UNION_TYPE))
1679             {
1680               tree anon = lookup_field (field, component);
1681
1682               if (anon)
1683                 return tree_cons (NULL_TREE, field, anon);
1684             }
1685
1686           if (DECL_NAME (field) == component)
1687             break;
1688         }
1689
1690       if (field == NULL_TREE)
1691         return NULL_TREE;
1692     }
1693
1694   return tree_cons (NULL_TREE, field, NULL_TREE);
1695 }
1696
1697 /* Make an expression to refer to the COMPONENT field of
1698    structure or union value DATUM.  COMPONENT is an IDENTIFIER_NODE.  */
1699
1700 tree
1701 build_component_ref (tree datum, tree component)
1702 {
1703   tree type = TREE_TYPE (datum);
1704   enum tree_code code = TREE_CODE (type);
1705   tree field = NULL;
1706   tree ref;
1707
1708   if (!objc_is_public (datum, component))
1709     return error_mark_node;
1710
1711   /* See if there is a field or component with name COMPONENT.  */
1712
1713   if (code == RECORD_TYPE || code == UNION_TYPE)
1714     {
1715       if (!COMPLETE_TYPE_P (type))
1716         {
1717           c_incomplete_type_error (NULL_TREE, type);
1718           return error_mark_node;
1719         }
1720
1721       field = lookup_field (datum, component);
1722
1723       if (!field)
1724         {
1725           error ("%qT has no member named %qE", type, component);
1726           return error_mark_node;
1727         }
1728
1729       /* Chain the COMPONENT_REFs if necessary down to the FIELD.
1730          This might be better solved in future the way the C++ front
1731          end does it - by giving the anonymous entities each a
1732          separate name and type, and then have build_component_ref
1733          recursively call itself.  We can't do that here.  */
1734       do
1735         {
1736           tree subdatum = TREE_VALUE (field);
1737
1738           if (TREE_TYPE (subdatum) == error_mark_node)
1739             return error_mark_node;
1740
1741           ref = build3 (COMPONENT_REF, TREE_TYPE (subdatum), datum, subdatum,
1742                         NULL_TREE);
1743           if (TREE_READONLY (datum) || TREE_READONLY (subdatum))
1744             TREE_READONLY (ref) = 1;
1745           if (TREE_THIS_VOLATILE (datum) || TREE_THIS_VOLATILE (subdatum))
1746             TREE_THIS_VOLATILE (ref) = 1;
1747
1748           if (TREE_DEPRECATED (subdatum))
1749             warn_deprecated_use (subdatum);
1750
1751           datum = ref;
1752
1753           field = TREE_CHAIN (field);
1754         }
1755       while (field);
1756
1757       return ref;
1758     }
1759   else if (code != ERROR_MARK)
1760     error ("request for member %qE in something not a structure or union",
1761            component);
1762
1763   return error_mark_node;
1764 }
1765 \f
1766 /* Given an expression PTR for a pointer, return an expression
1767    for the value pointed to.
1768    ERRORSTRING is the name of the operator to appear in error messages.  */
1769
1770 tree
1771 build_indirect_ref (tree ptr, const char *errorstring)
1772 {
1773   tree pointer = default_conversion (ptr);
1774   tree type = TREE_TYPE (pointer);
1775
1776   if (TREE_CODE (type) == POINTER_TYPE)
1777     {
1778       if (TREE_CODE (pointer) == ADDR_EXPR
1779           && (TREE_TYPE (TREE_OPERAND (pointer, 0))
1780               == TREE_TYPE (type)))
1781         return TREE_OPERAND (pointer, 0);
1782       else
1783         {
1784           tree t = TREE_TYPE (type);
1785           tree ref;
1786
1787           ref = build1 (INDIRECT_REF, t, pointer);
1788
1789           if (!COMPLETE_OR_VOID_TYPE_P (t) && TREE_CODE (t) != ARRAY_TYPE)
1790             {
1791               error ("dereferencing pointer to incomplete type");
1792               return error_mark_node;
1793             }
1794           if (VOID_TYPE_P (t) && skip_evaluation == 0)
1795             warning (0, "dereferencing %<void *%> pointer");
1796
1797           /* We *must* set TREE_READONLY when dereferencing a pointer to const,
1798              so that we get the proper error message if the result is used
1799              to assign to.  Also, &* is supposed to be a no-op.
1800              And ANSI C seems to specify that the type of the result
1801              should be the const type.  */
1802           /* A de-reference of a pointer to const is not a const.  It is valid
1803              to change it via some other pointer.  */
1804           TREE_READONLY (ref) = TYPE_READONLY (t);
1805           TREE_SIDE_EFFECTS (ref)
1806             = TYPE_VOLATILE (t) || TREE_SIDE_EFFECTS (pointer);
1807           TREE_THIS_VOLATILE (ref) = TYPE_VOLATILE (t);
1808           return ref;
1809         }
1810     }
1811   else if (TREE_CODE (pointer) != ERROR_MARK)
1812     error ("invalid type argument of %qs", errorstring);
1813   return error_mark_node;
1814 }
1815
1816 /* This handles expressions of the form "a[i]", which denotes
1817    an array reference.
1818
1819    This is logically equivalent in C to *(a+i), but we may do it differently.
1820    If A is a variable or a member, we generate a primitive ARRAY_REF.
1821    This avoids forcing the array out of registers, and can work on
1822    arrays that are not lvalues (for example, members of structures returned
1823    by functions).  */
1824
1825 tree
1826 build_array_ref (tree array, tree index)
1827 {
1828   bool swapped = false;
1829   if (TREE_TYPE (array) == error_mark_node
1830       || TREE_TYPE (index) == error_mark_node)
1831     return error_mark_node;
1832
1833   if (TREE_CODE (TREE_TYPE (array)) != ARRAY_TYPE
1834       && TREE_CODE (TREE_TYPE (array)) != POINTER_TYPE)
1835     {
1836       tree temp;
1837       if (TREE_CODE (TREE_TYPE (index)) != ARRAY_TYPE
1838           && TREE_CODE (TREE_TYPE (index)) != POINTER_TYPE)
1839         {
1840           error ("subscripted value is neither array nor pointer");
1841           return error_mark_node;
1842         }
1843       temp = array;
1844       array = index;
1845       index = temp;
1846       swapped = true;
1847     }
1848
1849   if (!INTEGRAL_TYPE_P (TREE_TYPE (index)))
1850     {
1851       error ("array subscript is not an integer");
1852       return error_mark_node;
1853     }
1854
1855   if (TREE_CODE (TREE_TYPE (TREE_TYPE (array))) == FUNCTION_TYPE)
1856     {
1857       error ("subscripted value is pointer to function");
1858       return error_mark_node;
1859     }
1860
1861   /* Subscripting with type char is likely to lose on a machine where
1862      chars are signed.  So warn on any machine, but optionally.  Don't
1863      warn for unsigned char since that type is safe.  Don't warn for
1864      signed char because anyone who uses that must have done so
1865      deliberately.  ??? Existing practice has also been to warn only
1866      when the char index is syntactically the index, not for
1867      char[array].  */
1868   if (!swapped
1869       && TYPE_MAIN_VARIANT (TREE_TYPE (index)) == char_type_node)
1870     warning (OPT_Wchar_subscripts, "array subscript has type %<char%>");
1871
1872   /* Apply default promotions *after* noticing character types.  */
1873   index = default_conversion (index);
1874
1875   gcc_assert (TREE_CODE (TREE_TYPE (index)) == INTEGER_TYPE);
1876
1877   if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE)
1878     {
1879       tree rval, type;
1880
1881       /* An array that is indexed by a non-constant
1882          cannot be stored in a register; we must be able to do
1883          address arithmetic on its address.
1884          Likewise an array of elements of variable size.  */
1885       if (TREE_CODE (index) != INTEGER_CST
1886           || (COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (array)))
1887               && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array)))) != INTEGER_CST))
1888         {
1889           if (!c_mark_addressable (array))
1890             return error_mark_node;
1891         }
1892       /* An array that is indexed by a constant value which is not within
1893          the array bounds cannot be stored in a register either; because we
1894          would get a crash in store_bit_field/extract_bit_field when trying
1895          to access a non-existent part of the register.  */
1896       if (TREE_CODE (index) == INTEGER_CST
1897           && TYPE_DOMAIN (TREE_TYPE (array))
1898           && !int_fits_type_p (index, TYPE_DOMAIN (TREE_TYPE (array))))
1899         {
1900           if (!c_mark_addressable (array))
1901             return error_mark_node;
1902         }
1903
1904       if (pedantic)
1905         {
1906           tree foo = array;
1907           while (TREE_CODE (foo) == COMPONENT_REF)
1908             foo = TREE_OPERAND (foo, 0);
1909           if (TREE_CODE (foo) == VAR_DECL && C_DECL_REGISTER (foo))
1910             pedwarn ("ISO C forbids subscripting %<register%> array");
1911           else if (!flag_isoc99 && !lvalue_p (foo))
1912             pedwarn ("ISO C90 forbids subscripting non-lvalue array");
1913         }
1914
1915       type = TREE_TYPE (TREE_TYPE (array));
1916       if (TREE_CODE (type) != ARRAY_TYPE)
1917         type = TYPE_MAIN_VARIANT (type);
1918       rval = build4 (ARRAY_REF, type, array, index, NULL_TREE, NULL_TREE);
1919       /* Array ref is const/volatile if the array elements are
1920          or if the array is.  */
1921       TREE_READONLY (rval)
1922         |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array)))
1923             | TREE_READONLY (array));
1924       TREE_SIDE_EFFECTS (rval)
1925         |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
1926             | TREE_SIDE_EFFECTS (array));
1927       TREE_THIS_VOLATILE (rval)
1928         |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
1929             /* This was added by rms on 16 Nov 91.
1930                It fixes  vol struct foo *a;  a->elts[1]
1931                in an inline function.
1932                Hope it doesn't break something else.  */
1933             | TREE_THIS_VOLATILE (array));
1934       return require_complete_type (fold (rval));
1935     }
1936   else
1937     {
1938       tree ar = default_conversion (array);
1939
1940       if (ar == error_mark_node)
1941         return ar;
1942
1943       gcc_assert (TREE_CODE (TREE_TYPE (ar)) == POINTER_TYPE);
1944       gcc_assert (TREE_CODE (TREE_TYPE (TREE_TYPE (ar))) != FUNCTION_TYPE);
1945
1946       return build_indirect_ref (build_binary_op (PLUS_EXPR, ar, index, 0),
1947                                  "array indexing");
1948     }
1949 }
1950 \f
1951 /* Build an external reference to identifier ID.  FUN indicates
1952    whether this will be used for a function call.  LOC is the source
1953    location of the identifier.  */
1954 tree
1955 build_external_ref (tree id, int fun, location_t loc)
1956 {
1957   tree ref;
1958   tree decl = lookup_name (id);
1959
1960   /* In Objective-C, an instance variable (ivar) may be preferred to
1961      whatever lookup_name() found.  */
1962   decl = objc_lookup_ivar (decl, id);
1963
1964   if (decl && decl != error_mark_node)
1965     ref = decl;
1966   else if (fun)
1967     /* Implicit function declaration.  */
1968     ref = implicitly_declare (id);
1969   else if (decl == error_mark_node)
1970     /* Don't complain about something that's already been
1971        complained about.  */
1972     return error_mark_node;
1973   else
1974     {
1975       undeclared_variable (id, loc);
1976       return error_mark_node;
1977     }
1978
1979   if (TREE_TYPE (ref) == error_mark_node)
1980     return error_mark_node;
1981
1982   if (TREE_DEPRECATED (ref))
1983     warn_deprecated_use (ref);
1984
1985   if (!skip_evaluation)
1986     assemble_external (ref);
1987   TREE_USED (ref) = 1;
1988
1989   if (TREE_CODE (ref) == FUNCTION_DECL && !in_alignof)
1990     {
1991       if (!in_sizeof && !in_typeof)
1992         C_DECL_USED (ref) = 1;
1993       else if (DECL_INITIAL (ref) == 0
1994                && DECL_EXTERNAL (ref)
1995                && !TREE_PUBLIC (ref))
1996         record_maybe_used_decl (ref);
1997     }
1998
1999   if (TREE_CODE (ref) == CONST_DECL)
2000     {
2001       ref = DECL_INITIAL (ref);
2002       TREE_CONSTANT (ref) = 1;
2003       TREE_INVARIANT (ref) = 1;
2004     }
2005   else if (current_function_decl != 0
2006            && !DECL_FILE_SCOPE_P (current_function_decl)
2007            && (TREE_CODE (ref) == VAR_DECL
2008                || TREE_CODE (ref) == PARM_DECL
2009                || TREE_CODE (ref) == FUNCTION_DECL))
2010     {
2011       tree context = decl_function_context (ref);
2012
2013       if (context != 0 && context != current_function_decl)
2014         DECL_NONLOCAL (ref) = 1;
2015     }
2016
2017   return ref;
2018 }
2019
2020 /* Record details of decls possibly used inside sizeof or typeof.  */
2021 struct maybe_used_decl
2022 {
2023   /* The decl.  */
2024   tree decl;
2025   /* The level seen at (in_sizeof + in_typeof).  */
2026   int level;
2027   /* The next one at this level or above, or NULL.  */
2028   struct maybe_used_decl *next;
2029 };
2030
2031 static struct maybe_used_decl *maybe_used_decls;
2032
2033 /* Record that DECL, an undefined static function reference seen
2034    inside sizeof or typeof, might be used if the operand of sizeof is
2035    a VLA type or the operand of typeof is a variably modified
2036    type.  */
2037
2038 static void
2039 record_maybe_used_decl (tree decl)
2040 {
2041   struct maybe_used_decl *t = XOBNEW (&parser_obstack, struct maybe_used_decl);
2042   t->decl = decl;
2043   t->level = in_sizeof + in_typeof;
2044   t->next = maybe_used_decls;
2045   maybe_used_decls = t;
2046 }
2047
2048 /* Pop the stack of decls possibly used inside sizeof or typeof.  If
2049    USED is false, just discard them.  If it is true, mark them used
2050    (if no longer inside sizeof or typeof) or move them to the next
2051    level up (if still inside sizeof or typeof).  */
2052
2053 void
2054 pop_maybe_used (bool used)
2055 {
2056   struct maybe_used_decl *p = maybe_used_decls;
2057   int cur_level = in_sizeof + in_typeof;
2058   while (p && p->level > cur_level)
2059     {
2060       if (used)
2061         {
2062           if (cur_level == 0)
2063             C_DECL_USED (p->decl) = 1;
2064           else
2065             p->level = cur_level;
2066         }
2067       p = p->next;
2068     }
2069   if (!used || cur_level == 0)
2070     maybe_used_decls = p;
2071 }
2072
2073 /* Return the result of sizeof applied to EXPR.  */
2074
2075 struct c_expr
2076 c_expr_sizeof_expr (struct c_expr expr)
2077 {
2078   struct c_expr ret;
2079   if (expr.value == error_mark_node)
2080     {
2081       ret.value = error_mark_node;
2082       ret.original_code = ERROR_MARK;
2083       pop_maybe_used (false);
2084     }
2085   else
2086     {
2087       ret.value = c_sizeof (TREE_TYPE (expr.value));
2088       ret.original_code = ERROR_MARK;
2089       pop_maybe_used (C_TYPE_VARIABLE_SIZE (TREE_TYPE (expr.value)));
2090     }
2091   return ret;
2092 }
2093
2094 /* Return the result of sizeof applied to T, a structure for the type
2095    name passed to sizeof (rather than the type itself).  */
2096
2097 struct c_expr
2098 c_expr_sizeof_type (struct c_type_name *t)
2099 {
2100   tree type;
2101   struct c_expr ret;
2102   type = groktypename (t);
2103   ret.value = c_sizeof (type);
2104   ret.original_code = ERROR_MARK;
2105   pop_maybe_used (C_TYPE_VARIABLE_SIZE (type));
2106   return ret;
2107 }
2108
2109 /* Build a function call to function FUNCTION with parameters PARAMS.
2110    PARAMS is a list--a chain of TREE_LIST nodes--in which the
2111    TREE_VALUE of each node is a parameter-expression.
2112    FUNCTION's data type may be a function type or a pointer-to-function.  */
2113
2114 tree
2115 build_function_call (tree function, tree params)
2116 {
2117   tree fntype, fundecl = 0;
2118   tree coerced_params;
2119   tree name = NULL_TREE, result;
2120   tree tem;
2121
2122   /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
2123   STRIP_TYPE_NOPS (function);
2124
2125   /* Convert anything with function type to a pointer-to-function.  */
2126   if (TREE_CODE (function) == FUNCTION_DECL)
2127     {
2128       /* Implement type-directed function overloading for builtins.
2129          resolve_overloaded_builtin and targetm.resolve_overloaded_builtin
2130          handle all the type checking.  The result is a complete expression
2131          that implements this function call.  */
2132       tem = resolve_overloaded_builtin (function, params);
2133       if (tem)
2134         return tem;
2135
2136       name = DECL_NAME (function);
2137       fundecl = function;
2138     }
2139   if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE)
2140     function = function_to_pointer_conversion (function);
2141
2142   /* For Objective-C, convert any calls via a cast to OBJC_TYPE_REF
2143      expressions, like those used for ObjC messenger dispatches.  */
2144   function = objc_rewrite_function_call (function, params);
2145
2146   fntype = TREE_TYPE (function);
2147
2148   if (TREE_CODE (fntype) == ERROR_MARK)
2149     return error_mark_node;
2150
2151   if (!(TREE_CODE (fntype) == POINTER_TYPE
2152         && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE))
2153     {
2154       error ("called object %qE is not a function", function);
2155       return error_mark_node;
2156     }
2157
2158   if (fundecl && TREE_THIS_VOLATILE (fundecl))
2159     current_function_returns_abnormally = 1;
2160
2161   /* fntype now gets the type of function pointed to.  */
2162   fntype = TREE_TYPE (fntype);
2163
2164   /* Check that the function is called through a compatible prototype.
2165      If it is not, replace the call by a trap, wrapped up in a compound
2166      expression if necessary.  This has the nice side-effect to prevent
2167      the tree-inliner from generating invalid assignment trees which may
2168      blow up in the RTL expander later.  */
2169   if (TREE_CODE (function) == NOP_EXPR
2170       && TREE_CODE (tem = TREE_OPERAND (function, 0)) == ADDR_EXPR
2171       && TREE_CODE (tem = TREE_OPERAND (tem, 0)) == FUNCTION_DECL
2172       && !comptypes (fntype, TREE_TYPE (tem)))
2173     {
2174       tree return_type = TREE_TYPE (fntype);
2175       tree trap = build_function_call (built_in_decls[BUILT_IN_TRAP],
2176                                        NULL_TREE);
2177
2178       /* This situation leads to run-time undefined behavior.  We can't,
2179          therefore, simply error unless we can prove that all possible
2180          executions of the program must execute the code.  */
2181       warning (0, "function called through a non-compatible type");
2182
2183       /* We can, however, treat "undefined" any way we please.
2184          Call abort to encourage the user to fix the program.  */
2185       inform ("if this code is reached, the program will abort");
2186
2187       if (VOID_TYPE_P (return_type))
2188         return trap;
2189       else
2190         {
2191           tree rhs;
2192
2193           if (AGGREGATE_TYPE_P (return_type))
2194             rhs = build_compound_literal (return_type,
2195                                           build_constructor (return_type, 0));
2196           else
2197             rhs = fold_build1 (NOP_EXPR, return_type, integer_zero_node);
2198
2199           return build2 (COMPOUND_EXPR, return_type, trap, rhs);
2200         }
2201     }
2202
2203   /* Convert the parameters to the types declared in the
2204      function prototype, or apply default promotions.  */
2205
2206   coerced_params
2207     = convert_arguments (TYPE_ARG_TYPES (fntype), params, function, fundecl);
2208
2209   if (coerced_params == error_mark_node)
2210     return error_mark_node;
2211
2212   /* Check that the arguments to the function are valid.  */
2213
2214   check_function_arguments (TYPE_ATTRIBUTES (fntype), coerced_params,
2215                             TYPE_ARG_TYPES (fntype));
2216
2217   if (require_constant_value)
2218     {
2219       result = fold_build3_initializer (CALL_EXPR, TREE_TYPE (fntype),
2220                                         function, coerced_params, NULL_TREE);
2221
2222       if (TREE_CONSTANT (result)
2223           && (name == NULL_TREE
2224               || strncmp (IDENTIFIER_POINTER (name), "__builtin_", 10) != 0))
2225         pedwarn_init ("initializer element is not constant");
2226     }
2227   else
2228     result = fold_build3 (CALL_EXPR, TREE_TYPE (fntype),
2229                           function, coerced_params, NULL_TREE);
2230
2231   if (VOID_TYPE_P (TREE_TYPE (result)))
2232     return result;
2233   return require_complete_type (result);
2234 }
2235 \f
2236 /* Convert the argument expressions in the list VALUES
2237    to the types in the list TYPELIST.  The result is a list of converted
2238    argument expressions, unless there are too few arguments in which
2239    case it is error_mark_node.
2240
2241    If TYPELIST is exhausted, or when an element has NULL as its type,
2242    perform the default conversions.
2243
2244    PARMLIST is the chain of parm decls for the function being called.
2245    It may be 0, if that info is not available.
2246    It is used only for generating error messages.
2247
2248    FUNCTION is a tree for the called function.  It is used only for
2249    error messages, where it is formatted with %qE.
2250
2251    This is also where warnings about wrong number of args are generated.
2252
2253    Both VALUES and the returned value are chains of TREE_LIST nodes
2254    with the elements of the list in the TREE_VALUE slots of those nodes.  */
2255
2256 static tree
2257 convert_arguments (tree typelist, tree values, tree function, tree fundecl)
2258 {
2259   tree typetail, valtail;
2260   tree result = NULL;
2261   int parmnum;
2262   tree selector;
2263
2264   /* Change pointer to function to the function itself for
2265      diagnostics.  */
2266   if (TREE_CODE (function) == ADDR_EXPR
2267       && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL)
2268     function = TREE_OPERAND (function, 0);
2269
2270   /* Handle an ObjC selector specially for diagnostics.  */
2271   selector = objc_message_selector ();
2272
2273   /* Scan the given expressions and types, producing individual
2274      converted arguments and pushing them on RESULT in reverse order.  */
2275
2276   for (valtail = values, typetail = typelist, parmnum = 0;
2277        valtail;
2278        valtail = TREE_CHAIN (valtail), parmnum++)
2279     {
2280       tree type = typetail ? TREE_VALUE (typetail) : 0;
2281       tree val = TREE_VALUE (valtail);
2282       tree rname = function;
2283       int argnum = parmnum + 1;
2284       const char *invalid_func_diag;
2285
2286       if (type == void_type_node)
2287         {
2288           error ("too many arguments to function %qE", function);
2289           break;
2290         }
2291
2292       if (selector && argnum > 2)
2293         {
2294           rname = selector;
2295           argnum -= 2;
2296         }
2297
2298       STRIP_TYPE_NOPS (val);
2299
2300       val = require_complete_type (val);
2301
2302       if (type != 0)
2303         {
2304           /* Formal parm type is specified by a function prototype.  */
2305           tree parmval;
2306
2307           if (type == error_mark_node || !COMPLETE_TYPE_P (type))
2308             {
2309               error ("type of formal parameter %d is incomplete", parmnum + 1);
2310               parmval = val;
2311             }
2312           else
2313             {
2314               /* Optionally warn about conversions that
2315                  differ from the default conversions.  */
2316               if (warn_conversion || warn_traditional)
2317                 {
2318                   unsigned int formal_prec = TYPE_PRECISION (type);
2319
2320                   if (INTEGRAL_TYPE_P (type)
2321                       && TREE_CODE (TREE_TYPE (val)) == REAL_TYPE)
2322                     warning (0, "passing argument %d of %qE as integer "
2323                              "rather than floating due to prototype",
2324                              argnum, rname);
2325                   if (INTEGRAL_TYPE_P (type)
2326                       && TREE_CODE (TREE_TYPE (val)) == COMPLEX_TYPE)
2327                     warning (0, "passing argument %d of %qE as integer "
2328                              "rather than complex due to prototype",
2329                              argnum, rname);
2330                   else if (TREE_CODE (type) == COMPLEX_TYPE
2331                            && TREE_CODE (TREE_TYPE (val)) == REAL_TYPE)
2332                     warning (0, "passing argument %d of %qE as complex "
2333                              "rather than floating due to prototype",
2334                              argnum, rname);
2335                   else if (TREE_CODE (type) == REAL_TYPE
2336                            && INTEGRAL_TYPE_P (TREE_TYPE (val)))
2337                     warning (0, "passing argument %d of %qE as floating "
2338                              "rather than integer due to prototype",
2339                              argnum, rname);
2340                   else if (TREE_CODE (type) == COMPLEX_TYPE
2341                            && INTEGRAL_TYPE_P (TREE_TYPE (val)))
2342                     warning (0, "passing argument %d of %qE as complex "
2343                              "rather than integer due to prototype",
2344                              argnum, rname);
2345                   else if (TREE_CODE (type) == REAL_TYPE
2346                            && TREE_CODE (TREE_TYPE (val)) == COMPLEX_TYPE)
2347                     warning (0, "passing argument %d of %qE as floating "
2348                              "rather than complex due to prototype",
2349                              argnum, rname);
2350                   /* ??? At some point, messages should be written about
2351                      conversions between complex types, but that's too messy
2352                      to do now.  */
2353                   else if (TREE_CODE (type) == REAL_TYPE
2354                            && TREE_CODE (TREE_TYPE (val)) == REAL_TYPE)
2355                     {
2356                       /* Warn if any argument is passed as `float',
2357                          since without a prototype it would be `double'.  */
2358                       if (formal_prec == TYPE_PRECISION (float_type_node))
2359                         warning (0, "passing argument %d of %qE as %<float%> "
2360                                  "rather than %<double%> due to prototype",
2361                                  argnum, rname);
2362                     }
2363                   /* Detect integer changing in width or signedness.
2364                      These warnings are only activated with
2365                      -Wconversion, not with -Wtraditional.  */
2366                   else if (warn_conversion && INTEGRAL_TYPE_P (type)
2367                            && INTEGRAL_TYPE_P (TREE_TYPE (val)))
2368                     {
2369                       tree would_have_been = default_conversion (val);
2370                       tree type1 = TREE_TYPE (would_have_been);
2371
2372                       if (TREE_CODE (type) == ENUMERAL_TYPE
2373                           && (TYPE_MAIN_VARIANT (type)
2374                               == TYPE_MAIN_VARIANT (TREE_TYPE (val))))
2375                         /* No warning if function asks for enum
2376                            and the actual arg is that enum type.  */
2377                         ;
2378                       else if (formal_prec != TYPE_PRECISION (type1))
2379                         warning (OPT_Wconversion, "passing argument %d of %qE "
2380                                  "with different width due to prototype",
2381                                  argnum, rname);
2382                       else if (TYPE_UNSIGNED (type) == TYPE_UNSIGNED (type1))
2383                         ;
2384                       /* Don't complain if the formal parameter type
2385                          is an enum, because we can't tell now whether
2386                          the value was an enum--even the same enum.  */
2387                       else if (TREE_CODE (type) == ENUMERAL_TYPE)
2388                         ;
2389                       else if (TREE_CODE (val) == INTEGER_CST
2390                                && int_fits_type_p (val, type))
2391                         /* Change in signedness doesn't matter
2392                            if a constant value is unaffected.  */
2393                         ;
2394                       /* If the value is extended from a narrower
2395                          unsigned type, it doesn't matter whether we
2396                          pass it as signed or unsigned; the value
2397                          certainly is the same either way.  */
2398                       else if (TYPE_PRECISION (TREE_TYPE (val)) < TYPE_PRECISION (type)
2399                                && TYPE_UNSIGNED (TREE_TYPE (val)))
2400                         ;
2401                       else if (TYPE_UNSIGNED (type))
2402                         warning (OPT_Wconversion, "passing argument %d of %qE "
2403                                  "as unsigned due to prototype",
2404                                  argnum, rname);
2405                       else
2406                         warning (OPT_Wconversion, "passing argument %d of %qE "
2407                                  "as signed due to prototype", argnum, rname);
2408                     }
2409                 }
2410
2411               parmval = convert_for_assignment (type, val, ic_argpass,
2412                                                 fundecl, function,
2413                                                 parmnum + 1);
2414
2415               if (targetm.calls.promote_prototypes (fundecl ? TREE_TYPE (fundecl) : 0)
2416                   && INTEGRAL_TYPE_P (type)
2417                   && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
2418                 parmval = default_conversion (parmval);
2419             }
2420           result = tree_cons (NULL_TREE, parmval, result);
2421         }
2422       else if (TREE_CODE (TREE_TYPE (val)) == REAL_TYPE
2423                && (TYPE_PRECISION (TREE_TYPE (val))
2424                    < TYPE_PRECISION (double_type_node)))
2425         /* Convert `float' to `double'.  */
2426         result = tree_cons (NULL_TREE, convert (double_type_node, val), result);
2427       else if ((invalid_func_diag = 
2428                 targetm.calls.invalid_arg_for_unprototyped_fn (typelist, fundecl, val)))
2429         {
2430           error (invalid_func_diag);
2431           return error_mark_node; 
2432         }
2433       else
2434         /* Convert `short' and `char' to full-size `int'.  */
2435         result = tree_cons (NULL_TREE, default_conversion (val), result);
2436
2437       if (typetail)
2438         typetail = TREE_CHAIN (typetail);
2439     }
2440
2441   if (typetail != 0 && TREE_VALUE (typetail) != void_type_node)
2442     {
2443       error ("too few arguments to function %qE", function);
2444       return error_mark_node;
2445     }
2446
2447   return nreverse (result);
2448 }
2449 \f
2450 /* This is the entry point used by the parser to build unary operators
2451    in the input.  CODE, a tree_code, specifies the unary operator, and
2452    ARG is the operand.  For unary plus, the C parser currently uses
2453    CONVERT_EXPR for code.  */
2454
2455 struct c_expr
2456 parser_build_unary_op (enum tree_code code, struct c_expr arg)
2457 {
2458   struct c_expr result;
2459
2460   result.original_code = ERROR_MARK;
2461   result.value = build_unary_op (code, arg.value, 0);
2462   overflow_warning (result.value);
2463   return result;
2464 }
2465
2466 /* This is the entry point used by the parser to build binary operators
2467    in the input.  CODE, a tree_code, specifies the binary operator, and
2468    ARG1 and ARG2 are the operands.  In addition to constructing the
2469    expression, we check for operands that were written with other binary
2470    operators in a way that is likely to confuse the user.  */
2471
2472 struct c_expr
2473 parser_build_binary_op (enum tree_code code, struct c_expr arg1,
2474                         struct c_expr arg2)
2475 {
2476   struct c_expr result;
2477
2478   enum tree_code code1 = arg1.original_code;
2479   enum tree_code code2 = arg2.original_code;
2480
2481   result.value = build_binary_op (code, arg1.value, arg2.value, 1);
2482   result.original_code = code;
2483
2484   if (TREE_CODE (result.value) == ERROR_MARK)
2485     return result;
2486
2487   /* Check for cases such as x+y<<z which users are likely
2488      to misinterpret.  */
2489   if (warn_parentheses)
2490     {
2491       if (code == LSHIFT_EXPR || code == RSHIFT_EXPR)
2492         {
2493           if (code1 == PLUS_EXPR || code1 == MINUS_EXPR
2494               || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
2495             warning (OPT_Wparentheses,
2496                      "suggest parentheses around + or - inside shift");
2497         }
2498
2499       if (code == TRUTH_ORIF_EXPR)
2500         {
2501           if (code1 == TRUTH_ANDIF_EXPR
2502               || code2 == TRUTH_ANDIF_EXPR)
2503             warning (OPT_Wparentheses,
2504                      "suggest parentheses around && within ||");
2505         }
2506
2507       if (code == BIT_IOR_EXPR)
2508         {
2509           if (code1 == BIT_AND_EXPR || code1 == BIT_XOR_EXPR
2510               || code1 == PLUS_EXPR || code1 == MINUS_EXPR
2511               || code2 == BIT_AND_EXPR || code2 == BIT_XOR_EXPR
2512               || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
2513             warning (OPT_Wparentheses,
2514                      "suggest parentheses around arithmetic in operand of |");
2515           /* Check cases like x|y==z */
2516           if (TREE_CODE_CLASS (code1) == tcc_comparison
2517               || TREE_CODE_CLASS (code2) == tcc_comparison)
2518             warning (OPT_Wparentheses,
2519                      "suggest parentheses around comparison in operand of |");
2520         }
2521
2522       if (code == BIT_XOR_EXPR)
2523         {
2524           if (code1 == BIT_AND_EXPR
2525               || code1 == PLUS_EXPR || code1 == MINUS_EXPR
2526               || code2 == BIT_AND_EXPR
2527               || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
2528             warning (OPT_Wparentheses,
2529                      "suggest parentheses around arithmetic in operand of ^");
2530           /* Check cases like x^y==z */
2531           if (TREE_CODE_CLASS (code1) == tcc_comparison
2532               || TREE_CODE_CLASS (code2) == tcc_comparison)
2533             warning (OPT_Wparentheses,
2534                      "suggest parentheses around comparison in operand of ^");
2535         }
2536
2537       if (code == BIT_AND_EXPR)
2538         {
2539           if (code1 == PLUS_EXPR || code1 == MINUS_EXPR
2540               || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
2541             warning (OPT_Wparentheses,
2542                      "suggest parentheses around + or - in operand of &");
2543           /* Check cases like x&y==z */
2544           if (TREE_CODE_CLASS (code1) == tcc_comparison
2545               || TREE_CODE_CLASS (code2) == tcc_comparison)
2546             warning (OPT_Wparentheses,
2547                      "suggest parentheses around comparison in operand of &");
2548         }
2549       /* Similarly, check for cases like 1<=i<=10 that are probably errors.  */
2550       if (TREE_CODE_CLASS (code) == tcc_comparison
2551           && (TREE_CODE_CLASS (code1) == tcc_comparison
2552               || TREE_CODE_CLASS (code2) == tcc_comparison))
2553         warning (OPT_Wparentheses, "comparisons like X<=Y<=Z do not "
2554                  "have their mathematical meaning");
2555
2556     }
2557
2558   unsigned_conversion_warning (result.value, arg1.value);
2559   unsigned_conversion_warning (result.value, arg2.value);
2560   overflow_warning (result.value);
2561
2562   return result;
2563 }
2564 \f
2565 /* Return a tree for the difference of pointers OP0 and OP1.
2566    The resulting tree has type int.  */
2567
2568 static tree
2569 pointer_diff (tree op0, tree op1)
2570 {
2571   tree restype = ptrdiff_type_node;
2572
2573   tree target_type = TREE_TYPE (TREE_TYPE (op0));
2574   tree con0, con1, lit0, lit1;
2575   tree orig_op1 = op1;
2576
2577   if (pedantic || warn_pointer_arith)
2578     {
2579       if (TREE_CODE (target_type) == VOID_TYPE)
2580         pedwarn ("pointer of type %<void *%> used in subtraction");
2581       if (TREE_CODE (target_type) == FUNCTION_TYPE)
2582         pedwarn ("pointer to a function used in subtraction");
2583     }
2584
2585   /* If the conversion to ptrdiff_type does anything like widening or
2586      converting a partial to an integral mode, we get a convert_expression
2587      that is in the way to do any simplifications.
2588      (fold-const.c doesn't know that the extra bits won't be needed.
2589      split_tree uses STRIP_SIGN_NOPS, which leaves conversions to a
2590      different mode in place.)
2591      So first try to find a common term here 'by hand'; we want to cover
2592      at least the cases that occur in legal static initializers.  */
2593   con0 = TREE_CODE (op0) == NOP_EXPR ? TREE_OPERAND (op0, 0) : op0;
2594   con1 = TREE_CODE (op1) == NOP_EXPR ? TREE_OPERAND (op1, 0) : op1;
2595
2596   if (TREE_CODE (con0) == PLUS_EXPR)
2597     {
2598       lit0 = TREE_OPERAND (con0, 1);
2599       con0 = TREE_OPERAND (con0, 0);
2600     }
2601   else
2602     lit0 = integer_zero_node;
2603
2604   if (TREE_CODE (con1) == PLUS_EXPR)
2605     {
2606       lit1 = TREE_OPERAND (con1, 1);
2607       con1 = TREE_OPERAND (con1, 0);
2608     }
2609   else
2610     lit1 = integer_zero_node;
2611
2612   if (operand_equal_p (con0, con1, 0))
2613     {
2614       op0 = lit0;
2615       op1 = lit1;
2616     }
2617
2618
2619   /* First do the subtraction as integers;
2620      then drop through to build the divide operator.
2621      Do not do default conversions on the minus operator
2622      in case restype is a short type.  */
2623
2624   op0 = build_binary_op (MINUS_EXPR, convert (restype, op0),
2625                          convert (restype, op1), 0);
2626   /* This generates an error if op1 is pointer to incomplete type.  */
2627   if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (orig_op1))))
2628     error ("arithmetic on pointer to an incomplete type");
2629
2630   /* This generates an error if op0 is pointer to incomplete type.  */
2631   op1 = c_size_in_bytes (target_type);
2632
2633   /* Divide by the size, in easiest possible way.  */
2634   return fold_build2 (EXACT_DIV_EXPR, restype, op0, convert (restype, op1));
2635 }
2636 \f
2637 /* Construct and perhaps optimize a tree representation
2638    for a unary operation.  CODE, a tree_code, specifies the operation
2639    and XARG is the operand.
2640    For any CODE other than ADDR_EXPR, FLAG nonzero suppresses
2641    the default promotions (such as from short to int).
2642    For ADDR_EXPR, the default promotions are not applied; FLAG nonzero
2643    allows non-lvalues; this is only used to handle conversion of non-lvalue
2644    arrays to pointers in C99.  */
2645
2646 tree
2647 build_unary_op (enum tree_code code, tree xarg, int flag)
2648 {
2649   /* No default_conversion here.  It causes trouble for ADDR_EXPR.  */
2650   tree arg = xarg;
2651   tree argtype = 0;
2652   enum tree_code typecode = TREE_CODE (TREE_TYPE (arg));
2653   tree val;
2654   int noconvert = flag;
2655   const char *invalid_op_diag;
2656
2657   if (typecode == ERROR_MARK)
2658     return error_mark_node;
2659   if (typecode == ENUMERAL_TYPE || typecode == BOOLEAN_TYPE)
2660     typecode = INTEGER_TYPE;
2661
2662   if ((invalid_op_diag
2663        = targetm.invalid_unary_op (code, TREE_TYPE (xarg))))
2664     {
2665       error (invalid_op_diag);
2666       return error_mark_node;
2667     }
2668
2669   switch (code)
2670     {
2671     case CONVERT_EXPR:
2672       /* This is used for unary plus, because a CONVERT_EXPR
2673          is enough to prevent anybody from looking inside for
2674          associativity, but won't generate any code.  */
2675       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
2676             || typecode == COMPLEX_TYPE
2677             || typecode == VECTOR_TYPE))
2678         {
2679           error ("wrong type argument to unary plus");
2680           return error_mark_node;
2681         }
2682       else if (!noconvert)
2683         arg = default_conversion (arg);
2684       arg = non_lvalue (arg);
2685       break;
2686
2687     case NEGATE_EXPR:
2688       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
2689             || typecode == COMPLEX_TYPE
2690             || typecode == VECTOR_TYPE))
2691         {
2692           error ("wrong type argument to unary minus");
2693           return error_mark_node;
2694         }
2695       else if (!noconvert)
2696         arg = default_conversion (arg);
2697       break;
2698
2699     case BIT_NOT_EXPR:
2700       if (typecode == INTEGER_TYPE || typecode == VECTOR_TYPE)
2701         {
2702           if (!noconvert)
2703             arg = default_conversion (arg);
2704         }
2705       else if (typecode == COMPLEX_TYPE)
2706         {
2707           code = CONJ_EXPR;
2708           if (pedantic)
2709             pedwarn ("ISO C does not support %<~%> for complex conjugation");
2710           if (!noconvert)
2711             arg = default_conversion (arg);
2712         }
2713       else
2714         {
2715           error ("wrong type argument to bit-complement");
2716           return error_mark_node;
2717         }
2718       break;
2719
2720     case ABS_EXPR:
2721       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE))
2722         {
2723           error ("wrong type argument to abs");
2724           return error_mark_node;
2725         }
2726       else if (!noconvert)
2727         arg = default_conversion (arg);
2728       break;
2729
2730     case CONJ_EXPR:
2731       /* Conjugating a real value is a no-op, but allow it anyway.  */
2732       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
2733             || typecode == COMPLEX_TYPE))
2734         {
2735           error ("wrong type argument to conjugation");
2736           return error_mark_node;
2737         }
2738       else if (!noconvert)
2739         arg = default_conversion (arg);
2740       break;
2741
2742     case TRUTH_NOT_EXPR:
2743       if (typecode != INTEGER_TYPE
2744           && typecode != REAL_TYPE && typecode != POINTER_TYPE
2745           && typecode != COMPLEX_TYPE)
2746         {
2747           error ("wrong type argument to unary exclamation mark");
2748           return error_mark_node;
2749         }
2750       arg = c_objc_common_truthvalue_conversion (arg);
2751       return invert_truthvalue (arg);
2752
2753     case NOP_EXPR:
2754       break;
2755
2756     case REALPART_EXPR:
2757       if (TREE_CODE (arg) == COMPLEX_CST)
2758         return TREE_REALPART (arg);
2759       else if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
2760         return fold_build1 (REALPART_EXPR, TREE_TYPE (TREE_TYPE (arg)), arg);
2761       else
2762         return arg;
2763
2764     case IMAGPART_EXPR:
2765       if (TREE_CODE (arg) == COMPLEX_CST)
2766         return TREE_IMAGPART (arg);
2767       else if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
2768         return fold_build1 (IMAGPART_EXPR, TREE_TYPE (TREE_TYPE (arg)), arg);
2769       else
2770         return convert (TREE_TYPE (arg), integer_zero_node);
2771
2772     case PREINCREMENT_EXPR:
2773     case POSTINCREMENT_EXPR:
2774     case PREDECREMENT_EXPR:
2775     case POSTDECREMENT_EXPR:
2776
2777       /* Increment or decrement the real part of the value,
2778          and don't change the imaginary part.  */
2779       if (typecode == COMPLEX_TYPE)
2780         {
2781           tree real, imag;
2782
2783           if (pedantic)
2784             pedwarn ("ISO C does not support %<++%> and %<--%>"
2785                      " on complex types");
2786
2787           arg = stabilize_reference (arg);
2788           real = build_unary_op (REALPART_EXPR, arg, 1);
2789           imag = build_unary_op (IMAGPART_EXPR, arg, 1);
2790           return build2 (COMPLEX_EXPR, TREE_TYPE (arg),
2791                          build_unary_op (code, real, 1), imag);
2792         }
2793
2794       /* Report invalid types.  */
2795
2796       if (typecode != POINTER_TYPE
2797           && typecode != INTEGER_TYPE && typecode != REAL_TYPE)
2798         {
2799           if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
2800             error ("wrong type argument to increment");
2801           else
2802             error ("wrong type argument to decrement");
2803
2804           return error_mark_node;
2805         }
2806
2807       {
2808         tree inc;
2809         tree result_type = TREE_TYPE (arg);
2810
2811         arg = get_unwidened (arg, 0);
2812         argtype = TREE_TYPE (arg);
2813
2814         /* Compute the increment.  */
2815
2816         if (typecode == POINTER_TYPE)
2817           {
2818             /* If pointer target is an undefined struct,
2819                we just cannot know how to do the arithmetic.  */
2820             if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (result_type)))
2821               {
2822                 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
2823                   error ("increment of pointer to unknown structure");
2824                 else
2825                   error ("decrement of pointer to unknown structure");
2826               }
2827             else if ((pedantic || warn_pointer_arith)
2828                      && (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE
2829                          || TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE))
2830               {
2831                 if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
2832                   pedwarn ("wrong type argument to increment");
2833                 else
2834                   pedwarn ("wrong type argument to decrement");
2835               }
2836
2837             inc = c_size_in_bytes (TREE_TYPE (result_type));
2838           }
2839         else
2840           inc = integer_one_node;
2841
2842         inc = convert (argtype, inc);
2843
2844         /* Complain about anything else that is not a true lvalue.  */
2845         if (!lvalue_or_else (arg, ((code == PREINCREMENT_EXPR
2846                                     || code == POSTINCREMENT_EXPR)
2847                                    ? lv_increment
2848                                    : lv_decrement)))
2849           return error_mark_node;
2850
2851         /* Report a read-only lvalue.  */
2852         if (TREE_READONLY (arg))
2853           readonly_error (arg,
2854                           ((code == PREINCREMENT_EXPR
2855                             || code == POSTINCREMENT_EXPR)
2856                            ? lv_increment : lv_decrement));
2857
2858         if (TREE_CODE (TREE_TYPE (arg)) == BOOLEAN_TYPE)
2859           val = boolean_increment (code, arg);
2860         else
2861           val = build2 (code, TREE_TYPE (arg), arg, inc);
2862         TREE_SIDE_EFFECTS (val) = 1;
2863         val = convert (result_type, val);
2864         if (TREE_CODE (val) != code)
2865           TREE_NO_WARNING (val) = 1;
2866         return val;
2867       }
2868
2869     case ADDR_EXPR:
2870       /* Note that this operation never does default_conversion.  */
2871
2872       /* Let &* cancel out to simplify resulting code.  */
2873       if (TREE_CODE (arg) == INDIRECT_REF)
2874         {
2875           /* Don't let this be an lvalue.  */
2876           if (lvalue_p (TREE_OPERAND (arg, 0)))
2877             return non_lvalue (TREE_OPERAND (arg, 0));
2878           return TREE_OPERAND (arg, 0);
2879         }
2880
2881       /* For &x[y], return x+y */
2882       if (TREE_CODE (arg) == ARRAY_REF)
2883         {
2884           tree op0 = TREE_OPERAND (arg, 0);
2885           if (!c_mark_addressable (op0))
2886             return error_mark_node;
2887           return build_binary_op (PLUS_EXPR,
2888                                   (TREE_CODE (TREE_TYPE (op0)) == ARRAY_TYPE
2889                                    ? array_to_pointer_conversion (op0)
2890                                    : op0),
2891                                   TREE_OPERAND (arg, 1), 1);
2892         }
2893
2894       /* Anything not already handled and not a true memory reference
2895          or a non-lvalue array is an error.  */
2896       else if (typecode != FUNCTION_TYPE && !flag
2897                && !lvalue_or_else (arg, lv_addressof))
2898         return error_mark_node;
2899
2900       /* Ordinary case; arg is a COMPONENT_REF or a decl.  */
2901       argtype = TREE_TYPE (arg);
2902
2903       /* If the lvalue is const or volatile, merge that into the type
2904          to which the address will point.  Note that you can't get a
2905          restricted pointer by taking the address of something, so we
2906          only have to deal with `const' and `volatile' here.  */
2907       if ((DECL_P (arg) || REFERENCE_CLASS_P (arg))
2908           && (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg)))
2909           argtype = c_build_type_variant (argtype,
2910                                           TREE_READONLY (arg),
2911                                           TREE_THIS_VOLATILE (arg));
2912
2913       if (!c_mark_addressable (arg))
2914         return error_mark_node;
2915
2916       gcc_assert (TREE_CODE (arg) != COMPONENT_REF
2917                   || !DECL_C_BIT_FIELD (TREE_OPERAND (arg, 1)));
2918
2919       argtype = build_pointer_type (argtype);
2920
2921       /* ??? Cope with user tricks that amount to offsetof.  Delete this
2922          when we have proper support for integer constant expressions.  */
2923       val = get_base_address (arg);
2924       if (val && TREE_CODE (val) == INDIRECT_REF
2925           && TREE_CONSTANT (TREE_OPERAND (val, 0)))
2926         {
2927           tree op0 = fold_convert (argtype, fold_offsetof (arg)), op1;
2928
2929           op1 = fold_convert (argtype, TREE_OPERAND (val, 0));
2930           return fold_build2 (PLUS_EXPR, argtype, op0, op1);
2931         }
2932
2933       val = build1 (ADDR_EXPR, argtype, arg);
2934
2935       return val;
2936
2937     default:
2938       break;
2939     }
2940
2941   if (argtype == 0)
2942     argtype = TREE_TYPE (arg);
2943   return require_constant_value ? fold_build1_initializer (code, argtype, arg)
2944                                 : fold_build1 (code, argtype, arg);
2945 }
2946
2947 /* Return nonzero if REF is an lvalue valid for this language.
2948    Lvalues can be assigned, unless their type has TYPE_READONLY.
2949    Lvalues can have their address taken, unless they have C_DECL_REGISTER.  */
2950
2951 static int
2952 lvalue_p (tree ref)
2953 {
2954   enum tree_code code = TREE_CODE (ref);
2955
2956   switch (code)
2957     {
2958     case REALPART_EXPR:
2959     case IMAGPART_EXPR:
2960     case COMPONENT_REF:
2961       return lvalue_p (TREE_OPERAND (ref, 0));
2962
2963     case COMPOUND_LITERAL_EXPR:
2964     case STRING_CST:
2965       return 1;
2966
2967     case INDIRECT_REF:
2968     case ARRAY_REF:
2969     case VAR_DECL:
2970     case PARM_DECL:
2971     case RESULT_DECL:
2972     case ERROR_MARK:
2973       return (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE
2974               && TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE);
2975
2976     case BIND_EXPR:
2977       return TREE_CODE (TREE_TYPE (ref)) == ARRAY_TYPE;
2978
2979     default:
2980       return 0;
2981     }
2982 }
2983 \f
2984 /* Give an error for storing in something that is 'const'.  */
2985
2986 static void
2987 readonly_error (tree arg, enum lvalue_use use)
2988 {
2989   gcc_assert (use == lv_assign || use == lv_increment || use == lv_decrement
2990               || use == lv_asm);
2991   /* Using this macro rather than (for example) arrays of messages
2992      ensures that all the format strings are checked at compile
2993      time.  */
2994 #define READONLY_MSG(A, I, D, AS) (use == lv_assign ? (A)               \
2995                                    : (use == lv_increment ? (I)         \
2996                                    : (use == lv_decrement ? (D) : (AS))))
2997   if (TREE_CODE (arg) == COMPONENT_REF)
2998     {
2999       if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg, 0))))
3000         readonly_error (TREE_OPERAND (arg, 0), use);
3001       else
3002         error (READONLY_MSG (G_("assignment of read-only member %qD"),
3003                              G_("increment of read-only member %qD"),
3004                              G_("decrement of read-only member %qD"),
3005                              G_("read-only member %qD used as %<asm%> output")),
3006                TREE_OPERAND (arg, 1));
3007     }
3008   else if (TREE_CODE (arg) == VAR_DECL)
3009     error (READONLY_MSG (G_("assignment of read-only variable %qD"),
3010                          G_("increment of read-only variable %qD"),
3011                          G_("decrement of read-only variable %qD"),
3012                          G_("read-only variable %qD used as %<asm%> output")),
3013            arg);
3014   else
3015     error (READONLY_MSG (G_("assignment of read-only location"),
3016                          G_("increment of read-only location"),
3017                          G_("decrement of read-only location"),
3018                          G_("read-only location used as %<asm%> output")));
3019 }
3020
3021
3022 /* Return nonzero if REF is an lvalue valid for this language;
3023    otherwise, print an error message and return zero.  USE says
3024    how the lvalue is being used and so selects the error message.  */
3025
3026 static int
3027 lvalue_or_else (tree ref, enum lvalue_use use)
3028 {
3029   int win = lvalue_p (ref);
3030
3031   if (!win)
3032     lvalue_error (use);
3033
3034   return win;
3035 }
3036 \f
3037 /* Mark EXP saying that we need to be able to take the
3038    address of it; it should not be allocated in a register.
3039    Returns true if successful.  */
3040
3041 bool
3042 c_mark_addressable (tree exp)
3043 {
3044   tree x = exp;
3045
3046   while (1)
3047     switch (TREE_CODE (x))
3048       {
3049       case COMPONENT_REF:
3050         if (DECL_C_BIT_FIELD (TREE_OPERAND (x, 1)))
3051           {
3052             error
3053               ("cannot take address of bit-field %qD", TREE_OPERAND (x, 1));
3054             return false;
3055           }
3056
3057         /* ... fall through ...  */
3058
3059       case ADDR_EXPR:
3060       case ARRAY_REF:
3061       case REALPART_EXPR:
3062       case IMAGPART_EXPR:
3063         x = TREE_OPERAND (x, 0);
3064         break;
3065
3066       case COMPOUND_LITERAL_EXPR:
3067       case CONSTRUCTOR:
3068         TREE_ADDRESSABLE (x) = 1;
3069         return true;
3070
3071       case VAR_DECL:
3072       case CONST_DECL:
3073       case PARM_DECL:
3074       case RESULT_DECL:
3075         if (C_DECL_REGISTER (x)
3076             && DECL_NONLOCAL (x))
3077           {
3078             if (TREE_PUBLIC (x) || TREE_STATIC (x) || DECL_EXTERNAL (x))
3079               {
3080                 error
3081                   ("global register variable %qD used in nested function", x);
3082                 return false;
3083               }
3084             pedwarn ("register variable %qD used in nested function", x);
3085           }
3086         else if (C_DECL_REGISTER (x))
3087           {
3088             if (TREE_PUBLIC (x) || TREE_STATIC (x) || DECL_EXTERNAL (x))
3089               error ("address of global register variable %qD requested", x);
3090             else
3091               error ("address of register variable %qD requested", x);
3092             return false;
3093           }
3094
3095         /* drops in */
3096       case FUNCTION_DECL:
3097         TREE_ADDRESSABLE (x) = 1;
3098         /* drops out */
3099       default:
3100         return true;
3101     }
3102 }
3103 \f
3104 /* Build and return a conditional expression IFEXP ? OP1 : OP2.  */
3105
3106 tree
3107 build_conditional_expr (tree ifexp, tree op1, tree op2)
3108 {
3109   tree type1;
3110   tree type2;
3111   enum tree_code code1;
3112   enum tree_code code2;
3113   tree result_type = NULL;
3114   tree orig_op1 = op1, orig_op2 = op2;
3115
3116   /* Promote both alternatives.  */
3117
3118   if (TREE_CODE (TREE_TYPE (op1)) != VOID_TYPE)
3119     op1 = default_conversion (op1);
3120   if (TREE_CODE (TREE_TYPE (op2)) != VOID_TYPE)
3121     op2 = default_conversion (op2);
3122
3123   if (TREE_CODE (ifexp) == ERROR_MARK
3124       || TREE_CODE (TREE_TYPE (op1)) == ERROR_MARK
3125       || TREE_CODE (TREE_TYPE (op2)) == ERROR_MARK)
3126     return error_mark_node;
3127
3128   type1 = TREE_TYPE (op1);
3129   code1 = TREE_CODE (type1);
3130   type2 = TREE_TYPE (op2);
3131   code2 = TREE_CODE (type2);
3132
3133   /* C90 does not permit non-lvalue arrays in conditional expressions.
3134      In C99 they will be pointers by now.  */
3135   if (code1 == ARRAY_TYPE || code2 == ARRAY_TYPE)
3136     {
3137       error ("non-lvalue array in conditional expression");
3138       return error_mark_node;
3139     }
3140
3141   /* Quickly detect the usual case where op1 and op2 have the same type
3142      after promotion.  */
3143   if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2))
3144     {
3145       if (type1 == type2)
3146         result_type = type1;
3147       else
3148         result_type = TYPE_MAIN_VARIANT (type1);
3149     }
3150   else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE
3151             || code1 == COMPLEX_TYPE)
3152            && (code2 == INTEGER_TYPE || code2 == REAL_TYPE
3153                || code2 == COMPLEX_TYPE))
3154     {
3155       result_type = c_common_type (type1, type2);
3156
3157       /* If -Wsign-compare, warn here if type1 and type2 have
3158          different signedness.  We'll promote the signed to unsigned
3159          and later code won't know it used to be different.
3160          Do this check on the original types, so that explicit casts
3161          will be considered, but default promotions won't.  */
3162       if (warn_sign_compare && !skip_evaluation)
3163         {
3164           int unsigned_op1 = TYPE_UNSIGNED (TREE_TYPE (orig_op1));
3165           int unsigned_op2 = TYPE_UNSIGNED (TREE_TYPE (orig_op2));
3166
3167           if (unsigned_op1 ^ unsigned_op2)
3168             {
3169               /* Do not warn if the result type is signed, since the
3170                  signed type will only be chosen if it can represent
3171                  all the values of the unsigned type.  */
3172               if (!TYPE_UNSIGNED (result_type))
3173                 /* OK */;
3174               /* Do not warn if the signed quantity is an unsuffixed
3175                  integer literal (or some static constant expression
3176                  involving such literals) and it is non-negative.  */
3177               else if ((unsigned_op2 && tree_expr_nonnegative_p (op1))
3178                        || (unsigned_op1 && tree_expr_nonnegative_p (op2)))
3179                 /* OK */;
3180               else
3181                 warning (0, "signed and unsigned type in conditional expression");
3182             }
3183         }
3184     }
3185   else if (code1 == VOID_TYPE || code2 == VOID_TYPE)
3186     {
3187       if (pedantic && (code1 != VOID_TYPE || code2 != VOID_TYPE))
3188         pedwarn ("ISO C forbids conditional expr with only one void side");
3189       result_type = void_type_node;
3190     }
3191   else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE)
3192     {
3193       if (comp_target_types (type1, type2))
3194         result_type = common_pointer_type (type1, type2);
3195       else if (integer_zerop (op1) && TREE_TYPE (type1) == void_type_node
3196                && TREE_CODE (orig_op1) != NOP_EXPR)
3197         result_type = qualify_type (type2, type1);
3198       else if (integer_zerop (op2) && TREE_TYPE (type2) == void_type_node
3199                && TREE_CODE (orig_op2) != NOP_EXPR)
3200         result_type = qualify_type (type1, type2);
3201       else if (VOID_TYPE_P (TREE_TYPE (type1)))
3202         {
3203           if (pedantic && TREE_CODE (TREE_TYPE (type2)) == FUNCTION_TYPE)
3204             pedwarn ("ISO C forbids conditional expr between "
3205                      "%<void *%> and function pointer");
3206           result_type = build_pointer_type (qualify_type (TREE_TYPE (type1),
3207                                                           TREE_TYPE (type2)));
3208         }
3209       else if (VOID_TYPE_P (TREE_TYPE (type2)))
3210         {
3211           if (pedantic && TREE_CODE (TREE_TYPE (type1)) == FUNCTION_TYPE)
3212             pedwarn ("ISO C forbids conditional expr between "
3213                      "%<void *%> and function pointer");
3214           result_type = build_pointer_type (qualify_type (TREE_TYPE (type2),
3215                                                           TREE_TYPE (type1)));
3216         }
3217       else
3218         {
3219           pedwarn ("pointer type mismatch in conditional expression");
3220           result_type = build_pointer_type (void_type_node);
3221         }
3222     }
3223   else if (code1 == POINTER_TYPE && code2 == INTEGER_TYPE)
3224     {
3225       if (!integer_zerop (op2))
3226         pedwarn ("pointer/integer type mismatch in conditional expression");
3227       else
3228         {
3229           op2 = null_pointer_node;
3230         }
3231       result_type = type1;
3232     }
3233   else if (code2 == POINTER_TYPE && code1 == INTEGER_TYPE)
3234     {
3235       if (!integer_zerop (op1))
3236         pedwarn ("pointer/integer type mismatch in conditional expression");
3237       else
3238         {
3239           op1 = null_pointer_node;
3240         }
3241       result_type = type2;
3242     }
3243
3244   if (!result_type)
3245     {
3246       if (flag_cond_mismatch)
3247         result_type = void_type_node;
3248       else
3249         {
3250           error ("type mismatch in conditional expression");
3251           return error_mark_node;
3252         }
3253     }
3254
3255   /* Merge const and volatile flags of the incoming types.  */
3256   result_type
3257     = build_type_variant (result_type,
3258                           TREE_READONLY (op1) || TREE_READONLY (op2),
3259                           TREE_THIS_VOLATILE (op1) || TREE_THIS_VOLATILE (op2));
3260
3261   if (result_type != TREE_TYPE (op1))
3262     op1 = convert_and_check (result_type, op1);
3263   if (result_type != TREE_TYPE (op2))
3264     op2 = convert_and_check (result_type, op2);
3265
3266   return fold_build3 (COND_EXPR, result_type, ifexp, op1, op2);
3267 }
3268 \f
3269 /* Return a compound expression that performs two expressions and
3270    returns the value of the second of them.  */
3271
3272 tree
3273 build_compound_expr (tree expr1, tree expr2)
3274 {
3275   if (!TREE_SIDE_EFFECTS (expr1))
3276     {
3277       /* The left-hand operand of a comma expression is like an expression
3278          statement: with -Wextra or -Wunused, we should warn if it doesn't have
3279          any side-effects, unless it was explicitly cast to (void).  */
3280       if (warn_unused_value)
3281         {
3282           if (VOID_TYPE_P (TREE_TYPE (expr1))
3283               && TREE_CODE (expr1) == CONVERT_EXPR)
3284             ; /* (void) a, b */
3285           else if (VOID_TYPE_P (TREE_TYPE (expr1))
3286                    && TREE_CODE (expr1) == COMPOUND_EXPR
3287                    && TREE_CODE (TREE_OPERAND (expr1, 1)) == CONVERT_EXPR)
3288             ; /* (void) a, (void) b, c */
3289           else
3290             warning (0, "left-hand operand of comma expression has no effect");
3291         }
3292     }
3293
3294   /* With -Wunused, we should also warn if the left-hand operand does have
3295      side-effects, but computes a value which is not used.  For example, in
3296      `foo() + bar(), baz()' the result of the `+' operator is not used,
3297      so we should issue a warning.  */
3298   else if (warn_unused_value)
3299     warn_if_unused_value (expr1, input_location);
3300
3301   return build2 (COMPOUND_EXPR, TREE_TYPE (expr2), expr1, expr2);
3302 }
3303
3304 /* Build an expression representing a cast to type TYPE of expression EXPR.  */
3305
3306 tree
3307 build_c_cast (tree type, tree expr)
3308 {
3309   tree value = expr;
3310
3311   if (type == error_mark_node || expr == error_mark_node)
3312     return error_mark_node;
3313
3314   /* The ObjC front-end uses TYPE_MAIN_VARIANT to tie together types differing
3315      only in <protocol> qualifications.  But when constructing cast expressions,
3316      the protocols do matter and must be kept around.  */
3317   if (objc_is_object_ptr (type) && objc_is_object_ptr (TREE_TYPE (expr)))
3318     return build1 (NOP_EXPR, type, expr);
3319
3320   type = TYPE_MAIN_VARIANT (type);
3321
3322   if (TREE_CODE (type) == ARRAY_TYPE)
3323     {
3324       error ("cast specifies array type");
3325       return error_mark_node;
3326     }
3327
3328   if (TREE_CODE (type) == FUNCTION_TYPE)
3329     {
3330       error ("cast specifies function type");
3331       return error_mark_node;
3332     }
3333
3334   if (type == TYPE_MAIN_VARIANT (TREE_TYPE (value)))
3335     {
3336       if (pedantic)
3337         {
3338           if (TREE_CODE (type) == RECORD_TYPE
3339               || TREE_CODE (type) == UNION_TYPE)
3340             pedwarn ("ISO C forbids casting nonscalar to the same type");
3341         }
3342     }
3343   else if (TREE_CODE (type) == UNION_TYPE)
3344     {
3345       tree field;
3346
3347       for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
3348         if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field)),
3349                        TYPE_MAIN_VARIANT (TREE_TYPE (value))))
3350           break;
3351
3352       if (field)
3353         {
3354           tree t;
3355
3356           if (pedantic)
3357             pedwarn ("ISO C forbids casts to union type");
3358           t = digest_init (type,
3359                            build_constructor_single (type, field, value),
3360                            true, 0);
3361           TREE_CONSTANT (t) = TREE_CONSTANT (value);
3362           TREE_INVARIANT (t) = TREE_INVARIANT (value);
3363           return t;
3364         }
3365       error ("cast to union type from type not present in union");
3366       return error_mark_node;
3367     }
3368   else
3369     {
3370       tree otype, ovalue;
3371
3372       if (type == void_type_node)
3373         return build1 (CONVERT_EXPR, type, value);
3374
3375       otype = TREE_TYPE (value);
3376
3377       /* Optionally warn about potentially worrisome casts.  */
3378
3379       if (warn_cast_qual
3380           && TREE_CODE (type) == POINTER_TYPE
3381           && TREE_CODE (otype) == POINTER_TYPE)
3382         {
3383           tree in_type = type;
3384           tree in_otype = otype;
3385           int added = 0;
3386           int discarded = 0;
3387
3388           /* Check that the qualifiers on IN_TYPE are a superset of
3389              the qualifiers of IN_OTYPE.  The outermost level of
3390              POINTER_TYPE nodes is uninteresting and we stop as soon
3391              as we hit a non-POINTER_TYPE node on either type.  */
3392           do
3393             {
3394               in_otype = TREE_TYPE (in_otype);
3395               in_type = TREE_TYPE (in_type);
3396
3397               /* GNU C allows cv-qualified function types.  'const'
3398                  means the function is very pure, 'volatile' means it
3399                  can't return.  We need to warn when such qualifiers
3400                  are added, not when they're taken away.  */
3401               if (TREE_CODE (in_otype) == FUNCTION_TYPE
3402                   && TREE_CODE (in_type) == FUNCTION_TYPE)
3403                 added |= (TYPE_QUALS (in_type) & ~TYPE_QUALS (in_otype));
3404               else
3405                 discarded |= (TYPE_QUALS (in_otype) & ~TYPE_QUALS (in_type));
3406             }
3407           while (TREE_CODE (in_type) == POINTER_TYPE
3408                  && TREE_CODE (in_otype) == POINTER_TYPE);
3409
3410           if (added)
3411             warning (0, "cast adds new qualifiers to function type");
3412
3413           if (discarded)
3414             /* There are qualifiers present in IN_OTYPE that are not
3415                present in IN_TYPE.  */
3416             warning (0, "cast discards qualifiers from pointer target type");
3417         }
3418
3419       /* Warn about possible alignment problems.  */
3420       if (STRICT_ALIGNMENT
3421           && TREE_CODE (type) == POINTER_TYPE
3422           && TREE_CODE (otype) == POINTER_TYPE
3423           && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE
3424           && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
3425           /* Don't warn about opaque types, where the actual alignment
3426              restriction is unknown.  */
3427           && !((TREE_CODE (TREE_TYPE (otype)) == UNION_TYPE
3428                 || TREE_CODE (TREE_TYPE (otype)) == RECORD_TYPE)
3429                && TYPE_MODE (TREE_TYPE (otype)) == VOIDmode)
3430           && TYPE_ALIGN (TREE_TYPE (type)) > TYPE_ALIGN (TREE_TYPE (otype)))
3431         warning (OPT_Wcast_align,
3432                  "cast increases required alignment of target type");
3433
3434       if (TREE_CODE (type) == INTEGER_TYPE
3435           && TREE_CODE (otype) == POINTER_TYPE
3436           && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
3437           && !TREE_CONSTANT (value))
3438         warning (OPT_Wpointer_to_int_cast,
3439                  "cast from pointer to integer of different size");
3440
3441       if (TREE_CODE (value) == CALL_EXPR
3442           && TREE_CODE (type) != TREE_CODE (otype))
3443         warning (OPT_Wbad_function_cast, "cast from function call of type %qT "
3444                  "to non-matching type %qT", otype, type);
3445
3446       if (TREE_CODE (type) == POINTER_TYPE
3447           && TREE_CODE (otype) == INTEGER_TYPE
3448           && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
3449           /* Don't warn about converting any constant.  */
3450           && !TREE_CONSTANT (value))
3451         warning (OPT_Wint_to_pointer_cast, "cast to pointer from integer "
3452                  "of different size");
3453
3454       strict_aliasing_warning (otype, type, expr);
3455
3456       /* If pedantic, warn for conversions between function and object
3457          pointer types, except for converting a null pointer constant
3458          to function pointer type.  */
3459       if (pedantic
3460           && TREE_CODE (type) == POINTER_TYPE
3461           && TREE_CODE (otype) == POINTER_TYPE
3462           && TREE_CODE (TREE_TYPE (otype)) == FUNCTION_TYPE
3463           && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE)
3464         pedwarn ("ISO C forbids conversion of function pointer to object pointer type");
3465
3466       if (pedantic
3467           && TREE_CODE (type) == POINTER_TYPE
3468           && TREE_CODE (otype) == POINTER_TYPE
3469           && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
3470           && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
3471           && !(integer_zerop (value) && TREE_TYPE (otype) == void_type_node
3472                && TREE_CODE (expr) != NOP_EXPR))
3473         pedwarn ("ISO C forbids conversion of object pointer to function pointer type");
3474
3475       ovalue = value;
3476       value = convert (type, value);
3477
3478       /* Ignore any integer overflow caused by the cast.  */
3479       if (TREE_CODE (value) == INTEGER_CST)
3480         {
3481           if (CONSTANT_CLASS_P (ovalue)
3482               && (TREE_OVERFLOW (ovalue) || TREE_CONSTANT_OVERFLOW (ovalue)))
3483             {
3484               /* Avoid clobbering a shared constant.  */
3485               value = copy_node (value);
3486               TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue);
3487               TREE_CONSTANT_OVERFLOW (value) = TREE_CONSTANT_OVERFLOW (ovalue);
3488             }
3489           else if (TREE_OVERFLOW (value) || TREE_CONSTANT_OVERFLOW (value))
3490             /* Reset VALUE's overflow flags, ensuring constant sharing.  */
3491             value = build_int_cst_wide (TREE_TYPE (value),
3492                                         TREE_INT_CST_LOW (value),
3493                                         TREE_INT_CST_HIGH (value));
3494         }
3495     }
3496
3497   /* Don't let a cast be an lvalue.  */
3498   if (value == expr)
3499     value = non_lvalue (value);
3500
3501   return value;
3502 }
3503
3504 /* Interpret a cast of expression EXPR to type TYPE.  */
3505 tree
3506 c_cast_expr (struct c_type_name *type_name, tree expr)
3507 {
3508   tree type;
3509   int saved_wsp = warn_strict_prototypes;
3510
3511   /* This avoids warnings about unprototyped casts on
3512      integers.  E.g. "#define SIG_DFL (void(*)())0".  */
3513   if (TREE_CODE (expr) == INTEGER_CST)
3514     warn_strict_prototypes = 0;
3515   type = groktypename (type_name);
3516   warn_strict_prototypes = saved_wsp;
3517
3518   return build_c_cast (type, expr);
3519 }
3520
3521 \f
3522 /* Build an assignment expression of lvalue LHS from value RHS.
3523    MODIFYCODE is the code for a binary operator that we use
3524    to combine the old value of LHS with RHS to get the new value.
3525    Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.  */
3526
3527 tree
3528 build_modify_expr (tree lhs, enum tree_code modifycode, tree rhs)
3529 {
3530   tree result;
3531   tree newrhs;
3532   tree lhstype = TREE_TYPE (lhs);
3533   tree olhstype = lhstype;
3534
3535   /* Types that aren't fully specified cannot be used in assignments.  */
3536   lhs = require_complete_type (lhs);
3537
3538   /* Avoid duplicate error messages from operands that had errors.  */
3539   if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK)
3540     return error_mark_node;
3541
3542   STRIP_TYPE_NOPS (rhs);
3543
3544   newrhs = rhs;
3545
3546   /* If a binary op has been requested, combine the old LHS value with the RHS
3547      producing the value we should actually store into the LHS.  */
3548
3549   if (modifycode != NOP_EXPR)
3550     {
3551       lhs = stabilize_reference (lhs);
3552       newrhs = build_binary_op (modifycode, lhs, rhs, 1);
3553     }
3554
3555   if (!lvalue_or_else (lhs, lv_assign))
3556     return error_mark_node;
3557
3558   /* Give an error for storing in something that is 'const'.  */
3559
3560   if (TREE_READONLY (lhs) || TYPE_READONLY (lhstype)
3561       || ((TREE_CODE (lhstype) == RECORD_TYPE
3562            || TREE_CODE (lhstype) == UNION_TYPE)
3563           && C_TYPE_FIELDS_READONLY (lhstype)))
3564     readonly_error (lhs, lv_assign);
3565
3566   /* If storing into a structure or union member,
3567      it has probably been given type `int'.
3568      Compute the type that would go with
3569      the actual amount of storage the member occupies.  */
3570
3571   if (TREE_CODE (lhs) == COMPONENT_REF
3572       && (TREE_CODE (lhstype) == INTEGER_TYPE
3573           || TREE_CODE (lhstype) == BOOLEAN_TYPE
3574           || TREE_CODE (lhstype) == REAL_TYPE
3575           || TREE_CODE (lhstype) == ENUMERAL_TYPE))
3576     lhstype = TREE_TYPE (get_unwidened (lhs, 0));
3577
3578   /* If storing in a field that is in actuality a short or narrower than one,
3579      we must store in the field in its actual type.  */
3580
3581   if (lhstype != TREE_TYPE (lhs))
3582     {
3583       lhs = copy_node (lhs);
3584       TREE_TYPE (lhs) = lhstype;
3585     }
3586
3587   /* Convert new value to destination type.  */
3588
3589   newrhs = convert_for_assignment (lhstype, newrhs, ic_assign,
3590                                    NULL_TREE, NULL_TREE, 0);
3591   if (TREE_CODE (newrhs) == ERROR_MARK)
3592     return error_mark_node;
3593
3594   /* Emit ObjC write barrier, if necessary.  */
3595   if (c_dialect_objc () && flag_objc_gc)
3596     {
3597       result = objc_generate_write_barrier (lhs, modifycode, newrhs);
3598       if (result)
3599         return result;
3600     }
3601
3602   /* Scan operands.  */
3603
3604   result = build2 (MODIFY_EXPR, lhstype, lhs, newrhs);
3605   TREE_SIDE_EFFECTS (result) = 1;
3606
3607   /* If we got the LHS in a different type for storing in,
3608      convert the result back to the nominal type of LHS
3609      so that the value we return always has the same type
3610      as the LHS argument.  */
3611
3612   if (olhstype == TREE_TYPE (result))
3613     return result;
3614   return convert_for_assignment (olhstype, result, ic_assign,
3615                                  NULL_TREE, NULL_TREE, 0);
3616 }
3617 \f
3618 /* Convert value RHS to type TYPE as preparation for an assignment
3619    to an lvalue of type TYPE.
3620    The real work of conversion is done by `convert'.
3621    The purpose of this function is to generate error messages
3622    for assignments that are not allowed in C.
3623    ERRTYPE says whether it is argument passing, assignment,
3624    initialization or return.
3625
3626    FUNCTION is a tree for the function being called.
3627    PARMNUM is the number of the argument, for printing in error messages.  */
3628
3629 static tree
3630 convert_for_assignment (tree type, tree rhs, enum impl_conv errtype,
3631                         tree fundecl, tree function, int parmnum)
3632 {
3633   enum tree_code codel = TREE_CODE (type);
3634   tree rhstype;
3635   enum tree_code coder;
3636   tree rname = NULL_TREE;
3637   bool objc_ok = false;
3638
3639   if (errtype == ic_argpass || errtype == ic_argpass_nonproto)
3640     {
3641       tree selector;
3642       /* Change pointer to function to the function itself for
3643          diagnostics.  */
3644       if (TREE_CODE (function) == ADDR_EXPR
3645           && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL)
3646         function = TREE_OPERAND (function, 0);
3647
3648       /* Handle an ObjC selector specially for diagnostics.  */
3649       selector = objc_message_selector ();
3650       rname = function;
3651       if (selector && parmnum > 2)
3652         {
3653           rname = selector;
3654           parmnum -= 2;
3655         }
3656     }
3657
3658   /* This macro is used to emit diagnostics to ensure that all format
3659      strings are complete sentences, visible to gettext and checked at
3660      compile time.  */
3661 #define WARN_FOR_ASSIGNMENT(AR, AS, IN, RE)     \
3662   do {                                          \
3663     switch (errtype)                            \
3664       {                                         \
3665       case ic_argpass:                          \
3666         pedwarn (AR, parmnum, rname);           \
3667         break;                                  \
3668       case ic_argpass_nonproto:                 \
3669         warning (0, AR, parmnum, rname);                \
3670         break;                                  \
3671       case ic_assign:                           \
3672         pedwarn (AS);                           \
3673         break;                                  \
3674       case ic_init:                             \
3675         pedwarn (IN);                           \
3676         break;                                  \
3677       case ic_return:                           \
3678         pedwarn (RE);                           \
3679         break;                                  \
3680       default:                                  \
3681         gcc_unreachable ();                     \
3682       }                                         \
3683   } while (0)
3684
3685   STRIP_TYPE_NOPS (rhs);
3686
3687   if (optimize && TREE_CODE (rhs) == VAR_DECL
3688            && TREE_CODE (TREE_TYPE (rhs)) != ARRAY_TYPE)
3689     rhs = decl_constant_value_for_broken_optimization (rhs);
3690
3691   rhstype = TREE_TYPE (rhs);
3692   coder = TREE_CODE (rhstype);
3693
3694   if (coder == ERROR_MARK)
3695     return error_mark_node;
3696
3697   if (c_dialect_objc ())
3698     {
3699       int parmno;
3700
3701       switch (errtype)
3702         {
3703         case ic_return:
3704           parmno = 0;
3705           break;
3706
3707         case ic_assign:
3708           parmno = -1;
3709           break;
3710
3711         case ic_init:
3712           parmno = -2;
3713           break;
3714
3715         default:
3716           parmno = parmnum;
3717           break;
3718         }
3719
3720       objc_ok = objc_compare_types (type, rhstype, parmno, rname);
3721     }
3722
3723   if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
3724     {
3725       overflow_warning (rhs);
3726       return rhs;
3727     }
3728
3729   if (coder == VOID_TYPE)
3730     {
3731       /* Except for passing an argument to an unprototyped function,
3732          this is a constraint violation.  When passing an argument to
3733          an unprototyped function, it is compile-time undefined;
3734          making it a constraint in that case was rejected in
3735          DR#252.  */
3736       error ("void value not ignored as it ought to be");
3737       return error_mark_node;
3738     }
3739   /* A type converts to a reference to it.
3740      This code doesn't fully support references, it's just for the
3741      special case of va_start and va_copy.  */
3742   if (codel == REFERENCE_TYPE
3743       && comptypes (TREE_TYPE (type), TREE_TYPE (rhs)) == 1)
3744     {
3745       if (!lvalue_p (rhs))
3746         {
3747           error ("cannot pass rvalue to reference parameter");
3748           return error_mark_node;
3749         }
3750       if (!c_mark_addressable (rhs))
3751         return error_mark_node;
3752       rhs = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (rhs)), rhs);
3753
3754       /* We already know that these two types are compatible, but they
3755          may not be exactly identical.  In fact, `TREE_TYPE (type)' is
3756          likely to be __builtin_va_list and `TREE_TYPE (rhs)' is
3757          likely to be va_list, a typedef to __builtin_va_list, which
3758          is different enough that it will cause problems later.  */
3759       if (TREE_TYPE (TREE_TYPE (rhs)) != TREE_TYPE (type))
3760         rhs = build1 (NOP_EXPR, build_pointer_type (TREE_TYPE (type)), rhs);
3761
3762       rhs = build1 (NOP_EXPR, type, rhs);
3763       return rhs;
3764     }
3765   /* Some types can interconvert without explicit casts.  */
3766   else if (codel == VECTOR_TYPE && coder == VECTOR_TYPE
3767            && vector_types_convertible_p (type, TREE_TYPE (rhs)))
3768     return convert (type, rhs);
3769   /* Arithmetic types all interconvert, and enum is treated like int.  */
3770   else if ((codel == INTEGER_TYPE || codel == REAL_TYPE
3771             || codel == ENUMERAL_TYPE || codel == COMPLEX_TYPE
3772             || codel == BOOLEAN_TYPE)
3773            && (coder == INTEGER_TYPE || coder == REAL_TYPE
3774                || coder == ENUMERAL_TYPE || coder == COMPLEX_TYPE
3775                || coder == BOOLEAN_TYPE))
3776     return convert_and_check (type, rhs);
3777
3778   /* Conversion to a transparent union from its member types.
3779      This applies only to function arguments.  */
3780   else if (codel == UNION_TYPE && TYPE_TRANSPARENT_UNION (type)
3781            && (errtype == ic_argpass || errtype == ic_argpass_nonproto))
3782     {
3783       tree memb, marginal_memb = NULL_TREE;
3784
3785       for (memb = TYPE_FIELDS (type); memb ; memb = TREE_CHAIN (memb))
3786         {
3787           tree memb_type = TREE_TYPE (memb);
3788
3789           if (comptypes (TYPE_MAIN_VARIANT (memb_type),
3790                          TYPE_MAIN_VARIANT (rhstype)))
3791             break;
3792
3793           if (TREE_CODE (memb_type) != POINTER_TYPE)
3794             continue;
3795
3796           if (coder == POINTER_TYPE)
3797             {
3798               tree ttl = TREE_TYPE (memb_type);
3799               tree ttr = TREE_TYPE (rhstype);
3800
3801               /* Any non-function converts to a [const][volatile] void *
3802                  and vice versa; otherwise, targets must be the same.
3803                  Meanwhile, the lhs target must have all the qualifiers of
3804                  the rhs.  */
3805               if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr)
3806                   || comp_target_types (memb_type, rhstype))
3807                 {
3808                   /* If this type won't generate any warnings, use it.  */
3809                   if (TYPE_QUALS (ttl) == TYPE_QUALS (ttr)
3810                       || ((TREE_CODE (ttr) == FUNCTION_TYPE
3811                            && TREE_CODE (ttl) == FUNCTION_TYPE)
3812                           ? ((TYPE_QUALS (ttl) | TYPE_QUALS (ttr))
3813                              == TYPE_QUALS (ttr))
3814                           : ((TYPE_QUALS (ttl) | TYPE_QUALS (ttr))
3815                              == TYPE_QUALS (ttl))))
3816                     break;
3817
3818                   /* Keep looking for a better type, but remember this one.  */
3819                   if (!marginal_memb)
3820                     marginal_memb = memb;
3821                 }
3822             }
3823
3824           /* Can convert integer zero to any pointer type.  */
3825           if (integer_zerop (rhs)
3826               || (TREE_CODE (rhs) == NOP_EXPR
3827                   && integer_zerop (TREE_OPERAND (rhs, 0))))
3828             {
3829               rhs = null_pointer_node;
3830               break;
3831             }
3832         }
3833
3834       if (memb || marginal_memb)
3835         {
3836           if (!memb)
3837             {
3838               /* We have only a marginally acceptable member type;
3839                  it needs a warning.  */
3840               tree ttl = TREE_TYPE (TREE_TYPE (marginal_memb));
3841               tree ttr = TREE_TYPE (rhstype);
3842
3843               /* Const and volatile mean something different for function
3844                  types, so the usual warnings are not appropriate.  */
3845               if (TREE_CODE (ttr) == FUNCTION_TYPE
3846                   && TREE_CODE (ttl) == FUNCTION_TYPE)
3847                 {
3848                   /* Because const and volatile on functions are
3849                      restrictions that say the function will not do
3850                      certain things, it is okay to use a const or volatile
3851                      function where an ordinary one is wanted, but not
3852                      vice-versa.  */
3853                   if (TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr))
3854                     WARN_FOR_ASSIGNMENT (G_("passing argument %d of %qE "
3855                                             "makes qualified function "
3856                                             "pointer from unqualified"),
3857                                          G_("assignment makes qualified "
3858                                             "function pointer from "
3859                                             "unqualified"),
3860                                          G_("initialization makes qualified "
3861                                             "function pointer from "
3862                                             "unqualified"),
3863                                          G_("return makes qualified function "
3864                                             "pointer from unqualified"));
3865                 }
3866               else if (TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl))
3867                 WARN_FOR_ASSIGNMENT (G_("passing argument %d of %qE discards "
3868                                         "qualifiers from pointer target type"),
3869                                      G_("assignment discards qualifiers "
3870                                         "from pointer target type"),
3871                                      G_("initialization discards qualifiers "
3872                                         "from pointer target type"),
3873                                      G_("return discards qualifiers from "
3874                                         "pointer target type"));
3875
3876               memb = marginal_memb;
3877             }
3878
3879           if (pedantic && (!fundecl || !DECL_IN_SYSTEM_HEADER (fundecl)))
3880             pedwarn ("ISO C prohibits argument conversion to union type");
3881
3882           return build_constructor_single (type, memb, rhs);
3883         }
3884     }
3885
3886   /* Conversions among pointers */
3887   else if ((codel == POINTER_TYPE || codel == REFERENCE_TYPE)
3888            && (coder == codel))
3889     {
3890       tree ttl = TREE_TYPE (type);
3891       tree ttr = TREE_TYPE (rhstype);
3892       tree mvl = ttl;
3893       tree mvr = ttr;
3894       bool is_opaque_pointer;
3895       int target_cmp = 0;   /* Cache comp_target_types () result.  */
3896
3897       if (TREE_CODE (mvl) != ARRAY_TYPE)
3898         mvl = TYPE_MAIN_VARIANT (mvl);
3899       if (TREE_CODE (mvr) != ARRAY_TYPE)
3900         mvr = TYPE_MAIN_VARIANT (mvr);
3901       /* Opaque pointers are treated like void pointers.  */
3902       is_opaque_pointer = (targetm.vector_opaque_p (type)
3903                            || targetm.vector_opaque_p (rhstype))
3904         && TREE_CODE (ttl) == VECTOR_TYPE
3905         && TREE_CODE (ttr) == VECTOR_TYPE;
3906       
3907       /* C++ does not allow the implicit conversion void* -> T*.  However,
3908          for the purpose of reducing the number of false positives, we
3909          tolerate the special case of
3910
3911                 int *p = NULL;
3912
3913          where NULL is typically defined in C to be '(void *) 0'.  */
3914       if (VOID_TYPE_P (ttr) && rhs != null_pointer_node && !VOID_TYPE_P (ttl))
3915         warning (OPT_Wc___compat, "request for implicit conversion from "
3916                  "%qT to %qT not permitted in C++", rhstype, type);
3917
3918       /* Check if the right-hand side has a format attribute but the
3919          left-hand side doesn't.  */
3920       if (warn_missing_format_attribute
3921           && check_missing_format_attribute (type, rhstype))
3922         {
3923           switch (errtype)
3924           {
3925           case ic_argpass:
3926           case ic_argpass_nonproto:
3927             warning (OPT_Wmissing_format_attribute,
3928                      "argument %d of %qE might be "
3929                      "a candidate for a format attribute",
3930                      parmnum, rname);
3931             break;
3932           case ic_assign:
3933             warning (OPT_Wmissing_format_attribute,
3934                      "assignment left-hand side might be "
3935                      "a candidate for a format attribute");
3936             break;
3937           case ic_init:
3938             warning (OPT_Wmissing_format_attribute,
3939                      "initialization left-hand side might be "
3940                      "a candidate for a format attribute");
3941             break;
3942           case ic_return:
3943             warning (OPT_Wmissing_format_attribute,
3944                      "return type might be "
3945                      "a candidate for a format attribute");
3946             break;
3947           default:
3948             gcc_unreachable ();
3949           }
3950         }
3951       
3952       /* Any non-function converts to a [const][volatile] void *
3953          and vice versa; otherwise, targets must be the same.
3954          Meanwhile, the lhs target must have all the qualifiers of the rhs.  */
3955       if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr)
3956           || (target_cmp = comp_target_types (type, rhstype))
3957           || is_opaque_pointer
3958           || (c_common_unsigned_type (mvl)
3959               == c_common_unsigned_type (mvr)))
3960         {
3961           if (pedantic
3962               && ((VOID_TYPE_P (ttl) && TREE_CODE (ttr) == FUNCTION_TYPE)
3963                   ||
3964                   (VOID_TYPE_P (ttr)
3965                    /* Check TREE_CODE to catch cases like (void *) (char *) 0
3966                       which are not ANSI null ptr constants.  */
3967                    && (!integer_zerop (rhs) || TREE_CODE (rhs) == NOP_EXPR)
3968                    && TREE_CODE (ttl) == FUNCTION_TYPE)))
3969             WARN_FOR_ASSIGNMENT (G_("ISO C forbids passing argument %d of "
3970                                     "%qE between function pointer "
3971                                     "and %<void *%>"),
3972                                  G_("ISO C forbids assignment between "
3973                                     "function pointer and %<void *%>"),
3974                                  G_("ISO C forbids initialization between "
3975                                     "function pointer and %<void *%>"),
3976                                  G_("ISO C forbids return between function "
3977                                     "pointer and %<void *%>"));
3978           /* Const and volatile mean something different for function types,
3979              so the usual warnings are not appropriate.  */
3980           else if (TREE_CODE (ttr) != FUNCTION_TYPE
3981                    && TREE_CODE (ttl) != FUNCTION_TYPE)
3982             {
3983               if (TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl))
3984                 {
3985                   /* Types differing only by the presence of the 'volatile'
3986                      qualifier are acceptable if the 'volatile' has been added
3987                      in by the Objective-C EH machinery.  */
3988                   if (!objc_type_quals_match (ttl, ttr))
3989                     WARN_FOR_ASSIGNMENT (G_("passing argument %d of %qE discards "
3990                                             "qualifiers from pointer target type"),
3991                                          G_("assignment discards qualifiers "
3992                                             "from pointer target type"),
3993                                          G_("initialization discards qualifiers "
3994                                             "from pointer target type"),
3995                                          G_("return discards qualifiers from "
3996                                             "pointer target type"));
3997                 }
3998               /* If this is not a case of ignoring a mismatch in signedness,
3999                  no warning.  */
4000               else if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr)
4001                        || target_cmp)
4002                 ;
4003               /* If there is a mismatch, do warn.  */
4004               else if (warn_pointer_sign)
4005                 WARN_FOR_ASSIGNMENT (G_("pointer targets in passing argument "
4006                                         "%d of %qE differ in signedness"),
4007                                      G_("pointer targets in assignment "
4008                                         "differ in signedness"),
4009                                      G_("pointer targets in initialization "
4010                                         "differ in signedness"),
4011                                      G_("pointer targets in return differ "
4012                                         "in signedness"));
4013             }
4014           else if (TREE_CODE (ttl) == FUNCTION_TYPE
4015                    && TREE_CODE (ttr) == FUNCTION_TYPE)
4016             {
4017               /* Because const and volatile on functions are restrictions
4018                  that say the function will not do certain things,
4019                  it is okay to use a const or volatile function
4020                  where an ordinary one is wanted, but not vice-versa.  */
4021               if (TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr))
4022                 WARN_FOR_ASSIGNMENT (G_("passing argument %d of %qE makes "
4023                                         "qualified function pointer "
4024                                         "from unqualified"),
4025                                      G_("assignment makes qualified function "
4026                                         "pointer from unqualified"),
4027                                      G_("initialization makes qualified "
4028                                         "function pointer from unqualified"),
4029                                      G_("return makes qualified function "
4030                                         "pointer from unqualified"));
4031             }
4032         }
4033       else
4034         /* Avoid warning about the volatile ObjC EH puts on decls.  */
4035         if (!objc_ok)
4036           WARN_FOR_ASSIGNMENT (G_("passing argument %d of %qE from "
4037                                   "incompatible pointer type"),
4038                                G_("assignment from incompatible pointer type"),
4039                                G_("initialization from incompatible "
4040                                   "pointer type"),
4041                                G_("return from incompatible pointer type"));
4042
4043       return convert (type, rhs);
4044     }
4045   else if (codel == POINTER_TYPE && coder == ARRAY_TYPE)
4046     {
4047       /* ??? This should not be an error when inlining calls to
4048          unprototyped functions.  */
4049       error ("invalid use of non-lvalue array");
4050       return error_mark_node;
4051     }
4052   else if (codel == POINTER_TYPE && coder == INTEGER_TYPE)
4053     {
4054       /* An explicit constant 0 can convert to a pointer,
4055          or one that results from arithmetic, even including
4056          a cast to integer type.  */
4057       if (!(TREE_CODE (rhs) == INTEGER_CST && integer_zerop (rhs))
4058           &&
4059           !(TREE_CODE (rhs) == NOP_EXPR
4060             && TREE_CODE (TREE_TYPE (rhs)) == INTEGER_TYPE
4061             && TREE_CODE (TREE_OPERAND (rhs, 0)) == INTEGER_CST
4062             && integer_zerop (TREE_OPERAND (rhs, 0))))
4063         WARN_FOR_ASSIGNMENT (G_("passing argument %d of %qE makes "
4064                                 "pointer from integer without a cast"),
4065                              G_("assignment makes pointer from integer "
4066                                 "without a cast"),
4067                              G_("initialization makes pointer from "
4068                                 "integer without a cast"),
4069                              G_("return makes pointer from integer "
4070                                 "without a cast"));
4071
4072       return convert (type, rhs);
4073     }
4074   else if (codel == INTEGER_TYPE && coder == POINTER_TYPE)
4075     {
4076       WARN_FOR_ASSIGNMENT (G_("passing argument %d of %qE makes integer "
4077                               "from pointer without a cast"),
4078                            G_("assignment makes integer from pointer "
4079                               "without a cast"),
4080                            G_("initialization makes integer from pointer "
4081                               "without a cast"),
4082                            G_("return makes integer from pointer "
4083                               "without a cast"));
4084       return convert (type, rhs);
4085     }
4086   else if (codel == BOOLEAN_TYPE && coder == POINTER_TYPE)
4087     return convert (type, rhs);
4088
4089   switch (errtype)
4090     {
4091     case ic_argpass:
4092     case ic_argpass_nonproto:
4093       /* ??? This should not be an error when inlining calls to
4094          unprototyped functions.  */
4095       error ("incompatible type for argument %d of %qE", parmnum, rname);
4096       break;
4097     case ic_assign:
4098       error ("incompatible types in assignment");
4099       break;
4100     case ic_init:
4101       error ("incompatible types in initialization");
4102       break;
4103     case ic_return:
4104       error ("incompatible types in return");
4105       break;
4106     default:
4107       gcc_unreachable ();
4108     }
4109
4110   return error_mark_node;
4111 }
4112
4113 /* Convert VALUE for assignment into inlined parameter PARM.  ARGNUM
4114    is used for error and waring reporting and indicates which argument
4115    is being processed.  */
4116
4117 tree
4118 c_convert_parm_for_inlining (tree parm, tree value, tree fn, int argnum)
4119 {
4120   tree ret, type;
4121
4122   /* If FN was prototyped, the value has been converted already
4123      in convert_arguments.  */
4124   if (!value || TYPE_ARG_TYPES (TREE_TYPE (fn)))
4125     return value;
4126
4127   type = TREE_TYPE (parm);
4128   ret = convert_for_assignment (type, value,
4129                                 ic_argpass_nonproto, fn,
4130                                 fn, argnum);
4131   if (targetm.calls.promote_prototypes (TREE_TYPE (fn))
4132       && INTEGRAL_TYPE_P (type)
4133       && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
4134     ret = default_conversion (ret);
4135   return ret;
4136 }
4137 \f
4138 /* If VALUE is a compound expr all of whose expressions are constant, then
4139    return its value.  Otherwise, return error_mark_node.
4140
4141    This is for handling COMPOUND_EXPRs as initializer elements
4142    which is allowed with a warning when -pedantic is specified.  */
4143
4144 static tree
4145 valid_compound_expr_initializer (tree value, tree endtype)
4146 {
4147   if (TREE_CODE (value) == COMPOUND_EXPR)
4148     {
4149       if (valid_compound_expr_initializer (TREE_OPERAND (value, 0), endtype)
4150           == error_mark_node)
4151         return error_mark_node;
4152       return valid_compound_expr_initializer (TREE_OPERAND (value, 1),
4153                                               endtype);
4154     }
4155   else if (!initializer_constant_valid_p (value, endtype))
4156     return error_mark_node;
4157   else
4158     return value;
4159 }
4160 \f
4161 /* Perform appropriate conversions on the initial value of a variable,
4162    store it in the declaration DECL,
4163    and print any error messages that are appropriate.
4164    If the init is invalid, store an ERROR_MARK.  */
4165
4166 void
4167 store_init_value (tree decl, tree init)
4168 {
4169   tree value, type;
4170
4171   /* If variable's type was invalidly declared, just ignore it.  */
4172
4173   type = TREE_TYPE (decl);
4174   if (TREE_CODE (type) == ERROR_MARK)
4175     return;
4176
4177   /* Digest the specified initializer into an expression.  */
4178
4179   value = digest_init (type, init, true, TREE_STATIC (decl));
4180
4181   /* Store the expression if valid; else report error.  */
4182
4183   if (!in_system_header
4184       && AGGREGATE_TYPE_P (TREE_TYPE (decl)) && !TREE_STATIC (decl))
4185     warning (OPT_Wtraditional, "traditional C rejects automatic "
4186              "aggregate initialization");
4187
4188   DECL_INITIAL (decl) = value;
4189
4190   /* ANSI wants warnings about out-of-range constant initializers.  */
4191   STRIP_TYPE_NOPS (value);
4192   constant_expression_warning (value);
4193
4194   /* Check if we need to set array size from compound literal size.  */
4195   if (TREE_CODE (type) == ARRAY_TYPE
4196       && TYPE_DOMAIN (type) == 0
4197       && value != error_mark_node)
4198     {
4199       tree inside_init = init;
4200
4201       STRIP_TYPE_NOPS (inside_init);
4202       inside_init = fold (inside_init);
4203
4204       if (TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
4205         {
4206           tree decl = COMPOUND_LITERAL_EXPR_DECL (inside_init);
4207
4208           if (TYPE_DOMAIN (TREE_TYPE (decl)))
4209             {
4210               /* For int foo[] = (int [3]){1}; we need to set array size
4211                  now since later on array initializer will be just the
4212                  brace enclosed list of the compound literal.  */
4213               TYPE_DOMAIN (type) = TYPE_DOMAIN (TREE_TYPE (decl));
4214               layout_type (type);
4215               layout_decl (decl, 0);
4216             }
4217         }
4218     }
4219 }
4220 \f
4221 /* Methods for storing and printing names for error messages.  */
4222
4223 /* Implement a spelling stack that allows components of a name to be pushed
4224    and popped.  Each element on the stack is this structure.  */
4225
4226 struct spelling
4227 {
4228   int kind;
4229   union
4230     {
4231       unsigned HOST_WIDE_INT i;
4232       const char *s;
4233     } u;
4234 };
4235
4236 #define SPELLING_STRING 1
4237 #define SPELLING_MEMBER 2
4238 #define SPELLING_BOUNDS 3
4239
4240 static struct spelling *spelling;       /* Next stack element (unused).  */
4241 static struct spelling *spelling_base;  /* Spelling stack base.  */
4242 static int spelling_size;               /* Size of the spelling stack.  */
4243
4244 /* Macros to save and restore the spelling stack around push_... functions.
4245    Alternative to SAVE_SPELLING_STACK.  */
4246
4247 #define SPELLING_DEPTH() (spelling - spelling_base)
4248 #define RESTORE_SPELLING_DEPTH(DEPTH) (spelling = spelling_base + (DEPTH))
4249
4250 /* Push an element on the spelling stack with type KIND and assign VALUE
4251    to MEMBER.  */
4252
4253 #define PUSH_SPELLING(KIND, VALUE, MEMBER)                              \
4254 {                                                                       \
4255   int depth = SPELLING_DEPTH ();                                        \
4256                                                                         \
4257   if (depth >= spelling_size)                                           \
4258     {                                                                   \
4259       spelling_size += 10;                                              \
4260       spelling_base = XRESIZEVEC (struct spelling, spelling_base,       \
4261                                   spelling_size);                       \
4262       RESTORE_SPELLING_DEPTH (depth);                                   \
4263     }                                                                   \
4264                                                                         \
4265   spelling->kind = (KIND);                                              \
4266   spelling->MEMBER = (VALUE);                                           \
4267   spelling++;                                                           \
4268 }
4269
4270 /* Push STRING on the stack.  Printed literally.  */
4271
4272 static void
4273 push_string (const char *string)
4274 {
4275   PUSH_SPELLING (SPELLING_STRING, string, u.s);
4276 }
4277
4278 /* Push a member name on the stack.  Printed as '.' STRING.  */
4279
4280 static void
4281 push_member_name (tree decl)
4282 {
4283   const char *const string
4284     = DECL_NAME (decl) ? IDENTIFIER_POINTER (DECL_NAME (decl)) : "<anonymous>";
4285   PUSH_SPELLING (SPELLING_MEMBER, string, u.s);
4286 }
4287
4288 /* Push an array bounds on the stack.  Printed as [BOUNDS].  */
4289
4290 static void
4291 push_array_bounds (unsigned HOST_WIDE_INT bounds)
4292 {
4293   PUSH_SPELLING (SPELLING_BOUNDS, bounds, u.i);
4294 }
4295
4296 /* Compute the maximum size in bytes of the printed spelling.  */
4297
4298 static int
4299 spelling_length (void)
4300 {
4301   int size = 0;
4302   struct spelling *p;
4303
4304   for (p = spelling_base; p < spelling; p++)
4305     {
4306       if (p->kind == SPELLING_BOUNDS)
4307         size += 25;
4308       else
4309         size += strlen (p->u.s) + 1;
4310     }
4311
4312   return size;
4313 }
4314
4315 /* Print the spelling to BUFFER and return it.  */
4316
4317 static char *
4318 print_spelling (char *buffer)
4319 {
4320   char *d = buffer;
4321   struct spelling *p;
4322
4323   for (p = spelling_base; p < spelling; p++)
4324     if (p->kind == SPELLING_BOUNDS)
4325       {
4326         sprintf (d, "[" HOST_WIDE_INT_PRINT_UNSIGNED "]", p->u.i);
4327         d += strlen (d);
4328       }
4329     else
4330       {
4331         const char *s;
4332         if (p->kind == SPELLING_MEMBER)
4333           *d++ = '.';
4334         for (s = p->u.s; (*d = *s++); d++)
4335           ;
4336       }
4337   *d++ = '\0';
4338   return buffer;
4339 }
4340
4341 /* Issue an error message for a bad initializer component.
4342    MSGID identifies the message.
4343    The component name is taken from the spelling stack.  */
4344
4345 void
4346 error_init (const char *msgid)
4347 {
4348   char *ofwhat;
4349
4350   error ("%s", _(msgid));
4351   ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
4352   if (*ofwhat)
4353     error ("(near initialization for %qs)", ofwhat);
4354 }
4355
4356 /* Issue a pedantic warning for a bad initializer component.
4357    MSGID identifies the message.
4358    The component name is taken from the spelling stack.  */
4359
4360 void
4361 pedwarn_init (const char *msgid)
4362 {
4363   char *ofwhat;
4364
4365   pedwarn ("%s", _(msgid));
4366   ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
4367   if (*ofwhat)
4368     pedwarn ("(near initialization for %qs)", ofwhat);
4369 }
4370
4371 /* Issue a warning for a bad initializer component.
4372    MSGID identifies the message.
4373    The component name is taken from the spelling stack.  */
4374
4375 static void
4376 warning_init (const char *msgid)
4377 {
4378   char *ofwhat;
4379
4380   warning (0, "%s", _(msgid));
4381   ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
4382   if (*ofwhat)
4383     warning (0, "(near initialization for %qs)", ofwhat);
4384 }
4385 \f
4386 /* If TYPE is an array type and EXPR is a parenthesized string
4387    constant, warn if pedantic that EXPR is being used to initialize an
4388    object of type TYPE.  */
4389
4390 void
4391 maybe_warn_string_init (tree type, struct c_expr expr)
4392 {
4393   if (pedantic
4394       && TREE_CODE (type) == ARRAY_TYPE
4395       && TREE_CODE (expr.value) == STRING_CST
4396       && expr.original_code != STRING_CST)
4397     pedwarn_init ("array initialized from parenthesized string constant");
4398 }
4399
4400 /* Digest the parser output INIT as an initializer for type TYPE.
4401    Return a C expression of type TYPE to represent the initial value.
4402
4403    If INIT is a string constant, STRICT_STRING is true if it is
4404    unparenthesized or we should not warn here for it being parenthesized.
4405    For other types of INIT, STRICT_STRING is not used.
4406
4407    REQUIRE_CONSTANT requests an error if non-constant initializers or
4408    elements are seen.  */
4409
4410 static tree
4411 digest_init (tree type, tree init, bool strict_string, int require_constant)
4412 {
4413   enum tree_code code = TREE_CODE (type);
4414   tree inside_init = init;
4415
4416   if (type == error_mark_node
4417       || !init
4418       || init == error_mark_node
4419       || TREE_TYPE (init) == error_mark_node)
4420     return error_mark_node;
4421
4422   STRIP_TYPE_NOPS (inside_init);
4423
4424   inside_init = fold (inside_init);
4425
4426   /* Initialization of an array of chars from a string constant
4427      optionally enclosed in braces.  */
4428
4429   if (code == ARRAY_TYPE && inside_init
4430       && TREE_CODE (inside_init) == STRING_CST)
4431     {
4432       tree typ1 = TYPE_MAIN_VARIANT (TREE_TYPE (type));
4433       /* Note that an array could be both an array of character type
4434          and an array of wchar_t if wchar_t is signed char or unsigned
4435          char.  */
4436       bool char_array = (typ1 == char_type_node
4437                          || typ1 == signed_char_type_node
4438                          || typ1 == unsigned_char_type_node);
4439       bool wchar_array = !!comptypes (typ1, wchar_type_node);
4440       if (char_array || wchar_array)
4441         {
4442           struct c_expr expr;
4443           bool char_string;
4444           expr.value = inside_init;
4445           expr.original_code = (strict_string ? STRING_CST : ERROR_MARK);
4446           maybe_warn_string_init (type, expr);
4447
4448           char_string
4449             = (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init)))
4450                == char_type_node);
4451
4452           if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
4453                          TYPE_MAIN_VARIANT (type)))
4454             return inside_init;
4455
4456           if (!wchar_array && !char_string)
4457             {
4458               error_init ("char-array initialized from wide string");
4459               return error_mark_node;
4460             }
4461           if (char_string && !char_array)
4462             {
4463               error_init ("wchar_t-array initialized from non-wide string");
4464               return error_mark_node;
4465             }
4466
4467           TREE_TYPE (inside_init) = type;
4468           if (TYPE_DOMAIN (type) != 0
4469               && TYPE_SIZE (type) != 0
4470               && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
4471               /* Subtract 1 (or sizeof (wchar_t))
4472                  because it's ok to ignore the terminating null char
4473                  that is counted in the length of the constant.  */
4474               && 0 > compare_tree_int (TYPE_SIZE_UNIT (type),
4475                                        TREE_STRING_LENGTH (inside_init)
4476                                        - ((TYPE_PRECISION (typ1)
4477                                            != TYPE_PRECISION (char_type_node))
4478                                           ? (TYPE_PRECISION (wchar_type_node)
4479                                              / BITS_PER_UNIT)
4480                                           : 1)))
4481             pedwarn_init ("initializer-string for array of chars is too long");
4482
4483           return inside_init;
4484         }
4485       else if (INTEGRAL_TYPE_P (typ1))
4486         {
4487           error_init ("array of inappropriate type initialized "
4488                       "from string constant");
4489           return error_mark_node;
4490         }
4491     }
4492
4493   /* Build a VECTOR_CST from a *constant* vector constructor.  If the
4494      vector constructor is not constant (e.g. {1,2,3,foo()}) then punt
4495      below and handle as a constructor.  */
4496   if (code == VECTOR_TYPE
4497       && TREE_CODE (TREE_TYPE (inside_init)) == VECTOR_TYPE
4498       && vector_types_convertible_p (TREE_TYPE (inside_init), type)
4499       && TREE_CONSTANT (inside_init))
4500     {
4501       if (TREE_CODE (inside_init) == VECTOR_CST
4502           && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
4503                         TYPE_MAIN_VARIANT (type)))
4504         return inside_init;
4505
4506       if (TREE_CODE (inside_init) == CONSTRUCTOR)
4507         {
4508           unsigned HOST_WIDE_INT ix;
4509           tree value;
4510           bool constant_p = true;
4511
4512           /* Iterate through elements and check if all constructor
4513              elements are *_CSTs.  */
4514           FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (inside_init), ix, value)
4515             if (!CONSTANT_CLASS_P (value))
4516               {
4517                 constant_p = false;
4518                 break;
4519               }
4520
4521           if (constant_p)
4522             return build_vector_from_ctor (type,
4523                                            CONSTRUCTOR_ELTS (inside_init));
4524         }
4525     }
4526
4527   /* Any type can be initialized
4528      from an expression of the same type, optionally with braces.  */
4529
4530   if (inside_init && TREE_TYPE (inside_init) != 0
4531       && (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
4532                      TYPE_MAIN_VARIANT (type))
4533           || (code == ARRAY_TYPE
4534               && comptypes (TREE_TYPE (inside_init), type))
4535           || (code == VECTOR_TYPE
4536               && comptypes (TREE_TYPE (inside_init), type))
4537           || (code == POINTER_TYPE
4538               && TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE
4539               && comptypes (TREE_TYPE (TREE_TYPE (inside_init)),
4540                             TREE_TYPE (type)))))
4541     {
4542       if (code == POINTER_TYPE)
4543         {
4544           if (TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE)
4545             {
4546               if (TREE_CODE (inside_init) == STRING_CST
4547                   || TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
4548                 inside_init = array_to_pointer_conversion (inside_init);
4549               else
4550                 {
4551                   error_init ("invalid use of non-lvalue array");
4552                   return error_mark_node;
4553                 }
4554             }
4555         }
4556
4557       if (code == VECTOR_TYPE)
4558         /* Although the types are compatible, we may require a
4559            conversion.  */
4560         inside_init = convert (type, inside_init);
4561
4562       if (require_constant && !flag_isoc99
4563           && TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
4564         {
4565           /* As an extension, allow initializing objects with static storage
4566              duration with compound literals (which are then treated just as
4567              the brace enclosed list they contain).  */
4568           tree decl = COMPOUND_LITERAL_EXPR_DECL (inside_init);
4569           inside_init = DECL_INITIAL (decl);
4570         }
4571
4572       if (code == ARRAY_TYPE && TREE_CODE (inside_init) != STRING_CST
4573           && TREE_CODE (inside_init) != CONSTRUCTOR)
4574         {
4575           error_init ("array initialized from non-constant array expression");
4576           return error_mark_node;
4577         }
4578
4579       if (optimize && TREE_CODE (inside_init) == VAR_DECL)
4580         inside_init = decl_constant_value_for_broken_optimization (inside_init);
4581
4582       /* Compound expressions can only occur here if -pedantic or
4583          -pedantic-errors is specified.  In the later case, we always want
4584          an error.  In the former case, we simply want a warning.  */
4585       if (require_constant && pedantic
4586           && TREE_CODE (inside_init) == COMPOUND_EXPR)
4587         {
4588           inside_init
4589             = valid_compound_expr_initializer (inside_init,
4590                                                TREE_TYPE (inside_init));
4591           if (inside_init == error_mark_node)
4592             error_init ("initializer element is not constant");
4593           else
4594             pedwarn_init ("initializer element is not constant");
4595           if (flag_pedantic_errors)
4596             inside_init = error_mark_node;
4597         }
4598       else if (require_constant
4599                && !initializer_constant_valid_p (inside_init,
4600                                                  TREE_TYPE (inside_init)))
4601         {
4602           error_init ("initializer element is not constant");
4603           inside_init = error_mark_node;
4604         }
4605
4606       /* Added to enable additional -Wmissing-format-attribute warnings.  */
4607       if (TREE_CODE (TREE_TYPE (inside_init)) == POINTER_TYPE)
4608         inside_init = convert_for_assignment (type, inside_init, ic_init, NULL_TREE,
4609                                               NULL_TREE, 0);
4610       return inside_init;
4611     }
4612
4613   /* Handle scalar types, including conversions.  */
4614
4615   if (code == INTEGER_TYPE || code == REAL_TYPE || code == POINTER_TYPE
4616       || code == ENUMERAL_TYPE || code == BOOLEAN_TYPE || code == COMPLEX_TYPE
4617       || code == VECTOR_TYPE)
4618     {
4619       if (TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE
4620           && (TREE_CODE (init) == STRING_CST
4621               || TREE_CODE (init) == COMPOUND_LITERAL_EXPR))
4622         init = array_to_pointer_conversion (init);
4623       inside_init
4624         = convert_for_assignment (type, init, ic_init,
4625                                   NULL_TREE, NULL_TREE, 0);
4626
4627       /* Check to see if we have already given an error message.  */
4628       if (inside_init == error_mark_node)
4629         ;
4630       else if (require_constant && !TREE_CONSTANT (inside_init))
4631         {
4632           error_init ("initializer element is not constant");
4633           inside_init = error_mark_node;
4634         }
4635       else if (require_constant
4636                && !initializer_constant_valid_p (inside_init,
4637                                                  TREE_TYPE (inside_init)))
4638         {
4639           error_init ("initializer element is not computable at load time");
4640           inside_init = error_mark_node;
4641         }
4642
4643       return inside_init;
4644     }
4645
4646   /* Come here only for records and arrays.  */
4647
4648   if (COMPLETE_TYPE_P (type) && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
4649     {
4650       error_init ("variable-sized object may not be initialized");
4651       return error_mark_node;
4652     }
4653
4654   error_init ("invalid initializer");
4655   return error_mark_node;
4656 }
4657 \f
4658 /* Handle initializers that use braces.  */
4659
4660 /* Type of object we are accumulating a constructor for.
4661    This type is always a RECORD_TYPE, UNION_TYPE or ARRAY_TYPE.  */
4662 static tree constructor_type;
4663
4664 /* For a RECORD_TYPE or UNION_TYPE, this is the chain of fields
4665    left to fill.  */
4666 static tree constructor_fields;
4667
4668 /* For an ARRAY_TYPE, this is the specified index
4669    at which to store the next element we get.  */
4670 static tree constructor_index;
4671
4672 /* For an ARRAY_TYPE, this is the maximum index.  */
4673 static tree constructor_max_index;
4674
4675 /* For a RECORD_TYPE, this is the first field not yet written out.  */
4676 static tree constructor_unfilled_fields;
4677
4678 /* For an ARRAY_TYPE, this is the index of the first element
4679    not yet written out.  */
4680 static tree constructor_unfilled_index;
4681
4682 /* In a RECORD_TYPE, the byte index of the next consecutive field.
4683    This is so we can generate gaps between fields, when appropriate.  */
4684 static tree constructor_bit_index;
4685
4686 /* If we are saving up the elements rather than allocating them,
4687    this is the list of elements so far (in reverse order,
4688    most recent first).  */
4689 static VEC(constructor_elt,gc) *constructor_elements;
4690
4691 /* 1 if constructor should be incrementally stored into a constructor chain,
4692    0 if all the elements should be kept in AVL tree.  */
4693 static int constructor_incremental;
4694
4695 /* 1 if so far this constructor's elements are all compile-time constants.  */
4696 static int constructor_constant;
4697
4698 /* 1 if so far this constructor's elements are all valid address constants.  */
4699 static int constructor_simple;
4700
4701 /* 1 if this constructor is erroneous so far.  */
4702 static int constructor_erroneous;
4703
4704 /* Structure for managing pending initializer elements, organized as an
4705    AVL tree.  */
4706
4707 struct init_node
4708 {
4709   struct init_node *left, *right;
4710   struct init_node *parent;
4711   int balance;
4712   tree purpose;
4713   tree value;
4714 };
4715
4716 /* Tree of pending elements at this constructor level.
4717    These are elements encountered out of order
4718    which belong at places we haven't reached yet in actually
4719    writing the output.
4720    Will never hold tree nodes across GC runs.  */
4721 static struct init_node *constructor_pending_elts;
4722
4723 /* The SPELLING_DEPTH of this constructor.  */
4724 static int constructor_depth;
4725
4726 /* DECL node for which an initializer is being read.
4727    0 means we are reading a constructor expression
4728    such as (struct foo) {...}.  */
4729 static tree constructor_decl;
4730
4731 /* Nonzero if this is an initializer for a top-level decl.  */
4732 static int constructor_top_level;
4733
4734 /* Nonzero if there were any member designators in this initializer.  */
4735 static int constructor_designated;
4736
4737 /* Nesting depth of designator list.  */
4738 static int designator_depth;
4739
4740 /* Nonzero if there were diagnosed errors in this designator list.  */
4741 static int designator_erroneous;
4742
4743 \f
4744 /* This stack has a level for each implicit or explicit level of
4745    structuring in the initializer, including the outermost one.  It
4746    saves the values of most of the variables above.  */
4747
4748 struct constructor_range_stack;
4749
4750 struct constructor_stack
4751 {
4752   struct constructor_stack *next;
4753   tree type;
4754   tree fields;
4755   tree index;
4756   tree max_index;
4757   tree unfilled_index;
4758   tree unfilled_fields;
4759   tree bit_index;
4760   VEC(constructor_elt,gc) *elements;
4761   struct init_node *pending_elts;
4762   int offset;
4763   int depth;
4764   /* If value nonzero, this value should replace the entire
4765      constructor at this level.  */
4766   struct c_expr replacement_value;
4767   struct constructor_range_stack *range_stack;
4768   char constant;
4769   char simple;
4770   char implicit;
4771   char erroneous;
4772   char outer;
4773   char incremental;
4774   char designated;
4775 };
4776
4777 static struct constructor_stack *constructor_stack;
4778
4779 /* This stack represents designators from some range designator up to
4780    the last designator in the list.  */
4781
4782 struct constructor_range_stack
4783 {
4784   struct constructor_range_stack *next, *prev;
4785   struct constructor_stack *stack;
4786   tree range_start;
4787   tree index;
4788   tree range_end;
4789   tree fields;
4790 };
4791
4792 static struct constructor_range_stack *constructor_range_stack;
4793
4794 /* This stack records separate initializers that are nested.
4795    Nested initializers can't happen in ANSI C, but GNU C allows them
4796    in cases like { ... (struct foo) { ... } ... }.  */
4797
4798 struct initializer_stack
4799 {
4800   struct initializer_stack *next;
4801   tree decl;
4802   struct constructor_stack *constructor_stack;
4803   struct constructor_range_stack *constructor_range_stack;
4804   VEC(constructor_elt,gc) *elements;
4805   struct spelling *spelling;
4806   struct spelling *spelling_base;
4807   int spelling_size;
4808   char top_level;
4809   char require_constant_value;
4810   char require_constant_elements;
4811 };
4812
4813 static struct initializer_stack *initializer_stack;
4814 \f
4815 /* Prepare to parse and output the initializer for variable DECL.  */
4816
4817 void
4818 start_init (tree decl, tree asmspec_tree ATTRIBUTE_UNUSED, int top_level)
4819 {
4820   const char *locus;
4821   struct initializer_stack *p = xmalloc (sizeof (struct initializer_stack));
4822
4823   p->decl = constructor_decl;
4824   p->require_constant_value = require_constant_value;
4825   p->require_constant_elements = require_constant_elements;
4826   p->constructor_stack = constructor_stack;
4827   p->constructor_range_stack = constructor_range_stack;
4828   p->elements = constructor_elements;
4829   p->spelling = spelling;
4830   p->spelling_base = spelling_base;
4831   p->spelling_size = spelling_size;
4832   p->top_level = constructor_top_level;
4833   p->next = initializer_stack;
4834   initializer_stack = p;
4835
4836   constructor_decl = decl;
4837   constructor_designated = 0;
4838   constructor_top_level = top_level;
4839
4840   if (decl != 0 && decl != error_mark_node)
4841     {
4842       require_constant_value = TREE_STATIC (decl);
4843       require_constant_elements
4844         = ((TREE_STATIC (decl) || (pedantic && !flag_isoc99))
4845            /* For a scalar, you can always use any value to initialize,
4846               even within braces.  */
4847            && (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
4848                || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
4849                || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
4850                || TREE_CODE (TREE_TYPE (decl)) == QUAL_UNION_TYPE));
4851       locus = IDENTIFIER_POINTER (DECL_NAME (decl));
4852     }
4853   else
4854     {
4855       require_constant_value = 0;
4856       require_constant_elements = 0;
4857       locus = "(anonymous)";
4858     }
4859
4860   constructor_stack = 0;
4861   constructor_range_stack = 0;
4862
4863   missing_braces_mentioned = 0;
4864
4865   spelling_base = 0;
4866   spelling_size = 0;
4867   RESTORE_SPELLING_DEPTH (0);
4868
4869   if (locus)
4870     push_string (locus);
4871 }
4872
4873 void
4874 finish_init (void)
4875 {
4876   struct initializer_stack *p = initializer_stack;
4877
4878   /* Free the whole constructor stack of this initializer.  */
4879   while (constructor_stack)
4880     {
4881       struct constructor_stack *q = constructor_stack;
4882       constructor_stack = q->next;
4883       free (q);
4884     }
4885
4886   gcc_assert (!constructor_range_stack);
4887
4888   /* Pop back to the data of the outer initializer (if any).  */
4889   free (spelling_base);
4890
4891   constructor_decl = p->decl;
4892   require_constant_value = p->require_constant_value;
4893   require_constant_elements = p->require_constant_elements;
4894   constructor_stack = p->constructor_stack;
4895   constructor_range_stack = p->constructor_range_stack;
4896   constructor_elements = p->elements;
4897   spelling = p->spelling;
4898   spelling_base = p->spelling_base;
4899   spelling_size = p->spelling_size;
4900   constructor_top_level = p->top_level;
4901   initializer_stack = p->next;
4902   free (p);
4903 }
4904 \f
4905 /* Call here when we see the initializer is surrounded by braces.
4906    This is instead of a call to push_init_level;
4907    it is matched by a call to pop_init_level.
4908
4909    TYPE is the type to initialize, for a constructor expression.
4910    For an initializer for a decl, TYPE is zero.  */
4911
4912 void
4913 really_start_incremental_init (tree type)
4914 {
4915   struct constructor_stack *p = XNEW (struct constructor_stack);
4916
4917   if (type == 0)
4918     type = TREE_TYPE (constructor_decl);
4919
4920   if (targetm.vector_opaque_p (type))
4921     error ("opaque vector types cannot be initialized");
4922
4923   p->type = constructor_type;
4924   p->fields = constructor_fields;
4925   p->index = constructor_index;
4926   p->max_index = constructor_max_index;
4927   p->unfilled_index = constructor_unfilled_index;
4928   p->unfilled_fields = constructor_unfilled_fields;
4929   p->bit_index = constructor_bit_index;
4930   p->elements = constructor_elements;
4931   p->constant = constructor_constant;
4932   p->simple = constructor_simple;
4933   p->erroneous = constructor_erroneous;
4934   p->pending_elts = constructor_pending_elts;
4935   p->depth = constructor_depth;
4936   p->replacement_value.value = 0;
4937   p->replacement_value.original_code = ERROR_MARK;
4938   p->implicit = 0;
4939   p->range_stack = 0;
4940   p->outer = 0;
4941   p->incremental = constructor_incremental;
4942   p->designated = constructor_designated;
4943   p->next = 0;
4944   constructor_stack = p;
4945
4946   constructor_constant = 1;
4947   constructor_simple = 1;
4948   constructor_depth = SPELLING_DEPTH ();
4949   constructor_elements = 0;
4950   constructor_pending_elts = 0;
4951   constructor_type = type;
4952   constructor_incremental = 1;
4953   constructor_designated = 0;
4954   designator_depth = 0;
4955   designator_erroneous = 0;
4956
4957   if (TREE_CODE (constructor_type) == RECORD_TYPE
4958       || TREE_CODE (constructor_type) == UNION_TYPE)
4959     {
4960       constructor_fields = TYPE_FIELDS (constructor_type);
4961       /* Skip any nameless bit fields at the beginning.  */
4962       while (constructor_fields != 0 && DECL_C_BIT_FIELD (constructor_fields)
4963              && DECL_NAME (constructor_fields) == 0)
4964         constructor_fields = TREE_CHAIN (constructor_fields);
4965
4966       constructor_unfilled_fields = constructor_fields;
4967       constructor_bit_index = bitsize_zero_node;
4968     }
4969   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
4970     {
4971       if (TYPE_DOMAIN (constructor_type))
4972         {
4973           constructor_max_index
4974             = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
4975
4976           /* Detect non-empty initializations of zero-length arrays.  */
4977           if (constructor_max_index == NULL_TREE
4978               && TYPE_SIZE (constructor_type))
4979             constructor_max_index = build_int_cst (NULL_TREE, -1);
4980
4981           /* constructor_max_index needs to be an INTEGER_CST.  Attempts
4982              to initialize VLAs will cause a proper error; avoid tree
4983              checking errors as well by setting a safe value.  */
4984           if (constructor_max_index
4985               && TREE_CODE (constructor_max_index) != INTEGER_CST)
4986             constructor_max_index = build_int_cst (NULL_TREE, -1);
4987
4988           constructor_index
4989             = convert (bitsizetype,
4990                        TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
4991         }
4992       else
4993         {
4994           constructor_index = bitsize_zero_node;
4995           constructor_max_index = NULL_TREE;
4996         }
4997
4998       constructor_unfilled_index = constructor_index;
4999     }
5000   else if (TREE_CODE (constructor_type) == VECTOR_TYPE)
5001     {
5002       /* Vectors are like simple fixed-size arrays.  */
5003       constructor_max_index =
5004         build_int_cst (NULL_TREE, TYPE_VECTOR_SUBPARTS (constructor_type) - 1);
5005       constructor_index = bitsize_zero_node;
5006       constructor_unfilled_index = constructor_index;
5007     }
5008   else
5009     {
5010       /* Handle the case of int x = {5}; */
5011       constructor_fields = constructor_type;
5012       constructor_unfilled_fields = constructor_type;
5013     }
5014 }
5015 \f
5016 /* Push down into a subobject, for initialization.
5017    If this is for an explicit set of braces, IMPLICIT is 0.
5018    If it is because the next element belongs at a lower level,
5019    IMPLICIT is 1 (or 2 if the push is because of designator list).  */
5020
5021 void
5022 push_init_level (int implicit)
5023 {
5024   struct constructor_stack *p;
5025   tree value = NULL_TREE;
5026
5027   /* If we've exhausted any levels that didn't have braces,
5028      pop them now.  If implicit == 1, this will have been done in
5029      process_init_element; do not repeat it here because in the case
5030      of excess initializers for an empty aggregate this leads to an
5031      infinite cycle of popping a level and immediately recreating
5032      it.  */
5033   if (implicit != 1)
5034     {
5035       while (constructor_stack->implicit)
5036         {
5037           if ((TREE_CODE (constructor_type) == RECORD_TYPE
5038                || TREE_CODE (constructor_type) == UNION_TYPE)
5039               && constructor_fields == 0)
5040             process_init_element (pop_init_level (1));
5041           else if (TREE_CODE (constructor_type) == ARRAY_TYPE
5042                    && constructor_max_index
5043                    && tree_int_cst_lt (constructor_max_index,
5044                                        constructor_index))
5045             process_init_element (pop_init_level (1));
5046           else
5047             break;
5048         }
5049     }
5050
5051   /* Unless this is an explicit brace, we need to preserve previous
5052      content if any.  */
5053   if (implicit)
5054     {
5055       if ((TREE_CODE (constructor_type) == RECORD_TYPE
5056            || TREE_CODE (constructor_type) == UNION_TYPE)
5057           && constructor_fields)
5058         value = find_init_member (constructor_fields);
5059       else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5060         value = find_init_member (constructor_index);
5061     }
5062
5063   p = XNEW (struct constructor_stack);
5064   p->type = constructor_type;
5065   p->fields = constructor_fields;
5066   p->index = constructor_index;
5067   p->max_index = constructor_max_index;
5068   p->unfilled_index = constructor_unfilled_index;
5069   p->unfilled_fields = constructor_unfilled_fields;
5070   p->bit_index = constructor_bit_index;
5071   p->elements = constructor_elements;
5072   p->constant = constructor_constant;
5073   p->simple = constructor_simple;
5074   p->erroneous = constructor_erroneous;
5075   p->pending_elts = constructor_pending_elts;
5076   p->depth = constructor_depth;
5077   p->replacement_value.value = 0;
5078   p->replacement_value.original_code = ERROR_MARK;
5079   p->implicit = implicit;
5080   p->outer = 0;
5081   p->incremental = constructor_incremental;
5082   p->designated = constructor_designated;
5083   p->next = constructor_stack;
5084   p->range_stack = 0;
5085   constructor_stack = p;
5086
5087   constructor_constant = 1;
5088   constructor_simple = 1;
5089   constructor_depth = SPELLING_DEPTH ();
5090   constructor_elements = 0;
5091   constructor_incremental = 1;
5092   constructor_designated = 0;
5093   constructor_pending_elts = 0;
5094   if (!implicit)
5095     {
5096       p->range_stack = constructor_range_stack;
5097       constructor_range_stack = 0;
5098       designator_depth = 0;
5099       designator_erroneous = 0;
5100     }
5101
5102   /* Don't die if an entire brace-pair level is superfluous
5103      in the containing level.  */
5104   if (constructor_type == 0)
5105     ;
5106   else if (TREE_CODE (constructor_type) == RECORD_TYPE
5107            || TREE_CODE (constructor_type) == UNION_TYPE)
5108     {
5109       /* Don't die if there are extra init elts at the end.  */
5110       if (constructor_fields == 0)
5111         constructor_type = 0;
5112       else
5113         {
5114           constructor_type = TREE_TYPE (constructor_fields);
5115           push_member_name (constructor_fields);
5116           constructor_depth++;
5117         }
5118     }
5119   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5120     {
5121       constructor_type = TREE_TYPE (constructor_type);
5122       push_array_bounds (tree_low_cst (constructor_index, 1));
5123       constructor_depth++;
5124     }
5125
5126   if (constructor_type == 0)
5127     {
5128       error_init ("extra brace group at end of initializer");
5129       constructor_fields = 0;
5130       constructor_unfilled_fields = 0;
5131       return;
5132     }
5133
5134   if (value && TREE_CODE (value) == CONSTRUCTOR)
5135     {
5136       constructor_constant = TREE_CONSTANT (value);
5137       constructor_simple = TREE_STATIC (value);
5138       constructor_elements = CONSTRUCTOR_ELTS (value);
5139       if (!VEC_empty (constructor_elt, constructor_elements)
5140           && (TREE_CODE (constructor_type) == RECORD_TYPE
5141               || TREE_CODE (constructor_type) == ARRAY_TYPE))
5142         set_nonincremental_init ();
5143     }
5144
5145   if (implicit == 1 && warn_missing_braces && !missing_braces_mentioned)
5146     {
5147       missing_braces_mentioned = 1;
5148       warning_init ("missing braces around initializer");
5149     }
5150
5151   if (TREE_CODE (constructor_type) == RECORD_TYPE
5152            || TREE_CODE (constructor_type) == UNION_TYPE)
5153     {
5154       constructor_fields = TYPE_FIELDS (constructor_type);
5155       /* Skip any nameless bit fields at the beginning.  */
5156       while (constructor_fields != 0 && DECL_C_BIT_FIELD (constructor_fields)
5157              && DECL_NAME (constructor_fields) == 0)
5158         constructor_fields = TREE_CHAIN (constructor_fields);
5159
5160       constructor_unfilled_fields = constructor_fields;
5161       constructor_bit_index = bitsize_zero_node;
5162     }
5163   else if (TREE_CODE (constructor_type) == VECTOR_TYPE)
5164     {
5165       /* Vectors are like simple fixed-size arrays.  */
5166       constructor_max_index =
5167         build_int_cst (NULL_TREE, TYPE_VECTOR_SUBPARTS (constructor_type) - 1);
5168       constructor_index = convert (bitsizetype, integer_zero_node);
5169       constructor_unfilled_index = constructor_index;
5170     }
5171   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5172     {
5173       if (TYPE_DOMAIN (constructor_type))
5174         {
5175           constructor_max_index
5176             = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
5177
5178           /* Detect non-empty initializations of zero-length arrays.  */
5179           if (constructor_max_index == NULL_TREE
5180               && TYPE_SIZE (constructor_type))
5181             constructor_max_index = build_int_cst (NULL_TREE, -1);
5182
5183           /* constructor_max_index needs to be an INTEGER_CST.  Attempts
5184              to initialize VLAs will cause a proper error; avoid tree
5185              checking errors as well by setting a safe value.  */
5186           if (constructor_max_index
5187               && TREE_CODE (constructor_max_index) != INTEGER_CST)
5188             constructor_max_index = build_int_cst (NULL_TREE, -1);
5189
5190           constructor_index
5191             = convert (bitsizetype,
5192                        TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
5193         }
5194       else
5195         constructor_index = bitsize_zero_node;
5196
5197       constructor_unfilled_index = constructor_index;
5198       if (value && TREE_CODE (value) == STRING_CST)
5199         {
5200           /* We need to split the char/wchar array into individual
5201              characters, so that we don't have to special case it
5202              everywhere.  */
5203           set_nonincremental_init_from_string (value);
5204         }
5205     }
5206   else
5207     {
5208       if (constructor_type != error_mark_node)
5209         warning_init ("braces around scalar initializer");
5210       constructor_fields = constructor_type;
5211       constructor_unfilled_fields = constructor_type;
5212     }
5213 }
5214
5215 /* At the end of an implicit or explicit brace level,
5216    finish up that level of constructor.  If a single expression
5217    with redundant braces initialized that level, return the
5218    c_expr structure for that expression.  Otherwise, the original_code
5219    element is set to ERROR_MARK.
5220    If we were outputting the elements as they are read, return 0 as the value
5221    from inner levels (process_init_element ignores that),
5222    but return error_mark_node as the value from the outermost level
5223    (that's what we want to put in DECL_INITIAL).
5224    Otherwise, return a CONSTRUCTOR expression as the value.  */
5225
5226 struct c_expr
5227 pop_init_level (int implicit)
5228 {
5229   struct constructor_stack *p;
5230   struct c_expr ret;
5231   ret.value = 0;
5232   ret.original_code = ERROR_MARK;
5233
5234   if (implicit == 0)
5235     {
5236       /* When we come to an explicit close brace,
5237          pop any inner levels that didn't have explicit braces.  */
5238       while (constructor_stack->implicit)
5239         process_init_element (pop_init_level (1));
5240
5241       gcc_assert (!constructor_range_stack);
5242     }
5243
5244   /* Now output all pending elements.  */
5245   constructor_incremental = 1;
5246   output_pending_init_elements (1);
5247
5248   p = constructor_stack;
5249
5250   /* Error for initializing a flexible array member, or a zero-length
5251      array member in an inappropriate context.  */
5252   if (constructor_type && constructor_fields
5253       && TREE_CODE (constructor_type) == ARRAY_TYPE
5254       && TYPE_DOMAIN (constructor_type)
5255       && !TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type)))
5256     {
5257       /* Silently discard empty initializations.  The parser will
5258          already have pedwarned for empty brackets.  */
5259       if (integer_zerop (constructor_unfilled_index))
5260         constructor_type = NULL_TREE;
5261       else
5262         {
5263           gcc_assert (!TYPE_SIZE (constructor_type));
5264           
5265           if (constructor_depth > 2)
5266             error_init ("initialization of flexible array member in a nested context");
5267           else if (pedantic)
5268             pedwarn_init ("initialization of a flexible array member");
5269
5270           /* We have already issued an error message for the existence
5271              of a flexible array member not at the end of the structure.
5272              Discard the initializer so that we do not die later.  */
5273           if (TREE_CHAIN (constructor_fields) != NULL_TREE)
5274             constructor_type = NULL_TREE;
5275         }
5276     }
5277
5278   /* Warn when some struct elements are implicitly initialized to zero.  */
5279   if (warn_missing_field_initializers
5280       && constructor_type
5281       && TREE_CODE (constructor_type) == RECORD_TYPE
5282       && constructor_unfilled_fields)
5283     {
5284         /* Do not warn for flexible array members or zero-length arrays.  */
5285         while (constructor_unfilled_fields
5286                && (!DECL_SIZE (constructor_unfilled_fields)
5287                    || integer_zerop (DECL_SIZE (constructor_unfilled_fields))))
5288           constructor_unfilled_fields = TREE_CHAIN (constructor_unfilled_fields);
5289
5290         /* Do not warn if this level of the initializer uses member
5291            designators; it is likely to be deliberate.  */
5292         if (constructor_unfilled_fields && !constructor_designated)
5293           {
5294             push_member_name (constructor_unfilled_fields);
5295             warning_init ("missing initializer");
5296             RESTORE_SPELLING_DEPTH (constructor_depth);
5297           }
5298     }
5299
5300   /* Pad out the end of the structure.  */
5301   if (p->replacement_value.value)
5302     /* If this closes a superfluous brace pair,
5303        just pass out the element between them.  */
5304     ret = p->replacement_value;
5305   else if (constructor_type == 0)
5306     ;
5307   else if (TREE_CODE (constructor_type) != RECORD_TYPE
5308            && TREE_CODE (constructor_type) != UNION_TYPE
5309            && TREE_CODE (constructor_type) != ARRAY_TYPE
5310            && TREE_CODE (constructor_type) != VECTOR_TYPE)
5311     {
5312       /* A nonincremental scalar initializer--just return
5313          the element, after verifying there is just one.  */
5314       if (VEC_empty (constructor_elt,constructor_elements))
5315         {
5316           if (!constructor_erroneous)
5317             error_init ("empty scalar initializer");
5318           ret.value = error_mark_node;
5319         }
5320       else if (VEC_length (constructor_elt,constructor_elements) != 1)
5321         {
5322           error_init ("extra elements in scalar initializer");
5323           ret.value = VEC_index (constructor_elt,constructor_elements,0)->value;
5324         }
5325       else
5326         ret.value = VEC_index (constructor_elt,constructor_elements,0)->value;
5327     }
5328   else
5329     {
5330       if (constructor_erroneous)
5331         ret.value = error_mark_node;
5332       else
5333         {
5334           ret.value = build_constructor (constructor_type,
5335                                          constructor_elements);
5336           if (constructor_constant)
5337             TREE_CONSTANT (ret.value) = TREE_INVARIANT (ret.value) = 1;
5338           if (constructor_constant && constructor_simple)
5339             TREE_STATIC (ret.value) = 1;
5340         }
5341     }
5342
5343   constructor_type = p->type;
5344   constructor_fields = p->fields;
5345   constructor_index = p->index;
5346   constructor_max_index = p->max_index;
5347   constructor_unfilled_index = p->unfilled_index;
5348   constructor_unfilled_fields = p->unfilled_fields;
5349   constructor_bit_index = p->bit_index;
5350   constructor_elements = p->elements;
5351   constructor_constant = p->constant;
5352   constructor_simple = p->simple;
5353   constructor_erroneous = p->erroneous;
5354   constructor_incremental = p->incremental;
5355   constructor_designated = p->designated;
5356   constructor_pending_elts = p->pending_elts;
5357   constructor_depth = p->depth;
5358   if (!p->implicit)
5359     constructor_range_stack = p->range_stack;
5360   RESTORE_SPELLING_DEPTH (constructor_depth);
5361
5362   constructor_stack = p->next;
5363   free (p);
5364
5365   if (ret.value == 0)
5366     {
5367       if (constructor_stack == 0)
5368         {
5369           ret.value = error_mark_node;
5370           return ret;
5371         }
5372       return ret;
5373     }
5374   return ret;
5375 }
5376
5377 /* Common handling for both array range and field name designators.
5378    ARRAY argument is nonzero for array ranges.  Returns zero for success.  */
5379
5380 static int
5381 set_designator (int array)
5382 {
5383   tree subtype;
5384   enum tree_code subcode;
5385
5386   /* Don't die if an entire brace-pair level is superfluous
5387      in the containing level.  */
5388   if (constructor_type == 0)
5389     return 1;
5390
5391   /* If there were errors in this designator list already, bail out
5392      silently.  */
5393   if (designator_erroneous)
5394     return 1;
5395
5396   if (!designator_depth)
5397     {
5398       gcc_assert (!constructor_range_stack);
5399
5400       /* Designator list starts at the level of closest explicit
5401          braces.  */
5402       while (constructor_stack->implicit)
5403         process_init_element (pop_init_level (1));
5404       constructor_designated = 1;
5405       return 0;
5406     }
5407
5408   switch (TREE_CODE (constructor_type))
5409     {
5410     case  RECORD_TYPE:
5411     case  UNION_TYPE:
5412       subtype = TREE_TYPE (constructor_fields);
5413       if (subtype != error_mark_node)
5414         subtype = TYPE_MAIN_VARIANT (subtype);
5415       break;
5416     case ARRAY_TYPE:
5417       subtype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
5418       break;
5419     default:
5420       gcc_unreachable ();
5421     }
5422
5423   subcode = TREE_CODE (subtype);
5424   if (array && subcode != ARRAY_TYPE)
5425     {
5426       error_init ("array index in non-array initializer");
5427       return 1;
5428     }
5429   else if (!array && subcode != RECORD_TYPE && subcode != UNION_TYPE)
5430     {
5431       error_init ("field name not in record or union initializer");
5432       return 1;
5433     }
5434
5435   constructor_designated = 1;
5436   push_init_level (2);
5437   return 0;
5438 }
5439
5440 /* If there are range designators in designator list, push a new designator
5441    to constructor_range_stack.  RANGE_END is end of such stack range or
5442    NULL_TREE if there is no range designator at this level.  */
5443
5444 static void
5445 push_range_stack (tree range_end)
5446 {
5447   struct constructor_range_stack *p;
5448
5449   p = GGC_NEW (struct constructor_range_stack);
5450   p->prev = constructor_range_stack;
5451   p->next = 0;
5452   p->fields = constructor_fields;
5453   p->range_start = constructor_index;
5454   p->index = constructor_index;
5455   p->stack = constructor_stack;
5456   p->range_end = range_end;
5457   if (constructor_range_stack)
5458     constructor_range_stack->next = p;
5459   constructor_range_stack = p;
5460 }
5461
5462 /* Within an array initializer, specify the next index to be initialized.
5463    FIRST is that index.  If LAST is nonzero, then initialize a range
5464    of indices, running from FIRST through LAST.  */
5465
5466 void
5467 set_init_index (tree first, tree last)
5468 {
5469   if (set_designator (1))
5470     return;
5471
5472   designator_erroneous = 1;
5473
5474   if (!INTEGRAL_TYPE_P (TREE_TYPE (first))
5475       || (last && !INTEGRAL_TYPE_P (TREE_TYPE (last))))
5476     {
5477       error_init ("array index in initializer not of integer type");
5478       return;
5479     }
5480
5481   if (TREE_CODE (first) != INTEGER_CST)
5482     error_init ("nonconstant array index in initializer");
5483   else if (last != 0 && TREE_CODE (last) != INTEGER_CST)
5484     error_init ("nonconstant array index in initializer");
5485   else if (TREE_CODE (constructor_type) != ARRAY_TYPE)
5486     error_init ("array index in non-array initializer");
5487   else if (tree_int_cst_sgn (first) == -1)
5488     error_init ("array index in initializer exceeds array bounds");
5489   else if (constructor_max_index
5490            && tree_int_cst_lt (constructor_max_index, first))
5491     error_init ("array index in initializer exceeds array bounds");
5492   else
5493     {
5494       constructor_index = convert (bitsizetype, first);
5495
5496       if (last)
5497         {
5498           if (tree_int_cst_equal (first, last))
5499             last = 0;
5500           else if (tree_int_cst_lt (last, first))
5501             {
5502               error_init ("empty index range in initializer");
5503               last = 0;
5504             }
5505           else
5506             {
5507               last = convert (bitsizetype, last);
5508               if (constructor_max_index != 0
5509                   && tree_int_cst_lt (constructor_max_index, last))
5510                 {
5511                   error_init ("array index range in initializer exceeds array bounds");
5512                   last = 0;
5513                 }
5514             }
5515         }
5516
5517       designator_depth++;
5518       designator_erroneous = 0;
5519       if (constructor_range_stack || last)
5520         push_range_stack (last);
5521     }
5522 }
5523
5524 /* Within a struct initializer, specify the next field to be initialized.  */
5525
5526 void
5527 set_init_label (tree fieldname)
5528 {
5529   tree tail;
5530
5531   if (set_designator (0))
5532     return;
5533
5534   designator_erroneous = 1;
5535
5536   if (TREE_CODE (constructor_type) != RECORD_TYPE
5537       && TREE_CODE (constructor_type) != UNION_TYPE)
5538     {
5539       error_init ("field name not in record or union initializer");
5540       return;
5541     }
5542
5543   for (tail = TYPE_FIELDS (constructor_type); tail;
5544        tail = TREE_CHAIN (tail))
5545     {
5546       if (DECL_NAME (tail) == fieldname)
5547         break;
5548     }
5549
5550   if (tail == 0)
5551     error ("unknown field %qE specified in initializer", fieldname);
5552   else
5553     {
5554       constructor_fields = tail;
5555       designator_depth++;
5556       designator_erroneous = 0;
5557       if (constructor_range_stack)
5558         push_range_stack (NULL_TREE);
5559     }
5560 }
5561 \f
5562 /* Add a new initializer to the tree of pending initializers.  PURPOSE
5563    identifies the initializer, either array index or field in a structure.
5564    VALUE is the value of that index or field.  */
5565
5566 static void
5567 add_pending_init (tree purpose, tree value)
5568 {
5569   struct init_node *p, **q, *r;
5570
5571   q = &constructor_pending_elts;
5572   p = 0;
5573
5574   if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5575     {
5576       while (*q != 0)
5577         {
5578           p = *q;
5579           if (tree_int_cst_lt (purpose, p->purpose))
5580             q = &p->left;
5581           else if (tree_int_cst_lt (p->purpose, purpose))
5582             q = &p->right;
5583           else
5584             {
5585               if (TREE_SIDE_EFFECTS (p->value))
5586                 warning_init ("initialized field with side-effects overwritten");
5587               p->value = value;
5588               return;
5589             }
5590         }
5591     }
5592   else
5593     {
5594       tree bitpos;
5595
5596       bitpos = bit_position (purpose);
5597       while (*q != NULL)
5598         {
5599           p = *q;
5600           if (tree_int_cst_lt (bitpos, bit_position (p->purpose)))
5601             q = &p->left;
5602           else if (p->purpose != purpose)
5603             q = &p->right;
5604           else
5605             {
5606               if (TREE_SIDE_EFFECTS (p->value))
5607                 warning_init ("initialized field with side-effects overwritten");
5608               p->value = value;
5609               return;
5610             }
5611         }
5612     }
5613
5614   r = GGC_NEW (struct init_node);
5615   r->purpose = purpose;
5616   r->value = value;
5617
5618   *q = r;
5619   r->parent = p;
5620   r->left = 0;
5621   r->right = 0;
5622   r->balance = 0;
5623
5624   while (p)
5625     {
5626       struct init_node *s;
5627
5628       if (r == p->left)
5629         {
5630           if (p->balance == 0)
5631             p->balance = -1;
5632           else if (p->balance < 0)
5633             {
5634               if (r->balance < 0)
5635                 {
5636                   /* L rotation.  */
5637                   p->left = r->right;
5638                   if (p->left)
5639                     p->left->parent = p;
5640                   r->right = p;
5641
5642                   p->balance = 0;
5643                   r->balance = 0;
5644
5645                   s = p->parent;
5646                   p->parent = r;
5647                   r->parent = s;
5648                   if (s)
5649                     {
5650                       if (s->left == p)
5651                         s->left = r;
5652                       else
5653                         s->right = r;
5654                     }
5655                   else
5656                     constructor_pending_elts = r;
5657                 }
5658               else
5659                 {
5660                   /* LR rotation.  */
5661                   struct init_node *t = r->right;
5662
5663                   r->right = t->left;
5664                   if (r->right)
5665                     r->right->parent = r;
5666                   t->left = r;
5667
5668                   p->left = t->right;
5669                   if (p->left)
5670                     p->left->parent = p;
5671                   t->right = p;
5672
5673                   p->balance = t->balance < 0;
5674                   r->balance = -(t->balance > 0);
5675                   t->balance = 0;
5676
5677                   s = p->parent;
5678                   p->parent = t;
5679                   r->parent = t;
5680                   t->parent = s;
5681                   if (s)
5682                     {
5683                       if (s->left == p)
5684                         s->left = t;
5685                       else
5686                         s->right = t;
5687                     }
5688                   else
5689                     constructor_pending_elts = t;
5690                 }
5691               break;
5692             }
5693           else
5694             {
5695               /* p->balance == +1; growth of left side balances the node.  */
5696               p->balance = 0;
5697               break;
5698             }
5699         }
5700       else /* r == p->right */
5701         {
5702           if (p->balance == 0)
5703             /* Growth propagation from right side.  */
5704             p->balance++;
5705           else if (p->balance > 0)
5706             {
5707               if (r->balance > 0)
5708                 {
5709                   /* R rotation.  */
5710                   p->right = r->left;
5711                   if (p->right)
5712                     p->right->parent = p;
5713                   r->left = p;
5714
5715                   p->balance = 0;
5716                   r->balance = 0;
5717
5718                   s = p->parent;
5719                   p->parent = r;
5720                   r->parent = s;
5721                   if (s)
5722                     {
5723                       if (s->left == p)
5724                         s->left = r;
5725                       else
5726                         s->right = r;
5727                     }
5728                   else
5729                     constructor_pending_elts = r;
5730                 }
5731               else /* r->balance == -1 */
5732                 {
5733                   /* RL rotation */
5734                   struct init_node *t = r->left;
5735
5736                   r->left = t->right;
5737                   if (r->left)
5738                     r->left->parent = r;
5739                   t->right = r;
5740
5741                   p->right = t->left;
5742                   if (p->right)
5743                     p->right->parent = p;
5744                   t->left = p;
5745
5746                   r->balance = (t->balance < 0);
5747                   p->balance = -(t->balance > 0);
5748                   t->balance = 0;
5749
5750                   s = p->parent;
5751                   p->parent = t;
5752                   r->parent = t;
5753                   t->parent = s;
5754                   if (s)
5755                     {
5756                       if (s->left == p)
5757                         s->left = t;
5758                       else
5759                         s->right = t;
5760                     }
5761                   else
5762                     constructor_pending_elts = t;
5763                 }
5764               break;
5765             }
5766           else
5767             {
5768               /* p->balance == -1; growth of right side balances the node.  */
5769               p->balance = 0;
5770               break;
5771             }
5772         }
5773
5774       r = p;
5775       p = p->parent;
5776     }
5777 }
5778
5779 /* Build AVL tree from a sorted chain.  */
5780
5781 static void
5782 set_nonincremental_init (void)
5783 {
5784   unsigned HOST_WIDE_INT ix;
5785   tree index, value;
5786
5787   if (TREE_CODE (constructor_type) != RECORD_TYPE
5788       && TREE_CODE (constructor_type) != ARRAY_TYPE)
5789     return;
5790
5791   FOR_EACH_CONSTRUCTOR_ELT (constructor_elements, ix, index, value)
5792     add_pending_init (index, value);
5793   constructor_elements = 0;
5794   if (TREE_CODE (constructor_type) == RECORD_TYPE)
5795     {
5796       constructor_unfilled_fields = TYPE_FIELDS (constructor_type);
5797       /* Skip any nameless bit fields at the beginning.  */
5798       while (constructor_unfilled_fields != 0
5799              && DECL_C_BIT_FIELD (constructor_unfilled_fields)
5800              && DECL_NAME (constructor_unfilled_fields) == 0)
5801         constructor_unfilled_fields = TREE_CHAIN (constructor_unfilled_fields);
5802
5803     }
5804   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5805     {
5806       if (TYPE_DOMAIN (constructor_type))
5807         constructor_unfilled_index
5808             = convert (bitsizetype,
5809                        TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
5810       else
5811         constructor_unfilled_index = bitsize_zero_node;
5812     }
5813   constructor_incremental = 0;
5814 }
5815
5816 /* Build AVL tree from a string constant.  */
5817
5818 static void
5819 set_nonincremental_init_from_string (tree str)
5820 {
5821   tree value, purpose, type;
5822   HOST_WIDE_INT val[2];
5823   const char *p, *end;
5824   int byte, wchar_bytes, charwidth, bitpos;
5825
5826   gcc_assert (TREE_CODE (constructor_type) == ARRAY_TYPE);
5827
5828   if (TYPE_PRECISION (TREE_TYPE (TREE_TYPE (str)))
5829       == TYPE_PRECISION (char_type_node))
5830     wchar_bytes = 1;
5831   else
5832     {
5833       gcc_assert (TYPE_PRECISION (TREE_TYPE (TREE_TYPE (str)))
5834                   == TYPE_PRECISION (wchar_type_node));
5835       wchar_bytes = TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT;
5836     }
5837   charwidth = TYPE_PRECISION (char_type_node);
5838   type = TREE_TYPE (constructor_type);
5839   p = TREE_STRING_POINTER (str);
5840   end = p + TREE_STRING_LENGTH (str);
5841
5842   for (purpose = bitsize_zero_node;
5843        p < end && !tree_int_cst_lt (constructor_max_index, purpose);
5844        purpose = size_binop (PLUS_EXPR, purpose, bitsize_one_node))
5845     {
5846       if (wchar_bytes == 1)
5847         {
5848           val[1] = (unsigned char) *p++;
5849           val[0] = 0;
5850         }
5851       else
5852         {
5853           val[0] = 0;
5854           val[1] = 0;
5855           for (byte = 0; byte < wchar_bytes; byte++)
5856             {
5857               if (BYTES_BIG_ENDIAN)
5858                 bitpos = (wchar_bytes - byte - 1) * charwidth;
5859               else
5860                 bitpos = byte * charwidth;
5861               val[bitpos < HOST_BITS_PER_WIDE_INT]
5862                 |= ((unsigned HOST_WIDE_INT) ((unsigned char) *p++))
5863                    << (bitpos % HOST_BITS_PER_WIDE_INT);
5864             }
5865         }
5866
5867       if (!TYPE_UNSIGNED (type))
5868         {
5869           bitpos = ((wchar_bytes - 1) * charwidth) + HOST_BITS_PER_CHAR;
5870           if (bitpos < HOST_BITS_PER_WIDE_INT)
5871             {
5872               if (val[1] & (((HOST_WIDE_INT) 1) << (bitpos - 1)))
5873                 {
5874                   val[1] |= ((HOST_WIDE_INT) -1) << bitpos;
5875                   val[0] = -1;
5876                 }
5877             }
5878           else if (bitpos == HOST_BITS_PER_WIDE_INT)
5879             {
5880               if (val[1] < 0)
5881                 val[0] = -1;
5882             }
5883           else if (val[0] & (((HOST_WIDE_INT) 1)
5884                              << (bitpos - 1 - HOST_BITS_PER_WIDE_INT)))
5885             val[0] |= ((HOST_WIDE_INT) -1)
5886                       << (bitpos - HOST_BITS_PER_WIDE_INT);
5887         }
5888
5889       value = build_int_cst_wide (type, val[1], val[0]);
5890       add_pending_init (purpose, value);
5891     }
5892
5893   constructor_incremental = 0;
5894 }
5895
5896 /* Return value of FIELD in pending initializer or zero if the field was
5897    not initialized yet.  */
5898
5899 static tree
5900 find_init_member (tree field)
5901 {
5902   struct init_node *p;
5903
5904   if (TREE_CODE (constructor_type) == ARRAY_TYPE)
5905     {
5906       if (constructor_incremental
5907           && tree_int_cst_lt (field, constructor_unfilled_index))
5908         set_nonincremental_init ();
5909
5910       p = constructor_pending_elts;
5911       while (p)
5912         {
5913           if (tree_int_cst_lt (field, p->purpose))
5914             p = p->left;
5915           else if (tree_int_cst_lt (p->purpose, field))
5916             p = p->right;
5917           else
5918             return p->value;
5919         }
5920     }
5921   else if (TREE_CODE (constructor_type) == RECORD_TYPE)
5922     {
5923       tree bitpos = bit_position (field);
5924
5925       if (constructor_incremental
5926           && (!constructor_unfilled_fields
5927               || tree_int_cst_lt (bitpos,
5928                                   bit_position (constructor_unfilled_fields))))
5929         set_nonincremental_init ();
5930
5931       p = constructor_pending_elts;
5932       while (p)
5933         {
5934           if (field == p->purpose)
5935             return p->value;
5936           else if (tree_int_cst_lt (bitpos, bit_position (p->purpose)))
5937             p = p->left;
5938           else
5939             p = p->right;
5940         }
5941     }
5942   else if (TREE_CODE (constructor_type) == UNION_TYPE)
5943     {
5944       if (!VEC_empty (constructor_elt, constructor_elements)
5945           && (VEC_last (constructor_elt, constructor_elements)->index
5946               == field))
5947         return VEC_last (constructor_elt, constructor_elements)->value;
5948     }
5949   return 0;
5950 }
5951
5952 /* "Output" the next constructor element.
5953    At top level, really output it to assembler code now.
5954    Otherwise, collect it in a list from which we will make a CONSTRUCTOR.
5955    TYPE is the data type that the containing data type wants here.
5956    FIELD is the field (a FIELD_DECL) or the index that this element fills.
5957    If VALUE is a string constant, STRICT_STRING is true if it is
5958    unparenthesized or we should not warn here for it being parenthesized.
5959    For other types of VALUE, STRICT_STRING is not used.
5960
5961    PENDING if non-nil means output pending elements that belong
5962    right after this element.  (PENDING is normally 1;
5963    it is 0 while outputting pending elements, to avoid recursion.)  */
5964
5965 static void
5966 output_init_element (tree value, bool strict_string, tree type, tree field,
5967                      int pending)
5968 {
5969   constructor_elt *celt;
5970
5971   if (type == error_mark_node || value == error_mark_node)
5972     {
5973       constructor_erroneous = 1;
5974       return;
5975     }
5976   if (TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
5977       && (TREE_CODE (value) == STRING_CST
5978           || TREE_CODE (value) == COMPOUND_LITERAL_EXPR)
5979       && !(TREE_CODE (value) == STRING_CST
5980            && TREE_CODE (type) == ARRAY_TYPE
5981            && INTEGRAL_TYPE_P (TREE_TYPE (type)))
5982       && !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (value)),
5983                      TYPE_MAIN_VARIANT (type)))
5984     value = array_to_pointer_conversion (value);
5985
5986   if (TREE_CODE (value) == COMPOUND_LITERAL_EXPR
5987       && require_constant_value && !flag_isoc99 && pending)
5988     {
5989       /* As an extension, allow initializing objects with static storage
5990          duration with compound literals (which are then treated just as
5991          the brace enclosed list they contain).  */
5992       tree decl = COMPOUND_LITERAL_EXPR_DECL (value);
5993       value = DECL_INITIAL (decl);
5994     }
5995
5996   if (value == error_mark_node)
5997     constructor_erroneous = 1;
5998   else if (!TREE_CONSTANT (value))
5999     constructor_constant = 0;
6000   else if (!initializer_constant_valid_p (value, TREE_TYPE (value))
6001            || ((TREE_CODE (constructor_type) == RECORD_TYPE
6002                 || TREE_CODE (constructor_type) == UNION_TYPE)
6003                && DECL_C_BIT_FIELD (field)
6004                && TREE_CODE (value) != INTEGER_CST))
6005     constructor_simple = 0;
6006
6007   if (!initializer_constant_valid_p (value, TREE_TYPE (value)))
6008     {
6009       if (require_constant_value)
6010         {
6011           error_init ("initializer element is not constant");
6012           value = error_mark_node;
6013         }
6014       else if (require_constant_elements)
6015         pedwarn ("initializer element is not computable at load time");
6016     }
6017
6018   /* If this field is empty (and not at the end of structure),
6019      don't do anything other than checking the initializer.  */
6020   if (field
6021       && (TREE_TYPE (field) == error_mark_node
6022           || (COMPLETE_TYPE_P (TREE_TYPE (field))
6023               && integer_zerop (TYPE_SIZE (TREE_TYPE (field)))
6024               && (TREE_CODE (constructor_type) == ARRAY_TYPE
6025                   || TREE_CHAIN (field)))))
6026     return;
6027
6028   value = digest_init (type, value, strict_string, require_constant_value);
6029   if (value == error_mark_node)
6030     {
6031       constructor_erroneous = 1;
6032       return;
6033     }
6034
6035   /* If this element doesn't come next in sequence,
6036      put it on constructor_pending_elts.  */
6037   if (TREE_CODE (constructor_type) == ARRAY_TYPE
6038       && (!constructor_incremental
6039           || !tree_int_cst_equal (field, constructor_unfilled_index)))
6040     {
6041       if (constructor_incremental
6042           && tree_int_cst_lt (field, constructor_unfilled_index))
6043         set_nonincremental_init ();
6044
6045       add_pending_init (field, value);
6046       return;
6047     }
6048   else if (TREE_CODE (constructor_type) == RECORD_TYPE
6049            && (!constructor_incremental
6050                || field != constructor_unfilled_fields))
6051     {
6052       /* We do this for records but not for unions.  In a union,
6053          no matter which field is specified, it can be initialized
6054          right away since it starts at the beginning of the union.  */
6055       if (constructor_incremental)
6056         {
6057           if (!constructor_unfilled_fields)
6058             set_nonincremental_init ();
6059           else
6060             {
6061               tree bitpos, unfillpos;
6062
6063               bitpos = bit_position (field);
6064               unfillpos = bit_position (constructor_unfilled_fields);
6065
6066               if (tree_int_cst_lt (bitpos, unfillpos))
6067                 set_nonincremental_init ();
6068             }
6069         }
6070
6071       add_pending_init (field, value);
6072       return;
6073     }
6074   else if (TREE_CODE (constructor_type) == UNION_TYPE
6075            && !VEC_empty (constructor_elt, constructor_elements))
6076     {
6077       if (TREE_SIDE_EFFECTS (VEC_last (constructor_elt,
6078                                        constructor_elements)->value))
6079         warning_init ("initialized field with side-effects overwritten");
6080
6081       /* We can have just one union field set.  */
6082       constructor_elements = 0;
6083     }
6084
6085   /* Otherwise, output this element either to
6086      constructor_elements or to the assembler file.  */
6087
6088   celt = VEC_safe_push (constructor_elt, gc, constructor_elements, NULL);
6089   celt->index = field;
6090   celt->value = value;
6091
6092   /* Advance the variable that indicates sequential elements output.  */
6093   if (TREE_CODE (constructor_type) == ARRAY_TYPE)
6094     constructor_unfilled_index
6095       = size_binop (PLUS_EXPR, constructor_unfilled_index,
6096                     bitsize_one_node);
6097   else if (TREE_CODE (constructor_type) == RECORD_TYPE)
6098     {
6099       constructor_unfilled_fields
6100         = TREE_CHAIN (constructor_unfilled_fields);
6101
6102       /* Skip any nameless bit fields.  */
6103       while (constructor_unfilled_fields != 0
6104              && DECL_C_BIT_FIELD (constructor_unfilled_fields)
6105              && DECL_NAME (constructor_unfilled_fields) == 0)
6106         constructor_unfilled_fields =
6107           TREE_CHAIN (constructor_unfilled_fields);
6108     }
6109   else if (TREE_CODE (constructor_type) == UNION_TYPE)
6110     constructor_unfilled_fields = 0;
6111
6112   /* Now output any pending elements which have become next.  */
6113   if (pending)
6114     output_pending_init_elements (0);
6115 }
6116
6117 /* Output any pending elements which have become next.
6118    As we output elements, constructor_unfilled_{fields,index}
6119    advances, which may cause other elements to become next;
6120    if so, they too are output.
6121
6122    If ALL is 0, we return when there are
6123    no more pending elements to output now.
6124
6125    If ALL is 1, we output space as necessary so that
6126    we can output all the pending elements.  */
6127
6128 static void
6129 output_pending_init_elements (int all)
6130 {
6131   struct init_node *elt = constructor_pending_elts;
6132   tree next;
6133
6134  retry:
6135
6136   /* Look through the whole pending tree.
6137      If we find an element that should be output now,
6138      output it.  Otherwise, set NEXT to the element
6139      that comes first among those still pending.  */
6140
6141   next = 0;
6142   while (elt)
6143     {
6144       if (TREE_CODE (constructor_type) == ARRAY_TYPE)
6145         {
6146           if (tree_int_cst_equal (elt->purpose,
6147                                   constructor_unfilled_index))
6148             output_init_element (elt->value, true,
6149                                  TREE_TYPE (constructor_type),
6150                                  constructor_unfilled_index, 0);
6151           else if (tree_int_cst_lt (constructor_unfilled_index,
6152                                     elt->purpose))
6153             {
6154               /* Advance to the next smaller node.  */
6155               if (elt->left)
6156                 elt = elt->left;
6157               else
6158                 {
6159                   /* We have reached the smallest node bigger than the
6160                      current unfilled index.  Fill the space first.  */
6161                   next = elt->purpose;
6162                   break;
6163                 }
6164             }
6165           else
6166             {
6167               /* Advance to the next bigger node.  */
6168               if (elt->right)
6169                 elt = elt->right;
6170               else
6171                 {
6172                   /* We have reached the biggest node in a subtree.  Find
6173                      the parent of it, which is the next bigger node.  */
6174                   while (elt->parent && elt->parent->right == elt)
6175                     elt = elt->parent;
6176                   elt = elt->parent;
6177                   if (elt && tree_int_cst_lt (constructor_unfilled_index,
6178                                               elt->purpose))
6179                     {
6180                       next = elt->purpose;
6181                       break;
6182                     }
6183                 }
6184             }
6185         }
6186       else if (TREE_CODE (constructor_type) == RECORD_TYPE
6187                || TREE_CODE (constructor_type) == UNION_TYPE)
6188         {
6189           tree ctor_unfilled_bitpos, elt_bitpos;
6190
6191           /* If the current record is complete we are done.  */
6192           if (constructor_unfilled_fields == 0)
6193             break;
6194
6195           ctor_unfilled_bitpos = bit_position (constructor_unfilled_fields);
6196           elt_bitpos = bit_position (elt->purpose);
6197           /* We can't compare fields here because there might be empty
6198              fields in between.  */
6199           if (tree_int_cst_equal (elt_bitpos, ctor_unfilled_bitpos))
6200             {
6201               constructor_unfilled_fields = elt->purpose;
6202               output_init_element (elt->value, true, TREE_TYPE (elt->purpose),
6203                                    elt->purpose, 0);
6204             }
6205           else if (tree_int_cst_lt (ctor_unfilled_bitpos, elt_bitpos))
6206             {
6207               /* Advance to the next smaller node.  */
6208               if (elt->left)
6209                 elt = elt->left;
6210               else
6211                 {
6212                   /* We have reached the smallest node bigger than the
6213                      current unfilled field.  Fill the space first.  */
6214                   next = elt->purpose;
6215                   break;
6216                 }
6217             }
6218           else
6219             {
6220               /* Advance to the next bigger node.  */
6221               if (elt->right)
6222                 elt = elt->right;
6223               else
6224                 {
6225                   /* We have reached the biggest node in a subtree.  Find
6226                      the parent of it, which is the next bigger node.  */
6227                   while (elt->parent && elt->parent->right == elt)
6228                     elt = elt->parent;
6229                   elt = elt->parent;
6230                   if (elt
6231                       && (tree_int_cst_lt (ctor_unfilled_bitpos,
6232                                            bit_position (elt->purpose))))
6233                     {
6234                       next = elt->purpose;
6235                       break;
6236                     }
6237                 }
6238             }
6239         }
6240     }
6241
6242   /* Ordinarily return, but not if we want to output all
6243      and there are elements left.  */
6244   if (!(all && next != 0))
6245     return;
6246
6247   /* If it's not incremental, just skip over the gap, so that after
6248      jumping to retry we will output the next successive element.  */
6249   if (TREE_CODE (constructor_type) == RECORD_TYPE
6250       || TREE_CODE (constructor_type) == UNION_TYPE)
6251     constructor_unfilled_fields = next;
6252   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
6253     constructor_unfilled_index = next;
6254
6255   /* ELT now points to the node in the pending tree with the next
6256      initializer to output.  */
6257   goto retry;
6258 }
6259 \f
6260 /* Add one non-braced element to the current constructor level.
6261    This adjusts the current position within the constructor's type.
6262    This may also start or terminate implicit levels
6263    to handle a partly-braced initializer.
6264
6265    Once this has found the correct level for the new element,
6266    it calls output_init_element.  */
6267
6268 void
6269 process_init_element (struct c_expr value)
6270 {
6271   tree orig_value = value.value;
6272   int string_flag = orig_value != 0 && TREE_CODE (orig_value) == STRING_CST;
6273   bool strict_string = value.original_code == STRING_CST;
6274
6275   designator_depth = 0;
6276   designator_erroneous = 0;
6277
6278   /* Handle superfluous braces around string cst as in
6279      char x[] = {"foo"}; */
6280   if (string_flag
6281       && constructor_type
6282       && TREE_CODE (constructor_type) == ARRAY_TYPE
6283       && INTEGRAL_TYPE_P (TREE_TYPE (constructor_type))
6284       && integer_zerop (constructor_unfilled_index))
6285     {
6286       if (constructor_stack->replacement_value.value)
6287         error_init ("excess elements in char array initializer");
6288       constructor_stack->replacement_value = value;
6289       return;
6290     }
6291
6292   if (constructor_stack->replacement_value.value != 0)
6293     {
6294       error_init ("excess elements in struct initializer");
6295       return;
6296     }
6297
6298   /* Ignore elements of a brace group if it is entirely superfluous
6299      and has already been diagnosed.  */
6300   if (constructor_type == 0)
6301     return;
6302
6303   /* If we've exhausted any levels that didn't have braces,
6304      pop them now.  */
6305   while (constructor_stack->implicit)
6306     {
6307       if ((TREE_CODE (constructor_type) == RECORD_TYPE
6308            || TREE_CODE (constructor_type) == UNION_TYPE)
6309           && constructor_fields == 0)
6310         process_init_element (pop_init_level (1));
6311       else if (TREE_CODE (constructor_type) == ARRAY_TYPE
6312                && (constructor_max_index == 0
6313                    || tree_int_cst_lt (constructor_max_index,
6314                                        constructor_index)))
6315         process_init_element (pop_init_level (1));
6316       else
6317         break;
6318     }
6319
6320   /* In the case of [LO ... HI] = VALUE, only evaluate VALUE once.  */
6321   if (constructor_range_stack)
6322     {
6323       /* If value is a compound literal and we'll be just using its
6324          content, don't put it into a SAVE_EXPR.  */
6325       if (TREE_CODE (value.value) != COMPOUND_LITERAL_EXPR
6326           || !require_constant_value
6327           || flag_isoc99)
6328         value.value = save_expr (value.value);
6329     }
6330
6331   while (1)
6332     {
6333       if (TREE_CODE (constructor_type) == RECORD_TYPE)
6334         {
6335           tree fieldtype;
6336           enum tree_code fieldcode;
6337
6338           if (constructor_fields == 0)
6339             {
6340               pedwarn_init ("excess elements in struct initializer");
6341               break;
6342             }
6343
6344           fieldtype = TREE_TYPE (constructor_fields);
6345           if (fieldtype != error_mark_node)
6346             fieldtype = TYPE_MAIN_VARIANT (fieldtype);
6347           fieldcode = TREE_CODE (fieldtype);
6348
6349           /* Error for non-static initialization of a flexible array member.  */
6350           if (fieldcode == ARRAY_TYPE
6351               && !require_constant_value
6352               && TYPE_SIZE (fieldtype) == NULL_TREE
6353               && TREE_CHAIN (constructor_fields) == NULL_TREE)
6354             {
6355               error_init ("non-static initialization of a flexible array member");
6356               break;
6357             }
6358
6359           /* Accept a string constant to initialize a subarray.  */
6360           if (value.value != 0
6361               && fieldcode == ARRAY_TYPE
6362               && INTEGRAL_TYPE_P (TREE_TYPE (fieldtype))
6363               && string_flag)
6364             value.value = orig_value;
6365           /* Otherwise, if we have come to a subaggregate,
6366              and we don't have an element of its type, push into it.  */
6367           else if (value.value != 0
6368                    && value.value != error_mark_node
6369                    && TYPE_MAIN_VARIANT (TREE_TYPE (value.value)) != fieldtype
6370                    && (fieldcode == RECORD_TYPE || fieldcode == ARRAY_TYPE
6371                        || fieldcode == UNION_TYPE))
6372             {
6373               push_init_level (1);
6374               continue;
6375             }
6376
6377           if (value.value)
6378             {
6379               push_member_name (constructor_fields);
6380               output_init_element (value.value, strict_string,
6381                                    fieldtype, constructor_fields, 1);
6382               RESTORE_SPELLING_DEPTH (constructor_depth);
6383             }
6384           else
6385             /* Do the bookkeeping for an element that was
6386                directly output as a constructor.  */
6387             {
6388               /* For a record, keep track of end position of last field.  */
6389               if (DECL_SIZE (constructor_fields))
6390                 constructor_bit_index
6391                   = size_binop (PLUS_EXPR,
6392                                 bit_position (constructor_fields),
6393                                 DECL_SIZE (constructor_fields));
6394
6395               /* If the current field was the first one not yet written out,
6396                  it isn't now, so update.  */
6397               if (constructor_unfilled_fields == constructor_fields)
6398                 {
6399                   constructor_unfilled_fields = TREE_CHAIN (constructor_fields);
6400                   /* Skip any nameless bit fields.  */
6401                   while (constructor_unfilled_fields != 0
6402                          && DECL_C_BIT_FIELD (constructor_unfilled_fields)
6403                          && DECL_NAME (constructor_unfilled_fields) == 0)
6404                     constructor_unfilled_fields =
6405                       TREE_CHAIN (constructor_unfilled_fields);
6406                 }
6407             }
6408
6409           constructor_fields = TREE_CHAIN (constructor_fields);
6410           /* Skip any nameless bit fields at the beginning.  */
6411           while (constructor_fields != 0
6412                  && DECL_C_BIT_FIELD (constructor_fields)
6413                  && DECL_NAME (constructor_fields) == 0)
6414             constructor_fields = TREE_CHAIN (constructor_fields);
6415         }
6416       else if (TREE_CODE (constructor_type) == UNION_TYPE)
6417         {
6418           tree fieldtype;
6419           enum tree_code fieldcode;
6420
6421           if (constructor_fields == 0)
6422             {
6423               pedwarn_init ("excess elements in union initializer");
6424               break;
6425             }
6426
6427           fieldtype = TREE_TYPE (constructor_fields);
6428           if (fieldtype != error_mark_node)
6429             fieldtype = TYPE_MAIN_VARIANT (fieldtype);
6430           fieldcode = TREE_CODE (fieldtype);
6431
6432           /* Warn that traditional C rejects initialization of unions.
6433              We skip the warning if the value is zero.  This is done
6434              under the assumption that the zero initializer in user
6435              code appears conditioned on e.g. __STDC__ to avoid
6436              "missing initializer" warnings and relies on default
6437              initialization to zero in the traditional C case.
6438              We also skip the warning if the initializer is designated,
6439              again on the assumption that this must be conditional on
6440              __STDC__ anyway (and we've already complained about the
6441              member-designator already).  */
6442           if (!in_system_header && !constructor_designated
6443               && !(value.value && (integer_zerop (value.value)
6444                                    || real_zerop (value.value))))
6445             warning (OPT_Wtraditional, "traditional C rejects initialization "
6446                      "of unions");
6447
6448           /* Accept a string constant to initialize a subarray.  */
6449           if (value.value != 0
6450               && fieldcode == ARRAY_TYPE
6451               && INTEGRAL_TYPE_P (TREE_TYPE (fieldtype))
6452               && string_flag)
6453             value.value = orig_value;
6454           /* Otherwise, if we have come to a subaggregate,
6455              and we don't have an element of its type, push into it.  */
6456           else if (value.value != 0
6457                    && value.value != error_mark_node
6458                    && TYPE_MAIN_VARIANT (TREE_TYPE (value.value)) != fieldtype
6459                    && (fieldcode == RECORD_TYPE || fieldcode == ARRAY_TYPE
6460                        || fieldcode == UNION_TYPE))
6461             {
6462               push_init_level (1);
6463               continue;
6464             }
6465
6466           if (value.value)
6467             {
6468               push_member_name (constructor_fields);
6469               output_init_element (value.value, strict_string,
6470                                    fieldtype, constructor_fields, 1);
6471               RESTORE_SPELLING_DEPTH (constructor_depth);
6472             }
6473           else
6474             /* Do the bookkeeping for an element that was
6475                directly output as a constructor.  */
6476             {
6477               constructor_bit_index = DECL_SIZE (constructor_fields);
6478               constructor_unfilled_fields = TREE_CHAIN (constructor_fields);
6479             }
6480
6481           constructor_fields = 0;
6482         }
6483       else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
6484         {
6485           tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
6486           enum tree_code eltcode = TREE_CODE (elttype);
6487
6488           /* Accept a string constant to initialize a subarray.  */
6489           if (value.value != 0
6490               && eltcode == ARRAY_TYPE
6491               && INTEGRAL_TYPE_P (TREE_TYPE (elttype))
6492               && string_flag)
6493             value.value = orig_value;
6494           /* Otherwise, if we have come to a subaggregate,
6495              and we don't have an element of its type, push into it.  */
6496           else if (value.value != 0
6497                    && value.value != error_mark_node
6498                    && TYPE_MAIN_VARIANT (TREE_TYPE (value.value)) != elttype
6499                    && (eltcode == RECORD_TYPE || eltcode == ARRAY_TYPE
6500                        || eltcode == UNION_TYPE))
6501             {
6502               push_init_level (1);
6503               continue;
6504             }
6505
6506           if (constructor_max_index != 0
6507               && (tree_int_cst_lt (constructor_max_index, constructor_index)
6508                   || integer_all_onesp (constructor_max_index)))
6509             {
6510               pedwarn_init ("excess elements in array initializer");
6511               break;
6512             }
6513
6514           /* Now output the actual element.  */
6515           if (value.value)
6516             {
6517               push_array_bounds (tree_low_cst (constructor_index, 1));
6518               output_init_element (value.value, strict_string,
6519                                    elttype, constructor_index, 1);
6520               RESTORE_SPELLING_DEPTH (constructor_depth);
6521             }
6522
6523           constructor_index
6524             = size_binop (PLUS_EXPR, constructor_index, bitsize_one_node);
6525
6526           if (!value.value)
6527             /* If we are doing the bookkeeping for an element that was
6528                directly output as a constructor, we must update
6529                constructor_unfilled_index.  */
6530             constructor_unfilled_index = constructor_index;
6531         }
6532       else if (TREE_CODE (constructor_type) == VECTOR_TYPE)
6533         {
6534           tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
6535
6536          /* Do a basic check of initializer size.  Note that vectors
6537             always have a fixed size derived from their type.  */
6538           if (tree_int_cst_lt (constructor_max_index, constructor_index))
6539             {
6540               pedwarn_init ("excess elements in vector initializer");
6541               break;
6542             }
6543
6544           /* Now output the actual element.  */
6545           if (value.value)
6546             output_init_element (value.value, strict_string,
6547                                  elttype, constructor_index, 1);
6548
6549           constructor_index
6550             = size_binop (PLUS_EXPR, constructor_index, bitsize_one_node);
6551
6552           if (!value.value)
6553             /* If we are doing the bookkeeping for an element that was
6554                directly output as a constructor, we must update
6555                constructor_unfilled_index.  */
6556             constructor_unfilled_index = constructor_index;
6557         }
6558
6559       /* Handle the sole element allowed in a braced initializer
6560          for a scalar variable.  */
6561       else if (constructor_type != error_mark_node
6562                && constructor_fields == 0)
6563         {
6564           pedwarn_init ("excess elements in scalar initializer");
6565           break;
6566         }
6567       else
6568         {
6569           if (value.value)
6570             output_init_element (value.value, strict_string,
6571                                  constructor_type, NULL_TREE, 1);
6572           constructor_fields = 0;
6573         }
6574
6575       /* Handle range initializers either at this level or anywhere higher
6576          in the designator stack.  */
6577       if (constructor_range_stack)
6578         {
6579           struct constructor_range_stack *p, *range_stack;
6580           int finish = 0;
6581
6582           range_stack = constructor_range_stack;
6583           constructor_range_stack = 0;
6584           while (constructor_stack != range_stack->stack)
6585             {
6586               gcc_assert (constructor_stack->implicit);
6587               process_init_element (pop_init_level (1));
6588             }
6589           for (p = range_stack;
6590                !p->range_end || tree_int_cst_equal (p->index, p->range_end);
6591                p = p->prev)
6592             {
6593               gcc_assert (constructor_stack->implicit);
6594               process_init_element (pop_init_level (1));
6595             }
6596
6597           p->index = size_binop (PLUS_EXPR, p->index, bitsize_one_node);
6598           if (tree_int_cst_equal (p->index, p->range_end) && !p->prev)
6599             finish = 1;
6600
6601           while (1)
6602             {
6603               constructor_index = p->index;
6604               constructor_fields = p->fields;
6605               if (finish && p->range_end && p->index == p->range_start)
6606                 {
6607                   finish = 0;
6608                   p->prev = 0;
6609                 }
6610               p = p->next;
6611               if (!p)
6612                 break;
6613               push_init_level (2);
6614               p->stack = constructor_stack;
6615               if (p->range_end && tree_int_cst_equal (p->index, p->range_end))
6616                 p->index = p->range_start;
6617             }
6618
6619           if (!finish)
6620             constructor_range_stack = range_stack;
6621           continue;
6622         }
6623
6624       break;
6625     }
6626
6627   constructor_range_stack = 0;
6628 }
6629 \f
6630 /* Build a complete asm-statement, whose components are a CV_QUALIFIER
6631    (guaranteed to be 'volatile' or null) and ARGS (represented using
6632    an ASM_EXPR node).  */
6633 tree
6634 build_asm_stmt (tree cv_qualifier, tree args)
6635 {
6636   if (!ASM_VOLATILE_P (args) && cv_qualifier)
6637     ASM_VOLATILE_P (args) = 1;
6638   return add_stmt (args);
6639 }
6640
6641 /* Build an asm-expr, whose components are a STRING, some OUTPUTS,
6642    some INPUTS, and some CLOBBERS.  The latter three may be NULL.
6643    SIMPLE indicates whether there was anything at all after the
6644    string in the asm expression -- asm("blah") and asm("blah" : )
6645    are subtly different.  We use a ASM_EXPR node to represent this.  */
6646 tree
6647 build_asm_expr (tree string, tree outputs, tree inputs, tree clobbers,
6648                 bool simple)
6649 {
6650   tree tail;
6651   tree args;
6652   int i;
6653   const char *constraint;
6654   const char **oconstraints;
6655   bool allows_mem, allows_reg, is_inout;
6656   int ninputs, noutputs;
6657
6658   ninputs = list_length (inputs);
6659   noutputs = list_length (outputs);
6660   oconstraints = (const char **) alloca (noutputs * sizeof (const char *));
6661
6662   string = resolve_asm_operand_names (string, outputs, inputs);
6663
6664   /* Remove output conversions that change the type but not the mode.  */
6665   for (i = 0, tail = outputs; tail; ++i, tail = TREE_CHAIN (tail))
6666     {
6667       tree output = TREE_VALUE (tail);
6668
6669       /* ??? Really, this should not be here.  Users should be using a
6670          proper lvalue, dammit.  But there's a long history of using casts
6671          in the output operands.  In cases like longlong.h, this becomes a
6672          primitive form of typechecking -- if the cast can be removed, then
6673          the output operand had a type of the proper width; otherwise we'll
6674          get an error.  Gross, but ...  */
6675       STRIP_NOPS (output);
6676
6677       if (!lvalue_or_else (output, lv_asm))
6678         output = error_mark_node;
6679
6680       if (output != error_mark_node
6681           && (TREE_READONLY (output)
6682               || TYPE_READONLY (TREE_TYPE (output))
6683               || ((TREE_CODE (TREE_TYPE (output)) == RECORD_TYPE
6684                    || TREE_CODE (TREE_TYPE (output)) == UNION_TYPE)
6685                   && C_TYPE_FIELDS_READONLY (TREE_TYPE (output)))))
6686         readonly_error (output, lv_asm);
6687
6688       constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail)));
6689       oconstraints[i] = constraint;
6690
6691       if (parse_output_constraint (&constraint, i, ninputs, noutputs,
6692                                    &allows_mem, &allows_reg, &is_inout))
6693         {
6694           /* If the operand is going to end up in memory,
6695              mark it addressable.  */
6696           if (!allows_reg && !c_mark_addressable (output))
6697             output = error_mark_node;
6698         }
6699       else
6700         output = error_mark_node;
6701
6702       TREE_VALUE (tail) = output;
6703     }
6704
6705   for (i = 0, tail = inputs; tail; ++i, tail = TREE_CHAIN (tail))
6706     {
6707       tree input;
6708
6709       constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail)));
6710       input = TREE_VALUE (tail);
6711
6712       if (parse_input_constraint (&constraint, i, ninputs, noutputs, 0,
6713                                   oconstraints, &allows_mem, &allows_reg))
6714         {
6715           /* If the operand is going to end up in memory,
6716              mark it addressable.  */
6717           if (!allows_reg && allows_mem)
6718             {
6719               /* Strip the nops as we allow this case.  FIXME, this really
6720                  should be rejected or made deprecated.  */
6721               STRIP_NOPS (input);
6722               if (!c_mark_addressable (input))
6723                 input = error_mark_node;
6724           }
6725         }
6726       else
6727         input = error_mark_node;
6728
6729       TREE_VALUE (tail) = input;
6730     }
6731
6732   args = build_stmt (ASM_EXPR, string, outputs, inputs, clobbers);
6733
6734   /* asm statements without outputs, including simple ones, are treated
6735      as volatile.  */
6736   ASM_INPUT_P (args) = simple;
6737   ASM_VOLATILE_P (args) = (noutputs == 0);
6738
6739   return args;
6740 }
6741 \f
6742 /* Generate a goto statement to LABEL.  */
6743
6744 tree
6745 c_finish_goto_label (tree label)
6746 {
6747   tree decl = lookup_label (label);
6748   if (!decl)
6749     return NULL_TREE;
6750
6751   if (C_DECL_UNJUMPABLE_STMT_EXPR (decl))
6752     {
6753       error ("jump into statement expression");
6754       return NULL_TREE;
6755     }
6756
6757   if (C_DECL_UNJUMPABLE_VM (decl))
6758     {
6759       error ("jump into scope of identifier with variably modified type");
6760       return NULL_TREE;
6761     }
6762
6763   if (!C_DECL_UNDEFINABLE_STMT_EXPR (decl))
6764     {
6765       /* No jump from outside this statement expression context, so
6766          record that there is a jump from within this context.  */
6767       struct c_label_list *nlist;
6768       nlist = XOBNEW (&parser_obstack, struct c_label_list);
6769       nlist->next = label_context_stack_se->labels_used;
6770       nlist->label = decl;
6771       label_context_stack_se->labels_used = nlist;
6772     }
6773
6774   if (!C_DECL_UNDEFINABLE_VM (decl))
6775     {
6776       /* No jump from outside this context context of identifiers with
6777          variably modified type, so record that there is a jump from
6778          within this context.  */
6779       struct c_label_list *nlist;
6780       nlist = XOBNEW (&parser_obstack, struct c_label_list);
6781       nlist->next = label_context_stack_vm->labels_used;
6782       nlist->label = decl;
6783       label_context_stack_vm->labels_used = nlist;
6784     }
6785
6786   TREE_USED (decl) = 1;
6787   return add_stmt (build1 (GOTO_EXPR, void_type_node, decl));
6788 }
6789
6790 /* Generate a computed goto statement to EXPR.  */
6791
6792 tree
6793 c_finish_goto_ptr (tree expr)
6794 {
6795   if (pedantic)
6796     pedwarn ("ISO C forbids %<goto *expr;%>");
6797   expr = convert (ptr_type_node, expr);
6798   return add_stmt (build1 (GOTO_EXPR, void_type_node, expr));
6799 }
6800
6801 /* Generate a C `return' statement.  RETVAL is the expression for what
6802    to return, or a null pointer for `return;' with no value.  */
6803
6804 tree
6805 c_finish_return (tree retval)
6806 {
6807   tree valtype = TREE_TYPE (TREE_TYPE (current_function_decl)), ret_stmt;
6808   bool no_warning = false;
6809
6810   if (TREE_THIS_VOLATILE (current_function_decl))
6811     warning (0, "function declared %<noreturn%> has a %<return%> statement");
6812
6813   if (!retval)
6814     {
6815       current_function_returns_null = 1;
6816       if ((warn_return_type || flag_isoc99)
6817           && valtype != 0 && TREE_CODE (valtype) != VOID_TYPE)
6818         {
6819           pedwarn_c99 ("%<return%> with no value, in "
6820                        "function returning non-void");
6821           no_warning = true;
6822         }
6823     }
6824   else if (valtype == 0 || TREE_CODE (valtype) == VOID_TYPE)
6825     {
6826       current_function_returns_null = 1;
6827       if (pedantic || TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
6828         pedwarn ("%<return%> with a value, in function returning void");
6829     }
6830   else
6831     {
6832       tree t = convert_for_assignment (valtype, retval, ic_return,
6833                                        NULL_TREE, NULL_TREE, 0);
6834       tree res = DECL_RESULT (current_function_decl);
6835       tree inner;
6836
6837       current_function_returns_value = 1;
6838       if (t == error_mark_node)
6839         return NULL_TREE;
6840
6841       inner = t = convert (TREE_TYPE (res), t);
6842
6843       /* Strip any conversions, additions, and subtractions, and see if
6844          we are returning the address of a local variable.  Warn if so.  */
6845       while (1)
6846         {
6847           switch (TREE_CODE (inner))
6848             {
6849             case NOP_EXPR:   case NON_LVALUE_EXPR:  case CONVERT_EXPR:
6850             case PLUS_EXPR:
6851               inner = TREE_OPERAND (inner, 0);
6852               continue;
6853
6854             case MINUS_EXPR:
6855               /* If the second operand of the MINUS_EXPR has a pointer
6856                  type (or is converted from it), this may be valid, so
6857                  don't give a warning.  */
6858               {
6859                 tree op1 = TREE_OPERAND (inner, 1);
6860
6861                 while (!POINTER_TYPE_P (TREE_TYPE (op1))
6862                        && (TREE_CODE (op1) == NOP_EXPR
6863                            || TREE_CODE (op1) == NON_LVALUE_EXPR
6864                            || TREE_CODE (op1) == CONVERT_EXPR))
6865                   op1 = TREE_OPERAND (op1, 0);
6866
6867                 if (POINTER_TYPE_P (TREE_TYPE (op1)))
6868                   break;
6869
6870                 inner = TREE_OPERAND (inner, 0);
6871                 continue;
6872               }
6873
6874             case ADDR_EXPR:
6875               inner = TREE_OPERAND (inner, 0);
6876
6877               while (REFERENCE_CLASS_P (inner)
6878                      && TREE_CODE (inner) != INDIRECT_REF)
6879                 inner = TREE_OPERAND (inner, 0);
6880
6881               if (DECL_P (inner)
6882                   && !DECL_EXTERNAL (inner)
6883                   && !TREE_STATIC (inner)
6884                   && DECL_CONTEXT (inner) == current_function_decl)
6885                 warning (0, "function returns address of local variable");
6886               break;
6887
6888             default:
6889               break;
6890             }
6891
6892           break;
6893         }
6894
6895       retval = build2 (MODIFY_EXPR, TREE_TYPE (res), res, t);
6896     }
6897
6898   ret_stmt = build_stmt (RETURN_EXPR, retval);
6899   TREE_NO_WARNING (ret_stmt) |= no_warning;
6900   return add_stmt (ret_stmt);
6901 }
6902 \f
6903 struct c_switch {
6904   /* The SWITCH_EXPR being built.  */
6905   tree switch_expr;
6906
6907   /* The original type of the testing expression, i.e. before the
6908      default conversion is applied.  */
6909   tree orig_type;
6910
6911   /* A splay-tree mapping the low element of a case range to the high
6912      element, or NULL_TREE if there is no high element.  Used to
6913      determine whether or not a new case label duplicates an old case
6914      label.  We need a tree, rather than simply a hash table, because
6915      of the GNU case range extension.  */
6916   splay_tree cases;
6917
6918   /* Number of nested statement expressions within this switch
6919      statement; if nonzero, case and default labels may not
6920      appear.  */
6921   unsigned int blocked_stmt_expr;
6922
6923   /* Scope of outermost declarations of identifiers with variably
6924      modified type within this switch statement; if nonzero, case and
6925      default labels may not appear.  */
6926   unsigned int blocked_vm;
6927
6928   /* The next node on the stack.  */
6929   struct c_switch *next;
6930 };
6931
6932 /* A stack of the currently active switch statements.  The innermost
6933    switch statement is on the top of the stack.  There is no need to
6934    mark the stack for garbage collection because it is only active
6935    during the processing of the body of a function, and we never
6936    collect at that point.  */
6937
6938 struct c_switch *c_switch_stack;
6939
6940 /* Start a C switch statement, testing expression EXP.  Return the new
6941    SWITCH_EXPR.  */
6942
6943 tree
6944 c_start_case (tree exp)
6945 {
6946   enum tree_code code;
6947   tree type, orig_type = error_mark_node;
6948   struct c_switch *cs;
6949
6950   if (exp != error_mark_node)
6951     {
6952       code = TREE_CODE (TREE_TYPE (exp));
6953       orig_type = TREE_TYPE (exp);
6954
6955       if (!INTEGRAL_TYPE_P (orig_type)
6956           && code != ERROR_MARK)
6957         {
6958           error ("switch quantity not an integer");
6959           exp = integer_zero_node;
6960           orig_type = error_mark_node;
6961         }
6962       else
6963         {
6964           type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
6965
6966           if (!in_system_header
6967               && (type == long_integer_type_node
6968                   || type == long_unsigned_type_node))
6969             warning (OPT_Wtraditional, "%<long%> switch expression not "
6970                      "converted to %<int%> in ISO C");
6971
6972           exp = default_conversion (exp);
6973           type = TREE_TYPE (exp);
6974         }
6975     }
6976
6977   /* Add this new SWITCH_EXPR to the stack.  */
6978   cs = XNEW (struct c_switch);
6979   cs->switch_expr = build3 (SWITCH_EXPR, orig_type, exp, NULL_TREE, NULL_TREE);
6980   cs->orig_type = orig_type;
6981   cs->cases = splay_tree_new (case_compare, NULL, NULL);
6982   cs->blocked_stmt_expr = 0;
6983   cs->blocked_vm = 0;
6984   cs->next = c_switch_stack;
6985   c_switch_stack = cs;
6986
6987   return add_stmt (cs->switch_expr);
6988 }
6989
6990 /* Process a case label.  */
6991
6992 tree
6993 do_case (tree low_value, tree high_value)
6994 {
6995   tree label = NULL_TREE;
6996
6997   if (c_switch_stack && !c_switch_stack->blocked_stmt_expr
6998       && !c_switch_stack->blocked_vm)
6999     {
7000       label = c_add_case_label (c_switch_stack->cases,
7001                                 SWITCH_COND (c_switch_stack->switch_expr),
7002                                 c_switch_stack->orig_type,
7003                                 low_value, high_value);
7004       if (label == error_mark_node)
7005         label = NULL_TREE;
7006     }
7007   else if (c_switch_stack && c_switch_stack->blocked_stmt_expr)
7008     {
7009       if (low_value)
7010         error ("case label in statement expression not containing "
7011                "enclosing switch statement");
7012       else
7013         error ("%<default%> label in statement expression not containing "
7014                "enclosing switch statement");
7015     }
7016   else if (c_switch_stack && c_switch_stack->blocked_vm)
7017     {
7018       if (low_value)
7019         error ("case label in scope of identifier with variably modified "
7020                "type not containing enclosing switch statement");
7021       else
7022         error ("%<default%> label in scope of identifier with variably "
7023                "modified type not containing enclosing switch statement");
7024     }
7025   else if (low_value)
7026     error ("case label not within a switch statement");
7027   else
7028     error ("%<default%> label not within a switch statement");
7029
7030   return label;
7031 }
7032
7033 /* Finish the switch statement.  */
7034
7035 void
7036 c_finish_case (tree body)
7037 {
7038   struct c_switch *cs = c_switch_stack;
7039   location_t switch_location;
7040
7041   SWITCH_BODY (cs->switch_expr) = body;
7042
7043   /* We must not be within a statement expression nested in the switch
7044      at this point; we might, however, be within the scope of an
7045      identifier with variably modified type nested in the switch.  */
7046   gcc_assert (!cs->blocked_stmt_expr);
7047
7048   /* Emit warnings as needed.  */
7049   if (EXPR_HAS_LOCATION (cs->switch_expr))
7050     switch_location = EXPR_LOCATION (cs->switch_expr);
7051   else
7052     switch_location = input_location;
7053   c_do_switch_warnings (cs->cases, switch_location,
7054                         TREE_TYPE (cs->switch_expr),
7055                         SWITCH_COND (cs->switch_expr));
7056
7057   /* Pop the stack.  */
7058   c_switch_stack = cs->next;
7059   splay_tree_delete (cs->cases);
7060   XDELETE (cs);
7061 }
7062 \f
7063 /* Emit an if statement.  IF_LOCUS is the location of the 'if'.  COND,
7064    THEN_BLOCK and ELSE_BLOCK are expressions to be used; ELSE_BLOCK
7065    may be null.  NESTED_IF is true if THEN_BLOCK contains another IF
7066    statement, and was not surrounded with parenthesis.  */
7067
7068 void
7069 c_finish_if_stmt (location_t if_locus, tree cond, tree then_block,
7070                   tree else_block, bool nested_if)
7071 {
7072   tree stmt;
7073
7074   /* Diagnose an ambiguous else if if-then-else is nested inside if-then.  */
7075   if (warn_parentheses && nested_if && else_block == NULL)
7076     {
7077       tree inner_if = then_block;
7078
7079       /* We know from the grammar productions that there is an IF nested
7080          within THEN_BLOCK.  Due to labels and c99 conditional declarations,
7081          it might not be exactly THEN_BLOCK, but should be the last
7082          non-container statement within.  */
7083       while (1)
7084         switch (TREE_CODE (inner_if))
7085           {
7086           case COND_EXPR:
7087             goto found;
7088           case BIND_EXPR:
7089             inner_if = BIND_EXPR_BODY (inner_if);
7090             break;
7091           case STATEMENT_LIST:
7092             inner_if = expr_last (then_block);
7093             break;
7094           case TRY_FINALLY_EXPR:
7095           case TRY_CATCH_EXPR:
7096             inner_if = TREE_OPERAND (inner_if, 0);
7097             break;
7098           default:
7099             gcc_unreachable ();
7100           }
7101     found:
7102
7103       if (COND_EXPR_ELSE (inner_if))
7104          warning (OPT_Wparentheses,
7105                   "%Hsuggest explicit braces to avoid ambiguous %<else%>",
7106                   &if_locus);
7107     }
7108
7109   /* Diagnose ";" via the special empty statement node that we create.  */
7110   if (extra_warnings)
7111     {
7112       tree *inner_then = &then_block, *inner_else = &else_block;
7113
7114       if (TREE_CODE (*inner_then) == STATEMENT_LIST
7115           && STATEMENT_LIST_TAIL (*inner_then))
7116         inner_then = &STATEMENT_LIST_TAIL (*inner_then)->stmt;
7117       if (*inner_else && TREE_CODE (*inner_else) == STATEMENT_LIST
7118           && STATEMENT_LIST_TAIL (*inner_else))
7119         inner_else = &STATEMENT_LIST_TAIL (*inner_else)->stmt;
7120
7121       if (TREE_CODE (*inner_then) == NOP_EXPR && !TREE_TYPE (*inner_then))
7122         {
7123           if (!*inner_else)
7124             warning (0, "%Hempty body in an if-statement",
7125                      EXPR_LOCUS (*inner_then));
7126
7127           *inner_then = alloc_stmt_list ();
7128         }
7129       if (*inner_else
7130           && TREE_CODE (*inner_else) == NOP_EXPR
7131           && !TREE_TYPE (*inner_else))
7132         {
7133           warning (0, "%Hempty body in an else-statement",
7134                    EXPR_LOCUS (*inner_else));
7135
7136           *inner_else = alloc_stmt_list ();
7137         }
7138     }
7139
7140   stmt = build3 (COND_EXPR, void_type_node, cond, then_block, else_block);
7141   SET_EXPR_LOCATION (stmt, if_locus);
7142   add_stmt (stmt);
7143 }
7144
7145 /* Emit a general-purpose loop construct.  START_LOCUS is the location of
7146    the beginning of the loop.  COND is the loop condition.  COND_IS_FIRST
7147    is false for DO loops.  INCR is the FOR increment expression.  BODY is
7148    the statement controlled by the loop.  BLAB is the break label.  CLAB is
7149    the continue label.  Everything is allowed to be NULL.  */
7150
7151 void
7152 c_finish_loop (location_t start_locus, tree cond, tree incr, tree body,
7153                tree blab, tree clab, bool cond_is_first)
7154 {
7155   tree entry = NULL, exit = NULL, t;
7156
7157   /* If the condition is zero don't generate a loop construct.  */
7158   if (cond && integer_zerop (cond))
7159     {
7160       if (cond_is_first)
7161         {
7162           t = build_and_jump (&blab);
7163           SET_EXPR_LOCATION (t, start_locus);
7164           add_stmt (t);
7165         }
7166     }
7167   else
7168     {
7169       tree top = build1 (LABEL_EXPR, void_type_node, NULL_TREE);
7170  
7171       /* If we have an exit condition, then we build an IF with gotos either
7172          out of the loop, or to the top of it.  If there's no exit condition,
7173          then we just build a jump back to the top.  */
7174       exit = build_and_jump (&LABEL_EXPR_LABEL (top));
7175  
7176       if (cond && !integer_nonzerop (cond))
7177         {
7178           /* Canonicalize the loop condition to the end.  This means
7179              generating a branch to the loop condition.  Reuse the
7180              continue label, if possible.  */
7181           if (cond_is_first)
7182             {
7183               if (incr || !clab)
7184                 {
7185                   entry = build1 (LABEL_EXPR, void_type_node, NULL_TREE);
7186                   t = build_and_jump (&LABEL_EXPR_LABEL (entry));
7187                 }
7188               else
7189                 t = build1 (GOTO_EXPR, void_type_node, clab);
7190               SET_EXPR_LOCATION (t, start_locus);
7191               add_stmt (t);
7192             }
7193  
7194           t = build_and_jump (&blab);
7195           exit = fold_build3 (COND_EXPR, void_type_node, cond, exit, t);
7196           if (cond_is_first)
7197             SET_EXPR_LOCATION (exit, start_locus);
7198           else
7199             SET_EXPR_LOCATION (exit, input_location);
7200         }
7201  
7202       add_stmt (top);
7203     }
7204  
7205   if (body)
7206     add_stmt (body);
7207   if (clab)
7208     add_stmt (build1 (LABEL_EXPR, void_type_node, clab));
7209   if (incr)
7210     add_stmt (incr);
7211   if (entry)
7212     add_stmt (entry);
7213   if (exit)
7214     add_stmt (exit);
7215   if (blab)
7216     add_stmt (build1 (LABEL_EXPR, void_type_node, blab));
7217 }
7218
7219 tree
7220 c_finish_bc_stmt (tree *label_p, bool is_break)
7221 {
7222   bool skip;
7223   tree label = *label_p;
7224
7225   /* In switch statements break is sometimes stylistically used after
7226      a return statement.  This can lead to spurious warnings about
7227      control reaching the end of a non-void function when it is
7228      inlined.  Note that we are calling block_may_fallthru with
7229      language specific tree nodes; this works because
7230      block_may_fallthru returns true when given something it does not
7231      understand.  */
7232   skip = !block_may_fallthru (cur_stmt_list);
7233
7234   if (!label)
7235     {
7236       if (!skip)
7237         *label_p = label = create_artificial_label ();
7238     }
7239   else if (TREE_CODE (label) != LABEL_DECL)
7240     {
7241       if (is_break)
7242         error ("break statement not within loop or switch");
7243       else
7244         error ("continue statement not within a loop");
7245       return NULL_TREE;
7246     }
7247
7248   if (skip)
7249     return NULL_TREE;
7250
7251   return add_stmt (build1 (GOTO_EXPR, void_type_node, label));
7252 }
7253
7254 /* A helper routine for c_process_expr_stmt and c_finish_stmt_expr.  */
7255
7256 static void
7257 emit_side_effect_warnings (tree expr)
7258 {
7259   if (expr == error_mark_node)
7260     ;
7261   else if (!TREE_SIDE_EFFECTS (expr))
7262     {
7263       if (!VOID_TYPE_P (TREE_TYPE (expr)) && !TREE_NO_WARNING (expr))
7264         warning (0, "%Hstatement with no effect",
7265                  EXPR_HAS_LOCATION (expr) ? EXPR_LOCUS (expr) : &input_location);
7266     }
7267   else if (warn_unused_value)
7268     warn_if_unused_value (expr, input_location);
7269 }
7270
7271 /* Process an expression as if it were a complete statement.  Emit
7272    diagnostics, but do not call ADD_STMT.  */
7273
7274 tree
7275 c_process_expr_stmt (tree expr)
7276 {
7277   if (!expr)
7278     return NULL_TREE;
7279
7280   if (warn_sequence_point)
7281     verify_sequence_points (expr);
7282
7283   if (TREE_TYPE (expr) != error_mark_node
7284       && !COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (expr))
7285       && TREE_CODE (TREE_TYPE (expr)) != ARRAY_TYPE)
7286     error ("expression statement has incomplete type");
7287
7288   /* If we're not processing a statement expression, warn about unused values.
7289      Warnings for statement expressions will be emitted later, once we figure
7290      out which is the result.  */
7291   if (!STATEMENT_LIST_STMT_EXPR (cur_stmt_list)
7292       && (extra_warnings || warn_unused_value))
7293     emit_side_effect_warnings (expr);
7294
7295   /* If the expression is not of a type to which we cannot assign a line
7296      number, wrap the thing in a no-op NOP_EXPR.  */
7297   if (DECL_P (expr) || CONSTANT_CLASS_P (expr))
7298     expr = build1 (NOP_EXPR, TREE_TYPE (expr), expr);
7299
7300   if (EXPR_P (expr))
7301     SET_EXPR_LOCATION (expr, input_location);
7302
7303   return expr;
7304 }
7305
7306 /* Emit an expression as a statement.  */
7307
7308 tree
7309 c_finish_expr_stmt (tree expr)
7310 {
7311   if (expr)
7312     return add_stmt (c_process_expr_stmt (expr));
7313   else
7314     return NULL;
7315 }
7316
7317 /* Do the opposite and emit a statement as an expression.  To begin,
7318    create a new binding level and return it.  */
7319
7320 tree
7321 c_begin_stmt_expr (void)
7322 {
7323   tree ret;
7324   struct c_label_context_se *nstack;
7325   struct c_label_list *glist;
7326
7327   /* We must force a BLOCK for this level so that, if it is not expanded
7328      later, there is a way to turn off the entire subtree of blocks that
7329      are contained in it.  */
7330   keep_next_level ();
7331   ret = c_begin_compound_stmt (true);
7332   if (c_switch_stack)
7333     {
7334       c_switch_stack->blocked_stmt_expr++;
7335       gcc_assert (c_switch_stack->blocked_stmt_expr != 0);
7336     }
7337   for (glist = label_context_stack_se->labels_used;
7338        glist != NULL;
7339        glist = glist->next)
7340     {
7341       C_DECL_UNDEFINABLE_STMT_EXPR (glist->label) = 1;
7342     }
7343   nstack = XOBNEW (&parser_obstack, struct c_label_context_se);
7344   nstack->labels_def = NULL;
7345   nstack->labels_used = NULL;
7346   nstack->next = label_context_stack_se;
7347   label_context_stack_se = nstack;
7348
7349   /* Mark the current statement list as belonging to a statement list.  */
7350   STATEMENT_LIST_STMT_EXPR (ret) = 1;
7351
7352   return ret;
7353 }
7354
7355 tree
7356 c_finish_stmt_expr (tree body)
7357 {
7358   tree last, type, tmp, val;
7359   tree *last_p;
7360   struct c_label_list *dlist, *glist, *glist_prev = NULL;
7361
7362   body = c_end_compound_stmt (body, true);
7363   if (c_switch_stack)
7364     {
7365       gcc_assert (c_switch_stack->blocked_stmt_expr != 0);
7366       c_switch_stack->blocked_stmt_expr--;
7367     }
7368   /* It is no longer possible to jump to labels defined within this
7369      statement expression.  */
7370   for (dlist = label_context_stack_se->labels_def;
7371        dlist != NULL;
7372        dlist = dlist->next)
7373     {
7374       C_DECL_UNJUMPABLE_STMT_EXPR (dlist->label) = 1;
7375     }
7376   /* It is again possible to define labels with a goto just outside
7377      this statement expression.  */
7378   for (glist = label_context_stack_se->next->labels_used;
7379        glist != NULL;
7380        glist = glist->next)
7381     {
7382       C_DECL_UNDEFINABLE_STMT_EXPR (glist->label) = 0;
7383       glist_prev = glist;
7384     }
7385   if (glist_prev != NULL)
7386     glist_prev->next = label_context_stack_se->labels_used;
7387   else
7388     label_context_stack_se->next->labels_used
7389       = label_context_stack_se->labels_used;
7390   label_context_stack_se = label_context_stack_se->next;
7391
7392   /* Locate the last statement in BODY.  See c_end_compound_stmt
7393      about always returning a BIND_EXPR.  */
7394   last_p = &BIND_EXPR_BODY (body);
7395   last = BIND_EXPR_BODY (body);
7396
7397  continue_searching:
7398   if (TREE_CODE (last) == STATEMENT_LIST)
7399     {
7400       tree_stmt_iterator i;
7401
7402       /* This can happen with degenerate cases like ({ }).  No value.  */
7403       if (!TREE_SIDE_EFFECTS (last))
7404         return body;
7405
7406       /* If we're supposed to generate side effects warnings, process
7407          all of the statements except the last.  */
7408       if (extra_warnings || warn_unused_value)
7409         {
7410           for (i = tsi_start (last); !tsi_one_before_end_p (i); tsi_next (&i))
7411             emit_side_effect_warnings (tsi_stmt (i));
7412         }
7413       else
7414         i = tsi_last (last);
7415       last_p = tsi_stmt_ptr (i);
7416       last = *last_p;
7417     }
7418
7419   /* If the end of the list is exception related, then the list was split
7420      by a call to push_cleanup.  Continue searching.  */
7421   if (TREE_CODE (last) == TRY_FINALLY_EXPR
7422       || TREE_CODE (last) == TRY_CATCH_EXPR)
7423     {
7424       last_p = &TREE_OPERAND (last, 0);
7425       last = *last_p;
7426       goto continue_searching;
7427     }
7428
7429   /* In the case that the BIND_EXPR is not necessary, return the
7430      expression out from inside it.  */
7431   if (last == error_mark_node
7432       || (last == BIND_EXPR_BODY (body)
7433           && BIND_EXPR_VARS (body) == NULL))
7434     {
7435       /* Do not warn if the return value of a statement expression is
7436          unused.  */
7437       if (EXPR_P (last))
7438         TREE_NO_WARNING (last) = 1;
7439       return last;
7440     }
7441
7442   /* Extract the type of said expression.  */
7443   type = TREE_TYPE (last);
7444
7445   /* If we're not returning a value at all, then the BIND_EXPR that
7446      we already have is a fine expression to return.  */
7447   if (!type || VOID_TYPE_P (type))
7448     return body;
7449
7450   /* Now that we've located the expression containing the value, it seems
7451      silly to make voidify_wrapper_expr repeat the process.  Create a
7452      temporary of the appropriate type and stick it in a TARGET_EXPR.  */
7453   tmp = create_tmp_var_raw (type, NULL);
7454
7455   /* Unwrap a no-op NOP_EXPR as added by c_finish_expr_stmt.  This avoids
7456      tree_expr_nonnegative_p giving up immediately.  */
7457   val = last;
7458   if (TREE_CODE (val) == NOP_EXPR
7459       && TREE_TYPE (val) == TREE_TYPE (TREE_OPERAND (val, 0)))
7460     val = TREE_OPERAND (val, 0);
7461
7462   *last_p = build2 (MODIFY_EXPR, void_type_node, tmp, val);
7463   SET_EXPR_LOCUS (*last_p, EXPR_LOCUS (last));
7464
7465   return build4 (TARGET_EXPR, type, tmp, body, NULL_TREE, NULL_TREE);
7466 }
7467
7468 /* Begin the scope of an identifier of variably modified type, scope
7469    number SCOPE.  Jumping from outside this scope to inside it is not
7470    permitted.  */
7471
7472 void
7473 c_begin_vm_scope (unsigned int scope)
7474 {
7475   struct c_label_context_vm *nstack;
7476   struct c_label_list *glist;
7477
7478   gcc_assert (scope > 0);
7479   if (c_switch_stack && !c_switch_stack->blocked_vm)
7480     c_switch_stack->blocked_vm = scope;
7481   for (glist = label_context_stack_vm->labels_used;
7482        glist != NULL;
7483        glist = glist->next)
7484     {
7485       C_DECL_UNDEFINABLE_VM (glist->label) = 1;
7486     }
7487   nstack = XOBNEW (&parser_obstack, struct c_label_context_vm);
7488   nstack->labels_def = NULL;
7489   nstack->labels_used = NULL;
7490   nstack->scope = scope;
7491   nstack->next = label_context_stack_vm;
7492   label_context_stack_vm = nstack;
7493 }
7494
7495 /* End a scope which may contain identifiers of variably modified
7496    type, scope number SCOPE.  */
7497
7498 void
7499 c_end_vm_scope (unsigned int scope)
7500 {
7501   if (label_context_stack_vm == NULL)
7502     return;
7503   if (c_switch_stack && c_switch_stack->blocked_vm == scope)
7504     c_switch_stack->blocked_vm = 0;
7505   /* We may have a number of nested scopes of identifiers with
7506      variably modified type, all at this depth.  Pop each in turn.  */
7507   while (label_context_stack_vm->scope == scope)
7508     {
7509       struct c_label_list *dlist, *glist, *glist_prev = NULL;
7510
7511       /* It is no longer possible to jump to labels defined within this
7512          scope.  */
7513       for (dlist = label_context_stack_vm->labels_def;
7514            dlist != NULL;
7515            dlist = dlist->next)
7516         {
7517           C_DECL_UNJUMPABLE_VM (dlist->label) = 1;
7518         }
7519       /* It is again possible to define labels with a goto just outside
7520          this scope.  */
7521       for (glist = label_context_stack_vm->next->labels_used;
7522            glist != NULL;
7523            glist = glist->next)
7524         {
7525           C_DECL_UNDEFINABLE_VM (glist->label) = 0;
7526           glist_prev = glist;
7527         }
7528       if (glist_prev != NULL)
7529         glist_prev->next = label_context_stack_vm->labels_used;
7530       else
7531         label_context_stack_vm->next->labels_used
7532           = label_context_stack_vm->labels_used;
7533       label_context_stack_vm = label_context_stack_vm->next;
7534     }
7535 }
7536 \f
7537 /* Begin and end compound statements.  This is as simple as pushing
7538    and popping new statement lists from the tree.  */
7539
7540 tree
7541 c_begin_compound_stmt (bool do_scope)
7542 {
7543   tree stmt = push_stmt_list ();
7544   if (do_scope)
7545     push_scope ();
7546   return stmt;
7547 }
7548
7549 tree
7550 c_end_compound_stmt (tree stmt, bool do_scope)
7551 {
7552   tree block = NULL;
7553
7554   if (do_scope)
7555     {
7556       if (c_dialect_objc ())
7557         objc_clear_super_receiver ();
7558       block = pop_scope ();
7559     }
7560
7561   stmt = pop_stmt_list (stmt);
7562   stmt = c_build_bind_expr (block, stmt);
7563
7564   /* If this compound statement is nested immediately inside a statement
7565      expression, then force a BIND_EXPR to be created.  Otherwise we'll
7566      do the wrong thing for ({ { 1; } }) or ({ 1; { } }).  In particular,
7567      STATEMENT_LISTs merge, and thus we can lose track of what statement
7568      was really last.  */
7569   if (cur_stmt_list
7570       && STATEMENT_LIST_STMT_EXPR (cur_stmt_list)
7571       && TREE_CODE (stmt) != BIND_EXPR)
7572     {
7573       stmt = build3 (BIND_EXPR, void_type_node, NULL, stmt, NULL);
7574       TREE_SIDE_EFFECTS (stmt) = 1;
7575     }
7576
7577   return stmt;
7578 }
7579
7580 /* Queue a cleanup.  CLEANUP is an expression/statement to be executed
7581    when the current scope is exited.  EH_ONLY is true when this is not
7582    meant to apply to normal control flow transfer.  */
7583
7584 void
7585 push_cleanup (tree ARG_UNUSED (decl), tree cleanup, bool eh_only)
7586 {
7587   enum tree_code code;
7588   tree stmt, list;
7589   bool stmt_expr;
7590
7591   code = eh_only ? TRY_CATCH_EXPR : TRY_FINALLY_EXPR;
7592   stmt = build_stmt (code, NULL, cleanup);
7593   add_stmt (stmt);
7594   stmt_expr = STATEMENT_LIST_STMT_EXPR (cur_stmt_list);
7595   list = push_stmt_list ();
7596   TREE_OPERAND (stmt, 0) = list;
7597   STATEMENT_LIST_STMT_EXPR (list) = stmt_expr;
7598 }
7599 \f
7600 /* Build a binary-operation expression without default conversions.
7601    CODE is the kind of expression to build.
7602    This function differs from `build' in several ways:
7603    the data type of the result is computed and recorded in it,
7604    warnings are generated if arg data types are invalid,
7605    special handling for addition and subtraction of pointers is known,
7606    and some optimization is done (operations on narrow ints
7607    are done in the narrower type when that gives the same result).
7608    Constant folding is also done before the result is returned.
7609
7610    Note that the operands will never have enumeral types, or function
7611    or array types, because either they will have the default conversions
7612    performed or they have both just been converted to some other type in which
7613    the arithmetic is to be done.  */
7614
7615 tree
7616 build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
7617                  int convert_p)
7618 {
7619   tree type0, type1;
7620   enum tree_code code0, code1;
7621   tree op0, op1;
7622   const char *invalid_op_diag;
7623
7624   /* Expression code to give to the expression when it is built.
7625      Normally this is CODE, which is what the caller asked for,
7626      but in some special cases we change it.  */
7627   enum tree_code resultcode = code;
7628
7629   /* Data type in which the computation is to be performed.
7630      In the simplest cases this is the common type of the arguments.  */
7631   tree result_type = NULL;
7632
7633   /* Nonzero means operands have already been type-converted
7634      in whatever way is necessary.
7635      Zero means they need to be converted to RESULT_TYPE.  */
7636   int converted = 0;
7637
7638   /* Nonzero means create the expression with this type, rather than
7639      RESULT_TYPE.  */
7640   tree build_type = 0;
7641
7642   /* Nonzero means after finally constructing the expression
7643      convert it to this type.  */
7644   tree final_type = 0;
7645
7646   /* Nonzero if this is an operation like MIN or MAX which can
7647      safely be computed in short if both args are promoted shorts.
7648      Also implies COMMON.
7649      -1 indicates a bitwise operation; this makes a difference
7650      in the exact conditions for when it is safe to do the operation
7651      in a narrower mode.  */
7652   int shorten = 0;
7653
7654   /* Nonzero if this is a comparison operation;
7655      if both args are promoted shorts, compare the original shorts.
7656      Also implies COMMON.  */
7657   int short_compare = 0;
7658
7659   /* Nonzero if this is a right-shift operation, which can be computed on the
7660      original short and then promoted if the operand is a promoted short.  */
7661   int short_shift = 0;
7662
7663   /* Nonzero means set RESULT_TYPE to the common type of the args.  */
7664   int common = 0;
7665
7666   /* True means types are compatible as far as ObjC is concerned.  */
7667   bool objc_ok;
7668
7669   if (convert_p)
7670     {
7671       op0 = default_conversion (orig_op0);
7672       op1 = default_conversion (orig_op1);
7673     }
7674   else
7675     {
7676       op0 = orig_op0;
7677       op1 = orig_op1;
7678     }
7679
7680   type0 = TREE_TYPE (op0);
7681   type1 = TREE_TYPE (op1);
7682
7683   /* The expression codes of the data types of the arguments tell us
7684      whether the arguments are integers, floating, pointers, etc.  */
7685   code0 = TREE_CODE (type0);
7686   code1 = TREE_CODE (type1);
7687
7688   /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
7689   STRIP_TYPE_NOPS (op0);
7690   STRIP_TYPE_NOPS (op1);
7691
7692   /* If an error was already reported for one of the arguments,
7693      avoid reporting another error.  */
7694
7695   if (code0 == ERROR_MARK || code1 == ERROR_MARK)
7696     return error_mark_node;
7697
7698   if ((invalid_op_diag
7699        = targetm.invalid_binary_op (code, type0, type1)))
7700     {
7701       error (invalid_op_diag);
7702       return error_mark_node;
7703     }
7704
7705   objc_ok = objc_compare_types (type0, type1, -3, NULL_TREE);
7706
7707   switch (code)
7708     {
7709     case PLUS_EXPR:
7710       /* Handle the pointer + int case.  */
7711       if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
7712         return pointer_int_sum (PLUS_EXPR, op0, op1);
7713       else if (code1 == POINTER_TYPE && code0 == INTEGER_TYPE)
7714         return pointer_int_sum (PLUS_EXPR, op1, op0);
7715       else
7716         common = 1;
7717       break;
7718
7719     case MINUS_EXPR:
7720       /* Subtraction of two similar pointers.
7721          We must subtract them as integers, then divide by object size.  */
7722       if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
7723           && comp_target_types (type0, type1))
7724         return pointer_diff (op0, op1);
7725       /* Handle pointer minus int.  Just like pointer plus int.  */
7726       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
7727         return pointer_int_sum (MINUS_EXPR, op0, op1);
7728       else
7729         common = 1;
7730       break;
7731
7732     case MULT_EXPR:
7733       common = 1;
7734       break;
7735
7736     case TRUNC_DIV_EXPR:
7737     case CEIL_DIV_EXPR:
7738     case FLOOR_DIV_EXPR:
7739     case ROUND_DIV_EXPR:
7740     case EXACT_DIV_EXPR:
7741       /* Floating point division by zero is a legitimate way to obtain
7742          infinities and NaNs.  */
7743       if (skip_evaluation == 0 && integer_zerop (op1))
7744         warning (OPT_Wdiv_by_zero, "division by zero");
7745
7746       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
7747            || code0 == COMPLEX_TYPE || code0 == VECTOR_TYPE)
7748           && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
7749               || code1 == COMPLEX_TYPE || code1 == VECTOR_TYPE))
7750         {
7751           enum tree_code tcode0 = code0, tcode1 = code1;
7752
7753           if (code0 == COMPLEX_TYPE || code0 == VECTOR_TYPE)
7754             tcode0 = TREE_CODE (TREE_TYPE (TREE_TYPE (op0)));
7755           if (code1 == COMPLEX_TYPE || code1 == VECTOR_TYPE)
7756             tcode1 = TREE_CODE (TREE_TYPE (TREE_TYPE (op1)));
7757
7758           if (!(tcode0 == INTEGER_TYPE && tcode1 == INTEGER_TYPE))
7759             resultcode = RDIV_EXPR;
7760           else
7761             /* Although it would be tempting to shorten always here, that
7762                loses on some targets, since the modulo instruction is
7763                undefined if the quotient can't be represented in the
7764                computation mode.  We shorten only if unsigned or if
7765                dividing by something we know != -1.  */
7766             shorten = (TYPE_UNSIGNED (TREE_TYPE (orig_op0))
7767                        || (TREE_CODE (op1) == INTEGER_CST
7768                            && !integer_all_onesp (op1)));
7769           common = 1;
7770         }
7771       break;
7772
7773     case BIT_AND_EXPR:
7774     case BIT_IOR_EXPR:
7775     case BIT_XOR_EXPR:
7776       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
7777         shorten = -1;
7778       else if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE)
7779         common = 1;
7780       break;
7781
7782     case TRUNC_MOD_EXPR:
7783     case FLOOR_MOD_EXPR:
7784       if (skip_evaluation == 0 && integer_zerop (op1))
7785         warning (OPT_Wdiv_by_zero, "division by zero");
7786
7787       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
7788         {
7789           /* Although it would be tempting to shorten always here, that loses
7790              on some targets, since the modulo instruction is undefined if the
7791              quotient can't be represented in the computation mode.  We shorten
7792              only if unsigned or if dividing by something we know != -1.  */
7793           shorten = (TYPE_UNSIGNED (TREE_TYPE (orig_op0))
7794                      || (TREE_CODE (op1) == INTEGER_CST
7795                          && !integer_all_onesp (op1)));
7796           common = 1;
7797         }
7798       break;
7799
7800     case TRUTH_ANDIF_EXPR:
7801     case TRUTH_ORIF_EXPR:
7802     case TRUTH_AND_EXPR:
7803     case TRUTH_OR_EXPR:
7804     case TRUTH_XOR_EXPR:
7805       if ((code0 == INTEGER_TYPE || code0 == POINTER_TYPE
7806            || code0 == REAL_TYPE || code0 == COMPLEX_TYPE)
7807           && (code1 == INTEGER_TYPE || code1 == POINTER_TYPE
7808               || code1 == REAL_TYPE || code1 == COMPLEX_TYPE))
7809         {
7810           /* Result of these operations is always an int,
7811              but that does not mean the operands should be
7812              converted to ints!  */
7813           result_type = integer_type_node;
7814           op0 = c_common_truthvalue_conversion (op0);
7815           op1 = c_common_truthvalue_conversion (op1);
7816           converted = 1;
7817         }
7818       break;
7819
7820       /* Shift operations: result has same type as first operand;
7821          always convert second operand to int.
7822          Also set SHORT_SHIFT if shifting rightward.  */
7823
7824     case RSHIFT_EXPR:
7825       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
7826         {
7827           if (TREE_CODE (op1) == INTEGER_CST && skip_evaluation == 0)
7828             {
7829               if (tree_int_cst_sgn (op1) < 0)
7830                 warning (0, "right shift count is negative");
7831               else
7832                 {
7833                   if (!integer_zerop (op1))
7834                     short_shift = 1;
7835
7836                   if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0)
7837                     warning (0, "right shift count >= width of type");
7838                 }
7839             }
7840
7841           /* Use the type of the value to be shifted.  */
7842           result_type = type0;
7843           /* Convert the shift-count to an integer, regardless of size
7844              of value being shifted.  */
7845           if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
7846             op1 = convert (integer_type_node, op1);
7847           /* Avoid converting op1 to result_type later.  */
7848           converted = 1;
7849         }
7850       break;
7851
7852     case LSHIFT_EXPR:
7853       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
7854         {
7855           if (TREE_CODE (op1) == INTEGER_CST && skip_evaluation == 0)
7856             {
7857               if (tree_int_cst_sgn (op1) < 0)
7858                 warning (0, "left shift count is negative");
7859
7860               else if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0)
7861                 warning (0, "left shift count >= width of type");
7862             }
7863
7864           /* Use the type of the value to be shifted.  */
7865           result_type = type0;
7866           /* Convert the shift-count to an integer, regardless of size
7867              of value being shifted.  */
7868           if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
7869             op1 = convert (integer_type_node, op1);
7870           /* Avoid converting op1 to result_type later.  */
7871           converted = 1;
7872         }
7873       break;
7874
7875     case EQ_EXPR:
7876     case NE_EXPR:
7877       if (code0 == REAL_TYPE || code1 == REAL_TYPE)
7878         warning (OPT_Wfloat_equal,
7879                  "comparing floating point with == or != is unsafe");
7880       /* Result of comparison is always int,
7881          but don't convert the args to int!  */
7882       build_type = integer_type_node;
7883       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
7884            || code0 == COMPLEX_TYPE)
7885           && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
7886               || code1 == COMPLEX_TYPE))
7887         short_compare = 1;
7888       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
7889         {
7890           tree tt0 = TREE_TYPE (type0);
7891           tree tt1 = TREE_TYPE (type1);
7892           /* Anything compares with void *.  void * compares with anything.
7893              Otherwise, the targets must be compatible
7894              and both must be object or both incomplete.  */
7895           if (comp_target_types (type0, type1))
7896             result_type = common_pointer_type (type0, type1);
7897           else if (VOID_TYPE_P (tt0))
7898             {
7899               /* op0 != orig_op0 detects the case of something
7900                  whose value is 0 but which isn't a valid null ptr const.  */
7901               if (pedantic && (!integer_zerop (op0) || op0 != orig_op0)
7902                   && TREE_CODE (tt1) == FUNCTION_TYPE)
7903                 pedwarn ("ISO C forbids comparison of %<void *%>"
7904                          " with function pointer");
7905             }
7906           else if (VOID_TYPE_P (tt1))
7907             {
7908               if (pedantic && (!integer_zerop (op1) || op1 != orig_op1)
7909                   && TREE_CODE (tt0) == FUNCTION_TYPE)
7910                 pedwarn ("ISO C forbids comparison of %<void *%>"
7911                          " with function pointer");
7912             }
7913           else
7914             /* Avoid warning about the volatile ObjC EH puts on decls.  */
7915             if (!objc_ok)
7916               pedwarn ("comparison of distinct pointer types lacks a cast");
7917
7918           if (result_type == NULL_TREE)
7919             result_type = ptr_type_node;
7920         }
7921       else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
7922                && integer_zerop (op1))
7923         result_type = type0;
7924       else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
7925                && integer_zerop (op0))
7926         result_type = type1;
7927       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
7928         {
7929           result_type = type0;
7930           pedwarn ("comparison between pointer and integer");
7931         }
7932       else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
7933         {
7934           result_type = type1;
7935           pedwarn ("comparison between pointer and integer");
7936         }
7937       break;
7938
7939     case LE_EXPR:
7940     case GE_EXPR:
7941     case LT_EXPR:
7942     case GT_EXPR:
7943       build_type = integer_type_node;
7944       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
7945           && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
7946         short_compare = 1;
7947       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
7948         {
7949           if (comp_target_types (type0, type1))
7950             {
7951               result_type = common_pointer_type (type0, type1);
7952               if (!COMPLETE_TYPE_P (TREE_TYPE (type0))
7953                   != !COMPLETE_TYPE_P (TREE_TYPE (type1)))
7954                 pedwarn ("comparison of complete and incomplete pointers");
7955               else if (pedantic
7956                        && TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE)
7957                 pedwarn ("ISO C forbids ordered comparisons of pointers to functions");
7958             }
7959           else
7960             {
7961               result_type = ptr_type_node;
7962               pedwarn ("comparison of distinct pointer types lacks a cast");
7963             }
7964         }
7965       else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
7966                && integer_zerop (op1))
7967         {
7968           result_type = type0;
7969           if (pedantic || extra_warnings)
7970             pedwarn ("ordered comparison of pointer with integer zero");
7971         }
7972       else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
7973                && integer_zerop (op0))
7974         {
7975           result_type = type1;
7976           if (pedantic)
7977             pedwarn ("ordered comparison of pointer with integer zero");
7978         }
7979       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
7980         {
7981           result_type = type0;
7982           pedwarn ("comparison between pointer and integer");
7983         }
7984       else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
7985         {
7986           result_type = type1;
7987           pedwarn ("comparison between pointer and integer");
7988         }
7989       break;
7990
7991     default:
7992       gcc_unreachable ();
7993     }
7994
7995   if (code0 == ERROR_MARK || code1 == ERROR_MARK)
7996     return error_mark_node;
7997
7998   if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE
7999       && (!tree_int_cst_equal (TYPE_SIZE (type0), TYPE_SIZE (type1))
8000           || !same_scalar_type_ignoring_signedness (TREE_TYPE (type0),
8001                                                     TREE_TYPE (type1))))
8002     {
8003       binary_op_error (code);
8004       return error_mark_node;
8005     }
8006
8007   if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE
8008        || code0 == VECTOR_TYPE)
8009       &&
8010       (code1 == INTEGER_TYPE || code1 == REAL_TYPE || code1 == COMPLEX_TYPE
8011        || code1 == VECTOR_TYPE))
8012     {
8013       int none_complex = (code0 != COMPLEX_TYPE && code1 != COMPLEX_TYPE);
8014
8015       if (shorten || common || short_compare)
8016         result_type = c_common_type (type0, type1);
8017
8018       /* For certain operations (which identify themselves by shorten != 0)
8019          if both args were extended from the same smaller type,
8020          do the arithmetic in that type and then extend.
8021
8022          shorten !=0 and !=1 indicates a bitwise operation.
8023          For them, this optimization is safe only if
8024          both args are zero-extended or both are sign-extended.
8025          Otherwise, we might change the result.
8026          Eg, (short)-1 | (unsigned short)-1 is (int)-1
8027          but calculated in (unsigned short) it would be (unsigned short)-1.  */
8028
8029       if (shorten && none_complex)
8030         {
8031           int unsigned0, unsigned1;
8032           tree arg0 = get_narrower (op0, &unsigned0);
8033           tree arg1 = get_narrower (op1, &unsigned1);
8034           /* UNS is 1 if the operation to be done is an unsigned one.  */
8035           int uns = TYPE_UNSIGNED (result_type);
8036           tree type;
8037
8038           final_type = result_type;
8039
8040           /* Handle the case that OP0 (or OP1) does not *contain* a conversion
8041              but it *requires* conversion to FINAL_TYPE.  */
8042
8043           if ((TYPE_PRECISION (TREE_TYPE (op0))
8044                == TYPE_PRECISION (TREE_TYPE (arg0)))
8045               && TREE_TYPE (op0) != final_type)
8046             unsigned0 = TYPE_UNSIGNED (TREE_TYPE (op0));
8047           if ((TYPE_PRECISION (TREE_TYPE (op1))
8048                == TYPE_PRECISION (TREE_TYPE (arg1)))
8049               && TREE_TYPE (op1) != final_type)
8050             unsigned1 = TYPE_UNSIGNED (TREE_TYPE (op1));
8051
8052           /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE.  */
8053
8054           /* For bitwise operations, signedness of nominal type
8055              does not matter.  Consider only how operands were extended.  */
8056           if (shorten == -1)
8057             uns = unsigned0;
8058
8059           /* Note that in all three cases below we refrain from optimizing
8060              an unsigned operation on sign-extended args.
8061              That would not be valid.  */
8062
8063           /* Both args variable: if both extended in same way
8064              from same width, do it in that width.
8065              Do it unsigned if args were zero-extended.  */
8066           if ((TYPE_PRECISION (TREE_TYPE (arg0))
8067                < TYPE_PRECISION (result_type))
8068               && (TYPE_PRECISION (TREE_TYPE (arg1))
8069                   == TYPE_PRECISION (TREE_TYPE (arg0)))
8070               && unsigned0 == unsigned1
8071               && (unsigned0 || !uns))
8072             result_type
8073               = c_common_signed_or_unsigned_type
8074               (unsigned0, common_type (TREE_TYPE (arg0), TREE_TYPE (arg1)));
8075           else if (TREE_CODE (arg0) == INTEGER_CST
8076                    && (unsigned1 || !uns)
8077                    && (TYPE_PRECISION (TREE_TYPE (arg1))
8078                        < TYPE_PRECISION (result_type))
8079                    && (type
8080                        = c_common_signed_or_unsigned_type (unsigned1,
8081                                                            TREE_TYPE (arg1)),
8082                        int_fits_type_p (arg0, type)))
8083             result_type = type;
8084           else if (TREE_CODE (arg1) == INTEGER_CST
8085                    && (unsigned0 || !uns)
8086                    && (TYPE_PRECISION (TREE_TYPE (arg0))
8087                        < TYPE_PRECISION (result_type))
8088                    && (type
8089                        = c_common_signed_or_unsigned_type (unsigned0,
8090                                                            TREE_TYPE (arg0)),
8091                        int_fits_type_p (arg1, type)))
8092             result_type = type;
8093         }
8094
8095       /* Shifts can be shortened if shifting right.  */
8096
8097       if (short_shift)
8098         {
8099           int unsigned_arg;
8100           tree arg0 = get_narrower (op0, &unsigned_arg);
8101
8102           final_type = result_type;
8103
8104           if (arg0 == op0 && final_type == TREE_TYPE (op0))
8105             unsigned_arg = TYPE_UNSIGNED (TREE_TYPE (op0));
8106
8107           if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type)
8108               /* We can shorten only if the shift count is less than the
8109                  number of bits in the smaller type size.  */
8110               && compare_tree_int (op1, TYPE_PRECISION (TREE_TYPE (arg0))) < 0
8111               /* We cannot drop an unsigned shift after sign-extension.  */
8112               && (!TYPE_UNSIGNED (final_type) || unsigned_arg))
8113             {
8114               /* Do an unsigned shift if the operand was zero-extended.  */
8115               result_type
8116                 = c_common_signed_or_unsigned_type (unsigned_arg,
8117                                                     TREE_TYPE (arg0));
8118               /* Convert value-to-be-shifted to that type.  */
8119               if (TREE_TYPE (op0) != result_type)
8120                 op0 = convert (result_type, op0);
8121               converted = 1;
8122             }
8123         }
8124
8125       /* Comparison operations are shortened too but differently.
8126          They identify themselves by setting short_compare = 1.  */
8127
8128       if (short_compare)
8129         {
8130           /* Don't write &op0, etc., because that would prevent op0
8131              from being kept in a register.
8132              Instead, make copies of the our local variables and
8133              pass the copies by reference, then copy them back afterward.  */
8134           tree xop0 = op0, xop1 = op1, xresult_type = result_type;
8135           enum tree_code xresultcode = resultcode;
8136           tree val
8137             = shorten_compare (&xop0, &xop1, &xresult_type, &xresultcode);
8138
8139           if (val != 0)
8140             return val;
8141
8142           op0 = xop0, op1 = xop1;
8143           converted = 1;
8144           resultcode = xresultcode;
8145
8146           if (warn_sign_compare && skip_evaluation == 0)
8147             {
8148               int op0_signed = !TYPE_UNSIGNED (TREE_TYPE (orig_op0));
8149               int op1_signed = !TYPE_UNSIGNED (TREE_TYPE (orig_op1));
8150               int unsignedp0, unsignedp1;
8151               tree primop0 = get_narrower (op0, &unsignedp0);
8152               tree primop1 = get_narrower (op1, &unsignedp1);
8153
8154               xop0 = orig_op0;
8155               xop1 = orig_op1;
8156               STRIP_TYPE_NOPS (xop0);
8157               STRIP_TYPE_NOPS (xop1);
8158
8159               /* Give warnings for comparisons between signed and unsigned
8160                  quantities that may fail.
8161
8162                  Do the checking based on the original operand trees, so that
8163                  casts will be considered, but default promotions won't be.
8164
8165                  Do not warn if the comparison is being done in a signed type,
8166                  since the signed type will only be chosen if it can represent
8167                  all the values of the unsigned type.  */
8168               if (!TYPE_UNSIGNED (result_type))
8169                 /* OK */;
8170               /* Do not warn if both operands are the same signedness.  */
8171               else if (op0_signed == op1_signed)
8172                 /* OK */;
8173               else
8174                 {
8175                   tree sop, uop;
8176
8177                   if (op0_signed)
8178                     sop = xop0, uop = xop1;
8179                   else
8180                     sop = xop1, uop = xop0;
8181
8182                   /* Do not warn if the signed quantity is an
8183                      unsuffixed integer literal (or some static
8184                      constant expression involving such literals or a
8185                      conditional expression involving such literals)
8186                      and it is non-negative.  */
8187                   if (tree_expr_nonnegative_p (sop))
8188                     /* OK */;
8189                   /* Do not warn if the comparison is an equality operation,
8190                      the unsigned quantity is an integral constant, and it
8191                      would fit in the result if the result were signed.  */
8192                   else if (TREE_CODE (uop) == INTEGER_CST
8193                            && (resultcode == EQ_EXPR || resultcode == NE_EXPR)
8194                            && int_fits_type_p
8195                            (uop, c_common_signed_type (result_type)))
8196                     /* OK */;
8197                   /* Do not warn if the unsigned quantity is an enumeration
8198                      constant and its maximum value would fit in the result
8199                      if the result were signed.  */
8200                   else if (TREE_CODE (uop) == INTEGER_CST
8201                            && TREE_CODE (TREE_TYPE (uop)) == ENUMERAL_TYPE
8202                            && int_fits_type_p
8203                            (TYPE_MAX_VALUE (TREE_TYPE (uop)),
8204                             c_common_signed_type (result_type)))
8205                     /* OK */;
8206                   else
8207                     warning (0, "comparison between signed and unsigned");
8208                 }
8209
8210               /* Warn if two unsigned values are being compared in a size
8211                  larger than their original size, and one (and only one) is the
8212                  result of a `~' operator.  This comparison will always fail.
8213
8214                  Also warn if one operand is a constant, and the constant
8215                  does not have all bits set that are set in the ~ operand
8216                  when it is extended.  */
8217
8218               if ((TREE_CODE (primop0) == BIT_NOT_EXPR)
8219                   != (TREE_CODE (primop1) == BIT_NOT_EXPR))
8220                 {
8221                   if (TREE_CODE (primop0) == BIT_NOT_EXPR)
8222                     primop0 = get_narrower (TREE_OPERAND (primop0, 0),
8223                                             &unsignedp0);
8224                   else
8225                     primop1 = get_narrower (TREE_OPERAND (primop1, 0),
8226                                             &unsignedp1);
8227
8228                   if (host_integerp (primop0, 0) || host_integerp (primop1, 0))
8229                     {
8230                       tree primop;
8231                       HOST_WIDE_INT constant, mask;
8232                       int unsignedp, bits;
8233
8234                       if (host_integerp (primop0, 0))
8235                         {
8236                           primop = primop1;
8237                           unsignedp = unsignedp1;
8238                           constant = tree_low_cst (primop0, 0);
8239                         }
8240                       else
8241                         {
8242                           primop = primop0;
8243                           unsignedp = unsignedp0;
8244                           constant = tree_low_cst (primop1, 0);
8245                         }
8246
8247                       bits = TYPE_PRECISION (TREE_TYPE (primop));
8248                       if (bits < TYPE_PRECISION (result_type)
8249                           && bits < HOST_BITS_PER_WIDE_INT && unsignedp)
8250                         {
8251                           mask = (~(HOST_WIDE_INT) 0) << bits;
8252                           if ((mask & constant) != mask)
8253                             warning (0, "comparison of promoted ~unsigned with constant");
8254                         }
8255                     }
8256                   else if (unsignedp0 && unsignedp1
8257                            && (TYPE_PRECISION (TREE_TYPE (primop0))
8258                                < TYPE_PRECISION (result_type))
8259                            && (TYPE_PRECISION (TREE_TYPE (primop1))
8260                                < TYPE_PRECISION (result_type)))
8261                     warning (0, "comparison of promoted ~unsigned with unsigned");
8262                 }
8263             }
8264         }
8265     }
8266
8267   /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
8268      If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
8269      Then the expression will be built.
8270      It will be given type FINAL_TYPE if that is nonzero;
8271      otherwise, it will be given type RESULT_TYPE.  */
8272
8273   if (!result_type)
8274     {
8275       binary_op_error (code);
8276       return error_mark_node;
8277     }
8278
8279   if (!converted)
8280     {
8281       if (TREE_TYPE (op0) != result_type)
8282         op0 = convert (result_type, op0);
8283       if (TREE_TYPE (op1) != result_type)
8284         op1 = convert (result_type, op1);
8285
8286       /* This can happen if one operand has a vector type, and the other
8287          has a different type.  */
8288       if (TREE_CODE (op0) == ERROR_MARK || TREE_CODE (op1) == ERROR_MARK)
8289         return error_mark_node;
8290     }
8291
8292   if (build_type == NULL_TREE)
8293     build_type = result_type;
8294
8295   {
8296     /* Treat expressions in initializers specially as they can't trap.  */
8297     tree result = require_constant_value ? fold_build2_initializer (resultcode,
8298                                                                     build_type,
8299                                                                     op0, op1)
8300                                          : fold_build2 (resultcode, build_type,
8301                                                         op0, op1);
8302
8303     if (final_type != 0)
8304       result = convert (final_type, result);
8305     return result;
8306   }
8307 }
8308
8309
8310 /* Convert EXPR to be a truth-value, validating its type for this
8311    purpose.  */
8312
8313 tree
8314 c_objc_common_truthvalue_conversion (tree expr)
8315 {
8316   switch (TREE_CODE (TREE_TYPE (expr)))
8317     {
8318     case ARRAY_TYPE:
8319       error ("used array that cannot be converted to pointer where scalar is required");
8320       return error_mark_node;
8321
8322     case RECORD_TYPE:
8323       error ("used struct type value where scalar is required");
8324       return error_mark_node;
8325
8326     case UNION_TYPE:
8327       error ("used union type value where scalar is required");
8328       return error_mark_node;
8329
8330     case FUNCTION_TYPE:
8331       gcc_unreachable ();
8332
8333     default:
8334       break;
8335     }
8336
8337   /* ??? Should we also give an error for void and vectors rather than
8338      leaving those to give errors later?  */
8339   return c_common_truthvalue_conversion (expr);
8340 }
8341 \f
8342
8343 /* Convert EXPR to a contained DECL, updating *TC, *TI and *SE as
8344    required.  */
8345
8346 tree
8347 c_expr_to_decl (tree expr, bool *tc ATTRIBUTE_UNUSED,
8348                 bool *ti ATTRIBUTE_UNUSED, bool *se)
8349 {
8350   if (TREE_CODE (expr) == COMPOUND_LITERAL_EXPR)
8351     {
8352       tree decl = COMPOUND_LITERAL_EXPR_DECL (expr);
8353       /* Executing a compound literal inside a function reinitializes
8354          it.  */
8355       if (!TREE_STATIC (decl))
8356         *se = true;
8357       return decl;
8358     }
8359   else
8360     return expr;
8361 }