OSDN Git Service

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