OSDN Git Service

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