OSDN Git Service

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