OSDN Git Service

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