OSDN Git Service

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