c-decl.c revision 57844
1/* Process declarations and variables for C compiler.
2   Copyright (C) 1988, 92-98, 1999 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/* Process declarations and symbol lookup for C front end.
23   Also constructs types; the standard scalar types at initialization,
24   and structure, union, array and enum types when they are declared.  */
25
26/* ??? not all decl nodes are given the most useful possible
27   line numbers.  For example, the CONST_DECLs for enum values.  */
28
29#include "config.h"
30#include "system.h"
31#include "tree.h"
32#include "flags.h"
33#include "output.h"
34#include "c-tree.h"
35#include "c-lex.h"
36#include "toplev.h"
37
38#if USE_CPPLIB
39#include "cpplib.h"
40extern cpp_reader parse_in;
41#endif
42
43/* In grokdeclarator, distinguish syntactic contexts of declarators.  */
44enum decl_context
45{ NORMAL,			/* Ordinary declaration */
46  FUNCDEF,			/* Function definition */
47  PARM,				/* Declaration of parm before function body */
48  FIELD,			/* Declaration inside struct or union */
49  BITFIELD,			/* Likewise but with specified width */
50  TYPENAME};			/* Typename (inside cast or sizeof)  */
51
52#ifndef CHAR_TYPE_SIZE
53#define CHAR_TYPE_SIZE BITS_PER_UNIT
54#endif
55
56#ifndef SHORT_TYPE_SIZE
57#define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
58#endif
59
60#ifndef INT_TYPE_SIZE
61#define INT_TYPE_SIZE BITS_PER_WORD
62#endif
63
64#ifndef LONG_TYPE_SIZE
65#define LONG_TYPE_SIZE BITS_PER_WORD
66#endif
67
68#ifndef LONG_LONG_TYPE_SIZE
69#define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
70#endif
71
72#ifndef WCHAR_UNSIGNED
73#define WCHAR_UNSIGNED 0
74#endif
75
76#ifndef FLOAT_TYPE_SIZE
77#define FLOAT_TYPE_SIZE BITS_PER_WORD
78#endif
79
80#ifndef DOUBLE_TYPE_SIZE
81#define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
82#endif
83
84#ifndef LONG_DOUBLE_TYPE_SIZE
85#define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
86#endif
87
88/* We let tm.h override the types used here, to handle trivial differences
89   such as the choice of unsigned int or long unsigned int for size_t.
90   When machines start needing nontrivial differences in the size type,
91   it would be best to do something here to figure out automatically
92   from other information what type to use.  */
93
94#ifndef SIZE_TYPE
95#define SIZE_TYPE "long unsigned int"
96#endif
97
98#ifndef PTRDIFF_TYPE
99#define PTRDIFF_TYPE "long int"
100#endif
101
102#ifndef WCHAR_TYPE
103#define WCHAR_TYPE "int"
104#endif
105
106/* a node which has tree code ERROR_MARK, and whose type is itself.
107   All erroneous expressions are replaced with this node.  All functions
108   that accept nodes as arguments should avoid generating error messages
109   if this node is one of the arguments, since it is undesirable to get
110   multiple error messages from one error in the input.  */
111
112tree error_mark_node;
113
114/* INTEGER_TYPE and REAL_TYPE nodes for the standard data types */
115
116tree short_integer_type_node;
117tree integer_type_node;
118tree long_integer_type_node;
119tree long_long_integer_type_node;
120
121tree short_unsigned_type_node;
122tree unsigned_type_node;
123tree long_unsigned_type_node;
124tree long_long_unsigned_type_node;
125
126tree boolean_type_node;
127tree boolean_false_node;
128tree boolean_true_node;
129
130tree ptrdiff_type_node;
131
132tree unsigned_char_type_node;
133tree signed_char_type_node;
134tree char_type_node;
135tree wchar_type_node;
136tree signed_wchar_type_node;
137tree unsigned_wchar_type_node;
138
139tree float_type_node;
140tree double_type_node;
141tree long_double_type_node;
142
143tree complex_integer_type_node;
144tree complex_float_type_node;
145tree complex_double_type_node;
146tree complex_long_double_type_node;
147
148tree intQI_type_node;
149tree intHI_type_node;
150tree intSI_type_node;
151tree intDI_type_node;
152#if HOST_BITS_PER_WIDE_INT >= 64
153tree intTI_type_node;
154#endif
155
156tree unsigned_intQI_type_node;
157tree unsigned_intHI_type_node;
158tree unsigned_intSI_type_node;
159tree unsigned_intDI_type_node;
160#if HOST_BITS_PER_WIDE_INT >= 64
161tree unsigned_intTI_type_node;
162#endif
163
164/* a VOID_TYPE node.  */
165
166tree void_type_node;
167
168/* Nodes for types `void *' and `const void *'.  */
169
170tree ptr_type_node, const_ptr_type_node;
171
172/* Nodes for types `char *' and `const char *'.  */
173
174tree string_type_node, const_string_type_node;
175
176/* Type `char[SOMENUMBER]'.
177   Used when an array of char is needed and the size is irrelevant.  */
178
179tree char_array_type_node;
180
181/* Type `int[SOMENUMBER]' or something like it.
182   Used when an array of int needed and the size is irrelevant.  */
183
184tree int_array_type_node;
185
186/* Type `wchar_t[SOMENUMBER]' or something like it.
187   Used when a wide string literal is created.  */
188
189tree wchar_array_type_node;
190
191/* type `int ()' -- used for implicit declaration of functions.  */
192
193tree default_function_type;
194
195/* function types `double (double)' and `double (double, double)', etc.  */
196
197tree double_ftype_double, double_ftype_double_double;
198tree int_ftype_int, long_ftype_long;
199tree float_ftype_float;
200tree ldouble_ftype_ldouble;
201
202/* Function type `void (void *, void *, int)' and similar ones */
203
204tree void_ftype_ptr_ptr_int, int_ftype_ptr_ptr_int, void_ftype_ptr_int_int;
205
206/* Function type `char *(char *, char *)' and similar ones */
207tree string_ftype_ptr_ptr, int_ftype_string_string;
208
209/* Function type `int (const void *, const void *, size_t)' */
210tree int_ftype_cptr_cptr_sizet;
211
212/* Two expressions that are constants with value zero.
213   The first is of type `int', the second of type `void *'.  */
214
215tree integer_zero_node;
216tree null_pointer_node;
217
218/* A node for the integer constant 1.  */
219
220tree integer_one_node;
221
222/* Nonzero if we have seen an invalid cross reference
223   to a struct, union, or enum, but not yet printed the message.  */
224
225tree pending_invalid_xref;
226/* File and line to appear in the eventual error message.  */
227char *pending_invalid_xref_file;
228int pending_invalid_xref_line;
229
230/* While defining an enum type, this is 1 plus the last enumerator
231   constant value.  Note that will do not have to save this or `enum_overflow'
232   around nested function definition since such a definition could only
233   occur in an enum value expression and we don't use these variables in
234   that case.  */
235
236static tree enum_next_value;
237
238/* Nonzero means that there was overflow computing enum_next_value.  */
239
240static int enum_overflow;
241
242/* Parsing a function declarator leaves a list of parameter names
243   or a chain or parameter decls here.  */
244
245static tree last_function_parms;
246
247/* Parsing a function declarator leaves here a chain of structure
248   and enum types declared in the parmlist.  */
249
250static tree last_function_parm_tags;
251
252/* After parsing the declarator that starts a function definition,
253   `start_function' puts here the list of parameter names or chain of decls.
254   `store_parm_decls' finds it here.  */
255
256static tree current_function_parms;
257
258/* Similar, for last_function_parm_tags.  */
259static tree current_function_parm_tags;
260
261/* Similar, for the file and line that the prototype came from if this is
262   an old-style definition.  */
263static char *current_function_prototype_file;
264static int current_function_prototype_line;
265
266/* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
267   that have names.  Here so we can clear out their names' definitions
268   at the end of the function.  */
269
270static tree named_labels;
271
272/* A list of LABEL_DECLs from outer contexts that are currently shadowed.  */
273
274static tree shadowed_labels;
275
276/* Nonzero when store_parm_decls is called indicates a varargs function.
277   Value not meaningful after store_parm_decls.  */
278
279static int c_function_varargs;
280
281/* The FUNCTION_DECL for the function currently being compiled,
282   or 0 if between functions.  */
283tree current_function_decl;
284
285/* Set to 0 at beginning of a function definition, set to 1 if
286   a return statement that specifies a return value is seen.  */
287
288int current_function_returns_value;
289
290/* Set to 0 at beginning of a function definition, set to 1 if
291   a return statement with no argument is seen.  */
292
293int current_function_returns_null;
294
295/* Set to nonzero by `grokdeclarator' for a function
296   whose return type is defaulted, if warnings for this are desired.  */
297
298static int warn_about_return_type;
299
300/* Nonzero when starting a function declared `extern inline'.  */
301
302static int current_extern_inline;
303
304/* For each binding contour we allocate a binding_level structure
305 * which records the names defined in that contour.
306 * Contours include:
307 *  0) the global one
308 *  1) one for each function definition,
309 *     where internal declarations of the parameters appear.
310 *  2) one for each compound statement,
311 *     to record its declarations.
312 *
313 * The current meaning of a name can be found by searching the levels from
314 * the current one out to the global one.
315 */
316
317/* Note that the information in the `names' component of the global contour
318   is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers.  */
319
320struct binding_level
321  {
322    /* A chain of _DECL nodes for all variables, constants, functions,
323       and typedef types.  These are in the reverse of the order supplied.
324     */
325    tree names;
326
327    /* A list of structure, union and enum definitions,
328     * for looking up tag names.
329     * It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name,
330     * or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE,
331     * or ENUMERAL_TYPE node.
332     */
333    tree tags;
334
335    /* For each level, a list of shadowed outer-level local definitions
336       to be restored when this level is popped.
337       Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
338       whose TREE_VALUE is its old definition (a kind of ..._DECL node).  */
339    tree shadowed;
340
341    /* For each level (except not the global one),
342       a chain of BLOCK nodes for all the levels
343       that were entered and exited one level down.  */
344    tree blocks;
345
346    /* The BLOCK node for this level, if one has been preallocated.
347       If 0, the BLOCK is allocated (if needed) when the level is popped.  */
348    tree this_block;
349
350    /* The binding level which this one is contained in (inherits from).  */
351    struct binding_level *level_chain;
352
353    /* Nonzero for the level that holds the parameters of a function.  */
354    char parm_flag;
355
356    /* Nonzero if this level "doesn't exist" for tags.  */
357    char tag_transparent;
358
359    /* Nonzero if sublevels of this level "don't exist" for tags.
360       This is set in the parm level of a function definition
361       while reading the function body, so that the outermost block
362       of the function body will be tag-transparent.  */
363    char subblocks_tag_transparent;
364
365    /* Nonzero means make a BLOCK for this level regardless of all else.  */
366    char keep;
367
368    /* Nonzero means make a BLOCK if this level has any subblocks.  */
369    char keep_if_subblocks;
370
371    /* Number of decls in `names' that have incomplete
372       structure or union types.  */
373    int n_incomplete;
374
375    /* A list of decls giving the (reversed) specified order of parms,
376       not including any forward-decls in the parmlist.
377       This is so we can put the parms in proper order for assign_parms.  */
378    tree parm_order;
379  };
380
381#define NULL_BINDING_LEVEL (struct binding_level *) NULL
382
383/* The binding level currently in effect.  */
384
385static struct binding_level *current_binding_level;
386
387/* A chain of binding_level structures awaiting reuse.  */
388
389static struct binding_level *free_binding_level;
390
391/* The outermost binding level, for names of file scope.
392   This is created when the compiler is started and exists
393   through the entire run.  */
394
395static struct binding_level *global_binding_level;
396
397/* Binding level structures are initialized by copying this one.  */
398
399static struct binding_level clear_binding_level
400  = {NULL, NULL, NULL, NULL, NULL, NULL_BINDING_LEVEL, 0, 0, 0, 0, 0, 0,
401     NULL};
402
403/* Nonzero means unconditionally make a BLOCK for the next level pushed.  */
404
405static int keep_next_level_flag;
406
407/* Nonzero means make a BLOCK for the next level pushed
408   if it has subblocks.  */
409
410static int keep_next_if_subblocks;
411
412/* The chain of outer levels of label scopes.
413   This uses the same data structure used for binding levels,
414   but it works differently: each link in the chain records
415   saved values of named_labels and shadowed_labels for
416   a label binding level outside the current one.  */
417
418static struct binding_level *label_level_chain;
419
420/* Functions called automatically at the beginning and end of execution.  */
421
422tree static_ctors, static_dtors;
423
424/* Forward declarations.  */
425
426static struct binding_level * make_binding_level	PROTO((void));
427static void clear_limbo_values		PROTO((tree));
428static int duplicate_decls		PROTO((tree, tree, int));
429static int redeclaration_error_message	PROTO((tree, tree));
430static void storedecls			PROTO((tree));
431static void storetags			PROTO((tree));
432static tree lookup_tag			PROTO((enum tree_code, tree,
433					       struct binding_level *, int));
434static tree lookup_tag_reverse		PROTO((tree));
435static tree grokdeclarator		PROTO((tree, tree, enum decl_context,
436					       int));
437static tree grokparms			PROTO((tree, int));
438static int field_decl_cmp		PROTO((const GENERIC_PTR, const GENERIC_PTR));
439static void layout_array_type		PROTO((tree));
440
441/* C-specific option variables.  */
442
443/* Nonzero means allow type mismatches in conditional expressions;
444   just make their values `void'.   */
445
446int flag_cond_mismatch;
447
448/* Nonzero means give `double' the same size as `float'.  */
449
450int flag_short_double;
451
452/* Nonzero means don't recognize the keyword `asm'.  */
453
454int flag_no_asm;
455
456/* Nonzero means don't recognize any builtin functions.  */
457
458int flag_no_builtin;
459
460/* Nonzero means don't recognize the non-ANSI builtin functions.
461   -ansi sets this.  */
462
463int flag_no_nonansi_builtin;
464
465/* Nonzero means do some things the same way PCC does.  */
466
467int flag_traditional;
468
469/* Nonzero means use the ISO C9x dialect of C.  */
470
471int flag_isoc9x = 0;
472
473/* Nonzero means that we have builtin functions, and main is an int */
474
475int flag_hosted = 1;
476
477/* Nonzero means to allow single precision math even if we're generally
478   being traditional.  */
479int flag_allow_single_precision = 0;
480
481/* Nonzero means to treat bitfields as signed unless they say `unsigned'.  */
482
483int flag_signed_bitfields = 1;
484int explicit_flag_signed_bitfields = 0;
485
486/* Nonzero means warn about use of implicit int. */
487
488int warn_implicit_int;
489
490/* Nonzero means warn about usage of long long when `-pedantic'.  */
491
492int warn_long_long = 1;
493
494/* Nonzero means message about use of implicit function declarations;
495 1 means warning; 2 means error. */
496
497int mesg_implicit_function_declaration;
498
499/* Nonzero means give string constants the type `const char *'
500   to get extra warnings from them.  These warnings will be too numerous
501   to be useful, except in thoroughly ANSIfied programs.  */
502
503int flag_const_strings;
504
505/* Nonzero means warn about pointer casts that can drop a type qualifier
506   from the pointer target type.  */
507
508int warn_cast_qual;
509
510/* Nonzero means warn when casting a function call to a type that does
511   not match the return type (e.g. (float)sqrt() or (anything*)malloc()
512   when there is no previous declaration of sqrt or malloc.  */
513
514int warn_bad_function_cast;
515
516/* Warn about functions which might be candidates for attribute noreturn. */
517
518int warn_missing_noreturn;
519
520/* Warn about traditional constructs whose meanings changed in ANSI C.  */
521
522int warn_traditional;
523
524/* Nonzero means warn about sizeof(function) or addition/subtraction
525   of function pointers.  */
526
527int warn_pointer_arith;
528
529/* Nonzero means warn for non-prototype function decls
530   or non-prototyped defs without previous prototype.  */
531
532int warn_strict_prototypes;
533
534/* Nonzero means warn for any global function def
535   without separate previous prototype decl.  */
536
537int warn_missing_prototypes;
538
539/* Nonzero means warn for any global function def
540   without separate previous decl.  */
541
542int warn_missing_declarations;
543
544/* Nonzero means warn about multiple (redundant) decls for the same single
545   variable or function.  */
546
547int warn_redundant_decls = 0;
548
549/* Nonzero means warn about extern declarations of objects not at
550   file-scope level and about *all* declarations of functions (whether
551   extern or static) not at file-scope level.  Note that we exclude
552   implicit function declarations.  To get warnings about those, use
553   -Wimplicit.  */
554
555int warn_nested_externs = 0;
556
557/* Warn about *printf or *scanf format/argument anomalies.  */
558
559int warn_format;
560
561/* Warn about a subscript that has type char.  */
562
563int warn_char_subscripts = 0;
564
565/* Warn if a type conversion is done that might have confusing results.  */
566
567int warn_conversion;
568
569/* Warn if adding () is suggested.  */
570
571int warn_parentheses;
572
573/* Warn if initializer is not completely bracketed.  */
574
575int warn_missing_braces;
576
577/* Warn if main is suspicious.  */
578
579int warn_main;
580
581/* Warn about #pragma directives that are not recognised.  */
582
583int warn_unknown_pragmas = 0; /* Tri state variable.  */
584
585/* Warn about comparison of signed and unsigned values.
586   If -1, neither -Wsign-compare nor -Wno-sign-compare has been specified.  */
587
588int warn_sign_compare = -1;
589
590/* Nonzero means warn about use of multicharacter literals.  */
591
592int warn_multichar = 1;
593
594/* Nonzero means `$' can be in an identifier.  */
595
596#ifndef DOLLARS_IN_IDENTIFIERS
597#define DOLLARS_IN_IDENTIFIERS 1
598#endif
599int dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
600
601/* Decode the string P as a language-specific option for C.
602   Return the number of strings consumed.  */
603
604int
605c_decode_option (argc, argv)
606     int argc ATTRIBUTE_UNUSED;
607     char **argv;
608{
609  int strings_processed;
610  char *p = argv[0];
611#if USE_CPPLIB
612  strings_processed = cpp_handle_option (&parse_in, argc, argv);
613#else
614  strings_processed = 0;
615#endif /* ! USE_CPPLIB */
616
617  if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional"))
618    {
619      flag_traditional = 1;
620      flag_writable_strings = 1;
621    }
622  else if (!strcmp (p, "-fallow-single-precision"))
623    flag_allow_single_precision = 1;
624  else if (!strcmp (p, "-fhosted") || !strcmp (p, "-fno-freestanding"))
625    {
626      flag_hosted = 1;
627      flag_no_builtin = 0;
628    }
629  else if (!strcmp (p, "-ffreestanding") || !strcmp (p, "-fno-hosted"))
630    {
631      flag_hosted = 0;
632      flag_no_builtin = 1;
633      /* warn_main will be 2 if set by -Wall, 1 if set by -Wmain */
634      if (warn_main == 2)
635	warn_main = 0;
636    }
637  else if (!strcmp (p, "-fnotraditional") || !strcmp (p, "-fno-traditional"))
638    {
639      flag_traditional = 0;
640      flag_writable_strings = 0;
641    }
642  else if (!strncmp (p, "-std=", 5))
643    {
644      /* Select the appropriate language standard.  We currently
645	 recognize:
646	 -std=iso9899:1990	same as -ansi
647	 -std=iso9899:199409	ISO C as modified in amend. 1
648	 -std=iso9899:199x	ISO C 9x
649	 -std=c89		same as -std=iso9899:1990
650	 -std=c9x		same as -std=iso9899:199x
651	 -std=gnu89		default, iso9899:1990 + gnu extensions
652	 -std=gnu9x		iso9899:199x + gnu extensions
653      */
654      const char *argstart = &p[5];
655
656      if (!strcmp (argstart, "iso9899:1990")
657	  || !strcmp (argstart, "c89"))
658	{
659	iso_1990:
660	  flag_traditional = 0;
661	  flag_writable_strings = 0;
662	  flag_no_asm = 1;
663	  flag_no_nonansi_builtin = 1;
664	  flag_isoc9x = 0;
665	}
666      else if (!strcmp (argstart, "iso9899:199409"))
667	{
668	  /* ??? The changes since ISO C 1990 are not supported.  */
669	  goto iso_1990;
670	}
671      else if (!strcmp (argstart, "iso9899:199x")
672	       || !strcmp (argstart, "c9x"))
673	{
674	  flag_traditional = 0;
675	  flag_writable_strings = 0;
676	  flag_no_asm = 1;
677	  flag_no_nonansi_builtin = 1;
678	  flag_isoc9x = 1;
679	}
680      else if (!strcmp (argstart, "gnu89"))
681	{
682	  flag_traditional = 0;
683	  flag_writable_strings = 0;
684	  flag_no_asm = 0;
685	  flag_no_nonansi_builtin = 0;
686	  flag_isoc9x = 0;
687	}
688      else if (!strcmp (argstart, "gnu9x"))
689	{
690	  flag_traditional = 0;
691	  flag_writable_strings = 0;
692	  flag_no_asm = 0;
693	  flag_no_nonansi_builtin = 0;
694	  flag_isoc9x = 1;
695	}
696      else
697	error ("unknown C standard `%s'", argstart);
698    }
699  else if (!strcmp (p, "-fdollars-in-identifiers"))
700    dollars_in_ident = 1;
701  else if (!strcmp (p, "-fno-dollars-in-identifiers"))
702    dollars_in_ident = 0;
703  else if (!strcmp (p, "-fsigned-char"))
704    flag_signed_char = 1;
705  else if (!strcmp (p, "-funsigned-char"))
706    flag_signed_char = 0;
707  else if (!strcmp (p, "-fno-signed-char"))
708    flag_signed_char = 0;
709  else if (!strcmp (p, "-fno-unsigned-char"))
710    flag_signed_char = 1;
711  else if (!strcmp (p, "-fsigned-bitfields")
712	   || !strcmp (p, "-fno-unsigned-bitfields"))
713    {
714      flag_signed_bitfields = 1;
715      explicit_flag_signed_bitfields = 1;
716    }
717  else if (!strcmp (p, "-funsigned-bitfields")
718	   || !strcmp (p, "-fno-signed-bitfields"))
719    {
720      flag_signed_bitfields = 0;
721      explicit_flag_signed_bitfields = 1;
722    }
723  else if (!strcmp (p, "-fshort-enums"))
724    flag_short_enums = 1;
725  else if (!strcmp (p, "-fno-short-enums"))
726    flag_short_enums = 0;
727  else if (!strcmp (p, "-fcond-mismatch"))
728    flag_cond_mismatch = 1;
729  else if (!strcmp (p, "-fno-cond-mismatch"))
730    flag_cond_mismatch = 0;
731  else if (!strcmp (p, "-fshort-double"))
732    flag_short_double = 1;
733  else if (!strcmp (p, "-fno-short-double"))
734    flag_short_double = 0;
735  else if (!strcmp (p, "-fasm"))
736    flag_no_asm = 0;
737  else if (!strcmp (p, "-fno-asm"))
738    flag_no_asm = 1;
739  else if (!strcmp (p, "-fbuiltin"))
740    flag_no_builtin = 0;
741  else if (!strcmp (p, "-fno-builtin"))
742    flag_no_builtin = 1;
743  else if (!strcmp (p, "-ansi"))
744    goto iso_1990;
745  else if (!strcmp (p, "-Werror-implicit-function-declaration"))
746    mesg_implicit_function_declaration = 2;
747  else if (!strcmp (p, "-Wimplicit-function-declaration"))
748    mesg_implicit_function_declaration = 1;
749  else if (!strcmp (p, "-Wno-implicit-function-declaration"))
750    mesg_implicit_function_declaration = 0;
751  else if (!strcmp (p, "-Wimplicit-int"))
752    warn_implicit_int = 1;
753  else if (!strcmp (p, "-Wno-implicit-int"))
754    warn_implicit_int = 0;
755  else if (!strcmp (p, "-Wimplicit"))
756    {
757      warn_implicit_int = 1;
758      if (mesg_implicit_function_declaration != 2)
759        mesg_implicit_function_declaration = 1;
760    }
761  else if (!strcmp (p, "-Wno-implicit"))
762    warn_implicit_int = 0, mesg_implicit_function_declaration = 0;
763  else if (!strcmp (p, "-Wlong-long"))
764    warn_long_long = 1;
765  else if (!strcmp (p, "-Wno-long-long"))
766    warn_long_long = 0;
767  else if (!strcmp (p, "-Wwrite-strings"))
768    flag_const_strings = 1;
769  else if (!strcmp (p, "-Wno-write-strings"))
770    flag_const_strings = 0;
771  else if (!strcmp (p, "-Wcast-qual"))
772    warn_cast_qual = 1;
773  else if (!strcmp (p, "-Wno-cast-qual"))
774    warn_cast_qual = 0;
775  else if (!strcmp (p, "-Wbad-function-cast"))
776    warn_bad_function_cast = 1;
777  else if (!strcmp (p, "-Wno-bad-function-cast"))
778    warn_bad_function_cast = 0;
779  else if (!strcmp (p, "-Wmissing-noreturn"))
780    warn_missing_noreturn = 1;
781  else if (!strcmp (p, "-Wno-missing-noreturn"))
782    warn_missing_noreturn = 0;
783  else if (!strcmp (p, "-Wpointer-arith"))
784    warn_pointer_arith = 1;
785  else if (!strcmp (p, "-Wno-pointer-arith"))
786    warn_pointer_arith = 0;
787  else if (!strcmp (p, "-Wstrict-prototypes"))
788    warn_strict_prototypes = 1;
789  else if (!strcmp (p, "-Wno-strict-prototypes"))
790    warn_strict_prototypes = 0;
791  else if (!strcmp (p, "-Wmissing-prototypes"))
792    warn_missing_prototypes = 1;
793  else if (!strcmp (p, "-Wno-missing-prototypes"))
794    warn_missing_prototypes = 0;
795  else if (!strcmp (p, "-Wmissing-declarations"))
796    warn_missing_declarations = 1;
797  else if (!strcmp (p, "-Wno-missing-declarations"))
798    warn_missing_declarations = 0;
799  else if (!strcmp (p, "-Wredundant-decls"))
800    warn_redundant_decls = 1;
801  else if (!strcmp (p, "-Wno-redundant-decls"))
802    warn_redundant_decls = 0;
803  else if (!strcmp (p, "-Wnested-externs"))
804    warn_nested_externs = 1;
805  else if (!strcmp (p, "-Wno-nested-externs"))
806    warn_nested_externs = 0;
807  else if (!strcmp (p, "-Wtraditional"))
808    warn_traditional = 1;
809  else if (!strcmp (p, "-Wno-traditional"))
810    warn_traditional = 0;
811  else if (!strcmp (p, "-Wformat"))
812    warn_format = 1;
813  else if (!strcmp (p, "-Wno-format"))
814    warn_format = 0;
815  else if (!strcmp (p, "-Wchar-subscripts"))
816    warn_char_subscripts = 1;
817  else if (!strcmp (p, "-Wno-char-subscripts"))
818    warn_char_subscripts = 0;
819  else if (!strcmp (p, "-Wconversion"))
820    warn_conversion = 1;
821  else if (!strcmp (p, "-Wno-conversion"))
822    warn_conversion = 0;
823  else if (!strcmp (p, "-Wparentheses"))
824    warn_parentheses = 1;
825  else if (!strcmp (p, "-Wno-parentheses"))
826    warn_parentheses = 0;
827  else if (!strcmp (p, "-Wreturn-type"))
828    warn_return_type = 1;
829  else if (!strcmp (p, "-Wno-return-type"))
830    warn_return_type = 0;
831  else if (!strcmp (p, "-Wcomment"))
832    ; /* cpp handles this one.  */
833  else if (!strcmp (p, "-Wno-comment"))
834    ; /* cpp handles this one.  */
835  else if (!strcmp (p, "-Wcomments"))
836    ; /* cpp handles this one.  */
837  else if (!strcmp (p, "-Wno-comments"))
838    ; /* cpp handles this one.  */
839  else if (!strcmp (p, "-Wtrigraphs"))
840    ; /* cpp handles this one.  */
841  else if (!strcmp (p, "-Wno-trigraphs"))
842    ; /* cpp handles this one.  */
843  else if (!strcmp (p, "-Wundef"))
844    ; /* cpp handles this one.  */
845  else if (!strcmp (p, "-Wno-undef"))
846    ; /* cpp handles this one.  */
847  else if (!strcmp (p, "-Wimport"))
848    ; /* cpp handles this one.  */
849  else if (!strcmp (p, "-Wno-import"))
850    ; /* cpp handles this one.  */
851  else if (!strcmp (p, "-Wmissing-braces"))
852    warn_missing_braces = 1;
853  else if (!strcmp (p, "-Wno-missing-braces"))
854    warn_missing_braces = 0;
855  else if (!strcmp (p, "-Wmain"))
856    warn_main = 1;
857  else if (!strcmp (p, "-Wno-main"))
858    warn_main = -1;
859  else if (!strcmp (p, "-Wsign-compare"))
860    warn_sign_compare = 1;
861  else if (!strcmp (p, "-Wno-sign-compare"))
862    warn_sign_compare = 0;
863  else if (!strcmp (p, "-Wmultichar"))
864    warn_multichar = 1;
865  else if (!strcmp (p, "-Wno-multichar"))
866    warn_multichar = 0;
867  else if (!strcmp (p, "-Wunknown-pragmas"))
868    /* Set to greater than 1, so that even unknown pragmas in system
869       headers will be warned about.  */
870    warn_unknown_pragmas = 2;
871  else if (!strcmp (p, "-Wno-unknown-pragmas"))
872    warn_unknown_pragmas = 0;
873  else if (!strcmp (p, "-Wall"))
874    {
875      /* We save the value of warn_uninitialized, since if they put
876	 -Wuninitialized on the command line, we need to generate a
877	 warning about not using it without also specifying -O.  */
878      if (warn_uninitialized != 1)
879	warn_uninitialized = 2;
880      warn_implicit_int = 1;
881      mesg_implicit_function_declaration = 1;
882      warn_return_type = 1;
883      warn_unused = 1;
884      warn_switch = 1;
885      warn_format = 1;
886      warn_char_subscripts = 1;
887      warn_parentheses = 1;
888      warn_missing_braces = 1;
889      /* We set this to 2 here, but 1 in -Wmain, so -ffreestanding can turn
890	 it off only if it's not explicit.  */
891      warn_main = 2;
892      /* Only warn about unknown pragmas that are not in system headers.  */
893      warn_unknown_pragmas = 1;
894    }
895  else
896    return strings_processed;
897
898  return 1;
899}
900
901/* Hooks for print_node.  */
902
903void
904print_lang_decl (file, node, indent)
905     FILE *file ATTRIBUTE_UNUSED;
906     tree node ATTRIBUTE_UNUSED;
907     int indent ATTRIBUTE_UNUSED;
908{
909}
910
911void
912print_lang_type (file, node, indent)
913     FILE *file ATTRIBUTE_UNUSED;
914     tree node ATTRIBUTE_UNUSED;
915     int indent ATTRIBUTE_UNUSED;
916{
917}
918
919void
920print_lang_identifier (file, node, indent)
921     FILE *file;
922     tree node;
923     int indent;
924{
925  print_node (file, "global", IDENTIFIER_GLOBAL_VALUE (node), indent + 4);
926  print_node (file, "local", IDENTIFIER_LOCAL_VALUE (node), indent + 4);
927  print_node (file, "label", IDENTIFIER_LABEL_VALUE (node), indent + 4);
928  print_node (file, "implicit", IDENTIFIER_IMPLICIT_DECL (node), indent + 4);
929  print_node (file, "error locus", IDENTIFIER_ERROR_LOCUS (node), indent + 4);
930  print_node (file, "limbo value", IDENTIFIER_LIMBO_VALUE (node), indent + 4);
931}
932
933/* Hook called at end of compilation to assume 1 elt
934   for a top-level array decl that wasn't complete before.  */
935
936void
937finish_incomplete_decl (decl)
938     tree decl;
939{
940  if (TREE_CODE (decl) == VAR_DECL)
941    {
942      tree type = TREE_TYPE (decl);
943      if (type != error_mark_node
944	  && TREE_CODE (type) == ARRAY_TYPE
945	  && TYPE_DOMAIN (type) == 0)
946	{
947	  if (! DECL_EXTERNAL (decl))
948	    warning_with_decl (decl, "array `%s' assumed to have one element");
949
950	  complete_array_type (type, NULL_TREE, 1);
951
952	  layout_decl (decl, 0);
953	}
954    }
955}
956
957/* Create a new `struct binding_level'.  */
958
959static
960struct binding_level *
961make_binding_level ()
962{
963  /* NOSTRICT */
964  return (struct binding_level *) xmalloc (sizeof (struct binding_level));
965}
966
967/* Nonzero if we are currently in the global binding level.  */
968
969int
970global_bindings_p ()
971{
972  return current_binding_level == global_binding_level;
973}
974
975void
976keep_next_level ()
977{
978  keep_next_level_flag = 1;
979}
980
981/* Nonzero if the current level needs to have a BLOCK made.  */
982
983int
984kept_level_p ()
985{
986  return ((current_binding_level->keep_if_subblocks
987	   && current_binding_level->blocks != 0)
988	  || current_binding_level->keep
989	  || current_binding_level->names != 0
990	  || (current_binding_level->tags != 0
991	      && !current_binding_level->tag_transparent));
992}
993
994/* Identify this binding level as a level of parameters.
995   DEFINITION_FLAG is 1 for a definition, 0 for a declaration.
996   But it turns out there is no way to pass the right value for
997   DEFINITION_FLAG, so we ignore it.  */
998
999void
1000declare_parm_level (definition_flag)
1001     int definition_flag ATTRIBUTE_UNUSED;
1002{
1003  current_binding_level->parm_flag = 1;
1004}
1005
1006/* Nonzero if currently making parm declarations.  */
1007
1008int
1009in_parm_level_p ()
1010{
1011  return current_binding_level->parm_flag;
1012}
1013
1014/* Enter a new binding level.
1015   If TAG_TRANSPARENT is nonzero, do so only for the name space of variables,
1016   not for that of tags.  */
1017
1018void
1019pushlevel (tag_transparent)
1020     int tag_transparent;
1021{
1022  register struct binding_level *newlevel = NULL_BINDING_LEVEL;
1023
1024  /* If this is the top level of a function,
1025     just make sure that NAMED_LABELS is 0.  */
1026
1027  if (current_binding_level == global_binding_level)
1028    {
1029      named_labels = 0;
1030    }
1031
1032  /* Reuse or create a struct for this binding level.  */
1033
1034  if (free_binding_level)
1035    {
1036      newlevel = free_binding_level;
1037      free_binding_level = free_binding_level->level_chain;
1038    }
1039  else
1040    {
1041      newlevel = make_binding_level ();
1042    }
1043
1044  /* Add this level to the front of the chain (stack) of levels that
1045     are active.  */
1046
1047  *newlevel = clear_binding_level;
1048  newlevel->tag_transparent
1049    = (tag_transparent
1050       || (current_binding_level
1051	   ? current_binding_level->subblocks_tag_transparent
1052	   : 0));
1053  newlevel->level_chain = current_binding_level;
1054  current_binding_level = newlevel;
1055  newlevel->keep = keep_next_level_flag;
1056  keep_next_level_flag = 0;
1057  newlevel->keep_if_subblocks = keep_next_if_subblocks;
1058  keep_next_if_subblocks = 0;
1059}
1060
1061/* Clear the limbo values of all identifiers defined in BLOCK or a subblock. */
1062
1063static void
1064clear_limbo_values (block)
1065     tree block;
1066{
1067  tree tem;
1068
1069  for (tem = BLOCK_VARS (block); tem; tem = TREE_CHAIN (tem))
1070    if (DECL_NAME (tem) != 0)
1071      IDENTIFIER_LIMBO_VALUE (DECL_NAME (tem)) = 0;
1072
1073  for (tem = BLOCK_SUBBLOCKS (block); tem; tem = TREE_CHAIN (tem))
1074    clear_limbo_values (tem);
1075}
1076
1077/* Exit a binding level.
1078   Pop the level off, and restore the state of the identifier-decl mappings
1079   that were in effect when this level was entered.
1080
1081   If KEEP is nonzero, this level had explicit declarations, so
1082   and create a "block" (a BLOCK node) for the level
1083   to record its declarations and subblocks for symbol table output.
1084
1085   If FUNCTIONBODY is nonzero, this level is the body of a function,
1086   so create a block as if KEEP were set and also clear out all
1087   label names.
1088
1089   If REVERSE is nonzero, reverse the order of decls before putting
1090   them into the BLOCK.  */
1091
1092tree
1093poplevel (keep, reverse, functionbody)
1094     int keep;
1095     int reverse;
1096     int functionbody;
1097{
1098  register tree link;
1099  /* The chain of decls was accumulated in reverse order.
1100     Put it into forward order, just for cleanliness.  */
1101  tree decls;
1102  tree tags = current_binding_level->tags;
1103  tree subblocks = current_binding_level->blocks;
1104  tree block = 0;
1105  tree decl;
1106  int block_previously_created;
1107
1108  keep |= current_binding_level->keep;
1109
1110  /* This warning is turned off because it causes warnings for
1111     declarations like `extern struct foo *x'.  */
1112#if 0
1113  /* Warn about incomplete structure types in this level.  */
1114  for (link = tags; link; link = TREE_CHAIN (link))
1115    if (TYPE_SIZE (TREE_VALUE (link)) == 0)
1116      {
1117	tree type = TREE_VALUE (link);
1118	tree type_name = TYPE_NAME (type);
1119	char *id = IDENTIFIER_POINTER (TREE_CODE (type_name) == IDENTIFIER_NODE
1120				       ? type_name
1121				       : DECL_NAME (type_name));
1122	switch (TREE_CODE (type))
1123	  {
1124	  case RECORD_TYPE:
1125	    error ("`struct %s' incomplete in scope ending here", id);
1126	    break;
1127	  case UNION_TYPE:
1128	    error ("`union %s' incomplete in scope ending here", id);
1129	    break;
1130	  case ENUMERAL_TYPE:
1131	    error ("`enum %s' incomplete in scope ending here", id);
1132	    break;
1133	  }
1134      }
1135#endif /* 0 */
1136
1137  /* Get the decls in the order they were written.
1138     Usually current_binding_level->names is in reverse order.
1139     But parameter decls were previously put in forward order.  */
1140
1141  if (reverse)
1142    current_binding_level->names
1143      = decls = nreverse (current_binding_level->names);
1144  else
1145    decls = current_binding_level->names;
1146
1147  /* Output any nested inline functions within this block
1148     if they weren't already output.  */
1149
1150  for (decl = decls; decl; decl = TREE_CHAIN (decl))
1151    if (TREE_CODE (decl) == FUNCTION_DECL
1152	&& ! TREE_ASM_WRITTEN (decl)
1153	&& DECL_INITIAL (decl) != 0
1154	&& TREE_ADDRESSABLE (decl))
1155      {
1156	/* If this decl was copied from a file-scope decl
1157	   on account of a block-scope extern decl,
1158	   propagate TREE_ADDRESSABLE to the file-scope decl.
1159
1160	   DECL_ABSTRACT_ORIGIN can be set to itself if warn_return_type is
1161	   true, since then the decl goes through save_for_inline_copying.  */
1162	if (DECL_ABSTRACT_ORIGIN (decl) != 0
1163	    && DECL_ABSTRACT_ORIGIN (decl) != decl)
1164	  TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1;
1165	else if (DECL_SAVED_INSNS (decl) != 0)
1166	  {
1167	    push_function_context ();
1168	    output_inline_function (decl);
1169	    pop_function_context ();
1170	  }
1171      }
1172
1173  /* If there were any declarations or structure tags in that level,
1174     or if this level is a function body,
1175     create a BLOCK to record them for the life of this function.  */
1176
1177  block = 0;
1178  block_previously_created = (current_binding_level->this_block != 0);
1179  if (block_previously_created)
1180    block = current_binding_level->this_block;
1181  else if (keep || functionbody
1182	   || (current_binding_level->keep_if_subblocks && subblocks != 0))
1183    block = make_node (BLOCK);
1184  if (block != 0)
1185    {
1186      BLOCK_VARS (block) = decls;
1187      BLOCK_TYPE_TAGS (block) = tags;
1188      BLOCK_SUBBLOCKS (block) = subblocks;
1189      remember_end_note (block);
1190    }
1191
1192  /* In each subblock, record that this is its superior.  */
1193
1194  for (link = subblocks; link; link = TREE_CHAIN (link))
1195    BLOCK_SUPERCONTEXT (link) = block;
1196
1197  /* Clear out the meanings of the local variables of this level.  */
1198
1199  for (link = decls; link; link = TREE_CHAIN (link))
1200    {
1201      if (DECL_NAME (link) != 0)
1202	{
1203	  /* If the ident. was used or addressed via a local extern decl,
1204	     don't forget that fact.  */
1205	  if (DECL_EXTERNAL (link))
1206	    {
1207	      if (TREE_USED (link))
1208		TREE_USED (DECL_NAME (link)) = 1;
1209	      if (TREE_ADDRESSABLE (link))
1210		TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1211	    }
1212	  IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0;
1213	}
1214    }
1215
1216  /* Restore all name-meanings of the outer levels
1217     that were shadowed by this level.  */
1218
1219  for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1220    IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1221
1222  /* If the level being exited is the top level of a function,
1223     check over all the labels, and clear out the current
1224     (function local) meanings of their names.  */
1225
1226  if (functionbody)
1227    {
1228      clear_limbo_values (block);
1229
1230      /* If this is the top level block of a function,
1231	 the vars are the function's parameters.
1232	 Don't leave them in the BLOCK because they are
1233	 found in the FUNCTION_DECL instead.  */
1234
1235      BLOCK_VARS (block) = 0;
1236
1237      /* Clear out the definitions of all label names,
1238	 since their scopes end here,
1239	 and add them to BLOCK_VARS.  */
1240
1241      for (link = named_labels; link; link = TREE_CHAIN (link))
1242	{
1243	  register tree label = TREE_VALUE (link);
1244
1245	  if (DECL_INITIAL (label) == 0)
1246	    {
1247	      error_with_decl (label, "label `%s' used but not defined");
1248	      /* Avoid crashing later.  */
1249	      define_label (input_filename, lineno,
1250			    DECL_NAME (label));
1251	    }
1252	  else if (warn_unused && !TREE_USED (label))
1253	    warning_with_decl (label, "label `%s' defined but not used");
1254	  IDENTIFIER_LABEL_VALUE (DECL_NAME (label)) = 0;
1255
1256	  /* Put the labels into the "variables" of the
1257	     top-level block, so debugger can see them.  */
1258	  TREE_CHAIN (label) = BLOCK_VARS (block);
1259	  BLOCK_VARS (block) = label;
1260	}
1261    }
1262
1263  /* Pop the current level, and free the structure for reuse.  */
1264
1265  {
1266    register struct binding_level *level = current_binding_level;
1267    current_binding_level = current_binding_level->level_chain;
1268
1269    level->level_chain = free_binding_level;
1270    free_binding_level = level;
1271  }
1272
1273  /* Dispose of the block that we just made inside some higher level.  */
1274  if (functionbody)
1275    DECL_INITIAL (current_function_decl) = block;
1276  else if (block)
1277    {
1278      if (!block_previously_created)
1279        current_binding_level->blocks
1280          = chainon (current_binding_level->blocks, block);
1281    }
1282  /* If we did not make a block for the level just exited,
1283     any blocks made for inner levels
1284     (since they cannot be recorded as subblocks in that level)
1285     must be carried forward so they will later become subblocks
1286     of something else.  */
1287  else if (subblocks)
1288    current_binding_level->blocks
1289      = chainon (current_binding_level->blocks, subblocks);
1290
1291  /* Set the TYPE_CONTEXTs for all of the tagged types belonging to this
1292     binding contour so that they point to the appropriate construct, i.e.
1293     either to the current FUNCTION_DECL node, or else to the BLOCK node
1294     we just constructed.
1295
1296     Note that for tagged types whose scope is just the formal parameter
1297     list for some function type specification, we can't properly set
1298     their TYPE_CONTEXTs here, because we don't have a pointer to the
1299     appropriate FUNCTION_TYPE node readily available to us.  For those
1300     cases, the TYPE_CONTEXTs of the relevant tagged type nodes get set
1301     in `grokdeclarator' as soon as we have created the FUNCTION_TYPE
1302     node which will represent the "scope" for these "parameter list local"
1303     tagged types.
1304  */
1305
1306  if (functionbody)
1307    for (link = tags; link; link = TREE_CHAIN (link))
1308      TYPE_CONTEXT (TREE_VALUE (link)) = current_function_decl;
1309  else if (block)
1310    for (link = tags; link; link = TREE_CHAIN (link))
1311      TYPE_CONTEXT (TREE_VALUE (link)) = block;
1312
1313  if (block)
1314    TREE_USED (block) = 1;
1315  return block;
1316}
1317
1318/* Delete the node BLOCK from the current binding level.
1319   This is used for the block inside a stmt expr ({...})
1320   so that the block can be reinserted where appropriate.  */
1321
1322void
1323delete_block (block)
1324     tree block;
1325{
1326  tree t;
1327  if (current_binding_level->blocks == block)
1328    current_binding_level->blocks = TREE_CHAIN (block);
1329  for (t = current_binding_level->blocks; t;)
1330    {
1331      if (TREE_CHAIN (t) == block)
1332	TREE_CHAIN (t) = TREE_CHAIN (block);
1333      else
1334	t = TREE_CHAIN (t);
1335    }
1336  TREE_CHAIN (block) = NULL;
1337  /* Clear TREE_USED which is always set by poplevel.
1338     The flag is set again if insert_block is called.  */
1339  TREE_USED (block) = 0;
1340}
1341
1342/* Insert BLOCK at the end of the list of subblocks of the
1343   current binding level.  This is used when a BIND_EXPR is expanded,
1344   to handle the BLOCK node inside the BIND_EXPR.  */
1345
1346void
1347insert_block (block)
1348     tree block;
1349{
1350  TREE_USED (block) = 1;
1351  current_binding_level->blocks
1352    = chainon (current_binding_level->blocks, block);
1353}
1354
1355/* Set the BLOCK node for the innermost scope
1356   (the one we are currently in).  */
1357
1358void
1359set_block (block)
1360     register tree block;
1361{
1362  current_binding_level->this_block = block;
1363}
1364
1365void
1366push_label_level ()
1367{
1368  register struct binding_level *newlevel;
1369
1370  /* Reuse or create a struct for this binding level.  */
1371
1372  if (free_binding_level)
1373    {
1374      newlevel = free_binding_level;
1375      free_binding_level = free_binding_level->level_chain;
1376    }
1377  else
1378    {
1379      newlevel = make_binding_level ();
1380    }
1381
1382  /* Add this level to the front of the chain (stack) of label levels.  */
1383
1384  newlevel->level_chain = label_level_chain;
1385  label_level_chain = newlevel;
1386
1387  newlevel->names = named_labels;
1388  newlevel->shadowed = shadowed_labels;
1389  named_labels = 0;
1390  shadowed_labels = 0;
1391}
1392
1393void
1394pop_label_level ()
1395{
1396  register struct binding_level *level = label_level_chain;
1397  tree link, prev;
1398
1399  /* Clear out the definitions of the declared labels in this level.
1400     Leave in the list any ordinary, non-declared labels.  */
1401  for (link = named_labels, prev = 0; link;)
1402    {
1403      if (C_DECLARED_LABEL_FLAG (TREE_VALUE (link)))
1404	{
1405	  if (DECL_SOURCE_LINE (TREE_VALUE (link)) == 0)
1406	    {
1407	      error_with_decl (TREE_VALUE (link),
1408			       "label `%s' used but not defined");
1409	      /* Avoid crashing later.  */
1410	      define_label (input_filename, lineno,
1411			    DECL_NAME (TREE_VALUE (link)));
1412	    }
1413	  else if (warn_unused && !TREE_USED (TREE_VALUE (link)))
1414	    warning_with_decl (TREE_VALUE (link),
1415			       "label `%s' defined but not used");
1416	  IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link))) = 0;
1417
1418	  /* Delete this element from the list.  */
1419	  link = TREE_CHAIN (link);
1420	  if (prev)
1421	    TREE_CHAIN (prev) = link;
1422	  else
1423	    named_labels = link;
1424	}
1425      else
1426	{
1427	  prev = link;
1428	  link = TREE_CHAIN (link);
1429	}
1430    }
1431
1432  /* Bring back all the labels that were shadowed.  */
1433  for (link = shadowed_labels; link; link = TREE_CHAIN (link))
1434    if (DECL_NAME (TREE_VALUE (link)) != 0)
1435      IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link)))
1436	= TREE_VALUE (link);
1437
1438  named_labels = chainon (named_labels, level->names);
1439  shadowed_labels = level->shadowed;
1440
1441  /* Pop the current level, and free the structure for reuse.  */
1442  label_level_chain = label_level_chain->level_chain;
1443  level->level_chain = free_binding_level;
1444  free_binding_level = level;
1445}
1446
1447/* Push a definition or a declaration of struct, union or enum tag "name".
1448   "type" should be the type node.
1449   We assume that the tag "name" is not already defined.
1450
1451   Note that the definition may really be just a forward reference.
1452   In that case, the TYPE_SIZE will be zero.  */
1453
1454void
1455pushtag (name, type)
1456     tree name, type;
1457{
1458  register struct binding_level *b;
1459
1460  /* Find the proper binding level for this type tag.  */
1461
1462  for (b = current_binding_level; b->tag_transparent; b = b->level_chain)
1463    continue;
1464
1465  if (name)
1466    {
1467      /* Record the identifier as the type's name if it has none.  */
1468
1469      if (TYPE_NAME (type) == 0)
1470	TYPE_NAME (type) = name;
1471    }
1472
1473  if (b == global_binding_level)
1474    b->tags = perm_tree_cons (name, type, b->tags);
1475  else
1476    b->tags = saveable_tree_cons (name, type, b->tags);
1477
1478  /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE will be the
1479     tagged type we just added to the current binding level.  This fake
1480     NULL-named TYPE_DECL node helps dwarfout.c to know when it needs
1481     to output a representation of a tagged type, and it also gives
1482     us a convenient place to record the "scope start" address for the
1483     tagged type.  */
1484
1485  TYPE_STUB_DECL (type) = pushdecl (build_decl (TYPE_DECL, NULL_TREE, type));
1486
1487  /* An approximation for now, so we can tell this is a function-scope tag.
1488     This will be updated in poplevel.  */
1489  TYPE_CONTEXT (type) = DECL_CONTEXT (TYPE_STUB_DECL (type));
1490}
1491
1492/* Handle when a new declaration NEWDECL
1493   has the same name as an old one OLDDECL
1494   in the same binding contour.
1495   Prints an error message if appropriate.
1496
1497   If safely possible, alter OLDDECL to look like NEWDECL, and return 1.
1498   Otherwise, return 0.
1499
1500   When DIFFERENT_BINDING_LEVEL is true, NEWDECL is an external declaration,
1501   and OLDDECL is in an outer binding level and should thus not be changed.  */
1502
1503static int
1504duplicate_decls (newdecl, olddecl, different_binding_level)
1505     register tree newdecl, olddecl;
1506     int different_binding_level;
1507{
1508  int types_match = comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
1509  int new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL
1510			   && DECL_INITIAL (newdecl) != 0);
1511  tree oldtype = TREE_TYPE (olddecl);
1512  tree newtype = TREE_TYPE (newdecl);
1513  int errmsg = 0;
1514
1515  if (TREE_CODE_CLASS (TREE_CODE (olddecl)) == 'd')
1516    DECL_MACHINE_ATTRIBUTES (newdecl)
1517      =  merge_machine_decl_attributes (olddecl, newdecl);
1518
1519  if (TREE_CODE (newtype) == ERROR_MARK
1520      || TREE_CODE (oldtype) == ERROR_MARK)
1521    types_match = 0;
1522
1523  /* New decl is completely inconsistent with the old one =>
1524     tell caller to replace the old one.
1525     This is always an error except in the case of shadowing a builtin.  */
1526  if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
1527    {
1528      if (TREE_CODE (olddecl) == FUNCTION_DECL
1529	  && (DECL_BUILT_IN (olddecl)
1530	      || DECL_BUILT_IN_NONANSI (olddecl)))
1531	{
1532	  /* If you declare a built-in or predefined function name as static,
1533	     the old definition is overridden,
1534	     but optionally warn this was a bad choice of name.  */
1535	  if (!TREE_PUBLIC (newdecl))
1536	    {
1537	      if (!warn_shadow)
1538		;
1539	      else if (DECL_BUILT_IN (olddecl))
1540		warning_with_decl (newdecl, "shadowing built-in function `%s'");
1541	      else
1542		warning_with_decl (newdecl, "shadowing library function `%s'");
1543	    }
1544	  /* Likewise, if the built-in is not ansi, then programs can
1545	     override it even globally without an error.  */
1546	  else if (! DECL_BUILT_IN (olddecl))
1547	    warning_with_decl (newdecl,
1548			       "library function `%s' declared as non-function");
1549
1550	  else if (DECL_BUILT_IN_NONANSI (olddecl))
1551	    warning_with_decl (newdecl,
1552			       "built-in function `%s' declared as non-function");
1553	  else
1554	    warning_with_decl (newdecl,
1555			     "built-in function `%s' declared as non-function");
1556	}
1557      else
1558	{
1559	  error_with_decl (newdecl, "`%s' redeclared as different kind of symbol");
1560	  error_with_decl (olddecl, "previous declaration of `%s'");
1561	}
1562
1563      return 0;
1564    }
1565
1566  /* For real parm decl following a forward decl,
1567     return 1 so old decl will be reused.  */
1568  if (types_match && TREE_CODE (newdecl) == PARM_DECL
1569      && TREE_ASM_WRITTEN (olddecl) && ! TREE_ASM_WRITTEN (newdecl))
1570    return 1;
1571
1572  /* The new declaration is the same kind of object as the old one.
1573     The declarations may partially match.  Print warnings if they don't
1574     match enough.  Ultimately, copy most of the information from the new
1575     decl to the old one, and keep using the old one.  */
1576
1577  if (flag_traditional && TREE_CODE (newdecl) == FUNCTION_DECL
1578      && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (newdecl)) == olddecl
1579      && DECL_INITIAL (olddecl) == 0)
1580    /* If -traditional, avoid error for redeclaring fcn
1581       after implicit decl.  */
1582    ;
1583  else if (TREE_CODE (olddecl) == FUNCTION_DECL
1584	   && DECL_BUILT_IN (olddecl))
1585    {
1586      /* A function declaration for a built-in function.  */
1587      if (!TREE_PUBLIC (newdecl))
1588	{
1589	  /* If you declare a built-in function name as static, the
1590	     built-in definition is overridden,
1591	     but optionally warn this was a bad choice of name.  */
1592	  if (warn_shadow)
1593	    warning_with_decl (newdecl, "shadowing built-in function `%s'");
1594	  /* Discard the old built-in function.  */
1595	  return 0;
1596	}
1597      else if (!types_match)
1598	{
1599          /* Accept the return type of the new declaration if same modes.  */
1600	  tree oldreturntype = TREE_TYPE (oldtype);
1601	  tree newreturntype = TREE_TYPE (newtype);
1602
1603	  /* Make sure we put the new type in the same obstack as the old ones.
1604	     If the old types are not both in the same obstack, use the
1605	     permanent one.  */
1606	  if (TYPE_OBSTACK (oldtype) == TYPE_OBSTACK (newtype))
1607	    push_obstacks (TYPE_OBSTACK (oldtype), TYPE_OBSTACK (oldtype));
1608	  else
1609	    {
1610	      push_obstacks_nochange ();
1611	      end_temporary_allocation ();
1612	    }
1613
1614          if (TYPE_MODE (oldreturntype) == TYPE_MODE (newreturntype))
1615            {
1616	      /* Function types may be shared, so we can't just modify
1617		 the return type of olddecl's function type.  */
1618	      tree trytype
1619		= build_function_type (newreturntype,
1620				       TYPE_ARG_TYPES (oldtype));
1621
1622              types_match = comptypes (newtype, trytype);
1623	      if (types_match)
1624		oldtype = trytype;
1625	    }
1626	  /* Accept harmless mismatch in first argument type also.
1627	     This is for ffs.  */
1628	  if (TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != 0
1629	      && TYPE_ARG_TYPES (oldtype) != 0
1630	      && TREE_VALUE (TYPE_ARG_TYPES (newtype)) != 0
1631	      && TREE_VALUE (TYPE_ARG_TYPES (oldtype)) != 0
1632	      && (TYPE_MODE (TREE_VALUE (TYPE_ARG_TYPES (newtype)))
1633		  == TYPE_MODE (TREE_VALUE (TYPE_ARG_TYPES (oldtype)))))
1634	    {
1635	      /* Function types may be shared, so we can't just modify
1636		 the return type of olddecl's function type.  */
1637	      tree trytype
1638		= build_function_type (TREE_TYPE (oldtype),
1639				       tree_cons (NULL_TREE,
1640						  TREE_VALUE (TYPE_ARG_TYPES (newtype)),
1641						  TREE_CHAIN (TYPE_ARG_TYPES (oldtype))));
1642
1643              types_match = comptypes (newtype, trytype);
1644	      if (types_match)
1645		oldtype = trytype;
1646	    }
1647	  if (! different_binding_level)
1648	    TREE_TYPE (olddecl) = oldtype;
1649
1650	  pop_obstacks ();
1651	}
1652      if (!types_match)
1653	{
1654	  /* If types don't match for a built-in, throw away the built-in.  */
1655	  warning_with_decl (newdecl, "conflicting types for built-in function `%s'");
1656	  return 0;
1657	}
1658    }
1659  else if (TREE_CODE (olddecl) == FUNCTION_DECL
1660	   && DECL_SOURCE_LINE (olddecl) == 0)
1661    {
1662      /* A function declaration for a predeclared function
1663	 that isn't actually built in.  */
1664      if (!TREE_PUBLIC (newdecl))
1665	{
1666	  /* If you declare it as static, the
1667	     default definition is overridden.  */
1668	  return 0;
1669	}
1670      else if (!types_match)
1671	{
1672	  /* If the types don't match, preserve volatility indication.
1673	     Later on, we will discard everything else about the
1674	     default declaration.  */
1675	  TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
1676	}
1677    }
1678  /* Permit char *foo () to match void *foo (...) if not pedantic,
1679     if one of them came from a system header file.  */
1680  else if (!types_match
1681	   && TREE_CODE (olddecl) == FUNCTION_DECL
1682	   && TREE_CODE (newdecl) == FUNCTION_DECL
1683	   && TREE_CODE (TREE_TYPE (oldtype)) == POINTER_TYPE
1684	   && TREE_CODE (TREE_TYPE (newtype)) == POINTER_TYPE
1685	   && (DECL_IN_SYSTEM_HEADER (olddecl)
1686	       || DECL_IN_SYSTEM_HEADER (newdecl))
1687	   && ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (newtype))) == void_type_node
1688		&& TYPE_ARG_TYPES (oldtype) == 0
1689		&& self_promoting_args_p (TYPE_ARG_TYPES (newtype))
1690		&& TREE_TYPE (TREE_TYPE (oldtype)) == char_type_node)
1691	       ||
1692	       (TREE_TYPE (TREE_TYPE (newtype)) == char_type_node
1693		&& TYPE_ARG_TYPES (newtype) == 0
1694		&& self_promoting_args_p (TYPE_ARG_TYPES (oldtype))
1695		&& TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (oldtype))) == void_type_node)))
1696    {
1697      if (pedantic)
1698	pedwarn_with_decl (newdecl, "conflicting types for `%s'");
1699      /* Make sure we keep void * as ret type, not char *.  */
1700      if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (oldtype))) == void_type_node)
1701	TREE_TYPE (newdecl) = newtype = oldtype;
1702
1703      /* Set DECL_IN_SYSTEM_HEADER, so that if we see another declaration
1704	 we will come back here again.  */
1705      DECL_IN_SYSTEM_HEADER (newdecl) = 1;
1706    }
1707  else if (!types_match
1708	   /* Permit char *foo (int, ...); followed by char *foo ();
1709	      if not pedantic.  */
1710	   && ! (TREE_CODE (olddecl) == FUNCTION_DECL
1711		 && ! pedantic
1712		 /* Return types must still match.  */
1713		 && comptypes (TREE_TYPE (oldtype),
1714			       TREE_TYPE (newtype))
1715		 && TYPE_ARG_TYPES (newtype) == 0))
1716    {
1717      error_with_decl (newdecl, "conflicting types for `%s'");
1718      /* Check for function type mismatch
1719	 involving an empty arglist vs a nonempty one.  */
1720      if (TREE_CODE (olddecl) == FUNCTION_DECL
1721	  && comptypes (TREE_TYPE (oldtype),
1722			TREE_TYPE (newtype))
1723	  && ((TYPE_ARG_TYPES (oldtype) == 0
1724	       && DECL_INITIAL (olddecl) == 0)
1725	      ||
1726	      (TYPE_ARG_TYPES (newtype) == 0
1727	       && DECL_INITIAL (newdecl) == 0)))
1728	{
1729	  /* Classify the problem further.  */
1730	  register tree t = TYPE_ARG_TYPES (oldtype);
1731	  if (t == 0)
1732	    t = TYPE_ARG_TYPES (newtype);
1733	  for (; t; t = TREE_CHAIN (t))
1734	    {
1735	      register tree type = TREE_VALUE (t);
1736
1737	      if (TREE_CHAIN (t) == 0
1738		  && TYPE_MAIN_VARIANT (type) != void_type_node)
1739		{
1740		  error ("A parameter list with an ellipsis can't match an empty parameter name list declaration.");
1741		  break;
1742		}
1743
1744	      if (TYPE_MAIN_VARIANT (type) == float_type_node
1745		  || C_PROMOTING_INTEGER_TYPE_P (type))
1746		{
1747		  error ("An argument type that has a default promotion can't match an empty parameter name list declaration.");
1748		  break;
1749		}
1750	    }
1751	}
1752      error_with_decl (olddecl, "previous declaration of `%s'");
1753    }
1754  else
1755    {
1756      errmsg = redeclaration_error_message (newdecl, olddecl);
1757      if (errmsg)
1758	{
1759	  switch (errmsg)
1760	    {
1761	    case 1:
1762	      error_with_decl (newdecl, "redefinition of `%s'");
1763	      break;
1764	    case 2:
1765	      error_with_decl (newdecl, "redeclaration of `%s'");
1766	      break;
1767	    case 3:
1768	      error_with_decl (newdecl, "conflicting declarations of `%s'");
1769	      break;
1770	    default:
1771	      abort ();
1772	    }
1773
1774	  error_with_decl (olddecl,
1775			   ((DECL_INITIAL (olddecl)
1776			     && current_binding_level == global_binding_level)
1777			    ? "`%s' previously defined here"
1778			    : "`%s' previously declared here"));
1779	}
1780      else if (TREE_CODE (newdecl) == TYPE_DECL
1781               && (DECL_IN_SYSTEM_HEADER (olddecl)
1782                   || DECL_IN_SYSTEM_HEADER (newdecl)))
1783	{
1784	  warning_with_decl (newdecl, "redefinition of `%s'");
1785	  warning_with_decl
1786	    (olddecl,
1787	     ((DECL_INITIAL (olddecl)
1788	       && current_binding_level == global_binding_level)
1789	      ? "`%s' previously defined here"
1790	      : "`%s' previously declared here"));
1791	}
1792      else if (TREE_CODE (olddecl) == FUNCTION_DECL
1793	       && DECL_INITIAL (olddecl) != 0
1794	       && TYPE_ARG_TYPES (oldtype) == 0
1795	       && TYPE_ARG_TYPES (newtype) != 0
1796	       && TYPE_ACTUAL_ARG_TYPES (oldtype) != 0)
1797	{
1798	  register tree type, parm;
1799	  register int nargs;
1800	  /* Prototype decl follows defn w/o prototype.  */
1801
1802	  for (parm = TYPE_ACTUAL_ARG_TYPES (oldtype),
1803	       type = TYPE_ARG_TYPES (newtype),
1804	       nargs = 1;
1805	       ;
1806	       parm = TREE_CHAIN (parm), type = TREE_CHAIN (type), nargs++)
1807	    {
1808	      if (TYPE_MAIN_VARIANT (TREE_VALUE (parm)) == void_type_node
1809		  && TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node)
1810		{
1811		  warning_with_decl (newdecl, "prototype for `%s' follows");
1812		  warning_with_decl (olddecl, "non-prototype definition here");
1813		  break;
1814		}
1815	      if (TYPE_MAIN_VARIANT (TREE_VALUE (parm)) == void_type_node
1816		  || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node)
1817		{
1818		  error_with_decl (newdecl, "prototype for `%s' follows and number of arguments doesn't match");
1819		  error_with_decl (olddecl, "non-prototype definition here");
1820		  errmsg = 1;
1821		  break;
1822		}
1823	      /* Type for passing arg must be consistent
1824		 with that declared for the arg.  */
1825	      if (! comptypes (TREE_VALUE (parm), TREE_VALUE (type))
1826		  /* If -traditional, allow `unsigned int' instead of `int'
1827		     in the prototype.  */
1828		  && (! (flag_traditional
1829			 && TYPE_MAIN_VARIANT (TREE_VALUE (parm)) == integer_type_node
1830			 && TYPE_MAIN_VARIANT (TREE_VALUE (type)) == unsigned_type_node)))
1831		{
1832		  error_with_decl (newdecl,
1833				   "prototype for `%s' follows and argument %d doesn't match",
1834				   nargs);
1835		  error_with_decl (olddecl, "non-prototype definition here");
1836		  errmsg = 1;
1837		  break;
1838		}
1839	    }
1840	}
1841      /* Warn about mismatches in various flags.  */
1842      else
1843	{
1844	  /* Warn if function is now inline
1845	     but was previously declared not inline and has been called.  */
1846	  if (TREE_CODE (olddecl) == FUNCTION_DECL
1847	      && ! DECL_INLINE (olddecl) && DECL_INLINE (newdecl)
1848	      && TREE_USED (olddecl))
1849	    warning_with_decl (newdecl,
1850			       "`%s' declared inline after being called");
1851	  if (TREE_CODE (olddecl) == FUNCTION_DECL
1852	      && ! DECL_INLINE (olddecl) && DECL_INLINE (newdecl)
1853	      && DECL_INITIAL (olddecl) != 0)
1854	    warning_with_decl (newdecl,
1855			       "`%s' declared inline after its definition");
1856
1857	  /* If pedantic, warn when static declaration follows a non-static
1858	     declaration.  Otherwise, do so only for functions.  */
1859	  if ((pedantic || TREE_CODE (olddecl) == FUNCTION_DECL)
1860	      && TREE_PUBLIC (olddecl)
1861	      && !TREE_PUBLIC (newdecl))
1862	    warning_with_decl (newdecl, "static declaration for `%s' follows non-static");
1863
1864	  /* If warn_traditional, warn when a non-static function
1865	     declaration follows a static one. */
1866	  if (warn_traditional
1867	      && TREE_CODE (olddecl) == FUNCTION_DECL
1868	      && !TREE_PUBLIC (olddecl)
1869	      && TREE_PUBLIC (newdecl))
1870	    warning_with_decl (newdecl, "non-static declaration for `%s' follows static");
1871
1872	  /* Warn when const declaration follows a non-const
1873	     declaration, but not for functions.  */
1874	  if (TREE_CODE (olddecl) != FUNCTION_DECL
1875	      && !TREE_READONLY (olddecl)
1876	      && TREE_READONLY (newdecl))
1877	    warning_with_decl (newdecl, "const declaration for `%s' follows non-const");
1878	  /* These bits are logically part of the type, for variables.
1879	     But not for functions
1880	     (where qualifiers are not valid ANSI anyway).  */
1881	  else if (pedantic && TREE_CODE (olddecl) != FUNCTION_DECL
1882	      && (TREE_READONLY (newdecl) != TREE_READONLY (olddecl)
1883		  || TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl)))
1884	    pedwarn_with_decl (newdecl, "type qualifiers for `%s' conflict with previous decl");
1885	}
1886    }
1887
1888  /* Optionally warn about more than one declaration for the same name.  */
1889  if (errmsg == 0 && warn_redundant_decls && DECL_SOURCE_LINE (olddecl) != 0
1890      /* Don't warn about a function declaration
1891	 followed by a definition.  */
1892      && !(TREE_CODE (newdecl) == FUNCTION_DECL && DECL_INITIAL (newdecl) != 0
1893	   && DECL_INITIAL (olddecl) == 0)
1894      /* Don't warn about extern decl followed by (tentative) definition.  */
1895      && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl)))
1896    {
1897      warning_with_decl (newdecl, "redundant redeclaration of `%s' in same scope");
1898      warning_with_decl (olddecl, "previous declaration of `%s'");
1899    }
1900
1901  /* Copy all the DECL_... slots specified in the new decl
1902     except for any that we copy here from the old type.
1903
1904     Past this point, we don't change OLDTYPE and NEWTYPE
1905     even if we change the types of NEWDECL and OLDDECL.  */
1906
1907  if (types_match)
1908    {
1909      /* When copying info to olddecl, we store into write_olddecl
1910	 instead.  This allows us to avoid modifying olddecl when
1911	 different_binding_level is true.  */
1912      tree write_olddecl = different_binding_level ? newdecl : olddecl;
1913
1914      /* Make sure we put the new type in the same obstack as the old ones.
1915	 If the old types are not both in the same obstack, use the permanent
1916	 one.  */
1917      if (TYPE_OBSTACK (oldtype) == TYPE_OBSTACK (newtype))
1918	push_obstacks (TYPE_OBSTACK (oldtype), TYPE_OBSTACK (oldtype));
1919      else
1920	{
1921	  push_obstacks_nochange ();
1922	  end_temporary_allocation ();
1923	}
1924
1925      /* Merge the data types specified in the two decls.  */
1926      if (TREE_CODE (newdecl) != FUNCTION_DECL || !DECL_BUILT_IN (olddecl))
1927	{
1928	  if (different_binding_level)
1929	    TREE_TYPE (newdecl)
1930	      = build_type_attribute_variant
1931		(newtype,
1932		 merge_attributes (TYPE_ATTRIBUTES (newtype),
1933				   TYPE_ATTRIBUTES (oldtype)));
1934	  else
1935	    TREE_TYPE (newdecl)
1936	      = TREE_TYPE (olddecl)
1937		= common_type (newtype, oldtype);
1938	}
1939
1940      /* Lay the type out, unless already done.  */
1941      if (oldtype != TREE_TYPE (newdecl))
1942	{
1943	  if (TREE_TYPE (newdecl) != error_mark_node)
1944	    layout_type (TREE_TYPE (newdecl));
1945	  if (TREE_CODE (newdecl) != FUNCTION_DECL
1946	      && TREE_CODE (newdecl) != TYPE_DECL
1947	      && TREE_CODE (newdecl) != CONST_DECL)
1948	    layout_decl (newdecl, 0);
1949	}
1950      else
1951	{
1952	  /* Since the type is OLDDECL's, make OLDDECL's size go with.  */
1953	  DECL_SIZE (newdecl) = DECL_SIZE (olddecl);
1954	  DECL_MODE (newdecl) = DECL_MODE (olddecl);
1955	  if (TREE_CODE (olddecl) != FUNCTION_DECL)
1956	    if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl))
1957	      DECL_ALIGN (newdecl) = DECL_ALIGN (olddecl);
1958	}
1959
1960      /* Keep the old rtl since we can safely use it.  */
1961      DECL_RTL (newdecl) = DECL_RTL (olddecl);
1962
1963      /* Merge the type qualifiers.  */
1964      if (DECL_BUILT_IN_NONANSI (olddecl) && TREE_THIS_VOLATILE (olddecl)
1965	  && !TREE_THIS_VOLATILE (newdecl))
1966	TREE_THIS_VOLATILE (write_olddecl) = 0;
1967      if (TREE_READONLY (newdecl))
1968	TREE_READONLY (write_olddecl) = 1;
1969      if (TREE_THIS_VOLATILE (newdecl))
1970	{
1971	  TREE_THIS_VOLATILE (write_olddecl) = 1;
1972	  if (TREE_CODE (newdecl) == VAR_DECL)
1973	    make_var_volatile (newdecl);
1974	}
1975
1976      /* Keep source location of definition rather than declaration.  */
1977      /* When called with different_binding_level set, keep the old
1978	 information so that meaningful diagnostics can be given.  */
1979      if (DECL_INITIAL (newdecl) == 0 && DECL_INITIAL (olddecl) != 0
1980	  && ! different_binding_level)
1981	{
1982	  DECL_SOURCE_LINE (newdecl) = DECL_SOURCE_LINE (olddecl);
1983	  DECL_SOURCE_FILE (newdecl) = DECL_SOURCE_FILE (olddecl);
1984	}
1985
1986      /* Merge the unused-warning information.  */
1987      if (DECL_IN_SYSTEM_HEADER (olddecl))
1988	DECL_IN_SYSTEM_HEADER (newdecl) = 1;
1989      else if (DECL_IN_SYSTEM_HEADER (newdecl))
1990	DECL_IN_SYSTEM_HEADER (write_olddecl) = 1;
1991
1992      /* Merge the initialization information.  */
1993      /* When called with different_binding_level set, don't copy over
1994	 DECL_INITIAL, so that we don't accidentally change function
1995	 declarations into function definitions.  */
1996      if (DECL_INITIAL (newdecl) == 0 && ! different_binding_level)
1997	DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
1998
1999      /* Merge the section attribute.
2000         We want to issue an error if the sections conflict but that must be
2001	 done later in decl_attributes since we are called before attributes
2002	 are assigned.  */
2003      if (DECL_SECTION_NAME (newdecl) == NULL_TREE)
2004	DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl);
2005
2006      if (TREE_CODE (newdecl) == FUNCTION_DECL)
2007	{
2008	  DECL_STATIC_CONSTRUCTOR(newdecl) |= DECL_STATIC_CONSTRUCTOR(olddecl);
2009	  DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
2010
2011	  DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
2012	    |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
2013	  DECL_NO_CHECK_MEMORY_USAGE (newdecl)
2014	    |= DECL_NO_CHECK_MEMORY_USAGE (olddecl);
2015	}
2016
2017      pop_obstacks ();
2018    }
2019  /* If cannot merge, then use the new type and qualifiers,
2020     and don't preserve the old rtl.  */
2021  else if (! different_binding_level)
2022    {
2023      TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
2024      TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
2025      TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
2026      TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
2027    }
2028
2029  /* Merge the storage class information.  */
2030  DECL_WEAK (newdecl) |= DECL_WEAK (olddecl);
2031  /* For functions, static overrides non-static.  */
2032  if (TREE_CODE (newdecl) == FUNCTION_DECL)
2033    {
2034      TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl);
2035      /* This is since we don't automatically
2036	 copy the attributes of NEWDECL into OLDDECL.  */
2037      /* No need to worry about different_binding_level here because
2038	 then TREE_PUBLIC (newdecl) was true.  */
2039      TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
2040      /* If this clears `static', clear it in the identifier too.  */
2041      if (! TREE_PUBLIC (olddecl))
2042	TREE_PUBLIC (DECL_NAME (olddecl)) = 0;
2043    }
2044  if (DECL_EXTERNAL (newdecl))
2045    {
2046      TREE_STATIC (newdecl) = TREE_STATIC (olddecl);
2047      DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (olddecl);
2048      /* An extern decl does not override previous storage class.  */
2049      TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
2050      if (! DECL_EXTERNAL (newdecl))
2051	DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
2052    }
2053  else
2054    {
2055      TREE_STATIC (olddecl) = TREE_STATIC (newdecl);
2056      TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
2057    }
2058
2059  /* If either decl says `inline', this fn is inline,
2060     unless its definition was passed already.  */
2061  if (DECL_INLINE (newdecl) && DECL_INITIAL (olddecl) == 0)
2062    DECL_INLINE (olddecl) = 1;
2063  DECL_INLINE (newdecl) = DECL_INLINE (olddecl);
2064
2065  if (TREE_CODE (newdecl) == FUNCTION_DECL)
2066    {
2067      if (DECL_BUILT_IN (olddecl))
2068	{
2069	  /* Get rid of any built-in function if new arg types don't match it
2070	     or if we have a function definition.  */
2071	  if (! types_match || new_is_definition)
2072	    {
2073	      if (! different_binding_level)
2074		{
2075		  TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
2076		  DECL_BUILT_IN (olddecl) = 0;
2077		}
2078	    }
2079	  else
2080	    {
2081	      /* If redeclaring a builtin function, and not a definition,
2082		 it stays built in.  */
2083	      DECL_BUILT_IN (newdecl) = 1;
2084	      DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
2085	    }
2086	}
2087      /* Also preserve various other info from the definition.  */
2088      else if (! new_is_definition)
2089	DECL_FRAME_SIZE (newdecl) = DECL_FRAME_SIZE (olddecl);
2090      if (! new_is_definition)
2091	{
2092	  DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
2093	  /* When called with different_binding_level set, don't copy over
2094	     DECL_INITIAL, so that we don't accidentally change function
2095	     declarations into function definitions.  */
2096	  if (! different_binding_level)
2097	    DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
2098	  DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl);
2099	  DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
2100	  if (DECL_INLINE (newdecl))
2101	    DECL_ABSTRACT_ORIGIN (newdecl) = DECL_ORIGIN (olddecl);
2102	}
2103    }
2104  if (different_binding_level)
2105    {
2106      /* Don't output a duplicate symbol or debugging information for this
2107	 declaration.
2108
2109	 Do not set TREE_ASM_WRITTEN for a FUNCTION_DECL since we may actually
2110	 just have two declarations without a definition.  VAR_DECLs may need
2111	 the same treatment, I'm not sure.  */
2112      if (TREE_CODE (newdecl) == FUNCTION_DECL)
2113	DECL_IGNORED_P (newdecl) = 1;
2114      else
2115	TREE_ASM_WRITTEN (newdecl) = DECL_IGNORED_P (newdecl) = 1;
2116      return 0;
2117    }
2118
2119  /* Copy most of the decl-specific fields of NEWDECL into OLDDECL.
2120     But preserve OLDDECL's DECL_UID.  */
2121  {
2122    register unsigned olddecl_uid = DECL_UID (olddecl);
2123
2124    bcopy ((char *) newdecl + sizeof (struct tree_common),
2125	   (char *) olddecl + sizeof (struct tree_common),
2126	   sizeof (struct tree_decl) - sizeof (struct tree_common));
2127    DECL_UID (olddecl) = olddecl_uid;
2128  }
2129
2130  /* NEWDECL contains the merged attribute lists.
2131     Update OLDDECL to be the same.  */
2132  DECL_MACHINE_ATTRIBUTES (olddecl) = DECL_MACHINE_ATTRIBUTES (newdecl);
2133
2134  return 1;
2135}
2136
2137/* Record a decl-node X as belonging to the current lexical scope.
2138   Check for errors (such as an incompatible declaration for the same
2139   name already seen in the same scope).
2140
2141   Returns either X or an old decl for the same name.
2142   If an old decl is returned, it may have been smashed
2143   to agree with what X says.  */
2144
2145tree
2146pushdecl (x)
2147     tree x;
2148{
2149  register tree t;
2150  register tree name = DECL_NAME (x);
2151  register struct binding_level *b = current_binding_level;
2152
2153  DECL_CONTEXT (x) = current_function_decl;
2154  /* A local extern declaration for a function doesn't constitute nesting.
2155     A local auto declaration does, since it's a forward decl
2156     for a nested function coming later.  */
2157  if (TREE_CODE (x) == FUNCTION_DECL && DECL_INITIAL (x) == 0
2158      && DECL_EXTERNAL (x))
2159    DECL_CONTEXT (x) = 0;
2160
2161  if (warn_nested_externs && DECL_EXTERNAL (x) && b != global_binding_level
2162      && x != IDENTIFIER_IMPLICIT_DECL (name)
2163      /* Don't print error messages for __FUNCTION__ and __PRETTY_FUNCTION__ */
2164      && !DECL_IN_SYSTEM_HEADER (x))
2165    warning ("nested extern declaration of `%s'", IDENTIFIER_POINTER (name));
2166
2167  if (name)
2168    {
2169      char *file;
2170      int line;
2171      int different_binding_level = 0;
2172
2173      t = lookup_name_current_level (name);
2174      /* Don't type check externs here when -traditional.  This is so that
2175	 code with conflicting declarations inside blocks will get warnings
2176	 not errors.  X11 for instance depends on this.  */
2177      if (! t && DECL_EXTERNAL (x) && TREE_PUBLIC (x) && ! flag_traditional)
2178	{
2179	  t = IDENTIFIER_GLOBAL_VALUE (name);
2180	  /* Type decls at global scope don't conflict with externs declared
2181	     inside lexical blocks.  */
2182	  if (t && TREE_CODE (t) == TYPE_DECL)
2183	    t = 0;
2184	  different_binding_level = 1;
2185	}
2186      if (t != 0 && t == error_mark_node)
2187	/* error_mark_node is 0 for a while during initialization!  */
2188	{
2189	  t = 0;
2190	  error_with_decl (x, "`%s' used prior to declaration");
2191	}
2192
2193      if (t != 0)
2194	{
2195	  file = DECL_SOURCE_FILE (t);
2196	  line = DECL_SOURCE_LINE (t);
2197	}
2198
2199      /* If this decl is `static' and an implicit decl was seen previously,
2200	 warn.  But don't complain if -traditional,
2201	 since traditional compilers don't complain.  */
2202      if (! flag_traditional && TREE_PUBLIC (name)
2203	  /* Don't test for DECL_EXTERNAL, because grokdeclarator
2204	     sets this for all functions.  */
2205	  && ! TREE_PUBLIC (x)
2206	  && (TREE_CODE (x) == FUNCTION_DECL || b == global_binding_level)
2207	  /* We used to warn also for explicit extern followed by static,
2208	     but sometimes you need to do it that way.  */
2209	  && IDENTIFIER_IMPLICIT_DECL (name) != 0)
2210	{
2211	  pedwarn ("`%s' was declared implicitly `extern' and later `static'",
2212		   IDENTIFIER_POINTER (name));
2213	  pedwarn_with_file_and_line
2214	    (DECL_SOURCE_FILE (IDENTIFIER_IMPLICIT_DECL (name)),
2215	     DECL_SOURCE_LINE (IDENTIFIER_IMPLICIT_DECL (name)),
2216	     "previous declaration of `%s'",
2217	     IDENTIFIER_POINTER (name));
2218	  TREE_THIS_VOLATILE (name) = 1;
2219	}
2220
2221      if (t != 0 && duplicate_decls (x, t, different_binding_level))
2222	{
2223	  if (TREE_CODE (t) == PARM_DECL)
2224	    {
2225	      /* Don't allow more than one "real" duplicate
2226		 of a forward parm decl.  */
2227	      TREE_ASM_WRITTEN (t) = TREE_ASM_WRITTEN (x);
2228	      return t;
2229	    }
2230	  return t;
2231	}
2232
2233      /* If we are processing a typedef statement, generate a whole new
2234	 ..._TYPE node (which will be just an variant of the existing
2235	 ..._TYPE node with identical properties) and then install the
2236	 TYPE_DECL node generated to represent the typedef name as the
2237	 TYPE_NAME of this brand new (duplicate) ..._TYPE node.
2238
2239	 The whole point here is to end up with a situation where each
2240	 and every ..._TYPE node the compiler creates will be uniquely
2241	 associated with AT MOST one node representing a typedef name.
2242	 This way, even though the compiler substitutes corresponding
2243	 ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
2244	 early on, later parts of the compiler can always do the reverse
2245	 translation and get back the corresponding typedef name.  For
2246	 example, given:
2247
2248		typedef struct S MY_TYPE;
2249		MY_TYPE object;
2250
2251	 Later parts of the compiler might only know that `object' was of
2252	 type `struct S' if it were not for code just below.  With this
2253	 code however, later parts of the compiler see something like:
2254
2255		struct S' == struct S
2256		typedef struct S' MY_TYPE;
2257		struct S' object;
2258
2259	 And they can then deduce (from the node for type struct S') that
2260	 the original object declaration was:
2261
2262		MY_TYPE object;
2263
2264	 Being able to do this is important for proper support of protoize,
2265	 and also for generating precise symbolic debugging information
2266	 which takes full account of the programmer's (typedef) vocabulary.
2267
2268         Obviously, we don't want to generate a duplicate ..._TYPE node if
2269	 the TYPE_DECL node that we are now processing really represents a
2270	 standard built-in type.
2271
2272         Since all standard types are effectively declared at line zero
2273         in the source file, we can easily check to see if we are working
2274         on a standard type by checking the current value of lineno.  */
2275
2276      if (TREE_CODE (x) == TYPE_DECL)
2277        {
2278          if (DECL_SOURCE_LINE (x) == 0)
2279            {
2280	      if (TYPE_NAME (TREE_TYPE (x)) == 0)
2281	        TYPE_NAME (TREE_TYPE (x)) = x;
2282            }
2283          else if (TREE_TYPE (x) != error_mark_node
2284		   && DECL_ORIGINAL_TYPE (x) == NULL_TREE)
2285            {
2286              tree tt = TREE_TYPE (x);
2287	      DECL_ORIGINAL_TYPE (x) = tt;
2288              tt = build_type_copy (tt);
2289              TYPE_NAME (tt) = x;
2290              TREE_TYPE (x) = tt;
2291            }
2292        }
2293
2294      /* Multiple external decls of the same identifier ought to match.
2295	 Check against both global declarations (when traditional) and out of
2296	 scope (limbo) block level declarations.
2297
2298	 We get warnings about inline functions where they are defined.
2299	 Avoid duplicate warnings where they are used.  */
2300      if (TREE_PUBLIC (x) && ! DECL_INLINE (x))
2301	{
2302	  tree decl;
2303
2304	  if (flag_traditional && IDENTIFIER_GLOBAL_VALUE (name) != 0
2305	      && (DECL_EXTERNAL (IDENTIFIER_GLOBAL_VALUE (name))
2306		  || TREE_PUBLIC (IDENTIFIER_GLOBAL_VALUE (name))))
2307	    decl = IDENTIFIER_GLOBAL_VALUE (name);
2308	  else if (IDENTIFIER_LIMBO_VALUE (name) != 0)
2309	    /* Decls in limbo are always extern, so no need to check that.  */
2310	    decl = IDENTIFIER_LIMBO_VALUE (name);
2311	  else
2312	    decl = 0;
2313
2314	  if (decl && ! comptypes (TREE_TYPE (x), TREE_TYPE (decl))
2315	      /* If old decl is built-in, we already warned if we should.  */
2316	      && !DECL_BUILT_IN (decl))
2317	    {
2318	      pedwarn_with_decl (x,
2319				 "type mismatch with previous external decl");
2320	      pedwarn_with_decl (decl, "previous external decl of `%s'");
2321	    }
2322	}
2323
2324      /* If a function has had an implicit declaration, and then is defined,
2325	 make sure they are compatible.  */
2326
2327      if (IDENTIFIER_IMPLICIT_DECL (name) != 0
2328	  && IDENTIFIER_GLOBAL_VALUE (name) == 0
2329	  && TREE_CODE (x) == FUNCTION_DECL
2330	  && ! comptypes (TREE_TYPE (x),
2331			  TREE_TYPE (IDENTIFIER_IMPLICIT_DECL (name))))
2332	{
2333	  warning_with_decl (x, "type mismatch with previous implicit declaration");
2334	  warning_with_decl (IDENTIFIER_IMPLICIT_DECL (name),
2335			     "previous implicit declaration of `%s'");
2336	}
2337
2338      /* In PCC-compatibility mode, extern decls of vars with no current decl
2339	 take effect at top level no matter where they are.  */
2340      if (flag_traditional && DECL_EXTERNAL (x)
2341	  && lookup_name (name) == 0)
2342	{
2343	  tree type = TREE_TYPE (x);
2344
2345	  /* But don't do this if the type contains temporary nodes.  */
2346	  while (type)
2347	    {
2348	      if (type == error_mark_node)
2349		break;
2350	      if (! TREE_PERMANENT (type))
2351		{
2352		  warning_with_decl (x, "type of external `%s' is not global");
2353		  /* By exiting the loop early, we leave TYPE nonzero,
2354		     and thus prevent globalization of the decl.  */
2355		  break;
2356		}
2357	      else if (TREE_CODE (type) == FUNCTION_TYPE
2358		       && TYPE_ARG_TYPES (type) != 0)
2359		/* The types might not be truly local,
2360		   but the list of arg types certainly is temporary.
2361		   Since prototypes are nontraditional,
2362		   ok not to do the traditional thing.  */
2363		break;
2364	      type = TREE_TYPE (type);
2365	    }
2366
2367	  if (type == 0)
2368	    b = global_binding_level;
2369	}
2370
2371      /* This name is new in its binding level.
2372	 Install the new declaration and return it.  */
2373      if (b == global_binding_level)
2374	{
2375	  /* Install a global value.  */
2376
2377	  /* If the first global decl has external linkage,
2378	     warn if we later see static one.  */
2379	  if (IDENTIFIER_GLOBAL_VALUE (name) == 0 && TREE_PUBLIC (x))
2380	    TREE_PUBLIC (name) = 1;
2381
2382	  IDENTIFIER_GLOBAL_VALUE (name) = x;
2383
2384	  /* We no longer care about any previous block level declarations.  */
2385	  IDENTIFIER_LIMBO_VALUE (name) = 0;
2386
2387	  /* Don't forget if the function was used via an implicit decl.  */
2388	  if (IDENTIFIER_IMPLICIT_DECL (name)
2389	      && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name)))
2390	    TREE_USED (x) = 1, TREE_USED (name) = 1;
2391
2392	  /* Don't forget if its address was taken in that way.  */
2393	  if (IDENTIFIER_IMPLICIT_DECL (name)
2394	      && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name)))
2395	    TREE_ADDRESSABLE (x) = 1;
2396
2397	  /* Warn about mismatches against previous implicit decl.  */
2398	  if (IDENTIFIER_IMPLICIT_DECL (name) != 0
2399	      /* If this real decl matches the implicit, don't complain.  */
2400	      && ! (TREE_CODE (x) == FUNCTION_DECL
2401		    && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (x)))
2402			== integer_type_node)))
2403	    pedwarn ("`%s' was previously implicitly declared to return `int'",
2404		     IDENTIFIER_POINTER (name));
2405
2406	  /* If this decl is `static' and an `extern' was seen previously,
2407	     that is erroneous.  */
2408	  if (TREE_PUBLIC (name)
2409	      && ! TREE_PUBLIC (x) && ! DECL_EXTERNAL (x))
2410	    {
2411	      /* Okay to redeclare an ANSI built-in as static.  */
2412	      if (t != 0 && DECL_BUILT_IN (t))
2413		;
2414	      /* Okay to declare a non-ANSI built-in as anything.  */
2415	      else if (t != 0 && DECL_BUILT_IN_NONANSI (t))
2416		;
2417	      /* Okay to have global type decl after an earlier extern
2418		 declaration inside a lexical block.  */
2419	      else if (TREE_CODE (x) == TYPE_DECL)
2420		;
2421	      else if (IDENTIFIER_IMPLICIT_DECL (name))
2422		{
2423		  if (! TREE_THIS_VOLATILE (name))
2424		    pedwarn ("`%s' was declared implicitly `extern' and later `static'",
2425			     IDENTIFIER_POINTER (name));
2426		}
2427	      else
2428		pedwarn ("`%s' was declared `extern' and later `static'",
2429			 IDENTIFIER_POINTER (name));
2430	    }
2431	}
2432      else
2433	{
2434	  /* Here to install a non-global value.  */
2435	  tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
2436	  tree oldglobal = IDENTIFIER_GLOBAL_VALUE (name);
2437	  IDENTIFIER_LOCAL_VALUE (name) = x;
2438
2439	  /* If this is an extern function declaration, see if we
2440	     have a global definition or declaration for the function.  */
2441	  if (oldlocal == 0
2442	      && DECL_EXTERNAL (x) && !DECL_INLINE (x)
2443	      && oldglobal != 0
2444	      && TREE_CODE (x) == FUNCTION_DECL
2445	      && TREE_CODE (oldglobal) == FUNCTION_DECL)
2446	    {
2447	      /* We have one.  Their types must agree.  */
2448	      if (! comptypes (TREE_TYPE (x),
2449			       TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (name))))
2450		pedwarn_with_decl (x, "extern declaration of `%s' doesn't match global one");
2451	      else
2452		{
2453		  /* Inner extern decl is inline if global one is.
2454		     Copy enough to really inline it.  */
2455		  if (DECL_INLINE (oldglobal))
2456		    {
2457		      DECL_INLINE (x) = DECL_INLINE (oldglobal);
2458		      DECL_INITIAL (x) = (current_function_decl == oldglobal
2459					  ? 0 : DECL_INITIAL (oldglobal));
2460		      DECL_SAVED_INSNS (x) = DECL_SAVED_INSNS (oldglobal);
2461		      DECL_FRAME_SIZE (x) = DECL_FRAME_SIZE (oldglobal);
2462		      DECL_ARGUMENTS (x) = DECL_ARGUMENTS (oldglobal);
2463		      DECL_RESULT (x) = DECL_RESULT (oldglobal);
2464		      TREE_ASM_WRITTEN (x) = TREE_ASM_WRITTEN (oldglobal);
2465		      DECL_ABSTRACT_ORIGIN (x) = DECL_ORIGIN (oldglobal);
2466		    }
2467		  /* Inner extern decl is built-in if global one is.  */
2468		  if (DECL_BUILT_IN (oldglobal))
2469		    {
2470		      DECL_BUILT_IN (x) = DECL_BUILT_IN (oldglobal);
2471		      DECL_FUNCTION_CODE (x) = DECL_FUNCTION_CODE (oldglobal);
2472		    }
2473		  /* Keep the arg types from a file-scope fcn defn.  */
2474		  if (TYPE_ARG_TYPES (TREE_TYPE (oldglobal)) != 0
2475		      && DECL_INITIAL (oldglobal)
2476		      && TYPE_ARG_TYPES (TREE_TYPE (x)) == 0)
2477		    TREE_TYPE (x) = TREE_TYPE (oldglobal);
2478		}
2479	    }
2480
2481#if 0 /* This case is probably sometimes the right thing to do.  */
2482	  /* If we have a local external declaration,
2483	     then any file-scope declaration should not
2484	     have been static.  */
2485	  if (oldlocal == 0 && oldglobal != 0
2486	      && !TREE_PUBLIC (oldglobal)
2487	      && DECL_EXTERNAL (x) && TREE_PUBLIC (x))
2488	    warning ("`%s' locally external but globally static",
2489		     IDENTIFIER_POINTER (name));
2490#endif
2491
2492	  /* If we have a local external declaration,
2493	     and no file-scope declaration has yet been seen,
2494	     then if we later have a file-scope decl it must not be static.  */
2495	  if (oldlocal == 0
2496	      && DECL_EXTERNAL (x)
2497	      && TREE_PUBLIC (x))
2498	    {
2499	      if (oldglobal == 0)
2500	        TREE_PUBLIC (name) = 1;
2501
2502	      /* Save this decl, so that we can do type checking against
2503		 other decls after it falls out of scope.
2504
2505		 Only save it once.  This prevents temporary decls created in
2506		 expand_inline_function from being used here, since this
2507		 will have been set when the inline function was parsed.
2508		 It also helps give slightly better warnings.  */
2509	      if (IDENTIFIER_LIMBO_VALUE (name) == 0)
2510		IDENTIFIER_LIMBO_VALUE (name) = x;
2511	    }
2512
2513	  /* Warn if shadowing an argument at the top level of the body.  */
2514	  if (oldlocal != 0 && !DECL_EXTERNAL (x)
2515	      /* This warning doesn't apply to the parms of a nested fcn.  */
2516	      && ! current_binding_level->parm_flag
2517	      /* Check that this is one level down from the parms.  */
2518	      && current_binding_level->level_chain->parm_flag
2519	      /* Check that the decl being shadowed
2520		 comes from the parm level, one level up.  */
2521	      && chain_member (oldlocal, current_binding_level->level_chain->names))
2522	    {
2523	      if (TREE_CODE (oldlocal) == PARM_DECL)
2524		pedwarn ("declaration of `%s' shadows a parameter",
2525			 IDENTIFIER_POINTER (name));
2526	      else
2527		pedwarn ("declaration of `%s' shadows a symbol from the parameter list",
2528			 IDENTIFIER_POINTER (name));
2529	    }
2530
2531	  /* Maybe warn if shadowing something else.  */
2532	  else if (warn_shadow && !DECL_EXTERNAL (x)
2533		   /* No shadow warnings for internally generated vars.  */
2534		   && DECL_SOURCE_LINE (x) != 0
2535		   /* No shadow warnings for vars made for inlining.  */
2536		   && ! DECL_FROM_INLINE (x))
2537	    {
2538	      char *id = IDENTIFIER_POINTER (name);
2539
2540	      if (TREE_CODE (x) == PARM_DECL
2541		  && current_binding_level->level_chain->parm_flag)
2542		/* Don't warn about the parm names in function declarator
2543		   within a function declarator.
2544		   It would be nice to avoid warning in any function
2545		   declarator in a declaration, as opposed to a definition,
2546		   but there is no way to tell it's not a definition.  */
2547		;
2548	      else if (oldlocal != 0 && TREE_CODE (oldlocal) == PARM_DECL)
2549		warning ("declaration of `%s' shadows a parameter", id);
2550	      else if (oldlocal != 0)
2551		warning ("declaration of `%s' shadows previous local", id);
2552	      else if (IDENTIFIER_GLOBAL_VALUE (name) != 0
2553		       && IDENTIFIER_GLOBAL_VALUE (name) != error_mark_node)
2554		warning ("declaration of `%s' shadows global declaration", id);
2555	    }
2556
2557	  /* If storing a local value, there may already be one (inherited).
2558	     If so, record it for restoration when this binding level ends.  */
2559	  if (oldlocal != 0)
2560	    b->shadowed = tree_cons (name, oldlocal, b->shadowed);
2561	}
2562
2563      /* Keep count of variables in this level with incomplete type.  */
2564      if (TYPE_SIZE (TREE_TYPE (x)) == 0)
2565	++b->n_incomplete;
2566    }
2567
2568  /* Put decls on list in reverse order.
2569     We will reverse them later if necessary.  */
2570  TREE_CHAIN (x) = b->names;
2571  b->names = x;
2572
2573  return x;
2574}
2575
2576/* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate.  */
2577
2578tree
2579pushdecl_top_level (x)
2580     tree x;
2581{
2582  register tree t;
2583  register struct binding_level *b = current_binding_level;
2584
2585  current_binding_level = global_binding_level;
2586  t = pushdecl (x);
2587  current_binding_level = b;
2588  return t;
2589}
2590
2591/* Generate an implicit declaration for identifier FUNCTIONID
2592   as a function of type int ().  Print a warning if appropriate.  */
2593
2594tree
2595implicitly_declare (functionid)
2596     tree functionid;
2597{
2598  register tree decl;
2599  int traditional_warning = 0;
2600  /* Only one "implicit declaration" warning per identifier.  */
2601  int implicit_warning;
2602
2603  /* Save the decl permanently so we can warn if definition follows.  */
2604  push_obstacks_nochange ();
2605  end_temporary_allocation ();
2606
2607  /* We used to reuse an old implicit decl here,
2608     but this loses with inline functions because it can clobber
2609     the saved decl chains.  */
2610/*  if (IDENTIFIER_IMPLICIT_DECL (functionid) != 0)
2611    decl = IDENTIFIER_IMPLICIT_DECL (functionid);
2612  else  */
2613    decl = build_decl (FUNCTION_DECL, functionid, default_function_type);
2614
2615  /* Warn of implicit decl following explicit local extern decl.
2616     This is probably a program designed for traditional C.  */
2617  if (TREE_PUBLIC (functionid) && IDENTIFIER_GLOBAL_VALUE (functionid) == 0)
2618    traditional_warning = 1;
2619
2620  /* Warn once of an implicit declaration.  */
2621  implicit_warning = (IDENTIFIER_IMPLICIT_DECL (functionid) == 0);
2622
2623  DECL_EXTERNAL (decl) = 1;
2624  TREE_PUBLIC (decl) = 1;
2625
2626  /* Record that we have an implicit decl and this is it.  */
2627  IDENTIFIER_IMPLICIT_DECL (functionid) = decl;
2628
2629  /* ANSI standard says implicit declarations are in the innermost block.
2630     So we record the decl in the standard fashion.
2631     If flag_traditional is set, pushdecl does it top-level.  */
2632  pushdecl (decl);
2633
2634  /* This is a no-op in c-lang.c or something real in objc-actions.c.  */
2635  maybe_objc_check_decl (decl);
2636
2637  rest_of_decl_compilation (decl, NULL_PTR, 0, 0);
2638
2639  if (mesg_implicit_function_declaration && implicit_warning)
2640    {
2641      if (mesg_implicit_function_declaration == 2)
2642        error ("implicit declaration of function `%s'",
2643                 IDENTIFIER_POINTER (functionid));
2644      else
2645        warning ("implicit declaration of function `%s'",
2646                 IDENTIFIER_POINTER (functionid));
2647    }
2648  else if (warn_traditional && traditional_warning)
2649    warning ("function `%s' was previously declared within a block",
2650	     IDENTIFIER_POINTER (functionid));
2651
2652  /* Write a record describing this implicit function declaration to the
2653     prototypes file (if requested).  */
2654
2655  gen_aux_info_record (decl, 0, 1, 0);
2656
2657  pop_obstacks ();
2658
2659  return decl;
2660}
2661
2662/* Return zero if the declaration NEWDECL is valid
2663   when the declaration OLDDECL (assumed to be for the same name)
2664   has already been seen.
2665   Otherwise return 1 if NEWDECL is a redefinition, 2 if it is a redeclaration,
2666   and 3 if it is a conflicting declaration.  */
2667
2668static int
2669redeclaration_error_message (newdecl, olddecl)
2670     tree newdecl, olddecl;
2671{
2672  if (TREE_CODE (newdecl) == TYPE_DECL)
2673    {
2674      if (flag_traditional && TREE_TYPE (newdecl) == TREE_TYPE (olddecl))
2675	return 0;
2676      /* pushdecl creates distinct types for TYPE_DECLs by calling
2677	 build_type_copy, so the above comparison generally fails.  We do
2678	 another test against the TYPE_MAIN_VARIANT of the olddecl, which
2679	 is equivalent to what this code used to do before the build_type_copy
2680	 call.  The variant type distinction should not matter for traditional
2681	 code, because it doesn't have type qualifiers.  */
2682      if (flag_traditional
2683	  && TYPE_MAIN_VARIANT (TREE_TYPE (olddecl)) == TREE_TYPE (newdecl))
2684	return 0;
2685      if (DECL_IN_SYSTEM_HEADER (olddecl) || DECL_IN_SYSTEM_HEADER (newdecl))
2686	return 0;
2687      return 1;
2688    }
2689  else if (TREE_CODE (newdecl) == FUNCTION_DECL)
2690    {
2691      /* Declarations of functions can insist on internal linkage
2692	 but they can't be inconsistent with internal linkage,
2693	 so there can be no error on that account.
2694	 However defining the same name twice is no good.  */
2695      if (DECL_INITIAL (olddecl) != 0 && DECL_INITIAL (newdecl) != 0
2696	  /* However, defining once as extern inline and a second
2697	     time in another way is ok.  */
2698	  && !(DECL_INLINE (olddecl) && DECL_EXTERNAL (olddecl)
2699	       && !(DECL_INLINE (newdecl) && DECL_EXTERNAL (newdecl))))
2700	return 1;
2701      return 0;
2702    }
2703  else if (current_binding_level == global_binding_level)
2704    {
2705      /* Objects declared at top level:  */
2706      /* If at least one is a reference, it's ok.  */
2707      if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
2708	return 0;
2709      /* Reject two definitions.  */
2710      if (DECL_INITIAL (olddecl) != 0 && DECL_INITIAL (newdecl) != 0)
2711	return 1;
2712      /* Now we have two tentative defs, or one tentative and one real def.  */
2713      /* Insist that the linkage match.  */
2714      if (TREE_PUBLIC (olddecl) != TREE_PUBLIC (newdecl))
2715	return 3;
2716      return 0;
2717    }
2718  else if (current_binding_level->parm_flag
2719	   && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl))
2720    return 0;
2721  else
2722    {
2723      /* Newdecl has block scope.  If olddecl has block scope also, then
2724	 reject two definitions, and reject a definition together with an
2725	 external reference.  Otherwise, it is OK, because newdecl must
2726	 be an extern reference to olddecl.  */
2727      if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl))
2728	  && DECL_CONTEXT (newdecl) == DECL_CONTEXT (olddecl))
2729	return 2;
2730      return 0;
2731    }
2732}
2733
2734/* Get the LABEL_DECL corresponding to identifier ID as a label.
2735   Create one if none exists so far for the current function.
2736   This function is called for both label definitions and label references.  */
2737
2738tree
2739lookup_label (id)
2740     tree id;
2741{
2742  register tree decl = IDENTIFIER_LABEL_VALUE (id);
2743
2744  if (current_function_decl == 0)
2745    {
2746      error ("label %s referenced outside of any function",
2747	     IDENTIFIER_POINTER (id));
2748      return 0;
2749    }
2750
2751  /* Use a label already defined or ref'd with this name.  */
2752  if (decl != 0)
2753    {
2754      /* But not if it is inherited and wasn't declared to be inheritable.  */
2755      if (DECL_CONTEXT (decl) != current_function_decl
2756	  && ! C_DECLARED_LABEL_FLAG (decl))
2757	return shadow_label (id);
2758      return decl;
2759    }
2760
2761  decl = build_decl (LABEL_DECL, id, void_type_node);
2762
2763  /* Make sure every label has an rtx.  */
2764  label_rtx (decl);
2765
2766  /* A label not explicitly declared must be local to where it's ref'd.  */
2767  DECL_CONTEXT (decl) = current_function_decl;
2768
2769  DECL_MODE (decl) = VOIDmode;
2770
2771  /* Say where one reference is to the label,
2772     for the sake of the error if it is not defined.  */
2773  DECL_SOURCE_LINE (decl) = lineno;
2774  DECL_SOURCE_FILE (decl) = input_filename;
2775
2776  IDENTIFIER_LABEL_VALUE (id) = decl;
2777
2778  named_labels = tree_cons (NULL_TREE, decl, named_labels);
2779
2780  return decl;
2781}
2782
2783/* Make a label named NAME in the current function,
2784   shadowing silently any that may be inherited from containing functions
2785   or containing scopes.
2786
2787   Note that valid use, if the label being shadowed
2788   comes from another scope in the same function,
2789   requires calling declare_nonlocal_label right away.  */
2790
2791tree
2792shadow_label (name)
2793     tree name;
2794{
2795  register tree decl = IDENTIFIER_LABEL_VALUE (name);
2796
2797  if (decl != 0)
2798    {
2799      register tree dup;
2800
2801      /* Check to make sure that the label hasn't already been declared
2802	 at this label scope */
2803      for (dup = named_labels; dup; dup = TREE_CHAIN (dup))
2804	if (TREE_VALUE (dup) == decl)
2805	  {
2806	    error ("duplicate label declaration `%s'",
2807		   IDENTIFIER_POINTER (name));
2808	    error_with_decl (TREE_VALUE (dup),
2809			     "this is a previous declaration");
2810	    /* Just use the previous declaration.  */
2811	    return lookup_label (name);
2812	  }
2813
2814      shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
2815      IDENTIFIER_LABEL_VALUE (name) = decl = 0;
2816    }
2817
2818  return lookup_label (name);
2819}
2820
2821/* Define a label, specifying the location in the source file.
2822   Return the LABEL_DECL node for the label, if the definition is valid.
2823   Otherwise return 0.  */
2824
2825tree
2826define_label (filename, line, name)
2827     char *filename;
2828     int line;
2829     tree name;
2830{
2831  tree decl = lookup_label (name);
2832
2833  /* If label with this name is known from an outer context, shadow it.  */
2834  if (decl != 0 && DECL_CONTEXT (decl) != current_function_decl)
2835    {
2836      shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
2837      IDENTIFIER_LABEL_VALUE (name) = 0;
2838      decl = lookup_label (name);
2839    }
2840
2841  if (DECL_INITIAL (decl) != 0)
2842    {
2843      error ("duplicate label `%s'", IDENTIFIER_POINTER (name));
2844      return 0;
2845    }
2846  else
2847    {
2848      /* Mark label as having been defined.  */
2849      DECL_INITIAL (decl) = error_mark_node;
2850      /* Say where in the source.  */
2851      DECL_SOURCE_FILE (decl) = filename;
2852      DECL_SOURCE_LINE (decl) = line;
2853      return decl;
2854    }
2855}
2856
2857/* Return the list of declarations of the current level.
2858   Note that this list is in reverse order unless/until
2859   you nreverse it; and when you do nreverse it, you must
2860   store the result back using `storedecls' or you will lose.  */
2861
2862tree
2863getdecls ()
2864{
2865  return current_binding_level->names;
2866}
2867
2868/* Return the list of type-tags (for structs, etc) of the current level.  */
2869
2870tree
2871gettags ()
2872{
2873  return current_binding_level->tags;
2874}
2875
2876/* Store the list of declarations of the current level.
2877   This is done for the parameter declarations of a function being defined,
2878   after they are modified in the light of any missing parameters.  */
2879
2880static void
2881storedecls (decls)
2882     tree decls;
2883{
2884  current_binding_level->names = decls;
2885}
2886
2887/* Similarly, store the list of tags of the current level.  */
2888
2889static void
2890storetags (tags)
2891     tree tags;
2892{
2893  current_binding_level->tags = tags;
2894}
2895
2896/* Given NAME, an IDENTIFIER_NODE,
2897   return the structure (or union or enum) definition for that name.
2898   Searches binding levels from BINDING_LEVEL up to the global level.
2899   If THISLEVEL_ONLY is nonzero, searches only the specified context
2900   (but skips any tag-transparent contexts to find one that is
2901   meaningful for tags).
2902   CODE says which kind of type the caller wants;
2903   it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
2904   If the wrong kind of type is found, an error is reported.  */
2905
2906static tree
2907lookup_tag (code, name, binding_level, thislevel_only)
2908     enum tree_code code;
2909     struct binding_level *binding_level;
2910     tree name;
2911     int thislevel_only;
2912{
2913  register struct binding_level *level;
2914
2915  for (level = binding_level; level; level = level->level_chain)
2916    {
2917      register tree tail;
2918      for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
2919	{
2920	  if (TREE_PURPOSE (tail) == name)
2921	    {
2922	      if (TREE_CODE (TREE_VALUE (tail)) != code)
2923		{
2924		  /* Definition isn't the kind we were looking for.  */
2925		  pending_invalid_xref = name;
2926		  pending_invalid_xref_file = input_filename;
2927		  pending_invalid_xref_line = lineno;
2928		}
2929	      return TREE_VALUE (tail);
2930	    }
2931	}
2932      if (thislevel_only && ! level->tag_transparent)
2933	return NULL_TREE;
2934    }
2935  return NULL_TREE;
2936}
2937
2938/* Print an error message now
2939   for a recent invalid struct, union or enum cross reference.
2940   We don't print them immediately because they are not invalid
2941   when used in the `struct foo;' construct for shadowing.  */
2942
2943void
2944pending_xref_error ()
2945{
2946  if (pending_invalid_xref != 0)
2947    error_with_file_and_line (pending_invalid_xref_file,
2948			      pending_invalid_xref_line,
2949			      "`%s' defined as wrong kind of tag",
2950			      IDENTIFIER_POINTER (pending_invalid_xref));
2951  pending_invalid_xref = 0;
2952}
2953
2954/* Given a type, find the tag that was defined for it and return the tag name.
2955   Otherwise return 0.  */
2956
2957static tree
2958lookup_tag_reverse (type)
2959     tree type;
2960{
2961  register struct binding_level *level;
2962
2963  for (level = current_binding_level; level; level = level->level_chain)
2964    {
2965      register tree tail;
2966      for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
2967	{
2968	  if (TREE_VALUE (tail) == type)
2969	    return TREE_PURPOSE (tail);
2970	}
2971    }
2972  return NULL_TREE;
2973}
2974
2975/* Look up NAME in the current binding level and its superiors
2976   in the namespace of variables, functions and typedefs.
2977   Return a ..._DECL node of some kind representing its definition,
2978   or return 0 if it is undefined.  */
2979
2980tree
2981lookup_name (name)
2982     tree name;
2983{
2984  register tree val;
2985  if (current_binding_level != global_binding_level
2986      && IDENTIFIER_LOCAL_VALUE (name))
2987    val = IDENTIFIER_LOCAL_VALUE (name);
2988  else
2989    val = IDENTIFIER_GLOBAL_VALUE (name);
2990  return val;
2991}
2992
2993/* Similar to `lookup_name' but look only at current binding level.  */
2994
2995tree
2996lookup_name_current_level (name)
2997     tree name;
2998{
2999  register tree t;
3000
3001  if (current_binding_level == global_binding_level)
3002    return IDENTIFIER_GLOBAL_VALUE (name);
3003
3004  if (IDENTIFIER_LOCAL_VALUE (name) == 0)
3005    return 0;
3006
3007  for (t = current_binding_level->names; t; t = TREE_CHAIN (t))
3008    if (DECL_NAME (t) == name)
3009      break;
3010
3011  return t;
3012}
3013
3014/* Create the predefined scalar types of C,
3015   and some nodes representing standard constants (0, 1, (void *) 0).
3016   Initialize the global binding level.
3017   Make definitions for built-in primitive functions.  */
3018
3019void
3020init_decl_processing ()
3021{
3022  register tree endlink;
3023  /* Either char* or void*.  */
3024  tree traditional_ptr_type_node;
3025  /* Data types of memcpy and strlen.  */
3026  tree memcpy_ftype, memset_ftype, strlen_ftype;
3027  tree void_ftype_any, ptr_ftype_void, ptr_ftype_ptr;
3028  int wchar_type_size;
3029  tree temp;
3030  tree array_domain_type;
3031
3032  current_function_decl = NULL;
3033  named_labels = NULL;
3034  current_binding_level = NULL_BINDING_LEVEL;
3035  free_binding_level = NULL_BINDING_LEVEL;
3036  pushlevel (0);	/* make the binding_level structure for global names */
3037  global_binding_level = current_binding_level;
3038
3039  /* Define `int' and `char' first so that dbx will output them first.  */
3040
3041  integer_type_node = make_signed_type (INT_TYPE_SIZE);
3042  pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_INT],
3043			integer_type_node));
3044
3045  /* Define `char', which is like either `signed char' or `unsigned char'
3046     but not the same as either.  */
3047
3048  char_type_node
3049    = (flag_signed_char
3050       ? make_signed_type (CHAR_TYPE_SIZE)
3051       : make_unsigned_type (CHAR_TYPE_SIZE));
3052  pushdecl (build_decl (TYPE_DECL, get_identifier ("char"),
3053			char_type_node));
3054
3055  long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
3056  pushdecl (build_decl (TYPE_DECL, get_identifier ("long int"),
3057			long_integer_type_node));
3058
3059  unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
3060  pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned int"),
3061			unsigned_type_node));
3062
3063  long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
3064  pushdecl (build_decl (TYPE_DECL, get_identifier ("long unsigned int"),
3065			long_unsigned_type_node));
3066
3067  long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
3068  pushdecl (build_decl (TYPE_DECL, get_identifier ("long long int"),
3069			long_long_integer_type_node));
3070
3071  long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
3072  pushdecl (build_decl (TYPE_DECL, get_identifier ("long long unsigned int"),
3073			long_long_unsigned_type_node));
3074
3075  short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
3076  pushdecl (build_decl (TYPE_DECL, get_identifier ("short int"),
3077			short_integer_type_node));
3078
3079  short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
3080  pushdecl (build_decl (TYPE_DECL, get_identifier ("short unsigned int"),
3081			short_unsigned_type_node));
3082
3083  /* `unsigned long' is the standard type for sizeof.
3084     Traditionally, use a signed type.
3085     Note that stddef.h uses `unsigned long',
3086     and this must agree, even if long and int are the same size.  */
3087  set_sizetype
3088    (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (SIZE_TYPE))));
3089  if (flag_traditional && TREE_UNSIGNED (sizetype))
3090    set_sizetype (signed_type (sizetype));
3091
3092  ptrdiff_type_node
3093    = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (PTRDIFF_TYPE)));
3094
3095  error_mark_node = make_node (ERROR_MARK);
3096  TREE_TYPE (error_mark_node) = error_mark_node;
3097
3098  /* Define both `signed char' and `unsigned char'.  */
3099  signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
3100  pushdecl (build_decl (TYPE_DECL, get_identifier ("signed char"),
3101			signed_char_type_node));
3102
3103  unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
3104  pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned char"),
3105			unsigned_char_type_node));
3106
3107  intQI_type_node = make_signed_type (GET_MODE_BITSIZE (QImode));
3108  pushdecl (build_decl (TYPE_DECL, NULL_TREE, intQI_type_node));
3109
3110  intHI_type_node = make_signed_type (GET_MODE_BITSIZE (HImode));
3111  pushdecl (build_decl (TYPE_DECL, NULL_TREE, intHI_type_node));
3112
3113  intSI_type_node = make_signed_type (GET_MODE_BITSIZE (SImode));
3114  pushdecl (build_decl (TYPE_DECL, NULL_TREE, intSI_type_node));
3115
3116  intDI_type_node = make_signed_type (GET_MODE_BITSIZE (DImode));
3117  pushdecl (build_decl (TYPE_DECL, NULL_TREE, intDI_type_node));
3118
3119#if HOST_BITS_PER_WIDE_INT >= 64
3120  intTI_type_node = make_signed_type (GET_MODE_BITSIZE (TImode));
3121  pushdecl (build_decl (TYPE_DECL, NULL_TREE, intTI_type_node));
3122#endif
3123
3124  unsigned_intQI_type_node = make_unsigned_type (GET_MODE_BITSIZE (QImode));
3125  pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intQI_type_node));
3126
3127  unsigned_intHI_type_node = make_unsigned_type (GET_MODE_BITSIZE (HImode));
3128  pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intHI_type_node));
3129
3130  unsigned_intSI_type_node = make_unsigned_type (GET_MODE_BITSIZE (SImode));
3131  pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intSI_type_node));
3132
3133  unsigned_intDI_type_node = make_unsigned_type (GET_MODE_BITSIZE (DImode));
3134  pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intDI_type_node));
3135
3136#if HOST_BITS_PER_WIDE_INT >= 64
3137  unsigned_intTI_type_node = make_unsigned_type (GET_MODE_BITSIZE (TImode));
3138  pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intTI_type_node));
3139#endif
3140
3141  float_type_node = make_node (REAL_TYPE);
3142  TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
3143  pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_FLOAT],
3144			float_type_node));
3145  layout_type (float_type_node);
3146
3147  double_type_node = make_node (REAL_TYPE);
3148  if (flag_short_double)
3149    TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE;
3150  else
3151    TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;
3152  pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_DOUBLE],
3153			double_type_node));
3154  layout_type (double_type_node);
3155
3156  long_double_type_node = make_node (REAL_TYPE);
3157  TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
3158  pushdecl (build_decl (TYPE_DECL, get_identifier ("long double"),
3159			long_double_type_node));
3160  layout_type (long_double_type_node);
3161
3162  complex_integer_type_node = make_node (COMPLEX_TYPE);
3163  pushdecl (build_decl (TYPE_DECL, get_identifier ("complex int"),
3164			complex_integer_type_node));
3165  TREE_TYPE (complex_integer_type_node) = integer_type_node;
3166  layout_type (complex_integer_type_node);
3167
3168  complex_float_type_node = make_node (COMPLEX_TYPE);
3169  pushdecl (build_decl (TYPE_DECL, get_identifier ("complex float"),
3170			complex_float_type_node));
3171  TREE_TYPE (complex_float_type_node) = float_type_node;
3172  layout_type (complex_float_type_node);
3173
3174  complex_double_type_node = make_node (COMPLEX_TYPE);
3175  pushdecl (build_decl (TYPE_DECL, get_identifier ("complex double"),
3176			complex_double_type_node));
3177  TREE_TYPE (complex_double_type_node) = double_type_node;
3178  layout_type (complex_double_type_node);
3179
3180  complex_long_double_type_node = make_node (COMPLEX_TYPE);
3181  pushdecl (build_decl (TYPE_DECL, get_identifier ("complex long double"),
3182			complex_long_double_type_node));
3183  TREE_TYPE (complex_long_double_type_node) = long_double_type_node;
3184  layout_type (complex_long_double_type_node);
3185
3186  wchar_type_node
3187    = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (WCHAR_TYPE)));
3188  wchar_type_size = TYPE_PRECISION (wchar_type_node);
3189  signed_wchar_type_node = signed_type (wchar_type_node);
3190  unsigned_wchar_type_node = unsigned_type (wchar_type_node);
3191
3192  integer_zero_node = build_int_2 (0, 0);
3193  TREE_TYPE (integer_zero_node) = integer_type_node;
3194  integer_one_node = build_int_2 (1, 0);
3195  TREE_TYPE (integer_one_node) = integer_type_node;
3196
3197  boolean_type_node = integer_type_node;
3198  boolean_true_node = integer_one_node;
3199  boolean_false_node = integer_zero_node;
3200
3201  size_zero_node = build_int_2 (0, 0);
3202  TREE_TYPE (size_zero_node) = sizetype;
3203  size_one_node = build_int_2 (1, 0);
3204  TREE_TYPE (size_one_node) = sizetype;
3205
3206  void_type_node = make_node (VOID_TYPE);
3207  pushdecl (build_decl (TYPE_DECL,
3208			ridpointers[(int) RID_VOID], void_type_node));
3209  layout_type (void_type_node);	/* Uses integer_zero_node */
3210  /* We are not going to have real types in C with less than byte alignment,
3211     so we might as well not have any types that claim to have it.  */
3212  TYPE_ALIGN (void_type_node) = BITS_PER_UNIT;
3213
3214  null_pointer_node = build_int_2 (0, 0);
3215  TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node);
3216  layout_type (TREE_TYPE (null_pointer_node));
3217
3218  string_type_node = build_pointer_type (char_type_node);
3219  const_string_type_node
3220    = build_pointer_type (build_type_variant (char_type_node, 1, 0));
3221
3222  /* Make a type to be the domain of a few array types
3223     whose domains don't really matter.
3224     200 is small enough that it always fits in size_t
3225     and large enough that it can hold most function names for the
3226     initializations of __FUNCTION__ and __PRETTY_FUNCTION__.  */
3227  array_domain_type = build_index_type (build_int_2 (200, 0));
3228
3229  /* make a type for arrays of characters.
3230     With luck nothing will ever really depend on the length of this
3231     array type.  */
3232  char_array_type_node
3233    = build_array_type (char_type_node, array_domain_type);
3234  /* Likewise for arrays of ints.  */
3235  int_array_type_node
3236    = build_array_type (integer_type_node, array_domain_type);
3237  /* This is for wide string constants.  */
3238  wchar_array_type_node
3239    = build_array_type (wchar_type_node, array_domain_type);
3240
3241  default_function_type
3242    = build_function_type (integer_type_node, NULL_TREE);
3243
3244  ptr_type_node = build_pointer_type (void_type_node);
3245  const_ptr_type_node
3246    = build_pointer_type (build_type_variant (void_type_node, 1, 0));
3247
3248  endlink = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
3249
3250  void_ftype_any
3251    = build_function_type (void_type_node, NULL_TREE);
3252
3253  float_ftype_float
3254    = build_function_type (float_type_node,
3255			   tree_cons (NULL_TREE, float_type_node, endlink));
3256
3257  double_ftype_double
3258    = build_function_type (double_type_node,
3259			   tree_cons (NULL_TREE, double_type_node, endlink));
3260
3261  ldouble_ftype_ldouble
3262    = build_function_type (long_double_type_node,
3263			   tree_cons (NULL_TREE, long_double_type_node,
3264				      endlink));
3265
3266  double_ftype_double_double
3267    = build_function_type (double_type_node,
3268			   tree_cons (NULL_TREE, double_type_node,
3269				      tree_cons (NULL_TREE,
3270						 double_type_node, endlink)));
3271
3272  int_ftype_int
3273    = build_function_type (integer_type_node,
3274			   tree_cons (NULL_TREE, integer_type_node, endlink));
3275
3276  long_ftype_long
3277    = build_function_type (long_integer_type_node,
3278			   tree_cons (NULL_TREE,
3279				      long_integer_type_node, endlink));
3280
3281  void_ftype_ptr_ptr_int
3282    = build_function_type (void_type_node,
3283			   tree_cons (NULL_TREE, ptr_type_node,
3284				      tree_cons (NULL_TREE, ptr_type_node,
3285						 tree_cons (NULL_TREE,
3286							    integer_type_node,
3287							    endlink))));
3288
3289  int_ftype_cptr_cptr_sizet
3290    = build_function_type (integer_type_node,
3291			   tree_cons (NULL_TREE, const_ptr_type_node,
3292				      tree_cons (NULL_TREE, const_ptr_type_node,
3293						 tree_cons (NULL_TREE,
3294							    sizetype,
3295							    endlink))));
3296
3297  void_ftype_ptr_int_int
3298    = build_function_type (void_type_node,
3299			   tree_cons (NULL_TREE, ptr_type_node,
3300				      tree_cons (NULL_TREE, integer_type_node,
3301						 tree_cons (NULL_TREE,
3302							    integer_type_node,
3303							    endlink))));
3304
3305  string_ftype_ptr_ptr		/* strcpy prototype */
3306    = build_function_type (string_type_node,
3307			   tree_cons (NULL_TREE, string_type_node,
3308				      tree_cons (NULL_TREE,
3309						 const_string_type_node,
3310						 endlink)));
3311
3312  int_ftype_string_string	/* strcmp prototype */
3313    = build_function_type (integer_type_node,
3314			   tree_cons (NULL_TREE, const_string_type_node,
3315				      tree_cons (NULL_TREE,
3316						 const_string_type_node,
3317						 endlink)));
3318
3319  strlen_ftype		/* strlen prototype */
3320    = build_function_type (flag_traditional ? integer_type_node : sizetype,
3321			   tree_cons (NULL_TREE, const_string_type_node,
3322				      endlink));
3323
3324  traditional_ptr_type_node
3325    = (flag_traditional ? string_type_node : ptr_type_node);
3326
3327  memcpy_ftype	/* memcpy prototype */
3328    = build_function_type (traditional_ptr_type_node,
3329			   tree_cons (NULL_TREE, ptr_type_node,
3330				      tree_cons (NULL_TREE, const_ptr_type_node,
3331						 tree_cons (NULL_TREE,
3332							    sizetype,
3333							    endlink))));
3334
3335  memset_ftype	/* memset prototype */
3336    = build_function_type (traditional_ptr_type_node,
3337			   tree_cons (NULL_TREE, ptr_type_node,
3338				      tree_cons (NULL_TREE, integer_type_node,
3339						 tree_cons (NULL_TREE,
3340							    sizetype,
3341							    endlink))));
3342
3343  ptr_ftype_void = build_function_type (ptr_type_node, endlink);
3344  ptr_ftype_ptr
3345    = build_function_type (ptr_type_node,
3346			   tree_cons (NULL_TREE, ptr_type_node, endlink));
3347
3348  builtin_function ("__builtin_constant_p", default_function_type,
3349		    BUILT_IN_CONSTANT_P, NULL_PTR);
3350
3351  builtin_function ("__builtin_return_address",
3352		    build_function_type (ptr_type_node,
3353					 tree_cons (NULL_TREE,
3354						    unsigned_type_node,
3355						    endlink)),
3356		    BUILT_IN_RETURN_ADDRESS, NULL_PTR);
3357
3358  builtin_function ("__builtin_frame_address",
3359		    build_function_type (ptr_type_node,
3360					 tree_cons (NULL_TREE,
3361						    unsigned_type_node,
3362						    endlink)),
3363		    BUILT_IN_FRAME_ADDRESS, NULL_PTR);
3364
3365  builtin_function ("__builtin_aggregate_incoming_address",
3366		    build_function_type (ptr_type_node, NULL_TREE),
3367		    BUILT_IN_AGGREGATE_INCOMING_ADDRESS, NULL_PTR);
3368
3369  /* Hooks for the DWARF 2 __throw routine.  */
3370  builtin_function ("__builtin_unwind_init",
3371		    build_function_type (void_type_node, endlink),
3372		    BUILT_IN_UNWIND_INIT, NULL_PTR);
3373  builtin_function ("__builtin_dwarf_cfa", ptr_ftype_void,
3374		    BUILT_IN_DWARF_CFA, NULL_PTR);
3375  builtin_function ("__builtin_dwarf_fp_regnum",
3376		    build_function_type (unsigned_type_node, endlink),
3377		    BUILT_IN_DWARF_FP_REGNUM, NULL_PTR);
3378  builtin_function ("__builtin_dwarf_reg_size", int_ftype_int,
3379		    BUILT_IN_DWARF_REG_SIZE, NULL_PTR);
3380  builtin_function ("__builtin_frob_return_addr", ptr_ftype_ptr,
3381		    BUILT_IN_FROB_RETURN_ADDR, NULL_PTR);
3382  builtin_function ("__builtin_extract_return_addr", ptr_ftype_ptr,
3383		    BUILT_IN_EXTRACT_RETURN_ADDR, NULL_PTR);
3384  builtin_function
3385    ("__builtin_eh_return",
3386     build_function_type (void_type_node,
3387			  tree_cons (NULL_TREE, ptr_type_node,
3388				     tree_cons (NULL_TREE,
3389						type_for_mode (ptr_mode, 0),
3390					        tree_cons (NULL_TREE,
3391							   ptr_type_node,
3392							   endlink)))),
3393     BUILT_IN_EH_RETURN, NULL_PTR);
3394
3395  builtin_function ("__builtin_alloca",
3396		    build_function_type (ptr_type_node,
3397					 tree_cons (NULL_TREE,
3398						    sizetype,
3399						    endlink)),
3400		    BUILT_IN_ALLOCA, "alloca");
3401  builtin_function ("__builtin_ffs", int_ftype_int, BUILT_IN_FFS, NULL_PTR);
3402  /* Define alloca, ffs as builtins.
3403     Declare _exit just to mark it as volatile.  */
3404  if (! flag_no_builtin && !flag_no_nonansi_builtin)
3405    {
3406      temp = builtin_function ("alloca",
3407			       build_function_type (ptr_type_node,
3408						    tree_cons (NULL_TREE,
3409							       sizetype,
3410							       endlink)),
3411			       BUILT_IN_ALLOCA, NULL_PTR);
3412      /* Suppress error if redefined as a non-function.  */
3413      DECL_BUILT_IN_NONANSI (temp) = 1;
3414      temp = builtin_function ("ffs", int_ftype_int, BUILT_IN_FFS, NULL_PTR);
3415      /* Suppress error if redefined as a non-function.  */
3416      DECL_BUILT_IN_NONANSI (temp) = 1;
3417      temp = builtin_function ("_exit", void_ftype_any, NOT_BUILT_IN,
3418			       NULL_PTR);
3419      TREE_THIS_VOLATILE (temp) = 1;
3420      TREE_SIDE_EFFECTS (temp) = 1;
3421      /* Suppress error if redefined as a non-function.  */
3422      DECL_BUILT_IN_NONANSI (temp) = 1;
3423    }
3424
3425  builtin_function ("__builtin_abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR);
3426  builtin_function ("__builtin_fabsf", float_ftype_float, BUILT_IN_FABS,
3427		    NULL_PTR);
3428  builtin_function ("__builtin_fabs", double_ftype_double, BUILT_IN_FABS,
3429		    NULL_PTR);
3430  builtin_function ("__builtin_fabsl", ldouble_ftype_ldouble, BUILT_IN_FABS,
3431		    NULL_PTR);
3432  builtin_function ("__builtin_labs", long_ftype_long, BUILT_IN_LABS,
3433		    NULL_PTR);
3434  builtin_function ("__builtin_saveregs",
3435		    build_function_type (ptr_type_node, NULL_TREE),
3436		    BUILT_IN_SAVEREGS, NULL_PTR);
3437/* EXPAND_BUILTIN_VARARGS is obsolete.  */
3438#if 0
3439  builtin_function ("__builtin_varargs",
3440		    build_function_type (ptr_type_node,
3441					 tree_cons (NULL_TREE,
3442						    integer_type_node,
3443						    endlink)),
3444		    BUILT_IN_VARARGS, NULL_PTR);
3445#endif
3446  builtin_function ("__builtin_classify_type", default_function_type,
3447		    BUILT_IN_CLASSIFY_TYPE, NULL_PTR);
3448  builtin_function ("__builtin_next_arg",
3449		    build_function_type (ptr_type_node, NULL_TREE),
3450		    BUILT_IN_NEXT_ARG, NULL_PTR);
3451  builtin_function ("__builtin_args_info",
3452		    build_function_type (integer_type_node,
3453					 tree_cons (NULL_TREE,
3454						    integer_type_node,
3455						    endlink)),
3456		    BUILT_IN_ARGS_INFO, NULL_PTR);
3457
3458  /* Untyped call and return.  */
3459  builtin_function ("__builtin_apply_args",
3460		    build_function_type (ptr_type_node, NULL_TREE),
3461		    BUILT_IN_APPLY_ARGS, NULL_PTR);
3462
3463  temp = tree_cons (NULL_TREE,
3464		    build_pointer_type (build_function_type (void_type_node,
3465							     NULL_TREE)),
3466		    tree_cons (NULL_TREE,
3467			       ptr_type_node,
3468			       tree_cons (NULL_TREE,
3469					  sizetype,
3470					  endlink)));
3471  builtin_function ("__builtin_apply",
3472		    build_function_type (ptr_type_node, temp),
3473		    BUILT_IN_APPLY, NULL_PTR);
3474  builtin_function ("__builtin_return",
3475		    build_function_type (void_type_node,
3476					 tree_cons (NULL_TREE,
3477						    ptr_type_node,
3478						    endlink)),
3479		    BUILT_IN_RETURN, NULL_PTR);
3480
3481  /* Currently under experimentation.  */
3482  builtin_function ("__builtin_memcpy", memcpy_ftype,
3483		    BUILT_IN_MEMCPY, "memcpy");
3484  builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet,
3485		    BUILT_IN_MEMCMP, "memcmp");
3486  builtin_function ("__builtin_memset", memset_ftype,
3487		    BUILT_IN_MEMSET, "memset");
3488  builtin_function ("__builtin_strcmp", int_ftype_string_string,
3489		    BUILT_IN_STRCMP, "strcmp");
3490  builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr,
3491		    BUILT_IN_STRCPY, "strcpy");
3492  builtin_function ("__builtin_strlen", strlen_ftype,
3493		    BUILT_IN_STRLEN, "strlen");
3494  builtin_function ("__builtin_sqrtf", float_ftype_float,
3495		    BUILT_IN_FSQRT, "sqrtf");
3496  builtin_function ("__builtin_fsqrt", double_ftype_double,
3497		    BUILT_IN_FSQRT, "sqrt");
3498  builtin_function ("__builtin_sqrtl", ldouble_ftype_ldouble,
3499		    BUILT_IN_FSQRT, "sqrtl");
3500  builtin_function ("__builtin_sinf", float_ftype_float,
3501		    BUILT_IN_SIN, "sinf");
3502  builtin_function ("__builtin_sin", double_ftype_double,
3503		    BUILT_IN_SIN, "sin");
3504  builtin_function ("__builtin_sinl", ldouble_ftype_ldouble,
3505		    BUILT_IN_SIN, "sinl");
3506  builtin_function ("__builtin_cosf", float_ftype_float,
3507		    BUILT_IN_COS, "cosf");
3508  builtin_function ("__builtin_cos", double_ftype_double,
3509		    BUILT_IN_COS, "cos");
3510  builtin_function ("__builtin_cosl", ldouble_ftype_ldouble,
3511		    BUILT_IN_COS, "cosl");
3512  builtin_function ("__builtin_setjmp",
3513		    build_function_type (integer_type_node,
3514					 tree_cons (NULL_TREE,
3515						    ptr_type_node, endlink)),
3516		    BUILT_IN_SETJMP, NULL_PTR);
3517  builtin_function ("__builtin_longjmp",
3518		    build_function_type
3519		    (void_type_node,
3520		     tree_cons (NULL, ptr_type_node,
3521				tree_cons (NULL_TREE,
3522					   integer_type_node,
3523					   endlink))),
3524		    BUILT_IN_LONGJMP, NULL_PTR);
3525  builtin_function ("__builtin_trap",
3526		    build_function_type (void_type_node, endlink),
3527		    BUILT_IN_TRAP, NULL_PTR);
3528
3529  /* In an ANSI C program, it is okay to supply built-in meanings
3530     for these functions, since applications cannot validly use them
3531     with any other meaning.
3532     However, honor the -fno-builtin option.  */
3533  if (!flag_no_builtin)
3534    {
3535      builtin_function ("abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR);
3536      builtin_function ("fabsf", float_ftype_float, BUILT_IN_FABS, NULL_PTR);
3537      builtin_function ("fabs", double_ftype_double, BUILT_IN_FABS, NULL_PTR);
3538      builtin_function ("fabsl", ldouble_ftype_ldouble, BUILT_IN_FABS,
3539			NULL_PTR);
3540      builtin_function ("labs", long_ftype_long, BUILT_IN_LABS, NULL_PTR);
3541      builtin_function ("memcpy", memcpy_ftype, BUILT_IN_MEMCPY, NULL_PTR);
3542      builtin_function ("memcmp", int_ftype_cptr_cptr_sizet, BUILT_IN_MEMCMP,
3543			NULL_PTR);
3544      builtin_function ("memset", memset_ftype, BUILT_IN_MEMSET, NULL_PTR);
3545      builtin_function ("strcmp", int_ftype_string_string, BUILT_IN_STRCMP,
3546			NULL_PTR);
3547      builtin_function ("strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY,
3548			NULL_PTR);
3549      builtin_function ("strlen", strlen_ftype, BUILT_IN_STRLEN, NULL_PTR);
3550      builtin_function ("sqrtf", float_ftype_float, BUILT_IN_FSQRT, NULL_PTR);
3551      builtin_function ("sqrt", double_ftype_double, BUILT_IN_FSQRT, NULL_PTR);
3552      builtin_function ("sqrtl", ldouble_ftype_ldouble, BUILT_IN_FSQRT,
3553			NULL_PTR);
3554      builtin_function ("sinf", float_ftype_float, BUILT_IN_SIN, NULL_PTR);
3555      builtin_function ("sin", double_ftype_double, BUILT_IN_SIN, NULL_PTR);
3556      builtin_function ("sinl", ldouble_ftype_ldouble, BUILT_IN_SIN, NULL_PTR);
3557      builtin_function ("cosf", float_ftype_float, BUILT_IN_COS, NULL_PTR);
3558      builtin_function ("cos", double_ftype_double, BUILT_IN_COS, NULL_PTR);
3559      builtin_function ("cosl", ldouble_ftype_ldouble, BUILT_IN_COS, NULL_PTR);
3560
3561      /* Declare these functions volatile
3562	 to avoid spurious "control drops through" warnings.  */
3563      /* Don't specify the argument types, to avoid errors
3564	 from certain code which isn't valid in ANSI but which exists.  */
3565      temp = builtin_function ("abort", void_ftype_any, NOT_BUILT_IN,
3566			       NULL_PTR);
3567      TREE_THIS_VOLATILE (temp) = 1;
3568      TREE_SIDE_EFFECTS (temp) = 1;
3569      temp = builtin_function ("exit", void_ftype_any, NOT_BUILT_IN, NULL_PTR);
3570      TREE_THIS_VOLATILE (temp) = 1;
3571      TREE_SIDE_EFFECTS (temp) = 1;
3572    }
3573
3574#if 0
3575  /* Support for these has not been written in either expand_builtin
3576     or build_function_call.  */
3577  builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV, NULL_PTR);
3578  builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV, NULL_PTR);
3579  builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR,
3580		    NULL_PTR);
3581  builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL,
3582		    NULL_PTR);
3583  builtin_function ("__builtin_fmod", double_ftype_double_double,
3584		    BUILT_IN_FMOD, NULL_PTR);
3585  builtin_function ("__builtin_frem", double_ftype_double_double,
3586		    BUILT_IN_FREM, NULL_PTR);
3587  builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP,
3588		    NULL_PTR);
3589  builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN,
3590		    NULL_PTR);
3591#endif
3592
3593  pedantic_lvalues = pedantic;
3594
3595  /* Create the global bindings for __FUNCTION__ and __PRETTY_FUNCTION__.  */
3596  declare_function_name ();
3597
3598  start_identifier_warnings ();
3599
3600  /* Prepare to check format strings against argument lists.  */
3601  init_function_format_info ();
3602
3603  init_iterators ();
3604
3605  incomplete_decl_finalize_hook = finish_incomplete_decl;
3606
3607  lang_get_alias_set = c_get_alias_set;
3608}
3609
3610/* Return a definition for a builtin function named NAME and whose data type
3611   is TYPE.  TYPE should be a function type with argument types.
3612   FUNCTION_CODE tells later passes how to compile calls to this function.
3613   See tree.h for its possible values.
3614
3615   If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
3616   the name to be called if we can't opencode the function.  */
3617
3618tree
3619builtin_function (name, type, function_code, library_name)
3620     const char *name;
3621     tree type;
3622     enum built_in_function function_code;
3623     const char *library_name;
3624{
3625  tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type);
3626  DECL_EXTERNAL (decl) = 1;
3627  TREE_PUBLIC (decl) = 1;
3628  /* If -traditional, permit redefining a builtin function any way you like.
3629     (Though really, if the program redefines these functions,
3630     it probably won't work right unless compiled with -fno-builtin.)  */
3631  if (flag_traditional && name[0] != '_')
3632    DECL_BUILT_IN_NONANSI (decl) = 1;
3633  if (library_name)
3634    DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name);
3635  make_decl_rtl (decl, NULL_PTR, 1);
3636  pushdecl (decl);
3637  if (function_code != NOT_BUILT_IN)
3638    {
3639      DECL_BUILT_IN (decl) = 1;
3640      DECL_FUNCTION_CODE (decl) = function_code;
3641    }
3642  /* Warn if a function in the namespace for users
3643     is used without an occasion to consider it declared.  */
3644  if (name[0] != '_' || name[1] != '_')
3645    C_DECL_ANTICIPATED (decl) = 1;
3646
3647  return decl;
3648}
3649
3650/* Called when a declaration is seen that contains no names to declare.
3651   If its type is a reference to a structure, union or enum inherited
3652   from a containing scope, shadow that tag name for the current scope
3653   with a forward reference.
3654   If its type defines a new named structure or union
3655   or defines an enum, it is valid but we need not do anything here.
3656   Otherwise, it is an error.  */
3657
3658void
3659shadow_tag (declspecs)
3660     tree declspecs;
3661{
3662  shadow_tag_warned (declspecs, 0);
3663}
3664
3665void
3666shadow_tag_warned (declspecs, warned)
3667     tree declspecs;
3668     int warned;
3669     /* 1 => we have done a pedwarn.  2 => we have done a warning, but
3670	no pedwarn.  */
3671{
3672  int found_tag = 0;
3673  register tree link;
3674  tree specs, attrs;
3675
3676  pending_invalid_xref = 0;
3677
3678  /* Remove the attributes from declspecs, since they will confuse the
3679     following code.  */
3680  split_specs_attrs (declspecs, &specs, &attrs);
3681
3682  for (link = specs; link; link = TREE_CHAIN (link))
3683    {
3684      register tree value = TREE_VALUE (link);
3685      register enum tree_code code = TREE_CODE (value);
3686
3687      if (code == RECORD_TYPE || code == UNION_TYPE || code == ENUMERAL_TYPE)
3688	/* Used to test also that TYPE_SIZE (value) != 0.
3689	   That caused warning for `struct foo;' at top level in the file.  */
3690	{
3691	  register tree name = lookup_tag_reverse (value);
3692	  register tree t;
3693
3694	  found_tag++;
3695
3696	  if (name == 0)
3697	    {
3698	      if (warned != 1 && code != ENUMERAL_TYPE)
3699		/* Empty unnamed enum OK */
3700		{
3701		  pedwarn ("unnamed struct/union that defines no instances");
3702		  warned = 1;
3703		}
3704	    }
3705	  else
3706	    {
3707	      t = lookup_tag (code, name, current_binding_level, 1);
3708
3709	      if (t == 0)
3710		{
3711		  t = make_node (code);
3712		  pushtag (name, t);
3713		}
3714	    }
3715	}
3716      else
3717	{
3718	  if (!warned && ! in_system_header)
3719	    {
3720	      warning ("useless keyword or type name in empty declaration");
3721	      warned = 2;
3722	    }
3723	}
3724    }
3725
3726  if (found_tag > 1)
3727    error ("two types specified in one empty declaration");
3728
3729  if (warned != 1)
3730    {
3731      if (found_tag == 0)
3732	pedwarn ("empty declaration");
3733    }
3734}
3735
3736/* Decode a "typename", such as "int **", returning a ..._TYPE node.  */
3737
3738tree
3739groktypename (typename)
3740     tree typename;
3741{
3742  if (TREE_CODE (typename) != TREE_LIST)
3743    return typename;
3744  return grokdeclarator (TREE_VALUE (typename),
3745			 TREE_PURPOSE (typename),
3746			 TYPENAME, 0);
3747}
3748
3749/* Return a PARM_DECL node for a given pair of specs and declarator.  */
3750
3751tree
3752groktypename_in_parm_context (typename)
3753     tree typename;
3754{
3755  if (TREE_CODE (typename) != TREE_LIST)
3756    return typename;
3757  return grokdeclarator (TREE_VALUE (typename),
3758			 TREE_PURPOSE (typename),
3759			 PARM, 0);
3760}
3761
3762/* Decode a declarator in an ordinary declaration or data definition.
3763   This is called as soon as the type information and variable name
3764   have been parsed, before parsing the initializer if any.
3765   Here we create the ..._DECL node, fill in its type,
3766   and put it on the list of decls for the current context.
3767   The ..._DECL node is returned as the value.
3768
3769   Exception: for arrays where the length is not specified,
3770   the type is left null, to be filled in by `finish_decl'.
3771
3772   Function definitions do not come here; they go to start_function
3773   instead.  However, external and forward declarations of functions
3774   do go through here.  Structure field declarations are done by
3775   grokfield and not through here.  */
3776
3777/* Set this to zero to debug not using the temporary obstack
3778   to parse initializers.  */
3779int debug_temp_inits = 1;
3780
3781tree
3782start_decl (declarator, declspecs, initialized, attributes, prefix_attributes)
3783     tree declarator, declspecs;
3784     int initialized;
3785     tree attributes, prefix_attributes;
3786{
3787  register tree decl = grokdeclarator (declarator, declspecs,
3788				       NORMAL, initialized);
3789  register tree tem;
3790  int init_written = initialized;
3791
3792  /* The corresponding pop_obstacks is in finish_decl.  */
3793  push_obstacks_nochange ();
3794
3795  if (warn_main > 0 && TREE_CODE (decl) != FUNCTION_DECL
3796      && !strcmp (IDENTIFIER_POINTER (DECL_NAME (decl)), "main"))
3797    warning_with_decl (decl, "`%s' is usually a function");
3798
3799  if (initialized)
3800    /* Is it valid for this decl to have an initializer at all?
3801       If not, set INITIALIZED to zero, which will indirectly
3802       tell `finish_decl' to ignore the initializer once it is parsed.  */
3803    switch (TREE_CODE (decl))
3804      {
3805      case TYPE_DECL:
3806	/* typedef foo = bar  means give foo the same type as bar.
3807	   We haven't parsed bar yet, so `finish_decl' will fix that up.
3808	   Any other case of an initialization in a TYPE_DECL is an error.  */
3809	if (pedantic || list_length (declspecs) > 1)
3810	  {
3811	    error ("typedef `%s' is initialized",
3812		   IDENTIFIER_POINTER (DECL_NAME (decl)));
3813	    initialized = 0;
3814	  }
3815	break;
3816
3817      case FUNCTION_DECL:
3818	error ("function `%s' is initialized like a variable",
3819	       IDENTIFIER_POINTER (DECL_NAME (decl)));
3820	initialized = 0;
3821	break;
3822
3823      case PARM_DECL:
3824	/* DECL_INITIAL in a PARM_DECL is really DECL_ARG_TYPE.  */
3825	error ("parameter `%s' is initialized",
3826	       IDENTIFIER_POINTER (DECL_NAME (decl)));
3827	initialized = 0;
3828	break;
3829
3830      default:
3831	/* Don't allow initializations for incomplete types
3832	   except for arrays which might be completed by the initialization.  */
3833	if (TYPE_SIZE (TREE_TYPE (decl)) != 0)
3834	  {
3835	    /* A complete type is ok if size is fixed.  */
3836
3837	    if (TREE_CODE (TYPE_SIZE (TREE_TYPE (decl))) != INTEGER_CST
3838		|| C_DECL_VARIABLE_SIZE (decl))
3839	      {
3840		error ("variable-sized object may not be initialized");
3841		initialized = 0;
3842	      }
3843	  }
3844	else if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE)
3845	  {
3846	    error ("variable `%s' has initializer but incomplete type",
3847		   IDENTIFIER_POINTER (DECL_NAME (decl)));
3848	    initialized = 0;
3849	  }
3850	else if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl))) == 0)
3851	  {
3852	    error ("elements of array `%s' have incomplete type",
3853		   IDENTIFIER_POINTER (DECL_NAME (decl)));
3854	    initialized = 0;
3855	  }
3856      }
3857
3858  if (initialized)
3859    {
3860#if 0  /* Seems redundant with grokdeclarator.  */
3861      if (current_binding_level != global_binding_level
3862	  && DECL_EXTERNAL (decl)
3863	  && TREE_CODE (decl) != FUNCTION_DECL)
3864	warning ("declaration of `%s' has `extern' and is initialized",
3865		 IDENTIFIER_POINTER (DECL_NAME (decl)));
3866#endif
3867      DECL_EXTERNAL (decl) = 0;
3868      if (current_binding_level == global_binding_level)
3869	TREE_STATIC (decl) = 1;
3870
3871      /* Tell `pushdecl' this is an initialized decl
3872	 even though we don't yet have the initializer expression.
3873	 Also tell `finish_decl' it may store the real initializer.  */
3874      DECL_INITIAL (decl) = error_mark_node;
3875    }
3876
3877  /* If this is a function declaration, write a record describing it to the
3878     prototypes file (if requested).  */
3879
3880  if (TREE_CODE (decl) == FUNCTION_DECL)
3881    gen_aux_info_record (decl, 0, 0, TYPE_ARG_TYPES (TREE_TYPE (decl)) != 0);
3882
3883  /* ANSI specifies that a tentative definition which is not merged with
3884     a non-tentative definition behaves exactly like a definition with an
3885     initializer equal to zero.  (Section 3.7.2)
3886     -fno-common gives strict ANSI behavior.  Usually you don't want it.
3887     This matters only for variables with external linkage.  */
3888  if (! flag_no_common || ! TREE_PUBLIC (decl))
3889    DECL_COMMON (decl) = 1;
3890
3891#ifdef SET_DEFAULT_DECL_ATTRIBUTES
3892  SET_DEFAULT_DECL_ATTRIBUTES (decl, attributes);
3893#endif
3894
3895  /* Set attributes here so if duplicate decl, will have proper attributes.  */
3896  decl_attributes (decl, attributes, prefix_attributes);
3897
3898  /* Add this decl to the current binding level.
3899     TEM may equal DECL or it may be a previous decl of the same name.  */
3900  tem = pushdecl (decl);
3901
3902  /* For a local variable, define the RTL now.  */
3903  if (current_binding_level != global_binding_level
3904      /* But not if this is a duplicate decl
3905	 and we preserved the rtl from the previous one
3906	 (which may or may not happen).  */
3907      && DECL_RTL (tem) == 0)
3908    {
3909      if (TYPE_SIZE (TREE_TYPE (tem)) != 0)
3910	expand_decl (tem);
3911      else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE
3912	       && DECL_INITIAL (tem) != 0)
3913	expand_decl (tem);
3914    }
3915
3916  if (init_written)
3917    {
3918      /* When parsing and digesting the initializer,
3919	 use temporary storage.  Do this even if we will ignore the value.  */
3920      if (current_binding_level == global_binding_level && debug_temp_inits)
3921	temporary_allocation ();
3922    }
3923
3924  return tem;
3925}
3926
3927/* Finish processing of a declaration;
3928   install its initial value.
3929   If the length of an array type is not known before,
3930   it must be determined now, from the initial value, or it is an error.  */
3931
3932void
3933finish_decl (decl, init, asmspec_tree)
3934     tree decl, init;
3935     tree asmspec_tree;
3936{
3937  register tree type = TREE_TYPE (decl);
3938  int was_incomplete = (DECL_SIZE (decl) == 0);
3939  int temporary = allocation_temporary_p ();
3940  char *asmspec = 0;
3941
3942  /* If a name was specified, get the string.   */
3943  if (asmspec_tree)
3944    asmspec = TREE_STRING_POINTER (asmspec_tree);
3945
3946  /* If `start_decl' didn't like having an initialization, ignore it now.  */
3947
3948  if (init != 0 && DECL_INITIAL (decl) == 0)
3949    init = 0;
3950  /* Don't crash if parm is initialized.  */
3951  if (TREE_CODE (decl) == PARM_DECL)
3952    init = 0;
3953
3954  if (ITERATOR_P (decl))
3955    {
3956      if (init == 0)
3957	error_with_decl (decl, "iterator has no initial value");
3958      else
3959	init = save_expr (init);
3960    }
3961
3962  if (init)
3963    {
3964      if (TREE_CODE (decl) != TYPE_DECL)
3965	store_init_value (decl, init);
3966      else
3967	{
3968	  /* typedef foo = bar; store the type of bar as the type of foo.  */
3969	  TREE_TYPE (decl) = TREE_TYPE (init);
3970	  DECL_INITIAL (decl) = init = 0;
3971	}
3972    }
3973
3974  /* Pop back to the obstack that is current for this binding level.
3975     This is because MAXINDEX, rtl, etc. to be made below
3976     must go in the permanent obstack.  But don't discard the
3977     temporary data yet.  */
3978  pop_obstacks ();
3979#if 0 /* pop_obstacks was near the end; this is what was here.  */
3980  if (current_binding_level == global_binding_level && temporary)
3981    end_temporary_allocation ();
3982#endif
3983
3984  /* Deduce size of array from initialization, if not already known */
3985
3986  if (TREE_CODE (type) == ARRAY_TYPE
3987      && TYPE_DOMAIN (type) == 0
3988      && TREE_CODE (decl) != TYPE_DECL)
3989    {
3990      int do_default
3991	= (TREE_STATIC (decl)
3992	   /* Even if pedantic, an external linkage array
3993	      may have incomplete type at first.  */
3994	   ? pedantic && !TREE_PUBLIC (decl)
3995	   : !DECL_EXTERNAL (decl));
3996      int failure
3997	= complete_array_type (type, DECL_INITIAL (decl), do_default);
3998
3999      /* Get the completed type made by complete_array_type.  */
4000      type = TREE_TYPE (decl);
4001
4002      if (failure == 1)
4003	error_with_decl (decl, "initializer fails to determine size of `%s'");
4004
4005      if (failure == 2)
4006	{
4007	  if (do_default)
4008	    error_with_decl (decl, "array size missing in `%s'");
4009	  /* If a `static' var's size isn't known,
4010	     make it extern as well as static, so it does not get
4011	     allocated.
4012	     If it is not `static', then do not mark extern;
4013	     finish_incomplete_decl will give it a default size
4014	     and it will get allocated.  */
4015	  else if (!pedantic && TREE_STATIC (decl) && ! TREE_PUBLIC (decl))
4016	    DECL_EXTERNAL (decl) = 1;
4017	}
4018
4019      /* TYPE_MAX_VALUE is always one less than the number of elements
4020	 in the array, because we start counting at zero.  Therefore,
4021	 warn only if the value is less than zero.  */
4022      if (pedantic && TYPE_DOMAIN (type) != 0
4023	  && tree_int_cst_sgn (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) < 0)
4024	error_with_decl (decl, "zero or negative size array `%s'");
4025
4026      layout_decl (decl, 0);
4027    }
4028
4029  if (TREE_CODE (decl) == VAR_DECL)
4030    {
4031      if (DECL_SIZE (decl) == 0
4032	  && TYPE_SIZE (TREE_TYPE (decl)) != 0)
4033	layout_decl (decl, 0);
4034
4035      if (DECL_SIZE (decl) == 0
4036	  && (TREE_STATIC (decl)
4037	      ?
4038		/* A static variable with an incomplete type
4039		   is an error if it is initialized.
4040		   Also if it is not file scope.
4041		   Otherwise, let it through, but if it is not `extern'
4042		   then it may cause an error message later.  */
4043	      /* A duplicate_decls call could have changed an extern
4044		 declaration into a file scope one.  This can be detected
4045		 by TREE_ASM_WRITTEN being set.  */
4046		(DECL_INITIAL (decl) != 0
4047		 || (DECL_CONTEXT (decl) != 0 && ! TREE_ASM_WRITTEN (decl)))
4048	      :
4049		/* An automatic variable with an incomplete type
4050		   is an error.  */
4051		!DECL_EXTERNAL (decl)))
4052	{
4053	  error_with_decl (decl, "storage size of `%s' isn't known");
4054	  TREE_TYPE (decl) = error_mark_node;
4055	}
4056
4057      if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
4058	  && DECL_SIZE (decl) != 0)
4059	{
4060	  if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
4061	    constant_expression_warning (DECL_SIZE (decl));
4062	  else
4063	    error_with_decl (decl, "storage size of `%s' isn't constant");
4064	}
4065
4066      if (TREE_USED  (type))
4067	TREE_USED (decl) = 1;
4068    }
4069
4070  /* If this is a function and an assembler name is specified, it isn't
4071     builtin any more.  Also reset DECL_RTL so we can give it its new
4072     name.  */
4073  if (TREE_CODE (decl) == FUNCTION_DECL && asmspec)
4074      {
4075	DECL_BUILT_IN (decl) = 0;
4076	DECL_RTL (decl) = 0;
4077      }
4078
4079  /* Output the assembler code and/or RTL code for variables and functions,
4080     unless the type is an undefined structure or union.
4081     If not, it will get done when the type is completed.  */
4082
4083  if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL)
4084    {
4085      if ((flag_traditional || TREE_PERMANENT (decl))
4086	  && allocation_temporary_p ())
4087	{
4088	  push_obstacks_nochange ();
4089	  end_temporary_allocation ();
4090	  /* This is a no-op in c-lang.c or something real in objc-actions.c.  */
4091	  maybe_objc_check_decl (decl);
4092	  rest_of_decl_compilation (decl, asmspec,
4093				    (DECL_CONTEXT (decl) == 0
4094				     || TREE_ASM_WRITTEN (decl)),
4095				    0);
4096	  pop_obstacks ();
4097	}
4098      else
4099	{
4100	  /* This is a no-op in c-lang.c or something real in objc-actions.c.  */
4101	  maybe_objc_check_decl (decl);
4102	  rest_of_decl_compilation (decl, asmspec, DECL_CONTEXT (decl) == 0,
4103				    0);
4104	}
4105      if (DECL_CONTEXT (decl) != 0)
4106	{
4107	  /* Recompute the RTL of a local array now
4108	     if it used to be an incomplete type.  */
4109	  if (was_incomplete
4110	      && ! TREE_STATIC (decl) && ! DECL_EXTERNAL (decl))
4111	    {
4112	      /* If we used it already as memory, it must stay in memory.  */
4113	      TREE_ADDRESSABLE (decl) = TREE_USED (decl);
4114	      /* If it's still incomplete now, no init will save it.  */
4115	      if (DECL_SIZE (decl) == 0)
4116		DECL_INITIAL (decl) = 0;
4117	      expand_decl (decl);
4118	    }
4119	  /* Compute and store the initial value.  */
4120	  if (TREE_CODE (decl) != FUNCTION_DECL)
4121	    expand_decl_init (decl);
4122	}
4123    }
4124
4125  if (TREE_CODE (decl) == TYPE_DECL)
4126    {
4127      /* This is a no-op in c-lang.c or something real in objc-actions.c.  */
4128      maybe_objc_check_decl (decl);
4129      rest_of_decl_compilation (decl, NULL_PTR, DECL_CONTEXT (decl) == 0,
4130				0);
4131    }
4132
4133  /* ??? After 2.3, test (init != 0) instead of TREE_CODE.  */
4134  /* This test used to include TREE_PERMANENT, however, we have the same
4135     problem with initializers at the function level.  Such initializers get
4136     saved until the end of the function on the momentary_obstack.  */
4137  if (!(TREE_CODE (decl) == FUNCTION_DECL && DECL_INLINE (decl))
4138      && temporary
4139      /* DECL_INITIAL is not defined in PARM_DECLs, since it shares
4140	 space with DECL_ARG_TYPE.  */
4141      && TREE_CODE (decl) != PARM_DECL)
4142    {
4143      /* We need to remember that this array HAD an initialization,
4144	 but discard the actual temporary nodes,
4145	 since we can't have a permanent node keep pointing to them.  */
4146      /* We make an exception for inline functions, since it's
4147	 normal for a local extern redeclaration of an inline function
4148	 to have a copy of the top-level decl's DECL_INLINE.  */
4149      if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
4150	{
4151	  /* If this is a const variable, then preserve the
4152	     initializer instead of discarding it so that we can optimize
4153	     references to it.  */
4154	  /* This test used to include TREE_STATIC, but this won't be set
4155	     for function level initializers.  */
4156	  if (TREE_READONLY (decl) || ITERATOR_P (decl))
4157	    {
4158	      preserve_initializer ();
4159	      /* Hack?  Set the permanent bit for something that is permanent,
4160		 but not on the permanent obstack, so as to convince
4161		 output_constant_def to make its rtl on the permanent
4162		 obstack.  */
4163	      TREE_PERMANENT (DECL_INITIAL (decl)) = 1;
4164
4165	      /* The initializer and DECL must have the same (or equivalent
4166		 types), but if the initializer is a STRING_CST, its type
4167		 might not be on the right obstack, so copy the type
4168		 of DECL.  */
4169	      TREE_TYPE (DECL_INITIAL (decl)) = type;
4170	    }
4171	  else
4172	    DECL_INITIAL (decl) = error_mark_node;
4173	}
4174    }
4175
4176  /* If requested, warn about definitions of large data objects.  */
4177
4178  if (warn_larger_than
4179      && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL)
4180      && !DECL_EXTERNAL (decl))
4181    {
4182      register tree decl_size = DECL_SIZE (decl);
4183
4184      if (decl_size && TREE_CODE (decl_size) == INTEGER_CST)
4185	{
4186	   unsigned units = TREE_INT_CST_LOW(decl_size) / BITS_PER_UNIT;
4187
4188	  if (units > larger_than_size)
4189	    warning_with_decl (decl, "size of `%s' is %u bytes", units);
4190	}
4191    }
4192
4193#if 0
4194  /* Resume permanent allocation, if not within a function.  */
4195  /* The corresponding push_obstacks_nochange is in start_decl,
4196     and in push_parm_decl and in grokfield.  */
4197  pop_obstacks ();
4198#endif
4199
4200  /* If we have gone back from temporary to permanent allocation,
4201     actually free the temporary space that we no longer need.  */
4202  if (temporary && !allocation_temporary_p ())
4203    permanent_allocation (0);
4204
4205  /* At the end of a declaration, throw away any variable type sizes
4206     of types defined inside that declaration.  There is no use
4207     computing them in the following function definition.  */
4208  if (current_binding_level == global_binding_level)
4209    get_pending_sizes ();
4210}
4211
4212/* If DECL has a cleanup, build and return that cleanup here.
4213   This is a callback called by expand_expr.  */
4214
4215tree
4216maybe_build_cleanup (decl)
4217     tree decl ATTRIBUTE_UNUSED;
4218{
4219  /* There are no cleanups in C.  */
4220  return NULL_TREE;
4221}
4222
4223/* Given a parsed parameter declaration,
4224   decode it into a PARM_DECL and push that on the current binding level.
4225   Also, for the sake of forward parm decls,
4226   record the given order of parms in `parm_order'.  */
4227
4228void
4229push_parm_decl (parm)
4230     tree parm;
4231{
4232  tree decl;
4233  int old_immediate_size_expand = immediate_size_expand;
4234  /* Don't try computing parm sizes now -- wait till fn is called.  */
4235  immediate_size_expand = 0;
4236
4237  /* The corresponding pop_obstacks is in finish_decl.  */
4238  push_obstacks_nochange ();
4239
4240  decl = grokdeclarator (TREE_VALUE (TREE_PURPOSE (parm)),
4241			 TREE_PURPOSE (TREE_PURPOSE (parm)), PARM, 0);
4242  decl_attributes (decl, TREE_VALUE (TREE_VALUE (parm)),
4243		   TREE_PURPOSE (TREE_VALUE (parm)));
4244
4245#if 0
4246  if (DECL_NAME (decl))
4247    {
4248      tree olddecl;
4249      olddecl = lookup_name (DECL_NAME (decl));
4250      if (pedantic && olddecl != 0 && TREE_CODE (olddecl) == TYPE_DECL)
4251	pedwarn_with_decl (decl, "ANSI C forbids parameter `%s' shadowing typedef");
4252    }
4253#endif
4254
4255  decl = pushdecl (decl);
4256
4257  immediate_size_expand = old_immediate_size_expand;
4258
4259  current_binding_level->parm_order
4260    = tree_cons (NULL_TREE, decl, current_binding_level->parm_order);
4261
4262  /* Add this decl to the current binding level.  */
4263  finish_decl (decl, NULL_TREE, NULL_TREE);
4264}
4265
4266/* Clear the given order of parms in `parm_order'.
4267   Used at start of parm list,
4268   and also at semicolon terminating forward decls.  */
4269
4270void
4271clear_parm_order ()
4272{
4273  current_binding_level->parm_order = NULL_TREE;
4274}
4275
4276/* Make TYPE a complete type based on INITIAL_VALUE.
4277   Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
4278   2 if there was no information (in which case assume 1 if DO_DEFAULT).  */
4279
4280int
4281complete_array_type (type, initial_value, do_default)
4282     tree type;
4283     tree initial_value;
4284     int do_default;
4285{
4286  register tree maxindex = NULL_TREE;
4287  int value = 0;
4288
4289  if (initial_value)
4290    {
4291      /* Note MAXINDEX  is really the maximum index,
4292	 one less than the size.  */
4293      if (TREE_CODE (initial_value) == STRING_CST)
4294	{
4295	  int eltsize
4296	    = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value)));
4297	  maxindex = build_int_2 ((TREE_STRING_LENGTH (initial_value)
4298				   / eltsize) - 1, 0);
4299	}
4300      else if (TREE_CODE (initial_value) == CONSTRUCTOR)
4301	{
4302	  tree elts = CONSTRUCTOR_ELTS (initial_value);
4303	  maxindex = size_binop (MINUS_EXPR, integer_zero_node, size_one_node);
4304	  for (; elts; elts = TREE_CHAIN (elts))
4305	    {
4306	      if (TREE_PURPOSE (elts))
4307		maxindex = TREE_PURPOSE (elts);
4308	      else
4309		maxindex = size_binop (PLUS_EXPR, maxindex, size_one_node);
4310	    }
4311	  maxindex = copy_node (maxindex);
4312	}
4313      else
4314	{
4315	  /* Make an error message unless that happened already.  */
4316	  if (initial_value != error_mark_node)
4317	    value = 1;
4318
4319	  /* Prevent further error messages.  */
4320	  maxindex = build_int_2 (0, 0);
4321	}
4322    }
4323
4324  if (!maxindex)
4325    {
4326      if (do_default)
4327	maxindex = build_int_2 (0, 0);
4328      value = 2;
4329    }
4330
4331  if (maxindex)
4332    {
4333      TYPE_DOMAIN (type) = build_index_type (maxindex);
4334      if (!TREE_TYPE (maxindex))
4335	TREE_TYPE (maxindex) = TYPE_DOMAIN (type);
4336    }
4337
4338  /* Lay out the type now that we can get the real answer.  */
4339
4340  layout_type (type);
4341
4342  return value;
4343}
4344
4345/* Given declspecs and a declarator,
4346   determine the name and type of the object declared
4347   and construct a ..._DECL node for it.
4348   (In one case we can return a ..._TYPE node instead.
4349    For invalid input we sometimes return 0.)
4350
4351   DECLSPECS is a chain of tree_list nodes whose value fields
4352    are the storage classes and type specifiers.
4353
4354   DECL_CONTEXT says which syntactic context this declaration is in:
4355     NORMAL for most contexts.  Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
4356     FUNCDEF for a function definition.  Like NORMAL but a few different
4357      error messages in each case.  Return value may be zero meaning
4358      this definition is too screwy to try to parse.
4359     PARM for a parameter declaration (either within a function prototype
4360      or before a function body).  Make a PARM_DECL, or return void_type_node.
4361     TYPENAME if for a typename (in a cast or sizeof).
4362      Don't make a DECL node; just return the ..._TYPE node.
4363     FIELD for a struct or union field; make a FIELD_DECL.
4364     BITFIELD for a field with specified width.
4365   INITIALIZED is 1 if the decl has an initializer.
4366
4367   In the TYPENAME case, DECLARATOR is really an absolute declarator.
4368   It may also be so in the PARM case, for a prototype where the
4369   argument type is specified but not the name.
4370
4371   This function is where the complicated C meanings of `static'
4372   and `extern' are interpreted.  */
4373
4374static tree
4375grokdeclarator (declarator, declspecs, decl_context, initialized)
4376     tree declspecs;
4377     tree declarator;
4378     enum decl_context decl_context;
4379     int initialized;
4380{
4381  int specbits = 0;
4382  tree spec;
4383  tree type = NULL_TREE;
4384  int longlong = 0;
4385  int constp;
4386  int restrictp;
4387  int volatilep;
4388  int type_quals = TYPE_UNQUALIFIED;
4389  int inlinep;
4390  int explicit_int = 0;
4391  int explicit_char = 0;
4392  int defaulted_int = 0;
4393  tree typedef_decl = 0;
4394  const char *name;
4395  tree typedef_type = 0;
4396  int funcdef_flag = 0;
4397  enum tree_code innermost_code = ERROR_MARK;
4398  int bitfield = 0;
4399  int size_varies = 0;
4400  tree decl_machine_attr = NULL_TREE;
4401
4402  if (decl_context == BITFIELD)
4403    bitfield = 1, decl_context = FIELD;
4404
4405  if (decl_context == FUNCDEF)
4406    funcdef_flag = 1, decl_context = NORMAL;
4407
4408  push_obstacks_nochange ();
4409
4410  if (flag_traditional && allocation_temporary_p ())
4411    end_temporary_allocation ();
4412
4413  /* Look inside a declarator for the name being declared
4414     and get it as a string, for an error message.  */
4415  {
4416    register tree decl = declarator;
4417    name = 0;
4418
4419    while (decl)
4420      switch (TREE_CODE (decl))
4421	{
4422	case ARRAY_REF:
4423	case INDIRECT_REF:
4424	case CALL_EXPR:
4425	  innermost_code = TREE_CODE (decl);
4426	  decl = TREE_OPERAND (decl, 0);
4427	  break;
4428
4429	case IDENTIFIER_NODE:
4430	  name = IDENTIFIER_POINTER (decl);
4431	  decl = 0;
4432	  break;
4433
4434	default:
4435	  abort ();
4436	}
4437    if (name == 0)
4438      name = "type name";
4439  }
4440
4441  /* A function definition's declarator must have the form of
4442     a function declarator.  */
4443
4444  if (funcdef_flag && innermost_code != CALL_EXPR)
4445    return 0;
4446
4447  /* Anything declared one level down from the top level
4448     must be one of the parameters of a function
4449     (because the body is at least two levels down).  */
4450
4451  /* If this looks like a function definition, make it one,
4452     even if it occurs where parms are expected.
4453     Then store_parm_decls will reject it and not use it as a parm.  */
4454  if (decl_context == NORMAL && !funcdef_flag
4455      && current_binding_level->parm_flag)
4456    decl_context = PARM;
4457
4458  /* Look through the decl specs and record which ones appear.
4459     Some typespecs are defined as built-in typenames.
4460     Others, the ones that are modifiers of other types,
4461     are represented by bits in SPECBITS: set the bits for
4462     the modifiers that appear.  Storage class keywords are also in SPECBITS.
4463
4464     If there is a typedef name or a type, store the type in TYPE.
4465     This includes builtin typedefs such as `int'.
4466
4467     Set EXPLICIT_INT or EXPLICIT_CHAR if the type is `int' or `char'
4468     and did not come from a user typedef.
4469
4470     Set LONGLONG if `long' is mentioned twice.  */
4471
4472  for (spec = declspecs; spec; spec = TREE_CHAIN (spec))
4473    {
4474      register int i;
4475      register tree id = TREE_VALUE (spec);
4476
4477      if (id == ridpointers[(int) RID_INT])
4478	explicit_int = 1;
4479      if (id == ridpointers[(int) RID_CHAR])
4480	explicit_char = 1;
4481
4482      if (TREE_CODE (id) == IDENTIFIER_NODE)
4483	for (i = (int) RID_FIRST_MODIFIER; i < (int) RID_MAX; i++)
4484	  {
4485	    if (ridpointers[i] == id)
4486	      {
4487		if (i == (int) RID_LONG && specbits & (1<<i))
4488		  {
4489		    if (longlong)
4490		      error ("`long long long' is too long for GCC");
4491		    else
4492		      {
4493			if (pedantic && ! in_system_header && warn_long_long)
4494			  pedwarn ("ANSI C does not support `long long'");
4495			longlong = 1;
4496		      }
4497		  }
4498		else if (specbits & (1 << i))
4499		  pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id));
4500		specbits |= 1 << i;
4501		goto found;
4502	      }
4503	  }
4504      if (type)
4505	error ("two or more data types in declaration of `%s'", name);
4506      /* Actual typedefs come to us as TYPE_DECL nodes.  */
4507      else if (TREE_CODE (id) == TYPE_DECL)
4508	{
4509	  type = TREE_TYPE (id);
4510          decl_machine_attr = DECL_MACHINE_ATTRIBUTES (id);
4511	  typedef_decl = id;
4512	}
4513      /* Built-in types come as identifiers.  */
4514      else if (TREE_CODE (id) == IDENTIFIER_NODE)
4515	{
4516	  register tree t = lookup_name (id);
4517	  if (TREE_TYPE (t) == error_mark_node)
4518	    ;
4519	  else if (!t || TREE_CODE (t) != TYPE_DECL)
4520	    error ("`%s' fails to be a typedef or built in type",
4521		   IDENTIFIER_POINTER (id));
4522	  else
4523	    {
4524	      type = TREE_TYPE (t);
4525	      typedef_decl = t;
4526	    }
4527	}
4528      else if (TREE_CODE (id) != ERROR_MARK)
4529	type = id;
4530
4531    found: {}
4532    }
4533
4534  typedef_type = type;
4535  if (type)
4536    size_varies = C_TYPE_VARIABLE_SIZE (type);
4537
4538  /* No type at all: default to `int', and set DEFAULTED_INT
4539     because it was not a user-defined typedef.  */
4540
4541  if (type == 0)
4542    {
4543      if ((! (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
4544			  | (1 << (int) RID_SIGNED)
4545			  | (1 << (int) RID_UNSIGNED))))
4546	  /* Don't warn about typedef foo = bar.  */
4547	  && ! (specbits & (1 << (int) RID_TYPEDEF) && initialized)
4548	  && ! (in_system_header && ! allocation_temporary_p ()))
4549	{
4550	  /* Issue a warning if this is an ISO C 9x program or if -Wreturn-type
4551	     and this is a function, or if -Wimplicit; prefer the former
4552	     warning since it is more explicit.  */
4553	  if ((warn_implicit_int || warn_return_type) && funcdef_flag)
4554	    warn_about_return_type = 1;
4555	  else if (warn_implicit_int || flag_isoc9x)
4556	    warning ("type defaults to `int' in declaration of `%s'", name);
4557	}
4558
4559      defaulted_int = 1;
4560      type = integer_type_node;
4561    }
4562
4563  /* Now process the modifiers that were specified
4564     and check for invalid combinations.  */
4565
4566  /* Long double is a special combination.  */
4567
4568  if ((specbits & 1 << (int) RID_LONG) && ! longlong
4569      && TYPE_MAIN_VARIANT (type) == double_type_node)
4570    {
4571      specbits &= ~ (1 << (int) RID_LONG);
4572      type = long_double_type_node;
4573    }
4574
4575  /* Check all other uses of type modifiers.  */
4576
4577  if (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
4578		  | (1 << (int) RID_UNSIGNED) | (1 << (int) RID_SIGNED)))
4579    {
4580      int ok = 0;
4581
4582      if ((specbits & 1 << (int) RID_LONG)
4583	  && (specbits & 1 << (int) RID_SHORT))
4584	error ("both long and short specified for `%s'", name);
4585      else if (((specbits & 1 << (int) RID_LONG)
4586		|| (specbits & 1 << (int) RID_SHORT))
4587	       && explicit_char)
4588	error ("long or short specified with char for `%s'", name);
4589      else if (((specbits & 1 << (int) RID_LONG)
4590		|| (specbits & 1 << (int) RID_SHORT))
4591	       && TREE_CODE (type) == REAL_TYPE)
4592	{
4593	  static int already = 0;
4594
4595	  error ("long or short specified with floating type for `%s'", name);
4596	  if (! already && ! pedantic)
4597	    {
4598	      error ("the only valid combination is `long double'");
4599	      already = 1;
4600	    }
4601	}
4602      else if ((specbits & 1 << (int) RID_SIGNED)
4603	       && (specbits & 1 << (int) RID_UNSIGNED))
4604	error ("both signed and unsigned specified for `%s'", name);
4605      else if (TREE_CODE (type) != INTEGER_TYPE)
4606	error ("long, short, signed or unsigned invalid for `%s'", name);
4607      else
4608	{
4609	  ok = 1;
4610	  if (!explicit_int && !defaulted_int && !explicit_char && pedantic)
4611	    {
4612	      pedwarn ("long, short, signed or unsigned used invalidly for `%s'",
4613		       name);
4614	      if (flag_pedantic_errors)
4615		ok = 0;
4616	    }
4617	}
4618
4619      /* Discard the type modifiers if they are invalid.  */
4620      if (! ok)
4621	{
4622	  specbits &= ~((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
4623			| (1 << (int) RID_UNSIGNED) | (1 << (int) RID_SIGNED));
4624	  longlong = 0;
4625	}
4626    }
4627
4628  if ((specbits & (1 << (int) RID_COMPLEX))
4629      && TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
4630    {
4631      error ("complex invalid for `%s'", name);
4632      specbits &= ~ (1 << (int) RID_COMPLEX);
4633    }
4634
4635  /* Decide whether an integer type is signed or not.
4636     Optionally treat bitfields as signed by default.  */
4637  if (specbits & 1 << (int) RID_UNSIGNED
4638      /* Traditionally, all bitfields are unsigned.  */
4639      || (bitfield && flag_traditional
4640	  && (! explicit_flag_signed_bitfields || !flag_signed_bitfields))
4641      || (bitfield && ! flag_signed_bitfields
4642	  && (explicit_int || defaulted_int || explicit_char
4643	      /* A typedef for plain `int' without `signed'
4644		 can be controlled just like plain `int'.  */
4645	      || ! (typedef_decl != 0
4646		    && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
4647	  && TREE_CODE (type) != ENUMERAL_TYPE
4648	  && !(specbits & 1 << (int) RID_SIGNED)))
4649    {
4650      if (longlong)
4651	type = long_long_unsigned_type_node;
4652      else if (specbits & 1 << (int) RID_LONG)
4653	type = long_unsigned_type_node;
4654      else if (specbits & 1 << (int) RID_SHORT)
4655	type = short_unsigned_type_node;
4656      else if (type == char_type_node)
4657	type = unsigned_char_type_node;
4658      else if (typedef_decl)
4659	type = unsigned_type (type);
4660      else
4661	type = unsigned_type_node;
4662    }
4663  else if ((specbits & 1 << (int) RID_SIGNED)
4664	   && type == char_type_node)
4665    type = signed_char_type_node;
4666  else if (longlong)
4667    type = long_long_integer_type_node;
4668  else if (specbits & 1 << (int) RID_LONG)
4669    type = long_integer_type_node;
4670  else if (specbits & 1 << (int) RID_SHORT)
4671    type = short_integer_type_node;
4672
4673  if (specbits & 1 << (int) RID_COMPLEX)
4674    {
4675      /* If we just have "complex", it is equivalent to
4676	 "complex double", but if any modifiers at all are specified it is
4677	 the complex form of TYPE.  E.g, "complex short" is
4678	 "complex short int".  */
4679
4680      if (defaulted_int && ! longlong
4681	  && ! (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
4682			    | (1 << (int) RID_SIGNED)
4683			    | (1 << (int) RID_UNSIGNED))))
4684	type = complex_double_type_node;
4685      else if (type == integer_type_node)
4686	type = complex_integer_type_node;
4687      else if (type == float_type_node)
4688	type = complex_float_type_node;
4689      else if (type == double_type_node)
4690	type = complex_double_type_node;
4691      else if (type == long_double_type_node)
4692	type = complex_long_double_type_node;
4693      else
4694	type = build_complex_type (type);
4695    }
4696
4697  /* Figure out the type qualifiers for the declaration.  There are
4698     two ways a declaration can become qualified.  One is something
4699     like `const int i' where the `const' is explicit.  Another is
4700     something like `typedef const int CI; CI i' where the type of the
4701     declaration contains the `const'.  */
4702  constp = !! (specbits & 1 << (int) RID_CONST) + TYPE_READONLY (type);
4703  restrictp = !! (specbits & 1 << (int) RID_RESTRICT) + TYPE_RESTRICT (type);
4704  volatilep = !! (specbits & 1 << (int) RID_VOLATILE) + TYPE_VOLATILE (type);
4705  inlinep = !! (specbits & (1 << (int) RID_INLINE));
4706  if (constp > 1)
4707    pedwarn ("duplicate `const'");
4708  if (restrictp > 1)
4709    pedwarn ("duplicate `restrict'");
4710  if (volatilep > 1)
4711    pedwarn ("duplicate `volatile'");
4712  if (! flag_gen_aux_info && (TYPE_QUALS (type)))
4713    type = TYPE_MAIN_VARIANT (type);
4714  type_quals = ((constp ? TYPE_QUAL_CONST : 0)
4715		| (restrictp ? TYPE_QUAL_RESTRICT : 0)
4716		| (volatilep ? TYPE_QUAL_VOLATILE : 0));
4717
4718  /* Warn if two storage classes are given. Default to `auto'.  */
4719
4720  {
4721    int nclasses = 0;
4722
4723    if (specbits & 1 << (int) RID_AUTO) nclasses++;
4724    if (specbits & 1 << (int) RID_STATIC) nclasses++;
4725    if (specbits & 1 << (int) RID_EXTERN) nclasses++;
4726    if (specbits & 1 << (int) RID_REGISTER) nclasses++;
4727    if (specbits & 1 << (int) RID_TYPEDEF) nclasses++;
4728    if (specbits & 1 << (int) RID_ITERATOR) nclasses++;
4729
4730    /* Warn about storage classes that are invalid for certain
4731       kinds of declarations (parameters, typenames, etc.).  */
4732
4733    if (nclasses > 1)
4734      error ("multiple storage classes in declaration of `%s'", name);
4735    else if (funcdef_flag
4736	     && (specbits
4737		 & ((1 << (int) RID_REGISTER)
4738		    | (1 << (int) RID_AUTO)
4739		    | (1 << (int) RID_TYPEDEF))))
4740      {
4741	if (specbits & 1 << (int) RID_AUTO
4742	    && (pedantic || current_binding_level == global_binding_level))
4743	  pedwarn ("function definition declared `auto'");
4744	if (specbits & 1 << (int) RID_REGISTER)
4745	  error ("function definition declared `register'");
4746	if (specbits & 1 << (int) RID_TYPEDEF)
4747	  error ("function definition declared `typedef'");
4748	specbits &= ~ ((1 << (int) RID_TYPEDEF) | (1 << (int) RID_REGISTER)
4749		       | (1 << (int) RID_AUTO));
4750      }
4751    else if (decl_context != NORMAL && nclasses > 0)
4752      {
4753	if (decl_context == PARM && specbits & 1 << (int) RID_REGISTER)
4754	  ;
4755	else
4756	  {
4757	    error ((decl_context == FIELD
4758		    ? "storage class specified for structure field `%s'"
4759		    : (decl_context == PARM
4760		       ? "storage class specified for parameter `%s'"
4761		       : "storage class specified for typename")),
4762		   name);
4763	    specbits &= ~ ((1 << (int) RID_TYPEDEF) | (1 << (int) RID_REGISTER)
4764			   | (1 << (int) RID_AUTO) | (1 << (int) RID_STATIC)
4765			   | (1 << (int) RID_EXTERN));
4766	  }
4767      }
4768    else if (specbits & 1 << (int) RID_EXTERN && initialized && ! funcdef_flag)
4769      {
4770	/* `extern' with initialization is invalid if not at top level.  */
4771	if (current_binding_level == global_binding_level)
4772	  warning ("`%s' initialized and declared `extern'", name);
4773	else
4774	  error ("`%s' has both `extern' and initializer", name);
4775      }
4776    else if (specbits & 1 << (int) RID_EXTERN && funcdef_flag
4777	     && current_binding_level != global_binding_level)
4778      error ("nested function `%s' declared `extern'", name);
4779    else if (current_binding_level == global_binding_level
4780	     && specbits & (1 << (int) RID_AUTO))
4781      error ("top-level declaration of `%s' specifies `auto'", name);
4782    else if ((specbits & 1 << (int) RID_ITERATOR)
4783	     && TREE_CODE (declarator) != IDENTIFIER_NODE)
4784      {
4785	error ("iterator `%s' has derived type", name);
4786	type = error_mark_node;
4787      }
4788    else if ((specbits & 1 << (int) RID_ITERATOR)
4789	     && TREE_CODE (type) != INTEGER_TYPE)
4790      {
4791	error ("iterator `%s' has noninteger type", name);
4792	type = error_mark_node;
4793      }
4794  }
4795
4796  /* Now figure out the structure of the declarator proper.
4797     Descend through it, creating more complex types, until we reach
4798     the declared identifier (or NULL_TREE, in an absolute declarator).  */
4799
4800  while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE)
4801    {
4802      if (type == error_mark_node)
4803	{
4804	  declarator = TREE_OPERAND (declarator, 0);
4805	  continue;
4806	}
4807
4808      /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]),
4809	 an INDIRECT_REF (for *...),
4810	 a CALL_EXPR (for ...(...)),
4811	 an identifier (for the name being declared)
4812	 or a null pointer (for the place in an absolute declarator
4813	 where the name was omitted).
4814	 For the last two cases, we have just exited the loop.
4815
4816	 At this point, TYPE is the type of elements of an array,
4817	 or for a function to return, or for a pointer to point to.
4818	 After this sequence of ifs, TYPE is the type of the
4819	 array or function or pointer, and DECLARATOR has had its
4820	 outermost layer removed.  */
4821
4822      if (TREE_CODE (declarator) == ARRAY_REF)
4823	{
4824	  register tree itype = NULL_TREE;
4825	  register tree size = TREE_OPERAND (declarator, 1);
4826	  /* An uninitialized decl with `extern' is a reference.  */
4827	  int extern_ref = !initialized && (specbits & (1 << (int) RID_EXTERN));
4828	  /* The index is a signed object `sizetype' bits wide.  */
4829	  tree index_type = signed_type (sizetype);
4830
4831	  declarator = TREE_OPERAND (declarator, 0);
4832
4833	  /* Check for some types that there cannot be arrays of.  */
4834
4835	  if (TYPE_MAIN_VARIANT (type) == void_type_node)
4836	    {
4837	      error ("declaration of `%s' as array of voids", name);
4838	      type = error_mark_node;
4839	    }
4840
4841	  if (TREE_CODE (type) == FUNCTION_TYPE)
4842	    {
4843	      error ("declaration of `%s' as array of functions", name);
4844	      type = error_mark_node;
4845	    }
4846
4847	  if (size == error_mark_node)
4848	    type = error_mark_node;
4849
4850	  if (type == error_mark_node)
4851	    continue;
4852
4853	  /* If this is a block level extern, it must live past the end
4854	     of the function so that we can check it against other extern
4855	     declarations (IDENTIFIER_LIMBO_VALUE).  */
4856	  if (extern_ref && allocation_temporary_p ())
4857	    end_temporary_allocation ();
4858
4859	  /* If size was specified, set ITYPE to a range-type for that size.
4860	     Otherwise, ITYPE remains null.  finish_decl may figure it out
4861	     from an initial value.  */
4862
4863	  if (size)
4864	    {
4865	      /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
4866	      STRIP_TYPE_NOPS (size);
4867
4868	      if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE
4869		  && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE)
4870		{
4871		  error ("size of array `%s' has non-integer type", name);
4872		  size = integer_one_node;
4873		}
4874
4875	      if (pedantic && integer_zerop (size))
4876		pedwarn ("ANSI C forbids zero-size array `%s'", name);
4877
4878	      if (TREE_CODE (size) == INTEGER_CST)
4879		{
4880		  constant_expression_warning (size);
4881		  if (tree_int_cst_sgn (size) < 0)
4882		    {
4883		      error ("size of array `%s' is negative", name);
4884		      size = integer_one_node;
4885		    }
4886		}
4887	      else
4888		{
4889		  /* Make sure the array size remains visibly nonconstant
4890		     even if it is (eg) a const variable with known value.  */
4891		  size_varies = 1;
4892
4893		  if (pedantic)
4894		    {
4895		      if (TREE_CONSTANT (size))
4896			pedwarn ("ANSI C forbids array `%s' whose size can't be evaluated", name);
4897		      else
4898			pedwarn ("ANSI C forbids variable-size array `%s'", name);
4899		    }
4900		}
4901
4902	      /* Convert size to index_type, so that if it is a variable
4903		 the computations will be done in the proper mode.  */
4904	      itype = fold (build (MINUS_EXPR, index_type,
4905				   convert (index_type, size),
4906				   convert (index_type, size_one_node)));
4907
4908	      /* If that overflowed, the array is too big.
4909		 ??? While a size of INT_MAX+1 technically shouldn't cause
4910		 an overflow (because we subtract 1), the overflow is recorded
4911		 during the conversion to index_type, before the subtraction.
4912		 Handling this case seems like an unnecessary complication.  */
4913	      if (TREE_OVERFLOW (itype))
4914		{
4915		  error ("size of array `%s' is too large", name);
4916		  type = error_mark_node;
4917		  continue;
4918		}
4919
4920	      if (size_varies)
4921		itype = variable_size (itype);
4922	      itype = build_index_type (itype);
4923	    }
4924
4925#if 0 /* This had bad results for pointers to arrays, as in
4926	 union incomplete (*foo)[4];  */
4927	  /* Complain about arrays of incomplete types, except in typedefs.  */
4928
4929	  if (TYPE_SIZE (type) == 0
4930	      /* Avoid multiple warnings for nested array types.  */
4931	      && TREE_CODE (type) != ARRAY_TYPE
4932	      && !(specbits & (1 << (int) RID_TYPEDEF))
4933	      && !C_TYPE_BEING_DEFINED (type))
4934	    warning ("array type has incomplete element type");
4935#endif
4936
4937#if 0  /* We shouldn't have a function type here at all!
4938	  Functions aren't allowed as array elements.  */
4939	  if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
4940	      && (constp || volatilep))
4941	    pedwarn ("ANSI C forbids const or volatile function types");
4942#endif
4943
4944	  /* Build the array type itself, then merge any constancy or
4945	     volatility into the target type.  We must do it in this order
4946	     to ensure that the TYPE_MAIN_VARIANT field of the array type
4947	     is set correctly.  */
4948
4949	  type = build_array_type (type, itype);
4950	  if (type_quals)
4951	    type = c_build_qualified_type (type, type_quals);
4952
4953#if 0	/* don't clear these; leave them set so that the array type
4954	   or the variable is itself const or volatile.  */
4955	  type_quals = TYPE_UNQUALIFIED;
4956#endif
4957
4958	  if (size_varies)
4959	    C_TYPE_VARIABLE_SIZE (type) = 1;
4960	}
4961      else if (TREE_CODE (declarator) == CALL_EXPR)
4962	{
4963	  int extern_ref = (!(specbits & (1 << (int) RID_AUTO))
4964			    || current_binding_level == global_binding_level);
4965	  tree arg_types;
4966
4967	  /* Declaring a function type.
4968	     Make sure we have a valid type for the function to return.  */
4969	  if (type == error_mark_node)
4970	    continue;
4971
4972	  size_varies = 0;
4973
4974	  /* Warn about some types functions can't return.  */
4975
4976	  if (TREE_CODE (type) == FUNCTION_TYPE)
4977	    {
4978	      error ("`%s' declared as function returning a function", name);
4979	      type = integer_type_node;
4980	    }
4981	  if (TREE_CODE (type) == ARRAY_TYPE)
4982	    {
4983	      error ("`%s' declared as function returning an array", name);
4984	      type = integer_type_node;
4985	    }
4986
4987#ifndef TRADITIONAL_RETURN_FLOAT
4988	  /* Traditionally, declaring return type float means double.  */
4989
4990	  if (flag_traditional && TYPE_MAIN_VARIANT (type) == float_type_node)
4991	    type = double_type_node;
4992#endif /* TRADITIONAL_RETURN_FLOAT */
4993
4994	  /* If this is a block level extern, it must live past the end
4995	     of the function so that we can check it against other extern
4996	     declarations (IDENTIFIER_LIMBO_VALUE).  */
4997	  if (extern_ref && allocation_temporary_p ())
4998	    end_temporary_allocation ();
4999
5000	  /* Construct the function type and go to the next
5001	     inner layer of declarator.  */
5002
5003	  arg_types = grokparms (TREE_OPERAND (declarator, 1),
5004				 funcdef_flag
5005				 /* Say it's a definition
5006				    only for the CALL_EXPR
5007				    closest to the identifier.  */
5008				 && TREE_CODE (TREE_OPERAND (declarator, 0)) == IDENTIFIER_NODE);
5009#if 0 /* This seems to be false.  We turn off temporary allocation
5010	 above in this function if -traditional.
5011	 And this code caused inconsistent results with prototypes:
5012	 callers would ignore them, and pass arguments wrong.  */
5013
5014	  /* Omit the arg types if -traditional, since the arg types
5015	     and the list links might not be permanent.  */
5016	  type = build_function_type (type,
5017				      flag_traditional
5018				      ? NULL_TREE : arg_types);
5019#endif
5020	  /* Type qualifiers before the return type of the function
5021	     qualify the return type, not the function type.  */
5022	  if (type_quals)
5023	    type = c_build_qualified_type (type, type_quals);
5024	  type_quals = TYPE_UNQUALIFIED;
5025
5026	  type = build_function_type (type, arg_types);
5027	  declarator = TREE_OPERAND (declarator, 0);
5028
5029	  /* Set the TYPE_CONTEXTs for each tagged type which is local to
5030	     the formal parameter list of this FUNCTION_TYPE to point to
5031	     the FUNCTION_TYPE node itself.  */
5032
5033	  {
5034	    register tree link;
5035
5036	    for (link = last_function_parm_tags;
5037		 link;
5038		 link = TREE_CHAIN (link))
5039	      TYPE_CONTEXT (TREE_VALUE (link)) = type;
5040	  }
5041	}
5042      else if (TREE_CODE (declarator) == INDIRECT_REF)
5043	{
5044	  /* Merge any constancy or volatility into the target type
5045	     for the pointer.  */
5046
5047	  if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
5048	      && type_quals)
5049	    pedwarn ("ANSI C forbids qualified function types");
5050	  if (type_quals)
5051	    type = c_build_qualified_type (type, type_quals);
5052	  type_quals = TYPE_UNQUALIFIED;
5053	  size_varies = 0;
5054
5055	  type = build_pointer_type (type);
5056
5057	  /* Process a list of type modifier keywords
5058	     (such as const or volatile) that were given inside the `*'.  */
5059
5060	  if (TREE_TYPE (declarator))
5061	    {
5062	      register tree typemodlist;
5063	      int erred = 0;
5064
5065	      constp = 0;
5066	      volatilep = 0;
5067	      restrictp = 0;
5068	      for (typemodlist = TREE_TYPE (declarator); typemodlist;
5069		   typemodlist = TREE_CHAIN (typemodlist))
5070		{
5071		  tree qualifier = TREE_VALUE (typemodlist);
5072
5073		  if (qualifier == ridpointers[(int) RID_CONST])
5074		    constp++;
5075		  else if (qualifier == ridpointers[(int) RID_VOLATILE])
5076		    volatilep++;
5077		  else if (qualifier == ridpointers[(int) RID_RESTRICT])
5078		    restrictp++;
5079		  else if (!erred)
5080		    {
5081		      erred = 1;
5082		      error ("invalid type modifier within pointer declarator");
5083		    }
5084		}
5085	      if (constp > 1)
5086		pedwarn ("duplicate `const'");
5087	      if (volatilep > 1)
5088		pedwarn ("duplicate `volatile'");
5089	      if (restrictp > 1)
5090		pedwarn ("duplicate `restrict'");
5091
5092	      type_quals = ((constp ? TYPE_QUAL_CONST : 0)
5093			    | (restrictp ? TYPE_QUAL_RESTRICT : 0)
5094			    | (volatilep ? TYPE_QUAL_VOLATILE : 0));
5095	    }
5096
5097	  declarator = TREE_OPERAND (declarator, 0);
5098	}
5099      else
5100	abort ();
5101
5102    }
5103
5104  /* Now TYPE has the actual type.  */
5105
5106  /* Did array size calculations overflow?  */
5107
5108  if (TREE_CODE (type) == ARRAY_TYPE
5109      && TYPE_SIZE (type)
5110      && TREE_OVERFLOW (TYPE_SIZE (type)))
5111    error ("size of array `%s' is too large", name);
5112
5113  /* If this is declaring a typedef name, return a TYPE_DECL.  */
5114
5115  if (specbits & (1 << (int) RID_TYPEDEF))
5116    {
5117      tree decl;
5118      /* Note that the grammar rejects storage classes
5119	 in typenames, fields or parameters */
5120      if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
5121	  && type_quals)
5122	pedwarn ("ANSI C forbids qualified function types");
5123      if (type_quals)
5124	type = c_build_qualified_type (type, type_quals);
5125      decl = build_decl (TYPE_DECL, declarator, type);
5126      if ((specbits & (1 << (int) RID_SIGNED))
5127	  || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
5128	C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
5129      pop_obstacks ();
5130      return decl;
5131    }
5132
5133  /* Detect the case of an array type of unspecified size
5134     which came, as such, direct from a typedef name.
5135     We must copy the type, so that each identifier gets
5136     a distinct type, so that each identifier's size can be
5137     controlled separately by its own initializer.  */
5138
5139  if (type != 0 && typedef_type != 0
5140      && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (typedef_type)
5141      && TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type) == 0)
5142    {
5143      type = build_array_type (TREE_TYPE (type), 0);
5144      if (size_varies)
5145	C_TYPE_VARIABLE_SIZE (type) = 1;
5146    }
5147
5148  /* If this is a type name (such as, in a cast or sizeof),
5149     compute the type and return it now.  */
5150
5151  if (decl_context == TYPENAME)
5152    {
5153      /* Note that the grammar rejects storage classes
5154	 in typenames, fields or parameters */
5155      if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
5156	  && type_quals)
5157	pedwarn ("ANSI C forbids const or volatile function types");
5158      if (type_quals)
5159	type = c_build_qualified_type (type, type_quals);
5160      pop_obstacks ();
5161      return type;
5162    }
5163
5164  /* Aside from typedefs and type names (handle above),
5165     `void' at top level (not within pointer)
5166     is allowed only in public variables.
5167     We don't complain about parms either, but that is because
5168     a better error message can be made later.  */
5169
5170  if (TYPE_MAIN_VARIANT (type) == void_type_node && decl_context != PARM
5171      && ! ((decl_context != FIELD && TREE_CODE (type) != FUNCTION_TYPE)
5172	    && ((specbits & (1 << (int) RID_EXTERN))
5173		|| (current_binding_level == global_binding_level
5174		    && !(specbits
5175			 & ((1 << (int) RID_STATIC) | (1 << (int) RID_REGISTER)))))))
5176    {
5177      error ("variable or field `%s' declared void", name);
5178      type = integer_type_node;
5179    }
5180
5181  /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
5182     or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE.  */
5183
5184  {
5185    register tree decl;
5186
5187    if (decl_context == PARM)
5188      {
5189	tree type_as_written = type;
5190	tree main_type;
5191
5192	/* A parameter declared as an array of T is really a pointer to T.
5193	   One declared as a function is really a pointer to a function.  */
5194
5195	if (TREE_CODE (type) == ARRAY_TYPE)
5196	  {
5197	    /* Transfer const-ness of array into that of type pointed to.  */
5198	    type = TREE_TYPE (type);
5199	    if (type_quals)
5200	      type = c_build_qualified_type (type, type_quals);
5201	    type = build_pointer_type (type);
5202	    type_quals = TYPE_UNQUALIFIED;
5203	    size_varies = 0;
5204	  }
5205	else if (TREE_CODE (type) == FUNCTION_TYPE)
5206	  {
5207	    if (pedantic && type_quals)
5208	      pedwarn ("ANSI C forbids qualified function types");
5209	    if (type_quals)
5210	      type = c_build_qualified_type (type, type_quals);
5211	    type = build_pointer_type (type);
5212	    type_quals = TYPE_UNQUALIFIED;
5213	  }
5214
5215	decl = build_decl (PARM_DECL, declarator, type);
5216	if (size_varies)
5217	  C_DECL_VARIABLE_SIZE (decl) = 1;
5218
5219	/* Compute the type actually passed in the parmlist,
5220	   for the case where there is no prototype.
5221	   (For example, shorts and chars are passed as ints.)
5222	   When there is a prototype, this is overridden later.  */
5223
5224	DECL_ARG_TYPE (decl) = type;
5225	main_type = (type == error_mark_node
5226		     ? error_mark_node
5227		     : TYPE_MAIN_VARIANT (type));
5228	if (main_type == float_type_node)
5229	  DECL_ARG_TYPE (decl) = double_type_node;
5230	/* Don't use TYPE_PRECISION to decide whether to promote,
5231	   because we should convert short if it's the same size as int,
5232	   but we should not convert long if it's the same size as int.  */
5233	else if (TREE_CODE (main_type) != ERROR_MARK
5234		 && C_PROMOTING_INTEGER_TYPE_P (main_type))
5235	  {
5236	    if (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)
5237		&& TREE_UNSIGNED (type))
5238	      DECL_ARG_TYPE (decl) = unsigned_type_node;
5239	    else
5240	      DECL_ARG_TYPE (decl) = integer_type_node;
5241	  }
5242
5243	DECL_ARG_TYPE_AS_WRITTEN (decl) = type_as_written;
5244      }
5245    else if (decl_context == FIELD)
5246      {
5247	/* Structure field.  It may not be a function.  */
5248
5249	if (TREE_CODE (type) == FUNCTION_TYPE)
5250	  {
5251	    error ("field `%s' declared as a function", name);
5252	    type = build_pointer_type (type);
5253	  }
5254	else if (TREE_CODE (type) != ERROR_MARK && TYPE_SIZE (type) == 0)
5255	  {
5256	    error ("field `%s' has incomplete type", name);
5257	    type = error_mark_node;
5258	  }
5259	/* Move type qualifiers down to element of an array.  */
5260	if (TREE_CODE (type) == ARRAY_TYPE && type_quals)
5261	  {
5262	    type = build_array_type (c_build_qualified_type (TREE_TYPE (type),
5263							     type_quals),
5264				     TYPE_DOMAIN (type));
5265#if 0 /* Leave the field const or volatile as well.  */
5266	    type_quals = TYPE_UNQUALIFIED;
5267#endif
5268	  }
5269	decl = build_decl (FIELD_DECL, declarator, type);
5270	if (size_varies)
5271	  C_DECL_VARIABLE_SIZE (decl) = 1;
5272      }
5273    else if (TREE_CODE (type) == FUNCTION_TYPE)
5274      {
5275	/* Every function declaration is "external"
5276	   except for those which are inside a function body
5277	   in which `auto' is used.
5278	   That is a case not specified by ANSI C,
5279	   and we use it for forward declarations for nested functions.  */
5280	int extern_ref = (!(specbits & (1 << (int) RID_AUTO))
5281			  || current_binding_level == global_binding_level);
5282
5283	if (specbits & (1 << (int) RID_AUTO)
5284	    && (pedantic || current_binding_level == global_binding_level))
5285	  pedwarn ("invalid storage class for function `%s'", name);
5286	if (specbits & (1 << (int) RID_REGISTER))
5287	  error ("invalid storage class for function `%s'", name);
5288	/* Function declaration not at top level.
5289	   Storage classes other than `extern' are not allowed
5290	   and `extern' makes no difference.  */
5291	if (current_binding_level != global_binding_level
5292	    && (specbits & ((1 << (int) RID_STATIC) | (1 << (int) RID_INLINE)))
5293	    && pedantic)
5294	  pedwarn ("invalid storage class for function `%s'", name);
5295
5296	/* If this is a block level extern, it must live past the end
5297	   of the function so that we can check it against other
5298	   extern declarations (IDENTIFIER_LIMBO_VALUE).  */
5299	if (extern_ref && allocation_temporary_p ())
5300	  end_temporary_allocation ();
5301
5302	decl = build_decl (FUNCTION_DECL, declarator, type);
5303	decl = build_decl_attribute_variant (decl, decl_machine_attr);
5304
5305	if (pedantic && type_quals && ! DECL_IN_SYSTEM_HEADER (decl))
5306	  pedwarn ("ANSI C forbids qualified function types");
5307
5308	if (pedantic
5309	    && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl))) == void_type_node
5310	    && TYPE_QUALS (TREE_TYPE (TREE_TYPE (decl)))
5311	    && ! DECL_IN_SYSTEM_HEADER (decl))
5312	  pedwarn ("ANSI C forbids qualified void function return type");
5313
5314	/* GNU C interprets a `volatile void' return type to indicate
5315	   that the function does not return.  */
5316	if ((type_quals & TYPE_QUAL_VOLATILE)
5317	    && TREE_TYPE (TREE_TYPE (decl)) != void_type_node)
5318	  warning ("`noreturn' function returns non-void value");
5319
5320	if (extern_ref)
5321	  DECL_EXTERNAL (decl) = 1;
5322	/* Record absence of global scope for `static' or `auto'.  */
5323	TREE_PUBLIC (decl)
5324	  = !(specbits & ((1 << (int) RID_STATIC) | (1 << (int) RID_AUTO)));
5325
5326	/* Record presence of `inline', if it is reasonable.  */
5327	if (inlinep)
5328	  {
5329	    if (! strcmp (IDENTIFIER_POINTER (declarator), "main"))
5330	      warning ("cannot inline function `main'");
5331	    else
5332	      /* Assume that otherwise the function can be inlined.  */
5333	      DECL_INLINE (decl) = 1;
5334
5335	    if (specbits & (1 << (int) RID_EXTERN))
5336	      current_extern_inline = 1;
5337	  }
5338      }
5339    else
5340      {
5341	/* It's a variable.  */
5342	/* An uninitialized decl with `extern' is a reference.  */
5343	int extern_ref = !initialized && (specbits & (1 << (int) RID_EXTERN));
5344
5345	/* Move type qualifiers down to element of an array.  */
5346	if (TREE_CODE (type) == ARRAY_TYPE && type_quals)
5347	  {
5348	    type = build_array_type (c_build_qualified_type (TREE_TYPE (type),
5349							     type_quals),
5350				     TYPE_DOMAIN (type));
5351#if 0 /* Leave the variable const or volatile as well.  */
5352	    type_quals = TYPE_UNQUALIFIED;
5353#endif
5354	  }
5355
5356	/* If this is a block level extern, it must live past the end
5357	   of the function so that we can check it against other
5358	   extern declarations (IDENTIFIER_LIMBO_VALUE).  */
5359	if (extern_ref && allocation_temporary_p ())
5360	  end_temporary_allocation ();
5361
5362	decl = build_decl (VAR_DECL, declarator, type);
5363	if (size_varies)
5364	  C_DECL_VARIABLE_SIZE (decl) = 1;
5365
5366	if (inlinep)
5367	  pedwarn_with_decl (decl, "variable `%s' declared `inline'");
5368
5369	DECL_EXTERNAL (decl) = extern_ref;
5370	/* At top level, the presence of a `static' or `register' storage
5371	   class specifier, or the absence of all storage class specifiers
5372	   makes this declaration a definition (perhaps tentative).  Also,
5373	   the absence of both `static' and `register' makes it public.  */
5374	if (current_binding_level == global_binding_level)
5375	  {
5376	    TREE_PUBLIC (decl)
5377	      = !(specbits
5378		  & ((1 << (int) RID_STATIC) | (1 << (int) RID_REGISTER)));
5379	    TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
5380	  }
5381	/* Not at top level, only `static' makes a static definition.  */
5382	else
5383	  {
5384	    TREE_STATIC (decl) = (specbits & (1 << (int) RID_STATIC)) != 0;
5385	    TREE_PUBLIC (decl) = DECL_EXTERNAL (decl);
5386	  }
5387
5388	if (specbits & 1 << (int) RID_ITERATOR)
5389	  ITERATOR_P (decl) = 1;
5390      }
5391
5392    /* Record `register' declaration for warnings on &
5393       and in case doing stupid register allocation.  */
5394
5395    if (specbits & (1 << (int) RID_REGISTER))
5396      DECL_REGISTER (decl) = 1;
5397
5398    /* Record constancy and volatility.  */
5399    c_apply_type_quals_to_decl (type_quals, decl);
5400
5401    /* If a type has volatile components, it should be stored in memory.
5402       Otherwise, the fact that those components are volatile
5403       will be ignored, and would even crash the compiler.  */
5404    if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (decl)))
5405      mark_addressable (decl);
5406
5407    pop_obstacks ();
5408
5409    return decl;
5410  }
5411}
5412
5413/* Decode the parameter-list info for a function type or function definition.
5414   The argument is the value returned by `get_parm_info' (or made in parse.y
5415   if there is an identifier list instead of a parameter decl list).
5416   These two functions are separate because when a function returns
5417   or receives functions then each is called multiple times but the order
5418   of calls is different.  The last call to `grokparms' is always the one
5419   that contains the formal parameter names of a function definition.
5420
5421   Store in `last_function_parms' a chain of the decls of parms.
5422   Also store in `last_function_parm_tags' a chain of the struct, union,
5423   and enum tags declared among the parms.
5424
5425   Return a list of arg types to use in the FUNCTION_TYPE for this function.
5426
5427   FUNCDEF_FLAG is nonzero for a function definition, 0 for
5428   a mere declaration.  A nonempty identifier-list gets an error message
5429   when FUNCDEF_FLAG is zero.  */
5430
5431static tree
5432grokparms (parms_info, funcdef_flag)
5433     tree parms_info;
5434     int funcdef_flag;
5435{
5436  tree first_parm = TREE_CHAIN (parms_info);
5437
5438  last_function_parms = TREE_PURPOSE (parms_info);
5439  last_function_parm_tags = TREE_VALUE (parms_info);
5440
5441  if (warn_strict_prototypes && first_parm == 0 && !funcdef_flag
5442      && !in_system_header)
5443    warning ("function declaration isn't a prototype");
5444
5445  if (first_parm != 0
5446      && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE)
5447    {
5448      if (! funcdef_flag)
5449	pedwarn ("parameter names (without types) in function declaration");
5450
5451      last_function_parms = first_parm;
5452      return 0;
5453    }
5454  else
5455    {
5456      tree parm;
5457      tree typelt;
5458      /* We no longer test FUNCDEF_FLAG.
5459	 If the arg types are incomplete in a declaration,
5460	 they must include undefined tags.
5461	 These tags can never be defined in the scope of the declaration,
5462	 so the types can never be completed,
5463	 and no call can be compiled successfully.  */
5464#if 0
5465      /* In a fcn definition, arg types must be complete.  */
5466      if (funcdef_flag)
5467#endif
5468	for (parm = last_function_parms, typelt = first_parm;
5469	     parm;
5470	     parm = TREE_CHAIN (parm))
5471	  /* Skip over any enumeration constants declared here.  */
5472	  if (TREE_CODE (parm) == PARM_DECL)
5473	    {
5474	      /* Barf if the parameter itself has an incomplete type.  */
5475	      tree type = TREE_VALUE (typelt);
5476	      if (TYPE_SIZE (type) == 0)
5477		{
5478		  if (funcdef_flag && DECL_NAME (parm) != 0)
5479		    error ("parameter `%s' has incomplete type",
5480			   IDENTIFIER_POINTER (DECL_NAME (parm)));
5481		  else
5482		    warning ("parameter has incomplete type");
5483		  if (funcdef_flag)
5484		    {
5485		      TREE_VALUE (typelt) = error_mark_node;
5486		      TREE_TYPE (parm) = error_mark_node;
5487		    }
5488		}
5489#if 0  /* This has been replaced by parm_tags_warning
5490	  which uses a more accurate criterion for what to warn about.  */
5491	      else
5492		{
5493		  /* Now warn if is a pointer to an incomplete type.  */
5494		  while (TREE_CODE (type) == POINTER_TYPE
5495			 || TREE_CODE (type) == REFERENCE_TYPE)
5496		    type = TREE_TYPE (type);
5497		  type = TYPE_MAIN_VARIANT (type);
5498		  if (TYPE_SIZE (type) == 0)
5499		    {
5500		      if (DECL_NAME (parm) != 0)
5501			warning ("parameter `%s' points to incomplete type",
5502				 IDENTIFIER_POINTER (DECL_NAME (parm)));
5503		      else
5504			warning ("parameter points to incomplete type");
5505		    }
5506		}
5507#endif
5508	      typelt = TREE_CHAIN (typelt);
5509	    }
5510
5511      /* Allocate the list of types the way we allocate a type.  */
5512      if (first_parm && ! TREE_PERMANENT (first_parm))
5513	{
5514	  /* Construct a copy of the list of types
5515	     on the saveable obstack.  */
5516	  tree result = NULL;
5517	  for (typelt = first_parm; typelt; typelt = TREE_CHAIN (typelt))
5518	    result = saveable_tree_cons (NULL_TREE, TREE_VALUE (typelt),
5519					 result);
5520	  return nreverse (result);
5521	}
5522      else
5523	/* The list we have is permanent already.  */
5524	return first_parm;
5525    }
5526}
5527
5528
5529/* Return a tree_list node with info on a parameter list just parsed.
5530   The TREE_PURPOSE is a chain of decls of those parms.
5531   The TREE_VALUE is a list of structure, union and enum tags defined.
5532   The TREE_CHAIN is a list of argument types to go in the FUNCTION_TYPE.
5533   This tree_list node is later fed to `grokparms'.
5534
5535   VOID_AT_END nonzero means append `void' to the end of the type-list.
5536   Zero means the parmlist ended with an ellipsis so don't append `void'.  */
5537
5538tree
5539get_parm_info (void_at_end)
5540     int void_at_end;
5541{
5542  register tree decl, t;
5543  register tree types = 0;
5544  int erred = 0;
5545  tree tags = gettags ();
5546  tree parms = getdecls ();
5547  tree new_parms = 0;
5548  tree order = current_binding_level->parm_order;
5549
5550  /* Just `void' (and no ellipsis) is special.  There are really no parms.  */
5551  if (void_at_end && parms != 0
5552      && TREE_CHAIN (parms) == 0
5553      && TYPE_MAIN_VARIANT (TREE_TYPE (parms)) == void_type_node
5554      && DECL_NAME (parms) == 0)
5555    {
5556      parms = NULL_TREE;
5557      storedecls (NULL_TREE);
5558      return saveable_tree_cons (NULL_TREE, NULL_TREE,
5559				 saveable_tree_cons (NULL_TREE, void_type_node, NULL_TREE));
5560    }
5561
5562  /* Extract enumerator values and other non-parms declared with the parms.
5563     Likewise any forward parm decls that didn't have real parm decls.  */
5564  for (decl = parms; decl; )
5565    {
5566      tree next = TREE_CHAIN (decl);
5567
5568      if (TREE_CODE (decl) != PARM_DECL)
5569	{
5570	  TREE_CHAIN (decl) = new_parms;
5571	  new_parms = decl;
5572	}
5573      else if (TREE_ASM_WRITTEN (decl))
5574	{
5575	  error_with_decl (decl, "parameter `%s' has just a forward declaration");
5576	  TREE_CHAIN (decl) = new_parms;
5577	  new_parms = decl;
5578	}
5579      decl = next;
5580    }
5581
5582  /* Put the parm decls back in the order they were in in the parm list.  */
5583  for (t = order; t; t = TREE_CHAIN (t))
5584    {
5585      if (TREE_CHAIN (t))
5586	TREE_CHAIN (TREE_VALUE (t)) = TREE_VALUE (TREE_CHAIN (t));
5587      else
5588	TREE_CHAIN (TREE_VALUE (t)) = 0;
5589    }
5590
5591  new_parms = chainon (order ? nreverse (TREE_VALUE (order)) : 0,
5592		       new_parms);
5593
5594  /* Store the parmlist in the binding level since the old one
5595     is no longer a valid list.  (We have changed the chain pointers.)  */
5596  storedecls (new_parms);
5597
5598  for (decl = new_parms; decl; decl = TREE_CHAIN (decl))
5599    /* There may also be declarations for enumerators if an enumeration
5600       type is declared among the parms.  Ignore them here.  */
5601    if (TREE_CODE (decl) == PARM_DECL)
5602      {
5603	/* Since there is a prototype,
5604	   args are passed in their declared types.  */
5605	tree type = TREE_TYPE (decl);
5606	DECL_ARG_TYPE (decl) = type;
5607#ifdef PROMOTE_PROTOTYPES
5608	if ((TREE_CODE (type) == INTEGER_TYPE
5609	     || TREE_CODE (type) == ENUMERAL_TYPE)
5610	    && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
5611	  DECL_ARG_TYPE (decl) = integer_type_node;
5612#endif
5613
5614	types = saveable_tree_cons (NULL_TREE, TREE_TYPE (decl), types);
5615	if (TYPE_MAIN_VARIANT (TREE_VALUE (types)) == void_type_node && ! erred
5616	    && DECL_NAME (decl) == 0)
5617	  {
5618	    error ("`void' in parameter list must be the entire list");
5619	    erred = 1;
5620	  }
5621      }
5622
5623  if (void_at_end)
5624    return saveable_tree_cons (new_parms, tags,
5625			       nreverse (saveable_tree_cons (NULL_TREE, void_type_node, types)));
5626
5627  return saveable_tree_cons (new_parms, tags, nreverse (types));
5628}
5629
5630/* At end of parameter list, warn about any struct, union or enum tags
5631   defined within.  Do so because these types cannot ever become complete.  */
5632
5633void
5634parmlist_tags_warning ()
5635{
5636  tree elt;
5637  static int already;
5638
5639  for (elt = current_binding_level->tags; elt; elt = TREE_CHAIN (elt))
5640    {
5641      enum tree_code code = TREE_CODE (TREE_VALUE (elt));
5642      /* An anonymous union parm type is meaningful as a GNU extension.
5643	 So don't warn for that.  */
5644      if (code == UNION_TYPE && TREE_PURPOSE (elt) == 0 && !pedantic)
5645	continue;
5646      if (TREE_PURPOSE (elt) != 0)
5647	warning ("`%s %s' declared inside parameter list",
5648		 (code == RECORD_TYPE ? "struct"
5649		  : code == UNION_TYPE ? "union"
5650		  : "enum"),
5651		 IDENTIFIER_POINTER (TREE_PURPOSE (elt)));
5652      else
5653	warning ("anonymous %s declared inside parameter list",
5654		 (code == RECORD_TYPE ? "struct"
5655		  : code == UNION_TYPE ? "union"
5656		  : "enum"));
5657
5658      if (! already)
5659	{
5660	  warning ("its scope is only this definition or declaration, which is probably not what you want.");
5661	  already = 1;
5662	}
5663    }
5664}
5665
5666/* Get the struct, enum or union (CODE says which) with tag NAME.
5667   Define the tag as a forward-reference if it is not defined.  */
5668
5669tree
5670xref_tag (code, name)
5671     enum tree_code code;
5672     tree name;
5673{
5674  int temporary = allocation_temporary_p ();
5675
5676  /* If a cross reference is requested, look up the type
5677     already defined for this tag and return it.  */
5678
5679  register tree ref = lookup_tag (code, name, current_binding_level, 0);
5680  /* Even if this is the wrong type of tag, return what we found.
5681     There will be an error message anyway, from pending_xref_error.
5682     If we create an empty xref just for an invalid use of the type,
5683     the main result is to create lots of superfluous error messages.  */
5684  if (ref)
5685    return ref;
5686
5687  push_obstacks_nochange ();
5688
5689  if (current_binding_level == global_binding_level && temporary)
5690    end_temporary_allocation ();
5691
5692  /* If no such tag is yet defined, create a forward-reference node
5693     and record it as the "definition".
5694     When a real declaration of this type is found,
5695     the forward-reference will be altered into a real type.  */
5696
5697  ref = make_node (code);
5698  if (code == ENUMERAL_TYPE)
5699    {
5700      /* (In ANSI, Enums can be referred to only if already defined.)  */
5701      if (pedantic)
5702	pedwarn ("ANSI C forbids forward references to `enum' types");
5703      /* Give the type a default layout like unsigned int
5704	 to avoid crashing if it does not get defined.  */
5705      TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node);
5706      TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node);
5707      TREE_UNSIGNED (ref) = 1;
5708      TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
5709      TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
5710      TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
5711    }
5712
5713  pushtag (name, ref);
5714
5715  pop_obstacks ();
5716
5717  return ref;
5718}
5719
5720/* Make sure that the tag NAME is defined *in the current binding level*
5721   at least as a forward reference.
5722   CODE says which kind of tag NAME ought to be.
5723
5724   We also do a push_obstacks_nochange
5725   whose matching pop is in finish_struct.  */
5726
5727tree
5728start_struct (code, name)
5729     enum tree_code code;
5730     tree name;
5731{
5732  /* If there is already a tag defined at this binding level
5733     (as a forward reference), just return it.  */
5734
5735  register tree ref = 0;
5736
5737  push_obstacks_nochange ();
5738  if (current_binding_level == global_binding_level)
5739    end_temporary_allocation ();
5740
5741  if (name != 0)
5742    ref = lookup_tag (code, name, current_binding_level, 1);
5743  if (ref && TREE_CODE (ref) == code)
5744    {
5745      C_TYPE_BEING_DEFINED (ref) = 1;
5746      TYPE_PACKED (ref) = flag_pack_struct;
5747      if (TYPE_FIELDS (ref))
5748	error ((code == UNION_TYPE ? "redefinition of `union %s'"
5749		: "redefinition of `struct %s'"),
5750	       IDENTIFIER_POINTER (name));
5751
5752      return ref;
5753    }
5754
5755  /* Otherwise create a forward-reference just so the tag is in scope.  */
5756
5757  ref = make_node (code);
5758  pushtag (name, ref);
5759  C_TYPE_BEING_DEFINED (ref) = 1;
5760  TYPE_PACKED (ref) = flag_pack_struct;
5761  return ref;
5762}
5763
5764/* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
5765   of a structure component, returning a FIELD_DECL node.
5766   WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node.
5767
5768   This is done during the parsing of the struct declaration.
5769   The FIELD_DECL nodes are chained together and the lot of them
5770   are ultimately passed to `build_struct' to make the RECORD_TYPE node.  */
5771
5772tree
5773grokfield (filename, line, declarator, declspecs, width)
5774     const char *filename ATTRIBUTE_UNUSED;
5775     int line ATTRIBUTE_UNUSED;
5776     tree declarator, declspecs, width;
5777{
5778  tree value;
5779
5780  /* The corresponding pop_obstacks is in finish_decl.  */
5781  push_obstacks_nochange ();
5782
5783  value = grokdeclarator (declarator, declspecs, width ? BITFIELD : FIELD, 0);
5784
5785  finish_decl (value, NULL_TREE, NULL_TREE);
5786  DECL_INITIAL (value) = width;
5787
5788  maybe_objc_check_decl (value);
5789  return value;
5790}
5791
5792/* Function to help qsort sort FIELD_DECLs by name order.  */
5793
5794static int
5795field_decl_cmp (xp, yp)
5796     const GENERIC_PTR xp;
5797     const GENERIC_PTR yp;
5798{
5799  tree *x = (tree *)xp, *y = (tree *)yp;
5800
5801  if (DECL_NAME (*x) == DECL_NAME (*y))
5802    return 0;
5803  if (DECL_NAME (*x) == NULL)
5804    return -1;
5805  if (DECL_NAME (*y) == NULL)
5806    return 1;
5807  if (DECL_NAME (*x) < DECL_NAME (*y))
5808    return -1;
5809  return 1;
5810}
5811
5812/* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T.
5813   FIELDLIST is a chain of FIELD_DECL nodes for the fields.
5814   ATTRIBUTES are attributes to be applied to the structure.
5815
5816   We also do a pop_obstacks to match the push in start_struct.  */
5817
5818tree
5819finish_struct (t, fieldlist, attributes)
5820     tree t;
5821     tree fieldlist;
5822     tree attributes;
5823{
5824  register tree x;
5825  int old_momentary;
5826  int toplevel = global_binding_level == current_binding_level;
5827
5828  /* If this type was previously laid out as a forward reference,
5829     make sure we lay it out again.  */
5830
5831  TYPE_SIZE (t) = 0;
5832
5833  decl_attributes (t, attributes, NULL_TREE);
5834
5835  /* Nameless union parm types are useful as GCC extension.  */
5836  if (! (TREE_CODE (t) == UNION_TYPE && TYPE_NAME (t) == 0) && !pedantic)
5837    /* Otherwise, warn about any struct or union def. in parmlist.  */
5838    if (in_parm_level_p ())
5839      {
5840	if (pedantic)
5841	  pedwarn ((TREE_CODE (t) == UNION_TYPE ? "union defined inside parms"
5842		    : "structure defined inside parms"));
5843	else if (! flag_traditional)
5844	  warning ((TREE_CODE (t) == UNION_TYPE ? "union defined inside parms"
5845		    : "structure defined inside parms"));
5846      }
5847
5848  old_momentary = suspend_momentary ();
5849
5850  if (pedantic)
5851    {
5852      for (x = fieldlist; x; x = TREE_CHAIN (x))
5853	if (DECL_NAME (x) != 0)
5854	  break;
5855
5856      if (x == 0)
5857	pedwarn ((fieldlist
5858		  ? "%s has no named members"
5859		  : "%s has no members"),
5860		 TREE_CODE (t) == UNION_TYPE ? "union" : "struct");
5861    }
5862
5863  /* Install struct as DECL_CONTEXT of each field decl.
5864     Also process specified field sizes.
5865     Set DECL_FIELD_SIZE to the specified size, or 0 if none specified.
5866     The specified size is found in the DECL_INITIAL.
5867     Store 0 there, except for ": 0" fields (so we can find them
5868     and delete them, below).  */
5869
5870  for (x = fieldlist; x; x = TREE_CHAIN (x))
5871    {
5872      DECL_CONTEXT (x) = t;
5873      DECL_PACKED (x) |= TYPE_PACKED (t);
5874      DECL_FIELD_SIZE (x) = 0;
5875
5876      /* If any field is const, the structure type is pseudo-const.  */
5877      if (TREE_READONLY (x))
5878	C_TYPE_FIELDS_READONLY (t) = 1;
5879      else
5880	{
5881	  /* A field that is pseudo-const makes the structure likewise.  */
5882	  tree t1 = TREE_TYPE (x);
5883	  while (TREE_CODE (t1) == ARRAY_TYPE)
5884	    t1 = TREE_TYPE (t1);
5885	  if ((TREE_CODE (t1) == RECORD_TYPE || TREE_CODE (t1) == UNION_TYPE)
5886	      && C_TYPE_FIELDS_READONLY (t1))
5887	    C_TYPE_FIELDS_READONLY (t) = 1;
5888	}
5889
5890      /* Any field that is volatile means variables of this type must be
5891	 treated in some ways as volatile.  */
5892      if (TREE_THIS_VOLATILE (x))
5893	C_TYPE_FIELDS_VOLATILE (t) = 1;
5894
5895      /* Any field of nominal variable size implies structure is too.  */
5896      if (C_DECL_VARIABLE_SIZE (x))
5897	C_TYPE_VARIABLE_SIZE (t) = 1;
5898
5899      /* Detect invalid nested redefinition.  */
5900      if (TREE_TYPE (x) == t)
5901	error ("nested redefinition of `%s'",
5902	       IDENTIFIER_POINTER (TYPE_NAME (t)));
5903
5904      /* Detect invalid bit-field size.  */
5905      if (DECL_INITIAL (x))
5906	STRIP_NOPS (DECL_INITIAL (x));
5907      if (DECL_INITIAL (x))
5908	{
5909	  if (TREE_CODE (DECL_INITIAL (x)) == INTEGER_CST)
5910	    constant_expression_warning (DECL_INITIAL (x));
5911	  else
5912	    {
5913	      error_with_decl (x, "bit-field `%s' width not an integer constant");
5914	      DECL_INITIAL (x) = NULL;
5915	    }
5916	}
5917
5918      /* Detect invalid bit-field type.  */
5919      if (DECL_INITIAL (x)
5920	  && TREE_CODE (TREE_TYPE (x)) != INTEGER_TYPE
5921	  && TREE_CODE (TREE_TYPE (x)) != ENUMERAL_TYPE)
5922	{
5923	  error_with_decl (x, "bit-field `%s' has invalid type");
5924	  DECL_INITIAL (x) = NULL;
5925	}
5926      if (DECL_INITIAL (x) && pedantic
5927	  && TYPE_MAIN_VARIANT (TREE_TYPE (x)) != integer_type_node
5928	  && TYPE_MAIN_VARIANT (TREE_TYPE (x)) != unsigned_type_node
5929	  /* Accept an enum that's equivalent to int or unsigned int.  */
5930	  && !(TREE_CODE (TREE_TYPE (x)) == ENUMERAL_TYPE
5931	       && (TYPE_PRECISION (TREE_TYPE (x))
5932		   == TYPE_PRECISION (integer_type_node))))
5933	pedwarn_with_decl (x, "bit-field `%s' type invalid in ANSI C");
5934
5935      /* Detect and ignore out of range field width.  */
5936      if (DECL_INITIAL (x))
5937	{
5938	  unsigned HOST_WIDE_INT width = TREE_INT_CST_LOW (DECL_INITIAL (x));
5939
5940	  if (tree_int_cst_sgn (DECL_INITIAL (x)) < 0)
5941	    {
5942	      DECL_INITIAL (x) = NULL;
5943	      error_with_decl (x, "negative width in bit-field `%s'");
5944	    }
5945	  else if (TREE_INT_CST_HIGH (DECL_INITIAL (x)) != 0
5946		   || width > TYPE_PRECISION (TREE_TYPE (x)))
5947	    {
5948	      DECL_INITIAL (x) = NULL;
5949	      pedwarn_with_decl (x, "width of `%s' exceeds its type");
5950	    }
5951	  else if (width == 0 && DECL_NAME (x) != 0)
5952	    {
5953	      error_with_decl (x, "zero width for bit-field `%s'");
5954	      DECL_INITIAL (x) = NULL;
5955	    }
5956	}
5957
5958      /* Process valid field width.  */
5959      if (DECL_INITIAL (x))
5960	{
5961	  register int width = TREE_INT_CST_LOW (DECL_INITIAL (x));
5962
5963	  if (TREE_CODE (TREE_TYPE (x)) == ENUMERAL_TYPE
5964	      && (width < min_precision (TYPE_MIN_VALUE (TREE_TYPE (x)),
5965					 TREE_UNSIGNED (TREE_TYPE (x)))
5966		  || width < min_precision (TYPE_MAX_VALUE (TREE_TYPE (x)),
5967					    TREE_UNSIGNED (TREE_TYPE (x)))))
5968	    warning_with_decl (x, "`%s' is narrower than values of its type");
5969
5970	  DECL_FIELD_SIZE (x) = width;
5971	  DECL_BIT_FIELD (x) = DECL_C_BIT_FIELD (x) = 1;
5972	  DECL_INITIAL (x) = NULL;
5973
5974	  if (width == 0)
5975	    {
5976	      /* field size 0 => force desired amount of alignment.  */
5977#ifdef EMPTY_FIELD_BOUNDARY
5978	      DECL_ALIGN (x) = MAX (DECL_ALIGN (x), EMPTY_FIELD_BOUNDARY);
5979#endif
5980#ifdef PCC_BITFIELD_TYPE_MATTERS
5981	      if (PCC_BITFIELD_TYPE_MATTERS)
5982		DECL_ALIGN (x) = MAX (DECL_ALIGN (x),
5983				      TYPE_ALIGN (TREE_TYPE (x)));
5984#endif
5985	    }
5986	}
5987      else if (TREE_TYPE (x) != error_mark_node)
5988	{
5989	  unsigned int min_align = (DECL_PACKED (x) ? BITS_PER_UNIT
5990			   : TYPE_ALIGN (TREE_TYPE (x)));
5991	  /* Non-bit-fields are aligned for their type, except packed
5992	     fields which require only BITS_PER_UNIT alignment.  */
5993	  DECL_ALIGN (x) = MAX (DECL_ALIGN (x), min_align);
5994	}
5995    }
5996
5997  /* Now DECL_INITIAL is null on all members.  */
5998
5999  /* Delete all duplicate fields from the fieldlist */
6000  for (x = fieldlist; x && TREE_CHAIN (x);)
6001    /* Anonymous fields aren't duplicates.  */
6002    if (DECL_NAME (TREE_CHAIN (x)) == 0)
6003      x = TREE_CHAIN (x);
6004    else
6005      {
6006	register tree y = fieldlist;
6007
6008	while (1)
6009	  {
6010	    if (DECL_NAME (y) == DECL_NAME (TREE_CHAIN (x)))
6011	      break;
6012	    if (y == x)
6013	      break;
6014	    y = TREE_CHAIN (y);
6015	  }
6016	if (DECL_NAME (y) == DECL_NAME (TREE_CHAIN (x)))
6017	  {
6018	    error_with_decl (TREE_CHAIN (x), "duplicate member `%s'");
6019	    TREE_CHAIN (x) = TREE_CHAIN (TREE_CHAIN (x));
6020	  }
6021	else x = TREE_CHAIN (x);
6022      }
6023
6024  /* Now we have the nearly final fieldlist.  Record it,
6025     then lay out the structure or union (including the fields).  */
6026
6027  TYPE_FIELDS (t) = fieldlist;
6028
6029  layout_type (t);
6030
6031  /* Delete all zero-width bit-fields from the front of the fieldlist */
6032  while (fieldlist
6033	 && DECL_INITIAL (fieldlist))
6034    fieldlist = TREE_CHAIN (fieldlist);
6035  /* Delete all such members from the rest of the fieldlist */
6036  for (x = fieldlist; x;)
6037    {
6038      if (TREE_CHAIN (x) && DECL_INITIAL (TREE_CHAIN (x)))
6039	TREE_CHAIN (x) = TREE_CHAIN (TREE_CHAIN (x));
6040      else x = TREE_CHAIN (x);
6041    }
6042
6043  /*  Now we have the truly final field list.
6044      Store it in this type and in the variants.  */
6045
6046  TYPE_FIELDS (t) = fieldlist;
6047
6048  /* If there are lots of fields, sort so we can look through them fast.
6049     We arbitrarily consider 16 or more elts to be "a lot".  */
6050  {
6051    int len = 0;
6052
6053    for (x = fieldlist; x; x = TREE_CHAIN (x))
6054      {
6055	if (len > 15)
6056	  break;
6057	len += 1;
6058      }
6059    if (len > 15)
6060      {
6061	tree *field_array;
6062	char *space;
6063
6064	len += list_length (x);
6065	/* Use the same allocation policy here that make_node uses, to
6066	   ensure that this lives as long as the rest of the struct decl.
6067	   All decls in an inline function need to be saved.  */
6068	if (allocation_temporary_p ())
6069	  space = savealloc (sizeof (struct lang_type) + len * sizeof (tree));
6070	else
6071	  space = oballoc (sizeof (struct lang_type) + len * sizeof (tree));
6072
6073	TYPE_LANG_SPECIFIC (t) = (struct lang_type *) space;
6074	TYPE_LANG_SPECIFIC (t)->len = len;
6075
6076	field_array = &TYPE_LANG_SPECIFIC (t)->elts[0];
6077	len = 0;
6078	for (x = fieldlist; x; x = TREE_CHAIN (x))
6079	  field_array[len++] = x;
6080
6081	qsort (field_array, len, sizeof (tree), field_decl_cmp);
6082      }
6083  }
6084
6085  for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x))
6086    {
6087      TYPE_FIELDS (x) = TYPE_FIELDS (t);
6088      TYPE_LANG_SPECIFIC (x) = TYPE_LANG_SPECIFIC (t);
6089      TYPE_ALIGN (x) = TYPE_ALIGN (t);
6090    }
6091
6092  /* If this was supposed to be a transparent union, but we can't
6093     make it one, warn and turn off the flag.  */
6094  if (TREE_CODE (t) == UNION_TYPE
6095      && TYPE_TRANSPARENT_UNION (t)
6096      && TYPE_MODE (t) != DECL_MODE (TYPE_FIELDS (t)))
6097    {
6098      TYPE_TRANSPARENT_UNION (t) = 0;
6099      warning ("union cannot be made transparent");
6100    }
6101
6102  /* If this structure or union completes the type of any previous
6103     variable declaration, lay it out and output its rtl.  */
6104
6105  if (current_binding_level->n_incomplete != 0)
6106    {
6107      tree decl;
6108      for (decl = current_binding_level->names; decl; decl = TREE_CHAIN (decl))
6109	{
6110	  if (TREE_TYPE (decl) == t
6111	      && TREE_CODE (decl) != TYPE_DECL)
6112	    {
6113	      layout_decl (decl, 0);
6114	      /* This is a no-op in c-lang.c or something real in objc-actions.c.  */
6115	      maybe_objc_check_decl (decl);
6116	      rest_of_decl_compilation (decl, NULL_PTR, toplevel, 0);
6117	      if (! toplevel)
6118		expand_decl (decl);
6119	      --current_binding_level->n_incomplete;
6120	    }
6121	  else if (TYPE_SIZE (TREE_TYPE (decl)) == 0
6122		   && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
6123	    {
6124	      tree element = TREE_TYPE (decl);
6125	      while (TREE_CODE (element) == ARRAY_TYPE)
6126		element = TREE_TYPE (element);
6127	      if (element == t)
6128		layout_array_type (TREE_TYPE (decl));
6129	    }
6130	}
6131    }
6132
6133  resume_momentary (old_momentary);
6134
6135  /* Finish debugging output for this type.  */
6136  rest_of_type_compilation (t, toplevel);
6137
6138  /* The matching push is in start_struct.  */
6139  pop_obstacks ();
6140
6141  return t;
6142}
6143
6144/* Lay out the type T, and its element type, and so on.  */
6145
6146static void
6147layout_array_type (t)
6148     tree t;
6149{
6150  if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
6151    layout_array_type (TREE_TYPE (t));
6152  layout_type (t);
6153}
6154
6155/* Begin compiling the definition of an enumeration type.
6156   NAME is its name (or null if anonymous).
6157   Returns the type object, as yet incomplete.
6158   Also records info about it so that build_enumerator
6159   may be used to declare the individual values as they are read.  */
6160
6161tree
6162start_enum (name)
6163     tree name;
6164{
6165  register tree enumtype = 0;
6166
6167  /* If this is the real definition for a previous forward reference,
6168     fill in the contents in the same object that used to be the
6169     forward reference.  */
6170
6171  if (name != 0)
6172    enumtype = lookup_tag (ENUMERAL_TYPE, name, current_binding_level, 1);
6173
6174  /* The corresponding pop_obstacks is in finish_enum.  */
6175  push_obstacks_nochange ();
6176  /* If these symbols and types are global, make them permanent.  */
6177  if (current_binding_level == global_binding_level)
6178    end_temporary_allocation ();
6179
6180  if (enumtype == 0 || TREE_CODE (enumtype) != ENUMERAL_TYPE)
6181    {
6182      enumtype = make_node (ENUMERAL_TYPE);
6183      pushtag (name, enumtype);
6184    }
6185
6186  C_TYPE_BEING_DEFINED (enumtype) = 1;
6187
6188  if (TYPE_VALUES (enumtype) != 0)
6189    {
6190      /* This enum is a named one that has been declared already.  */
6191      error ("redeclaration of `enum %s'", IDENTIFIER_POINTER (name));
6192
6193      /* Completely replace its old definition.
6194	 The old enumerators remain defined, however.  */
6195      TYPE_VALUES (enumtype) = 0;
6196    }
6197
6198  enum_next_value = integer_zero_node;
6199  enum_overflow = 0;
6200
6201  if (flag_short_enums)
6202    TYPE_PACKED (enumtype) = 1;
6203
6204  return enumtype;
6205}
6206
6207/* After processing and defining all the values of an enumeration type,
6208   install their decls in the enumeration type and finish it off.
6209   ENUMTYPE is the type object, VALUES a list of decl-value pairs,
6210   and ATTRIBUTES are the specified attributes.
6211   Returns ENUMTYPE.  */
6212
6213tree
6214finish_enum (enumtype, values, attributes)
6215     tree enumtype;
6216     tree values;
6217     tree attributes;
6218{
6219  register tree pair, tem;
6220  tree minnode = 0, maxnode = 0;
6221  int lowprec, highprec, precision;
6222  int toplevel = global_binding_level == current_binding_level;
6223
6224  if (in_parm_level_p ())
6225    warning ("enum defined inside parms");
6226
6227  decl_attributes (enumtype, attributes, NULL_TREE);
6228
6229  /* Calculate the maximum value of any enumerator in this type.  */
6230
6231  if (values == error_mark_node)
6232    minnode = maxnode = integer_zero_node;
6233  else
6234    for (pair = values; pair; pair = TREE_CHAIN (pair))
6235      {
6236	tree value = TREE_VALUE (pair);
6237	if (pair == values)
6238	  minnode = maxnode = TREE_VALUE (pair);
6239	else
6240	  {
6241	    if (tree_int_cst_lt (maxnode, value))
6242	      maxnode = value;
6243	    if (tree_int_cst_lt (value, minnode))
6244	      minnode = value;
6245	  }
6246      }
6247
6248  TYPE_MIN_VALUE (enumtype) = minnode;
6249  TYPE_MAX_VALUE (enumtype) = maxnode;
6250
6251  /* An enum can have some negative values; then it is signed.  */
6252  TREE_UNSIGNED (enumtype) = tree_int_cst_sgn (minnode) >= 0;
6253
6254  /* Determine the precision this type needs.  */
6255
6256  lowprec = min_precision (minnode, TREE_UNSIGNED (enumtype));
6257  highprec = min_precision (maxnode, TREE_UNSIGNED (enumtype));
6258  precision = MAX (lowprec, highprec);
6259
6260  if (TYPE_PACKED (enumtype) || precision > TYPE_PRECISION (integer_type_node))
6261    {
6262      tree narrowest = type_for_size (precision, 1);
6263      if (narrowest == 0)
6264	{
6265	  warning ("enumeration values exceed range of largest integer");
6266	  narrowest = long_long_integer_type_node;
6267	}
6268
6269      TYPE_PRECISION (enumtype) = TYPE_PRECISION (narrowest);
6270    }
6271  else
6272    TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node);
6273
6274  TYPE_SIZE (enumtype) = 0;
6275  layout_type (enumtype);
6276
6277  if (values != error_mark_node)
6278    {
6279      /* Change the type of the enumerators to be the enum type.
6280	 Formerly this was done only for enums that fit in an int,
6281	 but the comment said it was done only for enums wider than int.
6282	 It seems necessary to do this for wide enums,
6283	 and best not to change what's done for ordinary narrower ones.  */
6284      for (pair = values; pair; pair = TREE_CHAIN (pair))
6285	{
6286	  TREE_TYPE (TREE_PURPOSE (pair)) = enumtype;
6287	  DECL_SIZE (TREE_PURPOSE (pair)) = TYPE_SIZE (enumtype);
6288	  if (TREE_CODE (TREE_PURPOSE (pair)) != FUNCTION_DECL)
6289	    DECL_ALIGN (TREE_PURPOSE (pair)) = TYPE_ALIGN (enumtype);
6290	}
6291
6292      /* Replace the decl nodes in VALUES with their names.  */
6293      for (pair = values; pair; pair = TREE_CHAIN (pair))
6294	TREE_PURPOSE (pair) = DECL_NAME (TREE_PURPOSE (pair));
6295
6296      TYPE_VALUES (enumtype) = values;
6297    }
6298
6299  /* Fix up all variant types of this enum type.  */
6300  for (tem = TYPE_MAIN_VARIANT (enumtype); tem; tem = TYPE_NEXT_VARIANT (tem))
6301    {
6302      TYPE_VALUES (tem) = TYPE_VALUES (enumtype);
6303      TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype);
6304      TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype);
6305      TYPE_SIZE (tem) = TYPE_SIZE (enumtype);
6306      TYPE_SIZE_UNIT (tem) = TYPE_SIZE_UNIT (enumtype);
6307      TYPE_MODE (tem) = TYPE_MODE (enumtype);
6308      TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype);
6309      TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype);
6310      TREE_UNSIGNED (tem) = TREE_UNSIGNED (enumtype);
6311    }
6312
6313  /* Finish debugging output for this type.  */
6314  rest_of_type_compilation (enumtype, toplevel);
6315
6316  /* This matches a push in start_enum.  */
6317  pop_obstacks ();
6318
6319  return enumtype;
6320}
6321
6322/* Build and install a CONST_DECL for one value of the
6323   current enumeration type (one that was begun with start_enum).
6324   Return a tree-list containing the CONST_DECL and its value.
6325   Assignment of sequential values by default is handled here.  */
6326
6327tree
6328build_enumerator (name, value)
6329     tree name, value;
6330{
6331  register tree decl, type;
6332
6333  /* Validate and default VALUE.  */
6334
6335  /* Remove no-op casts from the value.  */
6336  if (value)
6337    STRIP_TYPE_NOPS (value);
6338
6339  if (value != 0)
6340    {
6341      if (TREE_CODE (value) == INTEGER_CST)
6342	{
6343	  value = default_conversion (value);
6344	  constant_expression_warning (value);
6345	}
6346      else
6347	{
6348	  error ("enumerator value for `%s' not integer constant",
6349		 IDENTIFIER_POINTER (name));
6350	  value = 0;
6351	}
6352    }
6353
6354  /* Default based on previous value.  */
6355  /* It should no longer be possible to have NON_LVALUE_EXPR
6356     in the default.  */
6357  if (value == 0)
6358    {
6359      value = enum_next_value;
6360      if (enum_overflow)
6361	error ("overflow in enumeration values");
6362    }
6363
6364  if (pedantic && ! int_fits_type_p (value, integer_type_node))
6365    {
6366      pedwarn ("ANSI C restricts enumerator values to range of `int'");
6367      value = integer_zero_node;
6368    }
6369
6370  /* Set basis for default for next value.  */
6371  enum_next_value = build_binary_op (PLUS_EXPR, value, integer_one_node, 0);
6372  enum_overflow = tree_int_cst_lt (enum_next_value, value);
6373
6374  /* Now create a declaration for the enum value name.  */
6375
6376  type = TREE_TYPE (value);
6377  type = type_for_size (MAX (TYPE_PRECISION (type),
6378			     TYPE_PRECISION (integer_type_node)),
6379			((flag_traditional
6380			  || TYPE_PRECISION (type) >= TYPE_PRECISION (integer_type_node))
6381			 && TREE_UNSIGNED (type)));
6382
6383  decl = build_decl (CONST_DECL, name, type);
6384  DECL_INITIAL (decl) = value;
6385  TREE_TYPE (value) = type;
6386  pushdecl (decl);
6387
6388  return saveable_tree_cons (decl, value, NULL_TREE);
6389}
6390
6391/* Create the FUNCTION_DECL for a function definition.
6392   DECLSPECS, DECLARATOR, PREFIX_ATTRIBUTES and ATTRIBUTES are the parts of
6393   the declaration; they describe the function's name and the type it returns,
6394   but twisted together in a fashion that parallels the syntax of C.
6395
6396   This function creates a binding context for the function body
6397   as well as setting up the FUNCTION_DECL in current_function_decl.
6398
6399   Returns 1 on success.  If the DECLARATOR is not suitable for a function
6400   (it defines a datum instead), we return 0, which tells
6401   yyparse to report a parse error.
6402
6403   NESTED is nonzero for a function nested within another function.  */
6404
6405int
6406start_function (declspecs, declarator, prefix_attributes, attributes, nested)
6407     tree declarator, declspecs, prefix_attributes, attributes;
6408     int nested;
6409{
6410  tree decl1, old_decl;
6411  tree restype;
6412  int old_immediate_size_expand = immediate_size_expand;
6413
6414  current_function_returns_value = 0;  /* Assume, until we see it does.  */
6415  current_function_returns_null = 0;
6416  warn_about_return_type = 0;
6417  current_extern_inline = 0;
6418  c_function_varargs = 0;
6419  named_labels = 0;
6420  shadowed_labels = 0;
6421
6422  /* Don't expand any sizes in the return type of the function.  */
6423  immediate_size_expand = 0;
6424
6425  decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1);
6426
6427  /* If the declarator is not suitable for a function definition,
6428     cause a syntax error.  */
6429  if (decl1 == 0)
6430    {
6431      immediate_size_expand = old_immediate_size_expand;
6432      return 0;
6433    }
6434
6435  decl_attributes (decl1, prefix_attributes, attributes);
6436
6437  announce_function (decl1);
6438
6439  if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl1))) == 0)
6440    {
6441      error ("return-type is an incomplete type");
6442      /* Make it return void instead.  */
6443      TREE_TYPE (decl1)
6444	= build_function_type (void_type_node,
6445			       TYPE_ARG_TYPES (TREE_TYPE (decl1)));
6446    }
6447
6448  if (warn_about_return_type)
6449    warning ("return-type defaults to `int'");
6450
6451  /* Save the parm names or decls from this function's declarator
6452     where store_parm_decls will find them.  */
6453  current_function_parms = last_function_parms;
6454  current_function_parm_tags = last_function_parm_tags;
6455
6456  /* Make the init_value nonzero so pushdecl knows this is not tentative.
6457     error_mark_node is replaced below (in poplevel) with the BLOCK.  */
6458  DECL_INITIAL (decl1) = error_mark_node;
6459
6460  /* If this definition isn't a prototype and we had a prototype declaration
6461     before, copy the arg type info from that prototype.
6462     But not if what we had before was a builtin function.  */
6463  old_decl = lookup_name_current_level (DECL_NAME (decl1));
6464  if (old_decl != 0 && TREE_CODE (TREE_TYPE (old_decl)) == FUNCTION_TYPE
6465      && !DECL_BUILT_IN (old_decl)
6466      && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1)))
6467	  == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (old_decl))))
6468      && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0)
6469    {
6470      TREE_TYPE (decl1) = TREE_TYPE (old_decl);
6471      current_function_prototype_file = DECL_SOURCE_FILE (old_decl);
6472      current_function_prototype_line = DECL_SOURCE_LINE (old_decl);
6473    }
6474
6475  /* If there is no explicit declaration, look for any out-of-scope implicit
6476     declarations.  */
6477  if (old_decl == 0)
6478    old_decl = IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1));
6479
6480  /* Optionally warn of old-fashioned def with no previous prototype.  */
6481  if (warn_strict_prototypes
6482      && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0
6483      && !(old_decl != 0 && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) != 0))
6484    warning ("function declaration isn't a prototype");
6485  /* Optionally warn of any global def with no previous prototype.  */
6486  else if (warn_missing_prototypes
6487	   && TREE_PUBLIC (decl1)
6488	   && !(old_decl != 0 && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) != 0)
6489	   && strcmp ("main", IDENTIFIER_POINTER (DECL_NAME (decl1))))
6490    warning_with_decl (decl1, "no previous prototype for `%s'");
6491  /* Optionally warn of any def with no previous prototype
6492     if the function has already been used.  */
6493  else if (warn_missing_prototypes
6494	   && old_decl != 0 && TREE_USED (old_decl)
6495	   && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) == 0)
6496    warning_with_decl (decl1,
6497		      "`%s' was used with no prototype before its definition");
6498  /* Optionally warn of any global def with no previous declaration.  */
6499  else if (warn_missing_declarations
6500	   && TREE_PUBLIC (decl1)
6501	   && old_decl == 0
6502	   && strcmp ("main", IDENTIFIER_POINTER (DECL_NAME (decl1))))
6503    warning_with_decl (decl1, "no previous declaration for `%s'");
6504  /* Optionally warn of any def with no previous declaration
6505     if the function has already been used.  */
6506  else if (warn_missing_declarations
6507	   && old_decl != 0 && TREE_USED (old_decl)
6508	   && old_decl == IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)))
6509    warning_with_decl (decl1,
6510		    "`%s' was used with no declaration before its definition");
6511
6512  /* This is a definition, not a reference.
6513     So normally clear DECL_EXTERNAL.
6514     However, `extern inline' acts like a declaration
6515     except for defining how to inline.  So set DECL_EXTERNAL in that case.  */
6516  DECL_EXTERNAL (decl1) = current_extern_inline;
6517
6518#ifdef SET_DEFAULT_DECL_ATTRIBUTES
6519  SET_DEFAULT_DECL_ATTRIBUTES (decl1, attributes);
6520#endif
6521
6522  /* This function exists in static storage.
6523     (This does not mean `static' in the C sense!)  */
6524  TREE_STATIC (decl1) = 1;
6525
6526  /* A nested function is not global.  */
6527  if (current_function_decl != 0)
6528    TREE_PUBLIC (decl1) = 0;
6529
6530  /* Warn for unlikely, improbable, or stupid declarations of `main'. */
6531  if (warn_main > 0
6532      && strcmp ("main", IDENTIFIER_POINTER (DECL_NAME (decl1))) == 0)
6533    {
6534      tree args;
6535      int argct = 0;
6536
6537      if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1)))
6538	   != integer_type_node)
6539	pedwarn_with_decl (decl1, "return type of `%s' is not `int'");
6540
6541      for (args = TYPE_ARG_TYPES (TREE_TYPE (decl1)); args;
6542	   args = TREE_CHAIN (args))
6543	{
6544	  tree type = args ? TREE_VALUE (args) : 0;
6545
6546	  if (type == void_type_node)
6547	    break;
6548
6549	  ++argct;
6550	  switch (argct)
6551	    {
6552	    case 1:
6553	      if (TYPE_MAIN_VARIANT (type) != integer_type_node)
6554		pedwarn_with_decl (decl1,
6555				   "first argument of `%s' should be `int'");
6556	      break;
6557
6558	    case 2:
6559	      if (TREE_CODE (type) != POINTER_TYPE
6560		  || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE
6561		  || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type)))
6562		      != char_type_node))
6563		pedwarn_with_decl (decl1,
6564			       "second argument of `%s' should be `char **'");
6565	      break;
6566
6567	    case 3:
6568	      if (TREE_CODE (type) != POINTER_TYPE
6569		  || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE
6570		  || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type)))
6571		      != char_type_node))
6572		pedwarn_with_decl (decl1,
6573		   "third argument of `%s' should probably be `char **'");
6574	      break;
6575	    }
6576	}
6577
6578      /* It is intentional that this message does not mention the third
6579	 argument, which is warned for only pedantically, because it's
6580	 blessed by mention in an appendix of the standard. */
6581      if (argct > 0 && (argct < 2 || argct > 3))
6582	pedwarn_with_decl (decl1, "`%s' takes only zero or two arguments");
6583
6584      if (argct == 3 && pedantic)
6585	pedwarn_with_decl (decl1, "third argument of `%s' is deprecated");
6586
6587      if (! TREE_PUBLIC (decl1))
6588	pedwarn_with_decl (decl1, "`%s' is normally a non-static function");
6589    }
6590
6591  /* Record the decl so that the function name is defined.
6592     If we already have a decl for this name, and it is a FUNCTION_DECL,
6593     use the old decl.  */
6594
6595  current_function_decl = pushdecl (decl1);
6596
6597  pushlevel (0);
6598  declare_parm_level (1);
6599  current_binding_level->subblocks_tag_transparent = 1;
6600
6601  make_function_rtl (current_function_decl);
6602
6603  restype = TREE_TYPE (TREE_TYPE (current_function_decl));
6604  /* Promote the value to int before returning it.  */
6605  if (C_PROMOTING_INTEGER_TYPE_P (restype))
6606    {
6607      /* It retains unsignedness if traditional
6608	 or if not really getting wider.  */
6609      if (TREE_UNSIGNED (restype)
6610	  && (flag_traditional
6611	      || (TYPE_PRECISION (restype)
6612		  == TYPE_PRECISION (integer_type_node))))
6613	restype = unsigned_type_node;
6614      else
6615	restype = integer_type_node;
6616    }
6617  DECL_RESULT (current_function_decl)
6618    = build_decl (RESULT_DECL, NULL_TREE, restype);
6619
6620  if (!nested)
6621    /* Allocate further tree nodes temporarily during compilation
6622       of this function only.  */
6623    temporary_allocation ();
6624
6625  /* If this fcn was already referenced via a block-scope `extern' decl
6626     (or an implicit decl), propagate certain information about the usage.  */
6627  if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (current_function_decl)))
6628    TREE_ADDRESSABLE (current_function_decl) = 1;
6629
6630  immediate_size_expand = old_immediate_size_expand;
6631
6632  return 1;
6633}
6634
6635/* Record that this function is going to be a varargs function.
6636   This is called before store_parm_decls, which is too early
6637   to call mark_varargs directly.  */
6638
6639void
6640c_mark_varargs ()
6641{
6642  c_function_varargs = 1;
6643}
6644
6645/* Store the parameter declarations into the current function declaration.
6646   This is called after parsing the parameter declarations, before
6647   digesting the body of the function.
6648
6649   For an old-style definition, modify the function's type
6650   to specify at least the number of arguments.  */
6651
6652void
6653store_parm_decls ()
6654{
6655  register tree fndecl = current_function_decl;
6656  register tree parm;
6657
6658  /* This is either a chain of PARM_DECLs (if a prototype was used)
6659     or a list of IDENTIFIER_NODEs (for an old-fashioned C definition).  */
6660  tree specparms = current_function_parms;
6661
6662  /* This is a list of types declared among parms in a prototype.  */
6663  tree parmtags = current_function_parm_tags;
6664
6665  /* This is a chain of PARM_DECLs from old-style parm declarations.  */
6666  register tree parmdecls = getdecls ();
6667
6668  /* This is a chain of any other decls that came in among the parm
6669     declarations.  If a parm is declared with  enum {foo, bar} x;
6670     then CONST_DECLs for foo and bar are put here.  */
6671  tree nonparms = 0;
6672
6673  /* Nonzero if this definition is written with a prototype.  */
6674  int prototype = 0;
6675
6676  if (specparms != 0 && TREE_CODE (specparms) != TREE_LIST)
6677    {
6678      /* This case is when the function was defined with an ANSI prototype.
6679	 The parms already have decls, so we need not do anything here
6680	 except record them as in effect
6681	 and complain if any redundant old-style parm decls were written.  */
6682
6683      register tree next;
6684      tree others = 0;
6685
6686      prototype = 1;
6687
6688      if (parmdecls != 0)
6689	{
6690	  tree decl, link;
6691
6692	  error_with_decl (fndecl,
6693			   "parm types given both in parmlist and separately");
6694	  /* Get rid of the erroneous decls; don't keep them on
6695	     the list of parms, since they might not be PARM_DECLs.  */
6696	  for (decl = current_binding_level->names;
6697	       decl; decl = TREE_CHAIN (decl))
6698	    if (DECL_NAME (decl))
6699	      IDENTIFIER_LOCAL_VALUE (DECL_NAME (decl)) = 0;
6700	  for (link = current_binding_level->shadowed;
6701	       link; link = TREE_CHAIN (link))
6702	    IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
6703	  current_binding_level->names = 0;
6704	  current_binding_level->shadowed = 0;
6705	}
6706
6707      specparms = nreverse (specparms);
6708      for (parm = specparms; parm; parm = next)
6709	{
6710	  next = TREE_CHAIN (parm);
6711	  if (TREE_CODE (parm) == PARM_DECL)
6712	    {
6713	      if (DECL_NAME (parm) == 0)
6714		error_with_decl (parm, "parameter name omitted");
6715	      else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node)
6716		{
6717		  error_with_decl (parm, "parameter `%s' declared void");
6718		  /* Change the type to error_mark_node so this parameter
6719		     will be ignored by assign_parms.  */
6720		  TREE_TYPE (parm) = error_mark_node;
6721		}
6722	      pushdecl (parm);
6723	    }
6724	  else
6725	    {
6726	      /* If we find an enum constant or a type tag,
6727		 put it aside for the moment.  */
6728	      TREE_CHAIN (parm) = 0;
6729	      others = chainon (others, parm);
6730	    }
6731	}
6732
6733      /* Get the decls in their original chain order
6734	 and record in the function.  */
6735      DECL_ARGUMENTS (fndecl) = getdecls ();
6736
6737#if 0
6738      /* If this function takes a variable number of arguments,
6739	 add a phony parameter to the end of the parm list,
6740	 to represent the position of the first unnamed argument.  */
6741      if (TREE_VALUE (tree_last (TYPE_ARG_TYPES (TREE_TYPE (fndecl))))
6742	  != void_type_node)
6743	{
6744	  tree dummy = build_decl (PARM_DECL, NULL_TREE, void_type_node);
6745	  /* Let's hope the address of the unnamed parm
6746	     won't depend on its type.  */
6747	  TREE_TYPE (dummy) = integer_type_node;
6748	  DECL_ARG_TYPE (dummy) = integer_type_node;
6749	  DECL_ARGUMENTS (fndecl)
6750	    = chainon (DECL_ARGUMENTS (fndecl), dummy);
6751	}
6752#endif
6753
6754      /* Now pushdecl the enum constants.  */
6755      for (parm = others; parm; parm = next)
6756	{
6757	  next = TREE_CHAIN (parm);
6758	  if (DECL_NAME (parm) == 0)
6759	    ;
6760	  else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node)
6761	    ;
6762	  else if (TREE_CODE (parm) != PARM_DECL)
6763	    pushdecl (parm);
6764	}
6765
6766      storetags (chainon (parmtags, gettags ()));
6767    }
6768  else
6769    {
6770      /* SPECPARMS is an identifier list--a chain of TREE_LIST nodes
6771	 each with a parm name as the TREE_VALUE.
6772
6773	 PARMDECLS is a chain of declarations for parameters.
6774	 Warning! It can also contain CONST_DECLs which are not parameters
6775	 but are names of enumerators of any enum types
6776	 declared among the parameters.
6777
6778	 First match each formal parameter name with its declaration.
6779	 Associate decls with the names and store the decls
6780	 into the TREE_PURPOSE slots.  */
6781
6782      for (parm = parmdecls; parm; parm = TREE_CHAIN (parm))
6783	DECL_RESULT (parm) = 0;
6784
6785      for (parm = specparms; parm; parm = TREE_CHAIN (parm))
6786	{
6787	  register tree tail, found = NULL;
6788
6789	  if (TREE_VALUE (parm) == 0)
6790	    {
6791	      error_with_decl (fndecl, "parameter name missing from parameter list");
6792	      TREE_PURPOSE (parm) = 0;
6793	      continue;
6794	    }
6795
6796	  /* See if any of the parmdecls specifies this parm by name.
6797	     Ignore any enumerator decls.  */
6798	  for (tail = parmdecls; tail; tail = TREE_CHAIN (tail))
6799	    if (DECL_NAME (tail) == TREE_VALUE (parm)
6800		&& TREE_CODE (tail) == PARM_DECL)
6801	      {
6802		found = tail;
6803		break;
6804	      }
6805
6806	  /* If declaration already marked, we have a duplicate name.
6807	     Complain, and don't use this decl twice.   */
6808	  if (found && DECL_RESULT (found) != 0)
6809	    {
6810	      error_with_decl (found, "multiple parameters named `%s'");
6811	      found = 0;
6812	    }
6813
6814	  /* If the declaration says "void", complain and ignore it.  */
6815	  if (found && TYPE_MAIN_VARIANT (TREE_TYPE (found)) == void_type_node)
6816	    {
6817	      error_with_decl (found, "parameter `%s' declared void");
6818	      TREE_TYPE (found) = integer_type_node;
6819	      DECL_ARG_TYPE (found) = integer_type_node;
6820	      layout_decl (found, 0);
6821	    }
6822
6823	  /* Traditionally, a parm declared float is actually a double.  */
6824	  if (found && flag_traditional
6825	      && TYPE_MAIN_VARIANT (TREE_TYPE (found)) == float_type_node)
6826	    {
6827	      TREE_TYPE (found) = double_type_node;
6828	      DECL_ARG_TYPE (found) = double_type_node;
6829	      layout_decl (found, 0);
6830	    }
6831
6832	  /* If no declaration found, default to int.  */
6833	  if (!found)
6834	    {
6835	      found = build_decl (PARM_DECL, TREE_VALUE (parm),
6836				  integer_type_node);
6837	      DECL_ARG_TYPE (found) = TREE_TYPE (found);
6838	      DECL_SOURCE_LINE (found) = DECL_SOURCE_LINE (fndecl);
6839	      DECL_SOURCE_FILE (found) = DECL_SOURCE_FILE (fndecl);
6840	      if (extra_warnings)
6841		warning_with_decl (found, "type of `%s' defaults to `int'");
6842	      pushdecl (found);
6843	    }
6844
6845	  TREE_PURPOSE (parm) = found;
6846
6847	  /* Mark this decl as "already found" -- see test, above.
6848	     It is safe to use DECL_RESULT for this
6849	     since it is not used in PARM_DECLs or CONST_DECLs.  */
6850	  DECL_RESULT (found) = error_mark_node;
6851	}
6852
6853      /* Put anything which is on the parmdecls chain and which is
6854	 not a PARM_DECL onto the list NONPARMS.  (The types of
6855	 non-parm things which might appear on the list include
6856	 enumerators and NULL-named TYPE_DECL nodes.) Complain about
6857	 any actual PARM_DECLs not matched with any names.  */
6858
6859      nonparms = 0;
6860      for (parm = parmdecls; parm; )
6861	{
6862	  tree next = TREE_CHAIN (parm);
6863	  TREE_CHAIN (parm) = 0;
6864
6865	  if (TREE_CODE (parm) != PARM_DECL)
6866	    nonparms = chainon (nonparms, parm);
6867	  else
6868	    {
6869	      /* Complain about args with incomplete types.  */
6870	      if (TYPE_SIZE (TREE_TYPE (parm)) == 0)
6871	        {
6872	          error_with_decl (parm, "parameter `%s' has incomplete type");
6873	          TREE_TYPE (parm) = error_mark_node;
6874	        }
6875
6876	      if (DECL_RESULT (parm) == 0)
6877	        {
6878	          error_with_decl (parm,
6879			           "declaration for parameter `%s' but no such parameter");
6880	          /* Pretend the parameter was not missing.
6881		     This gets us to a standard state and minimizes
6882		     further error messages.  */
6883	          specparms
6884		    = chainon (specparms,
6885			       tree_cons (parm, NULL_TREE, NULL_TREE));
6886		}
6887	    }
6888
6889	  parm = next;
6890	}
6891
6892      /* Chain the declarations together in the order of the list of names.  */
6893      /* Store that chain in the function decl, replacing the list of names.  */
6894      parm = specparms;
6895      DECL_ARGUMENTS (fndecl) = 0;
6896      {
6897	register tree last;
6898	for (last = 0; parm; parm = TREE_CHAIN (parm))
6899	  if (TREE_PURPOSE (parm))
6900	    {
6901	      if (last == 0)
6902		DECL_ARGUMENTS (fndecl) = TREE_PURPOSE (parm);
6903	      else
6904		TREE_CHAIN (last) = TREE_PURPOSE (parm);
6905	      last = TREE_PURPOSE (parm);
6906	      TREE_CHAIN (last) = 0;
6907	    }
6908      }
6909
6910      /* If there was a previous prototype,
6911	 set the DECL_ARG_TYPE of each argument according to
6912	 the type previously specified, and report any mismatches.  */
6913
6914      if (TYPE_ARG_TYPES (TREE_TYPE (fndecl)))
6915	{
6916	  register tree type;
6917	  for (parm = DECL_ARGUMENTS (fndecl),
6918	       type = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
6919	       parm || (type && (TYPE_MAIN_VARIANT (TREE_VALUE (type))
6920				 != void_type_node));
6921	       parm = TREE_CHAIN (parm), type = TREE_CHAIN (type))
6922	    {
6923	      if (parm == 0 || type == 0
6924		  || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node)
6925		{
6926		  error ("number of arguments doesn't match prototype");
6927		  error_with_file_and_line (current_function_prototype_file,
6928					    current_function_prototype_line,
6929					    "prototype declaration");
6930		  break;
6931		}
6932	      /* Type for passing arg must be consistent
6933		 with that declared for the arg.  */
6934	      if (! comptypes (DECL_ARG_TYPE (parm), TREE_VALUE (type)))
6935		{
6936		  if (TYPE_MAIN_VARIANT (TREE_TYPE (parm))
6937		      == TYPE_MAIN_VARIANT (TREE_VALUE (type)))
6938		    {
6939		      /* Adjust argument to match prototype.  E.g. a previous
6940			 `int foo(float);' prototype causes
6941			 `int foo(x) float x; {...}' to be treated like
6942			 `int foo(float x) {...}'.  This is particularly
6943			 useful for argument types like uid_t.  */
6944		      DECL_ARG_TYPE (parm) = TREE_TYPE (parm);
6945#ifdef PROMOTE_PROTOTYPES
6946		      if ((TREE_CODE (TREE_TYPE (parm)) == INTEGER_TYPE
6947			   || TREE_CODE (TREE_TYPE (parm)) == ENUMERAL_TYPE)
6948			  && TYPE_PRECISION (TREE_TYPE (parm))
6949			  < TYPE_PRECISION (integer_type_node))
6950			DECL_ARG_TYPE (parm) = integer_type_node;
6951#endif
6952		      if (pedantic)
6953			{
6954			  pedwarn ("promoted argument `%s' doesn't match prototype",
6955				   IDENTIFIER_POINTER (DECL_NAME (parm)));
6956			  warning_with_file_and_line
6957			    (current_function_prototype_file,
6958			     current_function_prototype_line,
6959			     "prototype declaration");
6960			}
6961		    }
6962		  /* If -traditional, allow `int' argument to match
6963		     `unsigned' prototype.  */
6964		  else if (! (flag_traditional
6965			      && TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == integer_type_node
6966			      && TYPE_MAIN_VARIANT (TREE_VALUE (type)) == unsigned_type_node))
6967		    {
6968		      error ("argument `%s' doesn't match prototype",
6969			     IDENTIFIER_POINTER (DECL_NAME (parm)));
6970		      error_with_file_and_line (current_function_prototype_file,
6971						current_function_prototype_line,
6972						"prototype declaration");
6973		    }
6974		}
6975	    }
6976	  TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = 0;
6977	}
6978
6979      /* Otherwise, create a prototype that would match.  */
6980
6981      else
6982	{
6983	  tree actual = 0, last = 0, type;
6984
6985	  for (parm = DECL_ARGUMENTS (fndecl); parm; parm = TREE_CHAIN (parm))
6986	    {
6987	      type = perm_tree_cons (NULL_TREE, DECL_ARG_TYPE (parm),
6988				     NULL_TREE);
6989	      if (last)
6990		TREE_CHAIN (last) = type;
6991	      else
6992		actual = type;
6993	      last = type;
6994	    }
6995	  type = perm_tree_cons (NULL_TREE, void_type_node, NULL_TREE);
6996	  if (last)
6997	    TREE_CHAIN (last) = type;
6998	  else
6999	    actual = type;
7000
7001	  /* We are going to assign a new value for the TYPE_ACTUAL_ARG_TYPES
7002	     of the type of this function, but we need to avoid having this
7003	     affect the types of other similarly-typed functions, so we must
7004	     first force the generation of an identical (but separate) type
7005	     node for the relevant function type.  The new node we create
7006	     will be a variant of the main variant of the original function
7007	     type.  */
7008
7009	  TREE_TYPE (fndecl) = build_type_copy (TREE_TYPE (fndecl));
7010
7011	  TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = actual;
7012	}
7013
7014      /* Now store the final chain of decls for the arguments
7015	 as the decl-chain of the current lexical scope.
7016	 Put the enumerators in as well, at the front so that
7017	 DECL_ARGUMENTS is not modified.  */
7018
7019      storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl)));
7020    }
7021
7022  /* Make sure the binding level for the top of the function body
7023     gets a BLOCK if there are any in the function.
7024     Otherwise, the dbx output is wrong.  */
7025
7026  keep_next_if_subblocks = 1;
7027
7028  /* ??? This might be an improvement,
7029     but needs to be thought about some more.  */
7030#if 0
7031  keep_next_level_flag = 1;
7032#endif
7033
7034  /* Write a record describing this function definition to the prototypes
7035     file (if requested).  */
7036
7037  gen_aux_info_record (fndecl, 1, 0, prototype);
7038
7039  /* Initialize the RTL code for the function.  */
7040
7041  init_function_start (fndecl, input_filename, lineno);
7042
7043  /* If this is a varargs function, inform function.c.  */
7044
7045  if (c_function_varargs)
7046    mark_varargs ();
7047
7048  /* Declare __FUNCTION__ and __PRETTY_FUNCTION__ for this function.  */
7049
7050  declare_function_name ();
7051
7052  /* Set up parameters and prepare for return, for the function.  */
7053
7054  expand_function_start (fndecl, 0);
7055
7056  /* If this function is `main', emit a call to `__main'
7057     to run global initializers, etc.  */
7058  if (DECL_NAME (fndecl)
7059      && strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") == 0
7060      && DECL_CONTEXT (fndecl) == NULL_TREE)
7061    expand_main_function ();
7062}
7063
7064/* SPECPARMS is an identifier list--a chain of TREE_LIST nodes
7065   each with a parm name as the TREE_VALUE.  A null pointer as TREE_VALUE
7066   stands for an ellipsis in the identifier list.
7067
7068   PARMLIST is the data returned by get_parm_info for the
7069   parmlist that follows the semicolon.
7070
7071   We return a value of the same sort that get_parm_info returns,
7072   except that it describes the combination of identifiers and parmlist.  */
7073
7074tree
7075combine_parm_decls (specparms, parmlist, void_at_end)
7076     tree specparms, parmlist;
7077     int void_at_end;
7078{
7079  register tree fndecl = current_function_decl;
7080  register tree parm;
7081
7082  tree parmdecls = TREE_PURPOSE (parmlist);
7083
7084  /* This is a chain of any other decls that came in among the parm
7085     declarations.  They were separated already by get_parm_info,
7086     so we just need to keep them separate.  */
7087  tree nonparms = TREE_VALUE (parmlist);
7088
7089  tree types = 0;
7090
7091  for (parm = parmdecls; parm; parm = TREE_CHAIN (parm))
7092    DECL_RESULT (parm) = 0;
7093
7094  for (parm = specparms; parm; parm = TREE_CHAIN (parm))
7095    {
7096      register tree tail, found = NULL;
7097
7098      /* See if any of the parmdecls specifies this parm by name.  */
7099      for (tail = parmdecls; tail; tail = TREE_CHAIN (tail))
7100	if (DECL_NAME (tail) == TREE_VALUE (parm))
7101	  {
7102	    found = tail;
7103	    break;
7104	  }
7105
7106      /* If declaration already marked, we have a duplicate name.
7107	 Complain, and don't use this decl twice.   */
7108      if (found && DECL_RESULT (found) != 0)
7109	{
7110	  error_with_decl (found, "multiple parameters named `%s'");
7111	  found = 0;
7112	}
7113
7114      /* If the declaration says "void", complain and ignore it.  */
7115      if (found && TYPE_MAIN_VARIANT (TREE_TYPE (found)) == void_type_node)
7116	{
7117	  error_with_decl (found, "parameter `%s' declared void");
7118	  TREE_TYPE (found) = integer_type_node;
7119	  DECL_ARG_TYPE (found) = integer_type_node;
7120	  layout_decl (found, 0);
7121	}
7122
7123      /* Traditionally, a parm declared float is actually a double.  */
7124      if (found && flag_traditional
7125	  && TYPE_MAIN_VARIANT (TREE_TYPE (found)) == float_type_node)
7126	{
7127	  TREE_TYPE (found) = double_type_node;
7128	  DECL_ARG_TYPE (found) = double_type_node;
7129	  layout_decl (found, 0);
7130	}
7131
7132      /* If no declaration found, default to int.  */
7133      if (!found)
7134	{
7135	  found = build_decl (PARM_DECL, TREE_VALUE (parm),
7136			      integer_type_node);
7137	  DECL_ARG_TYPE (found) = TREE_TYPE (found);
7138	  DECL_SOURCE_LINE (found) = DECL_SOURCE_LINE (fndecl);
7139	  DECL_SOURCE_FILE (found) = DECL_SOURCE_FILE (fndecl);
7140	  error_with_decl (found, "type of parameter `%s' is not declared");
7141	  pushdecl (found);
7142	}
7143
7144      TREE_PURPOSE (parm) = found;
7145
7146      /* Mark this decl as "already found" -- see test, above.
7147	 It is safe to use DECL_RESULT for this
7148	 since it is not used in PARM_DECLs or CONST_DECLs.  */
7149      DECL_RESULT (found) = error_mark_node;
7150    }
7151
7152  /* Complain about any actual PARM_DECLs not matched with any names.  */
7153
7154  for (parm = parmdecls; parm; )
7155    {
7156      tree next = TREE_CHAIN (parm);
7157      TREE_CHAIN (parm) = 0;
7158
7159      /* Complain about args with incomplete types.  */
7160      if (TYPE_SIZE (TREE_TYPE (parm)) == 0)
7161	{
7162	  error_with_decl (parm, "parameter `%s' has incomplete type");
7163	  TREE_TYPE (parm) = error_mark_node;
7164	}
7165
7166      if (DECL_RESULT (parm) == 0)
7167	{
7168	  error_with_decl (parm,
7169			   "declaration for parameter `%s' but no such parameter");
7170	  /* Pretend the parameter was not missing.
7171	     This gets us to a standard state and minimizes
7172	     further error messages.  */
7173	  specparms
7174	    = chainon (specparms,
7175		       tree_cons (parm, NULL_TREE, NULL_TREE));
7176	}
7177
7178      parm = next;
7179    }
7180
7181  /* Chain the declarations together in the order of the list of names.
7182     At the same time, build up a list of their types, in reverse order.  */
7183
7184  parm = specparms;
7185  parmdecls = 0;
7186  {
7187    register tree last;
7188    for (last = 0; parm; parm = TREE_CHAIN (parm))
7189      if (TREE_PURPOSE (parm))
7190	{
7191	  if (last == 0)
7192	    parmdecls = TREE_PURPOSE (parm);
7193	  else
7194	    TREE_CHAIN (last) = TREE_PURPOSE (parm);
7195	  last = TREE_PURPOSE (parm);
7196	  TREE_CHAIN (last) = 0;
7197
7198	  types = saveable_tree_cons (NULL_TREE, TREE_TYPE (parm), types);
7199	}
7200  }
7201
7202  if (void_at_end)
7203    return saveable_tree_cons (parmdecls, nonparms,
7204			       nreverse (saveable_tree_cons (NULL_TREE,
7205							     void_type_node,
7206							     types)));
7207
7208  return saveable_tree_cons (parmdecls, nonparms, nreverse (types));
7209}
7210
7211/* Finish up a function declaration and compile that function
7212   all the way to assembler language output.  The free the storage
7213   for the function definition.
7214
7215   This is called after parsing the body of the function definition.
7216
7217   NESTED is nonzero if the function being finished is nested in another.  */
7218
7219void
7220finish_function (nested)
7221     int nested;
7222{
7223  register tree fndecl = current_function_decl;
7224
7225/*  TREE_READONLY (fndecl) = 1;
7226    This caused &foo to be of type ptr-to-const-function
7227    which then got a warning when stored in a ptr-to-function variable.  */
7228
7229  poplevel (1, 0, 1);
7230  BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
7231
7232  /* Must mark the RESULT_DECL as being in this function.  */
7233
7234  DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
7235
7236  /* Obey `register' declarations if `setjmp' is called in this fn.  */
7237  if (flag_traditional && current_function_calls_setjmp)
7238    {
7239      setjmp_protect (DECL_INITIAL (fndecl));
7240      setjmp_protect_args ();
7241    }
7242
7243  if (! strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main"))
7244    {
7245      if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl)))
7246	  != integer_type_node)
7247	{
7248	  /* If warn_main is 1 (-Wmain) or 2 (-Wall), we have already warned.
7249	     If warn_main is -1 (-Wno-main) we don't want to be warned. */
7250	  if (! warn_main)
7251	    pedwarn_with_decl (fndecl, "return type of `%s' is not `int'");
7252	}
7253      else
7254	{
7255#ifdef DEFAULT_MAIN_RETURN
7256	  /* Make it so that `main' always returns success by default.  */
7257	  DEFAULT_MAIN_RETURN;
7258#endif
7259	}
7260    }
7261
7262  /* Generate rtl for function exit.  */
7263  expand_function_end (input_filename, lineno, 0);
7264
7265  /* So we can tell if jump_optimize sets it to 1.  */
7266  can_reach_end = 0;
7267
7268  /* Run the optimizers and output the assembler code for this function.  */
7269  rest_of_compilation (fndecl);
7270
7271  current_function_returns_null |= can_reach_end;
7272
7273  if (warn_missing_noreturn
7274      && !TREE_THIS_VOLATILE (fndecl)
7275      && !current_function_returns_null
7276      && !current_function_returns_value)
7277    warning ("function might be possible candidate for attribute `noreturn'");
7278
7279  if (TREE_THIS_VOLATILE (fndecl) && current_function_returns_null)
7280    warning ("`noreturn' function does return");
7281  else if (warn_return_type && can_reach_end
7282	   && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl))) != void_type_node)
7283    /* If this function returns non-void and control can drop through,
7284       complain.  */
7285    warning ("control reaches end of non-void function");
7286  /* With just -W, complain only if function returns both with
7287     and without a value.  */
7288  else if (extra_warnings
7289	   && current_function_returns_value && current_function_returns_null)
7290    warning ("this function may return with or without a value");
7291
7292  /* If requested, warn about function definitions where the function will
7293     return a value (usually of some struct or union type) which itself will
7294     take up a lot of stack space.  */
7295
7296  if (warn_larger_than && !DECL_EXTERNAL (fndecl) && TREE_TYPE (fndecl))
7297    {
7298      register tree ret_type = TREE_TYPE (TREE_TYPE (fndecl));
7299
7300      if (ret_type)
7301	{
7302	  register tree ret_type_size = TYPE_SIZE (ret_type);
7303
7304	  if (TREE_CODE (ret_type_size) == INTEGER_CST)
7305	    {
7306	      unsigned units
7307		= TREE_INT_CST_LOW (ret_type_size) / BITS_PER_UNIT;
7308
7309	      if (units > larger_than_size)
7310		warning_with_decl (fndecl,
7311				   "size of return value of `%s' is %u bytes",
7312				   units);
7313	    }
7314	}
7315    }
7316
7317  /* Free all the tree nodes making up this function.  */
7318  /* Switch back to allocating nodes permanently
7319     until we start another function.  */
7320  if (! nested)
7321    permanent_allocation (1);
7322
7323  if (DECL_SAVED_INSNS (fndecl) == 0 && ! nested)
7324    {
7325      /* Stop pointing to the local nodes about to be freed.  */
7326      /* But DECL_INITIAL must remain nonzero so we know this
7327	 was an actual function definition.  */
7328      /* For a nested function, this is done in pop_c_function_context.  */
7329      /* If rest_of_compilation set this to 0, leave it 0.  */
7330      if (DECL_INITIAL (fndecl) != 0)
7331	DECL_INITIAL (fndecl) = error_mark_node;
7332      DECL_ARGUMENTS (fndecl) = 0;
7333    }
7334
7335  if (DECL_STATIC_CONSTRUCTOR (fndecl))
7336    {
7337#ifndef ASM_OUTPUT_CONSTRUCTOR
7338      if (! flag_gnu_linker)
7339	static_ctors = perm_tree_cons (NULL_TREE, fndecl, static_ctors);
7340      else
7341#endif
7342      assemble_constructor (IDENTIFIER_POINTER (DECL_NAME (fndecl)));
7343    }
7344  if (DECL_STATIC_DESTRUCTOR (fndecl))
7345    {
7346#ifndef ASM_OUTPUT_DESTRUCTOR
7347      if (! flag_gnu_linker)
7348	static_dtors = perm_tree_cons (NULL_TREE, fndecl, static_dtors);
7349      else
7350#endif
7351      assemble_destructor (IDENTIFIER_POINTER (DECL_NAME (fndecl)));
7352    }
7353
7354  if (! nested)
7355    {
7356      /* Let the error reporting routines know that we're outside a
7357	 function.  For a nested function, this value is used in
7358	 pop_c_function_context and then reset via pop_function_context.  */
7359      current_function_decl = NULL;
7360    }
7361}
7362
7363/* Save and restore the variables in this file and elsewhere
7364   that keep track of the progress of compilation of the current function.
7365   Used for nested functions.  */
7366
7367struct c_function
7368{
7369  struct c_function *next;
7370  tree named_labels;
7371  tree shadowed_labels;
7372  int returns_value;
7373  int returns_null;
7374  int warn_about_return_type;
7375  int extern_inline;
7376  struct binding_level *binding_level;
7377};
7378
7379struct c_function *c_function_chain;
7380
7381/* Save and reinitialize the variables
7382   used during compilation of a C function.  */
7383
7384void
7385push_c_function_context ()
7386{
7387  struct c_function *p
7388    = (struct c_function *) xmalloc (sizeof (struct c_function));
7389
7390  if (pedantic)
7391    pedwarn ("ANSI C forbids nested functions");
7392
7393  push_function_context ();
7394
7395  p->next = c_function_chain;
7396  c_function_chain = p;
7397
7398  p->named_labels = named_labels;
7399  p->shadowed_labels = shadowed_labels;
7400  p->returns_value = current_function_returns_value;
7401  p->returns_null = current_function_returns_null;
7402  p->warn_about_return_type = warn_about_return_type;
7403  p->extern_inline = current_extern_inline;
7404  p->binding_level = current_binding_level;
7405}
7406
7407/* Restore the variables used during compilation of a C function.  */
7408
7409void
7410pop_c_function_context ()
7411{
7412  struct c_function *p = c_function_chain;
7413  tree link;
7414
7415  /* Bring back all the labels that were shadowed.  */
7416  for (link = shadowed_labels; link; link = TREE_CHAIN (link))
7417    if (DECL_NAME (TREE_VALUE (link)) != 0)
7418      IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link)))
7419	= TREE_VALUE (link);
7420
7421  if (DECL_SAVED_INSNS (current_function_decl) == 0)
7422    {
7423      /* Stop pointing to the local nodes about to be freed.  */
7424      /* But DECL_INITIAL must remain nonzero so we know this
7425	 was an actual function definition.  */
7426      DECL_INITIAL (current_function_decl) = error_mark_node;
7427      DECL_ARGUMENTS (current_function_decl) = 0;
7428    }
7429
7430  pop_function_context ();
7431
7432  c_function_chain = p->next;
7433
7434  named_labels = p->named_labels;
7435  shadowed_labels = p->shadowed_labels;
7436  current_function_returns_value = p->returns_value;
7437  current_function_returns_null = p->returns_null;
7438  warn_about_return_type = p->warn_about_return_type;
7439  current_extern_inline = p->extern_inline;
7440  current_binding_level = p->binding_level;
7441
7442  free (p);
7443}
7444
7445/* integrate_decl_tree calls this function, but since we don't use the
7446   DECL_LANG_SPECIFIC field, this is a no-op.  */
7447
7448void
7449copy_lang_decl (node)
7450     tree node ATTRIBUTE_UNUSED;
7451{
7452}
7453