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