OSDN Git Service

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