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