OSDN Git Service

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