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