xref: /netbsd-src/external/gpl3/gcc.old/dist/gcc/c/c-decl.c (revision 946379e7b37692fc43f68eb0d1c10daa0a7f3b6c)
1 /* Process declarations and variables for C compiler.
2    Copyright (C) 1988-2013 Free Software Foundation, Inc.
3 
4 This file is part of GCC.
5 
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
10 
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3.  If not see
18 <http://www.gnu.org/licenses/>.  */
19 
20 /* Process declarations and symbol lookup for C front end.
21    Also constructs types; the standard scalar types at initialization,
22    and structure, union, array and enum types when they are declared.  */
23 
24 /* ??? not all decl nodes are given the most useful possible
25    line numbers.  For example, the CONST_DECLs for enum values.  */
26 
27 #include "config.h"
28 #include "system.h"
29 #include "coretypes.h"
30 #include "input.h"
31 #include "tm.h"
32 #include "intl.h"
33 #include "tree.h"
34 #include "tree-inline.h"
35 #include "flags.h"
36 #include "function.h"
37 #include "c-tree.h"
38 #include "toplev.h"
39 #include "tm_p.h"
40 #include "cpplib.h"
41 #include "target.h"
42 #include "debug.h"
43 #include "opts.h"
44 #include "timevar.h"
45 #include "c-family/c-common.h"
46 #include "c-family/c-objc.h"
47 #include "c-family/c-pragma.h"
48 #include "c-lang.h"
49 #include "langhooks.h"
50 #include "tree-iterator.h"
51 #include "diagnostic-core.h"
52 #include "dumpfile.h"
53 #include "cgraph.h"
54 #include "hash-table.h"
55 #include "langhooks-def.h"
56 #include "pointer-set.h"
57 #include "plugin.h"
58 #include "c-family/c-ada-spec.h"
59 
60 /* In grokdeclarator, distinguish syntactic contexts of declarators.  */
61 enum decl_context
62 { NORMAL,			/* Ordinary declaration */
63   FUNCDEF,			/* Function definition */
64   PARM,				/* Declaration of parm before function body */
65   FIELD,			/* Declaration inside struct or union */
66   TYPENAME};			/* Typename (inside cast or sizeof)  */
67 
68 /* States indicating how grokdeclarator() should handle declspecs marked
69    with __attribute__((deprecated)).  An object declared as
70    __attribute__((deprecated)) suppresses warnings of uses of other
71    deprecated items.  */
72 
73 enum deprecated_states {
74   DEPRECATED_NORMAL,
75   DEPRECATED_SUPPRESS
76 };
77 
78 
79 /* Nonzero if we have seen an invalid cross reference
80    to a struct, union, or enum, but not yet printed the message.  */
81 tree pending_invalid_xref;
82 
83 /* File and line to appear in the eventual error message.  */
84 location_t pending_invalid_xref_location;
85 
86 /* The file and line that the prototype came from if this is an
87    old-style definition; used for diagnostics in
88    store_parm_decls_oldstyle.  */
89 
90 static location_t current_function_prototype_locus;
91 
92 /* Whether this prototype was built-in.  */
93 
94 static bool current_function_prototype_built_in;
95 
96 /* The argument type information of this prototype.  */
97 
98 static tree current_function_prototype_arg_types;
99 
100 /* The argument information structure for the function currently being
101    defined.  */
102 
103 static struct c_arg_info *current_function_arg_info;
104 
105 /* The obstack on which parser and related data structures, which are
106    not live beyond their top-level declaration or definition, are
107    allocated.  */
108 struct obstack parser_obstack;
109 
110 /* The current statement tree.  */
111 
112 static GTY(()) struct stmt_tree_s c_stmt_tree;
113 
114 /* State saving variables.  */
115 tree c_break_label;
116 tree c_cont_label;
117 
118 /* A list of decls to be made automatically visible in each file scope.  */
119 static GTY(()) tree visible_builtins;
120 
121 /* Set to 0 at beginning of a function definition, set to 1 if
122    a return statement that specifies a return value is seen.  */
123 
124 int current_function_returns_value;
125 
126 /* Set to 0 at beginning of a function definition, set to 1 if
127    a return statement with no argument is seen.  */
128 
129 int current_function_returns_null;
130 
131 /* Set to 0 at beginning of a function definition, set to 1 if
132    a call to a noreturn function is seen.  */
133 
134 int current_function_returns_abnormally;
135 
136 /* Set to nonzero by `grokdeclarator' for a function
137    whose return type is defaulted, if warnings for this are desired.  */
138 
139 static int warn_about_return_type;
140 
141 /* Nonzero when the current toplevel function contains a declaration
142    of a nested function which is never defined.  */
143 
144 static bool undef_nested_function;
145 
146 /* Mode used to build pointers (VOIDmode means ptr_mode).  */
147 
148 enum machine_mode c_default_pointer_mode = VOIDmode;
149 
150 
151 /* Each c_binding structure describes one binding of an identifier to
152    a decl.  All the decls in a scope - irrespective of namespace - are
153    chained together by the ->prev field, which (as the name implies)
154    runs in reverse order.  All the decls in a given namespace bound to
155    a given identifier are chained by the ->shadowed field, which runs
156    from inner to outer scopes.
157 
158    The ->decl field usually points to a DECL node, but there are two
159    exceptions.  In the namespace of type tags, the bound entity is a
160    RECORD_TYPE, UNION_TYPE, or ENUMERAL_TYPE node.  If an undeclared
161    identifier is encountered, it is bound to error_mark_node to
162    suppress further errors about that identifier in the current
163    function.
164 
165    The ->u.type field stores the type of the declaration in this scope;
166    if NULL, the type is the type of the ->decl field.  This is only of
167    relevance for objects with external or internal linkage which may
168    be redeclared in inner scopes, forming composite types that only
169    persist for the duration of those scopes.  In the external scope,
170    this stores the composite of all the types declared for this
171    object, visible or not.  The ->inner_comp field (used only at file
172    scope) stores whether an incomplete array type at file scope was
173    completed at an inner scope to an array size other than 1.
174 
175    The ->u.label field is used for labels.  It points to a structure
176    which stores additional information used for warnings.
177 
178    The depth field is copied from the scope structure that holds this
179    decl.  It is used to preserve the proper ordering of the ->shadowed
180    field (see bind()) and also for a handful of special-case checks.
181    Finally, the invisible bit is true for a decl which should be
182    ignored for purposes of normal name lookup, and the nested bit is
183    true for a decl that's been bound a second time in an inner scope;
184    in all such cases, the binding in the outer scope will have its
185    invisible bit true.  */
186 
187 struct GTY((chain_next ("%h.prev"))) c_binding {
188   union GTY(()) {		/* first so GTY desc can use decl */
189     tree GTY((tag ("0"))) type; /* the type in this scope */
190     struct c_label_vars * GTY((tag ("1"))) label; /* for warnings */
191   } GTY((desc ("TREE_CODE (%0.decl) == LABEL_DECL"))) u;
192   tree decl;			/* the decl bound */
193   tree id;			/* the identifier it's bound to */
194   struct c_binding *prev;	/* the previous decl in this scope */
195   struct c_binding *shadowed;	/* the innermost decl shadowed by this one */
196   unsigned int depth : 28;      /* depth of this scope */
197   BOOL_BITFIELD invisible : 1;  /* normal lookup should ignore this binding */
198   BOOL_BITFIELD nested : 1;     /* do not set DECL_CONTEXT when popping */
199   BOOL_BITFIELD inner_comp : 1; /* incomplete array completed in inner scope */
200   BOOL_BITFIELD in_struct : 1;	/* currently defined as struct field */
201   location_t locus;		/* location for nested bindings */
202 };
203 #define B_IN_SCOPE(b1, b2) ((b1)->depth == (b2)->depth)
204 #define B_IN_CURRENT_SCOPE(b) ((b)->depth == current_scope->depth)
205 #define B_IN_FILE_SCOPE(b) ((b)->depth == 1 /*file_scope->depth*/)
206 #define B_IN_EXTERNAL_SCOPE(b) ((b)->depth == 0 /*external_scope->depth*/)
207 
208 #define I_SYMBOL_BINDING(node) \
209   (((struct lang_identifier *) IDENTIFIER_NODE_CHECK(node))->symbol_binding)
210 #define I_SYMBOL_DECL(node) \
211  (I_SYMBOL_BINDING(node) ? I_SYMBOL_BINDING(node)->decl : 0)
212 
213 #define I_TAG_BINDING(node) \
214   (((struct lang_identifier *) IDENTIFIER_NODE_CHECK(node))->tag_binding)
215 #define I_TAG_DECL(node) \
216  (I_TAG_BINDING(node) ? I_TAG_BINDING(node)->decl : 0)
217 
218 #define I_LABEL_BINDING(node) \
219   (((struct lang_identifier *) IDENTIFIER_NODE_CHECK(node))->label_binding)
220 #define I_LABEL_DECL(node) \
221  (I_LABEL_BINDING(node) ? I_LABEL_BINDING(node)->decl : 0)
222 
223 /* Each C symbol points to three linked lists of c_binding structures.
224    These describe the values of the identifier in the three different
225    namespaces defined by the language.  */
226 
227 struct GTY(()) lang_identifier {
228   struct c_common_identifier common_id;
229   struct c_binding *symbol_binding; /* vars, funcs, constants, typedefs */
230   struct c_binding *tag_binding;    /* struct/union/enum tags */
231   struct c_binding *label_binding;  /* labels */
232 };
233 
234 /* Validate c-lang.c's assumptions.  */
235 extern char C_SIZEOF_STRUCT_LANG_IDENTIFIER_isnt_accurate
236 [(sizeof(struct lang_identifier) == C_SIZEOF_STRUCT_LANG_IDENTIFIER) ? 1 : -1];
237 
238 /* The resulting tree type.  */
239 
240 union GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
241        chain_next ("(union lang_tree_node *) c_tree_chain_next (&%h.generic)"))) lang_tree_node
242  {
243   union tree_node GTY ((tag ("0"),
244 			desc ("tree_node_structure (&%h)")))
245     generic;
246   struct lang_identifier GTY ((tag ("1"))) identifier;
247 };
248 
249 /* Track bindings and other things that matter for goto warnings.  For
250    efficiency, we do not gather all the decls at the point of
251    definition.  Instead, we point into the bindings structure.  As
252    scopes are popped, we update these structures and gather the decls
253    that matter at that time.  */
254 
255 struct GTY(()) c_spot_bindings {
256   /* The currently open scope which holds bindings defined when the
257      label was defined or the goto statement was found.  */
258   struct c_scope *scope;
259   /* The bindings in the scope field which were defined at the point
260      of the label or goto.  This lets us look at older or newer
261      bindings in the scope, as appropriate.  */
262   struct c_binding *bindings_in_scope;
263   /* The number of statement expressions that have started since this
264      label or goto statement was defined.  This is zero if we are at
265      the same statement expression level.  It is positive if we are in
266      a statement expression started since this spot.  It is negative
267      if this spot was in a statement expression and we have left
268      it.  */
269   int stmt_exprs;
270   /* Whether we started in a statement expression but are no longer in
271      it.  This is set to true if stmt_exprs ever goes negative.  */
272   bool left_stmt_expr;
273 };
274 
275 /* This structure is used to keep track of bindings seen when a goto
276    statement is defined.  This is only used if we see the goto
277    statement before we see the label.  */
278 
279 struct GTY(()) c_goto_bindings {
280   /* The location of the goto statement.  */
281   location_t loc;
282   /* The bindings of the goto statement.  */
283   struct c_spot_bindings goto_bindings;
284 };
285 
286 typedef struct c_goto_bindings *c_goto_bindings_p;
287 
288 /* The additional information we keep track of for a label binding.
289    These fields are updated as scopes are popped.  */
290 
291 struct GTY(()) c_label_vars {
292   /* The shadowed c_label_vars, when one label shadows another (which
293      can only happen using a __label__ declaration).  */
294   struct c_label_vars *shadowed;
295   /* The bindings when the label was defined.  */
296   struct c_spot_bindings label_bindings;
297   /* A list of decls that we care about: decls about which we should
298      warn if a goto branches to this label from later in the function.
299      Decls are added to this list as scopes are popped.  We only add
300      the decls that matter.  */
301   vec<tree, va_gc> *decls_in_scope;
302   /* A list of goto statements to this label.  This is only used for
303      goto statements seen before the label was defined, so that we can
304      issue appropriate warnings for them.  */
305   vec<c_goto_bindings_p, va_gc> *gotos;
306 };
307 
308 /* Each c_scope structure describes the complete contents of one
309    scope.  Four scopes are distinguished specially: the innermost or
310    current scope, the innermost function scope, the file scope (always
311    the second to outermost) and the outermost or external scope.
312 
313    Most declarations are recorded in the current scope.
314 
315    All normal label declarations are recorded in the innermost
316    function scope, as are bindings of undeclared identifiers to
317    error_mark_node.  (GCC permits nested functions as an extension,
318    hence the 'innermost' qualifier.)  Explicitly declared labels
319    (using the __label__ extension) appear in the current scope.
320 
321    Being in the file scope (current_scope == file_scope) causes
322    special behavior in several places below.  Also, under some
323    conditions the Objective-C front end records declarations in the
324    file scope even though that isn't the current scope.
325 
326    All declarations with external linkage are recorded in the external
327    scope, even if they aren't visible there; this models the fact that
328    such declarations are visible to the entire program, and (with a
329    bit of cleverness, see pushdecl) allows diagnosis of some violations
330    of C99 6.2.2p7 and 6.2.7p2:
331 
332      If, within the same translation unit, the same identifier appears
333      with both internal and external linkage, the behavior is
334      undefined.
335 
336      All declarations that refer to the same object or function shall
337      have compatible type; otherwise, the behavior is undefined.
338 
339    Initially only the built-in declarations, which describe compiler
340    intrinsic functions plus a subset of the standard library, are in
341    this scope.
342 
343    The order of the blocks list matters, and it is frequently appended
344    to.  To avoid having to walk all the way to the end of the list on
345    each insertion, or reverse the list later, we maintain a pointer to
346    the last list entry.  (FIXME: It should be feasible to use a reversed
347    list here.)
348 
349    The bindings list is strictly in reverse order of declarations;
350    pop_scope relies on this.  */
351 
352 
353 struct GTY((chain_next ("%h.outer"))) c_scope {
354   /* The scope containing this one.  */
355   struct c_scope *outer;
356 
357   /* The next outermost function scope.  */
358   struct c_scope *outer_function;
359 
360   /* All bindings in this scope.  */
361   struct c_binding *bindings;
362 
363   /* For each scope (except the global one), a chain of BLOCK nodes
364      for all the scopes that were entered and exited one level down.  */
365   tree blocks;
366   tree blocks_last;
367 
368   /* The depth of this scope.  Used to keep the ->shadowed chain of
369      bindings sorted innermost to outermost.  */
370   unsigned int depth : 28;
371 
372   /* True if we are currently filling this scope with parameter
373      declarations.  */
374   BOOL_BITFIELD parm_flag : 1;
375 
376   /* True if we saw [*] in this scope.  Used to give an error messages
377      if these appears in a function definition.  */
378   BOOL_BITFIELD had_vla_unspec : 1;
379 
380   /* True if we already complained about forward parameter decls
381      in this scope.  This prevents double warnings on
382      foo (int a; int b; ...)  */
383   BOOL_BITFIELD warned_forward_parm_decls : 1;
384 
385   /* True if this is the outermost block scope of a function body.
386      This scope contains the parameters, the local variables declared
387      in the outermost block, and all the labels (except those in
388      nested functions, or declared at block scope with __label__).  */
389   BOOL_BITFIELD function_body : 1;
390 
391   /* True means make a BLOCK for this scope no matter what.  */
392   BOOL_BITFIELD keep : 1;
393 
394   /* True means that an unsuffixed float constant is _Decimal64.  */
395   BOOL_BITFIELD float_const_decimal64 : 1;
396 
397   /* True if this scope has any label bindings.  This is used to speed
398      up searching for labels when popping scopes, particularly since
399      labels are normally only found at function scope.  */
400   BOOL_BITFIELD has_label_bindings : 1;
401 
402   /* True if we should issue a warning if a goto statement crosses any
403      of the bindings.  We still need to check the list of bindings to
404      find the specific ones we need to warn about.  This is true if
405      decl_jump_unsafe would return true for any of the bindings.  This
406      is used to avoid looping over all the bindings unnecessarily.  */
407   BOOL_BITFIELD has_jump_unsafe_decl : 1;
408 };
409 
410 /* The scope currently in effect.  */
411 
412 static GTY(()) struct c_scope *current_scope;
413 
414 /* The innermost function scope.  Ordinary (not explicitly declared)
415    labels, bindings to error_mark_node, and the lazily-created
416    bindings of __func__ and its friends get this scope.  */
417 
418 static GTY(()) struct c_scope *current_function_scope;
419 
420 /* The C file scope.  This is reset for each input translation unit.  */
421 
422 static GTY(()) struct c_scope *file_scope;
423 
424 /* The outermost scope.  This is used for all declarations with
425    external linkage, and only these, hence the name.  */
426 
427 static GTY(()) struct c_scope *external_scope;
428 
429 /* A chain of c_scope structures awaiting reuse.  */
430 
431 static GTY((deletable)) struct c_scope *scope_freelist;
432 
433 /* A chain of c_binding structures awaiting reuse.  */
434 
435 static GTY((deletable)) struct c_binding *binding_freelist;
436 
437 /* Append VAR to LIST in scope SCOPE.  */
438 #define SCOPE_LIST_APPEND(scope, list, decl) do {	\
439   struct c_scope *s_ = (scope);				\
440   tree d_ = (decl);					\
441   if (s_->list##_last)					\
442     BLOCK_CHAIN (s_->list##_last) = d_;			\
443   else							\
444     s_->list = d_;					\
445   s_->list##_last = d_;					\
446 } while (0)
447 
448 /* Concatenate FROM in scope FSCOPE onto TO in scope TSCOPE.  */
449 #define SCOPE_LIST_CONCAT(tscope, to, fscope, from) do {	\
450   struct c_scope *t_ = (tscope);				\
451   struct c_scope *f_ = (fscope);				\
452   if (t_->to##_last)						\
453     BLOCK_CHAIN (t_->to##_last) = f_->from;			\
454   else								\
455     t_->to = f_->from;						\
456   t_->to##_last = f_->from##_last;				\
457 } while (0)
458 
459 /* A c_inline_static structure stores details of a static identifier
460    referenced in a definition of a function that may be an inline
461    definition if no subsequent declaration of that function uses
462    "extern" or does not use "inline".  */
463 
464 struct GTY((chain_next ("%h.next"))) c_inline_static {
465   /* The location for a diagnostic.  */
466   location_t location;
467 
468   /* The function that may be an inline definition.  */
469   tree function;
470 
471   /* The object or function referenced.  */
472   tree static_decl;
473 
474   /* What sort of reference this is.  */
475   enum c_inline_static_type type;
476 
477   /* The next such structure or NULL.  */
478   struct c_inline_static *next;
479 };
480 
481 /* List of static identifiers used or referenced in functions that may
482    be inline definitions.  */
483 static GTY(()) struct c_inline_static *c_inline_statics;
484 
485 /* True means unconditionally make a BLOCK for the next scope pushed.  */
486 
487 static bool keep_next_level_flag;
488 
489 /* True means the next call to push_scope will be the outermost scope
490    of a function body, so do not push a new scope, merely cease
491    expecting parameter decls.  */
492 
493 static bool next_is_function_body;
494 
495 /* A vector of pointers to c_binding structures.  */
496 
497 typedef struct c_binding *c_binding_ptr;
498 
499 /* Information that we keep for a struct or union while it is being
500    parsed.  */
501 
502 struct c_struct_parse_info
503 {
504   /* If warn_cxx_compat, a list of types defined within this
505      struct.  */
506   vec<tree> struct_types;
507   /* If warn_cxx_compat, a list of field names which have bindings,
508      and which are defined in this struct, but which are not defined
509      in any enclosing struct.  This is used to clear the in_struct
510      field of the c_bindings structure.  */
511   vec<c_binding_ptr> fields;
512   /* If warn_cxx_compat, a list of typedef names used when defining
513      fields in this struct.  */
514   vec<tree> typedefs_seen;
515 };
516 
517 /* Information for the struct or union currently being parsed, or
518    NULL if not parsing a struct or union.  */
519 static struct c_struct_parse_info *struct_parse_info;
520 
521 /* Forward declarations.  */
522 static tree lookup_name_in_scope (tree, struct c_scope *);
523 static tree c_make_fname_decl (location_t, tree, int);
524 static tree grokdeclarator (const struct c_declarator *,
525 			    struct c_declspecs *,
526 			    enum decl_context, bool, tree *, tree *, tree *,
527 			    bool *, enum deprecated_states);
528 static tree grokparms (struct c_arg_info *, bool);
529 static void layout_array_type (tree);
530 
531 /* T is a statement.  Add it to the statement-tree.  This is the
532    C/ObjC version--C++ has a slightly different version of this
533    function.  */
534 
535 tree
536 add_stmt (tree t)
537 {
538   enum tree_code code = TREE_CODE (t);
539 
540   if (CAN_HAVE_LOCATION_P (t) && code != LABEL_EXPR)
541     {
542       if (!EXPR_HAS_LOCATION (t))
543 	SET_EXPR_LOCATION (t, input_location);
544     }
545 
546   if (code == LABEL_EXPR || code == CASE_LABEL_EXPR)
547     STATEMENT_LIST_HAS_LABEL (cur_stmt_list) = 1;
548 
549   /* Add T to the statement-tree.  Non-side-effect statements need to be
550      recorded during statement expressions.  */
551   if (!building_stmt_list_p ())
552     push_stmt_list ();
553   append_to_statement_list_force (t, &cur_stmt_list);
554 
555   return t;
556 }
557 
558 /* Build a pointer type using the default pointer mode.  */
559 
560 static tree
561 c_build_pointer_type (tree to_type)
562 {
563   addr_space_t as = to_type == error_mark_node? ADDR_SPACE_GENERIC
564 					      : TYPE_ADDR_SPACE (to_type);
565   enum machine_mode pointer_mode;
566 
567   if (as != ADDR_SPACE_GENERIC || c_default_pointer_mode == VOIDmode)
568     pointer_mode = targetm.addr_space.pointer_mode (as);
569   else
570     pointer_mode = c_default_pointer_mode;
571   return build_pointer_type_for_mode (to_type, pointer_mode, false);
572 }
573 
574 
575 /* Return true if we will want to say something if a goto statement
576    crosses DECL.  */
577 
578 static bool
579 decl_jump_unsafe (tree decl)
580 {
581   if (error_operand_p (decl))
582     return false;
583 
584   /* Always warn about crossing variably modified types.  */
585   if ((TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == TYPE_DECL)
586       && variably_modified_type_p (TREE_TYPE (decl), NULL_TREE))
587     return true;
588 
589   /* Otherwise, only warn if -Wgoto-misses-init and this is an
590      initialized automatic decl.  */
591   if (warn_jump_misses_init
592       && TREE_CODE (decl) == VAR_DECL
593       && !TREE_STATIC (decl)
594       && DECL_INITIAL (decl) != NULL_TREE)
595     return true;
596 
597   return false;
598 }
599 
600 
601 void
602 c_print_identifier (FILE *file, tree node, int indent)
603 {
604   print_node (file, "symbol", I_SYMBOL_DECL (node), indent + 4);
605   print_node (file, "tag", I_TAG_DECL (node), indent + 4);
606   print_node (file, "label", I_LABEL_DECL (node), indent + 4);
607   if (C_IS_RESERVED_WORD (node) && C_RID_CODE (node) != RID_CXX_COMPAT_WARN)
608     {
609       tree rid = ridpointers[C_RID_CODE (node)];
610       indent_to (file, indent + 4);
611       fprintf (file, "rid " HOST_PTR_PRINTF " \"%s\"",
612 	       (void *) rid, IDENTIFIER_POINTER (rid));
613     }
614 }
615 
616 /* Establish a binding between NAME, an IDENTIFIER_NODE, and DECL,
617    which may be any of several kinds of DECL or TYPE or error_mark_node,
618    in the scope SCOPE.  */
619 static void
620 bind (tree name, tree decl, struct c_scope *scope, bool invisible,
621       bool nested, location_t locus)
622 {
623   struct c_binding *b, **here;
624 
625   if (binding_freelist)
626     {
627       b = binding_freelist;
628       binding_freelist = b->prev;
629     }
630   else
631     b = ggc_alloc_c_binding ();
632 
633   b->shadowed = 0;
634   b->decl = decl;
635   b->id = name;
636   b->depth = scope->depth;
637   b->invisible = invisible;
638   b->nested = nested;
639   b->inner_comp = 0;
640   b->in_struct = 0;
641   b->locus = locus;
642 
643   b->u.type = NULL;
644 
645   b->prev = scope->bindings;
646   scope->bindings = b;
647 
648   if (decl_jump_unsafe (decl))
649     scope->has_jump_unsafe_decl = 1;
650 
651   if (!name)
652     return;
653 
654   switch (TREE_CODE (decl))
655     {
656     case LABEL_DECL:     here = &I_LABEL_BINDING (name);   break;
657     case ENUMERAL_TYPE:
658     case UNION_TYPE:
659     case RECORD_TYPE:    here = &I_TAG_BINDING (name);     break;
660     case VAR_DECL:
661     case FUNCTION_DECL:
662     case TYPE_DECL:
663     case CONST_DECL:
664     case PARM_DECL:
665     case ERROR_MARK:     here = &I_SYMBOL_BINDING (name);  break;
666 
667     default:
668       gcc_unreachable ();
669     }
670 
671   /* Locate the appropriate place in the chain of shadowed decls
672      to insert this binding.  Normally, scope == current_scope and
673      this does nothing.  */
674   while (*here && (*here)->depth > scope->depth)
675     here = &(*here)->shadowed;
676 
677   b->shadowed = *here;
678   *here = b;
679 }
680 
681 /* Clear the binding structure B, stick it on the binding_freelist,
682    and return the former value of b->prev.  This is used by pop_scope
683    and get_parm_info to iterate destructively over all the bindings
684    from a given scope.  */
685 static struct c_binding *
686 free_binding_and_advance (struct c_binding *b)
687 {
688   struct c_binding *prev = b->prev;
689 
690   memset (b, 0, sizeof (struct c_binding));
691   b->prev = binding_freelist;
692   binding_freelist = b;
693 
694   return prev;
695 }
696 
697 /* Bind a label.  Like bind, but skip fields which aren't used for
698    labels, and add the LABEL_VARS value.  */
699 static void
700 bind_label (tree name, tree label, struct c_scope *scope,
701 	    struct c_label_vars *label_vars)
702 {
703   struct c_binding *b;
704 
705   bind (name, label, scope, /*invisible=*/false, /*nested=*/false,
706 	UNKNOWN_LOCATION);
707 
708   scope->has_label_bindings = true;
709 
710   b = scope->bindings;
711   gcc_assert (b->decl == label);
712   label_vars->shadowed = b->u.label;
713   b->u.label = label_vars;
714 }
715 
716 /* Hook called at end of compilation to assume 1 elt
717    for a file-scope tentative array defn that wasn't complete before.  */
718 
719 void
720 c_finish_incomplete_decl (tree decl)
721 {
722   if (TREE_CODE (decl) == VAR_DECL)
723     {
724       tree type = TREE_TYPE (decl);
725       if (type != error_mark_node
726 	  && TREE_CODE (type) == ARRAY_TYPE
727 	  && !DECL_EXTERNAL (decl)
728 	  && TYPE_DOMAIN (type) == 0)
729 	{
730 	  warning_at (DECL_SOURCE_LOCATION (decl),
731 		      0, "array %q+D assumed to have one element", decl);
732 
733 	  complete_array_type (&TREE_TYPE (decl), NULL_TREE, true);
734 
735 	  relayout_decl (decl);
736 	}
737     }
738 }
739 
740 /* Record that inline function FUNC contains a reference (location
741    LOC) to static DECL (file-scope or function-local according to
742    TYPE).  */
743 
744 void
745 record_inline_static (location_t loc, tree func, tree decl,
746 		      enum c_inline_static_type type)
747 {
748   struct c_inline_static *csi = ggc_alloc_c_inline_static ();
749   csi->location = loc;
750   csi->function = func;
751   csi->static_decl = decl;
752   csi->type = type;
753   csi->next = c_inline_statics;
754   c_inline_statics = csi;
755 }
756 
757 /* Check for references to static declarations in inline functions at
758    the end of the translation unit and diagnose them if the functions
759    are still inline definitions.  */
760 
761 static void
762 check_inline_statics (void)
763 {
764   struct c_inline_static *csi;
765   for (csi = c_inline_statics; csi; csi = csi->next)
766     {
767       if (DECL_EXTERNAL (csi->function))
768 	switch (csi->type)
769 	  {
770 	  case csi_internal:
771 	    pedwarn (csi->location, 0,
772 		     "%qD is static but used in inline function %qD "
773 		     "which is not static", csi->static_decl, csi->function);
774 	    break;
775 	  case csi_modifiable:
776 	    pedwarn (csi->location, 0,
777 		     "%q+D is static but declared in inline function %qD "
778 		     "which is not static", csi->static_decl, csi->function);
779 	    break;
780 	  default:
781 	    gcc_unreachable ();
782 	  }
783     }
784   c_inline_statics = NULL;
785 }
786 
787 /* Fill in a c_spot_bindings structure.  If DEFINING is true, set it
788    for the current state, otherwise set it to uninitialized.  */
789 
790 static void
791 set_spot_bindings (struct c_spot_bindings *p, bool defining)
792 {
793   if (defining)
794     {
795       p->scope = current_scope;
796       p->bindings_in_scope = current_scope->bindings;
797     }
798   else
799     {
800       p->scope = NULL;
801       p->bindings_in_scope = NULL;
802     }
803   p->stmt_exprs = 0;
804   p->left_stmt_expr = false;
805 }
806 
807 /* Update spot bindings P as we pop out of SCOPE.  Return true if we
808    should push decls for a label.  */
809 
810 static bool
811 update_spot_bindings (struct c_scope *scope, struct c_spot_bindings *p)
812 {
813   if (p->scope != scope)
814     {
815       /* This label or goto is defined in some other scope, or it is a
816 	 label which is not yet defined.  There is nothing to
817 	 update.  */
818       return false;
819     }
820 
821   /* Adjust the spot bindings to refer to the bindings already defined
822      in the enclosing scope.  */
823   p->scope = scope->outer;
824   p->bindings_in_scope = p->scope->bindings;
825 
826   return true;
827 }
828 
829 /* The Objective-C front-end often needs to determine the current scope.  */
830 
831 void *
832 objc_get_current_scope (void)
833 {
834   return current_scope;
835 }
836 
837 /* The following function is used only by Objective-C.  It needs to live here
838    because it accesses the innards of c_scope.  */
839 
840 void
841 objc_mark_locals_volatile (void *enclosing_blk)
842 {
843   struct c_scope *scope;
844   struct c_binding *b;
845 
846   for (scope = current_scope;
847        scope && scope != enclosing_blk;
848        scope = scope->outer)
849     {
850       for (b = scope->bindings; b; b = b->prev)
851 	objc_volatilize_decl (b->decl);
852 
853       /* Do not climb up past the current function.  */
854       if (scope->function_body)
855 	break;
856     }
857 }
858 
859 /* Return true if we are in the global binding level.  */
860 
861 bool
862 global_bindings_p (void)
863 {
864   return current_scope == file_scope;
865 }
866 
867 void
868 keep_next_level (void)
869 {
870   keep_next_level_flag = true;
871 }
872 
873 /* Set the flag for the FLOAT_CONST_DECIMAL64 pragma being ON.  */
874 
875 void
876 set_float_const_decimal64 (void)
877 {
878   current_scope->float_const_decimal64 = true;
879 }
880 
881 /* Clear the flag for the FLOAT_CONST_DECIMAL64 pragma.  */
882 
883 void
884 clear_float_const_decimal64 (void)
885 {
886   current_scope->float_const_decimal64 = false;
887 }
888 
889 /* Return nonzero if an unsuffixed float constant is _Decimal64.  */
890 
891 bool
892 float_const_decimal64_p (void)
893 {
894   return current_scope->float_const_decimal64;
895 }
896 
897 /* Identify this scope as currently being filled with parameters.  */
898 
899 void
900 declare_parm_level (void)
901 {
902   current_scope->parm_flag = true;
903 }
904 
905 void
906 push_scope (void)
907 {
908   if (next_is_function_body)
909     {
910       /* This is the transition from the parameters to the top level
911 	 of the function body.  These are the same scope
912 	 (C99 6.2.1p4,6) so we do not push another scope structure.
913 	 next_is_function_body is set only by store_parm_decls, which
914 	 in turn is called when and only when we are about to
915 	 encounter the opening curly brace for the function body.
916 
917 	 The outermost block of a function always gets a BLOCK node,
918 	 because the debugging output routines expect that each
919 	 function has at least one BLOCK.  */
920       current_scope->parm_flag         = false;
921       current_scope->function_body     = true;
922       current_scope->keep              = true;
923       current_scope->outer_function    = current_function_scope;
924       current_function_scope           = current_scope;
925 
926       keep_next_level_flag = false;
927       next_is_function_body = false;
928 
929       /* The FLOAT_CONST_DECIMAL64 pragma applies to nested scopes.  */
930       if (current_scope->outer)
931 	current_scope->float_const_decimal64
932 	  = current_scope->outer->float_const_decimal64;
933       else
934 	current_scope->float_const_decimal64 = false;
935     }
936   else
937     {
938       struct c_scope *scope;
939       if (scope_freelist)
940 	{
941 	  scope = scope_freelist;
942 	  scope_freelist = scope->outer;
943 	}
944       else
945 	scope = ggc_alloc_cleared_c_scope ();
946 
947       /* The FLOAT_CONST_DECIMAL64 pragma applies to nested scopes.  */
948       if (current_scope)
949 	scope->float_const_decimal64 = current_scope->float_const_decimal64;
950       else
951 	scope->float_const_decimal64 = false;
952 
953       scope->keep          = keep_next_level_flag;
954       scope->outer         = current_scope;
955       scope->depth	   = current_scope ? (current_scope->depth + 1) : 0;
956 
957       /* Check for scope depth overflow.  Unlikely (2^28 == 268,435,456) but
958 	 possible.  */
959       if (current_scope && scope->depth == 0)
960 	{
961 	  scope->depth--;
962 	  sorry ("GCC supports only %u nested scopes", scope->depth);
963 	}
964 
965       current_scope        = scope;
966       keep_next_level_flag = false;
967     }
968 }
969 
970 /* This is called when we are leaving SCOPE.  For each label defined
971    in SCOPE, add any appropriate decls to its decls_in_scope fields.
972    These are the decls whose initialization will be skipped by a goto
973    later in the function.  */
974 
975 static void
976 update_label_decls (struct c_scope *scope)
977 {
978   struct c_scope *s;
979 
980   s = scope;
981   while (s != NULL)
982     {
983       if (s->has_label_bindings)
984 	{
985 	  struct c_binding *b;
986 
987 	  for (b = s->bindings; b != NULL; b = b->prev)
988 	    {
989 	      struct c_label_vars *label_vars;
990 	      struct c_binding *b1;
991 	      bool hjud;
992 	      unsigned int ix;
993 	      struct c_goto_bindings *g;
994 
995 	      if (TREE_CODE (b->decl) != LABEL_DECL)
996 		continue;
997 	      label_vars = b->u.label;
998 
999 	      b1 = label_vars->label_bindings.bindings_in_scope;
1000 	      if (label_vars->label_bindings.scope == NULL)
1001 		hjud = false;
1002 	      else
1003 		hjud = label_vars->label_bindings.scope->has_jump_unsafe_decl;
1004 	      if (update_spot_bindings (scope, &label_vars->label_bindings))
1005 		{
1006 		  /* This label is defined in this scope.  */
1007 		  if (hjud)
1008 		    {
1009 		      for (; b1 != NULL; b1 = b1->prev)
1010 			{
1011 			  /* A goto from later in the function to this
1012 			     label will never see the initialization
1013 			     of B1, if any.  Save it to issue a
1014 			     warning if needed.  */
1015 			  if (decl_jump_unsafe (b1->decl))
1016 			    vec_safe_push(label_vars->decls_in_scope, b1->decl);
1017 			}
1018 		    }
1019 		}
1020 
1021 	      /* Update the bindings of any goto statements associated
1022 		 with this label.  */
1023 	      FOR_EACH_VEC_SAFE_ELT (label_vars->gotos, ix, g)
1024 		update_spot_bindings (scope, &g->goto_bindings);
1025 	    }
1026 	}
1027 
1028       /* Don't search beyond the current function.  */
1029       if (s == current_function_scope)
1030 	break;
1031 
1032       s = s->outer;
1033     }
1034 }
1035 
1036 /* Set the TYPE_CONTEXT of all of TYPE's variants to CONTEXT.  */
1037 
1038 static void
1039 set_type_context (tree type, tree context)
1040 {
1041   for (type = TYPE_MAIN_VARIANT (type); type;
1042        type = TYPE_NEXT_VARIANT (type))
1043     TYPE_CONTEXT (type) = context;
1044 }
1045 
1046 /* Exit a scope.  Restore the state of the identifier-decl mappings
1047    that were in effect when this scope was entered.  Return a BLOCK
1048    node containing all the DECLs in this scope that are of interest
1049    to debug info generation.  */
1050 
1051 tree
1052 pop_scope (void)
1053 {
1054   struct c_scope *scope = current_scope;
1055   tree block, context, p;
1056   struct c_binding *b;
1057 
1058   bool functionbody = scope->function_body;
1059   bool keep = functionbody || scope->keep || scope->bindings;
1060 
1061   update_label_decls (scope);
1062 
1063   /* If appropriate, create a BLOCK to record the decls for the life
1064      of this function.  */
1065   block = 0;
1066   if (keep)
1067     {
1068       block = make_node (BLOCK);
1069       BLOCK_SUBBLOCKS (block) = scope->blocks;
1070       TREE_USED (block) = 1;
1071 
1072       /* In each subblock, record that this is its superior.  */
1073       for (p = scope->blocks; p; p = BLOCK_CHAIN (p))
1074 	BLOCK_SUPERCONTEXT (p) = block;
1075 
1076       BLOCK_VARS (block) = 0;
1077     }
1078 
1079   /* The TYPE_CONTEXTs for all of the tagged types belonging to this
1080      scope must be set so that they point to the appropriate
1081      construct, i.e.  either to the current FUNCTION_DECL node, or
1082      else to the BLOCK node we just constructed.
1083 
1084      Note that for tagged types whose scope is just the formal
1085      parameter list for some function type specification, we can't
1086      properly set their TYPE_CONTEXTs here, because we don't have a
1087      pointer to the appropriate FUNCTION_TYPE node readily available
1088      to us.  For those cases, the TYPE_CONTEXTs of the relevant tagged
1089      type nodes get set in `grokdeclarator' as soon as we have created
1090      the FUNCTION_TYPE node which will represent the "scope" for these
1091      "parameter list local" tagged types.  */
1092   if (scope->function_body)
1093     context = current_function_decl;
1094   else if (scope == file_scope)
1095     {
1096       tree file_decl = build_translation_unit_decl (NULL_TREE);
1097       context = file_decl;
1098     }
1099   else
1100     context = block;
1101 
1102   /* Clear all bindings in this scope.  */
1103   for (b = scope->bindings; b; b = free_binding_and_advance (b))
1104     {
1105       p = b->decl;
1106       switch (TREE_CODE (p))
1107 	{
1108 	case LABEL_DECL:
1109 	  /* Warnings for unused labels, errors for undefined labels.  */
1110 	  if (TREE_USED (p) && !DECL_INITIAL (p))
1111 	    {
1112 	      error ("label %q+D used but not defined", p);
1113 	      DECL_INITIAL (p) = error_mark_node;
1114 	    }
1115 	  else
1116 	    warn_for_unused_label (p);
1117 
1118 	  /* Labels go in BLOCK_VARS.  */
1119 	  DECL_CHAIN (p) = BLOCK_VARS (block);
1120 	  BLOCK_VARS (block) = p;
1121 	  gcc_assert (I_LABEL_BINDING (b->id) == b);
1122 	  I_LABEL_BINDING (b->id) = b->shadowed;
1123 
1124 	  /* Also pop back to the shadowed label_vars.  */
1125 	  release_tree_vector (b->u.label->decls_in_scope);
1126 	  b->u.label = b->u.label->shadowed;
1127 	  break;
1128 
1129 	case ENUMERAL_TYPE:
1130 	case UNION_TYPE:
1131 	case RECORD_TYPE:
1132 	  set_type_context (p, context);
1133 
1134 	  /* Types may not have tag-names, in which case the type
1135 	     appears in the bindings list with b->id NULL.  */
1136 	  if (b->id)
1137 	    {
1138 	      gcc_assert (I_TAG_BINDING (b->id) == b);
1139 	      I_TAG_BINDING (b->id) = b->shadowed;
1140 	    }
1141 	  break;
1142 
1143 	case FUNCTION_DECL:
1144 	  /* Propagate TREE_ADDRESSABLE from nested functions to their
1145 	     containing functions.  */
1146 	  if (!TREE_ASM_WRITTEN (p)
1147 	      && DECL_INITIAL (p) != 0
1148 	      && TREE_ADDRESSABLE (p)
1149 	      && DECL_ABSTRACT_ORIGIN (p) != 0
1150 	      && DECL_ABSTRACT_ORIGIN (p) != p)
1151 	    TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (p)) = 1;
1152 	  if (!DECL_EXTERNAL (p)
1153 	      && !DECL_INITIAL (p)
1154 	      && scope != file_scope
1155 	      && scope != external_scope)
1156 	    {
1157 	      error ("nested function %q+D declared but never defined", p);
1158 	      undef_nested_function = true;
1159 	    }
1160 	  else if (DECL_DECLARED_INLINE_P (p)
1161 		   && TREE_PUBLIC (p)
1162 		   && !DECL_INITIAL (p))
1163 	    {
1164 	      /* C99 6.7.4p6: "a function with external linkage... declared
1165 		 with an inline function specifier ... shall also be defined
1166 		 in the same translation unit."  */
1167 	      if (!flag_gnu89_inline)
1168 		pedwarn (input_location, 0,
1169 			 "inline function %q+D declared but never defined", p);
1170 	      DECL_EXTERNAL (p) = 1;
1171 	    }
1172 
1173 	  goto common_symbol;
1174 
1175 	case VAR_DECL:
1176 	  /* Warnings for unused variables.  */
1177 	  if ((!TREE_USED (p) || !DECL_READ_P (p))
1178 	      && !TREE_NO_WARNING (p)
1179 	      && !DECL_IN_SYSTEM_HEADER (p)
1180 	      && DECL_NAME (p)
1181 	      && !DECL_ARTIFICIAL (p)
1182 	      && scope != file_scope
1183 	      && scope != external_scope)
1184 	    {
1185 	      if (!TREE_USED (p))
1186 		warning (OPT_Wunused_variable, "unused variable %q+D", p);
1187 	      else if (DECL_CONTEXT (p) == current_function_decl)
1188 		warning_at (DECL_SOURCE_LOCATION (p),
1189 			    OPT_Wunused_but_set_variable,
1190 			    "variable %qD set but not used", p);
1191 	    }
1192 
1193 	  if (b->inner_comp)
1194 	    {
1195 	      error ("type of array %q+D completed incompatibly with"
1196 		     " implicit initialization", p);
1197 	    }
1198 
1199 	  /* Fall through.  */
1200 	case TYPE_DECL:
1201 	case CONST_DECL:
1202 	common_symbol:
1203 	  /* All of these go in BLOCK_VARS, but only if this is the
1204 	     binding in the home scope.  */
1205 	  if (!b->nested)
1206 	    {
1207 	      DECL_CHAIN (p) = BLOCK_VARS (block);
1208 	      BLOCK_VARS (block) = p;
1209 	    }
1210 	  else if (VAR_OR_FUNCTION_DECL_P (p) && scope != file_scope)
1211 	    {
1212 	      /* For block local externs add a special
1213 		 DECL_EXTERNAL decl for debug info generation.  */
1214 	      tree extp = copy_node (p);
1215 
1216 	      DECL_EXTERNAL (extp) = 1;
1217 	      TREE_STATIC (extp) = 0;
1218 	      TREE_PUBLIC (extp) = 1;
1219 	      DECL_INITIAL (extp) = NULL_TREE;
1220 	      DECL_LANG_SPECIFIC (extp) = NULL;
1221 	      DECL_CONTEXT (extp) = current_function_decl;
1222 	      if (TREE_CODE (p) == FUNCTION_DECL)
1223 		{
1224 		  DECL_RESULT (extp) = NULL_TREE;
1225 		  DECL_SAVED_TREE (extp) = NULL_TREE;
1226 		  DECL_STRUCT_FUNCTION (extp) = NULL;
1227 		}
1228 	      if (b->locus != UNKNOWN_LOCATION)
1229 		DECL_SOURCE_LOCATION (extp) = b->locus;
1230 	      DECL_CHAIN (extp) = BLOCK_VARS (block);
1231 	      BLOCK_VARS (block) = extp;
1232 	    }
1233 	  /* If this is the file scope set DECL_CONTEXT of each decl to
1234 	     the TRANSLATION_UNIT_DECL.  This makes same_translation_unit_p
1235 	     work.  */
1236 	  if (scope == file_scope)
1237 	    {
1238 	      DECL_CONTEXT (p) = context;
1239 	      if (TREE_CODE (p) == TYPE_DECL
1240 		  && TREE_TYPE (p) != error_mark_node)
1241 		set_type_context (TREE_TYPE (p), context);
1242 	    }
1243 
1244 	  /* Fall through.  */
1245 	  /* Parameters go in DECL_ARGUMENTS, not BLOCK_VARS, and have
1246 	     already been put there by store_parm_decls.  Unused-
1247 	     parameter warnings are handled by function.c.
1248 	     error_mark_node obviously does not go in BLOCK_VARS and
1249 	     does not get unused-variable warnings.  */
1250 	case PARM_DECL:
1251 	case ERROR_MARK:
1252 	  /* It is possible for a decl not to have a name.  We get
1253 	     here with b->id NULL in this case.  */
1254 	  if (b->id)
1255 	    {
1256 	      gcc_assert (I_SYMBOL_BINDING (b->id) == b);
1257 	      I_SYMBOL_BINDING (b->id) = b->shadowed;
1258 	      if (b->shadowed && b->shadowed->u.type)
1259 		TREE_TYPE (b->shadowed->decl) = b->shadowed->u.type;
1260 	    }
1261 	  break;
1262 
1263 	default:
1264 	  gcc_unreachable ();
1265 	}
1266     }
1267 
1268 
1269   /* Dispose of the block that we just made inside some higher level.  */
1270   if ((scope->function_body || scope == file_scope) && context)
1271     {
1272       DECL_INITIAL (context) = block;
1273       BLOCK_SUPERCONTEXT (block) = context;
1274     }
1275   else if (scope->outer)
1276     {
1277       if (block)
1278 	SCOPE_LIST_APPEND (scope->outer, blocks, block);
1279       /* If we did not make a block for the scope just exited, any
1280 	 blocks made for inner scopes must be carried forward so they
1281 	 will later become subblocks of something else.  */
1282       else if (scope->blocks)
1283 	SCOPE_LIST_CONCAT (scope->outer, blocks, scope, blocks);
1284     }
1285 
1286   /* Pop the current scope, and free the structure for reuse.  */
1287   current_scope = scope->outer;
1288   if (scope->function_body)
1289     current_function_scope = scope->outer_function;
1290 
1291   memset (scope, 0, sizeof (struct c_scope));
1292   scope->outer = scope_freelist;
1293   scope_freelist = scope;
1294 
1295   return block;
1296 }
1297 
1298 void
1299 push_file_scope (void)
1300 {
1301   tree decl;
1302 
1303   if (file_scope)
1304     return;
1305 
1306   push_scope ();
1307   file_scope = current_scope;
1308 
1309   start_fname_decls ();
1310 
1311   for (decl = visible_builtins; decl; decl = DECL_CHAIN (decl))
1312     bind (DECL_NAME (decl), decl, file_scope,
1313 	  /*invisible=*/false, /*nested=*/true, DECL_SOURCE_LOCATION (decl));
1314 }
1315 
1316 void
1317 pop_file_scope (void)
1318 {
1319   /* In case there were missing closebraces, get us back to the global
1320      binding level.  */
1321   while (current_scope != file_scope)
1322     pop_scope ();
1323 
1324   /* __FUNCTION__ is defined at file scope ("").  This
1325      call may not be necessary as my tests indicate it
1326      still works without it.  */
1327   finish_fname_decls ();
1328 
1329   check_inline_statics ();
1330 
1331   /* This is the point to write out a PCH if we're doing that.
1332      In that case we do not want to do anything else.  */
1333   if (pch_file)
1334     {
1335       c_common_write_pch ();
1336       return;
1337     }
1338 
1339   /* Pop off the file scope and close this translation unit.  */
1340   pop_scope ();
1341   file_scope = 0;
1342 
1343   maybe_apply_pending_pragma_weaks ();
1344 }
1345 
1346 /* Adjust the bindings for the start of a statement expression.  */
1347 
1348 void
1349 c_bindings_start_stmt_expr (struct c_spot_bindings* switch_bindings)
1350 {
1351   struct c_scope *scope;
1352 
1353   for (scope = current_scope; scope != NULL; scope = scope->outer)
1354     {
1355       struct c_binding *b;
1356 
1357       if (!scope->has_label_bindings)
1358 	continue;
1359 
1360       for (b = scope->bindings; b != NULL; b = b->prev)
1361 	{
1362 	  struct c_label_vars *label_vars;
1363 	  unsigned int ix;
1364 	  struct c_goto_bindings *g;
1365 
1366 	  if (TREE_CODE (b->decl) != LABEL_DECL)
1367 	    continue;
1368 	  label_vars = b->u.label;
1369 	  ++label_vars->label_bindings.stmt_exprs;
1370 	  FOR_EACH_VEC_SAFE_ELT (label_vars->gotos, ix, g)
1371 	    ++g->goto_bindings.stmt_exprs;
1372 	}
1373     }
1374 
1375   if (switch_bindings != NULL)
1376     ++switch_bindings->stmt_exprs;
1377 }
1378 
1379 /* Adjust the bindings for the end of a statement expression.  */
1380 
1381 void
1382 c_bindings_end_stmt_expr (struct c_spot_bindings *switch_bindings)
1383 {
1384   struct c_scope *scope;
1385 
1386   for (scope = current_scope; scope != NULL; scope = scope->outer)
1387     {
1388       struct c_binding *b;
1389 
1390       if (!scope->has_label_bindings)
1391 	continue;
1392 
1393       for (b = scope->bindings; b != NULL; b = b->prev)
1394 	{
1395 	  struct c_label_vars *label_vars;
1396 	  unsigned int ix;
1397 	  struct c_goto_bindings *g;
1398 
1399 	  if (TREE_CODE (b->decl) != LABEL_DECL)
1400 	    continue;
1401 	  label_vars = b->u.label;
1402 	  --label_vars->label_bindings.stmt_exprs;
1403 	  if (label_vars->label_bindings.stmt_exprs < 0)
1404 	    {
1405 	      label_vars->label_bindings.left_stmt_expr = true;
1406 	      label_vars->label_bindings.stmt_exprs = 0;
1407 	    }
1408 	  FOR_EACH_VEC_SAFE_ELT (label_vars->gotos, ix, g)
1409 	    {
1410 	      --g->goto_bindings.stmt_exprs;
1411 	      if (g->goto_bindings.stmt_exprs < 0)
1412 		{
1413 		  g->goto_bindings.left_stmt_expr = true;
1414 		  g->goto_bindings.stmt_exprs = 0;
1415 		}
1416 	    }
1417 	}
1418     }
1419 
1420   if (switch_bindings != NULL)
1421     {
1422       --switch_bindings->stmt_exprs;
1423       gcc_assert (switch_bindings->stmt_exprs >= 0);
1424     }
1425 }
1426 
1427 /* Push a definition or a declaration of struct, union or enum tag "name".
1428    "type" should be the type node.
1429    We assume that the tag "name" is not already defined, and has a location
1430    of LOC.
1431 
1432    Note that the definition may really be just a forward reference.
1433    In that case, the TYPE_SIZE will be zero.  */
1434 
1435 static void
1436 pushtag (location_t loc, tree name, tree type)
1437 {
1438   /* Record the identifier as the type's name if it has none.  */
1439   if (name && !TYPE_NAME (type))
1440     TYPE_NAME (type) = name;
1441   bind (name, type, current_scope, /*invisible=*/false, /*nested=*/false, loc);
1442 
1443   /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE will be the
1444      tagged type we just added to the current scope.  This fake
1445      NULL-named TYPE_DECL node helps dwarfout.c to know when it needs
1446      to output a representation of a tagged type, and it also gives
1447      us a convenient place to record the "scope start" address for the
1448      tagged type.  */
1449 
1450   TYPE_STUB_DECL (type) = pushdecl (build_decl (loc,
1451 						TYPE_DECL, NULL_TREE, type));
1452 
1453   /* An approximation for now, so we can tell this is a function-scope tag.
1454      This will be updated in pop_scope.  */
1455   TYPE_CONTEXT (type) = DECL_CONTEXT (TYPE_STUB_DECL (type));
1456 
1457   if (warn_cxx_compat && name != NULL_TREE)
1458     {
1459       struct c_binding *b = I_SYMBOL_BINDING (name);
1460 
1461       if (b != NULL
1462 	  && b->decl != NULL_TREE
1463 	  && TREE_CODE (b->decl) == TYPE_DECL
1464 	  && (B_IN_CURRENT_SCOPE (b)
1465 	      || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b)))
1466 	  && (TYPE_MAIN_VARIANT (TREE_TYPE (b->decl))
1467 	      != TYPE_MAIN_VARIANT (type)))
1468 	{
1469 	  warning_at (loc, OPT_Wc___compat,
1470 		      ("using %qD as both a typedef and a tag is "
1471 		       "invalid in C++"),
1472 		      b->decl);
1473 	  if (b->locus != UNKNOWN_LOCATION)
1474 	    inform (b->locus, "originally defined here");
1475 	}
1476     }
1477 }
1478 
1479 /* Subroutine of compare_decls.  Allow harmless mismatches in return
1480    and argument types provided that the type modes match.  This function
1481    return a unified type given a suitable match, and 0 otherwise.  */
1482 
1483 static tree
1484 match_builtin_function_types (tree newtype, tree oldtype)
1485 {
1486   tree newrettype, oldrettype;
1487   tree newargs, oldargs;
1488   tree trytype, tryargs;
1489 
1490   /* Accept the return type of the new declaration if same modes.  */
1491   oldrettype = TREE_TYPE (oldtype);
1492   newrettype = TREE_TYPE (newtype);
1493 
1494   if (TYPE_MODE (oldrettype) != TYPE_MODE (newrettype))
1495     return 0;
1496 
1497   oldargs = TYPE_ARG_TYPES (oldtype);
1498   newargs = TYPE_ARG_TYPES (newtype);
1499   tryargs = newargs;
1500 
1501   while (oldargs || newargs)
1502     {
1503       if (!oldargs
1504 	  || !newargs
1505 	  || !TREE_VALUE (oldargs)
1506 	  || !TREE_VALUE (newargs)
1507 	  || TYPE_MODE (TREE_VALUE (oldargs))
1508 	     != TYPE_MODE (TREE_VALUE (newargs)))
1509 	return 0;
1510 
1511       oldargs = TREE_CHAIN (oldargs);
1512       newargs = TREE_CHAIN (newargs);
1513     }
1514 
1515   trytype = build_function_type (newrettype, tryargs);
1516   return build_type_attribute_variant (trytype, TYPE_ATTRIBUTES (oldtype));
1517 }
1518 
1519 /* Subroutine of diagnose_mismatched_decls.  Check for function type
1520    mismatch involving an empty arglist vs a nonempty one and give clearer
1521    diagnostics.  */
1522 static void
1523 diagnose_arglist_conflict (tree newdecl, tree olddecl,
1524 			   tree newtype, tree oldtype)
1525 {
1526   tree t;
1527 
1528   if (TREE_CODE (olddecl) != FUNCTION_DECL
1529       || !comptypes (TREE_TYPE (oldtype), TREE_TYPE (newtype))
1530       || !((!prototype_p (oldtype) && DECL_INITIAL (olddecl) == 0)
1531 	   || (!prototype_p (newtype) && DECL_INITIAL (newdecl) == 0)))
1532     return;
1533 
1534   t = TYPE_ARG_TYPES (oldtype);
1535   if (t == 0)
1536     t = TYPE_ARG_TYPES (newtype);
1537   for (; t; t = TREE_CHAIN (t))
1538     {
1539       tree type = TREE_VALUE (t);
1540 
1541       if (TREE_CHAIN (t) == 0
1542 	  && TYPE_MAIN_VARIANT (type) != void_type_node)
1543 	{
1544 	  inform (input_location, "a parameter list with an ellipsis can%'t match "
1545 		  "an empty parameter name list declaration");
1546 	  break;
1547 	}
1548 
1549       if (c_type_promotes_to (type) != type)
1550 	{
1551 	  inform (input_location, "an argument type that has a default promotion can%'t match "
1552 		  "an empty parameter name list declaration");
1553 	  break;
1554 	}
1555     }
1556 }
1557 
1558 /* Another subroutine of diagnose_mismatched_decls.  OLDDECL is an
1559    old-style function definition, NEWDECL is a prototype declaration.
1560    Diagnose inconsistencies in the argument list.  Returns TRUE if
1561    the prototype is compatible, FALSE if not.  */
1562 static bool
1563 validate_proto_after_old_defn (tree newdecl, tree newtype, tree oldtype)
1564 {
1565   tree newargs, oldargs;
1566   int i;
1567 
1568 #define END_OF_ARGLIST(t) ((t) == void_type_node)
1569 
1570   oldargs = TYPE_ACTUAL_ARG_TYPES (oldtype);
1571   newargs = TYPE_ARG_TYPES (newtype);
1572   i = 1;
1573 
1574   for (;;)
1575     {
1576       tree oldargtype = TREE_VALUE (oldargs);
1577       tree newargtype = TREE_VALUE (newargs);
1578 
1579       if (oldargtype == error_mark_node || newargtype == error_mark_node)
1580 	return false;
1581 
1582       oldargtype = TYPE_MAIN_VARIANT (oldargtype);
1583       newargtype = TYPE_MAIN_VARIANT (newargtype);
1584 
1585       if (END_OF_ARGLIST (oldargtype) && END_OF_ARGLIST (newargtype))
1586 	break;
1587 
1588       /* Reaching the end of just one list means the two decls don't
1589 	 agree on the number of arguments.  */
1590       if (END_OF_ARGLIST (oldargtype))
1591 	{
1592 	  error ("prototype for %q+D declares more arguments "
1593 		 "than previous old-style definition", newdecl);
1594 	  return false;
1595 	}
1596       else if (END_OF_ARGLIST (newargtype))
1597 	{
1598 	  error ("prototype for %q+D declares fewer arguments "
1599 		 "than previous old-style definition", newdecl);
1600 	  return false;
1601 	}
1602 
1603       /* Type for passing arg must be consistent with that declared
1604 	 for the arg.  */
1605       else if (!comptypes (oldargtype, newargtype))
1606 	{
1607 	  error ("prototype for %q+D declares argument %d"
1608 		 " with incompatible type",
1609 		 newdecl, i);
1610 	  return false;
1611 	}
1612 
1613       oldargs = TREE_CHAIN (oldargs);
1614       newargs = TREE_CHAIN (newargs);
1615       i++;
1616     }
1617 
1618   /* If we get here, no errors were found, but do issue a warning
1619      for this poor-style construct.  */
1620   warning (0, "prototype for %q+D follows non-prototype definition",
1621 	   newdecl);
1622   return true;
1623 #undef END_OF_ARGLIST
1624 }
1625 
1626 /* Subroutine of diagnose_mismatched_decls.  Report the location of DECL,
1627    first in a pair of mismatched declarations, using the diagnostic
1628    function DIAG.  */
1629 static void
1630 locate_old_decl (tree decl)
1631 {
1632   if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
1633     ;
1634   else if (DECL_INITIAL (decl))
1635     inform (input_location, "previous definition of %q+D was here", decl);
1636   else if (C_DECL_IMPLICIT (decl))
1637     inform (input_location, "previous implicit declaration of %q+D was here", decl);
1638   else
1639     inform (input_location, "previous declaration of %q+D was here", decl);
1640 }
1641 
1642 /* Subroutine of duplicate_decls.  Compare NEWDECL to OLDDECL.
1643    Returns true if the caller should proceed to merge the two, false
1644    if OLDDECL should simply be discarded.  As a side effect, issues
1645    all necessary diagnostics for invalid or poor-style combinations.
1646    If it returns true, writes the types of NEWDECL and OLDDECL to
1647    *NEWTYPEP and *OLDTYPEP - these may have been adjusted from
1648    TREE_TYPE (NEWDECL, OLDDECL) respectively.  */
1649 
1650 static bool
1651 diagnose_mismatched_decls (tree newdecl, tree olddecl,
1652 			   tree *newtypep, tree *oldtypep)
1653 {
1654   tree newtype, oldtype;
1655   bool pedwarned = false;
1656   bool warned = false;
1657   bool retval = true;
1658 
1659 #define DECL_EXTERN_INLINE(DECL) (DECL_DECLARED_INLINE_P (DECL)  \
1660 				  && DECL_EXTERNAL (DECL))
1661 
1662   /* If we have error_mark_node for either decl or type, just discard
1663      the previous decl - we're in an error cascade already.  */
1664   if (olddecl == error_mark_node || newdecl == error_mark_node)
1665     return false;
1666   *oldtypep = oldtype = TREE_TYPE (olddecl);
1667   *newtypep = newtype = TREE_TYPE (newdecl);
1668   if (oldtype == error_mark_node || newtype == error_mark_node)
1669     return false;
1670 
1671   /* Two different categories of symbol altogether.  This is an error
1672      unless OLDDECL is a builtin.  OLDDECL will be discarded in any case.  */
1673   if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
1674     {
1675       if (!(TREE_CODE (olddecl) == FUNCTION_DECL
1676 	    && DECL_BUILT_IN (olddecl)
1677 	    && !C_DECL_DECLARED_BUILTIN (olddecl)))
1678 	{
1679 	  error ("%q+D redeclared as different kind of symbol", newdecl);
1680 	  locate_old_decl (olddecl);
1681 	}
1682       else if (TREE_PUBLIC (newdecl))
1683 	warning (0, "built-in function %q+D declared as non-function",
1684 		 newdecl);
1685       else
1686 	warning (OPT_Wshadow, "declaration of %q+D shadows "
1687 		 "a built-in function", newdecl);
1688       return false;
1689     }
1690 
1691   /* Enumerators have no linkage, so may only be declared once in a
1692      given scope.  */
1693   if (TREE_CODE (olddecl) == CONST_DECL)
1694     {
1695       error ("redeclaration of enumerator %q+D", newdecl);
1696       locate_old_decl (olddecl);
1697       return false;
1698     }
1699 
1700   if (!comptypes (oldtype, newtype))
1701     {
1702       if (TREE_CODE (olddecl) == FUNCTION_DECL
1703 	  && DECL_BUILT_IN (olddecl) && !C_DECL_DECLARED_BUILTIN (olddecl))
1704 	{
1705 	  /* Accept harmless mismatch in function types.
1706 	     This is for the ffs and fprintf builtins.  */
1707 	  tree trytype = match_builtin_function_types (newtype, oldtype);
1708 
1709 	  if (trytype && comptypes (newtype, trytype))
1710 	    *oldtypep = oldtype = trytype;
1711 	  else
1712 	    {
1713 	      /* If types don't match for a built-in, throw away the
1714 		 built-in.  No point in calling locate_old_decl here, it
1715 		 won't print anything.  */
1716 	      warning (0, "conflicting types for built-in function %q+D",
1717 		       newdecl);
1718 	      return false;
1719 	    }
1720 	}
1721       else if (TREE_CODE (olddecl) == FUNCTION_DECL
1722 	       && DECL_IS_BUILTIN (olddecl))
1723 	{
1724 	  /* A conflicting function declaration for a predeclared
1725 	     function that isn't actually built in.  Objective C uses
1726 	     these.  The new declaration silently overrides everything
1727 	     but the volatility (i.e. noreturn) indication.  See also
1728 	     below.  FIXME: Make Objective C use normal builtins.  */
1729 	  TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
1730 	  return false;
1731 	}
1732       /* Permit void foo (...) to match int foo (...) if the latter is
1733 	 the definition and implicit int was used.  See
1734 	 c-torture/compile/920625-2.c.  */
1735       else if (TREE_CODE (newdecl) == FUNCTION_DECL && DECL_INITIAL (newdecl)
1736 	       && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == void_type_node
1737 	       && TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == integer_type_node
1738 	       && C_FUNCTION_IMPLICIT_INT (newdecl) && !DECL_INITIAL (olddecl))
1739 	{
1740 	  pedwarned = pedwarn (input_location, 0,
1741 			       "conflicting types for %q+D", newdecl);
1742 	  /* Make sure we keep void as the return type.  */
1743 	  TREE_TYPE (newdecl) = *newtypep = newtype = oldtype;
1744 	  C_FUNCTION_IMPLICIT_INT (newdecl) = 0;
1745 	}
1746       /* Permit void foo (...) to match an earlier call to foo (...) with
1747 	 no declared type (thus, implicitly int).  */
1748       else if (TREE_CODE (newdecl) == FUNCTION_DECL
1749 	       && TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == void_type_node
1750 	       && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == integer_type_node
1751 	       && C_DECL_IMPLICIT (olddecl) && !DECL_INITIAL (olddecl))
1752 	{
1753 	  pedwarned = pedwarn (input_location, 0,
1754 			       "conflicting types for %q+D", newdecl);
1755 	  /* Make sure we keep void as the return type.  */
1756 	  TREE_TYPE (olddecl) = *oldtypep = oldtype = newtype;
1757 	}
1758       else
1759 	{
1760 	  int new_quals = TYPE_QUALS (newtype);
1761 	  int old_quals = TYPE_QUALS (oldtype);
1762 
1763 	  if (new_quals != old_quals)
1764 	    {
1765 	      addr_space_t new_addr = DECODE_QUAL_ADDR_SPACE (new_quals);
1766 	      addr_space_t old_addr = DECODE_QUAL_ADDR_SPACE (old_quals);
1767 	      if (new_addr != old_addr)
1768 		{
1769 		  if (ADDR_SPACE_GENERIC_P (new_addr))
1770 		    error ("conflicting named address spaces (generic vs %s) "
1771 			   "for %q+D",
1772 			   c_addr_space_name (old_addr), newdecl);
1773 		  else if (ADDR_SPACE_GENERIC_P (old_addr))
1774 		    error ("conflicting named address spaces (%s vs generic) "
1775 			   "for %q+D",
1776 			   c_addr_space_name (new_addr), newdecl);
1777 		  else
1778 		    error ("conflicting named address spaces (%s vs %s) "
1779 			   "for %q+D",
1780 			   c_addr_space_name (new_addr),
1781 			   c_addr_space_name (old_addr),
1782 			   newdecl);
1783 		}
1784 
1785 	      if (CLEAR_QUAL_ADDR_SPACE (new_quals)
1786 		  != CLEAR_QUAL_ADDR_SPACE (old_quals))
1787 		error ("conflicting type qualifiers for %q+D", newdecl);
1788 	    }
1789 	  else
1790 	    error ("conflicting types for %q+D", newdecl);
1791 	  diagnose_arglist_conflict (newdecl, olddecl, newtype, oldtype);
1792 	  locate_old_decl (olddecl);
1793 	  return false;
1794 	}
1795     }
1796 
1797   /* Redeclaration of a type is a constraint violation (6.7.2.3p1),
1798      but silently ignore the redeclaration if either is in a system
1799      header.  (Conflicting redeclarations were handled above.)  This
1800      is allowed for C11 if the types are the same, not just
1801      compatible.  */
1802   if (TREE_CODE (newdecl) == TYPE_DECL)
1803     {
1804       bool types_different = false;
1805       int comptypes_result;
1806 
1807       comptypes_result
1808 	= comptypes_check_different_types (oldtype, newtype, &types_different);
1809 
1810       if (comptypes_result != 1 || types_different)
1811 	{
1812 	  error ("redefinition of typedef %q+D with different type", newdecl);
1813 	  locate_old_decl (olddecl);
1814 	  return false;
1815 	}
1816 
1817       if (DECL_IN_SYSTEM_HEADER (newdecl)
1818 	  || DECL_IN_SYSTEM_HEADER (olddecl)
1819 	  || TREE_NO_WARNING (newdecl)
1820 	  || TREE_NO_WARNING (olddecl))
1821 	return true;  /* Allow OLDDECL to continue in use.  */
1822 
1823       if (variably_modified_type_p (newtype, NULL))
1824 	{
1825 	  error ("redefinition of typedef %q+D with variably modified type",
1826 		 newdecl);
1827 	  locate_old_decl (olddecl);
1828 	}
1829       else if (pedantic && !flag_isoc11)
1830 	{
1831 	  pedwarn (input_location, OPT_Wpedantic,
1832 		   "redefinition of typedef %q+D", newdecl);
1833 	  locate_old_decl (olddecl);
1834 	}
1835 
1836       return true;
1837     }
1838 
1839   /* Function declarations can either be 'static' or 'extern' (no
1840      qualifier is equivalent to 'extern' - C99 6.2.2p5) and therefore
1841      can never conflict with each other on account of linkage
1842      (6.2.2p4).  Multiple definitions are not allowed (6.9p3,5) but
1843      gnu89 mode permits two definitions if one is 'extern inline' and
1844      one is not.  The non- extern-inline definition supersedes the
1845      extern-inline definition.  */
1846 
1847   else if (TREE_CODE (newdecl) == FUNCTION_DECL)
1848     {
1849       /* If you declare a built-in function name as static, or
1850 	 define the built-in with an old-style definition (so we
1851 	 can't validate the argument list) the built-in definition is
1852 	 overridden, but optionally warn this was a bad choice of name.  */
1853       if (DECL_BUILT_IN (olddecl)
1854 	  && !C_DECL_DECLARED_BUILTIN (olddecl)
1855 	  && (!TREE_PUBLIC (newdecl)
1856 	      || (DECL_INITIAL (newdecl)
1857 		  && !prototype_p (TREE_TYPE (newdecl)))))
1858 	{
1859 	  warning (OPT_Wshadow, "declaration of %q+D shadows "
1860 		   "a built-in function", newdecl);
1861 	  /* Discard the old built-in function.  */
1862 	  return false;
1863 	}
1864 
1865       if (DECL_INITIAL (newdecl))
1866 	{
1867 	  if (DECL_INITIAL (olddecl))
1868 	    {
1869 	      /* If both decls are in the same TU and the new declaration
1870 		 isn't overriding an extern inline reject the new decl.
1871 		 In c99, no overriding is allowed in the same translation
1872 		 unit.  */
1873 	      if ((!DECL_EXTERN_INLINE (olddecl)
1874 		   || DECL_EXTERN_INLINE (newdecl)
1875 		   || (!flag_gnu89_inline
1876 		       && (!DECL_DECLARED_INLINE_P (olddecl)
1877 			   || !lookup_attribute ("gnu_inline",
1878 						 DECL_ATTRIBUTES (olddecl)))
1879 		       && (!DECL_DECLARED_INLINE_P (newdecl)
1880 			   || !lookup_attribute ("gnu_inline",
1881 						 DECL_ATTRIBUTES (newdecl))))
1882 		  )
1883 		  && same_translation_unit_p (newdecl, olddecl))
1884 		{
1885 		  error ("redefinition of %q+D", newdecl);
1886 		  locate_old_decl (olddecl);
1887 		  return false;
1888 		}
1889 	    }
1890 	}
1891       /* If we have a prototype after an old-style function definition,
1892 	 the argument types must be checked specially.  */
1893       else if (DECL_INITIAL (olddecl)
1894 	       && !prototype_p (oldtype) && prototype_p (newtype)
1895 	       && TYPE_ACTUAL_ARG_TYPES (oldtype)
1896 	       && !validate_proto_after_old_defn (newdecl, newtype, oldtype))
1897 	{
1898 	  locate_old_decl (olddecl);
1899 	  return false;
1900 	}
1901       /* A non-static declaration (even an "extern") followed by a
1902 	 static declaration is undefined behavior per C99 6.2.2p3-5,7.
1903 	 The same is true for a static forward declaration at block
1904 	 scope followed by a non-static declaration/definition at file
1905 	 scope.  Static followed by non-static at the same scope is
1906 	 not undefined behavior, and is the most convenient way to get
1907 	 some effects (see e.g.  what unwind-dw2-fde-glibc.c does to
1908 	 the definition of _Unwind_Find_FDE in unwind-dw2-fde.c), but
1909 	 we do diagnose it if -Wtraditional.  */
1910       if (TREE_PUBLIC (olddecl) && !TREE_PUBLIC (newdecl))
1911 	{
1912 	  /* Two exceptions to the rule.  If olddecl is an extern
1913 	     inline, or a predeclared function that isn't actually
1914 	     built in, newdecl silently overrides olddecl.  The latter
1915 	     occur only in Objective C; see also above.  (FIXME: Make
1916 	     Objective C use normal builtins.)  */
1917 	  if (!DECL_IS_BUILTIN (olddecl)
1918 	      && !DECL_EXTERN_INLINE (olddecl))
1919 	    {
1920 	      error ("static declaration of %q+D follows "
1921 		     "non-static declaration", newdecl);
1922 	      locate_old_decl (olddecl);
1923 	    }
1924 	  return false;
1925 	}
1926       else if (TREE_PUBLIC (newdecl) && !TREE_PUBLIC (olddecl))
1927 	{
1928 	  if (DECL_CONTEXT (olddecl))
1929 	    {
1930 	      error ("non-static declaration of %q+D follows "
1931 		     "static declaration", newdecl);
1932 	      locate_old_decl (olddecl);
1933 	      return false;
1934 	    }
1935 	  else if (warn_traditional)
1936 	    {
1937 	      warned |= warning (OPT_Wtraditional,
1938 				 "non-static declaration of %q+D "
1939 				 "follows static declaration", newdecl);
1940 	    }
1941 	}
1942 
1943       /* Make sure gnu_inline attribute is either not present, or
1944 	 present on all inline decls.  */
1945       if (DECL_DECLARED_INLINE_P (olddecl)
1946 	  && DECL_DECLARED_INLINE_P (newdecl))
1947 	{
1948 	  bool newa = lookup_attribute ("gnu_inline",
1949 					DECL_ATTRIBUTES (newdecl)) != NULL;
1950 	  bool olda = lookup_attribute ("gnu_inline",
1951 					DECL_ATTRIBUTES (olddecl)) != NULL;
1952 	  if (newa != olda)
1953 	    {
1954 	      error_at (input_location, "%<gnu_inline%> attribute present on %q+D",
1955 			newa ? newdecl : olddecl);
1956 	      error_at (DECL_SOURCE_LOCATION (newa ? olddecl : newdecl),
1957 			"but not here");
1958 	    }
1959 	}
1960     }
1961   else if (TREE_CODE (newdecl) == VAR_DECL)
1962     {
1963       /* Only variables can be thread-local, and all declarations must
1964 	 agree on this property.  */
1965       if (C_DECL_THREADPRIVATE_P (olddecl) && !DECL_THREAD_LOCAL_P (newdecl))
1966 	{
1967 	  /* Nothing to check.  Since OLDDECL is marked threadprivate
1968 	     and NEWDECL does not have a thread-local attribute, we
1969 	     will merge the threadprivate attribute into NEWDECL.  */
1970 	  ;
1971 	}
1972       else if (DECL_THREAD_LOCAL_P (newdecl) != DECL_THREAD_LOCAL_P (olddecl))
1973 	{
1974 	  if (DECL_THREAD_LOCAL_P (newdecl))
1975 	    error ("thread-local declaration of %q+D follows "
1976 		   "non-thread-local declaration", newdecl);
1977 	  else
1978 	    error ("non-thread-local declaration of %q+D follows "
1979 		   "thread-local declaration", newdecl);
1980 
1981 	  locate_old_decl (olddecl);
1982 	  return false;
1983 	}
1984 
1985       /* Multiple initialized definitions are not allowed (6.9p3,5).  */
1986       if (DECL_INITIAL (newdecl) && DECL_INITIAL (olddecl))
1987 	{
1988 	  error ("redefinition of %q+D", newdecl);
1989 	  locate_old_decl (olddecl);
1990 	  return false;
1991 	}
1992 
1993       /* Objects declared at file scope: if the first declaration had
1994 	 external linkage (even if it was an external reference) the
1995 	 second must have external linkage as well, or the behavior is
1996 	 undefined.  If the first declaration had internal linkage, then
1997 	 the second must too, or else be an external reference (in which
1998 	 case the composite declaration still has internal linkage).
1999 	 As for function declarations, we warn about the static-then-
2000 	 extern case only for -Wtraditional.  See generally 6.2.2p3-5,7.  */
2001       if (DECL_FILE_SCOPE_P (newdecl)
2002 	  && TREE_PUBLIC (newdecl) != TREE_PUBLIC (olddecl))
2003 	{
2004 	  if (DECL_EXTERNAL (newdecl))
2005 	    {
2006 	      if (!DECL_FILE_SCOPE_P (olddecl))
2007 		{
2008 		  error ("extern declaration of %q+D follows "
2009 			 "declaration with no linkage", newdecl);
2010 		  locate_old_decl (olddecl);
2011 		  return false;
2012 		}
2013 	      else if (warn_traditional)
2014 		{
2015 		  warned |= warning (OPT_Wtraditional,
2016 				     "non-static declaration of %q+D "
2017 				     "follows static declaration", newdecl);
2018 		}
2019 	    }
2020 	  else
2021 	    {
2022 	      if (TREE_PUBLIC (newdecl))
2023 		error ("non-static declaration of %q+D follows "
2024 		       "static declaration", newdecl);
2025 	      else
2026 		error ("static declaration of %q+D follows "
2027 		       "non-static declaration", newdecl);
2028 
2029 	      locate_old_decl (olddecl);
2030 	      return false;
2031 	    }
2032 	}
2033       /* Two objects with the same name declared at the same block
2034 	 scope must both be external references (6.7p3).  */
2035       else if (!DECL_FILE_SCOPE_P (newdecl))
2036 	{
2037 	  if (DECL_EXTERNAL (newdecl))
2038 	    {
2039 	      /* Extern with initializer at block scope, which will
2040 		 already have received an error.  */
2041 	    }
2042 	  else if (DECL_EXTERNAL (olddecl))
2043 	    {
2044 	      error ("declaration of %q+D with no linkage follows "
2045 		     "extern declaration", newdecl);
2046 	      locate_old_decl (olddecl);
2047 	    }
2048 	  else
2049 	    {
2050 	      error ("redeclaration of %q+D with no linkage", newdecl);
2051 	      locate_old_decl (olddecl);
2052 	    }
2053 
2054 	  return false;
2055 	}
2056 
2057       /* C++ does not permit a decl to appear multiple times at file
2058 	 scope.  */
2059       if (warn_cxx_compat
2060 	  && DECL_FILE_SCOPE_P (newdecl)
2061 	  && !DECL_EXTERNAL (newdecl)
2062 	  && !DECL_EXTERNAL (olddecl))
2063 	warned |= warning_at (DECL_SOURCE_LOCATION (newdecl),
2064 			      OPT_Wc___compat,
2065 			      ("duplicate declaration of %qD is "
2066 			       "invalid in C++"),
2067 			      newdecl);
2068     }
2069 
2070   /* warnings */
2071   /* All decls must agree on a visibility.  */
2072   if (CODE_CONTAINS_STRUCT (TREE_CODE (newdecl), TS_DECL_WITH_VIS)
2073       && DECL_VISIBILITY_SPECIFIED (newdecl) && DECL_VISIBILITY_SPECIFIED (olddecl)
2074       && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl))
2075     {
2076       warned |= warning (0, "redeclaration of %q+D with different visibility "
2077 			 "(old visibility preserved)", newdecl);
2078     }
2079 
2080   if (TREE_CODE (newdecl) == FUNCTION_DECL)
2081     {
2082       /* Diagnose inline __attribute__ ((noinline)) which is silly.  */
2083       if (DECL_DECLARED_INLINE_P (newdecl)
2084 	  && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl)))
2085 	{
2086 	  warned |= warning (OPT_Wattributes,
2087 			     "inline declaration of %qD follows "
2088 			     "declaration with attribute noinline", newdecl);
2089 	}
2090       else if (DECL_DECLARED_INLINE_P (olddecl)
2091 	       && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl)))
2092 	{
2093 	  warned |= warning (OPT_Wattributes,
2094 			     "declaration of %q+D with attribute "
2095 			     "noinline follows inline declaration ", newdecl);
2096 	}
2097     }
2098   else /* PARM_DECL, VAR_DECL */
2099     {
2100       /* Redeclaration of a parameter is a constraint violation (this is
2101 	 not explicitly stated, but follows from C99 6.7p3 [no more than
2102 	 one declaration of the same identifier with no linkage in the
2103 	 same scope, except type tags] and 6.2.2p6 [parameters have no
2104 	 linkage]).  We must check for a forward parameter declaration,
2105 	 indicated by TREE_ASM_WRITTEN on the old declaration - this is
2106 	 an extension, the mandatory diagnostic for which is handled by
2107 	 mark_forward_parm_decls.  */
2108 
2109       if (TREE_CODE (newdecl) == PARM_DECL
2110 	  && (!TREE_ASM_WRITTEN (olddecl) || TREE_ASM_WRITTEN (newdecl)))
2111 	{
2112 	  error ("redefinition of parameter %q+D", newdecl);
2113 	  locate_old_decl (olddecl);
2114 	  return false;
2115 	}
2116     }
2117 
2118   /* Optional warning for completely redundant decls.  */
2119   if (!warned && !pedwarned
2120       && warn_redundant_decls
2121       /* Don't warn about a function declaration followed by a
2122 	 definition.  */
2123       && !(TREE_CODE (newdecl) == FUNCTION_DECL
2124 	   && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl))
2125       /* Don't warn about redundant redeclarations of builtins.  */
2126       && !(TREE_CODE (newdecl) == FUNCTION_DECL
2127 	   && !DECL_BUILT_IN (newdecl)
2128 	   && DECL_BUILT_IN (olddecl)
2129 	   && !C_DECL_DECLARED_BUILTIN (olddecl))
2130       /* Don't warn about an extern followed by a definition.  */
2131       && !(DECL_EXTERNAL (olddecl) && !DECL_EXTERNAL (newdecl))
2132       /* Don't warn about forward parameter decls.  */
2133       && !(TREE_CODE (newdecl) == PARM_DECL
2134 	   && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl))
2135       /* Don't warn about a variable definition following a declaration.  */
2136       && !(TREE_CODE (newdecl) == VAR_DECL
2137 	   && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl)))
2138     {
2139       warned = warning (OPT_Wredundant_decls, "redundant redeclaration of %q+D",
2140 			newdecl);
2141     }
2142 
2143   /* Report location of previous decl/defn.  */
2144   if (warned || pedwarned)
2145     locate_old_decl (olddecl);
2146 
2147 #undef DECL_EXTERN_INLINE
2148 
2149   return retval;
2150 }
2151 
2152 /* Subroutine of duplicate_decls.  NEWDECL has been found to be
2153    consistent with OLDDECL, but carries new information.  Merge the
2154    new information into OLDDECL.  This function issues no
2155    diagnostics.  */
2156 
2157 static void
2158 merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype)
2159 {
2160   bool new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL
2161 			    && DECL_INITIAL (newdecl) != 0);
2162   bool new_is_prototype = (TREE_CODE (newdecl) == FUNCTION_DECL
2163 			   && prototype_p (TREE_TYPE (newdecl)));
2164   bool old_is_prototype = (TREE_CODE (olddecl) == FUNCTION_DECL
2165 			   && prototype_p (TREE_TYPE (olddecl)));
2166 
2167   /* For real parm decl following a forward decl, rechain the old decl
2168      in its new location and clear TREE_ASM_WRITTEN (it's not a
2169      forward decl anymore).  */
2170   if (TREE_CODE (newdecl) == PARM_DECL
2171       && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl))
2172     {
2173       struct c_binding *b, **here;
2174 
2175       for (here = &current_scope->bindings; *here; here = &(*here)->prev)
2176 	if ((*here)->decl == olddecl)
2177 	  goto found;
2178       gcc_unreachable ();
2179 
2180     found:
2181       b = *here;
2182       *here = b->prev;
2183       b->prev = current_scope->bindings;
2184       current_scope->bindings = b;
2185 
2186       TREE_ASM_WRITTEN (olddecl) = 0;
2187     }
2188 
2189   DECL_ATTRIBUTES (newdecl)
2190     = targetm.merge_decl_attributes (olddecl, newdecl);
2191 
2192   /* Merge the data types specified in the two decls.  */
2193   TREE_TYPE (newdecl)
2194     = TREE_TYPE (olddecl)
2195     = composite_type (newtype, oldtype);
2196 
2197   /* Lay the type out, unless already done.  */
2198   if (!comptypes (oldtype, TREE_TYPE (newdecl)))
2199     {
2200       if (TREE_TYPE (newdecl) != error_mark_node)
2201 	layout_type (TREE_TYPE (newdecl));
2202       if (TREE_CODE (newdecl) != FUNCTION_DECL
2203 	  && TREE_CODE (newdecl) != TYPE_DECL
2204 	  && TREE_CODE (newdecl) != CONST_DECL)
2205 	layout_decl (newdecl, 0);
2206     }
2207   else
2208     {
2209       /* Since the type is OLDDECL's, make OLDDECL's size go with.  */
2210       DECL_SIZE (newdecl) = DECL_SIZE (olddecl);
2211       DECL_SIZE_UNIT (newdecl) = DECL_SIZE_UNIT (olddecl);
2212       DECL_MODE (newdecl) = DECL_MODE (olddecl);
2213       if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl))
2214 	{
2215 	  DECL_ALIGN (newdecl) = DECL_ALIGN (olddecl);
2216 	  DECL_USER_ALIGN (newdecl) |= DECL_USER_ALIGN (olddecl);
2217 	}
2218     }
2219 
2220   /* Keep the old rtl since we can safely use it.  */
2221   if (HAS_RTL_P (olddecl))
2222     COPY_DECL_RTL (olddecl, newdecl);
2223 
2224   /* Merge the type qualifiers.  */
2225   if (TREE_READONLY (newdecl))
2226     TREE_READONLY (olddecl) = 1;
2227 
2228   if (TREE_THIS_VOLATILE (newdecl))
2229     TREE_THIS_VOLATILE (olddecl) = 1;
2230 
2231   /* Merge deprecatedness.  */
2232   if (TREE_DEPRECATED (newdecl))
2233     TREE_DEPRECATED (olddecl) = 1;
2234 
2235   /* If a decl is in a system header and the other isn't, keep the one on the
2236      system header. Otherwise, keep source location of definition rather than
2237      declaration and of prototype rather than non-prototype unless that
2238      prototype is built-in.  */
2239   if (CODE_CONTAINS_STRUCT (TREE_CODE (olddecl), TS_DECL_WITH_VIS)
2240       && DECL_IN_SYSTEM_HEADER (olddecl)
2241       && !DECL_IN_SYSTEM_HEADER (newdecl) )
2242     DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
2243   else if (CODE_CONTAINS_STRUCT (TREE_CODE (olddecl), TS_DECL_WITH_VIS)
2244 	   && DECL_IN_SYSTEM_HEADER (newdecl)
2245 	   && !DECL_IN_SYSTEM_HEADER (olddecl))
2246     DECL_SOURCE_LOCATION (olddecl) = DECL_SOURCE_LOCATION (newdecl);
2247   else if ((DECL_INITIAL (newdecl) == 0 && DECL_INITIAL (olddecl) != 0)
2248 	   || (old_is_prototype && !new_is_prototype
2249 	       && !C_DECL_BUILTIN_PROTOTYPE (olddecl)))
2250     DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
2251 
2252   /* Merge the initialization information.  */
2253    if (DECL_INITIAL (newdecl) == 0)
2254     DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
2255 
2256   /* Merge the threadprivate attribute.  */
2257   if (TREE_CODE (olddecl) == VAR_DECL && C_DECL_THREADPRIVATE_P (olddecl))
2258     {
2259       DECL_TLS_MODEL (newdecl) = DECL_TLS_MODEL (olddecl);
2260       C_DECL_THREADPRIVATE_P (newdecl) = 1;
2261     }
2262 
2263   if (CODE_CONTAINS_STRUCT (TREE_CODE (olddecl), TS_DECL_WITH_VIS))
2264     {
2265       /* Merge the section attribute.
2266 	 We want to issue an error if the sections conflict but that
2267 	 must be done later in decl_attributes since we are called
2268 	 before attributes are assigned.  */
2269       if (DECL_SECTION_NAME (newdecl) == NULL_TREE)
2270 	DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl);
2271 
2272       /* Copy the assembler name.
2273 	 Currently, it can only be defined in the prototype.  */
2274       COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
2275 
2276       /* Use visibility of whichever declaration had it specified */
2277       if (DECL_VISIBILITY_SPECIFIED (olddecl))
2278 	{
2279 	  DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
2280 	  DECL_VISIBILITY_SPECIFIED (newdecl) = 1;
2281 	}
2282 
2283       if (TREE_CODE (newdecl) == FUNCTION_DECL)
2284 	{
2285 	  DECL_STATIC_CONSTRUCTOR(newdecl) |= DECL_STATIC_CONSTRUCTOR(olddecl);
2286 	  DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
2287 	  DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
2288 	  DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
2289 	    |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
2290 	  TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
2291 	  DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
2292 	  DECL_IS_OPERATOR_NEW (newdecl) |= DECL_IS_OPERATOR_NEW (olddecl);
2293 	  TREE_READONLY (newdecl) |= TREE_READONLY (olddecl);
2294 	  DECL_PURE_P (newdecl) |= DECL_PURE_P (olddecl);
2295 	  DECL_IS_NOVOPS (newdecl) |= DECL_IS_NOVOPS (olddecl);
2296 	}
2297 
2298       /* Merge the storage class information.  */
2299       merge_weak (newdecl, olddecl);
2300 
2301       /* For functions, static overrides non-static.  */
2302       if (TREE_CODE (newdecl) == FUNCTION_DECL)
2303 	{
2304 	  TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl);
2305 	  /* This is since we don't automatically
2306 	     copy the attributes of NEWDECL into OLDDECL.  */
2307 	  TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
2308 	  /* If this clears `static', clear it in the identifier too.  */
2309 	  if (!TREE_PUBLIC (olddecl))
2310 	    TREE_PUBLIC (DECL_NAME (olddecl)) = 0;
2311 	}
2312     }
2313 
2314   /* In c99, 'extern' declaration before (or after) 'inline' means this
2315      function is not DECL_EXTERNAL, unless 'gnu_inline' attribute
2316      is present.  */
2317   if (TREE_CODE (newdecl) == FUNCTION_DECL
2318       && !flag_gnu89_inline
2319       && (DECL_DECLARED_INLINE_P (newdecl)
2320 	  || DECL_DECLARED_INLINE_P (olddecl))
2321       && (!DECL_DECLARED_INLINE_P (newdecl)
2322 	  || !DECL_DECLARED_INLINE_P (olddecl)
2323 	  || !DECL_EXTERNAL (olddecl))
2324       && DECL_EXTERNAL (newdecl)
2325       && !lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (newdecl))
2326       && !current_function_decl)
2327     DECL_EXTERNAL (newdecl) = 0;
2328 
2329   if (DECL_EXTERNAL (newdecl))
2330     {
2331       TREE_STATIC (newdecl) = TREE_STATIC (olddecl);
2332       DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (olddecl);
2333 
2334       /* An extern decl does not override previous storage class.  */
2335       TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
2336       if (!DECL_EXTERNAL (newdecl))
2337 	{
2338 	  DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
2339 	  DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
2340 	}
2341     }
2342   else
2343     {
2344       TREE_STATIC (olddecl) = TREE_STATIC (newdecl);
2345       TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
2346     }
2347 
2348   if (TREE_CODE (newdecl) == FUNCTION_DECL)
2349     {
2350       /* If we're redefining a function previously defined as extern
2351 	 inline, make sure we emit debug info for the inline before we
2352 	 throw it away, in case it was inlined into a function that
2353 	 hasn't been written out yet.  */
2354       if (new_is_definition && DECL_INITIAL (olddecl))
2355 	/* The new defn must not be inline.  */
2356 	DECL_UNINLINABLE (newdecl) = 1;
2357       else
2358 	{
2359 	  /* If either decl says `inline', this fn is inline, unless
2360 	     its definition was passed already.  */
2361 	  if (DECL_DECLARED_INLINE_P (newdecl)
2362 	      || DECL_DECLARED_INLINE_P (olddecl))
2363 	    DECL_DECLARED_INLINE_P (newdecl) = 1;
2364 
2365 	  DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
2366 	    = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
2367 
2368 	  DECL_DISREGARD_INLINE_LIMITS (newdecl)
2369 	    = DECL_DISREGARD_INLINE_LIMITS (olddecl)
2370 	    = (DECL_DISREGARD_INLINE_LIMITS (newdecl)
2371 	       || DECL_DISREGARD_INLINE_LIMITS (olddecl));
2372 	}
2373 
2374       if (DECL_BUILT_IN (olddecl))
2375 	{
2376 	  /* If redeclaring a builtin function, it stays built in.
2377 	     But it gets tagged as having been declared.  */
2378 	  DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl);
2379 	  DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
2380 	  C_DECL_DECLARED_BUILTIN (newdecl) = 1;
2381 	  if (new_is_prototype)
2382 	    {
2383 	      C_DECL_BUILTIN_PROTOTYPE (newdecl) = 0;
2384 	      if (DECL_BUILT_IN_CLASS (newdecl) == BUILT_IN_NORMAL)
2385 		{
2386 		  enum built_in_function fncode = DECL_FUNCTION_CODE (newdecl);
2387 		  switch (fncode)
2388 		    {
2389 		      /* If a compatible prototype of these builtin functions
2390 			 is seen, assume the runtime implements it with the
2391 			 expected semantics.  */
2392 		    case BUILT_IN_STPCPY:
2393 		      if (builtin_decl_explicit_p (fncode))
2394 			set_builtin_decl_implicit_p (fncode, true);
2395 		      break;
2396 		    default:
2397 		      break;
2398 		    }
2399 		}
2400 	    }
2401 	  else
2402 	    C_DECL_BUILTIN_PROTOTYPE (newdecl)
2403 	      = C_DECL_BUILTIN_PROTOTYPE (olddecl);
2404 	}
2405 
2406       /* Preserve function specific target and optimization options */
2407       if (DECL_FUNCTION_SPECIFIC_TARGET (olddecl)
2408 	  && !DECL_FUNCTION_SPECIFIC_TARGET (newdecl))
2409 	DECL_FUNCTION_SPECIFIC_TARGET (newdecl)
2410 	  = DECL_FUNCTION_SPECIFIC_TARGET (olddecl);
2411 
2412       if (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl)
2413 	  && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl))
2414 	DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl)
2415 	  = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl);
2416 
2417       /* Also preserve various other info from the definition.  */
2418       if (!new_is_definition)
2419 	{
2420 	  tree t;
2421 	  DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
2422 	  DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
2423 	  DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl);
2424 	  DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
2425 	  DECL_ARGUMENTS (newdecl) = copy_list (DECL_ARGUMENTS (olddecl));
2426 	  for (t = DECL_ARGUMENTS (newdecl); t ; t = DECL_CHAIN (t))
2427 	    DECL_CONTEXT (t) = newdecl;
2428 
2429 	  /* See if we've got a function to instantiate from.  */
2430 	  if (DECL_SAVED_TREE (olddecl))
2431 	    DECL_ABSTRACT_ORIGIN (newdecl)
2432 	      = DECL_ABSTRACT_ORIGIN (olddecl);
2433 	}
2434     }
2435 
2436   /* Merge the USED information.  */
2437   if (TREE_USED (olddecl))
2438     TREE_USED (newdecl) = 1;
2439   else if (TREE_USED (newdecl))
2440     TREE_USED (olddecl) = 1;
2441   if (TREE_CODE (olddecl) == VAR_DECL || TREE_CODE (olddecl) == PARM_DECL)
2442     DECL_READ_P (newdecl) |= DECL_READ_P (olddecl);
2443   if (DECL_PRESERVE_P (olddecl))
2444     DECL_PRESERVE_P (newdecl) = 1;
2445   else if (DECL_PRESERVE_P (newdecl))
2446     DECL_PRESERVE_P (olddecl) = 1;
2447 
2448   /* Copy most of the decl-specific fields of NEWDECL into OLDDECL.
2449      But preserve OLDDECL's DECL_UID, DECL_CONTEXT and
2450      DECL_ARGUMENTS (if appropriate).  */
2451   {
2452     unsigned olddecl_uid = DECL_UID (olddecl);
2453     tree olddecl_context = DECL_CONTEXT (olddecl);
2454     tree olddecl_arguments = NULL;
2455     if (TREE_CODE (olddecl) == FUNCTION_DECL)
2456       olddecl_arguments = DECL_ARGUMENTS (olddecl);
2457 
2458     memcpy ((char *) olddecl + sizeof (struct tree_common),
2459 	    (char *) newdecl + sizeof (struct tree_common),
2460 	    sizeof (struct tree_decl_common) - sizeof (struct tree_common));
2461     DECL_USER_ALIGN (olddecl) = DECL_USER_ALIGN (newdecl);
2462     switch (TREE_CODE (olddecl))
2463       {
2464       case FUNCTION_DECL:
2465       case FIELD_DECL:
2466       case VAR_DECL:
2467       case PARM_DECL:
2468       case LABEL_DECL:
2469       case RESULT_DECL:
2470       case CONST_DECL:
2471       case TYPE_DECL:
2472 	memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
2473 		(char *) newdecl + sizeof (struct tree_decl_common),
2474 		tree_code_size (TREE_CODE (olddecl)) - sizeof (struct tree_decl_common));
2475 	break;
2476 
2477       default:
2478 
2479 	memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
2480 		(char *) newdecl + sizeof (struct tree_decl_common),
2481 		sizeof (struct tree_decl_non_common) - sizeof (struct tree_decl_common));
2482       }
2483     DECL_UID (olddecl) = olddecl_uid;
2484     DECL_CONTEXT (olddecl) = olddecl_context;
2485     if (TREE_CODE (olddecl) == FUNCTION_DECL)
2486       DECL_ARGUMENTS (olddecl) = olddecl_arguments;
2487   }
2488 
2489   /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
2490      so that encode_section_info has a chance to look at the new decl
2491      flags and attributes.  */
2492   if (DECL_RTL_SET_P (olddecl)
2493       && (TREE_CODE (olddecl) == FUNCTION_DECL
2494 	  || (TREE_CODE (olddecl) == VAR_DECL
2495 	      && TREE_STATIC (olddecl))))
2496     make_decl_rtl (olddecl);
2497 }
2498 
2499 /* Handle when a new declaration NEWDECL has the same name as an old
2500    one OLDDECL in the same binding contour.  Prints an error message
2501    if appropriate.
2502 
2503    If safely possible, alter OLDDECL to look like NEWDECL, and return
2504    true.  Otherwise, return false.  */
2505 
2506 static bool
2507 duplicate_decls (tree newdecl, tree olddecl)
2508 {
2509   tree newtype = NULL, oldtype = NULL;
2510 
2511   if (!diagnose_mismatched_decls (newdecl, olddecl, &newtype, &oldtype))
2512     {
2513       /* Avoid `unused variable' and other warnings for OLDDECL.  */
2514       TREE_NO_WARNING (olddecl) = 1;
2515       return false;
2516     }
2517 
2518   merge_decls (newdecl, olddecl, newtype, oldtype);
2519   return true;
2520 }
2521 
2522 
2523 /* Check whether decl-node NEW_DECL shadows an existing declaration.  */
2524 static void
2525 warn_if_shadowing (tree new_decl)
2526 {
2527   struct c_binding *b;
2528 
2529   /* Shadow warnings wanted?  */
2530   if (!warn_shadow
2531       /* No shadow warnings for internally generated vars.  */
2532       || DECL_IS_BUILTIN (new_decl)
2533       /* No shadow warnings for vars made for inlining.  */
2534       || DECL_FROM_INLINE (new_decl))
2535     return;
2536 
2537   /* Is anything being shadowed?  Invisible decls do not count.  */
2538   for (b = I_SYMBOL_BINDING (DECL_NAME (new_decl)); b; b = b->shadowed)
2539     if (b->decl && b->decl != new_decl && !b->invisible
2540 	&& (b->decl == error_mark_node
2541 	    || diagnostic_report_warnings_p (global_dc,
2542 					     DECL_SOURCE_LOCATION (b->decl))))
2543       {
2544 	tree old_decl = b->decl;
2545 
2546 	if (old_decl == error_mark_node)
2547 	  {
2548 	    warning (OPT_Wshadow, "declaration of %q+D shadows previous "
2549 		     "non-variable", new_decl);
2550 	    break;
2551 	  }
2552 	else if (TREE_CODE (old_decl) == PARM_DECL)
2553 	  warning (OPT_Wshadow, "declaration of %q+D shadows a parameter",
2554 		   new_decl);
2555 	else if (DECL_FILE_SCOPE_P (old_decl))
2556 	  {
2557 	    /* Do not warn if a variable shadows a function, unless
2558 	       the variable is a function or a pointer-to-function.  */
2559 	    if (TREE_CODE (old_decl) == FUNCTION_DECL
2560 		&& TREE_CODE (new_decl) != FUNCTION_DECL
2561 		&& !FUNCTION_POINTER_TYPE_P (TREE_TYPE (new_decl)))
2562 		continue;
2563 
2564 	    warning_at (DECL_SOURCE_LOCATION (new_decl), OPT_Wshadow,
2565 			"declaration of %qD shadows a global declaration",
2566 			new_decl);
2567 	  }
2568 	else if (TREE_CODE (old_decl) == FUNCTION_DECL
2569 		 && DECL_BUILT_IN (old_decl))
2570 	  {
2571 	    warning (OPT_Wshadow, "declaration of %q+D shadows "
2572 		     "a built-in function", new_decl);
2573 	    break;
2574 	  }
2575 	else
2576 	  warning (OPT_Wshadow, "declaration of %q+D shadows a previous local",
2577 		   new_decl);
2578 
2579 	warning_at (DECL_SOURCE_LOCATION (old_decl), OPT_Wshadow,
2580 		    "shadowed declaration is here");
2581 
2582 	break;
2583       }
2584 }
2585 
2586 /* Record a decl-node X as belonging to the current lexical scope.
2587    Check for errors (such as an incompatible declaration for the same
2588    name already seen in the same scope).
2589 
2590    Returns either X or an old decl for the same name.
2591    If an old decl is returned, it may have been smashed
2592    to agree with what X says.  */
2593 
2594 tree
2595 pushdecl (tree x)
2596 {
2597   tree name = DECL_NAME (x);
2598   struct c_scope *scope = current_scope;
2599   struct c_binding *b;
2600   bool nested = false;
2601   location_t locus = DECL_SOURCE_LOCATION (x);
2602 
2603   /* Must set DECL_CONTEXT for everything not at file scope or
2604      DECL_FILE_SCOPE_P won't work.  Local externs don't count
2605      unless they have initializers (which generate code).  */
2606   if (current_function_decl
2607       && ((TREE_CODE (x) != FUNCTION_DECL && TREE_CODE (x) != VAR_DECL)
2608 	  || DECL_INITIAL (x) || !DECL_EXTERNAL (x)))
2609     DECL_CONTEXT (x) = current_function_decl;
2610 
2611   /* Anonymous decls are just inserted in the scope.  */
2612   if (!name)
2613     {
2614       bind (name, x, scope, /*invisible=*/false, /*nested=*/false,
2615 	    locus);
2616       return x;
2617     }
2618 
2619   /* First, see if there is another declaration with the same name in
2620      the current scope.  If there is, duplicate_decls may do all the
2621      work for us.  If duplicate_decls returns false, that indicates
2622      two incompatible decls in the same scope; we are to silently
2623      replace the old one (duplicate_decls has issued all appropriate
2624      diagnostics).  In particular, we should not consider possible
2625      duplicates in the external scope, or shadowing.  */
2626   b = I_SYMBOL_BINDING (name);
2627   if (b && B_IN_SCOPE (b, scope))
2628     {
2629       struct c_binding *b_ext, *b_use;
2630       tree type = TREE_TYPE (x);
2631       tree visdecl = b->decl;
2632       tree vistype = TREE_TYPE (visdecl);
2633       if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
2634 	  && COMPLETE_TYPE_P (TREE_TYPE (x)))
2635 	b->inner_comp = false;
2636       b_use = b;
2637       b_ext = b;
2638       /* If this is an external linkage declaration, we should check
2639 	 for compatibility with the type in the external scope before
2640 	 setting the type at this scope based on the visible
2641 	 information only.  */
2642       if (TREE_PUBLIC (x) && TREE_PUBLIC (visdecl))
2643 	{
2644 	  while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext))
2645 	    b_ext = b_ext->shadowed;
2646 	  if (b_ext)
2647 	    {
2648 	      b_use = b_ext;
2649 	      if (b_use->u.type)
2650 		TREE_TYPE (b_use->decl) = b_use->u.type;
2651 	    }
2652 	}
2653       if (duplicate_decls (x, b_use->decl))
2654 	{
2655 	  if (b_use != b)
2656 	    {
2657 	      /* Save the updated type in the external scope and
2658 		 restore the proper type for this scope.  */
2659 	      tree thistype;
2660 	      if (comptypes (vistype, type))
2661 		thistype = composite_type (vistype, type);
2662 	      else
2663 		thistype = TREE_TYPE (b_use->decl);
2664 	      b_use->u.type = TREE_TYPE (b_use->decl);
2665 	      if (TREE_CODE (b_use->decl) == FUNCTION_DECL
2666 		  && DECL_BUILT_IN (b_use->decl))
2667 		thistype
2668 		  = build_type_attribute_variant (thistype,
2669 						  TYPE_ATTRIBUTES
2670 						  (b_use->u.type));
2671 	      TREE_TYPE (b_use->decl) = thistype;
2672 	    }
2673 	  return b_use->decl;
2674 	}
2675       else
2676 	goto skip_external_and_shadow_checks;
2677     }
2678 
2679   /* All declarations with external linkage, and all external
2680      references, go in the external scope, no matter what scope is
2681      current.  However, the binding in that scope is ignored for
2682      purposes of normal name lookup.  A separate binding structure is
2683      created in the requested scope; this governs the normal
2684      visibility of the symbol.
2685 
2686      The binding in the externals scope is used exclusively for
2687      detecting duplicate declarations of the same object, no matter
2688      what scope they are in; this is what we do here.  (C99 6.2.7p2:
2689      All declarations that refer to the same object or function shall
2690      have compatible type; otherwise, the behavior is undefined.)  */
2691   if (DECL_EXTERNAL (x) || scope == file_scope)
2692     {
2693       tree type = TREE_TYPE (x);
2694       tree vistype = 0;
2695       tree visdecl = 0;
2696       bool type_saved = false;
2697       if (b && !B_IN_EXTERNAL_SCOPE (b)
2698 	  && (TREE_CODE (b->decl) == FUNCTION_DECL
2699 	      || TREE_CODE (b->decl) == VAR_DECL)
2700 	  && DECL_FILE_SCOPE_P (b->decl))
2701 	{
2702 	  visdecl = b->decl;
2703 	  vistype = TREE_TYPE (visdecl);
2704 	}
2705       if (scope != file_scope
2706 	  && !DECL_IN_SYSTEM_HEADER (x))
2707 	warning (OPT_Wnested_externs, "nested extern declaration of %qD", x);
2708 
2709       while (b && !B_IN_EXTERNAL_SCOPE (b))
2710 	{
2711 	  /* If this decl might be modified, save its type.  This is
2712 	     done here rather than when the decl is first bound
2713 	     because the type may change after first binding, through
2714 	     being completed or through attributes being added.  If we
2715 	     encounter multiple such decls, only the first should have
2716 	     its type saved; the others will already have had their
2717 	     proper types saved and the types will not have changed as
2718 	     their scopes will not have been re-entered.  */
2719 	  if (DECL_P (b->decl) && DECL_FILE_SCOPE_P (b->decl) && !type_saved)
2720 	    {
2721 	      b->u.type = TREE_TYPE (b->decl);
2722 	      type_saved = true;
2723 	    }
2724 	  if (B_IN_FILE_SCOPE (b)
2725 	      && TREE_CODE (b->decl) == VAR_DECL
2726 	      && TREE_STATIC (b->decl)
2727 	      && TREE_CODE (TREE_TYPE (b->decl)) == ARRAY_TYPE
2728 	      && !TYPE_DOMAIN (TREE_TYPE (b->decl))
2729 	      && TREE_CODE (type) == ARRAY_TYPE
2730 	      && TYPE_DOMAIN (type)
2731 	      && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
2732 	      && !integer_zerop (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
2733 	    {
2734 	      /* Array type completed in inner scope, which should be
2735 		 diagnosed if the completion does not have size 1 and
2736 		 it does not get completed in the file scope.  */
2737 	      b->inner_comp = true;
2738 	    }
2739 	  b = b->shadowed;
2740 	}
2741 
2742       /* If a matching external declaration has been found, set its
2743 	 type to the composite of all the types of that declaration.
2744 	 After the consistency checks, it will be reset to the
2745 	 composite of the visible types only.  */
2746       if (b && (TREE_PUBLIC (x) || same_translation_unit_p (x, b->decl))
2747 	  && b->u.type)
2748 	TREE_TYPE (b->decl) = b->u.type;
2749 
2750       /* The point of the same_translation_unit_p check here is,
2751 	 we want to detect a duplicate decl for a construct like
2752 	 foo() { extern bar(); } ... static bar();  but not if
2753 	 they are in different translation units.  In any case,
2754 	 the static does not go in the externals scope.  */
2755       if (b
2756 	  && (TREE_PUBLIC (x) || same_translation_unit_p (x, b->decl))
2757 	  && duplicate_decls (x, b->decl))
2758 	{
2759 	  tree thistype;
2760 	  if (vistype)
2761 	    {
2762 	      if (comptypes (vistype, type))
2763 		thistype = composite_type (vistype, type);
2764 	      else
2765 		thistype = TREE_TYPE (b->decl);
2766 	    }
2767 	  else
2768 	    thistype = type;
2769 	  b->u.type = TREE_TYPE (b->decl);
2770 	  if (TREE_CODE (b->decl) == FUNCTION_DECL && DECL_BUILT_IN (b->decl))
2771 	    thistype
2772 	      = build_type_attribute_variant (thistype,
2773 					      TYPE_ATTRIBUTES (b->u.type));
2774 	  TREE_TYPE (b->decl) = thistype;
2775 	  bind (name, b->decl, scope, /*invisible=*/false, /*nested=*/true,
2776 		locus);
2777 	  return b->decl;
2778 	}
2779       else if (TREE_PUBLIC (x))
2780 	{
2781 	  if (visdecl && !b && duplicate_decls (x, visdecl))
2782 	    {
2783 	      /* An external declaration at block scope referring to a
2784 		 visible entity with internal linkage.  The composite
2785 		 type will already be correct for this scope, so we
2786 		 just need to fall through to make the declaration in
2787 		 this scope.  */
2788 	      nested = true;
2789 	      x = visdecl;
2790 	    }
2791 	  else
2792 	    {
2793 	      bind (name, x, external_scope, /*invisible=*/true,
2794 		    /*nested=*/false, locus);
2795 	      nested = true;
2796 	    }
2797 	}
2798     }
2799 
2800   if (TREE_CODE (x) != PARM_DECL)
2801     warn_if_shadowing (x);
2802 
2803  skip_external_and_shadow_checks:
2804   if (TREE_CODE (x) == TYPE_DECL)
2805     {
2806       /* So this is a typedef, set its underlying type.  */
2807       set_underlying_type (x);
2808 
2809       /* If X is a typedef defined in the current function, record it
2810 	 for the purpose of implementing the -Wunused-local-typedefs
2811 	 warning.  */
2812       record_locally_defined_typedef (x);
2813     }
2814 
2815   bind (name, x, scope, /*invisible=*/false, nested, locus);
2816 
2817   /* If x's type is incomplete because it's based on a
2818      structure or union which has not yet been fully declared,
2819      attach it to that structure or union type, so we can go
2820      back and complete the variable declaration later, if the
2821      structure or union gets fully declared.
2822 
2823      If the input is erroneous, we can have error_mark in the type
2824      slot (e.g. "f(void a, ...)") - that doesn't count as an
2825      incomplete type.  */
2826   if (TREE_TYPE (x) != error_mark_node
2827       && !COMPLETE_TYPE_P (TREE_TYPE (x)))
2828     {
2829       tree element = TREE_TYPE (x);
2830 
2831       while (TREE_CODE (element) == ARRAY_TYPE)
2832 	element = TREE_TYPE (element);
2833       element = TYPE_MAIN_VARIANT (element);
2834 
2835       if ((TREE_CODE (element) == RECORD_TYPE
2836 	   || TREE_CODE (element) == UNION_TYPE)
2837 	  && (TREE_CODE (x) != TYPE_DECL
2838 	      || TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE)
2839 	  && !COMPLETE_TYPE_P (element))
2840 	C_TYPE_INCOMPLETE_VARS (element)
2841 	  = tree_cons (NULL_TREE, x, C_TYPE_INCOMPLETE_VARS (element));
2842     }
2843   return x;
2844 }
2845 
2846 /* Record X as belonging to file scope.
2847    This is used only internally by the Objective-C front end,
2848    and is limited to its needs.  duplicate_decls is not called;
2849    if there is any preexisting decl for this identifier, it is an ICE.  */
2850 
2851 tree
2852 pushdecl_top_level (tree x)
2853 {
2854   tree name;
2855   bool nested = false;
2856   gcc_assert (TREE_CODE (x) == VAR_DECL || TREE_CODE (x) == CONST_DECL);
2857 
2858   name = DECL_NAME (x);
2859 
2860  gcc_assert (TREE_CODE (x) == CONST_DECL || !I_SYMBOL_BINDING (name));
2861 
2862   if (TREE_PUBLIC (x))
2863     {
2864       bind (name, x, external_scope, /*invisible=*/true, /*nested=*/false,
2865 	    UNKNOWN_LOCATION);
2866       nested = true;
2867     }
2868   if (file_scope)
2869     bind (name, x, file_scope, /*invisible=*/false, nested, UNKNOWN_LOCATION);
2870 
2871   return x;
2872 }
2873 
2874 static void
2875 implicit_decl_warning (tree id, tree olddecl)
2876 {
2877   if (warn_implicit_function_declaration)
2878     {
2879       bool warned;
2880 
2881       if (flag_isoc99)
2882 	warned = pedwarn (input_location, OPT_Wimplicit_function_declaration,
2883 			  "implicit declaration of function %qE", id);
2884       else
2885 	warned = warning (OPT_Wimplicit_function_declaration,
2886 			  G_("implicit declaration of function %qE"), id);
2887       if (olddecl && warned)
2888 	locate_old_decl (olddecl);
2889     }
2890 }
2891 
2892 /* Generate an implicit declaration for identifier FUNCTIONID at LOC as a
2893    function of type int ().  */
2894 
2895 tree
2896 implicitly_declare (location_t loc, tree functionid)
2897 {
2898   struct c_binding *b;
2899   tree decl = 0;
2900   tree asmspec_tree;
2901 
2902   for (b = I_SYMBOL_BINDING (functionid); b; b = b->shadowed)
2903     {
2904       if (B_IN_SCOPE (b, external_scope))
2905 	{
2906 	  decl = b->decl;
2907 	  break;
2908 	}
2909     }
2910 
2911   if (decl)
2912     {
2913       if (decl == error_mark_node)
2914 	return decl;
2915 
2916       /* FIXME: Objective-C has weird not-really-builtin functions
2917 	 which are supposed to be visible automatically.  They wind up
2918 	 in the external scope because they're pushed before the file
2919 	 scope gets created.  Catch this here and rebind them into the
2920 	 file scope.  */
2921       if (!DECL_BUILT_IN (decl) && DECL_IS_BUILTIN (decl))
2922 	{
2923 	  bind (functionid, decl, file_scope,
2924 		/*invisible=*/false, /*nested=*/true,
2925 		DECL_SOURCE_LOCATION (decl));
2926 	  return decl;
2927 	}
2928       else
2929 	{
2930 	  tree newtype = default_function_type;
2931 	  if (b->u.type)
2932 	    TREE_TYPE (decl) = b->u.type;
2933 	  /* Implicit declaration of a function already declared
2934 	     (somehow) in a different scope, or as a built-in.
2935 	     If this is the first time this has happened, warn;
2936 	     then recycle the old declaration but with the new type.  */
2937 	  if (!C_DECL_IMPLICIT (decl))
2938 	    {
2939 	      implicit_decl_warning (functionid, decl);
2940 	      C_DECL_IMPLICIT (decl) = 1;
2941 	    }
2942 	  if (DECL_BUILT_IN (decl))
2943 	    {
2944 	      newtype = build_type_attribute_variant (newtype,
2945 						      TYPE_ATTRIBUTES
2946 						      (TREE_TYPE (decl)));
2947 	      if (!comptypes (newtype, TREE_TYPE (decl)))
2948 		{
2949 		  warning_at (loc, 0, "incompatible implicit declaration of "
2950 			      "built-in function %qD", decl);
2951 		  newtype = TREE_TYPE (decl);
2952 		}
2953 	    }
2954 	  else
2955 	    {
2956 	      if (!comptypes (newtype, TREE_TYPE (decl)))
2957 		{
2958 		  error_at (loc, "incompatible implicit declaration of function %qD", decl);
2959 		  locate_old_decl (decl);
2960 		}
2961 	    }
2962 	  b->u.type = TREE_TYPE (decl);
2963 	  TREE_TYPE (decl) = newtype;
2964 	  bind (functionid, decl, current_scope,
2965 		/*invisible=*/false, /*nested=*/true,
2966 		DECL_SOURCE_LOCATION (decl));
2967 	  return decl;
2968 	}
2969     }
2970 
2971   /* Not seen before.  */
2972   decl = build_decl (loc, FUNCTION_DECL, functionid, default_function_type);
2973   DECL_EXTERNAL (decl) = 1;
2974   TREE_PUBLIC (decl) = 1;
2975   C_DECL_IMPLICIT (decl) = 1;
2976   implicit_decl_warning (functionid, 0);
2977   asmspec_tree = maybe_apply_renaming_pragma (decl, /*asmname=*/NULL);
2978   if (asmspec_tree)
2979     set_user_assembler_name (decl, TREE_STRING_POINTER (asmspec_tree));
2980 
2981   /* C89 says implicit declarations are in the innermost block.
2982      So we record the decl in the standard fashion.  */
2983   decl = pushdecl (decl);
2984 
2985   /* No need to call objc_check_decl here - it's a function type.  */
2986   rest_of_decl_compilation (decl, 0, 0);
2987 
2988   /* Write a record describing this implicit function declaration
2989      to the prototypes file (if requested).  */
2990   gen_aux_info_record (decl, 0, 1, 0);
2991 
2992   /* Possibly apply some default attributes to this implicit declaration.  */
2993   decl_attributes (&decl, NULL_TREE, 0);
2994 
2995   return decl;
2996 }
2997 
2998 /* Issue an error message for a reference to an undeclared variable
2999    ID, including a reference to a builtin outside of function-call
3000    context.  Establish a binding of the identifier to error_mark_node
3001    in an appropriate scope, which will suppress further errors for the
3002    same identifier.  The error message should be given location LOC.  */
3003 void
3004 undeclared_variable (location_t loc, tree id)
3005 {
3006   static bool already = false;
3007   struct c_scope *scope;
3008 
3009   if (current_function_decl == 0)
3010     {
3011       error_at (loc, "%qE undeclared here (not in a function)", id);
3012       scope = current_scope;
3013     }
3014   else
3015     {
3016       if (!objc_diagnose_private_ivar (id))
3017         error_at (loc, "%qE undeclared (first use in this function)", id);
3018       if (!already)
3019 	{
3020           inform (loc, "each undeclared identifier is reported only"
3021                   " once for each function it appears in");
3022 	  already = true;
3023 	}
3024 
3025       /* If we are parsing old-style parameter decls, current_function_decl
3026 	 will be nonnull but current_function_scope will be null.  */
3027       scope = current_function_scope ? current_function_scope : current_scope;
3028     }
3029   bind (id, error_mark_node, scope, /*invisible=*/false, /*nested=*/false,
3030 	UNKNOWN_LOCATION);
3031 }
3032 
3033 /* Subroutine of lookup_label, declare_label, define_label: construct a
3034    LABEL_DECL with all the proper frills.  Also create a struct
3035    c_label_vars initialized for the current scope.  */
3036 
3037 static tree
3038 make_label (location_t location, tree name, bool defining,
3039 	    struct c_label_vars **p_label_vars)
3040 {
3041   tree label = build_decl (location, LABEL_DECL, name, void_type_node);
3042   struct c_label_vars *label_vars;
3043 
3044   DECL_CONTEXT (label) = current_function_decl;
3045   DECL_MODE (label) = VOIDmode;
3046 
3047   label_vars = ggc_alloc_c_label_vars ();
3048   label_vars->shadowed = NULL;
3049   set_spot_bindings (&label_vars->label_bindings, defining);
3050   label_vars->decls_in_scope = make_tree_vector ();
3051   label_vars->gotos = NULL;
3052   *p_label_vars = label_vars;
3053 
3054   return label;
3055 }
3056 
3057 /* Get the LABEL_DECL corresponding to identifier NAME as a label.
3058    Create one if none exists so far for the current function.
3059    This is called when a label is used in a goto expression or
3060    has its address taken.  */
3061 
3062 tree
3063 lookup_label (tree name)
3064 {
3065   tree label;
3066   struct c_label_vars *label_vars;
3067 
3068   if (current_function_scope == 0)
3069     {
3070       error ("label %qE referenced outside of any function", name);
3071       return 0;
3072     }
3073 
3074   /* Use a label already defined or ref'd with this name, but not if
3075      it is inherited from a containing function and wasn't declared
3076      using __label__.  */
3077   label = I_LABEL_DECL (name);
3078   if (label && (DECL_CONTEXT (label) == current_function_decl
3079 		|| C_DECLARED_LABEL_FLAG (label)))
3080     {
3081       /* If the label has only been declared, update its apparent
3082 	 location to point here, for better diagnostics if it
3083 	 turns out not to have been defined.  */
3084       if (DECL_INITIAL (label) == NULL_TREE)
3085 	DECL_SOURCE_LOCATION (label) = input_location;
3086       return label;
3087     }
3088 
3089   /* No label binding for that identifier; make one.  */
3090   label = make_label (input_location, name, false, &label_vars);
3091 
3092   /* Ordinary labels go in the current function scope.  */
3093   bind_label (name, label, current_function_scope, label_vars);
3094 
3095   return label;
3096 }
3097 
3098 /* Issue a warning about DECL for a goto statement at GOTO_LOC going
3099    to LABEL.  */
3100 
3101 static void
3102 warn_about_goto (location_t goto_loc, tree label, tree decl)
3103 {
3104   if (variably_modified_type_p (TREE_TYPE (decl), NULL_TREE))
3105     error_at (goto_loc,
3106 	      "jump into scope of identifier with variably modified type");
3107   else
3108     warning_at (goto_loc, OPT_Wjump_misses_init,
3109 		"jump skips variable initialization");
3110   inform (DECL_SOURCE_LOCATION (label), "label %qD defined here", label);
3111   inform (DECL_SOURCE_LOCATION (decl), "%qD declared here", decl);
3112 }
3113 
3114 /* Look up a label because of a goto statement.  This is like
3115    lookup_label, but also issues any appropriate warnings.  */
3116 
3117 tree
3118 lookup_label_for_goto (location_t loc, tree name)
3119 {
3120   tree label;
3121   struct c_label_vars *label_vars;
3122   unsigned int ix;
3123   tree decl;
3124 
3125   label = lookup_label (name);
3126   if (label == NULL_TREE)
3127     return NULL_TREE;
3128 
3129   /* If we are jumping to a different function, we can't issue any
3130      useful warnings.  */
3131   if (DECL_CONTEXT (label) != current_function_decl)
3132     {
3133       gcc_assert (C_DECLARED_LABEL_FLAG (label));
3134       return label;
3135     }
3136 
3137   label_vars = I_LABEL_BINDING (name)->u.label;
3138 
3139   /* If the label has not yet been defined, then push this goto on a
3140      list for possible later warnings.  */
3141   if (label_vars->label_bindings.scope == NULL)
3142     {
3143       struct c_goto_bindings *g;
3144 
3145       g = ggc_alloc_c_goto_bindings ();
3146       g->loc = loc;
3147       set_spot_bindings (&g->goto_bindings, true);
3148       vec_safe_push (label_vars->gotos, g);
3149       return label;
3150     }
3151 
3152   /* If there are any decls in label_vars->decls_in_scope, then this
3153      goto has missed the declaration of the decl.  This happens for a
3154      case like
3155        int i = 1;
3156       lab:
3157        ...
3158        goto lab;
3159      Issue a warning or error.  */
3160   FOR_EACH_VEC_SAFE_ELT (label_vars->decls_in_scope, ix, decl)
3161     warn_about_goto (loc, label, decl);
3162 
3163   if (label_vars->label_bindings.left_stmt_expr)
3164     {
3165       error_at (loc, "jump into statement expression");
3166       inform (DECL_SOURCE_LOCATION (label), "label %qD defined here", label);
3167     }
3168 
3169   return label;
3170 }
3171 
3172 /* Make a label named NAME in the current function, shadowing silently
3173    any that may be inherited from containing functions or containing
3174    scopes.  This is called for __label__ declarations.  */
3175 
3176 tree
3177 declare_label (tree name)
3178 {
3179   struct c_binding *b = I_LABEL_BINDING (name);
3180   tree label;
3181   struct c_label_vars *label_vars;
3182 
3183   /* Check to make sure that the label hasn't already been declared
3184      at this scope */
3185   if (b && B_IN_CURRENT_SCOPE (b))
3186     {
3187       error ("duplicate label declaration %qE", name);
3188       locate_old_decl (b->decl);
3189 
3190       /* Just use the previous declaration.  */
3191       return b->decl;
3192     }
3193 
3194   label = make_label (input_location, name, false, &label_vars);
3195   C_DECLARED_LABEL_FLAG (label) = 1;
3196 
3197   /* Declared labels go in the current scope.  */
3198   bind_label (name, label, current_scope, label_vars);
3199 
3200   return label;
3201 }
3202 
3203 /* When we define a label, issue any appropriate warnings if there are
3204    any gotos earlier in the function which jump to this label.  */
3205 
3206 static void
3207 check_earlier_gotos (tree label, struct c_label_vars* label_vars)
3208 {
3209   unsigned int ix;
3210   struct c_goto_bindings *g;
3211 
3212   FOR_EACH_VEC_SAFE_ELT (label_vars->gotos, ix, g)
3213     {
3214       struct c_binding *b;
3215       struct c_scope *scope;
3216 
3217       /* We have a goto to this label.  The goto is going forward.  In
3218 	 g->scope, the goto is going to skip any binding which was
3219 	 defined after g->bindings_in_scope.  */
3220       if (g->goto_bindings.scope->has_jump_unsafe_decl)
3221 	{
3222 	  for (b = g->goto_bindings.scope->bindings;
3223 	       b != g->goto_bindings.bindings_in_scope;
3224 	       b = b->prev)
3225 	    {
3226 	      if (decl_jump_unsafe (b->decl))
3227 		warn_about_goto (g->loc, label, b->decl);
3228 	    }
3229 	}
3230 
3231       /* We also need to warn about decls defined in any scopes
3232 	 between the scope of the label and the scope of the goto.  */
3233       for (scope = label_vars->label_bindings.scope;
3234 	   scope != g->goto_bindings.scope;
3235 	   scope = scope->outer)
3236 	{
3237 	  gcc_assert (scope != NULL);
3238 	  if (scope->has_jump_unsafe_decl)
3239 	    {
3240 	      if (scope == label_vars->label_bindings.scope)
3241 		b = label_vars->label_bindings.bindings_in_scope;
3242 	      else
3243 		b = scope->bindings;
3244 	      for (; b != NULL; b = b->prev)
3245 		{
3246 		  if (decl_jump_unsafe (b->decl))
3247 		    warn_about_goto (g->loc, label, b->decl);
3248 		}
3249 	    }
3250 	}
3251 
3252       if (g->goto_bindings.stmt_exprs > 0)
3253 	{
3254 	  error_at (g->loc, "jump into statement expression");
3255 	  inform (DECL_SOURCE_LOCATION (label), "label %qD defined here",
3256 		  label);
3257 	}
3258     }
3259 
3260   /* Now that the label is defined, we will issue warnings about
3261      subsequent gotos to this label when we see them.  */
3262   vec_safe_truncate (label_vars->gotos, 0);
3263   label_vars->gotos = NULL;
3264 }
3265 
3266 /* Define a label, specifying the location in the source file.
3267    Return the LABEL_DECL node for the label, if the definition is valid.
3268    Otherwise return 0.  */
3269 
3270 tree
3271 define_label (location_t location, tree name)
3272 {
3273   /* Find any preexisting label with this name.  It is an error
3274      if that label has already been defined in this function, or
3275      if there is a containing function with a declared label with
3276      the same name.  */
3277   tree label = I_LABEL_DECL (name);
3278 
3279   if (label
3280       && ((DECL_CONTEXT (label) == current_function_decl
3281 	   && DECL_INITIAL (label) != 0)
3282 	  || (DECL_CONTEXT (label) != current_function_decl
3283 	      && C_DECLARED_LABEL_FLAG (label))))
3284     {
3285       error_at (location, "duplicate label %qD", label);
3286       locate_old_decl (label);
3287       return 0;
3288     }
3289   else if (label && DECL_CONTEXT (label) == current_function_decl)
3290     {
3291       struct c_label_vars *label_vars = I_LABEL_BINDING (name)->u.label;
3292 
3293       /* The label has been used or declared already in this function,
3294 	 but not defined.  Update its location to point to this
3295 	 definition.  */
3296       DECL_SOURCE_LOCATION (label) = location;
3297       set_spot_bindings (&label_vars->label_bindings, true);
3298 
3299       /* Issue warnings as required about any goto statements from
3300 	 earlier in the function.  */
3301       check_earlier_gotos (label, label_vars);
3302     }
3303   else
3304     {
3305       struct c_label_vars *label_vars;
3306 
3307       /* No label binding for that identifier; make one.  */
3308       label = make_label (location, name, true, &label_vars);
3309 
3310       /* Ordinary labels go in the current function scope.  */
3311       bind_label (name, label, current_function_scope, label_vars);
3312     }
3313 
3314   if (!in_system_header && lookup_name (name))
3315     warning_at (location, OPT_Wtraditional,
3316 		"traditional C lacks a separate namespace "
3317 		"for labels, identifier %qE conflicts", name);
3318 
3319   /* Mark label as having been defined.  */
3320   DECL_INITIAL (label) = error_mark_node;
3321   return label;
3322 }
3323 
3324 /* Get the bindings for a new switch statement.  This is used to issue
3325    warnings as appropriate for jumps from the switch to case or
3326    default labels.  */
3327 
3328 struct c_spot_bindings *
3329 c_get_switch_bindings (void)
3330 {
3331   struct c_spot_bindings *switch_bindings;
3332 
3333   switch_bindings = XNEW (struct c_spot_bindings);
3334   set_spot_bindings (switch_bindings, true);
3335   return switch_bindings;
3336 }
3337 
3338 void
3339 c_release_switch_bindings (struct c_spot_bindings *bindings)
3340 {
3341   gcc_assert (bindings->stmt_exprs == 0 && !bindings->left_stmt_expr);
3342   XDELETE (bindings);
3343 }
3344 
3345 /* This is called at the point of a case or default label to issue
3346    warnings about decls as needed.  It returns true if it found an
3347    error, not just a warning.  */
3348 
3349 bool
3350 c_check_switch_jump_warnings (struct c_spot_bindings *switch_bindings,
3351 			      location_t switch_loc, location_t case_loc)
3352 {
3353   bool saw_error;
3354   struct c_scope *scope;
3355 
3356   saw_error = false;
3357   for (scope = current_scope;
3358        scope != switch_bindings->scope;
3359        scope = scope->outer)
3360     {
3361       struct c_binding *b;
3362 
3363       gcc_assert (scope != NULL);
3364 
3365       if (!scope->has_jump_unsafe_decl)
3366 	continue;
3367 
3368       for (b = scope->bindings; b != NULL; b = b->prev)
3369 	{
3370 	  if (decl_jump_unsafe (b->decl))
3371 	    {
3372 	      if (variably_modified_type_p (TREE_TYPE (b->decl), NULL_TREE))
3373 		{
3374 		  saw_error = true;
3375 		  error_at (case_loc,
3376 			    ("switch jumps into scope of identifier with "
3377 			     "variably modified type"));
3378 		}
3379 	      else
3380 		warning_at (case_loc, OPT_Wjump_misses_init,
3381 			    "switch jumps over variable initialization");
3382 	      inform (switch_loc, "switch starts here");
3383 	      inform (DECL_SOURCE_LOCATION (b->decl), "%qD declared here",
3384 		      b->decl);
3385 	    }
3386 	}
3387     }
3388 
3389   if (switch_bindings->stmt_exprs > 0)
3390     {
3391       saw_error = true;
3392       error_at (case_loc, "switch jumps into statement expression");
3393       inform (switch_loc, "switch starts here");
3394     }
3395 
3396   return saw_error;
3397 }
3398 
3399 /* Given NAME, an IDENTIFIER_NODE,
3400    return the structure (or union or enum) definition for that name.
3401    If THISLEVEL_ONLY is nonzero, searches only the current_scope.
3402    CODE says which kind of type the caller wants;
3403    it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
3404    If PLOC is not NULL and this returns non-null, it sets *PLOC to the
3405    location where the tag was defined.
3406    If the wrong kind of type is found, an error is reported.  */
3407 
3408 static tree
3409 lookup_tag (enum tree_code code, tree name, int thislevel_only,
3410 	    location_t *ploc)
3411 {
3412   struct c_binding *b = I_TAG_BINDING (name);
3413   int thislevel = 0;
3414 
3415   if (!b || !b->decl)
3416     return 0;
3417 
3418   /* We only care about whether it's in this level if
3419      thislevel_only was set or it might be a type clash.  */
3420   if (thislevel_only || TREE_CODE (b->decl) != code)
3421     {
3422       /* For our purposes, a tag in the external scope is the same as
3423 	 a tag in the file scope.  (Primarily relevant to Objective-C
3424 	 and its builtin structure tags, which get pushed before the
3425 	 file scope is created.)  */
3426       if (B_IN_CURRENT_SCOPE (b)
3427 	  || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b)))
3428 	thislevel = 1;
3429     }
3430 
3431   if (thislevel_only && !thislevel)
3432     return 0;
3433 
3434   if (TREE_CODE (b->decl) != code)
3435     {
3436       /* Definition isn't the kind we were looking for.  */
3437       pending_invalid_xref = name;
3438       pending_invalid_xref_location = input_location;
3439 
3440       /* If in the same binding level as a declaration as a tag
3441 	 of a different type, this must not be allowed to
3442 	 shadow that tag, so give the error immediately.
3443 	 (For example, "struct foo; union foo;" is invalid.)  */
3444       if (thislevel)
3445 	pending_xref_error ();
3446     }
3447 
3448   if (ploc != NULL)
3449     *ploc = b->locus;
3450 
3451   return b->decl;
3452 }
3453 
3454 /* Print an error message now
3455    for a recent invalid struct, union or enum cross reference.
3456    We don't print them immediately because they are not invalid
3457    when used in the `struct foo;' construct for shadowing.  */
3458 
3459 void
3460 pending_xref_error (void)
3461 {
3462   if (pending_invalid_xref != 0)
3463     error_at (pending_invalid_xref_location, "%qE defined as wrong kind of tag",
3464 	      pending_invalid_xref);
3465   pending_invalid_xref = 0;
3466 }
3467 
3468 
3469 /* Look up NAME in the current scope and its superiors
3470    in the namespace of variables, functions and typedefs.
3471    Return a ..._DECL node of some kind representing its definition,
3472    or return 0 if it is undefined.  */
3473 
3474 tree
3475 lookup_name (tree name)
3476 {
3477   struct c_binding *b = I_SYMBOL_BINDING (name);
3478   if (b && !b->invisible)
3479     {
3480       maybe_record_typedef_use (b->decl);
3481       return b->decl;
3482     }
3483   return 0;
3484 }
3485 
3486 /* Similar to `lookup_name' but look only at the indicated scope.  */
3487 
3488 static tree
3489 lookup_name_in_scope (tree name, struct c_scope *scope)
3490 {
3491   struct c_binding *b;
3492 
3493   for (b = I_SYMBOL_BINDING (name); b; b = b->shadowed)
3494     if (B_IN_SCOPE (b, scope))
3495       return b->decl;
3496   return 0;
3497 }
3498 
3499 /* Create the predefined scalar types of C,
3500    and some nodes representing standard constants (0, 1, (void *) 0).
3501    Initialize the global scope.
3502    Make definitions for built-in primitive functions.  */
3503 
3504 void
3505 c_init_decl_processing (void)
3506 {
3507   location_t save_loc = input_location;
3508 
3509   /* Initialize reserved words for parser.  */
3510   c_parse_init ();
3511 
3512   current_function_decl = 0;
3513 
3514   gcc_obstack_init (&parser_obstack);
3515 
3516   /* Make the externals scope.  */
3517   push_scope ();
3518   external_scope = current_scope;
3519 
3520   /* Declarations from c_common_nodes_and_builtins must not be associated
3521      with this input file, lest we get differences between using and not
3522      using preprocessed headers.  */
3523   input_location = BUILTINS_LOCATION;
3524 
3525   c_common_nodes_and_builtins ();
3526 
3527   /* In C, comparisons and TRUTH_* expressions have type int.  */
3528   truthvalue_type_node = integer_type_node;
3529   truthvalue_true_node = integer_one_node;
3530   truthvalue_false_node = integer_zero_node;
3531 
3532   /* Even in C99, which has a real boolean type.  */
3533   pushdecl (build_decl (UNKNOWN_LOCATION, TYPE_DECL, get_identifier ("_Bool"),
3534 			boolean_type_node));
3535 
3536   input_location = save_loc;
3537 
3538   pedantic_lvalues = true;
3539 
3540   make_fname_decl = c_make_fname_decl;
3541   start_fname_decls ();
3542 }
3543 
3544 /* Create the VAR_DECL at LOC for __FUNCTION__ etc. ID is the name to
3545    give the decl, NAME is the initialization string and TYPE_DEP
3546    indicates whether NAME depended on the type of the function.  As we
3547    don't yet implement delayed emission of static data, we mark the
3548    decl as emitted so it is not placed in the output.  Anything using
3549    it must therefore pull out the STRING_CST initializer directly.
3550    FIXME.  */
3551 
3552 static tree
3553 c_make_fname_decl (location_t loc, tree id, int type_dep)
3554 {
3555   const char *name = fname_as_string (type_dep);
3556   tree decl, type, init;
3557   size_t length = strlen (name);
3558 
3559   type = build_array_type (char_type_node,
3560 			   build_index_type (size_int (length)));
3561   type = c_build_qualified_type (type, TYPE_QUAL_CONST);
3562 
3563   decl = build_decl (loc, VAR_DECL, id, type);
3564 
3565   TREE_STATIC (decl) = 1;
3566   TREE_READONLY (decl) = 1;
3567   DECL_ARTIFICIAL (decl) = 1;
3568 
3569   init = build_string (length + 1, name);
3570   free (CONST_CAST (char *, name));
3571   TREE_TYPE (init) = type;
3572   DECL_INITIAL (decl) = init;
3573 
3574   TREE_USED (decl) = 1;
3575 
3576   if (current_function_decl
3577       /* For invalid programs like this:
3578 
3579          void foo()
3580          const char* p = __FUNCTION__;
3581 
3582 	 the __FUNCTION__ is believed to appear in K&R style function
3583 	 parameter declarator.  In that case we still don't have
3584 	 function_scope.  */
3585       && (!seen_error () || current_function_scope))
3586     {
3587       DECL_CONTEXT (decl) = current_function_decl;
3588       bind (id, decl, current_function_scope,
3589 	    /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION);
3590     }
3591 
3592   finish_decl (decl, loc, init, NULL_TREE, NULL_TREE);
3593 
3594   return decl;
3595 }
3596 
3597 tree
3598 c_builtin_function (tree decl)
3599 {
3600   tree type = TREE_TYPE (decl);
3601   tree   id = DECL_NAME (decl);
3602 
3603   const char *name = IDENTIFIER_POINTER (id);
3604   C_DECL_BUILTIN_PROTOTYPE (decl) = prototype_p (type);
3605 
3606   /* Should never be called on a symbol with a preexisting meaning.  */
3607   gcc_assert (!I_SYMBOL_BINDING (id));
3608 
3609   bind (id, decl, external_scope, /*invisible=*/true, /*nested=*/false,
3610 	UNKNOWN_LOCATION);
3611 
3612   /* Builtins in the implementation namespace are made visible without
3613      needing to be explicitly declared.  See push_file_scope.  */
3614   if (name[0] == '_' && (name[1] == '_' || ISUPPER (name[1])))
3615     {
3616       DECL_CHAIN (decl) = visible_builtins;
3617       visible_builtins = decl;
3618     }
3619 
3620   return decl;
3621 }
3622 
3623 tree
3624 c_builtin_function_ext_scope (tree decl)
3625 {
3626   tree type = TREE_TYPE (decl);
3627   tree   id = DECL_NAME (decl);
3628 
3629   const char *name = IDENTIFIER_POINTER (id);
3630   C_DECL_BUILTIN_PROTOTYPE (decl) = prototype_p (type);
3631 
3632   /* Should never be called on a symbol with a preexisting meaning.  */
3633   gcc_assert (!I_SYMBOL_BINDING (id));
3634 
3635   bind (id, decl, external_scope, /*invisible=*/false, /*nested=*/false,
3636 	UNKNOWN_LOCATION);
3637 
3638   /* Builtins in the implementation namespace are made visible without
3639      needing to be explicitly declared.  See push_file_scope.  */
3640   if (name[0] == '_' && (name[1] == '_' || ISUPPER (name[1])))
3641     {
3642       DECL_CHAIN (decl) = visible_builtins;
3643       visible_builtins = decl;
3644     }
3645 
3646   return decl;
3647 }
3648 
3649 /* Called when a declaration is seen that contains no names to declare.
3650    If its type is a reference to a structure, union or enum inherited
3651    from a containing scope, shadow that tag name for the current scope
3652    with a forward reference.
3653    If its type defines a new named structure or union
3654    or defines an enum, it is valid but we need not do anything here.
3655    Otherwise, it is an error.  */
3656 
3657 void
3658 shadow_tag (const struct c_declspecs *declspecs)
3659 {
3660   shadow_tag_warned (declspecs, 0);
3661 }
3662 
3663 /* WARNED is 1 if we have done a pedwarn, 2 if we have done a warning,
3664    but no pedwarn.  */
3665 void
3666 shadow_tag_warned (const struct c_declspecs *declspecs, int warned)
3667 {
3668   bool found_tag = false;
3669 
3670   if (declspecs->type && !declspecs->default_int_p && !declspecs->typedef_p)
3671     {
3672       tree value = declspecs->type;
3673       enum tree_code code = TREE_CODE (value);
3674 
3675       if (code == RECORD_TYPE || code == UNION_TYPE || code == ENUMERAL_TYPE)
3676 	/* Used to test also that TYPE_SIZE (value) != 0.
3677 	   That caused warning for `struct foo;' at top level in the file.  */
3678 	{
3679 	  tree name = TYPE_NAME (value);
3680 	  tree t;
3681 
3682 	  found_tag = true;
3683 
3684 	  if (declspecs->restrict_p)
3685 	    {
3686 	      error ("invalid use of %<restrict%>");
3687 	      warned = 1;
3688 	    }
3689 
3690 	  if (name == 0)
3691 	    {
3692 	      if (warned != 1 && code != ENUMERAL_TYPE)
3693 		/* Empty unnamed enum OK */
3694 		{
3695 		  pedwarn (input_location, 0,
3696 			   "unnamed struct/union that defines no instances");
3697 		  warned = 1;
3698 		}
3699 	    }
3700 	  else if (declspecs->typespec_kind != ctsk_tagdef
3701                    && declspecs->typespec_kind != ctsk_tagfirstref
3702 		   && declspecs->storage_class != csc_none)
3703 	    {
3704 	      if (warned != 1)
3705 		pedwarn (input_location, 0,
3706 			 "empty declaration with storage class specifier "
3707 			 "does not redeclare tag");
3708 	      warned = 1;
3709 	      pending_xref_error ();
3710 	    }
3711 	  else if (declspecs->typespec_kind != ctsk_tagdef
3712                    && declspecs->typespec_kind != ctsk_tagfirstref
3713 		   && (declspecs->const_p
3714 		       || declspecs->volatile_p
3715 		       || declspecs->restrict_p
3716 		       || declspecs->address_space))
3717 	    {
3718 	      if (warned != 1)
3719 		pedwarn (input_location, 0,
3720 			 "empty declaration with type qualifier "
3721 			  "does not redeclare tag");
3722 	      warned = 1;
3723 	      pending_xref_error ();
3724 	    }
3725 	  else if (declspecs->typespec_kind != ctsk_tagdef
3726                    && declspecs->typespec_kind != ctsk_tagfirstref
3727 		   && declspecs->alignas_p)
3728 	    {
3729 	      if (warned != 1)
3730 		pedwarn (input_location, 0,
3731 			 "empty declaration with %<_Alignas%> "
3732 			  "does not redeclare tag");
3733 	      warned = 1;
3734 	      pending_xref_error ();
3735 	    }
3736 	  else
3737 	    {
3738 	      pending_invalid_xref = 0;
3739 	      t = lookup_tag (code, name, 1, NULL);
3740 
3741 	      if (t == 0)
3742 		{
3743 		  t = make_node (code);
3744 		  pushtag (input_location, name, t);
3745 		}
3746 	    }
3747 	}
3748       else
3749 	{
3750 	  if (warned != 1 && !in_system_header)
3751 	    {
3752 	      pedwarn (input_location, 0,
3753 		       "useless type name in empty declaration");
3754 	      warned = 1;
3755 	    }
3756 	}
3757     }
3758   else if (warned != 1 && !in_system_header && declspecs->typedef_p)
3759     {
3760       pedwarn (input_location, 0, "useless type name in empty declaration");
3761       warned = 1;
3762     }
3763 
3764   pending_invalid_xref = 0;
3765 
3766   if (declspecs->inline_p)
3767     {
3768       error ("%<inline%> in empty declaration");
3769       warned = 1;
3770     }
3771 
3772   if (declspecs->noreturn_p)
3773     {
3774       error ("%<_Noreturn%> in empty declaration");
3775       warned = 1;
3776     }
3777 
3778   if (current_scope == file_scope && declspecs->storage_class == csc_auto)
3779     {
3780       error ("%<auto%> in file-scope empty declaration");
3781       warned = 1;
3782     }
3783 
3784   if (current_scope == file_scope && declspecs->storage_class == csc_register)
3785     {
3786       error ("%<register%> in file-scope empty declaration");
3787       warned = 1;
3788     }
3789 
3790   if (!warned && !in_system_header && declspecs->storage_class != csc_none)
3791     {
3792       warning (0, "useless storage class specifier in empty declaration");
3793       warned = 2;
3794     }
3795 
3796   if (!warned && !in_system_header && declspecs->thread_p)
3797     {
3798       warning (0, "useless %<__thread%> in empty declaration");
3799       warned = 2;
3800     }
3801 
3802   if (!warned && !in_system_header && (declspecs->const_p
3803 				       || declspecs->volatile_p
3804 				       || declspecs->restrict_p
3805 				       || declspecs->address_space))
3806     {
3807       warning (0, "useless type qualifier in empty declaration");
3808       warned = 2;
3809     }
3810 
3811   if (!warned && !in_system_header && declspecs->alignas_p)
3812     {
3813       warning (0, "useless %<_Alignas%> in empty declaration");
3814       warned = 2;
3815     }
3816 
3817   if (warned != 1)
3818     {
3819       if (!found_tag)
3820 	pedwarn (input_location, 0, "empty declaration");
3821     }
3822 }
3823 
3824 
3825 /* Return the qualifiers from SPECS as a bitwise OR of TYPE_QUAL_*
3826    bits.  SPECS represents declaration specifiers that the grammar
3827    only permits to contain type qualifiers and attributes.  */
3828 
3829 int
3830 quals_from_declspecs (const struct c_declspecs *specs)
3831 {
3832   int quals = ((specs->const_p ? TYPE_QUAL_CONST : 0)
3833 	       | (specs->volatile_p ? TYPE_QUAL_VOLATILE : 0)
3834 	       | (specs->restrict_p ? TYPE_QUAL_RESTRICT : 0)
3835 	       | (ENCODE_QUAL_ADDR_SPACE (specs->address_space)));
3836   gcc_assert (!specs->type
3837 	      && !specs->decl_attr
3838 	      && specs->typespec_word == cts_none
3839 	      && specs->storage_class == csc_none
3840 	      && !specs->typedef_p
3841 	      && !specs->explicit_signed_p
3842 	      && !specs->deprecated_p
3843 	      && !specs->long_p
3844 	      && !specs->long_long_p
3845 	      && !specs->short_p
3846 	      && !specs->signed_p
3847 	      && !specs->unsigned_p
3848 	      && !specs->complex_p
3849 	      && !specs->inline_p
3850 	      && !specs->noreturn_p
3851 	      && !specs->thread_p);
3852   return quals;
3853 }
3854 
3855 /* Construct an array declarator.  LOC is the location of the
3856    beginning of the array (usually the opening brace).  EXPR is the
3857    expression inside [], or NULL_TREE.  QUALS are the type qualifiers
3858    inside the [] (to be applied to the pointer to which a parameter
3859    array is converted).  STATIC_P is true if "static" is inside the
3860    [], false otherwise.  VLA_UNSPEC_P is true if the array is [*], a
3861    VLA of unspecified length which is nevertheless a complete type,
3862    false otherwise.  The field for the contained declarator is left to
3863    be filled in by set_array_declarator_inner.  */
3864 
3865 struct c_declarator *
3866 build_array_declarator (location_t loc,
3867 			tree expr, struct c_declspecs *quals, bool static_p,
3868 			bool vla_unspec_p)
3869 {
3870   struct c_declarator *declarator = XOBNEW (&parser_obstack,
3871 					    struct c_declarator);
3872   declarator->id_loc = loc;
3873   declarator->kind = cdk_array;
3874   declarator->declarator = 0;
3875   declarator->u.array.dimen = expr;
3876   if (quals)
3877     {
3878       declarator->u.array.attrs = quals->attrs;
3879       declarator->u.array.quals = quals_from_declspecs (quals);
3880     }
3881   else
3882     {
3883       declarator->u.array.attrs = NULL_TREE;
3884       declarator->u.array.quals = 0;
3885     }
3886   declarator->u.array.static_p = static_p;
3887   declarator->u.array.vla_unspec_p = vla_unspec_p;
3888   if (!flag_isoc99)
3889     {
3890       if (static_p || quals != NULL)
3891 	pedwarn (loc, OPT_Wpedantic,
3892 		 "ISO C90 does not support %<static%> or type "
3893 		 "qualifiers in parameter array declarators");
3894       if (vla_unspec_p)
3895 	pedwarn (loc, OPT_Wpedantic,
3896 		 "ISO C90 does not support %<[*]%> array declarators");
3897     }
3898   if (vla_unspec_p)
3899     {
3900       if (!current_scope->parm_flag)
3901 	{
3902 	  /* C99 6.7.5.2p4 */
3903 	  error_at (loc, "%<[*]%> not allowed in other than "
3904 		    "function prototype scope");
3905 	  declarator->u.array.vla_unspec_p = false;
3906 	  return NULL;
3907 	}
3908       current_scope->had_vla_unspec = true;
3909     }
3910   return declarator;
3911 }
3912 
3913 /* Set the contained declarator of an array declarator.  DECL is the
3914    declarator, as constructed by build_array_declarator; INNER is what
3915    appears on the left of the [].  */
3916 
3917 struct c_declarator *
3918 set_array_declarator_inner (struct c_declarator *decl,
3919 			    struct c_declarator *inner)
3920 {
3921   decl->declarator = inner;
3922   return decl;
3923 }
3924 
3925 /* INIT is a constructor that forms DECL's initializer.  If the final
3926    element initializes a flexible array field, add the size of that
3927    initializer to DECL's size.  */
3928 
3929 static void
3930 add_flexible_array_elts_to_size (tree decl, tree init)
3931 {
3932   tree elt, type;
3933 
3934   if (vec_safe_is_empty (CONSTRUCTOR_ELTS (init)))
3935     return;
3936 
3937   elt = CONSTRUCTOR_ELTS (init)->last ().value;
3938   type = TREE_TYPE (elt);
3939   if (TREE_CODE (type) == ARRAY_TYPE
3940       && TYPE_SIZE (type) == NULL_TREE
3941       && TYPE_DOMAIN (type) != NULL_TREE
3942       && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE)
3943     {
3944       complete_array_type (&type, elt, false);
3945       DECL_SIZE (decl)
3946 	= size_binop (PLUS_EXPR, DECL_SIZE (decl), TYPE_SIZE (type));
3947       DECL_SIZE_UNIT (decl)
3948 	= size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl), TYPE_SIZE_UNIT (type));
3949     }
3950 }
3951 
3952 /* Decode a "typename", such as "int **", returning a ..._TYPE node.
3953    Set *EXPR, if EXPR not NULL, to any expression to be evaluated
3954    before the type name, and set *EXPR_CONST_OPERANDS, if
3955    EXPR_CONST_OPERANDS not NULL, to indicate whether the type name may
3956    appear in a constant expression.  */
3957 
3958 tree
3959 groktypename (struct c_type_name *type_name, tree *expr,
3960 	      bool *expr_const_operands)
3961 {
3962   tree type;
3963   tree attrs = type_name->specs->attrs;
3964 
3965   type_name->specs->attrs = NULL_TREE;
3966 
3967   type = grokdeclarator (type_name->declarator, type_name->specs, TYPENAME,
3968 			 false, NULL, &attrs, expr, expr_const_operands,
3969 			 DEPRECATED_NORMAL);
3970 
3971   /* Apply attributes.  */
3972   decl_attributes (&type, attrs, 0);
3973 
3974   return type;
3975 }
3976 
3977 /* Decode a declarator in an ordinary declaration or data definition.
3978    This is called as soon as the type information and variable name
3979    have been parsed, before parsing the initializer if any.
3980    Here we create the ..._DECL node, fill in its type,
3981    and put it on the list of decls for the current context.
3982    The ..._DECL node is returned as the value.
3983 
3984    Exception: for arrays where the length is not specified,
3985    the type is left null, to be filled in by `finish_decl'.
3986 
3987    Function definitions do not come here; they go to start_function
3988    instead.  However, external and forward declarations of functions
3989    do go through here.  Structure field declarations are done by
3990    grokfield and not through here.  */
3991 
3992 tree
3993 start_decl (struct c_declarator *declarator, struct c_declspecs *declspecs,
3994 	    bool initialized, tree attributes)
3995 {
3996   tree decl;
3997   tree tem;
3998   tree expr = NULL_TREE;
3999   enum deprecated_states deprecated_state = DEPRECATED_NORMAL;
4000 
4001   /* An object declared as __attribute__((deprecated)) suppresses
4002      warnings of uses of other deprecated items.  */
4003   if (lookup_attribute ("deprecated", attributes))
4004     deprecated_state = DEPRECATED_SUPPRESS;
4005 
4006   decl = grokdeclarator (declarator, declspecs,
4007 			 NORMAL, initialized, NULL, &attributes, &expr, NULL,
4008 			 deprecated_state);
4009   if (!decl)
4010     return 0;
4011 
4012   if (expr)
4013     add_stmt (fold_convert (void_type_node, expr));
4014 
4015   if (TREE_CODE (decl) != FUNCTION_DECL && MAIN_NAME_P (DECL_NAME (decl)))
4016     warning (OPT_Wmain, "%q+D is usually a function", decl);
4017 
4018   if (initialized)
4019     /* Is it valid for this decl to have an initializer at all?
4020        If not, set INITIALIZED to zero, which will indirectly
4021        tell 'finish_decl' to ignore the initializer once it is parsed.  */
4022     switch (TREE_CODE (decl))
4023       {
4024       case TYPE_DECL:
4025 	error ("typedef %qD is initialized (use __typeof__ instead)", decl);
4026 	initialized = 0;
4027 	break;
4028 
4029       case FUNCTION_DECL:
4030 	error ("function %qD is initialized like a variable", decl);
4031 	initialized = 0;
4032 	break;
4033 
4034       case PARM_DECL:
4035 	/* DECL_INITIAL in a PARM_DECL is really DECL_ARG_TYPE.  */
4036 	error ("parameter %qD is initialized", decl);
4037 	initialized = 0;
4038 	break;
4039 
4040       default:
4041 	/* Don't allow initializations for incomplete types except for
4042 	   arrays which might be completed by the initialization.  */
4043 
4044 	/* This can happen if the array size is an undefined macro.
4045 	   We already gave a warning, so we don't need another one.  */
4046 	if (TREE_TYPE (decl) == error_mark_node)
4047 	  initialized = 0;
4048 	else if (COMPLETE_TYPE_P (TREE_TYPE (decl)))
4049 	  {
4050 	    /* A complete type is ok if size is fixed.  */
4051 
4052 	    if (TREE_CODE (TYPE_SIZE (TREE_TYPE (decl))) != INTEGER_CST
4053 		|| C_DECL_VARIABLE_SIZE (decl))
4054 	      {
4055 		error ("variable-sized object may not be initialized");
4056 		initialized = 0;
4057 	      }
4058 	  }
4059 	else if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE)
4060 	  {
4061 	    error ("variable %qD has initializer but incomplete type", decl);
4062 	    initialized = 0;
4063 	  }
4064 	else if (C_DECL_VARIABLE_SIZE (decl))
4065 	  {
4066 	    /* Although C99 is unclear about whether incomplete arrays
4067 	       of VLAs themselves count as VLAs, it does not make
4068 	       sense to permit them to be initialized given that
4069 	       ordinary VLAs may not be initialized.  */
4070 	    error ("variable-sized object may not be initialized");
4071 	    initialized = 0;
4072 	  }
4073       }
4074 
4075   if (initialized)
4076     {
4077       if (current_scope == file_scope)
4078 	TREE_STATIC (decl) = 1;
4079 
4080       /* Tell 'pushdecl' this is an initialized decl
4081 	 even though we don't yet have the initializer expression.
4082 	 Also tell 'finish_decl' it may store the real initializer.  */
4083       DECL_INITIAL (decl) = error_mark_node;
4084     }
4085 
4086   /* If this is a function declaration, write a record describing it to the
4087      prototypes file (if requested).  */
4088 
4089   if (TREE_CODE (decl) == FUNCTION_DECL)
4090     gen_aux_info_record (decl, 0, 0, prototype_p (TREE_TYPE (decl)));
4091 
4092   /* ANSI specifies that a tentative definition which is not merged with
4093      a non-tentative definition behaves exactly like a definition with an
4094      initializer equal to zero.  (Section 3.7.2)
4095 
4096      -fno-common gives strict ANSI behavior, though this tends to break
4097      a large body of code that grew up without this rule.
4098 
4099      Thread-local variables are never common, since there's no entrenched
4100      body of code to break, and it allows more efficient variable references
4101      in the presence of dynamic linking.  */
4102 
4103   if (TREE_CODE (decl) == VAR_DECL
4104       && !initialized
4105       && TREE_PUBLIC (decl)
4106       && !DECL_THREAD_LOCAL_P (decl)
4107       && !flag_no_common)
4108     DECL_COMMON (decl) = 1;
4109 
4110   /* Set attributes here so if duplicate decl, will have proper attributes.  */
4111   decl_attributes (&decl, attributes, 0);
4112 
4113   /* Handle gnu_inline attribute.  */
4114   if (declspecs->inline_p
4115       && !flag_gnu89_inline
4116       && TREE_CODE (decl) == FUNCTION_DECL
4117       && (lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (decl))
4118 	  || current_function_decl))
4119     {
4120       if (declspecs->storage_class == csc_auto && current_scope != file_scope)
4121 	;
4122       else if (declspecs->storage_class != csc_static)
4123 	DECL_EXTERNAL (decl) = !DECL_EXTERNAL (decl);
4124     }
4125 
4126   if (TREE_CODE (decl) == FUNCTION_DECL
4127       && targetm.calls.promote_prototypes (TREE_TYPE (decl)))
4128     {
4129       struct c_declarator *ce = declarator;
4130 
4131       if (ce->kind == cdk_pointer)
4132 	ce = declarator->declarator;
4133       if (ce->kind == cdk_function)
4134 	{
4135 	  tree args = ce->u.arg_info->parms;
4136 	  for (; args; args = DECL_CHAIN (args))
4137 	    {
4138 	      tree type = TREE_TYPE (args);
4139 	      if (type && INTEGRAL_TYPE_P (type)
4140 		  && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
4141 		DECL_ARG_TYPE (args) = integer_type_node;
4142 	    }
4143 	}
4144     }
4145 
4146   if (TREE_CODE (decl) == FUNCTION_DECL
4147       && DECL_DECLARED_INLINE_P (decl)
4148       && DECL_UNINLINABLE (decl)
4149       && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
4150     warning (OPT_Wattributes, "inline function %q+D given attribute noinline",
4151 	     decl);
4152 
4153   /* C99 6.7.4p3: An inline definition of a function with external
4154      linkage shall not contain a definition of a modifiable object
4155      with static storage duration...  */
4156   if (TREE_CODE (decl) == VAR_DECL
4157       && current_scope != file_scope
4158       && TREE_STATIC (decl)
4159       && !TREE_READONLY (decl)
4160       && DECL_DECLARED_INLINE_P (current_function_decl)
4161       && DECL_EXTERNAL (current_function_decl))
4162     record_inline_static (input_location, current_function_decl,
4163 			  decl, csi_modifiable);
4164 
4165   if (c_dialect_objc ()
4166       && (TREE_CODE (decl) == VAR_DECL
4167           || TREE_CODE (decl) == FUNCTION_DECL))
4168       objc_check_global_decl (decl);
4169 
4170   /* Add this decl to the current scope.
4171      TEM may equal DECL or it may be a previous decl of the same name.  */
4172   tem = pushdecl (decl);
4173 
4174   if (initialized && DECL_EXTERNAL (tem))
4175     {
4176       DECL_EXTERNAL (tem) = 0;
4177       TREE_STATIC (tem) = 1;
4178     }
4179 
4180   return tem;
4181 }
4182 
4183 /* Subroutine of finish_decl. TYPE is the type of an uninitialized object
4184    DECL or the non-array element type if DECL is an uninitialized array.
4185    If that type has a const member, diagnose this. */
4186 
4187 static void
4188 diagnose_uninitialized_cst_member (tree decl, tree type)
4189 {
4190   tree field;
4191   for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4192     {
4193       tree field_type;
4194       if (TREE_CODE (field) != FIELD_DECL)
4195 	continue;
4196       field_type = strip_array_types (TREE_TYPE (field));
4197 
4198       if (TYPE_QUALS (field_type) & TYPE_QUAL_CONST)
4199       	{
4200 	  warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat,
4201 	  	      "uninitialized const member in %qT is invalid in C++",
4202 		      strip_array_types (TREE_TYPE (decl)));
4203 	  inform (DECL_SOURCE_LOCATION (field), "%qD should be initialized", field);
4204 	}
4205 
4206       if (TREE_CODE (field_type) == RECORD_TYPE
4207 	  || TREE_CODE (field_type) == UNION_TYPE)
4208 	diagnose_uninitialized_cst_member (decl, field_type);
4209     }
4210 }
4211 
4212 /* Finish processing of a declaration;
4213    install its initial value.
4214    If ORIGTYPE is not NULL_TREE, it is the original type of INIT.
4215    If the length of an array type is not known before,
4216    it must be determined now, from the initial value, or it is an error.
4217 
4218    INIT_LOC is the location of the initial value.  */
4219 
4220 void
4221 finish_decl (tree decl, location_t init_loc, tree init,
4222     	     tree origtype, tree asmspec_tree)
4223 {
4224   tree type;
4225   bool was_incomplete = (DECL_SIZE (decl) == 0);
4226   const char *asmspec = 0;
4227 
4228   /* If a name was specified, get the string.  */
4229   if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
4230       && DECL_FILE_SCOPE_P (decl))
4231     asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree);
4232   if (asmspec_tree)
4233     asmspec = TREE_STRING_POINTER (asmspec_tree);
4234 
4235   if (TREE_CODE (decl) == VAR_DECL
4236       && TREE_STATIC (decl)
4237       && global_bindings_p ())
4238     /* So decl is a global variable. Record the types it uses
4239        so that we can decide later to emit debug info for them.  */
4240     record_types_used_by_current_var_decl (decl);
4241 
4242   /* If `start_decl' didn't like having an initialization, ignore it now.  */
4243   if (init != 0 && DECL_INITIAL (decl) == 0)
4244     init = 0;
4245 
4246   /* Don't crash if parm is initialized.  */
4247   if (TREE_CODE (decl) == PARM_DECL)
4248     init = 0;
4249 
4250   if (init)
4251     store_init_value (init_loc, decl, init, origtype);
4252 
4253   if (c_dialect_objc () && (TREE_CODE (decl) == VAR_DECL
4254 			    || TREE_CODE (decl) == FUNCTION_DECL
4255 			    || TREE_CODE (decl) == FIELD_DECL))
4256     objc_check_decl (decl);
4257 
4258   type = TREE_TYPE (decl);
4259 
4260   /* Deduce size of array from initialization, if not already known.  */
4261   if (TREE_CODE (type) == ARRAY_TYPE
4262       && TYPE_DOMAIN (type) == 0
4263       && TREE_CODE (decl) != TYPE_DECL)
4264     {
4265       bool do_default
4266 	= (TREE_STATIC (decl)
4267 	   /* Even if pedantic, an external linkage array
4268 	      may have incomplete type at first.  */
4269 	   ? pedantic && !TREE_PUBLIC (decl)
4270 	   : !DECL_EXTERNAL (decl));
4271       int failure
4272 	= complete_array_type (&TREE_TYPE (decl), DECL_INITIAL (decl),
4273 			       do_default);
4274 
4275       /* Get the completed type made by complete_array_type.  */
4276       type = TREE_TYPE (decl);
4277 
4278       switch (failure)
4279 	{
4280 	case 1:
4281 	  error ("initializer fails to determine size of %q+D", decl);
4282 	  break;
4283 
4284 	case 2:
4285 	  if (do_default)
4286 	    error ("array size missing in %q+D", decl);
4287 	  /* If a `static' var's size isn't known,
4288 	     make it extern as well as static, so it does not get
4289 	     allocated.
4290 	     If it is not `static', then do not mark extern;
4291 	     finish_incomplete_decl will give it a default size
4292 	     and it will get allocated.  */
4293 	  else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
4294 	    DECL_EXTERNAL (decl) = 1;
4295 	  break;
4296 
4297 	case 3:
4298 	  error ("zero or negative size array %q+D", decl);
4299 	  break;
4300 
4301 	case 0:
4302 	  /* For global variables, update the copy of the type that
4303 	     exists in the binding.  */
4304 	  if (TREE_PUBLIC (decl))
4305 	    {
4306 	      struct c_binding *b_ext = I_SYMBOL_BINDING (DECL_NAME (decl));
4307 	      while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext))
4308 		b_ext = b_ext->shadowed;
4309 	      if (b_ext)
4310 		{
4311 		  if (b_ext->u.type && comptypes (b_ext->u.type, type))
4312 		    b_ext->u.type = composite_type (b_ext->u.type, type);
4313 		  else
4314 		    b_ext->u.type = type;
4315 		}
4316 	    }
4317 	  break;
4318 
4319 	default:
4320 	  gcc_unreachable ();
4321 	}
4322 
4323       if (DECL_INITIAL (decl))
4324 	TREE_TYPE (DECL_INITIAL (decl)) = type;
4325 
4326       relayout_decl (decl);
4327     }
4328 
4329   if (TREE_CODE (decl) == VAR_DECL)
4330     {
4331       if (init && TREE_CODE (init) == CONSTRUCTOR)
4332 	add_flexible_array_elts_to_size (decl, init);
4333 
4334       if (DECL_SIZE (decl) == 0 && TREE_TYPE (decl) != error_mark_node
4335 	  && COMPLETE_TYPE_P (TREE_TYPE (decl)))
4336 	layout_decl (decl, 0);
4337 
4338       if (DECL_SIZE (decl) == 0
4339 	  /* Don't give an error if we already gave one earlier.  */
4340 	  && TREE_TYPE (decl) != error_mark_node
4341 	  && (TREE_STATIC (decl)
4342 	      /* A static variable with an incomplete type
4343 		 is an error if it is initialized.
4344 		 Also if it is not file scope.
4345 		 Otherwise, let it through, but if it is not `extern'
4346 		 then it may cause an error message later.  */
4347 	      ? (DECL_INITIAL (decl) != 0
4348 		 || !DECL_FILE_SCOPE_P (decl))
4349 	      /* An automatic variable with an incomplete type
4350 		 is an error.  */
4351 	      : !DECL_EXTERNAL (decl)))
4352 	 {
4353 	   error ("storage size of %q+D isn%'t known", decl);
4354 	   TREE_TYPE (decl) = error_mark_node;
4355 	 }
4356 
4357       if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
4358 	  && DECL_SIZE (decl) != 0)
4359 	{
4360 	  if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
4361 	    constant_expression_warning (DECL_SIZE (decl));
4362 	  else
4363 	    {
4364 	      error ("storage size of %q+D isn%'t constant", decl);
4365 	      TREE_TYPE (decl) = error_mark_node;
4366 	    }
4367 	}
4368 
4369       if (TREE_USED (type))
4370 	{
4371 	  TREE_USED (decl) = 1;
4372 	  DECL_READ_P (decl) = 1;
4373 	}
4374     }
4375 
4376   /* If this is a function and an assembler name is specified, reset DECL_RTL
4377      so we can give it its new name.  Also, update builtin_decl if it
4378      was a normal built-in.  */
4379   if (TREE_CODE (decl) == FUNCTION_DECL && asmspec)
4380     {
4381       if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL)
4382 	set_builtin_user_assembler_name (decl, asmspec);
4383       set_user_assembler_name (decl, asmspec);
4384     }
4385 
4386   /* If #pragma weak was used, mark the decl weak now.  */
4387   maybe_apply_pragma_weak (decl);
4388 
4389   /* Output the assembler code and/or RTL code for variables and functions,
4390      unless the type is an undefined structure or union.
4391      If not, it will get done when the type is completed.  */
4392 
4393   if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL)
4394     {
4395       /* Determine the ELF visibility.  */
4396       if (TREE_PUBLIC (decl))
4397 	c_determine_visibility (decl);
4398 
4399       /* This is a no-op in c-lang.c or something real in objc-act.c.  */
4400       if (c_dialect_objc ())
4401 	objc_check_decl (decl);
4402 
4403       if (asmspec)
4404 	{
4405 	  /* If this is not a static variable, issue a warning.
4406 	     It doesn't make any sense to give an ASMSPEC for an
4407 	     ordinary, non-register local variable.  Historically,
4408 	     GCC has accepted -- but ignored -- the ASMSPEC in
4409 	     this case.  */
4410 	  if (!DECL_FILE_SCOPE_P (decl)
4411 	      && TREE_CODE (decl) == VAR_DECL
4412 	      && !C_DECL_REGISTER (decl)
4413 	      && !TREE_STATIC (decl))
4414 	    warning (0, "ignoring asm-specifier for non-static local "
4415 		     "variable %q+D", decl);
4416 	  else
4417 	    set_user_assembler_name (decl, asmspec);
4418 	}
4419 
4420       if (DECL_FILE_SCOPE_P (decl))
4421 	{
4422 	  if (DECL_INITIAL (decl) == NULL_TREE
4423 	      || DECL_INITIAL (decl) == error_mark_node)
4424 	    /* Don't output anything
4425 	       when a tentative file-scope definition is seen.
4426 	       But at end of compilation, do output code for them.  */
4427 	    DECL_DEFER_OUTPUT (decl) = 1;
4428 	  if (asmspec && C_DECL_REGISTER (decl))
4429 	    DECL_HARD_REGISTER (decl) = 1;
4430 	  rest_of_decl_compilation (decl, true, 0);
4431 	}
4432       else
4433 	{
4434 	  /* In conjunction with an ASMSPEC, the `register'
4435 	     keyword indicates that we should place the variable
4436 	     in a particular register.  */
4437 	  if (asmspec && C_DECL_REGISTER (decl))
4438 	    {
4439 	      DECL_HARD_REGISTER (decl) = 1;
4440 	      /* This cannot be done for a structure with volatile
4441 		 fields, on which DECL_REGISTER will have been
4442 		 reset.  */
4443 	      if (!DECL_REGISTER (decl))
4444 		error ("cannot put object with volatile field into register");
4445 	    }
4446 
4447 	  if (TREE_CODE (decl) != FUNCTION_DECL)
4448 	    {
4449 	      /* If we're building a variable sized type, and we might be
4450 		 reachable other than via the top of the current binding
4451 		 level, then create a new BIND_EXPR so that we deallocate
4452 		 the object at the right time.  */
4453 	      /* Note that DECL_SIZE can be null due to errors.  */
4454 	      if (DECL_SIZE (decl)
4455 		  && !TREE_CONSTANT (DECL_SIZE (decl))
4456 		  && STATEMENT_LIST_HAS_LABEL (cur_stmt_list))
4457 		{
4458 		  tree bind;
4459 		  bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL);
4460 		  TREE_SIDE_EFFECTS (bind) = 1;
4461 		  add_stmt (bind);
4462 		  BIND_EXPR_BODY (bind) = push_stmt_list ();
4463 		}
4464 	      add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl),
4465 				    DECL_EXPR, decl));
4466 	    }
4467 	}
4468 
4469 
4470       if (!DECL_FILE_SCOPE_P (decl))
4471 	{
4472 	  /* Recompute the RTL of a local array now
4473 	     if it used to be an incomplete type.  */
4474 	  if (was_incomplete
4475 	      && !TREE_STATIC (decl) && !DECL_EXTERNAL (decl))
4476 	    {
4477 	      /* If we used it already as memory, it must stay in memory.  */
4478 	      TREE_ADDRESSABLE (decl) = TREE_USED (decl);
4479 	      /* If it's still incomplete now, no init will save it.  */
4480 	      if (DECL_SIZE (decl) == 0)
4481 		DECL_INITIAL (decl) = 0;
4482 	    }
4483 	}
4484     }
4485 
4486   if (TREE_CODE (decl) == TYPE_DECL)
4487     {
4488       if (!DECL_FILE_SCOPE_P (decl)
4489 	  && variably_modified_type_p (TREE_TYPE (decl), NULL_TREE))
4490 	add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
4491 
4492       rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl), 0);
4493     }
4494 
4495   /* Install a cleanup (aka destructor) if one was given.  */
4496   if (TREE_CODE (decl) == VAR_DECL && !TREE_STATIC (decl))
4497     {
4498       tree attr = lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl));
4499       if (attr)
4500 	{
4501 	  tree cleanup_id = TREE_VALUE (TREE_VALUE (attr));
4502 	  tree cleanup_decl = lookup_name (cleanup_id);
4503 	  tree cleanup;
4504 	  vec<tree, va_gc> *v;
4505 
4506 	  /* Build "cleanup(&decl)" for the destructor.  */
4507 	  cleanup = build_unary_op (input_location, ADDR_EXPR, decl, 0);
4508 	  vec_alloc (v, 1);
4509 	  v->quick_push (cleanup);
4510 	  cleanup = c_build_function_call_vec (DECL_SOURCE_LOCATION (decl),
4511 					       cleanup_decl, v, NULL);
4512 	  vec_free (v);
4513 
4514 	  /* Don't warn about decl unused; the cleanup uses it.  */
4515 	  TREE_USED (decl) = 1;
4516 	  TREE_USED (cleanup_decl) = 1;
4517 	  DECL_READ_P (decl) = 1;
4518 
4519 	  push_cleanup (decl, cleanup, false);
4520 	}
4521     }
4522 
4523   if (warn_cxx_compat
4524       && TREE_CODE (decl) == VAR_DECL
4525       && !DECL_EXTERNAL (decl)
4526       && DECL_INITIAL (decl) == NULL_TREE)
4527     {
4528       type = strip_array_types (type);
4529       if (TREE_READONLY (decl))
4530 	warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat,
4531 		    "uninitialized const %qD is invalid in C++", decl);
4532       else if ((TREE_CODE (type) == RECORD_TYPE
4533 	      	|| TREE_CODE (type) == UNION_TYPE)
4534 	       && C_TYPE_FIELDS_READONLY (type))
4535 	diagnose_uninitialized_cst_member (decl, type);
4536     }
4537 
4538 	invoke_plugin_callbacks (PLUGIN_FINISH_DECL, decl);
4539 }
4540 
4541 /* Given a parsed parameter declaration, decode it into a PARM_DECL.
4542    EXPR is NULL or a pointer to an expression that needs to be
4543    evaluated for the side effects of array size expressions in the
4544    parameters.  */
4545 
4546 tree
4547 grokparm (const struct c_parm *parm, tree *expr)
4548 {
4549   tree attrs = parm->attrs;
4550   tree decl = grokdeclarator (parm->declarator, parm->specs, PARM, false,
4551 			      NULL, &attrs, expr, NULL, DEPRECATED_NORMAL);
4552 
4553   decl_attributes (&decl, attrs, 0);
4554 
4555   return decl;
4556 }
4557 
4558 /* Given a parsed parameter declaration, decode it into a PARM_DECL
4559    and push that on the current scope.  EXPR is a pointer to an
4560    expression that needs to be evaluated for the side effects of array
4561    size expressions in the parameters.  */
4562 
4563 void
4564 push_parm_decl (const struct c_parm *parm, tree *expr)
4565 {
4566   tree attrs = parm->attrs;
4567   tree decl;
4568 
4569   decl = grokdeclarator (parm->declarator, parm->specs, PARM, false, NULL,
4570 			 &attrs, expr, NULL, DEPRECATED_NORMAL);
4571   decl_attributes (&decl, attrs, 0);
4572 
4573   decl = pushdecl (decl);
4574 
4575   finish_decl (decl, input_location, NULL_TREE, NULL_TREE, NULL_TREE);
4576 }
4577 
4578 /* Mark all the parameter declarations to date as forward decls.
4579    Also diagnose use of this extension.  */
4580 
4581 void
4582 mark_forward_parm_decls (void)
4583 {
4584   struct c_binding *b;
4585 
4586   if (pedantic && !current_scope->warned_forward_parm_decls)
4587     {
4588       pedwarn (input_location, OPT_Wpedantic,
4589 	       "ISO C forbids forward parameter declarations");
4590       current_scope->warned_forward_parm_decls = true;
4591     }
4592 
4593   for (b = current_scope->bindings; b; b = b->prev)
4594     if (TREE_CODE (b->decl) == PARM_DECL)
4595       TREE_ASM_WRITTEN (b->decl) = 1;
4596 }
4597 
4598 /* Build a COMPOUND_LITERAL_EXPR.  TYPE is the type given in the compound
4599    literal, which may be an incomplete array type completed by the
4600    initializer; INIT is a CONSTRUCTOR at LOC that initializes the compound
4601    literal.  NON_CONST is true if the initializers contain something
4602    that cannot occur in a constant expression.  */
4603 
4604 tree
4605 build_compound_literal (location_t loc, tree type, tree init, bool non_const)
4606 {
4607   /* We do not use start_decl here because we have a type, not a declarator;
4608      and do not use finish_decl because the decl should be stored inside
4609      the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_EXPR.  */
4610   tree decl;
4611   tree complit;
4612   tree stmt;
4613 
4614   if (type == error_mark_node
4615       || init == error_mark_node)
4616     return error_mark_node;
4617 
4618   decl = build_decl (loc, VAR_DECL, NULL_TREE, type);
4619   DECL_EXTERNAL (decl) = 0;
4620   TREE_PUBLIC (decl) = 0;
4621   TREE_STATIC (decl) = (current_scope == file_scope);
4622   DECL_CONTEXT (decl) = current_function_decl;
4623   TREE_USED (decl) = 1;
4624   DECL_READ_P (decl) = 1;
4625   TREE_TYPE (decl) = type;
4626   TREE_READONLY (decl) = (TYPE_READONLY (type)
4627 			  || (TREE_CODE (type) == ARRAY_TYPE
4628 			      && TYPE_READONLY (TREE_TYPE (type))));
4629   store_init_value (loc, decl, init, NULL_TREE);
4630 
4631   if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type))
4632     {
4633       int failure = complete_array_type (&TREE_TYPE (decl),
4634 					 DECL_INITIAL (decl), true);
4635       /* If complete_array_type returns 3, it means that the
4636          initial value of the compound literal is empty.  Allow it.  */
4637       gcc_assert (failure == 0 || failure == 3);
4638 
4639       type = TREE_TYPE (decl);
4640       TREE_TYPE (DECL_INITIAL (decl)) = type;
4641     }
4642 
4643   if (type == error_mark_node || !COMPLETE_TYPE_P (type))
4644     {
4645       c_incomplete_type_error (NULL_TREE, type);
4646       return error_mark_node;
4647     }
4648 
4649   stmt = build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl);
4650   complit = build1 (COMPOUND_LITERAL_EXPR, type, stmt);
4651   TREE_SIDE_EFFECTS (complit) = 1;
4652 
4653   layout_decl (decl, 0);
4654 
4655   if (TREE_STATIC (decl))
4656     {
4657       /* This decl needs a name for the assembler output.  */
4658       set_compound_literal_name (decl);
4659       DECL_DEFER_OUTPUT (decl) = 1;
4660       DECL_COMDAT (decl) = 1;
4661       DECL_ARTIFICIAL (decl) = 1;
4662       DECL_IGNORED_P (decl) = 1;
4663       pushdecl (decl);
4664       rest_of_decl_compilation (decl, 1, 0);
4665     }
4666 
4667   if (non_const)
4668     {
4669       complit = build2 (C_MAYBE_CONST_EXPR, type, NULL, complit);
4670       C_MAYBE_CONST_EXPR_NON_CONST (complit) = 1;
4671     }
4672 
4673   return complit;
4674 }
4675 
4676 /* Check the type of a compound literal.  Here we just check that it
4677    is valid for C++.  */
4678 
4679 void
4680 check_compound_literal_type (location_t loc, struct c_type_name *type_name)
4681 {
4682   if (warn_cxx_compat
4683       && (type_name->specs->typespec_kind == ctsk_tagdef
4684           || type_name->specs->typespec_kind == ctsk_tagfirstref))
4685     warning_at (loc, OPT_Wc___compat,
4686 		"defining a type in a compound literal is invalid in C++");
4687 }
4688 
4689 /* Determine whether TYPE is a structure with a flexible array member,
4690    or a union containing such a structure (possibly recursively).  */
4691 
4692 static bool
4693 flexible_array_type_p (tree type)
4694 {
4695   tree x;
4696   switch (TREE_CODE (type))
4697     {
4698     case RECORD_TYPE:
4699       x = TYPE_FIELDS (type);
4700       if (x == NULL_TREE)
4701 	return false;
4702       while (DECL_CHAIN (x) != NULL_TREE)
4703 	x = DECL_CHAIN (x);
4704       if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
4705 	  && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
4706 	  && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE
4707 	  && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE)
4708 	return true;
4709       return false;
4710     case UNION_TYPE:
4711       for (x = TYPE_FIELDS (type); x != NULL_TREE; x = DECL_CHAIN (x))
4712 	{
4713 	  if (flexible_array_type_p (TREE_TYPE (x)))
4714 	    return true;
4715 	}
4716       return false;
4717     default:
4718     return false;
4719   }
4720 }
4721 
4722 /* Performs sanity checks on the TYPE and WIDTH of the bit-field NAME,
4723    replacing with appropriate values if they are invalid.  */
4724 static void
4725 check_bitfield_type_and_width (tree *type, tree *width, tree orig_name)
4726 {
4727   tree type_mv;
4728   unsigned int max_width;
4729   unsigned HOST_WIDE_INT w;
4730   const char *name = (orig_name
4731 		      ? identifier_to_locale (IDENTIFIER_POINTER (orig_name))
4732 		      : _("<anonymous>"));
4733 
4734   /* Detect and ignore out of range field width and process valid
4735      field widths.  */
4736   if (!INTEGRAL_TYPE_P (TREE_TYPE (*width)))
4737     {
4738       error ("bit-field %qs width not an integer constant", name);
4739       *width = integer_one_node;
4740     }
4741   else
4742     {
4743       if (TREE_CODE (*width) != INTEGER_CST)
4744 	{
4745 	  *width = c_fully_fold (*width, false, NULL);
4746 	  if (TREE_CODE (*width) == INTEGER_CST)
4747 	    pedwarn (input_location, OPT_Wpedantic,
4748 		     "bit-field %qs width not an integer constant expression",
4749 		     name);
4750 	}
4751       if (TREE_CODE (*width) != INTEGER_CST)
4752 	{
4753 	  error ("bit-field %qs width not an integer constant", name);
4754 	  *width = integer_one_node;
4755 	}
4756       constant_expression_warning (*width);
4757       if (tree_int_cst_sgn (*width) < 0)
4758 	{
4759 	  error ("negative width in bit-field %qs", name);
4760 	  *width = integer_one_node;
4761 	}
4762       else if (integer_zerop (*width) && orig_name)
4763 	{
4764 	  error ("zero width for bit-field %qs", name);
4765 	  *width = integer_one_node;
4766 	}
4767     }
4768 
4769   /* Detect invalid bit-field type.  */
4770   if (TREE_CODE (*type) != INTEGER_TYPE
4771       && TREE_CODE (*type) != BOOLEAN_TYPE
4772       && TREE_CODE (*type) != ENUMERAL_TYPE)
4773     {
4774       error ("bit-field %qs has invalid type", name);
4775       *type = unsigned_type_node;
4776     }
4777 
4778   type_mv = TYPE_MAIN_VARIANT (*type);
4779   if (!in_system_header
4780       && type_mv != integer_type_node
4781       && type_mv != unsigned_type_node
4782       && type_mv != boolean_type_node)
4783     pedwarn (input_location, OPT_Wpedantic,
4784 	     "type of bit-field %qs is a GCC extension", name);
4785 
4786   max_width = TYPE_PRECISION (*type);
4787 
4788   if (0 < compare_tree_int (*width, max_width))
4789     {
4790       error ("width of %qs exceeds its type", name);
4791       w = max_width;
4792       *width = build_int_cst (integer_type_node, w);
4793     }
4794   else
4795     w = tree_low_cst (*width, 1);
4796 
4797   if (TREE_CODE (*type) == ENUMERAL_TYPE)
4798     {
4799       struct lang_type *lt = TYPE_LANG_SPECIFIC (*type);
4800       if (!lt
4801 	  || w < tree_int_cst_min_precision (lt->enum_min, TYPE_UNSIGNED (*type))
4802 	  || w < tree_int_cst_min_precision (lt->enum_max, TYPE_UNSIGNED (*type)))
4803 	warning (0, "%qs is narrower than values of its type", name);
4804     }
4805 }
4806 
4807 
4808 
4809 /* Print warning about variable length array if necessary.  */
4810 
4811 static void
4812 warn_variable_length_array (tree name, tree size)
4813 {
4814   int const_size = TREE_CONSTANT (size);
4815 
4816   if (!flag_isoc99 && pedantic && warn_vla != 0)
4817     {
4818       if (const_size)
4819 	{
4820 	  if (name)
4821 	    pedwarn (input_location, OPT_Wvla,
4822 		     "ISO C90 forbids array %qE whose size "
4823 		     "can%'t be evaluated",
4824 		     name);
4825 	  else
4826 	    pedwarn (input_location, OPT_Wvla, "ISO C90 forbids array whose size "
4827 		     "can%'t be evaluated");
4828 	}
4829       else
4830 	{
4831 	  if (name)
4832 	    pedwarn (input_location, OPT_Wvla,
4833 		     "ISO C90 forbids variable length array %qE",
4834 		     name);
4835 	  else
4836 	    pedwarn (input_location, OPT_Wvla, "ISO C90 forbids variable length array");
4837 	}
4838     }
4839   else if (warn_vla > 0)
4840     {
4841       if (const_size)
4842         {
4843 	  if (name)
4844 	    warning (OPT_Wvla,
4845 		     "the size of array %qE can"
4846 		     "%'t be evaluated", name);
4847 	  else
4848 	    warning (OPT_Wvla,
4849 		     "the size of array can %'t be evaluated");
4850 	}
4851       else
4852 	{
4853 	  if (name)
4854 	    warning (OPT_Wvla,
4855 		     "variable length array %qE is used",
4856 		     name);
4857 	  else
4858 	    warning (OPT_Wvla,
4859 		     "variable length array is used");
4860 	}
4861     }
4862 }
4863 
4864 /* Given declspecs and a declarator,
4865    determine the name and type of the object declared
4866    and construct a ..._DECL node for it.
4867    (In one case we can return a ..._TYPE node instead.
4868     For invalid input we sometimes return 0.)
4869 
4870    DECLSPECS is a c_declspecs structure for the declaration specifiers.
4871 
4872    DECL_CONTEXT says which syntactic context this declaration is in:
4873      NORMAL for most contexts.  Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
4874      FUNCDEF for a function definition.  Like NORMAL but a few different
4875       error messages in each case.  Return value may be zero meaning
4876       this definition is too screwy to try to parse.
4877      PARM for a parameter declaration (either within a function prototype
4878       or before a function body).  Make a PARM_DECL, or return void_type_node.
4879      TYPENAME if for a typename (in a cast or sizeof).
4880       Don't make a DECL node; just return the ..._TYPE node.
4881      FIELD for a struct or union field; make a FIELD_DECL.
4882    INITIALIZED is true if the decl has an initializer.
4883    WIDTH is non-NULL for bit-fields, and is a pointer to an INTEGER_CST node
4884    representing the width of the bit-field.
4885    DECL_ATTRS points to the list of attributes that should be added to this
4886      decl.  Any nested attributes that belong on the decl itself will be
4887      added to this list.
4888    If EXPR is not NULL, any expressions that need to be evaluated as
4889      part of evaluating variably modified types will be stored in *EXPR.
4890    If EXPR_CONST_OPERANDS is not NULL, *EXPR_CONST_OPERANDS will be
4891      set to indicate whether operands in *EXPR can be used in constant
4892      expressions.
4893    DEPRECATED_STATE is a deprecated_states value indicating whether
4894    deprecation warnings should be suppressed.
4895 
4896    In the TYPENAME case, DECLARATOR is really an absolute declarator.
4897    It may also be so in the PARM case, for a prototype where the
4898    argument type is specified but not the name.
4899 
4900    This function is where the complicated C meanings of `static'
4901    and `extern' are interpreted.  */
4902 
4903 static tree
4904 grokdeclarator (const struct c_declarator *declarator,
4905 		struct c_declspecs *declspecs,
4906 		enum decl_context decl_context, bool initialized, tree *width,
4907 		tree *decl_attrs, tree *expr, bool *expr_const_operands,
4908 		enum deprecated_states deprecated_state)
4909 {
4910   tree type = declspecs->type;
4911   bool threadp = declspecs->thread_p;
4912   enum c_storage_class storage_class = declspecs->storage_class;
4913   int constp;
4914   int restrictp;
4915   int volatilep;
4916   int type_quals = TYPE_UNQUALIFIED;
4917   tree name = NULL_TREE;
4918   bool funcdef_flag = false;
4919   bool funcdef_syntax = false;
4920   bool size_varies = false;
4921   tree decl_attr = declspecs->decl_attr;
4922   int array_ptr_quals = TYPE_UNQUALIFIED;
4923   tree array_ptr_attrs = NULL_TREE;
4924   int array_parm_static = 0;
4925   bool array_parm_vla_unspec_p = false;
4926   tree returned_attrs = NULL_TREE;
4927   bool bitfield = width != NULL;
4928   tree element_type;
4929   struct c_arg_info *arg_info = 0;
4930   addr_space_t as1, as2, address_space;
4931   location_t loc = UNKNOWN_LOCATION;
4932   const char *errmsg;
4933   tree expr_dummy;
4934   bool expr_const_operands_dummy;
4935   enum c_declarator_kind first_non_attr_kind;
4936   unsigned int alignas_align = 0;
4937 
4938   if (TREE_CODE (type) == ERROR_MARK)
4939     return error_mark_node;
4940   if (expr == NULL)
4941     expr = &expr_dummy;
4942   if (expr_const_operands == NULL)
4943     expr_const_operands = &expr_const_operands_dummy;
4944 
4945   *expr = declspecs->expr;
4946   *expr_const_operands = declspecs->expr_const_operands;
4947 
4948   if (decl_context == FUNCDEF)
4949     funcdef_flag = true, decl_context = NORMAL;
4950 
4951   /* Look inside a declarator for the name being declared
4952      and get it as an IDENTIFIER_NODE, for an error message.  */
4953   {
4954     const struct c_declarator *decl = declarator;
4955 
4956     first_non_attr_kind = cdk_attrs;
4957     while (decl)
4958       switch (decl->kind)
4959 	{
4960 	case cdk_array:
4961 	  loc = decl->id_loc;
4962 	  /* FALL THRU.  */
4963 
4964 	case cdk_function:
4965 	case cdk_pointer:
4966 	  funcdef_syntax = (decl->kind == cdk_function);
4967 	  decl = decl->declarator;
4968 	  if (first_non_attr_kind == cdk_attrs)
4969 	    first_non_attr_kind = decl->kind;
4970 	  break;
4971 
4972 	case cdk_attrs:
4973 	  decl = decl->declarator;
4974 	  break;
4975 
4976 	case cdk_id:
4977 	  loc = decl->id_loc;
4978 	  if (decl->u.id)
4979 	    name = decl->u.id;
4980 	  if (first_non_attr_kind == cdk_attrs)
4981 	    first_non_attr_kind = decl->kind;
4982 	  decl = 0;
4983 	  break;
4984 
4985 	default:
4986 	  gcc_unreachable ();
4987 	}
4988     if (name == 0)
4989       {
4990 	gcc_assert (decl_context == PARM
4991 		    || decl_context == TYPENAME
4992 		    || (decl_context == FIELD
4993 			&& declarator->kind == cdk_id));
4994 	gcc_assert (!initialized);
4995       }
4996   }
4997 
4998   /* A function definition's declarator must have the form of
4999      a function declarator.  */
5000 
5001   if (funcdef_flag && !funcdef_syntax)
5002     return 0;
5003 
5004   /* If this looks like a function definition, make it one,
5005      even if it occurs where parms are expected.
5006      Then store_parm_decls will reject it and not use it as a parm.  */
5007   if (decl_context == NORMAL && !funcdef_flag && current_scope->parm_flag)
5008     decl_context = PARM;
5009 
5010   if (declspecs->deprecated_p && deprecated_state != DEPRECATED_SUPPRESS)
5011     warn_deprecated_use (declspecs->type, declspecs->decl_attr);
5012 
5013   if ((decl_context == NORMAL || decl_context == FIELD)
5014       && current_scope == file_scope
5015       && variably_modified_type_p (type, NULL_TREE))
5016     {
5017       if (name)
5018 	error_at (loc, "variably modified %qE at file scope", name);
5019       else
5020 	error_at (loc, "variably modified field at file scope");
5021       type = integer_type_node;
5022     }
5023 
5024   size_varies = C_TYPE_VARIABLE_SIZE (type) != 0;
5025 
5026   /* Diagnose defaulting to "int".  */
5027 
5028   if (declspecs->default_int_p && !in_system_header)
5029     {
5030       /* Issue a warning if this is an ISO C 99 program or if
5031 	 -Wreturn-type and this is a function, or if -Wimplicit;
5032 	 prefer the former warning since it is more explicit.  */
5033       if ((warn_implicit_int || warn_return_type || flag_isoc99)
5034 	  && funcdef_flag)
5035 	warn_about_return_type = 1;
5036       else
5037 	{
5038 	  if (name)
5039 	    pedwarn_c99 (loc, flag_isoc99 ? 0 : OPT_Wimplicit_int,
5040 			 "type defaults to %<int%> in declaration of %qE",
5041 			 name);
5042 	  else
5043 	    pedwarn_c99 (input_location, flag_isoc99 ? 0 : OPT_Wimplicit_int,
5044 			 "type defaults to %<int%> in type name");
5045 	}
5046     }
5047 
5048   /* Adjust the type if a bit-field is being declared,
5049      -funsigned-bitfields applied and the type is not explicitly
5050      "signed".  */
5051   if (bitfield && !flag_signed_bitfields && !declspecs->explicit_signed_p
5052       && TREE_CODE (type) == INTEGER_TYPE)
5053     type = unsigned_type_for (type);
5054 
5055   /* Figure out the type qualifiers for the declaration.  There are
5056      two ways a declaration can become qualified.  One is something
5057      like `const int i' where the `const' is explicit.  Another is
5058      something like `typedef const int CI; CI i' where the type of the
5059      declaration contains the `const'.  A third possibility is that
5060      there is a type qualifier on the element type of a typedefed
5061      array type, in which case we should extract that qualifier so
5062      that c_apply_type_quals_to_decl receives the full list of
5063      qualifiers to work with (C90 is not entirely clear about whether
5064      duplicate qualifiers should be diagnosed in this case, but it
5065      seems most appropriate to do so).  */
5066   element_type = strip_array_types (type);
5067   constp = declspecs->const_p + TYPE_READONLY (element_type);
5068   restrictp = declspecs->restrict_p + TYPE_RESTRICT (element_type);
5069   volatilep = declspecs->volatile_p + TYPE_VOLATILE (element_type);
5070   as1 = declspecs->address_space;
5071   as2 = TYPE_ADDR_SPACE (element_type);
5072   address_space = ADDR_SPACE_GENERIC_P (as1)? as2 : as1;
5073 
5074   if (pedantic && !flag_isoc99)
5075     {
5076       if (constp > 1)
5077 	pedwarn (loc, OPT_Wpedantic, "duplicate %<const%>");
5078       if (restrictp > 1)
5079 	pedwarn (loc, OPT_Wpedantic, "duplicate %<restrict%>");
5080       if (volatilep > 1)
5081 	pedwarn (loc, OPT_Wpedantic, "duplicate %<volatile%>");
5082     }
5083 
5084   if (!ADDR_SPACE_GENERIC_P (as1) && !ADDR_SPACE_GENERIC_P (as2) && as1 != as2)
5085     error_at (loc, "conflicting named address spaces (%s vs %s)",
5086 	      c_addr_space_name (as1), c_addr_space_name (as2));
5087 
5088   if ((TREE_CODE (type) == ARRAY_TYPE
5089        || first_non_attr_kind == cdk_array)
5090       && TYPE_QUALS (element_type))
5091     type = TYPE_MAIN_VARIANT (type);
5092   type_quals = ((constp ? TYPE_QUAL_CONST : 0)
5093 		| (restrictp ? TYPE_QUAL_RESTRICT : 0)
5094 		| (volatilep ? TYPE_QUAL_VOLATILE : 0)
5095 		| ENCODE_QUAL_ADDR_SPACE (address_space));
5096 
5097   /* Warn about storage classes that are invalid for certain
5098      kinds of declarations (parameters, typenames, etc.).  */
5099 
5100   if (funcdef_flag
5101       && (threadp
5102 	  || storage_class == csc_auto
5103 	  || storage_class == csc_register
5104 	  || storage_class == csc_typedef))
5105     {
5106       if (storage_class == csc_auto)
5107 	pedwarn (loc,
5108 		 (current_scope == file_scope) ? 0 : OPT_Wpedantic,
5109 		 "function definition declared %<auto%>");
5110       if (storage_class == csc_register)
5111 	error_at (loc, "function definition declared %<register%>");
5112       if (storage_class == csc_typedef)
5113 	error_at (loc, "function definition declared %<typedef%>");
5114       if (threadp)
5115 	error_at (loc, "function definition declared %<__thread%>");
5116       threadp = false;
5117       if (storage_class == csc_auto
5118 	  || storage_class == csc_register
5119 	  || storage_class == csc_typedef)
5120 	storage_class = csc_none;
5121     }
5122   else if (decl_context != NORMAL && (storage_class != csc_none || threadp))
5123     {
5124       if (decl_context == PARM && storage_class == csc_register)
5125 	;
5126       else
5127 	{
5128 	  switch (decl_context)
5129 	    {
5130 	    case FIELD:
5131 	      if (name)
5132 		error_at (loc, "storage class specified for structure "
5133 		    	  "field %qE", name);
5134 	      else
5135 		error_at (loc, "storage class specified for structure field");
5136 	      break;
5137 	    case PARM:
5138 	      if (name)
5139 		error_at (loc, "storage class specified for parameter %qE",
5140 		    	  name);
5141 	      else
5142 		error_at (loc, "storage class specified for unnamed parameter");
5143 	      break;
5144 	    default:
5145 	      error_at (loc, "storage class specified for typename");
5146 	      break;
5147 	    }
5148 	  storage_class = csc_none;
5149 	  threadp = false;
5150 	}
5151     }
5152   else if (storage_class == csc_extern
5153 	   && initialized
5154 	   && !funcdef_flag)
5155     {
5156       /* 'extern' with initialization is invalid if not at file scope.  */
5157        if (current_scope == file_scope)
5158          {
5159            /* It is fine to have 'extern const' when compiling at C
5160               and C++ intersection.  */
5161            if (!(warn_cxx_compat && constp))
5162              warning_at (loc, 0, "%qE initialized and declared %<extern%>",
5163 		 	 name);
5164          }
5165       else
5166 	error_at (loc, "%qE has both %<extern%> and initializer", name);
5167     }
5168   else if (current_scope == file_scope)
5169     {
5170       if (storage_class == csc_auto)
5171 	error_at (loc, "file-scope declaration of %qE specifies %<auto%>",
5172 	    	  name);
5173       if (pedantic && storage_class == csc_register)
5174 	pedwarn (input_location, OPT_Wpedantic,
5175 		 "file-scope declaration of %qE specifies %<register%>", name);
5176     }
5177   else
5178     {
5179       if (storage_class == csc_extern && funcdef_flag)
5180 	error_at (loc, "nested function %qE declared %<extern%>", name);
5181       else if (threadp && storage_class == csc_none)
5182 	{
5183 	  error_at (loc, "function-scope %qE implicitly auto and declared "
5184 		    "%<__thread%>",
5185 		    name);
5186 	  threadp = false;
5187 	}
5188     }
5189 
5190   /* Now figure out the structure of the declarator proper.
5191      Descend through it, creating more complex types, until we reach
5192      the declared identifier (or NULL_TREE, in an absolute declarator).
5193      At each stage we maintain an unqualified version of the type
5194      together with any qualifiers that should be applied to it with
5195      c_build_qualified_type; this way, array types including
5196      multidimensional array types are first built up in unqualified
5197      form and then the qualified form is created with
5198      TYPE_MAIN_VARIANT pointing to the unqualified form.  */
5199 
5200   while (declarator && declarator->kind != cdk_id)
5201     {
5202       if (type == error_mark_node)
5203 	{
5204 	  declarator = declarator->declarator;
5205 	  continue;
5206 	}
5207 
5208       /* Each level of DECLARATOR is either a cdk_array (for ...[..]),
5209 	 a cdk_pointer (for *...),
5210 	 a cdk_function (for ...(...)),
5211 	 a cdk_attrs (for nested attributes),
5212 	 or a cdk_id (for the name being declared
5213 	 or the place in an absolute declarator
5214 	 where the name was omitted).
5215 	 For the last case, we have just exited the loop.
5216 
5217 	 At this point, TYPE is the type of elements of an array,
5218 	 or for a function to return, or for a pointer to point to.
5219 	 After this sequence of ifs, TYPE is the type of the
5220 	 array or function or pointer, and DECLARATOR has had its
5221 	 outermost layer removed.  */
5222 
5223       if (array_ptr_quals != TYPE_UNQUALIFIED
5224 	  || array_ptr_attrs != NULL_TREE
5225 	  || array_parm_static)
5226 	{
5227 	  /* Only the innermost declarator (making a parameter be of
5228 	     array type which is converted to pointer type)
5229 	     may have static or type qualifiers.  */
5230 	  error_at (loc, "static or type qualifiers in non-parameter array declarator");
5231 	  array_ptr_quals = TYPE_UNQUALIFIED;
5232 	  array_ptr_attrs = NULL_TREE;
5233 	  array_parm_static = 0;
5234 	}
5235 
5236       switch (declarator->kind)
5237 	{
5238 	case cdk_attrs:
5239 	  {
5240 	    /* A declarator with embedded attributes.  */
5241 	    tree attrs = declarator->u.attrs;
5242 	    const struct c_declarator *inner_decl;
5243 	    int attr_flags = 0;
5244 	    declarator = declarator->declarator;
5245 	    inner_decl = declarator;
5246 	    while (inner_decl->kind == cdk_attrs)
5247 	      inner_decl = inner_decl->declarator;
5248 	    if (inner_decl->kind == cdk_id)
5249 	      attr_flags |= (int) ATTR_FLAG_DECL_NEXT;
5250 	    else if (inner_decl->kind == cdk_function)
5251 	      attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT;
5252 	    else if (inner_decl->kind == cdk_array)
5253 	      attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT;
5254 	    returned_attrs = decl_attributes (&type,
5255 					      chainon (returned_attrs, attrs),
5256 					      attr_flags);
5257 	    break;
5258 	  }
5259 	case cdk_array:
5260 	  {
5261 	    tree itype = NULL_TREE;
5262 	    tree size = declarator->u.array.dimen;
5263 	    /* The index is a signed object `sizetype' bits wide.  */
5264 	    tree index_type = c_common_signed_type (sizetype);
5265 
5266 	    array_ptr_quals = declarator->u.array.quals;
5267 	    array_ptr_attrs = declarator->u.array.attrs;
5268 	    array_parm_static = declarator->u.array.static_p;
5269 	    array_parm_vla_unspec_p = declarator->u.array.vla_unspec_p;
5270 
5271 	    declarator = declarator->declarator;
5272 
5273 	    /* Check for some types that there cannot be arrays of.  */
5274 
5275 	    if (VOID_TYPE_P (type))
5276 	      {
5277 		if (name)
5278 		  error_at (loc, "declaration of %qE as array of voids", name);
5279 		else
5280 		  error_at (loc, "declaration of type name as array of voids");
5281 		type = error_mark_node;
5282 	      }
5283 
5284 	    if (TREE_CODE (type) == FUNCTION_TYPE)
5285 	      {
5286 		if (name)
5287 		  error_at (loc, "declaration of %qE as array of functions",
5288 		      	    name);
5289 		else
5290 		  error_at (loc, "declaration of type name as array of "
5291 		            "functions");
5292 		type = error_mark_node;
5293 	      }
5294 
5295 	    if (pedantic && !in_system_header && flexible_array_type_p (type))
5296 	      pedwarn (loc, OPT_Wpedantic,
5297 		       "invalid use of structure with flexible array member");
5298 
5299 	    if (size == error_mark_node)
5300 	      type = error_mark_node;
5301 
5302 	    if (type == error_mark_node)
5303 	      continue;
5304 
5305 	    /* If size was specified, set ITYPE to a range-type for
5306 	       that size.  Otherwise, ITYPE remains null.  finish_decl
5307 	       may figure it out from an initial value.  */
5308 
5309 	    if (size)
5310 	      {
5311 		bool size_maybe_const = true;
5312 		bool size_int_const = (TREE_CODE (size) == INTEGER_CST
5313 				       && !TREE_OVERFLOW (size));
5314 		bool this_size_varies = false;
5315 
5316 		/* Strip NON_LVALUE_EXPRs since we aren't using as an
5317 		   lvalue.  */
5318 		STRIP_TYPE_NOPS (size);
5319 
5320 		if (!INTEGRAL_TYPE_P (TREE_TYPE (size)))
5321 		  {
5322 		    if (name)
5323 		      error_at (loc, "size of array %qE has non-integer type",
5324 			  	name);
5325 		    else
5326 		      error_at (loc,
5327 			  	"size of unnamed array has non-integer type");
5328 		    size = integer_one_node;
5329 		  }
5330 
5331 		size = c_fully_fold (size, false, &size_maybe_const);
5332 
5333 		if (pedantic && size_maybe_const && integer_zerop (size))
5334 		  {
5335 		    if (name)
5336 		      pedwarn (loc, OPT_Wpedantic,
5337 			       "ISO C forbids zero-size array %qE", name);
5338 		    else
5339 		      pedwarn (loc, OPT_Wpedantic,
5340 			       "ISO C forbids zero-size array");
5341 		  }
5342 
5343 		if (TREE_CODE (size) == INTEGER_CST && size_maybe_const)
5344 		  {
5345 		    constant_expression_warning (size);
5346 		    if (tree_int_cst_sgn (size) < 0)
5347 		      {
5348 			if (name)
5349 			  error_at (loc, "size of array %qE is negative", name);
5350 			else
5351 			  error_at (loc, "size of unnamed array is negative");
5352 			size = integer_one_node;
5353 		      }
5354 		    /* Handle a size folded to an integer constant but
5355 		       not an integer constant expression.  */
5356 		    if (!size_int_const)
5357 		      {
5358 			/* If this is a file scope declaration of an
5359 			   ordinary identifier, this is invalid code;
5360 			   diagnosing it here and not subsequently
5361 			   treating the type as variable-length avoids
5362 			   more confusing diagnostics later.  */
5363 			if ((decl_context == NORMAL || decl_context == FIELD)
5364 			    && current_scope == file_scope)
5365 			  pedwarn (input_location, 0,
5366 				   "variably modified %qE at file scope",
5367 				   name);
5368 			else
5369 			  this_size_varies = size_varies = true;
5370 			warn_variable_length_array (name, size);
5371 		      }
5372 		  }
5373 		else if ((decl_context == NORMAL || decl_context == FIELD)
5374 			 && current_scope == file_scope)
5375 		  {
5376 		    error_at (loc, "variably modified %qE at file scope", name);
5377 		    size = integer_one_node;
5378 		  }
5379 		else
5380 		  {
5381 		    /* Make sure the array size remains visibly
5382 		       nonconstant even if it is (eg) a const variable
5383 		       with known value.  */
5384 		    this_size_varies = size_varies = true;
5385 		    warn_variable_length_array (name, size);
5386 		  }
5387 
5388 		if (integer_zerop (size) && !this_size_varies)
5389 		  {
5390 		    /* A zero-length array cannot be represented with
5391 		       an unsigned index type, which is what we'll
5392 		       get with build_index_type.  Create an
5393 		       open-ended range instead.  */
5394 		    itype = build_range_type (sizetype, size, NULL_TREE);
5395 		  }
5396 		else
5397 		  {
5398 		    /* Arrange for the SAVE_EXPR on the inside of the
5399 		       MINUS_EXPR, which allows the -1 to get folded
5400 		       with the +1 that happens when building TYPE_SIZE.  */
5401 		    if (size_varies)
5402 		      size = save_expr (size);
5403 		    if (this_size_varies && TREE_CODE (size) == INTEGER_CST)
5404 		      size = build2 (COMPOUND_EXPR, TREE_TYPE (size),
5405 				     integer_zero_node, size);
5406 
5407 		    /* Compute the maximum valid index, that is, size
5408 		       - 1.  Do the calculation in index_type, so that
5409 		       if it is a variable the computations will be
5410 		       done in the proper mode.  */
5411 		    itype = fold_build2_loc (loc, MINUS_EXPR, index_type,
5412 					     convert (index_type, size),
5413 					     convert (index_type,
5414 						      size_one_node));
5415 
5416 		    /* The above overflows when size does not fit
5417 		       in index_type.
5418 		       ???  While a size of INT_MAX+1 technically shouldn't
5419 		       cause an overflow (because we subtract 1), handling
5420 		       this case seems like an unnecessary complication.  */
5421 		    if (TREE_CODE (size) == INTEGER_CST
5422 			&& !int_fits_type_p (size, index_type))
5423 		      {
5424 			if (name)
5425 			  error_at (loc, "size of array %qE is too large",
5426 			            name);
5427 			else
5428 			  error_at (loc, "size of unnamed array is too large");
5429 			type = error_mark_node;
5430 			continue;
5431 		      }
5432 
5433 		    itype = build_index_type (itype);
5434 		  }
5435 		if (this_size_varies)
5436 		  {
5437 		    if (*expr)
5438 		      *expr = build2 (COMPOUND_EXPR, TREE_TYPE (size),
5439 				      *expr, size);
5440 		    else
5441 		      *expr = size;
5442 		    *expr_const_operands &= size_maybe_const;
5443 		  }
5444 	      }
5445 	    else if (decl_context == FIELD)
5446 	      {
5447 		bool flexible_array_member = false;
5448 		if (array_parm_vla_unspec_p)
5449 		  /* Field names can in fact have function prototype
5450 		     scope so [*] is disallowed here through making
5451 		     the field variably modified, not through being
5452 		     something other than a declaration with function
5453 		     prototype scope.  */
5454 		  size_varies = true;
5455 		else
5456 		  {
5457 		    const struct c_declarator *t = declarator;
5458 		    while (t->kind == cdk_attrs)
5459 		      t = t->declarator;
5460 		    flexible_array_member = (t->kind == cdk_id);
5461 		  }
5462 		if (flexible_array_member
5463 		    && pedantic && !flag_isoc99 && !in_system_header)
5464 		  pedwarn (loc, OPT_Wpedantic,
5465 			   "ISO C90 does not support flexible array members");
5466 
5467 		/* ISO C99 Flexible array members are effectively
5468 		   identical to GCC's zero-length array extension.  */
5469 		if (flexible_array_member || array_parm_vla_unspec_p)
5470 		  itype = build_range_type (sizetype, size_zero_node,
5471 					    NULL_TREE);
5472 	      }
5473 	    else if (decl_context == PARM)
5474 	      {
5475 		if (array_parm_vla_unspec_p)
5476 		  {
5477 		    itype = build_range_type (sizetype, size_zero_node, NULL_TREE);
5478 		    size_varies = true;
5479 		  }
5480 	      }
5481 	    else if (decl_context == TYPENAME)
5482 	      {
5483 		if (array_parm_vla_unspec_p)
5484 		  {
5485 		    /* C99 6.7.5.2p4 */
5486 		    warning (0, "%<[*]%> not in a declaration");
5487 		    /* We use this to avoid messing up with incomplete
5488 		       array types of the same type, that would
5489 		       otherwise be modified below.  */
5490 		    itype = build_range_type (sizetype, size_zero_node,
5491 					      NULL_TREE);
5492 		    size_varies = true;
5493 		  }
5494 	      }
5495 
5496 	    /* Complain about arrays of incomplete types.  */
5497 	    if (!COMPLETE_TYPE_P (type))
5498 	      {
5499 		error_at (loc, "array type has incomplete element type");
5500 		type = error_mark_node;
5501 	      }
5502 	    else
5503 	    /* When itype is NULL, a shared incomplete array type is
5504 	       returned for all array of a given type.  Elsewhere we
5505 	       make sure we don't complete that type before copying
5506 	       it, but here we want to make sure we don't ever
5507 	       modify the shared type, so we gcc_assert (itype)
5508 	       below.  */
5509 	      {
5510 		addr_space_t as = DECODE_QUAL_ADDR_SPACE (type_quals);
5511 		if (!ADDR_SPACE_GENERIC_P (as) && as != TYPE_ADDR_SPACE (type))
5512 		  type = build_qualified_type (type,
5513 					       ENCODE_QUAL_ADDR_SPACE (as));
5514 
5515 		type = build_array_type (type, itype);
5516 	      }
5517 
5518 	    if (type != error_mark_node)
5519 	      {
5520 		if (size_varies)
5521 		  {
5522 		    /* It is ok to modify type here even if itype is
5523 		       NULL: if size_varies, we're in a
5524 		       multi-dimensional array and the inner type has
5525 		       variable size, so the enclosing shared array type
5526 		       must too.  */
5527 		    if (size && TREE_CODE (size) == INTEGER_CST)
5528 		      type
5529 			= build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
5530 		    C_TYPE_VARIABLE_SIZE (type) = 1;
5531 		  }
5532 
5533 		/* The GCC extension for zero-length arrays differs from
5534 		   ISO flexible array members in that sizeof yields
5535 		   zero.  */
5536 		if (size && integer_zerop (size))
5537 		  {
5538 		    gcc_assert (itype);
5539 		    type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
5540 		    TYPE_SIZE (type) = bitsize_zero_node;
5541 		    TYPE_SIZE_UNIT (type) = size_zero_node;
5542 		    SET_TYPE_STRUCTURAL_EQUALITY (type);
5543 		  }
5544 		if (array_parm_vla_unspec_p)
5545 		  {
5546 		    gcc_assert (itype);
5547 		    /* The type is complete.  C99 6.7.5.2p4  */
5548 		    type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
5549 		    TYPE_SIZE (type) = bitsize_zero_node;
5550 		    TYPE_SIZE_UNIT (type) = size_zero_node;
5551 		    SET_TYPE_STRUCTURAL_EQUALITY (type);
5552 		  }
5553 	      }
5554 
5555 	    if (decl_context != PARM
5556 		&& (array_ptr_quals != TYPE_UNQUALIFIED
5557 		    || array_ptr_attrs != NULL_TREE
5558 		    || array_parm_static))
5559 	      {
5560 		error_at (loc, "static or type qualifiers in non-parameter array declarator");
5561 		array_ptr_quals = TYPE_UNQUALIFIED;
5562 		array_ptr_attrs = NULL_TREE;
5563 		array_parm_static = 0;
5564 	      }
5565 	    break;
5566 	  }
5567 	case cdk_function:
5568 	  {
5569 	    /* Say it's a definition only for the declarator closest
5570 	       to the identifier, apart possibly from some
5571 	       attributes.  */
5572 	    bool really_funcdef = false;
5573 	    tree arg_types;
5574 	    if (funcdef_flag)
5575 	      {
5576 		const struct c_declarator *t = declarator->declarator;
5577 		while (t->kind == cdk_attrs)
5578 		  t = t->declarator;
5579 		really_funcdef = (t->kind == cdk_id);
5580 	      }
5581 
5582 	    /* Declaring a function type.  Make sure we have a valid
5583 	       type for the function to return.  */
5584 	    if (type == error_mark_node)
5585 	      continue;
5586 
5587 	    size_varies = false;
5588 
5589 	    /* Warn about some types functions can't return.  */
5590 	    if (TREE_CODE (type) == FUNCTION_TYPE)
5591 	      {
5592 		if (name)
5593 		  error_at (loc, "%qE declared as function returning a "
5594 		      		 "function", name);
5595 		else
5596 		  error_at (loc, "type name declared as function "
5597 			    "returning a function");
5598 		type = integer_type_node;
5599 	      }
5600 	    if (TREE_CODE (type) == ARRAY_TYPE)
5601 	      {
5602 		if (name)
5603 		  error_at (loc, "%qE declared as function returning an array",
5604 		      	    name);
5605 		else
5606 		  error_at (loc, "type name declared as function returning "
5607 		      	    "an array");
5608 		type = integer_type_node;
5609 	      }
5610 	    errmsg = targetm.invalid_return_type (type);
5611 	    if (errmsg)
5612 	      {
5613 		error (errmsg);
5614 		type = integer_type_node;
5615 	      }
5616 
5617 	    /* Construct the function type and go to the next
5618 	       inner layer of declarator.  */
5619 	    arg_info = declarator->u.arg_info;
5620 	    arg_types = grokparms (arg_info, really_funcdef);
5621 
5622 	    /* Type qualifiers before the return type of the function
5623 	       qualify the return type, not the function type.  */
5624 	    if (type_quals)
5625 	      {
5626 		/* Type qualifiers on a function return type are
5627 		   normally permitted by the standard but have no
5628 		   effect, so give a warning at -Wreturn-type.
5629 		   Qualifiers on a void return type are banned on
5630 		   function definitions in ISO C; GCC used to used
5631 		   them for noreturn functions.  */
5632 		if (VOID_TYPE_P (type) && really_funcdef)
5633 		  pedwarn (loc, 0,
5634 			   "function definition has qualified void return type");
5635 		else
5636 		  warning_at (loc, OPT_Wignored_qualifiers,
5637 			   "type qualifiers ignored on function return type");
5638 
5639 		type = c_build_qualified_type (type, type_quals);
5640 	      }
5641 	    type_quals = TYPE_UNQUALIFIED;
5642 
5643 	    type = build_function_type (type, arg_types);
5644 	    declarator = declarator->declarator;
5645 
5646 	    /* Set the TYPE_CONTEXTs for each tagged type which is local to
5647 	       the formal parameter list of this FUNCTION_TYPE to point to
5648 	       the FUNCTION_TYPE node itself.  */
5649 	    {
5650 	      c_arg_tag *tag;
5651 	      unsigned ix;
5652 
5653 	      FOR_EACH_VEC_SAFE_ELT_REVERSE (arg_info->tags, ix, tag)
5654 		TYPE_CONTEXT (tag->type) = type;
5655 	    }
5656 	    break;
5657 	  }
5658 	case cdk_pointer:
5659 	  {
5660 	    /* Merge any constancy or volatility into the target type
5661 	       for the pointer.  */
5662 
5663 	    if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
5664 		&& type_quals)
5665 	      pedwarn (loc, OPT_Wpedantic,
5666 		       "ISO C forbids qualified function types");
5667 	    if (type_quals)
5668 	      type = c_build_qualified_type (type, type_quals);
5669 	    size_varies = false;
5670 
5671 	    /* When the pointed-to type involves components of variable size,
5672 	       care must be taken to ensure that the size evaluation code is
5673 	       emitted early enough to dominate all the possible later uses
5674 	       and late enough for the variables on which it depends to have
5675 	       been assigned.
5676 
5677 	       This is expected to happen automatically when the pointed-to
5678 	       type has a name/declaration of it's own, but special attention
5679 	       is required if the type is anonymous.
5680 
5681 	       We handle the NORMAL and FIELD contexts here by attaching an
5682 	       artificial TYPE_DECL to such pointed-to type.  This forces the
5683 	       sizes evaluation at a safe point and ensures it is not deferred
5684 	       until e.g. within a deeper conditional context.
5685 
5686 	       We expect nothing to be needed here for PARM or TYPENAME.
5687 	       Pushing a TYPE_DECL at this point for TYPENAME would actually
5688 	       be incorrect, as we might be in the middle of an expression
5689 	       with side effects on the pointed-to type size "arguments" prior
5690 	       to the pointer declaration point and the fake TYPE_DECL in the
5691 	       enclosing context would force the size evaluation prior to the
5692 	       side effects.  */
5693 
5694 	    if (!TYPE_NAME (type)
5695 		&& (decl_context == NORMAL || decl_context == FIELD)
5696 		&& variably_modified_type_p (type, NULL_TREE))
5697 	      {
5698 		tree decl = build_decl (loc, TYPE_DECL, NULL_TREE, type);
5699 		DECL_ARTIFICIAL (decl) = 1;
5700 		pushdecl (decl);
5701 		finish_decl (decl, loc, NULL_TREE, NULL_TREE, NULL_TREE);
5702 		TYPE_NAME (type) = decl;
5703 	      }
5704 
5705 	    type = c_build_pointer_type (type);
5706 
5707 	    /* Process type qualifiers (such as const or volatile)
5708 	       that were given inside the `*'.  */
5709 	    type_quals = declarator->u.pointer_quals;
5710 
5711 	    declarator = declarator->declarator;
5712 	    break;
5713 	  }
5714 	default:
5715 	  gcc_unreachable ();
5716 	}
5717     }
5718   *decl_attrs = chainon (returned_attrs, *decl_attrs);
5719 
5720   /* Now TYPE has the actual type, apart from any qualifiers in
5721      TYPE_QUALS.  */
5722 
5723   /* Warn about address space used for things other than static memory or
5724      pointers.  */
5725   address_space = DECODE_QUAL_ADDR_SPACE (type_quals);
5726   if (!ADDR_SPACE_GENERIC_P (address_space))
5727     {
5728       if (decl_context == NORMAL)
5729 	{
5730 	  switch (storage_class)
5731 	    {
5732 	    case csc_auto:
5733 	      error ("%qs combined with %<auto%> qualifier for %qE",
5734 		     c_addr_space_name (address_space), name);
5735 	      break;
5736 	    case csc_register:
5737 	      error ("%qs combined with %<register%> qualifier for %qE",
5738 		     c_addr_space_name (address_space), name);
5739 	      break;
5740 	    case csc_none:
5741 	      if (current_function_scope)
5742 		{
5743 		  error ("%qs specified for auto variable %qE",
5744 			 c_addr_space_name (address_space), name);
5745 		  break;
5746 		}
5747 	      break;
5748 	    case csc_static:
5749 	    case csc_extern:
5750 	    case csc_typedef:
5751 	      break;
5752 	    default:
5753 	      gcc_unreachable ();
5754 	    }
5755 	}
5756       else if (decl_context == PARM && TREE_CODE (type) != ARRAY_TYPE)
5757 	{
5758 	  if (name)
5759 	    error ("%qs specified for parameter %qE",
5760 		   c_addr_space_name (address_space), name);
5761 	  else
5762 	    error ("%qs specified for unnamed parameter",
5763 		   c_addr_space_name (address_space));
5764 	}
5765       else if (decl_context == FIELD)
5766 	{
5767 	  if (name)
5768 	    error ("%qs specified for structure field %qE",
5769 		   c_addr_space_name (address_space), name);
5770 	  else
5771 	    error ("%qs specified for structure field",
5772 		   c_addr_space_name (address_space));
5773 	}
5774     }
5775 
5776   /* Check the type and width of a bit-field.  */
5777   if (bitfield)
5778     check_bitfield_type_and_width (&type, width, name);
5779 
5780   /* Reject invalid uses of _Alignas.  */
5781   if (declspecs->alignas_p)
5782     {
5783       if (storage_class == csc_typedef)
5784 	error_at (loc, "alignment specified for typedef %qE", name);
5785       else if (storage_class == csc_register)
5786 	error_at (loc, "alignment specified for %<register%> object %qE",
5787 		  name);
5788       else if (decl_context == PARM)
5789 	{
5790 	  if (name)
5791 	    error_at (loc, "alignment specified for parameter %qE", name);
5792 	  else
5793 	    error_at (loc, "alignment specified for unnamed parameter");
5794 	}
5795       else if (bitfield)
5796 	{
5797 	  if (name)
5798 	    error_at (loc, "alignment specified for bit-field %qE", name);
5799 	  else
5800 	    error_at (loc, "alignment specified for unnamed bit-field");
5801 	}
5802       else if (TREE_CODE (type) == FUNCTION_TYPE)
5803 	error_at (loc, "alignment specified for function %qE", name);
5804       else if (declspecs->align_log != -1)
5805 	{
5806 	  alignas_align = 1U << declspecs->align_log;
5807 	  if (alignas_align < TYPE_ALIGN_UNIT (type))
5808 	    {
5809 	      if (name)
5810 		error_at (loc, "%<_Alignas%> specifiers cannot reduce "
5811 			  "alignment of %qE", name);
5812 	      else
5813 		error_at (loc, "%<_Alignas%> specifiers cannot reduce "
5814 			  "alignment of unnamed field");
5815 	      alignas_align = 0;
5816 	    }
5817 	}
5818     }
5819 
5820   /* Did array size calculations overflow or does the array cover more
5821      than half of the address-space?  */
5822   if (TREE_CODE (type) == ARRAY_TYPE
5823       && COMPLETE_TYPE_P (type)
5824       && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST
5825       && ! valid_constant_size_p (TYPE_SIZE_UNIT (type)))
5826     {
5827       if (name)
5828 	error_at (loc, "size of array %qE is too large", name);
5829       else
5830 	error_at (loc, "size of unnamed array is too large");
5831       /* If we proceed with the array type as it is, we'll eventually
5832 	 crash in tree_low_cst().  */
5833       type = error_mark_node;
5834     }
5835 
5836   /* If this is declaring a typedef name, return a TYPE_DECL.  */
5837 
5838   if (storage_class == csc_typedef)
5839     {
5840       tree decl;
5841       if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
5842 	  && type_quals)
5843 	pedwarn (loc, OPT_Wpedantic,
5844 		 "ISO C forbids qualified function types");
5845       if (type_quals)
5846 	type = c_build_qualified_type (type, type_quals);
5847       decl = build_decl (declarator->id_loc,
5848 			 TYPE_DECL, declarator->u.id, type);
5849       if (declspecs->explicit_signed_p)
5850 	C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
5851       if (declspecs->inline_p)
5852 	pedwarn (loc, 0,"typedef %q+D declared %<inline%>", decl);
5853       if (declspecs->noreturn_p)
5854 	pedwarn (loc, 0,"typedef %q+D declared %<_Noreturn%>", decl);
5855 
5856       if (warn_cxx_compat && declarator->u.id != NULL_TREE)
5857 	{
5858 	  struct c_binding *b = I_TAG_BINDING (declarator->u.id);
5859 
5860 	  if (b != NULL
5861 	      && b->decl != NULL_TREE
5862 	      && (B_IN_CURRENT_SCOPE (b)
5863 		  || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b)))
5864 	      && TYPE_MAIN_VARIANT (b->decl) != TYPE_MAIN_VARIANT (type))
5865 	    {
5866 	      warning_at (declarator->id_loc, OPT_Wc___compat,
5867 			  ("using %qD as both a typedef and a tag is "
5868 			   "invalid in C++"),
5869 			  decl);
5870 	      if (b->locus != UNKNOWN_LOCATION)
5871 		inform (b->locus, "originally defined here");
5872 	    }
5873 	}
5874 
5875       return decl;
5876     }
5877 
5878   /* If this is a type name (such as, in a cast or sizeof),
5879      compute the type and return it now.  */
5880 
5881   if (decl_context == TYPENAME)
5882     {
5883       /* Note that the grammar rejects storage classes in typenames
5884 	 and fields.  */
5885       gcc_assert (storage_class == csc_none && !threadp
5886 		  && !declspecs->inline_p && !declspecs->noreturn_p);
5887       if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
5888 	  && type_quals)
5889 	pedwarn (loc, OPT_Wpedantic,
5890 		 "ISO C forbids const or volatile function types");
5891       if (type_quals)
5892 	type = c_build_qualified_type (type, type_quals);
5893       return type;
5894     }
5895 
5896   if (pedantic && decl_context == FIELD
5897       && variably_modified_type_p (type, NULL_TREE))
5898     {
5899       /* C99 6.7.2.1p8 */
5900       pedwarn (loc, OPT_Wpedantic, "a member of a structure or union cannot "
5901 	       "have a variably modified type");
5902     }
5903 
5904   /* Aside from typedefs and type names (handle above),
5905      `void' at top level (not within pointer)
5906      is allowed only in public variables.
5907      We don't complain about parms either, but that is because
5908      a better error message can be made later.  */
5909 
5910   if (VOID_TYPE_P (type) && decl_context != PARM
5911       && !((decl_context != FIELD && TREE_CODE (type) != FUNCTION_TYPE)
5912 	    && (storage_class == csc_extern
5913 		|| (current_scope == file_scope
5914 		    && !(storage_class == csc_static
5915 			 || storage_class == csc_register)))))
5916     {
5917       error_at (loc, "variable or field %qE declared void", name);
5918       type = integer_type_node;
5919     }
5920 
5921   /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
5922      or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE.  */
5923 
5924   {
5925     tree decl;
5926 
5927     if (decl_context == PARM)
5928       {
5929 	tree promoted_type;
5930 
5931 	/* A parameter declared as an array of T is really a pointer to T.
5932 	   One declared as a function is really a pointer to a function.  */
5933 
5934 	if (TREE_CODE (type) == ARRAY_TYPE)
5935 	  {
5936 	    /* Transfer const-ness of array into that of type pointed to.  */
5937 	    type = TREE_TYPE (type);
5938 	    if (type_quals)
5939 	      type = c_build_qualified_type (type, type_quals);
5940 	    type = c_build_pointer_type (type);
5941 	    type_quals = array_ptr_quals;
5942 	    if (type_quals)
5943 	      type = c_build_qualified_type (type, type_quals);
5944 
5945 	    /* We don't yet implement attributes in this context.  */
5946 	    if (array_ptr_attrs != NULL_TREE)
5947 	      warning_at (loc, OPT_Wattributes,
5948 			  "attributes in parameter array declarator ignored");
5949 
5950 	    size_varies = false;
5951 	  }
5952 	else if (TREE_CODE (type) == FUNCTION_TYPE)
5953 	  {
5954 	    if (type_quals)
5955 	      pedwarn (loc, OPT_Wpedantic,
5956 		       "ISO C forbids qualified function types");
5957 	    if (type_quals)
5958 	      type = c_build_qualified_type (type, type_quals);
5959 	    type = c_build_pointer_type (type);
5960 	    type_quals = TYPE_UNQUALIFIED;
5961 	  }
5962 	else if (type_quals)
5963 	  type = c_build_qualified_type (type, type_quals);
5964 
5965 	decl = build_decl (declarator->id_loc,
5966 			   PARM_DECL, declarator->u.id, type);
5967 	if (size_varies)
5968 	  C_DECL_VARIABLE_SIZE (decl) = 1;
5969 
5970 	/* Compute the type actually passed in the parmlist,
5971 	   for the case where there is no prototype.
5972 	   (For example, shorts and chars are passed as ints.)
5973 	   When there is a prototype, this is overridden later.  */
5974 
5975 	if (type == error_mark_node)
5976 	  promoted_type = type;
5977 	else
5978 	  promoted_type = c_type_promotes_to (type);
5979 
5980 	DECL_ARG_TYPE (decl) = promoted_type;
5981 	if (declspecs->inline_p)
5982 	  pedwarn (loc, 0, "parameter %q+D declared %<inline%>", decl);
5983 	if (declspecs->noreturn_p)
5984 	  pedwarn (loc, 0, "parameter %q+D declared %<_Noreturn%>", decl);
5985       }
5986     else if (decl_context == FIELD)
5987       {
5988 	/* Note that the grammar rejects storage classes in typenames
5989 	   and fields.  */
5990 	gcc_assert (storage_class == csc_none && !threadp
5991 		    && !declspecs->inline_p && !declspecs->noreturn_p);
5992 
5993 	/* Structure field.  It may not be a function.  */
5994 
5995 	if (TREE_CODE (type) == FUNCTION_TYPE)
5996 	  {
5997 	    error_at (loc, "field %qE declared as a function", name);
5998 	    type = build_pointer_type (type);
5999 	  }
6000 	else if (TREE_CODE (type) != ERROR_MARK
6001 		 && !COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (type))
6002 	  {
6003 	    if (name)
6004 	      error_at (loc, "field %qE has incomplete type", name);
6005 	    else
6006 	      error_at (loc, "unnamed field has incomplete type");
6007 	    type = error_mark_node;
6008 	  }
6009 	type = c_build_qualified_type (type, type_quals);
6010 	decl = build_decl (declarator->id_loc,
6011 			   FIELD_DECL, declarator->u.id, type);
6012 	DECL_NONADDRESSABLE_P (decl) = bitfield;
6013 	if (bitfield && !declarator->u.id)
6014 	  TREE_NO_WARNING (decl) = 1;
6015 
6016 	if (size_varies)
6017 	  C_DECL_VARIABLE_SIZE (decl) = 1;
6018       }
6019     else if (TREE_CODE (type) == FUNCTION_TYPE)
6020       {
6021 	if (storage_class == csc_register || threadp)
6022 	  {
6023 	    error_at (loc, "invalid storage class for function %qE", name);
6024 	  }
6025 	else if (current_scope != file_scope)
6026 	  {
6027 	    /* Function declaration not at file scope.  Storage
6028 	       classes other than `extern' are not allowed, C99
6029 	       6.7.1p5, and `extern' makes no difference.  However,
6030 	       GCC allows 'auto', perhaps with 'inline', to support
6031 	       nested functions.  */
6032 	    if (storage_class == csc_auto)
6033 		pedwarn (loc, OPT_Wpedantic,
6034 			 "invalid storage class for function %qE", name);
6035 	    else if (storage_class == csc_static)
6036 	      {
6037 		error_at (loc, "invalid storage class for function %qE", name);
6038 		if (funcdef_flag)
6039 		  storage_class = declspecs->storage_class = csc_none;
6040 		else
6041 		  return 0;
6042 	      }
6043 	  }
6044 
6045 	decl = build_decl (declarator->id_loc,
6046 			   FUNCTION_DECL, declarator->u.id, type);
6047 	decl = build_decl_attribute_variant (decl, decl_attr);
6048 
6049 	if (pedantic && type_quals && !DECL_IN_SYSTEM_HEADER (decl))
6050 	  pedwarn (loc, OPT_Wpedantic,
6051 		   "ISO C forbids qualified function types");
6052 
6053 	/* Every function declaration is an external reference
6054 	   (DECL_EXTERNAL) except for those which are not at file
6055 	   scope and are explicitly declared "auto".  This is
6056 	   forbidden by standard C (C99 6.7.1p5) and is interpreted by
6057 	   GCC to signify a forward declaration of a nested function.  */
6058 	if (storage_class == csc_auto && current_scope != file_scope)
6059 	  DECL_EXTERNAL (decl) = 0;
6060 	/* In C99, a function which is declared 'inline' with 'extern'
6061 	   is not an external reference (which is confusing).  It
6062 	   means that the later definition of the function must be output
6063 	   in this file, C99 6.7.4p6.  In GNU C89, a function declared
6064 	   'extern inline' is an external reference.  */
6065 	else if (declspecs->inline_p && storage_class != csc_static)
6066 	  DECL_EXTERNAL (decl) = ((storage_class == csc_extern)
6067 				  == flag_gnu89_inline);
6068 	else
6069 	  DECL_EXTERNAL (decl) = !initialized;
6070 
6071 	/* Record absence of global scope for `static' or `auto'.  */
6072 	TREE_PUBLIC (decl)
6073 	  = !(storage_class == csc_static || storage_class == csc_auto);
6074 
6075 	/* For a function definition, record the argument information
6076 	   block where store_parm_decls will look for it.  */
6077 	if (funcdef_flag)
6078 	  current_function_arg_info = arg_info;
6079 
6080 	if (declspecs->default_int_p)
6081 	  C_FUNCTION_IMPLICIT_INT (decl) = 1;
6082 
6083 	/* Record presence of `inline' and `_Noreturn', if it is
6084 	   reasonable.  */
6085 	if (flag_hosted && MAIN_NAME_P (declarator->u.id))
6086 	  {
6087 	    if (declspecs->inline_p)
6088 	      pedwarn (loc, 0, "cannot inline function %<main%>");
6089 	    if (declspecs->noreturn_p)
6090 	      pedwarn (loc, 0, "%<main%> declared %<_Noreturn%>");
6091 	  }
6092 	else
6093 	  {
6094 	    if (declspecs->inline_p)
6095 	      /* Record that the function is declared `inline'.  */
6096 	      DECL_DECLARED_INLINE_P (decl) = 1;
6097 	    if (declspecs->noreturn_p)
6098 	      {
6099 		if (!flag_isoc11)
6100 		  {
6101 		    if (flag_isoc99)
6102 		      pedwarn (loc, OPT_Wpedantic,
6103 			       "ISO C99 does not support %<_Noreturn%>");
6104 		    else
6105 		      pedwarn (loc, OPT_Wpedantic,
6106 			       "ISO C90 does not support %<_Noreturn%>");
6107 		  }
6108 		TREE_THIS_VOLATILE (decl) = 1;
6109 	      }
6110 	  }
6111       }
6112     else
6113       {
6114 	/* It's a variable.  */
6115 	/* An uninitialized decl with `extern' is a reference.  */
6116 	int extern_ref = !initialized && storage_class == csc_extern;
6117 
6118 	type = c_build_qualified_type (type, type_quals);
6119 
6120 	/* C99 6.2.2p7: It is invalid (compile-time undefined
6121 	   behavior) to create an 'extern' declaration for a
6122 	   variable if there is a global declaration that is
6123 	   'static' and the global declaration is not visible.
6124 	   (If the static declaration _is_ currently visible,
6125 	   the 'extern' declaration is taken to refer to that decl.) */
6126 	if (extern_ref && current_scope != file_scope)
6127 	  {
6128 	    tree global_decl  = identifier_global_value (declarator->u.id);
6129 	    tree visible_decl = lookup_name (declarator->u.id);
6130 
6131 	    if (global_decl
6132 		&& global_decl != visible_decl
6133 		&& TREE_CODE (global_decl) == VAR_DECL
6134 		&& !TREE_PUBLIC (global_decl))
6135 	      error_at (loc, "variable previously declared %<static%> "
6136 			"redeclared %<extern%>");
6137 	  }
6138 
6139 	decl = build_decl (declarator->id_loc,
6140 			   VAR_DECL, declarator->u.id, type);
6141 	if (size_varies)
6142 	  C_DECL_VARIABLE_SIZE (decl) = 1;
6143 
6144 	if (declspecs->inline_p)
6145 	  pedwarn (loc, 0, "variable %q+D declared %<inline%>", decl);
6146 	if (declspecs->noreturn_p)
6147 	  pedwarn (loc, 0, "variable %q+D declared %<_Noreturn%>", decl);
6148 
6149 	/* At file scope, an initialized extern declaration may follow
6150 	   a static declaration.  In that case, DECL_EXTERNAL will be
6151 	   reset later in start_decl.  */
6152 	DECL_EXTERNAL (decl) = (storage_class == csc_extern);
6153 
6154 	/* At file scope, the presence of a `static' or `register' storage
6155 	   class specifier, or the absence of all storage class specifiers
6156 	   makes this declaration a definition (perhaps tentative).  Also,
6157 	   the absence of `static' makes it public.  */
6158 	if (current_scope == file_scope)
6159 	  {
6160 	    TREE_PUBLIC (decl) = storage_class != csc_static;
6161 	    TREE_STATIC (decl) = !extern_ref;
6162 	  }
6163 	/* Not at file scope, only `static' makes a static definition.  */
6164 	else
6165 	  {
6166 	    TREE_STATIC (decl) = (storage_class == csc_static);
6167 	    TREE_PUBLIC (decl) = extern_ref;
6168 	  }
6169 
6170 	if (threadp)
6171 	  DECL_TLS_MODEL (decl) = decl_default_tls_model (decl);
6172       }
6173 
6174     if ((storage_class == csc_extern
6175 	 || (storage_class == csc_none
6176 	     && TREE_CODE (type) == FUNCTION_TYPE
6177 	     && !funcdef_flag))
6178 	&& variably_modified_type_p (type, NULL_TREE))
6179       {
6180 	/* C99 6.7.5.2p2 */
6181 	if (TREE_CODE (type) == FUNCTION_TYPE)
6182 	  error_at (loc, "non-nested function with variably modified type");
6183 	else
6184 	  error_at (loc, "object with variably modified type must have "
6185 	      	    "no linkage");
6186       }
6187 
6188     /* Record `register' declaration for warnings on &
6189        and in case doing stupid register allocation.  */
6190 
6191     if (storage_class == csc_register)
6192       {
6193 	C_DECL_REGISTER (decl) = 1;
6194 	DECL_REGISTER (decl) = 1;
6195       }
6196 
6197     /* Record constancy and volatility.  */
6198     c_apply_type_quals_to_decl (type_quals, decl);
6199 
6200     /* Apply _Alignas specifiers.  */
6201     if (alignas_align)
6202       {
6203 	DECL_ALIGN (decl) = alignas_align * BITS_PER_UNIT;
6204 	DECL_USER_ALIGN (decl) = 1;
6205       }
6206 
6207     /* If a type has volatile components, it should be stored in memory.
6208        Otherwise, the fact that those components are volatile
6209        will be ignored, and would even crash the compiler.
6210        Of course, this only makes sense on  VAR,PARM, and RESULT decl's.   */
6211     if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (decl))
6212 	&& (TREE_CODE (decl) == VAR_DECL ||  TREE_CODE (decl) == PARM_DECL
6213 	  || TREE_CODE (decl) == RESULT_DECL))
6214       {
6215 	/* It is not an error for a structure with volatile fields to
6216 	   be declared register, but reset DECL_REGISTER since it
6217 	   cannot actually go in a register.  */
6218 	int was_reg = C_DECL_REGISTER (decl);
6219 	C_DECL_REGISTER (decl) = 0;
6220 	DECL_REGISTER (decl) = 0;
6221 	c_mark_addressable (decl);
6222 	C_DECL_REGISTER (decl) = was_reg;
6223       }
6224 
6225   /* This is the earliest point at which we might know the assembler
6226      name of a variable.  Thus, if it's known before this, die horribly.  */
6227     gcc_assert (!DECL_ASSEMBLER_NAME_SET_P (decl));
6228 
6229     if (warn_cxx_compat
6230 	&& TREE_CODE (decl) == VAR_DECL
6231 	&& TREE_PUBLIC (decl)
6232 	&& TREE_STATIC (decl)
6233 	&& (TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
6234 	    || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
6235 	    || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
6236 	&& TYPE_NAME (TREE_TYPE (decl)) == NULL_TREE)
6237       warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat,
6238 		  ("non-local variable %qD with anonymous type is "
6239 		   "questionable in C++"),
6240 		  decl);
6241 
6242     return decl;
6243   }
6244 }
6245 
6246 /* Decode the parameter-list info for a function type or function definition.
6247    The argument is the value returned by `get_parm_info' (or made in c-parse.c
6248    if there is an identifier list instead of a parameter decl list).
6249    These two functions are separate because when a function returns
6250    or receives functions then each is called multiple times but the order
6251    of calls is different.  The last call to `grokparms' is always the one
6252    that contains the formal parameter names of a function definition.
6253 
6254    Return a list of arg types to use in the FUNCTION_TYPE for this function.
6255 
6256    FUNCDEF_FLAG is true for a function definition, false for
6257    a mere declaration.  A nonempty identifier-list gets an error message
6258    when FUNCDEF_FLAG is false.  */
6259 
6260 static tree
6261 grokparms (struct c_arg_info *arg_info, bool funcdef_flag)
6262 {
6263   tree arg_types = arg_info->types;
6264 
6265   if (funcdef_flag && arg_info->had_vla_unspec)
6266     {
6267       /* A function definition isn't function prototype scope C99 6.2.1p4.  */
6268       /* C99 6.7.5.2p4 */
6269       error ("%<[*]%> not allowed in other than function prototype scope");
6270     }
6271 
6272   if (arg_types == 0 && !funcdef_flag && !in_system_header)
6273     warning (OPT_Wstrict_prototypes,
6274 	     "function declaration isn%'t a prototype");
6275 
6276   if (arg_types == error_mark_node)
6277     return 0;  /* don't set TYPE_ARG_TYPES in this case */
6278 
6279   else if (arg_types && TREE_CODE (TREE_VALUE (arg_types)) == IDENTIFIER_NODE)
6280     {
6281       if (!funcdef_flag)
6282 	{
6283 	  pedwarn (input_location, 0, "parameter names (without types) in function declaration");
6284 	  arg_info->parms = NULL_TREE;
6285 	}
6286       else
6287 	arg_info->parms = arg_info->types;
6288 
6289       arg_info->types = 0;
6290       return 0;
6291     }
6292   else
6293     {
6294       tree parm, type, typelt;
6295       unsigned int parmno;
6296       const char *errmsg;
6297 
6298       /* If there is a parameter of incomplete type in a definition,
6299 	 this is an error.  In a declaration this is valid, and a
6300 	 struct or union type may be completed later, before any calls
6301 	 or definition of the function.  In the case where the tag was
6302 	 first declared within the parameter list, a warning has
6303 	 already been given.  If a parameter has void type, then
6304 	 however the function cannot be defined or called, so
6305 	 warn.  */
6306 
6307       for (parm = arg_info->parms, typelt = arg_types, parmno = 1;
6308 	   parm;
6309 	   parm = DECL_CHAIN (parm), typelt = TREE_CHAIN (typelt), parmno++)
6310 	{
6311 	  type = TREE_VALUE (typelt);
6312 	  if (type == error_mark_node)
6313 	    continue;
6314 
6315 	  if (!COMPLETE_TYPE_P (type))
6316 	    {
6317 	      if (funcdef_flag)
6318 		{
6319 		  if (DECL_NAME (parm))
6320 		    error_at (input_location,
6321 			      "parameter %u (%q+D) has incomplete type",
6322 			      parmno, parm);
6323 		  else
6324 		    error_at (DECL_SOURCE_LOCATION (parm),
6325 			      "parameter %u has incomplete type",
6326 			      parmno);
6327 
6328 		  TREE_VALUE (typelt) = error_mark_node;
6329 		  TREE_TYPE (parm) = error_mark_node;
6330 		  arg_types = NULL_TREE;
6331 		}
6332 	      else if (VOID_TYPE_P (type))
6333 		{
6334 		  if (DECL_NAME (parm))
6335 		    warning_at (input_location, 0,
6336 				"parameter %u (%q+D) has void type",
6337 				parmno, parm);
6338 		  else
6339 		    warning_at (DECL_SOURCE_LOCATION (parm), 0,
6340 				"parameter %u has void type",
6341 				parmno);
6342 		}
6343 	    }
6344 
6345 	  errmsg = targetm.invalid_parameter_type (type);
6346 	  if (errmsg)
6347 	    {
6348 	      error (errmsg);
6349 	      TREE_VALUE (typelt) = error_mark_node;
6350 	      TREE_TYPE (parm) = error_mark_node;
6351 	      arg_types = NULL_TREE;
6352 	    }
6353 
6354 	  if (DECL_NAME (parm) && TREE_USED (parm))
6355 	    warn_if_shadowing (parm);
6356 	}
6357       return arg_types;
6358     }
6359 }
6360 
6361 /* Allocate and initialize a c_arg_info structure from the parser's
6362    obstack.  */
6363 
6364 struct c_arg_info *
6365 build_arg_info (void)
6366 {
6367   struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
6368   ret->parms = NULL_TREE;
6369   ret->tags = NULL;
6370   ret->types = NULL_TREE;
6371   ret->others = NULL_TREE;
6372   ret->pending_sizes = NULL;
6373   ret->had_vla_unspec = 0;
6374   return ret;
6375 }
6376 
6377 /* Take apart the current scope and return a c_arg_info structure with
6378    info on a parameter list just parsed.
6379 
6380    This structure is later fed to 'grokparms' and 'store_parm_decls'.
6381 
6382    ELLIPSIS being true means the argument list ended in '...' so don't
6383    append a sentinel (void_list_node) to the end of the type-list.
6384 
6385    EXPR is NULL or an expression that needs to be evaluated for the
6386    side effects of array size expressions in the parameters.  */
6387 
6388 struct c_arg_info *
6389 get_parm_info (bool ellipsis, tree expr)
6390 {
6391   struct c_binding *b = current_scope->bindings;
6392   struct c_arg_info *arg_info = build_arg_info ();
6393 
6394   tree parms    = 0;
6395   vec<c_arg_tag, va_gc> *tags = NULL;
6396   tree types    = 0;
6397   tree others   = 0;
6398 
6399   static bool explained_incomplete_types = false;
6400   bool gave_void_only_once_err = false;
6401 
6402   arg_info->had_vla_unspec = current_scope->had_vla_unspec;
6403 
6404   /* The bindings in this scope must not get put into a block.
6405      We will take care of deleting the binding nodes.  */
6406   current_scope->bindings = 0;
6407 
6408   /* This function is only called if there was *something* on the
6409      parameter list.  */
6410   gcc_assert (b);
6411 
6412   /* A parameter list consisting solely of 'void' indicates that the
6413      function takes no arguments.  But if the 'void' is qualified
6414      (by 'const' or 'volatile'), or has a storage class specifier
6415      ('register'), then the behavior is undefined; issue an error.
6416      Typedefs for 'void' are OK (see DR#157).  */
6417   if (b->prev == 0			    /* one binding */
6418       && TREE_CODE (b->decl) == PARM_DECL   /* which is a parameter */
6419       && !DECL_NAME (b->decl)               /* anonymous */
6420       && VOID_TYPE_P (TREE_TYPE (b->decl))) /* of void type */
6421     {
6422       if (TREE_THIS_VOLATILE (b->decl)
6423 	  || TREE_READONLY (b->decl)
6424 	  || C_DECL_REGISTER (b->decl))
6425 	error ("%<void%> as only parameter may not be qualified");
6426 
6427       /* There cannot be an ellipsis.  */
6428       if (ellipsis)
6429 	error ("%<void%> must be the only parameter");
6430 
6431       arg_info->types = void_list_node;
6432       return arg_info;
6433     }
6434 
6435   if (!ellipsis)
6436     types = void_list_node;
6437 
6438   /* Break up the bindings list into parms, tags, types, and others;
6439      apply sanity checks; purge the name-to-decl bindings.  */
6440   while (b)
6441     {
6442       tree decl = b->decl;
6443       tree type = TREE_TYPE (decl);
6444       c_arg_tag tag;
6445       const char *keyword;
6446 
6447       switch (TREE_CODE (decl))
6448 	{
6449 	case PARM_DECL:
6450 	  if (b->id)
6451 	    {
6452 	      gcc_assert (I_SYMBOL_BINDING (b->id) == b);
6453 	      I_SYMBOL_BINDING (b->id) = b->shadowed;
6454 	    }
6455 
6456 	  /* Check for forward decls that never got their actual decl.  */
6457 	  if (TREE_ASM_WRITTEN (decl))
6458 	    error ("parameter %q+D has just a forward declaration", decl);
6459 	  /* Check for (..., void, ...) and issue an error.  */
6460 	  else if (VOID_TYPE_P (type) && !DECL_NAME (decl))
6461 	    {
6462 	      if (!gave_void_only_once_err)
6463 		{
6464 		  error ("%<void%> must be the only parameter");
6465 		  gave_void_only_once_err = true;
6466 		}
6467 	    }
6468 	  else
6469 	    {
6470 	      /* Valid parameter, add it to the list.  */
6471 	      DECL_CHAIN (decl) = parms;
6472 	      parms = decl;
6473 
6474 	      /* Since there is a prototype, args are passed in their
6475 		 declared types.  The back end may override this later.  */
6476 	      DECL_ARG_TYPE (decl) = type;
6477 	      types = tree_cons (0, type, types);
6478 	    }
6479 	  break;
6480 
6481 	case ENUMERAL_TYPE: keyword = "enum"; goto tag;
6482 	case UNION_TYPE:    keyword = "union"; goto tag;
6483 	case RECORD_TYPE:   keyword = "struct"; goto tag;
6484 	tag:
6485 	  /* Types may not have tag-names, in which case the type
6486 	     appears in the bindings list with b->id NULL.  */
6487 	  if (b->id)
6488 	    {
6489 	      gcc_assert (I_TAG_BINDING (b->id) == b);
6490 	      I_TAG_BINDING (b->id) = b->shadowed;
6491 	    }
6492 
6493 	  /* Warn about any struct, union or enum tags defined in a
6494 	     parameter list.  The scope of such types is limited to
6495 	     the parameter list, which is rarely if ever desirable
6496 	     (it's impossible to call such a function with type-
6497 	     correct arguments).  An anonymous union parm type is
6498 	     meaningful as a GNU extension, so don't warn for that.  */
6499 	  if (TREE_CODE (decl) != UNION_TYPE || b->id != 0)
6500 	    {
6501 	      if (b->id)
6502 		/* The %s will be one of 'struct', 'union', or 'enum'.  */
6503 		warning (0, "%<%s %E%> declared inside parameter list",
6504 			 keyword, b->id);
6505 	      else
6506 		/* The %s will be one of 'struct', 'union', or 'enum'.  */
6507 		warning (0, "anonymous %s declared inside parameter list",
6508 			 keyword);
6509 
6510 	      if (!explained_incomplete_types)
6511 		{
6512 		  warning (0, "its scope is only this definition or declaration,"
6513 			   " which is probably not what you want");
6514 		  explained_incomplete_types = true;
6515 		}
6516 	    }
6517 
6518 	  tag.id = b->id;
6519 	  tag.type = decl;
6520 	  vec_safe_push (tags, tag);
6521 	  break;
6522 
6523 	case CONST_DECL:
6524 	case TYPE_DECL:
6525 	case FUNCTION_DECL:
6526 	  /* CONST_DECLs appear here when we have an embedded enum,
6527 	     and TYPE_DECLs appear here when we have an embedded struct
6528 	     or union.  No warnings for this - we already warned about the
6529 	     type itself.  FUNCTION_DECLs appear when there is an implicit
6530 	     function declaration in the parameter list.  */
6531 
6532 	  /* When we reinsert this decl in the function body, we need
6533 	     to reconstruct whether it was marked as nested.  */
6534 	  gcc_assert (TREE_CODE (decl) == FUNCTION_DECL
6535 		      ? b->nested
6536 		      : !b->nested);
6537 	  DECL_CHAIN (decl) = others;
6538 	  others = decl;
6539 	  /* fall through */
6540 
6541 	case ERROR_MARK:
6542 	  /* error_mark_node appears here when we have an undeclared
6543 	     variable.  Just throw it away.  */
6544 	  if (b->id)
6545 	    {
6546 	      gcc_assert (I_SYMBOL_BINDING (b->id) == b);
6547 	      I_SYMBOL_BINDING (b->id) = b->shadowed;
6548 	    }
6549 	  break;
6550 
6551 	  /* Other things that might be encountered.  */
6552 	case LABEL_DECL:
6553 	case VAR_DECL:
6554 	default:
6555 	  gcc_unreachable ();
6556 	}
6557 
6558       b = free_binding_and_advance (b);
6559     }
6560 
6561   arg_info->parms = parms;
6562   arg_info->tags = tags;
6563   arg_info->types = types;
6564   arg_info->others = others;
6565   arg_info->pending_sizes = expr;
6566   return arg_info;
6567 }
6568 
6569 /* Get the struct, enum or union (CODE says which) with tag NAME.
6570    Define the tag as a forward-reference with location LOC if it is
6571    not defined.  Return a c_typespec structure for the type
6572    specifier.  */
6573 
6574 struct c_typespec
6575 parser_xref_tag (location_t loc, enum tree_code code, tree name)
6576 {
6577   struct c_typespec ret;
6578   tree ref;
6579   location_t refloc;
6580 
6581   ret.expr = NULL_TREE;
6582   ret.expr_const_operands = true;
6583 
6584   /* If a cross reference is requested, look up the type
6585      already defined for this tag and return it.  */
6586 
6587   ref = lookup_tag (code, name, 0, &refloc);
6588   /* If this is the right type of tag, return what we found.
6589      (This reference will be shadowed by shadow_tag later if appropriate.)
6590      If this is the wrong type of tag, do not return it.  If it was the
6591      wrong type in the same scope, we will have had an error
6592      message already; if in a different scope and declaring
6593      a name, pending_xref_error will give an error message; but if in a
6594      different scope and not declaring a name, this tag should
6595      shadow the previous declaration of a different type of tag, and
6596      this would not work properly if we return the reference found.
6597      (For example, with "struct foo" in an outer scope, "union foo;"
6598      must shadow that tag with a new one of union type.)  */
6599   ret.kind = (ref ? ctsk_tagref : ctsk_tagfirstref);
6600   if (ref && TREE_CODE (ref) == code)
6601     {
6602       if (C_TYPE_DEFINED_IN_STRUCT (ref)
6603 	  && loc != UNKNOWN_LOCATION
6604 	  && warn_cxx_compat)
6605 	{
6606 	  switch (code)
6607 	    {
6608 	    case ENUMERAL_TYPE:
6609 	      warning_at (loc, OPT_Wc___compat,
6610 			  ("enum type defined in struct or union "
6611 			   "is not visible in C++"));
6612 	      inform (refloc, "enum type defined here");
6613 	      break;
6614 	    case RECORD_TYPE:
6615 	      warning_at (loc, OPT_Wc___compat,
6616 			  ("struct defined in struct or union "
6617 			   "is not visible in C++"));
6618 	      inform (refloc, "struct defined here");
6619 	      break;
6620 	    case UNION_TYPE:
6621 	      warning_at (loc, OPT_Wc___compat,
6622 			  ("union defined in struct or union "
6623 			   "is not visible in C++"));
6624 	      inform (refloc, "union defined here");
6625 	      break;
6626 	    default:
6627 	      gcc_unreachable();
6628 	    }
6629 	}
6630 
6631       ret.spec = ref;
6632       return ret;
6633     }
6634 
6635   /* If no such tag is yet defined, create a forward-reference node
6636      and record it as the "definition".
6637      When a real declaration of this type is found,
6638      the forward-reference will be altered into a real type.  */
6639 
6640   ref = make_node (code);
6641   if (code == ENUMERAL_TYPE)
6642     {
6643       /* Give the type a default layout like unsigned int
6644 	 to avoid crashing if it does not get defined.  */
6645       SET_TYPE_MODE (ref, TYPE_MODE (unsigned_type_node));
6646       TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node);
6647       TYPE_USER_ALIGN (ref) = 0;
6648       TYPE_UNSIGNED (ref) = 1;
6649       TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
6650       TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
6651       TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
6652     }
6653 
6654   pushtag (loc, name, ref);
6655 
6656   ret.spec = ref;
6657   return ret;
6658 }
6659 
6660 /* Get the struct, enum or union (CODE says which) with tag NAME.
6661    Define the tag as a forward-reference if it is not defined.
6662    Return a tree for the type.  */
6663 
6664 tree
6665 xref_tag (enum tree_code code, tree name)
6666 {
6667   return parser_xref_tag (input_location, code, name).spec;
6668 }
6669 
6670 /* Make sure that the tag NAME is defined *in the current scope*
6671    at least as a forward reference.
6672    LOC is the location of the struct's definition.
6673    CODE says which kind of tag NAME ought to be.
6674 
6675    This stores the current value of the file static STRUCT_PARSE_INFO
6676    in *ENCLOSING_STRUCT_PARSE_INFO, and points STRUCT_PARSE_INFO at a
6677    new c_struct_parse_info structure.  The old value of
6678    STRUCT_PARSE_INFO is restored in finish_struct.  */
6679 
6680 tree
6681 start_struct (location_t loc, enum tree_code code, tree name,
6682 	      struct c_struct_parse_info **enclosing_struct_parse_info)
6683 {
6684   /* If there is already a tag defined at this scope
6685      (as a forward reference), just return it.  */
6686 
6687   tree ref = NULL_TREE;
6688   location_t refloc = UNKNOWN_LOCATION;
6689 
6690   if (name != NULL_TREE)
6691     ref = lookup_tag (code, name, 1, &refloc);
6692   if (ref && TREE_CODE (ref) == code)
6693     {
6694       if (TYPE_SIZE (ref))
6695 	{
6696 	  if (code == UNION_TYPE)
6697 	    error_at (loc, "redefinition of %<union %E%>", name);
6698 	  else
6699 	    error_at (loc, "redefinition of %<struct %E%>", name);
6700 	  if (refloc != UNKNOWN_LOCATION)
6701 	    inform (refloc, "originally defined here");
6702 	  /* Don't create structures using a name already in use.  */
6703 	  ref = NULL_TREE;
6704 	}
6705       else if (C_TYPE_BEING_DEFINED (ref))
6706 	{
6707 	  if (code == UNION_TYPE)
6708 	    error_at (loc, "nested redefinition of %<union %E%>", name);
6709 	  else
6710 	    error_at (loc, "nested redefinition of %<struct %E%>", name);
6711 	  /* Don't bother to report "originally defined here" for a
6712 	     nested redefinition; the original definition should be
6713 	     obvious.  */
6714 	  /* Don't create structures that contain themselves.  */
6715 	  ref = NULL_TREE;
6716 	}
6717     }
6718 
6719   /* Otherwise create a forward-reference just so the tag is in scope.  */
6720 
6721   if (ref == NULL_TREE || TREE_CODE (ref) != code)
6722     {
6723       ref = make_node (code);
6724       pushtag (loc, name, ref);
6725     }
6726 
6727   C_TYPE_BEING_DEFINED (ref) = 1;
6728   TYPE_PACKED (ref) = flag_pack_struct;
6729 
6730   *enclosing_struct_parse_info = struct_parse_info;
6731   struct_parse_info = XNEW (struct c_struct_parse_info);
6732   struct_parse_info->struct_types.create (0);
6733   struct_parse_info->fields.create (0);
6734   struct_parse_info->typedefs_seen.create (0);
6735 
6736   /* FIXME: This will issue a warning for a use of a type defined
6737      within a statement expr used within sizeof, et. al.  This is not
6738      terribly serious as C++ doesn't permit statement exprs within
6739      sizeof anyhow.  */
6740   if (warn_cxx_compat && (in_sizeof || in_typeof || in_alignof))
6741     warning_at (loc, OPT_Wc___compat,
6742 		"defining type in %qs expression is invalid in C++",
6743 		(in_sizeof
6744 		 ? "sizeof"
6745 		 : (in_typeof ? "typeof" : "alignof")));
6746 
6747   return ref;
6748 }
6749 
6750 /* Process the specs, declarator and width (NULL if omitted)
6751    of a structure component, returning a FIELD_DECL node.
6752    WIDTH is non-NULL for bit-fields only, and is an INTEGER_CST node.
6753    DECL_ATTRS is as for grokdeclarator.
6754 
6755    LOC is the location of the structure component.
6756 
6757    This is done during the parsing of the struct declaration.
6758    The FIELD_DECL nodes are chained together and the lot of them
6759    are ultimately passed to `build_struct' to make the RECORD_TYPE node.  */
6760 
6761 tree
6762 grokfield (location_t loc,
6763 	   struct c_declarator *declarator, struct c_declspecs *declspecs,
6764 	   tree width, tree *decl_attrs)
6765 {
6766   tree value;
6767 
6768   if (declarator->kind == cdk_id && declarator->u.id == NULL_TREE
6769       && width == NULL_TREE)
6770     {
6771       /* This is an unnamed decl.
6772 
6773 	 If we have something of the form "union { list } ;" then this
6774 	 is the anonymous union extension.  Similarly for struct.
6775 
6776 	 If this is something of the form "struct foo;", then
6777 	   If MS or Plan 9 extensions are enabled, this is handled as
6778 	     an anonymous struct.
6779 	   Otherwise this is a forward declaration of a structure tag.
6780 
6781 	 If this is something of the form "foo;" and foo is a TYPE_DECL, then
6782 	   If foo names a structure or union without a tag, then this
6783 	     is an anonymous struct (this is permitted by C11).
6784 	   If MS or Plan 9 extensions are enabled and foo names a
6785 	     structure, then again this is an anonymous struct.
6786 	   Otherwise this is an error.
6787 
6788 	 Oh what a horrid tangled web we weave.  I wonder if MS consciously
6789 	 took this from Plan 9 or if it was an accident of implementation
6790 	 that took root before someone noticed the bug...  */
6791 
6792       tree type = declspecs->type;
6793       bool type_ok = (TREE_CODE (type) == RECORD_TYPE
6794 		      || TREE_CODE (type) == UNION_TYPE);
6795       bool ok = false;
6796 
6797       if (type_ok
6798 	  && (flag_ms_extensions
6799 	      || flag_plan9_extensions
6800 	      || !declspecs->typedef_p))
6801 	{
6802 	  if (flag_ms_extensions || flag_plan9_extensions)
6803 	    ok = true;
6804 	  else if (TYPE_NAME (type) == NULL)
6805 	    ok = true;
6806 	  else
6807 	    ok = false;
6808 	}
6809       if (!ok)
6810 	{
6811 	  pedwarn (loc, 0, "declaration does not declare anything");
6812 	  return NULL_TREE;
6813 	}
6814       if (!flag_isoc11)
6815 	{
6816 	  if (flag_isoc99)
6817 	    pedwarn (loc, OPT_Wpedantic,
6818 		     "ISO C99 doesn%'t support unnamed structs/unions");
6819 	  else
6820 	    pedwarn (loc, OPT_Wpedantic,
6821 		     "ISO C90 doesn%'t support unnamed structs/unions");
6822 	}
6823     }
6824 
6825   value = grokdeclarator (declarator, declspecs, FIELD, false,
6826 			  width ? &width : NULL, decl_attrs, NULL, NULL,
6827 			  DEPRECATED_NORMAL);
6828 
6829   finish_decl (value, loc, NULL_TREE, NULL_TREE, NULL_TREE);
6830   DECL_INITIAL (value) = width;
6831 
6832   if (warn_cxx_compat && DECL_NAME (value) != NULL_TREE)
6833     {
6834       /* If we currently have a binding for this field, set the
6835 	 in_struct field in the binding, so that we warn about lookups
6836 	 which find it.  */
6837       struct c_binding *b = I_SYMBOL_BINDING (DECL_NAME (value));
6838       if (b != NULL)
6839 	{
6840 	  /* If the in_struct field is not yet set, push it on a list
6841 	     to be cleared when this struct is finished.  */
6842 	  if (!b->in_struct)
6843 	    {
6844 	      struct_parse_info->fields.safe_push (b);
6845 	      b->in_struct = 1;
6846 	    }
6847 	}
6848     }
6849 
6850   return value;
6851 }
6852 
6853 /* Subroutine of detect_field_duplicates: return whether X and Y,
6854    which are both fields in the same struct, have duplicate field
6855    names.  */
6856 
6857 static bool
6858 is_duplicate_field (tree x, tree y)
6859 {
6860   if (DECL_NAME (x) != NULL_TREE && DECL_NAME (x) == DECL_NAME (y))
6861     return true;
6862 
6863   /* When using -fplan9-extensions, an anonymous field whose name is a
6864      typedef can duplicate a field name.  */
6865   if (flag_plan9_extensions
6866       && (DECL_NAME (x) == NULL_TREE || DECL_NAME (y) == NULL_TREE))
6867     {
6868       tree xt, xn, yt, yn;
6869 
6870       xt = TREE_TYPE (x);
6871       if (DECL_NAME (x) != NULL_TREE)
6872 	xn = DECL_NAME (x);
6873       else if ((TREE_CODE (xt) == RECORD_TYPE || TREE_CODE (xt) == UNION_TYPE)
6874 	       && TYPE_NAME (xt) != NULL_TREE
6875 	       && TREE_CODE (TYPE_NAME (xt)) == TYPE_DECL)
6876 	xn = DECL_NAME (TYPE_NAME (xt));
6877       else
6878 	xn = NULL_TREE;
6879 
6880       yt = TREE_TYPE (y);
6881       if (DECL_NAME (y) != NULL_TREE)
6882 	yn = DECL_NAME (y);
6883       else if ((TREE_CODE (yt) == RECORD_TYPE || TREE_CODE (yt) == UNION_TYPE)
6884 	       && TYPE_NAME (yt) != NULL_TREE
6885 	       && TREE_CODE (TYPE_NAME (yt)) == TYPE_DECL)
6886 	yn = DECL_NAME (TYPE_NAME (yt));
6887       else
6888 	yn = NULL_TREE;
6889 
6890       if (xn != NULL_TREE && xn == yn)
6891 	return true;
6892     }
6893 
6894   return false;
6895 }
6896 
6897 /* Subroutine of detect_field_duplicates: add the fields of FIELDLIST
6898    to HTAB, giving errors for any duplicates.  */
6899 
6900 static void
6901 detect_field_duplicates_hash (tree fieldlist,
6902 			      hash_table <pointer_hash <tree_node> > htab)
6903 {
6904   tree x, y;
6905   tree_node **slot;
6906 
6907   for (x = fieldlist; x ; x = DECL_CHAIN (x))
6908     if ((y = DECL_NAME (x)) != 0)
6909       {
6910 	slot = htab.find_slot (y, INSERT);
6911 	if (*slot)
6912 	  {
6913 	    error ("duplicate member %q+D", x);
6914 	    DECL_NAME (x) = NULL_TREE;
6915 	  }
6916 	*slot = y;
6917       }
6918     else if (TREE_CODE (TREE_TYPE (x)) == RECORD_TYPE
6919 	     || TREE_CODE (TREE_TYPE (x)) == UNION_TYPE)
6920       {
6921 	detect_field_duplicates_hash (TYPE_FIELDS (TREE_TYPE (x)), htab);
6922 
6923 	/* When using -fplan9-extensions, an anonymous field whose
6924 	   name is a typedef can duplicate a field name.  */
6925 	if (flag_plan9_extensions
6926 	    && TYPE_NAME (TREE_TYPE (x)) != NULL_TREE
6927 	    && TREE_CODE (TYPE_NAME (TREE_TYPE (x))) == TYPE_DECL)
6928 	  {
6929 	    tree xn = DECL_NAME (TYPE_NAME (TREE_TYPE (x)));
6930 	    slot = htab.find_slot (xn, INSERT);
6931 	    if (*slot)
6932 	      error ("duplicate member %q+D", TYPE_NAME (TREE_TYPE (x)));
6933 	    *slot = xn;
6934 	  }
6935       }
6936 }
6937 
6938 /* Generate an error for any duplicate field names in FIELDLIST.  Munge
6939    the list such that this does not present a problem later.  */
6940 
6941 static void
6942 detect_field_duplicates (tree fieldlist)
6943 {
6944   tree x, y;
6945   int timeout = 10;
6946 
6947   /* If the struct is the list of instance variables of an Objective-C
6948      class, then we need to check all the instance variables of
6949      superclasses when checking for duplicates (since you can't have
6950      an instance variable in a subclass with the same name as an
6951      instance variable in a superclass).  We pass on this job to the
6952      Objective-C compiler.  objc_detect_field_duplicates() will return
6953      false if we are not checking the list of instance variables and
6954      the C frontend should proceed with the standard field duplicate
6955      checks.  If we are checking the list of instance variables, the
6956      ObjC frontend will do the check, emit the errors if needed, and
6957      then return true.  */
6958   if (c_dialect_objc ())
6959     if (objc_detect_field_duplicates (false))
6960       return;
6961 
6962   /* First, see if there are more than "a few" fields.
6963      This is trivially true if there are zero or one fields.  */
6964   if (!fieldlist || !DECL_CHAIN (fieldlist))
6965     return;
6966   x = fieldlist;
6967   do {
6968     timeout--;
6969     if (DECL_NAME (x) == NULL_TREE
6970 	&& (TREE_CODE (TREE_TYPE (x)) == RECORD_TYPE
6971 	    || TREE_CODE (TREE_TYPE (x)) == UNION_TYPE))
6972       timeout = 0;
6973     x = DECL_CHAIN (x);
6974   } while (timeout > 0 && x);
6975 
6976   /* If there were "few" fields and no anonymous structures or unions,
6977      avoid the overhead of allocating a hash table.  Instead just do
6978      the nested traversal thing.  */
6979   if (timeout > 0)
6980     {
6981       for (x = DECL_CHAIN (fieldlist); x; x = DECL_CHAIN (x))
6982 	/* When using -fplan9-extensions, we can have duplicates
6983 	   between typedef names and fields.  */
6984 	if (DECL_NAME (x)
6985 	    || (flag_plan9_extensions
6986 		&& DECL_NAME (x) == NULL_TREE
6987 		&& (TREE_CODE (TREE_TYPE (x)) == RECORD_TYPE
6988 		    || TREE_CODE (TREE_TYPE (x)) == UNION_TYPE)
6989 		&& TYPE_NAME (TREE_TYPE (x)) != NULL_TREE
6990 		&& TREE_CODE (TYPE_NAME (TREE_TYPE (x))) == TYPE_DECL))
6991 	  {
6992 	    for (y = fieldlist; y != x; y = TREE_CHAIN (y))
6993 	      if (is_duplicate_field (y, x))
6994 		{
6995 		  error ("duplicate member %q+D", x);
6996 		  DECL_NAME (x) = NULL_TREE;
6997 		}
6998 	  }
6999     }
7000   else
7001     {
7002       hash_table <pointer_hash <tree_node> > htab;
7003       htab.create (37);
7004 
7005       detect_field_duplicates_hash (fieldlist, htab);
7006       htab.dispose ();
7007     }
7008 }
7009 
7010 /* Finish up struct info used by -Wc++-compat.  */
7011 
7012 static void
7013 warn_cxx_compat_finish_struct (tree fieldlist)
7014 {
7015   unsigned int ix;
7016   tree x;
7017   struct c_binding *b;
7018 
7019   /* Set the C_TYPE_DEFINED_IN_STRUCT flag for each type defined in
7020      the current struct.  We do this now at the end of the struct
7021      because the flag is used to issue visibility warnings, and we
7022      only want to issue those warnings if the type is referenced
7023      outside of the struct declaration.  */
7024   FOR_EACH_VEC_ELT (struct_parse_info->struct_types, ix, x)
7025     C_TYPE_DEFINED_IN_STRUCT (x) = 1;
7026 
7027   /* The TYPEDEFS_SEEN field of STRUCT_PARSE_INFO is a list of
7028      typedefs used when declaring fields in this struct.  If the name
7029      of any of the fields is also a typedef name then the struct would
7030      not parse in C++, because the C++ lookup rules say that the
7031      typedef name would be looked up in the context of the struct, and
7032      would thus be the field rather than the typedef.  */
7033   if (!struct_parse_info->typedefs_seen.is_empty ()
7034       && fieldlist != NULL_TREE)
7035     {
7036       /* Use a pointer_set using the name of the typedef.  We can use
7037 	 a pointer_set because identifiers are interned.  */
7038       struct pointer_set_t *tset = pointer_set_create ();
7039 
7040       FOR_EACH_VEC_ELT (struct_parse_info->typedefs_seen, ix, x)
7041 	pointer_set_insert (tset, DECL_NAME (x));
7042 
7043       for (x = fieldlist; x != NULL_TREE; x = DECL_CHAIN (x))
7044 	{
7045 	  if (DECL_NAME (x) != NULL_TREE
7046 	      && pointer_set_contains (tset, DECL_NAME (x)))
7047 	    {
7048 	      warning_at (DECL_SOURCE_LOCATION (x), OPT_Wc___compat,
7049 			  ("using %qD as both field and typedef name is "
7050 			   "invalid in C++"),
7051 			  x);
7052 	      /* FIXME: It would be nice to report the location where
7053 		 the typedef name is used.  */
7054 	    }
7055 	}
7056 
7057       pointer_set_destroy (tset);
7058     }
7059 
7060   /* For each field which has a binding and which was not defined in
7061      an enclosing struct, clear the in_struct field.  */
7062   FOR_EACH_VEC_ELT (struct_parse_info->fields, ix, b)
7063     b->in_struct = 0;
7064 }
7065 
7066 /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T.
7067    LOC is the location of the RECORD_TYPE or UNION_TYPE's definition.
7068    FIELDLIST is a chain of FIELD_DECL nodes for the fields.
7069    ATTRIBUTES are attributes to be applied to the structure.
7070 
7071    ENCLOSING_STRUCT_PARSE_INFO is the value of STRUCT_PARSE_INFO when
7072    the struct was started.  */
7073 
7074 tree
7075 finish_struct (location_t loc, tree t, tree fieldlist, tree attributes,
7076 	       struct c_struct_parse_info *enclosing_struct_parse_info)
7077 {
7078   tree x;
7079   bool toplevel = file_scope == current_scope;
7080   int saw_named_field;
7081 
7082   /* If this type was previously laid out as a forward reference,
7083      make sure we lay it out again.  */
7084 
7085   TYPE_SIZE (t) = 0;
7086 
7087   decl_attributes (&t, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
7088 
7089   if (pedantic)
7090     {
7091       for (x = fieldlist; x; x = DECL_CHAIN (x))
7092 	{
7093 	  if (DECL_NAME (x) != 0)
7094 	    break;
7095 	  if (flag_isoc11
7096 	      && (TREE_CODE (TREE_TYPE (x)) == RECORD_TYPE
7097 		  || TREE_CODE (TREE_TYPE (x)) == UNION_TYPE))
7098 	    break;
7099 	}
7100 
7101       if (x == 0)
7102 	{
7103 	  if (TREE_CODE (t) == UNION_TYPE)
7104 	    {
7105 	      if (fieldlist)
7106 		pedwarn (loc, OPT_Wpedantic, "union has no named members");
7107 	      else
7108 		pedwarn (loc, OPT_Wpedantic, "union has no members");
7109 	    }
7110 	  else
7111 	    {
7112 	      if (fieldlist)
7113 		pedwarn (loc, OPT_Wpedantic, "struct has no named members");
7114 	      else
7115 		pedwarn (loc, OPT_Wpedantic, "struct has no members");
7116 	    }
7117 	}
7118     }
7119 
7120   /* Install struct as DECL_CONTEXT of each field decl.
7121      Also process specified field sizes, found in the DECL_INITIAL,
7122      storing 0 there after the type has been changed to precision equal
7123      to its width, rather than the precision of the specified standard
7124      type.  (Correct layout requires the original type to have been preserved
7125      until now.)  */
7126 
7127   saw_named_field = 0;
7128   for (x = fieldlist; x; x = DECL_CHAIN (x))
7129     {
7130       if (TREE_TYPE (x) == error_mark_node)
7131 	continue;
7132 
7133       DECL_CONTEXT (x) = t;
7134 
7135       /* If any field is const, the structure type is pseudo-const.  */
7136       if (TREE_READONLY (x))
7137 	C_TYPE_FIELDS_READONLY (t) = 1;
7138       else
7139 	{
7140 	  /* A field that is pseudo-const makes the structure likewise.  */
7141 	  tree t1 = strip_array_types (TREE_TYPE (x));
7142 	  if ((TREE_CODE (t1) == RECORD_TYPE || TREE_CODE (t1) == UNION_TYPE)
7143 	      && C_TYPE_FIELDS_READONLY (t1))
7144 	    C_TYPE_FIELDS_READONLY (t) = 1;
7145 	}
7146 
7147       /* Any field that is volatile means variables of this type must be
7148 	 treated in some ways as volatile.  */
7149       if (TREE_THIS_VOLATILE (x))
7150 	C_TYPE_FIELDS_VOLATILE (t) = 1;
7151 
7152       /* Any field of nominal variable size implies structure is too.  */
7153       if (C_DECL_VARIABLE_SIZE (x))
7154 	C_TYPE_VARIABLE_SIZE (t) = 1;
7155 
7156       if (DECL_INITIAL (x))
7157 	{
7158 	  unsigned HOST_WIDE_INT width = tree_low_cst (DECL_INITIAL (x), 1);
7159 	  DECL_SIZE (x) = bitsize_int (width);
7160 	  DECL_BIT_FIELD (x) = 1;
7161 	  SET_DECL_C_BIT_FIELD (x);
7162 	}
7163 
7164       if (TYPE_PACKED (t)
7165 	  && (DECL_BIT_FIELD (x)
7166 	      || TYPE_ALIGN (TREE_TYPE (x)) > BITS_PER_UNIT))
7167 	DECL_PACKED (x) = 1;
7168 
7169       /* Detect flexible array member in an invalid context.  */
7170       if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
7171 	  && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
7172 	  && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE
7173 	  && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE)
7174 	{
7175 	  if (TREE_CODE (t) == UNION_TYPE)
7176 	    {
7177 	      error_at (DECL_SOURCE_LOCATION (x),
7178 			"flexible array member in union");
7179 	      TREE_TYPE (x) = error_mark_node;
7180 	    }
7181 	  else if (DECL_CHAIN (x) != NULL_TREE)
7182 	    {
7183 	      error_at (DECL_SOURCE_LOCATION (x),
7184 			"flexible array member not at end of struct");
7185 	      TREE_TYPE (x) = error_mark_node;
7186 	    }
7187 	  else if (!saw_named_field)
7188 	    {
7189 	      error_at (DECL_SOURCE_LOCATION (x),
7190 			"flexible array member in otherwise empty struct");
7191 	      TREE_TYPE (x) = error_mark_node;
7192 	    }
7193 	}
7194 
7195       if (pedantic && TREE_CODE (t) == RECORD_TYPE
7196 	  && flexible_array_type_p (TREE_TYPE (x)))
7197 	pedwarn (DECL_SOURCE_LOCATION (x), OPT_Wpedantic,
7198 		 "invalid use of structure with flexible array member");
7199 
7200       if (DECL_NAME (x)
7201 	  || TREE_CODE (TREE_TYPE (x)) == RECORD_TYPE
7202 	  || TREE_CODE (TREE_TYPE (x)) == UNION_TYPE)
7203 	saw_named_field = 1;
7204     }
7205 
7206   detect_field_duplicates (fieldlist);
7207 
7208   /* Now we have the nearly final fieldlist.  Record it,
7209      then lay out the structure or union (including the fields).  */
7210 
7211   TYPE_FIELDS (t) = fieldlist;
7212 
7213   layout_type (t);
7214 
7215   /* Give bit-fields their proper types.  */
7216   {
7217     tree *fieldlistp = &fieldlist;
7218     while (*fieldlistp)
7219       if (TREE_CODE (*fieldlistp) == FIELD_DECL && DECL_INITIAL (*fieldlistp)
7220 	  && TREE_TYPE (*fieldlistp) != error_mark_node)
7221 	{
7222 	  unsigned HOST_WIDE_INT width
7223 	    = tree_low_cst (DECL_INITIAL (*fieldlistp), 1);
7224 	  tree type = TREE_TYPE (*fieldlistp);
7225 	  if (width != TYPE_PRECISION (type))
7226 	    {
7227 	      TREE_TYPE (*fieldlistp)
7228 		= c_build_bitfield_integer_type (width, TYPE_UNSIGNED (type));
7229 	      DECL_MODE (*fieldlistp) = TYPE_MODE (TREE_TYPE (*fieldlistp));
7230 	    }
7231 	  DECL_INITIAL (*fieldlistp) = 0;
7232 	}
7233       else
7234 	fieldlistp = &DECL_CHAIN (*fieldlistp);
7235   }
7236 
7237   /* Now we have the truly final field list.
7238      Store it in this type and in the variants.  */
7239 
7240   TYPE_FIELDS (t) = fieldlist;
7241 
7242   /* If there are lots of fields, sort so we can look through them fast.
7243      We arbitrarily consider 16 or more elts to be "a lot".  */
7244 
7245   {
7246     int len = 0;
7247 
7248     for (x = fieldlist; x; x = DECL_CHAIN (x))
7249       {
7250 	if (len > 15 || DECL_NAME (x) == NULL)
7251 	  break;
7252 	len += 1;
7253       }
7254 
7255     if (len > 15)
7256       {
7257 	tree *field_array;
7258 	struct lang_type *space;
7259 	struct sorted_fields_type *space2;
7260 
7261 	len += list_length (x);
7262 
7263 	/* Use the same allocation policy here that make_node uses, to
7264 	  ensure that this lives as long as the rest of the struct decl.
7265 	  All decls in an inline function need to be saved.  */
7266 
7267 	space = ggc_alloc_cleared_lang_type (sizeof (struct lang_type));
7268 	space2 = ggc_alloc_sorted_fields_type
7269 	  (sizeof (struct sorted_fields_type) + len * sizeof (tree));
7270 
7271 	len = 0;
7272 	space->s = space2;
7273 	field_array = &space2->elts[0];
7274 	for (x = fieldlist; x; x = DECL_CHAIN (x))
7275 	  {
7276 	    field_array[len++] = x;
7277 
7278 	    /* If there is anonymous struct or union, break out of the loop.  */
7279 	    if (DECL_NAME (x) == NULL)
7280 	      break;
7281 	  }
7282 	/* Found no anonymous struct/union.  Add the TYPE_LANG_SPECIFIC.  */
7283 	if (x == NULL)
7284 	  {
7285 	    TYPE_LANG_SPECIFIC (t) = space;
7286 	    TYPE_LANG_SPECIFIC (t)->s->len = len;
7287 	    field_array = TYPE_LANG_SPECIFIC (t)->s->elts;
7288 	    qsort (field_array, len, sizeof (tree), field_decl_cmp);
7289 	  }
7290       }
7291   }
7292 
7293   for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x))
7294     {
7295       TYPE_FIELDS (x) = TYPE_FIELDS (t);
7296       TYPE_LANG_SPECIFIC (x) = TYPE_LANG_SPECIFIC (t);
7297       C_TYPE_FIELDS_READONLY (x) = C_TYPE_FIELDS_READONLY (t);
7298       C_TYPE_FIELDS_VOLATILE (x) = C_TYPE_FIELDS_VOLATILE (t);
7299       C_TYPE_VARIABLE_SIZE (x) = C_TYPE_VARIABLE_SIZE (t);
7300     }
7301 
7302   /* If this was supposed to be a transparent union, but we can't
7303      make it one, warn and turn off the flag.  */
7304   if (TREE_CODE (t) == UNION_TYPE
7305       && TYPE_TRANSPARENT_AGGR (t)
7306       && (!TYPE_FIELDS (t) || TYPE_MODE (t) != DECL_MODE (TYPE_FIELDS (t))))
7307     {
7308       TYPE_TRANSPARENT_AGGR (t) = 0;
7309       warning_at (loc, 0, "union cannot be made transparent");
7310     }
7311 
7312   /* If this structure or union completes the type of any previous
7313      variable declaration, lay it out and output its rtl.  */
7314   for (x = C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t));
7315        x;
7316        x = TREE_CHAIN (x))
7317     {
7318       tree decl = TREE_VALUE (x);
7319       if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
7320 	layout_array_type (TREE_TYPE (decl));
7321       if (TREE_CODE (decl) != TYPE_DECL)
7322 	{
7323 	  layout_decl (decl, 0);
7324 	  if (c_dialect_objc ())
7325 	    objc_check_decl (decl);
7326 	  rest_of_decl_compilation (decl, toplevel, 0);
7327 	}
7328     }
7329   C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t)) = 0;
7330 
7331   /* Update type location to the one of the definition, instead of e.g.
7332      a forward declaration.  */
7333   if (TYPE_STUB_DECL (t))
7334     DECL_SOURCE_LOCATION (TYPE_STUB_DECL (t)) = loc;
7335 
7336   /* Finish debugging output for this type.  */
7337   rest_of_type_compilation (t, toplevel);
7338 
7339   /* If we're inside a function proper, i.e. not file-scope and not still
7340      parsing parameters, then arrange for the size of a variable sized type
7341      to be bound now.  */
7342   if (building_stmt_list_p () && variably_modified_type_p (t, NULL_TREE))
7343     add_stmt (build_stmt (loc,
7344 			  DECL_EXPR, build_decl (loc, TYPE_DECL, NULL, t)));
7345 
7346   if (warn_cxx_compat)
7347     warn_cxx_compat_finish_struct (fieldlist);
7348 
7349   struct_parse_info->struct_types.release ();
7350   struct_parse_info->fields.release ();
7351   struct_parse_info->typedefs_seen.release ();
7352   XDELETE (struct_parse_info);
7353 
7354   struct_parse_info = enclosing_struct_parse_info;
7355 
7356   /* If this struct is defined inside a struct, add it to
7357      struct_types.  */
7358   if (warn_cxx_compat
7359       && struct_parse_info != NULL
7360       && !in_sizeof && !in_typeof && !in_alignof)
7361     struct_parse_info->struct_types.safe_push (t);
7362 
7363   return t;
7364 }
7365 
7366 /* Lay out the type T, and its element type, and so on.  */
7367 
7368 static void
7369 layout_array_type (tree t)
7370 {
7371   if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
7372     layout_array_type (TREE_TYPE (t));
7373   layout_type (t);
7374 }
7375 
7376 /* Begin compiling the definition of an enumeration type.
7377    NAME is its name (or null if anonymous).
7378    LOC is the enum's location.
7379    Returns the type object, as yet incomplete.
7380    Also records info about it so that build_enumerator
7381    may be used to declare the individual values as they are read.  */
7382 
7383 tree
7384 start_enum (location_t loc, struct c_enum_contents *the_enum, tree name)
7385 {
7386   tree enumtype = NULL_TREE;
7387   location_t enumloc = UNKNOWN_LOCATION;
7388 
7389   /* If this is the real definition for a previous forward reference,
7390      fill in the contents in the same object that used to be the
7391      forward reference.  */
7392 
7393   if (name != NULL_TREE)
7394     enumtype = lookup_tag (ENUMERAL_TYPE, name, 1, &enumloc);
7395 
7396   if (enumtype == 0 || TREE_CODE (enumtype) != ENUMERAL_TYPE)
7397     {
7398       enumtype = make_node (ENUMERAL_TYPE);
7399       pushtag (loc, name, enumtype);
7400     }
7401 
7402   if (C_TYPE_BEING_DEFINED (enumtype))
7403     error_at (loc, "nested redefinition of %<enum %E%>", name);
7404 
7405   C_TYPE_BEING_DEFINED (enumtype) = 1;
7406 
7407   if (TYPE_VALUES (enumtype) != 0)
7408     {
7409       /* This enum is a named one that has been declared already.  */
7410       error_at (loc, "redeclaration of %<enum %E%>", name);
7411       if (enumloc != UNKNOWN_LOCATION)
7412 	inform (enumloc, "originally defined here");
7413 
7414       /* Completely replace its old definition.
7415 	 The old enumerators remain defined, however.  */
7416       TYPE_VALUES (enumtype) = 0;
7417     }
7418 
7419   the_enum->enum_next_value = integer_zero_node;
7420   the_enum->enum_overflow = 0;
7421 
7422   if (flag_short_enums)
7423     TYPE_PACKED (enumtype) = 1;
7424 
7425   /* FIXME: This will issue a warning for a use of a type defined
7426      within sizeof in a statement expr.  This is not terribly serious
7427      as C++ doesn't permit statement exprs within sizeof anyhow.  */
7428   if (warn_cxx_compat && (in_sizeof || in_typeof || in_alignof))
7429     warning_at (loc, OPT_Wc___compat,
7430 		"defining type in %qs expression is invalid in C++",
7431 		(in_sizeof
7432 		 ? "sizeof"
7433 		 : (in_typeof ? "typeof" : "alignof")));
7434 
7435   return enumtype;
7436 }
7437 
7438 /* After processing and defining all the values of an enumeration type,
7439    install their decls in the enumeration type and finish it off.
7440    ENUMTYPE is the type object, VALUES a list of decl-value pairs,
7441    and ATTRIBUTES are the specified attributes.
7442    Returns ENUMTYPE.  */
7443 
7444 tree
7445 finish_enum (tree enumtype, tree values, tree attributes)
7446 {
7447   tree pair, tem;
7448   tree minnode = 0, maxnode = 0;
7449   int precision, unsign;
7450   bool toplevel = (file_scope == current_scope);
7451   struct lang_type *lt;
7452 
7453   decl_attributes (&enumtype, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
7454 
7455   /* Calculate the maximum value of any enumerator in this type.  */
7456 
7457   if (values == error_mark_node)
7458     minnode = maxnode = integer_zero_node;
7459   else
7460     {
7461       minnode = maxnode = TREE_VALUE (values);
7462       for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair))
7463 	{
7464 	  tree value = TREE_VALUE (pair);
7465 	  if (tree_int_cst_lt (maxnode, value))
7466 	    maxnode = value;
7467 	  if (tree_int_cst_lt (value, minnode))
7468 	    minnode = value;
7469 	}
7470     }
7471 
7472   /* Construct the final type of this enumeration.  It is the same
7473      as one of the integral types - the narrowest one that fits, except
7474      that normally we only go as narrow as int - and signed iff any of
7475      the values are negative.  */
7476   unsign = (tree_int_cst_sgn (minnode) >= 0);
7477   precision = MAX (tree_int_cst_min_precision (minnode, unsign),
7478 		   tree_int_cst_min_precision (maxnode, unsign));
7479 
7480   if (TYPE_PACKED (enumtype) || precision > TYPE_PRECISION (integer_type_node))
7481     {
7482       tem = c_common_type_for_size (precision, unsign);
7483       if (tem == NULL)
7484 	{
7485 	  warning (0, "enumeration values exceed range of largest integer");
7486 	  tem = long_long_integer_type_node;
7487 	}
7488     }
7489   else
7490     tem = unsign ? unsigned_type_node : integer_type_node;
7491 
7492   TYPE_MIN_VALUE (enumtype) = TYPE_MIN_VALUE (tem);
7493   TYPE_MAX_VALUE (enumtype) = TYPE_MAX_VALUE (tem);
7494   TYPE_UNSIGNED (enumtype) = TYPE_UNSIGNED (tem);
7495   TYPE_SIZE (enumtype) = 0;
7496 
7497   /* If the precision of the type was specific with an attribute and it
7498      was too small, give an error.  Otherwise, use it.  */
7499   if (TYPE_PRECISION (enumtype))
7500     {
7501       if (precision > TYPE_PRECISION (enumtype))
7502 	error ("specified mode too small for enumeral values");
7503     }
7504   else
7505     TYPE_PRECISION (enumtype) = TYPE_PRECISION (tem);
7506 
7507   layout_type (enumtype);
7508 
7509   if (values != error_mark_node)
7510     {
7511       /* Change the type of the enumerators to be the enum type.  We
7512 	 need to do this irrespective of the size of the enum, for
7513 	 proper type checking.  Replace the DECL_INITIALs of the
7514 	 enumerators, and the value slots of the list, with copies
7515 	 that have the enum type; they cannot be modified in place
7516 	 because they may be shared (e.g.  integer_zero_node) Finally,
7517 	 change the purpose slots to point to the names of the decls.  */
7518       for (pair = values; pair; pair = TREE_CHAIN (pair))
7519 	{
7520 	  tree enu = TREE_PURPOSE (pair);
7521 	  tree ini = DECL_INITIAL (enu);
7522 
7523 	  TREE_TYPE (enu) = enumtype;
7524 
7525 	  /* The ISO C Standard mandates enumerators to have type int,
7526 	     even though the underlying type of an enum type is
7527 	     unspecified.  However, GCC allows enumerators of any
7528 	     integer type as an extensions.  build_enumerator()
7529 	     converts any enumerators that fit in an int to type int,
7530 	     to avoid promotions to unsigned types when comparing
7531 	     integers with enumerators that fit in the int range.
7532 	     When -pedantic is given, build_enumerator() would have
7533 	     already warned about those that don't fit. Here we
7534 	     convert the rest to the enumerator type. */
7535 	  if (TREE_TYPE (ini) != integer_type_node)
7536 	    ini = convert (enumtype, ini);
7537 
7538 	  DECL_INITIAL (enu) = ini;
7539 	  TREE_PURPOSE (pair) = DECL_NAME (enu);
7540 	  TREE_VALUE (pair) = ini;
7541 	}
7542 
7543       TYPE_VALUES (enumtype) = values;
7544     }
7545 
7546   /* Record the min/max values so that we can warn about bit-field
7547      enumerations that are too small for the values.  */
7548   lt = ggc_alloc_cleared_lang_type (sizeof (struct lang_type));
7549   lt->enum_min = minnode;
7550   lt->enum_max = maxnode;
7551   TYPE_LANG_SPECIFIC (enumtype) = lt;
7552 
7553   /* Fix up all variant types of this enum type.  */
7554   for (tem = TYPE_MAIN_VARIANT (enumtype); tem; tem = TYPE_NEXT_VARIANT (tem))
7555     {
7556       if (tem == enumtype)
7557 	continue;
7558       TYPE_VALUES (tem) = TYPE_VALUES (enumtype);
7559       TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype);
7560       TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype);
7561       TYPE_SIZE (tem) = TYPE_SIZE (enumtype);
7562       TYPE_SIZE_UNIT (tem) = TYPE_SIZE_UNIT (enumtype);
7563       SET_TYPE_MODE (tem, TYPE_MODE (enumtype));
7564       TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype);
7565       TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype);
7566       TYPE_USER_ALIGN (tem) = TYPE_USER_ALIGN (enumtype);
7567       TYPE_UNSIGNED (tem) = TYPE_UNSIGNED (enumtype);
7568       TYPE_LANG_SPECIFIC (tem) = TYPE_LANG_SPECIFIC (enumtype);
7569     }
7570 
7571   /* Finish debugging output for this type.  */
7572   rest_of_type_compilation (enumtype, toplevel);
7573 
7574   /* If this enum is defined inside a struct, add it to
7575      struct_types.  */
7576   if (warn_cxx_compat
7577       && struct_parse_info != NULL
7578       && !in_sizeof && !in_typeof && !in_alignof)
7579     struct_parse_info->struct_types.safe_push (enumtype);
7580 
7581   return enumtype;
7582 }
7583 
7584 /* Build and install a CONST_DECL for one value of the
7585    current enumeration type (one that was begun with start_enum).
7586    DECL_LOC is the location of the enumerator.
7587    LOC is the location of the '=' operator if any, DECL_LOC otherwise.
7588    Return a tree-list containing the CONST_DECL and its value.
7589    Assignment of sequential values by default is handled here.  */
7590 
7591 tree
7592 build_enumerator (location_t decl_loc, location_t loc,
7593 		  struct c_enum_contents *the_enum, tree name, tree value)
7594 {
7595   tree decl, type;
7596 
7597   /* Validate and default VALUE.  */
7598 
7599   if (value != 0)
7600     {
7601       /* Don't issue more errors for error_mark_node (i.e. an
7602 	 undeclared identifier) - just ignore the value expression.  */
7603       if (value == error_mark_node)
7604 	value = 0;
7605       else if (!INTEGRAL_TYPE_P (TREE_TYPE (value)))
7606 	{
7607 	  error_at (loc, "enumerator value for %qE is not an integer constant",
7608 		    name);
7609 	  value = 0;
7610 	}
7611       else
7612 	{
7613 	  if (TREE_CODE (value) != INTEGER_CST)
7614 	    {
7615 	      value = c_fully_fold (value, false, NULL);
7616 	      if (TREE_CODE (value) == INTEGER_CST)
7617 		pedwarn (loc, OPT_Wpedantic,
7618 			 "enumerator value for %qE is not an integer "
7619 			 "constant expression", name);
7620 	    }
7621 	  if (TREE_CODE (value) != INTEGER_CST)
7622 	    {
7623 	      error ("enumerator value for %qE is not an integer constant",
7624 		     name);
7625 	      value = 0;
7626 	    }
7627 	  else
7628 	    {
7629 	      value = default_conversion (value);
7630 	      constant_expression_warning (value);
7631 	    }
7632 	}
7633     }
7634 
7635   /* Default based on previous value.  */
7636   /* It should no longer be possible to have NON_LVALUE_EXPR
7637      in the default.  */
7638   if (value == 0)
7639     {
7640       value = the_enum->enum_next_value;
7641       if (the_enum->enum_overflow)
7642 	error_at (loc, "overflow in enumeration values");
7643     }
7644   /* Even though the underlying type of an enum is unspecified, the
7645      type of enumeration constants is explicitly defined as int
7646      (6.4.4.3/2 in the C99 Standard).  GCC allows any integer type as
7647      an extension.  */
7648   else if (!int_fits_type_p (value, integer_type_node))
7649     pedwarn (loc, OPT_Wpedantic,
7650 	     "ISO C restricts enumerator values to range of %<int%>");
7651 
7652   /* The ISO C Standard mandates enumerators to have type int, even
7653      though the underlying type of an enum type is unspecified.
7654      However, GCC allows enumerators of any integer type as an
7655      extensions.  Here we convert any enumerators that fit in an int
7656      to type int, to avoid promotions to unsigned types when comparing
7657      integers with enumerators that fit in the int range.  When
7658      -pedantic is given, we would have already warned about those that
7659      don't fit. We have to do this here rather than in finish_enum
7660      because this value may be used to define more enumerators.  */
7661   if (int_fits_type_p (value, integer_type_node))
7662     value = convert (integer_type_node, value);
7663 
7664   /* Set basis for default for next value.  */
7665   the_enum->enum_next_value
7666     = build_binary_op (EXPR_LOC_OR_HERE (value),
7667 		       PLUS_EXPR, value, integer_one_node, 0);
7668   the_enum->enum_overflow = tree_int_cst_lt (the_enum->enum_next_value, value);
7669 
7670   /* Now create a declaration for the enum value name.  */
7671 
7672   type = TREE_TYPE (value);
7673   type = c_common_type_for_size (MAX (TYPE_PRECISION (type),
7674 				      TYPE_PRECISION (integer_type_node)),
7675 				 (TYPE_PRECISION (type)
7676 				  >= TYPE_PRECISION (integer_type_node)
7677 				  && TYPE_UNSIGNED (type)));
7678 
7679   decl = build_decl (decl_loc, CONST_DECL, name, type);
7680   DECL_INITIAL (decl) = convert (type, value);
7681   pushdecl (decl);
7682 
7683   return tree_cons (decl, value, NULL_TREE);
7684 }
7685 
7686 
7687 /* Create the FUNCTION_DECL for a function definition.
7688    DECLSPECS, DECLARATOR and ATTRIBUTES are the parts of
7689    the declaration; they describe the function's name and the type it returns,
7690    but twisted together in a fashion that parallels the syntax of C.
7691 
7692    This function creates a binding context for the function body
7693    as well as setting up the FUNCTION_DECL in current_function_decl.
7694 
7695    Returns 1 on success.  If the DECLARATOR is not suitable for a function
7696    (it defines a datum instead), we return 0, which tells
7697    yyparse to report a parse error.  */
7698 
7699 int
7700 start_function (struct c_declspecs *declspecs, struct c_declarator *declarator,
7701 		tree attributes)
7702 {
7703   tree decl1, old_decl;
7704   tree restype, resdecl;
7705   location_t loc;
7706 
7707   current_function_returns_value = 0;  /* Assume, until we see it does.  */
7708   current_function_returns_null = 0;
7709   current_function_returns_abnormally = 0;
7710   warn_about_return_type = 0;
7711   c_switch_stack = NULL;
7712 
7713   /* Indicate no valid break/continue context by setting these variables
7714      to some non-null, non-label value.  We'll notice and emit the proper
7715      error message in c_finish_bc_stmt.  */
7716   c_break_label = c_cont_label = size_zero_node;
7717 
7718   decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, true, NULL,
7719 			  &attributes, NULL, NULL, DEPRECATED_NORMAL);
7720 
7721   /* If the declarator is not suitable for a function definition,
7722      cause a syntax error.  */
7723   if (decl1 == 0
7724       || TREE_CODE (decl1) != FUNCTION_DECL)
7725     return 0;
7726 
7727   loc = DECL_SOURCE_LOCATION (decl1);
7728 
7729   decl_attributes (&decl1, attributes, 0);
7730 
7731   if (DECL_DECLARED_INLINE_P (decl1)
7732       && DECL_UNINLINABLE (decl1)
7733       && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl1)))
7734     warning_at (loc, OPT_Wattributes,
7735 		"inline function %qD given attribute noinline",
7736 		decl1);
7737 
7738   /* Handle gnu_inline attribute.  */
7739   if (declspecs->inline_p
7740       && !flag_gnu89_inline
7741       && TREE_CODE (decl1) == FUNCTION_DECL
7742       && (lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (decl1))
7743 	  || current_function_decl))
7744     {
7745       if (declspecs->storage_class != csc_static)
7746 	DECL_EXTERNAL (decl1) = !DECL_EXTERNAL (decl1);
7747     }
7748 
7749   announce_function (decl1);
7750 
7751   if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl1))))
7752     {
7753       error_at (loc, "return type is an incomplete type");
7754       /* Make it return void instead.  */
7755       TREE_TYPE (decl1)
7756 	= build_function_type (void_type_node,
7757 			       TYPE_ARG_TYPES (TREE_TYPE (decl1)));
7758     }
7759 
7760   if (warn_about_return_type)
7761     pedwarn_c99 (loc, flag_isoc99 ? 0
7762 		 : (warn_return_type ? OPT_Wreturn_type : OPT_Wimplicit_int),
7763 		 "return type defaults to %<int%>");
7764 
7765   /* Make the init_value nonzero so pushdecl knows this is not tentative.
7766      error_mark_node is replaced below (in pop_scope) with the BLOCK.  */
7767   DECL_INITIAL (decl1) = error_mark_node;
7768 
7769   /* A nested function is not global.  */
7770   if (current_function_decl != 0)
7771     TREE_PUBLIC (decl1) = 0;
7772 
7773   /* If this definition isn't a prototype and we had a prototype declaration
7774      before, copy the arg type info from that prototype.  */
7775   old_decl = lookup_name_in_scope (DECL_NAME (decl1), current_scope);
7776   if (old_decl && TREE_CODE (old_decl) != FUNCTION_DECL)
7777     old_decl = 0;
7778   current_function_prototype_locus = UNKNOWN_LOCATION;
7779   current_function_prototype_built_in = false;
7780   current_function_prototype_arg_types = NULL_TREE;
7781   if (!prototype_p (TREE_TYPE (decl1)))
7782     {
7783       if (old_decl != 0 && TREE_CODE (TREE_TYPE (old_decl)) == FUNCTION_TYPE
7784 	  && comptypes (TREE_TYPE (TREE_TYPE (decl1)),
7785 			TREE_TYPE (TREE_TYPE (old_decl))))
7786 	{
7787 	  TREE_TYPE (decl1) = composite_type (TREE_TYPE (old_decl),
7788 					      TREE_TYPE (decl1));
7789 	  current_function_prototype_locus = DECL_SOURCE_LOCATION (old_decl);
7790 	  current_function_prototype_built_in
7791 	    = C_DECL_BUILTIN_PROTOTYPE (old_decl);
7792 	  current_function_prototype_arg_types
7793 	    = TYPE_ARG_TYPES (TREE_TYPE (decl1));
7794 	}
7795       if (TREE_PUBLIC (decl1))
7796 	{
7797 	  /* If there is an external prototype declaration of this
7798 	     function, record its location but do not copy information
7799 	     to this decl.  This may be an invisible declaration
7800 	     (built-in or in a scope which has finished) or simply
7801 	     have more refined argument types than any declaration
7802 	     found above.  */
7803 	  struct c_binding *b;
7804 	  for (b = I_SYMBOL_BINDING (DECL_NAME (decl1)); b; b = b->shadowed)
7805 	    if (B_IN_SCOPE (b, external_scope))
7806 	      break;
7807 	  if (b)
7808 	    {
7809 	      tree ext_decl, ext_type;
7810 	      ext_decl = b->decl;
7811 	      ext_type = b->u.type ? b->u.type : TREE_TYPE (ext_decl);
7812 	      if (TREE_CODE (ext_type) == FUNCTION_TYPE
7813 		  && comptypes (TREE_TYPE (TREE_TYPE (decl1)),
7814 				TREE_TYPE (ext_type)))
7815 		{
7816 		  current_function_prototype_locus
7817 		    = DECL_SOURCE_LOCATION (ext_decl);
7818 		  current_function_prototype_built_in
7819 		    = C_DECL_BUILTIN_PROTOTYPE (ext_decl);
7820 		  current_function_prototype_arg_types
7821 		    = TYPE_ARG_TYPES (ext_type);
7822 		}
7823 	    }
7824 	}
7825     }
7826 
7827   /* Optionally warn of old-fashioned def with no previous prototype.  */
7828   if (warn_strict_prototypes
7829       && old_decl != error_mark_node
7830       && !prototype_p (TREE_TYPE (decl1))
7831       && C_DECL_ISNT_PROTOTYPE (old_decl))
7832     warning_at (loc, OPT_Wstrict_prototypes,
7833 		"function declaration isn%'t a prototype");
7834   /* Optionally warn of any global def with no previous prototype.  */
7835   else if (warn_missing_prototypes
7836 	   && old_decl != error_mark_node
7837 	   && TREE_PUBLIC (decl1)
7838 	   && !MAIN_NAME_P (DECL_NAME (decl1))
7839 	   && C_DECL_ISNT_PROTOTYPE (old_decl))
7840     warning_at (loc, OPT_Wmissing_prototypes,
7841 		"no previous prototype for %qD", decl1);
7842   /* Optionally warn of any def with no previous prototype
7843      if the function has already been used.  */
7844   else if (warn_missing_prototypes
7845 	   && old_decl != 0
7846 	   && old_decl != error_mark_node
7847 	   && TREE_USED (old_decl)
7848 	   && !prototype_p (TREE_TYPE (old_decl)))
7849     warning_at (loc, OPT_Wmissing_prototypes,
7850 		"%qD was used with no prototype before its definition", decl1);
7851   /* Optionally warn of any global def with no previous declaration.  */
7852   else if (warn_missing_declarations
7853 	   && TREE_PUBLIC (decl1)
7854 	   && old_decl == 0
7855 	   && !MAIN_NAME_P (DECL_NAME (decl1)))
7856     warning_at (loc, OPT_Wmissing_declarations,
7857 		"no previous declaration for %qD",
7858 		decl1);
7859   /* Optionally warn of any def with no previous declaration
7860      if the function has already been used.  */
7861   else if (warn_missing_declarations
7862 	   && old_decl != 0
7863 	   && old_decl != error_mark_node
7864 	   && TREE_USED (old_decl)
7865 	   && C_DECL_IMPLICIT (old_decl))
7866     warning_at (loc, OPT_Wmissing_declarations,
7867 		"%qD was used with no declaration before its definition", decl1);
7868 
7869   /* This function exists in static storage.
7870      (This does not mean `static' in the C sense!)  */
7871   TREE_STATIC (decl1) = 1;
7872 
7873   /* This is the earliest point at which we might know the assembler
7874      name of the function.  Thus, if it's set before this, die horribly.  */
7875   gcc_assert (!DECL_ASSEMBLER_NAME_SET_P (decl1));
7876 
7877   /* If #pragma weak was used, mark the decl weak now.  */
7878   if (current_scope == file_scope)
7879     maybe_apply_pragma_weak (decl1);
7880 
7881   /* Warn for unlikely, improbable, or stupid declarations of `main'.  */
7882   if (warn_main && MAIN_NAME_P (DECL_NAME (decl1)))
7883     {
7884       if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1)))
7885 	  != integer_type_node)
7886 	pedwarn (loc, OPT_Wmain, "return type of %qD is not %<int%>", decl1);
7887 
7888       check_main_parameter_types (decl1);
7889 
7890       if (!TREE_PUBLIC (decl1))
7891 	pedwarn (loc, OPT_Wmain,
7892 		 "%qD is normally a non-static function", decl1);
7893     }
7894 
7895   /* Record the decl so that the function name is defined.
7896      If we already have a decl for this name, and it is a FUNCTION_DECL,
7897      use the old decl.  */
7898 
7899   current_function_decl = pushdecl (decl1);
7900 
7901   push_scope ();
7902   declare_parm_level ();
7903 
7904   restype = TREE_TYPE (TREE_TYPE (current_function_decl));
7905   resdecl = build_decl (loc, RESULT_DECL, NULL_TREE, restype);
7906   DECL_ARTIFICIAL (resdecl) = 1;
7907   DECL_IGNORED_P (resdecl) = 1;
7908   DECL_RESULT (current_function_decl) = resdecl;
7909 
7910   start_fname_decls ();
7911 
7912   return 1;
7913 }
7914 
7915 /* Subroutine of store_parm_decls which handles new-style function
7916    definitions (prototype format). The parms already have decls, so we
7917    need only record them as in effect and complain if any redundant
7918    old-style parm decls were written.  */
7919 static void
7920 store_parm_decls_newstyle (tree fndecl, const struct c_arg_info *arg_info)
7921 {
7922   tree decl;
7923   c_arg_tag *tag;
7924   unsigned ix;
7925 
7926   if (current_scope->bindings)
7927     {
7928       error_at (DECL_SOURCE_LOCATION (fndecl),
7929 		"old-style parameter declarations in prototyped "
7930 		"function definition");
7931 
7932       /* Get rid of the old-style declarations.  */
7933       pop_scope ();
7934       push_scope ();
7935     }
7936   /* Don't issue this warning for nested functions, and don't issue this
7937      warning if we got here because ARG_INFO_TYPES was error_mark_node
7938      (this happens when a function definition has just an ellipsis in
7939      its parameter list).  */
7940   else if (!in_system_header && !current_function_scope
7941 	   && arg_info->types != error_mark_node)
7942     warning_at (DECL_SOURCE_LOCATION (fndecl), OPT_Wtraditional,
7943 		"traditional C rejects ISO C style function definitions");
7944 
7945   /* Now make all the parameter declarations visible in the function body.
7946      We can bypass most of the grunt work of pushdecl.  */
7947   for (decl = arg_info->parms; decl; decl = DECL_CHAIN (decl))
7948     {
7949       DECL_CONTEXT (decl) = current_function_decl;
7950       if (DECL_NAME (decl))
7951 	{
7952 	  bind (DECL_NAME (decl), decl, current_scope,
7953 		/*invisible=*/false, /*nested=*/false,
7954 		UNKNOWN_LOCATION);
7955 	  if (!TREE_USED (decl))
7956 	    warn_if_shadowing (decl);
7957 	}
7958       else
7959 	error_at (DECL_SOURCE_LOCATION (decl), "parameter name omitted");
7960     }
7961 
7962   /* Record the parameter list in the function declaration.  */
7963   DECL_ARGUMENTS (fndecl) = arg_info->parms;
7964 
7965   /* Now make all the ancillary declarations visible, likewise.  */
7966   for (decl = arg_info->others; decl; decl = DECL_CHAIN (decl))
7967     {
7968       DECL_CONTEXT (decl) = current_function_decl;
7969       if (DECL_NAME (decl))
7970 	bind (DECL_NAME (decl), decl, current_scope,
7971 	      /*invisible=*/false,
7972 	      /*nested=*/(TREE_CODE (decl) == FUNCTION_DECL),
7973 	      UNKNOWN_LOCATION);
7974     }
7975 
7976   /* And all the tag declarations.  */
7977   FOR_EACH_VEC_SAFE_ELT_REVERSE (arg_info->tags, ix, tag)
7978     if (tag->id)
7979       bind (tag->id, tag->type, current_scope,
7980 	    /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION);
7981 }
7982 
7983 /* Subroutine of store_parm_decls which handles old-style function
7984    definitions (separate parameter list and declarations).  */
7985 
7986 static void
7987 store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info)
7988 {
7989   struct c_binding *b;
7990   tree parm, decl, last;
7991   tree parmids = arg_info->parms;
7992   struct pointer_set_t *seen_args = pointer_set_create ();
7993 
7994   if (!in_system_header)
7995     warning_at (DECL_SOURCE_LOCATION (fndecl),
7996 		OPT_Wold_style_definition, "old-style function definition");
7997 
7998   /* Match each formal parameter name with its declaration.  Save each
7999      decl in the appropriate TREE_PURPOSE slot of the parmids chain.  */
8000   for (parm = parmids; parm; parm = TREE_CHAIN (parm))
8001     {
8002       if (TREE_VALUE (parm) == 0)
8003 	{
8004 	  error_at (DECL_SOURCE_LOCATION (fndecl),
8005 		    "parameter name missing from parameter list");
8006 	  TREE_PURPOSE (parm) = 0;
8007 	  continue;
8008 	}
8009 
8010       b = I_SYMBOL_BINDING (TREE_VALUE (parm));
8011       if (b && B_IN_CURRENT_SCOPE (b))
8012 	{
8013 	  decl = b->decl;
8014 	  /* Skip erroneous parameters.  */
8015 	  if (decl == error_mark_node)
8016 	    continue;
8017 	  /* If we got something other than a PARM_DECL it is an error.  */
8018 	  if (TREE_CODE (decl) != PARM_DECL)
8019 	    error_at (DECL_SOURCE_LOCATION (decl),
8020 		      "%qD declared as a non-parameter", decl);
8021 	  /* If the declaration is already marked, we have a duplicate
8022 	     name.  Complain and ignore the duplicate.  */
8023 	  else if (pointer_set_contains (seen_args, decl))
8024 	    {
8025 	      error_at (DECL_SOURCE_LOCATION (decl),
8026 			"multiple parameters named %qD", decl);
8027 	      TREE_PURPOSE (parm) = 0;
8028 	      continue;
8029 	    }
8030 	  /* If the declaration says "void", complain and turn it into
8031 	     an int.  */
8032 	  else if (VOID_TYPE_P (TREE_TYPE (decl)))
8033 	    {
8034 	      error_at (DECL_SOURCE_LOCATION (decl),
8035 			"parameter %qD declared with void type", decl);
8036 	      TREE_TYPE (decl) = integer_type_node;
8037 	      DECL_ARG_TYPE (decl) = integer_type_node;
8038 	      layout_decl (decl, 0);
8039 	    }
8040 	  warn_if_shadowing (decl);
8041 	}
8042       /* If no declaration found, default to int.  */
8043       else
8044 	{
8045 	  /* FIXME diagnostics: This should be the location of the argument,
8046 	     not the FNDECL.  E.g., for an old-style declaration
8047 
8048 	       int f10(v) { blah; }
8049 
8050 	     We should use the location of the V, not the F10.
8051 	     Unfortunately, the V is an IDENTIFIER_NODE which has no
8052 	     location.  In the future we need locations for c_arg_info
8053 	     entries.
8054 
8055 	     See gcc.dg/Wshadow-3.c for an example of this problem. */
8056 	  decl = build_decl (DECL_SOURCE_LOCATION (fndecl),
8057 			     PARM_DECL, TREE_VALUE (parm), integer_type_node);
8058 	  DECL_ARG_TYPE (decl) = TREE_TYPE (decl);
8059 	  pushdecl (decl);
8060 	  warn_if_shadowing (decl);
8061 
8062 	  if (flag_isoc99)
8063 	    pedwarn (DECL_SOURCE_LOCATION (decl),
8064 		     0, "type of %qD defaults to %<int%>", decl);
8065 	  else
8066 	    warning_at (DECL_SOURCE_LOCATION (decl),
8067 			OPT_Wmissing_parameter_type,
8068 			"type of %qD defaults to %<int%>", decl);
8069 	}
8070 
8071       TREE_PURPOSE (parm) = decl;
8072       pointer_set_insert (seen_args, decl);
8073     }
8074 
8075   /* Now examine the parms chain for incomplete declarations
8076      and declarations with no corresponding names.  */
8077 
8078   for (b = current_scope->bindings; b; b = b->prev)
8079     {
8080       parm = b->decl;
8081       if (TREE_CODE (parm) != PARM_DECL)
8082 	continue;
8083 
8084       if (TREE_TYPE (parm) != error_mark_node
8085 	  && !COMPLETE_TYPE_P (TREE_TYPE (parm)))
8086 	{
8087 	  error_at (DECL_SOURCE_LOCATION (parm),
8088 		    "parameter %qD has incomplete type", parm);
8089 	  TREE_TYPE (parm) = error_mark_node;
8090 	}
8091 
8092       if (!pointer_set_contains (seen_args, parm))
8093 	{
8094 	  error_at (DECL_SOURCE_LOCATION (parm),
8095 		    "declaration for parameter %qD but no such parameter",
8096 		    parm);
8097 
8098 	  /* Pretend the parameter was not missing.
8099 	     This gets us to a standard state and minimizes
8100 	     further error messages.  */
8101 	  parmids = chainon (parmids, tree_cons (parm, 0, 0));
8102 	}
8103     }
8104 
8105   /* Chain the declarations together in the order of the list of
8106      names.  Store that chain in the function decl, replacing the
8107      list of names.  Update the current scope to match.  */
8108   DECL_ARGUMENTS (fndecl) = 0;
8109 
8110   for (parm = parmids; parm; parm = TREE_CHAIN (parm))
8111     if (TREE_PURPOSE (parm))
8112       break;
8113   if (parm && TREE_PURPOSE (parm))
8114     {
8115       last = TREE_PURPOSE (parm);
8116       DECL_ARGUMENTS (fndecl) = last;
8117 
8118       for (parm = TREE_CHAIN (parm); parm; parm = TREE_CHAIN (parm))
8119 	if (TREE_PURPOSE (parm))
8120 	  {
8121 	    DECL_CHAIN (last) = TREE_PURPOSE (parm);
8122 	    last = TREE_PURPOSE (parm);
8123 	  }
8124       DECL_CHAIN (last) = 0;
8125     }
8126 
8127   pointer_set_destroy (seen_args);
8128 
8129   /* If there was a previous prototype,
8130      set the DECL_ARG_TYPE of each argument according to
8131      the type previously specified, and report any mismatches.  */
8132 
8133   if (current_function_prototype_arg_types)
8134     {
8135       tree type;
8136       for (parm = DECL_ARGUMENTS (fndecl),
8137 	     type = current_function_prototype_arg_types;
8138 	   parm || (type && TREE_VALUE (type) != error_mark_node
8139                    && (TYPE_MAIN_VARIANT (TREE_VALUE (type)) != void_type_node));
8140 	   parm = DECL_CHAIN (parm), type = TREE_CHAIN (type))
8141 	{
8142 	  if (parm == 0 || type == 0
8143 	      || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node)
8144 	    {
8145 	      if (current_function_prototype_built_in)
8146 		warning_at (DECL_SOURCE_LOCATION (fndecl),
8147 			    0, "number of arguments doesn%'t match "
8148 			    "built-in prototype");
8149 	      else
8150 		{
8151 		  /* FIXME diagnostics: This should be the location of
8152 		     FNDECL, but there is bug when a prototype is
8153 		     declared inside function context, but defined
8154 		     outside of it (e.g., gcc.dg/pr15698-2.c).  In
8155 		     which case FNDECL gets the location of the
8156 		     prototype, not the definition.  */
8157 		  error_at (input_location,
8158 			    "number of arguments doesn%'t match prototype");
8159 
8160 		  error_at (current_function_prototype_locus,
8161 			    "prototype declaration");
8162 		}
8163 	      break;
8164 	    }
8165 	  /* Type for passing arg must be consistent with that
8166 	     declared for the arg.  ISO C says we take the unqualified
8167 	     type for parameters declared with qualified type.  */
8168 	  if (TREE_TYPE (parm) != error_mark_node
8169 	      && TREE_TYPE (type) != error_mark_node
8170 	      && !comptypes (TYPE_MAIN_VARIANT (DECL_ARG_TYPE (parm)),
8171 			     TYPE_MAIN_VARIANT (TREE_VALUE (type))))
8172 	    {
8173 	      if (TYPE_MAIN_VARIANT (TREE_TYPE (parm))
8174 		  == TYPE_MAIN_VARIANT (TREE_VALUE (type)))
8175 		{
8176 		  /* Adjust argument to match prototype.  E.g. a previous
8177 		     `int foo(float);' prototype causes
8178 		     `int foo(x) float x; {...}' to be treated like
8179 		     `int foo(float x) {...}'.  This is particularly
8180 		     useful for argument types like uid_t.  */
8181 		  DECL_ARG_TYPE (parm) = TREE_TYPE (parm);
8182 
8183 		  if (targetm.calls.promote_prototypes (TREE_TYPE (current_function_decl))
8184 		      && INTEGRAL_TYPE_P (TREE_TYPE (parm))
8185 		      && TYPE_PRECISION (TREE_TYPE (parm))
8186 		      < TYPE_PRECISION (integer_type_node))
8187 		    DECL_ARG_TYPE (parm) = integer_type_node;
8188 
8189 		  /* ??? Is it possible to get here with a
8190 		     built-in prototype or will it always have
8191 		     been diagnosed as conflicting with an
8192 		     old-style definition and discarded?  */
8193 		  if (current_function_prototype_built_in)
8194 		    warning_at (DECL_SOURCE_LOCATION (parm),
8195 				OPT_Wpedantic, "promoted argument %qD "
8196 				"doesn%'t match built-in prototype", parm);
8197 		  else
8198 		    {
8199 		      pedwarn (DECL_SOURCE_LOCATION (parm),
8200 			       OPT_Wpedantic, "promoted argument %qD "
8201 			       "doesn%'t match prototype", parm);
8202 		      pedwarn (current_function_prototype_locus, OPT_Wpedantic,
8203 			       "prototype declaration");
8204 		    }
8205 		}
8206 	      else
8207 		{
8208 		  if (current_function_prototype_built_in)
8209 		    warning_at (DECL_SOURCE_LOCATION (parm),
8210 				0, "argument %qD doesn%'t match "
8211 				"built-in prototype", parm);
8212 		  else
8213 		    {
8214 		      error_at (DECL_SOURCE_LOCATION (parm),
8215 				"argument %qD doesn%'t match prototype", parm);
8216 		      error_at (current_function_prototype_locus,
8217 				"prototype declaration");
8218 		    }
8219 		}
8220 	    }
8221 	}
8222       TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = 0;
8223     }
8224 
8225   /* Otherwise, create a prototype that would match.  */
8226 
8227   else
8228     {
8229       tree actual = 0, last = 0, type;
8230 
8231       for (parm = DECL_ARGUMENTS (fndecl); parm; parm = DECL_CHAIN (parm))
8232 	{
8233 	  type = tree_cons (NULL_TREE, DECL_ARG_TYPE (parm), NULL_TREE);
8234 	  if (last)
8235 	    TREE_CHAIN (last) = type;
8236 	  else
8237 	    actual = type;
8238 	  last = type;
8239 	}
8240       type = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
8241       if (last)
8242 	TREE_CHAIN (last) = type;
8243       else
8244 	actual = type;
8245 
8246       /* We are going to assign a new value for the TYPE_ACTUAL_ARG_TYPES
8247 	 of the type of this function, but we need to avoid having this
8248 	 affect the types of other similarly-typed functions, so we must
8249 	 first force the generation of an identical (but separate) type
8250 	 node for the relevant function type.  The new node we create
8251 	 will be a variant of the main variant of the original function
8252 	 type.  */
8253 
8254       TREE_TYPE (fndecl) = build_variant_type_copy (TREE_TYPE (fndecl));
8255 
8256       TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = actual;
8257     }
8258 }
8259 
8260 /* Store parameter declarations passed in ARG_INFO into the current
8261    function declaration.  */
8262 
8263 void
8264 store_parm_decls_from (struct c_arg_info *arg_info)
8265 {
8266   current_function_arg_info = arg_info;
8267   store_parm_decls ();
8268 }
8269 
8270 /* Store the parameter declarations into the current function declaration.
8271    This is called after parsing the parameter declarations, before
8272    digesting the body of the function.
8273 
8274    For an old-style definition, construct a prototype out of the old-style
8275    parameter declarations and inject it into the function's type.  */
8276 
8277 void
8278 store_parm_decls (void)
8279 {
8280   tree fndecl = current_function_decl;
8281   bool proto;
8282 
8283   /* The argument information block for FNDECL.  */
8284   struct c_arg_info *arg_info = current_function_arg_info;
8285   current_function_arg_info = 0;
8286 
8287   /* True if this definition is written with a prototype.  Note:
8288      despite C99 6.7.5.3p14, we can *not* treat an empty argument
8289      list in a function definition as equivalent to (void) -- an
8290      empty argument list specifies the function has no parameters,
8291      but only (void) sets up a prototype for future calls.  */
8292   proto = arg_info->types != 0;
8293 
8294   if (proto)
8295     store_parm_decls_newstyle (fndecl, arg_info);
8296   else
8297     store_parm_decls_oldstyle (fndecl, arg_info);
8298 
8299   /* The next call to push_scope will be a function body.  */
8300 
8301   next_is_function_body = true;
8302 
8303   /* Write a record describing this function definition to the prototypes
8304      file (if requested).  */
8305 
8306   gen_aux_info_record (fndecl, 1, 0, proto);
8307 
8308   /* Initialize the RTL code for the function.  */
8309   allocate_struct_function (fndecl, false);
8310 
8311   if (warn_unused_local_typedefs)
8312     cfun->language = ggc_alloc_cleared_language_function ();
8313 
8314   /* Begin the statement tree for this function.  */
8315   DECL_SAVED_TREE (fndecl) = push_stmt_list ();
8316 
8317   /* ??? Insert the contents of the pending sizes list into the function
8318      to be evaluated.  The only reason left to have this is
8319 	void foo(int n, int array[n++])
8320      because we throw away the array type in favor of a pointer type, and
8321      thus won't naturally see the SAVE_EXPR containing the increment.  All
8322      other pending sizes would be handled by gimplify_parameters.  */
8323   if (arg_info->pending_sizes)
8324     add_stmt (arg_info->pending_sizes);
8325 }
8326 
8327 
8328 /* Finish up a function declaration and compile that function
8329    all the way to assembler language output.  Then free the storage
8330    for the function definition.
8331 
8332    This is called after parsing the body of the function definition.  */
8333 
8334 void
8335 finish_function (void)
8336 {
8337   tree fndecl = current_function_decl;
8338 
8339   if (c_dialect_objc ())
8340     objc_finish_function ();
8341 
8342   if (TREE_CODE (fndecl) == FUNCTION_DECL
8343       && targetm.calls.promote_prototypes (TREE_TYPE (fndecl)))
8344     {
8345       tree args = DECL_ARGUMENTS (fndecl);
8346       for (; args; args = DECL_CHAIN (args))
8347 	{
8348 	  tree type = TREE_TYPE (args);
8349 	  if (INTEGRAL_TYPE_P (type)
8350 	      && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
8351 	    DECL_ARG_TYPE (args) = integer_type_node;
8352 	}
8353     }
8354 
8355   if (DECL_INITIAL (fndecl) && DECL_INITIAL (fndecl) != error_mark_node)
8356     BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
8357 
8358   /* Must mark the RESULT_DECL as being in this function.  */
8359 
8360   if (DECL_RESULT (fndecl) && DECL_RESULT (fndecl) != error_mark_node)
8361     DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
8362 
8363   if (MAIN_NAME_P (DECL_NAME (fndecl)) && flag_hosted
8364       && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl)))
8365       == integer_type_node && flag_isoc99)
8366     {
8367       /* Hack.  We don't want the middle-end to warn that this return
8368 	 is unreachable, so we mark its location as special.  Using
8369 	 UNKNOWN_LOCATION has the problem that it gets clobbered in
8370 	 annotate_one_with_locus.  A cleaner solution might be to
8371 	 ensure ! should_carry_locus_p (stmt), but that needs a flag.
8372       */
8373       c_finish_return (BUILTINS_LOCATION, integer_zero_node, NULL_TREE);
8374     }
8375 
8376   /* Tie off the statement tree for this function.  */
8377   DECL_SAVED_TREE (fndecl) = pop_stmt_list (DECL_SAVED_TREE (fndecl));
8378 
8379   finish_fname_decls ();
8380 
8381   /* Complain if there's just no return statement.  */
8382   if (warn_return_type
8383       && TREE_CODE (TREE_TYPE (TREE_TYPE (fndecl))) != VOID_TYPE
8384       && !current_function_returns_value && !current_function_returns_null
8385       /* Don't complain if we are no-return.  */
8386       && !current_function_returns_abnormally
8387       /* Don't complain if we are declared noreturn.  */
8388       && !TREE_THIS_VOLATILE (fndecl)
8389       /* Don't warn for main().  */
8390       && !MAIN_NAME_P (DECL_NAME (fndecl))
8391       /* Or if they didn't actually specify a return type.  */
8392       && !C_FUNCTION_IMPLICIT_INT (fndecl)
8393       /* Normally, with -Wreturn-type, flow will complain, but we might
8394          optimize out static functions.  */
8395       && !TREE_PUBLIC (fndecl))
8396     {
8397       warning (OPT_Wreturn_type,
8398 	       "no return statement in function returning non-void");
8399       TREE_NO_WARNING (fndecl) = 1;
8400     }
8401 
8402   /* Complain about parameters that are only set, but never otherwise used.  */
8403   if (warn_unused_but_set_parameter)
8404     {
8405       tree decl;
8406 
8407       for (decl = DECL_ARGUMENTS (fndecl);
8408 	   decl;
8409 	   decl = DECL_CHAIN (decl))
8410 	if (TREE_USED (decl)
8411 	    && TREE_CODE (decl) == PARM_DECL
8412 	    && !DECL_READ_P (decl)
8413 	    && DECL_NAME (decl)
8414 	    && !DECL_ARTIFICIAL (decl)
8415 	    && !TREE_NO_WARNING (decl))
8416 	  warning_at (DECL_SOURCE_LOCATION (decl),
8417 		      OPT_Wunused_but_set_parameter,
8418 		      "parameter %qD set but not used", decl);
8419     }
8420 
8421   /* Complain about locally defined typedefs that are not used in this
8422      function.  */
8423   maybe_warn_unused_local_typedefs ();
8424 
8425   /* Store the end of the function, so that we get good line number
8426      info for the epilogue.  */
8427   cfun->function_end_locus = input_location;
8428 
8429   /* Finalize the ELF visibility for the function.  */
8430   c_determine_visibility (fndecl);
8431 
8432   /* For GNU C extern inline functions disregard inline limits.  */
8433   if (DECL_EXTERNAL (fndecl)
8434       && DECL_DECLARED_INLINE_P (fndecl))
8435     DECL_DISREGARD_INLINE_LIMITS (fndecl) = 1;
8436 
8437   /* Genericize before inlining.  Delay genericizing nested functions
8438      until their parent function is genericized.  Since finalizing
8439      requires GENERIC, delay that as well.  */
8440 
8441   if (DECL_INITIAL (fndecl) && DECL_INITIAL (fndecl) != error_mark_node
8442       && !undef_nested_function)
8443     {
8444       if (!decl_function_context (fndecl))
8445 	{
8446 	  invoke_plugin_callbacks (PLUGIN_PRE_GENERICIZE, fndecl);
8447 	  c_genericize (fndecl);
8448 
8449 	  /* ??? Objc emits functions after finalizing the compilation unit.
8450 	     This should be cleaned up later and this conditional removed.  */
8451 	  if (cgraph_global_info_ready)
8452 	    {
8453 	      cgraph_add_new_function (fndecl, false);
8454 	      return;
8455 	    }
8456 	  cgraph_finalize_function (fndecl, false);
8457 	}
8458       else
8459 	{
8460 	  /* Register this function with cgraph just far enough to get it
8461 	    added to our parent's nested function list.  Handy, since the
8462 	    C front end doesn't have such a list.  */
8463 	  (void) cgraph_get_create_node (fndecl);
8464 	}
8465     }
8466 
8467   if (!decl_function_context (fndecl))
8468     undef_nested_function = false;
8469 
8470   if (cfun->language != NULL)
8471     {
8472       ggc_free (cfun->language);
8473       cfun->language = NULL;
8474     }
8475 
8476   /* We're leaving the context of this function, so zap cfun.
8477      It's still in DECL_STRUCT_FUNCTION, and we'll restore it in
8478      tree_rest_of_compilation.  */
8479   set_cfun (NULL);
8480   current_function_decl = NULL;
8481 }
8482 
8483 /* Check the declarations given in a for-loop for satisfying the C99
8484    constraints.  If exactly one such decl is found, return it.  LOC is
8485    the location of the opening parenthesis of the for loop.  The last
8486    parameter allows you to control the "for loop initial declarations
8487    are only allowed in C99 mode".  Normally, you should pass
8488    flag_isoc99 as that parameter.  But in some cases (Objective-C
8489    foreach loop, for example) we want to run the checks in this
8490    function even if not in C99 mode, so we allow the caller to turn
8491    off the error about not being in C99 mode.
8492 */
8493 
8494 tree
8495 check_for_loop_decls (location_t loc, bool turn_off_iso_c99_error)
8496 {
8497   struct c_binding *b;
8498   tree one_decl = NULL_TREE;
8499   int n_decls = 0;
8500 
8501   if (!turn_off_iso_c99_error)
8502     {
8503       static bool hint = true;
8504       /* If we get here, declarations have been used in a for loop without
8505 	 the C99 for loop scope.  This doesn't make much sense, so don't
8506 	 allow it.  */
8507       error_at (loc, "%<for%> loop initial declarations "
8508 		"are only allowed in C99 mode");
8509       if (hint)
8510 	{
8511 	  inform (loc,
8512 		  "use option -std=c99 or -std=gnu99 to compile your code");
8513 	  hint = false;
8514 	}
8515       return NULL_TREE;
8516     }
8517   /* C99 subclause 6.8.5 paragraph 3:
8518 
8519        [#3]  The  declaration  part  of  a for statement shall only
8520        declare identifiers for objects having storage class auto or
8521        register.
8522 
8523      It isn't clear whether, in this sentence, "identifiers" binds to
8524      "shall only declare" or to "objects" - that is, whether all identifiers
8525      declared must be identifiers for objects, or whether the restriction
8526      only applies to those that are.  (A question on this in comp.std.c
8527      in November 2000 received no answer.)  We implement the strictest
8528      interpretation, to avoid creating an extension which later causes
8529      problems.  */
8530 
8531   for (b = current_scope->bindings; b; b = b->prev)
8532     {
8533       tree id = b->id;
8534       tree decl = b->decl;
8535 
8536       if (!id)
8537 	continue;
8538 
8539       switch (TREE_CODE (decl))
8540 	{
8541 	case VAR_DECL:
8542 	  {
8543 	    location_t decl_loc = DECL_SOURCE_LOCATION (decl);
8544 	    if (TREE_STATIC (decl))
8545 	      error_at (decl_loc,
8546 			"declaration of static variable %qD in %<for%> loop "
8547 			"initial declaration", decl);
8548 	    else if (DECL_EXTERNAL (decl))
8549 	      error_at (decl_loc,
8550 			"declaration of %<extern%> variable %qD in %<for%> loop "
8551 			"initial declaration", decl);
8552 	  }
8553 	  break;
8554 
8555 	case RECORD_TYPE:
8556 	  error_at (loc,
8557 		    "%<struct %E%> declared in %<for%> loop initial "
8558 		    "declaration", id);
8559 	  break;
8560 	case UNION_TYPE:
8561 	  error_at (loc,
8562 		    "%<union %E%> declared in %<for%> loop initial declaration",
8563 		    id);
8564 	  break;
8565 	case ENUMERAL_TYPE:
8566 	  error_at (loc, "%<enum %E%> declared in %<for%> loop "
8567 		    "initial declaration", id);
8568 	  break;
8569 	default:
8570 	  error_at (loc, "declaration of non-variable "
8571 		    "%qD in %<for%> loop initial declaration", decl);
8572 	}
8573 
8574       n_decls++;
8575       one_decl = decl;
8576     }
8577 
8578   return n_decls == 1 ? one_decl : NULL_TREE;
8579 }
8580 
8581 /* Save and reinitialize the variables
8582    used during compilation of a C function.  */
8583 
8584 void
8585 c_push_function_context (void)
8586 {
8587   struct language_function *p = cfun->language;
8588   /* cfun->language might have been already allocated by the use of
8589      -Wunused-local-typedefs.  In that case, just re-use it.  */
8590   if (p == NULL)
8591     cfun->language = p = ggc_alloc_cleared_language_function ();
8592 
8593   p->base.x_stmt_tree = c_stmt_tree;
8594   c_stmt_tree.x_cur_stmt_list = vec_safe_copy (c_stmt_tree.x_cur_stmt_list);
8595   p->x_break_label = c_break_label;
8596   p->x_cont_label = c_cont_label;
8597   p->x_switch_stack = c_switch_stack;
8598   p->arg_info = current_function_arg_info;
8599   p->returns_value = current_function_returns_value;
8600   p->returns_null = current_function_returns_null;
8601   p->returns_abnormally = current_function_returns_abnormally;
8602   p->warn_about_return_type = warn_about_return_type;
8603 
8604   push_function_context ();
8605 }
8606 
8607 /* Restore the variables used during compilation of a C function.  */
8608 
8609 void
8610 c_pop_function_context (void)
8611 {
8612   struct language_function *p;
8613 
8614   pop_function_context ();
8615   p = cfun->language;
8616 
8617   /* When -Wunused-local-typedefs is in effect, cfun->languages is
8618      used to store data throughout the life time of the current cfun,
8619      So don't deallocate it.  */
8620   if (!warn_unused_local_typedefs)
8621     cfun->language = NULL;
8622 
8623   if (DECL_STRUCT_FUNCTION (current_function_decl) == 0
8624       && DECL_SAVED_TREE (current_function_decl) == NULL_TREE)
8625     {
8626       /* Stop pointing to the local nodes about to be freed.  */
8627       /* But DECL_INITIAL must remain nonzero so we know this
8628 	 was an actual function definition.  */
8629       DECL_INITIAL (current_function_decl) = error_mark_node;
8630       DECL_ARGUMENTS (current_function_decl) = 0;
8631     }
8632 
8633   c_stmt_tree = p->base.x_stmt_tree;
8634   p->base.x_stmt_tree.x_cur_stmt_list = NULL;
8635   c_break_label = p->x_break_label;
8636   c_cont_label = p->x_cont_label;
8637   c_switch_stack = p->x_switch_stack;
8638   current_function_arg_info = p->arg_info;
8639   current_function_returns_value = p->returns_value;
8640   current_function_returns_null = p->returns_null;
8641   current_function_returns_abnormally = p->returns_abnormally;
8642   warn_about_return_type = p->warn_about_return_type;
8643 }
8644 
8645 /* The functions below are required for functionality of doing
8646    function at once processing in the C front end. Currently these
8647    functions are not called from anywhere in the C front end, but as
8648    these changes continue, that will change.  */
8649 
8650 /* Returns the stmt_tree (if any) to which statements are currently
8651    being added.  If there is no active statement-tree, NULL is
8652    returned.  */
8653 
8654 stmt_tree
8655 current_stmt_tree (void)
8656 {
8657   return &c_stmt_tree;
8658 }
8659 
8660 /* Return the global value of T as a symbol.  */
8661 
8662 tree
8663 identifier_global_value	(tree t)
8664 {
8665   struct c_binding *b;
8666 
8667   for (b = I_SYMBOL_BINDING (t); b; b = b->shadowed)
8668     if (B_IN_FILE_SCOPE (b) || B_IN_EXTERNAL_SCOPE (b))
8669       return b->decl;
8670 
8671   return 0;
8672 }
8673 
8674 /* In C, the only C-linkage public declaration is at file scope.  */
8675 
8676 tree
8677 c_linkage_bindings (tree name)
8678 {
8679   return identifier_global_value (name);
8680 }
8681 
8682 /* Record a builtin type for C.  If NAME is non-NULL, it is the name used;
8683    otherwise the name is found in ridpointers from RID_INDEX.  */
8684 
8685 void
8686 record_builtin_type (enum rid rid_index, const char *name, tree type)
8687 {
8688   tree id, decl;
8689   if (name == 0)
8690     id = ridpointers[(int) rid_index];
8691   else
8692     id = get_identifier (name);
8693   decl = build_decl (UNKNOWN_LOCATION, TYPE_DECL, id, type);
8694   pushdecl (decl);
8695   if (debug_hooks->type_decl)
8696     debug_hooks->type_decl (decl, false);
8697 }
8698 
8699 /* Build the void_list_node (void_type_node having been created).  */
8700 tree
8701 build_void_list_node (void)
8702 {
8703   tree t = build_tree_list (NULL_TREE, void_type_node);
8704   return t;
8705 }
8706 
8707 /* Return a c_parm structure with the given SPECS, ATTRS and DECLARATOR.  */
8708 
8709 struct c_parm *
8710 build_c_parm (struct c_declspecs *specs, tree attrs,
8711 	      struct c_declarator *declarator)
8712 {
8713   struct c_parm *ret = XOBNEW (&parser_obstack, struct c_parm);
8714   ret->specs = specs;
8715   ret->attrs = attrs;
8716   ret->declarator = declarator;
8717   return ret;
8718 }
8719 
8720 /* Return a declarator with nested attributes.  TARGET is the inner
8721    declarator to which these attributes apply.  ATTRS are the
8722    attributes.  */
8723 
8724 struct c_declarator *
8725 build_attrs_declarator (tree attrs, struct c_declarator *target)
8726 {
8727   struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
8728   ret->kind = cdk_attrs;
8729   ret->declarator = target;
8730   ret->u.attrs = attrs;
8731   return ret;
8732 }
8733 
8734 /* Return a declarator for a function with arguments specified by ARGS
8735    and return type specified by TARGET.  */
8736 
8737 struct c_declarator *
8738 build_function_declarator (struct c_arg_info *args,
8739 			   struct c_declarator *target)
8740 {
8741   struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
8742   ret->kind = cdk_function;
8743   ret->declarator = target;
8744   ret->u.arg_info = args;
8745   return ret;
8746 }
8747 
8748 /* Return a declarator for the identifier IDENT (which may be
8749    NULL_TREE for an abstract declarator).  */
8750 
8751 struct c_declarator *
8752 build_id_declarator (tree ident)
8753 {
8754   struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
8755   ret->kind = cdk_id;
8756   ret->declarator = 0;
8757   ret->u.id = ident;
8758   /* Default value - may get reset to a more precise location. */
8759   ret->id_loc = input_location;
8760   return ret;
8761 }
8762 
8763 /* Return something to represent absolute declarators containing a *.
8764    TARGET is the absolute declarator that the * contains.
8765    TYPE_QUALS_ATTRS is a structure for type qualifiers and attributes
8766    to apply to the pointer type.  */
8767 
8768 struct c_declarator *
8769 make_pointer_declarator (struct c_declspecs *type_quals_attrs,
8770 			 struct c_declarator *target)
8771 {
8772   tree attrs;
8773   int quals = 0;
8774   struct c_declarator *itarget = target;
8775   struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
8776   if (type_quals_attrs)
8777     {
8778       attrs = type_quals_attrs->attrs;
8779       quals = quals_from_declspecs (type_quals_attrs);
8780       if (attrs != NULL_TREE)
8781 	itarget = build_attrs_declarator (attrs, target);
8782     }
8783   ret->kind = cdk_pointer;
8784   ret->declarator = itarget;
8785   ret->u.pointer_quals = quals;
8786   return ret;
8787 }
8788 
8789 /* Return a pointer to a structure for an empty list of declaration
8790    specifiers.  */
8791 
8792 struct c_declspecs *
8793 build_null_declspecs (void)
8794 {
8795   struct c_declspecs *ret = XOBNEW (&parser_obstack, struct c_declspecs);
8796   memset (&ret->locations, 0, cdw_number_of_elements);
8797   ret->type = 0;
8798   ret->expr = 0;
8799   ret->decl_attr = 0;
8800   ret->attrs = 0;
8801   ret->align_log = -1;
8802   ret->typespec_word = cts_none;
8803   ret->storage_class = csc_none;
8804   ret->expr_const_operands = true;
8805   ret->declspecs_seen_p = false;
8806   ret->typespec_kind = ctsk_none;
8807   ret->non_sc_seen_p = false;
8808   ret->typedef_p = false;
8809   ret->explicit_signed_p = false;
8810   ret->deprecated_p = false;
8811   ret->default_int_p = false;
8812   ret->long_p = false;
8813   ret->long_long_p = false;
8814   ret->short_p = false;
8815   ret->signed_p = false;
8816   ret->unsigned_p = false;
8817   ret->complex_p = false;
8818   ret->inline_p = false;
8819   ret->noreturn_p = false;
8820   ret->thread_p = false;
8821   ret->const_p = false;
8822   ret->volatile_p = false;
8823   ret->restrict_p = false;
8824   ret->saturating_p = false;
8825   ret->alignas_p = false;
8826   ret->address_space = ADDR_SPACE_GENERIC;
8827   return ret;
8828 }
8829 
8830 /* Add the address space ADDRSPACE to the declaration specifiers
8831    SPECS, returning SPECS.  */
8832 
8833 struct c_declspecs *
8834 declspecs_add_addrspace (source_location location,
8835 			 struct c_declspecs *specs, addr_space_t as)
8836 {
8837   specs->non_sc_seen_p = true;
8838   specs->declspecs_seen_p = true;
8839 
8840   if (!ADDR_SPACE_GENERIC_P (specs->address_space)
8841       && specs->address_space != as)
8842     error ("incompatible address space qualifiers %qs and %qs",
8843 	   c_addr_space_name (as),
8844 	   c_addr_space_name (specs->address_space));
8845   else
8846     {
8847       specs->address_space = as;
8848       specs->locations[cdw_address_space] = location;
8849     }
8850   return specs;
8851 }
8852 
8853 /* Add the type qualifier QUAL to the declaration specifiers SPECS,
8854    returning SPECS.  */
8855 
8856 struct c_declspecs *
8857 declspecs_add_qual (source_location loc,
8858 		    struct c_declspecs *specs, tree qual)
8859 {
8860   enum rid i;
8861   bool dupe = false;
8862   specs->non_sc_seen_p = true;
8863   specs->declspecs_seen_p = true;
8864   gcc_assert (TREE_CODE (qual) == IDENTIFIER_NODE
8865 	      && C_IS_RESERVED_WORD (qual));
8866   i = C_RID_CODE (qual);
8867   switch (i)
8868     {
8869     case RID_CONST:
8870       dupe = specs->const_p;
8871       specs->const_p = true;
8872       specs->locations[cdw_const] = loc;
8873       break;
8874     case RID_VOLATILE:
8875       dupe = specs->volatile_p;
8876       specs->volatile_p = true;
8877       specs->locations[cdw_volatile] = loc;
8878       break;
8879     case RID_RESTRICT:
8880       dupe = specs->restrict_p;
8881       specs->restrict_p = true;
8882       specs->locations[cdw_restrict] = loc;
8883       break;
8884     default:
8885       gcc_unreachable ();
8886     }
8887   if (dupe && !flag_isoc99)
8888     pedwarn (loc, OPT_Wpedantic, "duplicate %qE", qual);
8889   return specs;
8890 }
8891 
8892 /* Add the type specifier TYPE to the declaration specifiers SPECS,
8893    returning SPECS.  */
8894 
8895 struct c_declspecs *
8896 declspecs_add_type (location_t loc, struct c_declspecs *specs,
8897 		    struct c_typespec spec)
8898 {
8899   tree type = spec.spec;
8900   specs->non_sc_seen_p = true;
8901   specs->declspecs_seen_p = true;
8902   specs->typespec_kind = spec.kind;
8903   if (TREE_DEPRECATED (type))
8904     specs->deprecated_p = true;
8905 
8906   /* Handle type specifier keywords.  */
8907   if (TREE_CODE (type) == IDENTIFIER_NODE
8908       && C_IS_RESERVED_WORD (type)
8909       && C_RID_CODE (type) != RID_CXX_COMPAT_WARN)
8910     {
8911       enum rid i = C_RID_CODE (type);
8912       if (specs->type)
8913 	{
8914 	  error_at (loc, "two or more data types in declaration specifiers");
8915 	  return specs;
8916 	}
8917       if ((int) i <= (int) RID_LAST_MODIFIER)
8918 	{
8919 	  /* "long", "short", "signed", "unsigned", "_Complex" or "_Sat".  */
8920 	  bool dupe = false;
8921 	  switch (i)
8922 	    {
8923 	    case RID_LONG:
8924 	      if (specs->long_long_p)
8925 		{
8926 		  error_at (loc, "%<long long long%> is too long for GCC");
8927 		  break;
8928 		}
8929 	      if (specs->long_p)
8930 		{
8931 		  if (specs->typespec_word == cts_double)
8932 		    {
8933 		      error_at (loc,
8934 				("both %<long long%> and %<double%> in "
8935 				 "declaration specifiers"));
8936 		      break;
8937 		    }
8938 		  pedwarn_c90 (loc, OPT_Wlong_long,
8939 			       "ISO C90 does not support %<long long%>");
8940 		  specs->long_long_p = 1;
8941 		  specs->locations[cdw_long_long] = loc;
8942 		  break;
8943 		}
8944 	      if (specs->short_p)
8945 		error_at (loc,
8946 			  ("both %<long%> and %<short%> in "
8947 			   "declaration specifiers"));
8948 	      else if (specs->typespec_word == cts_void)
8949 		error_at (loc,
8950 			  ("both %<long%> and %<void%> in "
8951 			   "declaration specifiers"));
8952 	      else if (specs->typespec_word == cts_int128)
8953 		  error_at (loc,
8954 			    ("both %<long%> and %<__int128%> in "
8955 			     "declaration specifiers"));
8956 	      else if (specs->typespec_word == cts_bool)
8957 		error_at (loc,
8958 			  ("both %<long%> and %<_Bool%> in "
8959 			   "declaration specifiers"));
8960 	      else if (specs->typespec_word == cts_char)
8961 		error_at (loc,
8962 			  ("both %<long%> and %<char%> in "
8963 			   "declaration specifiers"));
8964 	      else if (specs->typespec_word == cts_float)
8965 		error_at (loc,
8966 			  ("both %<long%> and %<float%> in "
8967 			   "declaration specifiers"));
8968 	      else if (specs->typespec_word == cts_dfloat32)
8969 		error_at (loc,
8970 			  ("both %<long%> and %<_Decimal32%> in "
8971 			   "declaration specifiers"));
8972 	      else if (specs->typespec_word == cts_dfloat64)
8973 		error_at (loc,
8974 			  ("both %<long%> and %<_Decimal64%> in "
8975 			   "declaration specifiers"));
8976 	      else if (specs->typespec_word == cts_dfloat128)
8977 		error_at (loc,
8978 			  ("both %<long%> and %<_Decimal128%> in "
8979 			   "declaration specifiers"));
8980 	      else
8981 		{
8982 		  specs->long_p = true;
8983 		  specs->locations[cdw_long] = loc;
8984 		}
8985 	      break;
8986 	    case RID_SHORT:
8987 	      dupe = specs->short_p;
8988 	      if (specs->long_p)
8989 		error_at (loc,
8990 			  ("both %<long%> and %<short%> in "
8991 			   "declaration specifiers"));
8992 	      else if (specs->typespec_word == cts_void)
8993 		error_at (loc,
8994 			  ("both %<short%> and %<void%> in "
8995 			   "declaration specifiers"));
8996 	      else if (specs->typespec_word == cts_int128)
8997 		error_at (loc,
8998 			  ("both %<short%> and %<__int128%> in "
8999 			   "declaration specifiers"));
9000 	      else if (specs->typespec_word == cts_bool)
9001 		error_at (loc,
9002 			  ("both %<short%> and %<_Bool%> in "
9003 			   "declaration specifiers"));
9004 	      else if (specs->typespec_word == cts_char)
9005 		error_at (loc,
9006 			  ("both %<short%> and %<char%> in "
9007 			   "declaration specifiers"));
9008 	      else if (specs->typespec_word == cts_float)
9009 		error_at (loc,
9010 			  ("both %<short%> and %<float%> in "
9011 			   "declaration specifiers"));
9012 	      else if (specs->typespec_word == cts_double)
9013 		error_at (loc,
9014 			  ("both %<short%> and %<double%> in "
9015 			   "declaration specifiers"));
9016 	      else if (specs->typespec_word == cts_dfloat32)
9017                 error_at (loc,
9018 			  ("both %<short%> and %<_Decimal32%> in "
9019 			   "declaration specifiers"));
9020 	      else if (specs->typespec_word == cts_dfloat64)
9021 		error_at (loc,
9022 			  ("both %<short%> and %<_Decimal64%> in "
9023 			   "declaration specifiers"));
9024 	      else if (specs->typespec_word == cts_dfloat128)
9025 		error_at (loc,
9026 			  ("both %<short%> and %<_Decimal128%> in "
9027 			   "declaration specifiers"));
9028 	      else
9029 		{
9030 		  specs->short_p = true;
9031 		  specs->locations[cdw_short] = loc;
9032 		}
9033 	      break;
9034 	    case RID_SIGNED:
9035 	      dupe = specs->signed_p;
9036 	      if (specs->unsigned_p)
9037 		error_at (loc,
9038 			  ("both %<signed%> and %<unsigned%> in "
9039 			   "declaration specifiers"));
9040 	      else if (specs->typespec_word == cts_void)
9041 		error_at (loc,
9042 			  ("both %<signed%> and %<void%> in "
9043 			   "declaration specifiers"));
9044 	      else if (specs->typespec_word == cts_bool)
9045 		error_at (loc,
9046 			  ("both %<signed%> and %<_Bool%> in "
9047 			   "declaration specifiers"));
9048 	      else if (specs->typespec_word == cts_float)
9049 		error_at (loc,
9050 			  ("both %<signed%> and %<float%> in "
9051 			   "declaration specifiers"));
9052 	      else if (specs->typespec_word == cts_double)
9053 		error_at (loc,
9054 			  ("both %<signed%> and %<double%> in "
9055 			   "declaration specifiers"));
9056 	      else if (specs->typespec_word == cts_dfloat32)
9057 		error_at (loc,
9058 			  ("both %<signed%> and %<_Decimal32%> in "
9059 			   "declaration specifiers"));
9060 	      else if (specs->typespec_word == cts_dfloat64)
9061 		error_at (loc,
9062 			  ("both %<signed%> and %<_Decimal64%> in "
9063 			   "declaration specifiers"));
9064 	      else if (specs->typespec_word == cts_dfloat128)
9065 		error_at (loc,
9066 			  ("both %<signed%> and %<_Decimal128%> in "
9067 			   "declaration specifiers"));
9068 	      else
9069 		{
9070 		  specs->signed_p = true;
9071 		  specs->locations[cdw_signed] = loc;
9072 		}
9073 	      break;
9074 	    case RID_UNSIGNED:
9075 	      dupe = specs->unsigned_p;
9076 	      if (specs->signed_p)
9077 		error_at (loc,
9078 			  ("both %<signed%> and %<unsigned%> in "
9079 			   "declaration specifiers"));
9080 	      else if (specs->typespec_word == cts_void)
9081 		error_at (loc,
9082 			  ("both %<unsigned%> and %<void%> in "
9083 			   "declaration specifiers"));
9084 	      else if (specs->typespec_word == cts_bool)
9085 		error_at (loc,
9086 			  ("both %<unsigned%> and %<_Bool%> in "
9087 			   "declaration specifiers"));
9088 	      else if (specs->typespec_word == cts_float)
9089 		error_at (loc,
9090 			  ("both %<unsigned%> and %<float%> in "
9091 			   "declaration specifiers"));
9092 	      else if (specs->typespec_word == cts_double)
9093 		error_at (loc,
9094 			  ("both %<unsigned%> and %<double%> in "
9095 			   "declaration specifiers"));
9096               else if (specs->typespec_word == cts_dfloat32)
9097 		error_at (loc,
9098 			  ("both %<unsigned%> and %<_Decimal32%> in "
9099 			   "declaration specifiers"));
9100 	      else if (specs->typespec_word == cts_dfloat64)
9101 		error_at (loc,
9102 			  ("both %<unsigned%> and %<_Decimal64%> in "
9103 			   "declaration specifiers"));
9104 	      else if (specs->typespec_word == cts_dfloat128)
9105 		error_at (loc,
9106 			  ("both %<unsigned%> and %<_Decimal128%> in "
9107 			   "declaration specifiers"));
9108 	      else
9109 		{
9110 		  specs->unsigned_p = true;
9111 		  specs->locations[cdw_unsigned] = loc;
9112 		}
9113 	      break;
9114 	    case RID_COMPLEX:
9115 	      dupe = specs->complex_p;
9116 	      if (!flag_isoc99 && !in_system_header_at (loc))
9117 		pedwarn (loc, OPT_Wpedantic,
9118 			 "ISO C90 does not support complex types");
9119 	      if (specs->typespec_word == cts_void)
9120 		error_at (loc,
9121 			  ("both %<complex%> and %<void%> in "
9122 			   "declaration specifiers"));
9123 	      else if (specs->typespec_word == cts_bool)
9124 		error_at (loc,
9125 			  ("both %<complex%> and %<_Bool%> in "
9126 			   "declaration specifiers"));
9127               else if (specs->typespec_word == cts_dfloat32)
9128 		error_at (loc,
9129 			  ("both %<complex%> and %<_Decimal32%> in "
9130 			   "declaration specifiers"));
9131 	      else if (specs->typespec_word == cts_dfloat64)
9132 		error_at (loc,
9133 			  ("both %<complex%> and %<_Decimal64%> in "
9134 			   "declaration specifiers"));
9135 	      else if (specs->typespec_word == cts_dfloat128)
9136 		error_at (loc,
9137 			  ("both %<complex%> and %<_Decimal128%> in "
9138 			   "declaration specifiers"));
9139 	      else if (specs->typespec_word == cts_fract)
9140 		error_at (loc,
9141 			  ("both %<complex%> and %<_Fract%> in "
9142 			   "declaration specifiers"));
9143 	      else if (specs->typespec_word == cts_accum)
9144 		error_at (loc,
9145 			  ("both %<complex%> and %<_Accum%> in "
9146 			   "declaration specifiers"));
9147 	      else if (specs->saturating_p)
9148 		error_at (loc,
9149 			  ("both %<complex%> and %<_Sat%> in "
9150 			   "declaration specifiers"));
9151 	      else
9152 		{
9153 		  specs->complex_p = true;
9154 		  specs->locations[cdw_complex] = loc;
9155 		}
9156 	      break;
9157 	    case RID_SAT:
9158 	      dupe = specs->saturating_p;
9159 	      pedwarn (loc, OPT_Wpedantic,
9160 		       "ISO C does not support saturating types");
9161 	      if (specs->typespec_word == cts_int128)
9162 	        {
9163 		  error_at (loc,
9164 			    ("both %<_Sat%> and %<__int128%> in "
9165 			     "declaration specifiers"));
9166 	        }
9167 	      else if (specs->typespec_word == cts_void)
9168 		error_at (loc,
9169 			  ("both %<_Sat%> and %<void%> in "
9170 			   "declaration specifiers"));
9171 	      else if (specs->typespec_word == cts_bool)
9172 		error_at (loc,
9173 			  ("both %<_Sat%> and %<_Bool%> in "
9174 			   "declaration specifiers"));
9175 	      else if (specs->typespec_word == cts_char)
9176 		error_at (loc,
9177 			  ("both %<_Sat%> and %<char%> in "
9178 			   "declaration specifiers"));
9179 	      else if (specs->typespec_word == cts_int)
9180 		error_at (loc,
9181 			  ("both %<_Sat%> and %<int%> in "
9182 			   "declaration specifiers"));
9183 	      else if (specs->typespec_word == cts_float)
9184 		error_at (loc,
9185 			  ("both %<_Sat%> and %<float%> in "
9186 			   "declaration specifiers"));
9187 	      else if (specs->typespec_word == cts_double)
9188 		error_at (loc,
9189 			  ("both %<_Sat%> and %<double%> in "
9190 			   "declaration specifiers"));
9191               else if (specs->typespec_word == cts_dfloat32)
9192 		error_at (loc,
9193 			  ("both %<_Sat%> and %<_Decimal32%> in "
9194 			   "declaration specifiers"));
9195 	      else if (specs->typespec_word == cts_dfloat64)
9196 		error_at (loc,
9197 			  ("both %<_Sat%> and %<_Decimal64%> in "
9198 			   "declaration specifiers"));
9199 	      else if (specs->typespec_word == cts_dfloat128)
9200 		error_at (loc,
9201 			  ("both %<_Sat%> and %<_Decimal128%> in "
9202 			   "declaration specifiers"));
9203 	      else if (specs->complex_p)
9204 		error_at (loc,
9205 			  ("both %<_Sat%> and %<complex%> in "
9206 			   "declaration specifiers"));
9207 	      else
9208 		{
9209 		  specs->saturating_p = true;
9210 		  specs->locations[cdw_saturating] = loc;
9211 		}
9212 	      break;
9213 	    default:
9214 	      gcc_unreachable ();
9215 	    }
9216 
9217 	  if (dupe)
9218 	    error_at (loc, "duplicate %qE", type);
9219 
9220 	  return specs;
9221 	}
9222       else
9223 	{
9224 	  /* "void", "_Bool", "char", "int", "float", "double", "_Decimal32",
9225 	     "__int128", "_Decimal64", "_Decimal128", "_Fract" or "_Accum".  */
9226 	  if (specs->typespec_word != cts_none)
9227 	    {
9228 	      error_at (loc,
9229 			"two or more data types in declaration specifiers");
9230 	      return specs;
9231 	    }
9232 	  switch (i)
9233 	    {
9234 	    case RID_INT128:
9235 	      if (int128_integer_type_node == NULL_TREE)
9236 		{
9237 		  error_at (loc, "%<__int128%> is not supported for this target");
9238 		  return specs;
9239 		}
9240 	      if (!in_system_header)
9241 		pedwarn (loc, OPT_Wpedantic,
9242 			 "ISO C does not support %<__int128%> type");
9243 
9244 	      if (specs->long_p)
9245 		error_at (loc,
9246 			  ("both %<__int128%> and %<long%> in "
9247 			   "declaration specifiers"));
9248 	      else if (specs->saturating_p)
9249 		error_at (loc,
9250 			  ("both %<_Sat%> and %<__int128%> in "
9251 			   "declaration specifiers"));
9252 	      else if (specs->short_p)
9253 		error_at (loc,
9254 			  ("both %<__int128%> and %<short%> in "
9255 			   "declaration specifiers"));
9256 	      else
9257 		{
9258 		  specs->typespec_word = cts_int128;
9259 		  specs->locations[cdw_typespec] = loc;
9260 		}
9261 	      return specs;
9262 	    case RID_VOID:
9263 	      if (specs->long_p)
9264 		error_at (loc,
9265 			  ("both %<long%> and %<void%> in "
9266 			   "declaration specifiers"));
9267 	      else if (specs->short_p)
9268 		error_at (loc,
9269 			  ("both %<short%> and %<void%> in "
9270 			   "declaration specifiers"));
9271 	      else if (specs->signed_p)
9272 		error_at (loc,
9273 			  ("both %<signed%> and %<void%> in "
9274 			   "declaration specifiers"));
9275 	      else if (specs->unsigned_p)
9276 		error_at (loc,
9277 			  ("both %<unsigned%> and %<void%> in "
9278 			   "declaration specifiers"));
9279 	      else if (specs->complex_p)
9280 		error_at (loc,
9281 			  ("both %<complex%> and %<void%> in "
9282 			   "declaration specifiers"));
9283 	      else if (specs->saturating_p)
9284 		error_at (loc,
9285 			  ("both %<_Sat%> and %<void%> in "
9286 			   "declaration specifiers"));
9287 	      else
9288 		{
9289 		  specs->typespec_word = cts_void;
9290 		  specs->locations[cdw_typespec] = loc;
9291 		}
9292 	      return specs;
9293 	    case RID_BOOL:
9294 	      if (specs->long_p)
9295 		error_at (loc,
9296 			  ("both %<long%> and %<_Bool%> in "
9297 			   "declaration specifiers"));
9298 	      else if (specs->short_p)
9299 		error_at (loc,
9300 			  ("both %<short%> and %<_Bool%> in "
9301 			   "declaration specifiers"));
9302 	      else if (specs->signed_p)
9303 		error_at (loc,
9304 			  ("both %<signed%> and %<_Bool%> in "
9305 			   "declaration specifiers"));
9306 	      else if (specs->unsigned_p)
9307 		error_at (loc,
9308 			  ("both %<unsigned%> and %<_Bool%> in "
9309 			   "declaration specifiers"));
9310 	      else if (specs->complex_p)
9311 		error_at (loc,
9312 			  ("both %<complex%> and %<_Bool%> in "
9313 			   "declaration specifiers"));
9314 	      else if (specs->saturating_p)
9315 		error_at (loc,
9316 			  ("both %<_Sat%> and %<_Bool%> in "
9317 			   "declaration specifiers"));
9318 	      else
9319 		{
9320 		  specs->typespec_word = cts_bool;
9321 		  specs->locations[cdw_typespec] = loc;
9322 		}
9323 	      return specs;
9324 	    case RID_CHAR:
9325 	      if (specs->long_p)
9326 		error_at (loc,
9327 			  ("both %<long%> and %<char%> in "
9328 			   "declaration specifiers"));
9329 	      else if (specs->short_p)
9330 		error_at (loc,
9331 			  ("both %<short%> and %<char%> in "
9332 			   "declaration specifiers"));
9333 	      else if (specs->saturating_p)
9334 		error_at (loc,
9335 			  ("both %<_Sat%> and %<char%> in "
9336 			   "declaration specifiers"));
9337 	      else
9338 		{
9339 		  specs->typespec_word = cts_char;
9340 		  specs->locations[cdw_typespec] = loc;
9341 		}
9342 	      return specs;
9343 	    case RID_INT:
9344 	      if (specs->saturating_p)
9345 		error_at (loc,
9346 			  ("both %<_Sat%> and %<int%> in "
9347 			   "declaration specifiers"));
9348 	      else
9349 		{
9350 		  specs->typespec_word = cts_int;
9351 		  specs->locations[cdw_typespec] = loc;
9352 		}
9353 	      return specs;
9354 	    case RID_FLOAT:
9355 	      if (specs->long_p)
9356 		error_at (loc,
9357 			  ("both %<long%> and %<float%> in "
9358 			   "declaration specifiers"));
9359 	      else if (specs->short_p)
9360 		error_at (loc,
9361 			  ("both %<short%> and %<float%> in "
9362 			   "declaration specifiers"));
9363 	      else if (specs->signed_p)
9364 		error_at (loc,
9365 			  ("both %<signed%> and %<float%> in "
9366 			   "declaration specifiers"));
9367 	      else if (specs->unsigned_p)
9368 		error_at (loc,
9369 			  ("both %<unsigned%> and %<float%> in "
9370 			   "declaration specifiers"));
9371 	      else if (specs->saturating_p)
9372 		error_at (loc,
9373 			  ("both %<_Sat%> and %<float%> in "
9374 			   "declaration specifiers"));
9375 	      else
9376 		{
9377 		  specs->typespec_word = cts_float;
9378 		  specs->locations[cdw_typespec] = loc;
9379 		}
9380 	      return specs;
9381 	    case RID_DOUBLE:
9382 	      if (specs->long_long_p)
9383 		error_at (loc,
9384 			  ("both %<long long%> and %<double%> in "
9385 			   "declaration specifiers"));
9386 	      else if (specs->short_p)
9387 		error_at (loc,
9388 			  ("both %<short%> and %<double%> in "
9389 			   "declaration specifiers"));
9390 	      else if (specs->signed_p)
9391 		error_at (loc,
9392 			  ("both %<signed%> and %<double%> in "
9393 			   "declaration specifiers"));
9394 	      else if (specs->unsigned_p)
9395 		error_at (loc,
9396 			  ("both %<unsigned%> and %<double%> in "
9397 			   "declaration specifiers"));
9398 	      else if (specs->saturating_p)
9399 		error_at (loc,
9400 			  ("both %<_Sat%> and %<double%> in "
9401 			   "declaration specifiers"));
9402 	      else
9403 		{
9404 		  specs->typespec_word = cts_double;
9405 		  specs->locations[cdw_typespec] = loc;
9406 		}
9407 	      return specs;
9408 	    case RID_DFLOAT32:
9409 	    case RID_DFLOAT64:
9410 	    case RID_DFLOAT128:
9411 	      {
9412 		const char *str;
9413 		if (i == RID_DFLOAT32)
9414 		  str = "_Decimal32";
9415 		else if (i == RID_DFLOAT64)
9416 		  str = "_Decimal64";
9417 		else
9418 		  str = "_Decimal128";
9419 		if (specs->long_long_p)
9420 		  error_at (loc,
9421 			    ("both %<long long%> and %<%s%> in "
9422 			     "declaration specifiers"),
9423 			    str);
9424 		if (specs->long_p)
9425 		  error_at (loc,
9426 			    ("both %<long%> and %<%s%> in "
9427 			     "declaration specifiers"),
9428 			    str);
9429 		else if (specs->short_p)
9430 		  error_at (loc,
9431 			    ("both %<short%> and %<%s%> in "
9432 			     "declaration specifiers"),
9433 			    str);
9434 		else if (specs->signed_p)
9435 		  error_at (loc,
9436 			    ("both %<signed%> and %<%s%> in "
9437 			     "declaration specifiers"),
9438 			    str);
9439 		else if (specs->unsigned_p)
9440 		  error_at (loc,
9441 			    ("both %<unsigned%> and %<%s%> in "
9442 			     "declaration specifiers"),
9443 			    str);
9444                 else if (specs->complex_p)
9445                   error_at (loc,
9446 			    ("both %<complex%> and %<%s%> in "
9447 			     "declaration specifiers"),
9448 			    str);
9449                 else if (specs->saturating_p)
9450                   error_at (loc,
9451 			    ("both %<_Sat%> and %<%s%> in "
9452 			     "declaration specifiers"),
9453 			    str);
9454 		else if (i == RID_DFLOAT32)
9455 		  specs->typespec_word = cts_dfloat32;
9456 		else if (i == RID_DFLOAT64)
9457 		  specs->typespec_word = cts_dfloat64;
9458 		else
9459 		  specs->typespec_word = cts_dfloat128;
9460 		specs->locations[cdw_typespec] = loc;
9461 	      }
9462 	      if (!targetm.decimal_float_supported_p ())
9463 		error_at (loc,
9464 			  ("decimal floating point not supported "
9465 			   "for this target"));
9466 	      pedwarn (loc, OPT_Wpedantic,
9467 		       "ISO C does not support decimal floating point");
9468 	      return specs;
9469 	    case RID_FRACT:
9470 	    case RID_ACCUM:
9471 	      {
9472 		const char *str;
9473 		if (i == RID_FRACT)
9474 		  str = "_Fract";
9475 		else
9476 		  str = "_Accum";
9477                 if (specs->complex_p)
9478                   error_at (loc,
9479 			    ("both %<complex%> and %<%s%> in "
9480 			     "declaration specifiers"),
9481 			    str);
9482 		else if (i == RID_FRACT)
9483 		    specs->typespec_word = cts_fract;
9484 		else
9485 		    specs->typespec_word = cts_accum;
9486 		specs->locations[cdw_typespec] = loc;
9487 	      }
9488 	      if (!targetm.fixed_point_supported_p ())
9489 		error_at (loc,
9490 			  "fixed-point types not supported for this target");
9491 	      pedwarn (loc, OPT_Wpedantic,
9492 		       "ISO C does not support fixed-point types");
9493 	      return specs;
9494 	    default:
9495 	      /* ObjC reserved word "id", handled below.  */
9496 	      break;
9497 	    }
9498 	}
9499     }
9500 
9501   /* Now we have a typedef (a TYPE_DECL node), an identifier (some
9502      form of ObjC type, cases such as "int" and "long" being handled
9503      above), a TYPE (struct, union, enum and typeof specifiers) or an
9504      ERROR_MARK.  In none of these cases may there have previously
9505      been any type specifiers.  */
9506   if (specs->type || specs->typespec_word != cts_none
9507       || specs->long_p || specs->short_p || specs->signed_p
9508       || specs->unsigned_p || specs->complex_p)
9509     error_at (loc, "two or more data types in declaration specifiers");
9510   else if (TREE_CODE (type) == TYPE_DECL)
9511     {
9512       if (TREE_TYPE (type) == error_mark_node)
9513 	; /* Allow the type to default to int to avoid cascading errors.  */
9514       else
9515 	{
9516 	  specs->type = TREE_TYPE (type);
9517 	  specs->decl_attr = DECL_ATTRIBUTES (type);
9518 	  specs->typedef_p = true;
9519 	  specs->explicit_signed_p = C_TYPEDEF_EXPLICITLY_SIGNED (type);
9520 	  specs->locations[cdw_typedef] = loc;
9521 
9522 	  /* If this typedef name is defined in a struct, then a C++
9523 	     lookup would return a different value.  */
9524 	  if (warn_cxx_compat
9525 	      && I_SYMBOL_BINDING (DECL_NAME (type))->in_struct)
9526 	    warning_at (loc, OPT_Wc___compat,
9527 			"C++ lookup of %qD would return a field, not a type",
9528 			type);
9529 
9530 	  /* If we are parsing a struct, record that a struct field
9531 	     used a typedef.  */
9532 	  if (warn_cxx_compat && struct_parse_info != NULL)
9533 	    struct_parse_info->typedefs_seen.safe_push (type);
9534 	}
9535     }
9536   else if (TREE_CODE (type) == IDENTIFIER_NODE)
9537     {
9538       tree t = lookup_name (type);
9539       if (!t || TREE_CODE (t) != TYPE_DECL)
9540 	error_at (loc, "%qE fails to be a typedef or built in type", type);
9541       else if (TREE_TYPE (t) == error_mark_node)
9542 	;
9543       else
9544 	{
9545 	  specs->type = TREE_TYPE (t);
9546 	  specs->locations[cdw_typespec] = loc;
9547 	}
9548     }
9549   else
9550     {
9551       if (TREE_CODE (type) != ERROR_MARK && spec.kind == ctsk_typeof)
9552 	{
9553 	  specs->typedef_p = true;
9554 	  specs->locations[cdw_typedef] = loc;
9555 	  if (spec.expr)
9556 	    {
9557 	      if (specs->expr)
9558 		specs->expr = build2 (COMPOUND_EXPR, TREE_TYPE (spec.expr),
9559 				      specs->expr, spec.expr);
9560 	      else
9561 		specs->expr = spec.expr;
9562 	      specs->expr_const_operands &= spec.expr_const_operands;
9563 	    }
9564 	}
9565       specs->type = type;
9566     }
9567 
9568   return specs;
9569 }
9570 
9571 /* Add the storage class specifier or function specifier SCSPEC to the
9572    declaration specifiers SPECS, returning SPECS.  */
9573 
9574 struct c_declspecs *
9575 declspecs_add_scspec (source_location loc,
9576 		      struct c_declspecs *specs,
9577 		      tree scspec)
9578 {
9579   enum rid i;
9580   enum c_storage_class n = csc_none;
9581   bool dupe = false;
9582   specs->declspecs_seen_p = true;
9583   gcc_assert (TREE_CODE (scspec) == IDENTIFIER_NODE
9584 	      && C_IS_RESERVED_WORD (scspec));
9585   i = C_RID_CODE (scspec);
9586   if (specs->non_sc_seen_p)
9587     warning (OPT_Wold_style_declaration,
9588              "%qE is not at beginning of declaration", scspec);
9589   switch (i)
9590     {
9591     case RID_INLINE:
9592       /* C99 permits duplicate inline.  Although of doubtful utility,
9593 	 it seems simplest to permit it in gnu89 mode as well, as
9594 	 there is also little utility in maintaining this as a
9595 	 difference between gnu89 and C99 inline.  */
9596       dupe = false;
9597       specs->inline_p = true;
9598       specs->locations[cdw_inline] = loc;
9599       break;
9600     case RID_NORETURN:
9601       /* Duplicate _Noreturn is permitted.  */
9602       dupe = false;
9603       specs->noreturn_p = true;
9604       specs->locations[cdw_noreturn] = loc;
9605       break;
9606     case RID_THREAD:
9607       dupe = specs->thread_p;
9608       if (specs->storage_class == csc_auto)
9609 	error ("%<__thread%> used with %<auto%>");
9610       else if (specs->storage_class == csc_register)
9611 	error ("%<__thread%> used with %<register%>");
9612       else if (specs->storage_class == csc_typedef)
9613 	error ("%<__thread%> used with %<typedef%>");
9614       else
9615 	{
9616 	  specs->thread_p = true;
9617 	  specs->locations[cdw_thread] = loc;
9618 	}
9619       break;
9620     case RID_AUTO:
9621       n = csc_auto;
9622       break;
9623     case RID_EXTERN:
9624       n = csc_extern;
9625       /* Diagnose "__thread extern".  */
9626       if (specs->thread_p)
9627 	error ("%<__thread%> before %<extern%>");
9628       break;
9629     case RID_REGISTER:
9630       n = csc_register;
9631       break;
9632     case RID_STATIC:
9633       n = csc_static;
9634       /* Diagnose "__thread static".  */
9635       if (specs->thread_p)
9636 	error ("%<__thread%> before %<static%>");
9637       break;
9638     case RID_TYPEDEF:
9639       n = csc_typedef;
9640       break;
9641     default:
9642       gcc_unreachable ();
9643     }
9644   if (n != csc_none && n == specs->storage_class)
9645     dupe = true;
9646   if (dupe)
9647     error ("duplicate %qE", scspec);
9648   if (n != csc_none)
9649     {
9650       if (specs->storage_class != csc_none && n != specs->storage_class)
9651 	{
9652 	  error ("multiple storage classes in declaration specifiers");
9653 	}
9654       else
9655 	{
9656 	  specs->storage_class = n;
9657 	  specs->locations[cdw_storage_class] = loc;
9658 	  if (n != csc_extern && n != csc_static && specs->thread_p)
9659 	    {
9660 	      error ("%<__thread%> used with %qE", scspec);
9661 	      specs->thread_p = false;
9662 	    }
9663 	}
9664     }
9665   return specs;
9666 }
9667 
9668 /* Add the attributes ATTRS to the declaration specifiers SPECS,
9669    returning SPECS.  */
9670 
9671 struct c_declspecs *
9672 declspecs_add_attrs (source_location loc, struct c_declspecs *specs, tree attrs)
9673 {
9674   specs->attrs = chainon (attrs, specs->attrs);
9675   specs->locations[cdw_attributes] = loc;
9676   specs->declspecs_seen_p = true;
9677   return specs;
9678 }
9679 
9680 /* Add an _Alignas specifier (expression ALIGN, or type whose
9681    alignment is ALIGN) to the declaration specifiers SPECS, returning
9682    SPECS.  */
9683 struct c_declspecs *
9684 declspecs_add_alignas (source_location loc,
9685 		       struct c_declspecs *specs, tree align)
9686 {
9687   int align_log;
9688   specs->alignas_p = true;
9689   specs->locations[cdw_alignas] = loc;
9690   if (align == error_mark_node)
9691     return specs;
9692   align_log = check_user_alignment (align, true);
9693   if (align_log > specs->align_log)
9694     specs->align_log = align_log;
9695   return specs;
9696 }
9697 
9698 /* Combine "long", "short", "signed", "unsigned" and "_Complex" type
9699    specifiers with any other type specifier to determine the resulting
9700    type.  This is where ISO C checks on complex types are made, since
9701    "_Complex long" is a prefix of the valid ISO C type "_Complex long
9702    double".  */
9703 
9704 struct c_declspecs *
9705 finish_declspecs (struct c_declspecs *specs)
9706 {
9707   /* If a type was specified as a whole, we have no modifiers and are
9708      done.  */
9709   if (specs->type != NULL_TREE)
9710     {
9711       gcc_assert (!specs->long_p && !specs->long_long_p && !specs->short_p
9712 		  && !specs->signed_p && !specs->unsigned_p
9713 		  && !specs->complex_p);
9714 
9715       /* Set a dummy type.  */
9716       if (TREE_CODE (specs->type) == ERROR_MARK)
9717         specs->type = integer_type_node;
9718       return specs;
9719     }
9720 
9721   /* If none of "void", "_Bool", "char", "int", "float" or "double"
9722      has been specified, treat it as "int" unless "_Complex" is
9723      present and there are no other specifiers.  If we just have
9724      "_Complex", it is equivalent to "_Complex double", but e.g.
9725      "_Complex short" is equivalent to "_Complex short int".  */
9726   if (specs->typespec_word == cts_none)
9727     {
9728       if (specs->saturating_p)
9729 	{
9730 	  error_at (specs->locations[cdw_saturating],
9731 		    "%<_Sat%> is used without %<_Fract%> or %<_Accum%>");
9732 	  if (!targetm.fixed_point_supported_p ())
9733 	    error_at (specs->locations[cdw_saturating],
9734 		      "fixed-point types not supported for this target");
9735 	  specs->typespec_word = cts_fract;
9736 	}
9737       else if (specs->long_p || specs->short_p
9738 	       || specs->signed_p || specs->unsigned_p)
9739 	{
9740 	  specs->typespec_word = cts_int;
9741 	}
9742       else if (specs->complex_p)
9743 	{
9744 	  specs->typespec_word = cts_double;
9745 	  pedwarn (specs->locations[cdw_complex], OPT_Wpedantic,
9746 		   "ISO C does not support plain %<complex%> meaning "
9747 		   "%<double complex%>");
9748 	}
9749       else
9750 	{
9751 	  specs->typespec_word = cts_int;
9752 	  specs->default_int_p = true;
9753 	  /* We don't diagnose this here because grokdeclarator will
9754 	     give more specific diagnostics according to whether it is
9755 	     a function definition.  */
9756 	}
9757     }
9758 
9759   /* If "signed" was specified, record this to distinguish "int" and
9760      "signed int" in the case of a bit-field with
9761      -funsigned-bitfields.  */
9762   specs->explicit_signed_p = specs->signed_p;
9763 
9764   /* Now compute the actual type.  */
9765   switch (specs->typespec_word)
9766     {
9767     case cts_void:
9768       gcc_assert (!specs->long_p && !specs->short_p
9769 		  && !specs->signed_p && !specs->unsigned_p
9770 		  && !specs->complex_p);
9771       specs->type = void_type_node;
9772       break;
9773     case cts_bool:
9774       gcc_assert (!specs->long_p && !specs->short_p
9775 		  && !specs->signed_p && !specs->unsigned_p
9776 		  && !specs->complex_p);
9777       specs->type = boolean_type_node;
9778       break;
9779     case cts_char:
9780       gcc_assert (!specs->long_p && !specs->short_p);
9781       gcc_assert (!(specs->signed_p && specs->unsigned_p));
9782       if (specs->signed_p)
9783 	specs->type = signed_char_type_node;
9784       else if (specs->unsigned_p)
9785 	specs->type = unsigned_char_type_node;
9786       else
9787 	specs->type = char_type_node;
9788       if (specs->complex_p)
9789 	{
9790 	  pedwarn (specs->locations[cdw_complex], OPT_Wpedantic,
9791 		   "ISO C does not support complex integer types");
9792 	  specs->type = build_complex_type (specs->type);
9793 	}
9794       break;
9795     case cts_int128:
9796       gcc_assert (!specs->long_p && !specs->short_p && !specs->long_long_p);
9797       gcc_assert (!(specs->signed_p && specs->unsigned_p));
9798       specs->type = (specs->unsigned_p
9799 		     ? int128_unsigned_type_node
9800 		     : int128_integer_type_node);
9801       if (specs->complex_p)
9802 	{
9803 	  pedwarn (specs->locations[cdw_complex], OPT_Wpedantic,
9804 		   "ISO C does not support complex integer types");
9805 	  specs->type = build_complex_type (specs->type);
9806 	}
9807       break;
9808     case cts_int:
9809       gcc_assert (!(specs->long_p && specs->short_p));
9810       gcc_assert (!(specs->signed_p && specs->unsigned_p));
9811       if (specs->long_long_p)
9812 	specs->type = (specs->unsigned_p
9813 		       ? long_long_unsigned_type_node
9814 		       : long_long_integer_type_node);
9815       else if (specs->long_p)
9816 	specs->type = (specs->unsigned_p
9817 		       ? long_unsigned_type_node
9818 		       : long_integer_type_node);
9819       else if (specs->short_p)
9820 	specs->type = (specs->unsigned_p
9821 		       ? short_unsigned_type_node
9822 		       : short_integer_type_node);
9823       else
9824 	specs->type = (specs->unsigned_p
9825 		       ? unsigned_type_node
9826 		       : integer_type_node);
9827       if (specs->complex_p)
9828 	{
9829 	  pedwarn (specs->locations[cdw_complex], OPT_Wpedantic,
9830 		   "ISO C does not support complex integer types");
9831 	  specs->type = build_complex_type (specs->type);
9832 	}
9833       break;
9834     case cts_float:
9835       gcc_assert (!specs->long_p && !specs->short_p
9836 		  && !specs->signed_p && !specs->unsigned_p);
9837       specs->type = (specs->complex_p
9838 		     ? complex_float_type_node
9839 		     : float_type_node);
9840       break;
9841     case cts_double:
9842       gcc_assert (!specs->long_long_p && !specs->short_p
9843 		  && !specs->signed_p && !specs->unsigned_p);
9844       if (specs->long_p)
9845 	{
9846 	  specs->type = (specs->complex_p
9847 			 ? complex_long_double_type_node
9848 			 : long_double_type_node);
9849 	}
9850       else
9851 	{
9852 	  specs->type = (specs->complex_p
9853 			 ? complex_double_type_node
9854 			 : double_type_node);
9855 	}
9856       break;
9857     case cts_dfloat32:
9858     case cts_dfloat64:
9859     case cts_dfloat128:
9860       gcc_assert (!specs->long_p && !specs->long_long_p && !specs->short_p
9861 		  && !specs->signed_p && !specs->unsigned_p && !specs->complex_p);
9862       if (specs->typespec_word == cts_dfloat32)
9863 	specs->type = dfloat32_type_node;
9864       else if (specs->typespec_word == cts_dfloat64)
9865 	specs->type = dfloat64_type_node;
9866       else
9867 	specs->type = dfloat128_type_node;
9868       break;
9869     case cts_fract:
9870       gcc_assert (!specs->complex_p);
9871       if (!targetm.fixed_point_supported_p ())
9872 	specs->type = integer_type_node;
9873       else if (specs->saturating_p)
9874 	{
9875 	  if (specs->long_long_p)
9876 	    specs->type = specs->unsigned_p
9877 			  ? sat_unsigned_long_long_fract_type_node
9878 			  : sat_long_long_fract_type_node;
9879 	  else if (specs->long_p)
9880 	    specs->type = specs->unsigned_p
9881 			  ? sat_unsigned_long_fract_type_node
9882 			  : sat_long_fract_type_node;
9883 	  else if (specs->short_p)
9884 	    specs->type = specs->unsigned_p
9885 			  ? sat_unsigned_short_fract_type_node
9886 			  : sat_short_fract_type_node;
9887 	  else
9888 	    specs->type = specs->unsigned_p
9889 			  ? sat_unsigned_fract_type_node
9890 			  : sat_fract_type_node;
9891 	}
9892       else
9893 	{
9894 	  if (specs->long_long_p)
9895 	    specs->type = specs->unsigned_p
9896 			  ? unsigned_long_long_fract_type_node
9897 			  : long_long_fract_type_node;
9898 	  else if (specs->long_p)
9899 	    specs->type = specs->unsigned_p
9900 			  ? unsigned_long_fract_type_node
9901 			  : long_fract_type_node;
9902 	  else if (specs->short_p)
9903 	    specs->type = specs->unsigned_p
9904 			  ? unsigned_short_fract_type_node
9905 			  : short_fract_type_node;
9906 	  else
9907 	    specs->type = specs->unsigned_p
9908 			  ? unsigned_fract_type_node
9909 			  : fract_type_node;
9910 	}
9911       break;
9912     case cts_accum:
9913       gcc_assert (!specs->complex_p);
9914       if (!targetm.fixed_point_supported_p ())
9915 	specs->type = integer_type_node;
9916       else if (specs->saturating_p)
9917 	{
9918 	  if (specs->long_long_p)
9919 	    specs->type = specs->unsigned_p
9920 			  ? sat_unsigned_long_long_accum_type_node
9921 			  : sat_long_long_accum_type_node;
9922 	  else if (specs->long_p)
9923 	    specs->type = specs->unsigned_p
9924 			  ? sat_unsigned_long_accum_type_node
9925 			  : sat_long_accum_type_node;
9926 	  else if (specs->short_p)
9927 	    specs->type = specs->unsigned_p
9928 			  ? sat_unsigned_short_accum_type_node
9929 			  : sat_short_accum_type_node;
9930 	  else
9931 	    specs->type = specs->unsigned_p
9932 			  ? sat_unsigned_accum_type_node
9933 			  : sat_accum_type_node;
9934 	}
9935       else
9936 	{
9937 	  if (specs->long_long_p)
9938 	    specs->type = specs->unsigned_p
9939 			  ? unsigned_long_long_accum_type_node
9940 			  : long_long_accum_type_node;
9941 	  else if (specs->long_p)
9942 	    specs->type = specs->unsigned_p
9943 			  ? unsigned_long_accum_type_node
9944 			  : long_accum_type_node;
9945 	  else if (specs->short_p)
9946 	    specs->type = specs->unsigned_p
9947 			  ? unsigned_short_accum_type_node
9948 			  : short_accum_type_node;
9949 	  else
9950 	    specs->type = specs->unsigned_p
9951 			  ? unsigned_accum_type_node
9952 			  : accum_type_node;
9953 	}
9954       break;
9955     default:
9956       gcc_unreachable ();
9957     }
9958 
9959   return specs;
9960 }
9961 
9962 /* A subroutine of c_write_global_declarations.  Perform final processing
9963    on one file scope's declarations (or the external scope's declarations),
9964    GLOBALS.  */
9965 
9966 static void
9967 c_write_global_declarations_1 (tree globals)
9968 {
9969   tree decl;
9970   bool reconsider;
9971 
9972   /* Process the decls in the order they were written.  */
9973   for (decl = globals; decl; decl = DECL_CHAIN (decl))
9974     {
9975       /* Check for used but undefined static functions using the C
9976 	 standard's definition of "used", and set TREE_NO_WARNING so
9977 	 that check_global_declarations doesn't repeat the check.  */
9978       if (TREE_CODE (decl) == FUNCTION_DECL
9979 	  && DECL_INITIAL (decl) == 0
9980 	  && DECL_EXTERNAL (decl)
9981 	  && !TREE_PUBLIC (decl)
9982 	  && C_DECL_USED (decl))
9983 	{
9984 	  pedwarn (input_location, 0, "%q+F used but never defined", decl);
9985 	  TREE_NO_WARNING (decl) = 1;
9986 	}
9987 
9988       wrapup_global_declaration_1 (decl);
9989     }
9990 
9991   do
9992     {
9993       reconsider = false;
9994       for (decl = globals; decl; decl = DECL_CHAIN (decl))
9995 	reconsider |= wrapup_global_declaration_2 (decl);
9996     }
9997   while (reconsider);
9998 
9999   for (decl = globals; decl; decl = DECL_CHAIN (decl))
10000     check_global_declaration_1 (decl);
10001 }
10002 
10003 /* A subroutine of c_write_global_declarations Emit debug information for each
10004    of the declarations in GLOBALS.  */
10005 
10006 static void
10007 c_write_global_declarations_2 (tree globals)
10008 {
10009   tree decl;
10010 
10011   for (decl = globals; decl ; decl = DECL_CHAIN (decl))
10012     debug_hooks->global_decl (decl);
10013 }
10014 
10015 /* Callback to collect a source_ref from a DECL.  */
10016 
10017 static void
10018 collect_source_ref_cb (tree decl)
10019 {
10020   if (!DECL_IS_BUILTIN (decl))
10021     collect_source_ref (LOCATION_FILE (decl_sloc (decl, false)));
10022 }
10023 
10024 /* Preserve the external declarations scope across a garbage collect.  */
10025 static GTY(()) tree ext_block;
10026 
10027 /* Collect all references relevant to SOURCE_FILE.  */
10028 
10029 static void
10030 collect_all_refs (const char *source_file)
10031 {
10032   tree t;
10033   unsigned i;
10034 
10035   FOR_EACH_VEC_ELT (*all_translation_units, i, t)
10036     collect_ada_nodes (BLOCK_VARS (DECL_INITIAL (t)), source_file);
10037 
10038   collect_ada_nodes (BLOCK_VARS (ext_block), source_file);
10039 }
10040 
10041 /* Iterate over all global declarations and call CALLBACK.  */
10042 
10043 static void
10044 for_each_global_decl (void (*callback) (tree decl))
10045 {
10046   tree t;
10047   tree decls;
10048   tree decl;
10049   unsigned i;
10050 
10051   FOR_EACH_VEC_ELT (*all_translation_units, i, t)
10052     {
10053       decls = DECL_INITIAL (t);
10054       for (decl = BLOCK_VARS (decls); decl; decl = TREE_CHAIN (decl))
10055 	callback (decl);
10056     }
10057 
10058   for (decl = BLOCK_VARS (ext_block); decl; decl = TREE_CHAIN (decl))
10059     callback (decl);
10060 }
10061 
10062 void
10063 c_write_global_declarations (void)
10064 {
10065   tree t;
10066   unsigned i;
10067 
10068   /* We don't want to do this if generating a PCH.  */
10069   if (pch_file)
10070     return;
10071 
10072   timevar_start (TV_PHASE_DEFERRED);
10073 
10074   /* Do the Objective-C stuff.  This is where all the Objective-C
10075      module stuff gets generated (symtab, class/protocol/selector
10076      lists etc).  */
10077   if (c_dialect_objc ())
10078     objc_write_global_declarations ();
10079 
10080   /* Close the external scope.  */
10081   ext_block = pop_scope ();
10082   external_scope = 0;
10083   gcc_assert (!current_scope);
10084 
10085   /* Handle -fdump-ada-spec[-slim]. */
10086   if (flag_dump_ada_spec || flag_dump_ada_spec_slim)
10087     {
10088       /* Build a table of files to generate specs for */
10089       if (flag_dump_ada_spec_slim)
10090 	collect_source_ref (main_input_filename);
10091       else
10092 	for_each_global_decl (collect_source_ref_cb);
10093 
10094       dump_ada_specs (collect_all_refs, NULL);
10095     }
10096 
10097   if (ext_block)
10098     {
10099       tree tmp = BLOCK_VARS (ext_block);
10100       int flags;
10101       FILE * stream = dump_begin (TDI_tu, &flags);
10102       if (stream && tmp)
10103 	{
10104 	  dump_node (tmp, flags & ~TDF_SLIM, stream);
10105 	  dump_end (TDI_tu, stream);
10106 	}
10107     }
10108 
10109   /* Process all file scopes in this compilation, and the external_scope,
10110      through wrapup_global_declarations and check_global_declarations.  */
10111   FOR_EACH_VEC_ELT (*all_translation_units, i, t)
10112     c_write_global_declarations_1 (BLOCK_VARS (DECL_INITIAL (t)));
10113   c_write_global_declarations_1 (BLOCK_VARS (ext_block));
10114 
10115   timevar_stop (TV_PHASE_DEFERRED);
10116   timevar_start (TV_PHASE_OPT_GEN);
10117 
10118   /* We're done parsing; proceed to optimize and emit assembly.
10119      FIXME: shouldn't be the front end's responsibility to call this.  */
10120   finalize_compilation_unit ();
10121 
10122   timevar_stop (TV_PHASE_OPT_GEN);
10123   timevar_start (TV_PHASE_DBGINFO);
10124 
10125   /* After cgraph has had a chance to emit everything that's going to
10126      be emitted, output debug information for globals.  */
10127   if (!seen_error ())
10128     {
10129       timevar_push (TV_SYMOUT);
10130       FOR_EACH_VEC_ELT (*all_translation_units, i, t)
10131 	c_write_global_declarations_2 (BLOCK_VARS (DECL_INITIAL (t)));
10132       c_write_global_declarations_2 (BLOCK_VARS (ext_block));
10133       timevar_pop (TV_SYMOUT);
10134     }
10135 
10136   ext_block = NULL;
10137   timevar_stop (TV_PHASE_DBGINFO);
10138 }
10139 
10140 /* Register reserved keyword WORD as qualifier for address space AS.  */
10141 
10142 void
10143 c_register_addr_space (const char *word, addr_space_t as)
10144 {
10145   int rid = RID_FIRST_ADDR_SPACE + as;
10146   tree id;
10147 
10148   /* Address space qualifiers are only supported
10149      in C with GNU extensions enabled.  */
10150   if (c_dialect_objc () || flag_no_asm)
10151     return;
10152 
10153   id = get_identifier (word);
10154   C_SET_RID_CODE (id, rid);
10155   C_IS_RESERVED_WORD (id) = 1;
10156   ridpointers [rid] = id;
10157 }
10158 
10159 #include "gt-c-c-decl.h"
10160