OSDN Git Service

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