OSDN Git Service

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