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