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