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